/* * This source code is provided "AS IS" with no warranties, and confers no rights. */ using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using Microsoft.Win32; namespace SWI.ClassId_q { public class Ole32 { public static Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); public static Guid IID_IDispatch = new Guid("00020400-0000-0000-C000-000000000046"); public static Guid IID_IDispatchEx = new Guid("a6ef9860-c720-11d0-9337-00a0c90dcaa9"); public static Guid IID_IObjectSafety = new Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064"); public static Guid IID_IPersist = new Guid("0000010C-0000-0000-C000-000000000046"); public static Guid IID_IPersistStorage = new Guid("0000010A-0000-0000-C000-000000000046"); public static Guid IID_IPersistStream = new Guid("00000109-0000-0000-C000-000000000046"); public static Guid IID_IPersistPropertyBag = new Guid("37D84F60-42CB-11CE-8135-00AA004BB851"); public static int INTERFACE_SAFE_FOR_UNTRUSTED_CALLER = 0x00000001; public static int INTERFACE_SAFE_FOR_UNTRUSTED_DATA = 0x00000002; public static int S_OK = 0; public static int E_FAIL = unchecked((int)0x80004005); public static int E_NOINTERFACE = unchecked((int)0x80004002); } [ComImport, GuidAttribute("CB5BDC81-93C1-11CF-8F20-00805F2CD064"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] public interface IObjectSafety { [PreserveSig] int GetInterfaceSafetyOptions(ref Guid iid, ref Int32 supported_options, ref Int32 enabled_options); [PreserveSig()] int SetInterfaceSafetyOptions(ref Guid iid, Int32 options_mask, Int32 enabled_options); } class ClassId { private string clsid; public ClassId() { } public string get_clsid() { return clsid; } public void set_clsid(string value) { clsid = value; } public string get_progid() { RegistryKey reg; string ret_value = null; reg = Registry.ClassesRoot.OpenSubKey("CLSID\\" + clsid + "\\ProgId"); if (reg == null) { ret_value = null; } else { if (reg.GetValue(null) != null) { ret_value = reg.GetValue(null).ToString(); } else { ret_value = null; } reg.Close(); } return ret_value; } public string get_binary_path() { RegistryKey reg; string ret_value = null; reg = Registry.ClassesRoot.OpenSubKey("CLSID\\" + clsid + "\\InProcServer32"); if (reg == null) reg = Registry.ClassesRoot.OpenSubKey("CLSID\\" + clsid + "\\InProcServer"); if (reg == null) reg = Registry.ClassesRoot.OpenSubKey("CLSID\\" + clsid + "\\LocalServer32"); if (reg == null) reg = Registry.ClassesRoot.OpenSubKey("CLSID\\" + clsid + "\\LocalServer"); if (reg == null) { ret_value = null; } else { if (reg.GetValue(null) != null) { ret_value = reg.GetValue(null).ToString(); } else { ret_value = null; } reg.Close(); } return ret_value; } public bool get_safe_for_scripting_registry() { RegistryKey reg; bool ret_value = false; reg = Registry.ClassesRoot; reg = reg.OpenSubKey("CLSID\\" + clsid + "\\Implemented Categories\\{7DD95801-9882-11CF-9FA9-00AA006C42C4}"); if (reg == null) { ret_value = false; } else { ret_value = true; reg.Close(); } return ret_value; } public bool get_safe_for_initialization_registry() { RegistryKey reg; bool ret_value = false; reg = Registry.ClassesRoot; reg = reg.OpenSubKey("CLSID\\" + clsid + "\\Implemented Categories\\{7DD95802-9882-11CF-9FA9-00AA006C42C4}"); if (reg == null) { ret_value = false; } else { ret_value = true; reg.Close(); } return ret_value; } public bool get_implements_iobjectsafety() { Guid g_clsid; try { g_clsid = new Guid(clsid.Substring(1, 36)); object com = Activator.CreateInstance(Type.GetTypeFromCLSID(g_clsid)); IntPtr iunk = Marshal.GetIUnknownForObject(com); IntPtr out_ptr = new IntPtr(); int result = Marshal.QueryInterface(iunk, ref Ole32.IID_IObjectSafety, out out_ptr); if (result == 0) { return true; } } catch (Exception) { return false; } return false; } public bool get_safe_for_initialization_iobjectsafety() { Guid g_clsid; try { g_clsid = new Guid(clsid.Substring(1, 36)); object com = Activator.CreateInstance(Type.GetTypeFromCLSID(g_clsid)); IObjectSafety obj = com as IObjectSafety; int ret; ret = obj.SetInterfaceSafetyOptions(ref Ole32.IID_IPersist, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA); if (ret == Ole32.S_OK) { return true; } if (ret == Ole32.E_NOINTERFACE) { ret = obj.SetInterfaceSafetyOptions(ref Ole32.IID_IPersistPropertyBag, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA); if (ret == Ole32.S_OK) { return true; } if (ret == Ole32.E_NOINTERFACE) { ret = obj.SetInterfaceSafetyOptions(ref Ole32.IID_IPersistStorage, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA); if (ret == Ole32.S_OK) { return true; } if (ret == Ole32.E_NOINTERFACE) { ret = obj.SetInterfaceSafetyOptions(ref Ole32.IID_IPersistStream, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_DATA); if (ret == Ole32.S_OK) { return true; } } } } } catch (Exception e) { return false; } return false; } public bool get_safe_for_scripting_iobjectsafety() { Guid g_clsid; try { g_clsid = new Guid(clsid.Substring(1, 36)); object com = Activator.CreateInstance(Type.GetTypeFromCLSID(g_clsid)); IObjectSafety obj = com as IObjectSafety; int ret; ret = obj.SetInterfaceSafetyOptions(ref Ole32.IID_IDispatchEx, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_CALLER, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_CALLER); if (ret == Ole32.S_OK) { return true; } if (ret == Ole32.E_NOINTERFACE) { ret = obj.SetInterfaceSafetyOptions(ref Ole32.IID_IDispatch, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_CALLER, Ole32.INTERFACE_SAFE_FOR_UNTRUSTED_CALLER); if (ret == Ole32.S_OK) { return true; } } } catch (Exception) { return false; } return false; } public bool get_killbitted() { RegistryKey reg; bool ret_value = false; reg = Registry.LocalMachine; reg = reg.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Activex Compatibility\\" + clsid); if (reg == null) { ret_value = false; } else { Int32 comp_flags = Int32.Parse(reg.GetValue("Compatibility Flags").ToString()); if ((comp_flags & 0x400) != 0) { ret_value = true; } else { ret_value = false; } reg.Close(); } return ret_value; } public override string ToString() { string ret = ""; ret += "Clsid: " + get_clsid() + Environment.NewLine; if (get_progid() != null) ret += "Progid: " + get_progid() + Environment.NewLine; if (get_binary_path() != null) ret += "Binary Path: " + get_binary_path() + Environment.NewLine; ret += "Implements IObjectSafety: " + get_implements_iobjectsafety() + Environment.NewLine; if (get_implements_iobjectsafety() == true) { ret += "Safe For Initialization (IObjectSafety): " + get_safe_for_initialization_iobjectsafety() + Environment.NewLine; ret += "Safe For Scripting (IObjectSafety): " + get_safe_for_scripting_iobjectsafety() + Environment.NewLine; } ret += "Safe For Initialization (Registry): " + get_safe_for_initialization_registry() + Environment.NewLine; ret += "Safe For Scripting (Registry): " + get_safe_for_scripting_registry() + Environment.NewLine; ret += "KillBitted: " + get_killbitted() + Environment.NewLine; return (ret); } } }