From 8a154b48e0c56edab17ba519dba0980b44317e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 10 Jul 2015 19:52:29 +0200 Subject: [PATCH] do not use line info in block (obfuscated SWFs break it) Issue #961 Final process fix --- libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java | 7 ++++++- .../src/com/jpexs/decompiler/graph/GraphTargetItem.java | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index cac6cd4be..5e7133e50 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -537,7 +537,7 @@ public class Graph { if (exprLine > 0) { List forFirstCommands = new ArrayList<>(); for (int j = i - 1; j >= 0; j--) { - if (list.get(j).getLine() == exprLine) { + if (list.get(j).getLine() == exprLine && !(list.get(j) instanceof LoopItem /*to avoid recursion and StackOverflow*/)) { forFirstCommands.add(0, list.get(j)); removeFromList.add(j); } else { @@ -571,6 +571,11 @@ public class Graph { } } if (!forFirstCommands.isEmpty() || !forFinalCommands.isEmpty()) { + //Do not allow more than 2 first/final commands, since it can be obfuscated + if (forFirstCommands.size() > 2 || forFinalCommands.size() > 2) { + removeFromList.clear(); + whi.commands.addAll(forFinalCommands); //put it back + } if (whi.commands.isEmpty() && forFirstCommands.isEmpty()) { //it would be for(;expr;commands) {} which looks better as while(expr){commands} whi.commands.addAll(forFinalCommands); //put it back diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java index d2a8d82c3..1ebaa7d72 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -347,13 +347,17 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { } public GraphTextWriter appendBlock(GraphTargetItem prevLineItem, GraphTextWriter writer, LocalData localData, List commands) throws InterruptedException { + + //This may be useful in the future, but we must handle obfuscated SWFs where there is only one debugline instruction on the beggining. + final boolean useLineInfo = false; + int prevLine = prevLineItem == null ? 0 : prevLineItem.getLine(); writer.startBlock(); boolean first = true; for (GraphTargetItem ti : commands) { if (!ti.isEmpty()) { //Use stored line information if available to place commands on same line - if (!first && (ti.getLine() < 1 || prevLine < 1 || (prevLine >= 1 && prevLine != ti.getLine()))) { + if (!first && (!useLineInfo || (ti.getLine() < 1 || prevLine < 1 || (prevLine >= 1 && prevLine != ti.getLine())))) { writer.newLine(); } prevLine = ti.getLine();