def __init__(self, root_node, node_consumer, make_determinist=False, make_random=False, max_steps=-1, initial_step=1): self._root_node = root_node self._root_node.make_finite(all_conf=True, recursive=True) if make_determinist: assert(not make_random) self._root_node.make_determinist(all_conf=True, recursive=True) elif make_random: assert(not make_determinist) self._root_node.make_random(all_conf=True, recursive=True) self._root_node.freeze() self._max_steps = int(max_steps) self._initial_step = int(initial_step) assert(self._max_steps > 0 or self._max_steps == -1) self.ic = dm.NodeInternalsCriteria(mandatory_attrs=[dm.NodeInternals.Mutable, dm.NodeInternals.Finite]) self.triglast_ic = dm.NodeInternalsCriteria(mandatory_attrs=[dm.NodeInternals.TriggerLast]) self.consumed_node_path = None self.set_consumer(node_consumer)
def __init__(self, root_node, node_consumer, make_determinist=False, make_random=False, max_steps=-1, initial_step=1): self._root_node = root_node #Elt(root_node.name, base_node=root_node) self._root_node.make_finite(all_conf=True, recursive=True) if make_determinist: assert (not make_random) self._root_node.make_determinist(all_conf=True, recursive=True) elif make_random: assert (not make_determinist) self._root_node.make_random(all_conf=True, recursive=True) self._root_node.get_value() self._max_steps = int(max_steps) self._initial_step = int(initial_step) assert (self._max_steps > 0 or self._max_steps == -1) self.ic = dm.NodeInternalsCriteria(mandatory_attrs=[ dm.NodeInternals.Mutable, dm.NodeInternals.Finite ]) self.set_consumer(node_consumer)
def init_specific(self, separators): self._internals_criteria = \ dm.NodeInternalsCriteria(mandatory_attrs=[dm.NodeInternals.Mutable, dm.NodeInternals.Separator], node_kinds=[dm.NodeInternals_Term]) self.val_list = [b''] if separators is not None: self.val_list += list(separators) self.yield_original_val = False
def init_specific(self, args): self._internals_criteria = dm.NodeInternalsCriteria( mandatory_attrs=[dm.NodeInternals.Mutable], node_kinds=[dm.NodeInternals_TypedValue]) self.orig_value = None self.current_fuzz_vt_list = None self.current_node = None self.orig_internal = None self.yield_original_val = True self.need_reset_when_structure_change = True
def get_terminal_node(mem, top_node, paths_regexp=None): if mem.new: mem.internals_criteria = dm.NodeInternalsCriteria( mandatory_attrs=[dm.NodeInternals.Mutable], node_kinds=[dm.NodeInternals_Term]) return get_node_from_attr(mem, top_node, internals_criteria=mem.internals_criteria, paths_regexp=paths_regexp)
def init_specific(self, args): self.__node_backup = None self.yield_original_val = True self.need_reset_when_structure_change = True self._internals_criteria = dm.NodeInternalsCriteria(mandatory_attrs=[dm.NodeInternals.Mutable]) self._owned_confs = ['MAIN'] self.current_consumed_node = None self.orig_conf = None self.confs_list = None self.recover = False
def fuzz_data_tree(top_node, paths_regexp=None): c = dm.NodeInternalsCriteria(mandatory_attrs=[dm.NodeInternals.Mutable], node_kinds=[dm.NodeInternals_NonTerm]) if paths_regexp: node_list = top_node.get_reachable_nodes(path_regexp=paths_regexp) else: node_list = [top_node] for node in node_list: l = node.get_reachable_nodes(internals_criteria=c) for e in l: e.cc.change_subnodes_csts([('*', 'u=.')])
def get_node_with_alt_conf(mem, top_node, conf, paths_regexp=None): if mem.new: mem.new = False mem.val_nodes_list = [] mem.c = dm.NodeInternalsCriteria( mandatory_attrs=[dm.NodeInternals.Mutable]) if paths_regexp: mem.val_nodes_list = [] if len(mem.val_nodes_list) == 0: top_node.make_finite(all_conf=True, recursive=True) top_node.unfreeze_all(ignore_entanglement=True) top_node.get_value() if paths_regexp: node_list = top_node.get_reachable_nodes(path_regexp=paths_regexp) if not node_list: return None, None else: node_list = [top_node] mem.val_nodes_list = [] for e in node_list: mem.val_nodes_list += e.get_reachable_nodes( internals_criteria=mem.c, owned_conf=conf) if mem.val_nodes_list == []: return None, None mem.val_nodes_list = sorted(mem.val_nodes_list, key=lambda x: -x.depth) mem.prev_node = None if mem.prev_node: mem.prev_node.set_current_conf(conf='MAIN', reverse=True, recursive=False) mem.prev_node.unfreeze(conf, ignore_entanglement=True) node = mem.val_nodes_list.pop(0) node.unfreeze(conf, ignore_entanglement=True) mem.prev_node = node node.set_current_conf(conf=conf, recursive=False) return node, len(mem.val_nodes_list)
def init_specific(self, base_list): self._internals_criteria = dm.NodeInternalsCriteria( mandatory_attrs=[dm.NodeInternals.Mutable], node_kinds=[dm.NodeInternals_Term]) self.enforce_ascii = False self.determinist = True if base_list is None: self.val_list = [ b'', b'\x00', b'AhAh%s%s%s', b'BBB%n%n%n%n%n', b'\r\n' ] else: self.val_list = list(base_list) self.orig_internals = None self.yield_original_val = True self.need_reset_when_structure_change = True
def fuzz_typed_values(mem, top_node, paths_regexp=None): def _create_fuzzy_vt_list(e): vt = e.cc.get_value_type() if issubclass(vt.__class__, vtype.VT_Alt): new_vt = copy.copy(vt) new_vt.make_private(forget_current_state=False) new_vt.switch_mode() fuzzy_vt_list = [new_vt] else: fuzzy_vt_cls = list(vt.fuzzy_cls.values()) fuzzy_vt_list = [] for c in fuzzy_vt_cls: fuzzy_vt_list.append(c(vt.endian)) return fuzzy_vt_list def _extend_fuzzy_vt_list(flist, e): vt = e.cc.get_value_type() if issubclass(vt.__class__, vtype.VT_Alt): return specific_fuzzy_vals = e.cc.get_specific_fuzzy_values() val = vt.get_current_raw_val() if val is not None: supp_list = [val + 1, val - 1] if specific_fuzzy_vals is not None: for v in specific_fuzzy_vals: supp_list.insert(0, v) if vt.mini is not None: supp_list.append(vt.mini - 1) supp_list.append(vt.maxi + 1) for o in flist: # We don't need to check with vt.mini-1 or vt.maxi+1, # as the following test will provide the first # compliant choice that will also be OK for the # previous values (ortherwise, no VT will be OK, and # these values will be filtered through the call to # extend_value_list()) if o.is_compatible(val + 1) or o.is_compatible(val - 1): fuzzy_vt_obj = o break fuzzy_vt_obj.extend_value_list(supp_list) def prepare_new_fuzzy_vt(e): mem.current_node_fuzzy_vt_obj = _create_fuzzy_vt_list(e) _extend_fuzzy_vt_list(mem.current_node_fuzzy_vt_obj, e) def save_orig_vt_and_val(e): mem.orig_node_vt = e.cc.get_value_type() mem.orig_node_val = e.get_flatten_value() def restore_orig_vt_and_val(e): e.cc.import_value_type(value_type=mem.orig_node_vt) e.set_frozen_value(mem.orig_node_val) mem.orig_node_vt = None mem.orig_node_val = None def change_value_type(e): vt_obj = mem.current_node_fuzzy_vt_obj.pop(0) e.cc.import_value_type(value_type=vt_obj) if e.env != mem._env: print('\n*** DEBUG - e.env:', e.env) raise ValueError if mem.new: mem.new = False mem.tval_nodes_list = [] mem.internals_criteria = dm.NodeInternalsCriteria( mandatory_attrs=[dm.NodeInternals.Mutable], node_kinds=[dm.NodeInternals_TypedValue]) mem.orig_node_vt = None mem.orig_node_val = None mem.current_node = None mem.current_node_fuzzy_vt_obj = None top_node.make_finite(all_conf=True, recursive=True) top_node.get_value() top_node.env.clear_all_exhausted_nodes() mem._env = top_node.env if paths_regexp: node_list = top_node.get_reachable_nodes(path_regexp=paths_regexp) if not node_list: return None, None, None else: node_list = [top_node] mem.tval_nodes_list = [] for e in node_list: mem.tval_nodes_list += e.get_reachable_nodes( internals_criteria=mem.internals_criteria) if len(mem.tval_nodes_list) == 0: # if no typed value Node return None, None, None mem.current_node = mem.tval_nodes_list[0] prepare_new_fuzzy_vt(mem.current_node) save_orig_vt_and_val(mem.current_node) change_value_type(mem.current_node) if len(mem.tval_nodes_list) == 0: return None, None, None exhausted = top_node.env.exhausted_node_exists() if len(mem.current_node_fuzzy_vt_obj) != 0 and exhausted: top_node.env.clear_exhausted_node(mem.current_node) change_value_type(mem.current_node) elif len(mem.current_node_fuzzy_vt_obj) != 0 and not exhausted: pass elif len(mem.current_node_fuzzy_vt_obj) == 0 and exhausted: assert (len(mem.tval_nodes_list) != 0) top_node.env.clear_exhausted_node(mem.current_node) restore_orig_vt_and_val(mem.current_node) mem.tval_nodes_list.pop(0) if len(mem.tval_nodes_list) == 0: return None, None, None mem.current_node = mem.tval_nodes_list[0] prepare_new_fuzzy_vt(mem.current_node) save_orig_vt_and_val(mem.current_node) change_value_type(mem.current_node) elif len(mem.current_node_fuzzy_vt_obj) == 0 and not exhausted: pass else: raise ValueError('Implementation Error') mem.current_node.unfreeze(ignore_entanglement=True) mem.current_node.get_value() return mem.current_node, mem.orig_node_val, len(mem.tval_nodes_list)
def init_specific(self, args): self._internals_criteria = dm.NodeInternalsCriteria( negative_node_kinds=[dm.NodeInternals_NonTerm])
def init_specific(self, args): self.consumed = False self._internals_criteria = None self._internals_criteria = dm.NodeInternalsCriteria(negative_node_kinds=[dm.NodeInternals_NonTerm]) self.current_nt_node = None