forked from hugsy/windbg_js_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumModules.js
More file actions
73 lines (58 loc) · 1.61 KB
/
Copy pathEnumModules.js
File metadata and controls
73 lines (58 loc) · 1.61 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
*
* Enumerate modules from nt!PsLoadedModuleList
*
* Use as:
* kd> .scriptload \path\to\EnumModules.js
* kd> dx -g @$LoadedModules()
*
* Calling with `.scriptrun` will also dump the list
*/
"use strict";
const log = x => host.diagnostics.debugLog(x + "\n");
function IsKd(){ return host.namespace.Debugger.Sessions.First().Attributes.Target.IsKernelTarget === true; }
/**
* Create an iterator over the loaded modules (from nt!PsLoadedModuleList)
*/
function *LoadedModuleList()
{
if ( !IsKd() )
{
log("Not KD");
return;
}
// Get the value associated to the symbol nt!PsLoadedModuleList
// And cast it as nt!LIST_ENTRY
let pPsLoadedModuleHead = host.createPointerObject(host.getModuleSymbolAddress("nt", "PsLoadedModuleList"), "nt", "_LIST_ENTRY *");
// Dereference the pointer (which makes us point to ntoskrnl)
// Cast it to nt!KLDR_DATA_TABLE_ENTRY
let pNtLdrDataEntry = host.createPointerObject(pPsLoadedModuleHead.address, "nt", "_LDR_DATA_TABLE_ENTRY *");
// Create the iterator
let PsLoadedModuleList = host.namespace.Debugger.Utility.Collections.FromListEntry(
pNtLdrDataEntry.InLoadOrderLinks,
"nt!_LDR_DATA_TABLE_ENTRY",
"InLoadOrderLinks"
);
for (let item of PsLoadedModuleList)
{
yield item;
}
}
/**
*
*/
function invokeScript()
{
for ( var mod of LoadedModuleList() )
{
log(" - " + mod.FullDllName);
}
}
/**
*
*/
function initializeScript()
{
log("[+] Creating the variable `LoadedModules`...");
return [new host.functionAlias(LoadedModuleList, "LoadedModules")];
}