有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java内核32。例子在JNA中找不到ReadProcessMemory

       import com.sun.jna.Native;
       import com.sun.jna.Memory;
       import com.sun.jna.Pointer;
       import com.sun.jna.ptr.*;
       import com.sun.jna.platform.win32.Kernel32;
       import com.sun.jna.platform.win32.User32;
       import com.sun.jna.platform.win32.WinDef;
       import com.sun.jna.platform.win32.WinDef.HWND;
       import com.sun.jna.platform.win32.*;


public class apples {


       public static void main(String[] args) {

           IntByReference pid = new IntByReference();
           int offset = 0x7AF5DBDC;
           int buffer = 32;
           Memory output = new Memory(buffer);

HWND hwnd = User32.INSTANCE.FindWindow("notepad", null);   
    if (hwnd != null)
    {
    System.out.println("i got the handle");
    User32.INSTANCE.GetWindowThreadProcessId(hwnd, pid);
    System.out.println("PID is " + pid.getValue());
    WinNT.HANDLE hProc =  Kernel32.INSTANCE.OpenProcess(0, false, pid.getValue());

    Output: 
    i got the handle
    PID is 752

接下来,我想使用Kernel32。例子ReadProcessMemory()

但是,我无法在内核32中找到该函数。这个功能被删除了吗?如果是这样,是否还有其他方法来执行ReadProcessMemory

我正在使用Java和JNA库

多谢各位


共 (2) 个答案

  1. # 1 楼答案

    这个问题最初是在2012年提出的。ReadProcessMemory函数被添加到jna.platform.win32.Kernel32接口on Jun 29 2014,这意味着在请求时函数还没有被映射

    JNA 4.2.0及以上版本附带了该功能

  2. # 2 楼答案

    在调用其函数之前,可能需要定义Kernel32实例

    Kernel32 kernel32 = (Kernel32) Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    int memValue = kernel32.ReadProcessMemory(WinNT.HANDLE, pointer, pointer, int, IntByReference);