Skip to content

Commit 3e97d28

Browse files
authored
Merge pull request #1068 from wtdcode/fix-unicornafl
Fix unicornafl for linux_x8664 fuzzing example
2 parents fc40267 + 1e7f3d8 commit 3e97d28

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

examples/fuzzing/linux_x8664/fuzz_x8664_linux.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
$ rm -fr afl_outputs/default/
1818
"""
1919

20-
# This is new. Instead of unicorn, we import unicornafl. It's the same Uc with some new `afl_` functions
21-
import unicornafl as UcAfl
22-
23-
# Make sure Qiling uses our patched unicorn instead of it's own, second so without instrumentation!
24-
UcAfl.monkeypatch()
20+
# This uses the new unicornafl, which no longer provides any Unicorn stuff so we have to import by our own.
21+
from unicornafl import *
22+
from unicorn import *
2523

2624
import os
2725
import sys
@@ -43,7 +41,7 @@ def main(input_file: str):
4341
stdout=None,
4442
stderr=None)
4543

46-
def place_input_callback(uc: UcAfl.Uc, input: bytes, persistent_round: int, data: Any) -> Optional[bool]:
44+
def place_input_callback(uc: Uc, input: bytes, persistent_round: int, data: Any) -> Optional[bool]:
4745
"""Called with every newly generated input.
4846
"""
4947

@@ -56,16 +54,17 @@ def start_afl(_ql: Qiling):
5654
# We start our AFL forkserver or run once if AFL is not available.
5755
# This will only return after the fuzzing stopped.
5856
try:
59-
if not _ql.uc.afl_fuzz(input_file=input_file, place_input_callback=place_input_callback, exits=[ql.os.exit_point]):
57+
# _ql.uc.afl_fuzz shall also work, but just for compatibility with old unicornafl
58+
if not uc_afl_fuzz(_ql.uc, input_file=input_file, place_input_callback=place_input_callback, exits=[ql.os.exit_point]):
6059
_ql.log.warning("Ran once without AFL attached")
6160
os._exit(0)
6261

63-
except UcAfl.UcAflError as ex:
62+
except UcAflError as ex:
6463
# This hook triggers more than once in this example.
6564
# If this is the exception cause, we don't care.
6665

6766
# TODO: choose a better hook position :)
68-
if ex.errno != UcAfl.UC_AFL_RET_CALLED_TWICE:
67+
if ex.errno != UC_AFL_RET_CALLED_TWICE:
6968
raise
7069

7170
# get image base address

0 commit comments

Comments
 (0)