text stringlengths 81 112k |
|---|
Return a string representation of all state options.
:param bool exclude_false: Whether to exclude Boolean switches that are disabled.
:param bool description: Whether to display the description of each option.
:return: A string representation.
:rtype: ... |
Register a state option.
:param str name: Name of the state option.
:param types: A collection of allowed types of this state option.
:param default: The default value of this state option.
:param str description: The description of this state option.
:r... |
Register a Boolean switch as state option.
This is equivalent to cls.register_option(name, set([bool]), description=description)
:param str name: Name of the state option.
:param str description: The description of this state option.
:return: None
def register_boo... |
For now a lot of naive concretization is done when handling heap metadata to keep things manageable. This idiom
showed up a lot as a result, so to reduce code repetition this function uses a callback to handle the one or two
operations that varied across invocations.
:param x: the item to be concretized
... |
return a 5-tuple of strings sufficient for formatting with ``%s%s%s%s%s`` to verbosely describe the procedure
def _describe_me(self):
"""
return a 5-tuple of strings sufficient for formatting with ``%s%s%s%s%s`` to verbosely describe the procedure
"""
return (
self.display_n... |
Call this method with a SimState and a SimSuccessors to execute the procedure.
Alternately, successors may be none if this is an inline call. In that case, you should
provide arguments to the function.
def execute(self, state, successors=None, arguments=None, ret_to=None):
"""
Call thi... |
Returns the ith argument. Raise a SimProcedureArgumentError if we don't have such an argument available.
:param int i: The index of the argument to get
:return: The argument
:rtype: object
def arg(self, i):
"""
Returns the ith argument. Raise a SimProcedureArgumentError if we d... |
Call another SimProcedure in-line to retrieve its return value.
Returns an instance of the procedure with the ret_expr property set.
:param procedure: The class of the procedure to execute
:param arguments: Any additional positional args will be used as arguments to the
... |
Add an exit representing a return from this function.
If this is not an inline call, grab a return address from the state and jump to it.
If this is not an inline call, set a return expression with the calling convention.
def ret(self, expr=None):
"""
Add an exit representing a return f... |
Add an exit representing calling another function via pointer.
:param addr: The address of the function to call
:param args: The list of arguments to call the function with
:param continue_at: Later, when the called function returns, execution of the current
... |
Add an exit representing jumping to an address.
def jump(self, addr):
"""
Add an exit representing jumping to an address.
"""
self.inhibit_autoret = True
self._exit_action(self.state, addr)
self.successors.add_successor(self.state, addr, self.state.solver.true, 'Ijk_Bori... |
Add an exit representing terminating the program.
def exit(self, exit_code):
"""
Add an exit representing terminating the program.
"""
self.inhibit_autoret = True
self.state.options.discard(o.AST_DEPS)
self.state.options.discard(o.AUTO_REFS)
if isinstance(exit_c... |
Starting from the start_node, explore the entire VFG, and perform the following:
- Generate def-use chains for all registers and memory addresses using a worklist
def _explore(self):
"""
Starting from the start_node, explore the entire VFG, and perform the following:
- Generate def-use ... |
Given all live definitions prior to this program point, track the changes, and return a new list of live
definitions. We scan through the action list of the new state to track the changes.
:param state: The input state at that program point.
:param live_defs: A list of all live definiti... |
This is a backward lookup in the previous defs.
:param addr_list: a list of normalized addresses.
Note that, as we are using VSA, it is possible that @a is affected by several definitions.
:returns: a dict {stmt:labels} where label is the number of individual addresses of... |
Kill previous defs. `addr_list` is a list of normalized addresses.
def _kill(self, live_defs, variable, code_loc):
"""
Kill previous defs. `addr_list` is a list of normalized addresses.
"""
# Case 1: address perfectly match, we kill
# Case 2: a is a subset of the original addre... |
Add an edge in the graph from `s_a` to statement `s_b`, where `s_a` and `s_b` are tuples of statements of the
form (irsb_addr, stmt_idx).
def _add_edge(self, s_a, s_b, **edge_labels):
"""
Add an edge in the graph from `s_a` to statement `s_b`, where `s_a` and `s_b` are tuples of statements of t... |
Get all DDG nodes matching the given basic block address and statement index.
def get_all_nodes(self, simrun_addr, stmt_idx):
"""
Get all DDG nodes matching the given basic block address and statement index.
"""
nodes=[]
for n in self.graph.nodes():
if n.simrun_addr ... |
Yields each of the individual lane pairs from the arguments, in
order from most significan to least significant
def vector_args(self, args):
"""
Yields each of the individual lane pairs from the arguments, in
order from most significan to least significant
"""
for i i... |
Count the leading zeroes
def _op_generic_Clz(self, args):
"""Count the leading zeroes"""
wtf_expr = claripy.BVV(self._from_size, self._from_size)
for a in range(self._from_size):
bit = claripy.Extract(a, a, args[0])
wtf_expr = claripy.If(bit==1, claripy.BVV(self._from_si... |
Count the trailing zeroes
def _op_generic_Ctz(self, args):
"""Count the trailing zeroes"""
wtf_expr = claripy.BVV(self._from_size, self._from_size)
for a in reversed(range(self._from_size)):
bit = claripy.Extract(a, a, args[0])
wtf_expr = claripy.If(bit == 1, claripy.BVV... |
Halving add, for some ARM NEON instructions.
def _op_generic_HAdd(self, args):
"""
Halving add, for some ARM NEON instructions.
"""
components = []
for a, b in self.vector_args(args):
if self.is_signed:
a = a.sign_extend(self._vector_size)
... |
Saturating add.
def _op_generic_QAdd(self, args):
"""
Saturating add.
"""
components = []
for a, b in self.vector_args(args):
top_a = a[self._vector_size-1]
top_b = b[self._vector_size-1]
res = a + b
top_r = res[self._vector_size-1... |
Generic pack with unsigned saturation.
Split args in chunks of src_size signed bits and in pack them into unsigned saturated chunks of dst_size bits.
Then chunks are concatenated resulting in a BV of len(args)*dst_size//src_size*len(args[0]) bits.
def _op_generic_pack_StoU_saturation(self, args, src_si... |
Return unsigned saturated BV from signed BV.
Min and max value should be unsigned.
def _op_generic_StoU_saturation(self, value, min_value, max_value): #pylint:disable=no-self-use
"""
Return unsigned saturated BV from signed BV.
Min and max value should be unsigned.
"""
r... |
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.
... |
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_soot_bl... |
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... |
Revisit the entire control flow graph, create Function instances accordingly, and correctly put blocks into
each function.
Although Function objects are crated during the CFG recovery, they are neither sound nor accurate. With a
pre-constructed CFG, this method rebuilds all functions bearing th... |
Sets an instance field.
def set_field(self, state, field_name, field_type, value):
"""
Sets an instance field.
"""
field_ref = SimSootValue_InstanceFieldRef.get_ref(state=state,
obj_alloc_id=self.heap_alloc_id,
... |
Gets the value of an instance field.
def get_field(self, state, field_name, field_type):
"""
Gets the value of an instance field.
"""
# get field reference
field_ref = SimSootValue_InstanceFieldRef.get_ref(state=state,
ob... |
Store a field of a given object, without resolving hierachy
:param state: angr state where we want to allocate the object attribute
:type SimState
:param field_name: name of the attribute
:type str
:param field_value: attibute's value
:type SimSootValue
def store_field(... |
Load a field of a given object, without resolving hierachy
:param state: angr state where we want to load the object attribute
:type SimState
:param field_name: name of the attribute
:type str
:param field_type: type of the attribute
:type str
def load_field(self, state... |
Creates a new object reference.
:param state: State associated to the object.
:param type_: Class of the object.
:param init_object: Whether the objects initializer method should be run.
:return: Reference to the new object.
def new_object(cls, state, type_, symbolic=False, init_object=... |
Configure the project to set up global settings (like SimProcedures).
def configure_project(self):
"""
Configure the project to set up global settings (like SimProcedures).
"""
self.return_deadend = self.project.loader.extern_object.allocate()
self.project.hook(self.return_deade... |
Initialize a blank state.
All parameters are optional.
:param addr: The execution start address.
:param initial_prefix:
:param stack_end: The end of the stack (i.e., the byte after the last valid stack address).
:param stack_size: The number of bytes to al... |
This function prepares a state that is executing a call instruction.
If given an initial_state, it copies over all of the critical registers to it from the
calling_state. Otherwise, it prepares the calling_state for action.
This is mostly used to create minimalistic for CFG generation. Some ABI... |
Prepare the address space with the data necessary to perform relocations pointing to the given symbol
Returns a 2-tuple. The first item is the address of the function code, the second is the address of the
relocation target.
def prepare_function_symbol(self, symbol_name, basic_addr=None):
"""
... |
Write the GlobalDescriptorTable object in the current state memory
:param state: state in which to write the GDT
:param gdt: GlobalDescriptorTable object
:return:
def setup_gdt(self, state, gdt):
"""
Write the GlobalDescriptorTable object in the current state memory
:p... |
Generate a GlobalDescriptorTable object and populate it using the value of the gs and fs register
:param fs: value of the fs segment register
:param gs: value of the gs segment register
:param fs_size: size of the fs segment register
:param gs_size: size of the gs segment regi... |
Register a struct definition globally
>>> define_struct('struct abcd {int x; int y;}')
def define_struct(defn):
"""
Register a struct definition globally
>>> define_struct('struct abcd {int x; int y;}')
"""
struct = parse_type(defn)
ALL_TYPES[struct.name] = struct
return struct |
Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
def do_preprocess(defn):
"""
Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
"""
from pycparser.ply import lex, cpp
lexer = lex.lex(cpp)
p = cpp.Preproce... |
Parse a series of C definitions, returns a tuple of two type mappings, one for variable
definitions and one for type definitions.
def parse_file(defn, preprocess=True):
"""
Parse a series of C definitions, returns a tuple of two type mappings, one for variable
definitions and one for type definitions.
... |
Parse a simple type expression into a SimType
>>> parse_type('int *')
def parse_type(defn, preprocess=True):
"""
Parse a simple type expression into a SimType
>>> parse_type('int *')
"""
if pycparser is None:
raise ImportError("Please install pycparser in order to parse C definitions"... |
The alignment of the type in bytes.
def alignment(self):
"""
The alignment of the type in bytes.
"""
if self._arch is None:
return NotImplemented
return self.size // self._arch.byte_width |
Handle the switch between the concrete execution and angr.
This method takes care of:
1- Synchronize registers.
2- Set a concrete target to the memory backer so the memory reads are redirected in the concrete process memory.
3- If possible restore the SimProcedures with the real addresse... |
The (L2) distance between the counts of the state addresses in the history of the path.
:param state_a: The first state to compare
:param state_b: The second state to compare
def similarity(state_a, state_b):
"""
The (L2) distance between the counts of the state addresses in the history... |
The `difflib.SequenceMatcher` ratio between the state addresses in the history of the path.
:param state_a: The first state to compare
:param state_b: The second state to compare
def sequence_matcher_similarity(state_a, state_b):
"""
The `difflib.SequenceMatcher` ratio between the state... |
Resolves the method based on the given characteristics (name, class and
params) The method may be defined in one of the superclasses of the given
class (TODO: support interfaces).
:rtype: archinfo.arch_soot.SootMethodDescriptor
def resolve_method(state, method_name, class_name, params=(), ret_type=None,
... |
This is a hack to deal with small values being stored at offsets into large registers unpredictably
def _fix_offset(self, state, size, arch=None):
"""
This is a hack to deal with small values being stored at offsets into large registers unpredictably
"""
if state is not None:
... |
Get an instance of the class that will extract floating-point/integral args correctly.
:param arch: The Archinfo arch for this CC
:param fp_args: A list, with one entry for each argument the function can take. True if the argument is fp,
false if it is integral.
... |
Iterate through all the possible arg positions that can only be used to store integer or pointer values
Does not take into account customizations.
Returns an iterator of SimFunctionArguments
def int_args(self):
"""
Iterate through all the possible arg positions that can only be used to... |
Iterate through all the possible arg positions that can be used to store any kind of argument
Does not take into account customizations.
Returns an iterator of SimFunctionArguments
def both_args(self):
"""
Iterate through all the possible arg positions that can be used to store any kin... |
Iterate through all the possible arg positions that can only be used to store floating point values
Does not take into account customizations.
Returns an iterator of SimFunctionArguments
def fp_args(self):
"""
Iterate through all the possible arg positions that can only be used to stor... |
This should take a SimFunctionArgument instance and return whether or not that argument is a floating-point
argument.
Returns True for MUST be a floating point arg,
False for MUST NOT be a floating point arg,
None for when it can be either.
def is_fp_arg(self, arg):
... |
:param args: A list of SimFunctionArguments
:returns: The number of bytes that should be allocated on the stack to store all these args,
NOT INCLUDING the return address.
def stack_space(self, args):
"""
:param args: A list of SimFunctionArgu... |
Pass this a list of whether each parameter is floating-point or not, and get back a list of
SimFunctionArguments. Optionally, pass a list of argument sizes (in bytes) as well.
If you've customized this CC, this will sanity-check the provided locations with the given list.
def arg_locs(self, is_fp=None... |
Returns a bitvector expression representing the nth argument of a function.
`stack_base` is an optional pointer to the top of the stack at the function start. If it is not
specified, use the current stack pointer.
WARNING: this assumes that none of the arguments are floating-point and they're ... |
`is_fp` should be a list of booleans specifying whether each corresponding argument is floating-point -
True for fp and False for int. For a shorthand to assume that all the parameters are int, pass the number of
parameters as an int.
If you've customized this CC, you may omit this parameter en... |
This function performs the actions of the caller getting ready to jump into a function.
:param state: The SimState to operate on
:param ret_addr: The address to return to when the called function finishes
:param args: The list of arguments that that the called functi... |
This function performs the actions of the callee as it's getting ready to return.
It returns the address to return to.
:param state: The state to mutate
:param return_val: The value to return
:param arg_types: The fp-ness of each of the args.... |
Get the return value out of the given state
def get_return_val(self, state, is_fp=None, size=None, stack_base=None):
"""
Get the return value out of the given state
"""
ty = self.func_ty.returnty if self.func_ty is not None else None
if self.ret_val is not None:
loc ... |
Set the return value into the given state
def set_return_val(self, state, val, is_fp=None, size=None, stack_base=None):
"""
Set the return value into the given state
"""
ty = self.func_ty.returnty if self.func_ty is not None else None
try:
betterval = self._standardi... |
Pinpoint the best-fit calling convention and return the corresponding SimCC instance, or None if no fit is
found.
:param Arch arch: An ArchX instance. Can be obtained from archinfo.
:param list args: A list of arguments.
:param int sp_delta: The change of stack pointer be... |
This is just a simple wrapper that collects the information from various locations
is_fp and sizes are passed to self.arg_locs and self.get_args
:param angr.SimState state: The state to evaluate and extract the values from
:return: A list of tuples, where the nth tuple is (type, name, locatio... |
Add a successor state of the SimRun.
This procedure stores method parameters into state.scratch, does some housekeeping,
and calls out to helper functions to prepare the state and categorize it into the appropriate
successor lists.
:param SimState state: The successor state.
... |
Preprocesses the successor state.
:param state: the successor state
def _preprocess_successor(self, state, add_guard=True): #pylint:disable=unused-argument
"""
Preprocesses the successor state.
:param state: the successor state
"""
# Next, simplify what needs to be si... |
Append state into successor lists.
:param state: a SimState instance
:param target: The target (of the jump/call/ret)
:return: The state
def _categorize_successor(self, state):
"""
Append state into successor lists.
:param state: a SimState instance
:param targ... |
Resolve syscall information from the state, get the IP address of the syscall SimProcedure, and set the IP of
the state accordingly. Don't do anything if the resolution fails.
:param SimState state: the program state.
:return: None
def _fix_syscall_ip(state):
"""
Resolve syscal... |
Finalizes the request.
def _finalize(self):
"""
Finalizes the request.
"""
if len(self.all_successors) == 0:
return
# do some cleanup
if o.DOWNSIZE_Z3 in self.all_successors[0].options:
for s in self.all_successors:
s.downsize()
... |
A *very* fast method to evaluate symbolic jump targets if they are a) concrete targets, or b) targets coming
from jump tables.
:param state: A SimState instance.
:param ip: The AST of the instruction pointer to evaluate.
:param limit: The maximum number of concrete IPs.
... |
The traditional way of evaluating symbolic jump targets.
:param state: A SimState instance.
:param ip: The AST of the instruction pointer to evaluate.
:param limit: The maximum number of concrete IPs.
:return: A list of conditions and the corresponding concrete IPs.
... |
Get a long number for a byte being repeated for many times. This is part of the effort of optimizing
performance of angr's memory operations.
:param int byt: the byte to repeat
:param int rep: times to repeat the byte
:return: a long integer representing the repeating bytes
;rty... |
Make a copy of the MemoryData.
:return: A copy of the MemoryData instance.
:rtype: MemoryData
def copy(self):
"""
Make a copy of the MemoryData.
:return: A copy of the MemoryData instance.
:rtype: MemoryData
"""
s = MemoryData(self.address, self.size, s... |
Stores a memory object.
:param new_mo: the memory object
:param overwrite: whether to overwrite objects already in memory (if false, just fill in the holes)
def store_mo(self, state, new_mo, overwrite=True): #pylint:disable=unused-argument
"""
Stores a memory object.
:param ne... |
Loads a memory object from memory.
:param page_idx: the index into the page
:returns: a tuple of the object
def load_mo(self, state, page_idx):
"""
Loads a memory object from memory.
:param page_idx: the index into the page
:returns: a tuple of the object
"""
... |
Return the memory objects overlapping with the provided slice.
:param start: the start address
:param end: the end address (non-inclusive)
:returns: tuples of (starting_addr, memory_object)
def load_slice(self, state, start, end):
"""
Return the memory objects overlapping with ... |
Loads a memory object from memory.
:param page_idx: the index into the page
:returns: a tuple of the object
def load_mo(self, state, page_idx):
"""
Loads a memory object from memory.
:param page_idx: the index into the page
:returns: a tuple of the object
"""
... |
Return the memory objects overlapping with the provided slice.
:param start: the start address
:param end: the end address (non-inclusive)
:returns: tuples of (starting_addr, memory_object)
def load_slice(self, state, start, end):
"""
Return the memory objects overlapping with ... |
Tests if the address is contained in any page of paged memory, without considering memory backers.
:param int addr: The address to test.
:return: True if the address is included in one of the pages, False otherwise.
:rtype: bool
def contains_no_backer(self, addr):
"""
Tests if ... |
Gets the set of changed bytes between `self` and `other`.
:type other: SimPagedMemory
:returns: A set of differing bytes.
def __changed_bytes(self, other):
"""
Gets the set of changed bytes between `self` and `other`.
:type other: SimPagedMemory
:returns: ... |
Writes a memory object to a `page`
:param page_base: The base address of the page.
:param mo: The memory object.
:param page: (optional) the page to use.
:param overwrite: (optional) If False, only write to currently-empty memory.
def _apply_object_to_page(self, pag... |
This function optimizes a large store by storing a single reference to the :class:`SimMemoryObject` instead of
one for each byte.
:param memory_object: the memory object to store
def store_memory_object(self, mo, overwrite=True):
"""
This function optimizes a large store by storing a s... |
Replaces the memory object `old` with a new memory object containing `new_content`.
:param old: A SimMemoryObject (i.e., one from :func:`memory_objects_for_hash()` or :func:`
memory_objects_for_name()`).
:param new_content: The content (claripy expression) for the ne... |
Replaces all instances of expression `old` with expression `new`.
:param old: A claripy expression. Must contain at least one named variable (to make it possible to use the
name index for speedup).
:param new: The new variable to replace it with.
def replace_all(self, old, new):
... |
Returns addresses that contain expressions that contain a variable named `n`.
def addrs_for_name(self, n):
"""
Returns addresses that contain expressions that contain a variable named `n`.
"""
if n not in self._name_mapping:
return
self._mark_updated_mapping(self._n... |
Returns addresses that contain expressions that contain a variable with the hash of `h`.
def addrs_for_hash(self, h):
"""
Returns addresses that contain expressions that contain a variable with the hash of `h`.
"""
if h not in self._hash_mapping:
return
self._mark_u... |
:param white_list: white list of page number to exclude from the flush
def flush_pages(self, white_list):
"""
:param white_list: white list of page number to exclude from the flush
"""
white_list_page_number = []
for addr in white_list:
for page_addr in range(ad... |
Open a symbolic file. Basically open(2).
:param name: Path of the symbolic file, as a string or bytes.
:type name: string or bytes
:param flags: File operation flags, a bitfield of constants from open(2), as an AST
:param preferred_fd: Assign this fd ... |
Looks up the SimFileDescriptor associated with the given number (an AST).
If the number is concrete and does not map to anything, return None.
If the number is symbolic, constrain it to an open fd and create a new file for it.
def get_fd(self, fd):
"""
Looks up the SimFileDescriptor ass... |
Closes the given file descriptor (an AST).
Returns whether the operation succeeded (a concrete boolean)
def close(self, fd):
"""
Closes the given file descriptor (an AST).
Returns whether the operation succeeded (a concrete boolean)
"""
try:
fd = self.state.s... |
Gets the current sigmask. If it's blank, a new one is created (of sigsetsize).
:param sigsetsize: the size (in *bytes* of the sigmask set)
:return: the sigmask
def sigmask(self, sigsetsize=None):
"""
Gets the current sigmask. If it's blank, a new one is created (of sigsetsize).
... |
Updates the signal mask.
:param how: the "how" argument of sigprocmask (see manpage)
:param new_mask: the mask modification to apply
:param sigsetsize: the size (in *bytes* of the sigmask set)
:param valid_ptr: is set if the new_mask was not NULL
def sigprocmask(self, how, new_mask, si... |
Returns the concrete content for a file by path.
:param path: file path as string
:param kwargs: passed to state.solver.eval
:return: file contents as string
def dump_file_by_path(self, path, **kwargs):
"""
Returns the concrete content for a file by path.
:param path: ... |
Returns the concrete content for a file descriptor.
BACKWARD COMPATIBILITY: if you ask for file descriptors 0 1 or 2, it will return the data from stdin, stdout,
or stderr as a flat string.
:param fd: A file descriptor.
:return: The concrete content.
:rtype: str
def du... |
Handle the concrete execution of the process
This method takes care of:
1- Set the breakpoints on the addresses provided by the user
2- Concretize the symbolic variables and perform the write inside the concrete process
3- Continue the program execution.
:param state: ... |
Check if the concrete target methods return the correct type of data
:return: True if the concrete target is compliant
def check_concrete_target_methods(concrete_target):
"""
Check if the concrete target methods return the correct type of data
:return: True if the concrete target is com... |
:param state: The state with which to execute
:param irsb: The PyVEX IRSB object to use for execution. If not provided one will be lifted.
:param skip_stmts: The number of statements to skip in processing
:param last_stmt: Do not execute any statements after this statement
... |
This function receives an initial state and imark and processes a list of pyvex.IRStmts
It annotates the request with a final state, last imark, and a list of SimIRStmts
def _handle_statement(self, state, successors, stmt):
"""
This function receives an initial state and imark and processes a l... |
Lift an IRSB.
There are many possible valid sets of parameters. You at the very least must pass some
source of data, some source of an architecture, and some source of an address.
Sources of data in order of priority: insn_bytes, clemory, state
Sources of an address, in order of prior... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.