Last active
June 30, 2022 08:04
-
-
Save sum-catnip/1fc17a91c81d3d52cb5ff1598d1953e8 to your computer and use it in GitHub Desktop.
binary ninja snippet for finding a constant in a function / called function recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterator, Optional | |
checked = set() | |
def check_inst(i: HighLevelILInstruction, const: int) -> Iterator[HighLevelILInstruction]: | |
if isinstance(i, Constant) and i.constant == const: yield i | |
for o in filter(lambda i: isinstance(i,HighLevelILInstruction), i.operands): | |
yield from check_inst(o, const) | |
def check_func(f: Function, const: int, depth_max: int, depth: int = 0) -> Iterator[HighLevelILInstruction]: | |
if (depth > depth_max): return | |
if f in checked: return | |
checked.add(f) | |
yield from filter(lambda i: any(check_inst(i, const)), f.hlil.instructions) | |
for f in f.callees: | |
yield from check_func(f, const, depth_max, depth +1) | |
# todo: popup for depth and constant | |
for i in check_func(current_function, 0x570, 2): | |
print(' -- match:') | |
print(f'{i.function.source_function.symbol}:') | |
print(f'{i} @ {i.address}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment