Delphi(Pascal) codefunction WSPConnect(s: TSocket; name: PSockAddr; namelen: Integer; lpCallerData: LPWSABUF;lpCalleeData: LPWSABUF; lpSQOS: LPQOS; lpGQOS: LPQOS; var lpErrno: Integer): Integer; stdcall;
var
sin:sockaddr_in ;
begin
sin := sockaddr_in(name^);
rizhi('拦截访问目标:'+PChar(IPtoStr(sin.sin_addr.S_addr) + ':' + IntToStr(ntohs(sin.sin_port))));
result:=NextProcTable.lpWSPConnect(s,name,namelen,lpCallerData,lpCalleeData,lpSQOS,lpGQOS,lpErrno);
end;
function WSPStartup(wVersionRequested: WORD; lpWSPData: LPWSPDATA;lpProtocolInfo: LPWSAPROTOCOL_INFOW; UpcallTable: WSPUPCALLTABLE;lpProcTable: LPWSPPROC_TABLE): Integer; stdcall;
var
WSPStartupFunc:LPWSPSTARTUP;
slibpath:string;
hlibhandle:hmodule;
begin
rizhi('启动:WSPStartup...');
if not GetHookProvider(lpProtocolInfo,slibPath) then
begin
result:=WSAEPROVIDERFAILEDINIT;
exit;
end;
OutputDebugString(pchar(slibpath));
hlibhandle:=loadlibrary(pchar(slibpath));
if hlibhandle<>0 then
begin
WSPStartupFunc:= LPWSPSTARTUP(GetProcAddress(hlibhandle,pchar('WSPStartup')));
if Assigned(WSPStartupFunc) then
begin
rizhi('加载:Load library ok!');
result:=WSPStartupFunc(wVersionRequested,lpWSPData,lpProtocolInfo,UpcallTable,lpProcTable);
if result=0 then
begin
NextProcTable:=lpProcTable^;
lpProcTable.lpWSPConnect:=WSPConnect;
rizhi('加载成功:Hook ok!');
exit;
end;
end
else
begin
result:=WSAEPROVIDERFAILEDINIT;
end;
end
else
begin
result:=WSAEPROVIDERFAILEDINIT;
end;
end;