Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [System.Runtime.InteropServices.DllImport("kernel32.dll")]
- private static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesRead);
- [System.Runtime.InteropServices.DllImport("kernel32.dll")]
- private static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesWritten);
- [System.Runtime.InteropServices.DllImport("kernel32.dll")]
- private static extern int OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
- [System.Runtime.InteropServices.DllImport("kernel32.dll")]
- private static extern bool CloseHandle(int hObject);
- public static int ProcessHandle = 0;
- public static int BaseAddress = 0;
- private bool findProcess()
- {
- Process[] p = Process.GetProcessesByName("name");
- if (p.Length != 0)
- {
- ProcessHandle = (int)OpenProcess(0x1F0FFF, false, p[0].Id);
- BaseAddress = (int)p[0].MainModule.BaseAddress;
- return true;
- }
- else return false;
- }
- private int findAddress(int StaticPointer, int[] Offsets)
- {
- byte[] tmp;
- int address = BaseAddress + StaticPointer;
- for (int i = 0; i < Offsets.Count(); i++)
- {
- tmp = new byte[4];
- ReadProcessMemory(ProcessHandle, address, tmp, tmp.Length, 0);
- address = BitConverter.ToInt32(tmp, 0) + Offsets[i];
- }
- return address;
- }
- private void writeMemory(int address, int value, bool flt = false, int length = 4)
- {
- if (write)
- {
- byte[] bytes = new byte[4];
- if (flt) bytes = BitConverter.GetBytes(Convert.ToSingle(value));
- else bytes = BitConverter.GetBytes(value);
- WriteProcessMemory(ProcessHandle, address, bytes, length, 0);
- }
- }
- private int readMemory(int address, bool flt = false, int length = 4)
- {
- int value;
- byte[] tmp = new byte[4];
- ReadProcessMemory(ProcessHandle, address, tmp, length, 0);
- if (flt) value = (int)BitConverter.ToSingle(tmp, 0);
- else value = BitConverter.ToInt32(tmp, 0);
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement