diff --git a/CHANGELOG.md b/CHANGELOG.md index 03198e347..809f86026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Better continue in for handling +- AS1/2 For in break detection with inner switch statement - AS1/2 Using temporary registers after for..in (causing incorrect chained assignments handling, etc.) - AS1/2 getProperty, setProperty handling - AS1/2 callmethod action arguments diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java index 2a5aa4585..e99285d33 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java @@ -56,6 +56,7 @@ import com.jpexs.decompiler.graph.model.ContinueItem; import com.jpexs.decompiler.graph.model.DefaultItem; import com.jpexs.decompiler.graph.model.IfItem; import com.jpexs.decompiler.graph.model.SwitchItem; +import com.jpexs.decompiler.graph.model.UniversalLoopItem; import com.jpexs.decompiler.graph.model.WhileItem; import com.jpexs.helpers.Helper; import java.util.ArrayList; @@ -140,6 +141,24 @@ public class ActionGraph extends Graph { } } + @Override + protected boolean canBeBreakCandidate(GraphPart part) { + if (part.refs.size() <= 1) { + return true; + } + boolean isSwitch = true; + for (GraphPart r : part.refs) { + if (code.get(r.end) instanceof ActionIf) { + if (!(r.start < r.end - 1 && (code.get(r.end - 1) instanceof ActionStrictEquals))) { + isSwitch = false; + } + } else { + isSwitch = false; + } + } + return !isSwitch; + } + @Override protected void finalProcess(List list, int level, FinalProcessLocalData localData, String path) throws InterruptedException { 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 9943be833..a4235491b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -20,7 +20,9 @@ import com.jpexs.decompiler.flash.BaseLocalData; import com.jpexs.decompiler.flash.FinalProcessLocalData; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.model.FunctionActionItem; +import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction; +import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.model.AndItem; @@ -1309,6 +1311,10 @@ public class Graph { clearLoops(loops); } + protected boolean canBeBreakCandidate(GraphPart part) { + return true; + } + private void getLoops(BaseLocalData localData, GraphPart part, List loops, List stopPart, boolean first, int level, List visited) throws InterruptedException { if (part == null) { @@ -1339,7 +1345,7 @@ public class Graph { } } - if (lastP1 != null) { + if (lastP1 != null && canBeBreakCandidate(part)) { if (lastP1.breakCandidates.contains(part)) { lastP1.breakCandidates.add(part); lastP1.breakCandidatesLevels.add(level); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java index eef22e528..c795f2895 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java @@ -1991,4 +1991,31 @@ public class ActionScript2Test extends ActionScript2TestBase { + "var v1 = {};\r\n" ); } + + @Test + public void frame72_forInSwitchTest() { + compareSrc(72, "function f()\r\n" + + "{\r\n" + + "var _loc3_ = {};\r\n" + + "var _loc2_ = {};\r\n" + + "for(var _loc4_ in _loc3_)\r\n" + + "{\r\n" + + "var _loc1_ = _loc2_[_loc4_];\r\n" + + "switch(_loc1_)\r\n" + + "{\r\n" + + "case \"A\":\r\n" + + "case \"B\":\r\n" + + "case \"C\":\r\n" + + "trace(\"Ret 5\");\r\n" + + "return 5;\r\n" + + "default:\r\n" + + "continue;\r\n" + + "}\r\n" + + "}\r\n" + + "trace(\"Final\");\r\n" + + "return 10;\r\n" + + "}\r\n" + + "trace(\"forInSwitchTest\");\r\n" + ); + } } diff --git a/libsrc/ffdec_lib/testdata/as2/as2.fla b/libsrc/ffdec_lib/testdata/as2/as2.fla index f65866a74..4e3137e88 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2.fla and b/libsrc/ffdec_lib/testdata/as2/as2.fla differ diff --git a/libsrc/ffdec_lib/testdata/as2/as2.swf b/libsrc/ffdec_lib/testdata/as2/as2.swf index 9a417d836..5d076ded8 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2.swf and b/libsrc/ffdec_lib/testdata/as2/as2.swf differ