def test_global_condition():
    s = SimState(arch="AMD64")

    s.regs.rax = 10
    old_rax = s.regs.rax
    with s.with_condition(False):
        nose.tools.assert_false(s.se.satisfiable())
        s.regs.rax = 20
    nose.tools.assert_is(s._global_condition, None)
    nose.tools.assert_is(old_rax, s.regs.rax)

    with s.with_condition(True):
        s.regs.rax = 20
    nose.tools.assert_is(s._global_condition, None)
    nose.tools.assert_is_not(old_rax, s.regs.rax)
    nose.tools.assert_is(s.se.BVV(20, s.arch.bits), s.regs.rax)

    with s.with_condition(s.regs.rbx != 0):
        s.regs.rax = 25
    nose.tools.assert_is(s._global_condition, None)
    nose.tools.assert_is_not(s.se.BVV(25, s.arch.bits), s.regs.rax)

    with s.with_condition(s.regs.rbx != 1):
        s.regs.rax = 30
    nose.tools.assert_is(s._global_condition, None)
    nose.tools.assert_is_not(s.se.BVV(30, s.arch.bits), s.regs.rax)

    with s.with_condition(s.regs.rbx == 0):
        nose.tools.assert_equals(s.se.eval_upto(s.regs.rbx, 10), [ 0 ])
        nose.tools.assert_items_equal(s.se.eval_upto(s.regs.rax, 10), [ 30 ])
    with s.with_condition(s.regs.rbx == 1):
        nose.tools.assert_equals(s.se.eval_upto(s.regs.rbx, 10), [ 1 ])
        nose.tools.assert_items_equal(s.se.eval_upto(s.regs.rax, 10), [ 25 ])
Example #2
0
    def test_global_condition(self):
        s = SimState(arch="AMD64")

        s.regs.rax = 10
        old_rax = s.regs.rax
        with s.with_condition(False):
            assert not s.solver.satisfiable()
            s.regs.rax = 20
        assert s._global_condition is None
        assert old_rax is s.regs.rax

        with s.with_condition(True):
            s.regs.rax = 20
        assert s._global_condition is None
        assert old_rax is not s.regs.rax
        assert s.solver.BVV(20, s.arch.bits) is s.regs.rax

        with s.with_condition(s.regs.rbx != 0):
            s.regs.rax = 25
        assert s._global_condition is None
        assert s.solver.BVV(25, s.arch.bits) is not s.regs.rax

        with s.with_condition(s.regs.rbx != 1):
            s.regs.rax = 30
        assert s._global_condition is None
        assert s.solver.BVV(30, s.arch.bits) is not s.regs.rax

        with s.with_condition(s.regs.rbx == 0):
            assert s.solver.eval_upto(s.regs.rbx, 10) == [0]
            assert s.solver.eval_upto(s.regs.rax, 10) == [30]
        with s.with_condition(s.regs.rbx == 1):
            assert s.solver.eval_upto(s.regs.rbx, 10) == [1]
            assert s.solver.eval_upto(s.regs.rax, 10) == [25]