-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
111 lines (85 loc) · 2.92 KB
/
main.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
import os
from glob import glob
import multiprocessing
from smali_parser import SmaliFileParser
from commons import MethodStruct
from method_graph_comparer import are_methods_graph_equals
PATH = 'McDonald\'s_com.mcdonalds.mobileapp/smali'
#PATH = 'droid_scalpel_release_4/smali'
def process_file(file_path):
c = SmaliFileParser(file_path).get_parsed_class()
for y in c.methods:
y.create_graph()
return None
def main():
tot_m = 0
files = [y for x in os.walk(PATH) for y in glob(os.path.join(x[0], '*.smali'))]
out = []
p = multiprocessing.Pool()
out = p.map(process_file, files)
#for x in files:
#print (x)
# out.append((process_file(x)))
#for x in out:
#for y in x.methods:
# tot_m += 1
#print(y.method_name)
#for z in y.instructions:
# print(z)
#print(x.smali_file_path)
#print("-------------------")
# y.create_graph()
print("Parsed methods:", tot_m)
import cProfile
pr = cProfile.Profile()
pr.enable()
main()
pr.disable()
pr.print_stats(sort='time')
'''
#out = [SmaliFileParser("droid_scalpel_release_4/smali/okhttp3/Response$Builder.smali").get_parsed_class()]
#out = [SmaliFileParser("McDonald's_com.mcdonalds.mobileapp/smali/okhttp3/ac$a.smali").get_parsed_class()]
matching = 0
# File path: droid_scalpel_release_3-orig/smali/android/support/v4/internal/view/SupportMenuItem.smali
# Method name: getNumericModifiers
unk = MethodStruct()
unk.load_from_file('/tmp/a/unk.gz')
for c in out:
#print(len(c.methods))
for m in c.methods:
if unk.arguments == m.arguments and m.return_type == unk.return_type:
print("Creo il grafo di", m.method_name)
m.create_graph()
if are_methods_graph_equals(unk.method_graph, m.method_graph):
print("Match:", m.method_name, "", unk.return_type, "", m.return_type, "", unk.arguments, "", m.arguments)
'''
'''
for c in out:
for m in c.methods:
m.create_graph()
m.save_to_file('/tmp/a/' + m.method_name + '.gz')
'''
'''matching = 0
for c in out:
print("File path:", c.file_path)
print("Class name:", c.class_name)
print("Super class name:", c.super_class)
print("Enclosing class name:", c.enclosing_class)
print()
if len(c.methods) > 0:
for x in c.methods:
print("Method name:", x.method_name)
print("Method return type:", x.return_type)
print("Method arguments:", x.arguments)
#print("Method instructions:")
#for y in x.instructions:
# print(" ",y)
h = x.get_hash()
print("Method hash:", h)
if h == "f9915b1aca691d3298e12681f9517a08":
matching += 1
print()
else:
print("No methods in class")
print("--------------------------------------")
print("matching =", matching)'''