typedef struct _DEVICE_EXTENSION
{
PDEVICE_OBJECT pDeviceObject;
UNICODE_STRING DeviceName;
UNICODE_STRING SymbolicLinkName;
}DEVICE_EXTENSION,*PDEVICE_EXTENSION;
#pragma INITCODE
NTSTATUS CreateMyDevice(PDRIVER_OBJECT pDriverObject)
{
//创建设备
UNICODE_STRING DevName;
UNICODE_STRING SymbolicName;
PDEVICE_OBJECT pDevObj;
PDEVICE_EXTENSION pDevExt;
NTSTATUS status;
RtlInitUnicodeString(&DevName,L"\\Device\\StolenDfu");
status=IoCreateDevice(pDriverObject,
sizeof(DEVICE_EXTENSION),
&DevName,
FILE_DEVICE_UNKNOWN,0,
TRUE,&pDevObj);
if(!NT_SUCCESS(status))
{
DbgPrint("创建设备失败DbgPrint");
KdPrint(("创建设备失败 KdPrint"));
return status;
}
else{KdPrint(("创建成功"));}
pDevObj->Flags |= DO_BUFFERED_IO;
pDevExt=(PDEVICE_EXTENSION)pDevObj->DeviceExtension;
pDevExt->pDeviceObject=pDevObj;
pDevExt->DeviceName=DevName;
//创建符号连接
RtlInitUnicodeString(&SymbolicName,L"\\DosDevices\\stolenddk");
pDevExt->SymbolicLinkName=SymbolicName;
status=IoCreateSymbolicLink(&SymbolicName,&DevName);
if(!NT_SUCCESS(status))
{
DbgPrint("创建符号连接失败DbgPrint");
KdPrint(("创建符号连接失败 KdPrint"));
IoDeleteDevice(pDevObj);
return status;
}
else
{KdPrint(("创建符号连接成功"));}
return status;
}
VOID UnloadRutine(PDRIVER_OBJECT pDriverObject)
{
//删除设备
_asm int 3;
PDEVICE_OBJECT pNextDev;
NTSTATUS status;
PDEVICE_EXTENSION pDevExt;
pNextDev=pDriverObject->DeviceObject;
// UNNtCliVirualMemory();
/* if (IsRecover)
{
CheckChangeHookedRoutine();
}
if (IsProtect)
{
UnProtect();
}*/
while(pNextDev!=NULL)
{
pDevExt=(PDEVICE_EXTENSION)pNextDev->DeviceExtension;
UNICODE_STRING pLinkName = pDevExt->SymbolicLinkName;
status=IoDeleteSymbolicLink(&pLinkName); //此处出错 前几天还用得好好的
if(!NT_SUCCESS(status))
{
DbgPrint("删除符号连接失败DbgPrint");
KdPrint(("删除符号连接失败 KdPrint"));
}
else{KdPrint(("删除符号连接成功"));}
pNextDev=pNextDev->NextDevice;
IoDeleteDevice(pDevExt->pDeviceObject);
KdPrint(("删除设备成功"));
}
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!