Skip to content

Commit a092aed

Browse files
authored
libafl_frida: Allow setting path for DrCovRuntime (#1536)
1 parent f70a16a commit a092aed

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

libafl_frida/src/drcov_rt.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use std::{
33
collections::HashMap,
44
hash::{BuildHasher, Hasher},
5+
path::{Path, PathBuf},
56
rc::Rc,
67
};
78

@@ -25,6 +26,7 @@ pub struct DrCovRuntime {
2526
/// The memory ragnes of this target
2627
ranges: RangeMap<usize, (u16, String)>,
2728
stalked_addresses: HashMap<usize, usize>,
29+
coverage_directory: PathBuf,
2830
}
2931

3032
impl FridaRuntime for DrCovRuntime {
@@ -36,7 +38,7 @@ impl FridaRuntime for DrCovRuntime {
3638
_module_map: &Rc<ModuleMap>,
3739
) {
3840
self.ranges = ranges.clone();
39-
std::fs::create_dir_all("./coverage")
41+
std::fs::create_dir_all(&self.coverage_directory)
4042
.expect("failed to create directory for coverage files");
4143
}
4244

@@ -51,7 +53,9 @@ impl FridaRuntime for DrCovRuntime {
5153
let mut hasher = RandomState::with_seeds(0, 0, 0, 0).build_hasher();
5254
hasher.write(input.target_bytes().as_slice());
5355

54-
let filename = format!("./coverage/{:016x}.drcov", hasher.finish(),);
56+
let filename = self
57+
.coverage_directory
58+
.join(format!("{:016x}.drcov", hasher.finish(),));
5559
DrCovWriter::new(&self.ranges).write(filename, &self.drcov_basic_blocks)?;
5660
self.drcov_basic_blocks.clear();
5761

@@ -63,10 +67,14 @@ impl DrCovRuntime {
6367
/// Creates a new [`DrCovRuntime`]
6468
#[must_use]
6569
pub fn new() -> Self {
70+
Self::default()
71+
}
72+
73+
/// Create a new [`DrCovRuntime`] that writes coverage to the specified directory
74+
pub fn with_path<P: AsRef<Path>>(path: P) -> Self {
6675
Self {
67-
drcov_basic_blocks: vec![],
68-
ranges: RangeMap::new(),
69-
stalked_addresses: HashMap::new(),
76+
coverage_directory: path.as_ref().into(),
77+
..Self::default()
7078
}
7179
}
7280

@@ -88,6 +96,11 @@ impl DrCovRuntime {
8896

8997
impl Default for DrCovRuntime {
9098
fn default() -> Self {
91-
Self::new()
99+
Self {
100+
drcov_basic_blocks: vec![],
101+
ranges: RangeMap::new(),
102+
stalked_addresses: HashMap::new(),
103+
coverage_directory: PathBuf::from("./coverage"),
104+
}
92105
}
93106
}

0 commit comments

Comments
 (0)