1
1
use std:: {
2
- env, ffi:: CString , num:: NonZero , os:: unix:: ffi:: OsStrExt , path:: PathBuf , slice , time:: Duration ,
2
+ env, ffi:: CString , num:: NonZero , os:: unix:: ffi:: OsStrExt , path:: PathBuf , time:: Duration ,
3
3
} ;
4
4
5
5
use libafl:: {
@@ -20,7 +20,7 @@ use libafl::{
20
20
state:: StdState ,
21
21
} ;
22
22
use libafl_bolts:: { core_affinity, rands:: StdRand , tuples:: tuple_list} ;
23
- use libafl_intelpt:: { IntelPT , PAGE_SIZE } ;
23
+ use libafl_intelpt:: { AddrFilter , AddrFilterType , AddrFilters , IntelPT , PAGE_SIZE } ;
24
24
25
25
// Coverage map
26
26
const MAP_SIZE : usize = 4096 ;
@@ -90,25 +90,31 @@ pub fn main() {
90
90
91
91
// The target is a ET_DYN elf, it will be relocated by the loader with this offset.
92
92
// see https://github.com/torvalds/linux/blob/c1e939a21eb111a6d6067b38e8e04b8809b64c4e/arch/x86/include/asm/elf.h#L234C1-L239C38
93
- const DEFAULT_MAP_WINDOW : usize = ( 1 << 47 ) - PAGE_SIZE ;
94
- const ELF_ET_DYN_BASE : usize = ( DEFAULT_MAP_WINDOW / 3 * 2 ) & !( PAGE_SIZE - 1 ) ;
93
+ const DEFAULT_MAP_WINDOW : u64 = ( 1 << 47 ) - PAGE_SIZE as u64 ;
94
+ const ELF_ET_DYN_BASE : u64 = ( DEFAULT_MAP_WINDOW / 3 * 2 ) & !( PAGE_SIZE as u64 - 1 ) ;
95
95
96
96
// Set the instruction pointer (IP) filter and memory image of our target.
97
97
// These information can be retrieved from `readelf -l` (for example)
98
- let code_memory_addresses = ELF_ET_DYN_BASE + 0x15000 ..=ELF_ET_DYN_BASE + 0x14000 + 0x41000 ;
99
-
98
+ let ( code_memory_start, code_memory_end) =
99
+ ( ELF_ET_DYN_BASE + 0x6000 , ELF_ET_DYN_BASE + 0x6000 + 0x3dfd9 ) ;
100
+ let filters = AddrFilters :: new ( & [ AddrFilter :: new (
101
+ code_memory_start,
102
+ code_memory_end,
103
+ AddrFilterType :: FILTER ,
104
+ ) ] )
105
+ . unwrap ( ) ;
100
106
let intel_pt = IntelPT :: builder ( )
101
107
. cpu ( cpu. 0 )
102
108
. inherit ( true )
103
- . ip_filters ( slice :: from_ref ( & code_memory_addresses ) )
109
+ . ip_filters ( & filters )
104
110
. build ( )
105
111
. unwrap ( ) ;
106
112
107
113
let sections = [ SectionInfo {
108
114
filename : target_path. to_string_lossy ( ) . to_string ( ) ,
109
- offset : 0x14000 ,
110
- size : ( * code_memory_addresses . end ( ) - * code_memory_addresses . start ( ) + 1 ) as u64 ,
111
- virtual_address : * code_memory_addresses . start ( ) as u64 ,
115
+ offset : 0x6000 ,
116
+ size : code_memory_end - code_memory_start ,
117
+ virtual_address : code_memory_start ,
112
118
} ] ;
113
119
114
120
let hook = unsafe { IntelPTHook :: builder ( ) . map_ptr ( MAP_PTR ) . map_len ( MAP_SIZE ) }
0 commit comments