# Path: afl_utils/afl_collect.py
# def show_info():
# def get_fuzzer_instances(sync_dir, crash_dirs=True):
# def get_crash_directories(sync_dir, fuzzer_instances):
# def get_queue_directories(sync_dir, fuzzer_instances):
# def get_samples_from_dir(sample_subdir, abs_path=False):
# def collect_samples(sync_dir, fuzzer_instances):
# def build_sample_index(sync_dir, out_dir, fuzzer_instances, db=None, min_filename=False, omit_fuzzer_name=False):
# def copy_samples(sample_index):
# def generate_sample_list(list_filename, files_collected):
# def stdin_mode(target_cmd):
# def generate_gdb_exploitable_script(script_filename, sample_index, target_cmd, script_id=0, intermediate=False):
# def execute_gdb_script(out_dir, script_filename, num_samples, num_threads):
# def main(argv):
# 
# Path: afl_utils/afl_vcrash.py
# def show_info():
# def verify_samples(num_threads, samples, target_cmd, timeout_secs=60):
# def remove_samples(crash_samples, quiet=True):
# def build_target_cmd(target_cmdline):
# def main(argv):
# 
# Path: afl_utils/AflThread.py
# class VerifyThread(threading.Thread):
# class GdbThread(threading.Thread):
# class AflTminThread(threading.Thread):
#     def __init__(self, thread_id, timeout_secs, target_cmd, in_queue, out_queue, in_queue_lock, out_queue_lock):
#     def run(self):
#     def __init__(self, thread_id, gdb_cmd, out_dir, grep_for, out_queue, out_queue_lock):
#     def run(self):
#     def __init__(self, thread_id, tmin_cmd, target_cmd, output_dir, in_queue, out_queue, in_queue_lock, out_queue_lock):
#     def run(self):
# 
# Path: afl_utils/AflPrettyPrint.py
# class clr:
#     # taken from AFL's debug.h
#     BLK = "\x1b[0;30m"
#     RED = "\x1b[0;31m"
#     GRN = "\x1b[0;32m"
#     BRN = "\x1b[0;33m"
#     BLU = "\x1b[0;34m"
#     MGN = "\x1b[0;35m"
#     CYA = "\x1b[0;36m"
#     NOR = "\x1b[0;37m"
#     GRA = "\x1b[1;30m"
#     LRD = "\x1b[1;31m"
#     LGN = "\x1b[1;32m"
#     YEL = "\x1b[1;33m"
#     LBL = "\x1b[1;34m"
#     PIN = "\x1b[1;35m"
#     LCY = "\x1b[1;36m"
#     BRI = "\x1b[1;37m"
#     RST = "\x1b[0m"
# 
# def print_ok(msg_str):
#     print("{0}[*] {1}{2}".format(clr.LGN, clr.RST, msg_str))
# 
# def print_warn(msg_str):
#     print("{0}[!] {1}{2}".format(clr.YEL, clr.RST, msg_str))
# 
# def print_err(msg_str):
#     print("{0}[!] {1}{2}".format(clr.LRD, clr.RST, msg_str))


import argparse
import os
import shutil
import subprocess
import sys
import threading
import time
import queue
import afl_utils
from afl_utils import afl_collect, afl_vcrash, AflThread
from afl_utils.AflPrettyPrint import clr, print_ok, print_warn, print_err
    invalid_samples, timeout_samples = afl_vcrash.verify_samples(num_threads, input_files, target_cmd,
                                                                 timeout_secs=timeout)

    invalid_sample_set = set(invalid_samples+timeout_samples)
    input_sample_set = set(input_files)

    crashes_set = input_sample_set - invalid_sample_set
    crashes = list(crashes_set)

    if len(crashes) > 0:
        if not os.path.exists(crash_dir):
            os.makedirs(crash_dir, exist_ok=True)

        for c in crashes:
            shutil.move(c, os.path.join(crash_dir, os.path.basename(c)))

        print_warn("Moved %d crash samples from the corpus to %s." % (len(crashes), crash_dir))

        if len(timeout_samples) > 0:
            if not os.path.exists(timeout_dir):
                os.makedirs(timeout_dir, exist_ok=True)

            for t in timeout_samples:
                shutil.move(t, os.path.join(timeout_dir, os.path.basename(t)))

            print_warn("Moved %d timeouts from the corpus to %s." % (len(timeout_samples), timeout_dir))
    return


def afl_reseed(sync_dir, coll_dir):

