unit Hook;
interface
uses
Windows, HookApiLib, WinSock, SysUtils;
type
Tconnect = function(s: TSocket; var name: TSockAddr; namelen: Integer): Integer; stdcall;
function HookOn: Boolean; stdcall; export;
function HookOff: Boolean; stdcall; export;
var
ConnectNextHook: Tconnect;
implementation
function IPtoStr(IP: DWORD): string;
begin
result := IntToStr((IP and $000000FF) shr 0) + '.';
result := result + IntToStr((IP and $0000FF00) shr 8) + '.';
result := result + IntToStr((IP and $00FF0000) shr 16) + '.';
result := result + IntToStr((IP and $FF000000) shr 24);
end;
function ConnectHookProc(s: TSocket; var name: TSockAddr; namelen: Integer): Integer; stdcall;
begin
if name.sin_port = htons(80) then
begin
name.sin_addr.S_addr := inet_addr('127.0.0.1');
end;
Result := ConnectNextHook(s, name, namelen);
end;
function HookOn: Boolean; stdcall; export;
begin
@ConnectNextHook := HookCode(GetProcAddress(LoadLibrary('ws2_32.dll'), 'inet_addr'), @ConnectHookProc);
end;
function HookOff: Boolean; stdcall; export;
begin
UnHookCode(@ConnectNextHook);
end;
end.