diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index fc3402e47..cf0121416 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -18,7 +18,6 @@ package com.jpexs.decompiler.flash; import SevenZip.Compression.LZMA.Encoder; import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraphSource; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index 4db19ab80..391d55bbb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -27,7 +27,6 @@ import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.action.special.ActionEnd; import com.jpexs.decompiler.flash.action.swf4.*; import com.jpexs.decompiler.flash.action.swf5.*; -import com.jpexs.decompiler.flash.action.swf6.ActionEnumerate2; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.action.treemodel.*; import com.jpexs.decompiler.flash.action.treemodel.clauses.*; @@ -798,7 +797,6 @@ public class Action implements GraphSourceItem { ip++; continue; } - if (action instanceof GraphSourceItemContainer) { GraphSourceItemContainer cnt = (GraphSourceItemContainer) action; //List out=actionsPartToTree(new HashMap(), new HashMap(),new HashMap(), new Stack(), src, ip+1,endip-1 , version); @@ -836,15 +834,15 @@ public class Action implements GraphSourceItem { } /*ActionJump && ActionIf removed*/ - if ((action instanceof ActionEnumerate2) || (action instanceof ActionEnumerate)) { - loopStart = ip + 1; - isForIn = true; - ip += 4; - action.translate(localData, stack, output); - EnumerateTreeItem en = (EnumerateTreeItem) stack.peek(); - inItem = en.object; - continue; - } else /*if (action instanceof ActionTry) { + /*if ((action instanceof ActionEnumerate2) || (action instanceof ActionEnumerate)) { + loopStart = ip + 1; + isForIn = true; + ip += 4; + action.translate(localData, stack, output); + EnumerateTreeItem en = (EnumerateTreeItem) stack.peek(); + inItem = en.object; + continue; + } else*/ /*if (action instanceof ActionTry) { ActionTry atry = (ActionTry) action; List tryCommands = ActionGraph.translateViaGraph(registerNames, variables, functions, atry.tryBody, version); TreeItem catchName; diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index 2d86b58d7..387266a08 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -112,9 +112,10 @@ public class Graph { i = part.path.length(); } if (modify && ((uniqueRefs.size() > 1) && (prvni >= 0))) { - GraphPath newpath = uniqueRefs.get(prvni).path.parent(i); + GraphPath prvniUniq = uniqueRefs.get(prvni).path; + GraphPath newpath = prvniUniq.parent(i); if (!part.path.equals(newpath)) { - if (part.path.startsWith(newpath)) { + if (part.path.startsWith(newpath) && ((newpath.length() == prvniUniq.length()) || (prvniUniq.getKey(newpath.length()) == part.path.getKey(newpath.length())))) { GraphPath origPath = part.path; GraphPart p = part; part.path = newpath; @@ -123,6 +124,7 @@ public class Graph { if (!p.path.equals(origPath)) { break; } + p.path = newpath; } fixGraphOnce(part, new ArrayList(), true); @@ -146,7 +148,7 @@ public class Graph { GraphPart npart = part.nextParts.get(j); if (npart.path.length() > part.path.length() + 1) { - npart.path = part.path.sub(j); + npart.path = part.path.sub(j, part.end); fixed = true; } } @@ -246,7 +248,7 @@ public class Graph { int pos = 0; for (GraphPart p : part.nextParts) { if (!visited.contains(p)) { - p.path = part.path.sub(pos); + p.path = part.path.sub(pos, p.end); } resetGraph(p, visited); pos++; @@ -832,7 +834,6 @@ public class Graph { } loopContinues = getLoopsContinues(loops); - GraphPart next = part.getNextPartPath(loopContinues); List retx = ret; if ((!loop) || (doWhile && (part.nextParts.size() > 1))) { @@ -1293,7 +1294,7 @@ public class Graph { allBlocks.add(part); List branches = ins.getBranches(code); for (int i = 0; i < branches.size(); i++) { - part.nextParts.add(g = makeGraph(part, path.sub(i), code, branches.get(i), ip, allBlocks, refs, visited2)); + part.nextParts.add(g = makeGraph(part, path.sub(i, ip), code, branches.get(i), ip, allBlocks, refs, visited2)); g.refs.add(part); } break; diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java index 2c82b9a2c..9588d8660 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java @@ -69,6 +69,9 @@ public class GraphPart { } private GraphPart getNextPartPath(GraphPart original, GraphPath path, List visited) { + if (visited.contains(this) && (this == original)) { + return null; + } if (visited.contains(this) && (this != original)) { return null; } @@ -92,6 +95,9 @@ public class GraphPart { public GraphPart getNextPartPath(List ignored) { List visited = new ArrayList(); visited.addAll(ignored); + if (visited.contains(this)) { + visited.remove(this); + } return getNextPartPath(this, path, visited); } diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPath.java b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPath.java index f8bd1e69e..3691ef9d1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPath.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPath.java @@ -25,24 +25,35 @@ import java.util.List; */ public class GraphPath { - private List parts = new ArrayList(); + private List keys = new ArrayList(); + private List vals = new ArrayList(); public String rootName = ""; - public GraphPath(String rootName, List parts) { + public GraphPath(String rootName, List keys, List vals) { this.rootName = rootName; - this.parts.addAll(parts); + this.keys.addAll(keys); + this.vals.addAll(vals); } - public GraphPath(List parts) { - this.parts.addAll(parts); + public GraphPath(List keys, List vals) { + this.keys.addAll(keys); + this.vals.addAll(vals); } public boolean startsWith(GraphPath p) { if (p.length() > length()) { return false; } + + + List otherKeys = new ArrayList(p.keys); + List otherVals = new ArrayList(p.vals); + for (int i = 0; i < p.length(); i++) { - if (parts.get(i) != p.get(i)) { + if (keys.get(i) != otherKeys.get(i)) { + return false; + } + if (vals.get(i) != otherVals.get(i)) { return false; } } @@ -52,42 +63,44 @@ public class GraphPath { public GraphPath parent(int len) { GraphPath par = new GraphPath(rootName); for (int i = 0; i < len; i++) { - par.parts.add(parts.get(i)); + par.keys.add(keys.get(i)); + par.vals.add(vals.get(i)); } return par; } - public GraphPath sub(int part) { - GraphPath next = new GraphPath(rootName, this.parts); - next.parts.add(part); + public GraphPath sub(int part, int codePos) { + GraphPath next = new GraphPath(rootName, this.keys, this.vals); + next.keys.add(codePos); + next.vals.add(part); return next; } - public GraphPath(String rootName, Integer... parts) { + public GraphPath(String rootName) { this.rootName = rootName; - for (int p : parts) { - this.parts.add(p); - } } - public GraphPath(Integer... parts) { - for (int p : parts) { - this.parts.add(p); - } + public GraphPath() { } public int length() { - return parts.size(); + return vals.size(); } public int get(int index) { - return parts.get(index); + return vals.get(index); + } + + public int getKey(int index) { + return keys.get(index); } @Override public int hashCode() { - int hash = 7; - hash = 41 * hash + (this.parts != null ? this.parts.hashCode() : 0); + int hash = 5; + hash = 23 * hash + (this.keys != null ? this.keys.hashCode() : 0); + hash = 23 * hash + (this.vals != null ? this.vals.hashCode() : 0); + hash = 23 * hash + (this.rootName != null ? this.rootName.hashCode() : 0); return hash; } @@ -112,11 +125,22 @@ public class GraphPath { return false; } } - if (this.parts.size() != other.parts.size()) { + + if (!arrMatch(keys, other.keys)) { return false; } - for (int i = 0; i < this.parts.size(); i++) { - if (this.parts.get(i) != other.parts.get(i)) { + if (!arrMatch(vals, other.vals)) { + return false; + } + return true; + } + + private static boolean arrMatch(List arr, List arr2) { + if (arr.size() != arr2.size()) { + return false; + } + for (int i = 0; i < arr.size(); i++) { + if (arr.get(i) != arr2.get(i)) { return false; } } @@ -126,8 +150,8 @@ public class GraphPath { @Override public String toString() { String ret = rootName; - for (int i : parts) { - ret += "/" + i; + for (int i = 0; i < keys.size(); i++) { + ret += "/" + keys.get(i) + ":" + vals.get(i); } return ret; }