Hook高手看过来,我的这个思路可行吗?请指点(50分)

  • 主题发起人 主题发起人 zzy9903
  • 开始时间 开始时间
Z

zzy9903

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(][:(]<br>我想作个木马,监视记录程序的运行,我的想法是这样的:<br>作一个全局Hook,监视窗口建立消息(如WM_CREATE),如果有窗口建立,则检测窗口,如果符合条件就进行一系列操作,不知到我的这个想法是否可行.<br>我按照上面的想法作了个dl,可是没有我要的效果,不知到是怎么回事,请大虾们给予指点,谢谢了
 
用WH_SHELL钩子可以得到窗体建立的消息HSHELL_WINDOWCREATED,窗体destroy的消息是HSHELL_WINDOWDESTROYED
 
哦,原来是这样阿,回去试试
 
呜呜~~还是不好用阿,高手帮我看看我的代码对不对好吗??<br><br>unit winhook;<br><br>interface<br><br>uses<br>Windows,Messages,Dialogs;<br><br>var<br>hNextHookProc : HHook;<br>//ocSaveExit : Pointer;<br><br>function WindowCreate(iCode : Integer;wParam : WPARAM;lParam : LPARAM) : LRESULT; stdcall ; export;<br>function EnableWinHook():BOOL;export;<br>function DisableWinHook():BOOL;export;<br><br>implementation<br><br>function WindowCreate(iCode : Integer;wParam : WPARAM;lParam : LPARAM) : LRESULT; stdcall ; export;<br>begin<br>&nbsp; Result :=0;<br>&nbsp; if iCode &lt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; Result :=CallNextHookEx(hNextHookProc,iCode,wParam,lParam);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; if wParam = HSHELL_WINDOWCREATED then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('A Window Has Been Created');<br>&nbsp; &nbsp; messagebeep(0);<br>&nbsp; end;<br>&nbsp; if wParam = HSHELL_WINDOWDESTROYED then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('A Window Has Been Destroyed');<br>&nbsp; &nbsp; messagebeep(0);<br>&nbsp; end;<br>end;<br><br>function EnableWinHook():BOOL;export;<br>begin<br>&nbsp; Result:=False;<br>&nbsp; if hNextHookProc &lt;&gt; 0 then exit;<br>&nbsp; hNextHookProc:=SetWindowsHookEx(WH_SHELL,WindowCreate,Hinstance,0);<br>&nbsp; showmessage('Program Is Runing');<br>&nbsp; Result:=hNextHookProc &lt;&gt; 0 ;<br>end;<br><br>function DisableWinHook():BOOL;export;<br>begin<br>&nbsp; if hNextHookPRoc &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowshookEx(hNextHookProc);<br>&nbsp; &nbsp; hNextHookProc:=0;<br>&nbsp; &nbsp; Messagebeep(0);<br>&nbsp; end;<br>&nbsp; Result:=hNextHookPRoc=0;<br>end;<br><br>end.
 
怎么不好用?下面的DLL是我以前写的测试,可以钩到那两个消息,你参考一下吧。<br><br>MsgHook.dpr<br>--------------------------------------------------------<br>library MsgHook;<br><br>uses windows, Messages;<br><br>var<br>&nbsp; hNextHookProc: HHook;<br>&nbsp; procSaveExit: Pointer;<br>&nbsp; iReceiver, iFormCreateMsg, iFormDestroyMsg:integer;<br>&nbsp; pAppHandle: pInteger;<br>&nbsp; HMapFile:THandle;<br><br>function MousePosHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; <br>begin<br>&nbsp; if iCode &lt; 0 then<br>&nbsp; &nbsp; Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam) <br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; if iCode = HSHELL_WINDOWCREATED then //窗体Create消息<br>&nbsp; &nbsp; &nbsp; SendMessage(pAppHandle^, iFormCreateMsg, wParam, 0)<br>&nbsp; &nbsp; else if iCode = HSHELL_WINDOWDESTROYED then //窗体destroy消息<br>&nbsp; &nbsp; &nbsp; SendMessage(pAppHandle^, iFormDestroyMsg, wParam, 0);<br>&nbsp; &nbsp; Result := 0;<br>&nbsp; end;<br>end;<br><br>function EnableMouseHook(hld:hwnd): BOOL; export; //激活钩子<br>begin<br>&nbsp; Result := False;<br>&nbsp; pAppHandle^ := hld;<br>&nbsp; if hNextHookProc &lt;&gt; 0 then Exit;<br>&nbsp; hNextHookProc := SetWindowsHookEx(WH_SHELL, MousePosHookHandler,Hinstance, 0);<br>&nbsp; Result :=hNextHookProc &lt;&gt; 0 ;<br>end;<br><br>function DisableMouseHook: BOOL; export; //禁止钩子<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowshookEx(hNextHookProc);<br>&nbsp; &nbsp; hNextHookProc := 0;<br>&nbsp; end;<br>&nbsp; Result := hNextHookProc = 0;<br>end;<br><br>procedure MouseHookExit;<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then DisableMouseHook;<br>&nbsp; ExitProc := procSaveExit;<br>end;<br><br>procedure MapCommonData; //共享内存,用来与调用它的App交换数据<br>var FirstCall: Boolean;<br>begin<br>&nbsp; HMapFile:=OpenFileMapping(FILE_MAP_WRITE, False, 'CommonData');<br>&nbsp; FirstCall:=(HMapFile = 0);<br>&nbsp; if FirstCall then<br>&nbsp; &nbsp; HMapFile:=CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(pInteger), 'CommonData');<br>&nbsp; new(pAppHandle);<br>&nbsp; pAppHandle := MapViewOfFile(hMapFile, file_map_write, 0, 0, 0); <br>&nbsp; if FirstCall then FillChar(pAppHandle^, SizeOf(pInteger), 0);<br>end;<br><br>procedure IntoDll; stdcall;<br>begin<br>&nbsp; iFormCreateMsg := RegisterWindowMessage('FormCreateMsg');<br>&nbsp; iFormDestroyMsg := RegisterWindowMessage('FormDestroyMsg');<br>&nbsp; iReceiver:=0;<br>end;<br><br>exports<br>&nbsp; EnableMouseHook, &nbsp;DisableMouseHook;<br><br>begin<br>&nbsp; InToDll;<br>&nbsp; MapCommonData;<br>&nbsp; hNextHookProc := 0;<br>&nbsp; procSaveExit := ExitProc;<br>&nbsp; ExitProc := @MouseHookExit;<br>end.
 
接受答案了.
 
后退
顶部