-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhwid.cs
168 lines (149 loc) · 6.09 KB
/
hwid.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
namespace hwid
{
public class hwid : Form
{
public hwid()
{
Console.Write("Your HWID: ");
Console.WriteLine(Value());
Console.ReadLine();
}
private static string GetHash(string s)
{
//Initialize a new MD5 Crypto Service Provider in order to generate a hash
MD5 sec = new MD5CryptoServiceProvider();
//Grab the bytes of the variable 's'
byte[] bt = Encoding.ASCII.GetBytes(s);
//Grab the Hexadecimal value of the MD5 hash
return GetHexString(sec.ComputeHash(bt));
}
private static string GetHexString(IList<byte> bt)
{
string s = string.Empty;
for (int i = 0; i < bt.Count; i++)
{
byte b = bt[i];
int n = b;
int n1 = n & 15;
int n2 = (n >> 4) & 15;
if (n2 > 9)
s += ((char) (n2 - 10 + 'A')).ToString(CultureInfo.InvariantCulture);
else
s += n2.ToString(CultureInfo.InvariantCulture);
if (n1 > 9)
s += ((char) (n1 - 10 + 'A')).ToString(CultureInfo.InvariantCulture);
else
s += n1.ToString(CultureInfo.InvariantCulture);
if ((i + 1) != bt.Count && (i + 1) % 2 == 0) s += "-";
}
return s;
}
private static string _fingerPrint = string.Empty;
private static string Value()
{
//You don't need to generate the HWID again if it has already been generated. This is better for performance
//Also, your HWID generally doesn't change when your computer is turned on but it can happen.
//It's up to you if you want to keep generating a HWID or not if the function is called.
if (string.IsNullOrEmpty(_fingerPrint))
{
_fingerPrint = GetHash("CPU >> " + CpuId() + "\nBIOS >> " + BiosId() + "\nBASE >> " + BaseId() +
"\nDISK >> " + DiskId() + "\nVIDEO >> " + VideoId() + "\nMAC >> " + MacId());
}
return _fingerPrint;
}
//Return a hardware identifier
private static string Identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementBaseObject mo in moc)
{
if (mo[wmiMustBeTrue].ToString() != "True") continue;
//Only get the first one
if (result != "") continue;
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
return result;
}
//Return a hardware identifier
private static string Identifier(string wmiClass, string wmiProperty)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementBaseObject mo in moc)
{
//Only get the first one
if (result != "") continue;
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
return result;
}
private static string CpuId()
{
//Uses first CPU identifier available in order of preference
//Don't get all identifiers, as it is very time consuming
string retVal = Identifier("Win32_Processor", "UniqueId");
if (retVal != "") return retVal;
retVal = Identifier("Win32_Processor", "ProcessorId");
if (retVal != "") return retVal;
retVal = Identifier("Win32_Processor", "Name");
if (retVal == "") //If no Name, use Manufacturer
{
retVal = Identifier("Win32_Processor", "Manufacturer");
}
//Add clock speed for extra security
retVal += Identifier("Win32_Processor", "MaxClockSpeed");
return retVal;
}
//BIOS Identifier
private static string BiosId()
{
return Identifier("Win32_BIOS", "Manufacturer") + Identifier("Win32_BIOS", "SMBIOSBIOSVersion") +
Identifier("Win32_BIOS", "IdentificationCode") + Identifier("Win32_BIOS", "SerialNumber") +
Identifier("Win32_BIOS", "ReleaseDate") + Identifier("Win32_BIOS", "Version");
}
//Main physical hard drive ID
private static string DiskId()
{
return Identifier("Win32_DiskDrive", "Model") + Identifier("Win32_DiskDrive", "Manufacturer") +
Identifier("Win32_DiskDrive", "Signature") + Identifier("Win32_DiskDrive", "TotalHeads");
}
//Motherboard ID
private static string BaseId()
{
return Identifier("Win32_BaseBoard", "Model") + Identifier("Win32_BaseBoard", "Manufacturer") +
Identifier("Win32_BaseBoard", "Name") + Identifier("Win32_BaseBoard", "SerialNumber");
}
//Primary video controller ID
private static string VideoId()
{
return Identifier("Win32_VideoController", "DriverVersion") + Identifier("Win32_VideoController", "Name");
}
//First enabled network card ID
private static string MacId()
{
return Identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
}
}
}