Ejemplo n.º 1
0
from core.input_parser import add_repair_tool
from core.repair_tools.genprog import GenProg


class AE(GenProg):
    """GenProg"""

    def __init__(self, **kwargs):
        super(AE, self).__init__(name="AE", **kwargs)


def ae_args(input_parser):
    input_parser.add_argument('--version', action='version', version='GenProg/AE e720256')


parser = add_repair_tool("AE", AE, 'Repair the challenge with AE')
ae_args(parser)

Ejemplo n.º 2
0
        arguments["--pos-tests"] = str(pos_tests)
        arguments["--neg-tests"] = str(neg_tests)
        arguments[
            "--rep"] = "cilpatch" if challenge.manifest.multi_file else "c"
        manifest_file = challenge.working_dir / Path('gen_prog_manifest')
        self.write_manifest(challenge.manifest(preprocessed=True),
                            manifest_file)
        arguments["--program"] = str(manifest_file)

        repair_cmd = [str(self.program)]

        for opt, arg in arguments.items():
            if arg != "":
                repair_cmd.extend((opt, arg))
            else:
                repair_cmd.extend([opt])

        return repair_cmd


def genprog_args(input_parser):
    input_parser.add_argument('--version',
                              action='version',
                              version='GenProg e720256')


parser = add_repair_tool("GenProg", GenProg,
                         'Repair the challenge with GenProg')
genprog_args(parser)
Ejemplo n.º 3
0
        test_script_file.chmod(0o777)
        return test_script_file

    def _get_repair_cmd(self, target_file: Path, repair_dir: Path):
        repair_dir.mkdir(parents=True, exist_ok=True)
        args_str = ' '.join([f"{opt} {arg}" for opt, arg in self.tool_configs["args"].items()])

        cre = _regex_file(self.challenge.working_dir, "compile.txt", self.tool_configs["regex"]["compile"])
        gre = _regex_file(self.challenge.working_dir, "good.txt", self.tool_configs["regex"]["good"])
        bre = _regex_file(self.challenge.working_dir, "bad.txt", self.tool_configs["regex"]["bad"])

        test_good = str(self.write_test_script(type="good", regex=str(gre), repair_dir=str(repair_dir)))
        test_bad = str(self.write_test_script(type="bad", regex=str(bre), repair_dir=str(repair_dir)))
        compile_cmd = str(self.write_compile_script(str(cre), repair_dir=str(repair_dir), target_file=str(target_file)))
        modify_cmd = str(self.program)
        modify_cmd = modify_cmd + f" {args_str} {target_file}"
        # fix_cmd += f" --faultpath {fl_out_file}"
        modify_cmd += f" --gcc \"{compile_cmd}\""
        modify_cmd += f" --good \"{test_good}\""
        modify_cmd += f" --bad \"{test_bad}\""

        return modify_cmd


def mut_apr_args(input_parser):
    input_parser.add_argument('--version', action='version', version='MUT-APR')


parser = add_repair_tool("MUT-APR", MutApr, 'Repair challenges with MUT-APR')
mut_apr_args(parser)
Ejemplo n.º 4
0
        return test_script_file

    def write_compile_script(self) -> Path:
        compile_script_file = self.challenge.working_dir / "sos_compile.sh"
        log_file = self.challenge.working_dir / "clog.txt"

        with compile_script_file.open(mode="w") as tsf:
            compile_cmd = self.benchmark.compile(self.challenge,
                                                 coverage=True,
                                                 log_file=log_file,
                                                 gcc=True,
                                                 backup=self.patches_dir,
                                                 fault_localization=True,
                                                 sanity_check=True)
            tsf.write(
                f"#!/bin/bash\ncp {self.tmp_dir / self.target.name} {self.challenge.source / self.target}\n{compile_cmd}"
            )
        compile_script_file.chmod(0o777)
        return compile_script_file


def sosrepair_args(input_parser):
    input_parser.add_argument('--version',
                              action='version',
                              version='SOSRepair 966bb1e')


parser = add_repair_tool("SOSRepair", SOSRepair,
                         'Repair the challenge with SOSRepair')
sosrepair_args(parser)
Ejemplo n.º 5
0
from core.input_parser import add_repair_tool
from core.repair_tools.prophet import Prophet


class Kali(Prophet):
    """Kali"""
    def __init__(self, **kwargs):
        super(Kali, self).__init__(name="Kali", **kwargs)


def kali_args(input_parser):
    input_parser.add_argument('--version',
                              action='version',
                              version='Prophet/Kali')


parser = add_repair_tool("Kali", Kali, 'Repair the challenge with Kali')
kali_args(parser)
Ejemplo n.º 6
0
from core.input_parser import add_repair_tool
from core.repair_tools.prophet import Prophet


class SPR(Prophet):
    """SPR"""
    def __init__(self, **kwargs):
        super(SPR, self).__init__(name="SPR", **kwargs)


def spr_args(input_parser):
    input_parser.add_argument('--version',
                              action='version',
                              version='Prophet/SPR')


