自己改了个子类化代码,为什么完全没效果啊?(50)

  • 主题发起人 主题发起人 xf_z
  • 开始时间 开始时间
X

xf_z

Unregistered / Unconfirmed
GUEST, unregistred user!
以前在网上找的要用到全局的共享变量,我不想用那个就改了下怎么完全不能用了啊,DLL都没注入进去,难道非要用那个全局共享变量才行吗library Hook;uses windows, Messages; //SysUtils,const HOOK_EVENT_NAME = 'MyHook'; WM_MYCPSHOWWINDOW=WM_USER+600;varOldWndProc: pointer; {旧的窗口过程}HookWindow, SpyWindow: LongWORD; {要安装HOOK的窗口及用于接收消息的窗口}hHook: LongWORD; {HOOK句柄}{----------}{函数名:NewWndProc{函数功能:新的窗口过程{函数参数:hHwnd:窗口句柄 Msg:消息ID{ wParam, lParam:消息参数{函数返回值:下一个窗口过程的返回值{----------}function NewWndProc(hHwnd, Msg, wParam, lParam: LongWORD): Longint; stdcall;begin {给监视窗口发送拦载新消息的消息} if (Msg=WM_SHOWWINDOW) then begin SendMessage(SpyWindow,WM_MYCPSHOWWINDOW,wParam, lParam); end; Result := CallWindowProc(OldWndProc, hHwnd, Msg, wParam, lParam);end;{----------}{过程名:HookProc{过程功能:HOOK过程{过程参数:nCode, wParam, lParam消息的相{ 关参数{----------}procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;var hEvent: THandle;begin {保存窗口过程地址并子类化} if hEvent <> 0 then begin WaitForSingleObject(hEvent, INFINITE); CloseHandle(hEvent); end; OldWndProc := pointer(GetWindowLong(HookWindow, GWL_WNDPROC)); SetWindowLong(HookWindow, GWL_WNDPROC, integer(@NewWndProc)); hEvent := OpenEvent(Synchronize, False, HOOK_EVENT_NAME); {调用下一个Hook} CallNextHookEx(hHook, nCode, wParam, lParam);end;{----------}{函数名:InstallHook{函数功能:在指定窗口上安装HOOK{函数参数:HWindow:要安装HOOK的窗口{ SWindow:用于接收消息的窗口{返回值:成功返回TRUE,失败返回FALSE{----------}function InstallHook(HWindow, SWindow: LongWORD):Boolean;stdcall;var ThreadID: LongWORD; hEvent: THandle;begin Result := False; hHook := 0; HookWindow := HWindow; SpyWindow := SWindow; {得到指定窗口的线程ID} ThreadID := GetWindowThreadProcessId(HWindow, nil); {给指定窗口挂上钩子} hEvent := CreateEvent(nil, True, False, HOOK_EVENT_NAME); hHook := SetWindowsHookEx(WH_GETMESSAGE, @HookProc, Hinstance, ThreadID); SetEvent(hEvent); CloseHandle(hEvent); if hHook > 0 then Result := True; {是否成功HOOK}end;{----------}{过程名:UnHook{过程功能:卸载HOOK{过程参数:无{----------}procedure UnHook;stdcall;begin {发送卸载子类化消息给指定窗口} {卸载Hook} UnhookWindowsHookEx(hHook);end;{----------}{过程名:DLL入口函数{过程功能:进行DLL初始化,释放等{过程参数:DLL状态{----------}procedure MyDLLHandler(Reason: Integer);var FHandle: LongWORD;begin case Reason of DLL_PROCESS_ATTACH:; DLL_PROCESS_DETACH:; DLL_THREAD_ATTACH:; DLL_THREAD_DETACH:; end;end;exports InstallHook, UnHook, HookProc;begin DLLProc := @MyDLLHandler; MyDLLhandler(DLL_PROCESS_ATTACH);end.
 
后退
顶部