Upgrade stub

This commit is contained in:
Guus Waals 2025-06-01 22:13:09 +08:00
parent 7a7c907abb
commit 3ad0cb5bd1
38 changed files with 75 additions and 81 deletions

View File

@ -7,28 +7,20 @@
extern "C" {
undefined4 crt_createProgramHeap(undefined4 param_1) {
return gh_stub_impl_cdecl<undefined4>((void *)0x00404902, param_1);
}
undefined4 ioinit(void) {
return gh_stub_impl_cdecl<undefined4>((void *)0x004046bf);
}
void crt_initConsole(void) {
return gh_stub_impl_cdecl<void>((void *)0x00404503);
}
LPSTR crt_setupEnv(void) {
return gh_stub_impl_cdecl<LPSTR>((void *)0x004043d1);
return gh_stub_impl_cdecl<0x00404902, undefined4>(param_1);
}
undefined4 ioinit(void) { return gh_stub_impl_cdecl<0x004046bf, undefined4>(); }
void crt_initConsole(void) { return gh_stub_impl_cdecl<0x00404503, void>(); }
LPSTR crt_setupEnv(void) { return gh_stub_impl_cdecl<0x004043d1, LPSTR>(); }
undefined4 crt_main2(void) {
return gh_stub_impl_cdecl<undefined4>((void *)0x00404184);
return gh_stub_impl_cdecl<0x00404184, undefined4>();
}
undefined4 crt_main1(void) {
return gh_stub_impl_cdecl<undefined4>((void *)0x004040cb);
}
void crt_static_init(void) {
return gh_stub_impl_cdecl<void>((void *)0x004027be);
return gh_stub_impl_cdecl<0x004040cb, undefined4>();
}
void crt_static_init(void) { return gh_stub_impl_cdecl<0x004027be, void>(); }
char *crt_0(void) { return gh_stub_impl_cdecl<char *>((void *)0x00404073); }
char *crt_0(void) { return gh_stub_impl_cdecl<0x00404073, char *>(); }
void gh_pre_main(void) {
DWORD DVar1;
@ -45,16 +37,16 @@ void gh_pre_main(void) {
undefined4 local_8;
local_8 = 0xffffffff;
// This sets up the unhandled exception handler i think?
// puStack_c = &DAT_00597ca0;
// puStack_10 = &LAB_00404a58;
// pvStack_14 = ExceptionList;
// local_1c = &stack0xffffff88;
// ExceptionList = &pvStack_14;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// This sets up the unhandled exception handler i think?
// puStack_c = &DAT_00597ca0;
// puStack_10 = &LAB_00404a58;
// pvStack_14 = ExceptionList;
// local_1c = &stack0xffffff88;
// ExceptionList = &pvStack_14;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
DVar1 = GetVersion();
#pragma clang diagnostic pop
#pragma clang diagnostic pop
DWORD_005cf980 = DVar1 >> 8 & 0xff;
DWORD_005cf97c = DVar1 & 0xff;
DWORD_005cf978 = DWORD_005cf97c * 0x100 + DWORD_005cf980;

View File

@ -9,5 +9,5 @@
// 0043e1d0
// Erm_fn_ucInitErrMsg
extern "C" byte Erm_fn_ucInitErrMsg(void) {
return gh_stub_impl_stdcall<byte>((void*)0x0043e1d0);
return gh_stub_impl_stdcall<0x0043e1d0, byte>();
}

View File

@ -9,5 +9,5 @@
// 004010b0
// FUN_004010b0
extern "C" undefined FUN_004010b0(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x004010b0);
return gh_stub_impl_cdecl<0x004010b0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00401320
// FUN_00401320
extern "C" undefined FUN_00401320(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00401320);
return gh_stub_impl_cdecl<0x00401320, undefined>();
}

View File

@ -9,5 +9,5 @@
// 0043e4f0
// FUN_0043e4f0
extern "C" undefined FUN_0043e4f0(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x0043e4f0);
return gh_stub_impl_cdecl<0x0043e4f0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00441d70
// FUN_00441d70
extern "C" undefined FUN_00441d70(undefined4 param_1, undefined4 param_2, undefined4 param_3, undefined4 param_4, undefined4 param_5) {
return gh_stub_impl_cdecl<undefined>((void*)0x00441d70, param_1, param_2, param_3, param_4, param_5);
return gh_stub_impl_cdecl<0x00441d70, undefined>(param_1, param_2, param_3, param_4, param_5);
}

View File

@ -9,5 +9,5 @@
// 0046fe20
// FUN_0046fe20
extern "C" undefined FUN_0046fe20(undefined4 param_1, undefined4 param_2, undefined4 param_3) {
return gh_stub_impl_cdecl<undefined>((void*)0x0046fe20, param_1, param_2, param_3);
return gh_stub_impl_cdecl<0x0046fe20, undefined>(param_1, param_2, param_3);
}

View File

@ -9,5 +9,5 @@
// 00470db0
// FUN_00470db0
extern "C" undefined FUN_00470db0(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00470db0);
return gh_stub_impl_cdecl<0x00470db0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00472150
// FUN_00472150
extern "C" undefined FUN_00472150(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00472150);
return gh_stub_impl_cdecl<0x00472150, undefined>();
}

View File

@ -9,5 +9,5 @@
// 004725a0
// FUN_004725a0
extern "C" undefined FUN_004725a0(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x004725a0);
return gh_stub_impl_cdecl<0x004725a0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 004fb300
// FUN_004fb300
extern "C" undefined FUN_004fb300(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x004fb300);
return gh_stub_impl_cdecl<0x004fb300, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00503710
// FUN_00503710
extern "C" undefined FUN_00503710(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00503710);
return gh_stub_impl_cdecl<0x00503710, undefined>();
}

