内核安全编程(一)读写驱动程序1.1
读写驱动程序,即应用程序或者上层驱动程序发送主功能码为IRP_MJ_READ和IRP_MJ_WRITE的IO请求包(IRP)
DriverEntry函数如下:
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
UNICODE_STRING DeviceName,Win32Device;
PDEVICE_OBJECT DeviceObject = NULL;
NTSTATUS status;
unsigned i;
KdPrint(("[DriverEntry]\n"));
RtlInitUnicodeString(&DeviceName,L"\\Device\\Driver_write0");
RtlInitUnicodeString(&Win32Device,L"\\DosDevices\\Driver_write0");
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
DriverObject->MajorFunction[i] = Driver_writeDefaultHandler;
DriverObject->MajorFunction[IRP_MJ_CREATE] = Driver_writeCreateClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = Driver_writeCreateClose;
DriverObject->MajorFunction[IRP_MJ_READ]=Driver_ReadWrite;
DriverObject->MajorFunction[IRP_MJ_WRITE]=Driver_ReadWrite;
//DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=Driver_DevControl;
DriverObject->DriverUnload = Driver_writeUnload;
status = IoCreateDevice(DriverObject,
10