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

Method set_user_var_value

python/function.py:2908–2949  ·  view source on GitHub ↗

`set_user_var_value` allows the user to specify a PossibleValueSet value for an MLIL variable at its \ definition site. .. warning:: Setting the variable value, triggers a reanalysis of the function and allows the dataflow \ to compute and propagate values which depend on the current varia

(self, var: 'variable.Variable', def_addr: int, value: 'variable.PossibleValueSet', after: bool = True)

Source from the content-addressed store, hash-verified

2906 core.BNClearForcedVariableVersion(self.handle, var.to_BNVariable(), def_site)
2907
2908 def set_user_var_value(self, var: 'variable.Variable', def_addr: int, value: 'variable.PossibleValueSet', after: bool = True) -> None:
2909 """
2910 `set_user_var_value` allows the user to specify a PossibleValueSet value for an MLIL variable at its \
2911 definition site.
2912
2913 .. warning:: Setting the variable value, triggers a reanalysis of the function and allows the dataflow \
2914 to compute and propagate values which depend on the current variable. This implies that branch conditions \
2915 whose values can be determined statically will be computed, leading to potential branch elimination at \
2916 the HLIL layer.
2917
2918 :param Variable var: Variable for which the value is to be set
2919 :param int def_addr: Address where the variable is set
2920 :param PossibleValueSet value: Informed value of the variable
2921 :param bool after: Whether the value happens before or after the instruction
2922 :rtype: None
2923
2924 :Example:
2925
2926 >>> mlil_var = current_mlil[0].operands[0]
2927 >>> def_address = 0x40108d
2928 >>> var_value = PossibleValueSet.constant(5)
2929 >>> current_function.set_user_var_value(mlil_var, def_address, var_value)
2930 """
2931 #if var.index == 0:
2932 # # Special case: function parameters have index 0 and are defined at the start of the function
2933 # def_addr = self.start
2934 #else:
2935 # var_defs = self.mlil.get_var_definitions(var)
2936 # if var_defs is None:
2937 # raise ValueError("Could not get definition for Variable")
2938 # found = False
2939 # for site in var_defs:
2940 # if site.address == def_addr:
2941 # found = True
2942 # break
2943 # if not found:
2944 # raise ValueError("No definition for Variable found at given address")
2945 def_site = core.BNArchitectureAndAddress()
2946 def_site.arch = self.arch.handle
2947 def_site.address = def_addr
2948
2949 core.BNSetUserVariableValue(self.handle, var.to_BNVariable(), def_site, after, value._to_core_struct())
2950
2951 def clear_user_var_value(self, var: 'variable.Variable', def_addr: int, after: bool = True) -> None:
2952 """

Callers

nothing calls this directly

Calls 2

to_BNVariableMethod · 0.80
_to_core_structMethod · 0.45

Tested by

no test coverage detected