public EntryPoint( RemoteHooking.IContext context, string channelName, CaptureConfig config) { // Get reference to IPC to host application // Note: any methods called or events triggered against _interface will execute in the host process. _interface = RemoteHooking.IpcConnectClient<CaptureInterface>(channelName); // We try to ping immediately, if it fails then injection fails _interface.Ping(); #region Allow client event handlers (bi-directional IPC) // Attempt to create a IpcServerChannel so that any event handlers on the client will function correctly IDictionary properties = new Hashtable(); properties["name"] = channelName; properties["portName"] = channelName + Guid.NewGuid().ToString("N"); // random portName so no conflict with existing channels of channelName var binaryProv = new BinaryServerFormatterSinkProvider(); binaryProv.TypeFilterLevel = TypeFilterLevel.Full; var _clientServerChannel = new IpcServerChannel(properties, binaryProv); ChannelServices.RegisterChannel(_clientServerChannel, false); #endregion }
/// <summary> /// Prepares capturing in the target process. Note that the process must not already be hooked, and must have a /// <see cref="Process.MainWindowHandle" />. /// </summary> /// <param name="process">The process to inject into</param> /// <exception cref="ProcessHasNoWindowHandleException"> /// Thrown if the <paramref name="process" /> does not have a window /// handle. This could mean that the process does not have a UI, or that the process has not yet finished starting. /// </exception> /// <exception cref="ProcessAlreadyHookedException">Thrown if the <paramref name="process" /> is already hooked</exception> /// <exception cref="InjectionFailedException">Thrown if the injection failed - see the InnerException for more details.</exception> /// <remarks>The target process will have its main window brought to the foreground after successful injection.</remarks> public CaptureProcess(Process process, CaptureConfig config, CaptureInterface captureInterface) { // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc) if (process.MainWindowHandle == IntPtr.Zero) { throw new ProcessHasNoWindowHandleException(); } // Skip if the process is already hooked (and we want to hook multiple applications) if (HookManager.IsHooked(process.Id)) { throw new ProcessAlreadyHookedException(); } captureInterface.ProcessId = process.Id; CaptureInterface = captureInterface; //_serverInterface = new CaptureInterface() { ProcessId = process.Id }; // Initialise the IPC server (with our instance of _serverInterface) _screenshotServer = RemoteHooking.IpcCreateServer( ref _channelName, WellKnownObjectMode.Singleton, CaptureInterface); try { // Inject DLL into target process RemoteHooking.Inject( process.Id, InjectionOptions.Default, typeof (CaptureInterface).Assembly.Location, //"Capture.dll", // 32-bit version (the same because AnyCPU) could use different assembly that links to 32-bit C++ helper dll typeof (CaptureInterface).Assembly.Location, //"Capture.dll", // 64-bit version (the same because AnyCPU) could use different assembly that links to 64-bit C++ helper dll // the optional parameter list... _channelName, // The name of the IPC channel for the injected assembly to connect to config ); } catch (Exception e) { throw new InjectionFailedException(e); } HookManager.AddHookedProcess(process.Id); Process = process; // Ensure the target process is in the foreground, // this prevents an issue where the target app appears to be in // the foreground but does not receive any user inputs. // Note: the first Alt+Tab out of the target application after injection // may still be an issue - switching between windowed and // fullscreen fixes the issue however (see ScreenshotInjection.cs for another option) BringProcessWindowToFront(); }
public BaseDXHook(CaptureInterface ssInterface) { Interface = ssInterface; Timer = new Stopwatch(); Timer.Start(); FPS = new FramesPerSecond(); OverlayElements = new List<IOverlayElement>(); Interface.ScreenshotRequested += InterfaceEventProxy.ScreenshotRequestedProxyHandler; Interface.DisplayText += InterfaceEventProxy.DisplayTextProxyHandler; Interface.DrawOverlay += InterfaceEventProxy.DrawOverlayProxyHandler; InterfaceEventProxy.ScreenshotRequested += InterfaceEventProxy_ScreenshotRequested; InterfaceEventProxy.DisplayText += InterfaceEventProxy_DisplayText; InterfaceEventProxy.DrawOverlay += InterfaceEventProxy_DrawOverlay; }
public DXHookD3D10_1(CaptureInterface ssInterface) : base(ssInterface) { DebugMessage("Create"); }
public DXHookD3D11(CaptureInterface ssInterface) : base(ssInterface) { }
private void AttachProcess() { var exeName = Path.GetFileNameWithoutExtension(textBox1.Text); var processes = Process.GetProcessesByName(exeName); foreach (var process in processes) { // Simply attach to the first one found. // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc) if (process.MainWindowHandle == IntPtr.Zero) { continue; } // Skip if the process is already hooked (and we want to hook multiple applications) if (HookManager.IsHooked(process.Id)) { continue; } var direct3DVersion = Direct3DVersion.Direct3D10; if (rbDirect3D11.Checked) { direct3DVersion = Direct3DVersion.Direct3D11; } else if (rbDirect3D10_1.Checked) { direct3DVersion = Direct3DVersion.Direct3D10_1; } else if (rbDirect3D10.Checked) { direct3DVersion = Direct3DVersion.Direct3D10; } else if (rbDirect3D9.Checked) { direct3DVersion = Direct3DVersion.Direct3D9; } else if (rbAutodetect.Checked) { direct3DVersion = Direct3DVersion.AutoDetect; } var cc = new CaptureConfig { Direct3DVersion = direct3DVersion, ShowOverlay = cbDrawOverlay.Checked }; processId = process.Id; _process = process; var captureInterface = new CaptureInterface(); captureInterface.RemoteMessage += CaptureInterface_RemoteMessage; _captureProcess = new CaptureProcess(process, cc, captureInterface); break; } Thread.Sleep(10); if (_captureProcess == null) { MessageBox.Show("No executable found matching: '" + exeName + "'"); } else { btnLoadTest.Enabled = true; btnCapture.Enabled = true; } }