text
stringlengths
81
112k
Enumerate the imarks in the block. If any of them (after the first one) are at a stop point, returns the address of the stop point. None is returned otherwise. def _first_stoppoint(self, irsb, extra_stop_points=None): """ Enumerate the imarks in the block. If any of them (after the first one) a...
Generate a sif file from the call map. :param filepath: Path of the sif file :return: None def _genenare_callmap_sif(self, filepath): """ Generate a sif file from the call map. :param filepath: Path of the sif file :return: None """ ...
Return the function who has the least address that is greater than or equal to `addr`. :param int addr: The address to query. :return: A Function instance, or None if there is no other function after `addr`. :rtype: Function or None def ceiling_func(self, addr): """ ...
Return the function who has the greatest address that is less than or equal to `addr`. :param int addr: The address to query. :return: A Function instance, or None if there is no other function before `addr`. :rtype: Function or None def floor_func(self, addr): """ ...
Get a function object from the function manager. Pass either `addr` or `name` with the appropriate values. :param int addr: Address of the function. :param str name: Name of the function. :param bool create: Whether to create the function or not if the function does not exist. ...
Return a list of nodes that are control dependent on the given node in the control dependence graph def get_dependants(self, run): """ Return a list of nodes that are control dependent on the given node in the control dependence graph """ if run in self._graph.nodes(): retur...
Return a list of nodes on whom the specific node is control dependent in the control dependence graph def get_guardians(self, run): """ Return a list of nodes on whom the specific node is control dependent in the control dependence graph """ if run in self._graph.nodes(): re...
Construct a control dependence graph. This implementation is based on figure 6 of paper An Efficient Method of Computing Static Single Assignment Form by Ron Cytron, etc. def _construct(self): """ Construct a control dependence graph. This implementation is based on figure 6 o...
Pre-process the acyclic CFG. - Change all FakeRet edges to normal edges when necessary (e.g. the normal/expected return edge does not exist) def _pre_process_cfg(self): """ Pre-process the acyclic CFG. - Change all FakeRet edges to normal edges when necessary (e.g. the normal/expected r...
There are cases where a loop has two overlapping loop headers thanks to the way VEX is dealing with continuous instructions. As we were breaking the connection between the second loop header and its successor, we shall restore them in our CDG. def _post_process(self): """ There ...
Take care of those loop headers/tails where we manually broke their connection to the next BBL def _pd_post_process(self, cfg): """ Take care of those loop headers/tails where we manually broke their connection to the next BBL """ loop_back_edges = self._cfg.get_loop_bac...
Create a phi variable for variables at block `block_addr`. :param int block_addr: The address of the current block. :param variables: Variables that the phi variable represents. :return: The created phi variable. def make_phi_node(self, block_addr, *variables): ""...
Get a list of variables. :param str or None sort: Sort of the variable to get. :param collapse_same_ident: Whether variables of the same identifier should be collapsed or not. :return: A list of variables. :rtype: list def get_variables(self, s...
Get sub-variables that phi variable `var` represents. :param SimVariable var: The variable instance. :return: A set of sub-variables, or an empty set if `var` is not a phi variable. :rtype: set def get_phi_subvariables(self, var): """ Get sub-vari...
Get a dict of phi variables and their corresponding variables. :param int block_addr: Address of the block. :return: A dict of phi variables of an empty dict if there are no phi variables at the block. :rtype: dict def get_phi_variables(self, block_addr): ...
Get all variables that have never been written to. :return: A list of variables that are never written to. def input_variables(self, exclude_specials=True): """ Get all variables that have never been written to. :return: A list of variables that are never written to. """ ...
Assign default names to all variables. :return: None def assign_variable_names(self): """ Assign default names to all variables. :return: None """ for var in self._variables: if isinstance(var, SimStackVariable): if var.name is not None: ...
Get a list of all references to the given variable. :param SimVariable variable: The variable. :param bool same_name: Whether to include all variables with the same variable name, or just based on the variable identifier. :retur...
Call this Callable with a string of C-style arguments. :param str c_args: C-style arguments. :return: The return value from the call. :rtype: claripy.Ast def call_c(self, c_args): """ Call this Callable with a string of C-style arguments. :param...
Discard the ancestry of this state. def trim(self): """ Discard the ancestry of this state. """ new_hist = self.copy({}) new_hist.parent = None self.state.register_plugin('history', new_hist)
Filter self.actions based on some common parameters. :param block_addr: Only return actions generated in blocks starting at this address. :param block_stmt: Only return actions generated in the nth statement of each block. :param insn_addr: Only return actions generated in the assembly inst...
Find the common ancestor between this history node and 'other'. :param other: the PathHistory to find a common ancestor with. :return: the common ancestor SimStateHistory, or None if there isn't one def closest_common_ancestor(self, other): """ Find the common ancestor betwee...
Returns the constraints that have been accumulated since `other`. :param other: a prior PathHistory object :returns: a list of constraints def constraints_since(self, other): """ Returns the constraints that have been accumulated since `other`. :param other: a prior PathHistor...
Count occurrences of value v in the entire history. Note that the subclass must implement the __reversed__ method, otherwise an exception will be thrown. :param object v: The value to look for :return: The number of occurrences :rtype: int def count(self, v): """ Count o...
Generate a slice of the graph from the head node to the given frontier. :param networkx.DiGraph graph: The graph to work on. :param node: The starting node in the graph. :param frontier: A list of frontier nodes. :param bool include_frontier: Whether the frontier nodes are included in t...
Translates an integer, set, list or function into a lambda that checks if state's current basic block matches some condition. :param condition: An integer, set, list or lambda to convert to a lambda. :param default: The default return value of the lambda (in case condition is None). Default: false. ...
Determines a persistent ID for an object. Does NOT do stores. def _get_persistent_id(self, o): """ Determines a persistent ID for an object. Does NOT do stores. """ if type(o) in self.hash_dedup: oid = o.__class__.__name__ + "-" + str(hash(o)) sel...
Checks if the provided id is already in the vault. def is_stored(self, i): """ Checks if the provided id is already in the vault. """ if i in self.stored: return True try: with self._read_context(i): return True except (AngrVaultE...
Retrieves one object from the pickler with the provided id. :param id: an ID to use def load(self, id): #pylint:disable=redefined-builtin """ Retrieves one object from the pickler with the provided id. :param id: an ID to use """ l.debug("LOAD: %s", id) try: ...
Stores an object and returns its ID. :param o: the object :param id: an ID to use def store(self, o, id=None): #pylint:disable=redefined-builtin """ Stores an object and returns its ID. :param o: the object :param id: an ID to use """ actual_id = id or ...
Returns a serialized string representing the object, post-deduplication. :param o: the object def dumps(self, o): """ Returns a serialized string representing the object, post-deduplication. :param o: the object """ f = io.BytesIO() VaultPickler(self, f).dump(o...
Deserializes a string representation of the object. :param s: the string def loads(self, s): """ Deserializes a string representation of the object. :param s: the string """ f = io.BytesIO(s) return VaultUnpickler(self, f).load()
:param arch: the architecture :param reg_offset: Tries to find the name of a register given the offset in the registers. :return: The register name def get_reg_name(arch, reg_offset): """ :param arch: the architecture :param reg_offset: Tries to find the name of a register given...
converts an input state into a state with symbolic registers :return: the symbolic state def _make_regs_symbolic(input_state, reg_list, project): """ converts an input state into a state with symbolic registers :return: the symbolic state """ state = input_state.copy() ...
:return: an initial state with a symbolic stack and good options for rop def make_initial_state(project, stack_length): """ :return: an initial state with a symbolic stack and good options for rop """ initial_state = project.factory.blank_state( add_options={options.AVOID_MU...
converts an input state into a state with symbolic registers :return: the symbolic state def make_symbolic_state(project, reg_list, stack_length=80): """ converts an input state into a state with symbolic registers :return: the symbolic state """ input_state = Identifier...
Checks that the specified state options result in the same states over the next `depth` states. def set_state_options(self, left_add_options=None, left_remove_options=None, right_add_options=None, right_remove_options=None): """ Checks that the specified state options result in the same states over the...
Checks that the specified paths stay the same over the next `depth` states. def set_states(self, left_state, right_state): """ Checks that the specified paths stay the same over the next `depth` states. """ simgr = self.project.factory.simulation_manager(right_state) simgr.stas...
Checks that a detected incongruency is not caused by translation backends having a different idea of what constitutes a basic block. def _validate_incongruency(self): """ Checks that a detected incongruency is not caused by translation backends having a different idea of what constitute...
Checks that the paths in the specified path group stay the same over the next `depth` bytes. The path group should have a "left" and a "right" stash, each with a single path. def run(self, depth=None): """ Checks that the paths in the specified path group stay the same over the...
Compares two states for similarity. def compare_states(self, sl, sr): """ Compares two states for similarity. """ joint_solver = claripy.Solver() # make sure the canonicalized constraints are the same n_map, n_counter, n_canon_constraint = claripy.And(*sr.solver.constra...
Checks state `state` to see if the breakpoint should fire. :param state: The state. :param when: Whether the check is happening before or after the event. :return: A boolean representing whether the checkpoint should fire. def check(self, state, when): """ Checks st...
Trigger the breakpoint. :param state: The state. def fire(self, state): """ Trigger the breakpoint. :param state: The state. """ if self.action is None or self.action == BP_IPDB: import ipdb; ipdb.set_trace() #pylint:disable=F0401 elif self.acti...
Called from within SimuVEX when events happens. This function checks all breakpoints registered for that event and fires the ones whose conditions match. def action(self, event_type, when, **kwargs): """ Called from within SimuVEX when events happens. This function checks all breakpoints regist...
Creates and adds a breakpoint which would trigger on `event_type`. Additional arguments are passed to the :class:`BP` constructor. :return: The created breakpoint, so that it can be removed later. def make_breakpoint(self, event_type, *args, **kwargs): """ Creates and adds a breakpo...
Adds a breakpoint which would trigger on `event_type`. :param event_type: The event type to trigger on :param bp: The breakpoint :return: The created breakpoint. def add_breakpoint(self, event_type, bp): """ Adds a breakpoint which would trigger on `event_t...
Removes a breakpoint. :param bp: The breakpoint to remove. :param filter_func: A filter function to specify whether each breakpoint should be removed or not. def remove_breakpoint(self, event_type, bp=None, filter_func=None): """ Removes a breakpoint. :param bp: The breakpoi...
Remove previously stored attributes from this plugin instance to save memory. This method is supposed to be called by breakpoint implementors. A typical workflow looks like the following : >>> # Add `attr0` and `attr1` to `self.state.inspect` >>> self.state.inspect(xxxxxx, attr0=yyyy, attr1=zzz...
Given a state, return the procedure corresponding to the current syscall. This procedure will have .syscall_number, .display_name, and .addr set. :param state: The state to get the syscall number from :param allow_unsupported: Whether to return a "dummy" sycall instead of raisin...
Return whether or not the given address corresponds to a syscall implementation. def is_syscall_addr(self, addr): """ Return whether or not the given address corresponds to a syscall implementation. """ if self.kernel_base is None or addr < self.kernel_base: return False ...
Get a syscall SimProcedure from an address. :param addr: The address to convert to a syscall SimProcedure :param allow_unsupported: Whether to return a dummy procedure for an unsupported syscall instead of raising an exception. :return: The SimProcedure for the...
Get a syscall SimProcedure from its number. :param number: The syscall number :param allow_unsupported: Whether to return a "stub" syscall for unsupported numbers instead of throwing an error :param abi: The name of the abi to use. If None, will assume that the ab...
Convert from a windows memory protection constant to an angr bitmask def convert_prot(prot): """ Convert from a windows memory protection constant to an angr bitmask """ # https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx if prot & 0x10: return 4 if prot & ...
Make a hard copy of `self`. :return: A new LiveDefinition instance. :rtype: angr.analyses.ddg.LiveDefinitions def copy(self): """ Make a hard copy of `self`. :return: A new LiveDefinition instance. :rtype: angr.analyses.ddg.LiveDefinitions """ ld = Liv...
Add a new definition of variable. :param SimVariable variable: The variable being defined. :param CodeLocation location: Location of the varaible being defined. :param int size_threshold: The maximum bytes to consider for the variable. :return: True if the definition was new, False othe...
Add a collection of new definitions of a variable. :param SimVariable variable: The variable being defined. :param iterable locations: A collection of locations where the variable was defined. :param int size_threshold: The maximum bytes to consider for the variable. :return: True if an...
Add a new definition for variable and kill all previous definitions. :param SimVariable variable: The variable to kill. :param CodeLocation location: The location where this variable is defined. :param int size_threshold: The maximum bytes to consider for the variable. :return: None de...
Find all definitions of the varaible :param SimVariable variable: The variable to lookup for. :param int size_threshold: The maximum bytes to consider for the variable. For example, if the variable is 100 byte long, only the first `size_threshold` bytes are considered...
Convert a ProgramVariable instance to a DDGViewItem object. :param ProgramVariable prog_var: The ProgramVariable object to convert. :return: The converted DDGViewItem object. :rtype: DDGViewItem def _to_viewitem(self, prog_var): """ ...
Get all definitions located at the current instruction address. :return: A list of ProgramVariable instances. :rtype: list def definitions(self): """ Get all definitions located at the current instruction address. :return: A list of ProgramVariable instances. :rtype: ...
Pretty printing. def pp(self): """ Pretty printing. """ # TODO: make it prettier for src, dst, data in self.graph.edges(data=True): print("%s <-- %s, %s" % (src, dst, data))
Get a dependency graph for the function `func`. :param func: The Function object in CFG.function_manager. :returns: A networkx.DiGraph instance. def function_dependency_graph(self, func): """ Get a dependency graph for the function `func`. :param func: The Function...
Get a subgraph from the data graph or the simplified data graph that starts from node pv. :param ProgramVariable pv: The starting point of the subgraph. :param bool simplified: When True, the simplified data graph is used, otherwise the data graph is used. :param bool killing_edges: Are killing...
Construct the data dependence graph. We track the following types of dependence: - (Intra-IRSB) temporary variable dependencies - Register dependencies - Memory dependencies, although it's very limited. See below. We track the following types of memory access: - (Intra-...
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: All live definition...
This is a backward lookup in the previous defs. Note that, as we are using VSA, it is possible that `variable` is affected by several definitions. :param angr.analyses.ddg.LiveDefinitions live_defs: The collection of live definitions. :param SimVariable: The variable...
Kill previous defs. addr_list is a list of normalized addresses. def _kill(self, variable, code_loc): # pylint:disable=no-self-use """ 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...
Get the size of a register. :param int reg_offset: Offset of the register. :return: Size in bytes. :rtype: int def _get_register_size(self, reg_offset): """ Get the size of a register. :param int reg_offset: Offset of the register. :return: Size in bytes. ...
For memory actions, get a list of addresses it operates on. :param SimAction action: The action object to work with. :return: A list of addresses that are accessed with that action. :rtype: list def _get_actual_addrs(action, state): """ For memo...
Create a SimStackVariable or SimMemoryVariable based on action objects and its address. :param SimAction action: The action to work with. :param int addr: The address of the memory variable in creation. :param list addrs: A list of all addresses that the action was effective on. ...
Add an edge in the data dependence graph. :param ProgramVariable src: Source node. :param ProgramVariable dst: Destination node. :param edge_labels: All labels associated with the edge. :return: None def _data_graph_add_edge(self, src, dst, **edge_labels): """ Add an ed...
Add an edge in the statement dependence graph from a program location `src` to another program location `dst`. :param CodeLocation src: Source node. :param CodeLocation dst: Destination node. :param edge_labels: All labels associated with the edge. :returns: None def _stmt_graph_add_ed...
Add new annotations to edges in the statement dependence graph. :param list edges_to_annotate: A list of edges to annotate. :param new_labels: New labels to be added to those edges. :returns: None def _stmt_graph_annotate_edges(self, edges_to_annotate, **new_labels): """ ...
Simplify a data graph by removing all temp variable nodes on the graph. :param networkx.DiGraph data_graph: The data dependence graph to simplify. :return: The simplified graph. :rtype: networkx.MultiDiGraph def _simplify_data_graph(self, data_graph): # pylint:disable=no-self-use """ ...
Append a CFGNode and its successors into the work-list, and respect the call-depth limit :param node_wrapper: The NodeWrapper instance to insert. :param worklist: The work-list, which is a list. :param worklist_set: A set of all CFGNodes that are inside the work-list, just for the ...
Build dependency graphs for each function, and save them in self._function_data_dependencies. def _build_function_dependency_graphs(self): """ Build dependency graphs for each function, and save them in self._function_data_dependencies. """ # This is a map between functions and its cor...
If we are not tracing into the function that are called in a real execution, we should properly filter the defs to account for the behavior of the skipped function at this call site. This function is a WIP. See TODOs inside. :param defs: :return: def _filter_defs_at_call_sites(self, d...
Find all definitions of the given variable. :param SimVariable variable: :param bool simplified_graph: True if you just want to search in the simplified graph instead of the normal graph. Usually the simplified graph suffices for finding definitions of register ...
Find all consumers to the specified variable definition. :param ProgramVariable var_def: The variable definition. :param bool simplified_graph: True if we want to search in the simplified graph, False otherwise. :return: A collection of all consumers to the specified variable definition. ...
Find all killers to the specified variable definition. :param ProgramVariable var_def: The variable definition. :param bool simplified_graph: True if we want to search in the simplified graph, False otherwise. :return: A collection of all killers to the specified variable definition. :r...
Find all sources to the specified variable definition. :param ProgramVariable var_def: The variable definition. :param bool simplified_graph: True if we want to search in the simplified graph, False otherwise. :return: A collection of all sources to the specified variable definition. :r...
Allocates a new multi array in memory and returns the reference to the base. def new_array(state, element_type, size, default_value_generator=None): """ Allocates a new multi array in memory and returns the reference to the base. """ size_bounded = SimSootExpr_NewMultiArray._bound_multi...
Gets the minimum solution of an address. def _min(self, memory, addr, **kwargs): """ Gets the minimum solution of an address. """ return memory.state.solver.min(addr, exact=kwargs.pop('exact', self._exact), **kwargs)
Gets the maximum solution of an address. def _max(self, memory, addr, **kwargs): """ Gets the maximum solution of an address. """ return memory.state.solver.max(addr, exact=kwargs.pop('exact', self._exact), **kwargs)
Gets any solution of an address. def _any(self, memory, addr, **kwargs): """ Gets any solution of an address. """ return memory.state.solver.eval(addr, exact=kwargs.pop('exact', self._exact), **kwargs)
Gets n solutions for an address. def _eval(self, memory, addr, n, **kwargs): """ Gets n solutions for an address. """ return memory.state.solver.eval_upto(addr, n, exact=kwargs.pop('exact', self._exact), **kwargs)
Gets the (min, max) range of solutions for an address. def _range(self, memory, addr, **kwargs): """ Gets the (min, max) range of solutions for an address. """ return (self._min(memory, addr, **kwargs), self._max(memory, addr, **kwargs))
Concretizes the address into a list of values. If this strategy cannot handle this address, returns None. def concretize(self, memory, addr): """ Concretizes the address into a list of values. If this strategy cannot handle this address, returns None. """ if self._filter...
Given a local transition graph of a function, find all merge points inside, and then perform a quasi-topological sort of those merge points. A merge point might be one of the following cases: - two or more paths come together, and ends at the same address. - end of the current function ...
Given a local transition graph of a function, find all widening points inside. Correctly choosing widening points is very important in order to not lose too much information during static analysis. We mainly consider merge points that has at least one loop back edges coming in as widening points. ...
Sort a given set of nodes in reverse post ordering. :param networkx.DiGraph graph: A local transition graph of a function. :param iterable nodes: A collection of nodes to sort. :return: A list of sorted nodes. :rtype: list def reverse_post_order_sort_nodes(graph, nodes=None): "...
Sort a given set of nodes from a graph based on the following rules: # - if A -> B and not B -> A, then we have A < B # - if A -> B and B -> A, then the ordering is undefined Following the above rules gives us a quasi-topological sorting of nodes in the graph. It also works for cyclic ...
Append all nodes from a strongly connected component to a list of ordered nodes and ensure the topological order. :param networkx.DiGraph graph: The graph where all nodes belong to. :param list ordered_nodes: Ordered nodes. :param iterable scc: A set of nodes that forms a ...
Mulpyplex across several stashes. :param stashes: the stashes to mulpyplex :return: a mulpyplexed list of states from the stashes in question, in the specified order def mulpyplex(self, *stashes): """ Mulpyplex across several stashes. :param stashes: the stashes to mulpyplex ...
Make a copy of this simulation manager. Pass ``deep=True`` to copy all the states in it as well. def copy(self, deep=False): # pylint: disable=arguments-differ """ Make a copy of this simulation manager. Pass ``deep=True`` to copy all the states in it as well. """ simgr = SimulationMana...
Use an exploration technique with this SimulationManager. Techniques can be found in :mod:`angr.exploration_techniques`. :param tech: An ExplorationTechnique object that contains code to modify this SimulationManager's behavior. :type tech: ExplorationTechnique ...
Remove an exploration technique from a list of active techniques. :param tech: An ExplorationTechnique object. :type tech: ExplorationTechnique def remove_technique(self, tech): """ Remove an exploration technique from a list of active techniques. :param tech: An Exp...
Tick stash "stash" forward (up to "n" times or until "num_find" states are found), looking for condition "find", avoiding condition "avoid". Stores found states into "find_stash' and avoided states into "avoid_stash". The "find" and "avoid" parameters may be any of: - An address to find ...
Run until the SimulationManager has reached a completed state, according to the current exploration techniques. If no exploration techniques that define a completion state are being used, run until there is nothing left to run. :param stash: Operate on this stash :param n: ...
Returns whether or not this manager has reached a "completed" state. def complete(self): """ Returns whether or not this manager has reached a "completed" state. """ if not self._techniques: return False if not any(tech._is_overriden('complete') for tech in self._tec...