我在用WSCInstallProvider的时候,发现指定的dll好像从来不能载入
格式为
WSCInstallProvider(&filterguid,filter_path,&iplayerinfo,1,&errorcode)
即使把dll路径改成莫须有的路径,也能执行成功,但是结果显然不对
另外
在安装完自己的服务提供者之后
好像dns不能解析了
比如上网只能用ip了
把自己的服务提供者卸掉,又行了
大家遇到过的话,请指点一下。
谢谢
格式为
WSCInstallProvider(&filterguid,filter_path,&iplayerinfo,1,&errorcode)
即使把dll路径改成莫须有的路径,也能执行成功,但是结果显然不对
另外
在安装完自己的服务提供者之后
好像dns不能解析了
比如上网只能用ip了
把自己的服务提供者卸掉,又行了
大家遇到过的话,请指点一下。
谢谢
DLL里
#define UNICODE
#define _UNICODE#include <ws2spi.h>
#include <tchar.h>
#include <stdio.h>
GUID filterguid={0x4d1e91fd,0x116a,0x44aa,{0x8f,0xd4,0x1d,0x2c,0xf2,0x7b,0xd9,0xa9}};LPWSAPROTOCOL_INFOW protoinfo=NULL;
WSPPROC_TABLE nextproctable;
DWORD protoinfosize=0;
int totalprotos=0;BOOL getfilter()
{
int errorcode; protoinfo=NULL;
protoinfosize=0;
totalprotos=0; if(WSCEnumProtocols(NULL,protoinfo,&protoinfosize,&errorcode)==SOCKET_ERROR)
{
if(errorcode!=WSAENOBUFS)
{
OutputDebugString(_T("First WSCEnumProtocols Error!"));
return FALSE;
}
} if((protoinfo=(LPWSAPROTOCOL_INFOW)GlobalAlloc(GPTR,protoinfosize))==NULL)
{
OutputDebugString(_T("GlobalAlloc Error!"));
return FALSE;
} if((totalprotos=WSCEnumProtocols(NULL,protoinfo,&protoinfosize,&errorcode))==SOCKET_ERROR)
{
OutputDebugString(_T("Second WSCEnumProtocols Error!"));
return FALSE;
} return TRUE;
}void freefilter()
{
GlobalFree(protoinfo);
}BOOL WINAPI DllMain(HINSTANCE hmodule,
DWORD reason,
LPVOID lpreserved)
{
TCHAR processname[MAX_PATH];
TCHAR showmessage[MAX_PATH+25];
if(reason==DLL_PROCESS_ATTACH)
{
GetModuleFileName(NULL,processname,MAX_PATH);
_tcscpy(showmessage,processname);
_tcscat(showmessage,_T(" Loading IPFilter ..."));
OutputDebugString(showmessage);
}
return TRUE;
}/*int WSPAPI WSPSendTo(SOCKET s,
LPWSABUF lpbuffer,
DWORD dwbuffercount,
LPDWORD lpnumberofbytessent,
DWORD dwflags,
const struct sockaddr FAR *lpto,
int itolen,
LPWSAOVERLAPPED lpoverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpcompletionroutine,
LPWSATHREADID lpthreadid,
LPINT lperrno)
{ struct sockaddr_in sin; sin=*(const struct sockaddr_in *)lpto;
if(sin.sin_port==htons(8000))
{
OutputDebugString(_T("WSPSendTo Tencent Filtered"));
return 0;
//return nextproctable.lpWSPSendTo(s,lpbuffer,dwbuffercount,
// lpnumberofbytessent,dwflags,lpto,itolen,
// lpoverlapped,lpcompletionroutine,lpthreadid,lperrno);
}
else
{
//return 0;
return nextproctable.lpWSPSendTo(s,lpbuffer,dwbuffercount,
lpnumberofbytessent,dwflags,lpto,itolen,
lpoverlapped,lpcompletionroutine,lpthreadid,lperrno);
}
}*/int WSPAPI WSPRecvFrom (
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd,
LPDWORD lpFlags,
struct sockaddr FAR * lpFrom,
LPINT lpFromlen,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
LPWSATHREADID lpThreadId,
LPINT lpErrno
)
{
struct sockaddr_in sin; sin=*(const struct sockaddr_in *)lpFrom;
if(sin.sin_port==htons(8888))
{
OutputDebugString(_T("WSPSendTo Tencent Filtered"));
// return 0;
return nextproctable.lpWSPRecvFrom(s,lpBuffers,dwBufferCount,
lpNumberOfBytesRecvd,lpFlags,lpFrom,lpFromlen,
lpOverlapped,lpCompletionRoutine,lpThreadId,lpErrno);
//return nextproctable.lpWSPSendTo(s,lpbuffer,dwbuffercount,
// lpnumberofbytessent,dwflags,lpto,itolen,
// lpoverlapped,lpcompletionroutine,lpthreadid,lperrno);
}
else
{
//return 0;
return nextproctable.lpWSPRecvFrom(s,lpBuffers,dwBufferCount,
lpNumberOfBytesRecvd,lpFlags,lpFrom,lpFromlen,
lpOverlapped,lpCompletionRoutine,lpThreadId,lpErrno);
}
}int WSPAPI WSPStartup(
WORD wversionrequested,
LPWSPDATA lpwspdata,
LPWSAPROTOCOL_INFOW lpprotoinfo,
WSPUPCALLTABLE upcalltable,
LPWSPPROC_TABLE lpproctable
)
{
OutputDebugString(_T("IPFilter WSPStartup ...")); int i;
int errorcode;
int filterpathlen;
DWORD layerid=0;
DWORD nextlayerid=0;
TCHAR *filterpath;
HINSTANCE hfilter;
LPWSPSTARTUP wspstartupfunc=NULL;
if(lpprotoinfo->ProtocolChain.ChainLen<=1)
{
OutputDebugString(_T("ChainLen<=1"));
return FALSE;
} getfilter(); for(i=0;i<totalprotos;i++)
{
if(memcmp(&protoinfo[i].ProviderId,&filterguid,sizeof(GUID))==0)
{
layerid=protoinfo[i].dwCatalogEntryId;
break;
}
} for(i=0;i<lpprotoinfo->ProtocolChain.ChainLen;i++)
{
if(lpprotoinfo->ProtocolChain.ChainEntries[i]==layerid)
{
nextlayerid=lpprotoinfo->ProtocolChain.ChainEntries[i+1];
break;
}
} filterpathlen=MAX_PATH;
filterpath=(TCHAR*)GlobalAlloc(GPTR,filterpathlen);
for(i=0;i<totalprotos;i++)
{
if(nextlayerid==protoinfo[i].dwCatalogEntryId)
{
if(WSCGetProviderPath(&protoinfo[i].ProviderId,filterpath,&filterpathlen,&errorcode)==SOCKET_ERROR)
{
OutputDebugString(_T("WSCGetProviderPath Error!"));
return WSAEPROVIDERFAILEDINIT;
}
break;
}
} if(!ExpandEnvironmentStrings(filterpath,filterpath,MAX_PATH))
{
OutputDebugString(_T("ExpandEnvironmentStrings Error!"));
return WSAEPROVIDERFAILEDINIT;
} if((hfilter=LoadLibrary(filterpath))==NULL)
{
OutputDebugString(_T("LoadLibrary Error!"));
return WSAEPROVIDERFAILEDINIT;
} if((wspstartupfunc=(LPWSPSTARTUP)GetProcAddress(hfilter,"WSPStartup"))==NULL)
{
OutputDebugString(_T("GetProcessAddress Error!"));
return WSAEPROVIDERFAILEDINIT;
} if((errorcode=wspstartupfunc(wversionrequested,lpwspdata,lpprotoinfo,upcalltable,lpproctable))!=ERROR_SUCCESS)
{
OutputDebugString(_T("wspstartupfunc Error!"));
return errorcode;
} nextproctable=*lpproctable;
//lpproctable->lpWSPSendTo=WSPSendTo;
lpproctable->lpWSPRecvFrom=WSPRecvFrom;
freefilter();
return 0;
}
#define UNICODE
#define _UNICODE #include <stdio.h>
#include <tchar.h>
#include <string.h>
#include <ws2spi.h>
#include <sporder.h>
GUID filterguid={0x4d1e91fd,0x116a,0x44aa,{0x8f,0xd4,0x1d,0x2c,0xf2,0x7b,0xd9,0xa9}};GUID filterchainguid={0xd3c21121,0x85e1,0x48f3,{0x9a,0xb6,0x23,0xd9,0x0c,0x73,0x07,0xef}};BOOL getfilter();
void freefilter();
void installfilter();
void removefilter();
void start();
void usage();int totalprotos=0;
DWORD protoinfosize=0;
LPWSAPROTOCOL_INFOW protoinfo=NULL;
int main(int argc,char *argv[])
{
start(); if(argc==2)
{
if(strcmp(argv[1],"-install")==0)
{
installfilter();
return 0;
}
else if(strcmp(argv[1],"-remove")==0)
{
removefilter();
return 0;
}
}
usage();
return 0;
}BOOL getfilter()
{
int errorcode; protoinfo=NULL;
totalprotos=0;
protoinfosize=0; if(WSCEnumProtocols(NULL,protoinfo,&protoinfosize,&errorcode)==SOCKET_ERROR)
{
if(errorcode!=WSAENOBUFS)
{
_tprintf(_T("First WSCEnumProtocols Error: %d\n"),errorcode);
return FALSE;
}
} if((protoinfo=(LPWSAPROTOCOL_INFOW)GlobalAlloc(GPTR,protoinfosize))==NULL)
{
_tprintf(_T("GlobalAlloc in getfilter Error: %d\n"),GetLastError());
return FALSE;
} if((totalprotos=WSCEnumProtocols(NULL,protoinfo,&protoinfosize,&errorcode))==SOCKET_ERROR)
{
_tprintf(_T("Second WSCEnumProtocols Error: %d\n"),GetLastError());
return FALSE;
} _tprintf(_T("Found %d protocols!\n"),totalprotos);
return TRUE;
}void freefilter()
{
GlobalFree(protoinfo);
}void installfilter()
{
int i;
int provcnt;
int cataindex;
int errorcode;
BOOL rawip=FALSE;
BOOL udpip=FALSE;
DWORD iplayercataid=0,udporigcataid=0;
TCHAR filter_path[MAX_PATH];
TCHAR filter_name[MAX_PATH];
TCHAR chainname[WSAPROTOCOL_LEN+1];
LPDWORD cataentries;
WSAPROTOCOL_INFOW iplayerinfo,udpchaininfo,chainarray[1]; getfilter();
for(i=0;i<totalprotos;i++)
{
if(!rawip
&& protoinfo[i].iAddressFamily==AF_INET
&& protoinfo[i].iProtocol==IPPROTO_IP)
{
rawip=TRUE;
memcpy(&iplayerinfo,&protoinfo[i],sizeof(WSAPROTOCOL_INFOW));
iplayerinfo.dwServiceFlags1=protoinfo[i].dwServiceFlags1 & (~XP1_IFS_HANDLES);
} if(!udpip
&& protoinfo[i].iAddressFamily==AF_INET
&& protoinfo[i].iProtocol==IPPROTO_UDP)
{
udpip=TRUE;
udporigcataid=protoinfo[i].dwCatalogEntryId;
memcpy(&udpchaininfo,&protoinfo[i],sizeof(WSAPROTOCOL_INFOW));
udpchaininfo.dwServiceFlags1=protoinfo[i].dwServiceFlags1 & (~XP1_IFS_HANDLES);
}
} _tcscpy(iplayerinfo.szProtocol,_T("T-IpFilter"));
iplayerinfo.ProtocolChain.ChainLen=LAYERED_PROTOCOL; if(GetCurrentDirectory(MAX_PATH,filter_path)==0)
{
_tprintf(_T("GetCurrentDirectory Error: %d\n"),GetLastError());
return ;
}
_tcscpy(filter_name,_T("\\ce1.dll"));
_tcscat(filter_path,filter_name);
if(WSCInstallProvider(&filterguid,/*filter_path*/_T("ce1.dll"),&iplayerinfo,1,&errorcode)==SOCKET_ERROR)
{
_tprintf(_T("WSCInstallProvider Error: %d\n"),errorcode);
return ;
} freefilter(); getfilter(); for(i=0;i<totalprotos;i++)
{
if(memcmp(&protoinfo[i].ProviderId,&filterguid,sizeof(GUID))==0)
{
iplayercataid=protoinfo[i].dwCatalogEntryId;
break;
}
} provcnt=0;
if(udpip)
{
_tcscpy(chainname,_T("T-UdpFilter"));
_tcscpy(udpchaininfo.szProtocol,chainname); if(udpchaininfo.ProtocolChain.ChainLen==BASE_PROTOCOL)
{
udpchaininfo.ProtocolChain.ChainEntries[1]=udporigcataid;
}
else
{
for(i=udpchaininfo.ProtocolChain.ChainLen;i>0;i--)
{
udpchaininfo.ProtocolChain.ChainEntries[i+1]=udpchaininfo.ProtocolChain.ChainEntries[i];
}
} udpchaininfo.ProtocolChain.ChainLen++;
udpchaininfo.ProtocolChain.ChainEntries[0]=iplayercataid; memcpy(&chainarray[provcnt++],&udpchaininfo,sizeof(WSAPROTOCOL_INFOW));
} if(WSCInstallProvider(&filterchainguid,/*filter_path*/_T("ce1.dll"),chainarray,provcnt,&errorcode)==SOCKET_ERROR)
{
_tprintf(_T("WSCInstallProvider for chain Error: %d\n"),errorcode);
return ;
} freefilter(); getfilter(); if((cataentries=(LPDWORD)GlobalAlloc(GPTR,totalprotos*sizeof(WSAPROTOCOL_INFOW)))==NULL)
{
_tprintf(_T("GlobalAlloc int installfilter Error: %d\n"),errorcode);
return ;
} cataindex=0;
for(i=0;i<totalprotos;i++)
{
if(memcmp(&protoinfo[i].ProviderId,&filterguid,sizeof(GUID))==0
|| memcmp(&protoinfo[i].ProviderId,&filterchainguid,sizeof(GUID))==0)
{
cataentries[cataindex++]=protoinfo[i].dwCatalogEntryId;
}
} for(i=0;i<totalprotos;i++)
{
if(memcmp(&protoinfo[i].ProviderId,&filterguid,sizeof(GUID))!=0
&& memcmp(&protoinfo[i].ProviderId,&filterchainguid,sizeof(GUID))!=0)
{
cataentries[cataindex++]=protoinfo[i].dwCatalogEntryId;
}
} if((errorcode==WSCWriteProviderOrder(cataentries,totalprotos))!=ERROR_SUCCESS)
{
_tprintf(_T("WSCWriteProviderOrder Error: %d\n"),GetLastError());
return ;
} freefilter(); _tprintf(_T("\nInstall IP Filter Successfully"));
return ;
}void removefilter()
{
int errorcode;
BOOL signal=TRUE; if(WSCDeinstallProvider(&filterguid,&errorcode)==SOCKET_ERROR)
{
_tprintf(_T("WSCDeinstall filterguid Error: %d\n"),errorcode);
signal=FALSE;
} if(WSCDeinstallProvider(&filterchainguid,&errorcode)==SOCKET_ERROR)
{
_tprintf(_T("WSCDeinstall filterchainguid Error: %d\n"),errorcode);
signal=FALSE;
} if(signal)
{
_tprintf(_T("Deinstall IP Filter Successfully"));
}
return ;
}void start()
{
//_tprintf(_T("Install IP Filter, by TOo2y\n"));
//_tprintf(_T("E-Mail: [email protected]\n"));
//_tprintf(_T("HomePage: www.safechina.net\n"));
//_tprintf(_T("Date: 10-29-2002\n\n"));
return ;
}void usage()
{
_tprintf(_T("Usage: instif [ -install │ -remove ]\n"));
return ;
}