View File

@ -9,5 +9,5 @@
// 005038e0
// FUN_005038e0
extern "C" undefined FUN_005038e0(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x005038e0);
return gh_stub_impl_cdecl<0x005038e0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00505fe0
// IPT_fn_vReadInput
extern "C" void IPT_fn_vReadInput(void) {
gh_stub_impl_stdcall<void>((void*)0x00505fe0);
gh_stub_impl_stdcall<0x00505fe0, void>();
}

View File

@ -9,5 +9,5 @@
// 0043f830
// Mmg_fn_vFirstInitMmgModule
extern "C" undefined Mmg_fn_vFirstInitMmgModule(undefined1 ucMaxNbChannel) {
return gh_stub_impl_stdcall<undefined>((void*)0x0043f830, ucMaxNbChannel);
return gh_stub_impl_stdcall<0x0043f830, undefined>(ucMaxNbChannel);
}

View File

@ -9,5 +9,5 @@
// 004022f0
// fn_bCreateMainDisplayScreen
extern "C" undefined fn_bCreateMainDisplayScreen(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x004022f0);
return gh_stub_impl_cdecl<0x004022f0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00401310
// g_setInitVar0
extern "C" void g_setInitVar0(void) {
gh_stub_impl_stdcall<void>((void*)0x00401310);
gh_stub_impl_stdcall<0x00401310, void>();
}

View File

@ -9,5 +9,5 @@
// 00470be0
// gfx_init2
extern "C" undefined gfx_init2(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00470be0);
return gh_stub_impl_cdecl<0x00470be0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00402450
// loadSplashBitmap
extern "C" void loadSplashBitmap(HWND unused) {
gh_stub_impl_stdcall<void>((void*)0x00402450, unused);
gh_stub_impl_stdcall<0x00402450, void>(unused);
}

View File

@ -9,5 +9,5 @@
// 004704e0
// r3_config_setGLIMode
extern "C" undefined r3_config_setGLIMode(char * param_1) {
return gh_stub_impl_cdecl<undefined>((void*)0x004704e0, param_1);
return gh_stub_impl_cdecl<0x004704e0, undefined>(param_1);
}

View File

