-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget_internet_flows_apk.py
47 lines (38 loc) · 1.21 KB
/
get_internet_flows_apk.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
# get_internet_flows_apk.py
import os
import json
import csv
path_to_json = ""
mapping_file = ""
out_file = ""
def csv_file_to_dict():
with open(mapping_file, 'r') as infile:
reader = csv.reader(infile, delimiter=';')
dictionary = {rows[0]: rows[1] for rows in reader}
return dictionary
def to_class(loc):
clazz = loc.split('.')[0]
return clazz.replace('/', '.')
def get_apk(content):
for apk in content['apks']:
vercode = apk['vercode']
pkg = apk['pkg']
app_name = pkg + '_' + vercode
for flow in apk['ss']:
sink = '<' + flow['sink']['name'] + '>'
if mapping[sink] == 'INTERNET':
decl_class = to_class(flow['sink']['loc'])
return app_name, decl_class
return None, None
mapping = csv_file_to_dict()
lines = []
for root, dirs, files in os.walk(path_to_json):
for f_name in files:
with open(os.path.join(root, f_name), "r") as f:
content = json.load(f)
apk, clazz = get_apk(content)
if apk is not None:
line = apk + ';' + clazz + '\n'
lines.append(line.encode('utf-8'))
with open(out_file, 'w') as f:
f.writelines(lines)