diff options
| author | Glenn Smith <glenn@vector35.com> | 2025-05-21 15:40:40 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-05-21 15:55:33 -0400 |
| commit | 7034625749757855498719688163172210395379 (patch) | |
| tree | 1fd2b9b814eaa8ed81dcad7b386aeb0239e3f3e6 /python/examples/pseudo_python.py | |
| parent | 397b5693c4b354349ade15eab09baa5dde744f1c (diff) | |
Fix HLIL_LABEL rendering
Diffstat (limited to 'python/examples/pseudo_python.py')
| -rw-r--r-- | python/examples/pseudo_python.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/python/examples/pseudo_python.py b/python/examples/pseudo_python.py index 8c1a237e..c2019c0c 100644 --- a/python/examples/pseudo_python.py +++ b/python/examples/pseudo_python.py @@ -991,11 +991,31 @@ class PseudoPythonFunction(LanguageRepresentationFunction): tokens.append(InstructionTextToken(InstructionTextTokenType.GotoLabelToken, instr.target.name, instr.target.label_id)) elif instr.operation == HighLevelILOperation.HLIL_LABEL: - tokens.decrease_indent() + # NB: Not using decrease_indent() here because it will mess up the indentation guides + # that rely on matched calls to increase_indent()/decrease_indent() to properly set + # indentation groupings. Instead, we manually remove the last indent in the tokens + tokens.init_line() + new_tokens = tokens.current_tokens + found_indent = False + erased_indent = False + for i in range(len(new_tokens)): + token = new_tokens[i] + if token.type == InstructionTextTokenType.IndentationToken: + found_indent = True + elif found_indent: + # We have indents and this is the first non-indent token after all the indents, + # so remove the previous token. It must exist because we will have to have gone through + # the condition above and looped at least once. + new_tokens.pop(i - 1) + erased_indent = True + break + if found_indent and not erased_indent: + # Found an indent, but it was the last token, so erase the last token + new_tokens.pop(len(new_tokens) - 1) + tokens.current_tokens = new_tokens tokens.append(InstructionTextToken(InstructionTextTokenType.GotoLabelToken, instr.target.name, instr.target.label_id)) tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ":")) - tokens.increase_indent() elif instr.operation == HighLevelILOperation.HLIL_LOW_PART: parens = precedence > OperatorPrecedence.MemberAndFunctionOperatorPrecedence if parens: |
