Here is a C# class that can be used to edit integers in the memory, its an incomplete class im working on.
Code:
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Namespace
{
public class MemoryManager
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, Int32 dwProcessId);
[DllImport("kernel32.dll")]
public static extern Int32 CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] buffer, uint size, IntPtr lpNumberOfBytesRead);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, IntPtr lpNumberOfBytesWritten);
Process process;
IntPtr baseAddress;
int AddressLength;
int ProcessID;
IntPtr LinkHandle;
public MemoryManager(string ProcessName)
{
process = Process.GetProcessesByName(ProcessName)[0];
baseAddress = process.MainModule.BaseAddress;
AddressLength = process.MainModule.ModuleMemorySize;
ProcessID = process.Id;
LinkHandle = OpenProcess(0x001F0FFF, 1, ProcessID);
if (LinkHandle == IntPtr.Zero)
throw new Win32Exception(Marshal.GetLastWin32Error());
}
public void Dispose()
{
process.Dispose();
CloseHandle(LinkHandle);
}
public uint ReadUInt(uint Address)
{
byte[] buffer = new byte[4];
if (ReadProcessMemory(LinkHandle, (IntPtr)Address, buffer, (uint)buffer.Length, IntPtr.Zero) == 0)
throw new Win32Exception(Marshal.GetLastWin32Error());
return BitConverter.ToUInt32(buffer, 0);
}
public byte[] ReadBytes(int Address, int byteCount)
{
byte[] buffer = new byte[byteCount];
if (ReadProcessMemory(LinkHandle, (IntPtr)Address, buffer, (uint)buffer.Length, IntPtr.Zero) == 0)
throw new Win32Exception(Marshal.GetLastWin32Error());
return buffer;
}
public double ReadDouble(int Address)
{
byte[] buffer = new byte[8];
if (ReadProcessMemory(LinkHandle, (IntPtr)Address, buffer, (uint)buffer.Length, IntPtr.Zero) == 0)
throw new Win32Exception(Marshal.GetLastWin32Error());
return BitConverter.ToInt64(buffer, 0);
}
public void WriteUInt(uint Address, uint Value)
{
if (!WriteProcessMemory(LinkHandle, (IntPtr)Address, BitConverter.GetBytes(Value), 4, IntPtr.Zero))
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
}
You can use the class like this:
Code:
//fill in the process you want to hack
MemoryManager memoryManager = new MemoryManager("ProcessName");
//read an integer from the provided memory address
uint value = memoryManager.ReadUInt(0x009D3FD0);
//write an integer to the provided address
memoryManager.WriteUInt(0x009D3FD0, 123);
//dispose the manager
memoryManager.Dispose();
But as i said before its not complete, but you never really asked for anything specific.