阅读:2452回复:2
tcp filter再请教
那片<请教tcp filter中的一个错误>就是我发的,错误的症状就是:
当启动那个服务之后,使用telnet,http等都正确截获,但是唯独查找计算机的时候, 就会出现错误,错误提示是NO_MORE_IRP_STACK_LOCATION,我知道这是STACKSIZE的问题, 但是我实在不清楚,我的程序为什么会出现这样的错误,现在把源马铁出来,请高手指教. 代码很短,错误应该出在执行DISPATCH.C中的NFDispatchPassThrough的时候, 但是深层原因就不知道了. 请高手看一下,如果知道答案,恳请不吝赐教 //nfinit.c #include <ntddk.h> #include "tdi.h" #include "NFilter.h" NTSTATUS DriverEntry( IN PDRIVER_OBJECT NFDriverObject, IN PUNICODE_STRING RegistryPath ) { //define var PDEVICE_OBJECT NetDevice; UNICODE_STRING NetDeviceName; PDRIVER_OBJECT NetDriver; PDRIVER_DISPATCH EmptyDispatchValue; PDEVICE_OBJECT TargetDevice; PDEVICE_EXTENSION NFExtension; PDEVICE_OBJECT NFDevice; PFILE_OBJECT FileObject; NTSTATUS status; ULONG i; EmptyDispatchValue=NFDriverObject->MajorFunction[IRP_MJ_CREATE];//得到空槽的值 NFDriverObject->DriverUnload=NFDriverUnload; NFDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=NFDispatchDeviceIoControl;//这是我们要截获的 //get target device pointer RtlInitUnicodeString( &NetDeviceName, L"\\Device\\Tcp"); status=IoGetDeviceObjectPointer(//得到底层设备的指针 &NetDeviceName, FILE_ALL_ACCESS, &FileObject, &NetDevice); if(!NT_SUCCESS(status)) { return status; } //create filter device status=IoCreateDevice( NFDriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &NFDevice ); if(!NT_SUCCESS(status)) { return status; } //attach target device with filter device TargetDevice=IoAttachDeviceToDeviceStack( NFDevice, NetDevice); if(!TargetDevice) { IoDeleteDevice(NFDevice); return STATUS_SUCCESS; } //make filter device get target device's all character NFExtension=(PDEVICE_EXTENSION)NFDevice->DeviceExtension; NFExtension->DeviceObject=NFDevice; NFExtension->TargetDevice=TargetDevice; NFDevice->DeviceType=TargetDevice->DeviceType; NFDevice->Characteristics=TargetDevice->Characteristics; NFDevice->Flags|=(TargetDevice->Flags&(DO_DIRECT_IO|DO_BUFFERED_IO)); NetDriver=TargetDevice->DriverObject; for(i=0;i<IRP_MJ_MAXIMUM_FUNCTION;i++) { if((NetDriver->MajorFunction!=EmptyDispatchValue)&&(NFDriverObject->MajorFunction==EmptyDispatchValue)) { NFDriverObject->MajorFunction=NFDispatchPassThrough; } } ObDereferenceObject(FileObject); return STATUS_SUCCESS; } NTSTATUS NFDriverUnload(PDRIVER_OBJECT NFDriver) { PDEVICE_OBJECT NFDevice; PDEVICE_OBJECT NetDevice; PDEVICE_EXTENSION NFExtension; NTSTATUS status; NFDevice=NFDriver->DeviceObject; NFExtension=(PDEVICE_EXTENSION)NFDevice->DeviceExtension; NetDevice=NFExtension->TargetDevice; IoDetachDevice(NetDevice); IoDeleteDevice(NFDevice); return STATUS_SUCCESS; } //dispatch.c #include <ntddk.h> #include "tdi.h" #include "NFilter.h" NTSTATUS NFDispatchDeviceIoControl( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { PIO_STACK_LOCATION IrpStack=IoGetCurrentIrpStackLocation(Irp); Irp->IoStatus.Status=STATUS_SUCCESS; IoCompleteRequest(Irp,IO_NO_INCREMENT); return STATUS_SUCCESS; } NTSTATUS NFDispatchPassThrough( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { NTSTATUS status; PDEVICE_EXTENSION NFExtension=(PDEVICE_EXTENSION)DeviceObject->DeviceExtension; PIO_STACK_LOCATION IrpStack=IoGetCurrentIrpStackLocation(Irp); PIO_STACK_LOCATION NextIrpStack=IoGetNextIrpStackLocation(Irp); *NextIrpStack=*IrpStack; IoSetCompletionRoutine( Irp, NFGenericCompletion, NULL, TRUE,TRUE,TRUE); return IoCallDriver( NFExtension->TargetDevice, Irp); } NTSTATUS NFGenericCompletion( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context ) { if(Irp->PendingReturned) { IoMarkIrpPending(Irp); } return STATUS_SUCCESS; } |
|
最新喜欢:linwn
|
沙发#
发布于:2001-06-29 21:59
这部分代码是从哪来的?
|
|
|
板凳#
发布于:2003-09-16 01:44
好像Windows的一个Bug,看一下VTrace的说明就知道了。
需要构造一个新的IRP来发送请求。 |
|