I'm trying to port a wrapper function from 32bit to x86-64 asm for the Windows ABI. The function depends on indexing into its arguments as an array.
I know that MSVC cannot do inline assembly in X64 projects, but i am interested to build the equivalent function into a X64 .asm file.
The function sets the stackframe for the api to be called.
__declspec( naked ) PVOID WINAPIV CGX86( FARPROC lpPtr, UINT lpSize, ... )
{
__asm {
push ebp;
mov ebp, esp;
lea eax, [ ebp + 0x04 ];
mov [ ebp - 0x04 ], eax;
mov eax, [ ebp - 0x04 ];
mov ecx, [ ebp + 0x0C ];
add ecx, 2;
ParseArgs:
cmp ecx, 2;
jz short MoveFinal;
push dword ptr [ eax + ecx * 0x04 ];
sub ecx, 1;
jmp short ParseArgs;
MoveFinal:
call [ ebp + 0x08 ];
mov esp, ebp;
pop ebp;
retn;
}
}
example use:
CGX86( ( FARPROC )MessageBoxA, 4, GetForegroundWindow( ), "BODY", "TITLE", MB_OK );