Good afternoon,
Been home practising with MagicApiHooks in delphi, got to findout, delphi was cooler than I thought. But today foreducational purpose only, nothing harmful, I decided to hook recv(), but all the same, the DLL doesn't seem to compile.
The area of it saving to the txt file might workbut outputting the number of bytesn it didn't compile, so I decided to put ma source code, I am teaching myself delphi, using lazarus.
Code goes like this
library recvhook;
{$mode delphi}{$H+}
uses
Classes ,Windows, MagicApiHooks ,Winsock, SysUtils
{ you can add units after this };
var
oldrecv: Function(s:TSocket;var buf;len,flags:Integer):Integer;stdcall;
const
DLL_PROCESS_ATTACH=1;
function newrecv(s:TSocket;var buf;len,flags:Integer):Integer;stdcall;
var
f:TextFile;
begin
Result:=oldrecv(s,buf,len,flags);
if FileExists(ExtractFilePath(ParamStr(0))+'log.txt') then
begin
AssignFile(f,ExtractFilePath(ParamStr(0))+'log.txt');
Append(f);
ReWrite(f);
Writeln(f,'Bytes Recieved:'+intToStr(len)+'Bytes:'+ buf +'');
CloseFile(f);
Result:=recv(s,buf,len,flags);
end;
end;
procedure DLLEntryPoint(dwReason:DWORD);
begin
case dwReason of
DLL_PROCESS_ATTACH: begin
ApiHook('ws2_32.dll','recv',nil,@newrecv,@oldrecv);
end;
end;
begin
DllProc:=@DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
Sorry I may be too disturbing, just needsome help here.