开发者

Porting VC++ inline assembler to x64 (of a __stdcall hook)

I need to port the inline assembler to be able to compile on x64. I'm trying to get familiar with the x64 Intrinsics etc but I guess someone being into it could easily help me out.

void __stdcall Hook(P1, P2)
{
    __asm pushad

    static void* OriginalFunctionPointer =
        GetProcAddress(GetModuleHandleA("Some.dll"), "[...]");

    // [...]

    __asm popad

    __asm push (P2)
    __asm push (P1)
    __asm call (Or开发者_运维知识库iginalFunctionPointer)
}


seems you need a hooking library like this one(or this if you want a C++ API) along with a function proto, then no inline assembly is needed, in 32 or 64-bit mode. also, those pushad/popad's aren't needed when you are doing inline assembly.

typedef void (__stdcall*myfp)(int,int);
void __stdcall MyHook(int arg1, int arg2)
{
    static myfp TheFP = (myfp)GetProcAddress(GetModuleHandleA("Some.dll"), "[...]");

   //your extra code
   TheFP(arg1,arg2);
}

of course the injection of this hook needs to take place somewhere else. for hooking classes you need to account for the hidden this pointer (pDevice in this case):

#define D3D8FUNC(name,...) typedef HRESULT (__stdcall * name)(__VA_ARGS__)
D3D8FUNC(D3D8SetTexture,void* pDevice, DWORD dwStage, void* pTexture);

HRESULT __stdcall D3DSetTexture(void* pDevice, DWORD dwStage, void* pTexture)
{
    LOG("[D3DSetTexture][0x%p] Device: 0x%p Stage: %u Texture: 0x%p\n",_ReturnAddress(),pDevice,dwStage,pTexture);
    return Direct3D::gpfD3D8SetTexture(pDevice,dwStage,pTexture);
}

//in the init
Direct3D::gpfD3D8SetTexture = System::VirtualFunctionHook<Direct3D::D3D8SetTexture>(Direct3D::gpDevice,61,D3DSetTexture);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