From 97d425c3047e67cc36e7dec95cbcbc9236c6573f Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Thu, 1 Nov 2018 20:23:38 -0400 Subject: file_sys: Use common KeyManager in NCA container types Creates a single KeyManager for the entire container and then passes it into the NCA constructor, eliminating several unnecessary KeyManager reads. --- src/core/file_sys/card_image.cpp | 2 +- src/core/file_sys/card_image.h | 3 +++ src/core/file_sys/registered_cache.cpp | 13 ++++++++----- src/core/file_sys/registered_cache.h | 3 +++ src/core/file_sys/submission_package.cpp | 2 +- src/core/file_sys/submission_package.h | 2 ++ 6 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp index 1ece55731..2c145bd09 100644 --- a/src/core/file_sys/card_image.cpp +++ b/src/core/file_sys/card_image.cpp @@ -176,7 +176,7 @@ Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) { for (const VirtualFile& file : partitions[static_cast(part)]->GetFiles()) { if (file->GetExtension() != "nca") continue; - auto nca = std::make_shared(file); + auto nca = std::make_shared(file, nullptr, 0, keys); // TODO(DarkLordZach): Add proper Rev1+ Support if (nca->IsUpdate()) continue; diff --git a/src/core/file_sys/card_image.h b/src/core/file_sys/card_image.h index 8f62571cf..25f5914b6 100644 --- a/src/core/file_sys/card_image.h +++ b/src/core/file_sys/card_image.h @@ -9,6 +9,7 @@ #include #include "common/common_types.h" #include "common/swap.h" +#include "core/crypto/key_manager.h" #include "core/file_sys/vfs.h" namespace Loader { @@ -107,5 +108,7 @@ private: std::shared_ptr secure_partition; std::shared_ptr program; std::vector> ncas; + + Core::Crypto::KeyManager keys; }; } // namespace FileSys diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 96302a241..a3f8f2f73 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp @@ -106,9 +106,12 @@ static ContentRecordType GetCRTypeFromNCAType(NCAContentType type) { VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const { - if (dir->GetFileRelative(path) != nullptr) - return dir->GetFileRelative(path); - if (dir->GetDirectoryRelative(path) != nullptr) { + const auto file = dir->GetFileRelative(path); + if (file != nullptr) + return file; + + const auto nca_dir = dir->GetDirectoryRelative(path); + if (nca_dir != nullptr) { const auto nca_dir = dir->GetDirectoryRelative(path); VirtualFile file = nullptr; @@ -225,7 +228,7 @@ void RegisteredCache::ProcessFiles(const std::vector& ids) { if (file == nullptr) continue; - const auto nca = std::make_shared(parser(file, id)); + const auto nca = std::make_shared(parser(file, id), nullptr, 0, keys); if (nca->GetStatus() != Loader::ResultStatus::Success || nca->GetType() != NCAContentType::Meta) { continue; @@ -315,7 +318,7 @@ std::unique_ptr RegisteredCache::GetEntry(u64 title_id, ContentRecordType t const auto raw = GetEntryRaw(title_id, type); if (raw == nullptr) return nullptr; - return std::make_unique(raw); + return std::make_unique(raw, nullptr, 0, keys); } std::unique_ptr RegisteredCache::GetEntry(RegisteredCacheEntry entry) const { diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h index 6cfb16017..6b89db8de 100644 --- a/src/core/file_sys/registered_cache.h +++ b/src/core/file_sys/registered_cache.h @@ -12,6 +12,7 @@ #include #include #include "common/common_types.h" +#include "core/crypto/key_manager.h" #include "core/file_sys/vfs.h" namespace FileSys { @@ -133,6 +134,8 @@ private: VirtualDir dir; RegisteredCacheParsingFunction parser; + Core::Crypto::KeyManager keys; + // maps tid -> NcaID of meta boost::container::flat_map meta_id; // maps tid -> meta diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index 2aaba4179..e1a4210db 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp @@ -252,7 +252,7 @@ void NSP::ReadNCAs(const std::vector& files) { continue; } - auto next_nca = std::make_shared(next_file); + auto next_nca = std::make_shared(next_file, nullptr, 0, keys); if (next_nca->GetType() == NCAContentType::Program) program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); if (next_nca->GetStatus() == Loader::ResultStatus::Success || diff --git a/src/core/file_sys/submission_package.h b/src/core/file_sys/submission_package.h index 338080b7e..9a28ed5bb 100644 --- a/src/core/file_sys/submission_package.h +++ b/src/core/file_sys/submission_package.h @@ -70,6 +70,8 @@ private: std::map>> ncas; std::vector ticket_files; + Core::Crypto::KeyManager keys; + VirtualFile romfs; VirtualDir exefs; }; -- cgit v1.2.3