Commit graph

619 commits

Author SHA1 Message Date
Yuri Benditovich
d902e99a2a Use lower device for queries during initialization
It is more correct to use lower device in stack for queries
during filter initialization. Lower device is in initialized
state and can process all kinds of requests, when current one is
not ready yet.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2017-07-12 16:49:32 +03:00
Dmitry Fleytman
dfd3a4a0ca ci: Integrate with AppVeyor
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
2017-06-07 14:27:19 +03:00
Sameeh Jubran
5dda7555c5 Installer: Abort installation if the driver fails to start
Currently, in some cases, attempting to start the driver can fail
and cause Usb devices to become non functional. An example of such
case is attemteting to install an unsigned version of UsbDk on Windows
where the driver signature enforcement is enabled. The reason why this
happens is not making sure the driver can start on the system prior to
attaching it to all of the devices.

This patch solves this issue by checking that the driver can start on the
system prior to step 2 in the list below.

UsbDk's installation process:
1) Create and register UsbDk's service
2) Add UsbDk to the registry
3) Reset all Usb host conrollers on the system
4) PNP manager attaches and starts the driver for each Usb device's stack

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-05-29 16:45:38 +03:00
Sameeh Jubran
e7b4fd2391 ServiceManager: Add Start and Stop methods
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-05-29 16:45:32 +03:00
Yuri Benditovich
2214163c4e Documentation: Update tracing documentation
Include getting traces using logman and converting binary traces
to text using installed TMF file.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-05-29 10:28:06 +03:00
Yuri Benditovich
b41c88dd48 tools: Add BAT file for recording of binary trace
Existing batch file records binary trace using TraceView that
shall be copied from WDK, which is not always installed on end
user machine. Added batch file allows recording without additional
tools, using built-in logman application.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-05-29 10:27:24 +03:00
Yuri Benditovich
330368c38b build: Include TMF file to installation package
Single TMF file contains all the data required for converting
binary trace to text for all the operating systems.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-05-29 10:27:19 +03:00
Yuri Benditovich
860d2c2d11 build: Build TMF files after building all binaries
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-05-29 10:27:07 +03:00
Sameeh Jubran
6065c56ce9 Documentation: Add Uninstallation.txt
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
2017-05-25 12:12:09 +03:00
Dmitry Fleytman
446daeca3e Build: Introduce debug configurations without test signing
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
2017-04-06 13:24:06 +03:00
Sameeh Jubran
7abd2b9071 Documentation: Update for VS 2015 and Windows 10
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-03 15:06:48 +03:00
Sameeh Jubran
ae2d76c152 Build: Add Windows 10 to MSI
According to msdn [1]:
"When you install an .msi installation package on Windows 10 or Windows
Server 2016, the VersionNT value is 603." which is the same value for
Windows 8.1.
In order to differentiate between Windows 8.1 and Windows 10 the trick in
[2] was used.

[1] https://support.microsoft.com/en-us/help/3202260/versionnt-value-for-windows-10-and-windows-server-2016
[2] http://stackoverflow.com/questions/31932646/versionnt-msi-property-on-windows-10

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-03 15:06:48 +03:00
Sameeh Jubran
0cf33ff14c Build: Delete unnecessary build configurations
This commit deletes "Release" and "Debug" build configuration which
weren't used.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-03 15:06:47 +03:00
Sameeh Jubran
2cd4aa5262 Build: Migrate to VS 2015 and add Win10 configurations
This commit migrates from VS 2013 to VS 2015. Beside the auto conversion
which was performed by VS this commit includes the following fixes
which enabled the builld to work:

Win (7, 8, 8.1, 10):
* Set the KMDF Version Major to 1.
* Set the KMDF Version Minor to 11.

Win XP:
* Add _When_ define.
* Add empty implementation to guard functions which else would cause an
  unresolved symbols.
* Add path to WinDDK's wdfinstaller.h in UsbDkHelper project.
* Add "GetDriverProjectAttributes" and "GetPackageFiles" targets to
  UsbDkController, UsbDkHelper and UsbDkInstHelper project files.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-03 15:06:47 +03:00
