Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xdot output #1505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions miasm/arch/aarch64/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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()
Expand Down Expand Up @@ -394,30 +395,21 @@ def arg2html(expr, index=None, loc_db=None):
)
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):
Expand All @@ -430,7 +422,7 @@ def arg2html(expr, index=None, loc_db=None):
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")
Expand Down
15 changes: 7 additions & 8 deletions miasm/arch/arm/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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

Expand Down Expand Up @@ -413,15 +414,14 @@ def arg2str(expr, index=None, loc_db=None):
)

if isinstance(expr, ExprOp) and expr.op == 'postinc':
o = '[%s]' % r
o = BRACKET_O + str(r) + BRACKET_C
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 = BRACKET_O + ("%s, %s" % (r, s)) + BRACKET_C
else:
o = '[%s]' % (r)

o = BRACKET_O + str(r) + BRACKET_C

if wb:
o += "!"
Expand Down Expand Up @@ -492,15 +492,14 @@ def arg2html(expr, index=None, loc_db=None):
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 += "!"
Expand Down
5 changes: 3 additions & 2 deletions miasm/arch/x86/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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")
Expand Down Expand Up @@ -624,7 +625,7 @@ def arg2str(expr, index=None, loc_db=None):
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:
Expand Down Expand Up @@ -655,7 +656,7 @@ def arg2html(expr, index=None, loc_db=None):
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),
Expand Down
2 changes: 1 addition & 1 deletion miasm/core/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
# 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):
Expand Down
7 changes: 6 additions & 1 deletion miasm/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

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)
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion miasm/ir/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading