int /*WINAPI*/ MyMessageBox( HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType )
{
MsgHook.UnHook();
MessageBox(NULL, "现在可以调用了", "结果", MB_OK);
MessageBox(hWnd, lpText, lpCaption, uType);
// MsgHook.ReHook();
__asm
{
pop edi //these was fund by debug
pop esi
pop ebx
/* add esp,0x40*/ release not to use
pop ebp
ret 0x10
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
//没有hook前调用
MessageBox(NULL, "test", "test", MB_OK);
MsgHook.Hook("User32.dll", "MessageBoxA", (PROC)MyMessageBox); //hook掉MessageBoxA函数
MessageBox(NULL, "test", "test", MB_OK); //此时调用MessageBoxA,就会调用我们自己写的MyMessageBox函数
return 0;
}
高人指点:
1、Debug版本,用堆栈传参, 你计算出压栈的参数个数,最后Sub esp就OK
2、Release版本,会把一些堆栈传参的,优化为寄存器传参, Sub Esp的时候,要注意被优化后的堆栈大小