From e469e1ad3789eb5b4f4fe82924f1d4ab2385935a Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Wed, 13 Jun 2018 13:44:45 +0200 Subject: [PATCH] extended trace function - add result from remote service to the SHM trace bitmat --- afl.pyx | 27 +++++++++++++++++++++++++++ tests/test_import.py | 3 +++ 2 files changed, 30 insertions(+) diff --git a/afl.pyx b/afl.pyx index 1455539..b0db465 100644 --- a/afl.pyx +++ b/afl.pyx @@ -108,6 +108,17 @@ def trace(frame, event, arg): # TODO: make it configurable which modules are instrumented, and which are not return trace + +cdef object _trace_offset +def _trace_offset(offset, ignore_prev, preserve_prev): + global prev_location, tstl_mode + location = (offset % MAP_SIZE) + offset = location ^ prev_location if not ignore_prev else location + if not preserve_prev: + prev_location = location // 2 + afl_area[offset] += 1 + + cdef int except_signal_id = 0 cdef object except_signal_name = os.getenv('PYTHON_AFL_SIGNAL') or '0' if except_signal_name.isdigit(): @@ -235,9 +246,25 @@ def loop(max=None): sys.settrace(None) return False + +def hash32(buff, offset=0): + return lhash(buff, offset) + + +def trace_offset(offset, ignore_prev=False, preserve_prev=False): + _trace_offset(offset, ignore_prev, preserve_prev) + + +def install_default_trace(): + sys.settrace(trace) + + __all__ = [ 'init', 'loop', + 'hash32', + 'trace_offset', + 'install_default_trace', ] # vim:ts=4 sts=4 sw=4 et diff --git a/tests/test_import.py b/tests/test_import.py index 7b29e34..e11ae0e 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -29,6 +29,9 @@ exports = [ 'init', 'loop', + 'hash32', + 'trace_offset', + 'install_default_trace', ] deprecated = [