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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! Locates loaded modules in memory and extracts the information needed
//! to fetch their debug symbols.
//!
//! [`resolve_kernel_module`] and [`resolve_user_module`] return a
//! [`Resolved`] value containing the module's load address and an
//! OS-specific [`DebugSignature`]. The signature can then be passed
//! to an [`IsrCache`] to fetch the matching debug profile.
//!
//! [`DebugSignature`]: OsAdapter::DebugSignature
use IsrCache;
use ;
pub use ;
/// A resolved module with the metadata needed to fetch its debug symbols.
/// Resolves a kernel module by name and extracts its [`DebugSignature`].
///
/// # Platform-specific
///
/// - **Windows**:
/// - Walks `PsLoadedModuleList` to find the matching
/// `_KLDR_DATA_TABLE_ENTRY`.
/// - Reads the [`CodeView`] directly from its `DllBase`.
///
/// # Examples
///
/// ```no_run
/// # use isr_cache::IsrCache;
/// # use vmi::{
/// # VmiState,
/// # arch::amd64::Amd64,
/// # driver::VmiRead,
/// # os::windows::WindowsOs,
/// # utils::resolver::resolve_kernel_module,
/// # };
/// #
/// # fn example<Driver>(
/// # vmi: &VmiState<WindowsOs<Driver>>,
/// # isr: &IsrCache,
/// # ) -> Result<(), Box<dyn std::error::Error>>
/// # where
/// # Driver: VmiRead<Architecture = Amd64>,
/// # {
/// resolve_kernel_module(vmi, isr, "ntoskrnl.exe")?;
/// resolve_kernel_module(vmi, isr, "netio.sys")?;
/// # Ok(())
/// # }
/// ```
///
/// [`DebugSignature`]: OsAdapter::DebugSignature
/// [`CodeView`]: isr_cache::CodeView
/// Resolves a user module by name in the first process matching
/// `process` predicate and extracts its [`DebugSignature`].
///
/// # Platform-specific
///
/// **Windows** tries two strategies in order:
///
/// - **VAD**:
/// - Locates the module's VAD region.
/// - Reads the [`CodeView`] from it.
///
/// - **PEB**:
/// - Walks `PEB.Ldr.InLoadOrderModuleList` to find the matching
/// `_LDR_DATA_TABLE_ENTRY`.
/// - Builds an "image signature" from its `TimeDateStamp` and `SizeOfImage`.
/// - Downloads the PE from the Microsoft symbol server via [`IsrCache`].
/// - Extracts the [`CodeView`] from it.
///
/// If both strategies fail (e.g. VAD and PEB are paged out), the module
/// is considered not found and `Ok(None)` is returned.
///
/// # Notes
///
/// Use [`AnyProcess`] to resolve the module from any process that loads it.
///
/// # Examples
///
/// ```no_run
/// # use isr_cache::IsrCache;
/// # use vmi::{
/// # VmiState,
/// # arch::amd64::Amd64,
/// # driver::VmiRead,
/// # os::{
/// # AnyProcess, ProcessId, VmiOsProcess as _,
/// # windows::{WindowsOs, WindowsProcess},
/// # },
/// # utils::resolver::resolve_user_module,
/// # };
/// #
/// # fn example<Driver>(
/// # vmi: &VmiState<WindowsOs<Driver>>,
/// # isr: &IsrCache,
/// # ) -> Result<(), Box<dyn std::error::Error>>
/// # where
/// # Driver: VmiRead<Architecture = Amd64>,
/// # {
/// resolve_user_module(vmi, isr, "ncrypt.dll", "lsass.exe")?;
/// resolve_user_module(vmi, isr, "ncrypt.dll", ProcessId(1234))?;
/// resolve_user_module(vmi, isr, "ncrypt.dll", AnyProcess)?;
/// resolve_user_module(vmi, isr, "ncrypt.dll", |process: &WindowsProcess<_>| {
/// // Match "lsass.exe" in SessionId 0.
/// Ok(
/// matches!(process.session()?, Some(session) if session.id()? == 0)
/// && process.name()?.eq_ignore_ascii_case("lsass.exe"),
/// )
/// })?;
/// # Ok(())
/// # }
/// ```
///
/// [`DebugSignature`]: OsAdapter::DebugSignature
/// [`CodeView`]: isr_cache::CodeView
/// [`AnyProcess`]: vmi_core::os::AnyProcess