(bv, function)
| 30 | |
| 31 | |
| 32 | def 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 | |
| 88 | def instruction_data_flow(function, address): |
nothing calls this directly
no test coverage detected