summaryrefslogtreecommitdiff
path: root/src/core/loader/nso.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/loader/nso.cpp')
-rw-r--r--src/core/loader/nso.cpp15
1 files changed, 14 insertions, 1 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
95VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { 96VAddr 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));