-
Notifications
You must be signed in to change notification settings - Fork 4
/
read_and_parse.py
206 lines (200 loc) · 8.08 KB
/
read_and_parse.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import linecache
if __name__ == "__main__":
filename = "testeM4"
txt_file = open("./json_results/Androbugs/"+filename+".txt", "r")
lines = txt_file.readlines()
line_counter = 1
critical = []
warning = []
notice = []
info = []
critical_status = False
warning_status = False
notice_status = False
info_status = False
add = True
for line in lines:
if line.startswith("[Critical]"):
critical.append("Critical")
critical_status = True
warning_status = False
notice_status = False
info_status = False
add = True
if line.startswith("[Warning]"):
warning.append("Warning")
critical_status = False
warning_status = True
notice_status = False
info_status = False
add = True
if line.startswith("[Notice]"):
notice.append("Notice")
critical_status = False
warning_status = False
notice_status = True
info_status = False
add = True
if line.startswith("[Info]"):
info.append("Info")
critical_status = False
warning_status = False
notice_status = False
info_status = True
add = True
if line.startswith("-------"):
add = False
if critical_status and add:
critical.append(line_counter)
if warning_status and add:
warning.append(line_counter)
if notice_status and add:
notice.append(line_counter)
if info_status and add:
info.append(line_counter)
line_counter = line_counter + 1
print(critical)
print(warning)
print(notice)
print(info)
# now let's try to put everything on a JSON format :-)
json_file = open("./json_results/Androbugs/"+filename+".json", "w")
#json_file.write("{")
#json_file.write("\"results\": ")
#json_file.write("{\"M1\": [")
text2write = ""
is_first = True
hasM1 = False
hasM2 = False
hasM3 = False
hasM4 = False
hasM5 = False
hasM6 = False
hasM7 = False
hasM8 = False
hasM9 = False
hasM10 = False
json_file.write("{")
for critical_line in critical:
if critical_line == 'Critical' and is_first:
json_file.write("\"M1\": [")
text2write = text2write + "{\"vulnerability\": \""
is_first = False
hasM1 = True
continue
if critical_line == 'Critical' and not is_first:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Critical\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}, {\"vulnerability\": \""
else:
what2write = linecache.getline("./json_results/Androbugs/"+filename+".txt", critical_line)
text2write = text2write + what2write.replace('"', '\\"')[:-1]
if hasM1:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Critical\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}]"
json_file.write(text2write)
# print(text2write)
json_file.write(",")
#json_file.write("\"M2\": [")
text2write = ""
is_first = True
for warning_line in warning:
if warning_line == 'Warning' and is_first:
json_file.write("\"M2\": [")
text2write = text2write + "{\"vulnerability\": \""
is_first = False
hasM2 = True
continue
if warning_line == 'Warning' and not is_first:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Warning\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}, {\"vulnerability\": \""
else:
what2write = linecache.getline("./json_results/Androbugs/"+filename+".txt", warning_line)
text2write = text2write + what2write.replace('"', '\\"')[:-1]
if hasM2:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Critical\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}]"
json_file.write(text2write)
# print(text2write)
json_file.write(",")
#json_file.write("\"M3\": [")
text2write = ""
is_first = True
for notice_line in notice:
if notice_line == 'Notice' and is_first:
json_file.write("\"M3\": [")
text2write = text2write + "{\"vulnerability\": \""
is_first = False
hasM3 = True
continue
if notice_line == 'Notice' and not is_first:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Notice\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}, {\"vulnerability\": \""
else:
what2write = linecache.getline("./json_results/Androbugs/"+filename+".txt",
notice_line)
text2write = text2write + what2write.replace('"', '\\"')[:-1]
if hasM3:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Critical\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}]"
json_file.write(text2write)
# print(text2write)
json_file.write(",")
#json_file.write("\"M4\": [")
text2write = ""
is_first = True
for info_line in info:
if info_line == 'Info' and is_first:
json_file.write("\"M4\": [")
text2write = text2write + "{\"vulnerability\": \""
is_first = False
hasM4 = True
continue
if info_line == 'Info' and not is_first:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Info\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}, {\"vulnerability\": \""
else:
what2write = linecache.getline("./json_results/Androbugs/"+filename+".txt",
info_line)
text2write = text2write + what2write.replace('"', '\\"')[:-1]
if hasM4:
text2write = text2write + "\", "
text2write = text2write + "\"details\": \"\", \"severity\": \"Critical\", \"detectedby\": [\"Androbugs\"],"
text2write = text2write + "\"feedback\": [{\"url\":\"\"}, {\"video\":\"\"}, {\"book\":\"\"}, {\"other\":\"\"}]"
text2write = text2write + "}"
# print(text2write)
json_file.write(text2write)
json_file.write("]")
if hasM5:
json_file.write(", \"M5\": [")
json_file.write("],")
if hasM6:
json_file.write(", \"M6\": [")
json_file.write("],")
if hasM7:
json_file.write(", \"M7\": [")
json_file.write("],")
if hasM8:
json_file.write(", \"M8\": [")
json_file.write("],")
if hasM9:
json_file.write(", \"M9\": [")
json_file.write("],")
if hasM10:
json_file.write(", \"M10\": [")
json_file.write("]")
json_file.write("}")
#json_file.write("}")