diff options
| author | Kostya Serebryany <kcc@google.com> | 2018-06-06 01:23:29 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2018-06-06 01:23:29 +0000 |
| commit | 1fd005f552595ceb2a10f2deacc6b64a50019afb (patch) | |
| tree | 224b67c41f607b9c7564e49515ba03cfa5beaf85 /compiler-rt/lib/fuzzer/scripts/collect_data_flow.py | |
| parent | f3914b74c1825f4deece3317542743109dabbf56 (diff) | |
| download | bcm5719-llvm-1fd005f552595ceb2a10f2deacc6b64a50019afb.tar.gz bcm5719-llvm-1fd005f552595ceb2a10f2deacc6b64a50019afb.zip | |
[libFuzzer] initial implementation of -data_flow_trace. It parses the data flow trace and prints the summary, but doesn't use the information in any other way yet
llvm-svn: 334058
Diffstat (limited to 'compiler-rt/lib/fuzzer/scripts/collect_data_flow.py')
| -rwxr-xr-x | compiler-rt/lib/fuzzer/scripts/collect_data_flow.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/compiler-rt/lib/fuzzer/scripts/collect_data_flow.py b/compiler-rt/lib/fuzzer/scripts/collect_data_flow.py index d13f6dcc411..c3faf71c0af 100755 --- a/compiler-rt/lib/fuzzer/scripts/collect_data_flow.py +++ b/compiler-rt/lib/fuzzer/scripts/collect_data_flow.py @@ -11,9 +11,15 @@ # the complete trace for all input bytes (running it on all bytes at once # may fail if DFSan runs out of labels). # Usage: -# collect_data_flow.py BINARY INPUT [RESULT] +# +# # Collect dataflow for one input, store it in OUTPUT (default is stdout) +# collect_data_flow.py BINARY INPUT [OUTPUT] +# +# # Collect dataflow for all inputs in CORPUS_DIR, store them in OUTPUT_DIR +# collect_data_flow.py BINARY CORPUS_DIR OUTPUT_DIR #===------------------------------------------------------------------------===# import atexit +import hashlib import sys import os import subprocess @@ -26,9 +32,26 @@ def cleanup(d): print "removing: ", d shutil.rmtree(d) +def collect_dataflow_for_corpus(self, exe, corpus_dir, output_dir): + print "Collecting dataflow for corpus:", corpus_dir, \ + "output_dir:", output_dir + assert not os.path.exists(output_dir) + os.mkdir(output_dir) + for root, dirs, files in os.walk(corpus_dir): + for f in files: + path = os.path.join(root, f) + sha1 = hashlib.sha1(open(path).read()).hexdigest() + output = os.path.join(output_dir, sha1) + subprocess.call([self, exe, path, output]) + functions_txt = open(os.path.join(output_dir, "functions.txt"), "w") + subprocess.call([exe], stdout=functions_txt) + + def main(argv): exe = argv[1] inp = argv[2] + if os.path.isdir(inp): + return collect_dataflow_for_corpus(argv[0], exe, inp, argv[3]) size = os.path.getsize(inp) q = [[0, size]] tmpdir = tempfile.mkdtemp(prefix="libfuzzer-tmp-") |

