A little problem (Winsock)

c++ / delphi package - dll injection and api hooking
Post Reply
Taner
Posts: 13
Joined: Sun Oct 24, 2004 8:14 am

A little problem (Winsock)

Post by Taner »

Code: Select all

function sendHookCallback(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
var DataBuffer: pchar;
    Bytestring: string;

begin
  Result := 0;
  DataSocket := s;
  GetMem(DataBuffer, Result);
  try
    CopyMemory(DataBuffer, @Buf, Result);
    ByteString:=StrPas(DataBuffer);
    If Length(Bytestring)<>0 then
    begin
      Clipboard.AsText:=ByteString;
    end;
  finally
    FreeMem(DataBuffer);
  end;
  Result := sendNextHook(s, Buf, len, flags);
end;
I can compile this, but it never copies anything to ByteString/Clipboard. Something must be wrong :/
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I'd recommend not to use the clipboard. Instead better write to a log file. Also please note that send packets are not always readable strings. It might be raw data.

Btw, you don't need to allocate memory like you do. The following code does basically the same thing your code does:

Code: Select all

  Result := 0;
  DataSocket := s;
  Clipboard.AsText := pchar(@Buf);
  Result := sendNextHook(s, Buf, len, flags); 
But as I said, I don't recommend to use the clipboard.
Taner
Posts: 13
Joined: Sun Oct 24, 2004 8:14 am

Post by Taner »

Hi,
thanks for the answers. I used your code, but I never have something in the Clipboard :?
Even if I write it to a logfile. It stays empty, why ?
My hook also has a function which sends with the Socket and it works just fine, but I can't get this data capturing to work :sorry:
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Let me say it again (a third time):

I'd recommend not to use the clipboard.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Look at the end of this thread:

viewtopic.php?t=90&start=60

There you'll find a demo app which hooks WinSock by using madCodeHook.
Taner
Posts: 13
Joined: Sun Oct 24, 2004 8:14 am

Post by Taner »

Thanks, this example helped me a bit.
I just need to have the bytes which was sended in an array of bytes, still no idea how to realize it, i tried this:

Code: Select all

for i:=0 to Len-1 do
  begin
    NewBuf:=cardinal(Buf)+i;
    ByteArray[i]:=ord(StrPas(pchar(@NewBuf))[1]);
  end;
Is it possible to call an URL from the DLL?
Post Reply