public static void Write(int address, byte[] arr, int count) { if (arr.Length < count) { throw new ArgumentException("Length < Count"); } if (address < PointerBorder) { if (address < ProcessBorder) { throw new ArgumentOutOfRangeException("Address: " + address.ToString("X4")); } if (!ProcessImports.WriteProcessMemory(handle, new IntPtr(address), arr, (uint)count, out uint byteWritten)) { Win32Exception.ThrowLastError(); } } else { // FIXME: use memcpy or ints for (int i = 0; i < count; i++) { *(byte *)(address + i) = arr[i]; } } }
public static String GetWindowText() { int length = ProcessImports.GetWindowTextLength(Handle); StringBuilder sb = new StringBuilder(length + 1); ProcessImports.GetWindowText(Handle, sb, sb.Capacity); return(sb.ToString()); }
public static IntPtr Alloc(uint size) { if (size == 0) { return(IntPtr.Zero); } IntPtr ptr = ProcessImports.VirtualAllocEx(Handle, IntPtr.Zero, size, ProcessImports.AllocationType.Reserve | ProcessImports.AllocationType.Commit, ProcessImports.MemoryProtection.ReadWrite); if (ptr == IntPtr.Zero) { Error.GetLastError(); } return(ptr); }
public static uint Read(int address, byte[] buffer, uint count) { if (address == 0) { throw new Exception("Read address is 0!"); } uint bytesRead = 0; if (!ProcessImports.ReadProcessMemory(Handle, new IntPtr(address), buffer, count, ref bytesRead)) { Error.GetLastError(); } return(bytesRead); }
public static int ReadInt(int address) { if (address == 0) { throw new Exception("Read address is 0!"); } IntPtr rw; IntPtr puffer; if (!ProcessImports.ReadProcessMemory(Handle, new IntPtr(address), out puffer, new UIntPtr(4), out rw)) { Error.GetLastError(); } return(puffer.ToInt32()); }
public static uint Write(int address, byte[] arr, int count) { if (address == 0) { throw new ArgumentException("Write address is 0!"); } uint byteWritten; if (!ProcessImports.WriteProcessMemory(Handle, new IntPtr(address), arr, (uint)count, out byteWritten)) { Error.GetLastError(); } return(byteWritten); }
public static uint Write(int address, int value) { if (address == 0) { throw new Exception("Write position is 0!"); } IntPtr byteWritten = IntPtr.Zero; IntPtr ptr = new IntPtr(value); if (!ProcessImports.WriteProcessMemory(Handle, new IntPtr(address), out ptr, 4, out byteWritten)) { Error.GetLastError(); } return((uint)byteWritten.ToInt32()); }
public static bool Free(IntPtr ptr, uint size) { if (ptr == IntPtr.Zero || size == 0) { return(false); } if (!ProcessImports.VirtualFreeEx(Handle, ptr, size, ProcessImports.AllocationType.Decommit)) { Error.GetLastError(); } if (!ProcessImports.VirtualFreeEx(Handle, ptr, 0, ProcessImports.AllocationType.Release)) { Error.GetLastError(); } return(true); }
static Process() { try { ProcessID = (uint)System.Diagnostics.Process.GetCurrentProcess().Id; System.Diagnostics.Process.EnterDebugMode(); Handle = ProcessImports.OpenProcess((uint)ProcessImports.ProcessAccess.PROCESS_ALL_ACCESS, false, ProcessID); if (Handle == IntPtr.Zero) { Error.GetLastError(); } Guid CLSID_CLRRuntimeHost = new Guid(0x90F1A06E, 0x7712, 0x4762, 0x86, 0xB5, 0x7A, 0x5E, 0xBA, 0x6B, 0xDB, 0x02); Guid IID_ICLRRuntimeHost = new Guid(0x90F1A06C, 0x7712, 0x4762, 0x86, 0xB5, 0x7A, 0x5E, 0xBA, 0x6B, 0xDB, 0x02); runtimeInterface = RuntimeEnvironment.GetRuntimeInterfaceAsIntPtr(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost).ToInt32(); if (runtimeInterface == 0) { throw new Exception("Runtime interface not found!"); } IntPtr user32Handle = ProcessImports.GetModuleHandle("user32.dll"); if (user32Handle == IntPtr.Zero) { Error.GetLastError("GetModuleHandle user32.dll"); } IntPtr wptr = ProcessImports.GetProcAddress(user32Handle, "wsprintfW"); if (wptr == IntPtr.Zero) { Error.GetLastError("GetProcAddress wsprintfW"); } wsprintfWPtr = wptr.ToInt32(); wsprintfWTypeArg = AllocString("%p"); hookArg_DLLPath = AllocString(typeof(Process).Assembly.Location); hookArg_Namespace = AllocString(typeof(Process).FullName); hookArg_MethodName = AllocString(typeof(Process).GetMethod("ApiHook").Name); hookArg_Result = Alloc(4).ToInt32(); } catch (Exception e) { MessageBox(IntPtr.Zero, e.ToString(), "WinApi Exception!", 0); } }
public static void Write(int address, int value) { if (address < PointerBorder) { if (address < ProcessBorder) { throw new ArgumentOutOfRangeException("Address: " + address.ToString("X4")); } IntPtr ptr = new IntPtr(value); if (!ProcessImports.WriteProcessMemory(handle, new IntPtr(address), out ptr, 4, out IntPtr byteWritten)) { Win32Exception.ThrowLastError(); } } else { *(int *)address = value; } }
public static bool SetWindowText(String text) { return(ProcessImports.SetWindowText(Handle, text)); }
public static bool VirtualProtect(int address, uint size) { ProcessImports.MemoryProtection k; return(ProcessImports.VirtualProtect(new IntPtr(address), size, ProcessImports.MemoryProtection.ExecuteReadWrite, out k)); }