From 486a6750c816d22a0c8f0bcc34479fc1196f1030 Mon Sep 17 00:00:00 2001 From: c4llv07e Date: Wed, 22 May 2024 23:06:00 +0300 Subject: [PATCH] Add wmi hwid --- Directory.Packages.props | 1 + Robust.Shared/Network/HWId.cs | 36 +++++++++++++++--------------- Robust.Shared/Robust.Shared.csproj | 1 + 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 24284c3e6..abc58e8ca 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -60,6 +60,7 @@ + diff --git a/Robust.Shared/Network/HWId.cs b/Robust.Shared/Network/HWId.cs index ad936c031..dcb356077 100644 --- a/Robust.Shared/Network/HWId.cs +++ b/Robust.Shared/Network/HWId.cs @@ -1,31 +1,31 @@ -using System; -using System.Security.Cryptography; -using Microsoft.Win32; +using System; using Robust.Shared.Console; +using System.Management; +using System.Text; namespace Robust.Shared.Network { internal static class HWId { - public const int LengthHwid = 32; - + private static string? GetWmi(string wmi_class, string property) + { + var mbs = new ManagementObjectSearcher($"Select {property} From {wmi_class}"); + ManagementObjectCollection mbsList = mbs.Get(); + foreach (ManagementObject mo in mbsList) + { + var id = mo[property].ToString(); + if (id != null) + return id; + } + return null; + } public static byte[] Calc() { if (OperatingSystem.IsWindows()) { - var regKey = Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Space Wizards\Robust", "Hwid", null); - if (regKey is byte[] { Length: LengthHwid } bytes) - return bytes; - - var newId = new byte[LengthHwid]; - RandomNumberGenerator.Fill(newId); - Registry.SetValue( - @"HKEY_CURRENT_USER\SOFTWARE\Space Wizards\Robust", - "Hwid", - newId, - RegistryValueKind.Binary); - - return newId; + var processorId = GetWmi("Win32_Processor", "ProcessorId"); + var motherboardSerial = GetWmi("Win32_BaseBoard", "SerialNumber"); + return Encoding.ASCII.GetBytes(processorId + motherboardSerial); } return Array.Empty(); diff --git a/Robust.Shared/Robust.Shared.csproj b/Robust.Shared/Robust.Shared.csproj index 333cbd5a9..fc4f868a3 100644 --- a/Robust.Shared/Robust.Shared.csproj +++ b/Robust.Shared/Robust.Shared.csproj @@ -12,6 +12,7 @@ +