diff options
| author | 2018-08-16 17:02:31 -0400 | |
|---|---|---|
| committer | 2018-08-23 11:52:44 -0400 | |
| commit | 2164702cf7f878c84a1f148daca2416911e6e939 (patch) | |
| tree | 73db8e3ffb79e5b219cc23b935008a29a26b0de7 /src/core/loader | |
| parent | xts_encryption_layer: Implement XTSEncryptionLayer (diff) | |
| download | yuzu-2164702cf7f878c84a1f148daca2416911e6e939.tar.gz yuzu-2164702cf7f878c84a1f148daca2416911e6e939.tar.xz yuzu-2164702cf7f878c84a1f148daca2416911e6e939.zip | |
nax: Add AppLoader_NAX and update loader to support it
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/loader.cpp | 14 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 1 | ||||
| -rw-r--r-- | src/core/loader/nax.cpp | 65 | ||||
| -rw-r--r-- | src/core/loader/nax.h | 43 |
4 files changed, 121 insertions, 2 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 70ef5d240..fe5d71f68 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| 12 | #include "core/loader/deconstructed_rom_directory.h" | 12 | #include "core/loader/deconstructed_rom_directory.h" |
| 13 | #include "core/loader/elf.h" | 13 | #include "core/loader/elf.h" |
| 14 | #include "core/loader/nax.h" | ||
| 14 | #include "core/loader/nca.h" | 15 | #include "core/loader/nca.h" |
| 15 | #include "core/loader/nro.h" | 16 | #include "core/loader/nro.h" |
| 16 | #include "core/loader/nso.h" | 17 | #include "core/loader/nso.h" |
| @@ -32,6 +33,7 @@ FileType IdentifyFile(FileSys::VirtualFile file) { | |||
| 32 | CHECK_TYPE(NRO) | 33 | CHECK_TYPE(NRO) |
| 33 | CHECK_TYPE(NCA) | 34 | CHECK_TYPE(NCA) |
| 34 | CHECK_TYPE(XCI) | 35 | CHECK_TYPE(XCI) |
| 36 | CHECK_TYPE(NAX) | ||
| 35 | 37 | ||
| 36 | #undef CHECK_TYPE | 38 | #undef CHECK_TYPE |
| 37 | 39 | ||
| @@ -73,6 +75,8 @@ std::string GetFileTypeString(FileType type) { | |||
| 73 | return "NCA"; | 75 | return "NCA"; |
| 74 | case FileType::XCI: | 76 | case FileType::XCI: |
| 75 | return "XCI"; | 77 | return "XCI"; |
| 78 | case FileType::NAX: | ||
| 79 | return "NAX"; | ||
| 76 | case FileType::DeconstructedRomDirectory: | 80 | case FileType::DeconstructedRomDirectory: |
| 77 | return "Directory"; | 81 | return "Directory"; |
| 78 | case FileType::Error: | 82 | case FileType::Error: |
| @@ -150,13 +154,18 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT | |||
| 150 | case FileType::NRO: | 154 | case FileType::NRO: |
| 151 | return std::make_unique<AppLoader_NRO>(std::move(file)); | 155 | return std::make_unique<AppLoader_NRO>(std::move(file)); |
| 152 | 156 | ||
| 153 | // NX NCA file format. | 157 | // NX NCA (Nintendo Content Archive) file format. |
| 154 | case FileType::NCA: | 158 | case FileType::NCA: |
| 155 | return std::make_unique<AppLoader_NCA>(std::move(file)); | 159 | return std::make_unique<AppLoader_NCA>(std::move(file)); |
| 156 | 160 | ||
| 161 | // NX XCI (nX Card Image) file format. | ||
| 157 | case FileType::XCI: | 162 | case FileType::XCI: |
| 158 | return std::make_unique<AppLoader_XCI>(std::move(file)); | 163 | return std::make_unique<AppLoader_XCI>(std::move(file)); |
| 159 | 164 | ||
| 165 | // NX NAX (NintendoAesXts) file format. | ||
| 166 | case FileType::NAX: | ||
| 167 | return std::make_unique<AppLoader_NAX>(std::move(file)); | ||
| 168 | |||
| 160 | // NX deconstructed ROM directory. | 169 | // NX deconstructed ROM directory. |
| 161 | case FileType::DeconstructedRomDirectory: | 170 | case FileType::DeconstructedRomDirectory: |
| 162 | return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file)); | 171 | return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file)); |
| @@ -170,7 +179,8 @@ std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file) { | |||
| 170 | FileType type = IdentifyFile(file); | 179 | FileType type = IdentifyFile(file); |
| 171 | FileType filename_type = GuessFromFilename(file->GetName()); | 180 | FileType filename_type = GuessFromFilename(file->GetName()); |
| 172 | 181 | ||
| 173 | if (type != filename_type) { | 182 | // Special case: 00 is either a NCA or NAX. |
| 183 | if (type != filename_type && !(file->GetName() == "00" && type == FileType::NAX)) { | ||
| 174 | LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); | 184 | LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); |
| 175 | if (FileType::Unknown == type) | 185 | if (FileType::Unknown == type) |
| 176 | type = filename_type; | 186 | type = filename_type; |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index b74cfbf8a..d132fb4e8 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -32,6 +32,7 @@ enum class FileType { | |||
| 32 | NRO, | 32 | NRO, |
| 33 | NCA, | 33 | NCA, |
| 34 | XCI, | 34 | XCI, |
| 35 | NAX, | ||
| 35 | DeconstructedRomDirectory, | 36 | DeconstructedRomDirectory, |
| 36 | }; | 37 | }; |
| 37 | 38 | ||
diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp new file mode 100644 index 000000000..76390bf46 --- /dev/null +++ b/src/core/loader/nax.cpp | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/logging/log.h" | ||
| 6 | #include "core/core.h" | ||
| 7 | #include "core/file_sys/content_archive.h" | ||
| 8 | #include "core/file_sys/romfs.h" | ||
| 9 | #include "core/hle/kernel/process.h" | ||
| 10 | #include "core/loader/nax.h" | ||
| 11 | |||
| 12 | namespace Loader { | ||
| 13 | |||
| 14 | AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file) | ||
| 15 | : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)), | ||
| 16 | nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {} | ||
| 17 | |||
| 18 | AppLoader_NAX::~AppLoader_NAX() = default; | ||
| 19 | |||
| 20 | FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) { | ||
| 21 | FileSys::NAX nax(file); | ||
| 22 | |||
| 23 | if (nax.GetStatus() == ResultStatus::Success && nax.AsNCA() != nullptr && | ||
| 24 | nax.AsNCA()->GetStatus() == ResultStatus::Success) { | ||
| 25 | return FileType::NAX; | ||
| 26 | } | ||
| 27 | |||
| 28 | return FileType::Error; | ||
| 29 | } | ||
| 30 | |||
| 31 | ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) { | ||
| 32 | if (is_loaded) { | ||
| 33 | return ResultStatus::ErrorAlreadyLoaded; | ||
| 34 | } | ||
| 35 | |||
| 36 | if (nax->GetStatus() != ResultStatus::Success) | ||
| 37 | return nax->GetStatus(); | ||
| 38 | |||
| 39 | const auto nca = nax->AsNCA(); | ||
| 40 | if (nca == nullptr) { | ||
| 41 | if (!Core::Crypto::KeyManager::KeyFileExists(false)) | ||
| 42 | return ResultStatus::ErrorMissingProductionKeyFile; | ||
| 43 | return ResultStatus::ErrorNAXInconvertibleToNCA; | ||
| 44 | } | ||
| 45 | |||
| 46 | if (nca->GetStatus() != ResultStatus::Success) | ||
| 47 | return nca->GetStatus(); | ||
| 48 | |||
| 49 | const auto result = nca_loader->Load(process); | ||
| 50 | if (result != ResultStatus::Success) | ||
| 51 | return result; | ||
| 52 | |||
| 53 | is_loaded = true; | ||
| 54 | |||
| 55 | return ResultStatus::Success; | ||
| 56 | } | ||
| 57 | |||
| 58 | ResultStatus AppLoader_NAX::ReadRomFS(FileSys::VirtualFile& dir) { | ||
| 59 | return nca_loader->ReadRomFS(dir); | ||
| 60 | } | ||
| 61 | |||
| 62 | ResultStatus AppLoader_NAX::ReadProgramId(u64& out_program_id) { | ||
| 63 | return nca_loader->ReadProgramId(out_program_id); | ||
| 64 | } | ||
| 65 | } // namespace Loader | ||
diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h new file mode 100644 index 000000000..08d6ef346 --- /dev/null +++ b/src/core/loader/nax.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "core/file_sys/card_image.h" | ||
| 10 | #include "core/file_sys/xts_archive.h" | ||
| 11 | #include "core/loader/loader.h" | ||
| 12 | #include "core/loader/nca.h" | ||
| 13 | |||
| 14 | namespace Loader { | ||
| 15 | |||
| 16 | /// Loads a NAX file | ||
| 17 | class AppLoader_NAX final : public AppLoader { | ||
| 18 | public: | ||
| 19 | explicit AppLoader_NAX(FileSys::VirtualFile file); | ||
| 20 | ~AppLoader_NAX(); | ||
| 21 | |||
| 22 | /** | ||
| 23 | * Returns the type of the file | ||
| 24 | * @param file std::shared_ptr<VfsFile> open file | ||
| 25 | * @return FileType found, or FileType::Error if this loader doesn't know it | ||
| 26 | */ | ||
| 27 | static FileType IdentifyType(const FileSys::VirtualFile& file); | ||
| 28 | |||
| 29 | FileType GetFileType() override { | ||
| 30 | return IdentifyType(file); | ||
| 31 | } | ||
| 32 | |||
| 33 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | ||
| 34 | |||
| 35 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | ||
| 36 | ResultStatus ReadProgramId(u64& out_program_id) override; | ||
| 37 | |||
| 38 | private: | ||
| 39 | std::unique_ptr<FileSys::NAX> nax; | ||
| 40 | std::unique_ptr<AppLoader_NCA> nca_loader; | ||
| 41 | }; | ||
| 42 | |||
| 43 | } // namespace Loader | ||