recursively follow jumps in followThunkFunction

This commit is contained in:
matcool 2023-12-14 21:32:19 -03:00
parent e8a326f7cb
commit 44a018cdf9

View file

@ -68,12 +68,19 @@ Addresser::MultipleInheritance* Addresser::instance() {
intptr_t Addresser::followThunkFunction(intptr_t address) {
#ifdef GEODE_IS_WINDOWS
// check if first instruction is a jmp dword ptr [....], i.e. if the func is a thunk
if (*reinterpret_cast<uint8_t*>(address) == 0xFF && *reinterpret_cast<uint8_t*>(address + 1) == 0x25) {
// read where the jmp reads from
address = *reinterpret_cast<uint32_t*>(address + 2);
// that then contains the actual address of the func
address = *reinterpret_cast<uintptr_t*>(address);
for (int limit = 0; limit < 100; ++limit) {
// check if first instruction is a jmp dword ptr [....], i.e. if the func is a thunk
if (*reinterpret_cast<uint8_t*>(address) == 0xFF && *reinterpret_cast<uint8_t*>(address + 1) == 0x25) {
// read where the jmp reads from
address = *reinterpret_cast<uint32_t*>(address + 2);
// that then contains the actual address of the func
address = *reinterpret_cast<uintptr_t*>(address);
} else if (*reinterpret_cast<uint8_t*>(address) == 0xE9) {
auto relative = *reinterpret_cast<uint32_t*>(address + 1);
address = address + relative + 5;
} else {
break;
}
}
#endif
return address;