libafl_frida: Allow setting path for DrCovRuntime (#1536)
This commit is contained in:
parent
f70a16a09a
commit
a092aed538
@ -2,6 +2,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
hash::{BuildHasher, Hasher},
|
hash::{BuildHasher, Hasher},
|
||||||
|
path::{Path, PathBuf},
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ pub struct DrCovRuntime {
|
|||||||
/// The memory ragnes of this target
|
/// The memory ragnes of this target
|
||||||
ranges: RangeMap<usize, (u16, String)>,
|
ranges: RangeMap<usize, (u16, String)>,
|
||||||
stalked_addresses: HashMap<usize, usize>,
|
stalked_addresses: HashMap<usize, usize>,
|
||||||
|
coverage_directory: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FridaRuntime for DrCovRuntime {
|
impl FridaRuntime for DrCovRuntime {
|
||||||
@ -36,7 +38,7 @@ impl FridaRuntime for DrCovRuntime {
|
|||||||
_module_map: &Rc<ModuleMap>,
|
_module_map: &Rc<ModuleMap>,
|
||||||
) {
|
) {
|
||||||
self.ranges = ranges.clone();
|
self.ranges = ranges.clone();
|
||||||
std::fs::create_dir_all("./coverage")
|
std::fs::create_dir_all(&self.coverage_directory)
|
||||||
.expect("failed to create directory for coverage files");
|
.expect("failed to create directory for coverage files");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +53,9 @@ impl FridaRuntime for DrCovRuntime {
|
|||||||
let mut hasher = RandomState::with_seeds(0, 0, 0, 0).build_hasher();
|
let mut hasher = RandomState::with_seeds(0, 0, 0, 0).build_hasher();
|
||||||
hasher.write(input.target_bytes().as_slice());
|
hasher.write(input.target_bytes().as_slice());
|
||||||
|
|
||||||
let filename = format!("./coverage/{:016x}.drcov", hasher.finish(),);
|
let filename = self
|
||||||
|
.coverage_directory
|
||||||
|
.join(format!("{:016x}.drcov", hasher.finish(),));
|
||||||
DrCovWriter::new(&self.ranges).write(filename, &self.drcov_basic_blocks)?;
|
DrCovWriter::new(&self.ranges).write(filename, &self.drcov_basic_blocks)?;
|
||||||
self.drcov_basic_blocks.clear();
|
self.drcov_basic_blocks.clear();
|
||||||
|
|
||||||
@ -63,10 +67,14 @@ impl DrCovRuntime {
|
|||||||
/// Creates a new [`DrCovRuntime`]
|
/// Creates a new [`DrCovRuntime`]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new [`DrCovRuntime`] that writes coverage to the specified directory
|
||||||
|
pub fn with_path<P: AsRef<Path>>(path: P) -> Self {
|
||||||
Self {
|
Self {
|
||||||
drcov_basic_blocks: vec![],
|
coverage_directory: path.as_ref().into(),
|
||||||
ranges: RangeMap::new(),
|
..Self::default()
|
||||||
stalked_addresses: HashMap::new(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +96,11 @@ impl DrCovRuntime {
|
|||||||
|
|
||||||
impl Default for DrCovRuntime {
|
impl Default for DrCovRuntime {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self {
|
||||||
|
drcov_basic_blocks: vec![],
|
||||||
|
ranges: RangeMap::new(),
|
||||||
|
stalked_addresses: HashMap::new(),
|
||||||
|
coverage_directory: PathBuf::from("./coverage"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user