about summary refs log tree commit diff stats
path: root/miasm/arch/aarch64/arch.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm/arch/aarch64/arch.py')
-rw-r--r--miasm/arch/aarch64/arch.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/miasm/arch/aarch64/arch.py b/miasm/arch/aarch64/arch.py
index 4c0bcb09..050aa638 100644
--- a/miasm/arch/aarch64/arch.py
+++ b/miasm/arch/aarch64/arch.py
@@ -14,6 +14,8 @@ from miasm.arch.aarch64.regs import *
 from miasm.core.cpu import log as log_cpu
 from miasm.core.modint import mod_size2int
 from miasm.core.asm_ast import AstInt, AstId, AstMem, AstOp
+from miasm.ir.ir import color_expr_html
+from miasm.core import utils
 
 log = logging.getLogger("aarch64dis")
 console_handler = logging.StreamHandler()
@@ -367,6 +369,73 @@ class instruction_aarch64(instruction):
         else:
             raise NotImplementedError("bad op")
 
+    @staticmethod
+    def arg2html(expr, index=None, loc_db=None):
+        wb = False
+        if expr.is_id() or expr.is_int() or expr.is_loc():
+            return color_expr_html(expr, loc_db)
+        elif isinstance(expr, m2_expr.ExprOp) and expr.op in shift_expr:
+            op_str = shift_str[shift_expr.index(expr.op)]
+            return "%s %s %s" % (
+                color_expr_html(expr.args[0], loc_db),
+                utils.set_html_text_color(op_str, utils.COLOR_OP),
+                color_expr_html(expr.args[1], loc_db)
+            )
+        elif isinstance(expr, m2_expr.ExprOp) and expr.op == "slice_at":
+            return "%s LSL %s" % (
+                color_expr_html(expr.args[0], loc_db),
+                color_expr_html(expr.args[1], loc_db)
+            )
+        elif isinstance(expr, m2_expr.ExprOp) and expr.op in extend_lst:
+            op_str = expr.op
+            return "%s %s %s" % (
+                color_expr_html(expr.args[0], loc_db),
+                op_str,
+                color_expr_html(expr.args[1], loc_db)
+            )
+        elif isinstance(expr, m2_expr.ExprOp) and expr.op == "postinc":
+            if int(expr.args[1]) != 0:
+                return "[%s], %s" % (
+                    color_expr_html(expr.args[0], loc_db),
+                    color_expr_html(expr.args[1], loc_db)
+                )
+            else:
+                return "[%s]" % (color_expr_html(expr.args[0], loc_db))
+        elif isinstance(expr, m2_expr.ExprOp) and expr.op == "preinc_wb":
+            if int(expr.args[1]) != 0:
+                return "[%s, %s]!" % (
+                    color_expr_html(expr.args[0], loc_db),
+                    color_expr_html(expr.args[1], loc_db)
+                )
+            else:
+                return "[%s]" % (color_expr_html(expr.args[0], loc_db))
+        elif isinstance(expr, m2_expr.ExprOp) and expr.op == "preinc":
+            if len(expr.args) == 1:
+                return "[%s]" % (color_expr_html(expr.args[0], loc_db))
+            elif not isinstance(expr.args[1], m2_expr.ExprInt) or int(expr.args[1]) != 0:
+                return "[%s, %s]" % (
+                    color_expr_html(expr.args[0], loc_db),
+                    color_expr_html(expr.args[1], loc_db)
+                )
+            else:
+                return "[%s]" % color_expr_html(expr.args[0], loc_db)
+        elif isinstance(expr, m2_expr.ExprOp) and expr.op == 'segm':
+            arg = color_expr_html(expr.args[1], loc_db)
+            if isinstance(arg, m2_expr.ExprId):
+                arg = str(arg)
+            elif arg.op == 'LSL' and int(arg.args[1]) == 0:
+                arg = str(arg.args[0])
+            else:
+                arg = "%s %s %s" % (
+                    color_expr_html(arg.args[0], loc_db),
+                    utils.set_html_text_color(arg.op, utils.COLOR_OP),
+                    color_expr_html(arg.args[1], loc_db)
+                )
+            return '[%s, %s]' % (color_expr_html(expr.args[0], loc_db), arg)
+
+        else:
+            raise NotImplementedError("bad op")
+
     def dstflow(self):
         return self.name in BRCOND + ["B", "BL", "BR", "BLR"]