I am working on a singular driver that needs to filter mouse and keyboard input. They both will work together to achieve a common goal so cupelling them makes sense plus it makes life easier when installing, signing, etc. Anyways I have gotten these filter drivers working perfectly on their own but I am having trouble merging them. My DriverEntry function contains WDF_DRIVER_CONFIG_INIT(&config, Filter_EvtDeviceAdd)
where Filter_EvtDeviceAdd needs to be designed to handle both mouse and keyboard devices. My thought was to find a way to check for the incoming GUID and based on that I can run something like the following.
if (IsEqualGUID(&deviceClassGuid, &GUID_DEVCLASS_MOUSE)) {
WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_MOUSE);
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQueueConfig, WdfIoQueueDispatchParallel);
ioQueueConfig.EvtIoInternalDeviceControl = MouFilter_EvtIoInternalDeviceControl;
}
else if (IsEqualGUID(&deviceClassGuid, &GUID_DEVCLASS_KEYBOARD)) {
WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_KEYBOARD);
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQueueConfig, WdfIoQueueDispatchParallel);
ioQueueConfig.EvtIoInternalDeviceControl = KbFilter_EvtIoInternalDeviceControl;
}
else {
DebugMessage("Neither mouse nor keyboard device class assigned \n");
return STATUS_SUCCESS; // If it's neither a mouse nor a keyboard, just return.
}
The tricky part however is that I don’t know how I can determine deviceClassGuid
. At first I thought I could use IoGetDeviceProperty(WdfDeviceWdmGetPhysicalDevice(device), DevicePropertyClassGuid, sizeof(GUID), &deviceClassGuid, &returnedLength)
but that would require an instance of device which I don’t have because it would require me to call WdfDeviceCreate
which deletes DeviceInit
thus making it impossible to call WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_MOUSE)
. The only other idea I have is to make a generic EvtIoInternalDeviceControl
function and then check GUID there in the way I suggested above. Anyways I would greatly appreciate a solution to this so that I can correctly handle both types of devices.