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 <dfleytma@redhat.com>
This commit is contained in:
Dmitry Fleytman 2016-07-03 14:59:49 +03:00
parent 8c7edd9997
commit e68f982ff7
2 changed files with 46 additions and 0 deletions

View file

@ -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);
}

View file

@ -31,4 +31,5 @@ public:
private:
void PatchDeviceID(PIRP Irp);
NTSTATUS PatchDeviceText(PIRP Irp);
};