Example #1
0
        private static int Add_HKCR_Patches()
        {
            int cnt = 0;


            /****************************************************************************************************/
            //HKEY_CLASSES_ROOT\Installer\Patches
            /****************************************************************************************************/
            //HKEY_CLASSES_ROOT\Installer\Patches\023089E60AE02D343916E2D48AFCAA73\SourceList

            string sub = "Patches";

            Controller.UpdateProgress(@"Analyzing HKEY_CLASSES_ROOT\Installer\" + sub + "...", true);
            subKey sk = new subKey("SourceList", "PackageName");
            //   RegHive reghive = new RegHive(@"HKEY_CLASSES_ROOT\Installer\" + sub, sk);

            RegHive reghive = Controller.regHives[@"HKEY_CLASSES_ROOT\Installer\Patches"];

            foreach (string key in reghive.subKeys)
            {
                string reg = String.Format(@"HKEY_CLASSES_ROOT\Installer\" + sub + @"\{0}", key);
                //  Controller.UpdateProgress("Comparing " + reg);

                //for Patches, use Patch codes!!

                if (foundCompressedPatchCode.Contains(key) ||
                    sumSQLProduct.compressedPatchCodes.Contains(key))
                {
                    if (!Controller.sqlRegKeys.ContainsKey(reg))
                    {
                        string comment = "Patch code:" + key;
                        if (sumSQLProduct.patchCodeToName.ContainsKey(key))
                        {
                            comment = sumSQLProduct.patchCodeToName[key];
                        }


                        cnt++;
                        Controller.sqlRegKeys.Add(reg,
                                                  new Reason(SourceType.Installer_PatchCode, key, comment, true));
                    }

                    if (!foundCompressedPatchCode.Contains(key))
                    {
                        foundCompressedPatchCode.Add(key);
                    }
                }
            }

            //check source->packageName, whether match?
            foreach (KeyValuePair <string, List <string> > kv in reghive.propertyMap)
            {
                //check msp as well, sumSQLProduct.packageNames may not have .msp but it could have.msi file
                if (sumSQLProduct.packageNames.Contains(Path.GetFileName(kv.Key).ToLower()) ||
                    sumSQLProduct.packageNames.Contains(Path.GetFileNameWithoutExtension(kv.Key).ToLower() + ".msi")
                    )
                {
                    foreach (string path in kv.Value)
                    {
                        string comment = "Package name matches:" + kv.Key;
                        string name1   = Path.GetFileName(kv.Key).ToLower();
                        string name2   = Path.GetFileNameWithoutExtension(kv.Key).ToLower() + ".msi";
                        if (sumSQLProduct.packageToName.ContainsKey(name1))
                        {
                            comment = sumSQLProduct.packageToName[name1];
                        }

                        else if (sumSQLProduct.packageToName.ContainsKey(name2))
                        {
                            comment = sumSQLProduct.packageToName[name2];
                        }


                        if (!Controller.sqlRegKeys.ContainsKey(path))
                        {
                            cnt++;
                            Controller.sqlRegKeys.Add(path,
                                                      new Reason(SourceType.FromMSI_PackageName, kv.Key, comment, true));
                        }
                        int    start = path.IndexOf("Patches\\") + "Patches\\".Length;
                        string code  = path.Substring(start, 32);

                        if (!foundCompressedPatchCode.Contains(code))
                        {
                            foundCompressedPatchCode.Add(code);
                        }
                        if (!sumSQLProduct.patchCodeToName.ContainsKey(code))
                        {
                            sumSQLProduct.patchCodeToName.Add(code, comment);
                        }
                    }
                }
            }
            Controller.UpdateProgress("Add_HKCR_Patches keys:" + cnt, true);
            return(cnt);
        }
Example #2
0
        } //Add

        private static int Add_HKCR_Products()
        {
            int cnt = 0;
            /****************************************************************************************************/
            //HKEY_CLASSES_ROOT\Installer\Products
            /****************************************************************************************************/
            //HKEY_CLASSES_ROOT\Installer\Products\FCB7990CA27B16A4B88236108DBC3510\SourceList
            string sub = "Products";

            Controller.UpdateProgress(@"Analyzing HKEY_CLASSES_ROOT\Installer\" + sub + "...", true);
            subKey sk = new subKey("SourceList", "PackageName");
            //  RegHive reghive = new RegHive(@"HKEY_CLASSES_ROOT\Installer\" + sub, sk);
            RegHive reghive = Controller.regHives[@"HKEY_CLASSES_ROOT\Installer\Products"];

            //first, check product code

            foreach (string key in reghive.subKeys)
            {
                string reg = String.Format(@"HKEY_CLASSES_ROOT\Installer\" + sub + @"\{0}", key);
                //  Controller.UpdateProgress("Comparing " + reg);


                string comment = "Product code:" + key;
                if (sumSQLProduct.productCodeToName.ContainsKey(key))
                {
                    comment = sumSQLProduct.productCodeToName[key];
                }

                if (foundCompressedProductCodes.Contains(key) ||
                    sumSQLProduct.compressedProductCodes.Contains(key)
                    )
                {
                    if (!Controller.sqlRegKeys.ContainsKey(reg))
                    {
                        cnt++;
                        Controller.sqlRegKeys.Add(reg,
                                                  new Reason(SourceType.Installer_ProductCode, key, comment, true));
                    }
                    if (!foundCompressedProductCodes.Contains(key))
                    {
                        foundCompressedProductCodes.Add(key);
                    }

                    //Need to add patch information
                    string pKey = reg + "\\Patches";
                    if (RegHelper.IsKeyExist(pKey))
                    {
                        RegKey rk = new RegKey(pKey, "");
                        if (rk.Properties.ContainsKey("Patches"))
                        {
                            string[] patches = rk.Properties["Patches"][1].Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string s in patches)
                            {
                                if (!foundCompressedPatchCode.Contains(s.Trim()))
                                {
                                    foundCompressedPatchCode.Add(s.Trim());
                                }
                                if (!sumSQLProduct.patchCodeToName.ContainsKey(s.Trim()))
                                {
                                    sumSQLProduct.patchCodeToName.Add(s.Trim(), comment);
                                }
                            }
                        }
                    }
                } //match
            }
            //second, check package name to add more
            foreach (KeyValuePair <string, List <string> > kv in reghive.propertyMap)
            {
                //Just check *.msi, since we don't ship xml about patch.
                if (sumSQLProduct.packageNames.Contains(Path.GetFileName(kv.Key).ToLower()))
                {
                    foreach (string path in kv.Value)
                    {
                        string comment = "Package name matches:" + kv.Key;
                        string name1   = Path.GetFileName(kv.Key).ToLower();
                        if (sumSQLProduct.packageToName.ContainsKey(name1))
                        {
                            comment = sumSQLProduct.packageToName[name1];
                        }



                        if (!Controller.sqlRegKeys.ContainsKey(path))
                        {
                            cnt++;
                            Controller.sqlRegKeys.Add(path,
                                                      new Reason(SourceType.FromMSI_PackageName, kv.Key, comment, true));
                        }
                        int    start = path.IndexOf("Products\\") + "Products\\".Length;
                        string code  = path.Substring(start, 32);

                        if (!foundCompressedProductCodes.Contains(code))
                        {
                            foundCompressedProductCodes.Add(code);
                        }
                        if (!sumSQLProduct.productCodeToName.ContainsKey(code))
                        {
                            sumSQLProduct.productCodeToName.Add(code, comment);
                        }

                        //Need to add patch information
                        string pKey = path + "\\Patches";
                        if (RegHelper.IsKeyExist(pKey))
                        {
                            RegKey rk = new RegKey(pKey, "");
                            if (rk.Properties.ContainsKey("Patches"))
                            {
                                string[] patches = rk.Properties["Patches"][1].Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string s in patches)
                                {
                                    if (!foundCompressedPatchCode.Contains(s.Trim()))
                                    {
                                        foundCompressedPatchCode.Add(s.Trim());
                                    }
                                    if (!sumSQLProduct.patchCodeToName.ContainsKey(s.Trim()))
                                    {
                                        sumSQLProduct.patchCodeToName.Add(s.Trim(), comment);
                                    }
                                }
                            }
                        }
                    }
                } //match
            }

            //third, scan package code to see if any matches...could hit less

            foreach (RegKey rk in reghive.regKeys)
            {
                if (rk.Properties.ContainsKey("PackageCode"))
                {
                    string pcode = rk.Properties["PackageCode"][1];

                    if (sumSQLProduct.compressedPackageCodes.Contains(pcode))
                    {
                        string comment = "Package Code:" + pcode;
                        if (sumSQLProduct.packageCodeToName.ContainsKey(pcode))
                        {
                            comment = sumSQLProduct.packageCodeToName[pcode];
                        }

                        if (!Controller.sqlRegKeys.ContainsKey(rk.Path))
                        {
                            cnt++;
                            Controller.sqlRegKeys.Add(rk.Path,
                                                      new Reason(SourceType.FromMSI_PackageCode, pcode, comment, true));
                        }

                        int    start = rk.Path.IndexOf("Products\\") + "Products\\".Length;
                        string code  = rk.Path.Substring(start, 32);

                        if (!foundCompressedProductCodes.Contains(code))
                        {
                            foundCompressedProductCodes.Add(code);
                        }
                        if (!sumSQLProduct.productCodeToName.ContainsKey(code))
                        {
                            sumSQLProduct.productCodeToName.Add(code, comment);
                        }

                        //Need to add patch information
                        string pKey = rk.Path + "\\Patches";
                        if (RegHelper.IsKeyExist(pKey))
                        {
                            RegKey prk = new RegKey(pKey, "");
                            if (prk.Properties.ContainsKey("Patches"))
                            {
                                string[] patches = prk.Properties["Patches"][1].Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string s in patches)
                                {
                                    if (!foundCompressedPatchCode.Contains(s.Trim()))
                                    {
                                        foundCompressedPatchCode.Add(s.Trim());
                                    }
                                    if (!sumSQLProduct.patchCodeToName.ContainsKey(s.Trim()))
                                    {
                                        sumSQLProduct.patchCodeToName.Add(s.Trim(), comment);
                                    }
                                }
                            }
                        }
                    }
                }
            }//foreach
            Controller.UpdateProgress("Add_HKCR_Products keys:" + cnt, true);
            return(cnt);
        }
