Code:
public class Memory
{
string ProcName;
public Memory(string ProcessName)
{
ProcName = ProcessName.Replace(".exe", "");
}
#region DLL Imports
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
private static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
[DllImport("kernel32.dll")]
private static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
#endregion
#region Write & Read Main
private byte[] Read(int Add, int Length)
{
byte[] Buffer = new byte[Length];
IntPtr Zero = IntPtr.Zero;
ReadProcessMemory(Open_Memory(), (IntPtr)Add, Buffer, (UInt32)Buffer.Length, out Zero);
return Buffer;
}
private byte[] Write(int Address, byte[] Value, int Length = -1)
{
if (Length == -1)
Length = Value.Length;
byte[] Buffer = new byte[Length];
IntPtr Zero = IntPtr.Zero;
Convert.ToByte(10);
WriteProcessMemory(Open_Memory(), (IntPtr)Address, Buffer, (UInt32)Length, out Zero);
return Buffer;
}
private IntPtr Open_Memory()
{
if (Process.GetProcessesByName(ProcName).Length != 0)
{
return OpenProcess(0x1F0FFF, true, Process.GetProcessesByName(ProcName)[0].Id);
}
else return (IntPtr)0x0;
}
#endregion
#region Write Stuff
public void WriteInt(int Address, int Value)
{
byte[] buffer = BitConverter.GetBytes(Value);
IntPtr R;
WriteProcessMemory(Open_Memory(), (IntPtr)Address, buffer, 4, out R);
}
#endregion
#region Read Stuff
public uint ReadUInt(uint Address)
{
byte[] buffer = new byte[4];
IntPtr R;
ReadProcessMemory(Open_Memory(), (IntPtr)Address, buffer, 4, out R);
return BitConverter.ToUInt32(buffer, 0);
}
#endregion
#region Pointers
private uint BaseAddressU(string Module_Name)
{
try
{
if (Process.GetProcessesByName(ProcName).Length != 0)
{
foreach (ProcessModule Mod in Process.GetProcessesByName(ProcName)[0].Modules)
{
if (Mod.ModuleName == Module_Name)
return (uint)Mod.BaseAddress.ToInt32();
}
return 0;
}
else return 0;
}
catch { Console.WriteLine("Base Address Error"); return 0; }
}
public uint PointersU(string Module, uint[] Pointers)
{
uint Base = BaseAddressU(Module) + Pointers[0];
uint Runner = ReadUInt(Base) + Pointers[1];
for (int i = 2; i != Pointers.Length - 2; i++)
Runner = ReadUInt(Runner) + Pointers[i];
return Runner;
}
#endregion
}
If you don't know how to use it, wait until tomorrow.