Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## MemoryAddress - Base abstract class
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace ParseCT
- {
- public abstract class MemoryAddress
- {
- public IntPtr Address { get; protected set; }
- public IntPtr BaseAddress { get; protected set; }
- public Object Tag { get; set; }
- public String Description {get; set;}
- public IntPtr hProcess { get; protected set; }
- protected bool CloseProcess = false;
- protected Process Proc = null;
- public abstract void Calculate();
- public bool Read(byte[] buffer)
- {
- if (Address == null || Address == IntPtr.Zero)
- {
- throw new Exception("Address not properly initilized");
- }
- int outf;
- return WinAPI.ReadProcessMemory(hProcess, Address, buffer, buffer.Length, out outf);
- }
- public bool Write(byte[] data)
- {
- if (Address == null || Address == IntPtr.Zero)
- {
- throw new Exception("Address not properly initilized");
- }
- int outf;
- return WinAPI.WriteProcessMemory(hProcess, Address, data, (uint)data.Length, out outf);
- }
- }
- }
- ##BasicAddress - Basic address
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace ParseCT
- {
- class BasicAddress : MemoryAddress
- {
- private bool Recalculate = true;
- public BasicAddress(IntPtr BaseAddress, IntPtr hProcess, Process p, bool Recalc = true)
- {
- this.Recalculate = Recalc;
- this.hProcess = hProcess;
- this.Proc = p;
- this.BaseAddress = BaseAddress;
- Calculate();
- }
- public BasicAddress(IntPtr BaseAddress, Process p, bool Recalc = true)
- {
- this.Recalculate = Recalc;
- this.Proc = p;
- this.BaseAddress = BaseAddress;
- this.CloseProcess = true;
- this.hProcess = WinAPI.OpenProcess(WinAPI.ProcessAccess.VMRead | WinAPI.ProcessAccess.VMWrite, false, (uint)p.Id);
- if (this.hProcess == IntPtr.Zero)
- {
- throw new Exception("Error opening process");
- }
- Calculate();
- }
- public override void Calculate()
- {
- if (this.Recalculate)
- {
- this.Address = new IntPtr(this.Proc.MainModule.BaseAddress.ToInt64() + this.BaseAddress.ToInt64());
- }
- else
- {
- this.Address = BaseAddress;
- }
- }
- }
- }
- ##Pointer Address - Pass it an address and a list of offsets, it will find the end address
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace ParseCT
- {
- public class PointerAddress : MemoryAddress
- {
- public PointerAddress(IntPtr BaseAddress, List<int> Offsets, IntPtr hProcess, Process p)
- {
- this.hProcess = hProcess;
- this.Proc = p;
- this.BaseAddress = BaseAddress;
- Calculate(Offsets);
- }
- public void Calculate(List<int> Offsets)
- {
- BasicAddress addr = new BasicAddress(BaseAddress, hProcess, Proc);
- byte[] ptr = new byte[4];
- int a = 0;
- for (int i = 0; i < Offsets.Count; i++)
- {
- if (addr.Read(ptr))
- {
- a = BitConverter.ToInt32(ptr, 0) + Offsets[i];
- addr = new BasicAddress(new IntPtr(a), hProcess, Proc, false);
- }
- else
- {
- throw new Exception("Could not read memory from base pointer");
- }
- }
- this.Address = new IntPtr(a);
- }
- public override void Calculate()
- {
- Calculate(new List<int>(new int[] { 0 }));
- }
- }
- }
- ##Test program
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Threading;
- using System.Diagnostics;
- namespace ParseCT
- {
- class Program
- {
- static void Main(string[] args)
- {
- Process[] ps = null;
- do
- {
- if (ps == null)
- {
- Console.WriteLine("Waiting for CO GameClient");
- }
- ps = Process.GetProcessesByName("GameClient");
- if (ps.Length == 0)
- {
- Thread.Sleep(250);
- }
- } while (ps.Length == 0);
- IntPtr hProcess = WinAPI.OpenProcess(WinAPI.ProcessAccess.VMRead | WinAPI.ProcessAccess.VMWrite, false, (uint)ps[0].Id);
- if (hProcess != IntPtr.Zero)
- {
- Console.WriteLine("GameClient Process Accessed");
- BasicAddress ba = new BasicAddress(new IntPtr(0x1AA7174), hProcess, ps[0]);
- Console.WriteLine("Target address: {0:X}", ba.Address.ToInt32());
- PointerAddress pa = new PointerAddress(new IntPtr(0x006EE218), new List<int>(new int[] { 0x30 }), hProcess, ps[0]);
- Console.WriteLine("Found address: {0:X}", pa.Address.ToInt32());
- PointerAddress pa2 = new PointerAddress(new IntPtr(0x01D17800), new List<int>(new int[] { 0x6BC, 0x28C, 0x43C, 0x684, 0xD8 }), hProcess, ps[0]);
- Console.WriteLine("Found address: {0:X}", pa2.Address.ToInt32());
- }
- WinAPI.CloseHandle(hProcess);
- Console.Read();
- }
- }
- }
Add Comment
Please, Sign In to add comment