text
stringlengths
81
112k
Step a stash of states forward and categorize the successors appropriately. The parameters to this function allow you to control everything about the stepping and categorization process. :param stash: The name of the stash to step (default: 'active') :param selector_func: I...
Don't use this function manually - it is meant to interface with exploration techniques. def step_state(self, state, successor_func=None, **run_args): """ Don't use this function manually - it is meant to interface with exploration techniques. """ try: successors = self.succ...
Don't use this function manually - it is meant to interface with exploration techniques. def successors(self, state, successor_func=None, **run_args): """ Don't use this function manually - it is meant to interface with exploration techniques. """ if successor_func is not None: ...
Prune unsatisfiable states from a stash. This function will move all unsatisfiable states in the given stash into a different stash. :param filter_func: Only prune states that match this filter. :param from_stash: Prune states from this stash. (default: 'active') :param to_stash: P...
Move states from one stash to another. :param from_stash: Take matching states from this stash. :param to_stash: Put matching states into this stash. :param filter_func: Stash states that match this filter. Should be a function that takes a state and returns True...
Stash some states. This is an alias for move(), with defaults for the stashes. :param filter_func: Stash states that match this filter. Should be a function that takes a state and returns True or False. (default: stash all states) :param from_stash: Take matching states fro...
Unstash some states. This is an alias for move(), with defaults for the stashes. :param filter_func: Unstash states that match this filter. Should be a function that takes a state and returns True or False. (default: unstash all states) :param from_stash: take matching stat...
Drops states from a stash. This is an alias for move(), with defaults for the stashes. :param filter_func: Drop states that match this filter. Should be a function that takes a state and returns True or False. (default: drop all states) :param stash: Drop matching stat...
Applies a given function to a given stash. :param state_func: A function to apply to every state. Should take a state and return a state. The returned state will take the place of the old state. If the function *doesn't* return a state, the old state wil...
Split a stash of states into two stashes depending on the specified options. The stash from_stash will be split into two stashes depending on the other options passed in. If to_stash is provided, the second stash will be written there. stash_splitter overrides stash_ranker, which in turn overr...
Merge the states in a given stash. :param stash: The stash (default: 'active') :param merge_func: If provided, instead of using state.merge, call this function with the states as the argument. Should return the merged state. :param merge_key: If provided, sh...
Merges a list of states. :param states: the states to merge :returns SimState: the resulting state def _merge_states(self, states): """ Merges a list of states. :param states: the states to merge :returns SimState: the resulting state """ i...
Launch a postmortem debug shell at the site of the error. def debug(self): """ Launch a postmortem debug shell at the site of the error. """ try: __import__('ipdb').post_mortem(self.traceback) except ImportError: __import__('pdb').post_mortem(self.traceba...
Calculate the complement of `self` and `other`. :param other: Another SimVariableSet instance. :return: The complement result. def complement(self, other): """ Calculate the complement of `self` and `other`. :param other: Another SimVariableSet instance. :re...
Get the CFGNode object on the control flow graph given an angr state. :param angr.analyses.CFGEmulated cfg: An instance of CFGEmulated. :param angr.SimState state: The current state. :return: A CFGNode instance if the node exists, or None if the node cannot be found. :rtyp...
Perform a depth-first search on the given DiGraph, with a limit on maximum steps. :param networkx.DiGraph graph: The graph to traverse. :param Any source: The source to begin traversal. :param int max_steps: Maximum steps of the traversal, or None if not limiting steps. ...
Check if the specified address will be executed :param cfg: :param state: :param int peek_blocks: :return: :rtype: bool def check(self, cfg, state, peek_blocks): """ Check if the specified address will be executed :param cfg: :param state: ...
Check if the specified function will be reached with certain arguments. :param cfg: :param state: :param peek_blocks: :return: def check(self, cfg, state, peek_blocks): """ Check if the specified function will be reached with certain arguments. :param cfg: ...
Check if the specific function is reached with certain arguments :param angr.SimState state: The state to check :return: True if the function is reached with certain arguments, False otherwise. :rtype: bool def check_state(self, state): """ Check if the specific function is rea...
Make sure all current basic block on each state shows up in the CFG. For blocks that are not in the CFG, start CFG recovery from them with a maximum basic block depth of 100. :param simgr: :return: def _peek_forward(self, simgr): """ Make sure all current basic block on each st...
Load the last N deprioritized states will be extracted from the "deprioritized" stash and put to "active" stash. N is controlled by 'num_fallback_states'. :param SimulationManager pg: The simulation manager. :return: None def _load_fallback_states(self, pg): """ Load the last N...
Categorize all states into two different groups: reaching the destination within the peek depth, and not reaching the destination within the peek depth. :param SimulationManager simgr: The simulation manager that contains states. All active states (state belonging to "active" stash) ...
Detects if there is any xor operation in the function. :return: Tags def has_xor(self): """ Detects if there is any xor operation in the function. :return: Tags """ def _has_xor(expr): return isinstance(expr, pyvex.IRExpr.Binop) and expr.op.startswith("Iop...
Detects if there is any bitwise operation in the function. :return: Tags. def has_bitshifts(self): """ Detects if there is any bitwise operation in the function. :return: Tags. """ def _has_bitshifts(expr): if isinstance(expr, pyvex.IRExpr.Binop): ...
Merge another KeyedRegion into this KeyedRegion. :param KeyedRegion other: The other instance to merge with. :return: None def merge(self, other, replacements=None): """ Merge another KeyedRegion into this KeyedRegion. :param KeyedRegion other: The other instance to merge with...
Replace variables with other variables. :param dict replacements: A dict of variable replacements. :return: self def replace(self, replacements): """ Replace variables with other variables. :param dict replacements: A dict of variable replacements. ...
Get a debugging representation of this keyed region. :return: A string of debugging output. def dbg_repr(self): """ Get a debugging representation of this keyed region. :return: A string of debugging output. """ keys = self._storage.keys() offset_to_vars = { } ...
Add a variable to this region at the given offset. :param int start: :param SimVariable variable: :return: None def add_variable(self, start, variable): """ Add a variable to this region at the given offset. :param int start: :param SimVariable variable: ...
Add/Store an object to this region at the given offset. :param start: :param obj: :param int object_size: Size of the object :return: def add_object(self, start, obj, object_size): """ Add/Store an object to this region at the given offset. :param start: ...
Add a variable to this region at the given offset, and remove all other variables that are fully covered by this variable. :param int start: :param SimVariable variable: :return: None def set_variable(self, start, variable): """ Add a variable to this region at the give...
Add an object to this region at the given offset, and remove all other objects that are fully covered by this object. :param start: :param obj: :param object_size: :return: def set_object(self, start, obj, object_size): """ Add an object to this region at the gi...
Get the base offset (the key we are using to index objects covering the given offset) of a specific offset. :param int addr: :return: :rtype: int or None def get_base_addr(self, addr): """ Get the base offset (the key we are using to index objects covering the given offset) of...
Find variables covering the given region offset. :param int start: :return: A list of stack variables. :rtype: set def get_variables_by_offset(self, start): """ Find variables covering the given region offset. :param int start: :return: A list of stack variabl...
Find objects covering the given region offset. :param start: :return: def get_objects_by_offset(self, start): """ Find objects covering the given region offset. :param start: :return: """ _, container = self._get_container(start) if container i...
Store a variable into the storage. :param int start: The beginning address of the variable. :param obj: The object to store. :param int size: Size of the object to store. :param bool overwrite: Whether existing objects should be overwritten or not. :return: None def _store(self...
Store a variable into the storage. :param StoredObject stored_object: The descriptor describing start address and the variable. :param bool overwrite: Whether existing objects should be overwritten or not. True to make a strong update, False to make a weak update. ...
Initialize the progressbar. :return: None def _initialize_progressbar(self): """ Initialize the progressbar. :return: None """ self._progressbar = progressbar.ProgressBar(widgets=Analysis._PROGRESS_WIDGETS, maxval=10000 * 100).start()
Update the progress with a percentage, including updating the progressbar as well as calling the progress callback. :param float percentage: Percentage of the progressbar. from 0.0 to 100.0. :param kwargs: Other parameters that will be passed to the progress_callback handler. ...
Mark the progressbar as finished. :return: None def _finish_progress(self): """ Mark the progressbar as finished. :return: None """ if self._show_progressbar: if self._progressbar is None: self._initialize_progressbar() if self._p...
Merge two abstract states. :param VariableRecoveryState other: The other abstract state to merge. :return: The merged abstract state. :rtype: VariableRecoveryState def merge(self, other, successor=None): """ Merge two abstr...
Convert an address to a stack offset. :param claripy.ast.Base addr: The address to convert from. :return: A stack offset if the addr comes from the stack pointer, or None if the address does not come from the stack pointer. def _addr_to_sta...
Take an input abstract state, execute the node, and derive an output state. :param angr.Block node: The node to work on. :param VariableRecoveryState state: The input state. :return: A tuple of (changed, new output state). :rtype: ...
Re-create the DiGraph def _initialize_cfg(self): """ Re-create the DiGraph """ self.kb.functions = FunctionManager(self.kb) self._jobs_to_analyze_per_function = defaultdict(set) self._completed_functions = set()
Copy self attributes to the new object. :param CFGBase copy_to: The target to copy to. :return: None def make_copy(self, copy_to): """ Copy self attributes to the new object. :param CFGBase copy_to: The target to copy to. :return: None """ for attr, va...
Merge two adjacent CFGNodes into one. :param CFGNode cfgnode_0: The first CFGNode. :param CFGNode cfgnode_1: The second CFGNode. :return: None def _merge_cfgnodes(self, cfgnode_0, cfgnode_1): """ Merge two adjacent CFGNodes into one. :param CFGNo...
Convert a CFGNode instance to a CodeNode object. :param angr.analyses.CFGNode cfg_node: The CFGNode instance. :param int addr: Address of the node. Only used when `cfg_node` is None. :param bool thumb: Whether this is in THUMB mode or not. Only used for ARM code and when `cfg_node` is None. ...
Filter successors for THUMB mode basic blocks, and remove those successors that won't be taken normally. :param int addr: Address of the basic block / SimIRSB. :param int size: Size of the basic block. :param list successors: A list of successors. :param func get_ins_addr: A callable th...
Check whether the given memory region is extremely sparse, i.e., all bytes are the same value. :param int start: The beginning of the region. :param int end: The end of the region. :param base_state: The base state (optional). :return: True if the region is extremely sparse,...
Some regions usually do not contain any executable code, but are still marked as executable. We should skip those regions by default. :param int region_start: Address of the beginning of the region. :return: True/False :rtype: bool def _should_skip_regi...
Get all executable memory regions from the binaries :param objects: A collection of binary objects to collect regions from. If None, regions from all project binary objects are used. :param bool force_segment: Rely on binary segments instead of sections. :return: A sorte...
Test if the address belongs to an executable memory region. :param int addr: The address to test :return: True if the address belongs to an exectubale memory region, False otherwise :rtype: bool def _addr_in_exec_memory_regions(self, addr): """ Test if the address belongs to an...
Test if two addresses belong to the same section. :param int addr_a: The first address to test. :param int addr_b: The second address to test. :return: True if the two addresses belong to the same section or both of them do not belong to any section, Fal...
Check whether the address belongs to a hook or a syscall. :param int addr: The address to check. :return: True if the address is hooked or belongs to a syscall. False otherwise. :rtype: bool def _addr_hooked_or_syscall(self, addr): """ Check whether th...
Perform a fast memory loading of some data. :param int addr: Address to read from. :param int length: Size of the string to load. :return: A string or None if the address does not exist. :rtype: bytes or None def _fast_memory_load_bytes(self, addr, length): """...
Perform a fast memory loading of a pointer. :param int addr: Address to read from. :param int size: Size of the pointer. Default to machine-word size. :return: A pointer or None if the address does not exist. :rtype: int def _fast_memory_load_pointer(self, addr, size=N...
Determine if a function returns or not. A function does not return if a) it is a SimProcedure that has NO_RET being True, or b) it is completely recovered (i.e. every block of this function has been recovered, and no future block will be added to it), and it does not have a r...
For each function in the function_manager, try to determine if it returns or not. A function does not return if it calls another function that is known to be not returning, and this function does not have other exits. We might as well analyze other features of functions in the future. :param b...
Iteratively analyze function features until a fixed point is reached. :return: the "changes" dict :rtype: dict def _iteratively_analyze_function_features(self, all_funcs_completed=False): """ Iteratively analyze function features until a fixed point is reached. :return: the "...
Normalize the CFG, making sure that there are no overlapping basic blocks. Note that this method will not alter transition graphs of each function in self.kb.functions. You may call normalize() on each Function object to normalize their transition graphs. :return: None def normalize(self): ...
Obtain all functions of which we have finished analyzing. As _jobs_to_analyze_per_function is a defaultdict(), if a function address shows up in it with an empty job list, we consider we have exhausted all jobs of this function (both current jobs and pending jobs), thus the analysis of this function is ...
From job manager, remove all functions of which we have finished analysis. :param list or None finished_func_addrs: A list of addresses of functions of which we have finished analysis. A new list of function addresses will be obtained by calling ...
Fill in self._completed_functions list and clean up job manager. :return: None def _make_completed_functions(self): """ Fill in self._completed_functions list and clean up job manager. :return: None """ finished = self._get_finished_functions() for func_addr i...
Remove all function alignments. :return: None def remove_function_alignments(self): """ Remove all function alignments. :return: None """ # This function requires Capstone engine support if not self.project.arch.capstone_support: return fo...
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...
For unresolveable indirect jumps, angr marks those jump targets as individual functions. For example, usually the following pattern is seen: sub_0x400010: push ebp mov esp, ebp ... cmp eax, 10 ja end mov eax, jumptable[eax] ...
Functions that are identified via function prologues can be starting after the actual beginning of the function. For example, the following function (with an incorrect start) might exist after a CFG recovery: sub_8049f70: push esi sub_8049f71: sub esp, 0A8h ...
Convert an address to a Function object, and store the mapping in a dict. If the block is known to be part of a function, just return that function. :param int addr: Address to convert :param dict blockaddr_to_function: A mapping between block addresses to Function instances. :param ang...
If source and destination belong to the same function, and the following criteria apply: - source node has only one default exit - destination is not one of the known functions - destination does not belong to another function, or destination belongs to the same function that source be...
A customized control flow graph BFS implementation with the following rules: - Call edges are not followed. - Syscall edges are not followed. :param networkx.DiGraph g: The graph. :param list starts: A collection of beginning nodes to start graph traversal. :param func callback:...
Graph traversal handler. It takes in a node or an edge, and create new functions or add nodes to existing functions accordingly. Oh, it also create edges on the transition map of functions. :param g: The control flow graph that is currently being traversed. :param CFGNode src: Beginni...
Check if the block is a no-op block by checking VEX statements. :param block: The VEX block instance. :return: True if the entire block is a single-byte or multi-byte nop instruction, False otherwise. :rtype: bool def _is_noop_block(arch, block): """ Check if the block is a no-...
Check if the instruction does nothing. :param insn: The capstone insn object. :return: True if the instruction does no-op, False otherwise. def _is_noop_insn(insn): """ Check if the instruction does nothing. :param insn: The capstone insn object. :return: True if the i...
Calculate the total size of leading nop instructions. :param insns: A list of capstone insn objects. :return: Number of bytes of leading nop instructions. :rtype: int def _get_nop_length(cls, insns): """ Calculate the total size of leading nop instructions. :param insn...
Lift a basic block of code. Will use the base state as a source of bytes if possible. def _lift(self, *args, **kwargs): """ Lift a basic block of code. Will use the base state as a source of bytes if possible. """ if 'backup_state' not in kwargs: kwargs['backup_state'] = sel...
Checks if MIPS32 and calls MIPS32 check, otherwise false :param int addr: irsb address :param pyvex.IRSB block: irsb :param int func_addr: Function address :return: If it was resolved and targets alongside it :rtype: tuple def _resolve_indirect_jump_timelessly(self, addr, block...
Called when an indirect jump is successfully resolved. :param IndirectJump jump: The resolved indirect jump, or None if an IndirectJump instance is not available. :param int jump_addr: Address of the resolved in...
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. ...
Called when we encounter an indirect jump. We will try to resolve this indirect jump using timeless (fast) indirect jump resolvers. If it cannot be resolved, we will see if this indirect jump has been resolved before. :param int addr: Address of the block containing the indirect jump. ...
Resolve all unresolved indirect jumps found in previous scanning. Currently we support resolving the following types of indirect jumps: - Ijk_Call: indirect calls where the function address is passed in from a proceeding basic block - Ijk_Boring: jump tables - For an up-to-date list, se...
Resolve a given indirect jump. :param IndirectJump jump: The IndirectJump instance. :return: A set of resolved indirect jump targets (ints). def _process_one_indirect_jump(self, jump): """ Resolve a given indirect jump. :param IndirectJump jump: The IndirectJump insta...
Resolves jump tables. :param cfg: A CFG instance. :param int addr: IRSB address. :param int func_addr: The function address. :param pyvex.IRSB block: The IRSB. :return: A bool indicating whether the indirect jump is resolved successfully, and a list of resolved targets :...
Parse a memory load VEX statement and get the jump target addresses. :param load_stmt: The VEX statement for loading the jump target addresses. :param state: The SimState instance (in static mode). :return: An abstract value (or a concrete value) representing the jump target ...
Checks which segment that the address `addr` should belong to, and, returns the offset of that segment. Note that the address may not actually belong to the block. :param addr: The address to search :return: The offset of the segment. def _search(self, addr): """ Checks which s...
Determines whether the block specified by (address, size) should be merged with adjacent blocks. :param int address: Starting address of the block to be merged. :param int size: Size of the block to be merged. :param str sort: Type of the block. :param int idx: ID of the address. ...
The core part of method _insert_and_merge. :param int pos: The starting position. :param str direction: If we are traversing forwards or backwards in the list. It determines where the "sort" of the overlapping memory block comes from. If everything works as exp...
Returns a string representation of the segments that form this SegmentList :return: String representation of contents :rtype: str def _dbg_output(self): """ Returns a string representation of the segments that form this SegmentList :return: String representation of contents ...
Iterates over list checking segments with same sort do not overlap :raise: Exception: if segments overlap space with same sort def _debug_check(self): """ Iterates over list checking segments with same sort do not overlap :raise: Exception: if segments overlap space with same sort ...
Returns the next free position with respect to an address, including that address itself :param address: The address to begin the search with (including itself) :return: The next free position def next_free_pos(self, address): """ Returns the next free position with respect to an addre...
Returns the address of the next occupied block whose sort is not one of the specified ones. :param int address: The address to begin the search with (including itself). :param sorts: A collection of sort strings. :param max_distance: The maximum distance between `address` and the next ...
Check if an address belongs to any segment :param address: The address to check :return: True if this address belongs to a segment, False otherwise def is_occupied(self, address): """ Check if an address belongs to any segment :param address: The address to check :retu...
Check if an address belongs to any segment, and if yes, returns the sort of the segment :param int address: The address to check :return: Sort of the segment that occupies this address :rtype: str def occupied_by_sort(self, address): """ Check if an address belongs to any segme...
Include a block, specified by (address, size), in this segment list. :param int address: The starting address of the block. :param int size: Size of the block. :param str sort: Type of the block. :return: None def occupy(self, address, size, sort): """ ...
Make a copy of the SegmentList. :return: A copy of the SegmentList instance. :rtype: angr.analyses.cfg_fast.SegmentList def copy(self): """ Make a copy of the SegmentList. :return: A copy of the SegmentList instance. :rtype: angr.analyses.cfg_fast.SegmentList "...
Go over the variable information in variable manager for this function, and return all uninitialized register/stack variables. :return: def _analyze_function(self): """ Go over the variable information in variable manager for this function, and return all uninitialized register...
Filters all registers that are surly not members of function arguments. This can be seen as a workaround, since VariableRecoveryFast sometimes gives input variables of cc_ndep (which is a VEX-specific register) :-( :param SimRegisterVariable variable: The variable to test. :return: ...
Make a copy of this SimLibrary, allowing it to be mutated without affecting the global version. :return: A new SimLibrary object with the same library references but different dict/list references def copy(self): """ Make a copy of this SimLibrary, allowing it to be mutated without affectin...
Augment this SimLibrary with the information from another SimLibrary :param other: The other SimLibrary def update(self, other): """ Augment this SimLibrary with the information from another SimLibrary :param other: The other SimLibrary """ self.procedures.update(o...
Set some common names of this library by which it may be referred during linking :param names: Any number of string library names may be passed as varargs. def set_library_names(self, *names): """ Set some common names of this library by which it may be referred during linking :para...
Set the default calling convention used for this library under a given architecture :param arch_name: The string name of the architecture, i.e. the ``.name`` field from archinfo. :parm cc_cls: The SimCC class (not an instance!) to use def set_default_cc(self, arch_name, cc_cls): """ ...
Set the prototype of a function in the form of a C-style function declaration. :param str c_decl: The C-style declaration of the function. :return: A tuple of (function name, function prototype) :rtype: tuple def set_c_prototype(self, c_decl): """ Set the p...