@Override public Statement getSimpleCopy() { return new DoStatement(); }
Statement first = stat.getFirst(); while (first.type == Statement.TYPE_SEQUENCE) { first = first.getFirst(); stat.setLooptype(DoStatement.LOOP_WHILE); stat.setConditionExprent(ifexpr.getCondition()); if (stat.getAllSuccessorEdges().isEmpty()) { ifedge.setSource(stat); if (ifedge.closure == stat) { ifedge.closure = stat.getParent(); stat.addSuccessor(ifedge); if (firstif == stat.getFirst()) { BasicBlockStatement bstat = new BasicBlockStatement(new BasicBlock( DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.STATEMENT_COUNTER))); bstat.setExprents(new ArrayList<>()); stat.replaceStatement(firstif, bstat); stat.setLooptype(DoStatement.LOOP_WHILE); stat.setConditionExprent(((IfExprent)firstif.getHeadexprent().copy()).getCondition()); if (stat.getAllSuccessorEdges().isEmpty()) { elseedge.closure = stat.getParent();
ifstat.getStats().removeWithKey(target.id); loop.addLabeledEdge(ifedge); loop.getParent().replaceStatement(loop, block); block.setAllParent(); loop.addSuccessor(new StatEdge(StatEdge.TYPE_REGULAR, loop, target)); loop.addLabeledEdge(edge); if (loop.containsStatementStrict(edge.getSource())) { block.removePredecessor(edge); edge.getSource().changeEdgeNode(Statement.DIRECTION_FORWARD, edge, loop); loop.addPredecessor(edge);
@Override public List<Object> getSequentialObjects() { List<Object> lst = new ArrayList<>(); switch (looptype) { case LOOP_FOR: if (getInitExprent() != null) { lst.add(getInitExprent()); } case LOOP_WHILE: lst.add(getConditionExprent()); } lst.add(first); switch (looptype) { case LOOP_DOWHILE: lst.add(getConditionExprent()); break; case LOOP_FOR: lst.add(getIncExprent()); } return lst; }
DoStatement dost = (DoStatement)st; lst.addAll(dost.getInitExprentList()); lst.addAll(dost.getConditionExprentList());
if (dost.getLooptype() != DoStatement.LOOP_FOR && dost.getLooptype() != DoStatement.LOOP_DO) { currVars.add(dost.getConditionExprent());
private static void matchDoWhile(DoStatement stat) { Statement last = stat.getFirst(); while (last.type == Statement.TYPE_SEQUENCE) { last = last.getStats().getLast(); && isDirectPath(stat, elseedge.getDestination()))) { Set<Statement> set = stat.getNeighboursSet(StatEdge.TYPE_CONTINUE, Statement.DIRECTION_BACKWARD); set.remove(last); stat.setLooptype(DoStatement.LOOP_DOWHILE); ifexpr.negateIf(); stat.setConditionExprent(ifexpr.getCondition()); lastif.getFirst().removeSuccessor(ifedge); lastif.removeSuccessor(elseedge); stat.addLabeledEdge(newedge); if (stat.getAllSuccessorEdges().isEmpty()) { StatEdge edge = elseedge.getType() == StatEdge.TYPE_CONTINUE ? ifedge : elseedge; edge.closure = stat.getParent(); stat.addSuccessor(edge);
private static boolean isLoopRedundant(DoStatement loop) { if (loop.getLooptype() != DoStatement.LOOP_DO) { return false; Statement parentloop = loop.getParent(); while (parentloop != null && parentloop.type != Statement.TYPE_DO) { parentloop = parentloop.getParent(); if (parentloop == null || parentloop.getBasichead() != loop.getBasichead()) { return false; for (StatEdge edge : loop.getLabelEdges()) { if (edge.getType() == StatEdge.TYPE_BREAK) { // all break edges are explicit because of LOOP_DO type lstBreakEdges.add(edge); Statement loopcontent = loop.getFirst(); int precount = loop.isLabeled() ? 1 : 0; for (Statement st : lstEdgeClosures) { if (!statLabeled.containsKey(st.id)) {
lastData = getLastDirectData(stat.getFirst()); if (lastData == null || lastData.getExprents().isEmpty()) { return; Set<Statement> set = stat.getNeighboursSet(StatEdge.TYPE_CONTINUE, Statement.DIRECTION_BACKWARD); set.remove(lastData); stat.setLooptype(DoStatement.LOOP_FOR); if (hasinit) { stat.setInitExprent(preData.getExprents().remove(preData.getExprents().size() - 1)); stat.setIncExprent(lastData.getExprents().remove(lastData.getExprents().size() - 1));
int looptype = dostat.getLooptype(); case DoStatement.LOOP_DOWHILE: node = new DirectNode(DirectNode.NODE_CONDITION, stat, stat.id + "_cond"); node.exprents = dostat.getConditionExprentList(); graph.nodes.putWithKey(node, node.id); case DoStatement.LOOP_FOR: DirectNode nodeinit = new DirectNode(DirectNode.NODE_INIT, stat, stat.id + "_init"); if (dostat.getInitExprent() != null) { nodeinit.exprents = dostat.getInitExprentList(); nodecond.exprents = dostat.getConditionExprentList(); graph.nodes.putWithKey(nodecond, nodecond.id); nodeinc.exprents = dostat.getIncExprentList(); graph.nodes.putWithKey(nodeinc, nodeinc.id);
private static void removeLastEmptyStatement(DoStatement dostat, Statement stat) { if (stat == dostat.getFirst()) { BasicBlockStatement bstat = new BasicBlockStatement(new BasicBlock( DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.STATEMENT_COUNTER))); bstat.setExprents(new ArrayList<>()); dostat.replaceStatement(stat, bstat); } else { for (StatEdge edge : stat.getAllPredecessorEdges()) { edge.getSource().changeEdgeType(Statement.DIRECTION_FORWARD, edge, StatEdge.TYPE_CONTINUE); stat.removePredecessor(edge); edge.getSource().changeEdgeNode(Statement.DIRECTION_FORWARD, edge, dostat); dostat.addPredecessor(edge); dostat.addLabeledEdge(edge); } // parent is a sequence statement stat.getParent().getStats().removeWithKey(stat.id); } }
if (dstat.getLooptype() == DoStatement.LOOP_FOR) { if (dstat.getInitExprent() != null && setDefinition(dstat.getInitExprent(), index)) { continue; List<Exprent> lstSpecial = Arrays.asList(dstat.getConditionExprent(), dstat.getIncExprent()); for (VarExprent var : getAllVars(lstSpecial)) { if (var.getIndex() == index) {
private static boolean extractLastIf(DoStatement stat) { // search for an if condition at the end of the loop Statement last = stat.getFirst(); while (last.type == Statement.TYPE_SEQUENCE) { last = last.getStats().getLast(); } if (last.type == Statement.TYPE_IF) { IfStatement lastif = (IfStatement)last; if (lastif.iftype == IfStatement.IFTYPE_IF && lastif.getIfstat() != null) { Statement ifstat = lastif.getIfstat(); StatEdge elseedge = lastif.getAllSuccessorEdges().get(0); if (elseedge.getType() == StatEdge.TYPE_CONTINUE && elseedge.closure == stat) { Set<Statement> set = stat.getNeighboursSet(StatEdge.TYPE_CONTINUE, Statement.DIRECTION_BACKWARD); set.remove(last); if (set.isEmpty()) { // no direct continues in a do{}while loop if (isExternStatement(stat, ifstat, ifstat)) { extractIfBlock(stat, lastif); return true; } } } } } return false; }
private static boolean isExternStatement(DoStatement loop, Statement block, Statement stat) { for (StatEdge edge : stat.getAllSuccessorEdges()) { if (loop.containsStatement(edge.getDestination()) && !block.containsStatement(edge.getDestination())) { return false; } } for (Statement st : stat.getStats()) { if (!isExternStatement(loop, block, st)) { return false; } } return true; }
private static boolean extractFirstIf(DoStatement stat) { // search for an if condition at the entrance of the loop Statement first = stat.getFirst(); while (first.type == Statement.TYPE_SEQUENCE) { first = first.getFirst(); } // found an if statement if (first.type == Statement.TYPE_IF) { IfStatement firstif = (IfStatement)first; if (firstif.getFirst().getExprents().isEmpty()) { if (firstif.iftype == IfStatement.IFTYPE_IF && firstif.getIfstat() != null) { Statement ifstat = firstif.getIfstat(); if (isExternStatement(stat, ifstat, ifstat)) { extractIfBlock(stat, firstif); return true; } } } } return false; }
private static boolean matchDoWhile(DoStatement stat) { Statement last = stat.getFirst(); while (last.type == Statement.TYPE_SEQUENCE) { last = last.getStats().getLast(); && isDirectPath(stat, elseedge.getDestination()))) { Set<Statement> set = stat.getNeighboursSet(StatEdge.TYPE_CONTINUE, Statement.DIRECTION_BACKWARD); set.remove(last); stat.setLooptype(DoStatement.LOOP_DOWHILE); ifexpr.negateIf(); stat.setConditionExprent(ifexpr.getCondition()); lastif.getFirst().removeSuccessor(ifedge); lastif.removeSuccessor(elseedge); stat.addLabeledEdge(newedge); if (stat.getAllSuccessorEdges().isEmpty()) { StatEdge edge = elseedge.getType() == StatEdge.TYPE_CONTINUE ? ifedge : elseedge; edge.closure = stat.getParent(); stat.addSuccessor(edge);
lastData = getLastDirectData(stat.getFirst()); if (lastData == null || lastData.getExprents().isEmpty()) { return false; Set<Statement> set = stat.getNeighboursSet(StatEdge.TYPE_CONTINUE, Statement.DIRECTION_BACKWARD); set.remove(lastData); stat.setLooptype(DoStatement.LOOP_FOR); if (hasinit) { stat.setInitExprent(preData.getExprents().remove(preData.getExprents().size() - 1)); stat.setIncExprent(lastData.getExprents().remove(lastData.getExprents().size() - 1));
int looptype = dostat.getLooptype(); case DoStatement.LOOP_DOWHILE: node = new DirectNode(DirectNode.NODE_CONDITION, stat, stat.id + "_cond"); node.exprents = dostat.getConditionExprentList(); graph.nodes.putWithKey(node, node.id); case DoStatement.LOOP_FOR: DirectNode nodeinit = new DirectNode(DirectNode.NODE_INIT, stat, stat.id + "_init"); if (dostat.getInitExprent() != null) { nodeinit.exprents = dostat.getInitExprentList(); nodecond.exprents = dostat.getConditionExprentList(); graph.nodes.putWithKey(nodecond, nodecond.id); nodeinc.exprents = dostat.getIncExprentList(); graph.nodes.putWithKey(nodeinc, nodeinc.id);
private static void removeLastEmptyStatement(DoStatement dostat, Statement stat) { if (stat == dostat.getFirst()) { BasicBlockStatement bstat = new BasicBlockStatement(new BasicBlock( DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.STATEMENT_COUNTER))); bstat.setExprents(new ArrayList<>()); dostat.replaceStatement(stat, bstat); } else { for (StatEdge edge : stat.getAllPredecessorEdges()) { edge.getSource().changeEdgeType(Statement.DIRECTION_FORWARD, edge, StatEdge.TYPE_CONTINUE); stat.removePredecessor(edge); edge.getSource().changeEdgeNode(Statement.DIRECTION_FORWARD, edge, dostat); dostat.addPredecessor(edge); dostat.addLabeledEdge(edge); } // parent is a sequence statement stat.getParent().getStats().removeWithKey(stat.id); } }
if (dstat.getLooptype() == DoStatement.LOOP_FOR) { if (dstat.getInitExprent() != null && setDefinition(dstat.getInitExprent(), index)) { continue; List<Exprent> lstSpecial = Arrays.asList(dstat.getConditionExprent(), dstat.getIncExprent()); for (VarExprent var : getAllVars(lstSpecial)) { if (var.getIndex() == index.intValue()) {