public static int ReadBytes(long iMemoryAddress, uint b, bool bigEndian = true) { var bBuffer = new byte[b]; IntPtr lpNumberOfBytesRead; if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, b, out lpNumberOfBytesRead) == 0) { return((int)0); } if (bigEndian) { Array.Reverse(bBuffer); } switch (b) { case 4: return((int)BitConverter.ToInt32(bBuffer, 0)); case 2: return((int)BitConverter.ToInt16(bBuffer, 0)); default: return((int)bBuffer[0]); } }
public static bool Write(long iMemoryAddress, short iShortToWrite) { var bBuffer = BitConverter.GetBytes(iShortToWrite); Array.Reverse(bBuffer); IntPtr lpNumberOfBytesWritten; Mapi.WriteProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 2U, out lpNumberOfBytesWritten); return(lpNumberOfBytesWritten.ToInt32() == 2); }
public static byte ReadByte(long iMemoryAddress) { var bBuffer = new byte[1]; IntPtr lpNumberOfBytesRead; if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 1U, out lpNumberOfBytesRead) == 0) { return((byte)0); } return(bBuffer[0]); }
public static bool Write(long iMemoryAddress, byte bByteToWrite) { var bBuffer = new byte[1] { bByteToWrite }; Array.Reverse(bBuffer); IntPtr lpNumberOfBytesWritten; Mapi.WriteProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 1U, out lpNumberOfBytesWritten); return(lpNumberOfBytesWritten.ToInt32() == 1); }
public static double ReadDouble(long iMemoryAddress) { var bBuffer = new byte[8]; IntPtr lpNumberOfBytesRead; if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 8U, out lpNumberOfBytesRead) == 0) { return(0.0); } Array.Reverse(bBuffer); return(BitConverter.ToDouble(bBuffer, 0)); }
public static float ReadFloat(long iMemoryAddress) { var bBuffer = new byte[4]; IntPtr lpNumberOfBytesRead; if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 4U, out lpNumberOfBytesRead) == 0) { return(0.0f); } Array.Reverse(bBuffer); return(BitConverter.ToSingle(bBuffer, 0)); }
public static ushort ReadShort(long iMemoryAddress) { var bBuffer = new byte[2]; IntPtr lpNumberOfBytesRead; if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, 2U, out lpNumberOfBytesRead) == 0) { return((ushort)0); } Array.Reverse(bBuffer); return(BitConverter.ToUInt16(bBuffer, 0)); }
public static byte[] ReadBytesAsBytes(long iMemoryAddress, uint b, bool bigEndian = true) { var bBuffer = new byte[b]; IntPtr lpNumberOfBytesRead; if (Mapi.ReadProcessMemory(_hReadProcess, (IntPtr)iMemoryAddress, bBuffer, b, out lpNumberOfBytesRead) == 0) { return(null); } if (bigEndian) { Array.Reverse(bBuffer); } return(bBuffer); }