diff options
| author | Mason Reed <mason@vector35.com> | 2025-07-10 01:32:32 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-07-15 12:34:43 -0400 |
| commit | 1c01b00d87e45c7ae8eb6320b20e7dcf67915d77 (patch) | |
| tree | e861d689ad737bb1140cd24654d74bbd82c3068d /python/lowlevelil.py | |
| parent | 99e442620e8e19053120dc44239372d1fb5a3053 (diff) | |
Move LLIL instruction retrieval into the LLIL function where it belongs
The python API was kept the same seeing as we are close to the release, will likely start deprecating some of those API's soon.
Diffstat (limited to 'python/lowlevelil.py')
| -rw-r--r-- | python/lowlevelil.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/python/lowlevelil.py b/python/lowlevelil.py index 188a4623..82a09603 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -3799,6 +3799,45 @@ class LowLevelILFunction: return None return InstructionIndex(result) + def get_instructions_at(self, addr: int, arch: Optional['architecture.Architecture'] = None) -> List[InstructionIndex]: + """ + ``get_instructions_at`` gets the InstructionIndex(s) corresponding to the given virtual address + See the `docs for mappings between ils <https://dev-docs.binary.ninja/dev/concepts.html#mapping-between-ils>`_ for more information. + + :param int addr: virtual address of the instruction to be queried + :param Architecture arch: (optional) Architecture for the given function + :rtype: list(InstructionIndex) + :Example: + + >>> func = next(bv.functions) + >>> func.llil.get_instructions_at(func.start) + [0] + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + instrs = core.BNLowLevelILGetInstructionsAt(self.handle, arch.handle, addr, count) + assert instrs is not None, "core.BNLowLevelILGetInstructionsAt returned None" + try: + result = [] + for i in range(0, count.value): + result.append(instrs[i]) + return result + finally: + core.BNFreeILInstructionList(instrs) + + def get_exits_for_instr(self, idx: InstructionIndex) -> List[InstructionIndex]: + count = ctypes.c_ulonglong() + exits = core.BNLowLevelILGetExitsForInstruction(self.handle, idx, count) + assert exits is not None, "core.BNLowLevelILGetExitsForInstruction returned None" + try: + result = [] + for i in range(0, count.value): + result.append(exits[i]) + return result + finally: + core.BNFreeILInstructionList(exits) + def clear_indirect_branches(self) -> None: core.BNLowLevelILClearIndirectBranches(self.handle) |
