about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2013-02-13 11:19:38 +0100
committerserpilliere <devnull@localhost>2013-02-13 11:19:38 +0100
commit40641e97e5d5b72844e453b6d7b8cf937c9e8a02 (patch)
tree32cec05097c0e7c58dde994bef8ea17cf7f8c723
parent46604bef980e07af45f6fd6a4c2cd2dd48c64569 (diff)
downloadmiasm-40641e97e5d5b72844e453b6d7b8cf937c9e8a02.tar.gz
miasm-40641e97e5d5b72844e453b6d7b8cf937c9e8a02.zip
fix shld with 0 shifter
Diffstat (limited to '')
-rw-r--r--miasm/arch/ia32_sem.py35
-rw-r--r--miasm/tools/emul_lib/libcodenat.h19
-rw-r--r--miasm/tools/to_c_helper.py2
3 files changed, 15 insertions, 41 deletions
diff --git a/miasm/arch/ia32_sem.py b/miasm/arch/ia32_sem.py
index 46619e1a..211e0bfd 100644
--- a/miasm/arch/ia32_sem.py
+++ b/miasm/arch/ia32_sem.py
@@ -839,35 +839,7 @@ def shl(info, a, b):
     return e
 
 def shld_cl(info, a, b):
-    e= []
-    shifter = ExprOp('&',ecx, ExprInt_from(a, 0x1f))
-    c = ExprOp('|',
-            ExprOp('<<', a, shifter),
-            ExprOp('>>', b, ExprOp('-',
-                                    ExprInt_from(a, a.get_size()),
-                                    shifter)
-                                    )
-          )
-
-    new_cf = ExprOp('&',
-                    ExprInt_from(a, 1),
-                    ExprOp('>>',
-                           a,
-                           ExprOp('-',
-                                  ExprInt_from(b, a.get_size()),
-                                  shifter
-                                  )
-                           )
-                    )
-    e.append(ExprAff(cf, ExprCond(shifter,
-                                  new_cf,
-                                  cf)
-                     )
-             )
-    e+=update_flag_znp(c)
-    e.append(ExprAff(of, ExprOp('^', get_op_msb(c), new_cf)))
-    e.append(ExprAff(a, c))
-    return e
+    return shld(info, a, b, ecx)
 
 def shld(info, a, b, c):
     e= []
@@ -895,9 +867,12 @@ def shld(info, a, b, c):
                                   cf)
                      )
              )
+    # XXX todo: don't update flag if shifter is 0
     e+=update_flag_znp(c)
     e.append(ExprAff(of, ExprOp('^', get_op_msb(c), new_cf)))
-    e.append(ExprAff(a, c))
+    e.append(ExprAff(a, ExprCond(shifter,
+                                 c,
+                                 a)))
     return e
 
 
diff --git a/miasm/tools/emul_lib/libcodenat.h b/miasm/tools/emul_lib/libcodenat.h
index 43d247e8..8865b285 100644
--- a/miasm/tools/emul_lib/libcodenat.h
+++ b/miasm/tools/emul_lib/libcodenat.h
@@ -515,26 +515,25 @@ uint64_t double_to_mem_64(double d);
 
 
 #define shift_right_arith_08(a, b)\
-	((((char)(a)) >> ((int)(b)))&0xff)
+	((((char)(a)) >> ((int)(b)&0x1f))&0xff)
 #define shift_right_arith_16(a, b)\
-	((((short)(a)) >> ((int)(b)))&0xffff)
+	((((short)(a)) >> ((int)(b)&0x1f))&0xffff)
 #define shift_right_arith_32(a, b)\
-	((((int)(a)) >> ((int)(b)))&0xffffffff)
+	((((int)(a)) >> ((int)(b)&0x1f))&0xffffffff)
 
 
 #define shift_right_logic_08(a, b)\
-	((((unsigned char)(a)) >> ((unsigned int)(b)))&0xff)
+	((((unsigned char)(a)) >> ((unsigned int)(b)&0x1f))&0xff)
 #define shift_right_logic_16(a, b)\
-	((((unsigned short)(a)) >> ((unsigned int)(b)))&0xffff)
+	((((unsigned short)(a)) >> ((unsigned int)(b)&0x1f))&0xffff)
 #define shift_right_logic_32(a, b)\
-	((((unsigned int)(a)) >> ((unsigned int)(b)))&0xffffffff)
-
+	((((unsigned int)(a)) >> ((unsigned int)(b)&0x1f))&0xffffffff)
 
 #define shift_left_logic_08(a, b)\
-	(((a)<<(b))&0xff)
+	(((a)<<((b)&0x1f))&0xff)
 #define shift_left_logic_16(a, b)\
-	(((a)<<(b))&0xffff)
+	(((a)<<((b)&0x1f))&0xffff)
 #define shift_left_logic_32(a, b)\
-	(((a)<<(b))&0xffffffff)
+	(((a)<<((b)&0x1f))&0xffffffff)
 
 #endif
diff --git a/miasm/tools/to_c_helper.py b/miasm/tools/to_c_helper.py
index 84f8df22..e80a7067 100644
--- a/miasm/tools/to_c_helper.py
+++ b/miasm/tools/to_c_helper.py
@@ -1323,7 +1323,7 @@ def do_bloc_emul(known_blocs, in_str, my_eip, symbol_pool,
     if not known_blocs[my_eip].b.lines:
         raise ValueError('cannot disasm bloc')
     try:
-        my_eip = vm_exec_blocs(my_eip, known_blocs)
+        my_eip = vm_exec_bloc(my_eip, known_blocs)
     except KeyboardInterrupt:
         return None, None
     py_exception = vm_get_exception()