阅读:1819回复:0
驱动加载错误
UNICODE_STRING g_uszSrvKey;
////////////////////////////////////////////////// PDEVICE_OBJECT g_pDevObjTest; UNICODE_STRING g_uszDevName; UNICODE_STRING g_uszDevLink; #define DEVNAME L"\\Device\\testdrv3" #define DEVLINK L"\\DosDevices\\testdrv3" ////////////////////////////////////////////////// extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDrvObj, IN PUNICODE_STRING puszRegPath) { int iCount; NTSTATUS ntStatus; g_uszSrvKey.Buffer = (PWSTR)ExAllocatePool(PagedPool, puszRegPath->Length + sizeof(WCHAR)); if(g_uszSrvKey.Buffer == NULL) { DbgPrint("Unable to allocate %d bytes for copy of service key name\n", puszRegPath->Length); return STATUS_INSUFFICIENT_RESOURCES; } g_uszSrvKey.MaximumLength = puszRegPath->Length + sizeof(WCHAR); RtlCopyUnicodeString(&g_uszSrvKey, puszRegPath); ////////////////////////////////////////////////// RtlInitUnicodeString(&g_uszDevName, DEVNAME); ntStatus = IoCreateDevice(pDrvObj, sizeof(DEVICE_EXTENSION), &g_uszDevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &g_pDevObjTest); if(!NT_SUCCESS(ntStatus)) { RtlFreeUnicodeString(&g_uszSrvKey); return ntStatus; } RtlInitUnicodeString(&g_uszDevLink, DEVLINK); ntStatus = IoCreateSymbolicLink(&g_uszDevLink, &g_uszDevName); if(!NT_SUCCESS(ntStatus)) { RtlFreeUnicodeString(&g_uszSrvKey); IoDeleteDevice(g_pDevObjTest); return ntStatus; } ////////////////////////////////////////////////// pDrvObj->DriverUnload = DriverUnload; pDrvObj->DriverExtension->AddDevice = AddDevice; for( iCount = 0; iCount <= IRP_MJ_MAXIMUM_FUNCTION; iCount++) { pDrvObj->MajorFunction[iCount] = DispatchControl; } return ntStatus; } VOID DriverUnload(IN PDRIVER_OBJECT pDrvObj) { ////////////////////////////////////////////////// IoDeleteSymbolicLink(&g_uszDevLink); IoDeleteDevice(g_pDevObjTest); ////////////////////////////////////////////////// RtlFreeUnicodeString(&g_uszSrvKey); } NTSTATUS AddDevice(IN PDRIVER_OBJECT pDrvObj, IN PDEVICE_OBJECT pDevObj) { NTSTATUS ntStatus; ULONG uldxSize; PDEVICE_OBJECT pDevObjAdd; PDEVICE_EXTENSION pDevExt; UNICODE_STRING uszDevName; RtlInitUnicodeString(&uszDevName, L"\\DosDevices\\testdrv1adddev"); uldxSize = sizeof(DEVICE_EXTENSION); ntStatus = IoCreateDevice(pDrvObj, uldxSize, &uszDevName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &pDevObjAdd); if(!NT_SUCCESS(ntStatus)) { DbgPrint("IoCreateDevice failed with %x", ntStatus); return ntStatus; } pDevExt = (PDEVICE_EXTENSION)pDevObj->DeviceExtension; pDevExt->pDevObj = pDevObj; pDevExt->pPdo = pDevObj; pDevExt->pLowerDevObj = IoAttachDeviceToDeviceStack(pDevObjAdd, pDevObj); if(pDevExt->pLowerDevObj == NULL) { DbgPrint("AddDevice IoAttachDeviceToDeviceStack failed with %x"); IoDeleteDevice(pDevObjAdd); return STATUS_DEVICE_REMOVED; } pDevObjAdd->Flags &= ~DO_DEVICE_INITIALIZING; return STATUS_SUCCESS; } NTSTATUS DispatchControl(PDEVICE_OBJECT pDevObj, PIRP pIrp) { IoCompleteRequest(pIrp, IO_NO_INCREMENT); return STATUS_SUCCESS; } 这段代码,用DDK2003的2000编译环境编译.用DriverMonitor加载,结果只运行了DriverEntry()和DriverUnload(),加载器返回1058错误... 请大家怎么解决这个问题,万分感谢. |
|