-
Notifications
You must be signed in to change notification settings - Fork 10
/
Program.cs
58 lines (50 loc) · 2.25 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using HidSharp;
namespace winhiddump
{
class Program
{
static string GetArgument(IEnumerable<string> args, string option) => args.SkipWhile(i => i != option).Skip(1).Take(1).FirstOrDefault();
static void Main(string[] args)
{
int vid = 0;
int pid = 0;
int.TryParse(GetArgument(args, "--vid"), System.Globalization.NumberStyles.HexNumber, null, out vid);
int.TryParse(GetArgument(args, "--pid"), System.Globalization.NumberStyles.HexNumber, null, out pid);
var list = DeviceList.Local;
foreach (var dev in list.GetHidDevices())
{
if ((vid != 0 && vid != dev.VendorID) ||
(pid != 0 && pid != dev.ProductID))
{
continue;
}
string manufacturer = "(unnamed manufacturer)";
try { manufacturer = dev.GetManufacturer(); } catch { }
string productName = "(unnamed product)";
try { productName = dev.GetProductName(); } catch { }
Console.Write(string.Format("{0:X4}:{1:X4}: {2} - {3}\nPATH:{4}\n",
dev.VendorID, dev.ProductID, manufacturer, productName, dev.DevicePath));
byte[] rawReportDescriptor = new byte[] { };
try
{
rawReportDescriptor = dev.GetRawReportDescriptor();
} catch (Exception e){
Console.Write("Unable to parse HID Report: {0}", e);
}
Console.Write("DESCRIPTOR:\n ");
for( int i=0; i< rawReportDescriptor.Length; i++)
{
Console.Write(rawReportDescriptor[i].ToString("X2") + " ");
Console.Write((i % 16 == 15) ? "\n " : " ");
}
Console.WriteLine("\n ({0} bytes)", rawReportDescriptor.Length);
// Console.WriteLine(" {0} ({1} bytes)", string.Join(" ", rawReportDescriptor.Select(d => d.ToString("X2"))), rawReportDescriptor.Length);
}
// Console.WriteLine("Press any key to exit");
// Console.ReadKey();
}
}
}