Получение HardwareId для Inquartos Obfuscator

 

 

Получение HardwareId для Inquartos Obfuscator   HardwareId.Value()

 

 

 

    #region HardwareId

    internal class HardwareId

    {

        #region Value

        private static string hardwareId = string.Empty;

        public static string Value()

        {

            if (string.IsNullOrEmpty(hardwareId))

            {

                try

                {

                    hardwareId = GetHash("CPU=" + cpuId() + "\nBIOS=" + biosId() + "\nBASE=" + baseId());

                }

                catch

                {

                    hardwareId = GetHash(Environment.MachineName);

                }

            }

            return hardwareId;

        }

        #endregion

  

  

        #region GetHash

        private static string GetHash(string s)

        {

            MD5 sec = new MD5CryptoServiceProvider();

            ASCIIEncoding enc = new ASCIIEncoding();

            byte[] bt = enc.GetBytes(s);

            return GetHexString(sec.ComputeHash(bt));

        }

        #endregion

 

        #region GetHexString

        private static string GetHexString(byte[] bt)

        {

            string s = string.Empty;

            for (int i = 0; i < bt.Length; i++)

            {

                byte b = bt[i];

                int n, n1, n2;

                n = (int)b;

                n1 = n & 15;

                n2 = (n >> 4) & 15;

                if (n2 > 9)

                    s += ((char)(n2 - 10 + (int)'A')).ToString();

                else

                    s += n2.ToString();

                if (n1 > 9)

                    s += ((char)(n1 - 10 + (int)'A')).ToString();

                else

                    s += n1.ToString();

                if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";

            }

            return s.Trim();

        }

        #endregion

 

 

        #region Original Device ID Getting Code

        //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.ManagementObject mo in moc)

            {

                if (mo[wmiMustBeTrue].ToString() == "True")

                {

                    //Only get the first one

                    if (result == "")

                    {

                        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.ManagementObject mo in moc)

            {

                //Only get the first one

                if (result == "")

                {

                    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 very time consuming

            string retVal = identifier("Win32_Processor", "UniqueId");

            if (retVal == "") //If no UniqueID, use ProcessorID

            {

                retVal = identifier("Win32_Processor", "ProcessorId");

                if (retVal == "") //If no ProcessorId, use Name

                {

                    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");

        }

      

        //Motherboard ID

        private static string baseId()

        {

            return identifier("Win32_BaseBoard", "Model")

            + identifier("Win32_BaseBoard", "Manufacturer")

            + identifier("Win32_BaseBoard", "Name")

            + identifier("Win32_BaseBoard", "SerialNumber");

        }

   

        #endregion

    }

    #endregion

 

 

 
26.01.2009

Отзывы и комментарии

 


 
Тема
Ваше имя
Почтовый адрес
Текст сообщения
Ключ защиты:
Защита от спама
 
 
 
 
10.12  .NET Reactor
15.11  n
15.11  C# ClickOnce
 
01.08  Task Context
01.08  XLSX в Mono