diff --git a/.travis.yml b/.travis.yml index 9b284fc..c0089df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,10 @@ language: python matrix: include: - python: "2.6" - env: CYTHON=0.19 + env: CYTHON=0.19.1 - python: "2.7" - python: "3.2" - env: CYTHON=0.19 + env: CYTHON=0.19.1 - python: "3.3" - python: "3.4" - python: "3.5" diff --git a/afl.pyx b/afl.pyx index 1455539..4dc8747 100644 --- a/afl.pyx +++ b/afl.pyx @@ -68,6 +68,7 @@ cdef extern from 'signal.h': cdef extern from 'sys/shm.h': unsigned char *shmat(int shmid, void *shmaddr, int shmflg) +trace_map = None cdef unsigned char *afl_area = NULL cdef unsigned int prev_location = 0 @@ -125,7 +126,7 @@ cdef bint init_done = False cdef bint tstl_mode = False cdef int _init(bint persistent_mode) except -1: - global afl_area, init_done, tstl_mode + global afl_area, trace_map, init_done, tstl_mode tstl_mode = os.getenv('PYTHON_AFL_TSTL') is not None use_forkserver = True try: @@ -182,6 +183,8 @@ cdef int _init(bint persistent_mode) except -1: afl_area = shmat(int(afl_shm_id), NULL, 0) if afl_area == -1: PyErr_SetFromErrno(OSError) + cdef unsigned char[:] cy_trace_map = afl_area + trace_map = cy_trace_map sys.settrace(trace) return 0 @@ -238,6 +241,7 @@ def loop(max=None): __all__ = [ 'init', 'loop', + 'trace_map', ] # vim:ts=4 sts=4 sw=4 et diff --git a/doc/README b/doc/README index 548d428..8b477da 100644 --- a/doc/README +++ b/doc/README @@ -102,7 +102,7 @@ Prerequisites To build the module, you will need: * Python 2.6+ or 3.2+ -* Cython ≥ 0.19 (only at build time) +* Cython ≥ 0.19.1 (only at build time) *py-afl-fuzz* requires AFL proper to be installed. diff --git a/setup.py b/setup.py index 67cb5f8..ff7196e 100644 --- a/setup.py +++ b/setup.py @@ -79,7 +79,7 @@ def get_version(): author_email='jwilk@jwilk.net', ) -min_cython_version = '0.19' +min_cython_version = '0.19.1' try: import Cython except ImportError: diff --git a/tests/target_trace_map.py b/tests/target_trace_map.py new file mode 100644 index 0000000..6c95752 --- /dev/null +++ b/tests/target_trace_map.py @@ -0,0 +1,39 @@ +# encoding=UTF-8 + +# Copyright © 2018 Jakub Wilk +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the “Software”), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys + +import afl + +# pylint: disable=unsupported-assignment-operation + +def main(): + s = sys.stdin.read() + s.encode('ASCII') + for c in s: + afl.trace_map[ord(c)] += 1 + +if __name__ == '__main__': + afl.init() + main() + +# vim:ts=4 sts=4 sw=4 et diff --git a/tests/test_fuzz.py b/tests/test_fuzz.py index 871d158..1cfe6af 100644 --- a/tests/test_fuzz.py +++ b/tests/test_fuzz.py @@ -169,6 +169,8 @@ def t(target): ) yield t, 'target.py' yield t, 'target_persistent.py' + if not dumb: + yield t, 'target_trace_map.py' def test_fuzz_dumb(): if get_afl_version() < '1.95': diff --git a/tests/test_import.py b/tests/test_import.py index 7b29e34..f462fe6 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -29,6 +29,7 @@ exports = [ 'init', 'loop', + 'trace_map', ] deprecated = [