-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreflectionsHack.py
More file actions
91 lines (83 loc) · 2.31 KB
/
reflectionsHack.py
File metadata and controls
91 lines (83 loc) · 2.31 KB
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
#!/usr/bin/python
import sys, re, os
methodmap = {}
foundclasses = []
orphans = []
def readMethodMap(filename):
global methodmap
f = open(filename)
for line in f:
signature = line.rstrip()
signatureS = signature.split(".")
method = signatureS[len(signatureS)-1]
clazz = ""
for i in range(len(signatureS)-1):
clazz += signatureS[i]
if i < len(signatureS)-2:
clazz += "."
if method in methodmap:
methodmap[method].append(clazz)
else:
methodmap[method] = [ clazz ]
f.close()
def readOrphans(filename):
f = open(filename)
obj_pattern = re.compile("^java.lang.Object")
unk_pattern = re.compile("^\*\*unknown")
for line in f:
lineS = line.rstrip()
if obj_pattern.match(lineS) or unk_pattern.match(lineS):
split = lineS.split("/")
if len(split) <= 1:
split2 = lineS.split(".")
if len(split2) > 1:
orphans.append(split2[len(split2)-1])
else:
orphans.append(split[len(split)-1])
f.close()
def readOrphansDebug(filename):
f = open(filename)
obj_pattern = re.compile("^java.lang.Object")
unk_pattern = re.compile("^\*\*unknown")
for line in f:
linesplit = line.split(" ")
if len(linesplit) == 3:
lineS = linesplit[2].rstrip()
if obj_pattern.match(lineS) or unk_pattern.match(lineS):
split = lineS.split("/")
if len(split) <= 1:
split2 = lineS.split(".")
if len(split2) > 1:
orphans.append(split2[len(split2)-1])
else:
orphans.append(split[len(split)-1])
f.close()
def readFoundClasses(filename):
f = open(filename)
and_pattern1 = re.compile('^android.*')
and_pattern2 = re.compile('^com.android.*')
net_pattern = re.compile('^java.net.*')
for line in f:
lineS = line.rstrip()
if and_pattern1.match(lineS) or and_pattern2.match(lineS) or net_pattern.match(lineS):
foundclasses.append(lineS)
def main():
readMethodMap("methodlist.txt")
readFoundClasses(sys.argv[1])
readOrphansDebug(sys.argv[2])
if len(orphans) > 0:
if len(foundclasses) > 0:
for orphan in orphans:
if orphan in methodmap:
#print "Found in map: " + orphan
#print methodmap[orphan]
for clazz in methodmap[orphan]:
#print clazz
if clazz in foundclasses:
print clazz + "." + orphan
#if resolved:
# print "Resolved: " + resolvedstr
#else:
# print "Unresolved: " + orphan
if __name__ == "__main__":
main()