Example #1
0
 public override int GetHashCode()
 {
     return(Clsid.GetHashCode() ^ Name.GetSafeHashCode() ^ DllPath.GetSafeHashCode()
            ^ Server.GetSafeHashCode() ^ ActivationType.GetHashCode() ^ TrustLevel.GetHashCode()
            ^ Permissions.GetSafeHashCode() ^ Threading.GetHashCode() ^ ActivateInSharedBroker.GetHashCode()
            ^ PackageId.GetSafeHashCode() ^ Source.GetHashCode());
 }
Example #2
0
 public override int GetHashCode()
 {
     return(Clsid.GetHashCode() ^ Name.GetSafeHashCode() ^ TreatAs.GetHashCode()
            ^ AppID.GetHashCode() ^ TypeLib.GetHashCode() ^ Servers.Values.GetEnumHashCode()
            ^ Elevation.GetSafeHashCode() ^ ActivatableFromApp.GetHashCode() ^ TrustedMarshaller.GetHashCode()
            ^ Source.GetHashCode() ^ PackageId.GetSafeHashCode());
 }
Example #3
0
        public void IdTest()
        {
            var obj = new TestClass();
            var id  = Clsid.Id(obj);

            Assert.That(id, Is.EqualTo(Guid.Parse("33209477-886F-4031-8C34-8ACA964F1B96")));
        }
