Solved

Use Madshi's MadCodeHook to Hook winsock2

Posted on 2003-11-28
4
834 Views
Last Modified: 2012-06-21
Anyone know how to use Madshi's MadCodeHook to Hook winsock2's recv and send function?
please give me an example
Thanks a lot
sorry for my poor english...
0
Comment
Question by:xmichen
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 9841873
The following code should work, I guess. I've not tested it, though. Just typed it in here without even test compiling. It's not that difficult, is it?

Regards, Madshi.


library HookWinSock2;

uses Windows, WinSock, madCodeHook;

var
  sendNext : function (socket: TSocket; buf: pointer; len, flags: integer) : integer; stdcall;
  recvNext : function (socket: TSocket; buf: pointer; len, flags: integer) : integer; stdcall;

function sendCallback(socket: TSocket; buf: pointer; len, flags: integer) : integer; stdcall;
begin
  result := sendNext(socket, buf, len, flags);
end;

function recvCallback(socket: TSocket; buf: pointer; len, flags: integer) : integer; stdcall;
begin
  result := recvNext(socket, buf, len, flags);
end;

begin
  HookAPI('ws2_32.dll', 'send', @sendCallback, @sendNext);
  HookAPI('ws2_32.dll', 'recv', @recvCallback, @recvNext);
end.
0
 

Author Comment

by:xmichen
ID: 9841951
I have wrote my code like this
And my dll is global hook
If other application send packet begin with $AA001410, that application sometime will be crash...

type
  SockBuf    = array[0..4095] of Byte;

var
  sendNext : function( s       : Integer;
               const buffer  : SockBuf;
               length  : Integer;
               flags   : Integer ):Integer; stdcall;
function sendCallback( s       : Integer;
               const buffer  : SockBuf;
               length  : Integer;
               flags   : Integer ):Integer; stdcall;
var
  i : Integer;
begin
  if (buffer[0] = $AA) AND (buffer[1] = $0)
     AND (buffer[2] = $14) AND (buffer[3] = $10) then
  begin
    for i:=0 to 10 do
    begin
     AccName := AccName + Chr(buffer[i + 16]);
    end;
  end;
  Result := sendNext(s, buffer, length, flags);
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 9841960
Please check whether the buffer is assigned:

if @buffer <> nil then begin
  // all the other code here
end;

Does the solve the problem?
0
 

Author Comment

by:xmichen
ID: 9841970
Oh, I think that is the pocket less then 26 byte...
Thank madshi~~~
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 287
loading dll from external path 1 211
Thread safe  opinion 7 126
Convert Jpg /PNG To GIF 5 120
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now