(urgent) fix followThunkFunction

it was following hooks for cocos functions, causing bad crashes.
instead, now only follow jmp and then jmp dword ptr
This commit is contained in:
matcool 2023-12-15 11:59:11 -03:00
parent 2077a238d3
commit 4b7663015a
3 changed files with 20 additions and 14 deletions

View file

@ -1 +1 @@
1.3.8 1.3.9

View file

@ -48,7 +48,7 @@ gd::string decompressString2(unsigned char* data, bool decrypt, int size, int de
// Modify doesnt want to work for some reason! // Modify doesnt want to work for some reason!
$execute { $execute {
Mod::get()->addHook( (void) Mod::get()->addHook(
reinterpret_cast<void*>( reinterpret_cast<void*>(
geode::addresser::getNonVirtual( geode::addresser::getNonVirtual(
&cocos2d::ZipUtils::decompressString2 &cocos2d::ZipUtils::decompressString2

View file

@ -68,19 +68,25 @@ Addresser::MultipleInheritance* Addresser::instance() {
intptr_t Addresser::followThunkFunction(intptr_t address) { intptr_t Addresser::followThunkFunction(intptr_t address) {
#ifdef GEODE_IS_WINDOWS #ifdef GEODE_IS_WINDOWS
for (int limit = 0; limit < 100; ++limit) { // if theres a jmp at the start
if (*reinterpret_cast<uint8_t*>(address) == 0xE9) {
auto relative = *reinterpret_cast<uint32_t*>(address + 1);
auto newAddress = address + relative + 5;
// and if that jmp leads to a jmp dword ptr, only then follow it,
// because otherwise its just a hook.
// For some reason this [jmp -> jmp dword ptr] chain happens with a few cocos functions,
// but not all. For example: cocos2d::ZipUtils::decompressString2
if (*reinterpret_cast<uint8_t*>(newAddress) == 0xFF && *reinterpret_cast<uint8_t*>(newAddress + 1) == 0x25) {
address = newAddress;
}
}
// check if first instruction is a jmp dword ptr [....], i.e. if the func is a thunk // 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) { if (*reinterpret_cast<uint8_t*>(address) == 0xFF && *reinterpret_cast<uint8_t*>(address + 1) == 0x25) {
// read where the jmp reads from // read where the jmp reads from
address = *reinterpret_cast<uint32_t*>(address + 2); address = *reinterpret_cast<uint32_t*>(address + 2);
// that then contains the actual address of the func // that then contains the actual address of the func
address = *reinterpret_cast<uintptr_t*>(address); 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 #endif
return address; return address;