closures/
closures.rs

1use panda::plugins::proc_start_linux::ProcStartLinuxCallbacks;
2use panda::prelude::*;
3use panda::{Callback, PppCallback};
4
5fn main() {
6    // Callbacks can capture state
7    let mut count = 1;
8    let bb_callback = Callback::new();
9    bb_callback.before_block_exec(move |cpu, _| {
10        println!("Block: {} | PC: {:#x?}", count, panda::regs::get_pc(cpu));
11        count += 1;
12        if count > 5 {
13            // callbacks can disable themselves by capturing a copy
14            // of the `Callback` reference to it
15            bb_callback.disable();
16        }
17    });
18
19    // If you don't need to enable and disable the callback, you can just
20    // use method chaining instead of assigning to a variable
21    PppCallback::new().on_rec_auxv(|_, _, auxv| {
22        // print out the auxillary vector when any process starts
23        dbg!(auxv);
24    });
25
26    Panda::new().generic("x86_64").replay("test").run();
27}