-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (52 loc) · 2.35 KB
/
main.py
File metadata and controls
60 lines (52 loc) · 2.35 KB
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
import json
from taint_mini import taintmini
import argparse
import os
def main():
parser = argparse.ArgumentParser(prog="taint-mini",
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-i", "--input", dest="input", metavar="path", type=str, required=True,
help="path of input mini program(s)."
"Single mini program directory or index files will both be fine.")
parser.add_argument("-o", "--output", dest="output", metavar="path", type=str, default="results",
help="path of output results."
"The output file will be stored outside of the mini program directories.")
parser.add_argument("-c", "--config", dest="config", metavar="path", type=str,
help="path of config file."
"See default config file for example. Leave the field empty to include all results.")
parser.add_argument("-j", "--jobs", dest="workers", metavar="number", type=int, default=None,
help="number of workers.")
parser.add_argument("-b", "--bench", dest="bench", action="store_true",
help="enable benchmark data log."
"Default: False")
args = parser.parse_args()
input_path = args.input
output_path = args.output
config_path = args.config
workers = args.workers
bench = args.bench
# test config
config = None
if config_path is None:
# no config given, include all sources and sinks
config = dict()
else:
try:
config = json.load(open(config_path))
except FileNotFoundError:
print(f"[main] error: config not found")
exit(-1)
# test input_path
if os.path.exists(input_path):
if os.path.isfile(input_path):
# handle index files
with open(input_path) as f:
for i in f.readlines():
taintmini.analyze_mini_program(str.strip(i), output_path, config, workers, bench)
elif os.path.isdir(input_path):
# handle single mini program
taintmini.analyze_mini_program(input_path, output_path, config, workers, bench)
else:
print(f"[main] error: invalid input path")
if __name__ == "__main__":
main()