Exemplo n.º 1
0
        public async Task Constructor_PortPartnerPort_PassesMessages()
        {
            i1 = new IpcInterface(13773, 13774);
            i2 = new IpcInterface(i1.PartnerPort, i1.Port);

            await SpinlockForMessage();
        }
Exemplo n.º 2
0
        /// <summary>
        /// This callback is invoked whenever this process calls CreateFile(). This is where we can modify parameters and other cool things.
        /// </summary>
        /// <remarks>
        /// The method signature must match the original CreateFile().
        /// </remarks>
        private IntPtr OnCreateFile(string filePath, uint desiredAccess, uint shareMode, IntPtr securityAttributes, uint creationDisposition, uint flags, IntPtr templateFile)
        {
            try
            {
                /*
                 * Note that we can do whatever we want in this callback. We could change the file path, return an access denied (pretend we're an antivirus program),
                 * but we won't do that in this program. This program only monitors file access from processes.
                 */

                var fileEntry = new FileEntry()
                {
                    FullPath = filePath, Timestamp = DateTime.Now
                };
                var processId = Process.GetCurrentProcess().Id;

                IpcInterface.AddFileEntry(processId, fileEntry);
            }
            catch (Exception ex)
            {
                IpcInterface.PostException(ex);
            }

            // The process had originally intended to call CreateFile(), so let's actually call Windows' original CreateFile()
            return(CreateFile(filePath, desiredAccess, shareMode, securityAttributes, creationDisposition, flags, templateFile));
        }
Exemplo n.º 3
0
        public static async Task MainAsync(string[] args)
        {
            var i2 = new IpcInterface(int.Parse(args[0]), int.Parse(args[1]));
            await i2.SendMessage(new DummyClass());

            await Task.Delay(-1);
        }
Exemplo n.º 4
0
        public async Task ReceiveMessage_AvgTimeIsBelow1Ms()
        {
            i1 = new IpcInterface();
            i2 = new IpcInterface(i1.PartnerPort, i1.Port);
            var dummyClass = new DummyClass();
            var stopwatch  = new Stopwatch();

            var spinLock = true;

            i1.On <DummyClass>(dc =>
            {
                stopwatch.Stop();
                spinLock = false;
            });

            for (var i = 0; i < Iterations; i++)
            {
                await i2.SendMessage(dummyClass);

                stopwatch.Start();
                while (spinLock)
                {
                    await Task.Delay(1);
                }
                spinLock = true;
            }

            var averageMs = stopwatch.ElapsedMilliseconds / Iterations;

            Assert.IsTrue(averageMs <= 1, "Expected <=1ms, got {0}ms", averageMs);
        }
Exemplo n.º 5
0
        public async Task Constructor_HttpClientPortPartnerPort_PassesMessages()
        {
            using var http = new HttpClient();
            i1             = new IpcInterface(http, 13773, 13774);
            i2             = new IpcInterface(i1.PartnerPort, i1.Port);

            await SpinlockForMessage();
        }
Exemplo n.º 6
0
        public void SendFileList(params string[] files)
        {
            var ipc = new IpcInterface();

            foreach (string file in files)
            {
                ipc.AddInputFile(file);
            }

            ipc.UpdateUI();
        }
Exemplo n.º 7
0
 /// <summary>
 ///  When accepted client tries to make connection.
 /// </summary>
 /// <param name="pipe">the pipe</param>
 /// <param name="status">status of connect</param>
 /// <remarks>hen this function calls, it is right before making connection,
 /// so user can configure the pipe before the connection is actually made.	</remarks>
 public void OnNewConnection(IpcInterface pipe, IpcConnectStatus status)
 {
     if (status == IpcConnectStatus.SUCCESS)
     {
         if (!m_pipes.Contains(pipe))
         {
             m_pipes.Add(pipe);
         }
     }
     m_options.m_callBackObj.OnNewConnection(this, pipe, status);
 }
Exemplo n.º 8
0
        public void SendFileList(params string[] files)
        {
            var ipc = new IpcInterface();

            foreach (string file in files)
            {
                ipc.AddInputFile(file);
            }

            ipc.UpdateUI();
        }
Exemplo n.º 9
0
        public FormMain()
        {
            InitializeComponent();

            //  Prevent ListView flickering
            ListViewHelper.EnableDoubleBuffer(ListViewLog);
            ListViewHelper.EnableDoubleBuffer(ListViewProcesses);

            IpcInterface = new IpcInterface();
            IpcInterface.OnMessagePosted += IpcInterface_OnMessagePosted;
            ProcessEntries = new List <ProcessEntry>();
        }
Exemplo n.º 10
0
 public void Unload()
 {
     try
     {
         // We're exiting our program now
         IpcInterface.TerminatingProcesses.Remove(Process.GetCurrentProcess().Id);
         CreateFileHook.Dispose();
     }
     catch (Exception ex)
     {
         IpcInterface.PostException(ex);
     }
 }
