阅读:1829回复:3
关于获取HID硬件ID的疑问,请达人指点
我的代码如下:
//DriverEntry extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { DbgPrint("Entering DriverEntry"); NTSTATUS status = STATUS_SUCCESS; PDEVICE_OBJECT fdo; PFILE_OBJECT fobj; UNICODE_STRING name; IO_STATUS_BLOCK ioblock; char buff[1024]; //ExAllocatePool(PagedPool, 1024); //ZeroMemory(buff, 1024); RtlInitUnicodeString(&name, L"\\Device\\0000005c"); //RtlInitUnicodeString(&name, L"\\Device\\_HID00000001"); //设置卸载例程,方便卸载 DriverObject->DriverUnload = DriverUnload; //获取设备指针 status = IoGetDeviceObjectPointer(&name, FILE_READ_ATTRIBUTES, &fobj, &fdo); if(!NT_SUCCESS(status)) { //ShowErr(status); //ExFreePool(buff); DbgPrint("IoGetDeviceObjectPointer failed!"); return status; } KEVENT kevent; KeInitializeEvent(&kevent, NotificationEvent, FALSE); //mdl PIRP irp = NULL; irp = IoBuildDeviceIoControlRequest(IOCTL_HID_GET_HARDWARE_ID, fdo, NULL, 0, NULL, 0, TRUE, &kevent, &ioblock); if (NULL == irp) { DbgPrint("IoBuildDeviceIoControlRequest failed!"); ObDereferenceObject(fdo); } else { DbgPrint("IoBuildDeviceIoControlRequest Succeed!"); } PMDL mdl = IoAllocateMdl(buff, 1024, FALSE, FALSE, NULL); //到这里执行正常 irp->MdlAddress = mdl; if (NULL != mdl) { DbgPrint("IoAllocateMdl succeed!"); } else { DbgPrint("IoAllocateMdl faliled!"); } status = IoCallDriver(fdo, irp); //执行这一句后蓝屏! if (status == STATUS_PENDING) { status = KeWaitForSingleObject(&kevent, Executive, KernelMode, FALSE, NULL); if (status != STATUS_SUCCESS) { DbgPrint("KeWaitForSingleObject failed!"); } DbgPrint("KeWaitForSingleObject Succeed!"); DbgPrint("irp succeed!"); //status = ioblock.Status; } if (NT_SUCCESS(status)) { DbgPrint("IoCallDriver succeed!"); } else { DbgPrint("IoCallDriver failed!"); } //ShowErr(status); DbgPrint("irp succeed!"); ====== 将Memory.dmp用windbg调试,出现如下调试信息: PFN_LIST_CORRUPT (4e) Typically caused by drivers passing bad memory descriptor lists (ie: calling MmUnlockPages twice with the same list, etc). If a kernel debugger is available get the stack trace. Arguments: Arg1: 00000007, A driver has unlocked a page more times than it locked it Arg2: 000018d9, page frame number Arg3: 00000002, current share count Arg4: 00000000, 0 请问这是那里出的问题? 不胜感激…… |
|
沙发#
发布于:2008-05-16 10:02
怎么没人理啊?
这个论坛不是很火很专业吗? |
|
板凳#
发布于:2008-05-21 11:03
1.status = IoCallDriver(fdo, irp);
这样也行???发给自已?将会少一个IO_STACK,也就是越界 2.应当先AddDevice吧?没有这个,不知你如何向下CallDriver???? |
|
地板#
发布于:2008-05-21 11:05
其实我也是初学,请多关照。
PS:这个论坛,已经没有什么达人了,以后还请多多指教。 |
|