Read int from process memory
I'm reading data from the memory using a base adress and some offsets:
public static int ReadInt(long address)
{
byte[] buffer = new byte[sizeof(int)];
ReadProcessMemory(pHandle, (UIntPtr)address, buffer, (UIntPtr)4,
IntPtr.Zero);
return BitConverter.ToInt32(buffer, 0);
}
I add offsets like this:
var one = MemoryHandler.ReadInt((long)MemoryHandler.base_adress +
(long)0x0945BB0C);
var two = MemoryHandler.ReadInt(one + (long)0x28);
var three = MemoryHandler.ReadInt(two + (long)0x214);
var four = MemoryHandler.ReadInt(three + (long)0x38);
var five = MemoryHandler.ReadInt(four + (long)0x7EC);
var six = MemoryHandler.ReadInt(five + (long)0x230);
Where six contains the value that I need.
I tried to make an overload that does the very same thing. My problem is
that it's not giving me the same value. I would like to know why:
public static int ReadInt(long address, int[] offsets)
{
long prev = 0;
for (int i = 0; i < offsets.Length; i++)
{
address = prev > 0 ? ReadInt(prev + (long)offsets[i]) :
ReadInt(address);
prev = address + offsets[i];
}
return (int)address;
}
var offsets = new int[] { 0x28, 0x214, 0x38, 0x7EC, 0x230 };
var result = MemoryHandler.ReadInt((long)MemoryHandler.base_adress +
(long)0x0945BB0C, offsets);
Just to clarify: I want result to have the same value as six above.
No comments:
Post a Comment