Ejemplo n.º 1
0
    def test_merge3(self):
        ctx = context.newctx()
        x = util.FreshBitVec('x', 32)
        ctx.globals['%4'] = x

        cond = util.FreshBool('cond')

        ctx.push(cond)
        ctx.globals['%4'] += 1
        g1 = ctx.pop()

        ctx.push(z3.Not(cond))
        ctx.globals['%4'] += 1
        g2 = ctx.pop()

        assert not util.path_condition_implies(g1, cond)
        assert not util.path_condition_implies(g2, z3.Not(cond))

        assert not util.path_condition_implies(ctx, cond)
        assert not util.path_condition_implies(ctx, z3.Not(cond))

        ctx.merge(cond, g1, g2)

        assert not util.path_condition_implies(ctx, cond)
        assert not util.path_condition_implies(ctx, z3.Not(cond))
Ejemplo n.º 2
0
 def get_poison(self, type):
     if type.is_int():
         if type.size() == 1:
             return util.FreshBool('poison')
         else:
             return util.FreshBitVec('poison', type.size())
     assert False, "Can't get posion for {!r}".format(type)
Ejemplo n.º 3
0
    def test_nested_push_pop(self):
        ctx = context.newctx()

        x = util.FreshBitVec('x', 32)

        ctx.globals['%4'] = x

        ctx.push()

        ctx.push()
        ctx.globals['%4'] += 1
        self.prove(ctx.globals['%4'] == x + 1)
        b11 = ctx.pop()

        self.prove(ctx.globals['%4'] == x)

        ctx.push()
        ctx.globals['%4'] += 2
        self.prove(ctx.globals['%4'] == x + 2)
        b12 = ctx.pop()

        cond1 = util.FreshBool('cond')
        ctx.merge(cond1, b11, b12)

        self.prove(z3.Implies(cond1, ctx.globals['%4'] == x + 1))
        self.prove(z3.Implies(z3.Not(cond1), ctx.globals['%4'] == x + 2))

        b1 = ctx.pop()

        ctx.push()
        ctx.globals['%4'] += 10
        b2 = ctx.pop()

        cond2 = util.FreshBool('cond')
        ctx.merge(cond2, b1, b2)

        self.prove(z3.Implies(z3.And(cond1, cond2),
                              ctx.globals['%4'] == x + 1))
        self.prove(z3.Implies(z3.And(z3.Not(cond1), cond2),
                              ctx.globals['%4'] == x + 2))
        self.prove(z3.Implies(z3.And(cond1, z3.Not(cond2)),
                              ctx.globals['%4'] == x + 10))
        self.prove(z3.Implies(z3.And(z3.Not(cond1), z3.Not(cond2)),
                              ctx.globals['%4'] == x + 10))
Ejemplo n.º 4
0
    def test_push_pop(self):
        ctx = context.newctx()

        x = util.FreshBitVec('x', 32)
        cond = util.FreshBool('cond')

        ctx.globals['%4'] = x

        ctx.push(cond)
        ctx.globals['%4'] += 1
        b1 = ctx.pop()

        ctx.push(z3.Not(cond))
        ctx.globals['%4'] += 2
        b2 = ctx.pop()

        ctx.merge(cond, b1, b2)

        self.prove(z3.Implies(cond, ctx.globals['%4'] == x + 1))
        self.prove(z3.Implies(z3.Not(cond), ctx.globals['%4'] == x + 2))
Ejemplo n.º 5
0
    def _nest(self, ctx, depth):
        assert util.path_condition_implies(ctx, z3.And(*ctx.path_condition))
        assert not util.path_condition_implies(
            ctx, z3.Not(z3.And(*ctx.path_condition)))

        if depth == 0:
            return
        cond = util.FreshBool('cond')
        ctx.push(cond)
        ctx.globals['%4'] += 1
        self._nest(ctx, depth - 1)
        assert util.path_condition_implies(ctx, cond)
        ctx.pop()
        assert not util.path_condition_implies(ctx, cond)
        ctx.push(z3.Not(cond))
        self._nest(ctx, depth - 1)
        assert util.path_condition_implies(ctx, z3.Not(cond))
        ctx.pop()
        assert not util.path_condition_implies(ctx, z3.Not(cond))
        self._nest(ctx, depth - 1)
Ejemplo n.º 6
0
    def test_pcond(self):
        ctx = context.newctx()

        x = util.FreshBitVec('x', 32)
        cond = util.FreshBool('cond')

        ctx.globals['%4'] = x

        ctx.push(cond)
        ctx.globals['%4'] += 1
        print 'cond', ctx.path_condition
        b1 = ctx.pop()

        ctx.push(z3.Not(cond))
        ctx.globals['%4'] += 1
        print 'ncond', ctx.path_condition
        b2 = ctx.pop()

        print 'cond', b1.path_condition
        print 'ncond', b2.path_condition
        print [], ctx.path_condition
        ctx.restore(b1)
        print [], ctx.path_condition