Ejemplo n.º 1
0
        public HookProcess(Process process, OverlayConfig overlayConfig, OverlayInterface overlayInterface)
        {
            if (HookManager.IsHooked(process.Id))
            {
                throw new ProcessAlreadyHookedException();
            }

            overlayInterface.ProcessID = process.Id;
            OverlayInterface = overlayInterface;

            Server = RemoteHooking.IpcCreateServer<OverlayInterface>(ref ChannelName, WellKnownObjectMode.Singleton, OverlayInterface);

            try
            {
                var libraryName = typeof (OverlayInterface).Assembly.GetName()
                                                           .Name + ".dll";
                var location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, libraryName);
                RemoteHooking.Inject(process.Id, InjectionOptions.NoService | InjectionOptions.DoNotRequireStrongName, location, location, ChannelName, overlayConfig);
            }
            catch (Exception ex)
            {
                throw new InjectionFailedException(ex);
            }
            HookManager.AddHookedProcess(process.Id);
            InjectedProcess = process;
        }
Ejemplo n.º 2
0
        public EntryPoint(RemoteHooking.IContext inContext, string inChannelName, OverlayConfig overlayConfig)
        {
            _interface = RemoteHooking.IpcConnectClient<OverlayInterface>(inChannelName);
            _interface.Ping();

            IDictionary properties = new Hashtable();
            properties["name"] = inChannelName;
            properties["portName"] = inChannelName + Guid.NewGuid()
                                                         .ToString("N");

            var provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;

            _serverChannel = new IpcServerChannel(properties, provider);
            ChannelServices.RegisterChannel(_serverChannel, false);
        }
Ejemplo n.º 3
0
        public void Run(RemoteHooking.IContext inContext, string inChannelName, OverlayConfig overlayConfig)
        {
            Log.OverlayInterface = _interface;
            var domain = AppDomain.CurrentDomain;
            domain.AssemblyResolve += (sender, args) =>
            {
                return GetType()
                    .Assembly.FullName == args.Name ? GetType()
                        .Assembly : null;
            };

            Log.Write("Injected into process");

            _runWait = new ManualResetEvent(false);
            _runWait.Reset();
            try
            {
                if (!InstallHooks(overlayConfig))
                {
                    return;
                }

                _interface.Disconnected += _proxy.DisconnectedProxyHandler;
                _proxy.Disconnected += () => { _runWait.Set(); };
                CheckConnection();
                _runWait.WaitOne();
                StopCheckingConnection();
                UninstallHooks();
            }
            catch (Exception ex)
            {
                Log.Write(MessageType.Error, "An unexpected error occured: {0}", ex.ToString());
            }
            finally
            {
                try
                {
                    Log.Write(MessageType.Information, "Disconnecting from process {0}", RemoteHooking.GetCurrentProcessId());
                }
                catch
                {
                }
                ChannelServices.UnregisterChannel(_serverChannel);
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 4
0
        private bool InstallHooks(OverlayConfig overlayConfig)
        {
            var isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());
            Log.Write(MessageType.Information, "Remote process is a {0}-bit process.", isX64Process ? "64" : "32");
            try
            {
                var D3D11Handle = IntPtr.Zero;

                const int delay = 100;
                var retry = 0;

                while (D3D11Handle == IntPtr.Zero)
                {
                    retry++;
                    D3D11Handle = NativeMethods.GetModuleHandle("d3d11.dll");
                    if (retry * delay > 5000)
                    {
                        return false;
                    }
                }

                _hook = new DirectX11(_interface)
                {
                    OverlayConfig = overlayConfig
                };
                _hook.Install(RemoteHooking.GetCurrentProcessId());

                Log.Write(MessageType.Information, "Installed DirectX hook");
                return true;
            }
            catch (Exception ex)
            {
                Log.Write(MessageType.Error, "Failed to install DirectX hooks: {0}", ex.Message);
                return false;
            }
        }