1010afl-fuzz -i ./afl_inputs -o ./afl_outputs -m none -U -- python3 ./fuzz_x8664_linux.py @@
1111"""
1212
13- # This is new. Instead of unicorn, we import unicornafl. It's the same Uc with some new `afl_` functions
14- import unicornafl
15-
16- # Make sure Qiling uses our patched unicorn instead of it's own, second so without instrumentation!
17- unicornafl .monkeypatch ()
13+ # No more need for importing unicornafl, try ql.afl_fuzz instead!
1814
1915import sys , os
2016from binascii import hexlify
2117
2218sys .path .append ("../../.." )
2319from qiling import *
2420from qiling .extensions import pipe
21+ from qiling .extensions .afl import ql_afl_fuzz
2522
2623def main (input_file , enable_trace = False ):
2724 mock_stdin = pipe .SimpleInStream (sys .stdin .fileno ())
@@ -35,33 +32,17 @@ def main(input_file, enable_trace=False):
3532 # or this for output:
3633 # ... stdout=sys.stdout, stderr=sys.stderr)
3734
38- def place_input_callback (uc , input , _ , data ):
35+ def place_input_callback (ql : Qiling , input : bytes , _ : int ):
3936 ql .os .stdin .write (input )
37+ return True
4038
4139 def start_afl (_ql : Qiling ):
42- """
43- Callback from inside
44- """
45- # We start our AFL forkserver or run once if AFL is not available.
46- # This will only return after the fuzzing stopped.
47- try :
48- #print("Starting afl_fuzz().")
49- if not _ql .uc .afl_fuzz (input_file = input_file ,
50- place_input_callback = place_input_callback ,
51- exits = [ql .os .exit_point ]):
52- print ("Ran once without AFL attached." )
53- os ._exit (0 ) # that's a looot faster than tidying up.
54- except unicornafl .UcAflError as ex :
55- # This hook trigers more than once in this example.
56- # If this is the exception cause, we don't care.
57- # TODO: Chose a better hook position :)
58- if ex != unicornafl .UC_AFL_RET_CALLED_TWICE :
59- raise
40+ ql_afl_fuzz (_ql , input_file = input_file , place_input_callback = place_input_callback , exits = [ql .os .exit_point ])
6041
6142 LIBC_BASE = int (ql .profile .get ("OS32" , "interp_address" ), 16 )
6243
6344 # crash in case we reach SignalKill
64- ql .hook_address (callback = lambda x : os .abort (), address = LIBC_BASE + 0x456d4 )
45+ ql .hook_address (callback = lambda x : os .abort (), address = LIBC_BASE + 0x38170 )
6546
6647 # Add hook at main() that will fork Unicorn and start instrumentation.
6748 main_addr = 0x08048aa0
0 commit comments