Yuri Benditovich
2b41acd295 Tools: Add boot-time binary tracing scripts
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-03 11:32:37 +03:00
Yuri Benditovich
6863d52c3f README: Added notice about Windows 7 and required KB update
https://technet.microsoft.com/en-us/library/security/3033929
required on Windows 7, otherwise UsbDk driver's signature is not
recognized properly and OS fails to load driver.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-03 11:19:10 +03:00
Yuri Benditovich
6da5b27ca6 Alloc: Make non-paged allocation from Nx pool on Win8 and later
This is requirement of DeviceGuard and HyperVisor Code
Integrity Readiness Test on Win10/Server2016.
We use Nx allocations for all the systems where Nx pool
is implemented, i.e. for Windows 8 and later.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-02 17:24:35 +03:00
Yuri Benditovich
7c72773cd1 FilterDevice: Do not report non-USB devices in list of devices
The driver may report non-USB device in list of devices
available for redirection (for example, this happens with
FTDI dual-port serial adapter PID 6010)

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-02 17:24:19 +03:00
Sameeh Jubran
dddc046940 UsbDk: Use case sensitive comparison
When attempting to redirect a device and the <device id> input string doesn't
match the actual <device id> string (case sensitive) the UsbDkController gets
stuck for two minutes and the error: "Redirect of USB device failed" is shown.
This is caused by case insensitive comparison between the input string and the
<device id> string in "CRegText::Match(PCWSTR String)" followed by case
sensitive comparison in "CStringBase::operator== (const UNICODE_STRING& Str)"
causing the "m_RedirectionCreated" event's timeout - two minutes - to expire.

This commit makes the error message show instantly eliminating the two
minutes delay.

<device id> string comparison should be case sensitive as defined
by user mode UsbDk API contract.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-03-14 12:40:26 +02:00
Dmitry Fleytman
1217ff2739 HiderStrategy: Re-use serial numbers of UsbDk devices
See log message of previous commit for rationale.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 14:10:30 +02:00
Dmitry Fleytman
a4bf95a211 ControlDevice: Generate serial numbers for UsbDk devices
Windows recognizes USB devices by PID/VID/SN combination,
for each new USB device plugged in it generates a new
cached driver information entry in the registry.

When UsbDk hides or redirects a device it creates a virtual
device with UsbDk VID/PID and a generated serial number.

On one hand, this serial number should be unique because
there should be no multiple devices with the same PID/VID/SN
combination at any given moment of time. On the other hand,
UsbDk should re-use serial numbers of unplugged devices,
because we don't want Windows to cache one more driver
information entry each time we redirect of hide a device.

This patch introduces a simple but efficient mechanism
for serial number generation for virtual UsbDk devices.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 14:09:52 +02:00
Dmitry Fleytman
2e945fe180 FilterDevice: Add support for externally assigned serial number
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 13:54:06 +02:00
Dmitry Fleytman
6f383cb2b9 HiderStrategy: Do not allow hidden device removal right after creation
See commit diff for explanation.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 13:52:51 +02:00
Dmitry Fleytman
6dd93fb7c5 RedirectorStrategy: Fix MakeAvailable() logic chaining
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 11:15:50 +02:00
Dmitry Fleytman
2c06508b1c FilterStrategy: Introduce helper function for IRP completion
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 11:14:32 +02:00
Dmitry Fleytman
435ea8de58 UsbDkUtil: Introduce CStopWatch class
This class does elapsed time measurement.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-19 11:13:42 +02:00
Dmitry Fleytman
2f54f6e20f HiderStrategy: Add printout for device ID patcher
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-15 16:03:43 +02:00
Dmitry Fleytman
8624b1e0b6 WdfDevice: Add printout on device destruction
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-15 15:54:58 +02:00
Dmitry Fleytman
f5de68b75d WdfDevice: Fix severity of information printout
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-15 15:53:58 +02:00
Dmitry Fleytman
848bb79ac2 FilterDevice: Raise redirection removal event on device disconnection
This is useful for devices that change ID on reset.

