From 9e8539b1a67a4e2ae01fbcf3ecafcb36c0b1122c Mon Sep 17 00:00:00 2001 From: imro2 Date: Tue, 27 Sep 2022 08:00:56 -0500 Subject: [PATCH 1/2] handle exceptions --- Program.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index 9a58c36..dc9131e 100644 --- a/Program.cs +++ b/Program.cs @@ -27,9 +27,21 @@ static void Main(string[] args) 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, dev.GetManufacturer(), dev.GetProductName(), dev.DevicePath)); - byte[] rawReportDescriptor = dev.GetRawReportDescriptor(); + 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++) { @@ -39,8 +51,8 @@ static void Main(string[] args) 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(); + Console.WriteLine("Press any key to exit"); + Console.ReadKey(); } } } From 29f3d3a6dc59cb96baf599b7d859e50ed12890b2 Mon Sep 17 00:00:00 2001 From: imro2 Date: Tue, 27 Sep 2022 08:04:19 -0500 Subject: [PATCH 2/2] comment out wait for key press --- Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index dc9131e..2439fbc 100644 --- a/Program.cs +++ b/Program.cs @@ -51,8 +51,8 @@ static void Main(string[] args) 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(); +// Console.WriteLine("Press any key to exit"); +// Console.ReadKey(); } } }