如何使用模块+基指针+偏移量来获取ram地址的值



我正在尝试使用Auto热键来读取一些RAM值。为此,我使用以下库:

https://github.com/Kalamity/SC2-MacroTrainer/blob/master/Lib/classMemory.ahk

关于这个库如何工作的文档清楚地写在上面,但它缺乏任何关于如何将其与模块一起使用的文档。

我的基本指针是:"jvm.dll"+000338E84

我的偏移量是(从上到下):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的计算是错误的。两天来,我一直在尝试使用各种变体,但没有成功。有人能解释一下我做错了什么以及如何解决吗?

我真的没有时间检查你正在使用的库,但这里有一些提示:
如果你的目标进程以管理员身份运行,你的程序也必须这样做。此外,您可能还想设置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.dllOpenProcessToken", "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.dllLookupPrivilegeValue", "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.dllAdjustTokenPrivileges", "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中(作为浮点值)。然后你必须这样做(如果你使用原始ReadProcessMemory或类似的东西):

player1moduleOffset := 0x01088450  
healthOffset := 0x4  
moduleBaseAddress := GetModuleAddr("example.dll")  
player1BaseAddress := moduleBaseAddress+player1moduleOffset  
player1Base := MemoryReasAsInt(player1BaseAddress)  
player1HealthAddress := player1Base+healthOffset  
player1Health := MemoryReasAsFloat(player1HealthAddress)  

在库开发人员的帮助下,我设法解决了这个问题。这是工作代码:

#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%

最新更新