Ejemplo n.º 1
0
 public void AddSubKeys(string path)
 {
     subKeys = RegHelper.GetSubKeys(path);
     foreach (string sub in subKeys)
     {
         subKeys.Add(sub);
     }
 }
Ejemplo n.º 2
0
 public RegKey(string key, string cmt)
 {
     Index   = _index++;
     Path    = key;
     Comment = cmt;
     AddSubKeys(key);
     leaf          = GetLeaf(key);
     RegProperties = RegHelper.GetValuesAndData(key);
     Properties    = RegHelper.GetValuesAndDataToDict(key);
 }
Ejemplo n.º 3
0
        public RegHive(string regPath, subKey sk = null)
        {
            hivePath = regPath;
            if (null != sk)
            {
                sbkey = sk;
            }
            subKeys = RegHelper.GetSubKeys(regPath);
            int cnt = 0;

            foreach (string sub in subKeys)
            {
                string fullpath = hivePath + "\\" + sub;

                if (cnt % 500 == 0)
                {
                    Controller.UpdateProgress("Reading (" + cnt + ") " + fullpath, false);
                    //If closing
                    if (Controller.shouldAbort)
                    {
                        return;
                    }
                }
                cnt++;

                RegKey rk = new RegKey(fullpath, "");
                regKeys.Add(rk);

                if (sk != null)
                {
                    string fullpath2 = fullpath + "\\" + sk.subPath;
                    string result    = RegHelper.GetValueForProperty(fullpath2, sk.property);
                    if (!string.IsNullOrEmpty(result))
                    {
                        if (propertyMap.ContainsKey(result))
                        {
                            propertyMap[result].Add(fullpath);
                        }
                        else
                        {
                            propertyMap.Add(result, new List <string> {
                                fullpath
                            });
                        }
                    }
                } //if sk not null
            }
        }         //ctor
Ejemplo n.º 4
0
        public static void GetAllSubKeys_Recursive(TreeNode node)
        {
            if (isDone(node))
            {
                return;
            }

            string fullPath = node.Name;

            int    idx = fullPath.IndexOf("\\");
            string HK  = fullPath.Substring(0, idx);
            // string nodeKey = fullPath.Substring(idx + 1);


            Queue <TreeNode> queue = new Queue <TreeNode>();

            queue.Enqueue(node);

            while (queue.Count > 0)
            {
                TreeNode currentNode = queue.Dequeue();

                if (Controller.shouldAbort)
                {
                    return;
                }

                if (Index % 500 == 0)
                {
                    Controller.UpdateProgress("Adding Node (" + Index + ") " + currentNode.Name, false);
                    //If closing
                }
                Index++;


                string      myKey = currentNode.Name.Substring(idx + 1);
                RegistryKey rk    = RegHelper.HKMap[HK].OpenSubKey(myKey);

                if (rk == null)
                {
                    return;
                }

                string[] subkeys  = rk.GetSubKeyNames().OrderBy(p => p).ToArray();
                string   nodeName = "";
                foreach (string key in subkeys)
                {
                    nodeName = currentNode.Name + "\\" + key;

                    //Check to see if middle nodes exists or not
                    if (!currentNode.Nodes.ContainsKey(nodeName))
                    {
                        TreeNode nd = new TreeNode(key);
                        nd.Name = nodeName;
                        //Need to get its  values
                        RegKey regK = new RegKey(nodeName, "", RegHelper.GetValuesAndData(nodeName));
                        nd.Tag = regK;

                        if (nd != node)
                        {
                            nd.ForeColor = node.ForeColor;
                        }

                        currentNode.Nodes.Add(nd);
                    }
                    if (!isDone(currentNode.Nodes[nodeName]))
                    {
                        queue.Enqueue(currentNode.Nodes[nodeName]);
                    }
                }
                //mark this node done already
                ((RegKey)currentNode.Tag).Done = true;
            } //while queue.count>0
        }
