From df5b75694f5abde94ccf05fa6c7a557b1ba9079b Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 27 Jul 2018 23:55:23 -0400 Subject: Remove files that are not used --- src/core/file_sys/content_archive.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/core/file_sys/content_archive.h') diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index 0b8b9db61..1e8d9c8ae 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -12,10 +12,10 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" +#include "core/crypto/key_manager.h" #include "core/file_sys/partition_filesystem.h" namespace FileSys { - enum class NCAContentType : u8 { Program = 0, Meta = 1, @@ -24,6 +24,13 @@ enum class NCAContentType : u8 { Data = 4, }; +enum class NCASectionCryptoType : u8 { + NONE = 1, + XTS = 2, + CTR = 3, + BKTR = 4, +}; + struct NCASectionTableEntry { u32_le media_offset; u32_le media_end_offset; @@ -48,20 +55,19 @@ struct NCAHeader { std::array rights_id; std::array section_tables; std::array, 0x4> hash_tables; - std::array, 0x4> key_area; + std::array key_area; INSERT_PADDING_BYTES(0xC0); }; static_assert(sizeof(NCAHeader) == 0x400, "NCAHeader has incorrect size."); +union NCASectionHeader; + inline bool IsDirectoryExeFS(const std::shared_ptr& pfs) { // According to switchbrew, an exefs must only contain these two files: return pfs->GetFile("main") != nullptr && pfs->GetFile("main.npdm") != nullptr; } -inline bool IsValidNCA(const NCAHeader& header) { - return header.magic == Common::MakeMagic('N', 'C', 'A', '2') || - header.magic == Common::MakeMagic('N', 'C', 'A', '3'); -} +bool IsValidNCA(const NCAHeader& header); // An implementation of VfsDirectory that represents a Nintendo Content Archive (NCA) conatiner. // After construction, use GetStatus to determine if the file is valid and ready to be used. @@ -81,6 +87,8 @@ public: VirtualFile GetRomFS() const; VirtualDir GetExeFS() const; + VirtualFile GetBaseFile() const; + protected: bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; @@ -95,6 +103,12 @@ private: NCAHeader header{}; Loader::ResultStatus status{}; + + bool encrypted; + + Crypto::Key128 GetKeyAreaKey(NCASectionCryptoType type); + + VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, size_t starting_offset); }; } // namespace FileSys -- cgit v1.2.3 From 22342487e8fb851a9837db22408db56240aa6931 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 28 Jul 2018 16:23:00 -0400 Subject: Extract mbedtls to cpp file --- src/core/file_sys/content_archive.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/file_sys/content_archive.h') diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index 1e8d9c8ae..d9ad3bf7e 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -9,6 +9,7 @@ #include #include +#include "core/loader/loader.h" #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" @@ -108,7 +109,7 @@ private: Crypto::Key128 GetKeyAreaKey(NCASectionCryptoType type); - VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, size_t starting_offset); + VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, u64 starting_offset); }; } // namespace FileSys -- cgit v1.2.3 From 239a3113e4c6a53a2c7b12e67a0f21afae24b0aa Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 28 Jul 2018 21:39:42 -0400 Subject: Make XCI comply to review and style guidelines --- src/core/file_sys/content_archive.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/content_archive.h') diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index d9ad3bf7e..153142b06 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -9,12 +9,12 @@ #include #include -#include "core/loader/loader.h" #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" #include "core/crypto/key_manager.h" #include "core/file_sys/partition_filesystem.h" +#include "core/loader/loader.h" namespace FileSys { enum class NCAContentType : u8 { @@ -107,7 +107,8 @@ private: bool encrypted; - Crypto::Key128 GetKeyAreaKey(NCASectionCryptoType type); + Core::Crypto::KeyManager keys; + Core::Crypto::Key128 GetKeyAreaKey(NCASectionCryptoType type); VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, u64 starting_offset); }; -- cgit v1.2.3 From 03149d3e4a7f8038d9c88cbeb19dee25a39e0042 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 29 Jul 2018 19:00:09 -0400 Subject: Add missing includes and use const where applicable --- src/core/file_sys/content_archive.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/core/file_sys/content_archive.h') diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index 153142b06..e68ab0235 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -17,6 +17,9 @@ #include "core/loader/loader.h" namespace FileSys { + +union NCASectionHeader; + enum class NCAContentType : u8 { Program = 0, Meta = 1, @@ -61,8 +64,6 @@ struct NCAHeader { }; static_assert(sizeof(NCAHeader) == 0x400, "NCAHeader has incorrect size."); -union NCASectionHeader; - inline bool IsDirectoryExeFS(const std::shared_ptr& pfs) { // According to switchbrew, an exefs must only contain these two files: return pfs->GetFile("main") != nullptr && pfs->GetFile("main.npdm") != nullptr; @@ -94,6 +95,9 @@ protected: bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; private: + Core::Crypto::Key128 GetKeyAreaKey(NCASectionCryptoType type) const; + VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, u64 starting_offset) const; + std::vector dirs; std::vector files; @@ -108,9 +112,6 @@ private: bool encrypted; Core::Crypto::KeyManager keys; - Core::Crypto::Key128 GetKeyAreaKey(NCASectionCryptoType type); - - VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, u64 starting_offset); }; } // namespace FileSys -- cgit v1.2.3 From a9c921a41dec63f76f80df1f0d5dc3be40fa80de Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 29 Jul 2018 20:47:33 -0400 Subject: Use ErrorEncrypted where applicable and fix no keys crash --- src/core/file_sys/content_archive.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/content_archive.h') diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index e68ab0235..6492163b5 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -8,7 +8,7 @@ #include #include #include - +#include #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" @@ -95,7 +95,7 @@ protected: bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; private: - Core::Crypto::Key128 GetKeyAreaKey(NCASectionCryptoType type) const; + boost::optional GetKeyAreaKey(NCASectionCryptoType type) const; VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, u64 starting_offset) const; std::vector dirs; -- cgit v1.2.3