S
Sleinzel
This is a simple MemoryReading/Writing Class I used in one of my projects:
How To use It:
(Edit changed Quote tags to code Fl)
Have Fun
C++:
class Memory
{
public static int proccID;
public static IntPtr pHandle;
#region DllImports
[DllImport("kernel32.dll")]
private static extern bool WriteProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, byte[] lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesWritten);
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
private static extern bool _CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll")]
private static extern bool ReadProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [Out] byte[] lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesRead);
#endregion
public static void OpenProcess(string ProcName)
{
Process[] procs = Process.GetProcessesByName(ProcName);
if (procs.Length == 0)
{
proccID = 0;
}
else
{
proccID = procs[0].Id;
pHandle = OpenProcess(0x1F0FFF, false, proccID);
}
}
public static int readInt(long Address)
{
byte[] buffer = new byte[sizeof(int)];
ReadProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)4, IntPtr.Zero);
return BitConverter.ToInt32(buffer, 0);
}
public static uint readUInt(long Address)
{
byte[] buffer = new byte[sizeof(int)];
ReadProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)4, IntPtr.Zero);
return (uint)BitConverter.ToUInt32(buffer, 0);
}
public static float readFloat(long Address)
{
byte[] buffer = new byte[sizeof(float)];
ReadProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)4, IntPtr.Zero);
return BitConverter.ToSingle(buffer, 0);
}
public static string ReadString(long Address)
{
byte[] buffer = new byte[50];
ReadProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)50, IntPtr.Zero);
string ret = Encoding.Unicode.GetString(buffer);
if (ret.IndexOf('\0') != -1)
ret = ret.Remove(ret.IndexOf('\0'));
return ret;
}
public static byte readByte(long Address)
{
byte[] buffer = new byte[1];
ReadProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)1, IntPtr.Zero);
return buffer[0];
}
public static void WriteFloat(long Address, float value)
{
byte[] buffer = BitConverter.GetBytes(value);
WriteProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)buffer.Length, IntPtr.Zero);
}
public static void WriteInt(long Address, int value)
{
byte[] buffer = BitConverter.GetBytes(value);
WriteProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)buffer.Length, IntPtr.Zero);
}
public static void WriteUInt(long Address, uint value)
{
byte[] buffer = BitConverter.GetBytes(value);
WriteProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)buffer.Length, IntPtr.Zero);
}
public static void CloseProcess()
{
_CloseHandle(pHandle);
}
}
How To use It:
C++:
Memory.OpenProcess("chrome.exe");
float asdf = Memory.ReadFloat(0x999999);
Memory.CloseProcess();
Have Fun