1

以下の __usercall 関数を _ cdecl/ _stdcallにラップする必要があります。

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

a1 は整数、a2 は実際には int の配列 ('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);
4

1 に答える 1

3

関数は実際の値をとりますか、それとも sint*をとり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 関数がなくても実行できますが、実際には裸の func の方が好きです :)

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
    }
}
于 2011-01-28T06:29:57.693 に答える