Mercurial > paraspace
comparison paraspace/injection.py @ 109:835336632aba
Add collect_typeidxs_in_method()
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 01 Aug 2011 14:37:04 +0800 |
parents | 18be67af7f1e |
children | 6380730a80b4 |
comparison
equal
deleted
inserted
replaced
108:18be67af7f1e | 109:835336632aba |
---|---|
362 if idx in excludes: | 362 if idx in excludes: |
363 continue | 363 continue |
364 class_redirect_types(dex, classdef, types_redir, methods_redir) | 364 class_redirect_types(dex, classdef, types_redir, methods_redir) |
365 pass | 365 pass |
366 pass | 366 pass |
367 | |
368 | |
369 ## \brief Collect all type indices mentioned in the code of given method. | |
370 # | |
371 # \param method is a \ref _DEX_Method. | |
372 # | |
373 def collect_typeidxs_in_method(dex, method): | |
374 from paraspace.dexfile import _DEX_Method, DEXFile_linked | |
375 from paraspace.dalvik_opcodes import decode_insn_blk, all_opcodes | |
376 from itertools import chain | |
377 | |
378 assert isinstance(method, _DEX_Method) | |
379 | |
380 def get_typeidx_methodidx(methodidx): | |
381 methodid = dex.find_methodid_idx(methodidx) | |
382 method_typeid = methodid.classIdx | |
383 method_typeidx = dex.get_idx_typeid(method_typeid) | |
384 return method_typeidx | |
385 | |
386 def collect_types_in_op_vector(op_vector): | |
387 code, args = op_vector | |
388 | |
389 if code == all_opcodes.OP_NEW_INSTANCE: | |
390 return (args[1],) | |
391 | |
392 if code in (all_opcodes.OP_INVOKE_DIRECT, | |
393 all_opcodes.OP_INVOKE_VIRTUAL, | |
394 all_opcodes.OP_INVOKE_SUPER, | |
395 all_opcodes.OP_INVOKE_STATIC, | |
396 all_opcodes.OP_INVOKE_INTERFACE): | |
397 methodidx = args[2] | |
398 method_typeidx = get_typeidx_methodidx(methodidx) | |
399 return (method_typeidx,) | |
400 | |
401 if code in (all_opcodes.OP_INVOKE_VIRTUAL_RANGE, | |
402 all_opcodes.OP_INVOKE_DIRECT_RANGE, | |
403 all_opcodes.OP_INVOKE_SUPER_RANGE, | |
404 all_opcodes.OP_INVOKE_STATIC_RANGE, | |
405 all_opcodes.OP_INVOKE_INTERFACE_RANGE): | |
406 methodidx = args[1] | |
407 method_typeidx = get_typeidx_methodidx(methodidx) | |
408 return (method_typeidx,) | |
409 | |
410 return () | |
411 | |
412 code_blk = DEXFile_linked.get_code_block_method(method) | |
413 op_vectors = decode_insn_blk(code_blk) | |
414 types_insns = [collect_types_in_op_vector(op_vector) | |
415 for op_vector in op_vectors] | |
416 typeidxs = list(chain(*types_insns)) | |
417 | |
418 return typeidxs |