@@ -2,10 +2,6 @@ use std::{
22 hint:: black_box, num:: NonZero , path:: PathBuf , process, ptr:: copy_nonoverlapping, time:: Duration ,
33} ;
44
5- #[ cfg( feature = "tui" ) ]
6- use libafl:: monitors:: tui:: TuiMonitor ;
7- #[ cfg( not( feature = "tui" ) ) ]
8- use libafl:: monitors:: SimpleMonitor ;
95use libafl:: {
106 corpus:: { InMemoryCorpus , OnDiskCorpus } ,
117 events:: SimpleEventManager ,
@@ -18,26 +14,27 @@ use libafl::{
1814 fuzzer:: { Fuzzer , StdFuzzer } ,
1915 generators:: RandPrintablesGenerator ,
2016 inputs:: { BytesInput , HasTargetBytes } ,
17+ monitors:: SimpleMonitor ,
2118 mutators:: { havoc_mutations:: havoc_mutations, scheduled:: HavocScheduledMutator } ,
2219 observers:: ConstMapObserver ,
2320 schedulers:: QueueScheduler ,
2421 stages:: mutational:: StdMutationalStage ,
2522 state:: StdState ,
2623} ;
27- use libafl_bolts:: { current_nanos, nonnull_raw_mut, rands:: StdRand , tuples:: tuple_list, AsSlice } ;
24+ use libafl_bolts:: { current_nanos, nonnull_raw_mut, rands:: StdRand , tuples:: tuple_list} ;
2825use proc_maps:: get_process_maps;
2926
30- // Coverage map
27+ // Edge coverage map.
3128const MAP_SIZE : usize = 4096 ;
3229static mut MAP : [ u8 ; MAP_SIZE ] = [ 0 ; MAP_SIZE ] ;
3330static mut MAP_PTR : * mut u8 = & raw mut MAP as _ ;
3431
3532pub fn main ( ) {
36- // The closure that we want to fuzz
33+ // The function that we want to fuzz
3734 let mut harness = |input : & BytesInput | {
38- let target = input. target_bytes ( ) ;
39- let buf = target. as_slice ( ) ;
35+ let buf = input. target_bytes ( ) ;
4036 if !buf. is_empty ( ) && buf[ 0 ] == b'a' {
37+ // Avoid compiler optimizations
4138 let _do_something = black_box ( 0 ) ;
4239 if buf. len ( ) > 1 && buf[ 1 ] == b'b' {
4340 let _do_something = black_box ( 0 ) ;
@@ -50,17 +47,16 @@ pub fn main() {
5047 } ;
5148
5249 // Create an observation channel using the map
53- let observer = unsafe { ConstMapObserver :: from_mut_ptr ( "signals " , nonnull_raw_mut ! ( MAP ) ) } ;
50+ let observer = unsafe { ConstMapObserver :: from_mut_ptr ( "edges " , nonnull_raw_mut ! ( MAP ) ) } ;
5451
5552 // Feedback to rate the interestingness of an input
5653 let mut feedback = MaxMapFeedback :: new ( & observer) ;
5754
5855 // A feedback to choose if an input is a solution or not
5956 let mut objective = CrashFeedback :: new ( ) ;
6057
61- // create a State from scratch
6258 let mut state = StdState :: new (
63- // RNG
59+ // Random Number Generator
6460 StdRand :: with_seed ( current_nanos ( ) ) ,
6561 // Corpus that will be evolved, we keep it in memory for performance
6662 InMemoryCorpus :: new ( ) ,
@@ -75,14 +71,8 @@ pub fn main() {
7571 )
7672 . unwrap ( ) ;
7773
78- // The Monitor trait define how the fuzzer stats are displayed to the user
79- #[ cfg( not( feature = "tui" ) ) ]
74+ // The Monitor define how the fuzzer stats are displayed to the user, here we simply print
8075 let mon = SimpleMonitor :: new ( |s| println ! ( "{s}" ) ) ;
81- #[ cfg( feature = "tui" ) ]
82- let mon = TuiMonitor :: builder ( )
83- . title ( "Baby Fuzzer Intel PT" )
84- . enhanced_graphics ( false )
85- . build ( ) ;
8676
8777 // The event manager handle the various events generated during the fuzzing loop
8878 // such as the notification of the addition of a new item to the corpus
@@ -113,6 +103,7 @@ pub fn main() {
113103 } )
114104 . collect :: < Vec < _ > > ( ) ;
115105
106+ // Pass the executable memory to the code responsible for Intel PT trace decoding
116107 let pt = IntelPT :: builder ( ) . images ( images) . build ( ) . unwrap ( ) ;
117108 // Intel PT hook that will handle the setup of Intel PT for each execution and fill the map
118109 let pt_hook = unsafe {
0 commit comments