public async Task HostObject(ICOMClassEntry ent, object obj, bool factory) { Dictionary <string, string> props = new Dictionary <string, string>(); if (ent == null) { ent = new COMCLSIDEntry(m_registry, Guid.Empty, COMServerType.UnknownServer); } props.Add("CLSID", ent.Clsid.FormatGuid()); props.Add("Name", ent.Name); props.Add("Server", ent.DefaultServer); /* Need to implement a type library reader */ Type dispType = COMUtilities.GetDispatchTypeInfo(this, obj); if (!ent.InterfacesLoaded) { await ent.LoadSupportedInterfacesAsync(false, null); } IEnumerable <COMInterfaceInstance> intfs = factory ? ent.FactoryInterfaces : ent.Interfaces; ObjectInformation view = new ObjectInformation(m_registry, ent, ent.Name, obj, props, intfs.Select(i => m_registry.MapIidToInterface(i.Iid)).ToArray()); HostControl(view); }
private void viewProxyDefinitionToolStripMenuItem_Click(object sender, EventArgs e) { try { ListView view = GetListViewForMenu(sender); if (view != null && view.SelectedIndices.Count > 0) { ListViewItem item = view.SelectedItems[0]; Tuple <COMInterfaceInstance, COMInterfaceEntry> intf = item.Tag as Tuple <COMInterfaceInstance, COMInterfaceEntry>; if (m_registry.Clsids.ContainsKey(intf.Item2.ProxyClsid)) { COMCLSIDEntry clsid = m_registry.Clsids[intf.Item2.ProxyClsid]; using (var resolver = EntryPoint.GetProxyParserSymbolResolver()) { EntryPoint.GetMainForm(m_registry).HostControl(new TypeLibControl(m_registry, COMUtilities.GetFileName(clsid.DefaultServerName), COMProxyInstance.GetFromCLSID(clsid, resolver), intf.Item1.Iid)); } } } } catch (Exception ex) { EntryPoint.ShowError(this, ex); } }
public async Task OpenObjectInformation(object comObj, string defaultName) { if (comObj != null) { COMCLSIDEntry ent = null; Dictionary <string, string> props = new Dictionary <string, string>(); string strObjName = ""; IEnumerable <COMInterfaceEntry> ints = null; Guid clsid = COMUtilities.GetObjectClass(comObj); if (m_registry.Clsids.ContainsKey(clsid)) { ent = m_registry.Clsids[clsid]; strObjName = ent.Name; props.Add("CLSID", ent.Clsid.FormatGuid()); props.Add("Name", ent.Name); props.Add("Server", ent.DefaultServer); await ent.LoadSupportedInterfacesAsync(false, null); ints = ent.Interfaces.Select(i => m_registry.MapIidToInterface(i.Iid)); } else { ints = m_registry.GetInterfacesForObject(comObj).ToArray(); strObjName = defaultName != null ? defaultName : clsid.FormatGuid(); props.Add("CLSID", clsid.FormatGuid()); } Type dispType = COMUtilities.GetDispatchTypeInfo(this, comObj); HostControl(new ObjectInformation(m_registry, ent, strObjName, comObj, props, ints.ToArray())); } }
private void btnProxyProperties_Click(object sender, EventArgs e) { if (m_registry.Clsids.ContainsKey(m_interface.ProxyClsid)) { COMCLSIDEntry entry = m_registry.Clsids[m_interface.ProxyClsid]; EntryPoint.GetMainForm(m_registry).HostControl(new PropertiesControl(m_registry, entry.Name, entry)); } }
private void propertiesToolStripMenuItem_Click(object sender, EventArgs e) { COMProcessClassRegistration c = GetRegisteredClass(); if (c != null && m_registry.Clsids.ContainsKey(c.Clsid)) { COMCLSIDEntry clsid = m_registry.MapClsidToEntry(c.Clsid); EntryPoint.GetMainForm(m_registry).HostControl(new PropertiesControl(m_registry, clsid.Name, clsid)); } }
public override Control CreateInstance(COMRegistry registry, ICOMClassEntry entry, string strObjName, ObjectEntry pObject) { COMCLSIDEntry clsid_entry = entry as COMCLSIDEntry; if (clsid_entry == null) { throw new ArgumentException("Entry must be a COM class", "entry"); } return(new ElevatedFactoryServerTypeViewer(registry, clsid_entry, strObjName, pObject.Instance)); }
private void SetupProperties(object obj) { if (obj is COMCLSIDEntry) { SetupClsidEntry((COMCLSIDEntry)obj); } if (obj is COMProgIDEntry) { COMProgIDEntry entry = (COMProgIDEntry)obj; COMCLSIDEntry clsid_entry = m_registry.MapClsidToEntry(entry.Clsid); SetupClsidEntry(clsid_entry); } if (obj is COMAppIDEntry) { SetupAppIdEntry((COMAppIDEntry)obj); } if (obj is COMInterfaceEntry) { SetupInterfaceEntry((COMInterfaceEntry)obj); } if (obj is COMTypeLibVersionEntry) { SetupTypeLibVersionEntry((COMTypeLibVersionEntry)obj); } if (obj is COMProcessEntry) { SetupProcessEntry((COMProcessEntry)obj); } if (obj is COMIPIDEntry) { SetupIPIDEntry((COMIPIDEntry)obj); } if (obj is COMRuntimeClassEntry) { SetupRuntimeClassEntry((COMRuntimeClassEntry)obj); } if (obj is COMRuntimeServerEntry) { SetupRuntimeServerEntry((COMRuntimeServerEntry)obj); } }
private void listViewElevationVSOs_DoubleClick(object sender, EventArgs e) { if (listViewElevationVSOs.SelectedItems.Count < 1) { return; } COMCLSIDEntry clsid = listViewElevationVSOs.SelectedItems[0].Tag as COMCLSIDEntry; if (clsid != null) { EntryPoint.GetMainForm(m_registry).HostControl(new PropertiesControl(m_registry, clsid.Name, clsid)); } }
public CustomMarshalEditorControl(COMRegistry registry, COMObjRefCustom objref) { m_objref = objref; m_registry = registry; InitializeComponent(); textBoxClsid.Text = objref.Clsid.FormatGuid(); COMCLSIDEntry ent = registry.MapClsidToEntry(objref.Clsid); if (ent != null) { textBoxName.Text = ent.Name; } hexEditor.Bytes = objref.ObjectData; }
public ElevatedFactoryServerTypeViewer(COMRegistry registry, COMCLSIDEntry entry, string objName, object obj) { InitializeComponent(); _obj = obj; _name = objName; _registry = registry; _entry = entry; if (_entry != null && _entry.Elevation != null) { foreach (COMCLSIDEntry vso in _entry.Elevation.VirtualServerObjects.Select(v => registry.MapClsidToEntry(v))) { comboBoxClass.Items.Add(vso); } if (comboBoxClass.Items.Count > 0) { comboBoxClass.SelectedIndex = 0; } } }
private void SetupProcessEntry(COMProcessEntry obj) { m_process = obj; textBoxProcessExecutablePath.Text = obj.ExecutablePath; textBoxProcessProcessId.Text = obj.ProcessId.ToString(); textBoxProcessAppId.Text = GetGuidValue(obj.AppId); textBoxProcessAccessPermissions.Text = GetStringValue(obj.AccessPermissions); btnProcessViewAccessPermissions.Enabled = !String.IsNullOrWhiteSpace(obj.AccessPermissions); textBoxProcessLrpcPermissions.Text = GetStringValue(obj.LRpcPermissions); textBoxProcessUser.Text = GetStringValue(obj.User); textBoxProcessSecurity.Text = String.Format("Capabilities: {0}, Authn Level: {1}, Imp Level: {2}, Unmarshal Policy: {3}", obj.Capabilities, obj.AuthnLevel, obj.ImpLevel, obj.UnmarshalPolicy); textBoxProcessStaHwnd.Text = String.Format("0x{0:X}", obj.STAMainHWnd.ToInt64()); SetupIpidEntries(obj.Ipids, false); listViewProcessIPids.ListViewItemSorter = new ListItemComparer(0); lblProcess64bit.Text = COMUtilities.FormatBitness(obj.Is64Bit); tabControlProperties.TabPages.Add(tabPageProcess); if (m_registry.AppIDs.ContainsKey(obj.AppId)) { SetupAppIdEntry((COMAppIDEntry)m_registry.AppIDs[obj.AppId]); } if (obj.Classes.Any()) { tabControlProperties.TabPages.Add(tabPageRegisteredClasses); foreach (var c in obj.Classes) { COMCLSIDEntry clsid = m_registry.MapClsidToEntry(c.Clsid); ListViewItem item = listViewRegisteredClasses.Items.Add(c.Clsid.FormatGuid()); item.SubItems.Add(clsid.Name); item.SubItems.Add(c.VTable); item.SubItems.Add(c.RegFlags.ToString()); item.SubItems.Add(c.Apartment.ToString()); item.SubItems.Add(c.Context.ToString()); item.Tag = c; } listViewRegisteredClasses.ListViewItemSorter = new ListItemComparer(0); listViewRegisteredClasses.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewRegisteredClasses.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } }
void IActivationFilter.HandleActivation(uint dwActivationType, ref Guid rclsid, out Guid pReplacementClsId) { pReplacementClsId = rclsid; lock (this) { if (_writer == null) { return; } COMCLSIDEntry entry = _registry?.MapClsidToEntry(rclsid); if (entry == null) { _writer.WriteLine("dwActivationType: 0x{0:X} rclsid: {1}", dwActivationType, rclsid); } else { _writer.WriteLine("dwActivationType: 0x{0:X} rclsid: {1} name '{2}'", dwActivationType, rclsid, entry.Name); } } }
private async void menuObjectFromFile_Click(object sender, EventArgs e) { try { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "All Files (*.*)|*.*"; if (dlg.ShowDialog(this) == DialogResult.OK) { COMCLSIDEntry entry = m_registry.GetFileClass(dlg.FileName); if (entry != null) { IPersistFile ps = (IPersistFile)entry.CreateInstanceAsObject(entry.CreateContext, null); ps.Load(dlg.FileName, (int)STGM.READ); await HostObject(entry, ps, false); } } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnCreate_Click(object sender, EventArgs e) { try { IElevatedFactoryServer factory = (IElevatedFactoryServer)_obj; COMCLSIDEntry vso = comboBoxClass.SelectedItem as COMCLSIDEntry; if (vso != null) { object new_object; Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Name", _name); props.Add("CLSID", vso.Clsid.FormatGuid()); factory.ServerCreateElevatedObject(vso.Clsid, COMInterfaceEntry.IID_IUnknown, out new_object); ObjectInformation view = new ObjectInformation(_registry, vso, vso.Name, new_object, props, _registry.GetInterfacesForObject(new_object).ToArray()); EntryPoint.GetMainForm(_registry).HostControl(view); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public StandardMarshalEditorControl(COMRegistry registry, COMObjRefStandard objref) { m_objref = objref; m_registry = registry; InitializeComponent(); textBoxStandardFlags.Text = String.Format("0x{0:X}", objref.StdFlags); textBoxPublicRefs.Text = objref.PublicRefs.ToString(); textBoxOxid.Text = String.Format("0x{0:X016}", objref.Oxid); textBoxOid.Text = String.Format("0x{0:X016}", objref.Oid); textBoxIpid.Text = objref.Ipid.FormatGuid(); textBoxApartmentId.Text = COMUtilities.GetApartmentIdStringFromIPid(objref.Ipid); int pid = COMUtilities.GetProcessIdFromIPid(objref.Ipid); textBoxProcessId.Text = COMUtilities.GetProcessIdFromIPid(objref.Ipid).ToString(); try { Process p = Process.GetProcessById(pid); textBoxProcessName.Text = p.ProcessName; } catch (ArgumentException) { textBoxProcessName.Text = "N/A"; } COMObjRefHandler handler = objref as COMObjRefHandler; if (handler != null) { textBoxHandlerClsid.Text = handler.Clsid.FormatGuid(); COMCLSIDEntry ent = registry.MapClsidToEntry(handler.Clsid); if (ent != null) { textBoxHandlerName.Text = ent.Name; } } else { tableLayoutPanel.Controls.Remove(lblHandlerClsid); tableLayoutPanel.Controls.Remove(lblHandlerName); tableLayoutPanel.Controls.Remove(textBoxHandlerClsid); tableLayoutPanel.Controls.Remove(textBoxHandlerName); } foreach (COMStringBinding str in objref.StringBindings) { ListViewItem item = listViewStringBindings.Items.Add(str.TowerId.ToString()); item.SubItems.Add(str.NetworkAddr); item.Tag = str; } listViewStringBindings.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewStringBindings.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); foreach (COMSecurityBinding sec in objref.SecurityBindings) { ListViewItem item = listViewSecurityBindings.Items.Add(sec.AuthnSvc.ToString()); item.SubItems.Add(sec.PrincName); item.Tag = sec; } listViewSecurityBindings.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewSecurityBindings.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }
private void SetupClsidEntry(COMCLSIDEntry entry) { textBoxClsidName.Text = entry.Name; textBoxClsid.Text = entry.Clsid.FormatGuid(); textBoxServerType.Text = entry.DefaultServerType.ToString(); textBoxThreadingModel.Text = entry.DefaultThreadingModel.ToString(); textBoxServer.Text = entry.DefaultServer; textBoxCmdLine.Text = GetStringValue(entry.DefaultCmdLine); textBoxTreatAs.Text = GetGuidValue(entry.TreatAs); btnTreatAsProps.Enabled = m_registry.Clsids.ContainsKey(entry.TreatAs); var progids = m_registry.Progids; foreach (string progid in m_registry.GetProgIdsForClsid(entry.Clsid).Select(p => p.ProgID)) { ListViewItem item = listViewProgIDs.Items.Add(progid); if (progids.ContainsKey(progid)) { item.Tag = progids[progid]; } } listViewProgIDs.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); foreach (Guid catid in entry.Categories) { ListViewItem item = listViewCategories.Items.Add(COMUtilities.GetCategoryName(catid)); item.Tag = catid; } listViewCategories.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); LoadInterfaceList(entry.Interfaces, listViewInterfaces); LoadInterfaceList(entry.FactoryInterfaces, listViewFactoryInterfaces); tabPageSupportedInterfaces.Tag = entry; tabControlProperties.TabPages.Add(tabPageClsid); tabControlProperties.TabPages.Add(tabPageSupportedInterfaces); if (m_registry.AppIDs.ContainsKey(entry.AppID)) { SetupAppIdEntry(m_registry.AppIDs[entry.AppID]); } IEnumerable <COMInterfaceEntry> proxies = m_registry.GetProxiesForClsid(entry); if (proxies.Any()) { foreach (COMInterfaceEntry intf in proxies.OrderBy(i => i.Name)) { ListViewItem item = listViewProxies.Items.Add(intf.Name); item.SubItems.Add(intf.Iid.FormatGuid()); item.Tag = intf; } listViewProxies.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewProxies.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); listViewProxies.ListViewItemSorter = new ListItemComparer(0); tabControlProperties.TabPages.Add(tabPageProxies); } if (entry.Servers.Count > 1) { foreach (COMCLSIDServerEntry server in entry.Servers.Values) { ListViewItem item = listViewCLSIDServers.Items.Add(server.ServerType.ToString()); item.SubItems.Add(server.Server); item.SubItems.Add(server.CommandLine); item.SubItems.Add(server.ThreadingModel.ToString()); item.Tag = server; } listViewCLSIDServers.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewCLSIDServers.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); listViewCLSIDServers.ListViewItemSorter = new ListItemComparer(0); tabControlProperties.TabPages.Add(tabPageServers); } SetupTypeLibVersionEntry(m_registry.GetTypeLibVersionEntry(entry.TypeLib, null)); if (entry.Elevation != null) { textBoxElevationEnabled.Text = entry.Elevation.Enabled.ToString(); textBoxElevationAutoApproval.Text = entry.Elevation.AutoApproval.ToString(); textBoxElevationIconReference.Text = GetStringValue(entry.Elevation.IconReference); foreach (COMCLSIDEntry vso in entry.Elevation.VirtualServerObjects.Select(v => m_registry.MapClsidToEntry(v))) { ListViewItem item = listViewElevationVSOs.Items.Add(vso.Name); item.SubItems.Add(vso.Clsid.ToString()); item.SubItems.Add(vso.CanElevate.ToString()); item.SubItems.Add(vso.AutoElevation.ToString()); item.Tag = vso; } listViewElevationVSOs.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewElevationVSOs.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); listViewElevationVSOs.ListViewItemSorter = new ListItemComparer(0); tabControlProperties.TabPages.Add(tabPageElevation); } if (entry.Servers.ContainsKey(COMServerType.InProcServer32) && entry.Servers[COMServerType.InProcServer32].HasDotNet) { COMCLSIDServerDotNetEntry dotnet = entry.Servers[COMServerType.InProcServer32].DotNet; textBoxDotNetAssemblyName.Text = dotnet.AssemblyName; textBoxDotNetClassName.Text = dotnet.ClassName; textBoxDotNetCodeBase.Text = dotnet.CodeBase; textBoxDotNetRuntimeVersion.Text = dotnet.RuntimeVersion; tabControlProperties.TabPages.Add(tabPageDotNet); } m_clsid = entry; }
private static TreeNode CreateClsidNode(COMCLSIDEntry ent) { TreeNode currNode = new TreeNode(ent.Name, ClassIcon, ClassIcon); currNode.ToolTipText = BuildCLSIDToolTip(ent); currNode.Tag = ent; currNode.Nodes.Add("IUnknown"); return currNode; }
private TreeNode CreateCLSIDNode(COMCLSIDEntry ent) { TreeNode nodeRet = new TreeNode(String.Format("{0} - {1}", ent.Clsid.ToString(), ent.Name), ClassIcon, ClassIcon); nodeRet.ToolTipText = BuildCLSIDToolTip(ent); nodeRet.Tag = ent; nodeRet.Nodes.Add("IUnknown"); return nodeRet; }
/// <summary> /// Build a tooltip for a CLSID entry /// </summary> /// <param name="ent">The CLSID entry to build the tool tip from</param> /// <returns>A string tooltip</returns> private static string BuildCLSIDToolTip(COMCLSIDEntry ent) { StringBuilder strRet = new StringBuilder(); AppendFormatLine(strRet, "CLSID: {0}", ent.Clsid.ToString("B")); AppendFormatLine(strRet, "Name: {0}", ent.Name); AppendFormatLine(strRet, "{0}: {1}", ent.ServerType.ToString(), ent.Server); IEnumerable<string> progids = ent.ProgIDs; if (progids.Count() > 0) { strRet.AppendLine("ProgIDs:"); foreach (string progid in progids) { AppendFormatLine(strRet, "{0}", progid); } } if (ent.AppID != Guid.Empty) { AppendFormatLine(strRet, "AppID: {0}", ent.AppID.ToString("B")); } if (ent.TypeLib != Guid.Empty) { AppendFormatLine(strRet, "TypeLib: {0}", ent.TypeLib.ToString("B")); } IEnumerable<COMInterfaceEntry> proxies = ent.Proxies; if (proxies.Count() > 0) { AppendFormatLine(strRet, "Interface Proxies: {0}", proxies.Count()); } return strRet.ToString(); }
public static Guid[] GetInterfaces(COMCLSIDEntry ent) { string strProcess; strProcess = Path.Combine(COMUtilities.GetAppDirectory(), "EnumerateInterfaces.exe"); Process proc = new Process(); ProcessStartInfo info = new ProcessStartInfo(strProcess, String.Format("{0} s {1} {2}", ent.Clsid.ToString("B"), (int)ent.CreateContext, COMInterfaceEntry.IID_IMarshal.ToString("B"))); info.UseShellExecute = false; info.CreateNoWindow = true; info.RedirectStandardOutput = true; proc.StartInfo = info; proc.Start(); string strOutput = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); List<Guid> guids = new List<Guid>(); TextReader reader = new StringReader(strOutput); while (true) { string line = reader.ReadLine(); if (line == null) { break; } if (line.StartsWith("ERROR:")) { uint errorCode; try { errorCode = uint.Parse(line.Substring(6), System.Globalization.NumberStyles.AllowHexSpecifier); } catch (FormatException ex) { Debug.WriteLine(ex.ToString()); errorCode = 0x80004005; } throw new Win32Exception((int)errorCode); } else { try { guids.Add(new Guid(line)); } catch (FormatException ex) { Debug.WriteLine(ex.ToString()); } } } if (proc.ExitCode == 0) { return guids.ToArray(); } else { return new Guid[] { COMInterfaceEntry.IID_IUnknown }; } }
abstract public Control CreateInstance(COMRegistry registry, COMCLSIDEntry entry, string strObjName, ObjectEntry pObject);
public async static Task<COMEnumerateInterfaces> GetInterfacesOOP(COMCLSIDEntry ent) { using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(System.IO.Pipes.PipeDirection.In, HandleInheritability.Inheritable, 16 * 1024, null)) { string process = null; if (!Environment.Is64BitOperatingSystem || Environment.Is64BitProcess) { process = COMUtilities.GetExePath(); } else { process = COMUtilities.Get32bitExePath(); } string apartment = "s"; if (ent.ThreadingModel == COMThreadingModel.Both || ent.ThreadingModel == COMThreadingModel.Free) { apartment = "m"; } Process proc = new Process(); ProcessStartInfo info = new ProcessStartInfo(process, String.Format("{0} {1} {2} {3} \"{4}\"", "-e", server.GetClientHandleAsString(), ent.Clsid.ToString("B"), apartment, ent.CreateContext)); info.UseShellExecute = false; info.CreateNoWindow = true; proc.StartInfo = info; proc.Start(); try { server.DisposeLocalCopyOfClientHandle(); using (StreamReader reader = new StreamReader(server)) { List<COMInterfaceInstance> interfaces = new List<COMInterfaceInstance>(); List<COMInterfaceInstance> factory_interfaces = new List<COMInterfaceInstance>(); while (true) { string line = await reader.ReadLineAsync(); if (line == null) { break; } if (line.StartsWith("ERROR:")) { uint errorCode; try { errorCode = uint.Parse(line.Substring(6), System.Globalization.NumberStyles.AllowHexSpecifier); } catch (FormatException ex) { Debug.WriteLine(ex.ToString()); errorCode = 0x80004005; } throw new Win32Exception((int)errorCode); } else { Guid g; bool factory = false; if (line.StartsWith("*")) { factory = true; line = line.Substring(1); } string[] parts = line.Split(new char[] { ',' }, 3); if (Guid.TryParse(parts[0], out g)) { string module_path = null; long vtable_offset = 0; if (parts.Length == 3) { module_path = parts[1]; long.TryParse(parts[2], out vtable_offset); } if (factory) { factory_interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset)); } else { interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset)); } } } } if (!proc.WaitForExit(5000)) { proc.Kill(); } int exitCode = proc.ExitCode; if (exitCode != 0) { interfaces = new List<COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) }); factory_interfaces = new List<COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) }); } return new COMEnumerateInterfaces(ent.Clsid, ent.CreateContext, interfaces, factory_interfaces); } } finally { proc.Close(); } } }
public Control CreateInstance(COMRegistry registry, COMCLSIDEntry entry, string strObjName, ObjectEntry pObject) { return(new PersistStreamTypeViewer(strObjName, pObject.Instance)); }
public async Task CreateInstanceFromCLSID(Guid clsid, CLSCTX clsctx, bool class_factory) { try { COMCLSIDEntry ent = null; Dictionary <string, string> props = new Dictionary <string, string>(); object comObj = null; string strObjName = ""; IEnumerable <COMInterfaceEntry> ints = null; if (m_registry.Clsids.ContainsKey(clsid)) { ent = m_registry.Clsids[clsid]; strObjName = ent.Name; props.Add("CLSID", ent.Clsid.FormatGuid()); props.Add("Name", ent.Name); props.Add("Server", ent.DefaultServer); await ent.LoadSupportedInterfacesAsync(false, null); if (class_factory) { comObj = ent.CreateClassFactory(); ints = ent.FactoryInterfaces.Select(i => m_registry.MapIidToInterface(i.Iid)); } else { comObj = ent.CreateInstanceAsObject(clsctx, null); ints = ent.Interfaces.Select(i => m_registry.MapIidToInterface(i.Iid)); } } else { Guid unk = COMInterfaceEntry.IID_IUnknown; IntPtr pObj; int hr; if (class_factory) { hr = COMUtilities.CoGetClassObject(ref clsid, clsctx, null, ref unk, out pObj); } else { hr = COMUtilities.CoCreateInstance(ref clsid, IntPtr.Zero, clsctx, ref unk, out pObj); } if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } try { ints = m_registry.GetInterfacesForIUnknown(pObj).ToArray(); comObj = Marshal.GetObjectForIUnknown(pObj); strObjName = clsid.FormatGuid(); props.Add("CLSID", clsid.FormatGuid()); } finally { Marshal.Release(pObj); } } if (comObj != null) { /* Need to implement a type library reader */ Type dispType = COMUtilities.GetDispatchTypeInfo(this, comObj); HostControl(new ObjectInformation(m_registry, ent, strObjName, comObj, props, ints.ToArray())); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public override Control CreateInstance(COMRegistry registry, COMCLSIDEntry entry, string strObjName, ObjectEntry pObject) { return(new TypedObjectViewer(registry, strObjName, pObject, m_type)); }
private static void AddEntryToDictionary(Dictionary<string, List<COMCLSIDEntry>> dict, COMCLSIDEntry entry) { List<COMCLSIDEntry> list = null; string strServer = entry.Server.ToLower(); if (dict.ContainsKey(strServer)) { list = dict[strServer]; } else { list = new List<COMCLSIDEntry>(); dict[strServer] = list; } list.Add(entry); }
/// <summary> /// Load CLSID information from the registry key /// </summary> /// <param name="rootKey">The root registry key, e.g. HKEY_CLASSES_ROOT</param> private void LoadCLSIDs(RegistryKey rootKey) { Dictionary<Guid, COMCLSIDEntry> clsids = new Dictionary<Guid, COMCLSIDEntry>(); Dictionary<string, List<COMCLSIDEntry>> clsidbyserver = new Dictionary<string, List<COMCLSIDEntry>>(); Dictionary<string, List<COMCLSIDEntry>> clsidbylocalserver = new Dictionary<string, List<COMCLSIDEntry>>(); Dictionary<string, List<COMCLSIDEntry>> clsidwithsurrogate = new Dictionary<string, List<COMCLSIDEntry>>(); m_categories = new Dictionary<Guid, List<COMCLSIDEntry>>(); using (RegistryKey clsidKey = rootKey.OpenSubKey("CLSID")) { if (clsidKey != null) { string[] subkeys = clsidKey.GetSubKeyNames(); foreach (string key in subkeys) { Guid clsid; if(Guid.TryParse(key, out clsid)) { if (!clsids.ContainsKey(clsid)) { using (RegistryKey regKey = clsidKey.OpenSubKey(key)) { if (regKey != null) { COMCLSIDEntry ent = new COMCLSIDEntry(this, clsid, regKey); clsids.Add(clsid, ent); if (!String.IsNullOrEmpty(ent.Server) && ent.ServerType != (COMServerType.UnknownServer)) { AddEntryToDictionary(clsidbyserver, ent); if (ent.ServerType == COMServerType.LocalServer32) { AddEntryToDictionary(clsidbylocalserver, ent); } if (m_appid.ContainsKey(ent.AppID) && m_appid[ent.AppID].DllSurrogate != null) { AddEntryToDictionary(clsidwithsurrogate, ent); } } if (ent.Categories.Length > 0) { foreach (Guid catid in ent.Categories) { List<COMCLSIDEntry> list = null; if (m_categories.ContainsKey(catid)) { list = m_categories[catid]; } else { list = new List<COMCLSIDEntry>(); m_categories[catid] = list; } list.Add(ent); } } } } } } } } } int pos = 0; m_clsidbyname = new COMCLSIDEntry[clsids.Count]; foreach (COMCLSIDEntry ent in clsids.Values) { m_clsidbyname[pos++] = ent; } Array.Sort(m_clsidbyname); m_clsids = new SortedDictionary<Guid, COMCLSIDEntry>(clsids); m_clsidbyserver = new SortedDictionary<string, List<COMCLSIDEntry>>(clsidbyserver); m_clsidbylocalserver = new SortedDictionary<string, List<COMCLSIDEntry>>(clsidbylocalserver); m_clsidwithsurrogate = new SortedDictionary<string, List<COMCLSIDEntry>>(clsidwithsurrogate); }
/// <summary> /// Build a tooltip for a CLSID entry /// </summary> /// <param name="ent">The CLSID entry to build the tool tip from</param> /// <returns>A string tooltip</returns> private string BuildCLSIDToolTip(COMCLSIDEntry ent) { StringBuilder strRet = new StringBuilder(); strRet.AppendFormat("CLSID: {0}\n", ent.Clsid.ToString("B")); strRet.AppendFormat("Name: {0}\n", ent.Name); strRet.AppendFormat("{0}: {1}\n", ent.Type.ToString(), ent.Server); string[] progids = ent.ProgIDs; if (progids.Length > 0) { strRet.Append("ProgIDs:\n"); foreach (string progid in progids) { strRet.AppendFormat("{0}\n", progid); } } if (ent.AppID != Guid.Empty) { strRet.AppendFormat("AppID: {0}\n", ent.AppID.ToString("B")); } if (ent.TypeLib != Guid.Empty) { strRet.AppendFormat("TypeLib: {0}\n", ent.TypeLib.ToString("B")); } COMInterfaceEntry[] proxies = ent.Proxies; if (proxies.Length > 0) { strRet.Append("Interface Proxies:\n"); foreach (COMInterfaceEntry intEnt in proxies) { strRet.AppendFormat("{0} - {1}\n", intEnt.Iid.ToString(), intEnt.Name); } } return strRet.ToString(); }
/// <summary> /// Get list of supported Interface IIDs (that we know about) /// NOTE: This will load the object itself to check what is supported, it _might_ crash the app /// The returned array is cached so subsequent calls to this function return without calling into COM /// </summary> /// <param name="ent">The entry to get the interfaces for</param> /// <param name="bRefresh">Force the supported interface list to refresh</param> /// <returns>An array of supported interfaces</returns> public COMInterfaceEntry[] GetSupportedInterfaces(COMCLSIDEntry ent, bool bRefresh) { COMInterfaceEntry[] retList = null; if (ent != null) { if (m_supportediids.ContainsKey(ent.Clsid)) { retList = m_supportediids[ent.Clsid]; } else { Guid[] guids = EnumerateInterfaces.GetInterfaces(ent); List<COMInterfaceEntry> ents = new List<COMInterfaceEntry>(); foreach (Guid g in guids) { if (m_interfaces.ContainsKey(g)) { ents.Add(m_interfaces[g]); } } ents.Sort(); retList = ents.ToArray(); m_supportediids[ent.Clsid] = retList; } } else { retList = new COMInterfaceEntry[0]; } return retList; }
public override Control CreateInstance(COMRegistry registry, COMCLSIDEntry entry, string strObjName, ObjectEntry pObject) { return(new ElevatedFactoryServerTypeViewer(registry, entry, strObjName, pObject.Instance)); }
/// <summary> /// Load CLSID information from the registry key /// </summary> /// <param name="rootKey">The root registry key, e.g. HKEY_CLASSES_ROOT</param> private void LoadCLSIDs(RegistryKey rootKey) { Dictionary<Guid, COMCLSIDEntry> clsids = new Dictionary<Guid, COMCLSIDEntry>(); Dictionary<string, List<COMCLSIDEntry>> clsidbyserver = new Dictionary<string, List<COMCLSIDEntry>>(); m_categories = new Dictionary<Guid, List<COMCLSIDEntry>>(); RegistryKey clsidKey = rootKey.OpenSubKey("CLSID"); if (clsidKey != null) { string[] subkeys = clsidKey.GetSubKeyNames(); foreach (string key in subkeys) { try { Guid clsid = new Guid(key); if (!clsids.ContainsKey(clsid)) { RegistryKey regKey = clsidKey.OpenSubKey(key); if (regKey != null) { COMCLSIDEntry ent = new COMCLSIDEntry(clsid, regKey); clsids.Add(clsid, ent); if (!String.IsNullOrEmpty(ent.Server) && ent.Type != (COMCLSIDEntry.ServerType.UnknownServer)) { List<COMCLSIDEntry> list = null; string strServer = ent.Server.ToLower(); if (clsidbyserver.ContainsKey(strServer)) { list = clsidbyserver[strServer]; } else { list = new List<COMCLSIDEntry>(); clsidbyserver[strServer] = list; } list.Add(ent); } if (ent.Categories.Length > 0) { foreach (Guid catid in ent.Categories) { List<COMCLSIDEntry> list = null; if (m_categories.ContainsKey(catid)) { list = m_categories[catid]; } else { list = new List<COMCLSIDEntry>(); m_categories[catid] = list; } list.Add(ent); } } regKey.Close(); } } } catch (FormatException e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } } clsidKey.Close(); } int pos = 0; m_clsidbyname = new COMCLSIDEntry[clsids.Count]; foreach (COMCLSIDEntry ent in clsids.Values) { m_clsidbyname[pos++] = ent; } Array.Sort(m_clsidbyname); m_clsids = new SortedDictionary<Guid, COMCLSIDEntry>(clsids); m_clsidbyserver = new SortedDictionary<string, List<COMCLSIDEntry>>(clsidbyserver); }