diff options
Diffstat (limited to 'src/core/loader/nso.cpp')
| -rw-r--r-- | src/core/loader/nso.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index cbe2a3e53..2186b02af 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "core/core.h" | 12 | #include "core/core.h" |
| 13 | #include "core/file_sys/patch_manager.h" | ||
| 13 | #include "core/gdbstub/gdbstub.h" | 14 | #include "core/gdbstub/gdbstub.h" |
| 14 | #include "core/hle/kernel/kernel.h" | 15 | #include "core/hle/kernel/kernel.h" |
| 15 | #include "core/hle/kernel/process.h" | 16 | #include "core/hle/kernel/process.h" |
| @@ -36,8 +37,7 @@ struct NsoHeader { | |||
| 36 | INSERT_PADDING_WORDS(1); | 37 | INSERT_PADDING_WORDS(1); |
| 37 | u8 flags; | 38 | u8 flags; |
| 38 | std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order) | 39 | std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order) |
| 39 | u32_le bss_size; | 40 | std::array<u8, 0x20> build_id; |
| 40 | INSERT_PADDING_BYTES(0x1c); | ||
| 41 | std::array<u32_le, 3> segments_compressed_size; | 41 | std::array<u32_le, 3> segments_compressed_size; |
| 42 | 42 | ||
| 43 | bool IsSegmentCompressed(size_t segment_num) const { | 43 | bool IsSegmentCompressed(size_t segment_num) const { |
| @@ -93,7 +93,8 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 97 | boost::optional<FileSys::PatchManager> pm) { | ||
| 97 | if (file == nullptr) | 98 | if (file == nullptr) |
| 98 | return {}; | 99 | return {}; |
| 99 | 100 | ||
| @@ -142,6 +143,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | |||
| 142 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; | 143 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; |
| 143 | program_image.resize(image_size); | 144 | program_image.resize(image_size); |
| 144 | 145 | ||
| 146 | // Apply patches if necessary | ||
| 147 | if (pm != boost::none && pm->HasNSOPatch(nso_header.build_id)) { | ||
| 148 | std::vector<u8> pi_header(program_image.size() + 0x100); | ||
| 149 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); | ||
| 150 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); | ||
| 151 | |||
| 152 | pi_header = pm->PatchNSO(pi_header); | ||
| 153 | |||
| 154 | std::memcpy(program_image.data(), pi_header.data() + 0x100, program_image.size()); | ||
| 155 | } | ||
| 156 | |||
| 145 | // Load codeset for current process | 157 | // Load codeset for current process |
| 146 | codeset->name = file->GetName(); | 158 | codeset->name = file->GetName(); |
| 147 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 159 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |