?????????????????????????
????????????CreateFile??????-1?? GetLastError ????????123????????????????????????????
?????????????????????winObj????????FirstDevice?? ??????????????????? ??????
????????:
????????????
#include "ntddk.h"
NTSTATUS CreateDevice(PDRIVER_OBJECT pDriverObject);
NTSTATUS CreateComplateRoutine(PDEVICE_OBJECT pDeviceObj?? PIRP pIrp);
NTSTATUS ReadComplateRoutine(PDEVICE_OBJECT pDeviceObj?? PIRP pIrp);
NTSTATUS WriteComplateRoutine(PDEVICE_OBJECT pDeviceObj?? PIRP pIrp);
NTSTATUS CloseComplateRoutine(PDEVICE_OBJECT pDeviceObj?? PIRP pIrp);
VOID MyDriverUnoad(PDRIVER_OBJECT pDriverObject);
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject??PUNICODE_STRING pRegistryPath)
{
NTSTATUS status;
status = CreateDevice(pDriverObject);
KdPrint(("CreateDevice."));
if (!NT_SUCCESS(status))
{
KdPrint(("Create device faild."));
}
else
{
KdPrint(("Create device success."));
KdPrint(("%wZ"?? pRegistryPath));
}
pDriverObject->MajorFunction[IRP_MJ_CREATE] = CreateComplateRoutine;
pDriverObject->MajorFunction[IRP_MJ_READ] = ReadComplateRoutine;
pDriverObject->MajorFunction[IRP_MJ_WRITE] = WriteComplateRoutine;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = CloseComplateRoutine;
pDriverObject->DriverUnload = MyDriverUnoad;
return STATUS_SUCCESS;
}
NTSTATUS CreateDevice(PDRIVER_OBJECT pDriverObject)
{
NTSTATUS status;
PDEVICE_OBJECT pDevObj;
UNICODE_STRING usDevName;
UNICODE_STRING usSymName;
RtlInitUnicodeString(&usDevName?? L"\Device\FirstDevice");
RtlInitUnicodeString(&usSymName?? L"\??\FirstDevice");;
status = IoCreateDevice(pDriverObject??
0??
&usDevName??
FILE_DEVICE_UNKNOWN??
0??
TRUE??
&pDevObj);
pDevObj->Flags |= DO_BUFFERED_IO;
if (!NT_SUCCESS(status))
{
KdPrint(("IoCreateDevice faild."));
return status;
}
status = IoCreateSymbolicLink(&usSymName?? &usDevName);
if (!NT_SUCCESS(status))
{
KdPrint(("IoCreateSymbolicLink faild."));
IoDeleteDevice(pDevObj);
return status;
}
return STATUS_SUCCESS;
}
NTSTATUS CreateComplateRoutine (PDEVICE_OBJECT pDeviceObj?? PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
KdPrint(("Create"));
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp?? IO_NO_INCREMENT);
return status;
}
NTSTATUS ReadComplateRoutine (PDEVICE_OBJECT pDeviceObj?? PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
return status;
}
NTSTATUS WriteComplateRoutine (PDEVICE_OBJECT pDeviceObj?? PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
return status;
}
NTSTATUS CloseComplateRoutine (PDEVICE_OBJECT pDeviceObj?? PIRP pIrp)
{
NTSTATUS status;
status = STATUS_SUCCESS;
return status;
}
VOID MyDriverUnoad(PDRIVER_OBJECT pDriverObject)
{
UNICODE_STRING usSymName;
RtlInitUnicodeString(&usSymName?? L"\??\FirstDevice");
if (pDriverObject->DeviceObject != NULL)
{
IoDeleteSymbolicLink(&usSymName);
IoDeleteDevice(pDriverObject->DeviceObject);
KdPrint(("Delete device success!"));
}
}