public CommunicatingApplicationHook(System.Diagnostics.Process targetProcess)
            : base(targetProcess)
        {
            remoteProcess = new Native.Process.RemoteProcess(targetProcess);
            IPC.NamedPipes.NamedPipeServer server = new IPC.NamedPipes.NamedPipeServer();

            PipeId = Guid.NewGuid().ToString();

            Thread t = new Thread(() =>
            {
                server.ConnectionRecieved += (s, e) =>
                {
                    connection = e.Value;
                    while (e.Value.IsConnected)
                    {
                        var msg = e.Value.Receive();
                        if (e.Value.IsConnected && msg != null)
                        {
                            MessageReceived.RaiseEvent(this, msg);
                        }
                    }
                    ConnectionClosed.RaiseEvent(this);
                };
                server.Start(new IPC.NamedPipes.NamedPipeInitialisation(PipeId));
            });
            t.Start();
        }
Пример #2
0
        public CommunicatingApplicationHook(System.Diagnostics.Process targetProcess)
            : base(targetProcess)
        {
            remoteProcess = new Native.Process.RemoteProcess(targetProcess);
            IPC.NamedPipes.NamedPipeServer server = new IPC.NamedPipes.NamedPipeServer();

            PipeId = Guid.NewGuid().ToString();

            Thread t = new Thread(() =>
            {
                server.ConnectionRecieved += (s, e) =>
                {
                    connection = e.Value;
                    while (e.Value.IsConnected)
                    {
                        var msg = e.Value.Receive();
                        if (e.Value.IsConnected && msg != null)
                        {
                            MessageReceived.RaiseEvent(this, msg);
                        }
                    }
                    ConnectionClosed.RaiseEvent(this);
                };
                server.Start(new IPC.NamedPipes.NamedPipeInitialisation(PipeId));
            });

            t.Start();
        }
Пример #3
0
        public IntPtr LoadDotNetModule(string path, string typeName, string method, string args)
        {
            bool x64 = Process.Is64Bit();

            if (x64 != Environment.Is64BitProcess)
            {
                string helper = null;
                //Use helper
                if (x64)
                {
                    helper = CreateFile(string.Format(BOOTSTRAP_EXE, "x64"), Properties.Resources.StUtil_Native_Bootstrapper_x64);
                }
                else
                {
                    helper = CreateFile(string.Format(BOOTSTRAP_EXE, "x86"), Properties.Resources.StUtil_Native_Bootstrapper_x86);
                }
                helper = System.IO.Path.GetFullPath(helper);
                IPC.NamedPipes.NamedPipeServer server = new IPC.NamedPipes.NamedPipeServer();
                Guid      guid   = Guid.NewGuid();
                IntPtr    result = IntPtr.Zero;
                Exception ex     = null;;
                server.ConnectionRecieved += (s, e) =>
                {
                    IPC.IConnectionMessage msg = e.Value.SendAndReceive(new InjectionMessage
                    {
                        File      = path,
                        Type      = typeName,
                        Method    = method,
                        Args      = args,
                        ProcessId = Process.Id
                    });
                    if (msg is IPC.ValueMessage <IntPtr> )
                    {
                        result = ((IPC.ValueMessage <IntPtr>)msg).Value;
                    }
                    else
                    {
                        ex = ((IPC.ValueMessage <Exception>)msg).Value;
                    }
                };
                var p = System.Diagnostics.Process.Start(helper, guid.ToString());
                server.Start(new IPC.NamedPipes.NamedPipeInitialisation(guid.ToString()));
                if (ex != null)
                {
                    throw ex;
                }
                else
                {
                    return(result);
                }
            }
            else
            {
                return(LoadDotNetModuleImpl(path, typeName, method, args));
            }
        }
Пример #4
0
 public IntPtr LoadDotNetModule(string path, string typeName, string method, string args)
 {
     bool x64 = Process.Is64Bit();
     if (x64 != Environment.Is64BitProcess)
     {
         string helper = null;
         //Use helper
         if (x64)
         {
             helper = CreateFile(string.Format(BOOTSTRAP_EXE, "x64"), Properties.Resources.StUtil_Native_Bootstrapper_x64);
         }
         else
         {
             helper = CreateFile(string.Format(BOOTSTRAP_EXE, "x86"), Properties.Resources.StUtil_Native_Bootstrapper_x86);
         }
         helper = System.IO.Path.GetFullPath(helper);
         IPC.NamedPipes.NamedPipeServer server = new IPC.NamedPipes.NamedPipeServer();
         Guid guid = Guid.NewGuid();
         IntPtr result = IntPtr.Zero;
         Exception ex = null; ;
         server.ConnectionRecieved += (s, e) =>
         {
             IPC.IConnectionMessage msg = e.Value.SendAndReceive(new InjectionMessage
             {
                 File = path,
                 Type = typeName,
                 Method = method,
                 Args = args,
                 ProcessId = Process.Id
             });
             if (msg is IPC.ValueMessage<IntPtr>)
             {
                 result = ((IPC.ValueMessage<IntPtr>)msg).Value;
             }
             else
             {
                 ex = ((IPC.ValueMessage<Exception>)msg).Value;
             }
         };
         var p = System.Diagnostics.Process.Start(helper, guid.ToString());
         server.Start(new IPC.NamedPipes.NamedPipeInitialisation(guid.ToString()));
         if (ex != null)
         {
             throw ex;
         }
         else
         {
             return result;
         }
     }
     else
     {
         return LoadDotNetModuleImpl(path, typeName, method, args);
     }
 }