text
stringlengths
81
112k
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 %...
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__, ...
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._...
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__, ...
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__, ...
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__, ...
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__, ...
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 lis...
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__, ...
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 ...
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__, se...
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__, ...
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__, ...
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 t...
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...
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 ...
When an IRSB has more than two exits (for example, a jumptable), we cannot concretize their exits in concrete mode. Hence we statically execute the function from beginning in this method, and then switch to symbolic mode for the final IRSB to get all possible exits of that IRSB. def _sy...
Scan the entire program space for prologues, and start code scanning at those positions :param traced_address: :param function_exits: :param initial_state: :param next_addr: :returns: def _scan_function_prologues(self, traced_address, function_exits, initial_state): """ ...
Execute each basic block with an indeterminiable exit target :returns: def _process_indirect_jumps(self): """ Execute each basic block with an indeterminiable exit target :returns: """ function_starts = set() l.info("We have %d indirect jumps", len(self._indirec...
Voting for the most possible base address. :param function_starts: :param functions: :returns: def _solve_forbase_address(self, function_starts, functions): """ Voting for the most possible base address. :param function_starts: :param functions: :return...
The basic idea is simple: start from a specific point, try to construct functions as much as we can, and maintain a function distribution graph and a call graph simultaneously. Repeat searching until we come to the end that there is no new function to be found. A function should start wi...
Perform a full code scan on the target binary. def _full_code_scan(self): """ Perform a full code scan on the target binary. """ # We gotta time this function start_time = datetime.now() traced_address = set() self.functions = set() self.call_map = netw...
Generate a sif file from the call map def genenare_callmap_sif(self, filepath): """ Generate a sif file from the call map """ graph = self.call_map if graph is None: raise AngrGirlScoutError('Please generate the call graph first.') f = open(filepath, "wb") ...
Generate a list of all recovered basic blocks. def generate_code_cover(self): """ Generate a list of all recovered basic blocks. """ lst = [ ] for irsb_addr in self.cfg.nodes(): if irsb_addr not in self._block_size: continue irsb_size = s...
Reloads the solver. Useful when changing solver options. :param list constraints: A new list of constraints to use in the reloaded solver instead of the current one def reload_solver(self, constraints=None): """ Reloads the solver. Useful when changing solver options. :param list c...
Iterate over all variables for which their tracking key is a prefix of the values provided. Elements are a tuple, the first element is the full tracking key, the second is the symbol. >>> list(s.solver.get_variables('mem')) [(('mem', 0x1000), <BV64 mem_1000_4_64>), (('mem', 0x1008), <BV64 mem_...
Register a value with the variable tracking system :param v: The BVS to register :param key: A tuple to register the variable under :parma eternal: Whether this is an eternal variable, default True. If False, an incrementing counter will be appended to the key....
Given an AST, iterate over all the keys of all the BVS leaves in the tree which are registered. def describe_variables(self, v): """ Given an AST, iterate over all the keys of all the BVS leaves in the tree which are registered. """ reverse_mapping = {next(iter(var.variables)): k for k,...
Creates or gets a Claripy solver, based on the state options. def _solver(self): """ Creates or gets a Claripy solver, based on the state options. """ if self._stored_solver is not None: return self._stored_solver track = o.CONSTRAINT_TRACKING_IN_SOLVER in self.stat...
Creates an unconstrained symbol or a default concrete value (0), based on the state options. :param name: The name of the symbol. :param bits: The size (in bits) of the symbol. :param uninitialized: Whether this value should be counted as an "uninitialized" value in the ...
Creates a bit-vector symbol (i.e., a variable). Other keyword parameters are passed directly on to the constructor of claripy.ast.BV. :param name: The name of the symbol. :param size: The size (in bits) of the bit-vector. :param min: The minimum value o...
Evaluate an expression, using the solver if necessary. Returns AST objects. :param e: the expression :param n: the number of desired solutions :param extra_constraints: extra constraints to apply to the solver :param exact: if False, returns approximate solutions :return: a tupl...
Evaluate an expression, using the solver if necessary. Returns primitives. :param e: the expression :param n: the number of desired solutions :param extra_constraints: extra constraints to apply to the solver :param exact: if False, returns approximate solutions :return: a tuple...
Return the maximum value of expression `e`. :param e : expression (an AST) to evaluate :param extra_constraints: extra constraints (as ASTs) to add to the solver for this solve :param exact : if False, return approximate solutions. :return: the maximum possible...
Return True if `v` is a solution of `expr` with the extra constraints, False otherwise. :param e: An expression (an AST) to evaluate :param v: The proposed solution (an AST) :param extra_constraints: Extra constraints (as ASTs) to add to the solver for this...
This function returns the unsat core from the backend solver. :param extra_constraints: Extra constraints (as ASTs) to add to the solver for this solve. :return: The unsat core. def unsat_core(self, extra_constraints=()): """ This function returns the unsat core from the backend solv...
This function does a constraint check and checks if the solver is in a sat state. :param extra_constraints: Extra constraints (as ASTs) to add to s for this solve :param exact: If False, return approximate solutions. :return: True if sat, otherwise false def...
Add some constraints to the solver. :param constraints: Pass any constraints that you want to add (ASTs) as varargs. def add(self, *constraints): """ Add some constraints to the solver. :param constraints: Pass any constraints that you want to add (ASTs) as varargs. ""...
Casts a solution for the given expression to type `cast_to`. :param e: The expression `value` is a solution for :param value: The solution to be cast :param cast_to: The type `value` should be cast to. Must be one of the currently supported types (bytes|int) :raise ValueError: If cast_t...
Evaluate an expression, using the solver if necessary. Returns primitives as specified by the `cast_to` parameter. Only certain primitives are supported, check the implementation of `_cast_to` to see which ones. :param e: the expression :param n: the number of desired solutions :param e...
Evaluate an expression to get the only possible solution. Errors if either no or more than one solution is returned. A kwarg parameter `default` can be specified to be returned instead of failure! :param e: the expression to get a solution for :param default: A value can be passed as a kwarg he...
Evaluate an expression to get at most `n` possible solutions. Errors if either none or more than `n` solutions are returned. :param e: the expression to get a solution for :param n: the inclusive upper limit on the number of solutions :param kwargs: Any additional kwargs will be passed ...
Returns True if the expression `e` has only one solution by querying the constraint solver. It does also add that unique solution to the solver's constraints. def unique(self, e, **kwargs): """ Returns True if the expression `e` has only one solution by querying the constraint s...
Returns True if the expression `e` is symbolic. def symbolic(self, e): # pylint:disable=R0201 """ Returns True if the expression `e` is symbolic. """ if type(e) in (int, bytes, float, bool): return False return e.symbolic
Returns True whether `e` is a concrete value or is a value set with only 1 possible value. This differs from `unique` in that this *does* not query the constraint solver. def single_valued(self, e): """ Returns True whether `e` is a concrete value or is a value set with only 1 p...
Simplifies `e`. If `e` is None, simplifies the constraints of this state. def simplify(self, e=None): """ Simplifies `e`. If `e` is None, simplifies the constraints of this state. """ if e is None: return self._solver.simplify() elif isinstance(e, (in...
Add a preconstraint that ``variable == value`` to the state. :param value: The concrete value. Can be a bitvector or a bytestring or an integer. :param variable: The BVS to preconstrain. def preconstrain(self, value, variable): """ Add a preconstraint that ``variable == value`...
Preconstrain the contents of a file. :param content: The content to preconstrain the file to. Can be a bytestring or a list thereof. :param simfile: The actual simfile to preconstrain def preconstrain_file(self, content, simfile, set_length=False): """ Preconstrain the contents...
Preconstrain the data in the flag page. :param magic_content: The content of the magic page as a bytestring. def preconstrain_flag_page(self, magic_content): """ Preconstrain the data in the flag page. :param magic_content: The content of the magic page as a bytestring. ""...
Remove the preconstraints from the state. If you are using the zen plugin, this will also use that to filter the constraints. :param to_composite_solver: Whether to convert the replacement solver to a composite solver. You probably want this if you're switch...
Split the solver. If any of the subsolvers time out after a short timeout (10 seconds), re-add the preconstraints associated with each of its variables. Hopefully these constraints still allow us to do meaningful things to the state. def reconstrain(self): """ Split the solver. If any o...
Add a reference to a memory data object. :param CodeReference ref: The reference. :return: None def add_ref(self, ref): """ Add a reference to a memory data object. :param CodeReference ref: The reference. :return: None ...
Get an arbitrary CFGNode (without considering their contexts) from our graph. :param int addr: Address of the beginning of the basic block. Set anyaddr to True to support arbitrary address. :param bool is_syscall: Whether you want to get the syscall node or any ot...
Get all CFGNodes whose address is the specified one. :param addr: Address of the node :param is_syscall: True returns the syscall node, False returns the normal CFGNode, None returns both :return: all CFGNodes def get_all_nodes(self, addr, is_syscall=None, anyaddr=False): ...
Get predecessors of a node in the control flow graph. :param CFGNode cfgnode: The node. :param bool excluding_fakeret: True if you want to exclude all predecessors that is connected to the node with a fakeret edge. :param str or None ...
Get successors of a node in the control flow graph. :param CFGNode node: The node. :param bool excluding_fakeret: True if you want to exclude all successors that is connected to the node with a fakeret edge. :param str or None jump...
Get a list of tuples where the first element is the successor of the CFG node and the second element is the jumpkind of the successor. :param CFGNode node: The node. :param bool excluding_fakeret: True if you want to exclude all successors that are fall-through successors. :...
Get all predecessors of a specific node on the control flow graph. :param CFGNode cfgnode: The CFGNode object :return: A list of predecessors in the CFG :rtype: list def get_all_predecessors(self, cfgnode): """ Get all predecessors of a specific node on the control flow graph. ...
Returns all nodes that has an out degree >= 2 def get_branching_nodes(self): """ Returns all nodes that has an out degree >= 2 """ nodes = set() for n in self.graph.nodes(): if self.graph.out_degree(n) >= 2: nodes.add(n) return nodes
Get the corresponding exit statement ID for control flow to reach destination block from source block. The exit statement ID was put on the edge when creating the CFG. Note that there must be a direct edge between the two blocks, otherwise an exception will be raised. :return: The exit statemen...
Hook target for native function call returns. Recovers and stores the return value from native memory and toggles the state, s.t. execution continues in the Soot engine. def prepare_native_return_state(native_state): """ Hook target for native function call returns. Recovers a...
Return a concretization of the contents of the file, as a flat bytestring. def concretize(self, **kwargs): """ Return a concretization of the contents of the file, as a flat bytestring. """ size = self.state.solver.min(self._size, **kwargs) data = self.load(0, size) kwa...
Returns a list of the packets read or written as bytestrings. def concretize(self, **kwargs): """ Returns a list of the packets read or written as bytestrings. """ lengths = [self.state.solver.eval(x[1], **kwargs) for x in self.content] kwargs['cast_to'] = bytes return [...
Read a packet from the stream. :param int pos: The packet number to read from the sequence of the stream. May be None to append to the stream. :param size: The size to read. May be symbolic. :param short_reads: Whether to replace the size with a symbolic value constrained to less tha...
Write a packet to the stream. :param int pos: The packet number to write in the sequence of the stream. May be None to append to the stream. :param data: The data to write, as a string or bitvector. :param size: The optional size to write. May be symbolic; must be constrained ...
Reads some data from the file, storing it into memory. :param pos: The address to write the read data into memory :param size: The requested length of the read :return: The real length of the read def read(self, pos, size, **kwargs): """ Reads some data from the f...
Writes some data, loaded from the state, into the file. :param pos: The address to read the data to write from in memory :param size: The requested size of the write :return: The real length of the write def write(self, pos, size, **kwargs): """ Writes some data, ...
Return a concretization of the underlying files, as a tuple of (read file, write file). def concretize(self, **kwargs): """ Return a concretization of the underlying files, as a tuple of (read file, write file). """ return (self._read_file.concretize(**kwargs), self._write_file.concreti...
Find a sinkhole which is large enough to support `length` bytes. This uses first-fit. The first sinkhole (ordered in descending order by their address) which can hold `length` bytes is chosen. If there are more than `length` bytes in the sinkhole, a new sinkhole is created representing the rema...
A decorator function you should apply to ``copy`` def memo(f): """ A decorator function you should apply to ``copy`` """ def inner(self, memo=None, **kwargs): if memo is None: memo = {} if id(self) in memo: return memo[id(self)] ...
Appended a new state to this VFGNode. :param s: The new state to append :param is_widened_state: Whether it is a widened state or not. def append_state(self, s, is_widened_state=False): """ Appended a new state to this VFGNode. :param s: The new state to append :param is...
Get the first FunctionAnalysis task in the stack. :return: The top function analysis task in the stack, or None if there isn't any. :rtype: FunctionAnalysis def _top_function_analysis_task(self): """ Get the first FunctionAnalysis task in the stack. :return: The top function a...
Get any VFG node corresponding to the basic block at @addr. Note that depending on the context sensitivity level, there might be multiple nodes corresponding to different contexts. This function will return the first one it encounters, which might not be what you want. def get_any_node(self, ad...
Executed before analysis starts. Necessary initializations are performed here. :return: None def _pre_analysis(self): """ Executed before analysis starts. Necessary initializations are performed here. :return: None """ l.debug("Starting from %#x", self._start) ...
Get the sorting key of a VFGJob instance. :param VFGJob job: the VFGJob object. :return: An integer that determines the order of this job in the queue. :rtype: int def _job_sorting_key(self, job): """ Get the sorting key of a VFGJob instance. :param VFGJob job: the VFG...
Some code executed before actually processing the job. :param VFGJob job: the VFGJob object. :return: None def _pre_job_handling(self, job): """ Some code executed before actually processing the job. :param VFGJob job: the VFGJob object. :return: None """ ...
Process each successor generated by the job, and return a new list of succeeding jobs. :param VFGJob job: The VFGJob instance. :param SimState successor: The succeeding state. :param list all_successors: A list of all successors. :return: A list of newly created jobs from the successor...
Generate new jobs for all possible successor targets when there are more than one possible concrete value for successor.ip :param VFGJob job: The VFGJob instance. :param SimState successor: The succeeding state. :param list all_successors: All succeeding states from the same VFGJob. ...
Merge two given states, and return a new one. :param old_state: :param new_state: :returns: The merged state, and whether a merging has occurred def _merge_states(self, old_state, new_state): """ Merge two given states, and return a new one. :param old_state: :...
Perform widen operation on the given states, and return a new one. :param old_state: :param new_state: :returns: The widened state, and whether widening has occurred def _widen_states(old_state, new_state): """ Perform widen operation on the given states, and return a new one. ...
Try to narrow the state! :param old_state: :param new_state: :param previously_widened_state: :returns: The narrowed state, and whether a narrowing has occurred def _narrow_states(node, old_state, new_state, previously_widened_state): # pylint:disable=unused-argument,no-self-use ...
Get the state to start the analysis for function. :param int function_start: Address of the function :param SimState state: The program state to base on. def _prepare_initial_state(self, function_start, state): """ Get the state to start the analysis for function. :param int f...
Set the return address of the current state to a specific address. We assume we are at the beginning of a function, or in other words, we are about to execute the very first instruction of the function. :param SimState state: The program state :param int ret_addr: The return address :re...
Create a DiGraph out of the existing edge map. :param return_target_sources: Used for making up those missing returns :returns: A networkx.DiGraph() object def _create_graph(self, return_target_sources=None): """ Create a DiGraph out of the existing edge map. :param return_targe...
Get an existing VFGNode instance from the graph. :param BlockID block_id: The block ID for the node to get. :param bool terminator_for_nonexistent_node: True if a Terminator (which is a SimProcedure stub) should be created when th...
Add an edge onto the graph. :param BlockID src_block_id: The block ID for source node. :param BlockID dst_block_id: The block Id for destination node. :param str jumpkind: The jumpkind of the edge. :param exit_stmt_idx: ID of the statement in the source IRSB where this ed...
Create a list of new VFG jobs for the successor state. :param VFGJob job: The VFGJob instance. :param SimState successor: The succeeding state. :param BlockID new_block_id: Block ID for the new VFGJob :param new_call_stack: The new callstack. :r...
Remove all pending returns that are related to the current job. def _remove_pending_return(self, job, pending_returns): """ Remove all pending returns that are related to the current job. """ # Build the tuples that we want to remove from the dict fake_func_retn_exits tpls_to_r...
Print out debugging information after handling a VFGJob and generating the succeeding jobs. :param VFGJob job: The VFGJob instance. :param list successors: A list of succeeding states. :return: None def _post_job_handling_debug(self, job, successors): """ Print out debugging in...
Save the initial state of a function, and merge it with existing ones if there are any. :param FunctionKey function_key: The key to this function. :param int function_address: Address of the function. :param SimState state: Initial state of the function. :return: None def _save_functio...
Save the final state of a function, and merge it with existing ones if there are any. :param FunctionKey function_key: The key to this function. :param int function_address: Address of the function. :param SimState state: Initial state of the function. :return: None def _save_function_...
Get the possible (networkx) simple paths between two nodes or addresses corresponding to nodes. Input: addresses or node instances Return: a list of lists of nodes representing paths. def _get_nx_paths(self, begin, end): """ Get the possible (networkx) simple paths between two n...
Return the ordered merge points for a specific function. :param int function_address: Address of the querying function. :return: A list of sorted merge points (addresses). :rtype: list def _merge_points(self, function_address): """ Return the ordered merge points for a specific...
Return the ordered widening points for a specific function. :param int function_address: Address of the querying function. :return: A list of sorted merge points (addresses). :rtype: list def _widening_points(self, function_address): """ Return the ordered widening points for a...
For a given function, return all nodes in an optimal traversal order. If the function does not exist, return an empty list. :param int function_address: Address of the function. :return: A ordered list of the nodes. :rtype: list def _ordered_node_addrs(self, function_address): ...
Assign a new region for under-constrained symbolic execution. :param dst_addr_ast: the symbolic AST which address of the new allocated region will be assigned to. :return: as ast of memory address that points to a new region def assign(self, dst_addr_ast): """ Assign a new region for u...
Test whether an AST is bounded by any existing constraint in the related solver. :param ast: an claripy.AST object :return: True if there is at least one related constraint, False otherwise def is_bounded(self, ast): """ Test whether an AST is bounded by any existing constraint in the ...
Resolves the indirect jump in MIPS ELF binaries where all external function calls are indexed using gp. :param cfg: A CFG instance. :param int addr: IRSB address. :param int func_addr: The function address. :param pyvex.IRSB block: The IRSB. :param str jumpkind: The jumpkind. ...
Perform execution with a state. :param state: The state with which to execute :param procedure: An instance of a SimProcedure to run, optional :param ret_to: The address to return to when this procedure is finished :param inline: This is an inline execution. Do not bot...
[COMPATIBILITY] Make a copy of the current instance, and then discard all options that are in boolean_switches. :param set boolean_switches: A collection of Boolean switches to disable. :return: A new SimStateOptions instance. def difference(self, boolean_switches): ...