求教:各位spi防火墙高手请入 (200分)

  • 主题发起人 主题发起人 lussy
  • 开始时间 开始时间
L

lussy

Unregistered / Unconfirmed
GUEST, unregistred user!
本人最近在写一个spi的过滤程序,出于对delphi的喜爱,我试着用delphi来实现,wspstartup已经转化成功,目前在转化wsprecv时遇到了一些问题,请各位大虾救命!


以下是部分的源程序,请各位指教,万分感谢!!!
procedure COMPLETION_ROUTINE(dwError:dword;cbTransferred:dword;lpOverlapped:PWSAOVERLAPPED;dwFlags:dword);stdcall;
begin
end;


function WSPRECV(s:Tsocket;var lpBuffers:Twsabuf;dwBufferCount:dword;var lpNumberOfBytesRecvd:dword;var lpFlags:dword;lpOverlapped:PWSAOVERLAPPED;lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE;lpThreadId:PWSATHREADID;var lpErrno:integer):integer;pascal;
begin
issetcompletionroutine:=false;
if assigned(lpOverlapped) then
begin
if assigned(lpCompletionRoutine) then
begin
issetcompletionroutine:=true;
lpCompletionRoutine:=COMPLETION_ROUTINE; //该行代码加
//上后回调函数出错,哪位知道错在什么地方?

end;
end;
iret:=TWSPRECV(NextProcTable.LPWSPRecv)(s,lpBuffers,dwBufferCount,lpNumberOfBytesRecvd,lpFlags,lpOverlapped,lpCompletionRoutine,lpThreadId,lpErrno);
if (iret=socket_error) or (issetcompletionroutine=true) then
begin
result:=iret;
exit;
end;
result:=iret;
end;
 
分绝对不是问题,不够可以再加哟!!!
 
可以给偶一份完整源码吗?最好是转化前和转化后的两份。
偶可以给你开张300分的贴子。
分绝对不是问题,不够可以再加哟!!!
 
转化前的程序就是费尔防火墙的部分代码,我是把ws2spi.h中的结构和函数转换成了pascal的声明
library myfiltertest;
uses
SysUtils,
Classes,
windows,
registry,
Dialogs,
idwinsock,
ws2spi in 'ws2spi.pas';

const
REG_INSTALL_KEY='SYSTEM/CurrentControlSet/Services/WinSock2/Xstudio_Min_Winsock_Spi';

{$R *.res}
var
NextProcTable:TWSPPROC_TABLE;

procedure GetRightEntryIdItem(pProtocolInfo:PWSAPROTOCOL_INFOW;var sItem:pchar);
begin
if pProtocolInfo.ProtocolChain.ChainLen<=1 then
begin
sitem:=pchar(format('%u',[pProtocolInfo^.dwCatalogEntryId]));
end
else
begin
sItem:=pchar(format('%u', [pProtocolInfo^.ProtocolChain.ChainEntries[pProtocolInfo^.ProtocolChain.ChainLen - 1]]));
end;
end;

function GetHookProvider(pProtocolInfo:PWSAPROTOCOL_INFOW;var sPathName:pwchar):bool;pascal;
var sItem:pchar;
hSubkey:hkey;
ulDateLenth:dword;
stemp:pwchar;
Reg: TRegistry;
f:textfile;
begin
result:=false;
GetRightEntryIdItem(pProtocolInfo,sItem);
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey(REG_INSTALL_KEY,false) then
begin
sPathName:=pwchar(reg.ReadString(sItem));
Reg.CloseKey;
result:=true;
end;
finally
Reg.Free;
end;
end;
procedure COMPLETION_ROUTINE(dwError:dword;cbTransferred:dword;lpOverlapped:PWSAOVERLAPPED;dwFlags:dword);stdcall;
var f:textfile;
begin
messagebeep(0);
assignfile(f,'c:/wspcompletionroutinelog.txt');
append(f);
writeln(f,'completionroutine start');
close(f);
end;


