diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a163e107..5c518978e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ All notable changes to this project will be documented in this file. - [#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 +- [#2486] AS ifs with direct breaks (in obfuscated code) ### Changed - Icon of "Deobfuscation options" menu from pile of pills to medkit 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 a9634eb24..185ab8e94 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -549,19 +549,26 @@ public class Graph { } List loopContinues = new ArrayList<>(); + List loopBreaks = new ArrayList<>(); for (Loop l : loops) { if (l.phase == 1) { loopContinues.add(l.loopContinue); if (l.loopPreContinue != null) { loopContinues.add(l.loopPreContinue); } - } + if (l.loopBreak != null) { + loopBreaks.add(l.loopBreak); + } + } } for (GraphPart p : parts) { if (loopContinues.contains(p)) { break; } + if (loopBreaks.contains(p)) { + break; + } boolean common = true; for (GraphPart q : parts) { if (q == p) { @@ -596,6 +603,9 @@ public class Graph { if (loopContinues.contains(p)) { return null; } + if (loopBreaks.contains(p)) { + return null; + } return p; } } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3AssembledDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3AssembledDecompileTest.java index 404622e8b..47dddbd7c 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3AssembledDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3AssembledDecompileTest.java @@ -409,16 +409,18 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "case 1:\r\n" + "if(a)\r\n" + "{\r\n" - + "if(b)\r\n" + + "if(!b)\r\n" + "{\r\n" - + "trace(\"a\");\r\n" - + "addr0053:\r\n" - + "trace(\"c\");\r\n" - + "}\r\n" + "break;\r\n" + "}\r\n" + + "trace(\"a\");\r\n" + + "}\r\n" + + "else\r\n" + + "{\r\n" + "trace(\"b\");\r\n" - + "§§goto(addr0053);\r\n" + + "}\r\n" + + "trace(\"c\");\r\n" + + "break;\r\n" + "case 2:\r\n" + "trace(\"case2\");\r\n" + "}\r\n", diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java index b9bc90b3f..ae586e649 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java @@ -2322,6 +2322,37 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile false); } + @Test + public void testWhileBreak3() { + decompileMethod("classic_air", "testWhileBreak3", "var i:int = Math.floor(Math.random() * 11);\r\n" + + "while(true)\r\n" + + "{\r\n" + + "trace(\"A\");\r\n" + + "if(i < 100)\r\n" + + "{\r\n" + + "if(i < 0)\r\n" + + "{\r\n" + + "break;\r\n" + + "}\r\n" + + "if(i < 4)\r\n" + + "{\r\n" + + "break;\r\n" + + "}\r\n" + + "}\r\n" + + "else\r\n" + + "{\r\n" + + "trace(\"C\");\r\n" + + "}\r\n" + + "if(i == 4)\r\n" + + "{\r\n" + + "trace(\"D\");\r\n" + + "return i;\r\n" + + "}\r\n" + + "}\r\n" + + "return i;\r\n", + false); + } + @Test public void testWhileContinue() { decompileMethod("classic_air", "testWhileContinue", "var a:int = 5;\r\n" diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java index ab3927748..0d4557fad 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java @@ -2315,6 +2315,37 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes false); } + @Test + public void testWhileBreak3() { + decompileMethod("classic", "testWhileBreak3", "var i:int = Math.floor(Math.random() * 11);\r\n" + + "while(true)\r\n" + + "{\r\n" + + "trace(\"A\");\r\n" + + "if(i < 100)\r\n" + + "{\r\n" + + "if(i < 0)\r\n" + + "{\r\n" + + "break;\r\n" + + "}\r\n" + + "if(i < 4)\r\n" + + "{\r\n" + + "break;\r\n" + + "}\r\n" + + "}\r\n" + + "else\r\n" + + "{\r\n" + + "trace(\"C\");\r\n" + + "}\r\n" + + "if(i == 4)\r\n" + + "{\r\n" + + "trace(\"D\");\r\n" + + "return i;\r\n" + + "}\r\n" + + "}\r\n" + + "return i;\r\n", + false); + } + @Test public void testWhileContinue() { decompileMethod("classic", "testWhileContinue", "var a:* = 5;\r\n" diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf index cbf1d8cea..302a6d91c 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf index 896b2943c..53f40ff52 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as index 217bd3476..83d85a63e 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as @@ -136,6 +136,7 @@ package TestWhileAnd; TestWhileBreak; TestWhileBreak2; + TestWhileBreak3; TestWhileContinue; TestWhileDoWhile; TestWhileSwitch; diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestWhileBreak3.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestWhileBreak3.as new file mode 100644 index 000000000..01eb86381 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestWhileBreak3.as @@ -0,0 +1,29 @@ +package tests +{ + + public class TestWhileBreak3 + { + public function run():* + { + var i:int = Math.floor(Math.random() * 11); //1-14 + while (true) { + trace("A"); //15-27 + if (i < 100) { + if (i < 0) { //28-31 + break; + } + if (i < 4) { //32-35 + break; + } + } else { + trace("C"); //37-42 + } + if (i == 4) { //43-46 + trace("D"); //47-55 + return i; + } + } + return i; //58-60 + } + } +}