public void Run(RemoteHooking.IContext InContext, string InChannelName) { AppDomain domain = AppDomain.CurrentDomain; domain.AssemblyResolve += (sender, args) => { return this.GetType().Assembly.FullName == args.Name ? this.GetType().Assembly : null; }; Log.Write("Injected into process"); _runWait = new ManualResetEvent(false); _runWait.Reset(); try { if (!InstallHooks()) return; _interface.Disconnected += _proxy.DisconnectedProxyHandler; _proxy.Disconnected += () => { _runWait.Set(); }; CheckConnection(); _runWait.WaitOne(); StopCheckingConnection(); UninstallHooks(); } catch { } finally { ChannelServices.UnregisterChannel(_serverChannel); Thread.Sleep(1000); } _hook = null; _proxy = null; _interface = null; _serverChannel = null; _runWait = null; _checkConnectionTask = null; Log.Write("Unloading DLL"); }
private void UninstallHooks() { try { Log.Write(MessageType.Debug, "Disposing of hooks..."); } catch (RemotingException ex) { } if (_hook != null) { _hook.Dispose(); _hook = null; } }
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; } }
private void UninstallHooks() { if (_hook != null) { _hook.Dispose(); _hook = null; } }
private bool InstallHooks() { try { IntPtr d3d11 = IntPtr.Zero; int delay = 100; int retry = 0; while (d3d11 == IntPtr.Zero) { retry++; d3d11 = NativeMethods.GetModuleHandle("d3d11.dll"); if (retry * delay > 5000) { return false; } } _hook = new DirectX11(); _hook.Install(RemoteHooking.GetCurrentProcessId()); Log.Write("Installed DirectX hook"); return true; } catch(Exception ex) { Log.Write("Failed to install DirectX hooks: {0}", ex.Message); return false; } }