Merge pull request #4 from CrazyBloo/Cheats_Patches

Initial Patch Implementation
This commit is contained in:
DanielSvoboda
2024-08-23 08:53:53 -03:00
committed by GitHub
7 changed files with 128 additions and 33 deletions

View File

@@ -5,6 +5,7 @@
#include "common/alignment.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/memory_patcher.h"
#include "common/string_util.h"
#include "core/aerolib/aerolib.h"
#include "core/cpu_patches.h"
@@ -19,8 +20,6 @@ using EntryFunc = PS4_SYSV_ABI int (*)(size_t args, const void* argp, void* para
static u64 LoadOffset = CODE_BASE_OFFSET;
static constexpr u64 CODE_BASE_INCR = 0x010000000u;
uintptr_t g_eboot_address;
static u64 GetAlignedSize(const elf_program_header& phdr) {
return (phdr.p_align != 0 ? (phdr.p_memsz + (phdr.p_align - 1)) & ~(phdr.p_align - 1)
: phdr.p_memsz);
@@ -92,12 +91,6 @@ void Module::LoadModuleToMemory(u32& max_tls_index) {
LoadOffset += CODE_BASE_INCR * (1 + aligned_base_size / CODE_BASE_INCR);
LOG_INFO(Core_Linker, "Loading module {} to {}", name, fmt::ptr(*out_addr));
if (g_eboot_address == 0) {
if (name == "eboot") {
g_eboot_address = base_virtual_addr;
}
}
// Initialize trampoline generator.
void* trampoline_addr = std::bit_cast<void*>(base_virtual_addr + aligned_base_size);
Xbyak::CodeGenerator c(TrampolineSize, trampoline_addr);
@@ -200,6 +193,13 @@ void Module::LoadModuleToMemory(u32& max_tls_index) {
const VAddr entry_addr = base_virtual_addr + elf.GetElfEntry();
LOG_INFO(Core_Linker, "program entry addr ..........: {:#018x}", entry_addr);
if (MemoryPatcher::g_eboot_address == 0) {
if (name == "eboot") {
MemoryPatcher::g_eboot_address = base_virtual_addr;
MemoryPatcher::ApplyPendingPatches();
}
}
}
void Module::LoadDynamicInfo() {

View File

@@ -243,6 +243,4 @@ public:
std::vector<u8> rela_bits;
};
extern uintptr_t g_eboot_address;
} // namespace Core