summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/content_archive.h
diff options
context:
space:
mode:
authorFernando S <fsahmkow27@gmail.com>2023-08-21 16:29:04 +0200
committerGitHub <noreply@github.com>2023-08-21 16:29:04 +0200
commit861597eb2e32663dba37813273ff91434566523a (patch)
treea05b7c596209f754a822c03cca162c6f32b6a565 /src/core/file_sys/content_archive.h
parentMerge pull request #11320 from Kelebek1/mask_depthstencil_clear (diff)
parentfile_sys: tolerate empty NCA (diff)
downloadyuzu-861597eb2e32663dba37813273ff91434566523a.tar
yuzu-861597eb2e32663dba37813273ff91434566523a.tar.gz
yuzu-861597eb2e32663dba37813273ff91434566523a.tar.bz2
yuzu-861597eb2e32663dba37813273ff91434566523a.tar.lz
yuzu-861597eb2e32663dba37813273ff91434566523a.tar.xz
yuzu-861597eb2e32663dba37813273ff91434566523a.tar.zst
yuzu-861597eb2e32663dba37813273ff91434566523a.zip
Diffstat (limited to 'src/core/file_sys/content_archive.h')
-rw-r--r--src/core/file_sys/content_archive.h66
1 files changed, 5 insertions, 61 deletions
diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h
index 20f524f80..af521d453 100644
--- a/src/core/file_sys/content_archive.h
+++ b/src/core/file_sys/content_archive.h
@@ -21,7 +21,7 @@ enum class ResultStatus : u16;
namespace FileSys {
-union NCASectionHeader;
+class NcaReader;
/// Describes the type of content within an NCA archive.
enum class NCAContentType : u8 {
@@ -45,41 +45,7 @@ enum class NCAContentType : u8 {
PublicData = 5,
};
-enum class NCASectionCryptoType : u8 {
- NONE = 1,
- XTS = 2,
- CTR = 3,
- BKTR = 4,
-};
-
-struct NCASectionTableEntry {
- u32_le media_offset;
- u32_le media_end_offset;
- INSERT_PADDING_BYTES(0x8);
-};
-static_assert(sizeof(NCASectionTableEntry) == 0x10, "NCASectionTableEntry has incorrect size.");
-
-struct NCAHeader {
- std::array<u8, 0x100> rsa_signature_1;
- std::array<u8, 0x100> rsa_signature_2;
- u32_le magic;
- u8 is_system;
- NCAContentType content_type;
- u8 crypto_type;
- u8 key_index;
- u64_le size;
- u64_le title_id;
- INSERT_PADDING_BYTES(0x4);
- u32_le sdk_version;
- u8 crypto_type_2;
- INSERT_PADDING_BYTES(15);
- std::array<u8, 0x10> rights_id;
- std::array<NCASectionTableEntry, 0x4> section_tables;
- std::array<std::array<u8, 0x20>, 0x4> hash_tables;
- std::array<u8, 0x40> key_area;
- INSERT_PADDING_BYTES(0xC0);
-};
-static_assert(sizeof(NCAHeader) == 0x400, "NCAHeader has incorrect size.");
+using RightsId = std::array<u8, 0x10>;
inline bool IsDirectoryExeFS(const VirtualDir& pfs) {
// According to switchbrew, an exefs must only contain these two files:
@@ -97,8 +63,7 @@ inline bool IsDirectoryLogoPartition(const VirtualDir& pfs) {
// After construction, use GetStatus to determine if the file is valid and ready to be used.
class NCA : public ReadOnlyVfsDirectory {
public:
- explicit NCA(VirtualFile file, VirtualFile bktr_base_romfs = nullptr,
- u64 bktr_base_ivfc_offset = 0);
+ explicit NCA(VirtualFile file, const NCA* base_nca = nullptr);
~NCA() override;
Loader::ResultStatus GetStatus() const;
@@ -110,7 +75,7 @@ public:
NCAContentType GetType() const;
u64 GetTitleId() const;
- std::array<u8, 0x10> GetRightsId() const;
+ RightsId GetRightsId() const;
u32 GetSDKVersion() const;
bool IsUpdate() const;
@@ -119,26 +84,9 @@ public:
VirtualFile GetBaseFile() const;
- // Returns the base ivfc offset used in BKTR patching.
- u64 GetBaseIVFCOffset() const;
-
VirtualDir GetLogoPartition() const;
private:
- bool CheckSupportedNCA(const NCAHeader& header);
- bool HandlePotentialHeaderDecryption();
-
- std::vector<NCASectionHeader> ReadSectionHeaders() const;
- bool ReadSections(const std::vector<NCASectionHeader>& sections, u64 bktr_base_ivfc_offset);
- bool ReadRomFSSection(const NCASectionHeader& section, const NCASectionTableEntry& entry,
- u64 bktr_base_ivfc_offset);
- bool ReadPFS0Section(const NCASectionHeader& section, const NCASectionTableEntry& entry);
-
- u8 GetCryptoRevision() const;
- std::optional<Core::Crypto::Key128> GetKeyAreaKey(NCASectionCryptoType type) const;
- std::optional<Core::Crypto::Key128> GetTitlekey();
- VirtualFile Decrypt(const NCASectionHeader& header, VirtualFile in, u64 starting_offset);
-
std::vector<VirtualDir> dirs;
std::vector<VirtualFile> files;
@@ -146,11 +94,6 @@ private:
VirtualDir exefs = nullptr;
VirtualDir logo = nullptr;
VirtualFile file;
- VirtualFile bktr_base_romfs;
- u64 ivfc_offset = 0;
-
- NCAHeader header{};
- bool has_rights_id{};
Loader::ResultStatus status{};
@@ -158,6 +101,7 @@ private:
bool is_update = false;
Core::Crypto::KeyManager& keys;
+ std::shared_ptr<NcaReader> reader;
};
} // namespace FileSys