From e397c1c03ddca833bf39cf0bbdb6ce859bb16c7a Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 2 Jun 2016 00:09:18 -0400 Subject: properly escape higher unicode, use address instead of function in filename, add indirect branch style, split style --- python/examples/export-svg.py | 145 ++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 68 deletions(-) (limited to 'python/examples/export-svg.py') diff --git a/python/examples/export-svg.py b/python/examples/export-svg.py index 5826a546..c169337c 100755 --- a/python/examples/export-svg.py +++ b/python/examples/export-svg.py @@ -2,20 +2,21 @@ from binaryninja import * import os,sys escape_table = { - "&": "&", "'": "'", ">": ">", "<": "<", '"': """, - ' ': " ", + ' ': " " } def escape(string): - return ''.join(escape_table.get(i,i) for i in string) + string=string.decode('utf-8').encode('ascii','xmlcharrefreplace') #handle extended unicode + return ''.join(escape_table.get(i,i) for i in string) #still escape the basics def save_svg(bv,function): filename = bv.file.filename.split(os.sep)[-1] - outputfile = os.path.join(os.path.expanduser('~'), 'binaryninja-{filename}-{function}.html'.format(filename=filename,function=function.symbol.name)) + address = hex(function.start).replace('L','') + outputfile = os.path.join(os.path.expanduser('~'), 'binaryninja-{filename}-{function}.html'.format(filename=filename,function=address)) content = render_svg(function) output = open(outputfile,'w') output.write(content) @@ -37,74 +38,82 @@ def render_svg(function): ratio = 0.54 widthconst = int(heightconst*ratio) - output = ''' + output = ''' + + + + +''' + output += ''' - - + - + - + + + + @@ -131,7 +140,7 @@ def render_svg(function): output += ' \n'.format(x=x,y=y + (i + 1) * heightconst) for i,line in enumerate(block.lines): - output += ' '.format(x=x,y=y + (i + 0.7) * heightconst,address=hex(line.address)[:-1]) + output += ' '.format(x=x,y=y + (i + 0.7) * heightconst,address=hex(line.address)[:-1]) hover = instruction_data_flow(function, line.address) output += '{hover}'.format(hover=hover) for token in line.tokens: -- cgit v1.3.1