-
Notifications
You must be signed in to change notification settings - Fork 20
/
ListingMethods.py
executable file
·66 lines (56 loc) · 2.17 KB
/
ListingMethods.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
# JEB sample script
# http://www.android-decompiler.com/
# listing all methods in dex
#
# Copyright (c) 2013 SecureBrain
import os
from jeb.api import IScript
class ListingMethods(IScript):
def run(self, j):
self.dex = j.getDex()
if not self.dex:
print 'Error! Please provide an input file.'
j.exit()
self.listing()
def listing(self):
print "listing all methods in dex..."
for i in range(0, self.dex.getClassCount()):
cls = self.dex.getClass(i)
print self.dex.getType(cls.getClasstypeIndex())
cls_data = cls.getData()
if cls_data is None:
continue
for md in cls_data.getDirectMethods():
print "\t%s" % self.method_def_str(md)
for md in cls_data.getVirtualMethods():
print "\t%s" % self.method_def_str(md)
print ""
def method_def_str(self, method_data):
m = self.dex.getMethod(method_data.getMethodIndex())
name = m.getName()
proto = self.dex.getPrototype(m.getPrototypeIndex())
proto_strs = map(lambda p: self.dex.getType(p), proto.getParameterTypeIndexes())
ret = self.dex.getType(proto.getReturnTypeIndex())
acc = self.accessor(method_data.getAccessFlags())
return "%s %s %s(%s)" % (' '.join(acc), ret, name, ', '.join(proto_strs))
def accessor(self, flg):
accessor_strings = {
0x1: 'public',
0x2: 'private',
0x4: 'protected',
0x8: 'static',
0x10: 'final',
0x20: 'synchronized',
0x40: 'bridge',
0x80: 'varargs',
0x100: 'native',
0x200: 'interface',
0x400: 'abstract',
0x800: 'strict',
0x1000: 'synthetic',
0x2000: 'annotation',
0x4000: 'enum',
0x10000: 'constructor',
0x20000: 'declared-synchronized',
}
return map(lambda i: accessor_strings[i], filter(lambda k: k&flg, accessor_strings.keys()))