-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
85 lines (76 loc) · 2.03 KB
/
main.py
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
from rule_scanner import parseRules
from log_scanner import parseLogs
import cProfile
import sys, getopt
def main(argv):
RULES = ''
LOGS = ''
try:
opts, args = getopt.getopt(argv,"hl:r:",["rfile=","lfile="])
except getopt.GetoptError:
print('main.py -r <rule_file> -l <log_file>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('main.py -r <rule_file> -l <log_file>')
sys.exit()
elif opt in ("-r", "--rfile"):
RULES = arg
elif opt in ("-l", "--lfile"):
LOGS = arg
print('RULES file is "', RULES)
print('LOGS file is "', LOGS)
profiler = cProfile.Profile()
#RULES = "rules"
#LOGS = "log.txt"
# Parse Logs
L = parseLogs()
print("\n=>PARSING LOGS...")
profiler.enable()
L.parse(LOGS)
profiler.disable()
#profiler.print_stats()
LObj = L.getObjects()
#for k in LObj:
# print(k)
# Parse Rule file/s
print("\n=>PARSING RULES...")
R = parseRules()
profiler.enable()
R.parse(RULES)
#cProfile.runctx('R.parse(RULES)',globals(), locals())
profiler.disable()
#profiler.print_stats()
Obj = R.getObjects()
print("\n==>LOADING OBJECTS...")
for k, v in Obj.items():
print(f"{k}")
# Extract Constraints and verify
C = R.getConstraints()
print("\n=>VERIFYING CONSTRAINTS...")
profiler.enable()
for opr in C:
opr.verify(LObj)
# print(opr)
profiler.disable()
#profiler.print_stats()
# Extract Order and verify
print("\n=>VERIFYING ORDER...")
O = R.getOrder()
print("i/p state")
profiler.enable()
for order in O:
#print(order)
order.verify(LObj)
profiler.disable()
#profiler.print_stats()
# Extract Forbidden and verify
print("\n=>VERIFYING FORBIDDEN API...")
profiler.enable()
F = R.getForbidden()
profiler.disable()
#profiler.print_stats()
print(F)
F.verify(LObj)
if __name__ == "__main__":
main(sys.argv[1:])