我一直在研究一个小型项目 - 我试图创建一个C#程序,它将从游戏“英雄联盟”中读取人物的HP。如何使用Base地址和指针读取进程内存
我做了一些研究,经过一段时间搞乱了cheatengine后,即使重新启动电脑后,我也得到了指向HP地址的偏移量,并且每次都可以成功读取它。
现在我想做一个程序,将做同样的事情。我发现了一个类,我可以从内存中读取浮点数,称为VAMemory。我将Cheatengine的静态地址复制到我的程序中,并获得了HP值,就像我想要的那样。
VAMemory vam = new VAMemory("League Of Legends");
vam.ReadFloat((IntPtr)adress);
但是,重新启动游戏后,这不起作用,所以我必须再次从Cheatengine获取地址。
我发现了一个类似的question和回答说:
对于你要读取内存,看看什么是存储在地址每个级别。您找到的值将是您的下一个地址,您将应用下一个偏移量,等等。
在这个问题中,提问者有2个偏移量,但是我有5个偏移量?
用它来获得基地址:
Process GameProcess = Process.GetProcessesByName("League Of Legends").FirstOrDefault();
IntPtr BaseAddress = GameProcess.MainModule.BaseAddress;
于是我创造了这个怪物:
try
{
Process GameProcess = Process.GetProcessesByName("League Of Legends").FirstOrDefault();
VAMemory vam = new VAMemory("League Of Legends");
IntPtr BaseAddress = GameProcess.MainModule.BaseAddress;
float Basevalue = vam.ReadFloat((IntPtr)BaseAddress);
abase.Text = BaseAddress.ToString();
vbase.Text = Basevalue.ToString();
IntPtr Basefirst = IntPtr.Add(BaseAddress, 0x658);
float Basefirstvalue = vam.ReadFloat((IntPtr)Basefirst);
a1.Text = Basefirst.ToString();
v1.Text = Basefirstvalue.ToString();
IntPtr Basesecond = IntPtr.Add(IntPtrFromFloat(Basefirstvalue), 0x150);
float Basesecondvalue = vam.ReadFloat((IntPtr)Basefirstvalue);
a2.Text = Basesecond.ToString();
v2.Text = Basesecondvalue.ToString();
IntPtr Basethird = IntPtr.Add(IntPtrFromFloat(Basesecondvalue), 0x0);
float Basethirdvalue = vam.ReadFloat((IntPtr)Basethird);
a3.Text = Basethird.ToString();
v3.Text = Basethirdvalue.ToString();
IntPtr Basefourth = IntPtr.Add(IntPtrFromFloat(Basethirdvalue), 0x44);
float Basefourthvalue = vam.ReadFloat((IntPtr)Basefourth);
a4.Text = Basefourth.ToString();
v4.Text = Basefourthvalue.ToString();
IntPtr Basefifth = IntPtr.Add(IntPtrFromFloat(Basefourthvalue), 0x36c);
float Basefifthvalue = vam.ReadFloat((IntPtr)Basefirst);
a5.Text = Basefifth.ToString();
v5.Text = Basefifthvalue.ToString();
}
catch (Exception ex)
{ MessageBox.Show(ex.ToString()); }
}
static IntPtr IntPtrFromFloat(float f)
{
unsafe
{
return (*(IntPtr*)&f);
}
}
- 它采用基址,增加了第一偏移,[读取值,接着添加] x5,然后读取最后的地址,但不幸的是其值为0.
而不是在Cheatengine美丽的数字我得到这个: 我一直在搞这个东西很长一段时间,但我仍然不明白我在做什么错了?
如何从基地址和Pointers获得动态地址?
UPDATE:
我根据注释改变了代码, 它使用Readint32()而不是readfloat()和看起来清爽多了:
Process GameProcess = Process.GetProcessesByName("League Of Legends").FirstOrDefault();
VAMemory vam = new VAMemory("League Of Legends");
IntPtr BaseAddress = GameProcess.MainModule.BaseAddress;
IntPtr Base1 = IntPtr.Add((IntPtr)vam.ReadInt32(BaseAddress), 0x58);
IntPtr Base2 = IntPtr.Add((IntPtr)vam.ReadInt32(Base1), 0xC0);
IntPtr Base3 = IntPtr.Add((IntPtr)vam.ReadInt32(Base2), 0x118);
IntPtr Base4 = IntPtr.Add((IntPtr)vam.ReadInt32(Base3), 0x39C);
IntPtr Base5 = IntPtr.Add((IntPtr)vam.ReadInt32(Base4), 0xBC);
float value = vam.ReadFloat(Base4);
Lvalue.Text = value.ToString();
但是,它仍然不起作用。我同时跑Cheatengine,它得到了正确的地址和价值,但我的程序得到了这些: 和最终值为0,它应该是528。
不要把代码作为链接到Pastebin,把它放在问题本身。人们不需要点击外部链接即可完全理解您的问题。 –
这就是说,你的问题是你调用'vam.ReadFloat',在每个级别上,你应该只在最后调用ReadFloat,中间级别需要使用'vam.ReadInt32('获得下一层(IntPtr)vam.ReadInt32(Basefirst),0x150);' –
'IntPtr Basethird = IntPtr.Add((IntPtr)vam.ReadInt32(Basesecond),0x0); (IntPtr)vam.ReadInt32(Basethird),0x44);','IntPtr Basefourth = IntPtr.Add((IntPtr)vam.ReadInt32(Basefourth),0x36c);','float Basefifthvalue = vam.ReadFloat(Basefifth);' –