From 4c94ad3bdc27e39b29fb0980d076fa2bd33ce92c Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 22 Jun 2023 23:23:28 +0100 Subject: export svg now theme aware --- python/examples/export_svg.py | 117 ++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 32 deletions(-) (limited to 'python') diff --git a/python/examples/export_svg.py b/python/examples/export_svg.py index d0885524..4ff2106f 100755 --- a/python/examples/export_svg.py +++ b/python/examples/export_svg.py @@ -8,9 +8,10 @@ from urllib.request import pathname2url from binaryninja.interaction import get_save_filename_input, show_message_box, TextLineField, ChoiceField, SaveFileNameField, get_form_input from binaryninja.settings import Settings -from binaryninja.enums import MessageBoxButtonSet, MessageBoxIcon, MessageBoxButtonResult, InstructionTextTokenType, BranchType, DisassemblyOption, FunctionGraphType +from binaryninja.enums import MessageBoxButtonSet, MessageBoxIcon, MessageBoxButtonResult, InstructionTextTokenType, BranchType, DisassemblyOption, FunctionGraphType, ThemeColor from binaryninja.function import DisassemblySettings from binaryninja.plugin import PluginCommand +from binaryninjaui import getThemeColor, getTokenColor, UIContext colors = { 'green': [162, 217, 175], 'red': [222, 143, 151], 'blue': [128, 198, 233], 'cyan': [142, 230, 237], @@ -92,6 +93,23 @@ def instruction_data_flow(function, address): padded = ' '.join([hex[i:i + 2] for i in range(0, len(hex), 2)]) return f'Opcode: {padded}' +def rgbStr(tokenType): + '''Given a token string name, look up the theme color for it and return as rbg(x,y,z) str''' + try: + color = eval(f'getThemeColor(ThemeColor.{tokenType})') + except: + color = None + if (not color): + try: + ctx = UIContext.activeContext() + view_frame = ctx.getCurrentViewFrame() + color = eval(f'getTokenColor(view_frame, InstructionTextTokenType.{tokenType})') + except: + return 'rgb(224, 224, 224)' + r = color.getRgb()[0] + g = color.getRgb()[1] + b = color.getRgb()[2] + return f"rgb({r}, {g}, {b})" def render_svg(function, offset, mode, form, showOpcodes, showAddresses, origname): settings = DisassemblySettings() @@ -130,21 +148,23 @@ def render_svg(function, offset, mode, form, showOpcodes, showAddresses, orignam -- cgit v1.3.1