# HG changeset patch # User Thinker K.F. Li # Date 1311168682 -28800 # Node ID 63de54e61e5bedae4c2dafba7f4c216100e1148b # Parent fd668c00e7e08eac223753109d6d41055fba6e58 Add dump_code.py diff -r fd668c00e7e0 -r 63de54e61e5b paraspace/dump_code.py --- /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 ' % (sys.argv[0]) + sys.exit(1) + pass + + fn = sys.argv[1] + dump_code_items_filename(fn) + pass