add cmplog_runtime as feature

This commit is contained in:
Omree 2021-06-09 12:01:39 +03:00
parent 5de4c9305e
commit 6f98bbe6cf
4 changed files with 18 additions and 6 deletions

View File

@ -24,7 +24,7 @@ which = "4.1"
libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public" ] } #, "llmp_small_maps", "llmp_debug"]} libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public" ] } #, "llmp_small_maps", "llmp_debug"]}
capstone = "0.8.0" capstone = "0.8.0"
frida-gum = { version = "0.5.2", features = [ "auto-download", "backtrace", "event-sink", "invocation-listener"] } frida-gum = { version = "0.5.2", features = [ "auto-download", "backtrace", "event-sink", "invocation-listener"] }
libafl_frida = { path = "../../libafl_frida", version = "0.3.2" } libafl_frida = { path = "../../libafl_frida", version = "0.3.2", features = ["cmplog_runtime"] }
libafl_targets = { path = "../../libafl_targets", version = "0.3.2" , features = ["sancov_cmplog"] } libafl_targets = { path = "../../libafl_targets", version = "0.3.2" , features = ["sancov_cmplog"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
libc = "0.2" libc = "0.2"

View File

@ -10,6 +10,11 @@ license = "MIT OR Apache-2.0"
keywords = ["fuzzing", "frida", "instrumentation"] keywords = ["fuzzing", "frida", "instrumentation"]
edition = "2018" edition = "2018"
[features]
default = []
cmplog_runtime = []
[build-dependencies] [build-dependencies]
cc = { version = "1.0", features = ["parallel"] } cc = { version = "1.0", features = ["parallel"] }

View File

@ -33,8 +33,12 @@ use rangemap::RangeMap;
use nix::sys::mman::{mmap, MapFlags, ProtFlags}; use nix::sys::mman::{mmap, MapFlags, ProtFlags};
use crate::{asan_rt::AsanRuntime, cmplog_rt::CmpLogRuntime, FridaOptions}; use crate::{asan_rt::AsanRuntime, FridaOptions};
#[cfg(feature = "cmplog_runtime")]
use crate::cmplog_rt::CmpLogRuntime;
#[cfg(feature = "cmplog_runtime")]
enum CmplogOperandType { enum CmplogOperandType {
Regid(capstone::RegId), Regid(capstone::RegId),
Imm(u64), Imm(u64),
@ -85,6 +89,7 @@ pub struct FridaInstrumentationHelper<'a> {
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
capstone: Capstone, capstone: Capstone,
asan_runtime: AsanRuntime, asan_runtime: AsanRuntime,
#[cfg(all(feature = "cmplog_runtime"))]
cmplog_runtime: CmpLogRuntime, cmplog_runtime: CmpLogRuntime,
ranges: RangeMap<usize, (u16, String)>, ranges: RangeMap<usize, (u16, String)>,
module_map: ModuleMap, module_map: ModuleMap,
@ -271,6 +276,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
.build() .build()
.expect("Failed to create Capstone object"), .expect("Failed to create Capstone object"),
asan_runtime: AsanRuntime::new(options.clone()), asan_runtime: AsanRuntime::new(options.clone()),
#[cfg(all(feature = "cmplog_runtime"))]
cmplog_runtime: CmpLogRuntime::new(), cmplog_runtime: CmpLogRuntime::new(),
ranges: RangeMap::new(), ranges: RangeMap::new(),
module_map: ModuleMap::new_from_names(modules_to_instrument), module_map: ModuleMap::new_from_names(modules_to_instrument),
@ -348,11 +354,10 @@ impl<'a> FridaInstrumentationHelper<'a> {
); );
} }
} }
if helper.options().cmplog_enabled() { if helper.options().cmplog_enabled() {
#[cfg(not(target_arch = "aarch64"))] #[cfg(not(target_arch = "aarch64"))]
todo!("Implement cmplog for non-aarch64 targets"); todo!("Implement cmplog for non-aarch64 targets");
#[cfg(target_arch = "aarch64")] #[cfg(all(feature = "cmplog_runtime", target_arch = "aarch64"))]
// check if this instruction is a compare instruction and if so save the registers values // check if this instruction is a compare instruction and if so save the registers values
if let Ok((op1, op2)) = if let Ok((op1, op2)) =
helper.is_interesting_cmplog_instruction(address, instr) helper.is_interesting_cmplog_instruction(address, instr)
@ -377,6 +382,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
if helper.options().asan_enabled() || helper.options().drcov_enabled() { if helper.options().asan_enabled() || helper.options().drcov_enabled() {
helper.asan_runtime.init(gum, modules_to_instrument); helper.asan_runtime.init(gum, modules_to_instrument);
} }
#[cfg(all(feature = "cmplog_runtime"))]
if helper.options.cmplog_enabled() { if helper.options.cmplog_enabled() {
helper.cmplog_runtime.init(); helper.cmplog_runtime.init();
} }
@ -395,7 +401,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
Aarch64Register::from_u32(regint as u32).unwrap() Aarch64Register::from_u32(regint as u32).unwrap()
} }
#[cfg(target_arch = "aarch64")] #[cfg(all(feature = "cmplog_runtime", target_arch = "aarch64"))]
#[inline] #[inline]
fn emit_comparison_handling( fn emit_comparison_handling(
&self, &self,
@ -1027,7 +1033,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
Err(()) Err(())
} }
#[cfg(target_arch = "aarch64")] #[cfg(all(feature = "cmplog_runtime", target_arch = "aarch64"))]
#[inline] #[inline]
fn is_interesting_cmplog_instruction( fn is_interesting_cmplog_instruction(
&self, &self,

View File

@ -10,6 +10,7 @@ pub mod asan_errors;
/// The frida address sanitizer runtime /// The frida address sanitizer runtime
pub mod asan_rt; pub mod asan_rt;
#[cfg(all(feature = "cmplog_runtime"))]
/// The frida cmplog runtime /// The frida cmplog runtime
pub mod cmplog_rt; pub mod cmplog_rt;