当前位置: 首页>>代码示例>>Python>>正文


Python z3.simplify方法代码示例

本文整理汇总了Python中z3.simplify方法的典型用法代码示例。如果您正苦于以下问题:Python z3.simplify方法的具体用法?Python z3.simplify怎么用?Python z3.simplify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在z3的用法示例。


在下文中一共展示了z3.simplify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_storages

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [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) 
开发者ID:eth-sri,项目名称:ilf,代码行数:25,代码来源:svm.py

示例2: update_sha

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [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 
开发者ID:eth-sri,项目名称:ilf,代码行数:18,代码来源:svm.py

示例3: MUL

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def MUL(self, gstate, a, b):
        a, b = map(svm_utils.convert_to_bitvec, (a, b))
        if self.svm.abs_mul and not svm_utils.is_bv_concrete(a) and not svm_utils.is_bv_concrete(b):
            abs_bv = self.svm.sym_bv_generator.get_sym_bitvec(constraints.ConstraintType.MUL,
                                                              gstate.wstate.gen,
                                                              unique=True)
            gstate.mstate.stack.append(abs_bv)
        elif svm_utils.is_bv_pow2(a) or svm_utils.is_bv_pow2(b):
            if svm_utils.is_bv_pow2(b):
                a, b = b, a
            a = svm_utils.get_concrete_int(a)
            i = 0
            while a != (1 << i):
                i += 1
            gstate.mstate.stack.append(z3.simplify(b << i))
        else:
            gstate.mstate.stack.append(a * b) 
开发者ID:eth-sri,项目名称:ilf,代码行数:19,代码来源:execution.py

示例4: SHA3

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [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 
开发者ID:eth-sri,项目名称:ilf,代码行数:20,代码来源:execution.py

示例5: split_bv_into_bytes

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def split_bv_into_bytes(bv):
    if type(bv) == int:
        bv = z3.BitVecVal(bv, 256)
    assert bv.size() % 8 == 0
    is_conc = False
    if is_bv_concrete(bv):
        is_conc = True
        length = bv.size() // 8
        concrete_data = get_concrete_int(bv)
        data_bytes = ethereum.utils.zpad(ethereum.utils.int_to_bytes(concrete_data), length)
        bv_bytes = []
        for data_byte in data_bytes:
            bv_bytes.append(z3.BitVecVal(data_byte, 8))
        bv_bytes_a  = bv_bytes
    bv_bytes = []
    for i in range(bv.size(), 0, -8):
        bv_bytes.append(z3.simplify(z3.Extract(i-1, i-8, bv)))
    if is_conc:
        assert bv_bytes == bv_bytes_a
    assert len(bv_bytes) == bv.size() // 8
    return bv_bytes 
开发者ID:eth-sri,项目名称:ilf,代码行数:23,代码来源:svm_utils.py

示例6: synthesise

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def synthesise(command, result, index):
    ret = ""

    max_iter = command[0]
    uct_scalar = command[1]
    game = command[2]
    oracle = command[3]
    synthesis_inputs = command[4]

    mc = MCTS(game, oracle, synthesis_inputs, uct_scalar=uct_scalar)
    mc.verbosity_level = 2
    s = State(game, BITSIZE)

    mc.search(s, max_iter)

    if mc.final_expression:
        ret = rpn_to_infix(mc.final_expression)
        print "{} ({} iterations)".format(rpn_to_infix(mc.final_expression), mc.current_iter)
        try:
            print "{} (simplified)".format(simplify(game.to_z3(mc.final_expression)))
        except:
            pass

    result[index] = ret 
开发者ID:RUB-SysSec,项目名称:syntia,代码行数:26,代码来源:mcts.py

示例7: synthesise

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def synthesise(command, result, index):
    ret = ""

    max_iter = command[0]
    uct_scalar = command[1]
    game = command[2]
    oracle = command[3]
    synthesis_inputs = command[4]

    mc = MCTS(game, oracle, synthesis_inputs, uct_scalar=uct_scalar)
    mc.verbosity_level = 1
    s = State(game, BITSIZE)

    mc.search(s, max_iter)

    if mc.final_expression:
        ret = rpn_to_infix(mc.final_expression)
        print "{} ({} iterations)".format(rpn_to_infix(mc.final_expression), mc.current_iter)
        try:
            simplified = simplify(game.to_z3(mc.final_expression))
            print "{} (simplified)".format(simplified)
        except:
            pass

    result[index] = ret 
开发者ID:RUB-SysSec,项目名称:syntia,代码行数:27,代码来源:mcts_synthesis_multi_core.py

示例8: try_make_simple_if_else

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def try_make_simple_if_else(
        self, node1, node2, nodes_to_check, nodes_to_remove
    ):

        log_debug("try_make_simple_if_else")

        cond1 = node1.condition
        cond2 = node2.condition

        if is_true(simplify(cond1 == Not(cond2))):
            log_debug(f"found a simple if/else match")
            if cond1.decl().name() == "not":
                node2[False] = node1[True]
                nodes_to_check.remove(node2)
                nodes_to_remove.append(node1)
            else:
                node1[False] = node2[True]
                nodes_to_remove.append(node2)

            return True

        return False 
开发者ID:joshwatson,项目名称:f-ing-around-with-binaryninja,代码行数:24,代码来源:mlil_ast.py

示例9: _convert_to_while_loop

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def _convert_to_while_loop(
        self, node: MediumLevelILAstLoopNode, while_condition
    ):
        log_debug(f"{node} is a while loop")
        node.loop_type = "while"
        node.condition = reduce(
            And, Tactic("ctx-solver-simplify")(Not(while_condition))[0]
        )

        break_cond = node.body.nodes[0]

        if break_cond[False] is not None:
            node.body._nodes[0] = break_cond[False]

        # Flatten condition nodes that have the same condition
        # as the loop condition
        for idx, child in enumerate(node.body.nodes):
            if (
                isinstance(child, MediumLevelILAstCondNode)
                and is_true(simplify(child.condition == node.condition))
                and child[False] is None
            ):
                node.body._nodes[idx] = child[True] 
开发者ID:joshwatson,项目名称:f-ing-around-with-binaryninja,代码行数:25,代码来源:mlil_ast.py

示例10: get_z3_value_hex

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def get_z3_value_hex(item):

    if (type(item) == int):
        return hex(item)

    elif (type(item) == mythril.laser.smt.bitvec.BitVec and not item.symbolic):
        return hex(item.value)
    elif (type(item) == z3.BitVecNumRef):
        return hex(item.as_long())

    try:
        return hex(z3.simplify(item).as_long())
    except AttributeError:
        return str(z3.simplify(item)).replace("\n","\n    ")
    except z3.Z3Exception:
        return str(item).replace("\n","\n    ") 
开发者ID:tintinweb,项目名称:ethereum-dasm,代码行数:18,代码来源:simplify.py

示例11: get_z3_value

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def get_z3_value(item):

    if (type(item) == int):
        return item

    elif (type(item) == mythril.laser.smt.bitvec.BitVec and not item.symbolic):
        return item.value
    elif (type(item) == z3.BitVecNumRef):
        return item.as_long()

    try:
        return z3.simplify(item).as_long()
    except AttributeError:
        return str(z3.simplify(item))
    except z3.Z3Exception:
        return str(item) 
开发者ID:tintinweb,项目名称:ethereum-dasm,代码行数:18,代码来源:simplify.py

示例12: ror

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def ror(x, y):
    return z3.simplify(z3.RotateRight(x,y)) 
开发者ID:cylance,项目名称:winapi-deobfuscation,代码行数:4,代码来源:esil.py

示例13: rol

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def rol(x,y):
    return z3.simplify(z3.RotateLeft(x,y)) 
开发者ID:cylance,项目名称:winapi-deobfuscation,代码行数:4,代码来源:esil.py

示例14: mem_key

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def mem_key(addr, size):
    # addr_str = parse_addr_str(str(z3.simplify(addr)))
    addr_str = str(z3.simplify(addr))
    return '{0}:{1}'.format(size, addr_str) 
开发者ID:cylance,项目名称:winapi-deobfuscation,代码行数:6,代码来源:esil.py

示例15: get_arguments_from_stack

# 需要导入模块: import z3 [as 别名]
# 或者: from z3 import simplify [as 别名]
def get_arguments_from_stack(n_args, vm, exe, max_args=12):
    args = []

    n_stack_val = len(vm.x86_stack)
        
    if n_stack_val > max_args:
        n_stack_val = max_args
        
    x = max([n_args, n_stack_val])
    for i in xrange(x):
        if vm.x86_stack:
            if i < n_args:
                val = vm.x86_stack.pop()
            else:
                val = vm.x86_stack[n_args - i - 1]
            arg = z3.simplify(val)
            
            if hasattr(arg, 'as_long'):
                ptr_ = check_pointer(arg.as_long(), exe)
                if ptr_:
                    arg = ptr_
                else:
                    arg = '0x%x' % arg.as_long()
            else:
                arg = str(arg)
                name = process_arg_str(arg)#
                if name: arg = name
        else:
            if i >= n_args:break
            arg = '*'
                
        args.append(arg)
    return args 
开发者ID:cylance,项目名称:winapi-deobfuscation,代码行数:35,代码来源:analysis.py


注:本文中的z3.simplify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。