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/nax.cpp | |
| 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/nax.cpp')
| -rw-r--r-- | src/core/loader/nax.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
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 | ||