C#指针偏移> 255 - ProcessMemoryReader

时间:2013-04-16 20:11:36

标签: c# pointers offset readprocessmemory

我知道有很多教程向您展示如何使用“ProcessMemoryReader”函数。但是这个问题似乎是独特的或尚未解决。

很长一段时间以来,我一直在挖掘其他人的代码,以找到使用多个偏移的方法。 我认为使用多个偏移对我来说是个问题,但我认为我的偏移值大于255是个问题。

我试图获取内存值的游戏叫做“Assault Cube”。 由于我不确定我是否得到了正确的偏移值,因此我搜索了其他人的结果。 他们似乎完全一样: http://cheatengine.org/tables/moreinfo.php?tid=1142(如果您没有安装作弊引擎,可以使用记事本查看.ct文件。)

以下是我的代码,使用ProcessMemoryReader.cs

private void timer1_Tick(object sender, EventArgs e)
{
int bytesread;
int pointerbase;
byte[] memory;
Process[] myprocess = Process.GetProcessesByName("ac_client");
if (myprocess.Length != 0)
{
preader.ReadProcess = myprocess[0];
preader.OpenProcess();

//Ammo
memory = preader.ReadProcessMemory((IntPtr)0x4DF73C, 4, out bytesread);
pointerbase = BitConverter.ToInt32(memory, 0);
pointerbase += 0x00; //0 // 14 // 378

byte[] memory1 = preader.ReadProcessMemory((IntPtr)pointerbase, 4, out bytesread);
int pointerbase1 = BitConverter.ToInt32(memory1, 0);
pointerbase1 += 0x14; //0 // 14 // 378

byte[] memory2 = preader.ReadProcessMemory((IntPtr)pointerbase1, 4, out bytesread);
int pointerbase2 = BitConverter.ToInt32(memory2, 0);
pointerbase2 += 0x378; //00 // 14 // 378

byte[] memory3 = preader.ReadProcessMemory((IntPtr)pointerbase2, 4, out bytesread);
int valueis = BitConverter.ToInt32(memory3, 0);
label1.Text = valueis.ToString();
}

虽然使用单个指针,但该过程正常,例如:

 //HP
 memory = preader.ReadProcessMemory((IntPtr)0x4DF73C, 4, out bytesread);
 pointerbase = BitConverter.ToInt32(memory, 0);
 pointerbase += 0xf4;

 byte[] memory1 = preader.ReadProcessMemory((IntPtr)pointerbase, 4, out bytesread);
 int valueis = BitConverter.ToInt32(memory1, 0);
 label2.Text = valueis.ToString();

所以这很有效,这里发生的事情很简单,但是我无法想象如何用多个偏移读取Ammo代码。

2 个答案:

答案 0 :(得分:0)

我不熟悉CheatEngine及其表格格式,但我没有得到它指向你正在使用的内存地址的印象。

您在0x4DF73C读取4个字节,用作下次读取的新内存地址。这重复了几次。基本上,您正在从指向指针的指针读取信息。你确定这是预期的吗?

没有任何理由认为大于255的偏移值会成为问题。

答案 1 :(得分:0)

使用FindDMAAddy为您遍历指针链,这是一个有效的示例,请确保您以admin身份运行:

public static IntPtr FindDMAAddy(IntPtr hProc, IntPtr ptr, int[] offsets)
{
    var buffer = new byte[IntPtr.Size];

    foreach (int i in offsets)
    {
        ReadProcessMemory(hProc, ptr, buffer, buffer.Length, out
        var read);
        ptr = (IntPtr.Size == 4) ? IntPtr.Add(new IntPtr(BitConverter.ToInt32(buffer, 0)), i) : ptr = IntPtr.Add(new IntPtr(BitConverter.ToInt64(buffer, 0)), i);
    }
    return ptr;
}

var modBase = GetModuleBaseAddress(proc.Id, "ac_client.exe");

var ammoAddr = FindDMAAddy(hProc, (IntPtr)(modBase + 0x10f4f4), new int[] { 0x374, 0x14, 0 });

Console.WriteLine("Ammo address " + "0x" + ammoAddr.ToString("X"));

int newAmmo = 1337;

byte[] buffer = new byte[4];

ReadProcessMemory(proc.Handle, ammoAddr, buffer, 4, out _);

Console.WriteLine("Ammo value " + BitConverter.ToInt32(buffer, 0).ToString());

WriteProcessMemory(hProc, ammoAddr, newAmmo, 4, out _);
相关问题