Example #4
0
        public void Run(ref Report report, List <Dictionary <string, string> > list)
        {
            var hasEntries = false;

            using (
                var result =
                    Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad"))
            {
                var valueNames = result.GetValueNames();

                foreach (var valueName in valueNames)
                {
                    var value = (string)result.GetValue(valueName);
                    var dll   = Clsid.GetFile(value);

                    list.Add(new Dictionary <string, string>
                    {
                        { "token", "O21" },
                        { "clsid", value },
                        { "name", valueName },
                        { "dll", string.IsNullOrEmpty(dll) ? "(file not found)" : dll }
                    });


                    hasEntries = true;
                }
            }

            if (hasEntries)
            {
                report.Add(list);
            }
        }
Example #5
0
File: O2.cs Project: sitedata/cscan
        public void Run(ref Report report, List <Dictionary <string, string> > list)
        {
            using (
                var key =
                    Registry.LocalMachine.OpenSubKey(
                        @"Software\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects"))
            {
                if (key == null)
                {
                    return;
                }

                foreach (var subKeyName in key.GetSubKeyNames())
                {
                    using (var subKey = key.OpenSubKey(subKeyName))
                    {
                        var fileName = Clsid.GetFile(subKeyName);
                        var friendly = Clsid.GetName(subKeyName);

                        list.Add(new Dictionary <string, string>
                        {
                            { "token", "O2" },
                            { "name", friendly },
                            { "clsid", subKeyName },
                            { "file", fileName }
                        });
                    }
                }
            }
        }
Example #6
0
 internal COMCLSIDEntry(COMRegistry registry, ActCtxComServerRedirection com_server)
     : this(registry, com_server.Clsid)
 {
     Clsid   = com_server.Clsid;
     TypeLib = com_server.TypeLibraryId;
     Servers[COMServerType.InProcServer32] =
         new COMCLSIDServerEntry(COMServerType.InProcServer32, com_server.FullPath, com_server.ThreadingModel);
     Name   = string.IsNullOrWhiteSpace(com_server.ProgId) ? Clsid.ToString() : com_server.ProgId;
     Source = COMRegistryEntrySource.ActCtx;
 }
Example #7
0
        /// <summary>
        /// Inserts or updates (when a row with the session exists) the byte array
        /// and returns the new session Guid if none is given or the row was not found
        /// </summary>
        /// <param name="type"></param>
        /// <param name="bytes"></param>
        /// <param name="session"></param>
        /// <returns></returns>
        public Guid SaveMain(Type type, byte[] bytes, Guid?session)
        {
            var query = from m in this.Main
                        where m.session == session
                        select m;
            var main = query.FirstOrDefault();

            if (main == null)
            {
                main = new Main();
                this.Main.Add(main);    // INSERT
            }
            main.clsid = Clsid.Id(type);
            main.main  = bytes;
            this.SaveChanges();
            return(main.session);  // get the new session guid set by the db on insert
        }
Example #8
0
        /// <summary>
        /// Returns the (unencrypted!) literal INSERT string of the loaded object
        /// for manually exporting session dumps.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="bytes"></param>
        /// <returns>SQL INSERT string</returns>
        public string InsertSQL(Type type, byte[] bytes)
        {
            var clsid = Clsid.Id(type);
            // Let the future consumer SQL Server encode the string
            // representation of the byte[] Unlike EF6 use ADO.NET Core, as the
            // connection string is usable for both contexts.
            string hex   = String.Empty;
            var    query = "SELECT CONVERT(VARCHAR(MAX), @main, 1) AS [hex]";

            using (var conn = new SqlConnection(ConnectionString))
                using (var cmd = new SqlCommand(query, conn))
                {
                    conn.Open();
                    cmd.Parameters.AddWithValue("main", bytes);
                    hex = (string)cmd.ExecuteScalar();
                }
            // Format according to get copy-pasted into Management Studio
            return(String.Format("INSERT INTO Main (clsid, main) SELECT '{0}', {1}\n" +
                                 "SELECT session FROM Main WHERE mainid = @@IDENTITY\n",
                                 clsid, hex));
        }
Example #9
0
        private H264Encoder(Activate activate)
        {
            Activate     = activate;
            FriendlyName = activate.Get(TransformAttributeKeys.MftFriendlyNameAttribute);
            Clsid        = activate.Get(TransformAttributeKeys.MftTransformClsidAttribute);
            Flags        = (TransformEnumFlag)activate.Get(TransformAttributeKeys.TransformFlagsAttribute);
            var list       = new List <string>();
            var inputTypes = activate.Get(TransformAttributeKeys.MftInputTypesAttributes);

            for (int j = 0; j < inputTypes.Length; j += 32)                                                                           // two guids
            {
                var majorType = new Guid(Enumerable.Range(0, 16).Select(index => Marshal.ReadByte(inputTypes, j + index)).ToArray()); // Should be video in this context
                var subType   = new Guid(Enumerable.Range(0, 16).Select(index => Marshal.ReadByte(inputTypes, j + 16 + index)).ToArray());
                list.Add(GetFourCC(subType));
            }

            list.Sort();
            InputTypes = list;
            try
            {
                using (var tf = activate.ActivateObject <Transform>())
                {
                    IsBuiltin         = IsBuiltinEncoder(tf);
                    IsDirect3D11Aware = IsDirect3D11AwareEncoder(tf);
                    IsHardwareBased   = IsHardwareBasedEncoder(tf);
                }
            }
            catch
            {
                // do nothing
            }

            using (var key = Registry.ClassesRoot.OpenSubKey(Path.Combine("CLSID", Clsid.ToString("B"), "InprocServer32")))
            {
                if (key != null)
                {
                    DllPath = key.GetValue(null) as string;
                }
            }
        }
Example #10
0
File: O3.cs Project: Slurppa/cscan
        public void Run(ref Report report, List <Dictionary <string, string> > list)
        {
            foreach (RegistryResult result in RegistryWrapper.RegistryWrapper.QuerySubKey(RegistryHive.LocalMachine, ToolbarKey))
            {
                foreach (var toolbarClsid in result.key.GetValueNames())
                {
                    string companyName = Clsid.GetName(toolbarClsid, result.view);
                    string filePath    = Clsid.GetFile(toolbarClsid, result.view);

                    list.Add(new Dictionary <string, string>()
                    {
                        { "Token", "O3" },
                        { "regview", result.view.toEntryString() },
                        { "company", companyName ?? "()" },
                        { "clsid", toolbarClsid },
                        { "path", filePath ?? "<File not found>" }
                    });
                }
            }


            report.Add(list);
        }
Example #11
0
        private void LoadFromKey(RegistryKey key)
        {
            object name = key.GetValue(null);

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

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

            if (Name == null)
            {
                Name = Clsid.ToString("B");
            }

            RegistryKey serverKey = key.OpenSubKey("InProcServer32");

            try
            {
                ServerType = COMServerType.InProcServer32;
                if (serverKey == null)
                {
                    serverKey  = key.OpenSubKey("LocalServer32");
                    ServerType = COMServerType.LocalServer32;
                }

                if ((serverKey != null) && (serverKey.GetValue(null) != null))
                {
                    CmdLine = serverKey.GetValue(null).ToString();
                    Server  = ProcessFileName(CmdLine, ServerType == COMServerType.LocalServer32);
                    string threading_model = serverKey.GetValue("ThreadingModel") as string;
                    if (threading_model != null)
                    {
                        switch (threading_model.ToLower())
                        {
                        case "both":
                            ThreadingModel = COMThreadingModel.Both;
                            break;

                        case "free":
                            ThreadingModel = COMThreadingModel.Free;
                            break;

                        case "neutral":
                            ThreadingModel = COMThreadingModel.Neutral;
                            break;

                        case "apartment":
                        default:
                            ThreadingModel = COMThreadingModel.Apartment;
                            break;
                        }
                    }
                    else if (ServerType == COMServerType.LocalServer32)
                    {
                        ThreadingModel = COMThreadingModel.Both;
                    }

                    try
                    {
                        // Expand out any short filenames
                        if (Server.Contains("~") && !IsInvalidFileName(Server))
                        {
                            Server = Path.GetFullPath(Server);
                        }
                    }
                    catch (IOException)
                    {
                    }
                    catch (SecurityException)
                    {
                    }
                    catch (ArgumentException)
                    {
                    }
                }
                else
                {
                    Server     = String.Empty;
                    ServerType = COMServerType.UnknownServer;
                }
            }
            finally
            {
                if (serverKey != null)
                {
                    serverKey.Close();
                }
            }

            AppID = Guid.Empty;

            try
            {
                object appid = key.GetValue("AppID");
                if ((appid != null) && (appid.ToString().Length > 0))
                {
                    Guid appid_guid;
                    if (Guid.TryParse(appid.ToString(), out appid_guid))
                    {
                        if (appid_guid != Guid.Empty)
                        {
                            if (ServerType == COMServerType.UnknownServer)
                            {
                                ServerType = COMServerType.LocalServer32;
                            }
                            AppID = appid_guid;
                        }
                    }
                }
            }
            catch (FormatException e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }

            TypeLib = COMUtilities.ReadGuidFromKey(key, "TypeLib", null);
            if (key.HasSubkey("Control"))
            {
                m_categories.Add(ControlCategory);
            }

            if (key.HasSubkey("Insertable"))
            {
                m_categories.Add(InsertableCategory);
            }

            if (key.HasSubkey("DocObject"))
            {
                m_categories.Add(DocumentCategory);
            }

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

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

            TreatAs = COMUtilities.ReadGuidFromKey(key, "TreatAs", null);
        }
Example #12
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)
                    {
                        if (Guid.TryParse(s, out Guid 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);
            }

            Source = key.GetSource();
        }
