From 4cc64152bb6a7d1c627a4ea83e4f0690edcbe6aa Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Sat, 22 Jul 2023 22:07:37 -0400 Subject: Python API : Add examples to the docs for MediumLevelILInstruction.visit and HighLevelILInstruction.visit --- python/mediumlevelil.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'python/mediumlevelil.py') diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index def43581..77d5abe3 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -459,9 +459,20 @@ class MediumLevelILInstruction(BaseILInstruction): name: str = "root", parent: Optional['MediumLevelILInstruction'] = None) -> bool: """ Visits all MediumLevelILInstructions in the operands of this instruction and any sub-instructions. + In the callback you provide, you likely only need to interact with the second argument (see the example below). :param MediumLevelILVisitorCallback cb: Callback function that takes the name of the operand, the operand, operand type, and parent instruction :return: True if all instructions were visited, False if the callback returned False + :Example: + >>> def visitor(_a, inst, _c, _d) -> bool: + >>> if isinstance(inst, Constant): + >>> print(f"Found constant: {inst.constant}") + >>> return False # Stop recursion (once we find a constant, don't recurse in to any sub-instructions (which there won't actually be any...)) + >>> # Otherwise, keep recursing the subexpressions of this instruction; if no return value is provided, it'll keep descending + >>> + >>> # Finds all constants used in the program + >>> for inst in current_mlil.instructions: + >>> inst.visit(visitor) """ if cb(name, self, "MediumLevelILInstruction", parent) == False: return False -- cgit v1.3.1