public static int proccID;
public static IntPtr pHandle;
public static int base_adress;
#region DllImports
[DllImport("kernel32.dll")]
private static extern bool WriteProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, byte[] lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesWritten);
[DllImportAttribute("User32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll", EntryPoint = "CloseHandle")]
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 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 void OpenProcess()
{
Process[] procs = Process.GetProcessesByName("processname");
if (procs.Length == 0)
{
proccID = 0;
}
else
{
proccID = procs[0].Id;
pHandle = OpenProcess(0x1F0FFF, false, proccID);
}
}
public static void WriteString(long Address, string value)
{
byte[] buffer = Encoding.ASCII.GetBytes(value);
WriteProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)buffer.Length, IntPtr.Zero);
}