Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.78 KB | None | 0 0
  1. private static string GetHash(string s)
  2.         {
  3.             //Initialize a new MD5 Crypto Service Provider in order to generate a hash
  4.             MD5 sec = new MD5CryptoServiceProvider();
  5.             //Grab the bytes of the variable 's'
  6.             byte[] bt = Encoding.ASCII.GetBytes(s);
  7.             //Grab the Hexadecimal value of the MD5 hash
  8.             return GetHexString(sec.ComputeHash(bt));
  9.         }
  10.  
  11.         private static string GetHexString(IList<byte> bt)
  12.         {
  13.             string s = string.Empty;
  14.             for (int i = 0; i < bt.Count; i++)
  15.             {
  16.                 byte b = bt[i];
  17.                 int n = b;
  18.                 int n1 = n & 15;
  19.                 int n2 = (n >> 4) & 15;
  20.                 if (n2 > 9)
  21.                     s += ((char)(n2 - 10 + 'A')).ToString(CultureInfo.InvariantCulture);
  22.                 else
  23.                     s += n2.ToString(CultureInfo.InvariantCulture);
  24.                 if (n1 > 9)
  25.                     s += ((char)(n1 - 10 + 'A')).ToString(CultureInfo.InvariantCulture);
  26.                 else
  27.                     s += n1.ToString(CultureInfo.InvariantCulture);
  28.                 if ((i + 1) != bt.Count && (i + 1) % 2 == 0) s += "-";
  29.             }
  30.             return s;
  31.         }
  32.         private static string _fingerPrint = string.Empty;
  33.         private static char requestData;
  34.  
  35.         private static string Value()
  36.         {
  37.             //You don't need to generate the HWID again if it has already been generated. This is better for performance
  38.             //Also, your HWID generally doesn't change when your computer is turned on but it can happen.
  39.             //It's up to you if you want to keep generating a HWID or not if the function is called.
  40.             if (string.IsNullOrEmpty(_fingerPrint))
  41.             {
  42.                 _fingerPrint = GetHash("CPU >> " + CpuId() + "\nBIOS >> " + BiosId() + "\nBASE >> " + BaseId() + "\nDISK >> " + DiskId() + "\nVIDEO >> " + VideoId() + "\nMAC >> " + MacId());
  43.             }
  44.             return _fingerPrint;
  45.         }
  46.         //Return a hardware identifier
  47.         private static string Identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
  48.         {
  49.             string result = "";
  50.             System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
  51.             System.Management.ManagementObjectCollection moc = mc.GetInstances();
  52.             foreach (System.Management.ManagementBaseObject mo in moc)
  53.             {
  54.                 if (mo[wmiMustBeTrue].ToString() != "True") continue;
  55.                 //Only get the first one
  56.                 if (result != "") continue;
  57.                 try
  58.                 {
  59.                     result = mo[wmiProperty].ToString();
  60.                     break;
  61.                 }
  62.                 catch
  63.                 {
  64.                 }
  65.             }
  66.             return result;
  67.         }
  68.         //Return a hardware identifier
  69.         private static string Identifier(string wmiClass, string wmiProperty)
  70.         {
  71.             string result = "";
  72.             System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
  73.             System.Management.ManagementObjectCollection moc = mc.GetInstances();
  74.             foreach (System.Management.ManagementBaseObject mo in moc)
  75.             {
  76.                 //Only get the first one
  77.                 if (result != "") continue;
  78.                 try
  79.                 {
  80.                     result = mo[wmiProperty].ToString();
  81.                     break;
  82.                 }
  83.                 catch
  84.                 {
  85.                 }
  86.             }
  87.             return result;
  88.         }
  89.         private static string CpuId()
  90.             {
  91.             //Uses first CPU identifier available in order of preference
  92.             //Don't get all identifiers, as it is very time consuming
  93.             string retVal = Identifier("Win32_Processor", "UniqueId");
  94.             if (retVal != "") return retVal;
  95.             retVal = Identifier("Win32_Processor", "ProcessorId");
  96.             if (retVal != "") return retVal;
  97.             retVal = Identifier("Win32_Processor", "Name");
  98.             if (retVal == "") //If no Name, use Manufacturer
  99.             {
  100.                 retVal = Identifier("Win32_Processor", "Manufacturer");
  101.             }
  102.             //Add clock speed for extra security
  103.             retVal += Identifier("Win32_Processor", "MaxClockSpeed");
  104.             return retVal;
  105.         }
  106.         //BIOS Identifier
  107.         private static string BiosId()
  108.         {
  109.             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");
  110.         }
  111.         //Main physical hard drive ID
  112.         private static string DiskId()
  113.         {
  114.             return Identifier("Win32_DiskDrive", "Model") + Identifier("Win32_DiskDrive", "Manufacturer") + Identifier("Win32_DiskDrive", "Signature") + Identifier("Win32_DiskDrive", "TotalHeads");
  115.         }
  116.         //Motherboard ID
  117.         private static string BaseId()
  118.         {
  119.             return Identifier("Win32_BaseBoard", "Model") + Identifier("Win32_BaseBoard", "Manufacturer") + Identifier("Win32_BaseBoard", "Name") + Identifier("Win32_BaseBoard", "SerialNumber");
  120.         }
  121.         //Primary video controller ID
  122.         private static string VideoId()
  123.         {
  124.             return Identifier("Win32_VideoController", "DriverVersion") + Identifier("Win32_VideoController", "Name");
  125.         }
  126.         //First enabled network card ID
  127.         private static string MacId()
  128.         {
  129.             return Identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
  130.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement