-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLdrSnapshot.pas
64 lines (51 loc) · 1.26 KB
/
LdrSnapshot.pas
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
unit LdrSnapshot;
interface
uses
NtUtils;
type
TBaseModule = (
kmNtdll, kmNtdll32,
kmMsCoree, kmMsCoree32,
kmWinUI, kmWinUI32
);
// The modules that are used to perform process snapshotting
TBaseModules = class abstract
class var Handles: array [TBaseModule] of IHandle;
class constructor Create;
end;
TModuleData = record
hxFile: IHandle;
NtFileName: String;
end;
TKnownDllData = record
FileName: String;
ImageBase: UIntPtr;
ImageSize: NativeUInt;
end;
TModuleSnapshot = record
Modules: TArray<TModuleData>;
KnownDlls, KnownDlls32: TArray<TKnownDllData>;
end;
implementation
uses
Winapi.WinNt, Ntapi.ntioapi, NtUtils.Files;
{ TBaseModules }
class constructor TBaseModules.Create;
const
BaseNames: array [TBaseModule] of String = (
'\SystemRoot\System32\ntdll.dll',
'\SystemRoot\SysWoW64\ntdll.dll',
'\SystemRoot\System32\mscoree.dll',
'\SystemRoot\SysWoW64\mscoree.dll',
'\SystemRoot\System32\Windows.UI.dll',
'\SystemRoot\SysWoW64\Windows.UI.dll'
);
var
i: TBaseModule;
begin
for i := Low(TBaseModule) to High(TBaseModule) do
if not NtxOpenFile(Handles[i], FILE_READ_DATA or FILE_READ_ATTRIBUTES,
BaseNames[i]).IsSuccess then
Handles[i] := nil;
end;
end.