MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / get_param_sites

Function get_param_sites

python/examples/args_render_layer.py:38–103  ·  view source on GitHub ↗

For a given function, find all LLIL instructions that are parameters to a call, and return a mapping for each instruction with all the calls that it maps to, their corresponding MLIL call instruction, and which numbered parameter they are in the call. :param mlil: MLIL function

(mlil: MediumLevelILFunction)

Source from the content-addressed store, hash-verified

36
37@functools.lru_cache(maxsize=64)
38def get_param_sites(mlil: MediumLevelILFunction) -> Mapping[LowLevelILInstruction, List[Tuple[MediumLevelILInstruction, int]]]:
39 """
40 For a given function, find all LLIL instructions that are parameters to a call,
41 and return a mapping for each instruction with all the calls that it maps to,
42 their corresponding MLIL call instruction, and which numbered parameter they are
43 in the call.
44
45 :param mlil: MLIL function to search
46 :return: Map of param sites as described above
47 """
48 call_sites = {}
49 mlil = mlil.ssa_form
50
51 # As a function to handle call and tailcall identically
52 def collect_call_params(call_site, dest, params):
53 def_sites = []
54 for i, param in enumerate(params):
55 llil = param.llil
56 if llil is not None:
57 def_sites.append((param, llil))
58 continue
59
60 match param:
61 case MediumLevelILVarSsa(src=var_src):
62 def_site = mlil.get_ssa_var_definition(var_src)
63 if def_site is not None and def_site.llil is not None:
64 def_sites.append((i, def_site.llil))
65 continue
66 # Handle phis by just looking up the def sites of all their sources
67 match def_site:
68 case MediumLevelILVarPhi(src=phis):
69 for phi in phis:
70 phi_def = mlil.get_ssa_var_definition(phi)
71 if phi_def is not None and phi_def.llil is not None:
72 def_sites.append((i, phi_def.llil))
73 case MediumLevelILConstBase():
74 # This is wrong, but it works (sometimes)
75 # Oh god, have I just quoted php.net
76 def_site_idx = mlil.llil.get_instruction_start(param.address)
77 if def_site_idx is not None:
78 def_sites.append((i, mlil.llil[def_site_idx].ssa_form))
79 continue
80
81 if len(def_sites) == 0:
82 log_debug(f"Could not find def site for param {i} in call at {call_site.address:#x}")
83
84 call_sites[call_site] = def_sites
85
86 for instr in mlil.instructions:
87 match instr:
88 case MediumLevelILCallSsa(dest=dest, params=params) as call_site:
89 collect_call_params(call_site, dest, params)
90 case MediumLevelILTailcallSsa(dest=dest, params=params) as call_site:
91 collect_call_params(call_site, dest, params)
92
93 # Inverse args
94 all_def_sites = {}
95 for call_site, params in call_sites.items():

Callers 1

get_llil_argFunction · 0.85

Calls 3

collect_call_paramsFunction · 0.85
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected