Skip to main content

register_architecture_hook

Function register_architecture_hook 

Source
pub fn register_architecture_hook<H: ArchitectureHook>(
    base: CoreArchitecture,
    hook: H,
) -> &'static H
Expand description

Installs a hook on base, affecting all existing users of that architecture.

Hooks run in reverse registration order. Each callback receives the previous implementation, which can be called to delegate without recursion. The hook is retained for the lifetime of the core and cannot be unregistered. The returned reference can be used to access its state.

Like register_architecture, call this during CorePluginInit, after the base architecture is registered and before analysis starts.

use binaryninja::architecture::{
    register_architecture_hook, Architecture, ArchitectureHook, CoreArchitecture,
};
use binaryninja::disassembly::{InstructionTextToken, InstructionTextTokenKind};

struct Annotate;
impl ArchitectureHook for Annotate {
    fn instruction_text(
        &self, base: &CoreArchitecture, data: &[u8], addr: u64,
    ) -> Option<(usize, Vec<InstructionTextToken>)> {
        let (length, mut tokens) = base.instruction_text(data, addr)?;
        tokens.push(InstructionTextToken::new(" ; hooked", InstructionTextTokenKind::Annotation));
        Some((length, tokens))
    }
}
register_architecture_hook(CoreArchitecture::by_name("x86_64").unwrap(), Annotate);