1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import sys
20
21 PATH_INSTALL = "./"
22
23 sys.path.append(PATH_INSTALL + "/core")
24 sys.path.append(PATH_INSTALL + "/core/bytecodes")
25 sys.path.append(PATH_INSTALL + "/core/predicates")
26 sys.path.append(PATH_INSTALL + "/core/analysis")
27 sys.path.append(PATH_INSTALL + "/core/vm")
28
29 import bytecode, jvm, dvm, misc, analysis, opaque, vm
30
34
37
38 - def _get(self, val, name) :
39 l = []
40 r = getattr(self.__bc, val)(name)
41 for i in r :
42 l.append( i )
43 return l
44
46 l = []
47 r = getattr(self.__bc, val)()
48 for i in r :
49 l.append( i )
50 return l
51
52 - def gets(self, name) :
53 return self._gets("get_" + name)
54
55 - def get(self, val, name) :
56 return self._get("get_" + val, name)
57
60
63
66
68 return self.__bc.save()
69
71 return getattr(self.__bc, value)
72
74 """Androguard is the main object to abstract and manage differents formats
75
76 @param files : a list of filenames (filename must be terminated by .class or .dex)
77 """
78 - def __init__(self, files, config=None) :
79 self.__files = files
80 self.__bc = []
81 self._analyze()
82
84 for i in self.__files :
85 if ".class" in i :
86 bc = jvm.JVMFormat( open(i).read() )
87 elif ".dex" in i :
88 bc = dvm.DalvikVMFormat( open(i).read() )
89 else :
90 raise( "Unknown bytecode" )
91
92 self.__bc.append( (i, BC( bc )) )
93
95 for file_name, bc in self.__bc :
96 r = getattr(bc, "get_method")(name)
97 for i in r :
98 analysis.JBCA( bc, i )
99
101 """Return raw format of all file"""
102 l = []
103 for _, bc in self.__bc :
104 l.append( bc._get_raw() )
105 return l
106
107
108 - def get(self, name, val) :
109 if name == "file" :
110 for file_name, bc in self.__bc :
111 if file_name == val :
112 return bc
113
114 return None
115 else :
116 l = []
117 for file_name, bc in self.__bc :
118 l.append( bc.get( name, val ) )
119
120 return l
121
122 - def gets(self, name) :
123 l = []
124 for file_name, bc in self.__bc :
125 l.append( bc.gets( name ) )
126
127 return l
128
130 for _, bc in self.__bc :
131 bc.show()
132
134 """AndroguardS is the main object to abstract and manage differents formats but only per filename. In fact this class is just a wrapper to the main class Androguard
135
136 @param filename : the filename to use (filename must be terminated by .class or .dex)
137 """
139 a = Androguard( [ filename ] )
140 self.__a = a.get( "file", filename )
141
143 return getattr(self.__a, value)
144
145 VM_INT_AUTO = 0
146 VM_INT_BASIC_MATH_FORMULA = 1
147 VM_INT_BASIC_PRNG = 2
149 """VM_int is the main high level Virtual Machine object to protect a method by remplacing all integer contants
150
151 @param andro : an L{Androguard} / L{AndroguardS} object to have full access to the desired information
152 @param method_name : the name of the method to protect
153 @param vm_int_type : the type of the Virtual Machine
154 """
155 - def __init__(self, andro, method_name, vm_int_type) :
189