GeezerVison is showing api.binary.ninja — variable module — Binary Ninja API Documentation v6.0.10905
variable module¶
ArchitectureVariable¶
-
class ArchitectureVariable[source]¶
Bases: CoreVariable
class ArchitectureVariable is a wrapper around CoreVariable that
is bound to an architecture (for register/flag naming) but not a function. This
is typically used in calling conventions for specifying value locations. Calling
conventions can be used outside functions to resolve type information, so only
an architecture is required.
-
__init__(arch: Architecture, source_type: VariableSourceType, index: int, storage: int)[source]¶
- Parameters:
-
-
classmethod flag(arch: Architecture, flag: str | int)[source]¶
- Parameters:
-
-
classmethod from_BNVariable(arch: Architecture, var: BNVariable)[source]¶
- Parameters:
-
-
classmethod from_core_variable(arch: Architecture, var: CoreVariable)[source]¶
- Parameters:
-
-
classmethod from_identifier(arch: Architecture, identifier: int)[source]¶
- Parameters:
-
-
classmethod reg(arch: Architecture, reg: str | int)[source]¶
- Parameters:
-
-
classmethod stack_offset(arch: Architecture, offset: int)[source]¶
- Parameters:
-
-
property arch: Architecture¶
-
property name: str¶
CoreVariable¶
-
class CoreVariable[source]¶
Bases: object
class CoreVariable is the base class for other variable types,
such as VariableNameAndType and Variable
- Variables:
index – Internal identifier
storage – If this variable is a stack variable
(source_type == VariableSourceType.StackVariableSourceType),
then the storage location is the offset onto the stack that contains
the first byte of this variable. Otherwise it’s used as an internal identifier.
-
__init__(_source_type: int, index: int, storage: int) → None¶
- Parameters:
-
- Return type:
None
-
classmethod flag(flag: int)[source]¶
- Parameters:
flag (int)
-
classmethod from_BNVariable(var: BNVariable)[source]¶
- Parameters:
var (BNVariable)
-
classmethod from_identifier(identifier)[source]¶
-
classmethod reg(reg: int)[source]¶
- Parameters:
reg (int)
-
classmethod stack_offset(offset: int)[source]¶
- Parameters:
offset (int)
-
to_BNVariable()[source]¶
-
property identifier: int¶
A UID for a variable within a function.
-
index: int¶
-
property source_type: VariableSourceType¶
Whether this variable was created based off of an underlying register, stack location, or flag.
-
storage: int¶
PossibleValueSet¶
-
class PossibleValueSet[source]¶
Bases: object
class PossibleValueSet PossibleValueSet is used to define possible values
that a variable can take. It contains methods to instantiate different
value sets such as Constant, Signed/Unsigned Ranges, etc.
Note
This object is a “passive” object. Any changes you make to it will not be reflected in the core and vice-versa. If you wish to update a core version of this object you should use the appropriate API.
-
__init__(arch: Architecture | None = None, value: BNPossibleValueSet | None = None)[source]¶
- Parameters:
-
-
add(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Add two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
and_(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform bitwise AND of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
arith_shift_right(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform arithmetic right shift of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
static constant(value: int) → PossibleValueSet[source]¶
Create a constant valued PossibleValueSet object.
- Parameters:
value (int) – Integer value of the constant
- Return type:
PossibleValueSet
-
static constant_ptr(value: int) → PossibleValueSet[source]¶
Create constant pointer valued PossibleValueSet object.
- Parameters:
value (int) – Integer value of the constant pointer
- Return type:
PossibleValueSet
-
static in_set_of_values(values: Iterable[int]) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a value in a set of values.
- Parameters:
values (Iterable[int]) – Iterable of integer values
- Return type:
PossibleValueSet
-
intersection(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Compute the intersection of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
logical_shift_right(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform logical right shift of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
static lookup_table_value(lookup_table: List[LookupTableEntry], mapping: Dict[int, int]) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a value which is a member of a
lookup table.
- Parameters:
-
- Return type:
PossibleValueSet
-
multiply(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Multiply two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
negate(size: int) → PossibleValueSet[source]¶
Negate a PossibleValueSet.
- Parameters:
size (int)
- Return type:
PossibleValueSet
-
not_(size: int) → PossibleValueSet[source]¶
Perform bitwise NOT of a PossibleValueSet.
- Parameters:
size (int)
- Return type:
PossibleValueSet
-
static not_in_set_of_values(values: Iterable[int]) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a value NOT in a set of values.
- Parameters:
values (Iterable[int]) – Iterable of integer values
- Return type:
PossibleValueSet
-
or_(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform bitwise OR of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
static parameter_pointer(idx: int, offset: int) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a pointer to a parameter when the parameter is
stored at an unknown location in memory. This is typically used for calling conventions
that pass in a pointer to the storage location for parameters (usually larger than
can be held in a register).
- Parameters:
-
- Return type:
PossibleValueSet
-
static result_pointer(offset: int) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a pointer to the return value when the return value
is stored at an unknown location in memory. This is typically used for calling conventions
that pass in a pointer to the storage location for the return value.
- Parameters:
offset (int) – Integer value of the offset
- Return type:
PossibleValueSet
-
rotate_left(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform left rotation of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
rotate_right(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform right rotation of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
shift_left(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform left shift of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
signed_divide(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform signed division of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
signed_mod(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform signed modulo of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
static signed_range_value(ranges: List[ValueRange]) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a signed range of values.
- Parameters:
ranges (list(ValueRange)) – List of ValueRanges
- Return type:
PossibleValueSet
- Example:
>>> v_1 = ValueRange(-5, -1, 1)
>>> v_2 = ValueRange(7, 10, 1)
>>> val = PossibleValueSet.signed_range_value([v_1, v_2])
<signed ranges: [<range: -0x5 to -0x1>, <range: 0x7 to 0xa>]>
-
static stack_frame_offset(offset: int) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a stack frame offset.
- Parameters:
offset (int) – Integer value of the offset
- Return type:
PossibleValueSet
-
subtract(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Subtract two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
static undetermined() → PossibleValueSet[source]¶
Create a PossibleValueSet object of type UndeterminedValue.
- Returns:
PossibleValueSet object of type UndeterminedValue
- Return type:
PossibleValueSet
-
union(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Compute the union of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
unsigned_divide(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform unsigned division of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
unsigned_mod(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform unsigned modulo of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
static unsigned_range_value(ranges: List[ValueRange]) → PossibleValueSet[source]¶
Create a PossibleValueSet object for a unsigned signed range of values.
- Parameters:
ranges (list(ValueRange)) – List of ValueRanges
- Return type:
PossibleValueSet
- Example:
>>> v_1 = ValueRange(0, 5, 1)
>>> v_2 = ValueRange(7, 10, 1)
>>> val = PossibleValueSet.unsigned_range_value([v_1, v_2])
<unsigned ranges: [<range: 0x0 to 0x5>, <range: 0x7 to 0xa>]>
-
xor(other: PossibleValueSet, size: int) → PossibleValueSet[source]¶
Perform bitwise XOR of two PossibleValueSets.
- Parameters:
-
- Return type:
PossibleValueSet
-
property count: int¶
-
property mapping: Dict[int, int]¶
-
property offset: int¶
-
property ranges: List[ValueRange]¶
-
property reg: RegisterName¶
-
property size: int¶
-
property table: List[LookupTableEntry]¶
-
property type: RegisterValueType¶
-
property value: int¶
-
property values: Set[int]¶
Variable¶
-
class Variable[source]¶
Bases: CoreVariable
class Variable represents variables in Binary Ninja. Variables are resolved
in medium level IL, so variables objects are only valid for MLIL and above.
-
__init__(func: Function | LowLevelILFunction | MediumLevelILFunction | HighLevelILFunction, source_type: VariableSourceType, index: int, storage: int)[source]¶
- Parameters:
-
-
classmethod from_BNVariable(func: Function | LowLevelILFunction | MediumLevelILFunction | HighLevelILFunction, var: BNVariable)[source]¶
- Parameters:
-
-
classmethod from_core_variable(func: Function | LowLevelILFunction | MediumLevelILFunction | HighLevelILFunction, var: CoreVariable)[source]¶
- Parameters:
-
-
classmethod from_identifier(func: Function | LowLevelILFunction | MediumLevelILFunction | HighLevelILFunction, identifier: int)[source]¶
- Parameters:
-
-
classmethod from_variable_name_and_type(func: Function | LowLevelILFunction | MediumLevelILFunction | HighLevelILFunction, var: VariableNameAndType)[source]¶
- Parameters:
-
-
set_name_and_type_async(name: str | None, new_type: Type) → None[source]¶
set_name_and_type_async provides a way to asynchronously set both the name and type of a variable. This method should be used
when speed is of concern.
- Parameters:
-
- Return type:
None
-
set_name_async(name: str | None) → None[source]¶
set_name_async provides a way to asynchronously set the name of a variable. This method should be used
when speed is of concern.
- Parameters:
name (str | None)
- Return type:
None
-
set_type_async(new_type: Type) → None[source]¶
set_type_async provides a way to asynchronously set the type of a variable. This method should be used
when speed is of concern.
- Parameters:
new_type (Type)
- Return type:
None
-
property core_variable: CoreVariable¶
Retrieve the underlying CoreVariable class
-
property dead_store_elimination: DeadStoreElimination¶
returns the dead store elimination setting for this variable
-
property function: Function¶
returns the source Function object which this variable belongs to
-
property il_function: function.ILFunctionType¶
returns the IL Function object which this variable belongs to
-
property is_parameter_variable: bool¶
returns whether this variable is a function parameter
-
property last_seen_name: str¶
Name of the variable, or the name most recently assigned if the variable has since been removed (read-only).
-
property name: str¶
Name of the variable, Settings this property is slow because it ensures that analysis has been updated. If you are renaming many variables, use set_name_async, then call update_analysis when complete.
-
property offset_to_next_variable: int | None¶
returns number of bytes to the next variable on the stack
-
property ssa_versions: Generator[int, None, None]¶
Returns the SSA versions associated with this variable. Doesn’t return anything for aliased variables.
-
property type: Type | None¶
-
property var_name_and_type: VariableNameAndType¶
Convert to VariableNameAndType
VariableNameAndType¶
-
class VariableNameAndType[source]¶
Bases: CoreVariable
class VariableNameAndType is a lightweight wrapper around a
variable and its name, useful for shuttling between APIs that require
them both. While Variable has Variable.name and
Variable.type fields, those require additional core calls
each time you fetch them.
- Variables:
-
-
__init__(_source_type: int, index: int, storage: int, name: str, type: Type) → None¶
- Parameters:
-
- Return type:
None
-
classmethod from_core_variable(var, name, type)[source]¶
-
classmethod from_identifier(identifier, name, type)[source]¶
-
name: str¶
-
type: Type¶
|