Created
July 17, 2023 21:29
-
-
Save psifertex/6b83ddf9e61ce242f8ce981034e642aa to your computer and use it in GitHub Desktop.
small snippet written on the July 14 2023 Binary Ninja live stream
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
def myvisit(opName, op, opType, parentInstruction): | |
if (op.operation == MediumLevelILOperation.MLIL_MULU_DP) and isinstance(op.right, Constant) and isinstance(op.left, Constant): | |
nextInstruction = op.function[op.instr_index + 1] | |
leftVal = op.left.value.value | |
rightVal = op.right.value.value | |
upper = leftVal * rightVal >> 32 | |
lower = leftVal * rightVal & 0xffffffff | |
if isinstance(nextInstruction, SetVar): | |
nextVar = nextInstruction.src.operands[0] | |
if hasattr(nextVar, "name"): | |
if nextInstruction.src.operands[0].name == parentInstruction.high.name: | |
result = upper | |
else: | |
result = lower | |
val = PossibleValueSet.constant(result) | |
theVar = nextInstruction.dest | |
addr = nextInstruction.address | |
op.function.source_function.set_user_var_value(theVar, addr, val) | |
log_info(f"Set user value of {val} at {hex(addr)}") | |
for mf in bv.mlil_functions(): | |
mf.visit(myvisit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment