How to create a NativePointer which points to an int value(not memory address)?
Allocate memory for int and write to it
var temp = Memory.alloc(Process.pointerSize);
temp.writeInt(1337);
using NativePointer for similar task
var temp = new NativePointer('1337'); // you can use ptr('1337') as a shorthand
Make sure to always go through the docs before opening issues
@0xXA are you suggesting that ptr('1337') allocates an integer with the value '1337' and then returns a native pointer pointing to that value? I've 'read the docs' and they seem to suggest that code will simply create a pointer pointing to the address 0x539 (1337)...
@oleavr I would really like some clarification on this as it's boggling my mind a bit. If I have a libc function that takes a 'pointer to an int' as its argument (eg. wait()) - what is the best practice for creating an empty int allocation and passing a pointer to it as an argument to my native function?
Cheers
ptr('1337') is just a number, it doesn't allocate.
It's up to the native function on how to interpret it.
what is the best practice for creating an empty int allocation and passing a pointer to it as an argument to my native function?
const intPtr = Memory.alloc(Process.pointerSize);
wait(intPtr);
console.log(intPtr.readInt());
Also careful with scoping: as soon as intPtr is garbage collected in js, it will also free that memory region. You can store it in some global array for example if that happens.