From 9d421bb23ab5747665e943655ad8dc8eee6247a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20Pet=C5=99=C3=ADk?= Date: Thu, 5 Sep 2024 09:53:42 +0200 Subject: [PATCH] Fixed: #2301 AS3 direct editing - instance variables assignments producing additional static assignments --- CHANGELOG.md | 5 ++++- .../avm2/parser/script/AVM2SourceGenerator.java | 15 ++++----------- .../abc/avm2/parser/script/ConstAVM2Item.java | 6 ++++++ .../abc/avm2/parser/script/SlotAVM2Item.java | 9 +++++++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a1ee73ddb..a965de89b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Fixed - [#2293] FLA export - stackoverflow on multilevel clips extraction, clipping -- [#2294] FLA export - Nullpointer on AS3 SWFs without document class +- [#2294], [#2300] AS3 export - Nullpointer on SWFs without document class - [#2299] AS1/2 - Nullpointer on loadMovie with register as parameter +- [#2301] AS3 direct editing - instance variables assignments producing additional static assignments ## [21.0.4] - 2024-08-27 ### Fixed @@ -3534,7 +3535,9 @@ Major version of SWF to XML export changed to 2. [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 [#2293]: https://www.free-decompiler.com/flash/issues/2293 [#2294]: https://www.free-decompiler.com/flash/issues/2294 +[#2300]: https://www.free-decompiler.com/flash/issues/2300 [#2299]: https://www.free-decompiler.com/flash/issues/2299 +[#2301]: https://www.free-decompiler.com/flash/issues/2301 [#2266]: https://www.free-decompiler.com/flash/issues/2266 [#2275]: https://www.free-decompiler.com/flash/issues/2275 [#2276]: https://www.free-decompiler.com/flash/issues/2276 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 7267357f6f..c8e6486b18 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 @@ -808,7 +808,7 @@ override protected function get skinParts() : Object //List cinitcode = new ArrayList<>(); List initcode = new ArrayList<>(); - /*for (GraphTargetItem ti : commands) { + for (GraphTargetItem ti : commands) { if ((ti instanceof SlotAVM2Item) || (ti instanceof ConstAVM2Item)) { GraphTargetItem val = null; boolean isStatic = false; @@ -831,12 +831,13 @@ override protected function get skinParts() : Object continue; } } - if (isStatic && val != null) { + /*if (isStatic && val != null) { cinitcode.add(ins(AVM2Instructions.FindProperty, traitName(ns, tname))); localData.isStatic = true; cinitcode.addAll(toInsList(val.toSource(localData, this))); cinitcode.add(ins(isConst ? AVM2Instructions.InitProperty : AVM2Instructions.SetProperty, traitName(ns, tname))); } + */ if (!isStatic && val != null) { //do not init basic values, that can be stored in trait if (!(val instanceof IntegerValueAVM2Item) && !(val instanceof StringAVM2Item) && !(val instanceof BooleanAVM2Item) && !(val instanceof NullAVM2Item) && !(val instanceof UndefinedAVM2Item)) { @@ -846,16 +847,8 @@ override protected function get skinParts() : Object initcode.add(ins(isConst ? AVM2Instructions.InitProperty : AVM2Instructions.SetProperty, traitName(ns, tname))); } } - } else if (ti instanceof MethodAVM2Item) { - //ignore - } else { - localData.isStatic = true; - List srcs = ti.toSourceIgnoreReturnValue(localData, this); - for (GraphSourceItem src : srcs) { - cinitcode.add((AVM2Instruction)src); - } } - }*/ + } MethodBody initBody = null; if (!isInterface) { initBody = abcIndex.getSelectedAbc().findBody(init); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java index 4a2dcc1c9a..d82d01eb8c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java @@ -128,11 +128,17 @@ public boolean hasReturnValue() { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + + if (localData.isStatic != isStatic) { + return new ArrayList<>(); + } + AVM2SourceGenerator agen = (AVM2SourceGenerator) generator; int ns = agen.genNs(localData.importedClasses, pkg.name, pkg, localData.openedNamespaces, localData, line); if (type.toString().equals("Namespace")) { return new ArrayList<>(); } + List ret = new ArrayList<>(); if (value != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java index 2d568dc1af..d440dd25d8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java @@ -120,9 +120,14 @@ public boolean hasReturnValue() { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + + if (localData.isStatic != isStatic) { + return new ArrayList<>(); + } + AVM2SourceGenerator agen = (AVM2SourceGenerator) generator; - int ns = agen.genNs(localData.importedClasses, pkg.name, pkg, localData.openedNamespaces, localData, line); - + int ns = agen.genNs(localData.importedClasses, pkg.name, pkg, localData.openedNamespaces, localData, line); + List ret = new ArrayList<>(); if (value != null) { ret.add(ins(AVM2Instructions.FindProperty, agen.traitName(ns, var)));