MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / save_svg

Function save_svg

python/examples/export_svg.py:32–85  ·  view source on GitHub ↗
(bv, function)

Source from the content-addressed store, hash-verified

30
31
32def save_svg(bv, function):
33 sym = bv.get_symbol_at(function.start)
34 if sym:
35 offset = sym.name
36 else:
37 offset = "%x" % function.start
38 path = Path(os.path.dirname(bv.file.filename))
39 origname = os.path.basename(bv.file.filename)
40 filename = path / f'binaryninja-{origname}-{offset}.html'
41
42 functionChoice = TextLineField("Blank to accept default")
43 # TODO: implement linear disassembly settings and output
44 modeChoices = ["Graph"]
45 modeChoiceField = ChoiceField("Mode", modeChoices)
46 if Settings().get_bool('ui.debugMode'):
47 formChoices = [
48 "Assembly", "Lifted IL", "LLIL", "LLIL SSA", "Mapped Medium", "Mapped Medium SSA", "MLIL", "MLIL SSA", "HLIL",
49 "HLIL SSA"
50 ]
51 formChoiceField = ChoiceField("Form", formChoices)
52 else:
53 formChoices = ["Assembly", "LLIL", "MLIL", "HLIL"]
54 formChoiceField = ChoiceField("Form", formChoices)
55
56 showOpcodes = ChoiceField("Show Opcodes", ["Yes", "No"])
57 showAddresses = ChoiceField("Show Addresses", ["Yes", "No"])
58
59 saveFileChoices = SaveFileNameField("Output file", 'HTML files (*.html)', str(filename))
60 if not get_form_input([
61 f'Current Function: {offset}', functionChoice, formChoiceField, modeChoiceField, showOpcodes, showAddresses,
62 saveFileChoices
63 ], "SVG Export") or saveFileChoices.result is None:
64 return
65 if saveFileChoices.result == '':
66 outputfile = filename
67 else:
68 outputfile = saveFileChoices.result
69 content = render_svg(
70 function, offset, modeChoices[modeChoiceField.result], formChoices[formChoiceField.result], showOpcodes.result == 0,
71 showAddresses.result == 0, origname
72 )
73 output = open(outputfile, 'w')
74 output.write(content)
75 output.close()
76 result = show_message_box(
77 "Open SVG", "Would you like to view the exported SVG?", buttons=MessageBoxButtonSet.YesNoButtonSet,
78 icon=MessageBoxIcon.QuestionIcon
79 )
80 if result == MessageBoxButtonResult.YesButton:
81 # might need more testing, latest py3 on windows seems.... broken with these APIs relative to other platforms
82 if sys.platform == 'win32':
83 webbrowser.open(outputfile)
84 else:
85 webbrowser.open('file://' + str(outputfile))
86
87
88def instruction_data_flow(function, address):

Callers

nothing calls this directly

Calls 13

TextLineFieldClass · 0.90
ChoiceFieldClass · 0.90
SettingsClass · 0.90
SaveFileNameFieldClass · 0.90
get_form_inputFunction · 0.90
show_message_boxFunction · 0.90
render_svgFunction · 0.85
PathClass · 0.50
get_symbol_atMethod · 0.45
get_boolMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected