Skip to content

Instantly share code, notes, and snippets.

@adrianherrera
Last active July 5, 2020 11:50
Show Gist options
  • Save adrianherrera/5fbfad12cd08a9a3c5696fd755f7c975 to your computer and use it in GitHub Desktop.
Save adrianherrera/5fbfad12cd08a9a3c5696fd755f7c975 to your computer and use it in GitHub Desktop.
Create a libFuzzer-style merge file from afl-showmap
#!/usr/bin/env python3
"""
Create a libFuzzer-style merge from afl-showmap.
Author: Adrian Herrera
"""
from argparse import ArgumentParser
import os
def parse_args():
"""Parse command-line arguments."""
parser = ArgumentParser(description='libFuzzer merge control file from AFL '
'showmap output')
parser.add_argument('-o', '--output', required=True,
help='Path to output file')
parser.add_argument('bitmap', nargs='+',
help='Path to bitmap files generated by afl-showmap')
return parser.parse_args()
def parse_bitmap(bitmap):
"""Parse an afl-showkap bitmap file."""
tuples = []
with open(bitmap, 'r') as inf:
for line in inf:
edge, count = line.split(':')
tuples += [int(edge)] * int(count)
return tuples
def main():
"""The main function."""
args = parse_args()
coverage = {}
for path in args.bitmap:
coverage[os.path.realpath(path)] = parse_bitmap(path)
with open(args.output, 'w') as outf:
outf.write('%d\n' % len(coverage))
outf.write('0\n')
for f in coverage:
outf.write('%s\n' % f)
for i, (f, cov) in enumerate(coverage.items()):
outf.write('STARTED %d %d\n' % (i, os.path.getsize(f)))
outf.write('FT \n')
outf.write('COV %s\n' % ' '.join(('%d' % edge for edge in cov)))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment