4
       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

Next, I want to use Kernel32.INSTANCE.ReadProcessMemory();

However, I am unable to find the function within Kernel32. Was this function removed? If so, is there any other way to do ReadProcessMemory?

I am using Java and using JNA Lib.

Thank you.

Vikram
  • 3,996
  • 8
  • 37
  • 58

2 Answers2

1

The question was originally asked in 2012. The ReadProcessMemory function was added to the jna.platform.win32.Kernel32 interface on Jun 29 2014, meaning that the function was simply not mapped yet at the time of asking.

JNA versions 4.2.0 and above ship with the function included.

cbr
  • 12,563
  • 3
  • 38
  • 63
0

You may need to define the Kernel32 instance before calling it's functions.

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