/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.Collections.ObjectModel; using System.ComponentModel; namespace dnSpy.Contracts.Debugger { /// /// A debugged process /// public abstract class DbgProcess : DbgObject, INotifyPropertyChanged { /// /// Raised when a property is changed /// public abstract event PropertyChangedEventHandler? PropertyChanged; /// /// Gets the owner debug manager /// public abstract DbgManager DbgManager { get; } /// /// Process id /// public abstract int Id { get; } /// /// Gets all runtimes /// public abstract DbgRuntime[] Runtimes { get; } /// /// Raised when is changed /// public abstract event EventHandler>? RuntimesChanged; /// /// Gets the process bitness (32 or 64) /// public abstract int Bitness { get; } /// /// Gets the size of a pointer /// public int PointerSize => Bitness / 8; /// /// Gets the architecture /// public abstract DbgArchitecture Architecture { get; } /// /// Gets the operating system /// public abstract DbgOperatingSystem OperatingSystem { get; } /// /// Gets the process state /// public abstract DbgProcessState State { get; } /// /// Gets the filename or an empty string if it's unknown /// public abstract string Filename { get; } /// /// Gets the process name or an empty string if it's unknown /// public abstract string Name { get; } /// /// What is being debugged. This is shown in the UI (eg. Processes window) /// public abstract ReadOnlyCollection Debugging { get; } /// /// Gets all threads /// public abstract DbgThread[] Threads { get; } /// /// Raised when is changed /// public abstract event EventHandler>? ThreadsChanged; /// /// true if the process is running, false if it's paused or terminated (see ) /// public abstract bool IsRunning { get; } /// /// Raised when is changed, see also /// public abstract event EventHandler? IsRunningChanged; /// /// Raised when the process has been running for a little while, eg. 1 second. /// public abstract event EventHandler? DelayedIsRunningChanged; /// /// Reads memory. Unreadable memory is returned as 0s. /// /// Address in the debugged process /// Destination address /// Number of bytes to read public unsafe abstract void ReadMemory(ulong address, void* destination, int size); /// /// Reads memory. Unreadable memory is returned as 0s. /// /// Address in the debugged process /// Destination buffer /// Destination index /// Number of bytes to read public abstract void ReadMemory(ulong address, byte[] destination, int destinationIndex, int size); /// /// Reads memory. Unreadable memory is returned as 0s. /// /// Address in the debugged process /// Destination buffer public void ReadMemory(ulong address, byte[] destination) { if (destination is null) throw new ArgumentNullException(nameof(destination)); ReadMemory(address, destination, 0, destination.Length); } /// /// Reads memory. Unreadable memory is returned as 0s. /// /// Address in the debugged process /// Number of bytes to read /// public byte[] ReadMemory(ulong address, int size) { if (size < 0) throw new ArgumentOutOfRangeException(nameof(size)); if (size == 0) return Array.Empty(); var res = new byte[size]; ReadMemory(address, res, 0, size); return res; } /// /// Writes memory. /// /// Address in the debugged process /// Source address /// Number of bytes to write public unsafe abstract void WriteMemory(ulong address, void* source, int size); /// /// Writes memory. /// /// Address in the debugged process /// Source buffer /// Source index /// Number of bytes to write public abstract void WriteMemory(ulong address, byte[] source, int sourceIndex, int size); /// /// Writes memory. /// /// Address in the debugged process /// Source buffer public void WriteMemory(ulong address, byte[] source) { if (source is null) throw new ArgumentNullException(nameof(source)); WriteMemory(address, source, 0, source.Length); } /// /// true if the process gets detached when debugging stops (), /// false if the process gets terminated. /// public abstract bool ShouldDetach { get; set; } /// /// Stops debugging. This will either detach from the process or terminate it depending on /// public void StopDebugging() { if (ShouldDetach) Detach(); else Terminate(); } /// /// Detaches the process, if possible, else it will be terminated /// public abstract void Detach(); /// /// Terminates the process /// public abstract void Terminate(); /// /// Pauses the process /// public abstract void Break(); /// /// Lets the process run again /// public abstract void Run(); } /// /// Architecture /// public enum DbgArchitecture { /// /// x86, 32-bit /// X86, /// /// x64, 64-bit /// X64, /// /// 32-bit ARM /// Arm, /// /// 64-bit ARM /// Arm64, } /// /// Operating system /// public enum DbgOperatingSystem { /// /// Windows OS /// Windows, /// /// OSX/MacOS OS /// MacOS, /// /// Linux OS /// Linux, /// /// FreeBSD OS /// FreeBSD, } /// /// Process state /// public enum DbgProcessState { /// /// The process is running /// Running, /// /// The process is paused /// Paused, /// /// The process is terminated /// Terminated, } }