winsock hooking

c++ / delphi package - dll injection and api hooking
legion
Posts: 32
Joined: Sat May 15, 2004 7:48 pm

hi

Post by legion »

hi dear madshi
i am still now on this project
i have changed the code,now any error occur but when i send halo
the server or receiver's application doens't receive halo
but any others string are received successfully
did you why ?
what's happen ?

nildo i have also tried that but i obtain yje same result

here is my code

Code: Select all

library ws2hook;


uses
  windows,madcodehook,winsock,madstrings;

{$R *.res}
var
  sendNextHook: function(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;

function sendHookProc(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
var
i1 : integer;
s1 : string;
begin
    result:=0;
    i1 := 0;
    while true do
    begin
     i1 := PosPchar('halo', @Buf, 4, len, true, i1);
     if i1 >= 0 then
      begin 
      SetString(s1, pchar(@Buf), len);
      ReplaceStr(s1, 'hello', 'reallycool');
      Move(pchar(string(s1))^,(pchar(@buf))^,sizeof(@buf));
      len:=sizeof(buf);
      end
      else
      break;
    end;
 Result := sendNextHook(s, Buf, len, flags);
end;


begin
hookapi('ws2_32.dll','send', @sendHookProc, @sendNextHook);
hookapi('wsock32.dll','send', @sendHookProc, @sendNextHook);
end.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Why don't you use the code I gave you? That one should work (if you use it right).
legion
Posts: 32
Joined: Sat May 15, 2004 7:48 pm

hi

Post by legion »

hello

i tried your code but it don't work for me.
here is your code

Code: Select all

function SendCallback( s: Integer; Buf: Pointer; len, flags: Integer): Integer; stdcall; 
var s1 : string; 
begin 
  SetString(s1, Buf, len); 
  ReplaceStr(s1, 'hello', 'reallycool'); 
  result := sendNextHook(s, pointer(s1), length(s1), flags); 
end; 
did you know why ?
maybe it is mistake from me or what ?


thank in advance
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I already told you why. :?
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

Pay atention on your declaration
Post Reply