refactor: Soundbank runtime hooking improvement

> change default behaviour to pattern based patch for hooks::soundbank, see #13
> fix broken check for hooks::soundbank unsupported game version
This commit is contained in:
[ ]
2026-02-17 19:30:01 +09:00
parent 97cca85bc8
commit 82439962d6
3 changed files with 108 additions and 35 deletions
+49
View File
@@ -249,3 +249,52 @@ bool get_pe_identifier(const std::filesystem::path& dll_path, uint32_t* time_dat
return true;
}
intptr_t find_asm_leacstr_from(HMODULE module, reg_t reg, const char *cstr)
{
// get module information
MODULEINFO module_info{};
if (!GetModuleInformation(GetCurrentProcess(), module, &module_info, sizeof(module_info)))
{
return 0;
}
const unsigned char *modbegp = reinterpret_cast<unsigned char *>(module);
const unsigned char *modendp = reinterpret_cast<unsigned char *>(module) + static_cast<size_t>(module_info.SizeOfImage);
// search cstr
const unsigned char *cstr_addr = std::search(
modbegp,
modendp,
reinterpret_cast<const unsigned char *>(cstr),
reinterpret_cast<const unsigned char *>(cstr) + strlen(cstr)
);
if (cstr_addr == modendp)
{
return 0;
}
#if defined(__i386__)
// find LEA REG, [abs32]
unsigned char asmop[6] = { 0x8D, reg.v, 0x00, 0x00, 0x00, 0x00};
int32_t dist32 = reinterpret_cast<int32_t>(cstr_addr);
memcpy(asmop + (sizeof(asmop) - 4), &dist32, 4);
return reinterpret_cast<intptr_t>(std::search(
modbegp,
modendp,
asmop,
asmop + sizeof(asmop)
));
#elif defined(__x86_64__)
// find LEA REG, [RIP + rel32]
unsigned char rex = reg.t == GPR_EXT ? 0x4C : 0x48;
unsigned char asmop[7] = {rex, 0x8D, reg.v, 0x00, 0x00, 0x00, 0x00};
for (const unsigned char *addr = modbegp; addr < modendp - sizeof(asmop); addr++)
{
auto dist32 = static_cast<int32_t>(reinterpret_cast<intptr_t>(cstr_addr) - reinterpret_cast<intptr_t>(addr + sizeof(asmop)));
memcpy(asmop + (sizeof(asmop) - 4), &dist32, 4);
if (memcmp(addr, asmop, sizeof(asmop)) == 0) return reinterpret_cast<intptr_t>(addr);
}
#endif
return 0;
}