-
Notifications
You must be signed in to change notification settings - Fork 10
/
afl_cmin.py
executable file
·50 lines (34 loc) · 1.01 KB
/
afl_cmin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""
Wrapper around `afl-cmin`. Only keeps the names of the files in the minimized
corpus.
Author: Adrian Herrera
"""
from getopt import getopt
from pathlib import Path
from shutil import which
from subprocess import run
from tempfile import TemporaryDirectory
import os
import sys
def main():
"""The main function."""
opts, args = getopt(sys.argv[1:], '+i:f:m:t:eQC')
cmin = which('afl-cmin')
if not cmin:
raise Exception('afl-cmin not found. Check PATH')
env = os.environ.copy()
env['AFL_ALLOW_TMP'] = '1'
ret = 1
with TemporaryDirectory() as temp_dir:
cmin_args = [cmin, *[val for vals in opts for val in vals],
'-o', temp_dir, '--', *args]
proc = run(cmin_args, check=False, env=env)
seeds = list(Path(temp_dir).iterdir())
print('\nSeeds (%d):' % len(seeds))
for seed in seeds:
print(seed.name)
ret = proc.returncode
sys.exit(ret)
if __name__ == '__main__':
main()