diff options
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 3 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 18 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 4 | 
3 files changed, 20 insertions, 5 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index c1824b9c3..9a86e5824 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -130,6 +130,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)      }      process.LoadFromMetadata(metadata); +    const FileSys::PatchManager pm(metadata.GetTitleID());      // Load NSO modules      const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); @@ -139,7 +140,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)          const FileSys::VirtualFile module_file = dir->GetFile(module);          if (module_file != nullptr) {              const VAddr load_addr = next_load_addr; -            next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr); +            next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, pm);              LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);              // Register module with GDBStub              GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); 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 @@  #include "common/logging/log.h"  #include "common/swap.h"  #include "core/core.h" +#include "core/file_sys/patch_manager.h"  #include "core/gdbstub/gdbstub.h"  #include "core/hle/kernel/kernel.h"  #include "core/hle/kernel/process.h" @@ -36,8 +37,7 @@ struct NsoHeader {      INSERT_PADDING_WORDS(1);      u8 flags;      std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order) -    u32_le bss_size; -    INSERT_PADDING_BYTES(0x1c); +    std::array<u8, 0x20> build_id;      std::array<u32_le, 3> segments_compressed_size;      bool IsSegmentCompressed(size_t segment_num) const { @@ -93,7 +93,8 @@ static constexpr u32 PageAlignSize(u32 size) {      return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;  } -VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { +VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, +                                boost::optional<FileSys::PatchManager> pm) {      if (file == nullptr)          return {}; @@ -142,6 +143,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) {      const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)};      program_image.resize(image_size); +    // Apply patches if necessary +    if (pm != boost::none && pm->HasNSOPatch(nso_header.build_id)) { +        std::vector<u8> pi_header(program_image.size() + 0x100); +        std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); +        std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); + +        pi_header = pm->PatchNSO(pi_header); + +        std::memcpy(program_image.data(), pi_header.data() + 0x100, program_image.size()); +    } +      // Load codeset for current process      codeset->name = file->GetName();      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..05353d4d9 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -5,6 +5,7 @@  #pragma once  #include "common/common_types.h" +#include "core/file_sys/patch_manager.h"  #include "core/loader/linker.h"  #include "core/loader/loader.h" @@ -26,7 +27,8 @@ public:          return IdentifyType(file);      } -    static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base); +    static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, +                            boost::optional<FileSys::PatchManager> pm = boost::none);      ResultStatus Load(Kernel::Process& process) override;  };  | 
