pub struct InjectorHandler<Os, Mode, T, Bridge = ()>where
Os: InjectorExecutionAdapter<Mode, T, Bridge>,
Mode: ExecutionMode,
Bridge: BridgeDispatch<Os, u64>,{ /* private fields */ }Available on crate features
injector and utils only.Expand description
Generic injector handler that delegates to an OS- and mode-specific implementation.
Prefer the KernelInjectorHandler and UserInjectorHandler type
aliases for the common case without a bridge. When a custom
BridgeDispatch is needed, use this type directly with an explicit
Bridge parameter.
Implementations§
Source§impl<Os, Mode, T, Bridge> InjectorHandler<Os, Mode, T, Bridge>where
Os: InjectorExecutionAdapter<Mode, T, Bridge>,
Mode: ExecutionMode,
Bridge: BridgeDispatch<Os, u64>,
impl<Os, Mode, T, Bridge> InjectorHandler<Os, Mode, T, Bridge>where
Os: InjectorExecutionAdapter<Mode, T, Bridge>,
Mode: ExecutionMode,
Bridge: BridgeDispatch<Os, u64>,
Sourcepub fn new(
vmi: &VmiSession<'_, Os>,
recipe: Recipe<Os, T>,
) -> Result<InjectorHandler<Os, Mode, T, Bridge>, VmiError>where
Bridge: Default,
pub fn new(
vmi: &VmiSession<'_, Os>,
recipe: Recipe<Os, T>,
) -> Result<InjectorHandler<Os, Mode, T, Bridge>, VmiError>where
Bridge: Default,
Creates a new injector handler with a default (no-op) bridge.
Examples found in repository?
examples/windows-recipe-messagebox.rs (lines 93-99)
64fn main() -> Result<(), Box<dyn std::error::Error>> {
65 let (session, _profile) = common::create_vmi_session()?;
66
67 let explorer_pid = {
68 // This block is used to drop the pause guard after the PID is found.
69 // If the `session.handle()` would be called with the VM paused, no
70 // events would be triggered.
71 let paused = session.pause_guard()?;
72
73 let vmi = paused.state();
74
75 let explorer = match common::find_process(&vmi, "explorer.exe")? {
76 Some(explorer) => explorer,
77 None => {
78 tracing::error!("explorer.exe not found");
79 return Ok(());
80 }
81 };
82
83 tracing::info!(
84 pid = %explorer.id()?,
85 object = %explorer.object()?,
86 "found explorer.exe"
87 );
88
89 explorer.id()?
90 };
91
92 session.handle(|session| {
93 UserInjectorHandler::new(
94 session,
95 recipe_factory(MessageBox::new(
96 "Hello, World!",
97 "This is a message box from the VMI!",
98 )),
99 )?
100 .with_pid(explorer_pid)
101 })?;
102
103 Ok(())
104}More examples
examples/windows-recipe-writefile.rs (lines 233-239)
204fn main() -> Result<(), Box<dyn std::error::Error>> {
205 let (session, _profile) = common::create_vmi_session()?;
206
207 let explorer_pid = {
208 // This block is used to drop the pause guard after the PID is found.
209 // If the `session.handle()` would be called with the VM paused, no
210 // events would be triggered.
211 let paused = session.pause_guard()?;
212
213 let vmi = paused.state();
214
215 let explorer = match common::find_process(&vmi, "explorer.exe")? {
216 Some(explorer) => explorer,
217 None => {
218 tracing::error!("explorer.exe not found");
219 return Ok(());
220 }
221 };
222
223 tracing::info!(
224 pid = %explorer.id()?,
225 object = %explorer.object()?,
226 "found explorer.exe"
227 );
228
229 explorer.id()?
230 };
231
232 session.handle(|session| {
233 UserInjectorHandler::new(
234 session,
235 recipe_factory(GuestFile::new(
236 "C:\\Users\\John\\Desktop\\test.txt",
237 "Hello, World!".as_bytes(),
238 )),
239 )?
240 .with_pid(explorer_pid)
241 })?;
242
243 Ok(())
244}examples/windows-recipe-writefile-advanced.rs (lines 336-342)
302fn main() -> Result<(), Box<dyn std::error::Error>> {
303 let (session, _profile) = common::create_vmi_session()?;
304
305 let explorer_pid = {
306 // This block is used to drop the pause guard after the PID is found.
307 // If the `session.handle()` would be called with the VM paused, no
308 // events would be triggered.
309 let paused = session.pause_guard()?;
310
311 let vmi = paused.state();
312
313 let explorer = match common::find_process(&vmi, "explorer.exe")? {
314 Some(explorer) => explorer,
315 None => {
316 tracing::error!("explorer.exe not found");
317 return Ok(());
318 }
319 };
320
321 tracing::info!(
322 pid = %explorer.id()?,
323 object = %explorer.object()?,
324 "found explorer.exe"
325 );
326
327 explorer.id()?
328 };
329
330 let mut content = Vec::new();
331 for c in 'A'..='Z' {
332 content.extend((0..2049).map(|_| c as u8).collect::<Vec<_>>());
333 }
334
335 session.handle(|session| {
336 UserInjectorHandler::new(
337 session,
338 recipe_factory(GuestFile::new(
339 "C:\\Users\\John\\Desktop\\test.txt",
340 content,
341 )),
342 )?
343 .with_pid(explorer_pid)
344 })?;
345
346 Ok(())
347}Sourcepub fn with_bridge(
vmi: &VmiSession<'_, Os>,
bridge: Bridge,
recipe: Recipe<Os, T>,
) -> Result<InjectorHandler<Os, Mode, T, Bridge>, VmiError>
pub fn with_bridge( vmi: &VmiSession<'_, Os>, bridge: Bridge, recipe: Recipe<Os, T>, ) -> Result<InjectorHandler<Os, Mode, T, Bridge>, VmiError>
Creates a new injector handler with a custom bridge for guest-host communication.
Sourcepub fn with_pid(
self,
pid: ProcessId,
) -> Result<InjectorHandler<Os, Mode, T, Bridge>, VmiError>
pub fn with_pid( self, pid: ProcessId, ) -> Result<InjectorHandler<Os, Mode, T, Bridge>, VmiError>
Restricts injection to a specific process.
Examples found in repository?
examples/windows-recipe-messagebox.rs (line 100)
64fn main() -> Result<(), Box<dyn std::error::Error>> {
65 let (session, _profile) = common::create_vmi_session()?;
66
67 let explorer_pid = {
68 // This block is used to drop the pause guard after the PID is found.
69 // If the `session.handle()` would be called with the VM paused, no
70 // events would be triggered.
71 let paused = session.pause_guard()?;
72
73 let vmi = paused.state();
74
75 let explorer = match common::find_process(&vmi, "explorer.exe")? {
76 Some(explorer) => explorer,
77 None => {
78 tracing::error!("explorer.exe not found");
79 return Ok(());
80 }
81 };
82
83 tracing::info!(
84 pid = %explorer.id()?,
85 object = %explorer.object()?,
86 "found explorer.exe"
87 );
88
89 explorer.id()?
90 };
91
92 session.handle(|session| {
93 UserInjectorHandler::new(
94 session,
95 recipe_factory(MessageBox::new(
96 "Hello, World!",
97 "This is a message box from the VMI!",
98 )),
99 )?
100 .with_pid(explorer_pid)
101 })?;
102
103 Ok(())
104}More examples
examples/windows-recipe-writefile.rs (line 240)
204fn main() -> Result<(), Box<dyn std::error::Error>> {
205 let (session, _profile) = common::create_vmi_session()?;
206
207 let explorer_pid = {
208 // This block is used to drop the pause guard after the PID is found.
209 // If the `session.handle()` would be called with the VM paused, no
210 // events would be triggered.
211 let paused = session.pause_guard()?;
212
213 let vmi = paused.state();
214
215 let explorer = match common::find_process(&vmi, "explorer.exe")? {
216 Some(explorer) => explorer,
217 None => {
218 tracing::error!("explorer.exe not found");
219 return Ok(());
220 }
221 };
222
223 tracing::info!(
224 pid = %explorer.id()?,
225 object = %explorer.object()?,
226 "found explorer.exe"
227 );
228
229 explorer.id()?
230 };
231
232 session.handle(|session| {
233 UserInjectorHandler::new(
234 session,
235 recipe_factory(GuestFile::new(
236 "C:\\Users\\John\\Desktop\\test.txt",
237 "Hello, World!".as_bytes(),
238 )),
239 )?
240 .with_pid(explorer_pid)
241 })?;
242
243 Ok(())
244}examples/windows-recipe-writefile-advanced.rs (line 343)
302fn main() -> Result<(), Box<dyn std::error::Error>> {
303 let (session, _profile) = common::create_vmi_session()?;
304
305 let explorer_pid = {
306 // This block is used to drop the pause guard after the PID is found.
307 // If the `session.handle()` would be called with the VM paused, no
308 // events would be triggered.
309 let paused = session.pause_guard()?;
310
311 let vmi = paused.state();
312
313 let explorer = match common::find_process(&vmi, "explorer.exe")? {
314 Some(explorer) => explorer,
315 None => {
316 tracing::error!("explorer.exe not found");
317 return Ok(());
318 }
319 };
320
321 tracing::info!(
322 pid = %explorer.id()?,
323 object = %explorer.object()?,
324 "found explorer.exe"
325 );
326
327 explorer.id()?
328 };
329
330 let mut content = Vec::new();
331 for c in 'A'..='Z' {
332 content.extend((0..2049).map(|_| c as u8).collect::<Vec<_>>());
333 }
334
335 session.handle(|session| {
336 UserInjectorHandler::new(
337 session,
338 recipe_factory(GuestFile::new(
339 "C:\\Users\\John\\Desktop\\test.txt",
340 content,
341 )),
342 )?
343 .with_pid(explorer_pid)
344 })?;
345
346 Ok(())
347}Trait Implementations§
Source§impl<Os, Mode, T, Bridge> VmiHandler<Os> for InjectorHandler<Os, Mode, T, Bridge>where
Os: InjectorExecutionAdapter<Mode, T, Bridge>,
Mode: ExecutionMode,
Bridge: BridgeDispatch<Os, u64>,
impl<Os, Mode, T, Bridge> VmiHandler<Os> for InjectorHandler<Os, Mode, T, Bridge>where
Os: InjectorExecutionAdapter<Mode, T, Bridge>,
Mode: ExecutionMode,
Bridge: BridgeDispatch<Os, u64>,
Source§type Output = <<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler as VmiHandler<Os>>::Output
type Output = <<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler as VmiHandler<Os>>::Output
The output type of the handler.
Source§fn handle_event(
&mut self,
vmi: VmiContext<'_, Os>,
) -> VmiEventResponse<<Os as VmiOs>::Architecture>
fn handle_event( &mut self, vmi: VmiContext<'_, Os>, ) -> VmiEventResponse<<Os as VmiOs>::Architecture>
Called for each VMI event. Read more
Source§fn poll(
&self,
) -> Option<<InjectorHandler<Os, Mode, T, Bridge> as VmiHandler<Os>>::Output>
fn poll( &self, ) -> Option<<InjectorHandler<Os, Mode, T, Bridge> as VmiHandler<Os>>::Output>
Checks if the handler has completed. Read more
Source§fn handle_timeout(&mut self, _session: &VmiSession<'_, Os>)
fn handle_timeout(&mut self, _session: &VmiSession<'_, Os>)
Called when the event loop times out waiting for the next event. Read more
Source§fn handle_interrupted(&mut self, _session: &VmiSession<'_, Os>)
fn handle_interrupted(&mut self, _session: &VmiSession<'_, Os>)
Called when the event loop is interrupted by a signal. Read more
Source§fn cleanup(&mut self, _session: &VmiSession<'_, Os>)
fn cleanup(&mut self, _session: &VmiSession<'_, Os>)
Called once before the session tears down monitoring. Read more
Auto Trait Implementations§
impl<Os, Mode, T, Bridge> Freeze for InjectorHandler<Os, Mode, T, Bridge>
impl<Os, Mode, T, Bridge> RefUnwindSafe for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: RefUnwindSafe,
Os: RefUnwindSafe,
Mode: RefUnwindSafe,
T: RefUnwindSafe,
Bridge: RefUnwindSafe,
impl<Os, Mode, T, Bridge> Send for InjectorHandler<Os, Mode, T, Bridge>
impl<Os, Mode, T, Bridge> Sync for InjectorHandler<Os, Mode, T, Bridge>
impl<Os, Mode, T, Bridge> Unpin for InjectorHandler<Os, Mode, T, Bridge>
impl<Os, Mode, T, Bridge> UnsafeUnpin for InjectorHandler<Os, Mode, T, Bridge>
impl<Os, Mode, T, Bridge> UnwindSafe for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: UnwindSafe,
Os: UnwindSafe,
Mode: UnwindSafe,
T: UnwindSafe,
Bridge: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.