private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName)
        {
            if (keyName == null)
            {
                throw new ArgumentNullException("keyName");
            }
            int    num = keyName.IndexOf('\\');
            string text;

            if (num != -1)
            {
                text = keyName.Substring(0, num).ToUpper(CultureInfo.InvariantCulture);
            }
            else
            {
                text = keyName.ToUpper(CultureInfo.InvariantCulture);
            }
            uint        num2 = < PrivateImplementationDetails >.ComputeStringHash(text);
            RegistryKey result;

            if (num2 <= 1097425318U)
            {
                if (num2 != 126972219U)
                {
                    if (num2 != 457190004U)
                    {
                        if (num2 == 1097425318U)
                        {
                            if (text == "HKEY_CLASSES_ROOT")
                            {
                                result = Registry.ClassesRoot;
                                goto IL_169;
                            }
                        }
                    }
                    else if (text == "HKEY_LOCAL_MACHINE")
                    {
                        result = Registry.LocalMachine;
                        goto IL_169;
                    }
                }
                else if (text == "HKEY_CURRENT_CONFIG")
                {
                    result = Registry.CurrentConfig;
                    goto IL_169;
                }
            }
            else if (num2 <= 1568329430U)
            {
                if (num2 != 1198714601U)
                {
                    if (num2 == 1568329430U)
                    {
                        if (text == "HKEY_CURRENT_USER")
                        {
                            result = Registry.CurrentUser;
                            goto IL_169;
                        }
                    }
                }
                else if (text == "HKEY_USERS")
                {
                    result = Registry.Users;
                    goto IL_169;
                }
            }
            else if (num2 != 2823865611U)
            {
                if (num2 == 3554990456U)
                {
                    if (text == "HKEY_PERFORMANCE_DATA")
                    {
                        result = Registry.PerformanceData;
                        goto IL_169;
                    }
                }
            }
            else if (text == "HKEY_DYN_DATA")
            {
                result = RegistryKey.GetBaseKey(RegistryKey.HKEY_DYN_DATA);
                goto IL_169;
            }
            throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", new object[]
            {
                "keyName"
            }));
IL_169:
            if (num == -1 || num == keyName.Length)
            {
                subKeyName = string.Empty;
            }
            else
            {
                subKeyName = keyName.Substring(num + 1, keyName.Length - num - 1);
            }
            return(result);
        }
Exemple #2
0
        private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName)
        {
            string str;

            if (keyName == null)
            {
                throw new ArgumentNullException("keyName");
            }
            int index = keyName.IndexOf('\\');

            if (index != -1)
            {
                str = keyName.Substring(0, index).ToUpper(CultureInfo.InvariantCulture);
            }
            else
            {
                str = keyName.ToUpper(CultureInfo.InvariantCulture);
            }
            RegistryKey currentUser = null;

            switch (str)
            {
            case "HKEY_CURRENT_USER":
                currentUser = CurrentUser;
                break;

            case "HKEY_LOCAL_MACHINE":
                currentUser = LocalMachine;
                break;

            case "HKEY_CLASSES_ROOT":
                currentUser = ClassesRoot;
                break;

            case "HKEY_USERS":
                currentUser = Users;
                break;

            case "HKEY_PERFORMANCE_DATA":
                currentUser = PerformanceData;
                break;

            case "HKEY_CURRENT_CONFIG":
                currentUser = CurrentConfig;
                break;

            case "HKEY_DYN_DATA":
                currentUser = RegistryKey.GetBaseKey(RegistryKey.HKEY_DYN_DATA);
                break;

            default:
                throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", new object[] { "keyName" }));
            }
            if ((index == -1) || (index == keyName.Length))
            {
                subKeyName = string.Empty;
                return(currentUser);
            }
            subKeyName = keyName.Substring(index + 1, (keyName.Length - index) - 1);
            return(currentUser);
        }
Exemple #3
0
        private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName)
        {
            if (keyName == null)
            {
                throw new ArgumentNullException("keyName");
            }
            int    length = keyName.IndexOf('\\');
            string s      = length == -1 ? keyName.ToUpper(CultureInfo.InvariantCulture) : keyName.Substring(0, length).ToUpper(CultureInfo.InvariantCulture);
            // ISSUE: reference to a compiler-generated method
            uint        stringHash = \u003CPrivateImplementationDetails\u003E.ComputeStringHash(s);
            RegistryKey registryKey;

            if (stringHash <= 1097425318U)
            {
                if ((int)stringHash != 126972219)
                {
                    if ((int)stringHash != 457190004)
                    {
                        if ((int)stringHash == 1097425318 && s == "HKEY_CLASSES_ROOT")
                        {
                            registryKey = Registry.ClassesRoot;
                            goto label_23;
                        }
                    }
                    else if (s == "HKEY_LOCAL_MACHINE")
                    {
                        registryKey = Registry.LocalMachine;
                        goto label_23;
                    }
                }
                else if (s == "HKEY_CURRENT_CONFIG")
                {
                    registryKey = Registry.CurrentConfig;
                    goto label_23;
                }
            }
            else if (stringHash <= 1568329430U)
            {
                if ((int)stringHash != 1198714601)
                {
                    if ((int)stringHash == 1568329430 && s == "HKEY_CURRENT_USER")
                    {
                        registryKey = Registry.CurrentUser;
                        goto label_23;
                    }
                }
                else if (s == "HKEY_USERS")
                {
                    registryKey = Registry.Users;
                    goto label_23;
                }
            }
            else if ((int)stringHash != -1471101685)
            {
                if ((int)stringHash == -739976840 && s == "HKEY_PERFORMANCE_DATA")
                {
                    registryKey = Registry.PerformanceData;
                    goto label_23;
                }
            }
            else if (s == "HKEY_DYN_DATA")
            {
                registryKey = RegistryKey.GetBaseKey(RegistryKey.HKEY_DYN_DATA);
                goto label_23;
            }
            throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", (object)"keyName"));
label_23:
            subKeyName = length == -1 || length == keyName.Length ? string.Empty : keyName.Substring(length + 1, keyName.Length - length - 1);
            return(registryKey);
        }
        [System.Security.SecurityCritical]  // auto-generated
        private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName)
        {
            if (keyName == null)
            {
                throw new ArgumentNullException(nameof(keyName));
            }

            string basekeyName;
            int    i = keyName.IndexOf('\\');

            if (i != -1)
            {
                basekeyName = keyName.Substring(0, i).ToUpper(System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                basekeyName = keyName.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
            }
            RegistryKey basekey = null;

            switch (basekeyName)
            {
            case "HKEY_CURRENT_USER":
                basekey = Registry.CurrentUser;
                break;

            case "HKEY_LOCAL_MACHINE":
                basekey = Registry.LocalMachine;
                break;

            case "HKEY_CLASSES_ROOT":
                basekey = Registry.ClassesRoot;
                break;

            case "HKEY_USERS":
                basekey = Registry.Users;
                break;

            case "HKEY_PERFORMANCE_DATA":
                basekey = Registry.PerformanceData;
                break;

            case "HKEY_CURRENT_CONFIG":
                basekey = Registry.CurrentConfig;
                break;

#if !FEATURE_CORECLR
            case "HKEY_DYN_DATA":
                basekey = RegistryKey.GetBaseKey(RegistryKey.HKEY_DYN_DATA);
                break;
#endif
            default:
                throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", nameof(keyName)));
            }
            if (i == -1 || i == keyName.Length)
            {
                subKeyName = string.Empty;
            }
            else
            {
                subKeyName = keyName.Substring(i + 1, keyName.Length - i - 1);
            }
            return(basekey);
        }