[文档]classDeadblockRemover(OptimizationPass):""" Removes condition-unreachable blocks from the graph. """ARCHES=NonePLATFORMS=NoneSTAGE=OptimizationPassStage.BEFORE_REGION_IDENTIFICATIONNAME="Remove blocks with unsatisfiable conditions"DESCRIPTION=__doc__.strip()
def_check(self):cond_proc=ConditionProcessor(self.project.arch)ifnetworkx.is_directed_acyclic_graph(self._graph):acyclic_graph=self._graphelse:acyclic_graph=to_acyclic_graph(self._graph)cond_proc.recover_reaching_conditions(region=None,graph=acyclic_graph,simplify_conditions=False)ifnotany(claripy.is_false(c)forcincond_proc.reaching_conditions.values()):returnFalse,Nonecache={"cond_proc":cond_proc}returnTrue,cachedef_analyze(self,cache=None):cond_proc=cache["cond_proc"]to_remove={blkforblkinself._graph.nodes()if(blk.addr!=self._func.addrandself._graph.in_degree(blk)==0)orclaripy.is_false(cond_proc.reaching_conditions[blk])}# fix up predecessorsforbinto_remove:forpinself._graph.predecessors(b):ifself._graph.out_degree(p)!=2:continueother_successor=next(sforsinself._graph.successors(p)ifs!=b)p.statements[-1]=Jump(None,Const(None,None,other_successor.addr,self.project.arch.bits),other_successor.idx,**p.statements[-1].tags,)forninto_remove:self._graph.remove_node(n)self.out_graph=self._graph