Esempio n. 1
0
 def sext(self, ctx, return_type, a, atype, **kwargs):
     outsize = itypes.integer_size(return_type)
     insize = itypes.integer_size(atype)
     assert outsize > insize
     if z3.is_bool(a):
         return util.If(a, z3.BitVecVal(1, outsize),
                        z3.BitVecVal(0, outsize))
     return z3.SignExt(outsize - insize, a)
Esempio n. 2
0
 def select(self, ctx, return_type, cond, cond_type, trueval, trueval_type,
            falseval, falseval_type):
     self.assertion(ctx, not cond.is_poison(), "path condition is poison")
     assert itypes.integer_size(cond_type) == 1
     assert return_type == trueval_type
     assert trueval_type == falseval_type
     return util.If(cond, trueval, falseval)
Esempio n. 3
0
    def branch(self, ctx, cond, cond_type, iftrue, iffalse):
        self.assertion(ctx, not cond.is_poison(), "path condition is poison")
        assert itypes.integer_size(cond_type) == 1

        scond = util.simplify(cond)

        can_be_true = not z3.is_false(scond)
        can_be_false = not z3.is_true(scond)

        if ctx['depth'] >= ctx['prune_depth']:
            can_be_true = not z3.is_false(
                scond) and not util.path_condition_implies(ctx, z3.Not(scond))
            can_be_false = not can_be_true or (
                not z3.is_true(scond)
                and not util.path_condition_implies(ctx, scond))

        true_branch_exc = None
        false_branch_exc = None

        trueval = None
        falseval = None

        if can_be_true:
            try:
                ctx.push(path_condition=scond)
                trueval = iftrue()
            except ex.UnreachableException, e:
                stacktrace = getattr(e, 'stacktrace', None)
                self.assertion(ctx,
                               util.path_condition_implies(ctx,
                                                           z3.BoolVal(False),
                                                           print_model=True),
                               "Panic " + repr(e),
                               stacktrace=stacktrace)
                can_be_true = False
            except BaseException, e:
                true_branch_exc = e
Esempio n. 4
0
 def trunc(self, ctx, return_type, a, atype, **kwargs):
     outsize = itypes.integer_size(return_type)
     insize = itypes.integer_size(atype)
     assert insize > outsize
     return z3.Extract(outsize - 1, 0, a)