Skip to content

Commit

Permalink
Add wmi hwid
Browse files Browse the repository at this point in the history
  • Loading branch information
c4llv07e committed May 22, 2024
1 parent 512ebd8 commit 486a675
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<PackageVersion Include="SpaceWizards.NFluidsynth" Version="0.1.1" />
<PackageVersion Include="SpaceWizards.SharpFont" Version="1.0.2" />
<PackageVersion Include="SpaceWizards.Sodium" Version="0.2.1" />
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
Expand Down
36 changes: 18 additions & 18 deletions Robust.Shared/Network/HWId.cs
Original file line number Diff line number Diff line change
@@ -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<byte>();
Expand Down
1 change: 1 addition & 0 deletions Robust.Shared/Robust.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.ILVerification" PrivateAssets="compile" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" />
<PackageReference Include="Nett" PrivateAssets="compile" />
<PackageReference Include="System.Management" />
<PackageReference Include="VorbisPizza" PrivateAssets="compile" />
<PackageReference Include="Pidgin" />
<PackageReference Include="prometheus-net" />
Expand Down

0 comments on commit 486a675

Please sign in to comment.