pub struct Injection { /* private fields */ }Expand description
A code injection, and the RAII guard that owns it.
Reaching the target runs the injected work, then the displaced original
instructions, then the rest of the original code. The work is machine code
(code, asm) or a
register-context callback (inspect,
modify). Build one with Injection::at.
§Threads, batches and dropping
These work as for Hook: patching suspends other threads,
batch queues changes, and dropping reverts the patch and
frees the stub and callback, or leaks them if the patch can’t be reverted.
A callback may run on several threads at once, each with its own
Context, so keep its own state in atomics or locks.
Implementations§
Source§impl Injection
impl Injection
Sourcepub fn at(target: *const ()) -> InjectionBuilder
pub fn at(target: *const ()) -> InjectionBuilder
Starts building an injection at target.
Nothing is patched until install.
Sourcepub fn scan(pattern: &str) -> InjectionScan
pub fn scan(pattern: &str) -> InjectionScan
Sourcepub fn enable(&self) -> Result<()>
pub fn enable(&self) -> Result<()>
Enables the injection.
Does nothing if already enabled. Suspends other threads while patching;
see Injection for threads and batches.
§Errors
Returns an error naming the target if patching fails, such as
Error::TargetModified when a third party changed its code.
Sourcepub unsafe fn enable_unsuspended(&self) -> Result<()>
pub unsafe fn enable_unsuspended(&self) -> Result<()>
Sourcepub unsafe fn disable_unsuspended(&self) -> Result<()>
pub unsafe fn disable_unsuspended(&self) -> Result<()>
Disables the injection without suspending other threads.
Applied at once like enable_unsuspended.
§Errors
As for enable.
§Safety
No other thread may run the target’s first bytes while the original ones are written back.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns whether the injection is enabled.