From 4efa3191e729d29cffc600df363e7810fb072799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 26 Sep 2024 19:22:31 +0200 Subject: [PATCH] Fixed: #2324 AS3 direct editation - nested loop continue/break (with labels) --- CHANGELOG.md | 2 ++ .../avm2/parser/script/AVM2SourceGenerator.java | 16 +++++++++++----- .../avm2/parser/script/ActionScript3Parser.java | 4 ++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd32f1250..99dc9bf79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. - [#2322] AS3 Construct property name formatting - [#2322] AS3 Assigment position when using dup - [#2323] AS3 direct editation - Number class traits are duplicated in constructor +- [#2324] AS3 direct editation - nested loop continue/break (with labels) ## [21.1.0] - 2024-09-23 ### Added @@ -3588,6 +3589,7 @@ Major version of SWF to XML export changed to 2. [#2272]: https://www.free-decompiler.com/flash/issues/2272 [#2322]: https://www.free-decompiler.com/flash/issues/2322 [#2323]: https://www.free-decompiler.com/flash/issues/2323 +[#2324]: https://www.free-decompiler.com/flash/issues/2324 [#943]: https://www.free-decompiler.com/flash/issues/943 [#1812]: https://www.free-decompiler.com/flash/issues/1812 [#2287]: https://www.free-decompiler.com/flash/issues/2287 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index eb7532fcf..feeca82da 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -397,14 +397,20 @@ public class AVM2SourceGenerator implements SourceGenerator { pos += ins.getBytesLength(); if (ins.definition instanceof JumpIns) { if (ins.definition instanceof ContinueJumpIns) { - if (continueOffset != Integer.MAX_VALUE) { - ins.operands[0] = (-pos + continueOffset); - ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump]; + ContinueJumpIns cji = (ContinueJumpIns) ins.definition; + if (cji.getLoopId() == loopId) { + if (continueOffset != Integer.MAX_VALUE) { + ins.operands[0] = (-pos + continueOffset); + ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump]; + } } } if (ins.definition instanceof BreakJumpIns) { - ins.operands[0] = (-pos + breakOffset); - ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump]; + BreakJumpIns bji = (BreakJumpIns) ins.definition; + if (bji.getLoopId() == loopId) { + ins.operands[0] = (-pos + breakOffset); + ins.definition = AVM2Code.instructionSet[AVM2Instructions.Jump]; + } } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java index b35e5e236..f067aaaad 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java @@ -1711,6 +1711,7 @@ public class ActionScript3Parser { loops.push(wloop); whileBody.add(command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables, abc)); ret = new WhileItem(null, null, wloop, whileExpr, whileBody); + loops.pop(); break; case DO: List doBody = new ArrayList<>(); @@ -1726,6 +1727,7 @@ public class ActionScript3Parser { doExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, true, abc)); expectedType(SymbolType.PARENT_CLOSE); ret = new DoWhileItem(null, null, dloop, doBody, doExpr); + loops.pop(); break; case FOR: s = lex(); @@ -1791,6 +1793,7 @@ public class ActionScript3Parser { } else { ret = new ForItem(null, null, floop, forFirstCommands, forExpr, forFinalCommands, forBody); } + loops.pop(); break; case SWITCH: Loop sloop = new Loop(-uniqId(), null, null); //negative id marks switch = no continue @@ -1833,6 +1836,7 @@ public class ActionScript3Parser { } expected(s, lexer.yyline(), SymbolType.CURLY_CLOSE); ret = new SwitchItem(null, null, sloop, switchExpr, caseExprsAll, caseCmds, valueMapping); + loops.pop(); break; case BREAK: s = lex();