-
-
[求助]HOOK(WH_CALLWNDPROC)导致crash?
-
发表于:
2008-12-20 15:14
8329
-
[求助]HOOK(WH_CALLWNDPROC)导致crash?
1.问题描述:
程序A用来设一个HOOK,把DLL map 到另一个程序calc.exe,用WH_CALLWNDPROC的回调处理。HOOK设置没有问题,但一点calc.exe里的菜单的"关于"时,就crash掉了,如图:
----------------------------------------------------------------------------------------------------
2. DLL里部分代码
#pragma data_seg (".shared")
HWND g_hWndOth = 0;
HHOOK g_hHook2 = 0;
#pragma data_seg ()
#pragma comment(linker,"/SECTION:.shared,RWS")
int EnHook(HWND hWndOth)
{
g_hWndOth = hWndOth;
//设置HOOK
g_hHook2 = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)HookProc2, hDll, GetWindowThreadProcessId(hWndOth,NULL) );
if(g_hHook2==NULL)
{
return 0;
}
return 0;
}
LRESULT HookProc2 ( int code,
WPARAM wParam,
LPARAM lParam )
{
//里面就算不放处理语句,还是会出现crash问题
return ::CallNextHookEx(g_hHook2, code, wParam, lParam);
}
----------------------------------------------------------------------------------------------------
3. Try程序来设置HOOK
void CTryDlg::OnOK()
{
HWND hWndOth = ::FindWindow("SciCalc","计算器");
if(!hWndOth)
{
MessageBox("Can't find the file!","Info",0);
return;
}
//Set Hook
EnHook(hWndOth);
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)