Example #1
0
        /// <summary>
        /// Checks if the AppID exists
        /// </summary>
        /// <param name="appID">The AppID or GUID</param>
        /// <returns>True if it exists</returns>
        private static bool appidExists(string appID)
        {
            List <RegistryKey> listRegKeys = new List <RegistryKey>();

            listRegKeys.Add(Registry.ClassesRoot.OpenSubKey(@"AppID"));
            listRegKeys.Add(Registry.LocalMachine.OpenSubKey(@"Software\Classes\AppID"));
            listRegKeys.Add(Registry.CurrentUser.OpenSubKey(@"Software\Classes\AppID"));

            if (Utils.Is64BitOS)
            {
                listRegKeys.Add(Registry.ClassesRoot.OpenSubKey(@"Wow6432Node\AppID"));
                listRegKeys.Add(Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node\Classes\AppID"));
                listRegKeys.Add(Registry.CurrentUser.OpenSubKey(@"Software\Wow6432Node\Classes\AppID"));
            }

            try
            {
                foreach (RegistryKey rk in listRegKeys)
                {
                    if (rk == null)
                    {
                        continue;
                    }

                    using (RegistryKey subKey = rk.OpenSubKey(appID))
                    {
                        if (subKey != null)
                        {
                            if (!ScanDlg.IsOnIgnoreList(subKey.ToString()))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Scans for the CLSID subkey
        /// <param name="regKey">Location of CLSID Sub Key</param>
        /// </summary>
        private static void ScanCLSIDSubKey(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }

            Main.Logger.WriteLine("Scanning " + regKey.Name + " for invalid CLSID's");

            try
            {
                foreach (string strCLSID in regKey.GetSubKeyNames())
                {
                    RegistryKey rkCLSID = regKey.OpenSubKey(strCLSID);

                    if (rkCLSID == null)
                    {
                        continue;
                    }

                    ScanDlg.CurrentScannedObject = rkCLSID.ToString();

                    // Check for valid AppID
                    string strAppID = regKey.GetValue("AppID") as string;
                    if (!string.IsNullOrEmpty(strAppID))
                    {
                        if (!appidExists(strAppID))
                        {
                            ScanDlg.StoreInvalidKey(Strings.MissingAppID, rkCLSID.ToString(), "AppID");
                        }
                    }

                    // See if DefaultIcon exists
                    using (RegistryKey regKeyDefaultIcon = rkCLSID.OpenSubKey("DefaultIcon"))
                    {
                        if (regKeyDefaultIcon != null)
                        {
                            string iconPath = regKeyDefaultIcon.GetValue("") as string;

                            if (!string.IsNullOrEmpty(iconPath))
                            {
                                if (!Utils.IconExists(iconPath))
                                {
                                    if (!ScanDlg.IsOnIgnoreList(iconPath))
                                    {
                                        ScanDlg.StoreInvalidKey(Strings.InvalidFile, string.Format("{0}\\DefaultIcon", rkCLSID.ToString()));
                                    }
                                }
                            }
                        }
                    }

                    // Look for InprocServer files
                    using (RegistryKey regKeyInprocSrvr = rkCLSID.OpenSubKey("InprocServer"))
                    {
                        if (regKeyInprocSrvr != null)
                        {
                            string strInprocServer = regKeyInprocSrvr.GetValue("") as string;

                            if (!string.IsNullOrEmpty(strInprocServer))
                            {
                                if (!Utils.FileExists(strInprocServer))
                                {
                                    ScanDlg.StoreInvalidKey(Strings.InvalidInprocServer, regKeyInprocSrvr.ToString());
                                }
                            }

                            regKeyInprocSrvr.Close();
                        }
                    }

                    using (RegistryKey regKeyInprocSrvr32 = rkCLSID.OpenSubKey("InprocServer32"))
                    {
                        if (regKeyInprocSrvr32 != null)
                        {
                            string strInprocServer32 = regKeyInprocSrvr32.GetValue("") as string;

                            if (!string.IsNullOrEmpty(strInprocServer32))
                            {
                                if (!Utils.FileExists(strInprocServer32))
                                {
                                    ScanDlg.StoreInvalidKey(Strings.InvalidInprocServer32, regKeyInprocSrvr32.ToString());
                                }
                            }

                            regKeyInprocSrvr32.Close();
                        }
                    }

                    rkCLSID.Close();
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            catch (System.UnauthorizedAccessException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            regKey.Close();
            return;
        }
Example #3
0
        /// <summary>
        /// Finds invalid File extensions + ProgIDs referenced
        /// </summary>
        private static void ScanClasses(RegistryKey regKey)
        {
            if (regKey == null)
            {
                return;
            }

            Main.Logger.WriteLine("Scanning " + regKey.Name + " for invalid Classes");

            try
            {
                foreach (string strSubKey in regKey.GetSubKeyNames())
                {
                    // Update scan dialog
                    ScanDlg.CurrentScannedObject = string.Format("{0}\\{1}", regKey.Name, strSubKey);

                    // Skip any file (*)
                    if (strSubKey == "*")
                    {
                        continue;
                    }

                    if (strSubKey[0] == '.')
                    {
                        // File Extension
                        using (RegistryKey rkFileExt = regKey.OpenSubKey(strSubKey))
                        {
                            if (rkFileExt != null)
                            {
                                // Find reference to ProgID
                                string strProgID = rkFileExt.GetValue("") as string;

                                if (!string.IsNullOrEmpty(strProgID))
                                {
                                    if (!progIDExists(strProgID))
                                    {
                                        ScanDlg.StoreInvalidKey(Strings.MissingProgID, rkFileExt.ToString());
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // ProgID or file class

                        // See if DefaultIcon exists
                        using (RegistryKey regKeyDefaultIcon = regKey.OpenSubKey(string.Format("{0}\\DefaultIcon", strSubKey)))
                        {
                            if (regKeyDefaultIcon != null)
                            {
                                string iconPath = regKeyDefaultIcon.GetValue("") as string;

                                if (!string.IsNullOrEmpty(iconPath))
                                {
                                    if (!Utils.IconExists(iconPath))
                                    {
                                        if (!ScanDlg.IsOnIgnoreList(iconPath))
                                        {
                                            ScanDlg.StoreInvalidKey(Strings.InvalidFile, regKeyDefaultIcon.Name);
                                        }
                                    }
                                }
                            }
                        }

                        // Check referenced CLSID
                        using (RegistryKey rkCLSID = regKey.OpenSubKey(string.Format("{0}\\CLSID", strSubKey)))
                        {
                            if (rkCLSID != null)
                            {
                                string guid = rkCLSID.GetValue("") as string;

                                if (!string.IsNullOrEmpty(guid))
                                {
                                    if (!clsidExists(guid))
                                    {
                                        ScanDlg.StoreInvalidKey(Strings.MissingCLSID, string.Format("{0}\\{1}", regKey.Name, strSubKey));
                                    }
                                }
                            }
                        }
                    }

                    // Check for unused progid/extension
                    using (RegistryKey rk = regKey.OpenSubKey(strSubKey))
                    {
                        if (rk != null)
                        {
                            if (rk.ValueCount <= 0 && rk.SubKeyCount <= 0)
                            {
                                ScanDlg.StoreInvalidKey(Strings.InvalidProgIDFileExt, rk.Name);
                            }
                        }
                    }
                }
            }
            catch (System.Security.SecurityException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            catch (System.UnauthorizedAccessException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            regKey.Close();

            return;
        }