Skip to content

Commit

Permalink
RedirectorStrategy: Override device description for redirected devices.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dmitry Fleytman committed Jul 4, 2016
1 parent 8c7edd9 commit e68f982
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions UsbDk/HiderStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions UsbDk/HiderStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ class CUsbDkHiderStrategy : public CUsbDkNullFilterStrategy

private:
void PatchDeviceID(PIRP Irp);
NTSTATUS PatchDeviceText(PIRP Irp);
};

0 comments on commit e68f982

Please sign in to comment.