Skip to main content

Module hook

Module hook 

Source
Expand description

Hooks as rewrites of the lifted code.

A Hook names the sites in a block it cares about — the block’s entry, a guest address, every store to guest memory, every comparison — and, for each, emits QCode through an Emitter. What it emits is ordinary IR: a VM_INTERRUPT where the host must act, arithmetic to decide whether it must, loads and stores that count. The interpreter and the JIT run the result like any other code, so a hook whose condition is false costs a few native instructions and never leaves compiled code.

The two ways to stop:

  • Emitter::interrupt places an unconditional interrupt before the site.
  • Emitter::interrupt_if places the interrupt on a detour: the block is split before the site, and a conditional branch chooses between a small block holding the interrupt and the rest of the code. Only the condition is evaluated on the fast path.

Both pass values to the host — literals, or anything the block computes, such as the address and datum of a store — which the exit reports as the interrupt’s arguments.

HookInjector adapts a hook to the CodeInjector the machine runs, and handles idempotence: a site is instrumented once, remembered by its anchor instruction, which survives absorption and disappears with a re-lift.

Structs§

AddressHook
Stops before the guest instruction at each of a set of addresses, with vm.interrupt(code, address).
BlockEntryHook
Stops at the entry of every block whose address lies in a range, with vm.interrupt(code, address).
BlockView
A read-only look at a block, for choosing sites.
CompareHook
Stops before every integer comparison with vm.interrupt(code, lhs, rhs): the operands as the guest computed them, which is what a comparison logger for a fuzzer wants.
Emitter
Emits QCode before a site’s anchor, on the hook’s behalf.
HookInjector
Runs a Hook as the machine’s CodeInjector, instrumenting each site once.
WriteWatch
Stops before every store to guest memory whose address lies in begin..=end, with vm.interrupt(code, address, size, value).

Enums§

Site
A point in a block a hook may instrument. Every site is anchored to the instruction it precedes, which is where the hook’s code is inserted.

Traits§

Hook
A rewrite of lifted code at chosen sites. See the module docs.

Functions§

is_interrupt_op
Whether insn is a VM_INTERRUPT op.