vmi_os_windows/arch/
mod.rs1mod amd64;
2mod context;
3
4use vmi_core::{AccessContext, Architecture, Va, VmiCore, VmiError, VmiState, driver::VmiRead};
5
6pub use self::{
7 amd64::{WindowsExceptionVector, WindowsInterrupt, WindowsPageTableEntry},
8 context::{
9 CONTEXT_AMD64, CONTEXT_X86, FLOATING_SAVE_AREA, KDESCRIPTOR_AMD64, KDESCRIPTOR_X86,
10 KSPECIAL_REGISTERS_AMD64, KSPECIAL_REGISTERS_X86, M128A, MAXIMUM_SUPPORTED_EXTENSION,
11 SIZE_OF_80387_REGISTERS, WindowsContext, WindowsRegistersAdapter, WindowsSpecialRegisters,
12 XSAVE_FORMAT,
13 },
14};
15use crate::{WindowsKernelInformation, WindowsOs, WindowsOsExt};
16
17pub trait ArchAdapter<Driver>: Architecture
19where
20 Driver: VmiRead<Architecture = Self>,
21{
22 fn syscall_argument(vmi: VmiState<WindowsOs<Driver>>, index: u64) -> Result<u64, VmiError>;
31
32 fn function_argument(vmi: VmiState<WindowsOs<Driver>>, index: u64) -> Result<u64, VmiError>;
42
43 fn function_return_value(vmi: VmiState<WindowsOs<Driver>>) -> Result<u64, VmiError>;
49
50 fn find_kernel(
60 vmi: &VmiCore<Driver>,
61 registers: &<Driver::Architecture as Architecture>::Registers,
62 ) -> Result<Option<WindowsKernelInformation>, VmiError>;
63
64 fn kernel_image_base(vmi: VmiState<WindowsOs<Driver>>) -> Result<Va, VmiError>;
71
72 fn is_page_present_or_transition(
76 vmi: VmiState<WindowsOs<Driver>>,
77 address: Va,
78 ) -> Result<bool, VmiError>;
79
80 fn current_kpcr(vmi: VmiState<WindowsOs<Driver>>) -> Va;
83}
84
85pub trait StructLayout {
92 const ADDRESS_WIDTH: u64;
94
95 fn read_va<Driver>(
97 vmi: VmiState<WindowsOs<Driver>>,
98 ctx: impl Into<AccessContext>,
99 ) -> Result<Va, VmiError>
100 where
101 Driver: VmiRead,
102 Driver::Architecture: ArchAdapter<Driver>;
103
104 fn read_unicode_string<Driver>(
106 vmi: VmiState<WindowsOs<Driver>>,
107 ctx: impl Into<AccessContext>,
108 ) -> Result<String, VmiError>
109 where
110 Driver: VmiRead,
111 Driver::Architecture: ArchAdapter<Driver>;
112}
113
114pub struct StructLayout32;
116
117impl StructLayout for StructLayout32 {
118 const ADDRESS_WIDTH: u64 = 4;
119
120 fn read_va<Driver>(
121 vmi: VmiState<WindowsOs<Driver>>,
122 ctx: impl Into<AccessContext>,
123 ) -> Result<Va, VmiError>
124 where
125 Driver: VmiRead,
126 Driver::Architecture: ArchAdapter<Driver>,
127 {
128 vmi.core().read_va32(ctx)
129 }
130
131 fn read_unicode_string<Driver>(
132 vmi: VmiState<WindowsOs<Driver>>,
133 ctx: impl Into<AccessContext>,
134 ) -> Result<String, VmiError>
135 where
136 Driver: VmiRead,
137 Driver::Architecture: ArchAdapter<Driver>,
138 {
139 vmi.os().read_unicode_string32_in(ctx)
140 }
141}
142
143pub struct StructLayout64;
145
146impl StructLayout for StructLayout64 {
147 const ADDRESS_WIDTH: u64 = 8;
148
149 fn read_va<Driver>(
150 vmi: VmiState<WindowsOs<Driver>>,
151 ctx: impl Into<AccessContext>,
152 ) -> Result<Va, VmiError>
153 where
154 Driver: VmiRead,
155 Driver::Architecture: ArchAdapter<Driver>,
156 {
157 vmi.core().read_va64(ctx)
158 }
159
160 fn read_unicode_string<Driver>(
161 vmi: VmiState<WindowsOs<Driver>>,
162 ctx: impl Into<AccessContext>,
163 ) -> Result<String, VmiError>
164 where
165 Driver: VmiRead,
166 Driver::Architecture: ArchAdapter<Driver>,
167 {
168 vmi.os().read_unicode_string64_in(ctx)
169 }
170}