@ -9,5 +9,5 @@
// 00470570
// r3_config_setIdentifier
extern "C" undefined r3_config_setIdentifier(char * param_1) {
return gh_stub_impl_cdecl<undefined>((void*)0x00470570, param_1);
return gh_stub_impl_cdecl<0x00470570, undefined>(param_1);
}

View File

@ -9,5 +9,5 @@
// 00470f30
// r3_config_setTexturesMem
extern "C" void r3_config_setTexturesMem(char * param_1) {
gh_stub_impl_cdecl<void>((void*)0x00470f30, param_1);
gh_stub_impl_cdecl<0x00470f30, void>(param_1);
}

View File

@ -9,5 +9,5 @@
// 00401220
// r3_engineLoop
extern "C" undefined r3_engineLoop(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00401220);
return gh_stub_impl_cdecl<0x00401220, undefined>();
}

View File

@ -9,5 +9,5 @@
// 0047bb00
// r3_get_gli_height1
extern "C" int r3_get_gli_height1(void) {
return gh_stub_impl_stdcall<int>((void*)0x0047bb00);
return gh_stub_impl_stdcall<0x0047bb00, int>();
}

View File

@ -9,5 +9,5 @@
// 0047baf0
// r3_get_gli_width1
extern "C" int r3_get_gli_width1(void) {
return gh_stub_impl_stdcall<int>((void*)0x0047baf0);
return gh_stub_impl_stdcall<0x0047baf0, int>();
}

View File

@ -9,5 +9,5 @@
// 0046fed0
// r3_gfxFrame?
extern "C" undefined r3_gfxFrameUNK(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x0046fed0);
return gh_stub_impl_cdecl<0x0046fed0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 0043e630
// r3_module1_init
extern "C" undefined r3_module1_init(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x0043e630);
return gh_stub_impl_cdecl<0x0043e630, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00443f10
// r3_module_big_init
extern "C" undefined r3_module_big_init(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00443f10);
return gh_stub_impl_cdecl<0x00443f10, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00401100
// r3_noop
extern "C" void r3_noop(void * p_cTxt1, void * p_cTxt2) {
gh_stub_impl_stdcall<void>((void*)0x00401100, p_cTxt1, p_cTxt2);
gh_stub_impl_stdcall<0x00401100, void>(p_cTxt1, p_cTxt2);
}

View File

@ -9,5 +9,5 @@
// 00445fc0
// r3_read_game_config_modem_quality
extern "C" undefined r3_read_game_config_modem_quality(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00445fc0);
return gh_stub_impl_cdecl<0x00445fc0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 00446040
// r3_read_game_config_udp_port
extern "C" undefined r3_read_game_config_udp_port(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x00446040);
return gh_stub_impl_cdecl<0x00446040, undefined>();
}

View File

@ -9,5 +9,5 @@
// 0055a8d0
// r3_set_GameDataPath
extern "C" void r3_set_GameDataPath(char * param_1) {
gh_stub_impl_cdecl<void>((void*)0x0055a8d0, param_1);
gh_stub_impl_cdecl<0x0055a8d0, void>(param_1);
}

View File

@ -9,5 +9,5 @@
// 004013a0
// r3_windowUnlockCursor
extern "C" undefined r3_windowUnlockCursor(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x004013a0);
return gh_stub_impl_cdecl<0x004013a0, undefined>();
}

View File

@ -9,5 +9,5 @@
// 0043e620
// setGameHWND3
extern "C" void setGameHWND3(HWND wnd) {
gh_stub_impl_stdcall<void>((void*)0x0043e620, wnd);
gh_stub_impl_stdcall<0x0043e620, void>(wnd);
}

View File

@ -9,5 +9,5 @@
// 004477d0
// spawnThread
extern "C" undefined spawnThread(void) {
return gh_stub_impl_cdecl<undefined>((void*)0x004477d0);
return gh_stub_impl_cdecl<0x004477d0, undefined>();
}

View File

