Skip to main content

cradle_hooks/
breakpoints.rs

1use crate::defs::HookHandler;
2use std::collections::HashMap;
3
4/// A breakpoint object
5/// Contains information about the hooked function, and the hooking function
6pub struct Breakpoint {
7    /// Original byte of the breakpoint. Used to restore the process after removal of the breakpoint
8    pub original_byte: u8,
9    /// Hook handler functions. When the breakpoint is called, these are executed in registration order
10    pub handlers: Vec<HookHandler>,
11    /// Hooked function module name
12    pub module_name: String,
13    /// Hooked function export name
14    pub export_name: String,
15}
16
17impl Breakpoint {
18    /// Creates a new breakpoint
19    pub fn new(original_byte: u8, handler: HookHandler, module: String, export: String) -> Self {
20        Self {
21            original_byte,
22            handlers: vec![handler],
23            module_name: module,
24            export_name: export,
25        }
26    }
27
28    /// Adds a handler to an existing breakpoint
29    pub fn push_handler(&mut self, handler: HookHandler) {
30        self.handlers.push(handler);
31    }
32}
33
34/// Small helper type
35pub type BreakpointMap = HashMap<usize, Breakpoint>;
36/// Small helper type
37pub type ModuleBaseCache = HashMap<String, usize>;