- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- namespace ConsoleApplication18
- {
- class Program
- {
- static void Main(string[] args)
- {
- memory test = new memory();
- int bytesread;
- IntPtr H = test.open("Connector");
- Process handle = Process.GetCurrentProcess();
- int connector = 0x00400000;
- IntPtr pb = (IntPtr) connector + 0x0021B9A0;
- pb = test.pointer(H, pb, 0x2B4);
- pb = test.pointer(H, pb, 0x790);
- pb = test.pointer(H, pb, 0xac);
- pb = test.pointer(H, pb, 0x3c);
- pb = test.pointer(H, pb, 0x20);
- byte[] oldIP = test.ReadMemoryAtAdress(H, pb, 31, out bytesread);
- string IP = Encoding.ASCII.GetString(oldIP);
- Console.WriteLine(IP);
- ASCIIEncoding enc = new System.Text.ASCIIEncoding();
- string nip = "j";
- byte[] newIP = new byte[31] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- enc.GetBytes(nip).CopyTo(newIP, 0);
- test.WriteMemoryAtAdress(H, pb,newIP);
- Console.Read();
- }
- }
- class memory
- {
- [DllImport("kernel32.dll")]
- public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
- [DllImport("kernel32.dll")]
- public static extern Int32 CloseHandle(IntPtr hObject);
- [DllImport("kernel32.dll")]
- public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
- [DllImport("kernel32.dll")]
- public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
- [Flags]
- public enum ProcessAccessType
- {
- PROCESS_TERMINATE = (0x0001),
- PROCESS_CREATE_THREAD = (0x0002),
- PROCESS_SET_SESSIONID = (0x0004),
- PROCESS_VM_OPERATION = (0x0008),
- PROCESS_VM_READ = (0x0010),
- PROCESS_VM_WRITE = (0x0020),
- PROCESS_DUP_HANDLE = (0x0040),
- PROCESS_CREATE_PROCESS = (0x0080),
- PROCESS_SET_QUOTA = (0x0100),
- PROCESS_SET_INFORMATION = (0x0200),
- PROCESS_QUERY_INFORMATION = (0x0400)
- }
- public IntPtr open(string Name)
- {
- System.Diagnostics.Process[] myProgrammInstances;
- ProcessAccessType myAccessFlags;
- IntPtr handleProcess;
- handleProcess = IntPtr.Zero;
- myProgrammInstances = System.Diagnostics.Process.GetProcessesByName(Name);
- myAccessFlags = ProcessAccessType.PROCESS_VM_READ
- | ProcessAccessType.PROCESS_VM_WRITE
- | ProcessAccessType.PROCESS_VM_OPERATION;
- return handleProcess = OpenProcess((uint)myAccessFlags, 1, (uint)myProgrammInstances[0].Id);
- }
- public int close(IntPtr H)
- {
- return CloseHandle(H);
- }
- public byte[] ReadMemoryAtAdress(IntPtr H,IntPtr MemoryAddress, uint bytesToRead, out int bytesRead)
- {
- byte[] buffer = new byte[bytesToRead];
- IntPtr ptrBytesRead;
- ReadProcessMemory(H, MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
- bytesRead = ptrBytesRead.ToInt32();
- return buffer;
- }
- public int WriteMemoryAtAdress(IntPtr H, IntPtr MemoryAddress, byte[] bytesToWrite)
- {
- IntPtr ptrBytesWritten;
- WriteProcessMemory(H, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
- return ptrBytesWritten.ToInt32();
- }
- public IntPtr pointer(IntPtr H, IntPtr pointer, int offset = 0)
- {
- byte[] buffer = new byte[4];
- IntPtr ptrBytesRead;
- int add;
- int bytesRead;
- ReadProcessMemory(H, pointer, buffer, 4, out ptrBytesRead);
- bytesRead = ptrBytesRead.ToInt32();
- add = BitConverter.ToInt32(buffer, 0);
- return (IntPtr) add + offset;
- }
- }
- }