Exemplo n.º 11
0
        public async Task SendMessage_WorksWithActualChildProcess()
        {
            i1 = new IpcInterface();
            var spinLock = true;

            i1.On <DummyClass>(dummyClass => { spinLock = false; });
            var path    = Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", "..", "SimpleIPCHttp.TestDummy", "bin", "Debug", "netcoreapp3.1", "SimpleIPCHttp.TestDummy.exe");
            var program = Process.Start(path, $"{i1.PartnerPort} {i1.Port}");

            while (spinLock)
            {
                await Task.Delay(SpinlockWait);
            }
            program.Kill();
        }
Exemplo n.º 12
0
 /// <summary>
 ///  The pipe is disconnected.
 /// </summary>
 /// <param name="pipe">the pipe, disconnected.</param>
 public void OnDisconnected(IpcInterface pipe)
 {
     lock (m_pipes)
     {
         if (m_pipes.Contains(pipe))
         {
             m_pipes.Remove(pipe);
         }
         if (m_started)
         {
             pipe.Reconnect();
         }
     }
     m_options.m_callBackObj.OnDisconnected(this, pipe);
 }
Exemplo n.º 13
0
        public async Task On_FiresOnCorrectTypeOnly()
        {
            i1 = new IpcInterface();
            i2 = new IpcInterface(i1.PartnerPort, i1.Port);

            var spinLock = true;

            i1.On <DummyClass>(dummyClass => { spinLock = false; });
            i1.On <DummierClass>(dummierClass => {});
            await i2.SendMessage(new DummierClass());

            await Task.Delay(SpinlockWait * 5000);

            Assert.IsTrue(spinLock);
        }
Exemplo n.º 14
0
        public void Load()
        {
            try
            {
                CreateFileHook = LocalHook.Create(
                    LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"),
                    new CreateFileDelegate(OnCreateFile),
                    this);

                // All hooks start de-activated
                // The following ensures that this hook can be intercepted from all threads of this process
                CreateFileHook.ThreadACL.SetExclusiveACL(new Int32[1]);
            }
            catch (Exception ex)
            {
                IpcInterface.PostException(ex);
            }
        }
