diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2016-06-02 00:09:18 -0400 |
|---|---|---|
| committer | Jordan Wiens <jordan@psifertex.com> | 2016-06-02 00:09:18 -0400 |
| commit | e397c1c03ddca833bf39cf0bbdb6ce859bb16c7a (patch) | |
| tree | 35ad1b648ce7cce8f54e6757796e57b890b3b5bd /python | |
| parent | d77bcec46af3b1e08ec1bf26899bef8dae46a528 (diff) | |
properly escape higher unicode, use address instead of function in filename, add indirect branch style, split style
Diffstat (limited to 'python')
| -rwxr-xr-x | python/examples/export-svg.py | 145 |
1 files changed, 77 insertions, 68 deletions
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 = '''<html><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{width}" height="{height}"> + output = '''<html> + <head> + <style type="text/css"> + @import url(https://fonts.googleapis.com/css?family=Source+Code+Pro); + svg { + background-color: rgb(42, 42, 42); + } + .basicblock { + fill: rgb(74, 74, 74); + stroke: rgb(224, 224, 224); + } + .edge { + fill: none; + stroke-width: 1px; + } + .UnconditionalBranch, .IndirectBranch { + stroke: rgb(128, 198, 233); + color: rgb(128, 198, 233); + } + .FalseBranch { + stroke: rgb(222, 143, 151); + color: rgb(222, 143, 151); + } + .TrueBranch { + stroke: rgb(162, 217, 175); + color: rgb(162, 217, 175); + } + .arrow { + stroke-width: 1; + fill: currentColor; + } + text { + font-family: 'Source Code Pro'; + font-size: 9pt; + fill: rgb(224, 224, 224); + } + .CodeSymbolToken { + fill: rgb(128, 198, 223); + } + .DataSymbolToken { + fill: rgb(142, 230, 237); + } + .TextToken, .InstructionToken, .BeginMemoryOperandToken, .EndMemoryOperandToken { + fill: rgb(224, 224, 224); + } + .PossibleAddressToken, .IntegerToken { + fill: rgb(162, 217, 175); + } + .RegisterToken { + fill: rgb(237, 223, 179); + } + .AnnotationToken { + fill: rgb(218, 196, 209); + } + .ImportToken { + fill: rgb(237, 189, 129); + } + .StackVariableToken { + fill: rgb(193, 220, 199); + } + </style> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> + </head> +''' + output += '''<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{width}" height="{height}"> <defs> - <style type="text/css"><![CDATA[ - @import url(https://fonts.googleapis.com/css?family=Source+Code+Pro); - svg {{ - background-color: rgb(42, 42, 42); - }} - .basicblock {{ - fill: rgb(74, 74, 74); - stroke: rgb(224, 224, 224); - }} - .edge {{ - fill: none; - stroke-width: 2px; - }} - .UnconditionalBranch {{ - stroke: rgb(128, 198, 233); - color: rgb(128, 198, 233); - }} - .FalseBranch {{ - stroke: rgb(222, 143, 151); - color: rgb(222, 143, 151); - }} - .TrueBranch {{ - stroke: rgb(162, 217, 175); - color: rgb(162, 217, 175); - }} - .arrow {{ - stroke-width: 1; - fill: currentColor; - }} - text {{ - font-family: 'Source Code Pro'; - font-size: 9pt; - fill: rgb(224, 224, 224); - }} - .CodeSymbolToken {{ - fill: rgb(128, 198, 223); - }} - .DataSymbolToken {{ - fill: rgb(142, 230, 237); - }} - .TextToken, .InstructionToken, .BeginMemoryOperandToken, .EndMemoryOperandToken {{ - fill: rgb(224, 224, 224); - }} - .PossibleAddressToken, .IntegerToken {{ - fill: rgb(162, 217, 175); - }} - .RegisterToken {{ - fill: rgb(237, 223, 179); - }} - .AnnotationToken {{ - fill: rgb(218, 196, 209); - }} - .ImportToken {{ - fill: rgb(237, 189, 129); - }} - .StackVariableToken {{ - fill: rgb(193, 220, 199); - }} - ]]></style> - <marker id="arrow-TrueBranch" class="arrow TrueBranch" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="strokeWidth" markerWidth="4" markerHeight="3" orient="auto"> + <marker id="arrow-TrueBranch" class="arrow TrueBranch" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"> <path d="M 0 0 L 10 5 L 0 10 z" /> </marker> - <marker id="arrow-FalseBranch" class="arrow FalseBranch" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="strokeWidth" markerWidth="4" markerHeight="3" orient="auto"> + <marker id="arrow-FalseBranch" class="arrow FalseBranch" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"> <path d="M 0 0 L 10 5 L 0 10 z" /> </marker> - <marker id="arrow-UnconditionalBranch" class="arrow UnconditionalBranch" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="strokeWidth" markerWidth="4" markerHeight="3" orient="auto"> + <marker id="arrow-UnconditionalBranch" class="arrow UnconditionalBranch" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"> + <path d="M 0 0 L 10 5 L 0 10 z" /> + </marker> + <marker id="arrow-IndirectBranch" class="arrow IndirectBranch" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"> <path d="M 0 0 L 10 5 L 0 10 z" /> </marker> </defs> @@ -131,7 +140,7 @@ def render_svg(function): output += ' <text x="{x}" y="{y}">\n'.format(x=x,y=y + (i + 1) * heightconst) for i,line in enumerate(block.lines): - output += ' <tspan id="{address}" x="{x}" y="{y}">'.format(x=x,y=y + (i + 0.7) * heightconst,address=hex(line.address)[:-1]) + output += ' <tspan id="instr-{address}" x="{x}" y="{y}">'.format(x=x,y=y + (i + 0.7) * heightconst,address=hex(line.address)[:-1]) hover = instruction_data_flow(function, line.address) output += '<title>{hover}</title>'.format(hover=hover) for token in line.tokens: |
