【问题标题】:C# Read value from pointer with multiple offsetsC#从具有多个偏移量的指针读取值
【发布时间】:2019-08-11 09:34:44
【问题描述】:

我正在尝试使用 VAMemory 库读取浮点数,并且我有基本偏移量和要从 CE 添加到指针的偏移量,并且我知道它们正确引用了该值(在 CE 中相应地更改了值)

以下是 CE 显示的偏移量:(根据之前关于此主题的问题,它们应该在 CE 中出现时从下到上应用)

我已经尝试了在每次迭代中“取消引用”指针的多种实现,因为必须一个接一个地添加偏移量,我不确定我是否正确获取了基地址,如果我应该迭代而是通过流程的模块,并将其与我在其他问题中看到的名称匹配。我现在正在尝试使用类似问题中显示的实现,但是我得到的返回值始终是 0

private static float GetPointerValue(IntPtr baseAddress, int[] offsetArr)
{

VAMemory vam = new VAMemory("amtrucks");

//Adding original offset to base address
IntPtr pointer = IntPtr.Add((IntPtr)vam.ReadInt32(baseAddress + 0x014BC410), offsetArr[0]);
for (int i = 1; i < offsetArr.Length; i++)
{
   pointer = IntPtr.Add((IntPtr)vam.ReadInt32(pointer), offsetArr[i]);
}
return vam.ReadFloat(pointer);
}
public void SetCam(float height)
{
Process GameProcess = Process.GetProcessesByName("amtrucks").FirstOrDefault();
IntPtr BaseAddress = GameProcess.MainModule.BaseAddress;


//Offsets in reverse order
var offsetArr = new int[] { 0x18, 0x40, 0x0, 0x3C8, 0x48};

Console.WriteLine("value:" + GetPointerValue(BaseAddress, offsetArr));
}

它不会抛出任何异常或错误消息,但值始终为 0(实际值在 43 左右)

【问题讨论】:

    标签: c# memory


    【解决方案1】:
    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;
    }
    
    public static IntPtr GetModuleBaseAddress(Process proc, string modName)
    {
        IntPtr addr = IntPtr.Zero;
    
        foreach (ProcessModule m in proc.Modules)
        {
            if (m.ModuleName == modName)
            {
                addr = m.BaseAddress;
                break;
            }
        }
        return addr;
    }
    
    Process proc = Process.GetProcessesByName("whatever")[0];
    
    var modBase = GetModuleBaseAddress(proc, "whatever.exe");
    
    var freecamheight = FindDMAAddy(hProc, (IntPtr)(modBase + 0x14bc410), new int[] { 0x18, 0x40, 0, 0x3c8, 0x48});
    

    然后使用 VAMemory 读取地址“freecamheight”处的浮点数

    【讨论】:

      猜你喜欢
      • 2023-01-27
      • 2020-09-12
      • 2015-01-14
      • 2015-07-09
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      相关资源
      最近更新 更多