public static SafeProcessHandle OpenProcessHandle(ProcessAccessFlags desiredAccess, bool inheritHandle, int processId) { var handle = OpenProcess(desiredAccess, inheritHandle, processId); var error = GetLastError(); if (handle == IntPtr.Zero) throw new Exception(String.Format( "Failed to open process: Error {0:x8}", error )); return new SafeProcessHandle(handle); }
public static RemoteMemoryRegion Allocate(Process process, UInt32 size) { using (var handle = Win32.OpenProcessHandle( ProcessAccessFlags.VMOperation | ProcessAccessFlags.VMRead | ProcessAccessFlags.VMWrite, false, process.Id )) { return(Allocate(process, handle, size)); } }