现在的位置: 首页 > 综合 > 正文

100分求解 用madCodeHook Hook Send和Recv的问题

2012年10月17日 ⁄ 综合 ⁄ 共 2940字 ⁄ 字号 评论关闭
100分求解 用madCodeHook Hook Send和Recv的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061124075201178.html
目前可以正常呼出HOOK窗口..但是记录不到封包....  
   
  全部代码如下....  
  还试过   HookAPI('wsock32.dll'   同样不行....  
   
  Unit   MainUnit;  
   
  Interface  
   
  Uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs;  
   
  Type  
      TFrmMain=Class(TForm)  
          Procedure   FormCreate(Sender:TObject);  
      Private  
      Public  
      End;  
   
  Var  
      FrmMain:TFrmMain;  
   
  Function   HookIn(bHook:Boolean):Longint;   Stdcall;External'Hook.DLL';  
   
  Implementation  
   
  {$R   *.dfm}  
   
  Procedure   TFrmMain.FormCreate(Sender:TObject);  
  Begin  
      HookIn(True);  
  End;  
   
  End.  
   
  --------------------------------------------------------------------------  
  Library   Hook;  
   
  Uses  
      Windows,  
      WinSock2,  
      Messages,  
      SysUtils,  
      madCodeHook,  
      FrmUnit   In'FrmUnit.pas'{frm};  
   
  Type  
      TSock=Function(s:TSocket;Var   Buf;Len,   flags:Integer):Integer;Stdcall;  
   
  Var  
      OldSend,   OldRecv:TSock;  
      hMesHWnd:HWnd;  
   
  Function   pCharToHex(Buf:pChar;Len:Integer):String;  
  Var  
      I:Integer;  
  Begin  
      For   I   :=   0   To   Len-1   Do  
          Result   :=   Result+IntToHex(Ord(Buf[I]),   2)+'   ';  
  End;  
   
  Function   MySend(s:TSocket;Var   Buf;Len,   flags:Integer):Integer;   Stdcall;  
  Begin  
      frm.Logs.Lines.Add('Send:   '+pCharToHex(@Buf,   Len));  
      Result   :=   OldSend(s,   Buf,   Len,   flags);  
  End;  
  Function   MyRecv(s:TSocket;Var   Buf;Len,   flags:Integer):Integer;   Stdcall;  
  Begin  
      Result   :=   OldRecv(s,   Buf,   Len,   flags);  
      frm.Logs.Lines.Add('Reav:   '+pCharToHex(@Buf,   Len));  
  End;  
   
  Function   MesHook(nCode:Integer;WPARAM:WPARAM;lParam:lParam):LRESULT;   Stdcall;  
  Var  
      Msg:PMsg;  
      //tID:DWORD;  
  Begin  
      If   (nCode=HC_ACTION)   Then   Begin  
          If   (GetModuleHandleA('iexplore.exe')>0)   Then   Begin  
              Msg   :=   PMsg(lParam);  
              Case   Msg.Message   Of  
                  WM_KEYUP:Case   Msg.WPARAM   Of  
                          VK_F12:Begin  
                                  If   (frm=Nil)   Then   Begin  
                                      frm   :=   Tfrm.Create(Nil);  
                                      HookAPI('ws2_32.dll',   'send',   @MySend,   @OldSend);  
                                      HookAPI('ws2_32.dll',   'recv',   @MyRecv,   @OldRecv);  
                                      //HookCode(@send,   @MySend,   @OldSend);  
                                      //HookCode(@recv,   @MyRecv,   @OldRecv);  
                                  End;  
                                  frm.Show;  
                              End;  
                      End;//Case   Msg.WPARAM  
              End;//Case   Msg.message  
          End;//if   GetModuleHandleA  
      End;//If   nCode  
      Result   :=   CallNextHookEx(hMesHWnd,   nCode,   WPARAM,   lParam);  
  End;  
   
  Function   HookIn(bHook:Boolean):LongInt;   Stdcall;  
  Begin  
      If   bHook   Then   Begin  
          hMesHWnd   :=   SetWindowsHookEx(WH_GETMESSAGE,   @MesHook,   HInstance,   0);  
      End   Else   Begin  
          If   (hMesHWnd<>0)   Then   UnhookWindowsHookEx(hMesHWnd);  
          hMesHWnd   :=   0;  
      End;  
      Result   :=   hMesHWnd;  
  End;  
   
  {$R   *.res}  
  Exports  
      HookIn;  
  Begin  
   
  End.  
   
  --------------------------------------------------------------------------  
 

弄了1晚上..都不行...高手们帮帮忙了...  
  菜鸟我先去睡一觉先...55555

已经知道了问题所在...是因为没有madCHook.dll这个文件的问题...  
 

抱歉!评论已关闭.