Esempio n. 1
0
        public void Load(string fullPath)
        {
            using (StreamReader reader = new StreamReader(fullPath))
            {
                // Read the first line to determine the format.

                string line = reader.ReadLine();
                if (line != "REGEDIT4" && line != "Windows Registry Editor Version 5.00")
                {
                    throw new System.ApplicationException("The first line of the registry file is '" + line + "', but the expected first line is 'REGEDIT4' or 'Windows Registry Editor Version 5.00'.");
                }

                // REGEDIT version 4 saves expandable strings using ANSI encoding, but version 5 uses Unicode encoding.

                bool unicode = line == "Windows Registry Editor Version 5.00";
                RegistryCaptureKey currentKey = null;

                line = reader.ReadLine();

                for ( ; ;)
                {
                    if (line == null)
                    {
                        break;
                    }

                    Match match;
                    if ((match = m_keyRegex.Match(line)).Success)
                    {
                        currentKey = LoadKey(match);
                        if (currentKey != null)
                        {
                            m_keys.Add(currentKey.Path, currentKey);
                        }
                        line = reader.ReadLine();
                    }
                    else if ((match = m_defaultValueRegex.Match(line)).Success)
                    {
                        RegistryCaptureValue value = LoadDefaultValue(match);
                        if (currentKey != null && value != null)
                        {
                            currentKey.Add(value);
                        }
                        line = reader.ReadLine();
                    }
                    else if ((match = m_valueRegex.Match(line)).Success)
                    {
                        RegistryCaptureValue value = LoadValue(match, unicode, reader, ref line);
                        if (currentKey != null && value != null)
                        {
                            currentKey.Add(value);
                        }
                    }
                    else
                    {
                        line = reader.ReadLine();
                    }
                }
            }
        }
Esempio n. 2
0
        protected void Load(RegistryCaptureKey key, IParentElement component)
        {
            // Iterate.

            foreach (RegistryCaptureKey subKey in key.SubKeys)
            {
                Load(subKey, component);
            }

            // Iterate over values.

            foreach (RegistryCaptureValue value in key.Values)
            {
                // Add the common information.

                RegistryValue registryValue = new RegistryValue();
                if (!string.IsNullOrEmpty(value.Name))
                {
                    registryValue.Name = value.Name;
                }
                registryValue.Action = RegistryValue.ActionType.write;
                registryValue.Root   = GetRegistryRoot(key.Root);
                registryValue.Key    = key.RootRelativePath;

                // Add the type specific value.

                if (value is RegistryCaptureStringValue)
                {
                    registryValue.Type  = RegistryValue.TypeType.@string;
                    registryValue.Value = GetValue((RegistryCaptureStringValue)value);
                }
                else if (value is RegistryCaptureDWordValue)
                {
                    registryValue.Type  = RegistryValue.TypeType.integer;
                    registryValue.Value = GetValue((RegistryCaptureDWordValue)value);
                }
                else if (value is RegistryCaptureBinaryValue)
                {
                    registryValue.Type  = RegistryValue.TypeType.binary;
                    registryValue.Value = GetValue((RegistryCaptureBinaryValue)value);
                }
                else if (value is RegistryCaptureExpandStringValue)
                {
                    registryValue.Type  = RegistryValue.TypeType.@string;
                    registryValue.Value = GetValue((RegistryCaptureExpandStringValue)value);
                }
                else if (value is RegistryCaptureMultiStringValue)
                {
                    registryValue.Type = RegistryValue.TypeType.multiString;

                    foreach (string multiStringValueContent in ((RegistryCaptureMultiStringValue)value).Value)
                    {
                        MultiStringValue multiStringValue = new MultiStringValue();
                        multiStringValue.Content = multiStringValueContent;
                        registryValue.AddChild(multiStringValue);
                    }
                }
                else
                {
                    registryValue.Type  = RegistryValue.TypeType.@string;
                    registryValue.Value = GetValue(value);
                }

                component.AddChild(registryValue);
            }
        }
Esempio n. 3
0
 public void Add(RegistryCaptureKey key)
 {
     m_subKeys[key.Name] = key;
 }