Example #13
0
 public override int GetHashCode()
 {
     return(Clsid.GetHashCode() ^ Name.GetSafeHashCode() ^ DllPath.GetSafeHashCode()
            ^ Server.GetSafeHashCode() ^ ActivationType.GetHashCode() ^ TrustLevel.GetHashCode()
            ^ Permissions.GetSafeHashCode() & Threading.GetHashCode());
 }
Example #14
0
 public override int GetHashCode()
 {
     return(ProgID.GetSafeHashCode() ^ Name.GetSafeHashCode() ^ Clsid.GetHashCode()
            ^ Source.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(Name.GetSafeHashCode() ^ Uuid.GetHashCode()
            ^ Clsid.GetHashCode() ^ AppPath.GetSafeHashCode() ^ Policy.GetHashCode());
 }
Example #16
0
 public override int GetHashCode() => Clsid.GetHashCode();
Example #17
0
 public override int GetHashCode()
 {
     return(MimeType.GetSafeHashCode() ^ Clsid.GetHashCode() ^ Extension.GetSafeHashCode());
 }
Example #18
0
        public void MissingClsidTest()
        {
            var obj = new ClsidTest();

            Assert.That(() => Clsid.Id(obj), Throws.TypeOf <ArgumentException>());
        }
Example #19
0
 public override int GetHashCode()
 {
     return(Clsid.GetHashCode() ^ Name.GetSafeHashCode() ^ TreatAs.GetHashCode()
            ^ AppID.GetHashCode() ^ TypeLib.GetHashCode() ^ Servers.Values.GetEnumHashCode()
            ^ Elevation.GetSafeHashCode());
 }