Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Combining keyboard and mouse filters into one driver

IgnoreExceptionIgnoreException Member Posts: 47

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.

Comments

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,829
    WdfFdoInitWdmGetPhysicalDevice
    WdfFdoInitAllocAndQueryProperty
    WdfFdoInitAllocAndQueryPropertyEx
    WdfFdoInitQueryProperty
    WdfFdoInitQueryPropertyEx
    d
  • IgnoreExceptionIgnoreException Member Posts: 47

    @Doron_Holan said:
    WdfFdoInitWdmGetPhysicalDevice
    WdfFdoInitAllocAndQueryProperty
    WdfFdoInitAllocAndQueryPropertyEx
    WdfFdoInitQueryProperty
    WdfFdoInitQueryPropertyEx

    I am still stuck I decided to do the following.

    // Query for the device class GUID.
        if (NT_SUCCESS(status = WdfFdoInitAllocAndQueryProperty(DeviceInit, DevicePropertyClassGuid, NonPagedPool, WDF_NO_OBJECT_ATTRIBUTES, &memory))) {
            deviceClassGuid = WdfMemoryGetBuffer(memory, NULL);
    
            if (deviceClassGuid == NULL) {
                WdfObjectDelete(memory);
                DebugMessage("deviceClassGuid is null");
                return STATUS_SUCCESS;
            }
    
            DebugMessage("deviceClassGuid: {%.8lX-%.4hX-%.4hX-%.2hhX%.2hhX-%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX}\n",
                deviceClassGuid->Data1, deviceClassGuid->Data2, deviceClassGuid->Data3,
                deviceClassGuid->Data4[0], deviceClassGuid->Data4[1], deviceClassGuid->Data4[2],
                deviceClassGuid->Data4[3], deviceClassGuid->Data4[4], deviceClassGuid->Data4[5],
                deviceClassGuid->Data4[6], deviceClassGuid->Data4[7]);
    
            DebugMessage("GUID_DEVCLASS_KEYBOARD: {%.8lX-%.4hX-%.4hX-%.2hhX%.2hhX-%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX}\n",
                GUID_DEVCLASS_KEYBOARD.Data1, GUID_DEVCLASS_KEYBOARD.Data2, GUID_DEVCLASS_KEYBOARD.Data3,
                GUID_DEVCLASS_KEYBOARD.Data4[0], GUID_DEVCLASS_KEYBOARD.Data4[1], GUID_DEVCLASS_KEYBOARD.Data4[2],
                GUID_DEVCLASS_KEYBOARD.Data4[3], GUID_DEVCLASS_KEYBOARD.Data4[4], GUID_DEVCLASS_KEYBOARD.Data4[5],
                GUID_DEVCLASS_KEYBOARD.Data4[6], GUID_DEVCLASS_KEYBOARD.Data4[7]);
    
            DebugMessage("GUID_DEVCLASS_MOUSE: {%.8lX-%.4hX-%.4hX-%.2hhX%.2hhX-%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX}\n",
                GUID_DEVCLASS_MOUSE.Data1, GUID_DEVCLASS_MOUSE.Data2, GUID_DEVCLASS_MOUSE.Data3,
                GUID_DEVCLASS_MOUSE.Data4[0], GUID_DEVCLASS_MOUSE.Data4[1], GUID_DEVCLASS_MOUSE.Data4[2],
                GUID_DEVCLASS_MOUSE.Data4[3], GUID_DEVCLASS_MOUSE.Data4[4], GUID_DEVCLASS_MOUSE.Data4[5],
                GUID_DEVCLASS_MOUSE.Data4[6], GUID_DEVCLASS_MOUSE.Data4[7]);
    

    This resulted in the following debug messages.

    deviceClassGuid: {0034007B-0064-0033-3600-650039003600}
    GUID_DEVCLASS_KEYBOARD: {4D36E96B-E325-11CE-BFC1-08002BE10318}
    GUID_DEVCLASS_MOUSE: {4D36E96F-E325-11CE-BFC1-08002BE10318}
    

    I am manually creating the driver via cmd and then I am going into my device manager and then clicking on "HID-compliant mouse" and selecting disable before then reenabling it again which then runs my drivers code. But I have no idea what the 0034007B-0064-0033-3600-650039003600 GUID is because it does not even look valid so what is going on here and how can I fix it?

  • IgnoreExceptionIgnoreException Member Posts: 47

    Anyone have any suggestions to get the ClassGUID from a PWDFDEVICE_INIT DeviceInit before we can create its instance of WDFDEVICE device?

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,754

    Requests the GUID for the device's setup class. PropertyBuffer points to a NULL-terminated array of WCHAR. This routine returns the GUID in a string format as follows, where each "c" represents a hexadecimal character: {cccccccc-cccc-cccc-cccc-cccccccccccc}

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online