diff --git a/CHANGELOG.md b/CHANGELOG.md index b91d9ece9..e370fbed5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Fixed - [#1888] Casts for missing types, cast handling for script local classes +- [#1895] Handling of unstructured switch ## [17.0.3] - 2022-11-30 ### Added @@ -2537,7 +2538,8 @@ All notable changes to this project will be documented in this file. ### Added - Initial public release -[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.2...dev +[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.3...dev +[17.0.3]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.2...version17.0.3 [17.0.2]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.1...version17.0.2 [17.0.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.0...version17.0.1 [17.0.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.3.1...version17.0.0 @@ -2670,8 +2672,9 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 -[#1769]: https://www.free-decompiler.com/flash/issues/1769 [#1888]: https://www.free-decompiler.com/flash/issues/1888 +[#1895]: https://www.free-decompiler.com/flash/issues/1895 +[#1769]: https://www.free-decompiler.com/flash/issues/1769 [#1890]: https://www.free-decompiler.com/flash/issues/1890 [#1810]: https://www.free-decompiler.com/flash/issues/1810 [#1891]: https://www.free-decompiler.com/flash/issues/1891 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 905d8e119..3844acb42 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -363,7 +363,7 @@ public class Graph { } } - List> reachable = new ArrayList<>(); + Map> reachable = new HashMap<>(); Set allReachable = new LinkedHashSet<>(); for (GraphPart p : parts) { LinkedHashSet r1 = new LinkedHashSet<>(); @@ -371,12 +371,10 @@ public class Graph { Set r2 = new LinkedHashSet<>(); r2.add(p); r2.addAll(r1); - reachable.add(r2); + reachable.put(p, r2); allReachable.add(p); allReachable.addAll(r1); } - int maxCommonLevel = -1; - GraphPart maxCommonPart = null; Set commonSet = new TreeSet<>(); for (GraphPart r : allReachable) { if (loopContinues.contains(r)) { @@ -389,7 +387,7 @@ public class Graph { commonLevel++; continue; } - if (!p.leadsTo(localData, this, code, r, loops, throwStates, false)) { + if (!reachable.get(p).contains(r)) { common = false; } else { commonLevel++; @@ -434,6 +432,9 @@ public class Graph { } if (common) { + if (debugPrintLoopList) { + System.err.println("all time common: " + r); + } return r; } } @@ -455,33 +456,33 @@ public class Graph { } } } - + if (debugPrintLoopList) { System.err.println("commonset:"); for (PartCommon pc : commonSet) { System.err.println("- " + pc); } - + System.err.println("parts:"); - for(GraphPart p :parts) { - System.err.println("- "+p); - } + for (GraphPart p : parts) { + System.err.println("- " + p); + } if (stopPart != null) { System.err.println("stopparts:"); - for(GraphPart p :stopPart) { - System.err.println("- "+p); + for (GraphPart p : stopPart) { + System.err.println("- " + p); } } - + System.err.println("partsLeadingToStopPart:"); for (GraphPart p : partsLeadingToStopPart) { System.err.println("- " + p); } - - if (partsLeadingToStopPart.isEmpty()) { + + /*if (partsLeadingToStopPart.isEmpty()) { return null; //? - } + }*/ } loopc: @@ -518,7 +519,11 @@ public class Graph { @Override public int compareTo(PartCommon o) { - return o.level - level; + int ret = o.level - level; + if (ret == 0) { + ret = part.start - o.part.start; + } + return ret; } @Override @@ -655,7 +660,7 @@ public class Graph { if (localData.secondPassData == null) { SecondPassData secondPassData = prepareSecondPass(ret); - if (secondPassData == null) { + if (secondPassData == null) { if (!localData.allSwitchParts.isEmpty()) { secondPassData = new SecondPassData(); secondPassData.allSwitchParts = localData.allSwitchParts; @@ -1885,24 +1890,23 @@ public class Graph { GraphPart winner = null; int winnerCount = 0; int winnerNumBlock = Integer.MAX_VALUE; - + Set bannedCandidates = new HashSet<>(); - if(localData.secondPassData != null) { + if (localData.secondPassData != null) { bannedCandidates = localData.secondPassData.allSwitchParts; } - + if (debugPrintLoopList) { System.err.println("bannedCandidates:"); - for(GraphPart p:bannedCandidates) { - System.err.println("- "+p); + for (GraphPart p : bannedCandidates) { + System.err.println("- " + p); } - } - + for (GraphPart cand : currentLoop.breakCandidates) { if (bannedCandidates.contains(cand)) { if (debugPrintLoopList) { - System.err.println("cand "+cand+" is banned"); + System.err.println("cand " + cand + " is banned"); } continue; } @@ -2790,7 +2794,7 @@ public class Graph { } boolean isAllNotBlock = true; - for (GraphTargetItem ti: precoCommands) { + for (GraphTargetItem ti : precoCommands) { if (ti instanceof Block) { isAllNotBlock = false; break; @@ -3208,7 +3212,7 @@ public class Graph { } } } - + protected SwitchItem handleSwitch(GraphTargetItem switchedObject, GraphSourceItem switchStartItem, List foundGotos, Map> partCodes, Map partCodePos, Set visited, Set allParts, TranslateStack stack, List stopPart, List stopPartKind, List loops, List throwStates, BaseLocalData localData, int staticOperation, String path, List caseValuesMap, GraphPart defaultPart, List caseBodyParts, Reference nextRef, Reference tiRef) throws InterruptedException { @@ -3318,6 +3322,9 @@ public class Graph { for (int j = i + 1; j < caseBodies.size(); j++) { GraphPart b2 = caseBodies.get(j); if (b2.leadsTo(localData, this, code, b, loops, throwStates, false)) { + if (b.leadsTo(localData, this, code, b2, loops, throwStates, false)) { //unstructured code + continue; + } caseBodies.remove(j); caseBodies.add(i, b2); i--; @@ -3346,8 +3353,8 @@ public class Graph { } } - localData.allSwitchParts.add(caseBodies.get(i)); - + localData.allSwitchParts.add(caseBodies.get(i)); + List stopPart2x = new ArrayList<>(stopPart); List stopPartKind2x = new ArrayList<>(stopPartKind); for (GraphPart b : caseBodies) { diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index d355c8584..f3840dc73 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -25,7 +25,6 @@ import com.jpexs.debugger.flash.DebuggerCommands; import com.jpexs.debugger.flash.Variable; import com.jpexs.debugger.flash.VariableType; import com.jpexs.debugger.flash.messages.in.InCallFunction; -import com.jpexs.decompiler.flash.AppResources; import com.jpexs.decompiler.flash.ApplicationInfo; import com.jpexs.decompiler.flash.EventListener; import com.jpexs.decompiler.flash.SWF; @@ -134,7 +133,6 @@ import javax.swing.UnsupportedLookAndFeelException; import javax.swing.filechooser.FileFilter; import org.pushingpixels.substance.api.SubstanceLookAndFeel; import com.jpexs.decompiler.flash.Bundle; -import com.jpexs.decompiler.flash.EndOfStreamException; import com.jpexs.decompiler.flash.OpenableSourceKind; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ABCInputStream; @@ -142,7 +140,6 @@ import com.jpexs.decompiler.flash.abc.ABCOpenException; import com.jpexs.decompiler.flash.tags.DoABC2Tag; import com.jpexs.decompiler.flash.treeitems.Openable; import com.jpexs.helpers.MemoryInputStream; -import java.awt.GraphicsDevice; /** * Main executable class