-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_hidden.py
315 lines (299 loc) · 15.6 KB
/
process_hidden.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import csv
import json
from collections import defaultdict
def hidden_sum(path: str):
hidden = defaultdict(int)
with open(path, encoding="utf-8") as f:
reader = csv.reader(f)
rows = [row for row in reader]
for row in rows:
for index, column in enumerate(row):
if index == 0:
if '$$' in column:
hidden["$$"] = hidden['$$'] + 1
if 'clinit' in column:
hidden['$$_type'] = hidden['$$_type'] + 1
elif '(' in column or ')' in column:
hidden['$$_method'] = hidden['$$_method'] + 1
else:
hidden['$$_field'] = hidden['$$_field'] + 1
elif column.startswith('Lcom/google/android/collect'):
hidden["collect"] = hidden['collect'] + 1
if '(' in column or ')' in column:
hidden['collect_method'] = hidden['collect_method'] + 1
else:
hidden['collect_field'] = hidden['collect_field'] + 1
elif column.startswith('Lcom/google/android/gles_jni'):
# java 原生接口
hidden["jni"] = hidden['jni'] + 1
if 'clinit' in column:
hidden['jni_type'] = hidden['jni_type'] + 1
elif '(' in column or ')' in column:
hidden['jni_method'] = hidden['jni_method'] + 1
else:
hidden['jni_field'] = hidden['jni_field'] + 1
elif column.startswith('Lcom/google/android/mms'):
# Android源代码中的内部包.它不旨在由其他应用使用.
hidden["mms"] = hidden['mms'] + 1
if 'clinit' in column:
hidden['mms_type'] = hidden['mms_type'] + 1
elif '(' in column or ')' in column:
hidden['mms_method'] = hidden['mms_method'] + 1
else:
hidden['mms_field'] = hidden['mms_field'] + 1
elif column.startswith('Lcom/google/android/rappor'):
# RAPPOR 是一款新型的保密技术,它在提供人口统计数据的同时,能保护用户的私人数据。这个库里包含了用 Python 和 R 写成的代码。
hidden["rappor"] = hidden['rappor'] + 1
if 'clinit' in column:
hidden['rappor_type'] = hidden['rappor_type'] + 1
elif '(' in column or ')' in column:
hidden['rappor_method'] = hidden['rappor_method'] + 1
else:
hidden['rappor_field'] = hidden['rappor_field'] + 1
elif column.startswith('Lcom/google/android/util'):
# 工具库
hidden["util"] = hidden['util'] + 1
if 'clinit' in column:
hidden['util_type'] = hidden['util_type'] + 1
elif '(' in column or ')' in column:
hidden['util_method'] = hidden['util_method'] + 1
else:
hidden['util_field'] = hidden['util_field'] + 1
elif column.startswith('Lcom/sun'):
# com.sun.* sun.* 则是不被官方支持的,Oracle不保证这些API是跨平台的
hidden["com_sun"] = hidden['com_sun'] + 1
if 'clinit' in column:
hidden['com_sun_type'] = hidden['com_sun_type'] + 1
elif '(' in column or ')' in column:
hidden['com_sun_method'] = hidden['com_sun_method'] + 1
else:
hidden['com_sun_field'] = hidden['com_sun_field'] + 1
elif column.startswith('Ldalvik'):
# Google 公司自己设计用于Android平台的Java虚拟机
hidden["dalvik"] = hidden['dalvik'] + 1
if 'clinit' in column:
hidden['dalvik_type'] = hidden['dalvik_type'] + 1
elif '(' in column or ')' in column:
hidden['dalvik_method'] = hidden['dalvik_method'] + 1
else:
hidden['dalvik_field'] = hidden['dalvik_field'] + 1
elif column.startswith('Lgov/nist'):
# NIST是美国国家标准技术研究所
hidden["gov"] = hidden['gov'] + 1
if 'clinit' in column:
hidden['gov_type'] = hidden['gov_type'] + 1
elif '(' in column or ')' in column:
hidden['gov_method'] = hidden['gov_method'] + 1
else:
hidden['gov_field'] = hidden['gov_field'] + 1
elif column.startswith('Ljava/'):
# java库
hidden["java"] = hidden['java'] + 1
if 'clinit' in column:
hidden['java_type'] = hidden['java_type'] + 1
elif '(' in column or ')' in column:
hidden['java_method'] = hidden['java_method'] + 1
else:
hidden['java_field'] = hidden['java_field'] + 1
elif column.startswith('Ljavax/'):
# javax库
hidden["javax"] = hidden['javax'] + 1
if 'clinit' in column:
hidden['javax_type'] = hidden['javax_type'] + 1
elif '(' in column or ')' in column:
hidden['javax_method'] = hidden['javax_method'] + 1
else:
hidden['javax_field'] = hidden['javax_field'] + 1
elif column.startswith('Ljdk/'):
# jdk库
hidden["jdk"] = hidden['jdk'] + 1
if 'clinit' in column:
hidden['jdk_type'] = hidden['jdk_type'] + 1
elif '(' in column or ')' in column:
hidden['jdk_method'] = hidden['jdk_method'] + 1
else:
hidden['jdk_field'] = hidden['jdk_field'] + 1
elif column.startswith('Llibcore/'):
# libcore库
hidden["libcore"] = hidden['libcore'] + 1
if 'clinit' in column:
hidden['libcore_type'] = hidden['libcore_type'] + 1
elif '(' in column or ')' in column:
hidden['libcore_method'] = hidden['libcore_method'] + 1
else:
hidden['libcore_field'] = hidden['libcore_field'] + 1
elif column.startswith('Lorg/apache/'):
# apache库
hidden["apache"] = hidden['apache'] + 1
if 'clinit' in column:
hidden['apache_type'] = hidden['apache_type'] + 1
elif '(' in column or ')' in column:
hidden['apache_method'] = hidden['apache_method'] + 1
else:
hidden['apache_field'] = hidden['apache_field'] + 1
elif column.startswith('Lorg/ccil/cowan/tagsoup/'):
# ccil库
hidden["ccil"] = hidden['ccil'] + 1
if 'clinit' in column:
hidden['ccil_type'] = hidden['ccil_type'] + 1
elif '(' in column or ')' in column:
hidden['ccil_method'] = hidden['ccil_method'] + 1
else:
hidden['ccil_field'] = hidden['ccil_field'] + 1
elif column.startswith('Lorg/chromium/'):
# chromium库
hidden["chromium"] = hidden['chromium'] + 1
if 'clinit' in column:
hidden['chromium_type'] = hidden['chromium_type'] + 1
elif '(' in column or ')' in column:
hidden['chromium_method'] = hidden['chromium_method'] + 1
else:
hidden['chromium_field'] = hidden['chromium_field'] + 1
elif column.startswith('Lorg/json/'):
# json
hidden["json"] = hidden['json'] + 1
if 'clinit' in column:
hidden['json_type'] = hidden['json_type'] + 1
elif '(' in column or ')' in column:
hidden['json_method'] = hidden['json_method'] + 1
else:
hidden['json_field'] = hidden['json_field'] + 1
elif column.startswith('Lorg/w3c/'):
# w3c
hidden["w3c"] = hidden['w3c'] + 1
if 'clinit' in column:
hidden['w3c_type'] = hidden['w3c_type'] + 1
elif '(' in column or ')' in column:
hidden['w3c_method'] = hidden['w3c_method'] + 1
else:
hidden['w3c_field'] = hidden['w3c_field'] + 1
elif column.startswith('Lorg/xml/sax/'):
# xml
hidden["xml"] = hidden['xml'] + 1
if 'clinit' in column:
hidden['xml_type'] = hidden['xml_type'] + 1
elif '(' in column or ')' in column:
hidden['xml_method'] = hidden['xml_method'] + 1
else:
hidden['xml_field'] = hidden['xml_field'] + 1
elif column.startswith('Lorg/xmlpull/'):
# xmlpull
hidden["xmlpull"] = hidden['xmlpull'] + 1
if 'clinit' in column:
hidden['xmlpull_type'] = hidden['xmlpull_type'] + 1
elif '(' in column or ')' in column:
hidden['xmlpull_method'] = hidden['xmlpull_method'] + 1
else:
hidden['xmlpull_field'] = hidden['xmlpull_field'] + 1
elif column.startswith('Lsun/'):
# sun
hidden["sun"] = hidden['sun'] + 1
if 'clinit' in column:
hidden['sun_type'] = hidden['sun_type'] + 1
elif '(' in column or ')' in column:
hidden['sun_method'] = hidden['sun_method'] + 1
else:
hidden['sun_field'] = hidden['sun_field'] + 1
elif column.startswith('Landroid/Manifest$'):
# Manifest$
hidden["Manifest"] = hidden['Manifest'] + 1
if 'clinit' in column:
hidden['Manifest_type'] = hidden['Manifest_type'] + 1
elif '(' in column or ')' in column:
hidden['Manifest_method'] = hidden['Manifest_method'] + 1
else:
hidden['Manifest_field'] = hidden['Manifest_field'] + 1
if 'clinit' in column:
hidden['type'] = hidden['type'] + 1
elif '(' in column or ')' in column:
hidden['method'] = hidden['method'] + 1
else:
hidden['field'] = hidden['field'] + 1
return hidden
def check_hidden(column: str) -> str:
if column == "blacklist" or column == "blocked":
return column
elif column == "greylist" or column == "unsupported":
return column
elif "greylist-max-" in column or "max-target-" in column:
return column
elif column == "whitelist" or column == "sdk":
return column
else:
return ""
def read_csv(path: str) -> defaultdict:
with open(path, encoding="utf-8") as f:
hidden_api = defaultdict(list)
reader = csv.reader(f)
rows = [row for row in reader]
# header_row = next(reader)
for row in rows:
hidden_flag = ""
current_api = ""
for index, column in enumerate(row):
# print(index, column)
if index == 0:
current_api = column
else:
hidden_flag = hidden_flag + check_hidden(column)
hidden_api[hidden_flag].append(current_api)
return hidden_api
def compare_hidden(aosp: defaultdict, magic: defaultdict) -> defaultdict:
modify_dict = defaultdict(list)
for m_key in magic.keys():
for m in magic[m_key]:
for a_key in aosp.keys():
if m in aosp[a_key]:
if a_key == m_key:
pass
else:
# print(a_key + "2" + m_key)
modify_dict[a_key + "2" + m_key].append(m)
break
# modify_dict["new2" + m_key].append(m)
return modify_dict
def dict_to_json_write_file(data_dict, filename):
with open(filename, 'w') as f:
json.dump(data_dict, f, sort_keys=True, indent=4, separators=(',', ':'))
def dict_to_csv(data_dict, file_name):
with open(file_name, "wb") as csv_file:
writer = csv.writer(csv_file)
for key, value in data_dict.items:
writer.writerow([key, value])
if __name__ == '__main__':
aosp_13_beta = read_csv("E:/ASE/实验数据/2-Hidden/csvs/hiddenapi-flags-13-beta.csv")
aosp_12 = read_csv("E:/ASE/实验数据/2-Hidden/csvs/hiddenapi-flags-12.csv")
aosp_11 = read_csv("E:/ASE/实验数据/2-Hidden/csvs/hiddenapi-flags-11.csv")
# aosp_10 = read_csv("E:/ASE/实验数据/2-Hidden/csvs/hiddenapi-flags-10.csv")
# lineage_19 = read_csv("E:/ASE/实验数据/2-Hidden/csvs/hiddenapi-flags-lineage19.csv")
# lineage_18 = read_csv("E:/ASE/实验数据/2-Hidden/csvs/hiddenapi-flags-lineage18.csv")
#
result = compare_hidden(aosp_12, aosp_13_beta)
for key in result.keys():
print(key)
print(len(result[key]))
if key == "max-target-o2sdk":
print(result[key])
elif key == "blocked2sdk":
print(result[key])
elif key == "unsupported2blocked":
print(result[key])
#
# print("LINEAGE 19")
#
# conflicts = compare_hidden(aosp_12, lineage_19)
# for key in conflicts.keys():
# print(key)
# print(len(conflicts[key]))
# print(conflicts[key])
# process_hidden(read_csv(hidden_path))
# hidden_path = "E:/ASE/实验数据/2-Hidden/csvs/hiddenapi-flags_10_r2.csv"
# hiddens = read_csv(hidden_path)
# for keys in hiddens.keys():
# print(keys)
# print(len(hiddens[keys]))
#
# sum = hidden_sum(hidden_path)
# for k in sum.keys():
# print(k)
# print(sum[k])