I've just wrote some code, which accesses the memory. I checked the address (in code) with CheatEngine, and I printed it with System.out, and it's different. I know it's a long value, but in hex, the value 2 is 00000002 (which was the result in CheatEngine), and I get 844287491178496 with java. Why is that? How can I convert the value from the address to an int? And more important, what is the long value I've just read from the memory with java? Here's my code:
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class Memory2 {
public static void main(String args[]){
Unsafe unsafe = getUnsafe();
long address = 0x002005C;
unsafe.getAddress(address);
System.out.println(unsafe.getAddress(address));
}
public static Unsafe getUnsafe() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe)f.get(null);
} catch (Exception e) {}
return null;
}
}
Unsafeclass, which goes around all this as its name suggests.Fetches a native pointer from a given memory address. If the address is zero, or does not point into a block obtained from #allocateMemory , the results are undefined.