INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
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 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: """ if self._cfg is None: ...
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 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 """ ...
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) ...
def _categorize_states(self, simgr): """ 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 st...
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_Xor") found_xor = False for block in self._function.blocks: ...
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): return expr.op.startswith("Iop_Shl") or expr.op.startswith("Iop_Shr") \ ...
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. :return: None """ # TODO: is the current solution not optimal enough? for _, item in other._storage.items(...
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. :return: self """ for old_var, new_var in replacements.items(): old_var_id = id(old_var) ...
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 = { } for key in sorted(keys): ro = self._storage[key] variables = [ obj.obj...
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: :return: None """ size = variable.size if variable.size is not None else 1 self.add_object(start, variable, si...
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: :param obj: :param int object_size: Size of the object :return: """ self._store(start, obj, object_size, overwrite=False)
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 given offset, and remove all other variables that are fully covered by this variable. :param int start: :param SimVariable variable: :return: None """ size = variable.size ...
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 given offset, and remove all other objects that are fully covered by this object. :param start: :param obj: :param object_size: :return: """ self._store(start,...
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 a specific offset. :param int addr: :return: :rtype: int or None """ base_addr, container = self._get_container(addr) if containe...
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 variables. :rtype: set """ _, container = self._get_container(start) if container is None: return [] ...
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 is None: return set() else: return container.internal_obj...
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, start, obj, size, overwrite=False): """ 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 obj...
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. ...
def __store(self, stored_object, overwrite=False): """ 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 upd...
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. ...
def _update_progress(self, percentage, **kwargs): """ 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: Oth...
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._progressbar is not None: self._progressbar...
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 abstract states. :param VariableRecoveryState other: The other abstract state to merge. :return: The merged abstract state. :rtype: VariableRecoveryState """ ...
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_stack_offset(self, addr): """ 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 ...
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: ...
def _run_on_node(self, node, state): """ 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 (chan...
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, value in self.__dict__.items(): if attr.startswith('__') and attr.endswith('__'): continue ...
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 CFGNode cfgnode_0: The first CFGNode. :param CFGNode cfgnode_1: The second CFGNode. :return: None """ assert cfgnode_0.addr + cfgnode_0.size ...
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. ...
def _to_snippet(self, cfg_node=None, addr=None, size=None, thumb=False, jumpkind=None, base_state=None): """ 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 N...
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...
def _arm_thumb_filter_jump_successors(self, addr, size, successors, get_ins_addr, get_exit_stmt_idx): """ 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...
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,...
def _is_region_extremely_sparse(self, start, end, base_state=None): """ 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 b...
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_region(self, region_start): """ 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/F...
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...
def _executable_memory_regions(self, objects=None, force_segment=False): """ 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. :pa...
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 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 """ for start, en...
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...
def _addrs_belong_to_same_section(self, addr_a, addr_b): """ 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 ...
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 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 """ ...
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 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 ...
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=None): """ 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. ...
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...
def _determine_function_returning(self, func, all_funcs_completed=False): """ 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...
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...
def _analyze_function_features(self, all_funcs_completed=False): """ 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. ...
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 "changes" dict :rtype: dict """ changes = { 'functions_do_not_return': set(), 'fu...
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): """ 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. ...
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 ...
def _get_finished_functions(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 an...
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 ...
def _cleanup_analysis_jobs(self, finished_func_addrs=None): """ 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. ...
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 in finished: self._completed_functions.add(func_addr) self._cleanup_an...
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 for func_addr in self.kb.functions.keys(): fun...
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...
def make_functions(self): """ 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,...
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] ...
def _process_irrational_functions(self, functions, predetermined_function_addrs, blockaddr_to_function): """ For unresolveable indirect jumps, angr marks those jump targets as individual functions. For example, usually the following pattern is seen: sub_0x400010: push ebp ...
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 ...
def _process_irrational_function_starts(self, functions, predetermined_function_addrs, blockaddr_to_function): """ 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 ...
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...
def _addr_to_function(self, addr, blockaddr_to_function, known_functions): """ 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 blo...
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...
def _is_tail_call_optimization(self, g : networkx.DiGraph, src_addr, dst_addr, src_function, all_edges, known_functions, blockaddr_to_function): """ If source and destination belong to the same function, and the following criteria apply: - source node has only ...
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:...
def _graph_bfs_custom(self, g, starts, callback, blockaddr_to_function, known_functions, traversed_cfg_nodes=None): """ A customized control flow graph BFS implementation with the following rules: - Call edges are not followed. - Syscall edges are not followed. :param networkx.D...
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, func_addr, jumpkind): """ 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 ...
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 insns: A list of capstone insn objects. :return: Number of bytes of leading nop instructions. :rtype: int """ nop_length = 0 if insns and cls._is_noop_insn...
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-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 """ if arch...
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'] = self._base_state return self.project.factory.block(*args, **kwargs)
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...
def _indirect_jump_resolved(self, jump, jump_addr, resolved_by, targets): """ Called when an indirect jump is successfully resolved. :param IndirectJump jump: The resolved indirect jump, or None if an IndirectJump instance is ...
Called when we cannot resolve an indirect jump. :param IndirectJump jump: The unresolved indirect jump. :return: None
def _indirect_jump_unresolved(self, jump): """ Called when we cannot resolve an indirect jump. :param IndirectJump jump: The unresolved indirect jump. :return: None """ l.debug('Failed to resolve the indirect jump at %#x.', jump.addr) # tell KnowledgeBase that ...
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. ...
def _indirect_jump_encountered(self, addr, cfg_node, irsb, func_addr, stmt_idx=DEFAULT_STATEMENT): """ 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 h...
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...
def _process_unresolved_indirect_jumps(self): """ 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 ...
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 instance. :return: A set of resolved indirect jump targets (ints). """ resolved = False resolved_by = None targets = None ...
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 :...
def resolve(self, cfg, addr, func_addr, block, jumpkind): """ 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 in...
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 ...
def _parse_load_statement(load_stmt, state): """ 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 a...
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 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. """ ...
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. ...
def _insert_and_merge(self, address, size, sort, idx): """ 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...
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...
def _insert_and_merge_core(self, pos, direction): """ 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" ...
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 :rtype: str """ s = "[" lst = [] for segment in self._list: lst.append(repr(segment)) s +=...
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 """ # old_start = 0 old_end = 0 old_sort = "" for segment in self._list: if segment.star...
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 address, including that address itself :param address: The address to begin the search with (including itself) :return: The next free position """ idx = self._search(address) ...
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 ...
def next_pos_with_sort_not_in(self, address, sorts, max_distance=None): """ 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 s...
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 :return: True if this address belongs to a segment, False otherwise """ idx = self._search(address) if len(self._list) <= idx: return ...
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 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 """ idx = self._search(a...
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): """ 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 ...
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 """ n = SegmentList() n._list = [ a.copy() for a in self._list ] n._bytes_occupied = self._bytes_occupied ...
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/stack variables. :return: """ if not self._function.is_simprocedure \ and not self._function.is_plt \ ...
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: ...
def _is_sane_register_variable(self, variable): """ 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 SimRe...
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 affecting the global version. :return: A new SimLibrary object with the same library references but different dict/list references """ o = SimLibrary() o.procedures = dict(self.proce...
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(other.procedures) self.non_returning.update(other.non_returning) self.prototypes.update(other.prototy...
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 :param names: Any number of string library names may be passed as varargs. """ for name in names: self.names.append(name) SIM_LIBRA...
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 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...
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 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 ""...
Add a function implementation fo the library. :param name: The name of the function as a string :param proc_cls: The implementation of the function as a SimProcedure _class_, not instance :param kwargs: Any additional parameters to the procedure class constructor may be passed as...
def add(self, name, proc_cls, **kwargs): """ Add a function implementation fo the library. :param name: The name of the function as a string :param proc_cls: The implementation of the function as a SimProcedure _class_, not instance :param kwargs: Any additional p...
Batch-add function implementations to the library. :param dictionary: A mapping from name to procedure class, i.e. the first two arguments to add() :param kwargs: Any additional kwargs will be passed to the constructors of _each_ procedure class
def add_all_from_dict(self, dictionary, **kwargs): """ Batch-add function implementations to the library. :param dictionary: A mapping from name to procedure class, i.e. the first two arguments to add() :param kwargs: Any additional kwargs will be passed to the constructors of _ea...
Add some duplicate names for a given function. The original function's implementation must already be registered. :param name: The name of the function for which an implementation is already present :param alt_names: Any number of alternate names may be passed as varargs
def add_alias(self, name, *alt_names): """ Add some duplicate names for a given function. The original function's implementation must already be registered. :param name: The name of the function for which an implementation is already present :param alt_names: Any number...
Get an implementation of the given function specialized for the given arch, or a stub procedure if none exists. :param name: The name of the function as a string :param arch: The architecure to use, as either a string or an archinfo.Arch instance :return: A SimProcedure instance re...
def get(self, name, arch): """ Get an implementation of the given function specialized for the given arch, or a stub procedure if none exists. :param name: The name of the function as a string :param arch: The architecure to use, as either a string or an archinfo.Arch instance ...
Get a stub procedure for the given function, regardless of if a real implementation is available. This will apply any metadata, such as a default calling convention or a function prototype. By stub, we pretty much always mean a ``ReturnUnconstrained`` SimProcedure with the appropriate display name ...
def get_stub(self, name, arch): """ Get a stub procedure for the given function, regardless of if a real implementation is available. This will apply any metadata, such as a default calling convention or a function prototype. By stub, we pretty much always mean a ``ReturnUnconstrained``...
Check if a function has either an implementation or any metadata associated with it :param name: The name of the function as a string :return: A bool indicating if anything is known about the function
def has_metadata(self, name): """ Check if a function has either an implementation or any metadata associated with it :param name: The name of the function as a string :return: A bool indicating if anything is known about the function """ return self.has_implem...
:param abi: The abi to evaluate :return: The smallest syscall number known for the given abi
def minimum_syscall_number(self, abi): """ :param abi: The abi to evaluate :return: The smallest syscall number known for the given abi """ if abi not in self.syscall_number_mapping or \ not self.syscall_number_mapping[abi]: return 0 return ...
:param abi: The abi to evaluate :return: The largest syscall number known for the given abi
def maximum_syscall_number(self, abi): """ :param abi: The abi to evaluate :return: The largest syscall number known for the given abi """ if abi not in self.syscall_number_mapping or \ not self.syscall_number_mapping[abi]: return 0 return m...
Associate a syscall number with the name of a function present in the underlying SimLibrary :param abi: The abi for which this mapping applies :param number: The syscall number :param name: The name of the function
def add_number_mapping(self, abi, number, name): """ Associate a syscall number with the name of a function present in the underlying SimLibrary :param abi: The abi for which this mapping applies :param number: The syscall number :param name: The name of the function ...
Batch-associate syscall numbers with names of functions present in the underlying SimLibrary :param abi: The abi for which this mapping applies :param mapping: A dict mapping syscall numbers to function names
def add_number_mapping_from_dict(self, abi, mapping): """ Batch-associate syscall numbers with names of functions present in the underlying SimLibrary :param abi: The abi for which this mapping applies :param mapping: A dict mapping syscall numbers to function names """ ...
The get() function for SimSyscallLibrary looks a little different from its original version. Instead of providing a name, you provide a number, and you additionally provide a list of abi names that are applicable. The first abi for which the number is present in the mapping will be chosen. This allows ...
def get(self, number, arch, abi_list=()): """ The get() function for SimSyscallLibrary looks a little different from its original version. Instead of providing a name, you provide a number, and you additionally provide a list of abi names that are applicable. The first abi for which the...
Pretty much the intersection of SimLibrary.get_stub() and SimSyscallLibrary.get(). :param number: The syscall number :param arch: The architecture being worked with, as either a string name or an archinfo.Arch :param abi_list: A list of ABI names that could be used :retur...
def get_stub(self, number, arch, abi_list=()): """ Pretty much the intersection of SimLibrary.get_stub() and SimSyscallLibrary.get(). :param number: The syscall number :param arch: The architecture being worked with, as either a string name or an archinfo.Arch :param...
Pretty much the intersection of SimLibrary.has_implementation() and SimSyscallLibrary.get(). :param number: The syscall number :param arch: The architecture being worked with, as either a string name or an archinfo.Arch :param abi_list: A list of ABI names that could be used ...
def has_implementation(self, number, arch, abi_list=()): """ Pretty much the intersection of SimLibrary.has_implementation() and SimSyscallLibrary.get(). :param number: The syscall number :param arch: The architecture being worked with, as either a string name or an archinfo...
Returns the Claripy expression of a VEX temp value. :param tmp: the number of the tmp :param simplify: simplify the tmp before returning it :returns: a Claripy expression of the tmp
def tmp_expr(self, tmp): """ Returns the Claripy expression of a VEX temp value. :param tmp: the number of the tmp :param simplify: simplify the tmp before returning it :returns: a Claripy expression of the tmp """ self.state._inspect('tmp_read', BP_BEFORE, tmp_r...
Stores a Claripy expression in a VEX temp value. If in symbolic mode, this involves adding a constraint for the tmp's symbolic variable. :param tmp: the number of the tmp :param content: a Claripy expression of the content :param reg_deps: the register dependencies of the content ...
def store_tmp(self, tmp, content, reg_deps=None, tmp_deps=None, deps=None): """ Stores a Claripy expression in a VEX temp value. If in symbolic mode, this involves adding a constraint for the tmp's symbolic variable. :param tmp: the number of the tmp :param content: a Claripy ex...
Takes a path and returns a simple absolute path as a list of directories from the root
def _normalize_path(self, path): """ Takes a path and returns a simple absolute path as a list of directories from the root """ if type(path) is str: path = path.encode() path = path.split(b'\0')[0] if path[0:1] != self.pathsep: path = self.cwd + ...
Changes the current directory to the given path
def chdir(self, path): """ Changes the current directory to the given path """ self.cwd = self._join_chunks(self._normalize_path(path))
Get a file from the filesystem. Returns a SimFile or None.
def get(self, path): """ Get a file from the filesystem. Returns a SimFile or None. """ mountpoint, chunks = self.get_mountpoint(path) if mountpoint is None: return self._files.get(self._join_chunks(chunks)) else: return mountpoint.get(chunks)
Insert a file into the filesystem. Returns whether the operation was successful.
def insert(self, path, simfile): """ Insert a file into the filesystem. Returns whether the operation was successful. """ if self.state is not None: simfile.set_state(self.state) mountpoint, chunks = self.get_mountpoint(path) if mountpoint is None: ...
Remove a file from the filesystem. Returns whether the operation was successful. This will add a ``fs_unlink`` event with the path of the file and also the index into the `unlinks` list.
def delete(self, path): """ Remove a file from the filesystem. Returns whether the operation was successful. This will add a ``fs_unlink`` event with the path of the file and also the index into the `unlinks` list. """ mountpoint, chunks = self.get_mountpoint(path) apath...
Add a mountpoint to the filesystem.
def mount(self, path, mount): """ Add a mountpoint to the filesystem. """ self._mountpoints[self._join_chunks(self._normalize_path(path))] = mount