diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2023-09-10 13:40:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-10 13:40:39 -0400 |
commit | 64130d9f01c15bc021d3802e484b5a480911e5cc (patch) | |
tree | 88a1905a2dce48c34c77fc258b47b4aea66107a9 /src/core/loader/xci.cpp | |
parent | 3df56dc790939a01dd5e07825e168ce9b462c2a7 (diff) | |
parent | 716e0a126a22cfdeeaad6204f236324429345d2e (diff) |
Merge pull request #11456 from liamwhite/worse-integrity-verification
core: implement basic integrity verification
Diffstat (limited to 'src/core/loader/xci.cpp')
-rw-r--r-- | src/core/loader/xci.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 3a76bc788..12d72c380 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -85,6 +85,40 @@ AppLoader_XCI::LoadResult AppLoader_XCI::Load(Kernel::KProcess& process, Core::S return result; } +ResultStatus AppLoader_XCI::VerifyIntegrity(std::function<bool(size_t, size_t)> progress_callback) { + // Verify secure partition, as it is the only thing we can process. + auto secure_partition = xci->GetSecurePartitionNSP(); + + // Get list of all NCAs. + const auto ncas = secure_partition->GetNCAsCollapsed(); + + size_t total_size = 0; + size_t processed_size = 0; + + // Loop over NCAs, collecting the total size to verify. + for (const auto& nca : ncas) { + total_size += nca->GetBaseFile()->GetSize(); + } + + // Loop over NCAs again, verifying each. + for (const auto& nca : ncas) { + AppLoader_NCA loader_nca(nca->GetBaseFile()); + + const auto NcaProgressCallback = [&](size_t nca_processed_size, size_t nca_total_size) { + return progress_callback(processed_size + nca_processed_size, total_size); + }; + + const auto verification_result = loader_nca.VerifyIntegrity(NcaProgressCallback); + if (verification_result != ResultStatus::Success) { + return verification_result; + } + + processed_size += nca->GetBaseFile()->GetSize(); + } + + return ResultStatus::Success; +} + ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& out_file) { return nca_loader->ReadRomFS(out_file); } |