22//! The example harness is built for libpng.
33
44use libafl:: {
5- bolts:: tuples:: { tuple_list, Named } ,
5+ bolts:: tuples:: tuple_list,
66 corpus:: {
77 ondisk:: OnDiskMetadataFormat , Corpus , InMemoryCorpus ,
88 IndexesLenTimeMinimizerCorpusScheduler , OnDiskCorpus , QueueCorpusScheduler ,
99 } ,
10- events:: { setup_restarting_mgr_std, EventManager } ,
10+ events:: setup_restarting_mgr_std,
1111 executors:: {
12- inprocess:: InProcessExecutor , timeout:: TimeoutExecutor , Executor , ExitKind , HasObservers ,
12+ inprocess:: InProcessExecutor , timeout:: TimeoutExecutor , Executor , ExitKind , HasExecHooks ,
13+ HasExecHooksTuple , HasObservers , HasObserversHooks ,
1314 } ,
1415 feedbacks:: { CrashFeedback , MaxMapFeedback , TimeoutFeedback } ,
1516 fuzzer:: { Fuzzer , StdFuzzer } ,
@@ -37,14 +38,14 @@ use libafl_frida::{
3738 FridaOptions ,
3839} ;
3940
40- struct FridaInProcessExecutor < ' a , ' b , ' c , FH , H , I , OT >
41+ struct FridaInProcessExecutor < ' a , ' b , ' c , EM , FH , H , I , OT , S >
4142where
4243 FH : FridaHelper < ' b > ,
4344 H : FnMut ( & [ u8 ] ) -> ExitKind ,
4445 I : Input + HasTargetBytes ,
4546 OT : ObserversTuple ,
4647{
47- base : TimeoutExecutor < InProcessExecutor < ' a , H , I , OT > , I , OT > ,
48+ base : TimeoutExecutor < InProcessExecutor < ' a , EM , H , I , OT , S > , I > ,
4849 /// Frida's dynamic rewriting engine
4950 stalker : Stalker < ' a > ,
5051 /// User provided callback for instrumentation
@@ -53,19 +54,17 @@ where
5354 _phantom : PhantomData < & ' b u8 > ,
5455}
5556
56- impl < ' a , ' b , ' c , FH , H , I , OT > Executor < I > for FridaInProcessExecutor < ' a , ' b , ' c , FH , H , I , OT >
57+ impl < ' a , ' b , ' c , EM , FH , H , I , OT , S > Executor < I >
58+ for FridaInProcessExecutor < ' a , ' b , ' c , EM , FH , H , I , OT , S >
5759where
5860 FH : FridaHelper < ' b > ,
5961 H : FnMut ( & [ u8 ] ) -> ExitKind ,
6062 I : Input + HasTargetBytes ,
6163 OT : ObserversTuple ,
6264{
63- /// Called right before exexution starts
65+ /// Instruct the target about the input and run
6466 #[ inline]
65- fn pre_exec < EM , S > ( & mut self , state : & mut S , event_mgr : & mut EM , input : & I ) -> Result < ( ) , Error >
66- where
67- EM : EventManager < I , S > ,
68- {
67+ fn run_target ( & mut self , input : & I ) -> Result < ExitKind , Error > {
6968 if self . helper . stalker_enabled ( ) {
7069 if !self . followed {
7170 self . followed = true ;
@@ -77,45 +76,45 @@ where
7776 ) )
7877 }
7978 }
80-
81- self . helper . pre_exec ( input) ;
82-
83- self . base . pre_exec ( state, event_mgr, input)
84- }
85-
86- /// Instruct the target about the input and run
87- #[ inline]
88- fn run_target ( & mut self , input : & I ) -> Result < ExitKind , Error > {
8979 let res = self . base . run_target ( input) ;
9080 if unsafe { ASAN_ERRORS . is_some ( ) && !ASAN_ERRORS . as_ref ( ) . unwrap ( ) . is_empty ( ) } {
9181 println ! ( "Crashing target as it had ASAN errors" ) ;
9282 unsafe {
9383 libc:: raise ( libc:: SIGABRT ) ;
9484 }
9585 }
86+ if self . helper . stalker_enabled ( ) {
87+ self . stalker . deactivate ( ) ;
88+ }
9689 res
9790 }
91+ }
92+
93+ impl < ' a , ' b , ' c , EM , FH , H , I , OT , S > HasExecHooks < EM , I , S >
94+ for FridaInProcessExecutor < ' a , ' b , ' c , EM , FH , H , I , OT , S >
95+ where
96+ FH : FridaHelper < ' b > ,
97+ H : FnMut ( & [ u8 ] ) -> ExitKind ,
98+ I : Input + HasTargetBytes ,
99+ OT : ObserversTuple ,
100+ {
101+ /// Called right before exexution starts
102+ #[ inline]
103+ fn pre_exec ( & mut self , state : & mut S , event_mgr : & mut EM , input : & I ) -> Result < ( ) , Error > {
104+ self . helper . pre_exec ( input) ;
105+ self . base . pre_exec ( state, event_mgr, input)
106+ }
98107
99108 /// Called right after execution finished.
100109 #[ inline]
101- fn post_exec < EM , S > (
102- & mut self ,
103- state : & mut S ,
104- event_mgr : & mut EM ,
105- input : & I ,
106- ) -> Result < ( ) , Error >
107- where
108- EM : EventManager < I , S > ,
109- {
110- if self . helper . stalker_enabled ( ) {
111- self . stalker . deactivate ( ) ;
112- }
110+ fn post_exec ( & mut self , state : & mut S , event_mgr : & mut EM , input : & I ) -> Result < ( ) , Error > {
113111 self . helper . post_exec ( input) ;
114112 self . base . post_exec ( state, event_mgr, input)
115113 }
116114}
117115
118- impl < ' a , ' b , ' c , FH , H , I , OT > HasObservers < OT > for FridaInProcessExecutor < ' a , ' b , ' c , FH , H , I , OT >
116+ impl < ' a , ' b , ' c , EM , FH , H , I , OT , S > HasObservers < OT >
117+ for FridaInProcessExecutor < ' a , ' b , ' c , EM , FH , H , I , OT , S >
119118where
120119 FH : FridaHelper < ' b > ,
121120 H : FnMut ( & [ u8 ] ) -> ExitKind ,
@@ -133,19 +132,17 @@ where
133132 }
134133}
135134
136- impl < ' a , ' b , ' c , FH , H , I , OT > Named for FridaInProcessExecutor < ' a , ' b , ' c , FH , H , I , OT >
135+ impl < ' a , ' b , ' c , EM , FH , H , I , OT , S > HasObserversHooks < EM , I , OT , S >
136+ for FridaInProcessExecutor < ' a , ' b , ' c , EM , FH , H , I , OT , S >
137137where
138138 FH : FridaHelper < ' b > ,
139139 H : FnMut ( & [ u8 ] ) -> ExitKind ,
140140 I : Input + HasTargetBytes ,
141- OT : ObserversTuple ,
141+ OT : ObserversTuple + HasExecHooksTuple < EM , I , S > ,
142142{
143- fn name ( & self ) -> & str {
144- self . base . name ( )
145- }
146143}
147144
148- impl < ' a , ' b , ' c , FH , H , I , OT > FridaInProcessExecutor < ' a , ' b , ' c , FH , H , I , OT >
145+ impl < ' a , ' b , ' c , EM , FH , H , I , OT , S > FridaInProcessExecutor < ' a , ' b , ' c , EM , FH , H , I , OT , S >
149146where
150147 FH : FridaHelper < ' b > ,
151148 H : FnMut ( & [ u8 ] ) -> ExitKind ,
@@ -154,7 +151,7 @@ where
154151{
155152 pub fn new (
156153 gum : & ' a Gum ,
157- base : InProcessExecutor < ' a , H , I , OT > ,
154+ base : InProcessExecutor < ' a , EM , H , I , OT , S > ,
158155 helper : & ' c mut FH ,
159156 timeout : Duration ,
160157 ) -> Self {
@@ -324,7 +321,6 @@ unsafe fn fuzz(
324321 let mut executor = FridaInProcessExecutor :: new (
325322 & gum,
326323 InProcessExecutor :: new (
327- "in-process(edges)" ,
328324 & mut frida_harness,
329325 tuple_list ! ( edges_observer, AsanErrorsObserver :: new( & ASAN_ERRORS ) ) ,
330326 & mut state,
0 commit comments