ludwig
YaBB Newbies
Offline
Posts: 3
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?