步骤如下:
1、获取获取设备对象
2、生成过滤设备
3、设备绑定
4、把过滤设备绑定到设备对象上
5、进行过滤处理
6、解除设备绑定
7、删除生成的过滤设备
涉及函数如下:
1、通过设备名获取设备指针
IoGetDeviceObjectPointer
The IoGetDeviceObjectPointer routine returns a pointer to the top object in the named device object's stack and a pointer to the corresponding file object, if the requested access to the objects can be granted.
NTSTATUS
IoGetDeviceObjectPointer(
IN PUNICODE_STRING ObjectName,
IN ACCESS_MASK DesiredAccess,
OUT PFILE_OBJECT *FileObject,
OUT PDEVICE_OBJECT *DeviceObject
);
2、生成设备对象
Creating the Filter Device Object
Call IoCreateDevice to create a filter device object to attach to a volume or file system stack. In the FileSpy sample, this is done as follows:
status = IoCreateDevice(
gFileSpyDriverObject, //
DriverObject
sizeof(FILESPY_DEVICE_EXTENSION), //
DeviceExtensionSize
NULL, //
DeviceName
DeviceObject->DeviceType, //
DeviceType
0, //
DeviceCharacteristics
FALSE, //
Exclusive
&newDeviceObject); //
DeviceObject
3、绑定一个设备到另一个设备上IoAttachDeviceToDeviceStack
The IoAttachDeviceToDeviceStack routine attaches the caller's device object to the highest device object in the chain and returns a pointer to the previously highest device object.
PDEVICE_OBJECT
IoAttachDeviceToDeviceStack(
IN PDEVICE_OBJECT SourceDevice,
IN PDEVICE_OBJECT TargetDevice
);
- Pointer to the caller-created device object. TargetDevice
- Pointer to another driver's device object, such as a pointer returned by a preceding call to IoGetDeviceObjectPointer.
Parameters
SourceDevice4、负责将绑定的设备解除绑
IoDetachDevice
The IoDetachDevice routine releases an attachment between the caller's device object and a lower driver's device object.
VOID
IoDetachDevice(
IN OUT PDEVICE_OBJECT TargetDevice
);
- Pointer to the lower driver's device object. The caller previously called IoAttachDevice or IoAttachDeviceToDeviceStack successfully to get this pointer.
Parameters
TargetDeviceReturn Value
None
- Pointer to the device object to be deleted.
5、删除这个设备对象
IoDeleteDevice
The IoDeleteDevice routine removes a device object from the system, for example, when the underlying device is removed from the system.
VOID
IoDeleteDevice(
IN PDEVICE_OBJECT DeviceObject
);
Parameters
DeviceObjectReturn Value
None
其他函数:
- Pointer to the IRP.
1、获得IRP的当前栈空间指针
IoGetCurrentIrpStackLocation
The IoGetCurrentIrpStackLocation routine returns a pointer to the caller's stack location in the given IRP.
PIO_STACK_LOCATION
IoGetCurrentIrpStackLocation(
IN PIRP Irp
);
Parameters
IrpReturn Value
The routine returns a pointer to the I/O stack location for the driver.