Previous scheme of raising event on device
"reconnection" after port cycle does not work
for such devices because after reset
they look like another device for UsbDK.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-09 18:28:21 +02:00
Dmitry Fleytman
76299389ce ControlIrp: Clear event state prior to sending IRP
This is needed in case client sends the same IRP
for a few times.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-08 13:00:16 +02:00
Dmitry Fleytman
5288bfcbcb Utils: Fix event type for CWdmEvent
Event wrapped by CWdmEvent expected to be
NotificationEvent, i.e. not auto-reset.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-08 12:57:39 +02:00
Dmitry Fleytman
d47bd4d237 UsbDkHelper: Do not print API errors to console
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-07 15:59:58 +02:00
Dmitry Fleytman
db95b4651e FilterDevice: Fix recognition of HUB devices
Sometimes UsbDk cannot query device descriptors for USB hubs,
in such cases it does not attach to theirs stack during parent bus
relations processing.

However, since UsbDk is registered as USB hub class filter,
WDF will call its AddDevice callback anyway.

In this case UsbDk should assume that it is dealing with a hub
and assign its usual hub strategy.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-02 12:04:36 +02:00
Dmitry Fleytman
bb931eade4 ControlDevice: Add more traces for redirection set modifications
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-01-31 15:43:47 +02:00
Dmitry Fleytman
4ae38672d4 ControlDevice: Always log full device ID including serial number
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-01-30 14:43:44 +02:00
Sameeh Jubran
1340ea01e2 UsbDkHelper: Add static modifier to printExceptionString function
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
2017-01-26 18:03:27 +02:00
Sameeh Jubran
b0660af0d1 UsbDKHelper: Add unpackHandle function
unpackHandle checks if the provided HANDLE is null or has an
INVALID_HANDLE_VALUE and casts it to the suitable data type.
This check can prevent the UsbDkHelper from crashing becuase of api misuse.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
2017-01-26 18:03:20 +02:00
Sameeh Jubran
6b623e0ba2 Fix a possible BSOD due to null pointer
m_Relations can be null therefore we should access it carefully.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-01-18 15:28:09 +02:00
Dmitry Fleytman
bf79d6e942 ControlDevice: Fix removal of redirection on hub unplug
On unplug of USB hub that contains a redirected
device, removal of redirection is started when redirected
device PDO is still present in UsbDk device lists.

In this case UsbDk will try to send reset IOCTL to this device
and system will return STATUS_NO_SUCH_DEVICE error code.

This commit changes behavior of redirection removal
logic in a way that it will not interrupt removal
process when such an error is returned by reset.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-09-01 10:36:48 +03:00
Dmitry Fleytman
e68f982ff7 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>
2016-07-04 11:29:29 +03:00
Dmitry Fleytman
8c7edd9997 FilterDevice: Extend IRP post processing logic
This patch adds support for IRP post processing
on failure and in all cases.

New logic will be used by following commits to
implement device text patching.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-07-04 11:29:27 +03:00
Dmitry Fleytman
e0c43569d3 Trace: Add separate trace group for Hider strategy
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-07-04 11:29:27 +03:00
Dmitry Fleytman
f01408384a UsbDk: Simplify and refactor filter attachment code
This is a refactoring commit, no functional changes introduced.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:09 +03:00
Dmitry Fleytman
0b7487ba56 UsbDk: Retire old hiding logic
This commit retires old device hider logic based
on wiping PDOs from BusRelations array.

Previous commits introduce new logic based on IDs
patching.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:05 +03:00
Dmitry Fleytman
a9bbb929f5 UsbDk: Implement hider logic via patching device IDs
Wiping PDOs from BusRelations list has side effect
of absence of hotplug events from the OS.

This is not good for applications that want devices
appear hidden and start redirection process on plug
at the same time.

Following patches will retire old hiding logic.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:00 +03:00
Dmitry Fleytman
c80effc7dd UsbDk: Introduce hider strategy class
This class will be used by following patches to
implement hiding via patching device IDs.

See commit messages of corresponfing patches
for rationale.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:31:55 +03:00
Dmitry Fleytman
b354d0ea35 UsbDk: Trivial: Remove comments numbering
It is ridiculous to update numbering manually after
each change in that function.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:31:50 +03:00
Dmitry Fleytman
eadd31b315 UsbTarget: Trivial: Remove m_ prefix from stack variables names
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-03-09 11:03:26 +02:00
Dmitry Fleytman
0a4f4811bc RedirectorStrategy: Add request counters to traces
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 12:03:39 +02:00