diff options
| author | 2018-10-29 16:10:16 -0400 | |
|---|---|---|
| committer | 2018-10-29 16:10:16 -0400 | |
| commit | 1c0226815d453acfb5e1fd766765b43fd447c15c (patch) | |
| tree | 1d145a3261bd5976f7d10287009f2ff9a0515b79 | |
| parent | settings: Add setting to control NSO dumping (diff) | |
| download | yuzu-1c0226815d453acfb5e1fd766765b43fd447c15c.tar.gz yuzu-1c0226815d453acfb5e1fd766765b43fd447c15c.tar.xz yuzu-1c0226815d453acfb5e1fd766765b43fd447c15c.zip | |
patch_manager: Add support for dumping decompressed NSOs
When enabled in settings, PatchNSO will dump the unmodified NSO that it was passed to a file named <build id>.nso in the dump root for the current title ID.
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 13 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index cb457b987..3a1623ca0 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "core/file_sys/vfs_vector.h" | 19 | #include "core/file_sys/vfs_vector.h" |
| 20 | #include "core/hle/service/filesystem/filesystem.h" | 20 | #include "core/hle/service/filesystem/filesystem.h" |
| 21 | #include "core/loader/loader.h" | 21 | #include "core/loader/loader.h" |
| 22 | #include "core/settings.h" | ||
| 22 | 23 | ||
| 23 | namespace FileSys { | 24 | namespace FileSys { |
| 24 | 25 | ||
| @@ -119,6 +120,18 @@ std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { | |||
| 119 | const auto build_id_raw = Common::HexArrayToString(header.build_id); | 120 | const auto build_id_raw = Common::HexArrayToString(header.build_id); |
| 120 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | 121 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); |
| 121 | 122 | ||
| 123 | if (Settings::values.dump_nso) { | ||
| 124 | LOG_INFO(Loader, "Dumping NSO for build_id={}, title_id={:016X}", build_id, title_id); | ||
| 125 | const auto dump_dir = Service::FileSystem::GetModificationDumpRoot(title_id); | ||
| 126 | if (dump_dir != nullptr) { | ||
| 127 | const auto nso_dir = GetOrCreateDirectoryRelative(dump_dir, "/nso"); | ||
| 128 | const auto file = nso_dir->CreateFile(fmt::format("{}.nso", build_id)); | ||
| 129 | |||
| 130 | file->Resize(nso.size()); | ||
| 131 | file->WriteBytes(nso); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 122 | LOG_INFO(Loader, "Patching NSO for build_id={}", build_id); | 135 | LOG_INFO(Loader, "Patching NSO for build_id={}", build_id); |
| 123 | 136 | ||
| 124 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 137 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 68efca5c0..aaf006309 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -154,7 +154,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(const FileSys::VfsFile& file, VAd | |||
| 154 | program_image.resize(image_size); | 154 | program_image.resize(image_size); |
| 155 | 155 | ||
| 156 | // Apply patches if necessary | 156 | // Apply patches if necessary |
| 157 | if (pm && pm->HasNSOPatch(nso_header.build_id)) { | 157 | if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) { |
| 158 | std::vector<u8> pi_header(program_image.size() + 0x100); | 158 | std::vector<u8> pi_header(program_image.size() + 0x100); |
| 159 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); | 159 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); |
| 160 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); | 160 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); |