diff --git a/CHANGELOG.md b/CHANGELOG.md index aad64b9c7..88f68d852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file. - AS3 getslot/setslot in certain situations - #1185 AS3 Incorrect imports in obfuscated files - #1186 Missing import when item is fully qualified -- #1188 AS3 Static initializer - init slot only when not referencing other property +- #1188 AS3 reorder traits if one slot/const references another ## [13.0.1] - 2021-02-09 ### Fixed diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 48262c378..8465055be 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1958,7 +1958,7 @@ public class AVM2Code implements Cloneable { TraitSlotConst tsc = (TraitSlotConst) t; if (value != null && !convertData.assignedValues.containsKey(tsc)) { - if (ti instanceof SetPropertyAVM2Item) { //only for slots + /*if (ti instanceof SetPropertyAVM2Item) { //only for slots Set subItems = value.getAllSubItemsRecursively(); subItems.add(value); List laterMultinames = new ArrayList<>(); @@ -1989,7 +1989,7 @@ public class AVM2Code implements Cloneable { continue loopi; } } - } + }*/ if (value instanceof NewFunctionAVM2Item) { NewFunctionAVM2Item f = (NewFunctionAVM2Item) value; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ConvertData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ConvertData.java index 8db048661..043fbfc82 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ConvertData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ConvertData.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.types; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 341bc2f56..bf362eef6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -105,7 +105,7 @@ public final class MethodBody implements Cloneable { * DependencyParser uses this */ @Internal - private MethodBody lastConvertedBody = null; + private transient MethodBody lastConvertedBody = null; public MethodBody() { this.traits = new Traits(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index 41d43af6e..f8a044ae8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java @@ -17,7 +17,11 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.types.ConvertData; +import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.script.Dependency; @@ -25,9 +29,13 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.helpers.NulWriter; import com.jpexs.decompiler.flash.search.MethodId; import com.jpexs.decompiler.graph.DottedChain; +import com.jpexs.decompiler.graph.GraphTargetItem; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -153,8 +161,51 @@ public class Traits implements Cloneable, Serializable { } public GraphTextWriter toString(Class[] traitTypes, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, boolean makePackages, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { - for (int t = 0; t < traits.size(); t++) { - Trait trait = traits.get(t); + + List ordered = new ArrayList<>(traits); + loopi: + for (int i = 0; i < ordered.size(); i++) { + for (int j = i + 1; j < ordered.size(); j++) { + if (i == j) { + continue; + } + Trait o1 = ordered.get(i); + Trait o2 = ordered.get(j); + Multiname m2 = abc.constants.getMultiname(o2.name_index); + if (!convertData.assignedValues.containsKey(o1)) { + continue; + } + GraphTargetItem v1 = convertData.assignedValues.get(o1).value; + + + Set subitems1 = v1.getAllSubItemsRecursively(); + subitems1.add(v1); + for (GraphTargetItem si : subitems1) { + if (si instanceof GetPropertyAVM2Item) { + GetPropertyAVM2Item getProp = (GetPropertyAVM2Item) si; + Multiname sm1 = abc.constants.getMultiname(((FullMultinameAVM2Item) getProp.propertyName).multinameIndex); + if (sm1.equals(m2)) { + ordered.add(j + 1, o1); + ordered.remove(i); + i--; + continue loopi; + } + } + if (si instanceof GetLexAVM2Item) { + GetLexAVM2Item lex = (GetLexAVM2Item) si; + if (lex.propertyName.equals(m2)) { + ordered.add(j + 1, o1); + ordered.remove(i); + i--; + continue loopi; + } + } + } + } + } + + for (Trait trait : ordered) { + int t = traits.indexOf(trait); if (traitTypes != null) { boolean found = false; for (Class c : traitTypes) { diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java index 62af11b8d..6b518a7c9 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java @@ -338,13 +338,10 @@ public class ActionScript3ClassTest extends ActionScript3DecompileTestBase { + " {\n" + " public static var s_alpha:RegExp = /[a-z]+/;\n" + " \n" - + " public static var s_regs:Array;\n" - + " \n" + " public static var s_numbers:RegExp = /[0-9]+/;\n" + " \n" - + " {\n" - + " s_regs = [s_alpha,s_numbers];\n" - + " }\n" + + " public static var s_regs:Array = [s_alpha,s_numbers];\n" + + " \n" + " \n" + " public var i_email:RegExp;\n" + " \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 be151e140..cdba4fec5 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 1e190bdbf..35e348d35 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 709bc9b8c..a31beb195 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as @@ -105,7 +105,6 @@ package public function Main() { - new TestInitializer(); if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); }