@Override public Statement getSimpleCopy() { IfStatement is = new IfStatement(); is.iftype = this.iftype; is.negated = this.negated; return is; }
Statement parent = firstif.getParent(); if (secondif.getFirst().getExprents().isEmpty()) { firstif.getFirst().removeSuccessor(firstif.getIfEdge()); firstif.removeAllSuccessors(secondif); for (StatEdge edge : firstif.getAllPredecessorEdges()) { if (!firstif.containsStatementStrict(edge.getSource())) { firstif.removePredecessor(edge); edge.getSource().changeEdgeNode(Statement.DIRECTION_FORWARD, edge, secondif); secondif.addPredecessor(edge); IfExprent statexpr = secondif.getHeadexprent(); lstOperands.add(firstif.getHeadexprent().getCondition()); if (secondif.getFirst().getExprents().isEmpty() && !firstif.getFirst().getExprents().isEmpty()) { secondif.replaceStatement(secondif.getFirst(), firstif.getFirst()); firstif.removeAllSuccessors(second); firstif.addSuccessor(edge); StatEdge ifedge = firstif.getIfEdge(); firstif.getFirst().removeSuccessor(ifedge);
Statement ifstat = ifelsestat.getIfstat(); ifelsestat.getStats().removeWithKey(ifstat.id); ifelsestat.setIfstat(ifelsestat.getElsestat()); ifelsestat.setElsestat(null); if (ifelsestat.getAllSuccessorEdges().isEmpty() && !ifstat.getAllSuccessorEdges().isEmpty()) { StatEdge endedge = ifstat.getAllSuccessorEdges().get(0); endedge.setSource(ifelsestat); if (endedge.closure != null) { ifelsestat.getParent().addLabeledEdge(endedge); ifelsestat.addSuccessor(endedge); ifelsestat.getFirst().removeSuccessor(ifelsestat.getIfEdge()); ifelsestat.setIfEdge(ifelsestat.getElseEdge()); ifelsestat.setElseEdge(null); ifelsestat.setNegated(!ifelsestat.isNegated()); ifelsestat.getHeadexprentList().set(0, ((IfExprent)ifelsestat.getHeadexprent().copy()).negateIf());
private static void removeParameterCheck(Statement stat) { Statement st = stat.getFirst(); while (st.type == Statement.TYPE_SEQUENCE) { st = st.getFirst(); } IfStatement ifstat = (IfStatement)st; if (ifstat.getElsestat() != null) { // if - else StatEdge ifedge = ifstat.getIfEdge(); StatEdge elseedge = ifstat.getElseEdge(); Statement ifbranch = ifstat.getIfstat(); Statement elsebranch = ifstat.getElsestat(); ifstat.getFirst().removeSuccessor(ifedge); ifstat.getFirst().removeSuccessor(elseedge); ifstat.getStats().removeWithKey(ifbranch.id); ifstat.getStats().removeWithKey(elsebranch.id); if (!ifbranch.getAllSuccessorEdges().isEmpty()) { ifbranch.removeSuccessor(ifbranch.getAllSuccessorEdges().get(0)); } ifstat.getParent().replaceStatement(ifstat, elsebranch); ifstat.getParent().setAllParent(); } }
IfStatement ifchild = (IfStatement)ifbranch.value; if (ifchild.getFirst().getExprents().isEmpty()) { ifparent.getFirst().removeSuccessor(ifparent.getIfEdge()); ifchild.getFirst().removeSuccessor(ifchild.getIfEdge()); ifparent.getStats().removeWithKey(ifchild.id); ifparent.setIfstat(null); StatEdge ifedge = ifchild.getAllSuccessorEdges().get(0); ifchild.removeSuccessor(ifedge); ifedge.setSource(ifparent.getFirst()); ifparent.getFirst().addSuccessor(ifedge); ifparent.setIfEdge(ifedge); IfExprent statexpr = ifparent.getHeadexprent(); lstOperands.add(new FunctionExprent(FunctionExprent.FUNCTION_BOOL_NOT, ifchild.getHeadexprent().getCondition(), null)); statexpr.setCondition(new FunctionExprent(FunctionExprent.FUNCTION_CADD, lstOperands, null)); statexpr.addBytecodeOffsets(ifchild.getHeadexprent().bytecode);
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; }
Statement parent = ifstat.getParent(); Statement from = parent.type == Statement.TYPE_SEQUENCE ? parent : ifstat; if (ifstat.getIfstat() == null) { noifstat = true; ifdirect = ifstat.getIfEdge().getType() == StatEdge.TYPE_FINALLYEXIT || MergeHelper.isDirectPath(from, ifstat.getIfEdge().getDestination()); List<StatEdge> lstSuccs = ifstat.getIfstat().getAllSuccessorEdges(); ifdirect = !lstSuccs.isEmpty() && lstSuccs.get(0).getType() == StatEdge.TYPE_FINALLYEXIT || hasDirectEndEdge(ifstat.getIfstat(), from); if (!noelsestat && existsPath(ifstat, ifstat.getAllSuccessorEdges().get(0).getDestination())) { return false; ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); for (Statement st : lst) { sequence.getStats().removeWithKey(st.id); StatEdge elseedge = new StatEdge(StatEdge.TYPE_REGULAR, ifstat.getFirst(), stelse); ifstat.getFirst().addSuccessor(elseedge); ifstat.setElsestat(stelse); ifstat.setElseEdge(elseedge); ifstat.getStats().addWithKey(stelse, stelse.id); stelse.setParent(ifstat); IfExprent statexpr = ifstat.getHeadexprent();
Exprent if_condition = ifparent.getHeadexprent().getCondition(); if (ifparent.getElsestat() == stat && if_condition.type == Exprent.EXPRENT_FUNCTION && StatEdge ifedge = ifparent.getIfEdge(); StatEdge elseedge = ifparent.getElseEdge(); Statement ifbranch = ifparent.getIfstat(); Statement elsebranch = ifparent.getElsestat(); ifparent.getFirst().removeSuccessor(ifedge); ifparent.getFirst().removeSuccessor(elseedge); ifparent.getStats().removeWithKey(ifbranch.id); ifparent.getStats().removeWithKey(elsebranch.id); if (!ifparent.getFirst().getExprents().isEmpty()) { elsebranch.getExprents().addAll(0, ifparent.getFirst().getExprents()); ifparent.getParent().replaceStatement(ifparent, elsebranch); ifparent.getParent().setAllParent(); Exprent if_condition = ifstat.getHeadexprent().getCondition(); Statement ifbranch = ifstat.getIfstat(); ifstat.removeSuccessor(ifstat.getAllSuccessorEdges().get(0)); // remove 'else' edge if (!ifstat.getFirst().getExprents().isEmpty()) {
if (lastif.iftype == IfStatement.IFTYPE_IF && lastif.getIfstat() == null) { StatEdge ifedge = lastif.getIfEdge(); StatEdge elseedge = lastif.getAllSuccessorEdges().get(0); IfExprent ifexpr = (IfExprent)lastif.getHeadexprent().copy(); if (ifedge.getType() == StatEdge.TYPE_BREAK) { ifexpr.negateIf(); lastif.getFirst().removeSuccessor(ifedge); lastif.removeSuccessor(elseedge); if (lastif.getFirst().getExprents().isEmpty()) { removeLastEmptyStatement(stat, lastif); lastif.setExprents(lastif.getFirst().getExprents()); lastif.addSuccessor(newedge); stat.addLabeledEdge(newedge);
private static boolean buildIff(Statement stat, SSAConstructorSparseEx ssa) { if (stat.type == Statement.TYPE_IF && stat.getExprents() == null) { IfStatement statement = (IfStatement)stat; Exprent ifHeadExpr = statement.getHeadexprent(); Set<Integer> ifHeadExprBytecode = (ifHeadExpr == null ? null : ifHeadExpr.bytecode); Statement ifStatement = statement.getIfstat(); Statement elseStatement = statement.getElsestat(); List<Exprent> data = new ArrayList<>(statement.getFirst().getExprents()); List<Exprent> operands = Arrays.asList(statement.getHeadexprent().getCondition(), ifAssign.getRight(), elseAssign.getRight()); data.add(new AssignmentExprent(ifVar, new FunctionExprent(FunctionExprent.FUNCTION_IIF, operands, ifHeadExprBytecode), ifHeadExprBytecode)); statement.setExprents(data); if (statement.getAllSuccessorEdges().isEmpty()) { StatEdge ifEdge = ifStatement.getAllSuccessorEdges().get(0); StatEdge edge = new StatEdge(ifEdge.getType(), statement, ifEdge.getDestination()); statement.addSuccessor(edge); if (ifEdge.closure != null) { ifEdge.closure.addLabeledEdge(edge); List<Exprent> data = new ArrayList<>(statement.getFirst().getExprents()); statement.getHeadexprent().getCondition(), ifExit.getValue(), elseExit.getValue()), ifHeadExprBytecode), ifExit.getRetType(), ifHeadExprBytecode)); statement.setExprents(data);
Statement ifstat = stat.getIfstat(); InvocationExprent throwError = isAssertionError(ifstat); Statement elsestat = stat.getElsestat(); throwError = isAssertionError(elsestat); if (throwError == null) { Object[] exprres = getAssertionExprent(stat.getHeadexprent().getCondition().copy(), classname, key, throwInIf); if (!(Boolean)exprres[1]) { return false; Statement first = stat.getFirst(); first.removeSuccessor(stat.getIfEdge()); first.removeSuccessor(stat.getElseEdge()); if (stat.iftype == IfStatement.IFTYPE_IFELSE) { if (throwInIf) { lstStatements.add(stat.getElsestat()); lstStatements.add(stat.getIfstat()); Statement stmts; if (throwInIf) { stmts = stat.getElsestat(); stmts = stat.getIfstat(); newstat.getVarDefinitions().addAll(stat.getVarDefinitions());
if (firstif.getFirst().getExprents().isEmpty()) { if (firstif.getIfstat() == null) { StatEdge ifedge = firstif.getIfEdge(); if (isDirectPath(stat, ifedge.getDestination())) { IfExprent ifexpr = (IfExprent)firstif.getHeadexprent().copy(); ifexpr.negateIf(); stat.setConditionExprent(ifexpr.getCondition()); firstif.getFirst().removeSuccessor(ifedge); firstif.removeSuccessor(firstif.getAllSuccessorEdges().get(0)); Statement sequence = firstif.getParent(); sequence.getStats().removeWithKey(firstif.id); sequence.setFirst(sequence.getStats().get(0)); StatEdge elseedge = firstif.getAllSuccessorEdges().get(0); if (isDirectPath(stat, elseedge.getDestination())) { stat.setConditionExprent(((IfExprent)firstif.getHeadexprent().copy()).getCondition()); StatEdge ifedge = firstif.getIfEdge(); firstif.getFirst().removeSuccessor(ifedge); firstif.removeSuccessor(elseedge); if (firstif.getIfstat() == null) { BasicBlockStatement bstat = new BasicBlockStatement(new BasicBlock( DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.STATEMENT_COUNTER)));
if (ifst.getIfstat() == null) { StatEdge ifedge = ifst.getIfEdge(); dest = isExitEdge(ifedge); if (dest != null) { bstat.setExprents(DecHelper.copyExprentList(dest.getExprents())); ifst.getFirst().removeSuccessor(ifedge); StatEdge newedge = new StatEdge(StatEdge.TYPE_REGULAR, ifst.getFirst(), bstat); ifst.getFirst().addSuccessor(newedge); ifst.setIfEdge(newedge); ifst.setIfstat(bstat); ifst.getStats().addWithKey(bstat, bstat.id); bstat.setParent(ifst);
Statement ifchild = stat.getIfstat(); if (ifchild == null) { StatEdge edge = stat.getIfEdge(); res.addChild(new IfNode(edge.getDestination()), 1); if (ifchild.type == Statement.TYPE_IF && ((IfStatement)ifchild).iftype == IfStatement.IFTYPE_IF) { IfStatement stat2 = (IfStatement)ifchild; Statement ifchild2 = stat2.getIfstat(); if (ifchild2 == null) { StatEdge edge = stat2.getIfEdge(); ifnode.addChild(new IfNode(edge.getDestination()), 1); StatEdge edge = stat.getAllSuccessorEdges().get(0); Statement elsechild = edge.getDestination(); IfNode elsenode = new IfNode(elsechild); if (elsechild.type == Statement.TYPE_IF && ((IfStatement)elsechild).iftype == IfStatement.IFTYPE_IF) { IfStatement stat2 = (IfStatement)elsechild; Statement ifchild2 = stat2.getIfstat(); if (ifchild2 == null) { elsenode.addChild(new IfNode(stat2.getIfEdge().getDestination()), 1);
IfStatement ifstat = (IfStatement)stat; if (ifstat.getIfstat() == null) { // empty if processEdgesWithNext(ifstat.getFirst(), mapEdges, null); mapEdges = setExplicitEdges(ifstat.getIfstat()); processEdgesWithNext(ifstat.getIfstat(), mapEdges, null); if (ifstat.getElsestat() != null) { mapEdges1 = setExplicitEdges(ifstat.getElsestat()); processEdgesWithNext(ifstat.getElsestat(), mapEdges1, null);
IfStatement ifstat = (IfStatement)stat; if (ifstat.iftype == IfStatement.IFTYPE_IFELSE) { return hasDirectEndEdge(ifstat.getIfstat(), from) || hasDirectEndEdge(ifstat.getElsestat(), from);
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; }
Statement ifbranch = ifstat.getIfstat(); Exprent if_condition = ifstat.getHeadexprent().getCondition();
@Override public IMatchable findObject(MatchNode matchNode, int index) { IMatchable object = super.findObject(matchNode, index); if (object != null) { return object; } if (matchNode.getType() == MatchNode.MATCHNODE_EXPRENT) { String position = (String)matchNode.getRuleValue(MatchProperties.EXPRENT_POSITION); if ("head".equals(position)) { return getHeadexprent(); } } return null; }
head.removeSuccessor(edge); edge.setSource(this); this.addSuccessor(edge);