# Path: afl_utils/afl_collect.py
# def show_info():
# def get_fuzzer_instances(sync_dir, crash_dirs=True):
# def get_crash_directories(sync_dir, fuzzer_instances):
# def get_queue_directories(sync_dir, fuzzer_instances):
# def get_samples_from_dir(sample_subdir, abs_path=False):
# def collect_samples(sync_dir, fuzzer_instances):
# def build_sample_index(sync_dir, out_dir, fuzzer_instances, db=None, min_filename=False, omit_fuzzer_name=False):
# def copy_samples(sample_index):
# def generate_sample_list(list_filename, files_collected):
# def stdin_mode(target_cmd):
# def generate_gdb_exploitable_script(script_filename, sample_index, target_cmd, script_id=0, intermediate=False):
# def execute_gdb_script(out_dir, script_filename, num_samples, num_threads):
# def main(argv):
# 
# Path: afl_utils/afl_vcrash.py
# def show_info():
# def verify_samples(num_threads, samples, target_cmd, timeout_secs=60):
# def remove_samples(crash_samples, quiet=True):
# def build_target_cmd(target_cmdline):
# def main(argv):
# 
# Path: afl_utils/AflThread.py
# class VerifyThread(threading.Thread):
# class GdbThread(threading.Thread):
# class AflTminThread(threading.Thread):
#     def __init__(self, thread_id, timeout_secs, target_cmd, in_queue, out_queue, in_queue_lock, out_queue_lock):
#     def run(self):
#     def __init__(self, thread_id, gdb_cmd, out_dir, grep_for, out_queue, out_queue_lock):
#     def run(self):
#     def __init__(self, thread_id, tmin_cmd, target_cmd, output_dir, in_queue, out_queue, in_queue_lock, out_queue_lock):
#     def run(self):
# 
# Path: afl_utils/AflPrettyPrint.py
# class clr:
#     # taken from AFL's debug.h
#     BLK = "\x1b[0;30m"
#     RED = "\x1b[0;31m"
#     GRN = "\x1b[0;32m"
#     BRN = "\x1b[0;33m"
#     BLU = "\x1b[0;34m"
#     MGN = "\x1b[0;35m"
#     CYA = "\x1b[0;36m"
#     NOR = "\x1b[0;37m"
#     GRA = "\x1b[1;30m"
#     LRD = "\x1b[1;31m"
#     LGN = "\x1b[1;32m"
#     YEL = "\x1b[1;33m"
#     LBL = "\x1b[1;34m"
#     PIN = "\x1b[1;35m"
#     LCY = "\x1b[1;36m"
#     BRI = "\x1b[1;37m"
#     RST = "\x1b[0m"
# 
# def print_ok(msg_str):
#     print("{0}[*] {1}{2}".format(clr.LGN, clr.RST, msg_str))
# 
# def print_warn(msg_str):
#     print("{0}[!] {1}{2}".format(clr.YEL, clr.RST, msg_str))
# 
# def print_err(msg_str):
#     print("{0}[!] {1}{2}".format(clr.LRD, clr.RST, msg_str))


# Path: afl_utils/afl_minimize.py
import argparse
import os
import shutil
import subprocess
import sys
import threading
import time
import queue
import afl_utils
from afl_utils import afl_collect, afl_vcrash, AflThread
from afl_utils.AflPrettyPrint import clr, print_ok, print_warn, print_err

    invalid_samples, timeout_samples = afl_vcrash.verify_samples(num_threads, input_files, target_cmd,
                                                                 timeout_secs=timeout)

    invalid_sample_set = set(invalid_samples+timeout_samples)
    input_sample_set = set(input_files)

    crashes_set = input_sample_set - invalid_sample_set
    crashes = list(crashes_set)

    if len(crashes) > 0:
        if not os.path.exists(crash_dir):
            os.makedirs(crash_dir, exist_ok=True)

        for c in crashes:
            shutil.move(c, os.path.join(crash_dir, os.path.basename(c)))

        print_warn("Moved %d crash samples from the corpus to %s." % (len(crashes), crash_dir))

        if len(timeout_samples) > 0:
            if not os.path.exists(timeout_dir):
                os.makedirs(timeout_dir, exist_ok=True)

            for t in timeout_samples:
                shutil.move(t, os.path.join(timeout_dir, os.path.basename(t)))

            print_warn("Moved %d timeouts from the corpus to %s." % (len(timeout_samples), timeout_dir))
    return


def afl_reseed(sync_dir, coll_dir):

    fuzzer_queues = afl_collect.get_fuzzer_instances(sync_dir, crash_dirs=False)