2
2
use std:: {
3
3
collections:: HashMap ,
4
4
hash:: { BuildHasher , Hasher } ,
5
+ path:: { Path , PathBuf } ,
5
6
rc:: Rc ,
6
7
} ;
7
8
@@ -25,6 +26,7 @@ pub struct DrCovRuntime {
25
26
/// The memory ragnes of this target
26
27
ranges : RangeMap < usize , ( u16 , String ) > ,
27
28
stalked_addresses : HashMap < usize , usize > ,
29
+ coverage_directory : PathBuf ,
28
30
}
29
31
30
32
impl FridaRuntime for DrCovRuntime {
@@ -36,7 +38,7 @@ impl FridaRuntime for DrCovRuntime {
36
38
_module_map : & Rc < ModuleMap > ,
37
39
) {
38
40
self . ranges = ranges. clone ( ) ;
39
- std:: fs:: create_dir_all ( "./coverage" )
41
+ std:: fs:: create_dir_all ( & self . coverage_directory )
40
42
. expect ( "failed to create directory for coverage files" ) ;
41
43
}
42
44
@@ -51,7 +53,9 @@ impl FridaRuntime for DrCovRuntime {
51
53
let mut hasher = RandomState :: with_seeds ( 0 , 0 , 0 , 0 ) . build_hasher ( ) ;
52
54
hasher. write ( input. target_bytes ( ) . as_slice ( ) ) ;
53
55
54
- let filename = format ! ( "./coverage/{:016x}.drcov" , hasher. finish( ) , ) ;
56
+ let filename = self
57
+ . coverage_directory
58
+ . join ( format ! ( "{:016x}.drcov" , hasher. finish( ) , ) ) ;
55
59
DrCovWriter :: new ( & self . ranges ) . write ( filename, & self . drcov_basic_blocks ) ?;
56
60
self . drcov_basic_blocks . clear ( ) ;
57
61
@@ -63,10 +67,14 @@ impl DrCovRuntime {
63
67
/// Creates a new [`DrCovRuntime`]
64
68
#[ must_use]
65
69
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 {
66
75
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 ( )
70
78
}
71
79
}
72
80
@@ -88,6 +96,11 @@ impl DrCovRuntime {
88
96
89
97
impl Default for DrCovRuntime {
90
98
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
+ }
92
105
}
93
106
}
0 commit comments