changeset 103:8a53e6f7f517

Provide convinience API to convert str block into opcode vectors
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 27 Jul 2011 12:09:19 +0800
parents 7fcd555d802b
children 61cef1662035
files paraspace/dalvik_opcodes.py paraspace/dump_code.py
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dalvik_opcodes.py	Wed Jul 27 09:07:36 2011 +0800
+++ b/paraspace/dalvik_opcodes.py	Wed Jul 27 12:09:19 2011 +0800
@@ -1256,6 +1256,20 @@
     pass
 
 
+## \brief Decode a block of instructions.
+#
+# Split and docode a block of instructions into a list of opcode
+# vectors.
+#
+# \param insn_blk is a string that is block of instructions.
+# \return a list of (opcode, args) vectors.
+#
+def decode_insn_blk(insn_blk):
+    insns = split_blk_2_insns(insn_blk)
+    decoded_insns = [decode_inst(insn) for insn in insns]
+    return decoded_insns
+
+
 del name
 del _names
 del _opcode
--- a/paraspace/dump_code.py	Wed Jul 27 09:07:36 2011 +0800
+++ b/paraspace/dump_code.py	Wed Jul 27 12:09:19 2011 +0800
@@ -1,6 +1,5 @@
 from paraspace.dexfile import DEXFile
-from paraspace.dalvik_opcodes import split_blk_2_insns, decode_inst
-from paraspace.dalvik_opcodes import format_inst
+from paraspace.dalvik_opcodes import decode_insn_blk, format_inst
 
 
 def dump_code_item(item, dex):
@@ -11,7 +10,7 @@
     print 'debugInfoOff: 0x%x' % (item.debugInfoOff)
     print 'insnsSize: %d' % (item.insnsSize)
     block = item.insns.data
-    op_vectors = [decode_inst(insn) for insn in split_blk_2_insns(block)]
+    op_vectors = decode_insn_blk(block)
     for op_vector in op_vectors:
         op_str = format_inst(op_vector)
         print '\t%s' % (op_str)