public void Inject() { if (_captureProcess == null) { //btnInject.Enabled = false; AttachProcess(); } else { HookManager.RemoveHookedProcess(_captureProcess.Process.Id); _captureProcess.CaptureInterface.Disconnect(); _captureProcess = null; } if (_captureProcess != null) { //btnInject.Text = "Detach"; //btnInject.Enabled = true; } else { //btnInject.Text = "Inject"; //btnInject.Enabled = true; } }
private void Inject() { bool newInstanceFound = false; while (!newInstanceFound) { if (_stopped) break; Process[] processes = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(this.TargetProcess)); foreach (Process 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; } _processId = process.Id; _process = process; _capturedProcess = new CaptureProcess(process, new Capture.Interface.CaptureConfig{ ShowOverlay = false, Direct3DVersion = global::Capture.Interface.Direct3DVersion.AutoDetect }, _captureInterface); newInstanceFound = true; break; } Thread.Sleep(10); } }
private void AttachProcess() { string exeName = Path.GetFileNameWithoutExtension(textBox1.Text); Process[] processes = Process.GetProcessesByName(exeName); foreach (Process 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; } Direct3DVersion 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; } CaptureConfig cc = new CaptureConfig() { Direct3DVersion = direct3DVersion, ShowOverlay = cbDrawOverlay.Checked }; processId = process.Id; _process = process; var captureInterface = new CaptureInterface(); captureInterface.RemoteMessage += new MessageReceivedEvent(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; } }
private void btnInject_Click(object sender, EventArgs e) { if (_captureProcess == null) { btnInject.Enabled = false; if (cbAutoGAC.Checked) { // NOTE: On some 64-bit setups this doesn't work so well. // Sometimes if using a 32-bit target, it will not find the GAC assembly // without a machine restart, so requires manual insertion into the GAC // Alternatively if the required assemblies are in the target applications // search path they will load correctly. // Must be running as Administrator to allow dynamic registration in GAC Config.Register("Capture", "Capture.dll"); } AttachProcess(); } else { HookManager.RemoveHookedProcess(_captureProcess.Process.Id); _captureProcess.CaptureInterface.Disconnect(); _captureProcess = null; } if (_captureProcess != null) { btnInject.Text = "Detach"; btnInject.Enabled = true; } else { btnInject.Text = "Inject"; btnInject.Enabled = true; } }
private void CreateCaptureProcess(Process process) { _process = process; Direct3DVersion 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, TestThisShit = 300 }; var captureInterface = new CaptureInterface(); if (frm2 != null) { frm2.Close(); frm2.Dispose(); } frm2 = new form2JT(captureInterface); captureInterface.RemoteMessage += CaptureInterface_RemoteMessage; _captureProcess = new CaptureProcess(process, cc, captureInterface); }
private bool AttachHookToProcess() { if (attached) { return true; } var processes = Process.GetProcessesByName(HEARTHSTONE_PROCESS_NAME); if (processes.Length <= 0) { Log.Debug("GetProcessesByName failed."); return false; } var process = processes[0]; // Check incompatible modules: foreach (ProcessModule module in process.Modules) { if (module.ModuleName.ToLower().StartsWith("rtsshooks")) { Publish(new IncompatibleHooksFound("RTSSHooks", "MSI Afterburner / Riva Tuner Statistics Server")); } } //if (process.MainWindowHandle == IntPtr.Zero) //{ // Log.Debug("Could not get MainWindowHandle."); // return false; //} if (HookManager.IsHooked(process.Id)) { return true; } if (captureProcess != null) { Log.Warn("Call DettachHookFromProcess first"); DettachHookFromProcess(); extraDelay = 200; Thread.Sleep(200); } captureInterface = new CaptureInterface(); captureInterface.RemoteMessage += CaptureInterfaceOnRemoteMessage; captureProcess = new CaptureProcess(process, captureConfig, captureInterface); attached = true; return true; }
private void DettachHookFromProcess() { if (captureProcess != null) { captureInterface.RemoteMessage -= CaptureInterfaceOnRemoteMessage; captureProcess.Dispose(); captureProcess = null; attached = false; } for (var i = 0; i < 2; i++) { if (sharedTexturesAccess[i] != null) { sharedTexturesAccess[i].SafeMemoryMappedViewHandle.ReleasePointer(); sharedTexturesAccess[i].Dispose(); sharedTexturesAccess[i] = null; } if (sharedTextures[i] != null) { var locked = false; try { locked = sharedMemMutexes[i].WaitOne(1000); } catch (AbandonedMutexException) { locked = true; } finally { sharedTextures[i].Dispose(); sharedTextures[i] = null; if (locked) { sharedMemMutexes[i].ReleaseMutex(); } } } } if (copyDataMemAccess != null) { copyDataMemAccess.SafeMemoryMappedViewHandle.ReleasePointer(); copyDataMemAccess.Dispose(); copyDataMemAccess = null; } if (copyDataMem != null) { copyDataMem.Dispose(); copyDataMem = null; } // lastCaptured = -1; }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (captureProcess != null) { captureProcess.Dispose(); captureProcess = null; } for (var i = 0; i < 2; i++) { if (sharedTexturesAccess[i] != null) { sharedTexturesAccess[i].SafeMemoryMappedViewHandle.ReleasePointer(); sharedTexturesAccess[i].Dispose(); sharedTexturesAccess[i] = null; } if (sharedTextures[i] != null) { sharedTextures[i].Dispose(); sharedTextures[i] = null; } } if (copyDataMemAccess != null) { copyDataMemAccess.SafeMemoryMappedViewHandle.ReleasePointer(); copyDataMemAccess.Dispose(); copyDataMemAccess = null; } if (copyDataMem != null) { copyDataMem.Dispose(); copyDataMem = null; } }