From 165b0f9db55353c16c79735c320bb1202a5df964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Tue, 30 Sep 2025 19:36:45 +0200 Subject: [PATCH] Fixed: #2536 AS3 switches detection incorrectly replaces basic ifs with strict equals Fixed: #2536 AS3 switches detection not handling loops --- CHANGELOG.md | 4 ++++ .../flash/abc/avm2/graph/AVM2Graph.java | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 658ba05f7..90f6fa6a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed +- [#2536] AS3 switches detection incorrectly replaces basic ifs with strict equals +- [#2536] AS3 switches detection not handling loops ## [24.1.0] - 2025-09-28 ### Added @@ -4010,6 +4013,7 @@ Major version of SWF to XML export changed to 2. [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 +[#2536]: https://www.free-decompiler.com/flash/issues/2536 [#2477]: https://www.free-decompiler.com/flash/issues/2477 [#2478]: https://www.free-decompiler.com/flash/issues/2478 [#2485]: https://www.free-decompiler.com/flash/issues/2485 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index edef899f9..b62f6efff 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -1805,8 +1805,17 @@ public class AVM2Graph extends Graph { int cnt = 1; int branchCount = 2; try { + Set ignoredParts = new LinkedHashSet<>(); + for (Loop el : loops) { + ignoredParts.add(el.loopContinue); + } while (true) { List out = new ArrayList<>(); + + if (ignoredParts.contains(part)) { + break; + } + //Special: In Flex (not air) there are these blocks sometimes: // if(false) { // §§push(5); @@ -1815,7 +1824,7 @@ public class AVM2Graph extends Graph { //AVM2DeobfuscatorPushFalseIfFalse changes it to // nop // jump - // (to first case to work) + // (to first case to work) if (part.nextParts.size() == branchCount && part.nextParts.get(branchNum).getHeight() == 2 && ((AVM2Instruction) code.get(part.nextParts.get(branchNum).start >= code.size() ? code.size() - 1 : part.nextParts.get(branchNum).start)).definition instanceof NopIns @@ -1861,6 +1870,12 @@ public class AVM2Graph extends Graph { //ignore } List caseValuesMap = caseValuesMapLeft; + + //Only handle switches with more than 2 branches + if (caseValuesMap.size() <= 2) { + stack.push(set); + return ret; + } //determine whether local register are on left or on right side of === operator // -1 = there's no register,