Делаю фильтр-драйвер мыши.
Для доступа из UserMode хочу создать вторую символьную ссылку (девайс).
Ссылка создается (в devicetree появляется), но при попытке CreateFile из UserMode - синий экран.
Как сделать правильно?
Вот мой код.
NTSTATUS DriverEntry ( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath )
{
ULONG i;
UNREFERENCED_PARAMETER (RegistryPath);
DbgPrint(("MouFilter_DriverEntry() called\n"));
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
{
DriverObject->MajorFunction[i] = MouFilter_DispatchPassThrough;
}
DriverObject->MajorFunction [IRP_MJ_CREATE] = MouFilter_CreateClose;
DriverObject->MajorFunction [IRP_MJ_CLOSE] = MouFilter_CreateClose;
DriverObject->MajorFunction [IRP_MJ_PNP] = MouFilter_PnP;
DriverObject->MajorFunction [IRP_MJ_POWER] = MouFilter_Power;
DriverObject->MajorFunction [IRP_MJ_INTERNAL_DEVICE_CONTROL] = MouFilter_InternIoCtl;
DriverObject->DriverUnload = MouFilter_Unload;
DriverObject->DriverExtension->AddDevice = MouFilter_AddDevice;
return STATUS_SUCCESS;
}
NTSTATUS MouFilter_AddDevice( IN PDRIVER_OBJECT Driver, IN PDEVICE_OBJECT PDO )
{
PCWSTR dDeviceName2 = L"\\Device\\hideproc55"; //имя устройсва
PCWSTR dSymbolicLinkName2 = L"\\DosDevices\\hideproc55"; //имя устройсва дос
PDEVICE_EXTENSION devExt2;
PDEVICE_EXTENSION devExt;
IO_ERROR_LOG_PACKET errorLogEntry;
PDEVICE_OBJECT device;
PDEVICE_OBJECT device2;
NTSTATUS status = STATUS_SUCCESS;
NTSTATUS status2 = STATUS_SUCCESS;
PCWSTR dDeviceName = L"\\Device\\hideproc5"; //имя устройсва
PCWSTR dSymbolicLinkName = L"\\DosDevices\\hideproc5"; //имя устройсва дос
RtlInitUnicodeString(&DeviceName, dDeviceName);
RtlInitUnicodeString(&SymbolicLinkName, dSymbolicLinkName);
PAGED_CODE();
DbgPrint(("MouFilter_AddDevice() called\n"));
status = IoCreateDevice(Driver,
sizeof(DEVICE_EXTENSION),
&DeviceName,
FILE_DEVICE_MOUSE,
0,
FALSE,
&device
);
if (!NT_SUCCESS(status)) {
return (status);
}
RtlZeroMemory(device->DeviceExtension, sizeof(DEVICE_EXTENSION));
IoCreateSymbolicLink(&SymbolicLinkName, &DeviceName);
devExt = (PDEVICE_EXTENSION) device->DeviceExtension;
devExt->TopOfStack = IoAttachDeviceToDeviceStack(device, PDO);
ASSERT(devExt->TopOfStack);
devExt->Self = device;
devExt->PDO = PDO;
devExt->DeviceState = PowerDeviceD0;
devExt->SurpriseRemoved = FALSE;
devExt->Removed = FALSE;
devExt->Started = FALSE;
//DO_BUFFERED_IO
device->Flags |= (DO_BUFFERED_IO | DO_POWER_PAGABLE);
device->Flags &= ~DO_DEVICE_INITIALIZING;
///////////////////////////////////////////////////////////////
RtlInitUnicodeString(&DeviceName2, dDeviceName2);
RtlInitUnicodeString(&SymbolicLinkName2, dSymbolicLinkName2);
status2 = IoCreateDevice( device->DriverObject,
sizeof(DEVICE_EXTENSION2),
&DeviceName2,
FILE_DEVICE_MOUSE,
0,
FALSE,
&device2
);
if (!NT_SUCCESS(status2))
{
DbgPrint(("Device2 init failure!\n"));
return (status2);
}
else
{
DbgPrint(("Device2 init Ok!\n"));
};
RtlZeroMemory(device2->DeviceExtension, sizeof(DEVICE_EXTENSION2));
devExt2 = (PDEVICE_EXTENSION) device2->DeviceExtension;
devExt2->Self = device2;
devExt2->PDO = PDO;
devExt2->DeviceState = PowerDeviceD0;
devExt2->SurpriseRemoved = FALSE;
devExt2->Removed = FALSE;
devExt2->Started = FALSE;
device2->Flags |= (DO_BUFFERED_IO | DO_POWER_PAGABLE);
device2->Flags &= ~DO_DEVICE_INITIALIZING;
IoCreateSymbolicLink(&SymbolicLinkName2, &DeviceName2);
///////////////////////////////////////////////////////////////
return status;
}