better better tripcodes

https://github.com/davcs86/csharp-uhwid
This commit is contained in:
Bitl 2021-11-19 13:30:23 -07:00
parent c2f8608e64
commit f33399b758
5 changed files with 185 additions and 31 deletions

View File

@ -1,8 +1,8 @@
using NLog;
#region Usings
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
#endregion
namespace Novetus.Bootstrapper
{

View File

@ -0,0 +1,179 @@
#region Usings
using System;
using System.Management;
using System.Security.Cryptography;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
#endregion
//https://github.com/davcs86/csharp-uhwid
//merged into one class
namespace UHWID
{
#region UHWIDEngine
public static class UHWIDEngine
{
public static string SimpleUid { get; private set; }
public static string AdvancedUid { get; private set; }
static UHWIDEngine()
{
var volumeSerial = DiskId.GetDiskId();
var cpuId = CpuId.GetCpuId();
var windowsId = WindowsId.GetWindowsId();
SimpleUid = volumeSerial + cpuId;
AdvancedUid = SimpleUid + windowsId;
}
}
#endregion
#region DiskId
internal class DiskId
{
public static string GetDiskId()
{
return GetDiskId("");
}
private static string GetDiskId(string diskLetter)
{
//Find first drive
if (string.IsNullOrEmpty(diskLetter))
{
foreach (var compDrive in DriveInfo.GetDrives())
{
if (compDrive.IsReady)
{
diskLetter = compDrive.RootDirectory.ToString();
break;
}
}
}
if (!string.IsNullOrEmpty(diskLetter) && diskLetter.EndsWith(":\\"))
{
//C:\ -> C
diskLetter = diskLetter.Substring(0, diskLetter.Length - 2);
}
var disk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + diskLetter + @":""");
disk.Get();
var volumeSerial = disk["VolumeSerialNumber"].ToString();
disk.Dispose();
return volumeSerial;
}
}
#endregion
#region CpuId
internal static class CpuId
{
[DllImport("user32", EntryPoint = "CallWindowProcW", CharSet = CharSet.Unicode, SetLastError = true,
ExactSpelling = true)]
private static extern IntPtr CallWindowProcW([In] byte[] bytes, IntPtr hWnd, int msg, [In, Out] byte[] wParam,
IntPtr lParam);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool VirtualProtect([In] byte[] bytes, IntPtr size, int newProtect, out int oldProtect);
const int PAGE_EXECUTE_READWRITE = 0x40;
public static string GetCpuId()
{
var sn = new byte[8];
return !ExecuteCode(ref sn) ? "ND" : string.Format("{0:X8}{1:X8}", BitConverter.ToUInt32(sn, 4), BitConverter.ToUInt32(sn, 0));
}
private static bool ExecuteCode(ref byte[] result)
{
/* The opcodes below implement a C function with the signature:
* __stdcall CpuIdWindowProc(hWnd, Msg, wParam, lParam);
* with wParam interpreted as an 8 byte unsigned character buffer.
* */
var isX64Process = IntPtr.Size == 8;
byte[] code;
if (isX64Process)
{
code = new byte[]
{
0x53, /* push rbx */
0x48, 0xc7, 0xc0, 0x01, 0x00, 0x00, 0x00, /* mov rax, 0x1 */
0x0f, 0xa2, /* cpuid */
0x41, 0x89, 0x00, /* mov [r8], eax */
0x41, 0x89, 0x50, 0x04, /* mov [r8+0x4], edx */
0x5b, /* pop rbx */
0xc3, /* ret */
};
}
else
{
code = new byte[]
{
0x55, /* push ebp */
0x89, 0xe5, /* mov ebp, esp */
0x57, /* push edi */
0x8b, 0x7d, 0x10, /* mov edi, [ebp+0x10] */
0x6a, 0x01, /* push 0x1 */
0x58, /* pop eax */
0x53, /* push ebx */
0x0f, 0xa2, /* cpuid */
0x89, 0x07, /* mov [edi], eax */
0x89, 0x57, 0x04, /* mov [edi+0x4], edx */
0x5b, /* pop ebx */
0x5f, /* pop edi */
0x89, 0xec, /* mov esp, ebp */
0x5d, /* pop ebp */
0xc2, 0x10, 0x00, /* ret 0x10 */
};
}
var ptr = new IntPtr(code.Length);
if (!VirtualProtect(code, ptr, PAGE_EXECUTE_READWRITE, out _))
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
ptr = new IntPtr(result.Length);
return CallWindowProcW(code, IntPtr.Zero, 0, result, ptr) != IntPtr.Zero;
}
}
#endregion
#region WindowsId
internal class WindowsId
{
public static string GetWindowsId()
{
var windowsInfo = "";
var managClass = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");
var managCollec = managClass.Get();
var is64Bits = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"));
foreach (var o in managCollec)
{
var managObj = (ManagementObject)o;
windowsInfo = managObj.Properties["Caption"].Value + Environment.UserName + (string)managObj.Properties["Version"].Value;
break;
}
windowsInfo = windowsInfo.Replace(" ", "");
windowsInfo = windowsInfo.Replace("Windows", "");
windowsInfo = windowsInfo.Replace("windows", "");
windowsInfo += (is64Bits) ? " 64bit" : " 32bit";
//md5 hash of the windows version
var md5Hasher = MD5.Create();
var wi = md5Hasher.ComputeHash(Encoding.Default.GetBytes(windowsInfo));
var wiHex = BitConverter.ToString(wi).Replace("-", "");
return wiHex;
}
}
#endregion
}

View File

@ -22,6 +22,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Classes\RobloxXML.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Settings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\TextLineRemover.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Imported\UHWIDEngine.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StorageAndFunctions\GlobalFuncs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StorageAndFunctions\GlobalPaths.cs" />
<Compile Include="$(MSBuildThisFileDirectory)StorageAndFunctions\GlobalVars.cs" />

View File

@ -1280,27 +1280,8 @@ public class GlobalFuncs
public static string GenerateAndReturnTripcode()
{
//https://stackoverflow.com/questions/10546055/how-to-generate-a-system-pc-laptop-hardware-unique-id-in-c/50907399#50907399
ManagementObjectCollection mbsList = null;
ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
mbsList = mbs.Get();
string id = "";
foreach (ManagementObject mo in mbsList)
{
id = mo["ProcessorID"].ToString();
}
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
ManagementObjectCollection moc = mos.Get();
string motherBoard = "";
foreach (ManagementObject mo in moc)
{
motherBoard = (string)mo["SerialNumber"];
}
string uniqueSystemId = id + motherBoard;
return uniqueSystemId;
//Powered by https://github.com/davcs86/csharp-uhwid
return UHWID.UHWIDEngine.AdvancedUid;
}
public static GlobalVars.LauncherState GetStateForType(ScriptType type)

View File

@ -509,7 +509,6 @@ namespace NovetusLauncher
if (gameType == ScriptType.Client && GlobalVars.LocalPlayMode && FormStyle != Settings.Style.Stylish)
{
GeneratePlayerID();
GenerateTripcode();
}
else
{
@ -1021,12 +1020,6 @@ namespace NovetusLauncher
PlayerIDTextBox.Text = Convert.ToString(GlobalVars.UserConfiguration.UserID);
}
public void GenerateTripcode()
{
GlobalVars.UserConfiguration.PlayerTripcode = GlobalFuncs.GenerateAndReturnTripcode();
PlayerTripcodeLabel.Text = GlobalVars.UserConfiguration.PlayerTripcode;
}
public async void InstallAddon()
{
AddonLoader addon = new AddonLoader(ConsoleBox);