2019-06-13 14:43:11 +00:00
|
|
|
from z3 import *
|
|
|
|
|
|
|
|
def ADD(x, y):
|
|
|
|
return x + y
|
|
|
|
|
|
|
|
def MUL(x, y):
|
|
|
|
return x * y
|
|
|
|
|
|
|
|
def SUB(x, y):
|
|
|
|
return x - y
|
|
|
|
|
|
|
|
def DIV(x, y):
|
|
|
|
return If(y == 0, 0, UDiv(x, y))
|
|
|
|
|
|
|
|
def SDIV(x, y):
|
|
|
|
return If(y == 0, 0, x / y)
|
|
|
|
|
|
|
|
def MOD(x, y):
|
|
|
|
return If(y == 0, 0, URem(x, y))
|
|
|
|
|
|
|
|
def SMOD(x, y):
|
|
|
|
return If(y == 0, 0, x % y)
|
|
|
|
|
|
|
|
def LT(x, y):
|
2019-06-14 14:57:57 +00:00
|
|
|
return If(ULT(x, y), BitVecVal(1, x.size()), BitVecVal(0, x.size()))
|
2019-06-13 14:43:11 +00:00
|
|
|
|
|
|
|
def GT(x, y):
|
2019-06-14 14:57:57 +00:00
|
|
|
return If(UGT(x, y), BitVecVal(1, x.size()), BitVecVal(0, x.size()))
|
2019-06-13 14:43:11 +00:00
|
|
|
|
|
|
|
def SLT(x, y):
|
2019-06-14 14:57:57 +00:00
|
|
|
return If(x < y, BitVecVal(1, x.size()), BitVecVal(0, x.size()))
|
2019-06-13 14:43:11 +00:00
|
|
|
|
|
|
|
def SGT(x, y):
|
2019-06-14 14:57:57 +00:00
|
|
|
return If(x > y, BitVecVal(1, x.size()), BitVecVal(0, x.size()))
|
|
|
|
|
2019-06-14 15:47:54 +00:00
|
|
|
def EQ(x, y):
|
|
|
|
return If(x == y, BitVecVal(1, x.size()), BitVecVal(0, x.size()))
|
|
|
|
|
2019-06-14 14:57:57 +00:00
|
|
|
def ISZERO(x):
|
|
|
|
return If(x == 0, BitVecVal(1, x.size()), BitVecVal(0, x.size()))
|
2019-06-13 14:43:11 +00:00
|
|
|
|
|
|
|
def AND(x, y):
|
|
|
|
return x & y
|
|
|
|
|
2020-04-20 14:14:22 +00:00
|
|
|
def OR(x, y):
|
|
|
|
return x | y
|
|
|
|
|
2020-04-28 16:37:08 +00:00
|
|
|
def NOT(x):
|
|
|
|
return ~(x)
|
|
|
|
|
2019-06-13 14:43:11 +00:00
|
|
|
def SHL(x, y):
|
|
|
|
return y << x
|
|
|
|
|
|
|
|
def SHR(x, y):
|
|
|
|
return LShR(y, x)
|
|
|
|
|
|
|
|
def SAR(x, y):
|
|
|
|
return y >> x
|
2020-06-04 09:11:53 +00:00
|
|
|
|
|
|
|
def BYTE(i, x):
|
|
|
|
bit = (i + 1) * 8
|
2021-08-09 15:40:48 +00:00
|
|
|
return If(
|
|
|
|
UGT(i, x.size() / 8 - 1),
|
|
|
|
BitVecVal(0, x.size()),
|
|
|
|
(LShR(x, (x.size() - bit))) & 0xff
|
|
|
|
)
|