parser = add_repair_tool("SPR", SPR, 'Repair the challenge with SPR')
spr_args(parser)
Ejemplo n.º 7
0
        log_file = self.challenge.working_dir / "tlog.txt"

        with test_script_file.open(mode="w") as tsf:
            test_cmd = self.benchmark.test(self.challenge, tests=["$1"], exit_fail=True, log_file=log_file)
            tsf.write(f"#!/bin/bash\n{test_cmd}")
        test_script_file.chmod(0o777)
        return test_script_file

    def _get_repair_cmd(self):
        arguments = self.tool_configs["arguments"]
        arguments["-root"] = str(self.path / arguments["-root"])
        arguments["-prop"] = str(self.path / arguments["-prop"])
        arguments["--manifest_path"] = str(self.write_manifest())
        repair_cmd = "python " + str(self.program)

        for opt, arg in arguments.items():
            if arg != "":
                repair_cmd += f" {opt} {arg}"
            else:
                repair_cmd += f" {opt}"

        return repair_cmd


def flexi_args(input_parser):
    input_parser.add_argument('--version', action='version', version='FlexiRepair 26ccc50')


parser = add_repair_tool("FlexiRepair", FlexiRepair, 'Repair the challenge with FlexiRepair')
flexi_args(parser)
Ejemplo n.º 8
0
        manifest_file = challenge.working_dir / Path('hunk_manifest')
        self.write_manifest(challenge.vuln, manifest_file)
        arguments["--manifest_path"] = str(manifest_file)

        pos_tests, neg_tests = benchmark.count_tests(challenge)

        if int(neg_tests) == 0:
            raise ValueError("No negative tests")

        arguments["--pos_tests"] = str(pos_tests)
        arguments["--neg_tests"] = str(neg_tests)

        repair_cmd = [str(self.program)]

        for opt, arg in arguments.items():
            if arg != "":
                repair_cmd.extend((opt, arg))
            else:
                repair_cmd.extend([opt])

        return repair_cmd


def cquencer_args(input_parser):
    input_parser.add_argument('--version', action='version', version='1')


parser = add_repair_tool("CquenceR", CquenceR,
                         'Repair the challenge with CquenceR')
cquencer_args(parser)
Ejemplo n.º 9
0
        gre = _regex_file(challenge.working_dir, "good.txt", self.tool_configs["regex"]["good"])
        bre = _regex_file(challenge.working_dir, "bad.txt", self.tool_configs["regex"]["bad"])
        log_arg = f"{benchmark.log_file}"

        test_good = benchmark.test(challenge=challenge, regex=str(gre), pos_tests=True, prefix=str(repair_dir),
                                   log_file=log_arg, exit_fail=True)
        test_bad = benchmark.test(challenge=challenge, regex=str(bre), neg_tests=True, prefix=str(repair_dir),
                                  log_file=log_arg, exit_fail=True)
        compile_cmd = benchmark.compile(challenge=challenge, instrumented_files=[str(target_file)], regex=str(cre),
                                        log_file=log_arg, prefix=str(repair_dir), cpp_files=True)

        modify_cmd = str(self.program)
        modify_cmd = modify_cmd + f" {args_str} {target_file}"
        # fix_cmd += f" --faultpath {fl_out_file}"
        modify_cmd += f" --gcc \"python3 {compile_cmd}\""
        modify_cmd += f" --good \"python3 {test_good}\""
        modify_cmd += f" --bad \"python3 {test_bad}\""

        out, err = super().__call__(cmd_str=modify_cmd,
                                    cmd_cwd=repair_dir)

        return out, err


def rsrepair_args(input_parser):
    input_parser.add_argument('--version', action='version', version='RSRepair')


parser = add_repair_tool("RSRepair", RSRepair, 'Repair challenges with RSRepair')
rsrepair_args(parser)
Ejemplo n.º 10
0
        arguments = self.tool_configs["arguments"]
        build_cmd = self.tool_configs["conf"]["build_cmd"]
        test_cmd = self.tool_configs["conf"]["test_cmd"]
        arguments[
            "-dump-passed-candidate"] = self.challenge.working_dir.parent / "passed.txt"
        # Default is 5000 LOC
        #arguments["-first-n-loc"] = "1000"
        wd_pp = self.challenge.working_dir.parent / "workdir"
        (self.challenge.working_dir.parent / 'tests').mkdir(parents=True,
                                                            exist_ok=True)
        arguments["-r"] = str(wd_pp)
        rev_file = self.write_revlog_file()
        repair_cmd = f"{self.tool_configs['program']} {self.write_config_file(rev_file, build_cmd, test_cmd)}"

        for opt, arg in arguments.items():
            if arg != "":
                repair_cmd += f" {opt} {arg}"
            else:
                repair_cmd += f" {opt}"

        return repair_cmd


def prophet_args(input_parser):
    input_parser.add_argument('--version', action='version', version='Prophet')


parser = add_repair_tool("Prophet", Prophet,
                         'Repair the challenge with Prophet')
prophet_args(parser)
Ejemplo n.º 11
0
from core.input_parser import add_repair_tool
from core.repair_tools.sosrepair import SOSRepair


class SearchRepair(SOSRepair):
    """SearchRepair"""
    def __init__(self, **kwargs):
        super(SearchRepair, self).__init__(name="SearchRepair", **kwargs)


def search_repair_args(input_parser):
    input_parser.add_argument('--version',
                              action='version',
                              version='SOSRepair/SearchRepair ae6550e')


parser = add_repair_tool("SearchRepair", SearchRepair,
                         'Repair the challenge with SearchRepair')
search_repair_args(parser)