diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/loader/nso.cpp | 15 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 4 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 512954d40..d22a88af1 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" |
| @@ -92,7 +93,8 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 92 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 93 | } | 94 | } |
| 94 | 95 | ||
| 95 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 97 | std::shared_ptr<FileSys::PatchManager> pm) { | ||
| 96 | if (file == nullptr) | 98 | if (file == nullptr) |
| 97 | return {}; | 99 | return {}; |
| 98 | 100 | ||
| @@ -141,6 +143,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | |||
| 141 | 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)}; |
| 142 | program_image.resize(image_size); | 144 | program_image.resize(image_size); |
| 143 | 145 | ||
| 146 | // Apply patches if necessary | ||
| 147 | if (pm != nullptr && 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 | |||
| 144 | // Load codeset for current process | 157 | // Load codeset for current process |
| 145 | codeset->name = file->GetName(); | 158 | codeset->name = file->GetName(); |
| 146 | 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)); |
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 7f142405b..7c26aa4ba 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "core/file_sys/patch_manager.h" | ||
| 8 | #include "core/loader/linker.h" | 9 | #include "core/loader/linker.h" |
| 9 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 10 | 11 | ||
| @@ -26,7 +27,8 @@ public: | |||
| 26 | return IdentifyType(file); | 27 | return IdentifyType(file); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base); | 30 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 31 | std::shared_ptr<FileSys::PatchManager> pm = nullptr); | ||
| 30 | 32 | ||
| 31 | ResultStatus Load(Kernel::Process& process) override; | 33 | ResultStatus Load(Kernel::Process& process) override; |
| 32 | }; | 34 | }; |