hello,
i am a newer for driver design,now i want to design a tcp filter,
i do it step by step,first,i intercept all network irp and don’t
do anything else on them.
when i used telnet or http,it work properly,but when i lookup computer
through netneighbor ,the system crash,it showed"NO_MORE_STACK_LOCATION,but i check my source code,i can’t find
the reason .can u tell me?
thanks a lot.
below is my source code.
#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 {
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
#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;
}
_____________________________________________
»¯×±Æ·ÈÈÂô£¬ÊçŮҲ·è¿ñ http://shopping.263.net/category04.htm
¾«Æ·MP3¡¢ËæÉíÌý£¬¼Û¸ñÕ𺳠http://shopping.263.net/fs/81shop/
—
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</ntddk.h>