diff options
| -rw-r--r-- | src/core/file_sys/xts_archive.cpp | 11 | ||||
| -rw-r--r-- | src/core/file_sys/xts_archive.h | 4 | ||||
| -rw-r--r-- | src/core/loader/nax.cpp | 26 | ||||
| -rw-r--r-- | src/core/loader/nax.h | 4 |
4 files changed, 26 insertions, 19 deletions
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp index 0173f71c1..e937d1403 100644 --- a/src/core/file_sys/xts_archive.cpp +++ b/src/core/file_sys/xts_archive.cpp | |||
| @@ -30,9 +30,6 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t | |||
| 30 | mbedtls_md_context_t context; | 30 | mbedtls_md_context_t context; |
| 31 | mbedtls_md_init(&context); | 31 | mbedtls_md_init(&context); |
| 32 | 32 | ||
| 33 | const auto key_f = reinterpret_cast<const u8*>(key); | ||
| 34 | const std::vector<u8> key_v(key_f, key_f + key_length); | ||
| 35 | |||
| 36 | if (mbedtls_md_setup(&context, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1) || | 33 | if (mbedtls_md_setup(&context, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1) || |
| 37 | mbedtls_md_hmac_starts(&context, reinterpret_cast<const u8*>(key), key_length) || | 34 | mbedtls_md_hmac_starts(&context, reinterpret_cast<const u8*>(key), key_length) || |
| 38 | mbedtls_md_hmac_update(&context, reinterpret_cast<const u8*>(data), data_length) || | 35 | mbedtls_md_hmac_update(&context, reinterpret_cast<const u8*>(data), data_length) || |
| @@ -45,7 +42,7 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t | |||
| 45 | return true; | 42 | return true; |
| 46 | } | 43 | } |
| 47 | 44 | ||
| 48 | NAX::NAX(VirtualFile file_) : file(std::move(file_)), header(std::make_unique<NAXHeader>()) { | 45 | NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::move(file_)) { |
| 49 | std::string path = FileUtil::SanitizePath(file->GetFullPath()); | 46 | std::string path = FileUtil::SanitizePath(file->GetFullPath()); |
| 50 | static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca", | 47 | static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca", |
| 51 | std::regex_constants::ECMAScript | | 48 | std::regex_constants::ECMAScript | |
| @@ -65,7 +62,7 @@ NAX::NAX(VirtualFile file_) : file(std::move(file_)), header(std::make_unique<NA | |||
| 65 | } | 62 | } |
| 66 | 63 | ||
| 67 | NAX::NAX(VirtualFile file_, std::array<u8, 0x10> nca_id) | 64 | NAX::NAX(VirtualFile file_, std::array<u8, 0x10> nca_id) |
| 68 | : file(std::move(file_)), header(std::make_unique<NAXHeader>()) { | 65 | : header(std::make_unique<NAXHeader>()), file(std::move(file_)) { |
| 69 | Core::Crypto::SHA256Hash hash{}; | 66 | Core::Crypto::SHA256Hash hash{}; |
| 70 | mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0); | 67 | mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0); |
| 71 | status = Parse(fmt::format("/registered/000000{:02X}/{}.nca", hash[0], | 68 | status = Parse(fmt::format("/registered/000000{:02X}/{}.nca", hash[0], |
| @@ -138,9 +135,9 @@ VirtualFile NAX::GetDecrypted() const { | |||
| 138 | return dec_file; | 135 | return dec_file; |
| 139 | } | 136 | } |
| 140 | 137 | ||
| 141 | std::shared_ptr<NCA> NAX::AsNCA() const { | 138 | std::unique_ptr<NCA> NAX::AsNCA() const { |
| 142 | if (type == NAXContentType::NCA) | 139 | if (type == NAXContentType::NCA) |
| 143 | return std::make_shared<NCA>(GetDecrypted()); | 140 | return std::make_unique<NCA>(GetDecrypted()); |
| 144 | return nullptr; | 141 | return nullptr; |
| 145 | } | 142 | } |
| 146 | 143 | ||
diff --git a/src/core/file_sys/xts_archive.h b/src/core/file_sys/xts_archive.h index 55d2154a6..6e2fc4d2e 100644 --- a/src/core/file_sys/xts_archive.h +++ b/src/core/file_sys/xts_archive.h | |||
| @@ -38,7 +38,7 @@ public: | |||
| 38 | 38 | ||
| 39 | VirtualFile GetDecrypted() const; | 39 | VirtualFile GetDecrypted() const; |
| 40 | 40 | ||
| 41 | std::shared_ptr<NCA> AsNCA() const; | 41 | std::unique_ptr<NCA> AsNCA() const; |
| 42 | 42 | ||
| 43 | NAXContentType GetContentType() const; | 43 | NAXContentType GetContentType() const; |
| 44 | 44 | ||
| @@ -60,7 +60,7 @@ private: | |||
| 60 | 60 | ||
| 61 | VirtualFile file; | 61 | VirtualFile file; |
| 62 | Loader::ResultStatus status; | 62 | Loader::ResultStatus status; |
| 63 | NAXContentType type; | 63 | NAXContentType type{}; |
| 64 | 64 | ||
| 65 | VirtualFile dec_file; | 65 | VirtualFile dec_file; |
| 66 | 66 | ||
diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index b46d81c02..5d4380684 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp | |||
| @@ -11,6 +11,20 @@ | |||
| 11 | #include "core/loader/nca.h" | 11 | #include "core/loader/nca.h" |
| 12 | 12 | ||
| 13 | namespace Loader { | 13 | namespace Loader { |
| 14 | namespace { | ||
| 15 | FileType IdentifyTypeImpl(const FileSys::NAX& nax) { | ||
| 16 | if (nax.GetStatus() != ResultStatus::Success) { | ||
| 17 | return FileType::Error; | ||
| 18 | } | ||
| 19 | |||
| 20 | const auto nca = nax.AsNCA(); | ||
| 21 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { | ||
| 22 | return FileType::Error; | ||
| 23 | } | ||
| 24 | |||
| 25 | return FileType::NAX; | ||
| 26 | } | ||
| 27 | } // Anonymous namespace | ||
| 14 | 28 | ||
| 15 | AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file) | 29 | AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file) |
| 16 | : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)), | 30 | : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)), |
| @@ -19,14 +33,12 @@ AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file) | |||
| 19 | AppLoader_NAX::~AppLoader_NAX() = default; | 33 | AppLoader_NAX::~AppLoader_NAX() = default; |
| 20 | 34 | ||
| 21 | FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) { | 35 | FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) { |
| 22 | FileSys::NAX nax(file); | 36 | const FileSys::NAX nax(file); |
| 23 | 37 | return IdentifyTypeImpl(nax); | |
| 24 | if (nax.GetStatus() == ResultStatus::Success && nax.AsNCA() != nullptr && | 38 | } |
| 25 | nax.AsNCA()->GetStatus() == ResultStatus::Success) { | ||
| 26 | return FileType::NAX; | ||
| 27 | } | ||
| 28 | 39 | ||
| 29 | return FileType::Error; | 40 | FileType AppLoader_NAX::GetFileType() { |
| 41 | return IdentifyTypeImpl(*nax); | ||
| 30 | } | 42 | } |
| 31 | 43 | ||
| 32 | ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) { | 44 | ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) { |
diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index 4dbae2918..56605fe45 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h | |||
| @@ -31,9 +31,7 @@ public: | |||
| 31 | */ | 31 | */ |
| 32 | static FileType IdentifyType(const FileSys::VirtualFile& file); | 32 | static FileType IdentifyType(const FileSys::VirtualFile& file); |
| 33 | 33 | ||
| 34 | FileType GetFileType() override { | 34 | FileType GetFileType() override; |
| 35 | return IdentifyType(file); | ||
| 36 | } | ||
| 37 | 35 | ||
| 38 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 36 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 39 | 37 | ||