diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index c70f99ed1..d5267840f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.action.swf5.*; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.action.treemodel.*; import com.jpexs.decompiler.flash.action.treemodel.clauses.*; +import com.jpexs.decompiler.flash.graph.CommentItem; import com.jpexs.decompiler.flash.graph.Graph; import com.jpexs.decompiler.flash.graph.GraphSource; import com.jpexs.decompiler.flash.graph.GraphSourceItem; @@ -800,7 +801,14 @@ public class Action implements GraphSourceItem { outs.add(new ArrayList()); continue; } - List out = ActionGraph.translateViaGraph(cnt.getRegNames(), variables, functions, actions.subList(adr2ip(actions, endAddr, version), adr2ip(actions, endAddr + size, version)), version); + List out; + try { + out = ActionGraph.translateViaGraph(cnt.getRegNames(), variables, functions, actions.subList(adr2ip(actions, endAddr, version), adr2ip(actions, endAddr + size, version)), version); + } catch (RuntimeException re) { + out = new ArrayList<>(); + out.add(new CommentItem("Error " + re.getMessage())); + Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Error during container translation", re); + } outs.add(out); endAddr += size; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java index c0e2cdf85..0dd0e1d61 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java @@ -54,7 +54,7 @@ public class ActionSetProperty extends Action { if (value.getThroughDuplicate() instanceof IncrementTreeItem) { GraphTargetItem obj = ((IncrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostIncrementTreeItem(this, obj)); return; @@ -64,7 +64,7 @@ public class ActionSetProperty extends Action { if (value instanceof DecrementTreeItem) { GraphTargetItem obj = ((DecrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostDecrementTreeItem(this, obj)); return; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java index 0305524eb..99733cec4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java @@ -50,7 +50,7 @@ public class ActionSetVariable extends Action { if (value instanceof IncrementTreeItem) { GraphTargetItem obj = ((IncrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostIncrementTreeItem(this, obj)); return; @@ -60,7 +60,7 @@ public class ActionSetVariable extends Action { if (value instanceof DecrementTreeItem) { GraphTargetItem obj = ((DecrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostDecrementTreeItem(this, obj)); return; @@ -69,7 +69,7 @@ public class ActionSetVariable extends Action { } if (value instanceof IncrementTreeItem) { if (((IncrementTreeItem) value).object instanceof GetVariableTreeItem) { - if (((GetVariableTreeItem) ((IncrementTreeItem) value).object).name.equals(name)) { + if (((GetVariableTreeItem) ((IncrementTreeItem) value).object).name.valueEquals(name)) { output.add(new PostIncrementTreeItem(this, ((IncrementTreeItem) value).object)); return; } @@ -77,7 +77,7 @@ public class ActionSetVariable extends Action { } if (value instanceof DecrementTreeItem) { if (((DecrementTreeItem) value).object instanceof GetVariableTreeItem) { - if (((GetVariableTreeItem) ((DecrementTreeItem) value).object).name.equals(name)) { + if (((GetVariableTreeItem) ((DecrementTreeItem) value).object).name.valueEquals(name)) { output.add(new PostDecrementTreeItem(this, ((DecrementTreeItem) value).object)); return; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java index 445b1f4c7..f70742553 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java @@ -48,7 +48,7 @@ public class ActionSetMember extends Action { if (value instanceof IncrementTreeItem) { GraphTargetItem obj = ((IncrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostIncrementTreeItem(this, obj)); return; @@ -58,7 +58,7 @@ public class ActionSetMember extends Action { if (value instanceof DecrementTreeItem) { GraphTargetItem obj = ((DecrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostDecrementTreeItem(this, obj)); return; @@ -78,7 +78,7 @@ public class ActionSetMember extends Action { } if (value instanceof DecrementTreeItem) { if (((DecrementTreeItem) value).object instanceof GetMemberTreeItem) { - if (((GetMemberTreeItem) ((DecrementTreeItem) value).object).object.equals(object)) { + if (((GetMemberTreeItem) ((DecrementTreeItem) value).object).object.valueEquals(object)) { if (((GetMemberTreeItem) ((DecrementTreeItem) value).object).memberName.equals(memberName)) { output.add(new PostDecrementTreeItem(this, ((DecrementTreeItem) value).object)); return; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java index ccd4a4a48..31b96aa36 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java @@ -100,7 +100,7 @@ public class ActionStoreRegister extends Action { if (value instanceof IncrementTreeItem) { GraphTargetItem obj = ((IncrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostIncrementTreeItem(this, obj)); stack.push(obj); @@ -111,7 +111,7 @@ public class ActionStoreRegister extends Action { if (value instanceof DecrementTreeItem) { GraphTargetItem obj = ((DecrementTreeItem) value).object; if (!stack.isEmpty()) { - if (stack.peek().equals(obj)) { + if (stack.peek().valueEquals(obj)) { stack.pop(); stack.push(new PostDecrementTreeItem(this, obj)); stack.push(obj); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java index 295c27053..b5a5848ef 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DirectValueTreeItem.java @@ -195,9 +195,27 @@ public class DirectValueTreeItem extends TreeItem { @Override public int hashCode() { int hash = 7; + hash = 71 * hash + Objects.hashCode(this.value); + hash = 71 * hash + Objects.hashCode(this.constants); + hash = 71 * hash + pos; return hash; } + @Override + public boolean valueEquals(GraphTargetItem obj) { + if (obj == null) { + return false; + } + final DirectValueTreeItem other = (DirectValueTreeItem) obj; + if (!Objects.equals(this.value, other.value)) { + return false; + } + if (!Objects.equals(this.constants, other.constants)) { + return false; + } + return true; + } + @Override public boolean equals(Object obj) { if (obj == null) { diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index 53f6a2cf6..7fc6b1c0e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -343,7 +343,12 @@ public class Graph { return null; } - List loopContinues = getLoopsContinues(loops); + List loopContinues = new ArrayList<>();//getLoopsContinues(loops); + for (Loop l : loops) { + if (l.phase == 1) { + loopContinues.add(l.loopContinue); + } + } for (GraphPart p : parts) { if (loopContinues.contains(p)) { @@ -417,9 +422,9 @@ public class Graph { System.out.println("");*/ getPrecontinues(null, heads.get(0), loops, null); /*System.out.println(""); - for (Loop el : loops) { - System.out.println(el); - } + for (Loop el : loops) { + System.out.println(el); + } System.out.println("");*/ List ret = printGraph(new ArrayList(), localData, stack, allParts, null, heads.get(0), null, loops); @@ -962,6 +967,9 @@ public class Graph { } for (int i = currentLoop.breakCandidates.size() - 1; i >= 0; i--) { if (spcheck.contains(currentLoop.breakCandidates.get(i))) { + if (currentLoop.breakCandidates.get(i).start >= code.size()) { + continue; + } currentLoop.breakCandidatesLevels.remove(i); backupCandidates.add(currentLoop.breakCandidates.remove(i)); } @@ -1028,7 +1036,7 @@ public class Graph { } removed.add(found); } - } while (found != null); + } while ((found != null) && (currentLoop.breakCandidates.size() > 1)); Map count = new HashMap<>(); GraphPart winner = null; @@ -1237,14 +1245,23 @@ public class Graph { continue; } if (el.loopBreak == part) { + if (currentLoop != null) { + currentLoop.phase = 0; + } ret.add(new BreakItem(null, el.id)); return ret; } if (el.loopPreContinue == part) { + if (currentLoop != null) { + currentLoop.phase = 0; + } ret.add(new ContinueItem(null, el.id)); return ret; } if (el.loopContinue == part) { + if (currentLoop != null) { + currentLoop.phase = 0; + } ret.add(new ContinueItem(null, el.id)); return ret; } @@ -1253,6 +1270,9 @@ public class Graph { if (stopPart.contains(part)) { + if (currentLoop != null) { + currentLoop.phase = 0; + } return ret; } @@ -1613,14 +1633,18 @@ public class Graph { List commands = new ArrayList<>(); - loopItem.commands.remove(loopItem.commands.size() - 1); + if (!bodyBranch.isEmpty()) { - /*exprList.addAll(loopItem.commands); + ret.add(index, loopItem); + /* + loopItem.commands.remove(loopItem.commands.size() - 1); + exprList.addAll(loopItem.commands); commands.addAll(bodyBranch); exprList.add(expr); checkContinueAtTheEnd(commands, currentLoop); ret.add(index, li = new WhileItem(null, currentLoop, exprList, commands));*/ } else { + loopItem.commands.remove(loopItem.commands.size() - 1); commands.addAll(loopItem.commands); commands.addAll(bodyBranch); exprList.add(expr); diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java index 9d9d99acd..53e3547cc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java @@ -74,7 +74,7 @@ public class GraphPart { return false; } if (l.loopBreak == this) { - return false; + //return false; //? } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java index c47ac691e..0187163c0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/GraphTargetItem.java @@ -162,4 +162,8 @@ public abstract class GraphTargetItem { public GraphTargetItem getThroughDuplicate() { return this; } + + public boolean valueEquals(GraphTargetItem target) { + return equals(target); + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 36bc3e4b2..0d68d4707 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -426,9 +426,6 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi JMenuItem miGotoDocumentClass = new JMenuItem("Go to document class"); miGotoDocumentClass.setActionCommand("GOTODOCUMENTCLASS"); miGotoDocumentClass.addActionListener(this); - if (swf.fileAttributes.actionScript3) { - menuTools.add(miGotoDocumentClass); - } menuBar.add(menuTools); JMenu menuSettings = new JMenu("Settings"); @@ -499,6 +496,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi if (!abcList.isEmpty()) { addTab(tabPane, abcPanel = new ABCPanel(abcList), "ActionScript3", View.getIcon("as16")); detailPanel.add(abcPanel.tabbedPane, DETAILCARDAS3NAVIGATOR); + menuTools.add(miGotoDocumentClass); } else { actionPanel = new ActionPanel(); addTab(tabPane, actionPanel, "ActionScript", View.getIcon("as16"));