Skip to content

Commit 96436fa

Browse files
committed
improve traverse examples
1 parent ff771fa commit 96436fa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

python/highlevelil.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,11 @@ def traverse(self, cb: Callable[['HighLevelILInstruction', Any], Any], *args: An
798798
799799
:Example:
800800
>>> def get_constant_less_than_value(inst: HighLevelILInstruction, value: int) -> int:
801-
>>> if isinstance(inst, Constant) and inst.constant < value:
802-
>>> return inst.constant
801+
... if isinstance(inst, Constant) and inst.constant < value:
802+
... return inst.constant
803803
>>>
804-
>>> list(inst.traverse(get_constant_less_than_value, 10))
804+
>>> for result in inst.traverse(get_constant_less_than_value, 10):
805+
... print(f"Found a constant {result} < 10 in {repr(inst)}")
805806
"""
806807
if (result := cb(self, *args, **kwargs)) is not None:
807808
yield result
@@ -2556,7 +2557,7 @@ def get_basic_block_at(self, index: int) -> Optional['basicblock.BasicBlock']:
25562557

25572558
def traverse(self, cb: Callable[['HighLevelILInstruction', Any], Any], *args: Any, **kwargs: Any) -> Iterator[Any]:
25582559
"""
2559-
``traverse`` iterates through all the instructions in the HighLevelILInstruction and calls the callback function for
2560+
``traverse`` iterates through all the instructions in the HighLevelILFunction and calls the callback function for
25602561
each instruction and sub-instruction. See the `Developer Docs <https://docs.binary.ninja/dev/concepts.html#walking-ils>`_ for more examples.
25612562
25622563
:param Callable[[HighLevelILInstruction, Any], Any] cb: The callback function to call for each node in the HighLevelILInstruction
@@ -2572,7 +2573,8 @@ def traverse(self, cb: Callable[['HighLevelILInstruction', Any], Any], *args: An
25722573
... case Localcall(dest=Constant(constant=c), params=[_, _, p]) if c == target and not isinstance(p, Constant):
25732574
... return i
25742575
>>> target_address = bv.get_symbol_by_raw_name('_memcpy').address
2575-
>>> list(current_il_function.traverse(find_non_constant_memcpy, target_address))
2576+
>>> for result in current_il_function.traverse(find_non_constant_memcpy, target_address):
2577+
... print(f"Found suspicious memcpy: {repr(i)}")
25762578
"""
25772579
root = self.root
25782580
if root is None:

0 commit comments

Comments
 (0)