Python z3.is_true() Examples
The following are 7
code examples of z3.is_true().
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: mlil_ast.py From f-ing-around-with-binaryninja with MIT License | 6 votes |
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
Example #2
Source File: mlil_ast.py From f-ing-around-with-binaryninja with MIT License | 6 votes |
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]
Example #3
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 #4
Source File: mlil_ast.py From f-ing-around-with-binaryninja with MIT License | 5 votes |
def try_make_complex_if_else( self, parent, node1, node2, nodes_to_check, nodes_to_remove ): log_debug("try_make_complex_if_else") is_complex_if_else = self.find_c_and_R( node1.condition, node2.condition ) if not is_complex_if_else: return False else: c, R = is_complex_if_else # if we get here, we have a complex if/else new_if_else_node = MediumLevelILAstCondNode( self, c, node1._condition_il, node1[True], node2[True] ) log_debug(f"R is currently {R}") new_seq_node = MediumLevelILAstSeqNode(self, [new_if_else_node]) if is_true(R): new_cond_node = new_if_else_node else: new_cond_node = MediumLevelILAstCondNode( self, R, node1._condition_il, new_seq_node ) log_debug(f"new_cond_node: {new_cond_node}") if node1 in parent.nodes: node1_idx = parent.nodes.index(node1) parent._nodes[node1_idx] = new_cond_node nodes_to_remove.append(node2) nodes_to_check.remove(node2) else: log_debug(f"{node1} not in parent.nodes")
Example #5
Source File: Z3.py From jeeves with MIT License | 5 votes |
def evaluate(self, t): s = self.solver.model().eval(t.z3Node()) assert z3.is_true(s) or z3.is_false(s) return z3.is_true(s)
Example #6
Source File: mlil_ast.py From f-ing-around-with-binaryninja with MIT License | 4 votes |
def create_new_node_from_region( self, bb: MediumLevelILBasicBlock, block: MediumLevelILBasicBlock, sub_region: MediumLevelILAstNode, current_node: MediumLevelILAstNode, cases: dict, nodes: list ): log_debug( f"create_new_node_from_region({bb}, {block}, {sub_region}, {current_node})" ) reaching_constraint = self._reaching_constraints.get((bb.start, block.start)) if is_true(reaching_constraint): reaching_constraint = None if reaching_constraint is not None and self.any_node_dominated( sub_region, block, bb ): reaching_constraint = None if reaching_constraint is not None: if sub_region.type == "loop": sub_region = MediumLevelILAstSeqNode(self, [sub_region]) # This is now a condition node if a reaching constraint exists log_debug( f" Creating new CondNode with {sub_region} {reaching_constraint}\n\n" ) new_node = MediumLevelILAstCondNode( self, reaching_constraint, block.incoming_edges[0].source[-1], sub_region, ) else: new_node = sub_region if new_node is not None: if current_node.type != "switch": nodes.append(new_node) else: if block in cases: if current_node.block not in new_node.block.dominators: case = ["default"] else: case = cases[block] current_node.append( MediumLevelILAstCaseNode(self, case, [new_node]) ) else: return False return True
Example #7
Source File: mlil_ast.py From f-ing-around-with-binaryninja with MIT License | 4 votes |
def _convert_to_do_while_loop( self, node: MediumLevelILAstLoopNode, dowhile_condition ): log_debug(f"{node} is a do while loop") node.loop_type = "dowhile" node.condition = reduce( And, Tactic("ctx-solver-simplify")(Not(dowhile_condition))[0] ) break_cond = node.body.nodes[-1] if break_cond[False] is not None: node.body._nodes[-1] = break_cond[False] else: node.body._nodes.pop() # 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] log_debug(f"Checking {child} for break condition") if isinstance(child, MediumLevelILAstCondNode) and is_false( simplify(And(child.condition, node.condition)) ): break_instr = child[True].nodes[-1].block[-1] child[True]._nodes.append( MediumLevelILAstBreakNode( self, break_instr.instr_index, break_instr.address ) ) new_loop_condition = self._split_break_condition( node.condition, child.condition ) if new_loop_condition is not None: log_debug(f"new_loop_condition is {new_loop_condition}") node.condition = new_loop_condition