在JNA中找不到Kernel32.INSTANCE.ReadProcessMemory

时间:2012-11-26 15:35:13

标签: java jna kernel32

       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.INSTANCE.ReadProcessMemory();

但是,我无法在Kernel32中找到该功能。这个功能被移除了吗?如果是这样,还有其他方法可以做ReadProcessMemory吗?

我正在使用Java并使用JNA Lib。

谢谢。

2 个答案:

答案 0 :(得分:0)

在调用它的函数之前,您可能需要定义Kernel32实例。

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

答案 1 :(得分:0)

该问题最初是在2012年提出的。ReadProcessMemory函数已添加到jna.platform.win32.Kernel32接口on Jun 29 2014,这意味着该函数在询问时尚未映射。< / p>

JNA版本4.2.0及更高版本附带了该功能。