-
Notifications
You must be signed in to change notification settings - Fork 5
/
App_Permission_Extractor.py
36 lines (32 loc) · 1.15 KB
/
App_Permission_Extractor.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
import re
import os
# path to data-set folder
dir = "C:\\Users\\<user-name>\Desktop\\Machine-learning\\project\\Data-set\\drebin\\drebin-0\\drebin-0"
# path to APK folder in data-set folder
change_to = "C:\\Users\\<user-name>\Desktop\\Machine-learning\\project\\Data-set\\drebin\\drebin-0\\drebin-0\\"
root, dirs, files = os.walk(dir).__next__()
out = open("Apk-permissions.txt",'w')
temp = " "
for folder in dirs:
new_Dir = change_to+folder
app_Hash_Key = folder.strip(".zip.out")
out.write(app_Hash_Key)
print(app_Hash_Key)
try:
file = open(new_Dir + "\\AndroidManifest.xml",'r',encoding="utf8") # utf8 because we had some chinese text in Manifest.XML
except (FileNotFoundError,IOError):
continue
pattern = re.compile('<uses-permission')
line_list = []
for line in file:
return_True = pattern.search(line)
if return_True:
line_list.append(line)
for line in line_list:
feature_Word = line.strip().split(".",)
feature_Word = feature_Word[len(feature_Word)-1].strip("\"/>")
if temp != feature_Word: # to avoid duplication
out.write(" ")
out.write(feature_Word)
temp = feature_Word
out.write('\n')