diff options
| author | 2019-03-23 13:46:09 -0400 | |
|---|---|---|
| committer | 2019-03-23 13:46:09 -0400 | |
| commit | 6af322a347340953cb90098645ba6d1b26864c3b (patch) | |
| tree | ea15e581f4653eadc9eae05dd21e16920f04471d /src/core/file_sys | |
| parent | Merge pull request #2279 from lioncash/cheat-global (diff) | |
| parent | loader/nso: Place translation unit specific functions into an anonymous names... (diff) | |
| download | yuzu-6af322a347340953cb90098645ba6d1b26864c3b.tar.gz yuzu-6af322a347340953cb90098645ba6d1b26864c3b.tar.xz yuzu-6af322a347340953cb90098645ba6d1b26864c3b.zip | |
Merge pull request #2280 from lioncash/nso
loader/nso: Minor refactoring
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 58884b4a0..e11217708 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include "core/file_sys/vfs_vector.h" | 20 | #include "core/file_sys/vfs_vector.h" |
| 21 | #include "core/hle/service/filesystem/filesystem.h" | 21 | #include "core/hle/service/filesystem/filesystem.h" |
| 22 | #include "core/loader/loader.h" | 22 | #include "core/loader/loader.h" |
| 23 | #include "core/loader/nso.h" | ||
| 23 | #include "core/settings.h" | 24 | #include "core/settings.h" |
| 24 | 25 | ||
| 25 | namespace FileSys { | 26 | namespace FileSys { |
| @@ -32,14 +33,6 @@ constexpr std::array<const char*, 14> EXEFS_FILE_NAMES{ | |||
| 32 | "subsdk3", "subsdk4", "subsdk5", "subsdk6", "subsdk7", "subsdk8", "subsdk9", | 33 | "subsdk3", "subsdk4", "subsdk5", "subsdk6", "subsdk7", "subsdk8", "subsdk9", |
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 35 | struct NSOBuildHeader { | ||
| 36 | u32_le magic; | ||
| 37 | INSERT_PADDING_BYTES(0x3C); | ||
| 38 | std::array<u8, 0x20> build_id; | ||
| 39 | INSERT_PADDING_BYTES(0xA0); | ||
| 40 | }; | ||
| 41 | static_assert(sizeof(NSOBuildHeader) == 0x100, "NSOBuildHeader has incorrect size."); | ||
| 42 | |||
| 43 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | 36 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { |
| 44 | std::array<u8, sizeof(u32)> bytes{}; | 37 | std::array<u8, sizeof(u32)> bytes{}; |
| 45 | bytes[0] = version % SINGLE_BYTE_MODULUS; | 38 | bytes[0] = version % SINGLE_BYTE_MODULUS; |
| @@ -163,14 +156,16 @@ std::vector<VirtualFile> PatchManager::CollectPatches(const std::vector<VirtualD | |||
| 163 | } | 156 | } |
| 164 | 157 | ||
| 165 | std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { | 158 | std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { |
| 166 | if (nso.size() < 0x100) | 159 | if (nso.size() < sizeof(Loader::NSOHeader)) { |
| 167 | return nso; | 160 | return nso; |
| 161 | } | ||
| 168 | 162 | ||
| 169 | NSOBuildHeader header; | 163 | Loader::NSOHeader header; |
| 170 | std::memcpy(&header, nso.data(), sizeof(NSOBuildHeader)); | 164 | std::memcpy(&header, nso.data(), sizeof(header)); |
| 171 | 165 | ||
| 172 | if (header.magic != Common::MakeMagic('N', 'S', 'O', '0')) | 166 | if (header.magic != Common::MakeMagic('N', 'S', 'O', '0')) { |
| 173 | return nso; | 167 | return nso; |
| 168 | } | ||
| 174 | 169 | ||
| 175 | const auto build_id_raw = Common::HexArrayToString(header.build_id); | 170 | const auto build_id_raw = Common::HexArrayToString(header.build_id); |
| 176 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | 171 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); |
| @@ -213,9 +208,11 @@ std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { | |||
| 213 | } | 208 | } |
| 214 | } | 209 | } |
| 215 | 210 | ||
| 216 | if (out.size() < 0x100) | 211 | if (out.size() < sizeof(Loader::NSOHeader)) { |
| 217 | return nso; | 212 | return nso; |
| 218 | std::memcpy(out.data(), &header, sizeof(NSOBuildHeader)); | 213 | } |
| 214 | |||
| 215 | std::memcpy(out.data(), &header, sizeof(header)); | ||
| 219 | return out; | 216 | return out; |
| 220 | } | 217 | } |
| 221 | 218 | ||