private void Attach(Process process) { Exception exception = null; try { _StopType = SpyStopType.Closed; _Process = process; _ProcessHandle = NativeMethods.OpenProcess(NativeMethods.DesiredAccessProcess.PROCESS_ALL_ACCESS, false, (uint)_Process.Id); if (_ProcessHandle == IntPtr.Zero) { throw new SpyException("Error opening process. ErrorCode={0}", NativeMethods.GetLastError()); } if (!NativeMethods.DebugActiveProcess((uint)_Process.Id)) { throw new SpyException("Error starting debugger. ErrorCode={0}", NativeMethods.GetLastError()); } InitBreakpoints(); MainLoop(); } catch (Exception ex) { exception = ex; _StopType = SpyStopType.Error; } finally { try { if (SafeToStop) { SafeStop(); } } catch (Exception ex) { exception = ex; _StopType = SpyStopType.Error; } } OnStop(new SpyStoppedArgs(_StopType, exception)); }
/// <summary> /// Cosntructs a new insance of PacketStoppedArgs. /// </summary> /// <param name="stopType">Stop type.</param> /// <param name="error">Exception that might have occured.</param> public SpyStoppedArgs(SpyStopType stopType, Exception error = null) { _StopType = stopType; _Error = error; }
/// <summary> /// Stops spying. /// </summary> public void Stop() { _StopType = SpyStopType.Stopped; Dispose(); }
/// <summary> /// Cosntructs a new insance of PacketStoppedArgs. /// </summary> /// <param name="stopType">Stop type.</param> /// <param name="error">Exception that might have occured.</param> public SpyStoppedArgs( SpyStopType stopType, Exception error = null ) { _StopType = stopType; _Error = error; }
private void Attach( Process process ) { Exception exception = null; try { _StopType = SpyStopType.Closed; _Process = process; _ProcessHandle = NativeMethods.OpenProcess( NativeMethods.DesiredAccessProcess.PROCESS_ALL_ACCESS, false, (uint) _Process.Id ); if ( _ProcessHandle == IntPtr.Zero ) throw new SpyException( "Error opening process. ErrorCode={0}", NativeMethods.GetLastError() ); if ( !NativeMethods.DebugActiveProcess( (uint) _Process.Id ) ) throw new SpyException( "Error starting debugger. ErrorCode={0}", NativeMethods.GetLastError() ); InitBreakpoints(); MainLoop(); } catch ( Exception ex ) { exception = ex; _StopType = SpyStopType.Error; } finally { try { if ( SafeToStop ) SafeStop(); } catch ( Exception ex ) { exception = ex; _StopType = SpyStopType.Error; } } OnStop( new SpyStoppedArgs( _StopType, exception ) ); }
/// <summary> /// Stops spying. /// </summary> public void Stop() { _StopType = SpyStopType.Stopped; Dispose(); }