Skip to content

Commit d090e5b

Browse files
committed
extended trace function
- add result from remote service to the SHM trace bitmat
1 parent 6d51e15 commit d090e5b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

afl.pyx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ def trace(frame, event, arg):
108108
# TODO: make it configurable which modules are instrumented, and which are not
109109
return trace
110110

111+
112+
cdef object _trace_offset
113+
def _trace_offset(offset, ignore_prev, preserve_prev):
114+
global prev_location, tstl_mode
115+
location = (offset % MAP_SIZE)
116+
offset = location ^ prev_location if not ignore_prev else location
117+
if not preserve_prev:
118+
prev_location = location // 2
119+
afl_area[offset] += 1
120+
121+
111122
cdef int except_signal_id = 0
112123
cdef object except_signal_name = os.getenv('PYTHON_AFL_SIGNAL') or '0'
113124
if except_signal_name.isdigit():
@@ -235,9 +246,25 @@ def loop(max=None):
235246
sys.settrace(None)
236247
return False
237248

249+
250+
def hash32(buff, offset=0):
251+
return lhash(buff, offset)
252+
253+
254+
def trace_offset(offset, ignore_prev=False, preserve_prev=False):
255+
_trace_offset(offset, ignore_prev, preserve_prev)
256+
257+
258+
def install_default_trace():
259+
sys.settrace(trace)
260+
261+
238262
__all__ = [
239263
'init',
240264
'loop',
265+
'hash32',
266+
'trace_offset',
267+
'install_default_trace',
241268
]
242269

243270
# vim:ts=4 sts=4 sw=4 et

tests/test_import.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
exports = [
3030
'init',
3131
'loop',
32+
'hash32',
33+
'trace_buff',
34+
'trace_offset',
35+
'install_default_trace',
3236
]
3337

3438
deprecated = [

0 commit comments

Comments
 (0)