如何使用模块+基址指针+偏移量来获取RAM地址的值?
问题描述:
我正在尝试使用Autohotkey读取一些RAM值。要做到这一点我使用以下库:这个库是如何工作的写清楚在它的上面,但它缺乏对如何与模块使用的任何文件如何使用模块+基址指针+偏移量来获取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天现在没有成功。任何人都可以解释我做错了什么,以及如何解决它?
答
我真的没有时间去检查你正在使用的库,但这里有一些提示:
如果你的目标进程作为管理员你的程序将要,也。你也可能想要设置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
(作为浮点值)的玩家的健康。然后,你会去像这样(如果你用生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%
虽然我自己的答案是我需要的恰恰是,你已经把efford的大量提供这个答案。为此我会接受你的表达我的赞赏。 – icecub 2014-09-21 18:39:41