Skip to content

Instantly share code, notes, and snippets.

@lkmidas
Created July 13, 2021 03:24
Show Gist options
  • Save lkmidas/18c0f4afe30b005c82f0fe46e626fa9e to your computer and use it in GitHub Desktop.
Save lkmidas/18c0f4afe30b005c82f0fe46e626fa9e to your computer and use it in GitHub Desktop.
from idc import *
import idautils
import ida_allins
def find_call_with_arg(func_name, arg_no, arg_value):
func_ea = idaapi.get_name_ea(0, func_name)
for ref in idautils.CodeRefsTo(func_ea, 0):
arg_addrs = idaapi.get_arg_addrs(ref)
#print(hex(ref), arg_addrs)
if arg_addrs == None:
continue
if len(arg_addrs) < arg_no:
continue
insn = idaapi.insn_t()
idaapi.decode_insn(insn, arg_addrs[arg_no])
#if insn.itype != ida_allins.NN_mov:
# continue
arg = idc.get_operand_value(arg_addrs[arg_no], 1)
if arg == arg_value:
print("Found at: " + hex(ref))
# Example: find_call_with_arg("malloc", 0, 0x100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment