Java JNA 解引用指针

Java JNA Dereference Pointer

好吧,我在 c++ 中有以下代码

uintptr_t buf;

if ((reason = vm_read(task, (uintptr_t) &start, sizeof(int), &buf, &bytesRead)) != KERN_SUCCESS) {
    cout << "Failed to read: " << reason << endl;
}

cout << "Step 2 (after write, should = 100): " << (*(int *) buf) << endl;

在第 2 步打印的地方,我取消引用 buf 指针并转换为它的 int 值。

我想知道如何使用 JNA 在 Java 中执行此操作?

我尝试了以下方法,但它没有打印出正确的值。

    IntByReference o = new IntByReference();
    MemoryBuffer buffer = Cacheable.buffer(4);
    System.out.println(mac.vm_read(process.task(), new Pointer(140734594927432L), 4,  buffer, o));
    System.out.println(Pointer.nativeValue(buffer));

为了读取正确的值,我必须先调用 buffer.getPointer(0).getInt()

例如:

IntByReference o = new IntByReference();
MemoryBuffer buffer = Cacheable.buffer(4);
System.out.println(mac.vm_read(process.task(), new Pointer(140734594927432L), 4,  buffer, o));
System.out.println(buffer.getPointer(0).getInt());