-
Notifications
You must be signed in to change notification settings - Fork 21
/
sourceinfofucker.py
45 lines (39 loc) · 1.75 KB
/
sourceinfofucker.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
__author__ = 'flanker'
'''
Util to extract Source info from dex and restore class name from proguard
'''
from jeb.api import IScript
from jeb.api.ui import View
from collections import defaultdict
class sourceinfofucker(IScript):
def run(self, j):
self.instance = j
self.dex = j.getDex()
pool = defaultdict(list)
#ignore invalid source, i.e. "proguard" and other self-defined string
for i in self.dex.getClassSignatures(True):
cls = self.dex.getClass(i)
sourceIdx = cls.getSourceIndex()
if sourceIdx != -1:
source = self.dex.getString(sourceIdx)
if source == "" or source.lower() == "proguard":
continue
if source.endswith(".java"):
source = source[:-5]
pool[source].append(i)
if len(pool.keys()) == 0:
self.instance.print("fuck! no class source info found.")
elif len(pool.keys()) <= 2:
#less than two distinct keys, we're fooled
self.instance.print("fuck! we're fooled by %s. Stopping now" % pool.keys()[0])
else:
self.instance.print("renaming %d classes"%(len(pool.keys())))
for k, v in pool.iteritems():
for origin in v:
#notice some inner class may share same Source Info
self.instance.print("renaming from %s to %s" % (origin,k))
self.instance.renameClass(origin, k)
self.instance.print("renaming done")
self.instance.getUI().getView(View.Type.JAVA).refresh()
self.instance.getUI().getView(View.Type.ASSEMBLY).refresh()
self.instance.getUI().getView(View.Type.CLASS_HIERARCHY).refresh()