angr.knowledge_plugins.variables.variable_manager¶
- class angr.knowledge_plugins.variables.variable_manager.SortedDict¶
- class angr.knowledge_plugins.variables.variable_manager.VariableType¶
Bases:
objectDescribes variable types.
- REGISTER = 0¶
- MEMORY = 1¶
- class angr.knowledge_plugins.variables.variable_manager.LiveVariables¶
Bases:
objectA collection of live variables at a program point.
- __init__(register_region, stack_region)¶
- register_region
- stack_region
- class angr.knowledge_plugins.variables.variable_manager.VariableManagerInternal¶
Bases:
SerializableManage variables for a function. It is meant to be used internally by VariableManager, but it’s common to be given a reference to one in response to a query for “the variables for a given function”. Maybe a better name would be “VariableManagerScope”.
- __init__(manager, func_addr=None)¶
- manager: VariableManager
- variable_to_types: dict[SimVariable, SimType]
- set_manager(manager)¶
- Parameters:
manager (VariableManager)
- next_variable_ident(sort)¶
- add_variable(sort, start, variable)¶
- Parameters:
variable (SimVariable)
- set_variable(sort, start, variable)¶
- Parameters:
variable (SimVariable)
- write_to(variable, offset, location, overwrite=False, atom=None)¶
- read_from(variable, offset, location, overwrite=False, atom=None)¶
- reference_at(variable, offset, location, overwrite=False, atom=None)¶
- record_variable(location, variable, offset, overwrite=False, atom=None)¶
- Parameters:
location (CodeLocation)
offset (int | None)
atom (Atom | None)
- remove_variable_by_atom(location, variable, atom)¶
- Parameters:
location (CodeLocation)
variable (SimVariable)
- make_phi_node(block_addr, *variables)¶
Create a phi variable for variables at block block_addr.
- Parameters:
block_addr (int) – The address of the current block.
variables – Variables that the phi variable represents.
- Returns:
The created phi variable.
- set_live_variables(addr, register_region, stack_region)¶
- find_variables_by_insn(ins_addr, sort)¶
- is_variable_used_at(variable, loc)¶
- Return type:
- Parameters:
variable (SimVariable)
- find_variable_by_stmt(block_addr, stmt_idx, sort, block_idx=None)¶
- Parameters:
block_idx (int | None)
- find_variables_by_stmt(block_addr, stmt_idx, sort, block_idx=None)¶
- find_variable_by_atom(block_addr, stmt_idx, atom, block_idx=None)¶
- Parameters:
block_idx (int | None)
- find_variables_by_atom(block_addr, stmt_idx, atom, block_idx=None)¶
- Return type:
set[tuple[SimVariable,int|None]]- Parameters:
atom (Expression)
block_idx (int | None)
- find_variables_by_register(reg)¶
- Return type:
- Parameters:
- get_variable_accesses(variable, same_name=False)¶
- Return type:
- Parameters:
variable (SimVariable)
same_name (bool)
- get_variables(sort=None, collapse_same_ident=False)¶
- Overloads:
self, sort (Literal[‘stack’]), collapse_same_ident (bool) → list[SimStackVariable]
self, sort (Literal[‘reg’]), collapse_same_ident (bool) → list[SimRegisterVariable]
self, sort (None), collapse_same_ident (bool) → list[SimRegisterVariable | SimRegisterVariable]
Get a list of variables.
- Parameters:
sort – Sort of the variable to get.
collapse_same_ident – Whether variables of the same identifier should be collapsed or not.
- Returns:
A list of variables.
- get_unified_variables(sort=None)¶
- Overloads:
self, sort (Literal[‘stack’]) → list[SimStackVariable]
self, sort (Literal[‘reg’]) → list[SimRegisterVariable]
self, sort (None) → list[SimRegisterVariable | SimRegisterVariable]
Get a list of unified variables.
- Parameters:
sort – Sort of the variable to get.
- Returns:
A list of variables.
- get_global_variables(addr)¶
Get global variable by the address of the variable.
- Parameters:
addr (int) – Address of the variable.
- Returns:
A set of variables or an empty set if no variable exists.
- is_phi_variable(var)¶
Test if var is a phi variable.
- Parameters:
var (SimVariable) – The variable instance.
- Returns:
True if var is a phi variable, False otherwise.
- Return type:
- get_phi_subvariables(var)¶
Get sub-variables that phi variable var represents.
- Parameters:
var (SimVariable) – The variable instance.
- Returns:
A set of sub-variables, or an empty set if var is not a phi variable.
- Return type:
- get_phi_variables(block_addr)¶
Get a dict of phi variables and their corresponding variables.
- get_variables_without_writes()¶
Get all variables that have never been written to.
- Return type:
- Returns:
A list of variables that are never written to.
- input_variables(exclude_specials=True)¶
Get all variables that have never been written to.
- Returns:
A list of variables that are never written to.
- Parameters:
exclude_specials (bool)
- assign_variable_names(labels=None, types=None)¶
Assign default names to all SSA variables.
- Parameters:
labels – Known labels in the binary.
- Returns:
None
- assign_unified_variable_names(labels=None, arg_names=None, reset=False, func_blocks=None)¶
Assign default names to all unified variables. If func_blocks is provided, we will find out variables that are only ever written to in Phi assignments and never used elsewhere, and put these variables at the end of the sorted list. These variables are likely completely removed during the dephication process.
- set_variable_type(var, ty, name=None, override_bot=True, all_unified=False, mark_manual=False)¶
- remove_types()¶
- unify_variables(interference=None)¶
Map SSA variables to a unified variable. Fill in self._unified_variables.
- Parameters:
interference (networkx.Graph[int] | None)
- Return type:
None
- set_unified_variable(variable, unified)¶
Set the unified variable for a given SSA variable.
- Parameters:
variable (
SimVariable) – The SSA variable.unified (
SimVariable) – The unified variable.
- Return type:
- Returns:
None
- unified_variable(variable)¶
Return the unified variable for a given SSA variable,
- Parameters:
variable (
SimVariable) – The SSA variable.- Return type:
- Returns:
The unified variable, or None if there is no such SSA variable.
- get_stackvar_max_sizes(stack_items)¶
Get the maximum size of each stack variable regardless of the type of each stack variable, under the assumption that stack variables do not overlap.
- class angr.knowledge_plugins.variables.variable_manager.VariableManager¶
Bases:
KnowledgeBasePluginManage variables.
- __init__(kb)¶
- function_managers: dict[int, VariableManagerInternal]
- get_function_manager(func_addr)¶
- Return type:
- get_variable_accesses(variable, same_name=False)¶
Get a list of all references to the given variable.
- Parameters:
variable (
SimVariable) – The variable.same_name (
bool) – Whether to include all variables with the same variable name, or just based on the variable identifier.
- Return type:
- Returns:
All references to the variable.
- copy()¶
- static convert_variable_list(vlist, manager)¶
- Parameters:
manager (VariableManagerInternal)
- load_from_dwarf(cu_list=None)¶
- Parameters:
cu_list (list[CompilationUnit] | None)