Mercurial > paraspace
annotate paraspace/dalvik_opcodes.py @ 73:6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
- Append '\x00's to the tail of instructions
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 02 Jul 2011 00:09:50 +0800 |
parents | 6c2efdeffa7b |
children | 9a64fa2d78b7 |
rev | line source |
---|---|
69 | 1 OP_NOP = 0x00 |
2 OP_MOVE = 0x01 | |
3 OP_MOVE_FROM16 = 0x02 | |
4 OP_MOVE_16 = 0x03 | |
5 OP_MOVE_WIDE = 0x04 | |
6 OP_MOVE_WIDE_FROM16 = 0x05 | |
7 OP_MOVE_WIDE_16 = 0x06 | |
8 OP_MOVE_OBJECT = 0x07 | |
9 OP_MOVE_OBJECT_FROM16 = 0x08 | |
10 OP_MOVE_OBJECT_16 = 0x09 | |
11 OP_MOVE_RESULT = 0x0a | |
12 OP_MOVE_RESULT_WIDE = 0x0b | |
13 OP_MOVE_RESULT_OBJECT = 0x0c | |
14 OP_MOVE_EXCEPTION = 0x0d | |
15 OP_RETURN_VOID = 0x0e | |
16 OP_RETURN = 0x0f | |
17 OP_RETURN_WIDE = 0x10 | |
18 OP_RETURN_OBJECT = 0x11 | |
19 OP_CONST_4 = 0x12 | |
20 OP_CONST_16 = 0x13 | |
21 OP_CONST = 0x14 | |
22 OP_CONST_HIGH16 = 0x15 | |
23 OP_CONST_WIDE_16 = 0x16 | |
24 OP_CONST_WIDE_32 = 0x17 | |
25 OP_CONST_WIDE = 0x18 | |
26 OP_CONST_WIDE_HIGH16 = 0x19 | |
27 OP_CONST_STRING = 0x1a | |
28 OP_CONST_STRING_JUMBO = 0x1b | |
29 OP_CONST_CLASS = 0x1c | |
30 OP_MONITOR_ENTER = 0x1d | |
31 OP_MONITOR_EXIT = 0x1e | |
32 OP_CHECK_CAST = 0x1f | |
33 OP_INSTANCE_OF = 0x20 | |
34 OP_ARRAY_LENGTH = 0x21 | |
35 OP_NEW_INSTANCE = 0x22 | |
36 OP_NEW_ARRAY = 0x23 | |
37 OP_FILLED_NEW_ARRAY = 0x24 | |
38 OP_FILLED_NEW_ARRAY_RANGE = 0x25 | |
39 OP_FILL_ARRAY_DATA = 0x26 | |
40 OP_THROW = 0x27 | |
41 OP_GOTO = 0x28 | |
42 OP_GOTO_16 = 0x29 | |
43 OP_GOTO_32 = 0x2a | |
44 OP_PACKED_SWITCH = 0x2b | |
45 OP_SPARSE_SWITCH = 0x2c | |
46 OP_CMPL_FLOAT = 0x2d | |
47 OP_CMPG_FLOAT = 0x2e | |
48 OP_CMPL_DOUBLE = 0x2f | |
49 OP_CMPG_DOUBLE = 0x30 | |
50 OP_CMP_LONG = 0x31 | |
51 OP_IF_EQ = 0x32 | |
52 OP_IF_NE = 0x33 | |
53 OP_IF_LT = 0x34 | |
54 OP_IF_GE = 0x35 | |
55 OP_IF_GT = 0x36 | |
56 OP_IF_LE = 0x37 | |
57 OP_IF_EQZ = 0x38 | |
58 OP_IF_NEZ = 0x39 | |
59 OP_IF_LTZ = 0x3a | |
60 OP_IF_GEZ = 0x3b | |
61 OP_IF_GTZ = 0x3c | |
62 OP_IF_LEZ = 0x3d | |
63 OP_UNUSED_3E = 0x3e | |
64 OP_UNUSED_3F = 0x3f | |
65 OP_UNUSED_40 = 0x40 | |
66 OP_UNUSED_41 = 0x41 | |
67 OP_UNUSED_42 = 0x42 | |
68 OP_UNUSED_43 = 0x43 | |
69 OP_AGET = 0x44 | |
70 OP_AGET_WIDE = 0x45 | |
71 OP_AGET_OBJECT = 0x46 | |
72 OP_AGET_BOOLEAN = 0x47 | |
73 OP_AGET_BYTE = 0x48 | |
74 OP_AGET_CHAR = 0x49 | |
75 OP_AGET_SHORT = 0x4a | |
76 OP_APUT = 0x4b | |
77 OP_APUT_WIDE = 0x4c | |
78 OP_APUT_OBJECT = 0x4d | |
79 OP_APUT_BOOLEAN = 0x4e | |
80 OP_APUT_BYTE = 0x4f | |
81 OP_APUT_CHAR = 0x50 | |
82 OP_APUT_SHORT = 0x51 | |
83 OP_IGET = 0x52 | |
84 OP_IGET_WIDE = 0x53 | |
85 OP_IGET_OBJECT = 0x54 | |
86 OP_IGET_BOOLEAN = 0x55 | |
87 OP_IGET_BYTE = 0x56 | |
88 OP_IGET_CHAR = 0x57 | |
89 OP_IGET_SHORT = 0x58 | |
90 OP_IPUT = 0x59 | |
91 OP_IPUT_WIDE = 0x5a | |
92 OP_IPUT_OBJECT = 0x5b | |
93 OP_IPUT_BOOLEAN = 0x5c | |
94 OP_IPUT_BYTE = 0x5d | |
95 OP_IPUT_CHAR = 0x5e | |
96 OP_IPUT_SHORT = 0x5f | |
97 OP_SGET = 0x60 | |
98 OP_SGET_WIDE = 0x61 | |
99 OP_SGET_OBJECT = 0x62 | |
100 OP_SGET_BOOLEAN = 0x63 | |
101 OP_SGET_BYTE = 0x64 | |
102 OP_SGET_CHAR = 0x65 | |
103 OP_SGET_SHORT = 0x66 | |
104 OP_SPUT = 0x67 | |
105 OP_SPUT_WIDE = 0x68 | |
106 OP_SPUT_OBJECT = 0x69 | |
107 OP_SPUT_BOOLEAN = 0x6a | |
108 OP_SPUT_BYTE = 0x6b | |
109 OP_SPUT_CHAR = 0x6c | |
110 OP_SPUT_SHORT = 0x6d | |
111 OP_INVOKE_VIRTUAL = 0x6e | |
112 OP_INVOKE_SUPER = 0x6f | |
113 OP_INVOKE_DIRECT = 0x70 | |
114 OP_INVOKE_STATIC = 0x71 | |
115 OP_INVOKE_INTERFACE = 0x72 | |
116 OP_UNUSED_73 = 0x73 | |
117 OP_INVOKE_VIRTUAL_RANGE = 0x74 | |
118 OP_INVOKE_SUPER_RANGE = 0x75 | |
119 OP_INVOKE_DIRECT_RANGE = 0x76 | |
120 OP_INVOKE_STATIC_RANGE = 0x77 | |
121 OP_INVOKE_INTERFACE_RANGE = 0x78 | |
122 OP_UNUSED_79 = 0x79 | |
123 OP_UNUSED_7A = 0x7a | |
124 OP_NEG_INT = 0x7b | |
125 OP_NOT_INT = 0x7c | |
126 OP_NEG_LONG = 0x7d | |
127 OP_NOT_LONG = 0x7e | |
128 OP_NEG_FLOAT = 0x7f | |
129 OP_NEG_DOUBLE = 0x80 | |
130 OP_INT_TO_LONG = 0x81 | |
131 OP_INT_TO_FLOAT = 0x82 | |
132 OP_INT_TO_DOUBLE = 0x83 | |
133 OP_LONG_TO_INT = 0x84 | |
134 OP_LONG_TO_FLOAT = 0x85 | |
135 OP_LONG_TO_DOUBLE = 0x86 | |
136 OP_FLOAT_TO_INT = 0x87 | |
137 OP_FLOAT_TO_LONG = 0x88 | |
138 OP_FLOAT_TO_DOUBLE = 0x89 | |
139 OP_DOUBLE_TO_INT = 0x8a | |
140 OP_DOUBLE_TO_LONG = 0x8b | |
141 OP_DOUBLE_TO_FLOAT = 0x8c | |
142 OP_INT_TO_BYTE = 0x8d | |
143 OP_INT_TO_CHAR = 0x8e | |
144 OP_INT_TO_SHORT = 0x8f | |
145 OP_ADD_INT = 0x90 | |
146 OP_SUB_INT = 0x91 | |
147 OP_MUL_INT = 0x92 | |
148 OP_DIV_INT = 0x93 | |
149 OP_REM_INT = 0x94 | |
150 OP_AND_INT = 0x95 | |
151 OP_OR_INT = 0x96 | |
152 OP_XOR_INT = 0x97 | |
153 OP_SHL_INT = 0x98 | |
154 OP_SHR_INT = 0x99 | |
155 OP_USHR_INT = 0x9a | |
156 OP_ADD_LONG = 0x9b | |
157 OP_SUB_LONG = 0x9c | |
158 OP_MUL_LONG = 0x9d | |
159 OP_DIV_LONG = 0x9e | |
160 OP_REM_LONG = 0x9f | |
161 OP_AND_LONG = 0xa0 | |
162 OP_OR_LONG = 0xa1 | |
163 OP_XOR_LONG = 0xa2 | |
164 OP_SHL_LONG = 0xa3 | |
165 OP_SHR_LONG = 0xa4 | |
166 OP_USHR_LONG = 0xa5 | |
167 OP_ADD_FLOAT = 0xa6 | |
168 OP_SUB_FLOAT = 0xa7 | |
169 OP_MUL_FLOAT = 0xa8 | |
170 OP_DIV_FLOAT = 0xa9 | |
171 OP_REM_FLOAT = 0xaa | |
172 OP_ADD_DOUBLE = 0xab | |
173 OP_SUB_DOUBLE = 0xac | |
174 OP_MUL_DOUBLE = 0xad | |
175 OP_DIV_DOUBLE = 0xae | |
176 OP_REM_DOUBLE = 0xaf | |
177 OP_ADD_INT_2ADDR = 0xb0 | |
178 OP_SUB_INT_2ADDR = 0xb1 | |
179 OP_MUL_INT_2ADDR = 0xb2 | |
180 OP_DIV_INT_2ADDR = 0xb3 | |
181 OP_REM_INT_2ADDR = 0xb4 | |
182 OP_AND_INT_2ADDR = 0xb5 | |
183 OP_OR_INT_2ADDR = 0xb6 | |
184 OP_XOR_INT_2ADDR = 0xb7 | |
185 OP_SHL_INT_2ADDR = 0xb8 | |
186 OP_SHR_INT_2ADDR = 0xb9 | |
187 OP_USHR_INT_2ADDR = 0xba | |
188 OP_ADD_LONG_2ADDR = 0xbb | |
189 OP_SUB_LONG_2ADDR = 0xbc | |
190 OP_MUL_LONG_2ADDR = 0xbd | |
191 OP_DIV_LONG_2ADDR = 0xbe | |
192 OP_REM_LONG_2ADDR = 0xbf | |
193 OP_AND_LONG_2ADDR = 0xc0 | |
194 OP_OR_LONG_2ADDR = 0xc1 | |
195 OP_XOR_LONG_2ADDR = 0xc2 | |
196 OP_SHL_LONG_2ADDR = 0xc3 | |
197 OP_SHR_LONG_2ADDR = 0xc4 | |
198 OP_USHR_LONG_2ADDR = 0xc5 | |
199 OP_ADD_FLOAT_2ADDR = 0xc6 | |
200 OP_SUB_FLOAT_2ADDR = 0xc7 | |
201 OP_MUL_FLOAT_2ADDR = 0xc8 | |
202 OP_DIV_FLOAT_2ADDR = 0xc9 | |
203 OP_REM_FLOAT_2ADDR = 0xca | |
204 OP_ADD_DOUBLE_2ADDR = 0xcb | |
205 OP_SUB_DOUBLE_2ADDR = 0xcc | |
206 OP_MUL_DOUBLE_2ADDR = 0xcd | |
207 OP_DIV_DOUBLE_2ADDR = 0xce | |
208 OP_REM_DOUBLE_2ADDR = 0xcf | |
209 OP_ADD_INT_LIT16 = 0xd0 | |
210 OP_RSUB_INT = 0xd1 | |
211 OP_MUL_INT_LIT16 = 0xd2 | |
212 OP_DIV_INT_LIT16 = 0xd3 | |
213 OP_REM_INT_LIT16 = 0xd4 | |
214 OP_AND_INT_LIT16 = 0xd5 | |
215 OP_OR_INT_LIT16 = 0xd6 | |
216 OP_XOR_INT_LIT16 = 0xd7 | |
217 OP_ADD_INT_LIT8 = 0xd8 | |
218 OP_RSUB_INT_LIT8 = 0xd9 | |
219 OP_MUL_INT_LIT8 = 0xda | |
220 OP_DIV_INT_LIT8 = 0xdb | |
221 OP_REM_INT_LIT8 = 0xdc | |
222 OP_AND_INT_LIT8 = 0xdd | |
223 OP_OR_INT_LIT8 = 0xde | |
224 OP_XOR_INT_LIT8 = 0xdf | |
225 OP_SHL_INT_LIT8 = 0xe0 | |
226 OP_SHR_INT_LIT8 = 0xe1 | |
227 OP_USHR_INT_LIT8 = 0xe2 | |
228 OP_UNUSED_E3 = 0xe3 | |
229 OP_UNUSED_E4 = 0xe4 | |
230 OP_UNUSED_E5 = 0xe5 | |
231 OP_UNUSED_E6 = 0xe6 | |
232 OP_UNUSED_E7 = 0xe7 | |
233 OP_UNUSED_E8 = 0xe8 | |
234 OP_UNUSED_E9 = 0xe9 | |
235 OP_UNUSED_EA = 0xea | |
236 OP_UNUSED_EB = 0xeb | |
237 OP_UNUSED_EC = 0xec | |
238 OP_UNUSED_ED = 0xed | |
239 OP_EXECUTE_INLINE = 0xee | |
240 OP_UNUSED_EF = 0xef | |
241 OP_INVOKE_DIRECT_EMPTY = 0xf0 | |
242 OP_UNUSED_F1 = 0xf1 | |
243 OP_IGET_QUICK = 0xf2 | |
244 OP_IGET_WIDE_QUICK = 0xf3 | |
245 OP_IGET_OBJECT_QUICK = 0xf4 | |
246 OP_IPUT_QUICK = 0xf5 | |
247 OP_IPUT_WIDE_QUICK = 0xf6 | |
248 OP_IPUT_OBJECT_QUICK = 0xf7 | |
249 OP_INVOKE_VIRTUAL_QUICK = 0xf8 | |
250 OP_INVOKE_VIRTUAL_QUICK_RANGE = 0xf9 | |
251 OP_INVOKE_SUPER_QUICK = 0xfa | |
252 OP_INVOKE_SUPER_QUICK_RANGE = 0xfb | |
253 OP_UNUSED_FC = 0xfc | |
254 OP_UNUSED_FD = 0xfd | |
255 OP_UNUSED_FE = 0xfe | |
256 OP_UNUSED_FF = 0xff | |
257 | |
258 _g = dict(globals()) | |
259 opcode_names = sorted([name for name in _g if name.startswith('OP_')], | |
260 key=lambda name: _g[name]) | |
261 name_2_opcodes = dict([(name, code) for name, code in _g.items()]) | |
262 del _g | |
263 | |
264 opcode_widths = [0] * 256 | |
265 | |
266 w1_ops = '''OP_NOP | |
267 OP_MOVE | |
268 OP_MOVE_WIDE | |
269 OP_MOVE_OBJECT | |
270 OP_MOVE_RESULT | |
271 OP_MOVE_RESULT_WIDE | |
272 OP_MOVE_RESULT_OBJECT | |
273 OP_MOVE_EXCEPTION | |
274 OP_RETURN_VOID | |
275 OP_RETURN | |
276 OP_RETURN_WIDE | |
277 OP_RETURN_OBJECT | |
278 OP_CONST_4 | |
279 OP_MONITOR_ENTER | |
280 OP_MONITOR_EXIT | |
281 OP_ARRAY_LENGTH | |
282 OP_THROW | |
283 OP_GOTO | |
284 OP_NEG_INT | |
285 OP_NOT_INT | |
286 OP_NEG_LONG | |
287 OP_NOT_LONG | |
288 OP_NEG_FLOAT | |
289 OP_NEG_DOUBLE | |
290 OP_INT_TO_LONG | |
291 OP_INT_TO_FLOAT | |
292 OP_INT_TO_DOUBLE | |
293 OP_LONG_TO_INT | |
294 OP_LONG_TO_FLOAT | |
295 OP_LONG_TO_DOUBLE | |
296 OP_FLOAT_TO_INT | |
297 OP_FLOAT_TO_LONG | |
298 OP_FLOAT_TO_DOUBLE | |
299 OP_DOUBLE_TO_INT | |
300 OP_DOUBLE_TO_LONG | |
301 OP_DOUBLE_TO_FLOAT | |
302 OP_INT_TO_BYTE | |
303 OP_INT_TO_CHAR | |
304 OP_INT_TO_SHORT | |
305 OP_ADD_INT_2ADDR | |
306 OP_SUB_INT_2ADDR | |
307 OP_MUL_INT_2ADDR | |
308 OP_DIV_INT_2ADDR | |
309 OP_REM_INT_2ADDR | |
310 OP_AND_INT_2ADDR | |
311 OP_OR_INT_2ADDR | |
312 OP_XOR_INT_2ADDR | |
313 OP_SHL_INT_2ADDR | |
314 OP_SHR_INT_2ADDR | |
315 OP_USHR_INT_2ADDR | |
316 OP_ADD_LONG_2ADDR | |
317 OP_SUB_LONG_2ADDR | |
318 OP_MUL_LONG_2ADDR | |
319 OP_DIV_LONG_2ADDR | |
320 OP_REM_LONG_2ADDR | |
321 OP_AND_LONG_2ADDR | |
322 OP_OR_LONG_2ADDR | |
323 OP_XOR_LONG_2ADDR | |
324 OP_SHL_LONG_2ADDR | |
325 OP_SHR_LONG_2ADDR | |
326 OP_USHR_LONG_2ADDR | |
327 OP_ADD_FLOAT_2ADDR | |
328 OP_SUB_FLOAT_2ADDR | |
329 OP_MUL_FLOAT_2ADDR | |
330 OP_DIV_FLOAT_2ADDR | |
331 OP_REM_FLOAT_2ADDR | |
332 OP_ADD_DOUBLE_2ADDR | |
333 OP_SUB_DOUBLE_2ADDR | |
334 OP_MUL_DOUBLE_2ADDR | |
335 OP_DIV_DOUBLE_2ADDR | |
336 OP_REM_DOUBLE_2ADDR'''.split() | |
337 | |
338 for name in w1_ops: | |
339 opcode = name_2_opcodes[name] | |
340 opcode_widths[opcode] = 1 | |
341 pass | |
342 | |
343 | |
344 w2_ops = '''OP_MOVE_FROM16 | |
345 OP_MOVE_WIDE_FROM16 | |
346 OP_MOVE_OBJECT_FROM16 | |
347 OP_CONST_16 | |
348 OP_CONST_HIGH16 | |
349 OP_CONST_WIDE_16 | |
350 OP_CONST_WIDE_HIGH16 | |
351 OP_CONST_STRING | |
352 OP_CONST_CLASS | |
353 OP_CHECK_CAST | |
354 OP_INSTANCE_OF | |
355 OP_NEW_INSTANCE | |
356 OP_NEW_ARRAY | |
357 OP_CMPL_FLOAT | |
358 OP_CMPG_FLOAT | |
359 OP_CMPL_DOUBLE | |
360 OP_CMPG_DOUBLE | |
361 OP_CMP_LONG | |
362 OP_GOTO_16 | |
363 OP_IF_EQ | |
364 OP_IF_NE | |
365 OP_IF_LT | |
366 OP_IF_GE | |
367 OP_IF_GT | |
368 OP_IF_LE | |
369 OP_IF_EQZ | |
370 OP_IF_NEZ | |
371 OP_IF_LTZ | |
372 OP_IF_GEZ | |
373 OP_IF_GTZ | |
374 OP_IF_LEZ | |
375 OP_AGET | |
376 OP_AGET_WIDE | |
377 OP_AGET_OBJECT | |
378 OP_AGET_BOOLEAN | |
379 OP_AGET_BYTE | |
380 OP_AGET_CHAR | |
381 OP_AGET_SHORT | |
382 OP_APUT | |
383 OP_APUT_WIDE | |
384 OP_APUT_OBJECT | |
385 OP_APUT_BOOLEAN | |
386 OP_APUT_BYTE | |
387 OP_APUT_CHAR | |
388 OP_APUT_SHORT | |
389 OP_IGET | |
390 OP_IGET_WIDE | |
391 OP_IGET_OBJECT | |
392 OP_IGET_BOOLEAN | |
393 OP_IGET_BYTE | |
394 OP_IGET_CHAR | |
395 OP_IGET_SHORT | |
396 OP_IPUT | |
397 OP_IPUT_WIDE | |
398 OP_IPUT_OBJECT | |
399 OP_IPUT_BOOLEAN | |
400 OP_IPUT_BYTE | |
401 OP_IPUT_CHAR | |
402 OP_IPUT_SHORT | |
403 OP_SGET | |
404 OP_SGET_WIDE | |
405 OP_SGET_OBJECT | |
406 OP_SGET_BOOLEAN | |
407 OP_SGET_BYTE | |
408 OP_SGET_CHAR | |
409 OP_SGET_SHORT | |
410 OP_SPUT | |
411 OP_SPUT_WIDE | |
412 OP_SPUT_OBJECT | |
413 OP_SPUT_BOOLEAN | |
414 OP_SPUT_BYTE | |
415 OP_SPUT_CHAR | |
416 OP_SPUT_SHORT | |
417 OP_ADD_INT | |
418 OP_SUB_INT | |
419 OP_MUL_INT | |
420 OP_DIV_INT | |
421 OP_REM_INT | |
422 OP_AND_INT | |
423 OP_OR_INT | |
424 OP_XOR_INT | |
425 OP_SHL_INT | |
426 OP_SHR_INT | |
427 OP_USHR_INT | |
428 OP_ADD_LONG | |
429 OP_SUB_LONG | |
430 OP_MUL_LONG | |
431 OP_DIV_LONG | |
432 OP_REM_LONG | |
433 OP_AND_LONG | |
434 OP_OR_LONG | |
435 OP_XOR_LONG | |
436 OP_SHL_LONG | |
437 OP_SHR_LONG | |
438 OP_USHR_LONG | |
439 OP_ADD_FLOAT | |
440 OP_SUB_FLOAT | |
441 OP_MUL_FLOAT | |
442 OP_DIV_FLOAT | |
443 OP_REM_FLOAT | |
444 OP_ADD_DOUBLE | |
445 OP_SUB_DOUBLE | |
446 OP_MUL_DOUBLE | |
447 OP_DIV_DOUBLE | |
448 OP_REM_DOUBLE | |
449 OP_ADD_INT_LIT16 | |
450 OP_RSUB_INT | |
451 OP_MUL_INT_LIT16 | |
452 OP_DIV_INT_LIT16 | |
453 OP_REM_INT_LIT16 | |
454 OP_AND_INT_LIT16 | |
455 OP_OR_INT_LIT16 | |
456 OP_XOR_INT_LIT16 | |
457 OP_ADD_INT_LIT8 | |
458 OP_RSUB_INT_LIT8 | |
459 OP_MUL_INT_LIT8 | |
460 OP_DIV_INT_LIT8 | |
461 OP_REM_INT_LIT8 | |
462 OP_AND_INT_LIT8 | |
463 OP_OR_INT_LIT8 | |
464 OP_XOR_INT_LIT8 | |
465 OP_SHL_INT_LIT8 | |
466 OP_SHR_INT_LIT8 | |
467 OP_USHR_INT_LIT8'''.split() | |
468 | |
469 for name in w2_ops: | |
470 opcode = name_2_opcodes[name] | |
471 opcode_widths[opcode] = 2 | |
472 pass | |
473 | |
474 | |
475 w3_ops = '''OP_MOVE_16 | |
476 OP_MOVE_WIDE_16 | |
477 OP_MOVE_OBJECT_16 | |
478 OP_CONST | |
479 OP_CONST_WIDE_32 | |
480 OP_CONST_STRING_JUMBO | |
481 OP_GOTO_32 | |
482 OP_FILLED_NEW_ARRAY | |
483 OP_FILLED_NEW_ARRAY_RANGE | |
484 OP_FILL_ARRAY_DATA | |
485 OP_PACKED_SWITCH | |
486 OP_SPARSE_SWITCH | |
487 OP_INVOKE_VIRTUAL | |
488 OP_INVOKE_SUPER | |
489 OP_INVOKE_DIRECT | |
490 OP_INVOKE_STATIC | |
491 OP_INVOKE_INTERFACE | |
492 OP_INVOKE_VIRTUAL_RANGE | |
493 OP_INVOKE_SUPER_RANGE | |
494 OP_INVOKE_DIRECT_RANGE | |
495 OP_INVOKE_STATIC_RANGE | |
496 OP_INVOKE_INTERFACE_RANGE'''.split() | |
497 | |
498 for name in w3_ops: | |
499 opcode = name_2_opcodes[name] | |
500 opcode_widths[opcode] = 3 | |
501 pass | |
502 | |
503 opcode_widths[OP_CONST_WIDE] = 5 | |
504 | |
505 # | |
506 # Optimized instructions. We return negative size values for these | |
507 # to distinguish them. | |
508 # | |
509 w_2_ops = '''OP_IGET_QUICK | |
510 OP_IGET_WIDE_QUICK | |
511 OP_IGET_OBJECT_QUICK | |
512 OP_IPUT_QUICK | |
513 OP_IPUT_WIDE_QUICK | |
514 OP_IPUT_OBJECT_QUICK'''.split() | |
515 | |
516 for name in w_2_ops: | |
517 opcode = name_2_opcodes[name] | |
518 opcode_widths[opcode] = -2 | |
519 pass | |
520 | |
521 | |
522 w_3_ops = '''OP_INVOKE_VIRTUAL_QUICK | |
523 OP_INVOKE_VIRTUAL_QUICK_RANGE | |
524 OP_INVOKE_SUPER_QUICK | |
525 OP_INVOKE_SUPER_QUICK_RANGE | |
526 OP_EXECUTE_INLINE | |
527 OP_INVOKE_DIRECT_EMPTY'''.split() | |
528 | |
529 for name in w_3_ops: | |
530 opcode = name_2_opcodes[name] | |
531 opcode_widths[opcode] = -3 | |
532 pass | |
533 | |
534 w0_ops = '''OP_UNUSED_3E | |
535 OP_UNUSED_3F | |
536 OP_UNUSED_40 | |
537 OP_UNUSED_41 | |
538 OP_UNUSED_42 | |
539 OP_UNUSED_43 | |
540 OP_UNUSED_73 | |
541 OP_UNUSED_79 | |
542 OP_UNUSED_7A | |
543 OP_UNUSED_E3 | |
544 OP_UNUSED_E4 | |
545 OP_UNUSED_E5 | |
546 OP_UNUSED_E6 | |
547 OP_UNUSED_E7 | |
548 OP_UNUSED_E8 | |
549 OP_UNUSED_E9 | |
550 OP_UNUSED_EA | |
551 OP_UNUSED_EB | |
552 OP_UNUSED_EC | |
553 OP_UNUSED_ED | |
554 OP_UNUSED_EF | |
555 OP_UNUSED_F1 | |
556 OP_UNUSED_FC | |
557 OP_UNUSED_FD | |
558 OP_UNUSED_FE | |
559 OP_UNUSED_FF'''.split() | |
560 | |
561 | |
562 kFmtUnknown = 0 | |
563 kFmt10x = 1 | |
564 kFmt12x = 2 | |
565 kFmt11n = 3 | |
566 kFmt11x = 4 | |
567 kFmt10t = 5 | |
568 kFmt20t = 6 | |
569 kFmt22x = 7 | |
570 kFmt21t = 8 | |
571 kFmt21s = 9 | |
572 kFmt21h = 10 | |
573 kFmt21c = 11 | |
574 kFmt23x = 12 | |
575 kFmt22b = 13 | |
576 kFmt22t = 14 | |
577 kFmt22s = 15 | |
578 kFmt22c = 16 | |
579 kFmt22cs = 17 | |
580 kFmt32x = 18 | |
581 kFmt30t = 19 | |
582 kFmt31t = 20 | |
583 kFmt31i = 21 | |
584 kFmt31c = 22 | |
585 kFmt35c = 23 | |
586 kFmt35ms = 24 | |
587 kFmt35fs = 25 | |
588 kFmt3rc = 26 | |
589 kFmt3rms = 27 | |
590 kFmt3rfs = 28 | |
591 kFmt3inline = 29 | |
592 kFmt51l = 30 | |
593 | |
594 fmt_names = '''kFmtUnknown | |
595 kFmt10x | |
596 kFmt12x | |
597 kFmt11n | |
598 kFmt11x | |
599 kFmt10t | |
600 kFmt20t | |
601 kFmt22x | |
602 kFmt21t | |
603 kFmt21s | |
604 kFmt21h | |
605 kFmt21c | |
606 kFmt23x | |
607 kFmt22b | |
608 kFmt22t | |
609 kFmt22s | |
610 kFmt22c | |
611 kFmt22cs | |
612 kFmt32x | |
613 kFmt30t | |
614 kFmt31t | |
615 kFmt31i | |
616 kFmt31c | |
617 kFmt35c | |
618 kFmt35ms | |
619 kFmt35fs | |
620 kFmt3rc | |
621 kFmt3rms | |
622 kFmt3rfs | |
623 kFmt3inline | |
624 kFmt51l | |
625 '''.split() | |
626 | |
627 opcode_fmts = [0] * 256 | |
628 | |
629 opcode_fmts[OP_GOTO] = kFmt10t | |
630 | |
631 names = '''OP_NOP | |
632 OP_RETURN_VOID'''.split() | |
633 for name in names: | |
634 opcode = name_2_opcodes[name] | |
635 opcode_fmts[opcode] = kFmt10x | |
636 pass | |
637 | |
638 | |
639 opcode_fmts[OP_CONST_4] = kFmt11n | |
640 | |
641 | |
642 names = '''OP_CONST_HIGH16 | |
643 OP_CONST_WIDE_HIGH16'''.split() | |
644 for name in names: | |
645 opcode = name_2_opcodes[name] | |
646 opcode_fmts[opcode] = kFmt21h | |
647 pass | |
648 | |
649 | |
650 names = '''OP_MOVE_RESULT | |
651 OP_MOVE_RESULT_WIDE | |
652 OP_MOVE_RESULT_OBJECT | |
653 OP_MOVE_EXCEPTION | |
654 OP_RETURN | |
655 OP_RETURN_WIDE | |
656 OP_RETURN_OBJECT | |
657 OP_MONITOR_ENTER | |
658 OP_MONITOR_EXIT | |
659 OP_THROW'''.split() | |
660 for name in names: | |
661 opcode = name_2_opcodes[name] | |
662 opcode_fmts[opcode] = kFmt11x | |
663 pass | |
664 | |
665 | |
666 names = '''OP_MOVE | |
667 OP_MOVE_WIDE | |
668 OP_MOVE_OBJECT | |
669 OP_ARRAY_LENGTH | |
670 OP_NEG_INT | |
671 OP_NOT_INT | |
672 OP_NEG_LONG | |
673 OP_NOT_LONG | |
674 OP_NEG_FLOAT | |
675 OP_NEG_DOUBLE | |
676 OP_INT_TO_LONG | |
677 OP_INT_TO_FLOAT | |
678 OP_INT_TO_DOUBLE | |
679 OP_LONG_TO_INT | |
680 OP_LONG_TO_FLOAT | |
681 OP_LONG_TO_DOUBLE | |
682 OP_FLOAT_TO_INT | |
683 OP_FLOAT_TO_LONG | |
684 OP_FLOAT_TO_DOUBLE | |
685 OP_DOUBLE_TO_INT | |
686 OP_DOUBLE_TO_LONG | |
687 OP_DOUBLE_TO_FLOAT | |
688 OP_INT_TO_BYTE | |
689 OP_INT_TO_CHAR | |
690 OP_INT_TO_SHORT | |
691 OP_ADD_INT_2ADDR | |
692 OP_SUB_INT_2ADDR | |
693 OP_MUL_INT_2ADDR | |
694 OP_DIV_INT_2ADDR | |
695 OP_REM_INT_2ADDR | |
696 OP_AND_INT_2ADDR | |
697 OP_OR_INT_2ADDR | |
698 OP_XOR_INT_2ADDR | |
699 OP_SHL_INT_2ADDR | |
700 OP_SHR_INT_2ADDR | |
701 OP_USHR_INT_2ADDR | |
702 OP_ADD_LONG_2ADDR | |
703 OP_SUB_LONG_2ADDR | |
704 OP_MUL_LONG_2ADDR | |
705 OP_DIV_LONG_2ADDR | |
706 OP_REM_LONG_2ADDR | |
707 OP_AND_LONG_2ADDR | |
708 OP_OR_LONG_2ADDR | |
709 OP_XOR_LONG_2ADDR | |
710 OP_SHL_LONG_2ADDR | |
711 OP_SHR_LONG_2ADDR | |
712 OP_USHR_LONG_2ADDR | |
713 OP_ADD_FLOAT_2ADDR | |
714 OP_SUB_FLOAT_2ADDR | |
715 OP_MUL_FLOAT_2ADDR | |
716 OP_DIV_FLOAT_2ADDR | |
717 OP_REM_FLOAT_2ADDR | |
718 OP_ADD_DOUBLE_2ADDR | |
719 OP_SUB_DOUBLE_2ADDR | |
720 OP_MUL_DOUBLE_2ADDR | |
721 OP_DIV_DOUBLE_2ADDR | |
722 OP_REM_DOUBLE_2ADDR'''.split() | |
723 for name in names: | |
724 opcode = name_2_opcodes[name] | |
725 opcode_fmts[opcode] = kFmt12x | |
726 pass | |
727 | |
728 | |
729 opcode_fmts[OP_GOTO_16] = kFmt20t | |
730 opcode_fmts[OP_GOTO_32] = kFmt30t | |
731 | |
732 | |
733 names = '''OP_CONST_STRING | |
734 OP_CONST_CLASS | |
735 OP_CHECK_CAST | |
736 OP_NEW_INSTANCE | |
737 OP_SGET | |
738 OP_SGET_WIDE | |
739 OP_SGET_OBJECT | |
740 OP_SGET_BOOLEAN | |
741 OP_SGET_BYTE | |
742 OP_SGET_CHAR | |
743 OP_SGET_SHORT | |
744 OP_SPUT | |
745 OP_SPUT_WIDE | |
746 OP_SPUT_OBJECT | |
747 OP_SPUT_BOOLEAN | |
748 OP_SPUT_BYTE | |
749 OP_SPUT_CHAR | |
750 OP_SPUT_SHORT'''.split() | |
751 for name in names: | |
752 opcode = name_2_opcodes[name] | |
753 opcode_fmts[opcode] = kFmt21c | |
754 pass | |
755 | |
756 names = '''OP_CONST_16 | |
757 OP_CONST_WIDE_16'''.split() | |
758 for name in names: | |
759 opcode = name_2_opcodes[name] | |
760 opcode_fmts[opcode] = kFmt21s | |
761 pass | |
762 | |
763 | |
764 names = '''OP_IF_EQZ | |
765 OP_IF_NEZ | |
766 OP_IF_LTZ | |
767 OP_IF_GEZ | |
768 OP_IF_GTZ | |
769 OP_IF_LEZ'''.split() | |
770 for name in names: | |
771 opcode = name_2_opcodes[name] | |
772 opcode_fmts[opcode] = kFmt21t | |
773 pass | |
774 | |
775 | |
776 names = '''OP_FILL_ARRAY_DATA | |
777 OP_PACKED_SWITCH | |
778 OP_SPARSE_SWITCH'''.split() | |
779 for name in names: | |
780 opcode = name_2_opcodes[name] | |
781 opcode_fmts[opcode] = kFmt31t | |
782 pass | |
783 | |
784 | |
785 names = '''OP_ADD_INT_LIT8 | |
786 OP_RSUB_INT_LIT8 | |
787 OP_MUL_INT_LIT8 | |
788 OP_DIV_INT_LIT8 | |
789 OP_REM_INT_LIT8 | |
790 OP_AND_INT_LIT8 | |
791 OP_OR_INT_LIT8 | |
792 OP_XOR_INT_LIT8 | |
793 OP_SHL_INT_LIT8 | |
794 OP_SHR_INT_LIT8 | |
795 OP_USHR_INT_LIT8'''.split() | |
796 for name in names: | |
797 opcode = name_2_opcodes[name] | |
798 opcode_fmts[opcode] = kFmt22b | |
799 pass | |
800 | |
801 | |
802 names = '''OP_INSTANCE_OF | |
803 OP_NEW_ARRAY | |
804 OP_IGET | |
805 OP_IGET_WIDE | |
806 OP_IGET_OBJECT | |
807 OP_IGET_BOOLEAN | |
808 OP_IGET_BYTE | |
809 OP_IGET_CHAR | |
810 OP_IGET_SHORT | |
811 OP_IPUT | |
812 OP_IPUT_WIDE | |
813 OP_IPUT_OBJECT | |
814 OP_IPUT_BOOLEAN | |
815 OP_IPUT_BYTE | |
816 OP_IPUT_CHAR | |
817 OP_IPUT_SHORT'''.split() | |
818 for name in names: | |
819 opcode = name_2_opcodes[name] | |
820 opcode_fmts[opcode] = kFmt22c | |
821 pass | |
822 | |
823 | |
824 names = '''OP_ADD_INT_LIT16 | |
825 OP_RSUB_INT | |
826 OP_MUL_INT_LIT16 | |
827 OP_DIV_INT_LIT16 | |
828 OP_REM_INT_LIT16 | |
829 OP_AND_INT_LIT16 | |
830 OP_OR_INT_LIT16 | |
831 OP_XOR_INT_LIT16'''.split() | |
832 for name in names: | |
833 opcode = name_2_opcodes[name] | |
834 opcode_fmts[opcode] = kFmt22s | |
835 pass | |
836 | |
837 | |
838 names = '''OP_IF_EQ | |
839 OP_IF_NE | |
840 OP_IF_LT | |
841 OP_IF_GE | |
842 OP_IF_GT | |
843 OP_IF_LE'''.split() | |
844 for name in names: | |
845 opcode = name_2_opcodes[name] | |
846 opcode_fmts[opcode] = kFmt22t | |
847 pass | |
848 | |
849 | |
850 names = '''OP_MOVE_FROM16 | |
851 OP_MOVE_WIDE_FROM16 | |
852 OP_MOVE_OBJECT_FROM16'''.split() | |
853 for name in names: | |
854 opcode = name_2_opcodes[name] | |
855 opcode_fmts[opcode] = kFmt22x | |
856 pass | |
857 | |
858 | |
859 names = '''OP_CMPL_FLOAT | |
860 OP_CMPG_FLOAT | |
861 OP_CMPL_DOUBLE | |
862 OP_CMPG_DOUBLE | |
863 OP_CMP_LONG | |
864 OP_AGET | |
865 OP_AGET_WIDE | |
866 OP_AGET_OBJECT | |
867 OP_AGET_BOOLEAN | |
868 OP_AGET_BYTE | |
869 OP_AGET_CHAR | |
870 OP_AGET_SHORT | |
871 OP_APUT | |
872 OP_APUT_WIDE | |
873 OP_APUT_OBJECT | |
874 OP_APUT_BOOLEAN | |
875 OP_APUT_BYTE | |
876 OP_APUT_CHAR | |
877 OP_APUT_SHORT | |
878 OP_ADD_INT | |
879 OP_SUB_INT | |
880 OP_MUL_INT | |
881 OP_DIV_INT | |
882 OP_REM_INT | |
883 OP_AND_INT | |
884 OP_OR_INT | |
885 OP_XOR_INT | |
886 OP_SHL_INT | |
887 OP_SHR_INT | |
888 OP_USHR_INT | |
889 OP_ADD_LONG | |
890 OP_SUB_LONG | |
891 OP_MUL_LONG | |
892 OP_DIV_LONG | |
893 OP_REM_LONG | |
894 OP_AND_LONG | |
895 OP_OR_LONG | |
896 OP_XOR_LONG | |
897 OP_SHL_LONG | |
898 OP_SHR_LONG | |
899 OP_USHR_LONG | |
900 OP_ADD_FLOAT | |
901 OP_SUB_FLOAT | |
902 OP_MUL_FLOAT | |
903 OP_DIV_FLOAT | |
904 OP_REM_FLOAT | |
905 OP_ADD_DOUBLE | |
906 OP_SUB_DOUBLE | |
907 OP_MUL_DOUBLE | |
908 OP_DIV_DOUBLE | |
909 OP_REM_DOUBLE'''.split() | |
910 for name in names: | |
911 opcode = name_2_opcodes[name] | |
912 opcode_fmts[opcode] = kFmt23x | |
913 pass | |
914 | |
915 | |
916 names = '''OP_CONST | |
917 OP_CONST_WIDE_32'''.split() | |
918 for name in names: | |
919 opcode = name_2_opcodes[name] | |
920 opcode_fmts[opcode] = kFmt31i | |
921 pass | |
922 | |
923 | |
924 opcode_fmts[OP_CONST_STRING_JUMBO] = kFmt31c | |
925 | |
926 | |
927 names = '''OP_MOVE_16 | |
928 OP_MOVE_WIDE_16 | |
929 OP_MOVE_OBJECT_16'''.split() | |
930 for name in names: | |
931 opcode = name_2_opcodes[name] | |
932 opcode_fmts[opcode] = kFmt32x | |
933 pass | |
934 | |
935 | |
936 names = '''OP_FILLED_NEW_ARRAY | |
937 OP_INVOKE_VIRTUAL | |
938 OP_INVOKE_SUPER | |
939 OP_INVOKE_DIRECT | |
940 OP_INVOKE_STATIC | |
941 OP_INVOKE_INTERFACE'''.split() | |
942 for name in names: | |
943 opcode = name_2_opcodes[name] | |
944 opcode_fmts[opcode] = kFmt35c | |
945 pass | |
946 | |
947 | |
948 names = '''OP_FILLED_NEW_ARRAY_RANGE | |
949 OP_INVOKE_VIRTUAL_RANGE | |
950 OP_INVOKE_SUPER_RANGE | |
951 OP_INVOKE_DIRECT_RANGE | |
952 OP_INVOKE_STATIC_RANGE | |
953 OP_INVOKE_INTERFACE_RANGE'''.split() | |
954 for name in names: | |
955 opcode = name_2_opcodes[name] | |
956 opcode_fmts[opcode] = kFmt3rc | |
957 pass | |
958 | |
959 | |
960 opcode_fmts[OP_CONST_WIDE] = kFmt51l | |
961 | |
962 | |
963 names = '''OP_IGET_QUICK | |
964 OP_IGET_WIDE_QUICK | |
965 OP_IGET_OBJECT_QUICK | |
966 OP_IPUT_QUICK | |
967 OP_IPUT_WIDE_QUICK | |
968 OP_IPUT_OBJECT_QUICK'''.split() | |
969 for name in names: | |
970 opcode = name_2_opcodes[name] | |
971 opcode_fmts[opcode] = kFmt22cs | |
972 pass | |
973 | |
974 | |
975 names = '''OP_INVOKE_VIRTUAL_QUICK | |
976 OP_INVOKE_SUPER_QUICK'''.split() | |
977 for name in names: | |
978 opcode = name_2_opcodes[name] | |
979 opcode_fmts[opcode] = kFmt35ms | |
980 pass | |
981 | |
982 | |
983 names = '''OP_INVOKE_VIRTUAL_QUICK_RANGE | |
984 OP_INVOKE_SUPER_QUICK_RANGE'''.split() | |
985 for name in names: | |
986 opcode = name_2_opcodes[name] | |
987 opcode_fmts[opcode] = kFmt3rms | |
988 pass | |
989 | |
990 | |
991 opcode_fmts[OP_EXECUTE_INLINE] = kFmt3inline | |
992 | |
993 opcode_fmts[OP_INVOKE_DIRECT_EMPTY] = kFmt35c | |
994 | |
995 | |
996 names = '''OP_UNUSED_3E | |
997 OP_UNUSED_3F | |
998 OP_UNUSED_40 | |
999 OP_UNUSED_41 | |
1000 OP_UNUSED_42 | |
1001 OP_UNUSED_43 | |
1002 OP_UNUSED_73 | |
1003 OP_UNUSED_79 | |
1004 OP_UNUSED_7A | |
1005 OP_UNUSED_E3 | |
1006 OP_UNUSED_E4 | |
1007 OP_UNUSED_E5 | |
1008 OP_UNUSED_E6 | |
1009 OP_UNUSED_E7 | |
1010 OP_UNUSED_E8 | |
1011 OP_UNUSED_E9 | |
1012 OP_UNUSED_EA | |
1013 OP_UNUSED_EB | |
1014 OP_UNUSED_EC | |
1015 OP_UNUSED_ED | |
1016 OP_UNUSED_EF | |
1017 OP_UNUSED_F1 | |
1018 OP_UNUSED_FC | |
1019 OP_UNUSED_FD | |
1020 OP_UNUSED_FE | |
1021 OP_UNUSED_FF'''.split() | |
1022 for name in names: | |
1023 opcode = name_2_opcodes[name] | |
1024 opcode_fmts[opcode] = kFmtUnknown | |
1025 pass | |
1026 | |
1027 | |
1028 fmt_fmtstr = { | |
1029 'kFmtUnknown': '', | |
1030 'kFmt10x': '', | |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1031 'kFmt12x': 'v{0}, v{1}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1032 'kFmt11n': 'v{0}, #+{1}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1033 'kFmt11x': 'v{0}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1034 'kFmt10t': '+{0}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1035 'kFmt20t': '+{0}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1036 'kFmt22x': 'v{0}, {1:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1037 'kFmt21t': 'v{0}, +{1:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1038 'kFmt21s': 'v{0}, #+{1:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1039 'kFmt21h': 'v{0}, #+{1:04x}00000[00000000]', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1040 'kFmt21c': 'v{0}, thing@{:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1041 'kFmt23x': 'v{0}, v{1}, v{2}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1042 'kFmt22b': 'v{0}, v{1}, #+{2:02x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1043 'kFmt22t': 'v{0}, v{1}, +{2:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1044 'kFmt22s': 'v{0}, v{1}, #+{2:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1045 'kFmt22c': 'v{0}, v{1}, thing@{2:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1046 'kFmt22cs': 'v0{}, v{1}, field offset {2:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1047 'kFmt32x': 'v{0:04x}, v{1:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1048 'kFmt30t': '+{0:08x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1049 'kFmt31t': 'v{0}, +{1:08x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1050 'kFmt31i': 'v{0}, #+{1:08x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1051 'kFmt31c': 'v{0}, thing@{1:08x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1052 'kFmt35c': '{{v{3}, v{4}, v{5}, v{6}, v{0}}}, thing@{2:04x} ({1}: count, A: vG)', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1053 'kFmt35ms': '{{v{3}, v{4}, v{5}, v{6}, v{0}}}, thing@{2:04x} ({1}: count, A: vG)', |
69 | 1054 'kFmt35fs': 'invoke-interface', |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1055 'kFmt3rc': '{{v{2:04x} .. v({2:04x}+{0:02x}-1)}}, meth@{1:04x}', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1056 'kFmt3rms': '{{v{2:04x} .. v({2:04x}+{0:02x}-1)}}, meth@{1:04x}', |
69 | 1057 'kFmt3rfs': 'invoke-interface/range', |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1058 'kFmt3inline': '{{v{3}, v{4}, v{5}, v{6}}} thing@{2:04x} ({1}: count)', |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1059 'kFmt51l': 'v{0}, #+{1:016x}' |
69 | 1060 } |
1061 | |
1062 fmt_parse_cfgs = { | |
1063 'kFmtUnknown': (), # '' | |
1064 'kFmt10x': (), # '' | |
1065 'kFmt12x': (1, 1), # 'vA, vB' | |
1066 'kFmt11n': (1, 2), # 'vA, #+B' | |
1067 'kFmt11x': (2,), # 'vAA' | |
1068 'kFmt10t': (2,), # '+AA' | |
1069 'kFmt20t': (4,), # '+AAAA' | |
1070 'kFmt22x': (2, 4), # 'vAA, vBBBB' | |
1071 'kFmt21t': (2, 4), # 'vAA, +BBBB' | |
1072 'kFmt21s': (2, 4), # 'vAA, #+BBBB' | |
1073 'kFmt21h': (2, 4), # 'vAA, #+BBBB00000[00000000]' | |
1074 'kFmt21c': (2, 4), # 'vAA, thing@BBBB' | |
1075 'kFmt23x': (2, 2, 2), # 'vAA, vBB, vCC' | |
1076 'kFmt22b': (2, 2, 2), # 'vAA, vBB, #+CC' | |
1077 'kFmt22t': (1, 1, 4), # 'vA, vB, +CCCC' | |
1078 'kFmt22s': (1, 1, 4), # 'vA, vB, #+CCCC' | |
1079 'kFmt22c': (1, 1, 4), # 'vA, vB, thing@CCCC' | |
1080 'kFmt22cs': (1, 1, 4), # 'vA, vB, field offset CCCC' | |
1081 'kFmt32x': (4, 4), # 'vAAAA, vBBBB' | |
1082 'kFmt30t': (8,), # '+AAAAAAAA' | |
1083 'kFmt31t': (2, 8), # 'vAA, +BBBBBBBB' | |
1084 'kFmt31i': (2, 8), # 'vAA, #+BBBBBBBB' | |
1085 'kFmt31c': (2, 8), # 'vAA, thing@BBBBBBBB' | |
1086 # '{vC, vD, vE, vF, vG}, thing@BBBB (B: count, A: vG)' | |
1087 'kFmt35c': (1, 1, 4, 1, 1, 1, 1), | |
1088 'kFmt35ms': (1, 1, 4, 1, 1, 1, 1), # 'invoke-virtual+super' | |
1089 'kFmt35fs': (), # 'invoke-interface' | |
1090 'kFmt3rc': (2, 4, 4), # '{vCCCC .. v(CCCC+AA-1)}, meth@BBBB' | |
1091 'kFmt3rms': (2, 4, 4), # 'invoke-virtual+super/range' | |
1092 'kFmt3rfs': (), # 'invoke-interface/range' | |
1093 'kFmt3inline': (1, 1, 4, 1, 1, 1, 1), # 'inline invoke' | |
1094 'kFmt51l': (2, 16) # 'vAA, #+BBBBBBBBBBBBBBBB' | |
1095 } | |
1096 | |
1097 def decode_inst(insn): | |
1098 def build_arg(sz): | |
1099 if sz == 1: | |
1100 if build_arg.off & 0x1: | |
1101 arg = ord(insn[build_arg.off / 2]) >> 4 | |
1102 else: | |
1103 arg = ord(insn[build_arg.off / 2]) & 0xf | |
1104 pass | |
1105 build_arg.off = build_arg.off + 1 | |
1106 pass | |
1107 elif sz == 2: | |
1108 build_arg.off = (build_arg.off + 1) & ~0x1 | |
1109 arg = ord(insn[build_arg.off / 2]) | |
1110 build_arg.off = build_arg.off + 2 | |
1111 elif sz == 4: | |
1112 build_arg.off = (build_arg.off + 3) & ~0x3 | |
1113 arg = ord(insn[build_arg.off / 2]) | \ | |
1114 (ord(insn[build_arg.off / 2 + 1]) << 8) | |
1115 build_arg.off = build_arg.off + 4 | |
1116 elif sz == 8: | |
1117 build_arg.off = (build_arg.off + 3) & ~0x3 | |
1118 arg = ord(insn[build_arg.off / 2]) | \ | |
1119 (ord(insn[build_arg.off / 2 + 1]) << 8) | \ | |
1120 (ord(insn[build_arg.off / 2 + 2]) << 16)| \ | |
1121 (ord(insn[build_arg.off / 2 + 3]) << 24) | |
1122 build_arg.off = build_arg.off + 8 | |
1123 elif sz == 16: | |
1124 build_arg.off = (build_arg.off + 3) & ~0x3 | |
1125 arg = ord(insn[build_arg.off / 2]) | \ | |
1126 (ord(insn[build_arg.off / 2 + 1]) << 8) | \ | |
1127 (ord(insn[build_arg.off / 2 + 2]) << 16)| \ | |
1128 (ord(insn[build_arg.off / 2 + 3]) << 24)| \ | |
1129 (ord(insn[build_arg.off / 2 + 4]) << 32)| \ | |
1130 (ord(insn[build_arg.off / 2 + 5]) << 40)| \ | |
1131 (ord(insn[build_arg.off / 2 + 6]) << 48)| \ | |
1132 (ord(insn[build_arg.off / 2 + 7]) << 52) | |
1133 build_arg.off = build_arg.off + 16 | |
1134 else: | |
1135 raise ValueError, 'Invalid argument size %d' % (sz) | |
1136 | |
1137 return arg | |
1138 | |
1139 build_arg.off = 2 | |
1140 | |
1141 opcode = ord(insn[0]) | |
1142 | |
1143 fmt = opcode_fmts[opcode] | |
1144 fmt_name = fmt_names[fmt] | |
1145 fmt_parse_cfg = fmt_parse_cfgs[fmt_name] | |
1146 | |
1147 args = tuple([build_arg(sz) for sz in fmt_parse_cfg]) | |
1148 op_vector = (opcode, args) | |
1149 return op_vector | |
1150 | |
1151 | |
1152 def encode_inst(op_vector): | |
1153 def encode_arg(arg, sz): | |
1154 if sz == 1: | |
1155 if encode_arg.off & 0x1: | |
1156 arg_txt = chr((arg << 4) | encode_arg.value) | |
1157 else: | |
1158 arg_txt = '' | |
1159 encode_arg.value = arg | |
1160 pass | |
1161 encode_arg.off = encode_arg.off + 1 | |
1162 pass | |
1163 elif sz in (2, 4, 8, 16): | |
1164 if encode_arg.off & 0x1: | |
1165 arg_txt = chr(encode_arg.value) | |
1166 encode_arg.off = encode_arg.off + 1 | |
1167 else: | |
1168 arg_txt = '' | |
1169 pass | |
1170 if sz == 2: | |
1171 arg_txt = arg_txt + chr(arg) | |
1172 encode_arg.off = encode_arg.off + 2 | |
1173 elif sz in (4, 8, 16): | |
1174 while encode_arg.off % 4: | |
1175 encode_arg.off = encoe_arg.off + 1 | |
1176 arg_txt = arg_txt + chr(0) | |
1177 pass | |
1178 for i in range(sz / 4): | |
1179 arg_txt = arg_txt + \ | |
1180 chr(arg & 0xff) + chr((arg >> 8) & 0xff) | |
1181 pass | |
1182 pass | |
1183 pass | |
1184 else: | |
1185 raise ValueError, 'invalid argument size %d' % (sz) | |
1186 | |
1187 return arg_txt | |
1188 encode_arg.off = 2 | |
1189 encode_arg.value = 0 | |
1190 | |
1191 opcode, args = op_vector | |
1192 | |
1193 fmt = opcode_fmts[opcode] | |
1194 fmt_name = fmt_names[fmt] | |
1195 fmt_parse_cfg = fmt_parse_cfgs[fmt_name] | |
1196 arg_part = ''.join([encode_arg(arg, sz) | |
1197 for arg, sz in map(None, args, fmt_parse_cfg)]) | |
72
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1198 |
73
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
1199 while encode_arg.off % 4: |
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
1200 arg_part = arg_part + encode_arg(0, 1) |
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
1201 pass |
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
1202 |
72
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1203 inst = chr(opcode) + arg_part |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1204 |
69 | 1205 return inst |
1206 | |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1207 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1208 def format_inst(op_vector): |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1209 opcode, args = op_vector |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1210 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1211 opname = opcode_names[opcode] |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1212 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1213 fmt = opcode_fmts[opcode] |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1214 fmt_name = fmt_names[fmt] |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1215 fmt_str = fmt_fmtstr[fmt_name] |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1216 |
72
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1217 if fmt_str: |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1218 line = opname + ' ' + fmt_str.format(*args) |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1219 else: |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1220 line = opname |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
70
diff
changeset
|
1221 pass |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1222 return line |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1223 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1224 |
69 | 1225 del name |
1226 del names | |
1227 del opcode |