简体   繁体   English

ObReferenceObjectByHandle错误检查,内存访问冲突

[英]ObReferenceObjectByHandle Bugcheck, Memory Access Violation

I am working on a project to dynamically disable the keyboard. 我正在研究一个动态禁用键盘的项目。 I have written a driver which attempts to obtain the keyboards physical device object then call IoInvalidateDeviceState with it but I am having a problem getting its physical device object. 我编写了一个驱动程序,尝试获取键盘物理设备对象,然后使用它调用IoInvalidateDeviceState,但是获取其物理设备对象时遇到问题。 Whenever I try to call ObReferenceObjectByHandle with the handle to the device object, a bugcheck occurs and the error is a memory access violation. 每当我尝试使用设备对象的句柄调用ObReferenceObjectByHandle时,都会发生错误检查,并且错误是内存访问冲突。 Here is my source code: 这是我的源代码:

#include "ntifs.h"
#include "wdm.h" 
#include "ntstrsafe.h"
#pragma comment(lib, "ntstrsafe.lib")

VOID DriverUnloadRoutine(__in PDRIVER_OBJECT DriverObject);

DRIVER_INITIALIZE DriverEntry;
NTSTATUS DriverEntry( 
__in struct _DRIVER_OBJECT  *DriverObject,
__in PUNICODE_STRING  RegistryPath 
)
{
UNICODE_STRING keybdname;
FILE_OBJECT * keybdfo;
DEVICE_OBJECT * keybddo;
HANDLE hpdo;
FILE_OBJECT * pdofo;
DEVICE_OBJECT * pdo;

DriverObject->DriverUnload = DriverUnloadRoutine;

RtlInitUnicodeString(&keybdname,L"\\Device\\KeyboardClass0");
IoGetDeviceObjectPointer(&keybdname,GENERIC_ALL,&keybdfo,&keybddo);
ObOpenObjectByPointer(&keybddo,OBJ_KERNEL_HANDLE,0,0,0,KernelMode,&hpdo);
ObReferenceObjectByHandle(hpdo,FILE_ALL_ACCESS,*IoFileObjectType,KernelMode,&pdofo,NULL);
pdo = IoGetRelatedDeviceObject(&pdofo);
IoInvalidateDeviceState(&pdo);

return 0;  
}

VOID DriverUnloadRoutine(
    __in PDRIVER_OBJECT DriverObject
    )
{

}

I realize this is probably not the best way to accomplish this (maybe even the worst), but the only two other ways I know of are unplugging the keyboard or installing a filter driver, which would require a reboot. 我意识到这可能不是完成此操作的最佳方法(甚至可能是最坏的方法),但是我知道的仅有的另外两种方法是拔下键盘或安装筛选器驱动程序,这需要重新启动。 If there is another way to do this, informing me of it would be great. 如果有另一种方法可以做到,通知我也很好。 Thanks in advance for the help! 先谢谢您的帮助!

My guess would be, that one of your functions you are calling does return a error value, and does not fill out the according structure. 我的猜测是,您正在调用的函数之一确实返回错误值,并且没有填写相应的结构。

I would go about disabling the keyboard by looking at the SetupApi or the CfgMgr32 functions. 我将通过查看SetupApi或CfgMgr32函数来禁用键盘。

The "devcon" wdk sample should contain the code to disable a device from user mode. “ devcon” wdk示例应包含用于从用户模式禁用设备的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM