⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filteritem.h

📁 利用C++工具进行编程,NDIS的PASSTHRU层的驱动程序,是非常实用的程序.
💻 H
字号:
#ifndef _FilterItem_H_
#define _FilterItem_H_

/****************Some Defination*********************/

//Filter Item.
typedef struct tagFilterItem
{
	struct tagFilterItem	*pPre;
	struct tagFilterItem	*pNext;
		
	int					iItemBufferLen;//length of item 's buffer.
	FilterType			FilterType;//type of item.
	
	//U8					pItemBuffer[];
	U8			*pItemBuffer;//item's data buffer.
								//Only to match item will smart.

}FilterItem;



//Special Code.
//You should get the special code from any packet to check.
typedef struct tagSpecialCode{
//	PhycicalAddress PhyAdd,//Phycical address.
//	U16				EthProto,//Ethernet 's protocol.
	
	IpAddress		SrcIpAdd;//Ip Address.
	IpAddress		DestIpAdd;

	U8				IpProto;//Ip's protocol.
}SpecialCode;


//Allocate the Special code Arg buffer 's max size.
#define SpecialCodeAndArgBufSize	( 80 )


/****Filter function 's arg.****/

//Tcp parameter(Called by filter function's arg).
typedef struct tagTcpArg{
	U16			SrcPort;	
	U16			DestPort;

}TcpArg;

//Icmp parameter(Called by filter function's arg).
typedef struct tagIcmpArg{
	U8			type;
	U8			code;

}IcmpArg;


//passthru's filter item control struture.
typedef struct tagFilterItemCtl
{
	FilterItem SendIncludeQueue;	//Send Filter Include queue.
	FilterItem SendExcludeQueue;	//Send Filter Exclude queue.

	FilterItem RecIncludeQueue;		//Receive Filter Include queue.
	FilterItem RecExcludeQueue;		//Receive Filter Exclude queue.
	
}FilterItemCtl;


/*A Entire Filter Item.
|------------|------------------|-------------|---------------|-------|
| FilterType |  iItemBufferLen  | pItemBuffer | FilterContext | Param |
|------------|------------------|-------------|---------------|-------|
|        FilterItem                           |
|---------------------------------------------|
*/
//Get the special data from raw buffer.

#define GetFilterItem(pInputBuf)		\
	( (FilterItem *)( (U8*)(pInputBuf) )

#define GetFilterContext(pInputBuf)		\
	( (FilterContext *)( (U8*)(pInputBuf) + sizeof(FilterItem) ) )
		
#define GetFilterParamFromFilterItem(pInputBuf)	\
	( (U8*)(pInputBuf) + sizeof(FilterItem) + sizeof(FilterContext) )

#define GetFilterParamFromFilterContext(pInputBuf)		\
	( (U8*)(pInputBuf) + sizeof(FilterContext) )

/*Special code
|-------------|---------|
| SpecialCode | FuncArg |
|-------------|---------|
*/
//Get the special data from raw buffer.

#define GetSpecialStru(pInputBuf)					\
	( (SpecialCode *)( (U8*)(pInputBuf) )

#define GetSpecialArg(pInputBuf)				\
	( (U8*)(pInputBuf) + sizeof(SpecialCode) ) 


//Get the special data from raw buffer(Ip Packet).
#define GetIpContextFromIpPacket(pInputBuf)										\
	( (U8*)(pInputBuf) +											\
			(( (U32)( ( (PIpPacketHeader)(pInputBuf) )->headerLength) )<<2) )

#define GetIpHeaderFromEtherHeader(pInputBuf)						\
	( (PIpPacketHeader) ((U8*)(pInputBuf) + 14 ) )

/****************Variable Declaration*******************/
extern int iFilterFlag;//The Filter flag indicate whether has IP to filter.
extern KSPIN_LOCK FilterLock;
extern KIRQL FilterIrql;

extern KSPIN_LOCK FilterItemLock;//The Filter Entry's Spin Lock.
extern KIRQL FilterItemIrql;

extern FilterItemCtl pFilterEntry;//The Entry Filter Item.

/***************Function Declaration***********************/

//The Filter module's Init.
//If success,return Zero;
//else return NoZero.
int InitFilterItem(void);

void FreeFilterItem(void);//The Filter module's Free.

//Add a Filter Item.
void AddFilterItem(
		U32			  uInputBufferLength,
		FilterType	  uInputFilterType,
		PVOID		  pInputBuffer
		);

//Delete a Filter Item.
void DeleteFilterItem(
		U32			  uInputBufferLength,
		FilterType	  uInputFilterType,
		PVOID		  pInputBuffer
		);

//Judge whether the input data included in the item entry.
//If Include,Mark the copy Flag ,return NoZero;
//Else return Zero.
int JudgeEntryInclude(
		SpecialCode		*pInputSpecialCode,
		FilterItem		*pInputItemEntry,
		int				*pOutputCopyFlag
	);

////////////////////////////////

//You can call this function to get special code.
//And Check the special code in filter.
//If success ,return 0;
//else return NoZero.
int GetSpecialCodeFromPacket(
			PNDIS_PACKET	pInputPacket,
			SpecialCode		*pOutputSpecialCode
		);



//You can call this function to get special code.
//		(Now Only Get the Ip's Address, protocol And port,
//				So the HeaderBuffer no used.)
//And Check the special code in filter.
//If success ,return 0;
//else return NoZero.
int GetSpecialCodeFromBuffer(
		IN  PVOID				HeaderBuffer,
		IN  UINT				HeaderBufferSize,
		IN  PVOID				LookAheadBuffer,
		IN  UINT				LookAheadBufferSize,
		SpecialCode				*pOutputSpecialCode
	);


#endif//_FilterItem_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -