-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathHWID.cs
56 lines (51 loc) · 1.87 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
using System;
using System.Collections.Generic;
using System.Management;
using System.Security.Cryptography;
using System.Text;
namespace AdvancedBot
{
internal class HWID
{
static internal Dictionary<String, Boolean> blacklist = new Dictionary<String, Boolean>();
internal static Boolean allowed = false;
internal void SetAllowed(Boolean value)
{
allowed = value;
}
internal Boolean isAllowed()
{
return allowed;
}
internal string cachedHwid = null;
internal string getHWID()
{
if (cachedHwid != null) return cachedHwid;
SHA1Managed sha1 = new SHA1Managed();
string[] queries = new string[] { "SELECT SerialNumber FROM Win32_BIOS", //"SELECT SerialNumber FROM Win32_DiskDrive"
"SELECT SerialNumber FROM Win32_BaseBoard",
"SELECT ProcessorId FROM Win32_Processor" };
foreach (string q in queries)
{
using (var mbs = new ManagementObjectSearcher(q))
{
using (ManagementObjectCollection mbsList = mbs.Get())
{
foreach (ManagementObject mo in mbsList)
{
byte[] block = Encoding.UTF8.GetBytes(mo[q.Split(' ')[1]].ToString());
sha1.TransformBlock(block, 0, block.Length, null, 0);
mo.Dispose();
}
}
}
}
sha1.TransformFinalBlock(new byte[0], 0, 0);
return cachedHwid = BitConverter.ToString(sha1.Hash, 0, 12).Replace("-", "");
}
internal string getComputerUsername()
{
return Environment.UserName;
}
}
}