library hook;
uses
SysUtils,
Classes,
Windows,
uallHook,
WinSock,
Messages,
Variants,
WinSock2
in '
WinSock2.pas',
IPC in '
IPC.pas';
{$R *.res}
type
TsendMethod =
function(s: TSocket; Buf : Pointer; Len, Flags: Integer): Integer;
stdcall;
TsendToMethod =
function(s: TSocket;
var Buf; len, flags: Integer;
var addrto: TSockAddr; tolen: Integer): Integer;
stdcall;
TrecvMethod =
function(s: TSocket; Buf : Pointer; Len, Flags: Integer): Integer;
stdcall;
TrecvFromMethod =
function(s: TSocket;
var Buf; len, flags: Integer;
var from: TSockAddr;
var fromlen: Integer): Integer;
stdcall;
var
orgiSend : TsendMethod;
orgiRecv : TrecvMethod;
orgiSendto : TsendToMethod;
orgiRecvFrom : TrecvFromMethod;
procedure informMaster(func:Integer);
var
data: TIPCData;
begin
data.s := '
';
data.func := func;
IPC.sendData(data);
end;
function callbackSend(s: TSocket; Buf : Pointer; Len, Flags: Integer): Integer;
stdcall;
begin
Result := orgiSend(s, Buf, Len, Flags);
informMaster(1);
end;
function callbackSendTo(s: TSocket;
var Buf; len, flags: Integer;
var addrto: TSockAddr; tolen: Integer): Integer;
stdcall;
begin
Result := orgiSendTo(s, Buf, Len, Flags, addrto, tolen);
informMaster(2);
end;
function callbackRecv(s: TSocket; Buf : Pointer; Len, Flags: Integer): Integer;
stdcall;
begin
Result := orgiRecv(s, Buf, Len, Flags);
informMaster(3);
end;
function callbackRecvFrom(s: TSocket;
var Buf; len, flags: Integer;
var from: TSockAddr;
var fromlen: Integer): Integer;
stdcall;
begin
Result := orgiRecvFrom(s, Buf, Len, Flags, from, fromlen);
informMaster(4);
end;
procedure injectmain;
begin
//MessageBox(0, 'Its me', '', 0);
if not(HookApiIAT('
ws2_32.dll', '
recvfrom',@callbackRecvFrom, @orgiRecvFrom))
then
begin
MessageBox(0, '
RecvFrom', '
', 0);
end;
if not(HookApiIAT('
ws2_32.dll', '
send',@callbackSend, @orgiSend))
then
begin
MessageBox(0, '
Send', '
', 0);
end;
if not(HookApiIAT('
ws2_32.dll', '
sendto',@callbackSendTo, @orgiSendTo))
then
begin
MessageBox(0, '
SendTo', '
', 0);
end;
if not(HookApiIAT('
ws2_32.dll', '
recv',@callbackRecv, @orgiRecv))
then
begin
MessageBox(0, '
Recv', '
', 0);
end;
end;
procedure uninjectmain;
begin
//MessageBox(0, 'Bye!', '', 0);
uallHook.UnHookApiIAT(@callbackSend, @orgiSend);
uallHook.UnHookApiIAT(@callbackSendTo, @orgiSendTo);
uallHook.UnHookApiIAT(@callbackRecv, @orgiRecv);
uallHook.UnHookApiIAT(@callbackRecvfrom, @orgiRecvFrom);
end;
procedure dllmain(dwReason: integer);
begin
case dwreason
of
DLL_PROCESS_ATTACH:
injectmain;
DLL_PROCESS_DETACH:
uninjectmain;
end;
end;
begin
DLLProc := @DLLMain;
DLLMain(1);
end.