當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。