@ -9,14 +9,14 @@ struct GHStubException : public std::exception {
void *gh_stub_impl_ptr(void *ptr);
template <typename T, typename... Args>
T gh_stub_impl_cdecl(void *ptr_, Args... args) {
template <uintptr_t addr, typename T, typename... Args>
T gh_stub_impl_cdecl(Args... args) {
#if RE_DBG_INJECTED
#if MSVC
static T (*__cdecl ptr)(Args...) = (T(*)(Args...))gh_stub_impl_ptr(ptr_);
static T (*__cdecl ptr)(Args...) = (T(*)(Args...))gh_stub_impl_ptr((void*)addr);
#else
using TFn = __cdecl T (*)(Args...);
static TFn ptr = (TFn)gh_stub_impl_ptr(ptr_);
static TFn ptr = (TFn)gh_stub_impl_ptr((void*)addr);
#endif
return ptr(args...);
#else
@ -24,15 +24,15 @@ T gh_stub_impl_cdecl(void *ptr_, Args... args) {
#endif
}
template <typename T, typename... Args>
T gh_stub_impl_stdcall(void *ptr_, Args... args) {
template <uintptr_t addr, typename T, typename... Args>
T gh_stub_impl_stdcall(Args... args) {
#if RE_DBG_INJECTED
#if MSVC
static T (*__stdcall ptr)(Args...) =
(T(*__stdcall)(Args...))gh_stub_impl_ptr(ptr_);
(T(*__stdcall)(Args...))gh_stub_impl_ptr((void*)addr);
#else
using TFn = __stdcall T (*)(Args...);
static TFn ptr = (TFn)gh_stub_impl_ptr(ptr_);
static TFn ptr = (TFn)gh_stub_impl_ptr((void*)addr);
#endif
return ptr(args...);
#else

View File

@ -28,8 +28,8 @@ public class RedumpStubFunctions extends GhidraScript {
printerr("Function not found at address: " + entry.address);
continue;
}
println("Dumping stub function: " + function.getName());
dumper.dumpStubFunction(function);
// println("Dumping stub function: " + function.getName());
dumper.dumpStubFunction(function, true);
}
}
}

View File

@ -108,20 +108,24 @@ public class FunctionDumper {
}
}
public void dumpStubFunction(Function externalFunction) throws Exception {
public void dumpStubFunction(Function externalFunction, boolean force) throws Exception {
String sanitizedExtFunctionName = Utils.sanitizeIdentifier(externalFunction.getName());
List<FunctionDatabase.FunctionEntry> entries1 = functionDatabase
.findEntriesByAddress(externalFunction.getEntryPoint());
boolean needStub = true;
if (!force) {
for (FunctionDatabase.FunctionEntry entry : entries1) {
if (entry.type == FunctionDatabase.Type.Auto || entry.type == FunctionDatabase.Type.Fix) {
needStub = false;
break;
}
}
if (!needStub)
if (!needStub) {
script.println("Function exists for " + externalFunction.getName() + " - skipping generating stub");
return;
}
}
String fileName = sanitizedExtFunctionName + ".cxx";
File f4 = new File(RemanConfig.INSTANCE.dirDecompStub, fileName);
@ -172,12 +176,10 @@ public class FunctionDumper {
String addrString = "0x" +
externalFunction.getEntryPoint().toString().replace("0x", "");
if (returnType.equals("void")) {
writer2.println(" " + stubFunction + "<" + addrString + ", void>(" +
(paramList.length() > 0 ? ", " + paramList.toString() : "") + ");");
writer2.println(" " + stubFunction + "<" + addrString + ", void>(" + paramList.toString() + ");");
} else {
writer2.println(" return " + stubFunction + "<" + addrString + ", " + returnType + ">(" +
externalFunction.getEntryPoint().toString().replace("0x", "") +
(paramList.length() > 0 ? ", " + paramList.toString() : "") + ");");
paramList.toString() + ");");
}
writer2.println("}");
@ -431,7 +433,7 @@ public class FunctionDumper {
// Possibly generate stubs for external functions
for (Function externalFunction : externalFunctionCalls) {
dumpStubFunction(externalFunction);
dumpStubFunction(externalFunction, false);
}
}
}