todbot / win-hid-dump

Sort of a Windows version of `usbhid-dump` to show HID Report Descriptors
52 stars 10 forks source link

Don't bail on exception #7

Closed imro2 closed 1 year ago

imro2 commented 1 year ago

Addresses issue #2. It handles exceptions thrown by HidSharp. Code for GetManufacturer and GetProductName lifted from HidSharp

imro2 commented 1 year ago

Sample output:

046D:C02B: (unnamed manufacturer) - (unnamed product)
PATH:\\?\hid#wmvirtualdevice#2&a934e6f&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
DESCRIPTOR:
  05  01  09  06  A1  01  05  07  19  E0  29  E7  15  00  25  01
  35  00  45  01  65  00  55  00  75  01  95  08  81  02  95  38
  81  03  05  08  19  01  29  05  95  05  91  02  95  03  91  03
  C1  00
  (50 bytes)
1B1C:1BF0:  -
PATH:\\?\hid#virtualdevice&10&col05#2&6b49825&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}
DESCRIPTOR:
  05  0C  09  01  A1  01  85  07  15  00  25  01  35  00  45  01
  65  00  55  00  75  01  95  10  81  03  C1  00
  (28 bytes)
046D:C541: Logitech - USB Receiver
PATH:\\?\hid#vid_046d&pid_c541&mi_01&col03#9&18334857&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
Unable to parse HID Report: System.NotSupportedException: Unable to reconstruct the report descriptor.
   at HidSharp.Platform.Windows.WinHidDevice.GetRawReportDescriptor() in C:\Code\src\oss\hidsharp\hid\HidSharp\Platform\Windows\WinHidDevice.cs:line 194
   at winhiddump.Program.Main(String[] args) in C:\Users\pvazn\OneDrive\VS Code\win-hid-dump\Program.cs:line 41DESCRIPTOR:

  (0 bytes)
todbot commented 1 year ago

awesome thanks!

bjanders commented 1 year ago

I think you forgot the continue; after catching the exception. No point in going on with printing the invalid, zero length rawReportDescriptor.

Also a newline char after the error message would make the output clearer.

                try
                {
                    rawReportDescriptor = dev.GetRawReportDescriptor();
                } catch (Exception e){ 
                    Console.Write("Unable to parse HID Report: {0}\n", e);
                    continue;
                }