#!/usr/bin/env pypy

'''
Frontend for driller, AFL invokes this script when it's having trouble making any progress.
'''

import angr
import driller

import argparse
import sys
import logging

l = logging.getLogger("drill")
l.setLevel("INFO")

def main(argc, argv):
    parser = argparse.ArgumentParser(description="Increase AFL's code coverage")
    
    parser.add_argument("-b", dest="binary", 
                        type=str, 
                        metavar="<binary>", 
                        help="binary executable",
                        required=True)

    parser.add_argument("-i", 
                        dest="in_dir", 
                        type=str, 
                        metavar="<in_dir>", 
                        help="input directory", 
                        required=True)

    parser.add_argument("-o", 
                        dest="out_dir", 
                        type=str, 
                        metavar="<out_dir>", 
                        help="output directory",
                        required=True)

    parser.add_argument("-f", 
                        dest="fuzz_bitmap", 
                        type=str, 
                        metavar="<fuzz_bitmap>", 
                        help="AFL's fuzz bitmap file",
                        required=True)

    parser.add_argument("-q",
                        dest="qemu_dir",
                        type=str,
                        metavar="<qemu_dir>",
                        help="installation directory of driller's qemus",
                        required=True)

    parser.add_argument("-j",
                        dest="proc_cnt",
                        type=int,
                        metavar="<proc_cnt>",
                        help="number of processes to invoke",
                        default=1)

    parser.add_argument("-s",
                        dest="sync_dir",
                        type=str,
                        metavar="<sync_dir>",
                        help="AFL's sync directory",
                        default=None)
        

    args = parser.parse_args()
    
    binary      = args.binary
    in_dir      = args.in_dir
    out_dir     = args.out_dir
    fuzz_bitmap = args.fuzz_bitmap
    qemu_dir    = args.qemu_dir
    proc_cnt    = args.proc_cnt
    sync_dir    = args.sync_dir

    try:
        d = driller.Driller(binary, in_dir, out_dir, fuzz_bitmap, qemu_dir, proc_cnt, sync_dir)
    except driller.DrillerConservativeStartup:
        l.info("another driller process has already been invoked recently")
        return 1

    d.drill()

    return 0

if __name__ == "__main__":
    sys.exit(main(len(sys.argv), sys.argv))

@@ -2549,16 +2549,37 @@
 recently
+, refusing to spin up
 %22)%0A     

Make drill's conservative startup message more clear