谁能帮我看看我为什么hook不到ws2_32.dll的recv[附代码(100)

  • 主题发起人 主题发起人 tungh
  • 开始时间 开始时间
T

tungh

Unregistered / Unconfirmed
GUEST, unregistred user!
library Hook; uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,StrUtils,madcodehook,WinSock, myDLl in 'myDLl.pas' {Form1}; var hHk:HHOOK=0; hThread:Cardinal; hmod:Pointer; ////////////////// sendNextHook: function(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall; recvNextHook: function(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall; acceptNextHook : function (s: TSocket; addr: PSockAddr; addrlen: PInteger): TSocket; stdcall; t : textfile; ////////////////// function mioAccept (s: TSocket; addr: PSockAddr; addrlen: PInteger): TSocket; stdcall; begin append (T); writeln (T, 'accept'); closefile (T); Result := acceptNextHook(s, addr, addrlen); end; function mioSend (s: TSocket; var Buf; len, flags: Integer): Integer; stdcall; begin append (T); writeln (T, 'Send'); closefile (T); result:= SendNextHook (s, Buf, len, flags); end; function mioRecv (s: TSocket; var Buf; len, flags: Integer): Integer; stdcall; begin { append (T); writeln (T, 'Recv'); closefile (T); } ShowMessage('123321'); result:= RecvNextHook (s, Buf, len, flags); end; ///////////////////// //===========接收按键F12开呼出隐藏窗口================== function HookProc(nCode:Integer;WParam: WPARAM;LParam:LPARAM):LRESULT;stdcall; label theExit; begin if nCode < 0 then goto theExit; if (nCode <> HC_ACTION) then goto theExit; if ((lParam and $80000000) = 0) { or (GetAsyncKeyState(VK_Control)=0) } then goto theExit; case wParam of VK_F12: begin //ShowMessage('11111222223'); AssignFile (T, 'log.txt'); rewrite (T); closefile (t); {acceptNextHook:= nil; RecvNextHook:= nil; SendNextHook:= nil; } HookAPI ('ws2_32.dll', 'accept', @mioAccept, @acceptNextHook); // if Assigned (acceptNextHook) then {writeln ('accept ok');} // ShowMessage('accept ok'); if HookAPI ('ws2_32.dll', 'recv', @mioRecv, @recvNextHook) then // if Assigned (RecvNextHook) then {writeln ('recv ok'); } ShowMessage('recv ok'); if HookAPI ('ws2_32.dll', 'send', @mioSend, @sendNextHook) then // if Assigned (SendNextHook) then {writeln ('send ok'); } ShowMessage('send ok'); // writeln ('started'); if form1 <> nil then begin if form1.Visible = true then Form1.Hide else Form1.Show; end else //窗体还没有加载 Form1:=TForm1.Create(Application); end; end; theExit: result := CallNextHookEx(hHk, nCode, wParam, lParam); end; //------------------------------------------------------------------------------ function HookOn(lpHwnd:HWND):Longint;stdcall;export;//安装钩子 begin hThread :=GetWindowThreadProcessId(lpHwnd,hmod); if lpHwnd <>0 then hHk :=SetWindowsHookEx(WH_KEYBOARD,@HookProc,hInstance,hThread); Result :=hHk end; //------------------------------------------------------------------------------ function HookOff:Boolean;stdcall;export; //卸载钩子 begin if hHk <>0 then begin UnHookWindowsHookEx(hHk); hHk :=0; Result :=true; end else Result :=false; end; //------------------------------------------------------------------------------ {$R *.res} exports HookOn,HookOff; begin {Application.Initialize; Application.Run; } end. /////////////////////////////////////////////////////////////////////////////////// unit myDLl; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls , ComCtrls, XPMan, Grids; type TForm1 = class(TForm) PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; TabSheet3: TTabSheet; edt1: TEdit; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} end. ////以上是DLL的 ///以下是EXE的 program zhuru; uses Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. ///////// unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, XPMan; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Label1: TLabel; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; hhk:Longint; function HookOn(lpHwnd:HWND):Longint;stdcall;external 'Hook.dll' name 'HookOn'; function HookOff:Boolean;stdcall;external 'Hook.dll' name 'HookOff'; implementation function UninstallHook(hk:HHOOK):Boolean;stdcall;export; //卸载钩子 begin if hk <>0 then begin UnHookWindowsHookEx(hHk); hk :=0; Result :=true; end else Result :=false; end; //------------------------------------------------------------------------------ {$R *.dfm} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin hookoff; end; procedure TForm1.Button1Click(Sender: TObject); var h1:HWND; txt:string; begin if Edit1.Text <>'' then begin txt:=edit1.text; h1:=FindWindow(nil,pchar(txt)); if h1>0 then begin hhk:=HookOn(h1); showmessage('找到进程,已注入!'); Caption:=IntToStr(hhk); end else showmessage('没找到进程!'); edit1.setfocus; end else begin showmessage('窗口标题不能为空!'); edit1.setfocus; end; end; procedure TForm1.Button2Click(Sender: TObject); begin UninstallHook(hhk); showmessage('注入已被取消!'); end; end. ///////////////////// object Form1: TForm1 Left = 93 Top = 373 Width = 180 Height = 154 BorderIcons = [biSystemMenu, biMinimize] Caption = #25353'F12'#21628#20986 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnClose = FormClose PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 17 Top = 11 Width = 60 Height = 13 Caption = #31383#21475#26631#39064#65306 end object Button1: TButton Left = 48 Top = 63 Width = 75 Height = 24 Caption = 'DLL'#27880#20837 TabOrder = 1 OnClick = Button1Click end object Button2: TButton Left = 48 Top = 90 Width = 75 Height = 24 Caption = #21462#28040#27880#20837 TabOrder = 2 OnClick = Button2Click end object Edit1: TEdit Left = 21 Top = 32 Width = 126 Height = 21 TabOrder = 0 end end ///////////////////////////////////////HookAPI ('ws2_32.dll', 'accept', @mioAccept, @acceptNextHook); // if Assigned (acceptNextHook) then {writeln ('accept ok');} // ShowMessage('accept ok'); if HookAPI ('ws2_32.dll', 'recv', @mioRecv, @recvNextHook) then // if Assigned (RecvNextHook) then {writeln ('recv ok'); } ShowMessage('recv ok'); if HookAPI ('ws2_32.dll', 'send', @mioSend, @sendNextHook) then // if Assigned (SendNextHook) then {writeln ('send ok'); } ShowMessage('send ok'); 这段里面 HookAPI ('ws2_32.dll', 'accept', @mioAccept, @acceptNextHook); 这个accept能hook到 而下面2个recv 与 send却hook不到 。希望懂的能帮忙看看
 
垃圾hook代码hook不到很正常。
 
HOOK高手发话楼主应自检
 
刚学HOOK不久,不懂才问。谁能帮忙看看?
 

Similar threads

后退
顶部