about summary refs log tree commit diff stats
path: root/miasm/core
diff options
context:
space:
mode:
Diffstat (limited to 'miasm/core')
-rw-r--r--miasm/core/asmblock.py10
-rw-r--r--miasm/core/cpu.py14
-rw-r--r--miasm/core/graph.py12
-rw-r--r--miasm/core/utils.py24
4 files changed, 54 insertions, 6 deletions
diff --git a/miasm/core/asmblock.py b/miasm/core/asmblock.py
index 47bffb34..e92034fe 100644
--- a/miasm/core/asmblock.py
+++ b/miasm/core/asmblock.py
@@ -35,6 +35,9 @@ class AsmRaw(object):
     def to_string(self, loc_db):
         return str(self)
 
+    def to_html(self, loc_db):
+        return str(self)
+
 
 class AsmConstraint(object):
     c_to = "c_to"
@@ -439,6 +442,9 @@ class AsmCFG(DiGraph):
             # between the two graphs
             self.add_edge(*edge, constraint=graph.edges2constraint[edge])
 
+    def escape_text(self, text):
+        return text
+
 
     def node2lines(self, node):
         loc_key_name = self.loc_db.pretty_str(node)
@@ -462,9 +468,9 @@ class AsmCFG(DiGraph):
             if self._dot_offset:
                 yield [self.DotCellDescription(text="%.8X" % line.offset,
                                                attr={}),
-                       self.DotCellDescription(text=line.to_string(self.loc_db), attr={})]
+                       self.DotCellDescription(text=line.to_html(self.loc_db), attr={})]
             else:
-                yield self.DotCellDescription(text=line.to_string(self.loc_db), attr={})
+                yield self.DotCellDescription(text=line.to_html(self.loc_db), attr={})
 
     def node_attr(self, node):
         block = self._loc_key_to_block.get(node, None)
diff --git a/miasm/core/cpu.py b/miasm/core/cpu.py
index d9c1955b..fac03248 100644
--- a/miasm/core/cpu.py
+++ b/miasm/core/cpu.py
@@ -19,6 +19,7 @@ from miasm.expression.simplifications import expr_simp
 
 
 from miasm.core.asm_ast import AstNode, AstInt, AstId, AstOp
+from miasm.core import utils
 from future.utils import with_metaclass
 
 log = logging.getLogger("cpuhelper")
@@ -1005,6 +1006,19 @@ class instruction(object):
         o += self.gen_args(args)
         return o
 
+    def to_html(self, loc_db=None):
+        out = "%-10s " % self.name
+        out = '<font color="%s">%s</font>' % (utils.COLOR_MNEMO, out)
+
+        args = []
+        for i, arg in enumerate(self.args):
+            if not isinstance(arg, m2_expr.Expr):
+                raise ValueError('zarb arg type')
+            x = self.arg2html(arg, i, loc_db)
+            args.append(x)
+        out += self.gen_args(args)
+        return out
+
     def get_asm_offset(self, expr):
         return m2_expr.ExprInt(self.offset, expr.size)
 
diff --git a/miasm/core/graph.py b/miasm/core/graph.py
index 1ee30c9f..0dfd7e6a 100644
--- a/miasm/core/graph.py
+++ b/miasm/core/graph.py
@@ -20,6 +20,9 @@ class DiGraph(object):
         # N -> Nodes N2 with a edge (N2 -> N)
         self._nodes_pred = {}
 
+        self.escape_chars = re.compile('[' + re.escape('{}') + '&|<>' + ']')
+
+
     def __repr__(self):
         out = []
         for node in self._nodes:
@@ -239,10 +242,12 @@ class DiGraph(object):
                            **attr))
         )
 
+    def escape_text(self, text):
+        return self.escape_chars.sub(self._fix_chars, text)
+
     def dot(self):
         """Render dot graph with HTML"""
 
-        escape_chars = re.compile('[' + re.escape('{}') + '&|<>' + ']')
         td_attr = {'align': 'left'}
         nodes_attr = {'shape': 'Mrecord',
                       'fontname': 'Courier New'}
@@ -266,7 +271,7 @@ class DiGraph(object):
                 for col in lineDesc:
                     out_render += "<td %s>%s</td>" % (
                         self._attr2str(td_attr, col.attr),
-                        escape_chars.sub(self._fix_chars, str(col.text)))
+                        self.escape_text(str(col.text)))
                 node_html_lines.append(out_render)
 
             node_html_lines = ('<tr>' +
@@ -302,7 +307,6 @@ class DiGraph(object):
 
             self.gv = graphviz.Digraph('html_table')
             self._dot_offset = False
-            escape_chars = re.compile('[' + re.escape('{}') + '&|<>' + ']')
             td_attr = {'align': 'left'}
             nodes_attr = {'shape': 'Mrecord',
                           'fontname': 'Courier New'}
@@ -320,7 +324,7 @@ class DiGraph(object):
                     for col in lineDesc:
                         out_render += "<td %s>%s</td>" % (
                             self._attr2str(td_attr, col.attr),
-                            escape_chars.sub(self._fix_chars, str(col.text)))
+                            self.escape_text(str(col.text)))
                     node_html_lines.append(out_render)
 
                 node_html_lines = ('<tr>' +
diff --git a/miasm/core/utils.py b/miasm/core/utils.py
index cfe96de4..41bf78c1 100644
--- a/miasm/core/utils.py
+++ b/miasm/core/utils.py
@@ -1,4 +1,5 @@
 from __future__ import print_function
+import re
 import sys
 from builtins import range
 import struct
@@ -16,6 +17,28 @@ from future.utils import viewitems
 
 import collections
 
+COLOR_INT = "azure4"
+COLOR_ID = "forestgreen"#"chartreuse3"
+COLOR_MEM = "deeppink4"
+COLOR_OP_FUNC = "blue1"
+COLOR_LOC = "darkslateblue"
+COLOR_OP = "black"
+
+COLOR_MNEMO = "blue1"
+
+ESCAPE_CHARS = re.compile('[' + re.escape('{}') + '&|<>' + ']')
+
+def set_html_text_color(text, color):
+    return '<font color="%s">%s</font>' % (color, text)
+
+
+def _fix_chars(token):
+    return "&#%04d;" % ord(token.group())
+
+
+def fix_html_chars(text):
+    return ESCAPE_CHARS.sub(_fix_chars, str(text))
+
 upck8 = lambda x: struct.unpack('B', x)[0]
 upck16 = lambda x: struct.unpack('H', x)[0]
 upck32 = lambda x: struct.unpack('I', x)[0]
@@ -261,3 +284,4 @@ class BoundedDict(DictMixin):
 
     def __iter__(self):
         return iter(self._data)
+