-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocess_logs.py
executable file
·94 lines (81 loc) · 2.62 KB
/
process_logs.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
86
87
88
89
90
91
92
93
94
import os, sys
brand = ""
path = ""
name = ""
sha256sum = ""
extracted = False
canrun = False
curlpassed = False
webpassed = False
def process_log_dump(LOGPATH, iid):
global brand, name, path, sha256sum
global extracted, canrun, curlpassed, webpassed
lineCount = 0
targetPath = os.path.join(LOGPATH, iid)
if not os.path.exists(targetPath):
print(targetPath, "doesnt exist")
return
with open(targetPath, "rb") as bFile:
for line in bFile:
lineCount += 1
try:
line = line.decode('utf-8',errors='ignore')
if "PATCH LOOP [0]" in line:
extracted = True
if "TARGET HASH" in line:
sha256sum = line.split(":")[1].strip()
if not curlpassed and "failed to parse trace_path" in line:
canrun = False
if "parse completed!" or "[GreenHouseQEMU] IP" in line or curlpassed:
canrun = True
if "[connected]: True" in line:
curlpassed = True
if "[wellformed]: True" in line:
webpassed = True
if line.startswith("copying "):
path = line.split()[1]
name = path.split("/")[-1] # .rsplit(".", 1)[0]
name = name.replace("(", "_").replace(")", "_").replace("-", "_")
dirpath = os.path.dirname(path)
brand = dirpath.split("/")[-1].split("_")[0].strip()
except Exception as e:
print(e)
print(traceback.format_exc())
print("Line: ", lineCount)
()
exit()
bFile.close()
def reset():
global brand
global path
global name
global extracted
global canrun
global curlpassed
global webpassed
global sha256sum
brand = ""
path = ""
name = ""
sha256sum = ""
extracted = False
canrun = False
curlpassed = False
webpassed = False
def main(LOGPATH, NUM_TARGETS):
print("BRAND,HASH,NAME,Unpack,Execute,Connect,Interact")
for i in range(1, NUM_TARGETS+1):
iid = str(i)
reset()
process_log_dump(LOGPATH, iid)
print("%s,%s,%s,%s,%s,%s,%s" % (brand, sha256sum, name, extracted, canrun, curlpassed, webpassed))
if len(sys.argv) < 2:
print("process_logs.py <path-to-log-folder>")
exit()
LOGPATH = sys.argv[1]
#print("Processing", LOGPATH)
if not os.path.exists(LOGPATH):
print("%s doesn't exist" % LOGPATH)
exit()
NUM_TARGETS = len(os.listdir(LOGPATH))
main(LOGPATH, NUM_TARGETS)