; 获取进程中加载的所有模块,以自身脚本进程为例
OwnPID := DllCall("GetCurrentProcessId")
for i, v in GetProcessModules(OwnPID)
MsgBox % "Module #" i ":`n" v
; -> C:\Program Files\AutoHotkey\AutoHotkey.exe
; -> C:\Windows\SYSTEM32\ntdll.dll
; -> C:\Windows\System32\KERNEL32.DLL
; -> ...
GetProcessModules(ProcessID) {
if !(hProcess := DllCall("OpenProcess", "uint", 0x0410, "int", 0, "uint", ProcessID, "ptr"))
throw Exception("OpenProcess failed", -1)
if !(DllCall("psapi\EnumProcessModulesEx", "ptr", hProcess, "ptr", 0, "uint", 0, "uint*", size, "uint", 0x03))
throw Exception("EnumProcessModulesEx failed", -1)
cb := VarSetCapacity(hModule, size, 0)
if !(DllCall("psapi\EnumProcessModulesEx", "ptr", hProcess, "ptr", &hModule, "uint", cb, "uint*", size, "uint", 0x03))
throw Exception("EnumProcessModulesEx failed", -1)
MODULES := []
loop % size // A_PtrSize
{
size := VarSetCapacity(buf, 0x0104 << 1, 0)
if !(DllCall("psapi\GetModuleFileNameEx", "ptr", hProcess, "ptr", NumGet(hModule, (A_Index - 1) * A_PtrSize, "ptr"), "ptr", &buf, "uint", size))
throw Exception("GetModuleFileNameEx failed", -1)
MODULES[A_Index] := StrGet(&buf)
}
return MODULES, DllCall("CloseHandle", "ptr", hProcess)
}
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)