簡體   English   中英

我的usercall函數的stdcall包裝器正確嗎?

[英]Is my stdcall wrapper for usercall function correct?

我需要將下面的__usercall函數包裝到_ cdecl / _stdcall中:

char __usercall sub_4017B0<al>(int a1<ebx>, int a2)

a1是整數,a2實際上是整數的整數('int args [10]')

這個對嗎? <al>在sub_4017B0后面意味着什么?

int __stdcall func_hook_payload(int callnum, int* args);

// Wrapper for
// char __usercall sub_4017B0<al>(int callnum<ebx>, int a2)
__declspec(naked) void func_hook()
{__asm{
    push ebp
    mov ebp, esp

    push dword ptr[ebp + 0x28] // args[9]
    push dword ptr[ebp + 0x24] // args[8]
    push dword ptr[ebp + 0x20] // args[7]
    push dword ptr[ebp + 0x1C] // args[6]
    push dword ptr[ebp + 0x18] // args[5]
    push dword ptr[ebp + 0x14] // args[4]
    push dword ptr[ebp + 0x10] // args[3]
    push dword ptr[ebp + 0x0C] // args[2]
    push dword ptr[ebp + 0x08] // args[1]
    push dword ptr[ebp + 0x04] // args[0]
    push ebx // callnum
    call func_hook_payload
    leave
    ret // note: __usercall is cdecl-like
}}

包裝器調用sub_4017B0的外觀如何?
包裝器應具有以下簽名:

int sub_4017B0_wrapper(int callnum, int* args);

該函數采用實際的int*還是采用va_arg 在這種情況下,您需要提供原始的調用代碼。

從我可以收集的信息來看,您的包裝器應如下所示(我不使用堆棧框架,但是您的框架是錯誤的,因為您在返回之前未pop ebp ):

__declspec(naked) void func_hook()
{
    __asm
    {
        push dword [esp + 4]    //int* - pArgs
        push ebx                //int - nArgs
        call func_hook_payload  //you can even just jump to this, the stack should clean itself up correctly
        retn
    }
}

如果是va_args ,則可以執行以下操作:

__declspec(naked) void func_hook()
{
    __asm
    {
        lea eax,[esp + 4]       //int* - &nArg[0]: here we abuse the way the windows stack grows, creating a stack based buffer 
        push eax                //int* - pArgs
        push ebx                //int - nArgs
        call func_hook_payload
        retn
    }
}

調用舊的func也非常簡單,您可以不使用nake函數,但實際上我更喜歡裸函數:)

void __declspec(naked) __stdcall CallTheOldVMFunc(int nArgs, int* pArgs)
{
    __asm
    {
        push ebx                //save ebx, its not a scratch register
        mov ebx,[esp + 8]       //set the number of args
        push [esp + 12]         //push the arg ptr
        call TheOldVMFunc
        pop ebx                 //restore ebx
        retn 8                  //ret and cleanup
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM