Пример #1
0
        private COMCLSIDServerEntry ReadServerKey(Dictionary <COMServerType, COMCLSIDServerEntry> servers, RegistryKey key, COMServerType server_type)
        {
            using (RegistryKey server_key = key.OpenSubKey(server_type.ToString()))
            {
                if (server_key == null)
                {
                    return(null);
                }

                COMCLSIDServerEntry entry = new COMCLSIDServerEntry(server_key, server_type);
                if (!String.IsNullOrWhiteSpace(entry.Server))
                {
                    servers.Add(server_type, new COMCLSIDServerEntry(server_key, server_type));
                }
                return(entry);
            }
        }
Пример #2
0
        public override bool Equals(object obj)
        {
            if (base.Equals(obj))
            {
                return(true);
            }

            COMCLSIDServerEntry right = obj as COMCLSIDServerEntry;

            if (right == null)
            {
                return(false);
            }

            return(Server == right.Server &&
                   CommandLine == right.CommandLine &&
                   ServerType == right.ServerType && ThreadingModel == right.ThreadingModel);
        }
Пример #3
0
        private void LoadFromKey(RegistryKey key)
        {
            HashSet <Guid> categories = new HashSet <Guid>();
            object         name       = key.GetValue(null);

            Name = null;
            if (name != null)
            {
                string s = name.ToString().Trim();

                if (s.Length > 0)
                {
                    Name = name.ToString();
                }
            }

            bool fake_name = false;

            if (Name == null)
            {
                fake_name = true;
                Name      = Clsid.FormatGuidDefault();
            }

            Dictionary <COMServerType, COMCLSIDServerEntry> servers = new Dictionary <COMServerType, COMCLSIDServerEntry>();
            COMCLSIDServerEntry inproc_server = ReadServerKey(servers, key, COMServerType.InProcServer32);

            ReadServerKey(servers, key, COMServerType.LocalServer32);
            ReadServerKey(servers, key, COMServerType.InProcHandler32);
            Servers = new ReadOnlyDictionary <COMServerType, COMCLSIDServerEntry>(servers);

            if (fake_name && inproc_server != null && inproc_server.HasDotNet)
            {
                Name = string.Format("{0}, {1}", inproc_server.DotNet.ClassName, inproc_server.DotNet.AssemblyName);
            }

            AppID = COMUtilities.ReadGuid(key, null, "AppID");
            if (AppID == Guid.Empty)
            {
                AppID = COMUtilities.ReadGuid(Registry.ClassesRoot,
                                              string.Format(@"AppID\{0}", COMUtilities.GetFileName(DefaultServer)), "AppID");
            }

            if (AppID != Guid.Empty && !servers.ContainsKey(COMServerType.LocalServer32))
            {
                servers.Add(COMServerType.LocalServer32, new COMCLSIDServerEntry(COMServerType.LocalServer32, "<APPID HOSTED>"));
            }

            TypeLib = COMUtilities.ReadGuid(key, "TypeLib", null);
            if (key.HasSubkey("Control"))
            {
                categories.Add(COMCategory.CATID_Control);
            }

            if (key.HasSubkey("Insertable"))
            {
                categories.Add(COMCategory.CATID_Insertable);
            }

            if (key.HasSubkey("DocObject"))
            {
                categories.Add(COMCategory.CATID_Document);
            }

            using (RegistryKey catkey = key.OpenSubKey("Implemented Categories"))
            {
                if (catkey != null)
                {
                    string[] subKeys = catkey.GetSubKeyNames();
                    foreach (string s in subKeys)
                    {
                        Guid g;

                        if (Guid.TryParse(s, out g))
                        {
                            categories.Add(g);
                        }
                    }
                }
            }

            Categories = categories.ToList().AsReadOnly();
            TreatAs    = COMUtilities.ReadGuid(key, "TreatAs", null);

            using (RegistryKey elev_key = key.OpenSubKey("Elevation"),
                   vso_key = key.OpenSubKey("VirtualServerObjects"))
            {
                if (elev_key != null)
                {
                    using (var base_key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
                                                                  Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Default))
                    {
                        int auto_approval = COMUtilities.ReadInt(base_key,
                                                                 @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\UAC\COMAutoApprovalList", Clsid.ToString("B"));
                        Elevation = new COMCLSIDElevationEntry(elev_key, vso_key, auto_approval != 0);
                    }
                }
            }

            ActivatableFromApp = _app_activatable.Contains(Clsid);
            using (RegistryKey trustkey = Registry.LocalMachine.OpenSubKey(@"Software\Classes\Unmarshalers\System\" + Clsid.ToString("B")))
            {
                TrustedMarshaller = trustkey != null ? true : categories.Contains(COMCategory.CATID_TrustedMarshaler);
            }
        }