本文整理汇总了Python中z3.BitVecVal方法的典型用法代码示例。如果您正苦于以下问题:Python z3.BitVecVal方法的具体用法?Python z3.BitVecVal怎么用?Python z3.BitVecVal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类z3
的用法示例。
在下文中一共展示了z3.BitVecVal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_storages
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def update_storages(self, sstore_data):
for address, index, value in sstore_data:
address = int(address[2:], 16)
assert address in self.root_wstate.address_to_account
if index > 100:
if index in self.log_sha_to_sym_sha:
store_index = self.log_sha_to_sym_sha[index]
else:
log_shas = list(self.log_sha_to_sym_sha.keys())
diffs = [abs(l - index) for l in log_shas]
min_index = diffs.index(min(diffs))
diff = diffs[min_index]
if diff < 10:
relative_index = log_shas[min_index]
store_index = z3.simplify(self.log_sha_to_sym_sha[relative_index] + z3.BitVecVal(diff, 256))
self.log_sha_to_sym_sha[index] = store_index
else:
store_index = z3.BitVecVal(index, 256)
else:
store_index = z3.BitVecVal(index, 256)
store_value = self.log_sha_to_sym_sha.get(value, z3.BitVecVal(value, 256))
account = self.root_wstate.address_to_account[address]
account.storage.store(store_index, store_value)
示例2: execute
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def execute(self, expr):
expr = expr.encode('utf-8')
for op in expr.split(','):
val = to_int(op)
if val:
self.push(z3.BitVecVal(val, 32))
elif op in self.instr_table:
self.instr_table[op]()
elif op == '':
# Sometimes a value might be absent, set to 0 as a
# temporary workaround, probably a bug in ESIL
self.push(zero())
else:
# Otherwise it's either register or
# a flag
self.push(op)
# Commands
示例3: check_interp
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def check_interp(interp, constraints, bits=32, valbits=8):
"""Checks that a list of @constraints (addr, value) (as python ints)
match a z3 FuncInterp (@interp).
"""
constraints = dict((addr,
z3.BitVecVal(val, valbits))
for addr, val in constraints)
entry = interp.children()
assert len(entry) == 3
_, addr, value = entry
addr = addr.as_long()
assert addr in constraints
assert equiv(value, constraints[addr])
# equiv short test
# --------------------------------------------------------------------------
示例4: update_sha
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def update_sha(self, sha_data):
for arg, log_value, length_bytes in sha_data:
if log_value in self.log_sha_to_sym_sha:
continue
data = z3.BitVecVal(arg, length_bytes * 8)
if data.size() == 512:
data_words = svm_utils.split_bv_by_words(data)
data_words = [d.as_long() for d in data_words]
data_words = [self.log_sha_to_sym_sha.get(d, z3.BitVecVal(d, 256)) for d in data_words]
data = z3.simplify(z3.Concat(data_words))
sha_constraints, hash_vector = svm_utils.symbolic_keccak(self, data)
self.log_sha_to_sym_sha[log_value] = hash_vector
self.root_wstate.constraints.extend(sha_constraints)
solver = z3.Solver()
solver.add(self.root_wstate.constraints)
assert solver.check() == z3.sat
示例5: SHA3
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def SHA3(self, gstate, index, length):
if svm_utils.is_bv_concrete(index) and svm_utils.is_bv_concrete(length):
index = svm_utils.get_concrete_int(index)
length = svm_utils.get_concrete_int(length)
if length == 0:
gstate.mstate.stack.append(z3.BitVecVal(SHA_EMPTY_ARGS_VALUE, 256))
return
data = z3.simplify(svm_utils.get_memory_data(gstate.mstate.memory, index, length))
sha_constraints, hash_vector = svm_utils.symbolic_keccak(self, data)
gstate.wstate.constraints.extend(sha_constraints)
gstate.mstate.stack.append(hash_vector)
return
hash_vector = self.svm.sym_bv_generator.get_sym_bitvec(constraints.ConstraintType.SHA3,
gstate.wstate.gen,
unique=True)
logging.debug('SHA index or len not resolved. Using the symbolic vector')
gstate.mstate.stack.append(hash_vector)
return
示例6: zero
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def zero():
return z3.BitVecVal(0, BITS)
示例7: BVV
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def BVV(self, ast):
if ast.args[0] is None:
raise BackendError("Z3 can't handle empty BVVs")
size = ast.size()
# TODO: Here there is no need to use low level API since teh high level API just perform some conversions which
# are mandatory to fix the types of the arguments requested by the low level API
return z3.BitVecVal(ast.args[0], size, ctx=self._context)
示例8: from_ExprInt
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def from_ExprInt(self, expr):
return z3.BitVecVal(int(expr), expr.size)
示例9: from_ExprLoc
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def from_ExprLoc(self, expr):
if self.loc_db is None:
# No loc_db, fallback to default name
return z3.BitVec(str(expr), expr.size)
loc_key = expr.loc_key
offset = self.loc_db.get_location_offset(loc_key)
if offset is not None:
return z3.BitVecVal(offset, expr.size)
# fallback to default name
return z3.BitVec(str(loc_key), expr.size)
示例10: _sdivC
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
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
示例11: PUSH
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def PUSH(self, gstate):
instr = gstate.environment.disassembly.instruction_list[gstate.mstate.pc]
value = z3.BitVecVal(int(instr['argument'][2:], 16), 256)
gstate.mstate.stack.append(value)
示例12: EXP
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def EXP(self, gstate, base, exponent):
base, exponent = map(svm_utils.convert_to_bitvec, (base, exponent))
if svm_utils.is_bv_concrete(base) and svm_utils.is_bv_concrete(exponent):
base = svm_utils.get_concrete_int(base)
exponent = svm_utils.get_concrete_int(exponent)
value = pow(base, exponent, 2**256)
gstate.mstate.stack.append(z3.BitVecVal(value, 256))
else:
active_account = gstate.wstate.address_to_account[gstate.environment.active_address]
gstate.mstate.stack.append(self.svm.sym_bv_generator.get_sym_bitvec(constraints.ConstraintType.EXP,
gstate.wstate.gen,
unique=True,
acc=active_account.id))
示例13: CALLDATACOPY
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def CALLDATACOPY(self, gstate, dest_offset, offset, length):
length_concrete = svm_utils.is_bv_concrete(length)
if not length_concrete:
logging.warning('Symbolic calldata size')
length = z3.BitVecVal(64, 256)
if gstate.environment.calldata_type == CalldataType.UNDEFINED:
length = svm_utils.get_concrete_int(length)
if svm_utils.is_bv_concrete(offset):
offset = svm_utils.get_concrete_int(offset)
for i in range(length):
data_word = self.svm.sym_bv_generator.get_sym_bitvec(constraints.ConstraintType.CALLDATA,
gstate.wstate.gen,
index=offset+(i//32))
slot = i % 32
data_bytes = svm_utils.split_bv_into_bytes(data_word)
data = data_bytes[slot]
gstate.mstate.memory = z3.Store(gstate.mstate.memory, dest_offset+i, data)
else:
for i in range(length):
data = self.svm.sym_bv_generator.get_sym_bitvec(constraints.ConstraintType.CALLDATA,
gstate.wstate.gen,
unique=True,
bv_size=8)
gstate.mstate.memory = z3.Store(gstate.mstate.memory, dest_offset+i, data)
elif gstate.environment.calldata_type == CalldataType.DEFINED:
length = svm_utils.get_concrete_int(length)
offset_concrete = svm_utils.is_bv_concrete(offset)
calldata_bytes = svm_utils.split_bv_into_bytes(gstate.environment.calldata)
offset_concrete = svm_utils.is_bv_concrete(offset)
for i in range(length):
gstate.mstate.memory = z3.Store(gstate.mstate.memory, dest_offset+i, calldata_bytes[offset_concrete+i])
else:
raise SVMRuntimeError('Unknown calldata type')
示例14: ADDRESS
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def ADDRESS(self, gstate):
gstate.mstate.stack.append(z3.BitVecVal(gstate.environment.active_address, 256))
示例15: CODESIZE
# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import BitVecVal [as 别名]
def CODESIZE(self, gstate):
gstate.mstate.stack.append(z3.BitVecVal(len(gstate.environment.runtime_bytecode_bytes), 256))