public byte[] ReadProcMem(int procId, IntPtr addressToRead, int lengthToRead) { if (Proc == IntPtr.Zero) { Proc = Unmanaged.OpenProcess(ProcessAccessRights.PROCESS_ALL_ACCESS, false, procId); } return(ReadProcMem(addressToRead, lengthToRead)); }
public int WriteProcMem(IntPtr procHandle, IntPtr addressToWrite, byte[] bytesToWrite) { if (Proc == IntPtr.Zero) { Proc = Unmanaged.OpenProcess(ProcessAccessRights.PROCESS_ALL_ACCESS, false, procHandle.ToInt32()); } return(WriteProcMem(addressToWrite, bytesToWrite)); }
public Memory(int procId) { Proc = Unmanaged.OpenProcess(ProcessAccessRights.PROCESS_ALL_ACCESS, false, procId); if (Proc == IntPtr.Zero) { var error = new Win32Exception(Marshal.GetLastWin32Error()); if (error.ErrorCode == 5) { throw new Exception(string.Format("ERROR: OpenProcess error {0} try running as admin.", error.ErrorCode)); } throw new Exception(string.Format("ERROR: OpenProcess error {0}", error.Message)); } }