Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 /// <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;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Stops spying.
 /// </summary>
 public void Stop()
 {
     _StopType = SpyStopType.Stopped;
     Dispose();
 }
Exemplo n.º 4
0
 /// <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;
 }
Exemplo n.º 5
0
        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 ) );
        }
Exemplo n.º 6
0
 /// <summary>
 /// Stops spying.
 /// </summary>
 public void Stop()
 {
     _StopType = SpyStopType.Stopped;
     Dispose();
 }