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

传说中的勇哥 2006-11-24 07:52:01
目前可以正常呼出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.

--------------------------------------------------------------------------
...全文
291 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
传说中的勇哥 2006-11-24
  • 打赏
  • 举报
回复
已经知道了问题所在...是因为没有madCHook.dll这个文件的问题...
传说中的勇哥 2006-11-24
  • 打赏
  • 举报
回复
弄了1晚上..都不行...高手们帮帮忙了...
菜鸟我先去睡一觉先...55555

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