diff options
author | Dmitry Fleytman <dfleytma@redhat.com> | 2016-07-03 14:59:49 +0300 |
---|---|---|
committer | Dmitry Fleytman <dfleytma@redhat.com> | 2016-07-04 11:29:29 +0300 |
commit | e68f982ff7370f9c75bcabce1b76f3df6d9299be (patch) | |
tree | f25ab89a3b8c320dc6b6db6af933f57f4dbe5dca | |
parent | 8c7edd99971655dffd54ca39a2e5e6c351730076 (diff) |
RedirectorStrategy: Override device description for redirected devices.v1.00-14
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 <dfleytma@redhat.com>
-rw-r--r-- | UsbDk/HiderStrategy.cpp | 45 | ||||
-rw-r--r-- | UsbDk/HiderStrategy.h | 1 |
2 files changed, 46 insertions, 0 deletions
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<PVOID>(Irp->IoStatus.Information)); + } + + Irp->IoStatus.Information = reinterpret_cast<ULONG_PTR>(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 @@ public: private: void PatchDeviceID(PIRP Irp); + NTSTATUS PatchDeviceText(PIRP Irp); }; |