public static HackContext CreateContext(System.Diagnostics.Process process, WinAPI.ProcessAccessFlags flags = WinAPI.ProcessAccessFlags.All) { var proc = new LocalProcess(process); var mem = proc.CreateMemoryInterface(flags, true); return(new LocalHackContext(proc, mem)); }
public static HackContext CreateContext(int pid, WinAPI.ProcessAccessFlags flags = WinAPI.ProcessAccessFlags.All) { var process = System.Diagnostics.Process.GetProcessById(pid); if (process == null) { throw new Exception($"Could not find process with id {pid}!"); } return(CreateContext(process, flags)); }
public static HackContext CreateContext(string processName, WinAPI.ProcessAccessFlags flags = WinAPI.ProcessAccessFlags.All) { var processes = System.Diagnostics.Process.GetProcessesByName(processName); if (processes.Length == 0) { throw new Exception($"Could not find process \"{processName}\"!"); } if (processes.Length > 1) { throw new Exception($"There are multiple instances of \"{processName}\"!"); } return(CreateContext(processes[0], flags)); }
internal LocalMemory(LocalProcess process, bool raiseExceptions, WinAPI.ProcessAccessFlags flags) { this.process = process; this.raiseExceptions = raiseExceptions; this.pageCacheTime = DateTime.MinValue; PageCacheDuration = TimeSpan.FromSeconds(5); if ((flags & WinAPI.ProcessAccessFlags.VirtualMemoryRead) == 0) { throw new ArgumentException("Flags require at least ProcessAccessFlags.VirtualMemoryRead to be set"); } MemoryHandle = WinAPI.OpenProcess(flags, false, process.PID); if (MemoryHandle == IntPtr.Zero) { throw new Exception("Failed to aquire memory handle", new Win32Exception(Marshal.GetLastWin32Error())); } }
public IMemory CreateMemoryInterface(WinAPI.ProcessAccessFlags flags, bool raiseExceptions) { return(new LocalMemory(this, raiseExceptions, flags)); }
public static extern IntPtr OpenProcess(WinAPI.ProcessAccessFlags processAccess, bool bInheritHandle, int processId);
public static extern IntPtr OpenProcess(WinAPI.ProcessAccessFlags dwDesiredAccess, int bInheritHandle, uint dwProcessId);
/// <summary> /// Opens a handle to a process /// </summary> /// <param name="name">Name of the process</param> /// <param name="flags">ProcessAccessFlags to use</param> /// <returns>A handle to the process</returns> public static IntPtr OpenHandleByProcessName(string name, WinAPI.ProcessAccessFlags flags) { return(OpenHandleByProcessID(Process.GetProcessesByName(name)[0].Id, flags)); }
/// <summary> /// Opens a handle to a process /// </summary> /// <param name="process">The process-object of the process</param> /// <param name="flags">ProcessAccessFlags to use</param> /// <returns>A handle to the process</returns> public static IntPtr OpenHandleByProcess(Process process, WinAPI.ProcessAccessFlags flags) { return(OpenHandleByProcessID(process.Id, flags)); }
/// <summary> /// Opens a handle to a process /// </summary> /// <param name="id">ID of the process</param> /// <param name="flags">ProcessAccessFlags to use</param> /// <returns>A handle to the process</returns> public static IntPtr OpenHandleByProcessID(int id, WinAPI.ProcessAccessFlags flags) { return(WinAPI.OpenProcess(flags, false, id)); }
/// <summary> /// Initializes a new ProcUtils /// </summary> /// <param name="process">Process-object of the process</param> /// <param name="handleFlags">ProcessAccessFlags to use</param> public ProcUtils(Process process, WinAPI.ProcessAccessFlags handleFlags) { Process = process; Handle = OpenHandleByProcess(process, handleFlags); }
/// <summary> /// Initializes a new ProcUtils /// </summary> /// <param name="id">ID of the process</param> /// <param name="handleFlags">ProcessAccessFlags to use</param> public ProcUtils(int id, WinAPI.ProcessAccessFlags handleFlags) : this(Process.GetProcessById(id), handleFlags) { }
/// <summary> /// Initializes a new ProcUtils /// </summary> /// <param name="processName">Name of the process</param> /// <param name="handleFlags">ProcessAccessFlags to use</param> public ProcUtils(string processName, WinAPI.ProcessAccessFlags handleFlags) : this(Process.GetProcessesByName(processName)[0], handleFlags) { }
/// <summary> /// Initializes a new ProcUtils /// </summary> /// <param name="process">Process-object of the process</param> /// <param name="handleFlags">ProcessAccessFlags to use</param> public ProcUtils(Process process, WinAPI.ProcessAccessFlags handleFlags) { this.Process = process; this.Handle = ProcUtils.OpenHandleByProcess(process, handleFlags); }