From e68f982ff7370f9c75bcabce1b76f3df6d9299be Mon Sep 17 00:00:00 2001 From: Dmitry Fleytman Date: Sun, 3 Jul 2016 14:59:49 +0300 Subject: [PATCH] RedirectorStrategy: Override device description for redirected devices. There are two reasons for that: 1. There are devices that do not provide device description: In this case, for normal devices, Windows gets description from INF file. Since there is no INF file for UsbDk devices, Windows may fail to initialize the device (depending on implementation of bus driver). 2. With this patch redirected devices show up in device manager as "UsbDk device" which is better then "Unknown Device" or "Mass Storage Device" etc. Signed-off-by: Dmitry Fleytman --- UsbDk/HiderStrategy.cpp | 45 +++++++++++++++++++++++++++++++++++++++++ UsbDk/HiderStrategy.h | 1 + 2 files changed, 46 insertions(+) diff --git a/UsbDk/HiderStrategy.cpp b/UsbDk/HiderStrategy.cpp index 1753279..c9df379 100644 --- a/UsbDk/HiderStrategy.cpp +++ b/UsbDk/HiderStrategy.cpp @@ -98,6 +98,44 @@ void CUsbDkHiderStrategy::PatchDeviceID(PIRP Irp) } } +NTSTATUS CUsbDkHiderStrategy::PatchDeviceText(PIRP Irp) +{ + static const WCHAR UsbDkDeviceText[] = USBDK_DRIVER_NAME L" device"; + + const WCHAR *Buffer = nullptr; + SIZE_T Size = 0; + + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_HIDER, "%!FUNC! Entry"); + + PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp); + switch (irpStack->Parameters.QueryDeviceText.DeviceTextType) + { + case DeviceTextDescription: + Buffer = &UsbDkDeviceText[0]; + Size = sizeof(UsbDkDeviceText); + break; + default: + break; + } + + if (Buffer != nullptr) + { + auto Result = DuplicateStaticBuffer(Buffer, Size); + if (Result != nullptr) + { + if (Irp->IoStatus.Information != 0) + { + ExFreePool(reinterpret_cast(Irp->IoStatus.Information)); + } + + Irp->IoStatus.Information = reinterpret_cast(Result); + Irp->IoStatus.Status = STATUS_SUCCESS; + } + } + return Irp->IoStatus.Status; +} + + NTSTATUS CUsbDkHiderStrategy::PNPPreProcess(PIRP Irp) { PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp); @@ -123,6 +161,13 @@ NTSTATUS CUsbDkHiderStrategy::PNPPreProcess(PIRP Irp) irpStack->Parameters.DeviceCapabilities.Capabilities->SilentInstall = 1; return STATUS_SUCCESS; }); + case IRP_MN_QUERY_DEVICE_TEXT: + return PostProcess(Irp, + [this](PIRP Irp, NTSTATUS Status) -> NTSTATUS + { + UNREFERENCED_PARAMETER(Status); + return PatchDeviceText(Irp); + }); default: return CUsbDkNullFilterStrategy::PNPPreProcess(Irp); } diff --git a/UsbDk/HiderStrategy.h b/UsbDk/HiderStrategy.h index ff88351..e20ff15 100644 --- a/UsbDk/HiderStrategy.h +++ b/UsbDk/HiderStrategy.h @@ -31,4 +31,5 @@ class CUsbDkHiderStrategy : public CUsbDkNullFilterStrategy private: void PatchDeviceID(PIRP Irp); + NTSTATUS PatchDeviceText(PIRP Irp); };