问题描述
我试图用Java编写一个小培训师,但是我被困在ReadProcessMemory中。我在项目中使用JNA和JNA平台v5.6.0。当我尝试以此方式读取ProcessMemory时
Psapi.MODULEINFO moduleinfo = process.getModuleInfo("ac_client");
long base_address = Pointer.nativeValue(moduleinfo.lpBaSEOfDll);
int player = process.readInt32(base_address + player_ptr);
仅发出了ReadProcessMemory或WriteProcessMemory请求的一部分。
基地址和player_ptr是正确的地址。我在互联网上看到的所有ReadProcessMemory示例都没有将指针作为内存地址的参数。
这是我的全班课。
private final HANDLE process;
private BProcess(HANDLE process) {
this.process = process;
}
public static BProcess open(String name) {
WinDef.HWND window = User32.INSTANCE.FindWindow(null,name);
IntByReference i_ref = new IntByReference();
User32.INSTANCE.GetwindowThreadProcessId(window,i_ref);
HANDLE process = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_VM_READ | WinNT.PROCESS_VM_OPERATION | WinNT.PROCESS_VM_WRITE,false,i_ref.getValue());
return new BProcess(process);
}
public int readInt32(long address) {
Pointer buffer = new Memory(4);
Pointer p_address = new Memory(8);
p_address.setLong(0,address);
IntByReference iref = new IntByReference();
boolean b = Kernel32.INSTANCE.ReadProcessMemory(this.process,p_address,buffer,4,iref);
if (!b) {
System.out.println(p_address.getLong(0));
throw new Win32Exception(Native.getLastError());
}
return ByteBuffer.wrap(buffer.getByteArray(0,4)).get();
}
public Psapi.MODULEINFO getModuleInfo(String name) {
WinDef.HMODULE[] hmodules = new WinDef.HMODULE[400];
IntByReference i_ref = new IntByReference();
boolean b = Psapi.INSTANCE.EnumProcessModules(this.process,hmodules,hmodules.length,i_ref);
if (!b) {
throw new Win32Exception(Native.getLastError());
}
WinDef.HMODULE module = null;
int i = 0;
while ((module = hmodules[i]) != null) {
char[] c = new char[500];
Psapi.INSTANCE.GetmodulefileNameExW(this.process,module,c,500);
System.out.println(new String(c));
String moduleName = new String(c);
if (moduleName.contains(name)) {
break;
}
i++;
}
if (module == null) {
throw new NoSuchElementException(name);
}
Psapi.MODULEINFO moduleinfo = new Psapi.MODULEINFO();
Psapi.INSTANCE.GetModuleinformation(this.process,moduleinfo,moduleinfo.size());
return moduleinfo;
}
public void close() {
Kernel32.INSTANCE.CloseHandle(this.process);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)