text
stringlengths
81
112k
Returns the provider's name of the credit card. def credit_card_provider(self, card_type=None): """ Returns the provider's name of the credit card. """ if card_type is None: card_type = self.random_element(self.credit_card_types.keys()) return self._credit_card_type(card_type).name
Returns a valid credit card number. def credit_card_number(self, card_type=None): """ Returns a valid credit card number. """ card = self._credit_card_type(card_type) prefix = self.random_element(card.prefixes) number = self._generate_number(self.numerify(prefix), card.length) r...
Returns a security code string. def credit_card_security_code(self, card_type=None): """ Returns a security code string. """ sec_len = self._credit_card_type(card_type).security_code_length return self.numerify('#' * sec_len)
Returns a random credit card type instance. def _credit_card_type(self, card_type=None): """ Returns a random credit card type instance. """ if card_type is None: card_type = self.random_element(self.credit_card_types.keys()) elif isinstance(card_type, CreditCard): retur...
'prefix' is the start of the CC number as a string, any number of digits. 'length' is the length of the CC number to generate. Typically 13 or 16 def _generate_number(self, prefix, length): """ 'prefix' is the start of the CC number as a string, any number of digits. 'length' is the len...
Returns Finnish company Business Identity Code (y-tunnus). Format is 8 digits - e.g. FI99999999,[8] last digit is a check digit utilizing MOD 11-2. The first digit is zero for some old organizations. This function provides current codes starting with non-zero. def company_business_id(se...
Returns a 11 digits Belgian SSN called "rijksregisternummer" as a string The first 6 digits represent the birthdate with (in order) year, month and day. The second group of 3 digits is represents a sequence number (order of birth). It is even for women and odd for men. For men the range...
:example 세종특별자치시 어진동 507 def land_address(self): """ :example 세종특별자치시 어진동 507 """ pattern = self.random_element(self.land_address_formats) return self.generator.parse(pattern)
:example 세종특별자치시 도움5로 19 (어진동) def road_address(self): """ :example 세종특별자치시 도움5로 19 (어진동) """ pattern = self.random_element(self.road_address_formats) return self.generator.parse(pattern)
:example 가나아파트 가동 102호 def address_detail(self): """ :example 가나아파트 가동 102호 """ pattern = self.bothify(self.random_element( self.address_detail_formats)) return self.generator.parse(pattern)
:example 도움5로 def road(self): """ :example 도움5로 """ pattern = self.random_element(self.road_formats) return self.generator.parse(pattern)
:example 고양시 def city(self): """ :example 고양시 """ pattern = self.random_element(self.cities) return self.generator.parse(pattern)
:example 가나동 def town(self): """ :example 가나동 """ pattern = self.random_element(self.town_formats) return self.generator.parse(pattern)
:example 김구아파트 def building_name(self): """ :example 김구아파트 """ pattern = self.random_element(self.building_name_formats) return self.generator.parse(pattern)
Determine validity of a Canadian Social Insurance Number. Validation is performed using a modified Luhn Algorithm. To check the Every second digit of the SIN is doubled and the result is summed. If the result is a multiple of ten, the Social Insurance Number is considered valid. https://en.wikipe...
Produce a hostname with specified number of subdomain levels. >>> hostname() db-01.nichols-phillips.com >>> hostname(0) laptop-56 >>> hostname(2) web-12.williamson-hopkins.jackson.com def hostname(self, levels=1): """ Produce a hostname with specified nu...
Produce an Internet domain name with the specified number of subdomain levels. >>> domain_name() nichols-phillips.com >>> domain_name(2) williamson-hopkins.jackson.com def domain_name(self, levels=1): """ Produce an Internet domain name with the specified number...
:param schemes: a list of strings to use as schemes, one will chosen randomly. If None, it will generate http and https urls. Passing an empty list will result in schemeless url generation like "://domain.com". :returns: a random url string. def url(self, schemes=None): """ :pa...
Produces a random IPv4 address or network with a valid CIDR from within a given subnet. :param subnet: IPv4Network to choose from within :param network: Return a network address, and not an IP address def _random_ipv4_address_from_subnet(self, subnet, network=False): """ Produc...
Exclude the list of networks from another list of networks and return a flat list of new networks. :param networks: List of IPv4 networks to exclude from :param networks_to_exclude: List of IPv4 networks to exclude :returns: Flat list of IPv4 networks def _exclude_ipv4_networks(self, n...
Produce a random IPv4 address or network with a valid CIDR. :param network: Network address :param address_class: IPv4 address class (a, b, or c) :param private: Public or private :returns: IPv4 def ipv4(self, network=False, address_class=None, private=None): """ Produc...
Returns a private IPv4. :param network: Network address :param address_class: IPv4 address class (a, b, or c) :returns: Private IPv4 def ipv4_private(self, network=False, address_class=None): """ Returns a private IPv4. :param network: Network address :param ad...
Returns a public IPv4 excluding private blocks. :param network: Network address :param address_class: IPv4 address class (a, b, or c) :returns: Public IPv4 def ipv4_public(self, network=False, address_class=None): """ Returns a public IPv4 excluding private blocks. :pa...
Produce a random IPv6 address or network with a valid CIDR def ipv6(self, network=False): """Produce a random IPv6 address or network with a valid CIDR""" address = str(ip_address(self.generator.random.randint( 2 ** IPV4LENGTH, (2 ** IPV6LENGTH) - 1))) if network: addres...
Returns URL to placeholder image Example: http://placehold.it/640x480 def image_url(self, width=None, height=None): """ Returns URL to placeholder image Example: http://placehold.it/640x480 """ width_ = width or self.random_int(max=1024) height_ = height or self....
Calls random.seed def seed_instance(self, seed=None): """Calls random.seed""" if self.__random == random: # create per-instance random obj when first time seed_instance() is # called self.__random = random_module.Random() self.__random.seed(seed) retu...
This is a secure way to make a fake from another Provider. def format(self, formatter, *args, **kwargs): """ This is a secure way to make a fake from another Provider. """ # TODO: data export? return self.get_formatter(formatter)(*args, **kwargs)
Perform a forward execution and perform alias analysis. Note that this analysis is fast, light-weight, and by no means complete. For instance, most arithmetic operations are not supported. - Depending on user settings, stack pointer and stack base pointer will be mocked and propagated to individual ...
Slice it! def _slice(self): """ Slice it! """ regs = set(self._target_regs) tmps = set(self._target_tmps) stack_offsets = set(self._target_stack_offsets) state = SimLightState(regs=regs, temps=tmps, stack_offsets=stack_offsets) for stmt_idx, stmt in re...
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 target. def prepare_function_symbol(self, symbol_name, basic_addr=None): """...
Set the fs register in the angr to the value of the fs register in the concrete process :param state: state which will be modified :param concrete_target: concrete target that will be used to read the fs register :return: None def initialize_segment_register_x64(self, state, ...
Create a GDT in the state memory and populate the segment registers. Rehook the vsyscall address using the real value in the concrete process memory :param state: state which will be modified :param concrete_target: concrete target that will be used to read the fs register ...
Merges this node with the other, returning a new node that spans the both. def merge(self, other): """ Merges this node with the other, returning a new node that spans the both. """ new_node = self.copy() new_node.size += other.size new_node.instruction_addrs += other.in...
Allocates a new array in memory and returns the reference to the base. def new_array(state, element_type, size): """ Allocates a new array in memory and returns the reference to the base. """ size_bounded = SimSootExpr_NewArray._bound_array_size(state, size) # return the referen...
Convert recovered reaching conditions from claripy ASTs to ailment Expressions :return: None def _convert_claripy_bool_ast(self, cond): """ Convert recovered reaching conditions from claripy ASTs to ailment Expressions :return: None """ if isinstance(cond, ailment.Exp...
Extract goto targets from a Jump or a ConditionalJump statement. :param stmt: The statement to analyze. :return: A list of known concrete jump targets. :rtype: list def _extract_jump_targets(stmt): """ Extract goto targets from a Jump or a ConditionalJump stat...
A somewhat faithful implementation of libc `malloc`. :param sim_size: the amount of memory (in bytes) to be allocated :returns: the address of the allocation, or a NULL pointer if the allocation failed def malloc(self, sim_size): """ A somewhat faithful implementation of libc `m...
A somewhat faithful implementation of libc `free`. :param ptr: the location in memory to be freed def free(self, ptr): #pylint:disable=unused-argument """ A somewhat faithful implementation of libc `free`. :param ptr: the location in memory to be freed """ raise NotIm...
A somewhat faithful implementation of libc `calloc`. :param sim_nmemb: the number of elements to allocated :param sim_size: the size of each element (in bytes) :returns: the address of the allocation, or a NULL pointer if the allocation failed def calloc(self, sim_nmemb, sim_size): ...
A somewhat faithful implementation of libc `realloc`. :param ptr: the location in memory to be reallocated :param size: the new size desired for the allocation :returns: the address of the allocation, or a NULL pointer if the allocation was freed or if no new allocation ...
Stack dump is a dump of the stack from gdb, i.e. the result of the following gdb command : ``dump binary memory [stack_dump] [begin_addr] [end_addr]`` We set the stack to the same addresses as the gdb session to avoid pointers corruption. :param stack_dump: The dump file. :param stac...
Heap dump is a dump of the heap from gdb, i.e. the result of the following gdb command: ``dump binary memory [stack_dump] [begin] [end]`` :param heap_dump: The dump file. :param heap_base: The start address of the heap in the gdb session. def set_heap(self, heap_dump, heap_base): ...
Update any data range (most likely use is the data segments of loaded objects) def set_data(self, addr, data_dump): """ Update any data range (most likely use is the data segments of loaded objects) """ data = self._read_data(data_dump) l.info("Set data from 0x%x to %#x", addr, ...
Initialize register values within the state :param regs_dump: The output of ``info registers`` in gdb. def set_regs(self, regs_dump): """ Initialize register values within the state :param regs_dump: The output of ``info registers`` in gdb. """ if self.real_stack_top ...
Adjust bp and sp w.r.t. stack difference between GDB session and angr. This matches sp and bp registers, but there is a high risk of pointers inconsistencies. def _adjust_regs(self): """ Adjust bp and sp w.r.t. stack difference between GDB session and angr. This matches sp and bp regist...
Create a Loop object for a strongly connected graph, and any strongly connected subgraphs, if possible. :param subg: A strongly connected subgraph. :param bigg: The graph which subg is a subgraph of. :return: A list of Loop objects, some of which may be inside others, ...
Return all Loop instances that can be extracted from a graph. :param graph: The graph to analyze. :return: A list of all the Loop instances that were found in the graph. def _parse_loops_from_graph(self, graph): """ Return all Loop instances that can be extracted from a graph...
Resolve the field within the given state. def get_ref(cls, state, obj_alloc_id, field_class_name, field_name, field_type): """ Resolve the field within the given state. """ # resolve field field_class = state.javavm_classloader.get_class(field_class_name) field_id = reso...
:param vector_a: A list of numbers. :param vector_b: A list of numbers. :returns: The euclidean distance between the two vectors. def _euclidean_dist(vector_a, vector_b): """ :param vector_a: A list of numbers. :param vector_b: A list of numbers. :returns: The eu...
:param input_attributes: First dictionary of objects to attribute tuples. :param target_attributes: Second dictionary of blocks to attribute tuples. :returns: A dictionary of objects in the input_attributes to the closest objects in the target_attributes. ...
:param s1: A list or string :param s2: Another list or string :returns: The levenshtein distance between the two def _levenshtein_distance(s1, s2): """ :param s1: A list or string :param s2: Another list or string :returns: The levenshtein distance between the two """ if len(s...
This function calculates the levenshtein distance but allows for elements in the lists to be different by any number in the set acceptable_differences. :param s1: A list. :param s2: Another list. :param acceptable_differences: A set of numbers. If (s2[i]-s1[i]...
:param x: The first element of a possible match. :param y: The second element of a possible match. :param matched_a: The current matches for the first set. :param matched_b: The current matches for the second set. :param attributes_dict_a: The at...
Compares two basic blocks and finds all the constants that differ from the first block to the second. :param block_a: The first block to compare. :param block_b: The second block to compare. :returns: Returns a list of differing constants in the form of ConstantChange, which has the offset in the ...
:returns: Whether or not these two functions are identical. def probably_identical(self): """ :returns: Whether or not these two functions are identical. """ if len(self._unmatched_blocks_from_a | self._unmatched_blocks_from_b) > 0: return False for (a, b) in self._b...
:returns: A list of block matches which appear to be identical def identical_blocks(self): """ :returns: A list of block matches which appear to be identical """ identical_blocks = [] for (block_a, block_b) in self._block_matches: if self.blocks_probably_identical(bl...
:returns: A list of block matches which appear to differ def differing_blocks(self): """ :returns: A list of block matches which appear to differ """ differing_blocks = [] for (block_a, block_b) in self._block_matches: if not self.blocks_probably_identical(block_a, b...
:return: A list of block matches which appear to differ def blocks_with_differing_constants(self): """ :return: A list of block matches which appear to differ """ differing_blocks = [] diffs = dict() for (block_a, block_b) in self._block_matches: if self.bloc...
:param block_a: The first block address. :param block_b: The second block address. :returns: The similarity of the basic blocks, normalized for the base address of the block and function call addresses. def block_similarity(self, block_a, block_b): """ :par...
:param block_a: The first block address. :param block_b: The second block address. :param check_constants: Whether or not to require matching constants in blocks. :returns: Whether or not the blocks appear to be identical. def blocks_probably_identical(self, block_...
:param function: A normalized function object. :returns: A dictionary of basic block addresses to tuples of attributes. def _compute_block_attributes(function): """ :param function: A normalized function object. :returns: A dictionary of basic block addresses t...
:param function: A normalized Function object. :returns: A dictionary of basic block addresses and their distance to the exit of the function. def _distances_from_function_exit(function): """ :param function: A normalized Function object. :returns: A dictionary...
Computes the diff of the functions and saves the result. def _compute_diff(self): """ Computes the diff of the functions and saves the result. """ # get the attributes for all blocks l.debug("Computing diff of functions: %s, %s", ("%#x" % self._function_a.startpo...
:param attributes_a: A dict of blocks to their attributes :param attributes_b: A dict of blocks to their attributes The following parameters are optional. :param filter_set_a: A set to limit attributes_a to the blocks in this set. :param filter_set_b: A set to limit attribu...
Compare two functions and return True if they appear identical. :param func_a_addr: The address of the first function (in the first binary). :param func_b_addr: The address of the second function (in the second binary). :returns: Whether or not the functions appear to be identical. d...
:returns: A list of function matches that appear to be identical def identical_functions(self): """ :returns: A list of function matches that appear to be identical """ identical_funcs = [] for (func_a, func_b) in self.function_matches: if self.functions_probably_ide...
:returns: A list of function matches that appear to differ def differing_functions(self): """ :returns: A list of function matches that appear to differ """ different_funcs = [] for (func_a, func_b) in self.function_matches: if not self.functions_probably_identical(f...
:return: A list of function matches that appear to differ including just by constants def differing_functions_with_consts(self): """ :return: A list of function matches that appear to differ including just by constants """ different_funcs = [] for (func_a, func_b) in self.functi...
:returns: A list of block matches that appear to differ def differing_blocks(self): """ :returns: A list of block matches that appear to differ """ differing_blocks = [] for (func_a, func_b) in self.function_matches: differing_blocks.extend(self.get_function_diff(fun...
:return A list of all block matches that appear to be identical def identical_blocks(self): """ :return A list of all block matches that appear to be identical """ identical_blocks = [] for (func_a, func_b) in self.function_matches: identical_blocks.extend(self.get_f...
:return: A dict of block matches with differing constants to the tuple of constants def blocks_with_differing_constants(self): """ :return: A dict of block matches with differing constants to the tuple of constants """ diffs = dict() for (func_a, func_b) in self.function_matches...
:param function_addr_a: The address of the first function (in the first binary) :param function_addr_b: The address of the second function (in the second binary) :returns: the FunctionDiff of the two functions def get_function_diff(self, function_addr_a, function_addr_b): """ :param fun...
:param cfg: An angr CFG object :returns: a dictionary of function addresses to tuples of attributes def _compute_function_attributes(cfg): """ :param cfg: An angr CFG object :returns: a dictionary of function addresses to tuples of attributes """ # the attributes w...
:param attributes_a: A dict of functions to their attributes :param attributes_b: A dict of functions to their attributes The following parameters are optional. :param filter_set_a: A set to limit attributes_a to the functions in this set. :param filter_set_b: A set to limi...
Load a new project based on a string of raw bytecode. :param shellcode: The data to load :param arch: The name of the arch to use, or an archinfo class :param start_offset: The offset into the data to start analysis (default 0) :param load_address: The address to place the data i...
This scans through an objects imports and hooks them with simprocedures from our library whenever possible def _register_object(self, obj, sim_proc_arch): """ This scans through an objects imports and hooks them with simprocedures from our library whenever possible """ # Step 1: get th...
Does symbol name `f` exist as a SIM_PROCEDURE? If so, return it, else return None. Narrows down the set of libraries to search based on hint. Part of the hack to enable Binary Ninja support. Remove if _register_objects() stops using it. def _guess_simprocedure(self, f, hint): """ Does s...
Has symbol name `f` been marked for exclusion by any of the user parameters? def _check_user_blacklists(self, f): """ Has symbol name `f` been marked for exclusion by any of the user parameters? """ return not self._should_use_sim_procedures or \ f in self._e...
Hook a section of code with a custom function. This is used internally to provide symbolic summaries of library functions, and can be used to instrument execution or to modify control flow. When hook is not specified, it returns a function decorator that allows easy hooking. Usage:: ...
Returns the current hook for `addr`. :param addr: An address. :returns: None if the address is not hooked. def hooked_by(self, addr): """ Returns the current hook for `addr`. :param addr: An address. :returns: None if the address is not hooked. """ ...
Remove a hook. :param addr: The address of the hook. def unhook(self, addr): """ Remove a hook. :param addr: The address of the hook. """ if not self.is_hooked(addr): l.warning("Address %s not hooked", self._addr_to_str(addr)) return ...
Resolve a dependency in a binary. Looks up the address of the given symbol, and then hooks that address. If the symbol was not available in the loaded libraries, this address may be provided by the CLE externs object. Additionally, if instead of a symbol name you provide an address, some secret...
Check if a symbol is already hooked. :param str symbol_name: Name of the symbol. :return: True if the symbol can be resolved and is hooked, False otherwise. :rtype: bool def is_symbol_hooked(self, symbol_name): """ Check if a symbol is already hooked. :param str symbol...
Remove the hook on a symbol. This function will fail if the symbol is provided by the extern object, as that would result in a state where analysis would be unable to cope with a call to this symbol. def unhook_symbol(self, symbol_name): """ Remove the hook on a symbol. This fun...
Move the hook for a symbol to a specific address :param new_address: the new address that will trigger the SimProc execution :param symbol_name: the name of the symbol (f.i. strcmp ) :return: None def rehook_symbol(self, new_address, symbol_name): """ Move the hook for a symbol ...
This function is a symbolic execution helper in the simple style supported by triton and manticore. It designed to be run after setting up hooks (see Project.hook), in which the symbolic state can be checked. This function can be run in three different ways: - When run with...
Return a function decorator that allows easy hooking. Please refer to hook() for its usage. :return: The function decorator. def _hook_decorator(self, addr, length=0, kwargs=None): """ Return a function decorator that allows easy hooking. Please refer to hook() for its usage. :return:...
Indicates if the project's main binary is a Java Archive. def is_java_project(self): """ Indicates if the project's main binary is a Java Archive. """ if self._is_java_project is None: self._is_java_project = isinstance(self.arch, ArchSoot) return self._is_java_proje...
Indicates if the project's main binary is a Java Archive, which interacts during its execution with native libraries (via JNI). def is_java_jni_project(self): """ Indicates if the project's main binary is a Java Archive, which interacts during its execution with native libraries (via JN...
Register a preset instance with the class of the hub it corresponds to. This allows individual plugin objects to automatically register themselves with a preset by using a classmethod of their own with only the name of the preset to register with. def register_preset(cls, name, preset): """ ...
Apply a preset to the hub. If there was a previously active preset, discard it. Preset can be either the string name of a preset or a PluginPreset instance. def use_plugin_preset(self, preset): """ Apply a preset to the hub. If there was a previously active preset, discard it. Preset ...
Discard the current active preset. Will release any active plugins that could have come from the old preset. def discard_plugin_preset(self): """ Discard the current active preset. Will release any active plugins that could have come from the old preset. """ if self.has_plugin_preset: ...
Get the plugin named ``name``. If no such plugin is currently active, try to activate a new one using the current preset. def get_plugin(self, name): """ Get the plugin named ``name``. If no such plugin is currently active, try to activate a new one using the current preset. """...
Add a new plugin ``plugin`` with name ``name`` to the active plugins. def register_plugin(self, name, plugin): """ Add a new plugin ``plugin`` with name ``name`` to the active plugins. """ if self.has_plugin(name): self.release_plugin(name) self._active_plugins[name]...
Deactivate and remove the plugin with name ``name``. def release_plugin(self, name): """ Deactivate and remove the plugin with name ``name``. """ plugin = self._active_plugins[name] if id(plugin) in self._provided_by_preset: self._provided_by_preset.remove(id(plugin)...
Return a copy of self. def copy(self): """ Return a copy of self. """ cls = self.__class__ result = cls.__new__(cls) result._default_plugins = dict(self._default_plugins) # pylint:disable=protected-access return result
Grabs the concretized result so we can add the constraint ourselves. def _grab_concretization_results(cls, state): """ Grabs the concretized result so we can add the constraint ourselves. """ # only grab ones that match the constrained addrs if cls._should_add_constraints(state)...
Check to see if the current address concretization variable is any of the registered constrained_addrs we want to allow concretization for def _should_add_constraints(cls, state): """ Check to see if the current address concretization variable is any of the registered constrained_addrs ...
The actual allocation primitive for this heap implementation. Increases the position of the break to allocate space. Has no guards against the heap growing too large. :param sim_size: a size specifying how much to increase the break pointer by :returns: a pointer to the previous break position,...
The memory release primitive for this heap implementation. Decreases the position of the break to deallocate space. Guards against releasing beyond the initial heap base. :param sim_size: a size specifying how much to decrease the break pointer by (may be symbolic or not) def release(self, sim_size): ...