changeset 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 cdc27039654c
files paraspace/dalvik_opcodes.py paraspace/tests/dalvik_opcodes_test.py
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dalvik_opcodes.py	Sat Jul 02 00:03:17 2011 +0800
+++ b/paraspace/dalvik_opcodes.py	Sat Jul 02 00:09:50 2011 +0800
@@ -1196,12 +1196,12 @@
     arg_part = ''.join([encode_arg(arg, sz)
                         for arg, sz in map(None, args, fmt_parse_cfg)])
 
+    while encode_arg.off % 4:
+        arg_part = arg_part + encode_arg(0, 1)
+        pass
+    
     inst = chr(opcode) + arg_part
 
-    while len(inst) % 2:
-        encode_arg(0, 1)
-        pass
-    
     return inst
 
 
--- a/paraspace/tests/dalvik_opcodes_test.py	Sat Jul 02 00:03:17 2011 +0800
+++ b/paraspace/tests/dalvik_opcodes_test.py	Sat Jul 02 00:09:50 2011 +0800
@@ -14,6 +14,11 @@
     opv = (0x6f, (0, 1, 0xa601, 1, 0, 0, 0))
     insn = encode_inst(opv)
     assert insn == '\x6f\x10\x01\xa6\x01\x00'
+    
+    opv = (0, ())
+    insn = encode_inst(opv)
+    print repr(insn)
+    assert insn == '\x00\x00'
     pass