c# - Read int from process memory -
i'm reading data memory using base adress , 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 this:
var 1 = memoryhandler.readint((long)memoryhandler.base_adress + (long)0x0945bb0c); var 2 = memoryhandler.readint(one + (long)0x28); var 3 = memoryhandler.readint(two + (long)0x214); var 4 = memoryhandler.readint(three + (long)0x38); var 5 = memoryhandler.readint(four + (long)0x7ec); var 6 = memoryhandler.readint(five + (long)0x230);
where six
contains value need.
i tried make overload same thing. problem it's not giving me same value. know why:
public static int readint(long address, int[] offsets) { long prev = 0; (int = 0; < 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 clarify: want result
have same value six
above.
note work on 32bits
public static int readint(long address, int[] offsets) { address = readint(address); (int = 0; < offsets.length; i++) { address = readint(address + (long)offsets[i]); } return (int)address; }
you have offsets.length + 1
readint
(s) do, 1 without offset , offsets.length
offset. each 1 returns address next one. last 1 returns value.
considering work on 32 bits (because reading 32 bits , using them ptr), using long
useless. int
enough.
Comments
Post a Comment