Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Memory
- {
- public static int GetIntFromPointers(int baseAddress, params int[] offsets)
- {
- int value = BitConverter.ToInt32(MemoryEdit.ReadMemory(baseAddress, 4, (int)EffectSome.processHandle), 0);
- for (int i = 0; i < offsets.Length; i++)
- value = BitConverter.ToInt32(MemoryEdit.ReadMemory(value + offsets[i], 4, (int)EffectSome.processHandle), 0);
- return value;
- }
- public static float GetFloatFromPointers(int baseAddress, params int[] offsets)
- {
- int value = BitConverter.ToInt32(MemoryEdit.ReadMemory(baseAddress, 4, (int)EffectSome.processHandle), 0);
- for (int i = 0; i < offsets.Length - 1; i++)
- value = BitConverter.ToInt32(MemoryEdit.ReadMemory(value + offsets[i], 4, (int)EffectSome.processHandle), 0);
- float result = BitConverter.ToSingle(MemoryEdit.ReadMemory(value + offsets[offsets.Length - 1], 4, (int)EffectSome.processHandle), 0);
- return result;
- }
- public static bool GetBoolFromPointers(int baseAddress, params int[] offsets)
- {
- int value = BitConverter.ToInt32(MemoryEdit.ReadMemory(baseAddress, 4, (int)EffectSome.processHandle), 0);
- for (int i = 0; i < offsets.Length - 1; i++)
- value = BitConverter.ToInt32(MemoryEdit.ReadMemory(value + offsets[i], 4, (int)EffectSome.processHandle), 0);
- bool result = BitConverter.ToBoolean(MemoryEdit.ReadMemory(value + offsets[offsets.Length - 1], 4, (int)EffectSome.processHandle), 0);
- return result;
- }
- public static void SetValueFromPointers(int baseAddress, byte[] bytes, params int[] offsets)
- {
- int address = BitConverter.ToInt32(MemoryEdit.ReadMemory(baseAddress, 4, (int)EffectSome.processHandle), 0);
- for (int i = 0; i < offsets.Length - 1; i++)
- address = BitConverter.ToInt32(MemoryEdit.ReadMemory(address + offsets[i], 4, (int)EffectSome.processHandle), 0);
- address += offsets[offsets.Length - 1];
- MemoryEdit.WriteMemory(address, bytes, (int)EffectSome.processHandle);
- }
- public static void SetIntFromPointers(int baseAddress, int value, params int[] offsets)
- {
- int address = BitConverter.ToInt32(MemoryEdit.ReadMemory(baseAddress, 4, (int)EffectSome.processHandle), 0);
- for (int i = 0; i < offsets.Length - 1; i++)
- address = BitConverter.ToInt32(MemoryEdit.ReadMemory(address + offsets[i], 4, (int)EffectSome.processHandle), 0);
- address += offsets[offsets.Length - 1];
- MemoryEdit.WriteMemory(address, BitConverter.GetBytes(value), (int)EffectSome.processHandle);
- }
- public static void SetFloatFromPointers(int baseAddress, float value, params int[] offsets)
- {
- int address = BitConverter.ToInt32(MemoryEdit.ReadMemory(baseAddress, 4, (int)EffectSome.processHandle), 0);
- for (int i = 0; i < offsets.Length - 1; i++)
- address = BitConverter.ToInt32(MemoryEdit.ReadMemory(address + offsets[i], 4, (int)EffectSome.processHandle), 0);
- address += offsets[offsets.Length - 1];
- MemoryEdit.WriteMemory(address, BitConverter.GetBytes(value), (int)EffectSome.processHandle);
- }
- public static void EditInt(int baseAddress, NumericUpDown NUD, params int[] offsets)
- {
- SetValueFromPointers(baseAddress, BitConverter.GetBytes(GetIntFromPointers(baseAddress, offsets) + (int)NUD.Value), offsets);
- }
- public static void EditFloat(int baseAddress, NumericUpDown NUD, params int[] offsets)
- {
- SetValueFromPointers(baseAddress, BitConverter.GetBytes(GetIntFromPointers(baseAddress, offsets) + (float)NUD.Value), offsets);
- }
- }
- public static class MemoryEdit
- {
- [DllImport("kernel32.dll")]
- public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
- [DllImport("Kernel32.dll", SetLastError = true)]
- public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, ref uint lpNumberOfBytesRead);
- [DllImport("kernel32.dll")]
- public static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] buffer, int size, ref uint lpNumberOfBytesWritten);
- [DllImport("kernel32.dll")]
- public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
- public static byte[] ReadMemory(int address, int processSize, int processHandle)
- {
- byte[] buffer = new byte[processSize];
- uint shit = 0;
- ReadProcessMemory(new IntPtr(processHandle), new IntPtr(address), buffer, (uint)processSize, ref shit);
- return buffer;
- }
- public static void WriteMemory(int address, byte[] processBytes, int processHandle)
- {
- uint shit = 0;
- ChangeMemoryProtection(address, (uint)processBytes.Length, processHandle);
- WriteProcessMemory(processHandle, address, processBytes, processBytes.Length, ref shit);
- }
- public static void ChangeMemoryProtection(int address, uint size, int processHandle)
- {
- VirtualProtectEx(new IntPtr(processHandle), new IntPtr(address), new UIntPtr(size), EffectSome.PAGE_READWRITE, out uint shit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement