From 8767400b712f12f459556844e27d9b9f5ff037bd Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 27 Nov 2024 12:15:23 -0500 Subject: Add line formatter API and a generic line formatter plugin --- python/function.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'python/function.py') diff --git a/python/function.py b/python/function.py index e962d91f..80f0a37c 100644 --- a/python/function.py +++ b/python/function.py @@ -135,6 +135,18 @@ class DisassemblySettings: option = DisassemblyOption[option] core.BNSetDisassemblySettingsOption(self.handle, option, state) + @staticmethod + def default_settings() -> 'DisassemblySettings': + return DisassemblySettings(core.BNDefaultDisassemblySettings()) + + @staticmethod + def default_graph_settings() -> 'DisassemblySettings': + return DisassemblySettings(core.BNDefaultGraphDisassemblySettings()) + + @staticmethod + def default_linear_settings() -> 'DisassemblySettings': + return DisassemblySettings(core.BNDefaultLinearDisassemblySettings()) + @dataclass class ILReferenceSource: @@ -3355,6 +3367,52 @@ class DisassemblyTextLine: return f"" return f"" + @property + def total_width(self): + return sum(token.width for token in self.tokens) + + def _find_address_and_indentation_tokens(self, callback): + start_token = 0 + for i in range(len(self.tokens)): + if self.tokens[i].type == InstructionTextTokenType.AddressSeparatorToken: + start_token = i + 1 + break + + for token in self.tokens[:start_token]: + callback(token) + + for token in self.tokens[start_token:]: + if token.type in [InstructionTextTokenType.AddressDisplayToken, + InstructionTextTokenType.AddressSeparatorToken, + InstructionTextTokenType.CollapseStateIndicatorToken]: + callback(token) + continue + if len(token.text) != 0 and not token.text.isspace(): + break + callback(token) + + @property + def address_and_indentation_width(self): + result = 0 + + def sum_width(token): + nonlocal result + result += token.width + + self._find_address_and_indentation_tokens(sum_width) + return result + + @property + def address_and_indentation_tokens(self): + result = [] + + def collect_tokens(token): + nonlocal result + result.append(token) + + self._find_address_and_indentation_tokens(collect_tokens) + return result + class DisassemblyTextRenderer: def __init__( -- cgit v1.3.1