We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › win memory access
Page Index Toggle Pages: 1
win memory access (Read 224 times)
win memory access
Aug 4th, 2009, 6:32am
 
Hi!

a question.. i´m trying to read memory from outside jvm
and ive found this

import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;

public class ReadProcessMemoryDemo {

   public static final int PROCESS_QUERY_INFORMATION = 0x0400;
   public static final int PROCESS_VM_READ = 0x0010;

   public interface Kernel32 extends StdCallLibrary {
       Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);

       public Pointer OpenProcess(int dwDesiredAccess, boolean bInheritHandle, int dwProcessId);

       boolean ReadProcessMemory(Pointer hProcess, int inBaseAddress, Pointer outputBuffer, int nSize,
               IntByReference outNumberOfBytesRead);
   }

   public static void main(String[] args) {

       Kernel32 lib = Kernel32.INSTANCE;

       int pid = 1276;
       int bufferSize = 128;
       int offset = 65536;
       Pointer process = lib.OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid);

       if (process == null) {
           throw new RuntimeException("no such pid");
       }

       IntByReference baseAddress = new IntByReference();
       baseAddress.setValue(offset);
       Memory outputBuffer = new Memory(bufferSize);
       boolean success = lib.ReadProcessMemory(process, offset,  outputBuffer, bufferSize, null);
       System.out.println("success = " + success);

       byte[] bufferBytes = outputBuffer.getByteArray(0, bufferSize);
       System.out.println(new String(bufferBytes));
   }
}


by martin_c

but i cant get it to work in processing..why?
Page Index Toggle Pages: 1