Example #3
0
        public static void Add()
        {
            var sumSQLProduct = Controller.sumSQLProduct;

            HashSet <string> foundCLSID   = new HashSet <string>();
            HashSet <string> foundTypeLib = new HashSet <string>();
            HashSet <string> foundProgID  = new HashSet <string>();

            string[] hives = new string[] { "HKEY_CLASSES_ROOT", "HKEY_CLASSES_ROOT\\Wow6432Node" };

            foreach (string hiveRoot in hives)
            {
                /*******************************************************************/

                /*
                 * HKEY_CLASSES_ROOT\CLSID
                 */
                /*******************************************************************/
                int    cnt = 0;
                subKey sbk = new subKey("InProcServer32", "");
                Controller.UpdateProgress(@"Scanning " + hiveRoot, true);

                //RegHive reghive = new RegHive(hiveRoot + @"\CLSID", sbk);
                RegHive reghive = Controller.regHives[hiveRoot + @"\CLSID"];


                Logger.LogMsg("reghive.propertyMap:" + reghive.propertyMap.Count);

                foreach (KeyValuePair <string, List <string> > kv in reghive.propertyMap)
                {
                    //Ignore those like:C:\Program Files\Common Files\Microsoft Shared\VS7Debug\pdm.dll
                    if (kv.Key.ToLower().Contains("microsoft shared"))
                    {
                        continue;
                    }
                    //   foreach (SQLProduct sql in sqlProducts)
                    {
                        try
                        {
                            if (sumSQLProduct.files_EXE_DLL.Contains(Path.GetFileName(kv.Key).ToLower()))
                            {
                                foreach (string path in kv.Value)
                                {
                                    if (!Controller.sqlRegKeys.ContainsKey(path))
                                    {
                                        cnt++;
                                        Controller.sqlRegKeys.Add(path, new Reason(SourceType.FromMSI_File, kv.Key));
                                    }

                                    //HKEY_CLASSES_ROOT\CLSID\{FE2D84B0-BBD5-4EC6-9A74-EE1C55148D78}\TypeLib
                                    string typeLibKey = path + "\\TypeLib";
                                    if (RegHelper.IsKeyExist(typeLibKey))
                                    {
                                        RegKey rk = new RegKey(typeLibKey, "");
                                        if (rk.Properties.ContainsKey("(Default)"))
                                        {
                                            if (!foundTypeLib.Contains(rk.Properties["(Default)"][1].ToString()))
                                            {
                                                foundTypeLib.Add(rk.Properties["(Default)"][1].ToString());
                                            }
                                        }
                                    }

                                    //HKEY_CLASSES_ROOT\CLSID\{02E7E69E-E80A-48E3-8B1D-6448C25B1710}\ProgID
                                    string progIDKey = path + "\\ProgID";
                                    if (RegHelper.IsKeyExist(progIDKey))
                                    {
                                        RegKey rk = new RegKey(progIDKey, "");
                                        if (rk.Properties.ContainsKey("(Default)"))
                                        {
                                            if (!foundProgID.Contains(rk.Properties["(Default)"][1].ToString()))
                                            {
                                                foundProgID.Add(rk.Properties["(Default)"][1].ToString());
                                            }
                                        }
                                    }

                                    int    idx   = path.IndexOf("CLSID\\") + 6;
                                    string CLSID = path.Substring(idx, 38);

                                    if (!foundCLSID.Contains(CLSID))
                                    {
                                        foundCLSID.Add(CLSID);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError(ex.Message);
                        }
                    } //foreach SQL products
                }

                Controller.UpdateProgress(reghive.hivePath + " Add keys:" + cnt, true);

                /*******************************************************************/

                /*
                 * HKEY_CLASSES_ROOT\TypeLib
                 */
                /*******************************************************************/
                cnt = 0;
                Controller.UpdateProgress(@"Scanning " + hiveRoot, true);
                //reghive = new RegHive(hiveRoot + @"\TypeLib");
                reghive = Controller.regHives[hiveRoot + @"\TypeLib"];

                string[] winxx = new string[] { "win32", "win64" };
                foreach (RegKey rk in reghive.regKeys)
                {
                    foreach (string win in winxx)
                    {
                        string fullpath = RegHelper.FindSubKey(rk.Path, win, 4);
                        if (!string.IsNullOrEmpty(fullpath))
                        {
                            //we find one

                            RegKey subrk = new RegKey(fullpath, "");
                            if (subrk.Properties.ContainsKey("(Default)"))
                            {
                                try
                                {
                                    string file = subrk.Properties["(Default)"][1].ToLower();
                                    string name = Path.GetFileName(file);

                                    if (file.Contains("microsoft shared"))
                                    {
                                        continue;
                                    }
                                    if (sumSQLProduct.files_EXE_DLL.Contains(name))
                                    {
                                        if (!Controller.sqlRegKeys.ContainsKey(rk.Path))
                                        {
                                            Controller.sqlRegKeys.Add(rk.Path, new Reason(SourceType.FromMSI_File, file));
                                            cnt++;
                                        }
                                        if (!foundTypeLib.Contains(rk.leaf))
                                        {
                                            foundTypeLib.Add(rk.leaf);
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                            }
                        } //if
                    }     //foreach winxx
                }         //foreach

                Controller.UpdateProgress(reghive.hivePath + " Add keys:" + cnt, true);

                //now check ProdID
                //HKEY_CLASSES_ROOT\DTS.ConnectionManagerOlap.5\CLSID

                //.this require .NET 45. so comment it
                //  RegistryKey hkcr = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64);

                var hkcr = RegistryExtensions.OpenBaseKey(RegistryHive.ClassesRoot, RegistryExtensions.RegistryHiveType.X64);

                string[] allnames = hkcr.GetSubKeyNames();
                cnt = 0;
                foreach (string s in allnames)
                {
                    string      sub    = hiveRoot + "\\" + s;
                    RegistryKey subkey = hkcr.OpenSubKey(s);

                    if (subkey == null)
                    {
                        continue;
                    }
                    string[] subnames = subkey.GetSubKeyNames();
                    if (subnames.Contains("CLSID") || subnames.Contains("Clsid"))
                    {
                        string result = RegHelper.GetValueForProperty(sub + "\\CLSID", "");
                        if (foundCLSID.Contains(result))
                        {
                            //we find one
                            if (!Controller.sqlRegKeys.ContainsKey(sub))
                            {
                                Controller.sqlRegKeys.Add(sub, new Reason(SourceType.COMClass, result, "CLSID:" + result));
                                cnt++;
                            }
                        }
                    }
                }

                Controller.UpdateProgress("HKEY_CLASSES_ROOT\\ProdID Add keys:" + cnt, true);

                //Add HKCR\ProdID
                cnt = 0;

                foreach (string s in foundProgID)
                {
                    string path = hiveRoot + "\\" + s;
                    if (Controller.sqlRegKeys.ContainsKey(path))
                    {
                        continue;
                    }
                    else
                    {
                        if (RegHelper.IsKeyExist(path))
                        {
                            cnt++; Controller.sqlRegKeys.Add(path, new Reason(SourceType.COMClass, s, "ProdID:" + s));
                        }
                    }
                }

                Controller.UpdateProgress("HKEY_CLASSES_ROOT\\ProdID (from foundProgID) Add keys:" + cnt, true);

                //for HKEY_CLASSES_ROOT\AppID I don't know how to add it here

                //
                /********************************************************/
                //HKEY_CLASSES_ROOT\Interface
                /********************************************************/
                //HKEY_CLASSES_ROOT\Interface\{33d00d41-c94f-5a61-9ab7-280dcefa0b08}\ProxyStubClsid32

                //below could have less hits...
                Controller.UpdateProgress(@"Scanning " + hiveRoot, true);
                //  reghive = new RegHive(hiveRoot + @"\Interface");

                reghive = Controller.regHives[hiveRoot + @"\Interface"];
                cnt     = 0;

                foreach (string sub in reghive.subKeys)
                {
                    try
                    {
                        string path = hiveRoot + "\\Interface\\" + sub;
                        if (!RegHelper.IsKeyExist(path + "\\ProxyStubClsid32"))
                        {
                            continue;
                        }
                        RegKey rk = new RegKey(path + "\\ProxyStubClsid32", "");
                        if (rk.Properties.ContainsKey("(Default)"))
                        {
                            string clsid = rk.Properties["(Default)"][1];
                            if (foundCLSID.Contains(clsid))
                            {
                                if (!Controller.sqlRegKeys.ContainsKey(path))
                                {
                                    cnt++;
                                    Controller.sqlRegKeys.Add(path, new Reason(SourceType.COMClass, clsid, "CLSID:" + clsid));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(ex.Message);
                    }
                }

                Controller.UpdateProgress(reghive.hivePath + " Add keys:" + cnt, true);
            }// for hiveRoot
        }