INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Checks whether this size can be supported by FastMemory." | def _translate_size(self, s): #pylint:disable=no-self-use
"""
Checks whether this size can be supported by FastMemory."
"""
if isinstance(s, claripy.ast.Base) and not s.singlevalued:
raise SimFastMemoryError("size not supported")
if s is None:
return s
... |
Checks whether this condition can be supported by FastMemory." | def _translate_cond(self, c): #pylint:disable=no-self-use
"""
Checks whether this condition can be supported by FastMemory."
"""
if isinstance(c, claripy.ast.Base) and not c.singlevalued:
raise SimFastMemoryError("size not supported")
if c is None:
return ... |
Resolves a memory access of a certain size. Returns a sequence of the bases, offsets, and sizes of the accesses required
to fulfil this. | def _resolve_access(self, addr, size):
"""
Resolves a memory access of a certain size. Returns a sequence of the bases, offsets, and sizes of the accesses required
to fulfil this.
"""
# if we fit in one word
first_offset = addr % self.width
first_base = addr - fi... |
Performs a single load. | def _single_load(self, addr, offset, size, inspect=True, events=True):
"""
Performs a single load.
"""
try:
d = self._contents[addr]
except KeyError:
d = self._handle_uninitialized_read(addr, inspect=inspect, events=events)
self._contents[addr]... |
Performs a single store. | def _single_store(self, addr, offset, size, data):
"""
Performs a single store.
"""
if offset == 0 and size == self.width:
self._contents[addr] = data
elif offset == 0:
cur = self._single_load(addr, size, self.width - size)
self._contents[addr... |
Gets the set of changed bytes between self and other. | def changed_bytes(self, other):
"""
Gets the set of changed bytes between self and other.
"""
changes = set()
l.warning("FastMemory.changed_bytes(): This implementation is very slow and only for debug purposes.")
for addr,v in self._contents.items():
for i i... |
If an argument passed from the stack (i.e. dword ptr [ebp+4h]) is saved to a local variable on the stack at the
beginning of the function, and this local variable was never modified anywhere in this function, and no pointer
of any stack variable is saved in any register, then we can replace all referenc... | def _redundant_stack_variable_removal(self, function, data_graph):
"""
If an argument passed from the stack (i.e. dword ptr [ebp+4h]) is saved to a local variable on the stack at the
beginning of the function, and this local variable was never modified anywhere in this function, and no pointer
... |
Find unused registers throughout the function, and use those registers to replace stack variables.
Only functions that satisfy the following criteria can be optimized in this way:
- The function does not call any other function.
- The function does not use esp to index any stack variable.
... | def _register_reallocation(self, function, data_graph):
"""
Find unused registers throughout the function, and use those registers to replace stack variables.
Only functions that satisfy the following criteria can be optimized in this way:
- The function does not call any other function... |
Remove assignments to registers that has no consumers, but immediately killed.
BROKEN - DO NOT USE IT
:param angr.knowledge.Function function:
:param networkx.MultiDiGraph data_graph:
:return: None | def _dead_assignment_elimination(self, function, data_graph): #pylint:disable=unused-argument
"""
Remove assignments to registers that has no consumers, but immediately killed.
BROKEN - DO NOT USE IT
:param angr.knowledge.Function function:
:param networkx.MultiDiGraph data_gr... |
Set the gs register in the angr to the value of the fs register in the concrete process
:param state: state which will be modified
:param concrete_target: concrete target that will be used to read the fs register
:return: None | def initialize_segment_register_x64(self, state, concrete_target):
"""
Set the gs register in the angr to the value of the fs register in the concrete process
:param state: state which will be modified
:param concrete_target: concrete target that will be used to read t... |
Create a GDT in the state memory and populate the segment registers.
:param state: state which will be modified
:param concrete_target: concrete target that will be used to read the fs register
:return: the created GlobalDescriptorTable object | def initialize_gdt_x86(self, state, concrete_target):
"""
Create a GDT in the state memory and populate the segment registers.
:param state: state which will be modified
:param concrete_target: concrete target that will be used to read the fs register
:return: ... |
Lookups the object that was used for creating the reference. | def lookup(self, opaque_ref):
"""
Lookups the object that was used for creating the reference.
"""
opaque_ref_value = self._get_reference_value(opaque_ref)
# check local refs
if opaque_ref_value in self.local_refs:
return self.local_refs[opaque_ref_value]
... |
Create a new reference thats maps to the given object.
:param obj: Object which gets referenced.
:param bool global_ref: Whether a local or global reference is created. | def create_new_reference(self, obj, global_ref=False):
"""
Create a new reference thats maps to the given object.
:param obj: Object which gets referenced.
:param bool global_ref: Whether a local or global reference is created.
"""
# get an unique address
... |
Delete the stored mapping of a reference.
:param opaque_ref: Reference which should be removed.
:param bool global_ref: Whether opaque_ref is a local or global
reference. | def delete_reference(self, opaque_ref, global_ref=False):
"""
Delete the stored mapping of a reference.
:param opaque_ref: Reference which should be removed.
:param bool global_ref: Whether opaque_ref is a local or global
reference.
"""
... |
Pop a job from the pending jobs list.
When returning == True, we prioritize the jobs whose functions are known to be returning (function.returning is
True). As an optimization, we are sorting the pending jobs list according to job.function.returning.
:param bool returning: Only pop a pending j... | def pop_job(self, returning=True):
"""
Pop a job from the pending jobs list.
When returning == True, we prioritize the jobs whose functions are known to be returning (function.returning is
True). As an optimization, we are sorting the pending jobs list according to job.function.returnin... |
Remove those pending exits if:
a) they are the return exits of non-returning SimProcedures
b) they are the return exits of non-returning syscalls
b) they are the return exits of non-returning functions
:return: None | def cleanup(self):
"""
Remove those pending exits if:
a) they are the return exits of non-returning SimProcedures
b) they are the return exits of non-returning syscalls
b) they are the return exits of non-returning functions
:return: None
"""
pending_exi... |
Mark a function as returning.
:param int func_addr: Address of the function that returns.
:return: None | def add_returning_function(self, func_addr):
"""
Mark a function as returning.
:param int func_addr: Address of the function that returns.
:return: None
"""
self._returning_functions.add(func_addr)
self._updated_functions.add(func_addr) |
Calculate the entropy of a piece of data
:param data: The target data to calculate entropy on
:param size: Size of the data, Optional.
:return: A float | def _calc_entropy(data, size=None):
"""
Calculate the entropy of a piece of data
:param data: The target data to calculate entropy on
:param size: Size of the data, Optional.
:return: A float
"""
if not data:
return 0
entropy = 0
if s... |
Check if the address is inside any existing region.
:param int address: Address to check.
:return: True if the address is within one of the memory regions, False otherwise.
:rtype: bool | def _inside_regions(self, address):
"""
Check if the address is inside any existing region.
:param int address: Address to check.
:return: True if the address is within one of the memory regions, False otherwise.
:rtype: bool
"""
try:
... |
Get the minimum address out of all regions. We assume self._regions is sorted.
:return: The minimum address.
:rtype: int | def _get_min_addr(self):
"""
Get the minimum address out of all regions. We assume self._regions is sorted.
:return: The minimum address.
:rtype: int
"""
if not self._regions:
if self.project.arch.name != "Soot":
l.error("self._regions is em... |
Return the next immediate address that is inside any of the regions.
:param int address: The address to start scanning.
:return: The next address that is inside one of the memory regions.
:rtype: int | def _next_address_in_regions(self, address):
"""
Return the next immediate address that is inside any of the regions.
:param int address: The address to start scanning.
:return: The next address that is inside one of the memory regions.
:rtype: int
... |
Find the next address that we haven't processed
:param alignment: Assures the address returns must be aligned by this number
:return: An address to process next, or None if all addresses have been processed | def _next_unscanned_addr(self, alignment=None):
"""
Find the next address that we haven't processed
:param alignment: Assures the address returns must be aligned by this number
:return: An address to process next, or None if all addresses have been processed
"""
# TODO:... |
Call _next_unscanned_addr() first to get the next address that is not scanned. Then check if data locates at
that address seems to be code or not. If not, we'll continue to for the next un-scanned address. | def _next_code_addr_core(self):
"""
Call _next_unscanned_addr() first to get the next address that is not scanned. Then check if data locates at
that address seems to be code or not. If not, we'll continue to for the next un-scanned address.
"""
next_addr = self._next_unscanned_... |
Some pre job-processing tasks, like update progress bar.
:param CFGJob job: The CFGJob instance.
:return: None | def _pre_job_handling(self, job): # pylint:disable=arguments-differ
"""
Some pre job-processing tasks, like update progress bar.
:param CFGJob job: The CFGJob instance.
:return: None
"""
if self._low_priority:
self._release_gil(len(self._nodes), 20, 0.0001)... |
Get all possible function addresses that are specified by the symbols in the binary
:return: A set of addresses that are probably functions
:rtype: set | def _func_addrs_from_symbols(self):
"""
Get all possible function addresses that are specified by the symbols in the binary
:return: A set of addresses that are probably functions
:rtype: set
"""
return {sym.rebased_addr for sym in self._binary.symbols if sym.is_functio... |
Scan the entire program image for function prologues, and start code scanning at those positions
:return: A list of possible function addresses | def _func_addrs_from_prologues(self):
"""
Scan the entire program image for function prologues, and start code scanning at those positions
:return: A list of possible function addresses
"""
# Pre-compile all regexes
regexes = list()
for ins_regex in self.project... |
Scan a basic block starting at a specific address
:param CFGJob cfg_job: The CFGJob instance.
:return: a list of successors
:rtype: list | def _scan_block(self, cfg_job):
"""
Scan a basic block starting at a specific address
:param CFGJob cfg_job: The CFGJob instance.
:return: a list of successors
:rtype: list
"""
addr = cfg_job.addr
current_func_addr = cfg_job.func_addr
# Fix the ... |
Checks the hooking procedure for this address searching for new static
exit points to add to successors (generating entries for them)
if this address has not been traced before. Updates previous CFG nodes
with edges.
:param CFGJob cfg_job: The CFGJob instance.
:param int cu... | def _scan_procedure(self, cfg_job, current_func_addr):
"""
Checks the hooking procedure for this address searching for new static
exit points to add to successors (generating entries for them)
if this address has not been traced before. Updates previous CFG nodes
with edges.
... |
Generate a list of successors (generating them each as entries) to IRSB.
Updates previous CFG nodes with edges.
:param CFGJob cfg_job: The CFGJob instance.
:param int current_func_addr: Address of the current function
:return: a list of successors
:rtype: list | def _scan_irsb(self, cfg_job, current_func_addr):
"""
Generate a list of successors (generating them each as entries) to IRSB.
Updates previous CFG nodes with edges.
:param CFGJob cfg_job: The CFGJob instance.
:param int current_func_addr: Address of the current function
... |
Given a node and details of a successor, makes a list of CFGJobs
and if it is a call or exit marks it appropriately so in the CFG
:param int target: Destination of the resultant job
:param str jumpkind: The jumpkind of the edge going to this node
:param int current_funct... | def _create_jobs(self, target, jumpkind, current_function_addr, irsb, addr, cfg_node, ins_addr, stmt_idx):
"""
Given a node and details of a successor, makes a list of CFGJobs
and if it is a call or exit marks it appropriately so in the CFG
:param int target: Destination of the... |
Generate a CFGJob for target address, also adding to _pending_entries
if returning to succeeding position (if irsb arg is populated)
:param int addr: Address of the predecessor node
:param pyvex.IRSB irsb: IRSB of the predecessor node
:param CFGNode cfg_node: The CFGNo... | def _create_job_call(self, addr, irsb, cfg_node, stmt_idx, ins_addr, current_function_addr, target_addr, jumpkind,
is_syscall=False):
"""
Generate a CFGJob for target address, also adding to _pending_entries
if returning to succeeding position (if irsb arg is populated)
... |
Unoptimises IRSB and _add_data_reference's for individual statements or
for parts of statements (e.g. Store)
:param pyvex.IRSB irsb: Block to scan for data references
:param int irsb_addr: Address of block
:return: None | def _collect_data_references(self, irsb, irsb_addr):
"""
Unoptimises IRSB and _add_data_reference's for individual statements or
for parts of statements (e.g. Store)
:param pyvex.IRSB irsb: Block to scan for data references
:param int irsb_addr: Address of block
:return:... |
Checks addresses are in the correct segments and creates or updates
MemoryData in _memory_data as appropriate, labelling as segment
boundaries or data type
:param int irsb_addr: irsb address
:param int stmt_idx: Statement ID
:param int insn_addr: instruction address
:par... | def _add_data_reference(self, irsb_addr, stmt_idx, insn_addr, data_addr, # pylint: disable=unused-argument
data_size=None, data_type=None):
"""
Checks addresses are in the correct segments and creates or updates
MemoryData in _memory_data as appropriate, labelling as... |
Make a guess to the data type.
Users can provide their own data type guessing code when initializing CFGFast instance, and each guessing
handler will be called if this method fails to determine what the data is.
:param int data_addr: Address of the data.
:param int max_size: The maximu... | def _guess_data_type(self, data_addr, max_size, content_holder=None):
"""
Make a guess to the data type.
Users can provide their own data type guessing code when initializing CFGFast instance, and each guessing
handler will be called if this method fails to determine what the data is.
... |
Determine if the IRSB at the given address is a PLT stub. If it is, concretely execute the basic block to
resolve the jump target.
:param int addr: Address of the block.
:param irsb: The basic block.
:param IndirectJump indir_jump: The IndirectJump inst... | def _resolve_plt(self, addr, irsb, indir_jump):
"""
Determine if the IRSB at the given address is a PLT stub. If it is, concretely execute the basic block to
resolve the jump target.
:param int addr: Address of the block.
:param irsb: The basic ... |
Called when an indirect jump is successfully resolved.
:param IndirectJump jump: The resolved indirect jump.
:param IndirectJumpResolver resolved_by: The resolver used to resolve this indirect jump.
:param list targets: List of indirect jump targets.
... | def _indirect_jump_resolved(self, jump, jump_addr, resolved_by, targets):
"""
Called when an indirect jump is successfully resolved.
:param IndirectJump jump: The resolved indirect jump.
:param IndirectJumpResolver resolved_by: The resolver used to resolve this indi... |
Called when we cannot resolve an indirect jump.
:param IndirectJump jump: The unresolved indirect jump.
:return: None | def _indirect_jump_unresolved(self, jump):
"""
Called when we cannot resolve an indirect jump.
:param IndirectJump jump: The unresolved indirect jump.
:return: None
"""
# add a node from this node to UnresolvableJumpTarget or UnresolvalbeCallTarget node,
# d... |
On some architectures there are sometimes garbage bytes (usually nops) between functions in order to properly
align the succeeding function. CFGFast does a linear sweeping which might create duplicated blocks for
function epilogues where one block starts before the garbage bytes and the other starts aft... | def _remove_redundant_overlapping_blocks(self):
"""
On some architectures there are sometimes garbage bytes (usually nops) between functions in order to properly
align the succeeding function. CFGFast does a linear sweeping which might create duplicated blocks for
function epilogues wher... |
Remove a CFGNode from self.graph as well as from the function manager (if it is the beginning of a function)
:param CFGNode node: The CFGNode to remove from the graph.
:return: None | def _remove_node(self, node):
"""
Remove a CFGNode from self.graph as well as from the function manager (if it is the beginning of a function)
:param CFGNode node: The CFGNode to remove from the graph.
:return: None
"""
self.graph.remove_node(node)
if node.addr ... |
Shrink the size of a node in CFG.
:param CFGNode node: The CFGNode to shrink
:param int new_size: The new size of the basic block
:param bool remove_function: If there is a function starting at `node`, should we remove that function or not.
:return: None | def _shrink_node(self, node, new_size, remove_function=True):
"""
Shrink the size of a node in CFG.
:param CFGNode node: The CFGNode to shrink
:param int new_size: The new size of the basic block
:param bool remove_function: If there is a function starting at `node`, should we r... |
Iteratively analyze all changed functions, update their returning attribute, until a fix-point is reached (i.e.
no new returning/not-returning functions are found).
:return: None | def _analyze_all_function_features(self, all_funcs_completed=False):
"""
Iteratively analyze all changed functions, update their returning attribute, until a fix-point is reached (i.e.
no new returning/not-returning functions are found).
:return: None
"""
while True:
... |
Add edge between nodes, or add node if entry point
:param CFGNode cfg_node: node which is jumped to
:param CFGNode src_node: node which is jumped from none if entry point
:param str src_jumpkind: what type of jump the edge takes
:param int or str src_stmt_idx: source statements ID
... | def _graph_add_edge(self, cfg_node, src_node, src_jumpkind, src_ins_addr, src_stmt_idx):
"""
Add edge between nodes, or add node if entry point
:param CFGNode cfg_node: node which is jumped to
:param CFGNode src_node: node which is jumped from none if entry point
:param str src_... |
For each returning function, create return edges in self.graph.
:return: None | def _make_return_edges(self):
"""
For each returning function, create return edges in self.graph.
:return: None
"""
for func_addr, func in self.functions.items():
if func.returning is False:
continue
# get the node on CFG
if ... |
Adds node to function manager, converting address to CodeNode if
possible
:param CFGNode cfg_node: A CFGNode instance.
:param int function_addr: Address of the current function.
:return: None | def _function_add_node(self, cfg_node, function_addr):
"""
Adds node to function manager, converting address to CodeNode if
possible
:param CFGNode cfg_node: A CFGNode instance.
:param int function_addr: Address of the current function.
:return: None
"""
... |
Add a transition edge to the function transiton map.
:param int dst_addr: Address that the control flow transits to.
:param CFGNode src_node: The source node that the control flow transits from.
:param int src_func_addr: Function address.
:return: True if the edge is correctly added. Fa... | def _function_add_transition_edge(self, dst_addr, src_node, src_func_addr, to_outside=False, dst_func_addr=None,
stmt_idx=None, ins_addr=None):
"""
Add a transition edge to the function transiton map.
:param int dst_addr: Address that the control flow trans... |
Add a call edge to the function transition map.
:param int addr: Address that is being called (callee).
:param CFGNode src_node: The source CFG node (caller).
:param int ret_addr: Address that returns to (in case the function returns).
:param int function_addr: Function address..
... | def _function_add_call_edge(self, addr, src_node, function_addr, syscall=False, stmt_idx=None, ins_addr=None):
"""
Add a call edge to the function transition map.
:param int addr: Address that is being called (callee).
:param CFGNode src_node: The source CFG node (caller).
:para... |
Generate CodeNodes for target and source, if no source node add node
for function, otherwise creates fake return to in function manager
:param int addr: target address
:param angr.analyses.CFGNode src_node: source node
:param int src_func_addr: address of function
:param confirm... | def _function_add_fakeret_edge(self, addr, src_node, src_func_addr, confirmed=None):
"""
Generate CodeNodes for target and source, if no source node add node
for function, otherwise creates fake return to in function manager
:param int addr: target address
:param angr.analyses.C... |
Generate CodeNodes for target address, registers node for function to
function manager as return site
:param int addr: target address
:param int function_addr: address of function
:return: None | def _function_add_return_site(self, addr, function_addr):
"""
Generate CodeNodes for target address, registers node for function to
function manager as return site
:param int addr: target address
:param int function_addr: address of function
:return: None
"""
... |
Generate CodeNodes for return_to_addr, add this node for function to
function manager generating new edge
:param int return_from_addr: target address
:param int return_to_addr: target address
:param int function_addr: address of function
:return: None | def _function_add_return_edge(self, return_from_addr, return_to_addr, function_addr):
"""
Generate CodeNodes for return_to_addr, add this node for function to
function manager generating new edge
:param int return_from_addr: target address
:param int return_to_addr: target addre... |
At the beginning of the basic block, we check if the first instruction stores the LR register onto the stack.
If it does, we calculate the offset of that store, and record the offset in function.info.
For instance, here is the disassembly of a THUMB mode function:
000007E4 STR.W LR,... | def _arm_track_lr_on_stack(self, addr, irsb, function):
"""
At the beginning of the basic block, we check if the first instruction stores the LR register onto the stack.
If it does, we calculate the offset of that store, and record the offset in function.info.
For instance, here is the ... |
At the end of a basic block, simulate the very last instruction to see if the return address is read from the
stack and written in PC. If so, the jumpkind of this IRSB will be set to Ijk_Ret. For detailed explanations,
please see the documentation of _arm_track_lr_on_stack().
:param pyvex.IRSB ... | def _arm_track_read_lr_from_stack(self, irsb, function): # pylint:disable=unused-argument
"""
At the end of a basic block, simulate the very last instruction to see if the return address is read from the
stack and written in PC. If so, the jumpkind of this IRSB will be set to Ijk_Ret. For detai... |
Generate a CFGNode that starts at `cfg_job.addr`.
Since lifting machine code to IRSBs is slow, self._nodes is used as a cache of CFGNodes.
If the current architecture is ARM, this method will try to lift the block in the mode specified by the address
(determined by the parity of the address: e... | def _generate_cfgnode(self, cfg_job, current_function_addr):
"""
Generate a CFGNode that starts at `cfg_job.addr`.
Since lifting machine code to IRSBs is slow, self._nodes is used as a cache of CFGNodes.
If the current architecture is ARM, this method will try to lift the block in the ... |
According to arch types ['ARMEL', 'ARMHF', 'MIPS32'] does different
fixes
For ARM deals with link register on the stack
(see _arm_track_lr_on_stack)
For MIPS32 simulates a new state where the global pointer is 0xffffffff
from current address after three steps if the first succes... | def _process_block_arch_specific(self, addr, irsb, func_addr): # pylint: disable=unused-argument
"""
According to arch types ['ARMEL', 'ARMHF', 'MIPS32'] does different
fixes
For ARM deals with link register on the stack
(see _arm_track_lr_on_stack)
For MIPS32 simulates... |
Generate a list of all recovered basic blocks. | def generate_code_cover(self):
"""
Generate a list of all recovered basic blocks.
"""
lst = []
for cfg_node in self.graph.nodes():
size = cfg_node.size
lst.append((cfg_node.addr, size))
lst = sorted(lst, key=lambda x: x[0])
return lst |
Deprecated alias for `solver` | def se(self):
"""
Deprecated alias for `solver`
"""
global _complained_se
if not _complained_se:
_complained_se = True
l.critical("The name state.se is deprecated; please use state.solver.")
return self.get_plugin('solver') |
Get the concrete address of the instruction pointer, without triggering SimInspect breakpoints or generating
SimActions. An integer is returned, or an exception is raised if the instruction pointer is symbolic.
:return: an int | def addr(self):
"""
Get the concrete address of the instruction pointer, without triggering SimInspect breakpoints or generating
SimActions. An integer is returned, or an exception is raised if the instruction pointer is symbolic.
:return: an int
"""
ip = self.regs._ip
... |
Add some constraints to the state.
You may pass in any number of symbolic booleans as variadic positional arguments. | def add_constraints(self, *args, **kwargs):
"""
Add some constraints to the state.
You may pass in any number of symbolic booleans as variadic positional arguments.
"""
if len(args) > 0 and isinstance(args[0], (list, tuple)):
raise Exception("Tuple or list passed to ... |
Whether the state's constraints are satisfiable | def satisfiable(self, **kwargs):
"""
Whether the state's constraints are satisfiable
"""
if o.ABSTRACT_SOLVER in self.options or o.SYMBOLIC not in self.options:
extra_constraints = kwargs.pop('extra_constraints', ())
for e in extra_constraints:
if ... |
Represent the basic block at this state's instruction pointer.
Any arguments to `AngrObjectFactory.block` can ba passed to this.
:return: A Block object describing the basic block of code at this point. | def block(self, *args, **kwargs):
"""
Represent the basic block at this state's instruction pointer.
Any arguments to `AngrObjectFactory.block` can ba passed to this.
:return: A Block object describing the basic block of code at this point.
"""
if not args and 'addr' not... |
Returns a copy of the state. | def copy(self):
"""
Returns a copy of the state.
"""
if self._global_condition is not None:
raise SimStateError("global condition was not cleared before state.copy().")
c_plugins = self._copy_plugins()
state = SimState(project=self.project, arch=self.arch, p... |
Merges this state with the other states. Returns the merging result, merged state, and the merge flag.
:param states: the states to merge
:param merge_conditions: a tuple of the conditions under which each state holds
:param common_ancestor: a state that represents the common history between t... | def merge(self, *others, **kwargs):
"""
Merges this state with the other states. Returns the merging result, merged state, and the merge flag.
:param states: the states to merge
:param merge_conditions: a tuple of the conditions under which each state holds
:param common_ancesto... |
Perform a widening between self and other states
:param others:
:return: | def widen(self, *others):
"""
Perform a widening between self and other states
:param others:
:return:
"""
if len(set(frozenset(o.plugins.keys()) for o in others)) != 1:
raise SimMergeError("Unable to widen due to different sets of plugins.")
if len(s... |
Returns the contents of a register but, if that register is symbolic,
raises a SimValueError. | def reg_concrete(self, *args, **kwargs):
"""
Returns the contents of a register but, if that register is symbolic,
raises a SimValueError.
"""
e = self.registers.load(*args, **kwargs)
if self.solver.symbolic(e):
raise SimValueError("target of reg_concrete is s... |
Returns the contents of a memory but, if the contents are symbolic,
raises a SimValueError. | def mem_concrete(self, *args, **kwargs):
"""
Returns the contents of a memory but, if the contents are symbolic,
raises a SimValueError.
"""
e = self.memory.load(*args, **kwargs)
if self.solver.symbolic(e):
raise SimValueError("target of mem_concrete is symbol... |
Push 'thing' to the stack, writing the thing to memory and adjusting the stack pointer. | def stack_push(self, thing):
"""
Push 'thing' to the stack, writing the thing to memory and adjusting the stack pointer.
"""
# increment sp
sp = self.regs.sp + self.arch.stack_change
self.regs.sp = sp
return self.memory.store(sp, thing, endness=self.arch.memory_en... |
Pops from the stack and returns the popped thing. The length will be the architecture word size. | def stack_pop(self):
"""
Pops from the stack and returns the popped thing. The length will be the architecture word size.
"""
sp = self.regs.sp
self.regs.sp = sp - self.arch.stack_change
return self.memory.load(sp, self.arch.bytes, endness=self.arch.memory_endness) |
Reads length bytes, at an offset into the stack.
:param offset: The offset from the stack pointer.
:param length: The number of bytes to read.
:param bp: If True, offset from the BP instead of the SP. Default: False. | def stack_read(self, offset, length, bp=False):
"""
Reads length bytes, at an offset into the stack.
:param offset: The offset from the stack pointer.
:param length: The number of bytes to read.
:param bp: If True, offset from the BP instead of the SP. Default: False.
... |
Convert each stack value to a string
:param stack_values: A list of values
:return: The converted string | def _stack_values_to_string(self, stack_values):
"""
Convert each stack value to a string
:param stack_values: A list of values
:return: The converted string
"""
strings = [ ]
for stack_value in stack_values:
if self.solver.symbolic(stack_value):
... |
Only used for debugging purposes.
Return the current stack info in formatted string. If depth is None, the
current stack frame (from sp to bp) will be printed out. | def dbg_print_stack(self, depth=None, sp=None):
"""
Only used for debugging purposes.
Return the current stack info in formatted string. If depth is None, the
current stack frame (from sp to bp) will be printed out.
"""
var_size = self.arch.bytes
sp_sim = self.re... |
Concretizes a size argument, if necessary, to something that makes sense when allocating space. Here we just
maximize its potential size up to the maximum variable size specified in the libc plugin.
TODO:
Further consideration of the tradeoffs of this approach is probably warranted. SimHeapPTMa... | def _conc_alloc_size(self, sim_size):
"""
Concretizes a size argument, if necessary, to something that makes sense when allocating space. Here we just
maximize its potential size up to the maximum variable size specified in the libc plugin.
TODO:
Further consideration of the tra... |
Handler for any libc `malloc` SimProcedure call. If the heap has faithful support for `malloc`, it ought to be
implemented in a `malloc` function (as opposed to the `_malloc` function).
:param sim_size: the amount of memory (in bytes) to be allocated | def _malloc(self, sim_size):
"""
Handler for any libc `malloc` SimProcedure call. If the heap has faithful support for `malloc`, it ought to be
implemented in a `malloc` function (as opposed to the `_malloc` function).
:param sim_size: the amount of memory (in bytes) to be allocated
... |
Handler for any libc `free` SimProcedure call. If the heap has faithful support for `free`, it ought to be
implemented in a `free` function (as opposed to the `_free` function).
:param ptr: the location in memory to be freed | def _free(self, ptr):
"""
Handler for any libc `free` SimProcedure call. If the heap has faithful support for `free`, it ought to be
implemented in a `free` function (as opposed to the `_free` function).
:param ptr: the location in memory to be freed
"""
raise NotImpleme... |
Handler for any libc `calloc` SimProcedure call. If the heap has faithful support for `calloc`, it ought to be
implemented in a `calloc` function (as opposed to the `_calloc` function).
:param sim_nmemb: the number of elements to allocated
:param sim_size: the size of each element (in bytes) | def _calloc(self, sim_nmemb, sim_size):
"""
Handler for any libc `calloc` SimProcedure call. If the heap has faithful support for `calloc`, it ought to be
implemented in a `calloc` function (as opposed to the `_calloc` function).
:param sim_nmemb: the number of elements to allocated
... |
Handler for any libc `realloc` SimProcedure call. If the heap has faithful support for `realloc`, it ought to be
implemented in a `realloc` function (as opposed to the `_realloc` function).
:param ptr: the location in memory to be reallocated
:param size: the new size desired for the allocation | def _realloc(self, ptr, size):
"""
Handler for any libc `realloc` SimProcedure call. If the heap has faithful support for `realloc`, it ought to be
implemented in a `realloc` function (as opposed to the `_realloc` function).
:param ptr: the location in memory to be reallocated
:... |
The implementation here is simple - just perform a pattern matching of all different architectures we support,
and then perform a vote. | def _reconnoiter(self):
"""
The implementation here is simple - just perform a pattern matching of all different architectures we support,
and then perform a vote.
"""
# Retrieve the binary string of main binary
votes = defaultdict(int)
for arch in all_arches:
... |
Convert multiple supported forms of stack pointer representations into stack offsets.
:param sp: A stack pointer representation.
:return: A stack pointer offset.
:rtype: int | def parse_stack_pointer(sp):
"""
Convert multiple supported forms of stack pointer representations into stack offsets.
:param sp: A stack pointer representation.
:return: A stack pointer offset.
:rtype: int
"""
if isinstance(sp, int):
return sp
if isinstance(sp, StackBa... |
Get variables that are defined at the specified block.
:param int block_addr: Address of the block.
:return: A set of variables. | def get_variable_definitions(self, block_addr):
"""
Get variables that are defined at the specified block.
:param int block_addr: Address of the block.
:return: A set of variables.
"""
if block_addr in self._outstates:
return self._outstates[... |
Checks if `phi_variable` is a phi variable, and if it contains `variable` as a sub-variable.
:param phi_variable:
:param variable:
:return: | def _phi_node_contains(self, phi_variable, variable):
"""
Checks if `phi_variable` is a phi variable, and if it contains `variable` as a sub-variable.
:param phi_variable:
:param variable:
:return:
"""
if self.variable_manager[self.function.addr].is_phi_variable... |
Returns the lineage of histories leading up to `h`. | def lineage(self, h):
"""
Returns the lineage of histories leading up to `h`.
"""
lineage = [ ]
predecessors = list(self._graph.predecessors(h))
while len(predecessors):
lineage.append(predecessors[0])
predecessors = list(self._graph.predecessors... |
Find the "most mergeable" set of states from those provided.
:param states: a list of states
:returns: a tuple of: (a list of states to merge, those states' common history, a list of states to not merge yet) | def most_mergeable(self, states):
"""
Find the "most mergeable" set of states from those provided.
:param states: a list of states
:returns: a tuple of: (a list of states to merge, those states' common history, a list of states to not merge yet)
"""
histories = set(self... |
Perform execution with a state.
You should only override this method in a subclass in order to provide the correct method signature and
docstring. You should override the ``_process`` method to do your actual execution.
:param state: The state with which to execute. This state will be co... | def process(self, state, *args, **kwargs):
"""
Perform execution with a state.
You should only override this method in a subclass in order to provide the correct method signature and
docstring. You should override the ``_process`` method to do your actual execution.
:param stat... |
Check if this engine can be used for execution on the current state. A callback `check_failure` is called upon
failed checks. Note that the execution can still fail even if check() returns True.
You should only override this method in a subclass in order to provide the correct method signature and
... | def check(self, state, *args, **kwargs):
"""
Check if this engine can be used for execution on the current state. A callback `check_failure` is called upon
failed checks. Note that the execution can still fail even if check() returns True.
You should only override this method in a subcl... |
Check if the resolved target is valid.
:param cfg: The CFG analysis object.
:param int target: The target to check.
:return: True if the target is valid. False otherwise.
:rtype: bool | def _is_target_valid(self, cfg, target): # pylint:disable=no-self-use
"""
Check if the resolved target is valid.
:param cfg: The CFG analysis object.
:param int target: The target to check.
:return: True if the target is valid. False otherwise.
:rtyp... |
:param state: The state with which to execute
:param step: How many basic blocks we want to execute
:param extra_stop_points: A collection of addresses at which execution should halt
:param inline: This is an inline execution. Do not bother copying the... | def process(self, state,
step=None,
extra_stop_points=None,
inline=False,
force_addr=None,
**kwargs):
"""
:param state: The state with which to execute
:param step: How many basic blocks we want to execute
... |
Returns the actual size of a chunk (as opposed to the entire size field, which may include some flags). | def get_size(self):
"""
Returns the actual size of a chunk (as opposed to the entire size field, which may include some flags).
"""
raise NotImplementedError("%s not implemented for %s" % (self.get_size.__func__.__name__,
s... |
Sets the size of the chunk, preserving any flags. | def set_size(self, size):
"""
Sets the size of the chunk, preserving any flags.
"""
raise NotImplementedError("%s not implemented for %s" % (self.set_size.__func__.__name__,
self.__class__.__name__)) |
Returns the address of the payload of the chunk. | def data_ptr(self):
"""
Returns the address of the payload of the chunk.
"""
raise NotImplementedError("%s not implemented for %s" % (self.data_ptr.__func__.__name__,
self.__class__.__name__)) |
Returns a concrete determination as to whether the chunk is free. | def is_free(self):
"""
Returns a concrete determination as to whether the chunk is free.
"""
raise NotImplementedError("%s not implemented for %s" % (self.is_free.__func__.__name__,
self.__class__.__name__)) |
Returns the chunk immediately following (and adjacent to) this one. | def next_chunk(self):
"""
Returns the chunk immediately following (and adjacent to) this one.
"""
raise NotImplementedError("%s not implemented for %s" % (self.next_chunk.__func__.__name__,
self.__class__.__name__)) |
Returns the chunk immediately prior (and adjacent) to this one. | def prev_chunk(self):
"""
Returns the chunk immediately prior (and adjacent) to this one.
"""
raise NotImplementedError("%s not implemented for %s" % (self.prev_chunk.__func__.__name__,
self.__class__.__name__)) |
Returns the chunk following this chunk in the list of free chunks. | def fwd_chunk(self):
"""
Returns the chunk following this chunk in the list of free chunks.
"""
raise NotImplementedError("%s not implemented for %s" % (self.fwd_chunk.__func__.__name__,
self.__class__.__name__)) |
Sets the chunk following this chunk in the list of free chunks.
:param fwd: the chunk to follow this chunk in the list of free chunks | def set_fwd_chunk(self, fwd):
"""
Sets the chunk following this chunk in the list of free chunks.
:param fwd: the chunk to follow this chunk in the list of free chunks
"""
raise NotImplementedError("%s not implemented for %s" % (self.set_fwd_chunk.__func__.__name__,
... |
Returns the chunk backward from this chunk in the list of free chunks. | def bck_chunk(self):
"""
Returns the chunk backward from this chunk in the list of free chunks.
"""
raise NotImplementedError("%s not implemented for %s" % (self.bck_chunk.__func__.__name__,
self.__class__.__name__)) |
Sets the chunk backward from this chunk in the list of free chunks.
:param bck: the chunk to precede this chunk in the list of free chunks | def set_bck_chunk(self, bck):
"""
Sets the chunk backward from this chunk in the list of free chunks.
:param bck: the chunk to precede this chunk in the list of free chunks
"""
raise NotImplementedError("%s not implemented for %s" % (self.set_bck_chunk.__func__.__name__,
... |
Returns an iterator over all the chunks in the heap. | def chunks(self):
"""
Returns an iterator over all the chunks in the heap.
"""
raise NotImplementedError("%s not implemented for %s" % (self.chunks.__func__.__name__,
self.__class__.__name__)) |
Returns an iterator over all the allocated chunks in the heap. | def allocated_chunks(self):
"""
Returns an iterator over all the allocated chunks in the heap.
"""
raise NotImplementedError("%s not implemented for %s" % (self.allocated_chunks.__func__.__name__,
self.__class__.__name__)) |
Returns an iterator over all the free chunks in the heap. | def free_chunks(self):
"""
Returns an iterator over all the free chunks in the heap.
"""
raise NotImplementedError("%s not implemented for %s" % (self.free_chunks.__func__.__name__,
self.__class__.__name__)) |
Given a pointer to a user payload, return the chunk associated with that payload.
:param ptr: a pointer to the base of a user payload in the heap
:returns: the associated heap chunk | def chunk_from_mem(self, ptr):
"""
Given a pointer to a user payload, return the chunk associated with that payload.
:param ptr: a pointer to the base of a user payload in the heap
:returns: the associated heap chunk
"""
raise NotImplementedError("%s not implemented for ... |
Perform execution using any applicable engine. Enumerate the current engines and use the
first one that works. Engines are enumerated in order, specified by the ``order`` attribute.
:param state: The state to analyze
:param addr: optional, an address to execute at i... | def successors(self, state, addr=None, jumpkind=None, default_engine=False, procedure_engine=False,
engines=None, **kwargs):
"""
Perform execution using any applicable engine. Enumerate the current engines and use the
first one that works. Engines are enumerated in order, spec... |
Besides calling _get_next_addr, we will check if data locates at that address seems to be code or not. If not,
we'll move on to request for next valid address. | def _get_next_code_addr(self, initial_state):
"""
Besides calling _get_next_addr, we will check if data locates at that address seems to be code or not. If not,
we'll move on to request for next valid address.
"""
next_addr = self._get_next_addr_to_search()
if next_addr ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.