Python z3.If() Examples
The following are 10
code examples of z3.If().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
z3
, or try the search function
.
Example #1
Source File: backend_z3.py From claripy with BSD 2-Clause "Simplified" License | 6 votes |
def BVS(self, ast): name = ast._encoded_name if hasattr(ast, 'annotations'): self.extra_bvs_data[name] = (ast.args, ast.annotations) else: self.extra_bvs_data[name] = (ast.args, None) size = ast.size() # TODO: Here we can use low level APIs because the check performed by the high level API always results in # the else branch of the check. This evidence although comes from the execution of the angr and claripy # test suite so I'm not sure if this assumption would hold on 100% of the cases bv = z3.BitVecSortRef(z3.Z3_mk_bv_sort(self._context.ref(), size), self._context) expr = z3.BitVecRef(z3.Z3_mk_const(self._context.ref(), z3.to_symbol(name, self._context), bv.ast), self._context) #if mn is not None: # expr = z3.If(z3.ULT(expr, mn), mn, expr, ctx=self._context) #if mx is not None: # expr = z3.If(z3.UGT(expr, mx), mx, expr, ctx=self._context) #if stride is not None: # expr = (expr // stride) * stride return expr
Example #2
Source File: solver.py From cozy with Apache License 2.0 | 5 votes |
def to_bool(e : z3.AstRef): """ If `e` is a boolean literal, return its value (True or False). Otherwise, return None. """ if z3.is_true(e): return True if z3.is_false(e): return False return None
Example #3
Source File: z3_ir.py From miasm with GNU General Public License v2.0 | 5 votes |
def from_ExprCond(self, expr): cond = self.from_expr(expr.cond) src1 = self.from_expr(expr.src1) src2 = self.from_expr(expr.src2) return z3.If(cond != 0, src1, src2)
Example #4
Source File: z3_ir.py From miasm with GNU General Public License v2.0 | 5 votes |
def _abs(self, z3_value): return z3.If(z3_value >= 0,z3_value,-z3_value)
Example #5
Source File: z3_ir.py From miasm with GNU General Public License v2.0 | 5 votes |
def _sdivC(self, num, den): """Divide (signed) @num by @den (z3 values) as C would See modint.__div__ for implementation choice """ result_sign = z3.If(num * den >= 0, z3.BitVecVal(1, num.size()), z3.BitVecVal(-1, num.size()), ) return z3.UDiv(self._abs(num), self._abs(den)) * result_sign
Example #6
Source File: execution.py From ilf with Apache License 2.0 | 5 votes |
def MSTORE(self, gstate, index, value): if isinstance(value, z3.BoolRef): value = z3.If(value, z3.BitVecVal(1, 256), z3.BitVecVal(0, 256)) value_bytes = svm_utils.split_bv_into_bytes(value) for i in range(32): if svm_utils.is_bv_concrete(index): gstate.mstate.memory_dict[svm_utils.get_concrete_int(index)+i] = value_bytes[i] gstate.mstate.memory = z3.Store(gstate.mstate.memory, index+i, value_bytes[i])
Example #7
Source File: svm_utils.py From ilf with Apache License 2.0 | 5 votes |
def convert_to_bitvec(val): if isinstance(val, z3.BoolRef): return z3.If(val, z3.BitVecVal(1, 256), z3.BitVecVal(0, 256)) elif isinstance(val, bool): return z3.BitVecVal(1, 256) if val else z3.BitVecVal(0, 256) elif isinstance(val, int): return z3.BitVecVal(val, 256) else: return z3.simplify(val)
Example #8
Source File: crc32.py From acsploit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def z3crc32(bytes, hash_table_size): # computes the crc32 checksum in z3 format checksum = 0x00000000ffffffff for byte in bytes: checksum ^= z3.ZeroExt(56, byte) & 0xff for _ in range(8): # test each bit in the byte we just xor'd in checksum = z3.If(checksum & 1 == z3.BitVecVal(1, 64), z3.LShR(checksum, 1) ^ 0xedb88320, # the binary representation of the CRC-32 polynomial z3.LShR(checksum, 1)) return (checksum ^ 0xffffffff) % hash_table_size
Example #9
Source File: find_name_for_bits.py From on-pwning with MIT License | 5 votes |
def hash3(name): h = z3.BitVecVal(0, 32) for i in range(len(name)): for j in range(8): h = z3.If(z3.LShR(name[i], j) & 1 == 1, (h + 1) & 0xff, h) h &= 0x1f return h
Example #10
Source File: AST.py From jeeves with MIT License | 5 votes |
def z3Node(self): return z3.If(self.cond.z3Node(), self.thn.z3Node(), self.els.z3Node())