diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2024-11-27 12:15:23 -0500 |
|---|---|---|
| committer | Rusty Wagner <rusty.wagner@gmail.com> | 2025-01-24 12:52:12 -0500 |
| commit | 8767400b712f12f459556844e27d9b9f5ff037bd (patch) | |
| tree | bbac40ec6fb68b647e2f9bd4a0c528088072dc79 /basicblock.cpp | |
| parent | 1c81ef63a163b479d07f3182f7831fdb6548488b (diff) | |
Add line formatter API and a generic line formatter plugin
Diffstat (limited to 'basicblock.cpp')
| -rw-r--r-- | basicblock.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/basicblock.cpp b/basicblock.cpp index 6bdd93ae..67856d88 100644 --- a/basicblock.cpp +++ b/basicblock.cpp @@ -36,6 +36,24 @@ DisassemblySettings::DisassemblySettings(BNDisassemblySettings* settings) } +Ref<DisassemblySettings> DisassemblySettings::GetDefaultSettings() +{ + return new DisassemblySettings(BNDefaultDisassemblySettings()); +} + + +Ref<DisassemblySettings> DisassemblySettings::GetDefaultGraphSettings() +{ + return new DisassemblySettings(BNDefaultGraphDisassemblySettings()); +} + + +Ref<DisassemblySettings> DisassemblySettings::GetDefaultLinearSettings() +{ + return new DisassemblySettings(BNDefaultLinearDisassemblySettings()); +} + + DisassemblySettings* DisassemblySettings::Duplicate() { return new DisassemblySettings(BNDuplicateDisassemblySettings(m_object)); @@ -144,6 +162,73 @@ DisassemblyTextLine::DisassemblyTextLine() } +size_t DisassemblyTextLine::GetTotalWidth() const +{ + size_t result = 0; + for (auto& i : tokens) + result += i.width; + return result; +} + + +static void FindAddressAndIndentationTokens( + const vector<InstructionTextToken>& tokens, const std::function<void(const InstructionTextToken&)>& callback) +{ + size_t startToken = 0; + for (size_t i = 0; i < tokens.size(); i++) + { + if (tokens[i].type == AddressSeparatorToken) + { + startToken = i + 1; + break; + } + } + + for (size_t i = 0; i < startToken; i++) + callback(tokens[i]); + for (size_t i = startToken; i < tokens.size(); i++) + { + if (tokens[i].type == AddressDisplayToken || tokens[i].type == AddressSeparatorToken + || tokens[i].type == CollapseStateIndicatorToken) + { + callback(tokens[i]); + continue; + } + + bool whitespace = true; + for (auto ch : tokens[i].text) + { + if (!isspace(ch)) + { + whitespace = false; + break; + } + } + + if (!whitespace) + break; + + callback(tokens[i]); + } +} + + +size_t DisassemblyTextLine::GetAddressAndIndentationWidth() const +{ + size_t result = 0; + FindAddressAndIndentationTokens(tokens, [&](const InstructionTextToken& token) { result += token.width; }); + return result; +} + + +vector<InstructionTextToken> DisassemblyTextLine::GetAddressAndIndentationTokens() const +{ + vector<InstructionTextToken> result; + FindAddressAndIndentationTokens(tokens, [&](const InstructionTextToken& token) { result.push_back(token); }); + return result; +} + + BasicBlock::BasicBlock(BNBasicBlock* block) { m_object = block; |
