Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/libafl_qemu/src/modules/calls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::{cell::UnsafeCell, fmt::Debug};
use hashbrown::HashSet;

use capstone::prelude::*;
use libafl::{
Expand Down Expand Up @@ -235,6 +236,8 @@ where
filter: StdAddressFilter,
cs: Capstone,
collectors: Option<T>,
registered_call_addrs: HashSet<GuestAddr>,
registered_ret_addrs: HashSet<GuestAddr>,
}

impl<T> CallTracerModule<T>
Expand All @@ -247,6 +250,8 @@ where
filter,
cs: capstone().detail(true).build().unwrap(),
collectors: Some(collectors),
registered_call_addrs: HashSet::new(),
registered_ret_addrs: HashSet::new(),
}
}

Expand Down Expand Up @@ -379,6 +384,14 @@ where
}

for (call_addr, call_len) in call_addrs {
// Skip registration if we already have a hook at this address.
if !emulator_modules
.get_mut::<Self>()
.is_none_or(|h| h.registered_call_addrs.insert(call_addr))
{
continue;
}

// TODO do not use a closure, find a more efficient way to pass call_len
let call_cb = Box::new(
move |_qemu: Qemu,
Expand All @@ -405,6 +418,13 @@ where
}

for ret_addr in ret_addrs {
// Skip registration if we already have a hook at this address.
if !emulator_modules
.get_mut::<Self>()
.is_none_or(|h| h.registered_ret_addrs.insert(ret_addr))
{
continue;
}
emulator_modules.instruction_function(ret_addr, Self::on_ret, false);
}

Expand Down
Loading