附上驱动创建设备的源码
NTSTATUS CreateDevice(PDRIVER_OBJECT pDriver)
{
NTSTATUS status = STATUS_SUCCESS;
UNICODE_STRING strLinkName;
PDEVICE_OBJECT pDevice = NULL;
PDEVICE_EXTENSION pDeviceExtension = NULL;
UNICODE_STRING strDeviceName;
RtlInitUnicodeString(&strDeviceName, L"\\Device\\FileToolDevice");
status = IoCreateDevice(pDriver,
sizeof(DEVICE_EXTENSION),
&strDeviceName,
FILE_DEVICE_UNKNOWN,
0,
FALSE,
&pDevice);
if (!NT_SUCCESS(status))
{
return status;
}
KdPrint(("Create Device Succ!\n"));
pDevice->Flags |= DO_BUFFERED_IO;
pDevice->Flags &= ~DO_DEVICE_INITIALIZING;
pDeviceExtension = (PDEVICE_EXTENSION)pDevice->DeviceExtension;
pDeviceExtension->pDevice = pDevice;
pDeviceExtension->ustrDeviceName = strDeviceName;
pDeviceExtension->ulHideNum = 0;
pDeviceExtension->ulProtectNum = 0;
RtlInitUnicodeString(&strLinkName, L"\\??\\FileTool");
pDeviceExtension->ustrSymLinkName = strLinkName;
status = IoCreateSymbolicLink(&strLinkName, &strDeviceName);
if (!NT_SUCCESS(status))
{
KdPrint(("IoCreateSymbolicLink Err\n"));
IoDeleteDevice(pDevice);
return status;
}
///> 这里能成功打印
KdPrint(("Create IoCreateSymbolicLink Succ!\n"));
return STATUS_SUCCESS;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)