Exemplo n.º 15
0
        private void ButtonInject_CheckedChanged(object sender, System.EventArgs e)
        {
            if (this.ButtonInject.IsDepressed)
            {
                try
                {
                    var processName = this.TextBoxProcess.Text;
                    var processes   = Process.GetProcessesByName(processName);

                    if (processes.Any())
                    {
                        this.IpcInterface = new IpcInterface();

                        if (CheckStartPaused.Checked)
                        {
                            IpcInterface.StartPaused = true;
                        }

                        InjectionHelper.IpcServerCreateListeningChannel(this.IpcInterface);

                        EasyHook.Config.Register("Starcraft 2 AI Bot",
                                                 "Logging.dll",
                                                 "RemotingInterface.dll",
                                                 "Interceptor.dll",
                                                 "Game.dll",
                                                 "Direct3D9Hook.dll",
                                                 "NLog.dll",
                                                 "SharpDX.dll",
                                                 "SharpDX.Direct3D9.dll");

                        InjectionHelper.Inject("Interceptor.dll", "Interceptor.dll", processes.First().Id);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Injection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                // Should exit, but not implemented
            }
        }
Exemplo n.º 16
0
        public void Main()
        {
            try
            {
                // All of our program's main execution takes place within the OnCreateFile() hook callback. So we don't really do anything here.
                // Except Ping() our FileMonitorController program to make sure it's still alive; if it's closed, we should also close
                while (!IpcInterface.TerminatingProcesses.Contains(Process.GetCurrentProcess().Id))
                {
                    Thread.Sleep(0);
                    IpcInterface.Ping();
                }

                // When this method returns (and, consequently, Run()), our injected DLL terminates and that's the end of our program (though Unload() will be called first)
            }
            catch (Exception ex)
            {
                IpcInterface.PostException(ex);
            }
        }
Exemplo n.º 17
0
        public async Task SendMessage_AvgTimeIsBelow1Ms()
        {
            i1 = new IpcInterface();
            i2 = new IpcInterface(i1.PartnerPort, i1.Port);
            var stopwatch = new Stopwatch();

            i1.On <DummyClass>(dummyClass => {});

            for (var i = 0; i < Iterations; i++)
            {
                stopwatch.Start();
                await i2.SendMessage(new DummyClass());

                stopwatch.Stop();
            }

            var averageMs = stopwatch.ElapsedMilliseconds / Iterations;

            Assert.IsTrue(averageMs <= 1, "Expected <=1ms, got {0}ms", averageMs);
        }
Exemplo n.º 18
0
        public MogmogInteropConnectionManager(MogmogConfiguration config, HttpClient client)
        {
            this.client = client;
            this.ipc    = new IpcInterface(client);

            this.ipc.On <ChatMessageInterop>(ChatMessageReceived);
            this.ipc.On <GenericInterop>(LogMessageReceived);

            var filePath         = Path.Combine(Assembly.GetExecutingAssembly().Location, "..", "Mogmog.FFXIV.UpgradeLayer.exe");
            var serializedConfig = JsonConvert.SerializeObject(config).Replace("\"", "\\\"");
            var args             = $"{serializedConfig} {this.ipc.PartnerPort} {this.ipc.Port}";
            var startInfo        = new ProcessStartInfo(filePath, string.Join(" ", args))
            {
                CreateNoWindow  = true,
                UseShellExecute = false,
                WindowStyle     = ProcessWindowStyle.Hidden,
            };

            this.upgradeLayer = Process.Start(startInfo);
        }
Exemplo n.º 19
0
 public static void IpcServerCreateListeningChannel(IpcInterface ipcInterface)
 {
     ipcServer = RemoteHooking.IpcCreateServer <IpcInterface>(ref IpcChannelName, WellKnownObjectMode.Singleton, ipcInterface, IpcChannelName, true, WellKnownSidType.WorldSid);
 }
Exemplo n.º 20
0
 public virtual void CreateSocket(byte _0, out uint _1, out IpcInterface _2) => throw new NotImplementedException();
Exemplo n.º 21
0
 public virtual void Accept(out byte[] _0, out uint _1, out IpcInterface _2) => throw new NotImplementedException();
Exemplo n.º 22
0
 /// <summary>
 ///  When accepted client tries to make connection.
 /// </summary>
 /// <param name="pipe">the pipe</param>
 /// <param name="status">status of connect</param>
 /// <remarks>hen this function calls, it is right before making connection,
 /// so user can configure the pipe before the connection is actually made.	</remarks>
 public void OnNewConnection(IpcInterface pipe, IpcConnectStatus status)
 {
     if (status == IpcConnectStatus.SUCCESS)
     {
         if (!m_pipes.Contains(pipe))
             m_pipes.Add(pipe);
     }
     m_options.m_callBackObj.OnNewConnection(this, pipe, status);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Received the data from the client.
 /// </summary>
 /// <param name="pipe">the pipe which received the packet</param>
 /// <param name="receivedData">the received data</param>
 /// <param name="receivedDataByteSize">the received data byte size</param>
 public void OnReadComplete(IpcInterface pipe, byte[] receivedData, int receivedDataByteSize)
 {
     m_options.m_callBackObj.OnReadComplete(this, pipe, receivedData, receivedDataByteSize);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Received the packet from the client.
 /// </summary>
 /// <param name="pipe">the pipe which wrote the packet</param>
 /// <param name="status">the status of write</param>
 public void OnWriteComplete(IpcInterface pipe, IpcWriteStatus status)
 {
     m_options.m_callBackObj.OnWriteComplete(this, pipe, status);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Received the packet from the client.
 /// </summary>
 /// <param name="pipe">the pipe which wrote the packet</param>
 /// <param name="status">the status of write</param>
 public void OnWriteComplete(IpcInterface pipe, IpcWriteStatus status)
 {
     m_options.m_callBackObj.OnWriteComplete(this, pipe, status);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Received the data from the client.
 /// </summary>
 /// <param name="pipe">the pipe which received the packet</param>
 /// <param name="receivedData">the received data</param>
 /// <param name="receivedDataByteSize">the received data byte size</param>
 public void OnReadComplete(IpcInterface pipe, byte[] receivedData, int receivedDataByteSize)
 {
     m_options.m_callBackObj.OnReadComplete(this, pipe, receivedData, receivedDataByteSize);
 }
Exemplo n.º 27
0
 /// <summary>
 ///  The pipe is disconnected.
 /// </summary>
 /// <param name="pipe">the pipe, disconnected.</param>
 public void OnDisconnected(IpcInterface pipe)
 {
     lock (m_pipes)
     {
         if (m_pipes.Contains(pipe))
             m_pipes.Remove(pipe);
         if(m_started)
             pipe.Reconnect();
     }
     m_options.m_callBackObj.OnDisconnected(this, pipe);
 }
Exemplo n.º 28
0
 public void Constructor_Default_PortsAreConsistent()
 {
     i1 = new IpcInterface();
     i2 = new IpcInterface(i1.PartnerPort, i1.Port);
     Assert.IsTrue(i1.Port == i2.PartnerPort && i1.PartnerPort == i2.Port, "Got i1: [{0} {1}] i2: [{2} {3}], expected i1: [{0} {1}] i2: [{0} {1}]", i1.Port, i1.PartnerPort, i2.Port, i2.PartnerPort);
 }
Exemplo n.º 29
0
 public virtual void CreateSocketOld(out uint _0, out IpcInterface _1) => throw new NotImplementedException();
Exemplo n.º 30
0
 static IpcInterface RemoveDuplicates(IpcInterface iface) =>