Esempio n. 1
0
 /// <summary>
 /// Initializes a new Boot Configuration Database.
 /// </summary>
 /// <param name="root">The registry key at the root of the database.</param>
 /// <returns>The BCD store.</returns>
 public static Store Initialize(RegistryKey root)
 {
     RegistryKey descKey = root.CreateSubKey("Description");
     descKey.SetValue("KeyName", "BCD00000001");
     root.CreateSubKey("Objects");
     return new Store(root);
 }
        private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            if (e.NewValue == e.OldValue)
            {
                return;
            }

            keyVals.Clear();

            void PopulateListView(RegistryKey registryKey, RegistryHive registryBase)
            {
                if (registryKey.ValueCount > 0)
                {
                    foreach (var keyval in registryKey.GetValueNames())
                    {
                        keyVals.Add(new KeyVal
                        {
                            Name         = keyval,
                            DataTypeEnum = (DataTypeEnum)registryKey.GetValueType(keyval),
                            Data         = registryKey.GetValueRaw(keyval),
                            Path         = registryKey.Name,
                            Hive         = registryBase
                        });
                    }
                }
            }

            if (e.NewValue is RegistryKeyTreeView registryKeyTreeView)
            {
                RegistryKey currKey = registryKeyTreeView.AttachedHive.Root.OpenSubKey(registryKeyTreeView.Path);

                if (currKey == null)
                {
                    Debugger.Break();
                }

                currentPathTxt.Text      = "Computer" + "\\" + registryKeyTreeView.Root.Name + "\\" + registryKeyTreeView.Path;
                selectedIconImage.Source = registryKeyTreeView.ImageSource;
                PopulateListView(currKey, registryKeyTreeView.AttachedHive);
            }
            else if (e.NewValue is RegistryHiveTreeView registryHiveTreeView)
            {
                RegistryKey currKey = registryHiveTreeView.AttachedHive.Root;

                currentPathTxt.Text      = "Computer" + "\\" + registryHiveTreeView.Name;
                selectedIconImage.Source = new BitmapImage(new Uri("Assets/RegistryIcon.png", UriKind.Relative));
                PopulateListView(currKey, registryHiveTreeView.AttachedHive);
            }
            else
            {
                currentPathTxt.Text      = "Computer";
                selectedIconImage.Source = computerBitmap;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the Store class.
 /// </summary>
 /// <param name="key">The registry key that is the root of the configuration database.</param>
 public Store(RegistryKey key)
 {
     _store = new DiscUtilsRegistryStorage(key);
 }
Esempio n. 4
0
 private static void InnerRead(RegistryKey key, XDictionary<string, XDictionary<string, ValueObject>> data)
 {
     foreach (var name in key.GetValueNames())
     {
         data[key.Name][name] = new ValueObject(key.GetValueType(name), key.GetValue(name));
     }
     foreach (var sub in key.GetSubKeyNames())
     {
         InnerRead(key.OpenSubKey(sub), data);
     }
 }
Esempio n. 5
0
        private async Task<bool> BOnlyInnerCompare(RegistryKey A, RegistryKey B, string root)
        {

            List<Task<bool>> tasks = new List<Task<bool>>();
            List<bool> bools = new List<bool>();
            try
            {
                if (B != null)
                {
                    // Process A
                    string[] bVals;
                    lock (HiveB)
                        bVals = B.GetValueNames();
                    string[] aVals = new string[0];
                    if (A != null)
                        lock (HiveA)
                            aVals = A.GetValueNames();
                    foreach (var Name in bVals)
                    {
                        string EntryName;
                        lock (HiveB)
                            EntryName = root + B.Name + "::" + Name;
                        var dat = new Data();
                        lock (HiveB)
                            dat.SetB(B.GetValue(Name), B.GetValueType(Name));
                        if (aVals.Contains(Name, StringComparer.CurrentCultureIgnoreCase))
                            lock (HiveA)
                                dat.SetA(A.GetValue(Name), A.GetValueType(Name));
                        lock(Output)
                            Output.Add(EntryName, dat);
                    }
                    string[] BSubKeys;
                    lock (HiveB)
                        BSubKeys = B.GetSubKeyNames();
                    string[] ASubKeys = new string[0];
                    if (A != null)
                        lock (HiveA)
                            ASubKeys = A.GetSubKeyNames();
                    tasks.AddRange(BSubKeys.Select(async keyName => 
                    {
                        RegistryKey aSub, bSub;
                        lock (HiveB)
                            bSub = B.OpenSubKey(keyName);
                        lock (HiveA)
                            aSub = A == null
                                       ? null
                                       : ASubKeys.Contains(keyName, StringComparer.CurrentCultureIgnoreCase)
                                             ? A.OpenSubKey(keyName)
                                             : null;
                        return await BOnlyInnerCompare(aSub, bSub, root + keyName + @"\");
                    }));
                }

                /*
                return Task.Factory.StartNew(() =>
                                             tasks.AsParallel().Aggregate(true, (ret, task) =>
                                             {
                                                 task.Wait();
                                                 return ret && task.Result;
                                             }), TaskCreationOptions.AttachedToParent);
                */
                return tasks.AsParallel().Aggregate(true, (ret, task) =>
                                             {
                                                 task.Wait();
                                                 return ret && task.Result;
                                             });
            }
            catch (Exception e)
            {
                throw;
            }
        }
Esempio n. 6
0
        private Task<bool> InnerCompare(RegistryKey A, RegistryKey B, string root) // TODO:  Adjust to match the BOnly comparison (below)
        {

            List<Task<bool>> tasks = new List<Task<bool>>();
            try
            {
                if (A != null)
                {
                    // Process A
                    string[] aVals;
                    lock (HiveA)
                        aVals = A.GetValueNames();
                    foreach (var Name in aVals)
                    {
                        string EntryName;
                        lock (HiveA)
                            EntryName = root + A.Name + "::" + Name;
                        var dat = new Data();
                        lock (HiveA)
                            dat.SetA(A.GetValue(Name), A.GetValueType(Name));
                        Output.Add(EntryName, dat);
                    }
                    string[] ASubKeys;
                    lock (HiveA)
                        ASubKeys = A.GetSubKeyNames();
                    string[] BSubKeys = new string[0];
                    if (B != null)
                        lock (HiveB)
                            BSubKeys = B.GetSubKeyNames();
                    tasks.AddRange(ASubKeys.AsParallel().Select(keyName =>
                        {
                            RegistryKey aSub, bSub;
                            lock (HiveA)
                                aSub = A.OpenSubKey(keyName);
                            lock (HiveB)
                                bSub = B == null
                                           ? null
                                           : BSubKeys.Contains(keyName, StringComparer.CurrentCultureIgnoreCase)
                                                 ? B.OpenSubKey(keyName)
                                                 : null;
                            return InnerCompare(aSub, bSub, root + keyName + @"\");
                        }));
                }
                if (B != null)
                {
                    // Process B
                    string[] bVals;
                    lock (HiveB)
                        bVals = B.GetValueNames();

                    foreach (var Name in bVals)
                    {
                        string EntryName;
                        lock (HiveB)
                            EntryName = root + B.Name + "::" + Name;
                        Data dat = Output.ContainsKey(EntryName) ? Output[EntryName] : new Data();
                        lock (HiveB)
                            dat.SetB(B.GetValue(Name), B.GetValueType(Name));
                        Output[EntryName] = dat;
                    }
                    string[] BSubKeys;
                    lock (HiveB)
                        BSubKeys = B.GetSubKeyNames();
                    tasks.AddRange(BSubKeys.AsParallel().Select(keyName =>
                        {
                            RegistryKey bSub;
                            lock (HiveB)
                                bSub = B.OpenSubKey(keyName);
                            return InnerCompare(null, bSub, root + keyName + @"\");
                        }));
                }

                return Task.Factory.StartNew(() =>
                                             tasks.Aggregate(true, (ret, task) =>
                                                 {
                                                     task.Wait();
                                                     return ret && task.Result;
                                                 }), TaskCreationOptions.AttachedToParent);
            }
            catch (Exception e)
            {
                throw;
            }
        }
 public DiscUtilsRegistryStorage(RegistryKey key)
 {
     _rootKey = key;
 }
Esempio n. 8
0
        private void WriteKey(string path, RegistryKey key)
        {
            if (key == null)
            {
                return;
            }

            PSObject psObj = PSObject.AsPSObject(key);

            string[] valueNames = key.GetValueNames();
            for (int i = 0; i < valueNames.Length; ++i)
            {
                if (string.IsNullOrEmpty(valueNames[i]))
                {
                    valueNames[i] = DefaultValueName;
                }
            }

            psObj.Properties.Add(new PSNoteProperty("Property", valueNames));
            WriteItemObject(psObj, path.Trim('\\'), true);
        }
Esempio n. 9
-1
        internal bool ApplyTo(RegistryKey Root, Action<string> Log = null)
        {
            if (Root == null)
                throw new ArgumentNullException("Root");
            bool status = true;
            try
            {
                foreach (var path in Data)
                {
                    try
                    {
                        RegistryKey currentPath = path.Key.Split('\\')
                                                      .Aggregate(Root, (current, sub) => current.CreateSubKey(sub));
                        foreach (var item in path.Value)
                        {
                            try
                            {
                                currentPath.SetValue(item.Key, item.Value.Value, item.Value.Type);
                            }
                            catch (Exception e)
                            {
                                if (Log != null)
                                    Log(e.Message + '\n' + e.StackTrace);
                                status = false;
                            }

                        }
                    }
                    catch (Exception e)
                    {
                        if (Log != null)
                            Log(e.Message + '\n' + e.StackTrace);
                        status = false;
                    }
                }

            }
            catch (Exception e)
            {
                if (Log != null)
                    Log(e.Message + '\n' + e.StackTrace);
                status = false;
            }
            return status;
        }