-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathGetProcessModules.ahk
33 lines (30 loc) · 1.64 KB
/
GetProcessModules.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
; ===============================================================================================================================
; Get all modules loaded in a process.
; ===============================================================================================================================
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)
}
; ===============================================================================================================================
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
; -> ...