summaryrefslogtreecommitdiff
path: root/python/mediumlevelil.py
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2023-07-22 22:07:37 -0400
committerKyleMiles <krm504@nyu.edu>2023-07-22 22:07:37 -0400
commit4cc64152bb6a7d1c627a4ea83e4f0690edcbe6aa (patch)
treee8a1ff3c1057d31cb18f7e8eb14b465ec77fe696 /python/mediumlevelil.py
parent5a7282fb8df4f9fdaa681339568d53250e36a38f (diff)
Python API : Add examples to the docs for MediumLevelILInstruction.visit and HighLevelILInstruction.visit
Diffstat (limited to 'python/mediumlevelil.py')
-rw-r--r--python/mediumlevelil.py11
1 files changed, 11 insertions, 0 deletions
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