diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2025-01-24 09:19:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 09:19:48 +0100 |
| commit | 0164999126ce49b8033eea283467c5d719a25640 (patch) | |
| tree | d32a0a96849f16012013bbb245ded833558b1741 | |
| parent | cbc722eed8dc807955bd46f84886ae74d161dd0c (diff) | |
| parent | e46b1fc2551d112f2f7c2849a780d102d84b8f7b (diff) | |
| download | focaccia-miasm-0164999126ce49b8033eea283467c5d719a25640.tar.gz focaccia-miasm-0164999126ce49b8033eea283467c5d719a25640.zip | |
Merge pull request #1505 from serpilliere/fix_xdot_output
Fix xdot output
| -rw-r--r-- | miasm/arch/aarch64/arch.py | 26 | ||||
| -rw-r--r-- | miasm/arch/arm/arch.py | 15 | ||||
| -rw-r--r-- | miasm/arch/x86/arch.py | 5 | ||||
| -rw-r--r-- | miasm/core/graph.py | 2 | ||||
| -rw-r--r-- | miasm/core/utils.py | 7 | ||||
| -rw-r--r-- | miasm/ir/ir.py | 2 |
6 files changed, 27 insertions, 30 deletions
diff --git a/miasm/arch/aarch64/arch.py b/miasm/arch/aarch64/arch.py index 5246d920..ab6b7528 100644 --- a/miasm/arch/aarch64/arch.py +++ b/miasm/arch/aarch64/arch.py @@ -16,6 +16,7 @@ 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 +from miasm.core.utils import BRACKET_O, BRACKET_C log = logging.getLogger("aarch64dis") console_handler = logging.StreamHandler() @@ -394,30 +395,21 @@ class instruction_aarch64(instruction): ) 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) - ) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + BRACKET_C + ", " + color_expr_html(expr.args[1], loc_db) else: - return "[%s]" % (color_expr_html(expr.args[0], loc_db)) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + BRACKET_C 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) - ) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + ", " + color_expr_html(expr.args[1], loc_db) + BRACKET_C + '!' else: - return "[%s]" % (color_expr_html(expr.args[0], loc_db)) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + BRACKET_C 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)) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + BRACKET_C 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) - ) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + ", " + color_expr_html(expr.args[1], loc_db) + BRACKET_C else: - return "[%s]" % color_expr_html(expr.args[0], loc_db) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + BRACKET_C elif isinstance(expr, m2_expr.ExprOp) and expr.op == 'segm': arg = expr.args[1] if isinstance(arg, m2_expr.ExprId): @@ -430,7 +422,7 @@ class instruction_aarch64(instruction): 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) + return BRACKET_O + color_expr_html(expr.args[0], loc_db) + ', ' + arg + BRACKET_C else: raise NotImplementedError("bad op") diff --git a/miasm/arch/arm/arch.py b/miasm/arch/arm/arch.py index 91c22bd5..10551515 100644 --- a/miasm/arch/arm/arch.py +++ b/miasm/arch/arm/arch.py @@ -14,6 +14,7 @@ from miasm.arch.arm.regs import * from miasm.core.asm_ast import AstInt, AstId, AstMem, AstOp from miasm.ir.ir import color_expr_html from miasm.core import utils +from miasm.core.utils import BRACKET_O, BRACKET_C # A1 encoding @@ -413,15 +414,14 @@ class instruction_arm(instruction): ) if isinstance(expr, ExprOp) and expr.op == 'postinc': - o = '[%s]' % r + o = '[' + str(r) + ']' if s and not (isinstance(s, ExprInt) and int(s) == 0): o += ', %s' % s else: if s and not (isinstance(s, ExprInt) and int(s) == 0): - o = '[%s, %s]' % (r, s) + o = '[' + ("%s, %s" % (r, s)) + ']' else: - o = '[%s]' % (r) - + o = '[' + str(r) + ']' if wb: o += "!" @@ -492,15 +492,14 @@ class instruction_arm(instruction): s_html = color_expr_html(s, loc_db) if isinstance(expr, ExprOp) and expr.op == 'postinc': - o = '[%s]' % color_expr_html(r, loc_db) + o = BRACKET_O + color_expr_html(r, loc_db) + BRACKET_C if s and not (isinstance(s, ExprInt) and int(s) == 0): o += ', %s' % s_html else: if s and not (isinstance(s, ExprInt) and int(s) == 0): - o = '[%s, %s]' % (color_expr_html(r, loc_db), s_html) + o = BRACKET_O + color_expr_html(r, loc_db) + ", " + s_html + BRACKET_C else: - o = '[%s]' % color_expr_html(r, loc_db) - + o = BRACKET_O + color_expr_html(r, loc_db) + BRACKET_C if wb: o += "!" diff --git a/miasm/arch/x86/arch.py b/miasm/arch/x86/arch.py index c5ff9b63..2fdac30c 100644 --- a/miasm/arch/x86/arch.py +++ b/miasm/arch/x86/arch.py @@ -15,6 +15,7 @@ import miasm.arch.x86.regs as regs_module from miasm.arch.x86.regs import * from miasm.core.asm_ast import AstNode, AstInt, AstId, AstMem, AstOp from miasm.ir.ir import color_expr_html +from miasm.core.utils import BRACKET_O, BRACKET_C log = logging.getLogger("x86_arch") @@ -624,7 +625,7 @@ class instruction_x86(instruction): s = str(expr).replace('(', '').replace(')', '') else: s = str(expr) - o = prefix + sz + ' PTR %s[%s]' % (segm, s) + o = prefix + sz + ' PTR ' + str(segm) + '[%s]' % s elif isinstance(expr, ExprOp) and expr.op == 'segm': o = "%s:%s" % (expr.args[0], expr.args[1]) else: @@ -655,7 +656,7 @@ class instruction_x86(instruction): s = color_expr_html(expr, loc_db)#.replace('(', '').replace(')', '') else: s = color_expr_html(expr, loc_db) - o = prefix + sz + ' PTR %s[%s]' % (segm, s) + o = prefix + sz + ' PTR ' + str(segm) + BRACKET_O + str(s) + BRACKET_C elif isinstance(expr, ExprOp) and expr.op == 'segm': o = "%s:%s" % ( color_expr_html(expr.args[0], loc_db), diff --git a/miasm/core/graph.py b/miasm/core/graph.py index e680894c..debea38e 100644 --- a/miasm/core/graph.py +++ b/miasm/core/graph.py @@ -20,7 +20,7 @@ class DiGraph(object): # N -> Nodes N2 with a edge (N2 -> N) self._nodes_pred = {} - self.escape_chars = re.compile(r'[\{\}&|<>]') + self.escape_chars = re.compile('[' + re.escape('{}[]') + '&|<>' + ']') def __repr__(self): diff --git a/miasm/core/utils.py b/miasm/core/utils.py index eb170576..291c5f4d 100644 --- a/miasm/core/utils.py +++ b/miasm/core/utils.py @@ -26,7 +26,9 @@ COLOR_OP = "black" COLOR_MNEMO = "blue1" -ESCAPE_CHARS = re.compile(r'[\{\}&|<>]') +ESCAPE_CHARS = re.compile('[' + re.escape('{}[]') + '&|<>' + ']') + + def set_html_text_color(text, color): return '<font color="%s">%s</font>' % (color, text) @@ -39,6 +41,9 @@ def _fix_chars(token): def fix_html_chars(text): return ESCAPE_CHARS.sub(_fix_chars, str(text)) +BRACKET_O = fix_html_chars('[') +BRACKET_C = fix_html_chars(']') + upck8 = lambda x: struct.unpack('B', x)[0] upck16 = lambda x: struct.unpack('H', x)[0] upck32 = lambda x: struct.unpack('I', x)[0] diff --git a/miasm/ir/ir.py b/miasm/ir/ir.py index d26c5d1d..57bff4db 100644 --- a/miasm/ir/ir.py +++ b/miasm/ir/ir.py @@ -48,7 +48,7 @@ def _expr_loc_to_symb(expr, loc_db): return m2_expr.ExprId(name, expr.size) -ESCAPE_CHARS = re.compile(r'[\{\}&|<>]') +ESCAPE_CHARS = re.compile('[' + re.escape('{}[]') + '&|<>' + ']') class TranslatorHtml(Translator): __LANG__ = "custom_expr_color" |