From 0e60e22b73dd0693b349cbb63cf9a390c01fd5dd Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 12 Jan 2021 17:01:18 -0500 Subject: filter raw input based on id use device id (from device instance) over first hardware id use buffered method for all ioctls update gui/DeviceIDManager to match driver behavior respond to device change events desync MouseData and PointData accessors --- driver/driver.cpp | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'driver/driver.cpp') diff --git a/driver/driver.cpp b/driver/driver.cpp index 4f108bd..a92f773 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -58,8 +58,8 @@ Arguments: bool any = num_packets > 0; bool rel_move = !(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE); - bool dev_match = global.args.device_hw_id[0] == 0 || - wcsncmp(devExt->hwid, global.args.device_hw_id, MAX_HWID_LEN) == 0; + bool dev_match = global.args.device_id[0] == 0 || + wcsncmp(devExt->dev_id, global.args.device_id, MAX_DEV_ID_LEN) == 0; if (any && rel_move && dev_match) { // if IO is backed up to the point where we get more than 1 packet here @@ -146,6 +146,8 @@ Return Value: NTSTATUS status; void* buffer; + size_t bytes_out = 0; + UNREFERENCED_PARAMETER(Queue); UNREFERENCED_PARAMETER(OutputBufferLength); UNREFERENCED_PARAMETER(InputBufferLength); @@ -166,6 +168,7 @@ Return Value: } else { *reinterpret_cast(buffer) = global.args; + bytes_out = sizeof(ra::settings); } break; case RA_WRITE: @@ -205,6 +208,7 @@ Return Value: } else { *reinterpret_cast(buffer) = { RA_VER_MAJOR, RA_VER_MINOR, RA_VER_PATCH }; + bytes_out = sizeof(ra::version_t); } break; default: @@ -212,7 +216,7 @@ Return Value: break; } - WdfRequestComplete(Request, status); + WdfRequestCompleteWithInformation(Request, status, bytes_out); } #pragma warning(pop) // enable 28118 again @@ -480,25 +484,31 @@ Return Value: } // - // get device hwid + // get device id from bus driver // - WDFMEMORY memory = NULL; + DEVICE_OBJECT* pdo = WdfDeviceWdmGetPhysicalDevice(hDevice); - NTSTATUS hwid_query = WdfDeviceAllocAndQueryProperty( - hDevice, - DevicePropertyHardwareID, - PagedPool, - WDF_NO_OBJECT_ATTRIBUTES, - &memory); + KEVENT ke; + KeInitializeEvent(&ke, NotificationEvent, FALSE); + IO_STATUS_BLOCK iosb = {}; + PIRP Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP, + pdo, NULL, 0, NULL, &ke, &iosb); + Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; + PIO_STACK_LOCATION stack = IoGetNextIrpStackLocation(Irp); + stack->MinorFunction = IRP_MN_QUERY_ID; + stack->Parameters.QueryId.IdType = BusQueryDeviceID; + + NTSTATUS nts = IoCallDriver(pdo, Irp); - if (!NT_SUCCESS(hwid_query)) { - DebugPrint(("WdfDeviceAllocAndQueryProperty failed: 0x%x\n", hwid_query)); + if (nts == STATUS_PENDING) { + KeWaitForSingleObject(&ke, Executive, KernelMode, FALSE, NULL); } - else { - auto dev_ext = FilterGetData(hDevice); - void* buffer = WdfMemoryGetBuffer(memory, NULL); - wcsncpy(dev_ext->hwid, reinterpret_cast(buffer), MAX_HWID_LEN); - WdfObjectDelete(memory); + + if (NT_SUCCESS(nts)) { + auto* id_ptr = reinterpret_cast(iosb.Information); + wcsncpy(FilterGetData(hDevice)->dev_id, id_ptr, MAX_DEV_ID_LEN); + DebugPrint(("Device ID = %ws\n", id_ptr)); + ExFreePool(id_ptr); } // -- cgit v1.2.3