aboutsummaryrefslogtreecommitdiffstats
path: root/mutator.py
blob: 376140cbaea505da36d368009284dfeabe320fde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/python3

import argparse
import sys
from subprocess import call

class Colors:
    purple = '\033[95m'
    blue = '\033[94m'
    green = '\033[92m'
    yellow = '\033[93m'
    red = '\033[91m'
    grey = '\033[1;37m'
    darkgrey = '\033[1;30m'
    cyan = '\033[1;36m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

class ArgParser(object):
    def __init__(self):
        self.inputs = []
        self.outputs = []
        self.opts = []
        self.copts = []
        self.command = []
        self.pretty = bool
        parser = argparse.ArgumentParser()
        parser.add_argument("-help", action='store_true', help="display the driver's help", default=False)
        parser.add_argument("-f", "--file", type=str, help="run an action file")
        parser.add_argument("-c", "--command", type=str, help="run a command")
        parser.add_argument("-v", "--version", action='store_true', help="display version info", default=False)
        parser.add_argument("-i", "--input", type=str, help="the input file(s)")
        parser.add_argument("-o", "--output", type=str, help="the output file(s)")
        parser.add_argument("-pp", "--print-pretty", action='store_true', help="print pretty simple text reports", default=False)
        parser.add_argument("-t", "--test", type=str, help="runs the tests on the built executables")
        parser.add_argument("-opts", "--options", type=str, help="pass clang options to the executables")
        parser.add_argument("-copts", "--custom-options", type=str, help="runs the tests on the built executables")
        self.args = parser.parse_args()

    def run(self):
        if self.args.file  is not None:
            self.parseActionFile(self.args.file)
        if self.args.command is not None:
            self.runCommand(self.args.command)

    def runTest(self):
        pass

    def parseActionFile(self, action_file_path):
        line_number = int()
        action_file = open(action_file_path)
        self.inputs = str
        self.outputs = str
        self.opts = str
        self.copts = str
        self.command = str
        self.logfile = str
        self.pretty = bool
        self.exename = str
        self.endaction = str
        self.action_name = str
        for line in action_file:
            line_number += 1
            pos = line.find("action_name:", 0, len(line))
            if pos == 0:
                self.action_name = line[pos+len("action_name:"):-1]
                print(Colors.green + "action name: " + Colors.cyan + self.action_name + Colors.ENDC)
            pos = line.find("executable_name:", 0, len(line))
            if pos == 0:
                self.exename = line[pos+len("executable_name:"):-1]
                print(Colors.green + "executable_name: " + Colors.cyan + self.exename + Colors.ENDC)
            pos = line.find("exec_opts:", 0, len(line))
            if pos == 0:
                self.copts = line[pos+len("exec_opts:"):-1]
                print(Colors.green + "exec options: " + Colors.cyan + self.copts + Colors.ENDC)
            pos = line.find("in_files:", 0, len(line))
            if pos == 0:
                self.inputs = line[pos+len("in_files:"):-1]
                print(Colors.green + "input files: " + Colors.cyan + self.inputs + Colors.ENDC)
            pos = line.find("libtooling_options:", 0, len(line))
            if pos == 0:
                self.opts = line[pos+len("libtooling_options:"):-1]
                print(Colors.green + "libtooling options: " + Colors.cyan + self.opts  + Colors.ENDC)
            pos = line.find("out_files:", 0, len(line))
            if pos == 0:
                self.outputs = line[pos+len("out_files:"):-1]
                print(Colors.green + "output files: " + Colors.cyan + self.outputs + Colors.ENDC)
            pos = line.find("log_files:", 0, len(line))
            if pos == 0:
                self.logfile = line[pos+len("log_files:"):-1]
                print(Colors.green + "log files: " + Colors.cyan + self.logfile + Colors.ENDC)
            pos = line.find("print_pretty:", 0, len(line))
            if pos == 0:
                if line[pos+len("print_pretty:"):-1] == "true": self.pretty = True
                elif line[pos+len("print_pretty:"):-1] == "false": self.pretty = False
                else: raise Exception(Colors.red + repr(line_number) + " : " + "invalid value for a boolean switch. should be true or false." + Colors.ENDC)
                print(Colors.green + "pretty print: " + Colors.cyan + repr(self.pretty) + Colors.ENDC)
            pos = line.find("end_action:", 0, len(line))
            if pos == 0:
                self.endaction = line[pos+len("end_action:"):-1]
                print(Colors.green + "end action: " + Colors.cyan + self.endaction + Colors.ENDC)

    def runActionFile(self):
        pass

    def printVersionInfo(self):
        pass

    def runCommand(self, command):
        if command == "clean":
            call(["make", "clean"])
        elif command == "build":
            call(["make", "all"])
        elif command == "install":
            call(["make", "install"])
        elif command == "format":
            pass
        elif command == "test":
            pass
        elif command == "build-all":
            call(["make", "build-all"])
        elif command == "m0":
            pass
        elif command == "m1":
            pass
        elif command == "m2":
            pass
        elif command == "bruiser":
            pass
        elif command == "obfuscator":
            pass
        elif command == "safercpp":
            pass
        else:
            raise Exception(Colors.red + "unknown command. for a list of valid commands run with -h." + Colors.ENDC);


def main():
    argparser = ArgParser()
    argparser.run()

if __name__ == "__main__":
    main()