diff options
| author | Glenn Smith <glenn@vector35.com> | 2025-05-16 16:24:46 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-05-16 16:37:00 -0400 |
| commit | 64706bbd526c22e38b0be34f5d2b5a75766a6c02 (patch) | |
| tree | 4b48507f26b3eb1c2af318018bc0adfb5cf400ac /python/highlevelil.py | |
| parent | c0ef307ab4241257ec86ece0351bf1604cb8f232 (diff) | |
[Python] Support HLIL collapsing and update PseudoPython
Fixes Vector35/binaryninja-api#6679
Diffstat (limited to 'python/highlevelil.py')
| -rw-r--r-- | python/highlevelil.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/python/highlevelil.py b/python/highlevelil.py index 8503bbe4..dc16e333 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -943,6 +943,36 @@ class HighLevelILInstruction(BaseILInstruction): finally: core.BNFreeDisassemblyTextLines(lines, count.value) + @property + def can_collapse(self) -> bool: + """If this instruction can be collapsed in rendered lines""" + return self.operation in [ + HighLevelILOperation.HLIL_IF, + HighLevelILOperation.HLIL_WHILE, + HighLevelILOperation.HLIL_WHILE_SSA, + HighLevelILOperation.HLIL_DO_WHILE, + HighLevelILOperation.HLIL_DO_WHILE_SSA, + HighLevelILOperation.HLIL_FOR, + HighLevelILOperation.HLIL_FOR_SSA, + HighLevelILOperation.HLIL_SWITCH, + HighLevelILOperation.HLIL_CASE + ] + + def get_instruction_hash(self, discriminator: int) -> int: + """ + Hash of instruction matching the C++ HighLevelILInstruction::GetInstructionHash, + used for collapsed region matching. + :param discriminator: Extra value to include in the hash to differentiate regions + """ + + def rotl(value, shift): + return ((value << shift) & 0xffffffffffffffff) | (value >> (64 - shift)) + + hash = self.operation.value + hash ^= rotl(self.address, 23) + hash ^= rotl(discriminator, 47) + return hash + @dataclass(frozen=True, repr=False, eq=False) class HighLevelILUnaryBase(HighLevelILInstruction, UnaryOperation): |
