follow thunk functions for non virtuals

This commit is contained in:
matcool 2023-02-09 13:54:30 -03:00
parent 0cfb064631
commit 65f2cbb286
No known key found for this signature in database
GPG key ID: BF58756086D7AB1C

View file

@ -131,15 +131,7 @@ namespace geode::addresser {
// [[this + thunk] + offset] is the f we want
auto address = *(intptr_t*)(*(intptr_t*)(reference_cast<intptr_t>(ins) + thunk) + index);
#ifdef GEODE_IS_WINDOWS
// check if first instruction is a jmp, i.e. if the func is a thunk
if (*reinterpret_cast<uint16_t*>(address) == 0x25ff) {
// read where the jmp points to and jump there
address = *reinterpret_cast<uint32_t*>(address + 2);
// that then contains the actual address of the func
address = *reinterpret_cast<uintptr_t*>(address);
}
#endif
address = followThunkFunction(address);
return address;
}
@ -171,14 +163,27 @@ namespace geode::addresser {
return addressOfNonVirtual(reinterpret_cast<R (T::*)(Ps...)>(func));
}
static inline intptr_t 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);
}
#endif
return address;
}
template <typename R, typename T, typename... Ps>
static intptr_t addressOfNonVirtual(R (T::*func)(Ps...)) {
return geode::cast::reference_cast<intptr_t>(func);
return followThunkFunction(geode::cast::reference_cast<intptr_t>(func));
}
template <typename R, typename... Ps>
static intptr_t addressOfNonVirtual(R (*func)(Ps...)) {
return geode::cast::reference_cast<intptr_t>(func);
return followThunkFunction(geode::cast::reference_cast<intptr_t>(func));
}
template <typename T>