From 40f88649f1839259475e1a0652791b40898eeeea Mon Sep 17 00:00:00 2001 From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com> Date: Mon, 30 Dec 2019 15:09:16 +0100 Subject: [PATCH] Minor change --- .gitignore | 2 +- Misc/GenericExtensions.cs | 9 +++++---- Misc/HID.cs | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 4a4d13c..d29f780 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ - +CREPLSETUP.creplscript # Created by https://www.gitignore.io/api/csharp,visualstudio # Edit at https://www.gitignore.io/?templates=csharp,visualstudio diff --git a/Misc/GenericExtensions.cs b/Misc/GenericExtensions.cs index ade759d..f676cdf 100644 --- a/Misc/GenericExtensions.cs +++ b/Misc/GenericExtensions.cs @@ -41,10 +41,8 @@ namespace CC_Functions.Misc func(); } - public static T ParseToEnum(string value) - { - return (T) Enum.Parse(typeof(T), Enum.GetNames(typeof(T)).First(s => s.ToLower() == value.ToLower())); - } + public static T ParseToEnum(string value) => (T) Enum.Parse(typeof(T), + Enum.GetNames(typeof(T)).First(s => s.ToLower() == value.ToLower())); public static bool? ParseBool(string value) => string.IsNullOrWhiteSpace(value) || value.ToLower() == "Indeterminate" @@ -62,5 +60,8 @@ namespace CC_Functions.Misc public static bool FALSE(this bool? self) => self == false; public static bool NULL(this bool? self) => self == null; + + public static void RemoveAt(this Dictionary dict, int index) => + dict.Remove(dict.Keys.OfType().ToArray()[index]); } } \ No newline at end of file diff --git a/Misc/HID.cs b/Misc/HID.cs index 60048f0..1b35426 100644 --- a/Misc/HID.cs +++ b/Misc/HID.cs @@ -9,8 +9,8 @@ namespace CC_Functions.Misc { public static class HID { + public static bool forceWindows = false; private static byte[] _fingerPrint; - private static readonly string HIDClasses = @"Win32_Processor:UniqueId Win32_Processor:ProcessorId Win32_Processor:Name @@ -25,7 +25,7 @@ Win32_BaseBoard:Model Win32_BaseBoard:Manufacturer Win32_BaseBoard:Name Win32_BaseBoard:SerialNumber -Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled"; +Win32_NetworkAdapterConfiguration:MACAddress"; public static byte[] Value { @@ -34,9 +34,9 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled"; if (_fingerPrint == null) { string fingerprintTmp = ""; - if (Type.GetType("Mono.Runtime") == null) + if (forceWindows || Type.GetType("Mono.Runtime") == null) { - HIDClasses.Split('\r').Select(s => + HIDClasses.Split(new[] {"\r\n"}, StringSplitOptions.None).Select(s => { if (s.StartsWith("\n")) s = s.Remove(0, 1); @@ -48,8 +48,6 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled"; { ManagementBaseObject[] array = moc.OfType().ToArray(); for (int j = 0; j < array.Length; j++) - { - if (s.Length > 2 && array[j][s[2]].ToString() != "True") continue; try { fingerprintTmp += array[j][s[1]].ToString(); @@ -59,11 +57,10 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled"; { Console.WriteLine("Failed to read property"); } - } } }); } - else //Linux implementation. This will not work if you are using Mono on windows or do not have uname and lscpu available + else //Linux implementation. This will not work if you are using Mono on windows or do not have "uname", "lscpu" and "id" available { Process p = new Process { @@ -83,8 +80,12 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled"; p.Start(); fingerprintTmp += p.StandardOutput.ReadToEnd(); p.WaitForExit(); + p.StartInfo.FileName = "ip"; + p.StartInfo.Arguments = "link"; + p.Start(); + fingerprintTmp += p.StandardOutput.ReadToEnd(); + p.WaitForExit(); } - using (MD5 sec = new MD5CryptoServiceProvider()) { byte[] bt = Encoding.ASCII.GetBytes(fingerprintTmp);