private void buildDominatorTree() { VBStyleCollection<Integer, Integer> orderedIDoms = domEngine.getOrderedIDoms(); List<Integer> lstKeys = orderedIDoms.getLstKeys(); for (int index = lstKeys.size() - 1; index >= 0; index--) { Integer key = lstKeys.get(index); Integer idom = orderedIDoms.get(index); mapTreeBranches.computeIfAbsent(idom, k -> new HashSet<>()).add(key); } Integer firstid = statement.getFirst().id; mapTreeBranches.get(firstid).remove(firstid); }
private void buildExceptionRanges() { for (Statement stat : statement.getStats()) { List<Statement> lstPreds = stat.getNeighbours(StatEdge.TYPE_EXCEPTION, Statement.DIRECTION_BACKWARD); if (!lstPreds.isEmpty()) { Set<Integer> set = new HashSet<>(); for (Statement st : lstPreds) { set.add(st.id); } mapExceptionRanges.put(stat.id, set); } } mapExceptionDoms = buildExceptionDoms(statement.getFirst().id); }
private static Statement getFirstExprentlist(Statement stat) { if (stat.getExprents() != null) { return stat; } switch (stat.type) { case Statement.TYPE_IF: case Statement.TYPE_SEQUENCE: case Statement.TYPE_SWITCH: case Statement.TYPE_SYNCRONIZED: return getFirstExprentlist(stat.getFirst()); } return null; }
private static Statement findFirstBlock(Statement stat, Set<Statement> setStats) { LinkedList<Statement> stack = new LinkedList<>(); stack.add(stat); while (!stack.isEmpty()) { Statement st = stack.remove(0); if (stack.isEmpty() || setStats.contains(st)) { if (st.isLabeled() && !stack.isEmpty() || st.getExprents() != null) { return st; } stack.clear(); switch (st.type) { case Statement.TYPE_SEQUENCE: stack.addAll(0, st.getStats()); break; case Statement.TYPE_IF: case Statement.TYPE_ROOT: case Statement.TYPE_SWITCH: case Statement.TYPE_SYNCRONIZED: stack.add(st.getFirst()); break; default: return st; } } } return null; }
case Statement.TYPE_SWITCH: case Statement.TYPE_SYNCRONIZED: stack.add(st.getFirst()); break; default:
public StrongConnectivityHelper(Statement stat) { components = new ArrayList<>(); setProcessed = new HashSet<>(); visitTree(stat.getFirst()); for (Statement st : stat.getStats()) { if (!setProcessed.contains(st) && st.getPredecessorEdges(Statement.STATEDGE_DIRECT_ALL).isEmpty()) { visitTree(st); } } // should not find any more nodes! FIXME: ?? for (Statement st : stat.getStats()) { if (!setProcessed.contains(st)) { visitTree(st); } } }
private static Integer getFirstProtectedRange(Statement stat) { while (true) { Statement parent = stat.getParent(); if (parent == null) { break; } if (parent.type == Statement.TYPE_CATCHALL || parent.type == Statement.TYPE_TRYCATCH) { if (parent.getFirst() == stat) { return parent.id; } } else if (parent.type == Statement.TYPE_SYNCRONIZED) { if (((SynchronizedStatement)parent).getBody() == stat) { return parent.id; } } stat = parent; } return null; }
public void initialize() { domEngine = new DominatorEngine(statement); domEngine.initialize(); buildDominatorTree(); buildExceptionRanges(); buildFilter(statement.getFirst().id); // free resources mapTreeBranches.clear(); mapExceptionRanges.clear(); }
public static Statement findFirstData(Statement stat) { if (stat.getExprents() != null) { return stat; } else if (stat.isLabeled()) { // FIXME: Why?? return null; } switch (stat.type) { case Statement.TYPE_SEQUENCE: case Statement.TYPE_IF: case Statement.TYPE_ROOT: case Statement.TYPE_SWITCH: case Statement.TYPE_SYNCRONIZED: return findFirstData(stat.getFirst()); default: return null; } }
private void calcIDoms() { orderStatements(); colOrderedIDoms.putWithKey(statement.getFirst().id, statement.getFirst().id); // exclude first statement List<Integer> lstIds = colOrderedIDoms.getLstKeys().subList(1, colOrderedIDoms.getLstKeys().size()); while (true) { boolean changed = false; for (Integer id : lstIds) { Statement stat = statement.getStats().getWithKey(id); Integer idom = null; for (StatEdge edge : stat.getAllPredecessorEdges()) { if (colOrderedIDoms.getWithKey(edge.getSource().id) != null) { idom = getCommonIDom(idom, edge.getSource().id, colOrderedIDoms); } } Integer oldidom = colOrderedIDoms.putWithKey(idom, id); if (!idom.equals(oldidom)) { changed = true; } } if (!changed) { break; } } }
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; }
stat == parent.getFirst() && !parent.isCopied()) {
private static boolean sameCatchRanges(StatEdge edge) { Statement from = edge.getSource(); Statement to = edge.getDestination(); while (true) { Statement parent = from.getParent(); if (parent.containsStatementStrict(to)) { break; } if (parent.type == Statement.TYPE_TRYCATCH || parent.type == Statement.TYPE_CATCHALL) { if (parent.getFirst() == from) { return false; } } else if (parent.type == Statement.TYPE_SYNCRONIZED) { if (parent.getStats().get(1) == from) { return false; } } from = parent; } return true; }
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(); } }
private static boolean collapseInlinedClass14(Statement stat) { boolean ret = class14Builder.match(stat); if (ret) { String class_name = (String)class14Builder.getVariableValue("$classname$"); AssignmentExprent assignment = (AssignmentExprent)class14Builder.getVariableValue("$assignfield$"); FieldExprent fieldExpr = (FieldExprent)class14Builder.getVariableValue("$field$"); assignment.replaceExprent(assignment.getRight(), new ConstExprent(VarType.VARTYPE_CLASS, class_name, null)); List<Exprent> data = new ArrayList<>(stat.getFirst().getExprents()); stat.setExprents(data); SequenceHelper.destroyAndFlattenStatement(stat); ClassWrapper wrapper = (ClassWrapper)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS_WRAPPER); if (wrapper != null) { wrapper.getHiddenMembers().add(InterpreterUtil.makeUniqueKey(fieldExpr.getName(), fieldExpr.getDescriptor().descriptorString)); } } return ret; } }
public static void lowContinueLabels(Statement stat, HashSet<StatEdge> edges) { boolean ok = (stat.type != Statement.TYPE_DO); if (!ok) { DoStatement dostat = (DoStatement)stat; ok = dostat.getLooptype() == DoStatement.LOOP_DO || dostat.getLooptype() == DoStatement.LOOP_WHILE || (dostat.getLooptype() == DoStatement.LOOP_FOR && dostat.getIncExprent() == null); } if (ok) { edges.addAll(stat.getPredecessorEdges(StatEdge.TYPE_CONTINUE)); } if (ok && stat.type == Statement.TYPE_DO) { for (StatEdge edge : edges) { if (stat.containsStatementStrict(edge.getSource())) { edge.getDestination().removePredecessor(edge); edge.getSource().changeEdgeNode(Statement.DIRECTION_FORWARD, edge, stat); stat.addPredecessor(edge); stat.addLabeledEdge(edge); } } } for (Statement st : stat.getStats()) { if (st == stat.getFirst()) { lowContinueLabels(st, edges); } else { lowContinueLabels(st, new HashSet<>()); } } }
next = next.getFirst();
source == parent.getFirst()) { IfStatement ifparent = (IfStatement)parent; SequenceStatement block = new SequenceStatement(lst);