changeset 84:63de54e61e5b

Add dump_code.py
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 20 Jul 2011 21:31:22 +0800
parents fd668c00e7e0
children 55ae976c3ff8
files paraspace/dump_code.py
diffstat 1 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paraspace/dump_code.py	Wed Jul 20 21:31:22 2011 +0800
@@ -0,0 +1,41 @@
+from paraspace.dexfile import DEXFile
+from paraspace.dalvik_opcodes import split_blk_2_insns, decode_inst
+from paraspace.dalvik_opcodes import format_inst
+
+
+def dump_code_item(item, dex):
+    print 'registersSize: %d' % (item.registersSize)
+    print 'insSize: %d' % (item.insSize)
+    print 'outsSize: %d' % (item.outsSize)
+    print 'triesSize: %d' % (item.triesSize)
+    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)]
+    for op_vector in op_vectors:
+        op_str = format_inst(op_vector)
+        print '\t%s' % (op_str)
+        pass
+    pass
+
+
+def dump_code_items_filename(fn):
+    dex = DEXFile.open(fn)
+    items = dex.codeItems.items
+    for item in items:
+        dump_code_item(item, dex)
+        pass
+    pass
+
+
+if __name__ == '__main__':
+    import sys
+    
+    if len(sys.argv) != 2:
+        print >> sys.stderr, 'Usage: %s <dex file>' % (sys.argv[0])
+        sys.exit(1)
+        pass
+    
+    fn = sys.argv[1]
+    dump_code_items_filename(fn)
+    pass