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 94-100)
65fn main() -> Result<(), Error> {
66 let session = common::create_vmi_session()?;
67
68 let explorer_pid = {
69 // This block is used to drop the pause guard after the PID is found.
70 // If the `session.handle()` would be called with the VM paused, no
71 // events would be triggered.
72 let paused = session.pause_guard()?;
73
74 let vmi = paused.state();
75
76 let explorer = match vmi.os().find_process("explorer.exe")? {
77 Some(explorer) => explorer,
78 None => {
79 tracing::error!("explorer.exe not found");
80 return Ok(());
81 }
82 };
83
84 tracing::info!(
85 pid = %explorer.id()?,
86 object = %explorer.object()?,
87 "found explorer.exe"
88 );
89
90 explorer.id()?
91 };
92
93 session.handle(|session| {
94 UserInjectorHandler::new(
95 session,
96 recipe_factory(MessageBox::new(
97 "Hello, World!",
98 "This is a message box from the VMI!",
99 )),
100 )?
101 .with_pid(explorer_pid)
102 })?;
103
104 Ok(())
105}More examples
examples/windows-recipe-writefile.rs (lines 234-240)
205fn main() -> Result<(), Error> {
206 let session = common::create_vmi_session()?;
207
208 let explorer_pid = {
209 // This block is used to drop the pause guard after the PID is found.
210 // If the `session.handle()` would be called with the VM paused, no
211 // events would be triggered.
212 let paused = session.pause_guard()?;
213
214 let vmi = paused.state();
215
216 let explorer = match vmi.os().find_process("explorer.exe")? {
217 Some(explorer) => explorer,
218 None => {
219 tracing::error!("explorer.exe not found");
220 return Ok(());
221 }
222 };
223
224 tracing::info!(
225 pid = %explorer.id()?,
226 object = %explorer.object()?,
227 "found explorer.exe"
228 );
229
230 explorer.id()?
231 };
232
233 session.handle(|session| {
234 UserInjectorHandler::new(
235 session,
236 recipe_factory(GuestFile::new(
237 "C:\\Users\\John\\Desktop\\test.txt",
238 "Hello, World!".as_bytes(),
239 )),
240 )?
241 .with_pid(explorer_pid)
242 })?;
243
244 Ok(())
245}examples/windows-recipe-writefile-advanced.rs (lines 337-343)
303fn main() -> Result<(), Error> {
304 let session = common::create_vmi_session()?;
305
306 let explorer_pid = {
307 // This block is used to drop the pause guard after the PID is found.
308 // If the `session.handle()` would be called with the VM paused, no
309 // events would be triggered.
310 let paused = session.pause_guard()?;
311
312 let vmi = paused.state();
313
314 let explorer = match vmi.os().find_process("explorer.exe")? {
315 Some(explorer) => explorer,
316 None => {
317 tracing::error!("explorer.exe not found");
318 return Ok(());
319 }
320 };
321
322 tracing::info!(
323 pid = %explorer.id()?,
324 object = %explorer.object()?,
325 "found explorer.exe"
326 );
327
328 explorer.id()?
329 };
330
331 let mut content = Vec::new();
332 for c in 'A'..='Z' {
333 content.extend((0..2049).map(|_| c as u8).collect::<Vec<_>>());
334 }
335
336 session.handle(|session| {
337 UserInjectorHandler::new(
338 session,
339 recipe_factory(GuestFile::new(
340 "C:\\Users\\John\\Desktop\\test.txt",
341 content,
342 )),
343 )?
344 .with_pid(explorer_pid)
345 })?;
346
347 Ok(())
348}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 101)
65fn main() -> Result<(), Error> {
66 let session = common::create_vmi_session()?;
67
68 let explorer_pid = {
69 // This block is used to drop the pause guard after the PID is found.
70 // If the `session.handle()` would be called with the VM paused, no
71 // events would be triggered.
72 let paused = session.pause_guard()?;
73
74 let vmi = paused.state();
75
76 let explorer = match vmi.os().find_process("explorer.exe")? {
77 Some(explorer) => explorer,
78 None => {
79 tracing::error!("explorer.exe not found");
80 return Ok(());
81 }
82 };
83
84 tracing::info!(
85 pid = %explorer.id()?,
86 object = %explorer.object()?,
87 "found explorer.exe"
88 );
89
90 explorer.id()?
91 };
92
93 session.handle(|session| {
94 UserInjectorHandler::new(
95 session,
96 recipe_factory(MessageBox::new(
97 "Hello, World!",
98 "This is a message box from the VMI!",
99 )),
100 )?
101 .with_pid(explorer_pid)
102 })?;
103
104 Ok(())
105}More examples
examples/windows-recipe-writefile.rs (line 241)
205fn main() -> Result<(), Error> {
206 let session = common::create_vmi_session()?;
207
208 let explorer_pid = {
209 // This block is used to drop the pause guard after the PID is found.
210 // If the `session.handle()` would be called with the VM paused, no
211 // events would be triggered.
212 let paused = session.pause_guard()?;
213
214 let vmi = paused.state();
215
216 let explorer = match vmi.os().find_process("explorer.exe")? {
217 Some(explorer) => explorer,
218 None => {
219 tracing::error!("explorer.exe not found");
220 return Ok(());
221 }
222 };
223
224 tracing::info!(
225 pid = %explorer.id()?,
226 object = %explorer.object()?,
227 "found explorer.exe"
228 );
229
230 explorer.id()?
231 };
232
233 session.handle(|session| {
234 UserInjectorHandler::new(
235 session,
236 recipe_factory(GuestFile::new(
237 "C:\\Users\\John\\Desktop\\test.txt",
238 "Hello, World!".as_bytes(),
239 )),
240 )?
241 .with_pid(explorer_pid)
242 })?;
243
244 Ok(())
245}examples/windows-recipe-writefile-advanced.rs (line 344)
303fn main() -> Result<(), Error> {
304 let session = common::create_vmi_session()?;
305
306 let explorer_pid = {
307 // This block is used to drop the pause guard after the PID is found.
308 // If the `session.handle()` would be called with the VM paused, no
309 // events would be triggered.
310 let paused = session.pause_guard()?;
311
312 let vmi = paused.state();
313
314 let explorer = match vmi.os().find_process("explorer.exe")? {
315 Some(explorer) => explorer,
316 None => {
317 tracing::error!("explorer.exe not found");
318 return Ok(());
319 }
320 };
321
322 tracing::info!(
323 pid = %explorer.id()?,
324 object = %explorer.object()?,
325 "found explorer.exe"
326 );
327
328 explorer.id()?
329 };
330
331 let mut content = Vec::new();
332 for c in 'A'..='Z' {
333 content.extend((0..2049).map(|_| c as u8).collect::<Vec<_>>());
334 }
335
336 session.handle(|session| {
337 UserInjectorHandler::new(
338 session,
339 recipe_factory(GuestFile::new(
340 "C:\\Users\\John\\Desktop\\test.txt",
341 content,
342 )),
343 )?
344 .with_pid(explorer_pid)
345 })?;
346
347 Ok(())
348}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>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: Freeze,
PhantomData<(Os, Mode, T, Bridge)>: Freeze,
impl<Os, Mode, T, Bridge> RefUnwindSafe for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: RefUnwindSafe,
PhantomData<(Os, Mode, T, Bridge)>: RefUnwindSafe,
impl<Os, Mode, T, Bridge> Send for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: Send,
PhantomData<(Os, Mode, T, Bridge)>: Send,
impl<Os, Mode, T, Bridge> Sync for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: Sync,
PhantomData<(Os, Mode, T, Bridge)>: Sync,
impl<Os, Mode, T, Bridge> Unpin for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: Unpin,
PhantomData<(Os, Mode, T, Bridge)>: Unpin,
impl<Os, Mode, T, Bridge> UnsafeUnpin for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: UnsafeUnpin,
PhantomData<(Os, Mode, T, Bridge)>: UnsafeUnpin,
impl<Os, Mode, T, Bridge> UnwindSafe for InjectorHandler<Os, Mode, T, Bridge>where
<Os as InjectorExecutionAdapter<Mode, T, Bridge>>::Handler: UnwindSafe,
PhantomData<(Os, Mode, T, 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.