Struct HookManager
pub struct HookManager { /* private fields */ }Expand description
Manager for registering and executing hooks.
The HookManager maintains a collection of hooks sorted by priority (highest
first). When a method call is intercepted, the manager finds the first matching
hook and executes its handlers.
§Hook Resolution
When looking for a matching hook:
- Hooks are checked in priority order (highest first)
- The first hook whose matchers all match is selected
- Only one hook is executed per method call
§Examples
ⓘ
use dotscope::emulation::{HookManager, Hook, HookPriority, PreHookResult, EmValue};
let mut manager = HookManager::new();
// Register hooks (order doesn't matter, they're sorted by priority)
manager.register(
Hook::new("low-priority")
.with_priority(HookPriority::LOW)
.match_method_name("Decrypt")
.pre(|ctx, thread| PreHookResult::Continue)
);
manager.register(
Hook::new("high-priority")
.with_priority(HookPriority::HIGH)
.match_method_name("Decrypt")
.pre(|ctx, thread| PreHookResult::Bypass(Some(EmValue::I32(42))))
);
// When "Decrypt" is called, "high-priority" matches firstImplementations§
§impl HookManager
impl HookManager
pub fn new() -> Self
pub fn new() -> Self
Creates a new, empty hook manager.
pub fn find_matching<'a>(
&'a self,
context: &HookContext<'_>,
thread: &EmulationThread,
) -> Option<&'a Hook>
pub fn find_matching<'a>( &'a self, context: &HookContext<'_>, thread: &EmulationThread, ) -> Option<&'a Hook>
Finds the first matching hook for the given context.
Hooks are checked in priority order (highest first). The first hook whose matchers all match is returned.
§Arguments
context- The hook context containing method call informationthread- The emulation thread for runtime data inspection
§Returns
The first matching hook, or None if no hook matches.
pub fn execute<F>(
&self,
context: &HookContext<'_>,
thread: &mut EmulationThread,
execute_original: F,
) -> Result<HookOutcome>
pub fn execute<F>( &self, context: &HookContext<'_>, thread: &mut EmulationThread, execute_original: F, ) -> Result<HookOutcome>
Executes a method call through the hook system.
This is the primary entry point for hook execution. It handles the complete hook lifecycle:
- Find a matching hook (by priority order)
- Execute the pre-hook
- If pre-hook returns
Continue, execute the original method via callback - Execute the post-hook on the result
- Return the final outcome
§Arguments
context- The hook context containing method call informationthread- The emulation threadexecute_original- Callback to execute the original method. Only called if a hook matches and returnsContinue.
§Returns
Ok(HookOutcome::NoMatch)- No hook matched; caller should execute normallyOk(HookOutcome::Handled(value))- Hook handled the call; use this resultErr(...)- Hook execution failed
§Errors
Returns an error if a pre-hook or post-hook returns Error.
§Examples
ⓘ
use dotscope::emulation::{HookContext, HookOutcome};
let context = HookContext::new(
method_token,
"System", "String", "Concat",
);
let outcome = manager.execute(&context, &mut thread, |thread| {
// Execute the original method
Some(EmValue::String(...))
})?;
match outcome {
HookOutcome::NoMatch => { /* execute normally */ }
HookOutcome::Handled(value) => { /* use value */ }
}Trait Implementations§
§impl Debug for HookManager
impl Debug for HookManager
§impl Default for HookManager
impl Default for HookManager
§fn default() -> HookManager
fn default() -> HookManager
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for HookManager
impl !RefUnwindSafe for HookManager
impl Send for HookManager
impl Sync for HookManager
impl Unpin for HookManager
impl !UnwindSafe for HookManager
Blanket Implementations§
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more