From 6d6de880eb9faabbc83ff31b62dd91e5bb4a490b Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 12 Feb 2023 23:02:39 +0100 Subject: Also needed a RunFunctionWindows, following the Windows Calling Convention (and now d3datapter9 works) --- src/tools/callback.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/tools') diff --git a/src/tools/callback.c b/src/tools/callback.c index d3d5101e..9aafa6d8 100755 --- a/src/tools/callback.c +++ b/src/tools/callback.c @@ -163,3 +163,47 @@ uint64_t RunFunctionWithEmu(x64emu_t *emu, int QuitOnLongJump, uintptr_t fnc, in return R_RAX; } + +EXPORTDYN +uint64_t RunFunctionWindows(box64context_t *context, uintptr_t fnc, int nargs, ...) +{ + (void)context; + + x64emu_t *emu = thread_get_emu(); + int align = (nargs>4)?(((nargs-4)&1)):0; + int stackn = align + ((nargs>4)?(nargs-4):0); + + Push64(emu, R_RBP); // push rbp + R_RBP = R_RSP; // mov rbp, rsp + + R_RSP -= stackn*sizeof(void*); // need to push in reverse order + + uint64_t *p = (uint64_t*)R_RSP; + + va_list va; + va_start (va, nargs); + for (int i=0; iregs[nn[i]].q[0] = va_arg(va, uint64_t); + } else { + *p = va_arg(va, uint64_t); + p++; + } + } + va_end (va); + + R_RSP -= 32; // ShadowArea + + uintptr_t oldip = R_RIP; + DynaCall(emu, fnc); + + if(oldip==R_RIP) { + R_RSP = R_RBP; // mov rsp, rbp + R_RBP = Pop64(emu); // pop rbp + } + + uint64_t ret = R_RAX; + + return ret; +} \ No newline at end of file -- cgit 1.4.1