def test_composite_solver(): s = claripy.CompositeFrontend(claripy.FullFrontend(claripy.backends.z3)) x = claripy.BVS("x", 32) y = claripy.BVS("y", 32) z = claripy.BVS("z", 32) c = claripy.And(x == 1, y == 2, z == 3) s.add(c) nose.tools.assert_equals(len(s._solver_list), 4) # including the CONSTANT solver nose.tools.assert_true(s.satisfiable()) s.add(x < y) nose.tools.assert_equal(len(s._solver_list), 3) nose.tools.assert_true(s.satisfiable()) s.simplify() nose.tools.assert_equal(len(s._solver_list), 4) nose.tools.assert_true(s.satisfiable()) s1 = s.branch() s1.add(x > y) nose.tools.assert_equal(len(s1._solver_list), 3) nose.tools.assert_false(s1.satisfiable()) nose.tools.assert_equal(len(s._solver_list), 4) nose.tools.assert_true(s.satisfiable()) s.add(claripy.BVV(1, 32) == claripy.BVV(2, 32)) nose.tools.assert_equal(len(s._solver_list), 4) # the CONCRETE one nose.tools.assert_false(s.satisfiable())
def test_solver_branching(): yield raw_solver_branching, lambda: claripy.FullFrontend(claripy.backends. z3) yield raw_solver_branching, lambda: claripy.HybridFrontend(claripy.backends .z3) yield raw_solver_branching, lambda: claripy.CompositeFrontend( claripy.FullFrontend(claripy.backends.z3))
def _solver(self): if self._stored_solver is not None: return self._stored_solver if o.ABSTRACT_SOLVER in self.state.options: self._stored_solver = claripy.LightFrontend(claripy.backend_vsa) elif o.COMPOSITE_SOLVER in self.state.options: self._stored_solver = claripy.CompositeFrontend(claripy.backend_z3) else: self._stored_solver = claripy.FullFrontend(claripy.backend_z3) return self._stored_solver
def test_datalayer(): l.info("Running test_datalayer") pickle_dir = tempfile.mkdtemp() ana.set_dl(pickle_dir=pickle_dir) l.debug("Pickling to %s", pickle_dir) a = claripy.BVV(1, 32) b = claripy.BVS("x", 32) c = a + b d = a + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b + b l.debug("Storing!") a.ana_store() c_info = c.ana_store() d_info = d.ana_store() l.debug("Loading!") ana.set_dl(pickle_dir=pickle_dir) #nose.tools.assert_equal(len(claripy.dl._cache), 0) cc = claripy.ast.BV.ana_load(c_info) nose.tools.assert_equal(str(cc), str(c)) cd = claripy.ast.BV.ana_load(d_info) nose.tools.assert_equal(str(cd), str(d)) l.debug("Time to test some solvers!") s = claripy.FullFrontend(claripy.backends.z3) x = claripy.BVS("x", 32) s.add(x == 3) s.finalize() ss = claripy.FullFrontend.ana_load(s.ana_store()) nose.tools.assert_equal(str(s.constraints), str(ss.constraints)) nose.tools.assert_equal(str(s.variables), str(ss.variables)) s = claripy.CompositeFrontend(claripy.FullFrontend(claripy.backends.z3)) x = claripy.BVS("x", 32) s.add(x == 3) s.finalize() ss = claripy.CompositeFrontend.ana_load(s.ana_store()) old_constraint_sets = [[hash(j) for j in k.constraints] for k in s._solver_list] new_constraint_sets = [[hash(j) for j in k.constraints] for k in ss._solver_list] nose.tools.assert_items_equal(old_constraint_sets, new_constraint_sets) nose.tools.assert_equal(str(s.variables), str(ss.variables))
def _solver(self): if self._stored_solver is not None: return self._stored_solver if o.ABSTRACT_SOLVER in self.state.options: self._stored_solver = claripy.LightFrontend(claripy.backends.vsa, cache=False) elif o.REPLACEMENT_SOLVER in self.state.options: self._stored_solver = claripy.ReplacementFrontend(claripy.FullFrontend(claripy.backends.z3), unsafe_replacement=True) elif o.COMPOSITE_SOLVER in self.state.options: self._stored_solver = claripy.CompositeFrontend(claripy.hybrid_vsa_z3()) elif o.SYMBOLIC in self.state.options: if o.approximation & self.state.options: self._stored_solver = claripy.hybrid_vsa_z3() else: self._stored_solver = claripy.FullFrontend(claripy.backends.z3) else: self._stored_solver = claripy.LightFrontend(claripy.backends.concrete) return self._stored_solver
def test_simple_merging(): yield raw_simple_merging, lambda: claripy.FullFrontend(claripy.backends.z3) yield raw_simple_merging, claripy.hybrid_vsa_z3 yield raw_simple_merging, lambda: claripy.CompositeFrontend(claripy.FullFrontend(claripy.backends.z3))
def test_ite(): yield raw_ite, lambda: claripy.FullFrontend(claripy.backends.z3) yield raw_ite, lambda: claripy.HybridFrontend(claripy.backends.z3) yield raw_ite, lambda: claripy.CompositeFrontend( claripy.FullFrontend(claripy.backends.z3))
def test_solver(): yield raw_solver, lambda: claripy.FullFrontend(claripy.backends.z3) yield raw_solver, claripy.hybrid_vsa_z3 yield raw_solver, lambda: claripy.CompositeFrontend(claripy.FullFrontend(claripy.backends.z3))
def test_combine(): yield raw_combine, lambda: claripy.FullFrontend(claripy.backends.z3) yield raw_combine, claripy.hybrid_vsa_z3 yield raw_combine, lambda: claripy.CompositeFrontend(claripy.FullFrontend(claripy.backends.z3))