我尝试使用Autohotkey读取一些RAM值。要做到这一点,我使用以下库:
https://github.com/Kalamity/SC2-MacroTrainer/blob/master/Lib/classMemory.ahk
关于这个库如何工作的文件清楚地写在它上面,但它没有关于如何在模块中使用它的任何文档。
我的基本指针是:" jvm.dll" + 00338E84
我的偏移是(从上到下):0x8,0x294,0x4B8,0x24,0x20
到目前为止我的代码是:
#include %a_scriptdir%/classMemory.ahk
java := new _ClassMemory("ahk_exe javaw.exe", "", hProcessCopy)
if !isObject(java)
msgbox failed to open a handle
myBase := java.getModuleBaseAddress("jvm.dll")
pointerBase := myBase + 0x00338E84
arrayPointerOffsets := [0x20, 0x24, 0x4B8, 0x294, 0x8]
value := java.read(pointerBase, "UInt", arrayPointerOffsets*)
msgbox %value%
不幸的是,这不起作用。显然,pointerBase计算错误。一直试图使用各种变化2天,但没有成功。谁能解释一下我做错了什么以及如何解决它?
答案 0 :(得分:2)
我没有时间检查您正在使用的库,但这里有一些提示:
如果您的目标流程以管理员身份运行,您的程序也必须运行。你也可能想设置SeDebugPrivileges(如果lib不是自己做的话)。
If !A_IsAdmin {
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
SetSeDebugPrivilege()
SetSeDebugPrivilege(enable := True)
{
h := DllCall("OpenProcess", "UInt", 0x0400, "Int", false, "UInt", DllCall("GetCurrentProcessId"), "Ptr")
; Open an adjustable access token with this process (TOKEN_ADJUST_PRIVILEGES = 32)
DllCall("Advapi32.dll\OpenProcessToken", "Ptr", h, "UInt", 32, "PtrP", t)
VarSetCapacity(ti, 16, 0) ; structure of privileges
NumPut(1, ti, 0, "UInt") ; one entry in the privileges array...
; Retrieves the locally unique identifier of the debug privilege:
DllCall("Advapi32.dll\LookupPrivilegeValue", "Ptr", 0, "Str", "SeDebugPrivilege", "Int64P", luid)
NumPut(luid, ti, 4, "Int64")
if enable
NumPut(2, ti, 12, "UInt") ; enable this privilege: SE_PRIVILEGE_ENABLED = 2
; Update the privileges of this process with the new access token:
r := DllCall("Advapi32.dll\AdjustTokenPrivileges", "Ptr", t, "Int", false, "Ptr", &ti, "UInt", 0, "Ptr", 0, "Ptr", 0)
DllCall("CloseHandle", "Ptr", t) ; close this access token handle to save memory
DllCall("CloseHandle", "Ptr", h) ; close this process handle to save memory
return r
}
要读取偏移量,您只需将它们添加到您的地址即可
所以,让我们假装你是一个阅读游戏的记忆。并且你想要读取一直存储在["example.dll"+0x01088450]+0x4
中的玩家1的健康状况(作为浮动值)。然后你必须这样(如果你使用原始的ReadProcessMemory或类似的):
player1moduleOffset := 0x01088450
healthOffset := 0x4
moduleBaseAddress := GetModuleAddr("example.dll")
player1BaseAddress := moduleBaseAddress+player1moduleOffset
player1Base := MemoryReasAsInt(player1BaseAddress)
player1HealthAddress := player1Base+healthOffset
player1Health := MemoryReasAsFloat(player1HealthAddress)
答案 1 :(得分:1)
在图书馆开发人员的帮助下,我设法解决了这个问题。这是工作代码:
#include %a_scriptdir%/classMemory.ahk
java := new _ClassMemory("ahk_exe javaw.exe")
if !isObject(java)
msgbox failed to open a handle
baseAddress := java.getModuleBaseAddress("jvm.dll")
arrayPointerOffsets := [0x20, 0x24, 0x4B8, 0x294, 0x8]
value := java.read(baseAddress + 0x00338E84, "UInt", arrayPointerOffsets*)
msgbox %value%