Skip to content

Instantly share code, notes, and snippets.

@psifertex
Created July 17, 2023 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psifertex/6b83ddf9e61ce242f8ce981034e642aa to your computer and use it in GitHub Desktop.
Save psifertex/6b83ddf9e61ce242f8ce981034e642aa to your computer and use it in GitHub Desktop.
small snippet written on the July 14 2023 Binary Ninja live stream
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