Skip to content

Commit 0a750c0

Browse files
committed
switch to python3
1 parent e6a6fb9 commit 0a750c0

File tree

3 files changed

+54
-51
lines changed

3 files changed

+54
-51
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
afl-cov-0.6.5 (2020-05-28)
2+
- switched to python3
3+
14
afl-cov-0.6.4 (2020-05-23):
25
- afl-cov now supports stdin targets (just omit @@/AFL_FILE)
36
- enhance scripts

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# afl-cov - AFL Fuzzing Code Coverage
22

3-
Version: 0.6.4
3+
Version: 0.6.5
44

55
- [Preface](#preface)
66
- [Introduction](#introduction)

afl-cov

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
#
33
# File: afl-cov
44
#
5-
# Version: 0.6.4
5+
# Version: 0.6.5
66
#
77
# Purpose: Perform lcov coverage diff's against each AFL queue file to see
88
# new functions and line coverage evolve from an AFL fuzzing cycle.
@@ -45,7 +45,7 @@ try:
4545
except ImportError:
4646
import subprocess
4747

48-
__version__ = '0.6.4'
48+
__version__ = '0.6.5'
4949

5050
NO_OUTPUT = 0
5151
WANT_OUTPUT = 1
@@ -62,7 +62,7 @@ def main():
6262
cargs.coverage_cmd = cargs.coverage_cmd.replace('@@', 'AFL_FILE')
6363

6464
if cargs.version:
65-
print "afl-cov-" + __version__
65+
print("afl-cov-" + __version__)
6666
return exit_success
6767

6868
if cargs.gcov_check or cargs.gcov_check_bin:
@@ -100,7 +100,7 @@ def run_in_background():
100100
### capability anyway
101101
pid = os.fork()
102102
if (pid < 0):
103-
print "[*] fork() error, exiting."
103+
print("[*] fork() error, exiting.")
104104
os._exit()
105105
elif (pid > 0):
106106
os._exit(0)
@@ -710,7 +710,7 @@ def run_cmd(cmd, log_file, cargs, collect, aflrun, fn):
710710
if log_file:
711711
logr(" CMD: %s" % cmd, log_file, cargs)
712712
else:
713-
print " CMD: %s" % cmd
713+
print(" CMD: %s" % cmd)
714714

715715
es = subprocess.call(cmd, stdin=None,
716716
stdout=fh, stderr=subprocess.STDOUT, shell=True)
@@ -731,14 +731,14 @@ def run_cmd(cmd, log_file, cargs, collect, aflrun, fn):
731731
for line in out:
732732
logr(line, log_file, cargs)
733733
else:
734-
print " Non-zero exit status '%d' for CMD: %s" % (es, cmd)
734+
print(" Non-zero exit status '%d' for CMD: %s" % (es, cmd))
735735

736736
return es, out
737737

738738
def import_fuzzing_dirs(cov_paths, cargs):
739739

740740
if not cargs.afl_fuzzing_dir:
741-
print "[*] Must specify AFL fuzzing dir with --afl-fuzzing-dir or -d"
741+
print("[*] Must specify AFL fuzzing dir with --afl-fuzzing-dir or -d")
742742
return False
743743

744744
if 'top_dir' not in cov_paths:
@@ -794,8 +794,8 @@ def init_tracking(cov_paths, cargs):
794794
else:
795795
if is_dir(cov_paths['top_dir']):
796796
if not cargs.func_search and not cargs.line_search:
797-
print "[*] Existing coverage dir %s found, use --overwrite to " \
798-
"re-calculate coverage" % (cov_paths['top_dir'])
797+
print("[*] Existing coverage dir %s found, use --overwrite to " \
798+
"re-calculate coverage" % (cov_paths['top_dir']))
799799
return False
800800
else:
801801
mkdirs(cov_paths, cargs)
@@ -839,18 +839,18 @@ def is_bin_gcov_enabled(binary, cargs):
839839
False, cargs, WANT_OUTPUT, False, "")[1]:
840840
if ' __gcov' in line:
841841
if cargs.validate_args or cargs.gcov_check or cargs.gcov_check_bin:
842-
print "[+] Binary '%s' is compiled with code coverage support via gcc." % binary
842+
print("[+] Binary '%s' is compiled with code coverage support via gcc." % binary)
843843
rv = True
844844
break
845845

846846
if '__llvm_gcov' in line:
847847
if cargs.validate_args or cargs.gcov_check or cargs.gcov_check_bin:
848-
print "[+] Binary '%s' is compiled with code coverage support via llvm." % binary
848+
print("[+] Binary '%s' is compiled with code coverage support via llvm." % binary)
849849
rv = True
850850
break
851851

852852
if not rv and cargs.gcov_check_bin:
853-
print "[*] Binary '%s' is not compiled with code coverage support." % binary
853+
print("[*] Binary '%s' is not compiled with code coverage support." % binary)
854854

855855
return rv
856856

@@ -878,26 +878,26 @@ def check_requirements(cargs):
878878
genhtml = which ( cargs.genhtml_path )
879879

880880
if ( lcov == None or gcov == None):
881-
print "Required command not found :"
881+
print("Required command not found :")
882882
else:
883883
if (genhtml == None and not cargs.disable_lcov_web):
884-
print "Required command not found :"
884+
print("Required command not found :")
885885
else:
886886
return True
887887

888888
if ( lcov == None ):
889-
print "[*] lcov command does not exist : %s" % (cargs.lcov_path)
889+
print("[*] lcov command does not exist : %s" % (cargs.lcov_path))
890890
if ( genhtml == None and not cargs.disable_lcov_web):
891-
print "[*] genhtml command does not exist : %s" % (cargs.genhtml_path)
891+
print("[*] genhtml command does not exist : %s" % (cargs.genhtml_path))
892892
if ( gcov == None ):
893-
print "[*] gcov command does not exist : %s" % (cargs.gcov_path)
893+
print("[*] gcov command does not exist : %s" % (cargs.gcov_path))
894894

895895
return False
896896

897897
def is_gcov_enabled(cargs):
898898

899899
if not is_exe(cargs.readelf_path):
900-
print "[*] Need a valid path to readelf, use --readelf-path"
900+
print("[*] Need a valid path to readelf, use --readelf-path")
901901
return False
902902

903903
if cargs.coverage_cmd:
@@ -917,21 +917,21 @@ def is_gcov_enabled(cargs):
917917
break
918918

919919
if not found_exec:
920-
print "[*] Could not find an executable binary " \
921-
"--coverage-cmd '%s'" % cargs.coverage_cmd
920+
print("[*] Could not find an executable binary " \
921+
"--coverage-cmd '%s'" % cargs.coverage_cmd)
922922
return False
923923

924924
if not cargs.disable_gcov_check and not found_code_cov_binary:
925-
print "[*] Could not find an executable binary with code " \
925+
print("[*] Could not find an executable binary with code " \
926926
"coverage support ('-fprofile-arcs -ftest-coverage') " \
927-
"in --coverage-cmd '%s'" % cargs.coverage_cmd
927+
"in --coverage-cmd '%s'" % cargs.coverage_cmd)
928928
return False
929929

930930
elif cargs.gcov_check_bin:
931931
if not is_bin_gcov_enabled(cargs.gcov_check_bin, cargs):
932932
return False
933933
elif cargs.gcov_check:
934-
print "[*] Either --coverage-cmd or --gcov-check-bin required in --gcov-check mode"
934+
print("[*] Either --coverage-cmd or --gcov-check-bin required in --gcov-check mode")
935935
return False
936936

937937
return True
@@ -943,12 +943,12 @@ def validate_cargs(cargs):
943943
return False
944944
else:
945945
if not cargs.func_search and not cargs.line_search:
946-
print "[*] Must set --coverage-cmd or --func-search/--line-search"
946+
print("[*] Must set --coverage-cmd or --func-search/--line-search")
947947
return False
948948

949949
if cargs.code_dir:
950950
if not is_dir(cargs.code_dir):
951-
print "[*] --code-dir path does not exist"
951+
print("[*] --code-dir path does not exist")
952952
return False
953953

954954
### make sure code coverage support is compiled in
@@ -957,31 +957,31 @@ def validate_cargs(cargs):
957957

958958
else:
959959
if not cargs.func_search and not cargs.line_search:
960-
print "[*] Must set --code-dir unless using --func-search " \
961-
"against existing afl-cov directory"
960+
print("[*] Must set --code-dir unless using --func-search " \
961+
"against existing afl-cov directory")
962962
return False
963963

964964
if cargs.func_search or cargs.line_search:
965965
if not cargs.afl_fuzzing_dir:
966-
print "[*] Must set --afl-fuzzing-dir"
966+
print("[*] Must set --afl-fuzzing-dir")
967967
return False
968968
if cargs.func_search and '()' not in cargs.func_search:
969969
cargs.func_search += '()'
970970
if cargs.line_search and not cargs.src_file:
971-
print "[*] Must set --src-file in --line-search mode"
971+
print("[*] Must set --src-file in --line-search mode")
972972
return False
973973

974974
if cargs.live and not cargs.ignore_core_pattern:
975975
if not check_core_pattern():
976976
return False
977977

978978
if not cargs.live and not is_dir(cargs.afl_fuzzing_dir):
979-
print "[*] It doesn't look like directory '%s' exists" \
980-
% (cargs.afl_fuzzing_dir)
979+
print("[*] It doesn't look like directory '%s' exists" \
980+
% (cargs.afl_fuzzing_dir))
981981
return False
982982

983983
if cargs.disable_lcov_web and cargs.lcov_web_all:
984-
print "[*] --disable-lcov-web and --lcov-web-all are incompatible"
984+
print("[*] --disable-lcov-web and --lcov-web-all are incompatible")
985985
return False
986986

987987
return True
@@ -997,24 +997,24 @@ def gcno_files_exist(cargs):
997997
if filename[-5:] == '.gcno':
998998
found_code_coverage_support = True
999999
if not found_code_coverage_support:
1000-
print "[*] Could not find any *.gcno files in --code-dir " \
1000+
print("[*] Could not find any *.gcno files in --code-dir " \
10011001
"'%s', is code coverage ('-fprofile-arcs -ftest-coverage') " \
1002-
"compiled in?" % cargs.code_dir
1002+
"compiled in?" % cargs.code_dir)
10031003
return False
10041004
return True
10051005

10061006
def is_afl_running(cargs):
10071007
while not is_dir(cargs.afl_fuzzing_dir):
10081008
if not cargs.background:
1009-
print "[-] Sleep for %d seconds for AFL fuzzing directory to be created..." \
1010-
% cargs.sleep
1009+
print("[-] Sleep for %d seconds for AFL fuzzing directory to be created..." \
1010+
% cargs.sleep)
10111011
time.sleep(cargs.sleep)
10121012

10131013
### if we make it here then afl-fuzz is presumably running
10141014
while not is_afl_fuzz_running(cargs):
10151015
if not cargs.background:
1016-
print "[-] Sleep for %d seconds waiting for afl-fuzz to be started...." \
1017-
% cargs.sleep
1016+
print("[-] Sleep for %d seconds waiting for afl-fuzz to be started...." \
1017+
% cargs.sleep)
10181018
time.sleep(cargs.sleep)
10191019
return
10201020

@@ -1053,7 +1053,7 @@ def is_dir(dpath):
10531053

10541054
def logr(pstr, log_file, cargs):
10551055
if not cargs.background and not cargs.quiet:
1056-
print " " + pstr
1056+
print(" " + pstr)
10571057
append_file(pstr, log_file)
10581058
return
10591059

@@ -1066,22 +1066,22 @@ def stop_afl(cargs):
10661066
### is also stopped.
10671067

10681068
if not cargs.afl_fuzzing_dir:
1069-
print "[*] Must set --afl-fuzzing-dir"
1069+
print("[*] Must set --afl-fuzzing-dir")
10701070
return False
10711071

10721072
if not is_dir(cargs.afl_fuzzing_dir):
1073-
print "[*] Doesn't look like AFL fuzzing directory '%s' exists." \
1074-
% cargs.afl_fuzzing_dir
1073+
print("[*] Doesn't look like AFL fuzzing directory '%s' exists." \
1074+
% cargs.afl_fuzzing_dir)
10751075
return False
10761076

10771077
if os.path.exists(cargs.afl_fuzzing_dir + '/fuzzer_stats'):
10781078
afl_pid = get_running_pid(cargs.afl_fuzzing_dir + '/fuzzer_stats',
10791079
'fuzzer_pid\s+\:\s+(\d+)')
10801080
if afl_pid:
1081-
print "[+] Stopping running afl-fuzz instance, PID: %d" % afl_pid
1081+
print("[+] Stopping running afl-fuzz instance, PID: %d" % afl_pid)
10821082
os.kill(afl_pid, signal.SIGTERM)
10831083
else:
1084-
print "[-] No running afl-fuzz instance"
1084+
print("[-] No running afl-fuzz instance")
10851085
rv = False
10861086
else:
10871087
found = False
@@ -1090,12 +1090,12 @@ def stop_afl(cargs):
10901090
if os.path.exists(stats_file):
10911091
afl_pid = get_running_pid(stats_file, 'fuzzer_pid\s+\:\s+(\d+)')
10921092
if afl_pid:
1093-
print "[+] Stopping running afl-fuzz instance, PID: %d" \
1094-
% afl_pid
1093+
print("[+] Stopping running afl-fuzz instance, PID: %d" \
1094+
% afl_pid)
10951095
os.kill(afl_pid, signal.SIGTERM)
10961096
found = True
10971097
if not found:
1098-
print "[-] No running afl-fuzz instance"
1098+
print("[-] No running afl-fuzz instance")
10991099
rv = False
11001100

11011101
return rv
@@ -1112,8 +1112,8 @@ def check_core_pattern():
11121112
with open(core_pattern_file, 'r') as f:
11131113
if f.readline().rstrip()[0] == '|':
11141114
### same logic as implemented by afl-fuzz itself
1115-
print "[*] afl-fuzz requires 'echo core >%s'" \
1116-
% core_pattern_file
1115+
print("[*] afl-fuzz requires 'echo core >%s'" \
1116+
% core_pattern_file)
11171117
rv = False
11181118
return rv
11191119

0 commit comments

Comments
 (0)