-
Notifications
You must be signed in to change notification settings - Fork 62
/
aux_functions.py
65 lines (45 loc) · 1.61 KB
/
aux_functions.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
import os
import shutil
import json
import fnmatch
import subprocess
def list_files(directory, string):
result = []
for dirpath, dirnames, files in os.walk(directory):
for file in fnmatch.filter(files, string):
result.append(os.path.join(dirpath, file))
return result
def unzip_apk(analyze_apk):
# directory = source_directory + os.path.basename(filename).replace('.apk', '')
directory = analyze_apk.replace('.apk', '/')
if not os.path.exists(directory):
command = "java -jar Libraries/apktool.jar d " + analyze_apk + " -o " + directory + " -f"
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, err = p.communicate()
def cleanup(analyze_apk):
# directory = source_directory + os.path.basename(filename).replace('.apk', '')
directory = analyze_apk.replace('.apk', '/')
shutil.rmtree(directory)
def save_as_json(data, output_name):
with open(str(output_name), 'w') as fp:
json.dump(data, fp, indent=4)
# print '[*] Analysis saved into:', str(output_name)
def save_as_csv(data):
# TODO
return 0
def load_file(filename):
with open(filename, 'rb') as text_file:
lines = text_file.readlines()
return lines
def check_overloaded_methods(dic):
# not used
for key, value in dic.iteritems():
if len(dic[key].keys()) > 1:
print '\nOVERCHARGED!!!\n'
def load_from_json(name):
if os.path.isfile(name):
with open(name, 'r') as fp:
data = json.load(fp)
return data
else:
return ['Not available']