about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2015-07-29 16:28:45 +0200
committerserpilliere <fabrice.desclaux@cea.fr>2015-07-29 19:29:37 +0200
commit484190af82fd2ddba7d9cd04878da4fe67b8a91c (patch)
treefccf590aaad3c019d1c19cb752a70f5ce0259ce4
parentdb711b79cc5047757ab6af2f0960f0e3b52cba66 (diff)
downloadmiasm-484190af82fd2ddba7d9cd04878da4fe67b8a91c.tar.gz
miasm-484190af82fd2ddba7d9cd04878da4fe67b8a91c.zip
X86/Sem: add DAA/DAS
-rw-r--r--miasm2/arch/x86/sem.py62
1 files changed, 60 insertions, 2 deletions
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py
index 7f174e82..f99d2d9d 100644
--- a/miasm2/arch/x86/sem.py
+++ b/miasm2/arch/x86/sem.py
@@ -20,6 +20,7 @@ import miasm2.expression.expression as m2_expr
 from miasm2.expression.simplifications import expr_simp
 from miasm2.arch.x86.regs import *
 from miasm2.arch.x86.arch import mn_x86, repeat_mn, replace_regs
+from miasm2.expression.expression_helper import expr_cmps, expr_cmpu
 from miasm2.ir.ir import ir, irbloc
 import math
 import struct
@@ -2458,9 +2459,65 @@ def rdtsc(ir, instr):
     return e, []
 
 
-# XXX TODO
 def daa(ir, instr):
-    return [], None
+    e = []
+    r_al = mRAX[instr.mode][:8]
+
+    cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt_fromsize(4, 0x9)) | af
+    e.append(m2_expr.ExprAff(af, cond1))
+
+
+    cond2 = expr_cmpu(m2_expr.ExprInt8(6), r_al)
+    cond3 = expr_cmpu(r_al, m2_expr.ExprInt8(0x99)) | cf
+
+
+    cf_c1 = m2_expr.ExprCond(cond1,
+                             cf | (cond2),
+                             m2_expr.ExprInt1(0))
+    new_cf = m2_expr.ExprCond(cond3,
+                              m2_expr.ExprInt1(1),
+                              m2_expr.ExprInt1(0))
+    e.append(m2_expr.ExprAff(cf, new_cf))
+
+    al_c1 = m2_expr.ExprCond(cond1,
+                             r_al + m2_expr.ExprInt8(6),
+                             r_al)
+
+    new_al = m2_expr.ExprCond(cond3,
+                              al_c1 + m2_expr.ExprInt8(0x60),
+                              al_c1)
+    e.append(m2_expr.ExprAff(r_al, new_al))
+    return e, []
+
+def das(ir, instr):
+    e = []
+    r_al = mRAX[instr.mode][:8]
+
+    cond1 = expr_cmpu(r_al[:4], m2_expr.ExprInt_fromsize(4, 0x9)) | af
+    e.append(m2_expr.ExprAff(af, cond1))
+
+
+    cond2 = expr_cmpu(m2_expr.ExprInt8(6), r_al)
+    cond3 = expr_cmpu(r_al, m2_expr.ExprInt8(0x99)) | cf
+
+
+    cf_c1 = m2_expr.ExprCond(cond1,
+                             cf | (cond2),
+                             m2_expr.ExprInt1(0))
+    new_cf = m2_expr.ExprCond(cond3,
+                              m2_expr.ExprInt1(1),
+                              cf_c1)
+    e.append(m2_expr.ExprAff(cf, new_cf))
+
+    al_c1 = m2_expr.ExprCond(cond1,
+                             r_al - m2_expr.ExprInt8(6),
+                             r_al)
+
+    new_al = m2_expr.ExprCond(cond3,
+                              al_c1 - m2_expr.ExprInt8(0x60),
+                              al_c1)
+    e.append(m2_expr.ExprAff(r_al, new_al))
+    return e, []
 
 
 def aam(ir, instr, a):
@@ -3314,6 +3371,7 @@ mnemo_func = {'mov': mov,
               'cqo': cqo,
 
               'daa': daa,
+              'das': das,
               'aam': aam,
               'aad': aad,
               'aaa': aaa,