From ceafa572d0a05cc9afa0f19838f28174aeea5e46 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Tue, 21 Apr 2020 18:05:18 -0400 Subject: Add indentation option for text renderer --- architecture.cpp | 9 +++++---- binaryninjaapi.h | 5 +++-- binaryninjacore.h | 4 ++-- python/function.py | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/architecture.cpp b/architecture.cpp index 6ca7733e..09ef2013 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -2302,7 +2302,7 @@ bool DisassemblyTextRenderer::GetInstructionText(uint64_t addr, size_t& len, vector DisassemblyTextRenderer::PostProcessInstructionTextLines(uint64_t addr, - size_t len, const vector& lines) + size_t len, const vector& lines, const string& indentSpaces) { BNDisassemblyTextLine* inLines = new BNDisassemblyTextLine[lines.size()]; for (size_t i = 0; i < lines.size(); i++) @@ -2317,7 +2317,8 @@ vector DisassemblyTextRenderer::PostProcessInstructionTextL BNDisassemblyTextLine* result = nullptr; size_t count = 0; - result = BNPostProcessDisassemblyTextRendererLines(m_object, addr, len, inLines, lines.size(), &count); + result = BNPostProcessDisassemblyTextRendererLines(m_object, addr, len, inLines, lines.size(), &count, + indentSpaces.c_str()); BNFreeDisassemblyTextLines(inLines, lines.size()); vector outLines; @@ -2427,7 +2428,7 @@ void DisassemblyTextRenderer::AddIntegerToken(vector& toke void DisassemblyTextRenderer::WrapComment(DisassemblyTextLine& line, vector& lines, - const string& comment, bool hasAutoAnnotations, const string& leadingSpaces) + const string& comment, bool hasAutoAnnotations, const string& leadingSpaces, const string& indentSpaces) { BNDisassemblyTextLine inLine; inLine.addr = line.addr; @@ -2439,7 +2440,7 @@ void DisassemblyTextRenderer::WrapComment(DisassemblyTextLine& line, vector& tokens, uint64_t addr); virtual bool GetInstructionText(uint64_t addr, size_t& len, std::vector& lines); std::vector PostProcessInstructionTextLines(uint64_t addr, - size_t len, const std::vector& lines); + size_t len, const std::vector& lines, const std::string& indentSpaces = ""); virtual bool GetDisassemblyText(uint64_t addr, size_t& len, std::vector& lines); void ResetDeduplicatedComments(); @@ -5223,7 +5223,8 @@ __attribute__ ((format (printf, 1, 2))) std::vector& lines, const std::string& comment, bool hasAutoAnnotations, - const std::string& leadingSpaces=" "); + const std::string& leadingSpaces=" ", + const std::string& indentSpaces=""); }; struct LinearViewObjectIdentifier diff --git a/binaryninjacore.h b/binaryninjacore.h index ea718dbe..f6ac4510 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2980,7 +2980,7 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI bool BNGetDisassemblyTextRendererLines(BNDisassemblyTextRenderer* renderer, uint64_t addr, size_t* len, BNDisassemblyTextLine** result, size_t* count); BINARYNINJACOREAPI BNDisassemblyTextLine* BNPostProcessDisassemblyTextRendererLines(BNDisassemblyTextRenderer* renderer, - uint64_t addr, size_t len, BNDisassemblyTextLine* inLines, size_t inCount, size_t* outCount); + uint64_t addr, size_t len, BNDisassemblyTextLine* inLines, size_t inCount, size_t* outCount, const char* indentSpaces); BINARYNINJACOREAPI void BNResetDisassemblyTextRendererDeduplicatedComments(BNDisassemblyTextRenderer* renderer); BINARYNINJACOREAPI bool BNGetDisassemblyTextRendererSymbolTokens(BNDisassemblyTextRenderer* renderer, uint64_t addr, size_t size, size_t operand, BNInstructionTextToken** result, size_t* count); @@ -2991,7 +2991,7 @@ __attribute__ ((format (printf, 1, 2))) BNInstructionTextToken* token, BNArchitecture* arch, uint64_t addr, size_t* count); BINARYNINJACOREAPI BNDisassemblyTextLine* BNDisassemblyTextRendererWrapComment(BNDisassemblyTextRenderer* renderer, const BNDisassemblyTextLine* inLine, size_t* outLineCount, const char* comment, bool hasAutoAnnotations, - const char* leadingSpaces); + const char* leadingSpaces, const char* indentSpaces); BINARYNINJACOREAPI void BNMarkFunctionAsRecentlyUsed(BNFunction* func); BINARYNINJACOREAPI void BNMarkBasicBlockAsRecentlyUsed(BNBasicBlock* block); diff --git a/python/function.py b/python/function.py index 97f832d1..81cfc6b6 100644 --- a/python/function.py +++ b/python/function.py @@ -3153,7 +3153,7 @@ class DisassemblyTextRenderer(object): core.BNFreeDisassemblyTextLines(lines, count.value) return (result, length.value) - def post_process_lines(self, addr, length, in_lines): + def post_process_lines(self, addr, length, in_lines, indent_spaces=""): if isinstance(in_lines, str): in_lines = in_lines.split('\n') line_buf = (core.BNDisassemblyTextLine * len(in_lines))() @@ -3184,7 +3184,7 @@ class DisassemblyTextRenderer(object): line_buf[i].tokens = InstructionTextToken.get_instruction_lines(line.tokens) count = ctypes.c_ulonglong() lines = ctypes.POINTER(core.BNDisassemblyTextLine)() - lines = core.BNPostProcessDisassemblyTextRendererLines(self.handle, addr, length, line_buf, len(in_lines), count) + lines = core.BNPostProcessDisassemblyTextRendererLines(self.handle, addr, length, line_buf, len(in_lines), count, indent_spaces) il_function = self.il_function result = [] for i in range(0, count.value): @@ -3250,7 +3250,7 @@ class DisassemblyTextRenderer(object): tokens += result core.BNFreeInstructionText(new_tokens, count.value) - def wrap_comment(self, lines, cur_line, comment, has_auto_annotations, leading_spaces = " "): + def wrap_comment(self, lines, cur_line, comment, has_auto_annotations, leading_spaces = " ", indent_spaces = ""): cur_line_obj = core.BNDisassemblyTextLine() cur_line_obj.addr = cur_line.address if cur_line.il_instruction is None: @@ -3262,7 +3262,7 @@ class DisassemblyTextRenderer(object): cur_line_obj.count = len(cur_line.tokens) count = ctypes.c_ulonglong() new_lines = core.BNDisassemblyTextRendererWrapComment(self.handle, cur_line_obj, count, comment, - has_auto_annotations, leading_spaces) + has_auto_annotations, leading_spaces, indent_spaces) il_function = self.il_function for i in range(0, count.value): addr = new_lines[i].addr -- cgit v1.3.1