Skip to content

Extended trace function #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions afl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
exports = [
'init',
'loop',
'hash32',
'trace_offset',
'install_default_trace',
]

deprecated = [
Expand Down