diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b2944e1d..6a163e107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ All notable changes to this project will be documented in this file. - [#1277] AS1/2 Propagate break/continue to avoid loop/switch labels - [#2483] Editing shape gradient records - RGB vs RGBA - [#2486] AS Loop in loop producing gotos in some cases +- [#2486] AS1/2 Switch after function, problem with labels ### Changed - Icon of "Deobfuscation options" menu from pile of pills to medkit 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 4ae3046c5..df0f41119 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 @@ -72,6 +72,7 @@ import com.jpexs.decompiler.graph.model.BreakItem; import com.jpexs.decompiler.graph.model.CommentItem; import com.jpexs.decompiler.graph.model.GotoItem; import com.jpexs.decompiler.graph.model.IfItem; +import com.jpexs.decompiler.graph.model.LabelItem; import com.jpexs.decompiler.graph.model.PopItem; import com.jpexs.decompiler.graph.model.PushItem; import com.jpexs.decompiler.graph.model.ScriptEndItem; @@ -181,6 +182,7 @@ public class ActionGraph extends Graph { for (long size : cnt.getContainerSizes()) { if (size == 0) { outs.add(new ActionList(((ActionGraphSource) code).getCharset())); + startIps.add(0); continue; } int startIp = Action.adr2ip(alist, endAddr); @@ -1012,6 +1014,19 @@ public class ActionGraph extends Graph { } return spd; } + + private GraphTargetItem getFirstListItem(List list) { + int i = 0; + while(i < list.size()) { + GraphTargetItem item = list.get(i); + if (item instanceof LabelItem) { + i++; + continue; + } + return item; + } + return null; + } /** * Checks second pass switches. @@ -1057,9 +1072,9 @@ public class ActionGraph extends Graph { IfItem ii2 = ii; IfItem lastOkayIi = ii; while (true) { - if ((isNeq && (!ii2.onTrue.isEmpty() && (ii2.onTrue.get(0) instanceof IfItem))) - || (!isNeq && (!ii2.onFalse.isEmpty() && (ii2.onFalse.get(0) instanceof IfItem)))) { - ii2 = (IfItem) (isNeq ? ii2.onTrue.get(0) : ii2.onFalse.get(0)); + if ((isNeq && (getFirstListItem(ii2.onTrue) instanceof IfItem)) + || (!isNeq && (getFirstListItem(ii2.onFalse) instanceof IfItem))) { + ii2 = (IfItem) (isNeq ? getFirstListItem(ii2.onTrue) : getFirstListItem(ii2.onFalse)); if ((ii2.expression instanceof StrictNeqActionItem) || (ii2.expression instanceof StrictEqActionItem)) { isNeq = (ii2.expression instanceof StrictNeqActionItem); sneq = ((BinaryOpItem) ii2.expression); 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 cedfc6a62..d56500334 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java @@ -86,6 +86,7 @@ public class ActionScript2Test extends ActionScript2TestBase { return null; } + //--FRAMES-START-- @Test public void frame23_Test() { compareSrc(23, "stop();\r\n" @@ -2542,4 +2543,24 @@ public class ActionScript2Test extends ActionScript2TestBase { + "trace(\"end\");\r\n" ); } + + @Test + public void frame94_functionSwitchTest() { + compareSrc(94, "function reset()\r\n" + + "{\r\n" + + "}\r\n" + + "trace(\"functionSwitchTest\");\r\n" + + "stop();\r\n" + + "switch(test)\r\n" + + "{\r\n" + + "case 1:\r\n" + + "trace(\"A\");\r\n" + + "break;\r\n" + + "case 2:\r\n" + + "case 3:\r\n" + + "trace(\"B\");\r\n" + + "}\r\n" + ); + } + //--FRAMES-END-- } diff --git a/libsrc/ffdec_lib/testdata/as2/as2.swf b/libsrc/ffdec_lib/testdata/as2/as2.swf index be0659fac..06dca9a55 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2.swf and b/libsrc/ffdec_lib/testdata/as2/as2.swf differ diff --git a/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml b/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml index a90c8b892..69dabfab7 100644 --- a/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml +++ b/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml @@ -31,7 +31,7 @@ - + @@ -379,7 +379,7 @@ - + @@ -587,7 +587,7 @@ - + @@ -761,9 +761,9 @@ +!3159 7239[3270 7033 3327 6947!3327 6947[3353 6908 3412 6794!3412 6794[3470 6682 3500 6639!3500 6639[3602 6491 3649 6692!3649 6692|3713 6670!3713 6670[3760 6655 3782 6655!3782 6655[3942 6655 3985 6781!3985 6781[4007 6844 3996 6914!3996 + 6914[3996 6948 3999 6995!3999 6995[4000 7031 3993 7054!3993 7054[3976 7106 3860 7224!3860 7224[3847 7237 3741 7292!3741 7292[3638 7346 3616 7372!3616 7372[3594 7396 3511 7442!3511 7442[3435 7483 3427 7483!3427 7483[3409 7483 3407 7468 +!3407 7468[3405 7453 3386 7453!3386 7453[3361 7468 3330 7483!3330 7483[3270 7512 3235 7512!3235 7512[3220 7512 3156 7501!3156 7501[3091 7490 3054 7490!3054 7490[3050 7494 3050 7457!3050 7457[3050 7441 3159 7239"/> + @@ -3452,6 +3452,26 @@ trace("end");]]> + + + + + + @@ -3459,6 +3479,9 @@ trace("end");]]> + + + @@ -3476,8 +3499,5 @@ trace("end");]]> - - - \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml b/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml index 136a13f94..fc9515dac 100644 --- a/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml +++ b/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml @@ -5,8 +5,8 @@ xmlns:xmp="http://ns.adobe.com/xap/1.0/"> Adobe Flash CS4 Professional 2010-08-03T10:48:58+02:00 - 2025-07-12T09:55:06-07:00 - 2025-07-12T09:55:06-07:00 + 2025-07-13T10:54:33-07:00 + 2025-07-13T10:54:33-07:00 @@ -22,7 +22,7 @@ xmp.did:8DD71700DC9EDF1194ADAC9B23608190 xmp.did:F0EB4FF7CAC3ED11AC9DC078F41E1AA7 - xmp.iid:4A7A9C9D365FF011AB05F1E1201C406F + xmp.iid:587E6B88F65FF0119C96D9FB8C6458ED xmp.did:8DD71700DC9EDF1194ADAC9B23608190 @@ -488,6 +488,12 @@ 2010-08-03T10:48:58+02:00 Adobe Flash Professional CS6 - build 481 + + created + xmp.iid:587E6B88F65FF0119C96D9FB8C6458ED + 2010-08-03T10:48:58+02:00 + Adobe Flash Professional CS6 - build 481 + diff --git a/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache b/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache index dfdfc96c3..339afd1f2 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache and b/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache differ