示例#1
0
 protected bool Equals(DwordRegistryKey other)
 {
     return(Data == other.Data);
 }
        private static List <RegistryEntry> GetRegistryEntries(string rootKey, RegistryKey hive)
        {
            RegistryKey          key;
            List <RegistryEntry> entries = new List <RegistryEntry>();

            key = hive.OpenSubKey(rootKey);
            if (key == null)
            {
                return(new List <RegistryEntry>());
            }
            if (key != null && key.SubKeyCount > 1)
            {
                foreach (var k in key.GetSubKeyNames())
                {
                    string      rootKeyLocation = Regex.Replace(key.Name, hive.Name + @"\\", "");
                    RegistryKey subkey          = hive.OpenSubKey(rootKeyLocation + "\\" + k);
                    entries.AddRange(GetRegistryEntries(rootKeyLocation + "\\" + k, hive));
                }
            }

            foreach (var valueName in key.GetValueNames())
            {
                var               rawValue = key.GetValue(valueName, "", RegistryValueOptions.DoNotExpandEnvironmentNames);
                RegistryKeyData   keyValue = null;
                RegistryValueKind kvk      = key.GetValueKind(valueName);

                switch (kvk)
                {
                case RegistryValueKind.String:
                    keyValue = new SZRegistryKey(rawValue);
                    break;

                case RegistryValueKind.DWord:
                    keyValue = new DwordRegistryKey(rawValue);
                    break;

                case RegistryValueKind.ExpandString:
                    keyValue = new EXSZRegistryKey(rawValue);
                    break;

                case RegistryValueKind.MultiString:
                    keyValue = new MultiSZRegistryKey(rawValue);
                    break;

                case RegistryValueKind.QWord:
                    object keyValue3 = key.GetValue(valueName);
                    keyValue = new QwordRegistryKey(rawValue);
                    break;

                case RegistryValueKind.Binary:
                    byte[] binary    = (byte[])rawValue;
                    var    hexstring = ConvertUtility.ByteToHexString(binary);
                    keyValue = new BinaryRegistryKey(hexstring);
                    break;

                case RegistryValueKind.Unknown:
                case RegistryValueKind.None:
                    keyValue = new SZRegistryKey(string.Empty);
                    break;

                default:
                    keyValue = new SZRegistryKey(string.Empty);
                    break;
                }

                entries.Add(new RegistryEntry()
                {
                    Name     = valueName,
                    Data     = keyValue,
                    Type     = key.GetValueKind(valueName),
                    FullPath = key.Name + "\\" + valueName,
                    Location = key.Name
                });
            }

            return(entries);
        }