pykd
1from pykd import *
2
3def main():
4pass
5
6def listModuleFromLdr64():
7
8dprintln( "<u>64 bit modules:</u>", True )
9
10peb = typedVar( "ntdll!PEB", getProcessOffset(getCurrentProcess()) )
11
12moduleLst = typedVarList( peb.Ldr.deref().InMemoryOrderModuleList, "ntdll!_LDR_DATA_TABLE_ENTRY", "InMemoryOrderLinks" )
13
14for mod in moduleLst:
15name = typedVar( "ntdll!_UNICODE_STRING", mod.BaseDllName )
16dprintln(loadWChars(name.Buffer, name.Length/2))
17
18try:
19
20peb32 = typedVar( "ntdll32!_PEB", getProcessOffset(getCurrentProcess()) - pageSize() )
21
22dprintln( "\n<u>32 bit modules:</u>", True)
23
24moduleLst = typedVarList( peb32.Ldr.deref().InMemoryOrderModuleList, "ntdll32!_LDR_DATA_TABLE_ENTRY", "InMemoryOrderLinks" )
25
26for mod in moduleLst:
27name = typedVar( "ntdll32!_UNICODE_STRING", mod.BaseDllName )
28dprintln(loadWChars(name.Buffer, name.Length/2))
29
30except BaseException:
31pass
32
33def listModuleFromLdr():
34
35peb = typedVar( "ntdll!PEB", getProcessOffset(getCurrentProcess()) )
36
37moduleLst = typedVarList( peb.Ldr.deref().InMemoryOrderModuleList, "ntdll!_LDR_DATA_TABLE_ENTRY", "InMemoryOrderLinks" )
38
39for mod in moduleLst:
40dprintln(loadUnicodeString(mod.BaseDllName))
41
42
43def run():
44
45while True:
46
47if isKernelDebugging():
48dprintln( "not a user debugging" )
49break
50
51if is64bitSystem():
52listModuleFromLdr64()
53else:
54listModuleFromLdr()
55
56break
57
58if __name__ == "__main__":
59run()