I'm using JNA
. The Pointer
class represents a native pointer. It seems quite common to access the pointer's address which seems to be the peer
member variable. However, they made sure you can't query it. Why? What's the recommended way to getting it if you want to work with it?
I wrote the following "hack":
public static long getBaseAddress(Pointer pointer)
{
String stringPointer = pointer.toString();
String[] splitStringPointer = stringPointer.split("@");
int expectedSplitLength = 2;
if (splitStringPointer.length != expectedSplitLength)
{
throw new IllegalStateException("Expected a length of "
+ expectedSplitLength + " but got " + splitStringPointer.length);
}
String hexadecimalAddress = splitStringPointer[1].substring("0x".length());
return parseLong(hexadecimalAddress, 16);
}
But isn't there a proper way other than abusing the toString()
method for grabbing the address?
I want to use Reflection
even less than the approach above since it is also brittle.