mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
follow thunk functions for non virtuals
This commit is contained in:
parent
0cfb064631
commit
65f2cbb286
1 changed files with 16 additions and 11 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue