From 6f98bbe6cf5e4a6b6c55ccb25a389a83bac5718d Mon Sep 17 00:00:00 2001 From: Omree Date: Wed, 9 Jun 2021 12:01:39 +0300 Subject: [PATCH] add cmplog_runtime as feature --- fuzzers/frida_libpng/Cargo.toml | 2 +- libafl_frida/Cargo.toml | 5 +++++ libafl_frida/src/helper.rs | 16 +++++++++++----- libafl_frida/src/lib.rs | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fuzzers/frida_libpng/Cargo.toml b/fuzzers/frida_libpng/Cargo.toml index cf4dbb83be..a411002168 100644 --- a/fuzzers/frida_libpng/Cargo.toml +++ b/fuzzers/frida_libpng/Cargo.toml @@ -24,7 +24,7 @@ which = "4.1" libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public" ] } #, "llmp_small_maps", "llmp_debug"]} capstone = "0.8.0" 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"] } lazy_static = "1.4.0" libc = "0.2" diff --git a/libafl_frida/Cargo.toml b/libafl_frida/Cargo.toml index f173c89b5b..3d4784f6b0 100644 --- a/libafl_frida/Cargo.toml +++ b/libafl_frida/Cargo.toml @@ -10,6 +10,11 @@ license = "MIT OR Apache-2.0" keywords = ["fuzzing", "frida", "instrumentation"] edition = "2018" + +[features] +default = [] +cmplog_runtime = [] + [build-dependencies] cc = { version = "1.0", features = ["parallel"] } diff --git a/libafl_frida/src/helper.rs b/libafl_frida/src/helper.rs index d3d5c00d80..f94ba4e79a 100644 --- a/libafl_frida/src/helper.rs +++ b/libafl_frida/src/helper.rs @@ -33,8 +33,12 @@ use rangemap::RangeMap; 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 { Regid(capstone::RegId), Imm(u64), @@ -85,6 +89,7 @@ pub struct FridaInstrumentationHelper<'a> { #[cfg(target_arch = "aarch64")] capstone: Capstone, asan_runtime: AsanRuntime, + #[cfg(all(feature = "cmplog_runtime"))] cmplog_runtime: CmpLogRuntime, ranges: RangeMap, module_map: ModuleMap, @@ -271,6 +276,7 @@ impl<'a> FridaInstrumentationHelper<'a> { .build() .expect("Failed to create Capstone object"), asan_runtime: AsanRuntime::new(options.clone()), + #[cfg(all(feature = "cmplog_runtime"))] cmplog_runtime: CmpLogRuntime::new(), ranges: RangeMap::new(), module_map: ModuleMap::new_from_names(modules_to_instrument), @@ -348,11 +354,10 @@ impl<'a> FridaInstrumentationHelper<'a> { ); } } - if helper.options().cmplog_enabled() { #[cfg(not(target_arch = "aarch64"))] 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 if let Ok((op1, op2)) = helper.is_interesting_cmplog_instruction(address, instr) @@ -377,6 +382,7 @@ impl<'a> FridaInstrumentationHelper<'a> { if helper.options().asan_enabled() || helper.options().drcov_enabled() { helper.asan_runtime.init(gum, modules_to_instrument); } + #[cfg(all(feature = "cmplog_runtime"))] if helper.options.cmplog_enabled() { helper.cmplog_runtime.init(); } @@ -395,7 +401,7 @@ impl<'a> FridaInstrumentationHelper<'a> { Aarch64Register::from_u32(regint as u32).unwrap() } - #[cfg(target_arch = "aarch64")] + #[cfg(all(feature = "cmplog_runtime", target_arch = "aarch64"))] #[inline] fn emit_comparison_handling( &self, @@ -1027,7 +1033,7 @@ impl<'a> FridaInstrumentationHelper<'a> { Err(()) } - #[cfg(target_arch = "aarch64")] + #[cfg(all(feature = "cmplog_runtime", target_arch = "aarch64"))] #[inline] fn is_interesting_cmplog_instruction( &self, diff --git a/libafl_frida/src/lib.rs b/libafl_frida/src/lib.rs index bf94096f55..a459944881 100644 --- a/libafl_frida/src/lib.rs +++ b/libafl_frida/src/lib.rs @@ -10,6 +10,7 @@ pub mod asan_errors; /// The frida address sanitizer runtime pub mod asan_rt; +#[cfg(all(feature = "cmplog_runtime"))] /// The frida cmplog runtime pub mod cmplog_rt;