summaryrefslogtreecommitdiff
path: root/python/examples/export_svg.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/examples/export_svg.py')
-rwxr-xr-xpython/examples/export_svg.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/python/examples/export_svg.py b/python/examples/export_svg.py
index 89bc41a1..7814c9fd 100755
--- a/python/examples/export_svg.py
+++ b/python/examples/export_svg.py
@@ -1,6 +1,7 @@
# from binaryninja import *
import os
import webbrowser
+import time
try:
from urllib import pathname2url # Python 2.x
except:
@@ -34,7 +35,7 @@ def save_svg(bv, function):
outputfile = get_save_filename_input('File name for export_svg', 'HTML files (*.html)', filename)
if outputfile is None:
return
- content = render_svg(function)
+ content = render_svg(function, origname)
output = open(outputfile, 'w')
output.write(content)
output.close()
@@ -54,7 +55,7 @@ def instruction_data_flow(function, address):
return 'Opcode: {bytes}'.format(bytes=padded)
-def render_svg(function):
+def render_svg(function, origname):
graph = function.create_graph()
graph.layout_and_wait()
heightconst = 15
@@ -67,7 +68,13 @@ def render_svg(function):
@import url(https://fonts.googleapis.com/css?family=Source+Code+Pro);
body {
background-color: rgb(42, 42, 42);
+ color: rgb(220, 220, 220);
+ font-family: "Source Code Pro", "Lucida Console", "Consolas", monospace;
}
+ a, a:visited {
+ color: rgb(200, 200, 200);
+ font-weight: bold;
+ }
svg {
background-color: rgb(42, 42, 42);
display: block;
@@ -80,6 +87,10 @@ def render_svg(function):
fill: none;
stroke-width: 1px;
}
+ .back_edge {
+ fill: none;
+ stroke-width: 2px;
+ }
.UnconditionalBranch, .IndirectBranch {
stroke: rgb(128, 198, 233);
color: rgb(128, 198, 233);
@@ -97,7 +108,7 @@ def render_svg(function):
fill: currentColor;
}
text {
- font-family: 'Source Code Pro';
+ font-family: "Source Code Pro", "Lucida Console", "Consolas", monospace;
font-size: 9pt;
fill: rgb(224, 224, 224);
}
@@ -197,10 +208,16 @@ def render_svg(function):
points += str(x * widthconst) + "," + str(y * heightconst) + " "
x, y = edge.points[-1]
points += str(x * widthconst) + "," + str(y * heightconst + 0) + " "
- edges += ' <polyline class="edge {type}" points="{points}" marker-end="url(#arrow-{type})"/>\n'.format(type=BranchType(edge.type).name, points=points)
+ if edge.back_edge:
+ edges += ' <polyline class="back_edge {type}" points="{points}" marker-end="url(#arrow-{type})"/>\n'.format(type=BranchType(edge.type).name, points=points)
+ else:
+ edges += ' <polyline class="edge {type}" points="{points}" marker-end="url(#arrow-{type})"/>\n'.format(type=BranchType(edge.type).name, points=points)
output += ' ' + edges + '\n'
output += ' </g>\n'
- output += '</svg></html>'
+ output += '</svg>'
+
+ output += '<p>This CFG generated by <a href="https://binary.ninja/">Binary Ninja</a> from {filename} on {timestring}.</p>'.format(filename = origname, timestring = time.strftime("%c"))
+ output += '</html>'
return output