INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
Return unsigned saturated BV from signed BV. Min and max value should be unsigned.
def _op_generic_StoU_saturation(self, value, min_value, max_value): #pylint:disable=no-self-use """ Return unsigned saturated BV from signed BV. Min and max value should be unsigned. """ return claripy.If( claripy.SGT(value, max_value), max_value, ...
Scan a basic block starting at a specific address
def _scan_block(self, cfg_job): """ Scan a basic block starting at a specific address :param CFGJob cfg_job: The CFGJob instance. :return: a list of successors :rtype: list """ addr = cfg_job.addr current_func_addr = cfg_job.func_addr if self._a...
Generate a list of successors ( generating them each as entries ) to IRSB. Updates previous CFG nodes with edges.
def _scan_soot_block(self, cfg_job, current_func_addr): """ Generate a list of successors (generating them each as entries) to IRSB. Updates previous CFG nodes with edges. :param CFGJob cfg_job: The CFGJob instance. :param int current_func_addr: Address of the current function ...
Given a node and details of a successor makes a list of CFGJobs and if it is a call or exit marks it appropriately so in the CFG
def _create_jobs(self, target, jumpkind, current_function_addr, soot_block, addr, cfg_node, stmt_addr, stmt_idx): # pylint:disable=arguments-differ """ Given a node and details of a successor, makes a list of CFGJobs and if it is a call or exit marks it appropriately so in the CFG :pa...
Revisit the entire control flow graph create Function instances accordingly and correctly put blocks into each function.
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,...
Sets an instance field.
def set_field(self, state, field_name, field_type, value): """ Sets an instance field. """ field_ref = SimSootValue_InstanceFieldRef.get_ref(state=state, obj_alloc_id=self.heap_alloc_id, ...
Gets the value of an instance field.
def get_field(self, state, field_name, field_type): """ Gets the value of an instance field. """ # get field reference field_ref = SimSootValue_InstanceFieldRef.get_ref(state=state, obj_alloc_id=self.heap_alloc_id, ...
Store a field of a given object without resolving hierachy
def store_field(self, state, field_name, field_type, value): """ Store a field of a given object, without resolving hierachy :param state: angr state where we want to allocate the object attribute :type SimState :param field_name: name of the attribute :type str ...
Load a field of a given object without resolving hierachy
def load_field(self, state, field_name, field_type): """ Load a field of a given object, without resolving hierachy :param state: angr state where we want to load the object attribute :type SimState :param field_name: name of the attribute :type str :param field_...
Creates a new object reference.: param state: State associated to the object.: param type_: Class of the object.: param init_object: Whether the objects initializer method should be run.: return: Reference to the new object.
def new_object(cls, state, type_, symbolic=False, init_object=False): """ Creates a new object reference. :param state: State associated to the object. :param type_: Class of the object. :param init_object: Whether the objects initializer method should be run. :return: Re...
Configure the project to set up global settings ( like SimProcedures ).
def configure_project(self): """ Configure the project to set up global settings (like SimProcedures). """ self.return_deadend = self.project.loader.extern_object.allocate() self.project.hook(self.return_deadend, P['stubs']['CallReturn']()) self.unresolvable_jump_target ...
Initialize a blank state.
def state_blank(self, addr=None, initial_prefix=None, brk=None, stack_end=None, stack_size=1024*1024*8, stdin=None, **kwargs): """ Initialize a blank state. All parameters are optional. :param addr: The execution start address. :param initial_prefix: :param s...
This function prepares a state that is executing a call instruction. If given an initial_state it copies over all of the critical registers to it from the calling_state. Otherwise it prepares the calling_state for action.
def prepare_call_state(self, calling_state, initial_state=None, preserve_registers=(), preserve_memory=()): """ This function prepares a state that is executing a call instruction. If given an initial_state, it copies over all of the critical registers to it from the ...
Prepare the address space with the data necessary to perform relocations pointing to the given symbol
def prepare_function_symbol(self, symbol_name, basic_addr=None): """ Prepare the address space with the data necessary to perform relocations pointing to the given symbol Returns a 2-tuple. The first item is the address of the function code, the second is the address of the relocation t...
Write the GlobalDescriptorTable object in the current state memory
def setup_gdt(self, state, gdt): """ Write the GlobalDescriptorTable object in the current state memory :param state: state in which to write the GDT :param gdt: GlobalDescriptorTable object :return: """ state.memory.store(gdt.addr+8, gdt.table) state.reg...
Generate a GlobalDescriptorTable object and populate it using the value of the gs and fs register
def generate_gdt(self, fs, gs, fs_size=0xFFFFFFFF, gs_size=0xFFFFFFFF): """ Generate a GlobalDescriptorTable object and populate it using the value of the gs and fs register :param fs: value of the fs segment register :param gs: value of the gs segment register :param ...
Register a struct definition globally
def define_struct(defn): """ Register a struct definition globally >>> define_struct('struct abcd {int x; int y;}') """ struct = parse_type(defn) ALL_TYPES[struct.name] = struct return struct
Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
def do_preprocess(defn): """ Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible? """ from pycparser.ply import lex, cpp lexer = lex.lex(cpp) p = cpp.Preprocessor(lexer) # p.add_path(dir) will add dir to the include search path p.parse(defn) ...
Parse a series of C definitions returns a tuple of two type mappings one for variable definitions and one for type definitions.
def parse_file(defn, preprocess=True): """ Parse a series of C definitions, returns a tuple of two type mappings, one for variable definitions and one for type definitions. """ if pycparser is None: raise ImportError("Please install pycparser in order to parse C definitions") defn = '\n...
Parse a simple type expression into a SimType
def parse_type(defn, preprocess=True): """ Parse a simple type expression into a SimType >>> parse_type('int *') """ if pycparser is None: raise ImportError("Please install pycparser in order to parse C definitions") defn = 'typedef ' + defn.strip('; \n\t\r') + ' QQQQ;' if preproc...
The alignment of the type in bytes.
def alignment(self): """ The alignment of the type in bytes. """ if self._arch is None: return NotImplemented return self.size // self._arch.byte_width
Handle the switch between the concrete execution and angr. This method takes care of: 1 - Synchronize registers. 2 - Set a concrete target to the memory backer so the memory reads are redirected in the concrete process memory. 3 - If possible restore the SimProcedures with the real addresses inside the concrete process...
def sync(self): """ Handle the switch between the concrete execution and angr. This method takes care of: 1- Synchronize registers. 2- Set a concrete target to the memory backer so the memory reads are redirected in the concrete process memory. 3- If possible restore the ...
The ( L2 ) distance between the counts of the state addresses in the history of the path.: param state_a: The first state to compare: param state_b: The second state to compare
def similarity(state_a, state_b): """ The (L2) distance between the counts of the state addresses in the history of the path. :param state_a: The first state to compare :param state_b: The second state to compare """ count_a = Counter(state_a.history.bbl_addrs) co...
The difflib. SequenceMatcher ratio between the state addresses in the history of the path.: param state_a: The first state to compare: param state_b: The second state to compare
def sequence_matcher_similarity(state_a, state_b): """ The `difflib.SequenceMatcher` ratio between the state addresses in the history of the path. :param state_a: The first state to compare :param state_b: The second state to compare """ addrs_a = tuple(state_a.history.bb...
Resolves the method based on the given characteristics ( name class and params ) The method may be defined in one of the superclasses of the given class ( TODO: support interfaces ).
def resolve_method(state, method_name, class_name, params=(), ret_type=None, include_superclasses=True, init_class=True, raise_exception_if_not_found=False): """ Resolves the method based on the given characteristics (name, class and params) The method may be defined in...
This is a hack to deal with small values being stored at offsets into large registers unpredictably
def _fix_offset(self, state, size, arch=None): """ This is a hack to deal with small values being stored at offsets into large registers unpredictably """ if state is not None: arch = state.arch if arch is None: raise ValueError('Either "state" or "arch" ...
Get an instance of the class that will extract floating - point/ integral args correctly.
def from_arg_kinds(cls, arch, fp_args, ret_fp=False, sizes=None, sp_delta=None, func_ty=None): """ Get an instance of the class that will extract floating-point/integral args correctly. :param arch: The Archinfo arch for this CC :param fp_args: A list, with one entry for each...
Iterate through all the possible arg positions that can only be used to store integer or pointer values Does not take into account customizations.
def int_args(self): """ Iterate through all the possible arg positions that can only be used to store integer or pointer values Does not take into account customizations. Returns an iterator of SimFunctionArguments """ if self.ARG_REGS is None: raise NotImple...
Iterate through all the possible arg positions that can be used to store any kind of argument Does not take into account customizations.
def both_args(self): """ Iterate through all the possible arg positions that can be used to store any kind of argument Does not take into account customizations. Returns an iterator of SimFunctionArguments """ turtle = self.STACKARG_SP_BUFF + self.STACKARG_SP_DIFF ...
Iterate through all the possible arg positions that can only be used to store floating point values Does not take into account customizations.
def fp_args(self): """ Iterate through all the possible arg positions that can only be used to store floating point values Does not take into account customizations. Returns an iterator of SimFunctionArguments """ if self.FP_ARG_REGS is None: raise NotImpleme...
This should take a SimFunctionArgument instance and return whether or not that argument is a floating - point argument.
def is_fp_arg(self, arg): """ This should take a SimFunctionArgument instance and return whether or not that argument is a floating-point argument. Returns True for MUST be a floating point arg, False for MUST NOT be a floating point arg, None for when it...
: param args: A list of SimFunctionArguments
def stack_space(self, args): """ :param args: A list of SimFunctionArguments :returns: The number of bytes that should be allocated on the stack to store all these args, NOT INCLUDING the return address. """ out = self.STACKARG_SP_DIF...
Pass this a list of whether each parameter is floating - point or not and get back a list of SimFunctionArguments. Optionally pass a list of argument sizes ( in bytes ) as well.
def arg_locs(self, is_fp=None, sizes=None): """ Pass this a list of whether each parameter is floating-point or not, and get back a list of SimFunctionArguments. Optionally, pass a list of argument sizes (in bytes) as well. If you've customized this CC, this will sanity-check the provid...
Returns a bitvector expression representing the nth argument of a function.
def arg(self, state, index, stack_base=None): """ Returns a bitvector expression representing the nth argument of a function. `stack_base` is an optional pointer to the top of the stack at the function start. If it is not specified, use the current stack pointer. WARNING: this ...
is_fp should be a list of booleans specifying whether each corresponding argument is floating - point - True for fp and False for int. For a shorthand to assume that all the parameters are int pass the number of parameters as an int.
def get_args(self, state, is_fp=None, sizes=None, stack_base=None): """ `is_fp` should be a list of booleans specifying whether each corresponding argument is floating-point - True for fp and False for int. For a shorthand to assume that all the parameters are int, pass the number of par...
This function performs the actions of the caller getting ready to jump into a function.
def setup_callsite(self, state, ret_addr, args, stack_base=None, alloc_base=None, grow_like_stack=True): """ This function performs the actions of the caller getting ready to jump into a function. :param state: The SimState to operate on :param ret_addr: The address to ...
This function performs the actions of the callee as it s getting ready to return. It returns the address to return to.
def teardown_callsite(self, state, return_val=None, arg_types=None, force_callee_cleanup=False): """ This function performs the actions of the callee as it's getting ready to return. It returns the address to return to. :param state: The state to mutate :param ...
Get the return value out of the given state
def get_return_val(self, state, is_fp=None, size=None, stack_base=None): """ Get the return value out of the given state """ ty = self.func_ty.returnty if self.func_ty is not None else None if self.ret_val is not None: loc = self.ret_val elif is_fp is not None...
Set the return value into the given state
def set_return_val(self, state, val, is_fp=None, size=None, stack_base=None): """ Set the return value into the given state """ ty = self.func_ty.returnty if self.func_ty is not None else None try: betterval = self._standardize_value(val, ty, state, None) exce...
Pinpoint the best - fit calling convention and return the corresponding SimCC instance or None if no fit is found.
def find_cc(arch, args, sp_delta): """ Pinpoint the best-fit calling convention and return the corresponding SimCC instance, or None if no fit is found. :param Arch arch: An ArchX instance. Can be obtained from archinfo. :param list args: A list of arguments. ...
This is just a simple wrapper that collects the information from various locations is_fp and sizes are passed to self. arg_locs and self. get_args: param angr. SimState state: The state to evaluate and extract the values from: return: A list of tuples where the nth tuple is ( type name location value ) of the nth argum...
def get_arg_info(self, state, is_fp=None, sizes=None): """ This is just a simple wrapper that collects the information from various locations is_fp and sizes are passed to self.arg_locs and self.get_args :param angr.SimState state: The state to evaluate and extract the values from ...
Add a successor state of the SimRun. This procedure stores method parameters into state. scratch does some housekeeping and calls out to helper functions to prepare the state and categorize it into the appropriate successor lists.
def add_successor(self, state, target, guard, jumpkind, add_guard=True, exit_stmt_idx=None, exit_ins_addr=None, source=None): """ Add a successor state of the SimRun. This procedure stores method parameters into state.scratch, does some housekeeping, and calls out t...
Preprocesses the successor state.
def _preprocess_successor(self, state, add_guard=True): #pylint:disable=unused-argument """ Preprocesses the successor state. :param state: the successor state """ # Next, simplify what needs to be simplified if o.SIMPLIFY_EXIT_STATE in state.options: state....
Append state into successor lists.
def _categorize_successor(self, state): """ Append state into successor lists. :param state: a SimState instance :param target: The target (of the jump/call/ret) :return: The state """ self.all_successors.append(state) target = state.scratch.target ...
Resolve syscall information from the state get the IP address of the syscall SimProcedure and set the IP of the state accordingly. Don t do anything if the resolution fails.
def _fix_syscall_ip(state): """ Resolve syscall information from the state, get the IP address of the syscall SimProcedure, and set the IP of the state accordingly. Don't do anything if the resolution fails. :param SimState state: the program state. :return: None """ ...
Finalizes the request.
def _finalize(self): """ Finalizes the request. """ if len(self.all_successors) == 0: return # do some cleanup if o.DOWNSIZE_Z3 in self.all_successors[0].options: for s in self.all_successors: s.downsize() # record if the ...
A * very * fast method to evaluate symbolic jump targets if they are a ) concrete targets or b ) targets coming from jump tables.
def _eval_target_jumptable(state, ip, limit): """ A *very* fast method to evaluate symbolic jump targets if they are a) concrete targets, or b) targets coming from jump tables. :param state: A SimState instance. :param ip: The AST of the instruction pointer to evaluate. ...
The traditional way of evaluating symbolic jump targets.
def _eval_target_brutal(state, ip, limit): """ The traditional way of evaluating symbolic jump targets. :param state: A SimState instance. :param ip: The AST of the instruction pointer to evaluate. :param limit: The maximum number of concrete IPs. :return: ...
Get a long number for a byte being repeated for many times. This is part of the effort of optimizing performance of angr s memory operations.
def _repeat_bytes(byt, rep): """ Get a long number for a byte being repeated for many times. This is part of the effort of optimizing performance of angr's memory operations. :param int byt: the byte to repeat :param int rep: times to repeat the byte :return: a long inte...
Make a copy of the MemoryData.
def copy(self): """ Make a copy of the MemoryData. :return: A copy of the MemoryData instance. :rtype: MemoryData """ s = MemoryData(self.address, self.size, self.sort, pointer_addr=self.pointer_addr, max_size=self.max_size) s.content = self.content retu...
Stores a memory object.
def store_mo(self, state, new_mo, overwrite=True): #pylint:disable=unused-argument """ Stores a memory object. :param new_mo: the memory object :param overwrite: whether to overwrite objects already in memory (if false, just fill in the holes) """ start, end = self._reso...
Loads a memory object from memory.
def load_mo(self, state, page_idx): """ Loads a memory object from memory. :param page_idx: the index into the page :returns: a tuple of the object """ try: key = next(self._storage.irange(maximum=page_idx, reverse=True)) except StopIteration: ...
Return the memory objects overlapping with the provided slice.
def load_slice(self, state, start, end): """ Return the memory objects overlapping with the provided slice. :param start: the start address :param end: the end address (non-inclusive) :returns: tuples of (starting_addr, memory_object) """ keys = list(self._storag...
Loads a memory object from memory.
def load_mo(self, state, page_idx): """ Loads a memory object from memory. :param page_idx: the index into the page :returns: a tuple of the object """ mo = self._storage[page_idx-self._page_addr] return self._sinkhole if mo is None else mo
Return the memory objects overlapping with the provided slice.
def load_slice(self, state, start, end): """ Return the memory objects overlapping with the provided slice. :param start: the start address :param end: the end address (non-inclusive) :returns: tuples of (starting_addr, memory_object) """ items = [ ] if s...
Tests if the address is contained in any page of paged memory without considering memory backers.
def contains_no_backer(self, addr): """ Tests if the address is contained in any page of paged memory, without considering memory backers. :param int addr: The address to test. :return: True if the address is included in one of the pages, False otherwise. :rtype: bool ""...
Gets the set of changed bytes between self and other.
def __changed_bytes(self, other): """ Gets the set of changed bytes between `self` and `other`. :type other: SimPagedMemory :returns: A set of differing bytes. """ if self._page_size != other._page_size: raise SimMemoryError("SimPagedMemory page size...
Writes a memory object to a page
def _apply_object_to_page(self, page_base, mo, page=None, overwrite=True): """ Writes a memory object to a `page` :param page_base: The base address of the page. :param mo: The memory object. :param page: (optional) the page to use. :param overwrite: ...
This function optimizes a large store by storing a single reference to the: class: SimMemoryObject instead of one for each byte.
def store_memory_object(self, mo, overwrite=True): """ This function optimizes a large store by storing a single reference to the :class:`SimMemoryObject` instead of one for each byte. :param memory_object: the memory object to store """ for p in self._containing_pages_...
Replaces the memory object old with a new memory object containing new_content.
def replace_memory_object(self, old, new_content): """ Replaces the memory object `old` with a new memory object containing `new_content`. :param old: A SimMemoryObject (i.e., one from :func:`memory_objects_for_hash()` or :func:` memory_objects_for_name()`). ...
Replaces all instances of expression old with expression new.
def replace_all(self, old, new): """ Replaces all instances of expression `old` with expression `new`. :param old: A claripy expression. Must contain at least one named variable (to make it possible to use the name index for speedup). :param new: The new variable to ...
Returns addresses that contain expressions that contain a variable named n.
def addrs_for_name(self, n): """ Returns addresses that contain expressions that contain a variable named `n`. """ if n not in self._name_mapping: return self._mark_updated_mapping(self._name_mapping, n) to_discard = set() for e in self._name_mapping...
Returns addresses that contain expressions that contain a variable with the hash of h.
def addrs_for_hash(self, h): """ Returns addresses that contain expressions that contain a variable with the hash of `h`. """ if h not in self._hash_mapping: return self._mark_updated_mapping(self._hash_mapping, h) to_discard = set() for e in self._h...
: param white_list: white list of page number to exclude from the flush
def flush_pages(self, white_list): """ :param white_list: white list of page number to exclude from the flush """ white_list_page_number = [] for addr in white_list: for page_addr in range(addr[0], addr[1], self._page_size): white_list_page_number...
Open a symbolic file. Basically open ( 2 ).
def open(self, name, flags, preferred_fd=None): """ Open a symbolic file. Basically open(2). :param name: Path of the symbolic file, as a string or bytes. :type name: string or bytes :param flags: File operation flags, a bitfield of constants fro...
Looks up the SimFileDescriptor associated with the given number ( an AST ). If the number is concrete and does not map to anything return None. If the number is symbolic constrain it to an open fd and create a new file for it.
def get_fd(self, fd): """ Looks up the SimFileDescriptor associated with the given number (an AST). If the number is concrete and does not map to anything, return None. If the number is symbolic, constrain it to an open fd and create a new file for it. """ try: ...
Closes the given file descriptor ( an AST ). Returns whether the operation succeeded ( a concrete boolean )
def close(self, fd): """ Closes the given file descriptor (an AST). Returns whether the operation succeeded (a concrete boolean) """ try: fd = self.state.solver.eval_one(fd) except SimSolverError: l.error("Trying to close a symbolic file descriptor...
Gets the current sigmask. If it s blank a new one is created ( of sigsetsize ).
def sigmask(self, sigsetsize=None): """ Gets the current sigmask. If it's blank, a new one is created (of sigsetsize). :param sigsetsize: the size (in *bytes* of the sigmask set) :return: the sigmask """ if self._sigmask is None: if sigsetsize is not None: ...
Updates the signal mask.
def sigprocmask(self, how, new_mask, sigsetsize, valid_ptr=True): """ Updates the signal mask. :param how: the "how" argument of sigprocmask (see manpage) :param new_mask: the mask modification to apply :param sigsetsize: the size (in *bytes* of the sigmask set) :param v...
Returns the concrete content for a file by path.
def dump_file_by_path(self, path, **kwargs): """ Returns the concrete content for a file by path. :param path: file path as string :param kwargs: passed to state.solver.eval :return: file contents as string """ file = self.state.fs.get(path) if file is No...
Returns the concrete content for a file descriptor.
def dumps(self, fd, **kwargs): """ Returns the concrete content for a file descriptor. BACKWARD COMPATIBILITY: if you ask for file descriptors 0 1 or 2, it will return the data from stdin, stdout, or stderr as a flat string. :param fd: A file descriptor. :return: Th...
Handle the concrete execution of the process This method takes care of: 1 - Set the breakpoints on the addresses provided by the user 2 - Concretize the symbolic variables and perform the write inside the concrete process 3 - Continue the program execution.
def to_engine(self, state, extra_stop_points, concretize, timeout): """ Handle the concrete execution of the process This method takes care of: 1- Set the breakpoints on the addresses provided by the user 2- Concretize the symbolic variables and perform the write inside the concr...
Check if the concrete target methods return the correct type of data: return: True if the concrete target is compliant
def check_concrete_target_methods(concrete_target): """ Check if the concrete target methods return the correct type of data :return: True if the concrete target is compliant """ entry_point = concrete_target.read_register("pc") if not type(entry_point) is int: ...
: param state: The state with which to execute: param irsb: The PyVEX IRSB object to use for execution. If not provided one will be lifted.: param skip_stmts: The number of statements to skip in processing: param last_stmt: Do not execute any statements after this statement: param whitelist: Only execute statements in ...
def process(self, state, irsb=None, skip_stmts=0, last_stmt=99999999, whitelist=None, inline=False, force_addr=None, insn_bytes=None, size=None, num_inst=None, traceflags=0, thumb=False, ...
This function receives an initial state and imark and processes a list of pyvex. IRStmts It annotates the request with a final state last imark and a list of SimIRStmts
def _handle_statement(self, state, successors, stmt): """ This function receives an initial state and imark and processes a list of pyvex.IRStmts It annotates the request with a final state, last imark, and a list of SimIRStmts """ if type(stmt) == pyvex.IRStmt.IMark: ...
Lift an IRSB.
def lift(self, state=None, clemory=None, insn_bytes=None, arch=None, addr=None, size=None, num_inst=None, traceflags=0, thumb=False, extra_stop_points=None, opt_level=None, ...
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) are at a stop point, returns the address of the stop point. None is returned otherwise. """ if self._stop_points is None and extra_stop_points is ...
Generate a sif file from the call map.
def _genenare_callmap_sif(self, filepath): """ Generate a sif file from the call map. :param filepath: Path of the sif file :return: None """ with open(filepath, "wb") as f: for src, dst in self.callgraph.edges(): f.write("%#x\tD...
Return the function who has the least address that is greater than or equal to addr.
def ceiling_func(self, addr): """ 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 ...
Return the function who has the greatest address that is less than or equal to addr.
def floor_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 N...
Get a function object from the function manager.
def function(self, addr=None, name=None, create=False, syscall=False, plt=None): """ 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. ...
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(): return list(self._graph.successors(run)) else: return []
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(): return list(self._graph.predecessors(run)) else: return []
Construct a control dependence graph.
def _construct(self): """ 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. """ self._acyclic_cfg = self._cfg.copy() # TODO: Cycle-removing i...
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 return edge does not exist) """ for _, dst, data in self._acyclic_cfg.graph.edges(data=True): if 'jumpkind' in data and dat...
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 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. ...
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_back_edges() for b1, b2 in loop_back_edges: # The edge between b1 and b2 is manually b...
Create a phi variable for variables at block block_addr.
def make_phi_node(self, block_addr, *variables): """ 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 v...
Get a list of variables.
def get_variables(self, sort=None, collapse_same_ident=False): """ 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 lis...
Get sub - variables that phi variable var represents.
def get_phi_subvariables(self, var): """ 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 """ ...
Get a dict of phi variables and their corresponding variables.
def get_phi_variables(self, block_addr): """ 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: ...
Get all variables that have never been 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. """ def has_write_access(accesses): return any(acc for acc in accesses if acc.access_type == 'write') ...
Assign default names to all variables.
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: continue if var.ident.startsw...
Get a list of all references to the given variable.
def get_variable_accesses(self, variable, same_name=False): """ 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 ...
Call this Callable with a string of C - style arguments.
def call_c(self, c_args): """ 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 """ c_args = c_args.strip() if c_args[0] != "(...
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.
def filter_actions(self, block_addr=None, block_stmt=None, insn_addr=None, read_from=None, write_to=None): """ 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 actio...
Find the common ancestor between this history node and other.
def closest_common_ancestor(self, other): """ 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 """ our_history_...
Returns the constraints that have been accumulated since other.
def constraints_since(self, other): """ Returns the constraints that have been accumulated since `other`. :param other: a prior PathHistory object :returns: a list of constraints """ constraints = [ ] cur = self while cur is not other and cur is not None...
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 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 ...