diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-07-28 05:55:23 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-08-01 06:16:54 +0200 |
commit | df5b75694f5abde94ccf05fa6c7a557b1ba9079b (patch) | |
tree | 70f0cf96b1a9834360fb1c5d5547939693ecd577 /src/core/file_sys/content_archive.h | |
parent | Merge pull request #871 from bunnei/audio-config (diff) | |
download | yuzu-df5b75694f5abde94ccf05fa6c7a557b1ba9079b.tar yuzu-df5b75694f5abde94ccf05fa6c7a557b1ba9079b.tar.gz yuzu-df5b75694f5abde94ccf05fa6c7a557b1ba9079b.tar.bz2 yuzu-df5b75694f5abde94ccf05fa6c7a557b1ba9079b.tar.lz yuzu-df5b75694f5abde94ccf05fa6c7a557b1ba9079b.tar.xz yuzu-df5b75694f5abde94ccf05fa6c7a557b1ba9079b.tar.zst yuzu-df5b75694f5abde94ccf05fa6c7a557b1ba9079b.zip |
Diffstat (limited to 'src/core/file_sys/content_archive.h')
-rw-r--r-- | src/core/file_sys/content_archive.h | 26 |
1 files changed, 20 insertions, 6 deletions
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<u8, 0x10> rights_id; std::array<NCASectionTableEntry, 0x4> section_tables; std::array<std::array<u8, 0x20>, 0x4> hash_tables; - std::array<std::array<u8, 0x10>, 0x4> key_area; + std::array<u8, 0x40> key_area; INSERT_PADDING_BYTES(0xC0); }; static_assert(sizeof(NCAHeader) == 0x400, "NCAHeader has incorrect size."); +union NCASectionHeader; + inline bool IsDirectoryExeFS(const std::shared_ptr<VfsDirectory>& 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 |