예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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()));
            }
        }
예제 #5
0
 public IMemory CreateMemoryInterface(WinAPI.ProcessAccessFlags flags, bool raiseExceptions)
 {
     return(new LocalMemory(this, raiseExceptions, flags));
 }
예제 #6
0
 public static extern IntPtr OpenProcess(WinAPI.ProcessAccessFlags processAccess, bool bInheritHandle, int processId);
예제 #7
0
 public static extern IntPtr OpenProcess(WinAPI.ProcessAccessFlags dwDesiredAccess, int bInheritHandle, uint dwProcessId);
예제 #8
0
 /// <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));
 }
예제 #9
0
 /// <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));
 }
예제 #10
0
 /// <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));
 }
예제 #11
0
 /// <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);
 }
예제 #12
0
 /// <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)
 {
 }
예제 #13
0
 /// <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)
 {
 }
예제 #14
0
 /// <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);
 }