From 1c01b00d87e45c7ae8eb6320b20e7dcf67915d77 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Thu, 10 Jul 2025 01:32:32 -0400 Subject: 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. --- python/lowlevelil.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'python/lowlevelil.py') 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 `_ 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) -- cgit v1.3.1