# 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 sys
import subprocess
import afl_utils
from afl_utils.AflPrettyPrint import clr, print_ok, print_warn, print_err
        # strip pulled dirs
        fuzzers = (fuzzer for fuzzer in fuzzers if not fuzzer.endswith('.sync'))
        return fuzzers

    def rsync_put(self, local_path, remote_path, rsync_options=list(_rsync_default_options), rsync_excludes=list([])):
        cmd = self.__prepare_rsync_commandline(local_path, remote_path, rsync_options, rsync_excludes)
        return self.__invoke_rsync(cmd)

    def rsync_get(self, remote_path, local_path, rsync_options=list(_rsync_default_options), rsync_excludes=list([])):
        cmd = self.__prepare_rsync_commandline(local_path, remote_path, rsync_options, rsync_excludes, True)
        return self.__invoke_rsync(cmd)

    def push(self):
        fuzzers = self.__get_fuzzers()

        # restrict to certain session, if requested
        if self.fuzzer_config['session'] is not None:
            fuzzers = (fuzzer for fuzzer in fuzzers if fuzzer.startswith(self.fuzzer_config['session']))

        excludes = self.__excludes

        if self.fuzzer_config['exclude_crashes']:
            excludes += ['crashes*/']

        if self.fuzzer_config['exclude_hangs']:
            excludes += ['hangs*/']

        for f in fuzzers:
            local_path = os.path.join(self.fuzzer_config['sync_dir'], f)
            remote_path = os.path.join(self.server_config['remote_path'], f)

# 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_sync.py
import argparse
import os
import sys
import subprocess
import afl_utils
from afl_utils.AflPrettyPrint import clr, print_ok, print_warn, print_err

        # strip pulled dirs
        fuzzers = (fuzzer for fuzzer in fuzzers if not fuzzer.endswith('.sync'))
        return fuzzers

    def rsync_put(self, local_path, remote_path, rsync_options=list(_rsync_default_options), rsync_excludes=list([])):
        cmd = self.__prepare_rsync_commandline(local_path, remote_path, rsync_options, rsync_excludes)
        return self.__invoke_rsync(cmd)

    def rsync_get(self, remote_path, local_path, rsync_options=list(_rsync_default_options), rsync_excludes=list([])):
        cmd = self.__prepare_rsync_commandline(local_path, remote_path, rsync_options, rsync_excludes, True)
        return self.__invoke_rsync(cmd)

    def push(self):
        fuzzers = self.__get_fuzzers()

        # restrict to certain session, if requested
        if self.fuzzer_config['session'] is not None:
            fuzzers = (fuzzer for fuzzer in fuzzers if fuzzer.startswith(self.fuzzer_config['session']))

        excludes = self.__excludes

        if self.fuzzer_config['exclude_crashes']:
            excludes += ['crashes*/']

        if self.fuzzer_config['exclude_hangs']:
            excludes += ['hangs*/']

        for f in fuzzers:
            local_path = os.path.join(self.fuzzer_config['sync_dir'], f)
            remote_path = os.path.join(self.server_config['remote_path'], f)

            print_ok('Pushing {} -> {}.sync'.format(local_path, remote_path))