Пример #1
0
 public EntryPoint(RemoteHooking.IContext context, string channelName, EntryPointParameters parameter)
 {
     // connect to host
     _remoteObject = RemoteHooking.IpcConnectClient <CustomRemoteObject>(channelName);
     _remoteObject.TriggerPingEvent();
 }
Пример #2
0
        private static void Main(string[] args)
        {
            if (!IsAdministrator())
            {
                throw new Exception("Run this app as administrator");
            }

            Console.WriteLine("Waiting for process...");

            Process process = null;

            while (process == null)
            {
                process = Process.GetProcessesByName("Setup")
                          .Where(IsRadStudioSetupProcess)
                          .FirstOrDefault();
                if (process == null)
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(500));
                }
                else
                {
                    Console.WriteLine("Process found");
                }
            }

            DateTime?latestPing = null;
            bool     exited     = false;

            var remoteObject = new CustomRemoteObject();

            remoteObject.InjectionEvent += (sender, eventArgs) => { Console.WriteLine($"Injected into {eventArgs.ClientProcessId}"); };
            remoteObject.MessageEvent   += (sender, eventArgs) => { Console.WriteLine($"Message: {eventArgs.Message}"); };
            remoteObject.PingEvent      += (sender, eventArgs) => { latestPing = DateTime.UtcNow; };
            remoteObject.ExitEvent      += (sender, eventArgs) => { exited = true; };
            remoteObject.ExceptionEvent += (sender, eventArgs) => { Console.WriteLine($"Exception: {eventArgs.SerializedException}"); };

            string channelName      = null;
            var    ipcServerChannel = RemoteHooking.IpcCreateServer <CustomRemoteObject>(ref channelName, WellKnownObjectMode.Singleton, remoteObject);

            var parameter = new EntryPointParameters
            {
                Message       = "hello world",
                HostProcessId = RemoteHooking.GetCurrentProcessId(),
            };

            var processId = process.Id;

            RemoteHooking.Inject(processId,
                                 InjectionOptions.Default | InjectionOptions.DoNotRequireStrongName,
                                 typeof(EntryPointParameters).Assembly.Location,
                                 typeof(EntryPointParameters).Assembly.Location,
                                 channelName,
                                 parameter);

            while (!process.HasExited)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(100));
                if (exited)
                {
                    Console.WriteLine("Exit event received");
                    break;
                }

                /*
                 * if (latestPing.HasValue && DateTime.UtcNow.Subtract(latestPing.Value) > TimeSpan.FromSeconds(2))
                 * {
                 *  Console.WriteLine("Ping timeout");
                 *  break;
                 * }
                 */
            }
        }