Ejemplo n.º 5
0
        public static TreeNode  AddKey(TreeNode rootNode, RegistryKey HKXX, string key)
        {
            //Logger.LogMsg("AddKey:" + key);

            RegistryKey rk = HKXX.OpenSubKey(key);

            // RegistryKey rk = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine,
            // RegistryView.Registry64).OpenSubKey(key);


            if (rk == null)
            {
                Logger.LogMsg(HKXX.Name + "\\" + key + " doesn't exist.");

                return(null);
            }
            rk.Close();

            //Check to see if HKXX exists, if not create it
            TreeNode HKNode = null;

            if (!rootNode.Nodes.ContainsKey(HKXX.Name))
            {
                TreeNode hk = new TreeNode(HKXX.Name);
                hk.Name = HKXX.Name;

                //hk.Expand(); //HKCR has many nodes, so don't expand
                rootNode.Nodes.Add(hk);
                HKNode = hk;
            }
            else
            {
                HKNode = rootNode.Nodes[HKXX.Name];
            }

            //Now add other nodes in the middle of the path
            string[] middleNames = key.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
            string   nodeName    = "";
            TreeNode parent      = HKNode;
            TreeNode current     = null;

            for (int i = 0; i < middleNames.Length; i++)
            {
                nodeName = parent.Name + "\\" + middleNames[i];
                //Check to see if middle nodes exists or not
                if (!parent.Nodes.ContainsKey(nodeName))
                {
                    TreeNode nd = new TreeNode(middleNames[i]);
                    nd.Name = nodeName;

                    //Need to get its  values
                    RegKey regK = new RegKey(nodeName, "", RegHelper.GetValuesAndData(HKXX, nodeName.Replace(HKNode.Name + "\\", "")));
                    nd.Tag = regK;


                    parent.Nodes.Add(nd);
                }

                parent  = parent.Nodes[nodeName];
                current = parent;
            }

            //now current is the last key, we need to get its subkeys recurivsly
            if (Controller.sqlRegKeys.ContainsKey(current.Name))
            {
                Reason r = Controller.sqlRegKeys[current.Name];
                if (r.cleanable == true)
                {
                    ((RegKey)current.Tag).IsSQLOwned = true;
                    ((RegKey)current.Tag).IsSQLRoot  = true;
                    current.ForeColor = Color.DarkBlue;
                }
                else
                {
                    ((RegKey)current.Tag).IsSQLOwned = false;
                    ((RegKey)current.Tag).IsSQLRoot  = true;
                    current.ForeColor = Color.DarkBlue;//same color anyway
                }
            }
            else
            {
                /*
                 * 2018 - 02 - 06 21:36:48[ERROR][RegNode.cs:231:AddKey]sqlRegKeys doesn't have this node name! HKEY_CLASSES_ROOT\TypeLib\{3F98D457-551B-48C5-BDE8-7FDECCD5AFA5} vs key:TYPELIB\{3F98D457-551B-48C5-BDE8-7FDECCD5AFA5}
                 * 2018 - 02 - 06 21:36:49[ERROR][RegNode.cs:231:AddKey]sqlRegKeys doesn't have this node name! HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\Snapins\{d52e5f54-75d9-4a93-91b7-2215ea5cbed2} vs key:Software\Microsoft\MMC\Snapins\{d52e5f54-75d9-4a93-91b7-2215ea5cbed2}
                 * 2018 - 02 - 06 21:36:49[ERROR][RegNode.cs:231:AddKey]sqlRegKeys doesn't have this node name! HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\Snapins\{f66ae3a2-97c7-4e45-9c70-4ecea8b3bfa0} vs key:Software\Microsoft\MMC\Snapins\{f66ae3a2-97c7-4e45-9c70-4ecea8b3bfa0}
                 *
                 * I got above error in some cases, but it doesn't matther, because GetAllSubKeys_Recursive() will still be called on it.
                 * just IsSQLRoot is not able to set.
                 */

                Logger.LogError("sqlRegKeys doesn't have this node name! " + current.Name + " vs key:" + key);
            }

            GetAllSubKeys_Recursive(current);

            return(current);
            //  Logger.LogMsg("AddKey " + key);
        }