about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <serpilliere@users.noreply.github.com>2019-11-22 06:48:27 +0100
committerGitHub <noreply@github.com>2019-11-22 06:48:27 +0100
commit30916ae176b52ccf9aa894ebe65e822deb115743 (patch)
tree9313bf1c07c20738dfaee7954a0985f666c845de
parent7ae7576c2a506806defa276d8c328c50f29d3ac3 (diff)
parent9ac74510eb5c9ed0ba6234ba4215f0b147b71e5d (diff)
downloadmiasm-30916ae176b52ccf9aa894ebe65e822deb115743.tar.gz
miasm-30916ae176b52ccf9aa894ebe65e822deb115743.zip
Merge pull request #1102 from serpilliere/asm_fix_instr_gen
Asmblock: fix instruction generation
-rw-r--r--miasm/core/asmblock.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/miasm/core/asmblock.py b/miasm/core/asmblock.py
index 9b07686f..a92e5bf9 100644
--- a/miasm/core/asmblock.py
+++ b/miasm/core/asmblock.py
@@ -1227,8 +1227,23 @@ def assemble_block(mnemo, block, loc_db, conservative=False):
             instr.fixDstOffset()
 
         old_l = instr.l
-        cached_candidate, _ = conservative_asm(mnemo, instr, loc_db,
-                                               conservative)
+        cached_candidate, _ = conservative_asm(
+            mnemo, instr, loc_db,
+            conservative
+        )
+        if len(cached_candidate) != instr.l:
+            # The output instruction length is different from the one we guessed
+            # Retry assembly with updated length
+            instr.l = len(cached_candidate)
+            instr.args = saved_args
+            instr.args = instr.resolve_args_with_symbols(loc_db)
+            if instr.dstflow():
+                instr.fixDstOffset()
+            cached_candidate, _ = conservative_asm(
+                mnemo, instr, loc_db,
+                conservative
+            )
+            assert len(cached_candidate) == instr.l
 
         # Restore original arguments
         instr.args = saved_args