Example #1
0
def generate_special_paths(con_loc, ppc_str):
    parser = SmtLibParser()
    special_list = []
    script = parser.get_script(cStringIO(ppc_str))
    path_condition = script.get_last_formula()
    angelic_count = int(len(re.findall("angelic!(.+?)!0", str(path_condition.serialize()))) / 4)
    if angelic_count > 1:
        false_path = generate_false_path(path_condition)
        true_path = generate_true_path(path_condition)
        if true_path:
            special_list.append((con_loc, true_path, len(str(true_path.serialize()))))
        if false_path:
            special_list.append((con_loc, false_path, len(str(false_path.serialize()))))
    return special_list
Example #2
0
def generate_flipped_path(ppc):
    """
    This function will check if a selected path is feasible
           ppc : partial path conditoin at chosen control loc
           chosen_control_loc: branch location selected for flip
           returns satisfiability of the negated path
    """
    parser = SmtLibParser()
    script = parser.get_script(cStringIO(ppc))
    formula = script.get_last_formula()
    prefix = formula.arg(0)
    constraint = formula.arg(1)
    new_path = And(prefix, Not(constraint))

    assert str(new_path.serialize()) != str(formula.serialize())
    return new_path
Example #3
0
def generate_path_for_negation():
    constraint_list = []
    parser = SmtLibParser()
    emitter.normal("\tgenerating path for negation of patch constraint")
    for control_loc, sym_path in values.LIST_PPC:
        if control_loc == values.CONF_LOC_PATCH:
            script = parser.get_script(cStringIO(sym_path))
            formula = script.get_last_formula()
            patch_constraint = formula
            if formula.is_and():
                patch_constraint = formula.arg(1)
            constraint_list.append(patch_constraint.serialize())
    if not constraint_list:
        return None
    last_sym_path = values.LAST_PPC_FORMULA
    # script = parser.get_script(cStringIO(last_sym_path))
    # formula = script.get_last_formula()
    negated_path = None
    while constraint_list:
        constraint = last_sym_path
        if last_sym_path.is_and():
            constraint = last_sym_path.arg(1)
        constraint_str = constraint.serialize()
        if constraint_str in constraint_list:
            constraint_list.remove(constraint_str)
            constraint = Not(constraint)
        if negated_path is None:
            negated_path = constraint
        else:
            negated_path = And(negated_path, constraint)
        if last_sym_path.is_and():
            last_sym_path = last_sym_path.arg(0)
        else:
            break
    negated_path = And(negated_path, last_sym_path)
    return negated_path
Example #4
0
def generate_formula(formula_str):
    parser = SmtLibParser()
    script = parser.get_script(cStringIO(formula_str))
    formula = script.get_last_formula()
    return formula