Winsock Hook problem

c++ / delphi package - dll injection and api hooking
Post Reply
cogumel0
Posts: 8
Joined: Wed Nov 10, 2004 2:32 am

Winsock Hook problem

Post by cogumel0 »

I got a little problem with my program, still trying to figure out a way around it.

I inject my dll into a program with CreateProcessEx, and then, if I try to hook the winsock before the program has made any attempt to send information to the net, the program where I injected my dll crashes. It doesn't give any error while hooking... it just crashes when the program actually tries to access the internet.

Also, after hooking, I can't send packets from my application until a packet is actually sent from the other program (this is easily explained by the "DataSocket := 0"). Still, is there anyway around this?

Thx in advance,
Cogumel0
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Try leaving the hook callback function empty - except calling the original API. Something like this:

function HookCallback(...) : ...;
begin
result := HookNext(...);
end;

Does it work that way?
cogumel0
Posts: 8
Joined: Wed Nov 10, 2004 2:32 am

Post by cogumel0 »

function HookCallback? :o

I don't even use that nor do I know what it's for or even where to put it :crazy:

This is how I hook it and all I do to hook it:

Code: Select all

Function HookWinsock(): boolean;//True if successful
begin
  try
    hookapi('ws2_32.dll','send', @sendHookProc, @sendNextHook);
    hookapi('wsock32.dll','send', @sendHookProc, @sendNextHook);
    HookWinsock:=True;
  except
    HookWinsock:=False;
  end;
end;
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You can't use the same hook and callback function for hooking two different APIs. So use "sendHookProc1" and "sendHookProc2". Then try to leave "sendHookProcX" empty (except calling the original API, of course).
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

Theres no need to hook both library. Hook just w2_32.dll
Post Reply