INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Sometimes there exists a pointer that points to a few bytes before the beginning of a section, or a few bytes
after the beginning of the section. We take care of that here.
:param int addr: The address to check.
:return: A 2-tuple of (bool, the closest base address)
:rtype: tuple | def main_nonexecutable_region_limbos_contain(self, addr, tolerance_before=64, tolerance_after=64):
"""
Sometimes there exists a pointer that points to a few bytes before the beginning of a section, or a few bytes
after the beginning of the section. We take care of that here.
:param int ... |
Add a new label to the symbol manager.
:param str name: Name of the label.
:param int addr: Address of the label.
:return: None | def add_label(self, name, addr):
"""
Add a new label to the symbol manager.
:param str name: Name of the label.
:param int addr: Address of the label.
:return: None
"""
# set the label
self._symbolization_needed = True
self.symbol_manager.new_la... |
Insert some assembly code at the specific address. There must be an instruction starting at that address.
:param int addr: Address of insertion
:param str asm_code: The assembly code to insert
:return: None | def insert_asm(self, addr, asm_code, before_label=False):
"""
Insert some assembly code at the specific address. There must be an instruction starting at that address.
:param int addr: Address of insertion
:param str asm_code: The assembly code to insert
:return: None
""... |
Add a new procedure with specific name and assembly code.
:param str name: The name of the new procedure.
:param str asm_code: The assembly code of the procedure
:return: None | def append_procedure(self, name, asm_code):
"""
Add a new procedure with specific name and assembly code.
:param str name: The name of the new procedure.
:param str asm_code: The assembly code of the procedure
:return: None
"""
proc = Procedure(self, name=name, ... |
Append a new data entry into the binary with specific name, content, and size.
:param str name: Name of the data entry. Will be used as the label.
:param bytes initial_content: The initial content of the data entry.
:param int size: Size of the data entry.
:param bool readonly: If the d... | def append_data(self, name, initial_content, size, readonly=False, sort="unknown"): # pylint:disable=unused-argument
"""
Append a new data entry into the binary with specific name, content, and size.
:param str name: Name of the data entry. Will be used as the label.
:param bytes initi... |
Remove CGC attachments.
:return: True if CGC attachments are found and removed, False otherwise
:rtype: bool | def remove_cgc_attachments(self):
"""
Remove CGC attachments.
:return: True if CGC attachments are found and removed, False otherwise
:rtype: bool
"""
cgc_package_list = None
cgc_extended_application = None
for data in self.data:
if data.sor... |
Remove unnecessary functions and data
:return: None | def remove_unnecessary_stuff(self):
"""
Remove unnecessary functions and data
:return: None
"""
glibc_functions_blacklist = {
'_start',
'_init',
'_fini',
'__gmon_start__',
'__do_global_dtors_aux',
'frame_du... |
Initialize the binary.
:return: None | def _initialize(self):
"""
Initialize the binary.
:return: None
"""
# figure out section alignments
for section in self.project.loader.main_object.sections:
in_segment = False
for segment in self.project.loader.main_object.segments:
... |
Find sequences in binary data.
:param angr.analyses.CFG cfg: The control flow graph.
:param pyvex.IRSB irsb: The IRSB object.
:param int irsb_addr: Address of the block.
:param int stmt_idx: Statement ID.
:param int data_addr: Address of the data in memory.
:param int ma... | def _sequence_handler(self, cfg, irsb, irsb_addr, stmt_idx, data_addr, max_size): # pylint:disable=unused-argument
"""
Find sequences in binary data.
:param angr.analyses.CFG cfg: The control flow graph.
:param pyvex.IRSB irsb: The IRSB object.
:param int irsb_addr: Address of ... |
Identifies the CGC package list associated with the CGC binary.
:param int data_addr: Address of the data in memory.
:param int data_size: Maximum size possible.
:return: A 2-tuple of data type and size.
:rtype: tuple | def _cgc_package_list_identifier(self, data_addr, data_size):
"""
Identifies the CGC package list associated with the CGC binary.
:param int data_addr: Address of the data in memory.
:param int data_size: Maximum size possible.
:return: A 2-tuple of data type and size.
:... |
Identifies the extended application (a PDF file) associated with the CGC binary.
:param angr.analyses.CFG cfg: The control flow graph.
:param pyvex.IRSB irsb: The IRSB object.
:param int irsb_addr: Address of the block.
:param int stmt_idx: Statement ID.
:param int data_addr: Ad... | def _cgc_extended_application_handler(self, cfg, irsb, irsb_addr, stmt_idx, data_addr, max_size): # pylint:disable=unused-argument
"""
Identifies the extended application (a PDF file) associated with the CGC binary.
:param angr.analyses.CFG cfg: The control flow graph.
:param pyvex.IRS... |
Return the maximum number of bytes until a potential pointer or a potential sequence is found.
:param angr.analyses.CFG cfg: The control flow graph.
:param pyvex.IRSB irsb: The IRSB object.
:param int irsb_addr: Address of the block.
:param int stmt_idx: Statement ID.
:param int... | def _unknown_data_size_handler(self, cfg, irsb, irsb_addr, stmt_idx, data_addr, max_size): # pylint:disable=unused-argument
"""
Return the maximum number of bytes until a potential pointer or a potential sequence is found.
:param angr.analyses.CFG cfg: The control flow graph.
:param py... |
Test if there is any (suspicious) pointer decryption in the code.
:return: True if there is any pointer decryption, False otherwise.
:rtype: bool | def _has_integer_used_as_pointers(self):
"""
Test if there is any (suspicious) pointer decryption in the code.
:return: True if there is any pointer decryption, False otherwise.
:rtype: bool
"""
# check all integer accesses and see if there is any integer being used as ... |
Load memory bytes from loader's memory backend.
:param int addr: The address to begin memory loading.
:param int size: Size in bytes.
:param data_type: Type of the data.
:param str endness: Endianness of this memory load.
:return: Data read out of the memory.
... | def fast_memory_load(self, addr, size, data_type, endness='Iend_LE'):
"""
Load memory bytes from loader's memory backend.
:param int addr: The address to begin memory loading.
:param int size: Size in bytes.
:param data_type: Type of the data.
:param str endness:... |
Merge two abstract states.
For any node A whose dominance frontier that the current node (at the current program location) belongs to, we
create a phi variable V' for each variable V that is defined in A, and then replace all existence of V with V'
in the merged abstract state.
:param ... | def merge(self, other, successor=None):
"""
Merge two abstract states.
For any node A whose dominance frontier that the current node (at the current program location) belongs to, we
create a phi variable V' for each variable V that is defined in A, and then replace all existence of V wi... |
Scan through all statements and perform the following tasks:
- Find stack pointers and the VEX temporary variable storing stack pointers
- Selectively calculate VEX statements
- Track memory loading and mark stack and global variables accordingly
:param angr.Block block:
:return... | def _process_block(self, state, block): # pylint:disable=no-self-use
"""
Scan through all statements and perform the following tasks:
- Find stack pointers and the VEX temporary variable storing stack pointers
- Selectively calculate VEX statements
- Track memory loading and mar... |
Make a shallow copy of a directional graph and reverse the edges. This is a workaround to solve the issue that one
cannot easily make a shallow reversed copy of a graph in NetworkX 2, since networkx.reverse(copy=False) now returns
a GraphView, and GraphViews are always read-only.
:param networkx.DiGraph g:... | def shallow_reverse(g):
"""
Make a shallow copy of a directional graph and reverse the edges. This is a workaround to solve the issue that one
cannot easily make a shallow reversed copy of a graph in NetworkX 2, since networkx.reverse(copy=False) now returns
a GraphView, and GraphViews are always read-o... |
Do a DFS traversal of the graph, and return with the back edges.
Note: This is just a naive recursive implementation, feel free to replace it.
I couldn't find anything in networkx to do this functionality. Although the
name suggest it, but `dfs_labeled_edges` is doing something different.
:param graph... | def dfs_back_edges(graph, start_node):
"""
Do a DFS traversal of the graph, and return with the back edges.
Note: This is just a naive recursive implementation, feel free to replace it.
I couldn't find anything in networkx to do this functionality. Although the
name suggest it, but `dfs_labeled_edg... |
Compute a dominance frontier based on the given post-dominator tree.
This implementation is based on figure 2 of paper An Efficient Method of Computing Static Single Assignment
Form by Ron Cytron, etc.
:param graph: The graph where we want to compute the dominance frontier.
:param domtree: The domin... | def compute_dominance_frontier(graph, domtree):
"""
Compute a dominance frontier based on the given post-dominator tree.
This implementation is based on figure 2 of paper An Efficient Method of Computing Static Single Assignment
Form by Ron Cytron, etc.
:param graph: The graph where we want to c... |
Return the successors of a node in the graph.
This method can be overriden in case there are special requirements with the graph and the successors. For
example, when we are dealing with a control flow graph, we may not want to get the FakeRet successors.
:param graph: The graph.
:param... | def _graph_successors(self, graph, node):
"""
Return the successors of a node in the graph.
This method can be overriden in case there are special requirements with the graph and the successors. For
example, when we are dealing with a control flow graph, we may not want to get the FakeRe... |
Find post-dominators for each node in the graph.
This implementation is based on paper A Fast Algorithm for Finding Dominators in a Flow Graph by Thomas
Lengauer and Robert E. Tarjan from Stanford University, ACM Transactions on Programming Languages and Systems,
Vol. 1, No. 1, July 1979 | def _construct(self, graph, entry_node):
"""
Find post-dominators for each node in the graph.
This implementation is based on paper A Fast Algorithm for Finding Dominators in a Flow Graph by Thomas
Lengauer and Robert E. Tarjan from Stanford University, ACM Transactions on Programming L... |
A dumb and simple way to conveniently aggregate all loggers.
Adds attributes to this instance of each registered logger, replacing '.' with '_' | def load_all_loggers(self):
"""
A dumb and simple way to conveniently aggregate all loggers.
Adds attributes to this instance of each registered logger, replacing '.' with '_'
"""
for name, logger in logging.Logger.manager.loggerDict.items():
if any(name.startswith(x... |
Perform execution with a state.
:param state: The state with which to execute
:param procedure: An instance of a SimProcedure to run
:param ret_to: The address to return to when this procedure is finished
:param inline: This is an inline execution. Do not bother copyin... | def process(self, state, procedure,
ret_to=None,
inline=None,
force_addr=None,
**kwargs):
"""
Perform execution with a state.
:param state: The state with which to execute
:param procedure: An instance of a SimProcedure to run
... |
:return: Default value for array elements. | def get_default_value(self, state):
"""
:return: Default value for array elements.
"""
if self._default_value_generator:
return self._default_value_generator(state)
else:
return state.project.simos.get_default_value_by_type(self.element_type, state=state) |
Add a function `func` and all blocks of this function to the blanket. | def add_function(self, func):
"""
Add a function `func` and all blocks of this function to the blanket.
"""
for block in func.blocks:
self.add_obj(block.addr, block) |
The debugging representation of this CFBlanket.
:return: The debugging representation of this CFBlanket.
:rtype: str | def dbg_repr(self):
"""
The debugging representation of this CFBlanket.
:return: The debugging representation of this CFBlanket.
:rtype: str
"""
output = [ ]
for obj in self.project.loader.all_objects:
for section in obj.sections:
... |
Initialize CFBlanket from a CFG instance.
:param cfg: A CFG instance.
:return: None | def _from_cfg(self, cfg):
"""
Initialize CFBlanket from a CFG instance.
:param cfg: A CFG instance.
:return: None
"""
# Let's first add all functions first
for func in cfg.kb.functions.values():
self.add_function(func)
self._mark_unknowns... |
Mark all unmapped regions.
:return: None | def _mark_unknowns(self):
"""
Mark all unmapped regions.
:return: None
"""
for obj in self.project.loader.all_objects:
if isinstance(obj, cle.ELF):
# sections?
if obj.sections:
for section in obj.sections:
... |
:param flag_page: Flag page content, either a string or a list of BV8s | def state_blank(self, flag_page=None, **kwargs):
"""
:param flag_page: Flag page content, either a string or a list of BV8s
"""
s = super(SimCGC, self).state_blank(**kwargs) # pylint:disable=invalid-name
# Special stack base for CGC binaries to work with Shellphish CRS
... |
Test whether a statement is inside the loop body or not.
:param stmt_idx:
:return: | def _stmt_inside_loop(self, stmt_idx):
"""
Test whether a statement is inside the loop body or not.
:param stmt_idx:
:return:
"""
# TODO: This is slow. Fix the performance issue
for node in self.loop.body_nodes:
if node.addr.stmt_idx <= stmt_idx < n... |
Iterator based check.
With respect to a certain variable/value A,
- there must be at least one exit condition being A//Iterator//HasNext == 0
- there must be at least one local that ticks the iterator next: A//Iterator//Next | def _is_bounded_iterator_based(self):
"""
Iterator based check.
With respect to a certain variable/value A,
- there must be at least one exit condition being A//Iterator//HasNext == 0
- there must be at least one local that ticks the iterator next: A//Iterator//Next
"""
... |
Overwrite existing definitions w.r.t 'atom' with a dummy definition instance. A dummy definition will not be
removed during simplification.
:param Atom atom:
:param CodeLocation code_loc:
:param object data:
:return: None | def kill_definitions(self, atom, code_loc, data=None, dummy=True):
"""
Overwrite existing definitions w.r.t 'atom' with a dummy definition instance. A dummy definition will not be
removed during simplification.
:param Atom atom:
:param CodeLocation code_loc:
:param objec... |
Create an entry state.
:param args: List of SootArgument values (optional). | def state_entry(self, args=None, **kwargs): # pylint: disable=arguments-differ
"""
Create an entry state.
:param args: List of SootArgument values (optional).
"""
state = self.state_blank(**kwargs)
# for the Java main method `public static main(String[] args)`,
#... |
Generates a new symbolic cmd line argument string.
:return: The string reference. | def generate_symbolic_cmd_line_arg(state, max_length=1000):
"""
Generates a new symbolic cmd line argument string.
:return: The string reference.
"""
str_ref = SimSootValue_StringRef(state.memory.get_new_uuid())
str_sym = StringS("cmd_line_arg", max_length)
state.... |
Create a native or a Java call state.
:param addr: Soot or native addr of the invoke target.
:param args: List of SootArgument values. | def state_call(self, addr, *args, **kwargs):
"""
Create a native or a Java call state.
:param addr: Soot or native addr of the invoke target.
:param args: List of SootArgument values.
"""
state = kwargs.pop('base_state', None)
# check if we need to setup a n... |
Java specify defaults values for primitive and reference types. This
method returns the default value for a given type.
:param str type_: Name of type.
:return: Default value for this type. | def get_default_value_by_type(type_, state=None):
"""
Java specify defaults values for primitive and reference types. This
method returns the default value for a given type.
:param str type_: Name of type.
:return: Default value for this type.
"""
if... |
Cast the value of primtive types.
:param value: Bitvector storing the primitive value.
:param to_type: Name of the targeted type.
:return: Resized value. | def cast_primitive(state, value, to_type):
"""
Cast the value of primtive types.
:param value: Bitvector storing the primitive value.
:param to_type: Name of the targeted type.
:return: Resized value.
"""
if to_type in ['float', 'double']:
... |
Initialize the static field with an allocated, but not initialized,
object of the given type.
:param state: State associated to the field.
:param field_class_name: Class containing the field.
:param field_name: Name of the field.
:param field_type: Type of the field and the new ... | def init_static_field(state, field_class_name, field_name, field_type):
"""
Initialize the static field with an allocated, but not initialized,
object of the given type.
:param state: State associated to the field.
:param field_class_name: Class containing the field.
:pa... |
Get address of the implementation from a native declared Java function.
:param soot_method: Method descriptor of a native declared function.
:return: CLE address of the given method. | def get_addr_of_native_method(self, soot_method):
"""
Get address of the implementation from a native declared Java function.
:param soot_method: Method descriptor of a native declared function.
:return: CLE address of the given method.
"""
for name, symbol in self.nativ... |
Maps the Java type to a SimTypeReg representation of its native
counterpart. This type can be used to indicate the (well-defined) size
of native JNI types.
:return: A SymTypeReg with the JNI size of the given type. | def get_native_type(self, java_type):
"""
Maps the Java type to a SimTypeReg representation of its native
counterpart. This type can be used to indicate the (well-defined) size
of native JNI types.
:return: A SymTypeReg with the JNI size of the given type.
"""
if... |
:return: SimCC object for the native simos. | def get_native_cc(self, func_ty=None):
"""
:return: SimCC object for the native simos.
"""
native_cc_cls = DEFAULT_CC[self.native_simos.arch.name]
return native_cc_cls(self.native_simos.arch, func_ty=func_ty) |
Fill the class with constrained symbolic values. | def fill_symbolic(self):
"""
Fill the class with constrained symbolic values.
"""
self.wYear = self.state.solver.BVS('cur_year', 16, key=('api', 'GetLocalTime', 'cur_year'))
self.wMonth = self.state.solver.BVS('cur_month', 16, key=('api', 'GetLocalTime', 'cur_month'))
sel... |
Fill the class with the appropriate values extracted from the given timestamp.
:param ts: A POSIX timestamp. | def fill_from_timestamp(self, ts):
"""
Fill the class with the appropriate values extracted from the given timestamp.
:param ts: A POSIX timestamp.
"""
dt = datetime.datetime.fromtimestamp(ts)
self.wYear = dt.year
self.wMonth = dt.month
self.wDayOfWeek =... |
Initialize this AnnotatedCFG object with a networkx.DiGraph consisting of the following
form of nodes:
Tuples like (block address, statement ID)
Those nodes are connected by edges indicating the execution flow.
:param networkx.DiGraph digraph: A networkx.DiGraph object | def from_digraph(self, digraph):
"""
Initialize this AnnotatedCFG object with a networkx.DiGraph consisting of the following
form of nodes:
Tuples like (block address, statement ID)
Those nodes are connected by edges indicating the execution flow.
:param networkx.DiGra... |
:returns: True if all statements are whitelisted | def get_whitelisted_statements(self, addr):
"""
:returns: True if all statements are whitelisted
"""
if addr in self._run_statement_whitelist:
if self._run_statement_whitelist[addr] is True:
return None # This is the default value used to say
... |
Pretty-print an IRSB with whitelist information | def dbg_print_irsb(self, irsb_addr, project=None):
"""
Pretty-print an IRSB with whitelist information
"""
if project is None:
project = self._project
if project is None:
raise Exception("Dict addr_to_run is empty. " + \
"Give... |
Given a path, returns True if the path should be kept, False if it should be cut. | def keep_path(self, path):
"""
Given a path, returns True if the path should be kept, False if it should be cut.
"""
if len(path.addr_trace) < 2:
return True
return self.should_take_exit(path.addr_trace[-2], path.addr_trace[-1]) |
Callback routine that takes in a path, and returns all feasible successors to path group. This callback routine
should be passed to the keyword argument "successor_func" of PathGroup.step().
:param path: A Path instance.
:return: A list of all feasible Path successors. | def successor_func(self, path):
"""
Callback routine that takes in a path, and returns all feasible successors to path group. This callback routine
should be passed to the keyword argument "successor_func" of PathGroup.step().
:param path: A Path instance.
:return: A list of all... |
Convert to a ValueSet instance
:param state: A state
:return: The converted ValueSet instance | def to_valueset(self, state):
"""
Convert to a ValueSet instance
:param state: A state
:return: The converted ValueSet instance
"""
return state.solver.VS(state.arch.bits, self.region, self.region_base_addr, self.address) |
Add a mapping between an absolute address and a region ID. If this is a stack region map, all stack regions
beyond (lower than) this newly added regions will be discarded.
:param absolute_address: An absolute memory address.
:param region_id: ID of the memory region... | def map(self, absolute_address, region_id, related_function_address=None):
"""
Add a mapping between an absolute address and a region ID. If this is a stack region map, all stack regions
beyond (lower than) this newly added regions will be discarded.
:param absolute_address: ... |
Removes a mapping based on its absolute address.
:param absolute_address: An absolute address | def unmap_by_address(self, absolute_address):
"""
Removes a mapping based on its absolute address.
:param absolute_address: An absolute address
"""
desc = self._address_to_region_id[absolute_address]
del self._address_to_region_id[absolute_address]
del self._reg... |
Convert a relative address in some memory region to an absolute address.
:param region_id: The memory region ID
:param relative_address: The relative memory offset in that memory region
:return: An absolute address if converted, or an exception is raised when reg... | def absolutize(self, region_id, relative_address):
"""
Convert a relative address in some memory region to an absolute address.
:param region_id: The memory region ID
:param relative_address: The relative memory offset in that memory region
:return: ... |
Convert an absolute address to the memory offset in a memory region.
Note that if an address belongs to heap region is passed in to a stack region map, it will be converted to an
offset included in the closest stack frame, and vice versa for passing a stack address to a heap region.
Therefore y... | def relativize(self, absolute_address, target_region_id=None):
"""
Convert an absolute address to the memory offset in a memory region.
Note that if an address belongs to heap region is passed in to a stack region map, it will be converted to an
offset included in the closest stack fram... |
Return the category of this SimMemory instance. It can be one of the three following categories: reg, mem,
or file. | def category(self):
"""
Return the category of this SimMemory instance. It can be one of the three following categories: reg, mem,
or file.
"""
if self.id in ('reg', 'mem'):
return self.id
elif self._abstract_backer:
return 'mem'
elif se... |
Call the set_state method in SimStatePlugin class, and then perform the delayed initialization.
:param state: The SimState instance | def set_state(self, state):
"""
Call the set_state method in SimStatePlugin class, and then perform the delayed initialization.
:param state: The SimState instance
"""
SimStatePlugin.set_state(self, state)
# Delayed initialization
stack_region_map, generic_regio... |
Make an AST out of concrete @data_e | def _convert_to_ast(self, data_e, size_e=None):
"""
Make an AST out of concrete @data_e
"""
if type(data_e) is bytes:
# Convert the string into a BVV, *regardless of endness*
bits = len(data_e) * self.state.arch.byte_width
data_e = self.state.solver.BV... |
Create a new mapping between an absolute address (which is the base address of a specific stack frame) and a
region ID.
:param absolute_address: The absolute memory address.
:param region_id: The region ID.
:param related_function_address: Related function address. | def set_stack_address_mapping(self, absolute_address, region_id, related_function_address=None):
"""
Create a new mapping between an absolute address (which is the base address of a specific stack frame) and a
region ID.
:param absolute_address: The absolute memory address.
:par... |
Remove a stack mapping.
:param absolute_address: An absolute memory address, which is the base address of the stack frame to destroy. | def unset_stack_address_mapping(self, absolute_address):
"""
Remove a stack mapping.
:param absolute_address: An absolute memory address, which is the base address of the stack frame to destroy.
"""
if self._stack_region_map is None:
raise SimMemoryError('Stack regio... |
Return a memory region ID for a function. If the default region ID exists in the region mapping, an integer
will appended to the region name. In this way we can handle recursive function calls, or a function that
appears more than once in the call frame.
This also means that `stack_id()` should... | def stack_id(self, function_address):
"""
Return a memory region ID for a function. If the default region ID exists in the region mapping, an integer
will appended to the region name. In this way we can handle recursive function calls, or a function that
appears more than once in the cal... |
Stores content into memory.
:param addr: A claripy expression representing the address to store at.
:param data: The data to store (claripy expression or something convertable to a claripy expression).
:param size: A claripy expression representing the size of the data to s... | def store(self, addr, data, size=None, condition=None, add_constraints=None, endness=None, action=None,
inspect=True, priv=None, disable_actions=False):
"""
Stores content into memory.
:param addr: A claripy expression representing the address to store at.
:param da... |
Stores content into memory, conditional by case.
:param addr: A claripy expression representing the address to store at.
:param contents: A list of bitvectors, not necessarily of the same size. Use None to denote an empty
write.
:param condition... | def store_cases(self, addr, contents, conditions, fallback=None, add_constraints=None, endness=None, action=None):
"""
Stores content into memory, conditional by case.
:param addr: A claripy expression representing the address to store at.
:param contents: A list of bi... |
Loads size bytes from dst.
:param dst: The address to load from.
:param size: The size (in bytes) of the load.
:param condition: A claripy expression representing a condition for a conditional load.
:param fallback: A fallback value if the condition e... | def load(self, addr, size=None, condition=None, fallback=None, add_constraints=None, action=None, endness=None,
inspect=True, disable_actions=False, ret_on_segv=False):
"""
Loads size bytes from dst.
:param dst: The address to load from.
:param size: ... |
Returns the address of bytes equal to 'what', starting from 'start'. Note that, if you don't specify a default
value, this search could cause the state to go unsat if no possible matching byte exists.
:param addr: The start address.
:param what: What to search for;... | def find(self, addr, what, max_search=None, max_symbolic_bytes=None, default=None, step=1,
disable_actions=False, inspect=True, chunk_size=None):
"""
Returns the address of bytes equal to 'what', starting from 'start'. Note that, if you don't specify a default
value, this search co... |
Copies data within a memory.
:param dst: A claripy expression representing the address of the destination
:param src: A claripy expression representing the address of the source
The following parameters are optional.
:param src_memory: Copy data from this SimMemory in... | def copy_contents(self, dst, src, size, condition=None, src_memory=None, dst_memory=None, inspect=True,
disable_actions=False):
"""
Copies data within a memory.
:param dst: A claripy expression representing the address of the destination
:param src: ... |
Pretty print the graph. @imarks determine whether the printed graph
represents instructions (coarse grained) for easier navigation, or
exact statements. | def pp(self, imarks=False):
"""
Pretty print the graph. @imarks determine whether the printed graph
represents instructions (coarse grained) for easier navigation, or
exact statements.
"""
for e in self.graph.edges():
data = dict(self.graph.get_edge_data(e[0... |
Gets vfg node at @addr
Returns VFGNode or None | def _vfg_node(self, addr):
"""
Gets vfg node at @addr
Returns VFGNode or None
"""
for n in self._vfg._nodes.values():
if n.addr == addr:
return n
raise DataGraphError("No VFG node at 0x%x" % addr) |
Recursive function, it branches in every possible path in the VFG.
@live_defs: a dict {addr:stmt} of live definitions at the start point
@node: the starting vfg node
Returns: the address of the block where the execution stops | def _branch(self, live_defs, node, path=""):
"""
Recursive function, it branches in every possible path in the VFG.
@live_defs: a dict {addr:stmt} of live definitions at the start point
@node: the starting vfg node
Returns: the address of the block where the execution stops
... |
Get a list of abstract locations that is within the range of [addr, addr + size]
This implementation is pretty slow. But since this method won't be called frequently, we can live with the bad
implementation for now.
:param addr: Starting address of the memory region.
:param size: ... | def get_abstract_locations(self, addr, size):
"""
Get a list of abstract locations that is within the range of [addr, addr + size]
This implementation is pretty slow. But since this method won't be called frequently, we can live with the bad
implementation for now.
:param addr:... |
Helper function for merging. | def _merge_alocs(self, other_region):
"""
Helper function for merging.
"""
merging_occurred = False
for aloc_id, aloc in other_region.alocs.items():
if aloc_id not in self.alocs:
self.alocs[aloc_id] = aloc.copy()
merging_occurred = True... |
Print out debugging information | def dbg_print(self, indent=0):
"""
Print out debugging information
"""
print("%sA-locs:" % (" " * indent))
for aloc_id, aloc in self._alocs.items():
print("%s<0x%x> %s" % (" " * (indent + 2), aloc_id, aloc))
print("%sMemory:" % (" " * indent))
self.me... |
Get the base address of a memory region.
:param str region: ID of the memory region
:return: Address of the memory region
:rtype: int | def _region_base(self, region):
"""
Get the base address of a memory region.
:param str region: ID of the memory region
:return: Address of the memory region
:rtype: int
"""
if region == 'global':
region_base_addr = 0
elif region.startswith('... |
Create a new MemoryRegion with the region key specified, and store it to self._regions.
:param key: a string which is the region key
:param state: the SimState instance
:param bool is_stack: Whether this memory region is on stack. True/False
:param related_function_addr: Which function ... | def create_region(self, key, state, is_stack, related_function_addr, endness, backer_dict=None):
"""
Create a new MemoryRegion with the region key specified, and store it to self._regions.
:param key: a string which is the region key
:param state: the SimState instance
:param bo... |
If this is a stack address, we convert it to a correct region and address
:param region_id: a string indicating which region the address is relative to
:param relative_address: an address that is relative to the region parameter
:param target_region: the ideal target region that address is norm... | def _normalize_address(self, region_id, relative_address, target_region=None):
"""
If this is a stack address, we convert it to a correct region and address
:param region_id: a string indicating which region the address is relative to
:param relative_address: an address that is relative... |
Overriding the SimStatePlugin.set_state() method
:param state: A SimState object
:return: None | def set_state(self, state):
"""
Overriding the SimStatePlugin.set_state() method
:param state: A SimState object
:return: None
"""
# Sanity check
if REGION_MAPPING not in state.options:
# add REGION_MAPPING into state.options
l.warning('O... |
Convert a ValueSet object into a list of addresses.
:param addr: A ValueSet object (which describes an address)
:param is_write: Is this address used in a write or not
:param convert_to_valueset: True if you want to have a list of ValueSet instances instead of AddressWrappers,
... | def normalize_address(self, addr, is_write=False, convert_to_valueset=False, target_region=None, condition=None): #pylint:disable=arguments-differ
"""
Convert a ValueSet object into a list of addresses.
:param addr: A ValueSet object (which describes an address)
:param is_write: Is this... |
Convert address of different types to a list of mapping between region IDs and offsets (strided intervals).
:param claripy.ast.Base addr: Address to convert
:return: A list of mapping between region IDs and offsets.
:rtype: dict | def _normalize_address_type(self, addr): #pylint:disable=no-self-use
"""
Convert address of different types to a list of mapping between region IDs and offsets (strided intervals).
:param claripy.ast.Base addr: Address to convert
:return: A list of mapping between region IDs and offsets... |
Get a segmented memory region based on AbstractLocation information available from VSA.
Here are some assumptions to make this method fast:
- The entire memory region [addr, addr + size] is located within the same MemoryRegion
- The address 'addr' has only one concrete value. It cannot ... | def get_segments(self, addr, size):
"""
Get a segmented memory region based on AbstractLocation information available from VSA.
Here are some assumptions to make this method fast:
- The entire memory region [addr, addr + size] is located within the same MemoryRegion
- Th... |
Make a copy of this SimAbstractMemory object
:return: | def copy(self, memo):
"""
Make a copy of this SimAbstractMemory object
:return:
"""
am = SimAbstractMemory(
memory_id=self._memory_id,
endness=self.endness,
stack_region_map=self._stack_region_map,
generic_region_map=self._generic_r... |
Merge this guy with another SimAbstractMemory instance | def merge(self, others, merge_conditions, common_ancestor=None):
"""
Merge this guy with another SimAbstractMemory instance
"""
merging_occurred = False
for o in others:
for region_id, region in o._regions.items():
if region_id in self._regions:
... |
Print out debugging information | def dbg_print(self):
"""
Print out debugging information
"""
for region_id, region in self.regions.items():
print("Region [%s]:" % region_id)
region.dbg_print(indent=2) |
Initialize ptable for ctype
See __ctype_toupper_loc.c in libc implementation | def _initialize_toupper_loc_table(self):
"""
Initialize ptable for ctype
See __ctype_toupper_loc.c in libc implementation
"""
malloc = angr.SIM_PROCEDURES['libc']['malloc']
# 384 entries, 4 bytes each
table = self.inline_call(malloc, 384*4).ret_expr
table... |
Extract arguments and set them to
:param angr.sim_state.SimState state: The program state.
:param main: An argument to __libc_start_main.
:param argc: An argument to __libc_start_main.
:param argv: An argument to __libc_start_main.
:param init: An argument to __libc_start_main.
... | def _extract_args(state, main, argc, argv, init, fini):
"""
Extract arguments and set them to
:param angr.sim_state.SimState state: The program state.
:param main: An argument to __libc_start_main.
:param argc: An argument to __libc_start_main.
:param argv: An argument t... |
Debugging output of this slice.
:param max_display: The maximum number of SimRun slices to show.
:return: A string representation. | def dbg_repr(self, max_display=10):
"""
Debugging output of this slice.
:param max_display: The maximum number of SimRun slices to show.
:return: A string representation.
"""
s = repr(self) + "\n"
if len(self.chosen_statements) > max_display:
... |
Debugging output of a single SimRun slice.
:param run_addr: Address of the SimRun.
:return: A string representation. | def dbg_repr_run(self, run_addr):
"""
Debugging output of a single SimRun slice.
:param run_addr: Address of the SimRun.
:return: A string representation.
"""
if self.project.is_hooked(run_addr):
ss = "%#x Hooked\n" % run_addr
else:
... |
Returns an AnnotatedCFG based on slicing result. | def annotated_cfg(self, start_point=None):
"""
Returns an AnnotatedCFG based on slicing result.
"""
# TODO: Support context-sensitivity
targets = [ ]
for simrun, stmt_idx in self._targets:
targets.append((simrun.addr, stmt_idx))
l.debug("Initializi... |
Query in taint graph to check if a specific taint will taint the IP in the future or not.
The taint is specified with the tuple (simrun_addr, stmt_idx, taint_type).
:param simrun_addr: Address of the SimRun.
:param stmt_idx: Statement ID.
:param taint_type: T... | def is_taint_related_to_ip(self, simrun_addr, stmt_idx, taint_type, simrun_whitelist=None):
"""
Query in taint graph to check if a specific taint will taint the IP in the future or not.
The taint is specified with the tuple (simrun_addr, stmt_idx, taint_type).
:param simrun_addr: ... |
Construct a dependency graph based on given parameters.
:param targets: A list of tuples like (CFGNode, statement ID)
:param control_flow_slice: Is the backward slicing only depends on CFG or not. | def _construct(self, targets, control_flow_slice=False):
"""
Construct a dependency graph based on given parameters.
:param targets: A list of tuples like (CFGNode, statement ID)
:param control_flow_slice: Is the backward slicing only depends on CFG or not.
"""
... |
Build a slice of the program without considering the effect of data dependencies.
This is an incorrect hack, but it should work fine with small programs.
:param simruns: A list of SimRun targets. You probably wanna get it from the CFG somehow. It must exist in the
CFG. | def _construct_control_flow_slice(self, simruns):
"""
Build a slice of the program without considering the effect of data dependencies.
This is an incorrect hack, but it should work fine with small programs.
:param simruns: A list of SimRun targets. You probably wanna get it from the CF... |
Create a backward slice from a specific statement in a specific block. This is done by traverse the CFG
backwards, and mark all tainted statements based on dependence graphs (CDG and DDG) provided initially. The
traversal terminated when we reach the entry point, or when there is no unresolved dependenc... | def _construct_default(self, targets):
"""
Create a backward slice from a specific statement in a specific block. This is done by traverse the CFG
backwards, and mark all tainted statements based on dependence graphs (CDG and DDG) provided initially. The
traversal terminated when we reac... |
Based on control dependence graph, pick all exits (statements) that lead to the target.
:param target_node: A CFGNode instance.
:returns: A set of new tainted code locations. | def _handle_control_dependence(self, target_node):
"""
Based on control dependence graph, pick all exits (statements) that lead to the target.
:param target_node: A CFGNode instance.
:returns: A set of new tainted code locations.
"""
new_taints = set()
... |
Source block has more than one exit, and through some of those exits, the control flow can eventually go to
the target block. This method returns exits that lead to the target block.
:param src_block: The block that has multiple exits.
:param target_block: The target block to reach.
... | def _find_exits(self, src_block, target_block):
"""
Source block has more than one exit, and through some of those exits, the control flow can eventually go to
the target block. This method returns exits that lead to the target block.
:param src_block: The block that has multiple ... |
Map our current slice to CFG.
Based on self._statements_per_run and self._exit_statements_per_run, this method will traverse the CFG and
check if there is any missing block on the path. If there is, the default exit of that missing block will be
included in the slice. This is because Slicecutor... | def _map_to_cfg(self):
"""
Map our current slice to CFG.
Based on self._statements_per_run and self._exit_statements_per_run, this method will traverse the CFG and
check if there is any missing block on the path. If there is, the default exit of that missing block will be
includ... |
Include a statement in the final slice.
:param int block_address: Address of the basic block.
:param int stmt_idx: Statement ID. | def _pick_statement(self, block_address, stmt_idx):
"""
Include a statement in the final slice.
:param int block_address: Address of the basic block.
:param int stmt_idx: Statement ID.
"""
# TODO: Support context-sensitivity
# Sanity check
if n... |
Include an exit in the final slice.
:param block_address: Address of the basic block.
:param stmt_idx: ID of the exit statement.
:param target_ips: The target address of this exit statement. | def _pick_exit(self, block_address, stmt_idx, target_ips):
"""
Include an exit in the final slice.
:param block_address: Address of the basic block.
:param stmt_idx: ID of the exit statement.
:param target_ips: The target address of this exit statement.
"""... |
Return a list of conditional statement exits with respect to a basic block.
:param block_addr: The address of the basic block.
:return: A list of statement IDs. | def _conditional_exits(self, block_addr):
"""
Return a list of conditional statement exits with respect to a basic block.
:param block_addr: The address of the basic block.
:return: A list of statement IDs.
"""
vex_block = self.project.factory.block(block_ad... |
For each statement ID, convert 'default' to (last_stmt_idx+1)
:param block_addr: The block address.
:param stmt_idx: Statement ID.
:returns: New statement ID. | def _normalize_stmt_idx(self, block_addr, stmt_idx):
"""
For each statement ID, convert 'default' to (last_stmt_idx+1)
:param block_addr: The block address.
:param stmt_idx: Statement ID.
:returns: New statement ID.
"""
if type(stmt_idx) is int:
... |
Search for the last branching exit, just like
# if (t12) { PUT(184) = 0xBADF00D:I64; exit-Boring }
and then taint the temp variable inside if predicate | def _last_branching_statement(statements):
"""
Search for the last branching exit, just like
# if (t12) { PUT(184) = 0xBADF00D:I64; exit-Boring }
and then taint the temp variable inside if predicate
"""
cmp_stmt_id = None
cmp_tmp_id = None
total_stmts = ... |
Returns the address of the methods basic block that contains the given
instruction.
:param instr: The index of the instruction (within the current method).
:rtype: SootAddressDescriptor | def _get_bb_addr_from_instr(self, instr):
"""
Returns the address of the methods basic block that contains the given
instruction.
:param instr: The index of the instruction (within the current method).
:rtype: SootAddressDescriptor
"""
current_method = self.state... |
The default uninitialized read handler. Returns symbolic bytes. | def _handle_uninitialized_read(self, addr, inspect=True, events=True):
"""
The default uninitialized read handler. Returns symbolic bytes.
"""
if self._uninitialized_read_handler is None:
v = self.state.solver.Unconstrained("%s_%s" % (self.id, addr), self.width*self.state.arc... |
Resolves this address. | def _translate_addr(self, a): #pylint:disable=no-self-use
"""
Resolves this address.
"""
if isinstance(a, claripy.ast.Base) and not a.singlevalued:
raise SimFastMemoryError("address not supported")
return self.state.solver.eval(a) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.