function WSPRECV(s:Tsocket;var lpBuffers:Twsabuf;dwBufferCount:dword;var lpNumberOfBytesRecvd:dword;var lpFlags:dword;lpOverlapped:PWSAOVERLAPPED;lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE;lpThreadId:PWSATHREADID;var lpErrno:integer):integer;pascal;
var proto,sourceIP,destIP,SPort,DPort: string;
header:pchar;
header_size:integer;
data:pchar;
datasize:integer;
f:textfile;
buf:array[0..max_pack_len] of char;
iBufSize:integer;
issetcompletionroutine:bool;
iret:integer;
begin
assignfile(f,'c:/wsprecvlog.txt');
append(f);
issetcompletionroutine:=false;
if assigned(lpOverlapped) then
begin
if assigned(lpCompletionRoutine) then
begin
issetcompletionroutine:=true;
lastCompletionRoutine:=lpCompletionRoutine;
lpCompletionRoutine:=COMPLETION_ROUTINE;
writeln(f,'issetcompletionroutine=true');
writeln(f,'lpFlags='+inttostr(lpFlags));
end;
end;
close(f);


iret:=TWSPRECV(NextProcTable.LPWSPRecv)(s,lpBuffers,dwBufferCount,lpNumberOfBytesRecvd,lpFlags,lpOverlapped,lpCompletionRoutine,lpThreadId,lpErrno);
if (iret=socket_error) or (issetcompletionroutine=true) then
begin
result:=iret;
exit;
end;
result:=iret; {

end;

function WSPStartup(wversionrequested:word;var lpwspdata:Twsadata;lpprotocolinfo:PWSAPROTOCOL_INFOW;upcalltable:TWSPUPCALLTABLE;var lpproctable:TWSPPROC_TABLE):integer;stdcall;
var sLibraryPath:pchar;
WSPStartupFunc:TWSPSTARTUP;
hLibraryHandle:HMODULE;
ErrorCode:integer;
f:textfile;
lpaddress:Tsockaddr;
lpaddresslength,lperrno:integer;
begin
result:=WSAEPROVIDERFAILEDINIT;
//messagebeep(0);
assignfile(f,'c:/wspstartuplog.txt');
append(f);
try
writeln(f,'wspstartup');

if GetHookProvider(lpProtocolInfo, pwchar(sLibraryPath)) then
begin
//messagebeep(0);
writeln(f,'sLibraryPath='+sLibraryPath);
sLibraryPath:='C:/winnt/system32/msafd.dll';
hLibraryHandle:=loadlibrary(sLibraryPath);
writeln(f,'hlibraryhandle='+inttostr(hLibraryHandle));
if hLibraryHandle<>0 then
begin
@WSPStartupFunc:=GetProcAddress(hLibraryHandle,'WSPStartup');
writeln(f,'error='+inttostr(getlasterror));
if @WSPStartupFunc<> nil then
begin
writeln(f,'@WSPStartupFunc<>nil');
ErrorCode := TWSPSTARTUP(WSPStartupFunc)(wVersionRequested,lpWSPData,lpProtocolInfo,upcallTable,lpProcTable);

writeln(f,'ErrorCode='+inttostr(ErrorCode));
if ErrorCode=ERROR_SUCCESS then
begin
NextProcTable := lpProcTable;
lpProcTable.LPWSPRecv:=WSPRECV;
result:=0;
end
else
begin
result:=ErrorCode;
end;

end;

end;

end;
writeln(f,'wspreturnvalue='+inttostr(result));
except
on e:exception do
begin
writeln(f,e.Message);
closefile(f);
end;
end;
closefile(f);

end;

exports
wspstartup name 'WSPStartup';

begin

end.
 
晕,不会就这么少吧?偶真亏呀~~~~~~~~~~`
费尔防火墙的源码偶也有哇
 
只是最基本的功能,dll程序只有这么多
 
费尔防火墙的源码的源码是公开的么?
能否给我一份呀,ego兄
 
to coolbaby:
给你没问题,请留下你的邮箱。
 
后退
顶部