diff options
| author | 2018-06-21 11:16:23 -0400 | |
|---|---|---|
| committer | 2018-06-21 11:16:23 -0400 | |
| commit | 63f26d5c40adb49094b03b232528672f526afe49 (patch) | |
| tree | b76a154e17c819df7803d5860f08406446507a5c /src/core/file_sys | |
| parent | Merge pull request #576 from Subv/warnings1 (diff) | |
| download | yuzu-63f26d5c40adb49094b03b232528672f526afe49.tar.gz yuzu-63f26d5c40adb49094b03b232528672f526afe49.tar.xz yuzu-63f26d5c40adb49094b03b232528672f526afe49.zip | |
Add support for decrypted NCA files (#567)
* Start to add NCA support in loader
* More nca stuff
* More changes to nca.cpp
* Now identifies decrypted NCA cont.
* Game list fixes and more structs and stuff
* More updates to Nca class
* Now reads ExeFs (i think)
* ACTUALLY LOADS EXEFS!
* RomFS loads and games execute
* Cleanup and Finalize
* plumbing, cleanup and testing
* fix some things that i didnt think of before
* Preliminary Review Changes
* Review changes for bunnei and subv
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/partition_filesystem.cpp | 18 | ||||
| -rw-r--r-- | src/core/file_sys/partition_filesystem.h | 2 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index 86a01a5eb..874b9e23b 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp | |||
| @@ -19,13 +19,20 @@ Loader::ResultStatus PartitionFilesystem::Load(const std::string& file_path, siz | |||
| 19 | if (file.GetSize() < sizeof(Header)) | 19 | if (file.GetSize() < sizeof(Header)) |
| 20 | return Loader::ResultStatus::Error; | 20 | return Loader::ResultStatus::Error; |
| 21 | 21 | ||
| 22 | file.Seek(offset, SEEK_SET); | ||
| 22 | // For cartridges, HFSs can get very large, so we need to calculate the size up to | 23 | // For cartridges, HFSs can get very large, so we need to calculate the size up to |
| 23 | // the actual content itself instead of just blindly reading in the entire file. | 24 | // the actual content itself instead of just blindly reading in the entire file. |
| 24 | Header pfs_header; | 25 | Header pfs_header; |
| 25 | if (!file.ReadBytes(&pfs_header, sizeof(Header))) | 26 | if (!file.ReadBytes(&pfs_header, sizeof(Header))) |
| 26 | return Loader::ResultStatus::Error; | 27 | return Loader::ResultStatus::Error; |
| 27 | 28 | ||
| 28 | bool is_hfs = (memcmp(pfs_header.magic.data(), "HFS", 3) == 0); | 29 | if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') && |
| 30 | pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) { | ||
| 31 | return Loader::ResultStatus::ErrorInvalidFormat; | ||
| 32 | } | ||
| 33 | |||
| 34 | bool is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); | ||
| 35 | |||
| 29 | size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); | 36 | size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); |
| 30 | size_t metadata_size = | 37 | size_t metadata_size = |
| 31 | sizeof(Header) + (pfs_header.num_entries * entry_size) + pfs_header.strtab_size; | 38 | sizeof(Header) + (pfs_header.num_entries * entry_size) + pfs_header.strtab_size; |
| @@ -50,7 +57,12 @@ Loader::ResultStatus PartitionFilesystem::Load(const std::vector<u8>& file_data, | |||
| 50 | return Loader::ResultStatus::Error; | 57 | return Loader::ResultStatus::Error; |
| 51 | 58 | ||
| 52 | memcpy(&pfs_header, &file_data[offset], sizeof(Header)); | 59 | memcpy(&pfs_header, &file_data[offset], sizeof(Header)); |
| 53 | is_hfs = (memcmp(pfs_header.magic.data(), "HFS", 3) == 0); | 60 | if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') && |
| 61 | pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) { | ||
| 62 | return Loader::ResultStatus::ErrorInvalidFormat; | ||
| 63 | } | ||
| 64 | |||
| 65 | is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); | ||
| 54 | 66 | ||
| 55 | size_t entries_offset = offset + sizeof(Header); | 67 | size_t entries_offset = offset + sizeof(Header); |
| 56 | size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); | 68 | size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); |
| @@ -113,7 +125,7 @@ u64 PartitionFilesystem::GetFileSize(const std::string& name) const { | |||
| 113 | } | 125 | } |
| 114 | 126 | ||
| 115 | void PartitionFilesystem::Print() const { | 127 | void PartitionFilesystem::Print() const { |
| 116 | NGLOG_DEBUG(Service_FS, "Magic: {:.4}", pfs_header.magic.data()); | 128 | NGLOG_DEBUG(Service_FS, "Magic: {}", pfs_header.magic); |
| 117 | NGLOG_DEBUG(Service_FS, "Files: {}", pfs_header.num_entries); | 129 | NGLOG_DEBUG(Service_FS, "Files: {}", pfs_header.num_entries); |
| 118 | for (u32 i = 0; i < pfs_header.num_entries; i++) { | 130 | for (u32 i = 0; i < pfs_header.num_entries; i++) { |
| 119 | NGLOG_DEBUG(Service_FS, " > File {}: {} (0x{:X} bytes, at 0x{:X})", i, | 131 | NGLOG_DEBUG(Service_FS, " > File {}: {} (0x{:X} bytes, at 0x{:X})", i, |
diff --git a/src/core/file_sys/partition_filesystem.h b/src/core/file_sys/partition_filesystem.h index 65cf572f4..9c5810cf1 100644 --- a/src/core/file_sys/partition_filesystem.h +++ b/src/core/file_sys/partition_filesystem.h | |||
| @@ -37,7 +37,7 @@ public: | |||
| 37 | 37 | ||
| 38 | private: | 38 | private: |
| 39 | struct Header { | 39 | struct Header { |
| 40 | std::array<char, 4> magic; | 40 | u32_le magic; |
| 41 | u32_le num_entries; | 41 | u32_le num_entries; |
| 42 | u32_le strtab_size; | 42 | u32_le strtab_size; |
| 43 | INSERT_PADDING_BYTES(0x4); | 43 | INSERT_PADDING_BYTES(0x4); |