diff --git a/.gitignore b/.gitignore index 64d0077d8..bedbc66cc 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.identcache *.recompiled.swf *(Selective Sync Conflict* +~ffdec*.* buildlog.*.txt run_test_*.swf Thumbs.db diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f6c64132..c12f63aba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ All notable changes to this project will be documented in this file. - [#2275] Export to FlashDevelop - framerate setting - [#2276] Protected namespaces do not use fully qualified names - Target flash player version in FlashDevelop and IDEA projects +- Script/Class initializers order of assignment + + +### Changed +- Compound script has slot/const traits inside main script initializer ## [21.0.2] - 2024-08-12 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index b79bcab0a..9da95b296 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -35,6 +35,7 @@ import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; +import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; @@ -258,7 +259,7 @@ public class ScriptPack extends AS3ClassTreeItem { int sinit_index = abc.script_info.get(scriptIndex).init_index; int sinit_bodyIndex = abc.findBodyIndex(sinit_index); - if (sinit_bodyIndex != -1) { + if (sinit_bodyIndex != -1 && (isSimple || traitIndices.isEmpty())) { //initialize all classes traits /*for (Trait t : traits) { if (t instanceof TraitClass) { @@ -306,42 +307,28 @@ public class ScriptPack extends AS3ClassTreeItem { if (!isSimple && traitIndices.isEmpty()) { for (Trait t : abc.script_info.get(scriptIndex).traits.traits) { + + if (t instanceof TraitSlotConst) { + continue; + } + String fullName = t.getName(abc).getNameWithNamespace(abc.constants, false).toPrintableString(true); writer.appendNoHilight("include \"" + fullName.replace(".", "/") + ".as\";").newLine(); } writer.newLine(); - } - - if (bodyIndex != -1 && (isSimple || traitIndices.isEmpty())) { - //Note: There must be trait/method highlight even if the initializer is empty to TraitList in GUI to work correctly - writer.startTrait(GraphTextWriter.TRAIT_SCRIPT_INITIALIZER); - writer.startMethod(script_init, null); - if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { - if (!scriptInitializerIsEmpty) { - writer.startBlock(); - List callStack = new ArrayList<>(); - callStack.add(abc.bodies.get(bodyIndex)); - abc.bodies.get(bodyIndex).toString(callStack, abcIndex, path + "/.scriptinitializer", exportMode, abc, null, writer, new ArrayList<>(), new HashSet<>()); - writer.endBlock(); - } else { - writer.append(""); - } - } - writer.endMethod(); - writer.endTrait(); - if (!scriptInitializerIsEmpty) { - writer.newLine(); - first = false; - } - } - + } + for (int t : traitIndices) { + + Trait trait = traits.get(t); + + if ((trait instanceof TraitSlotConst) && convertData.assignedValues.containsKey((TraitSlotConst) trait)) { + continue; + } + if (!first) { writer.newLine(); } - - Trait trait = traits.get(t); - //if (!(trait instanceof TraitClass)) { writer.startTrait(t); //} @@ -357,6 +344,29 @@ public class ScriptPack extends AS3ClassTreeItem { } first = false; } + + if (bodyIndex != -1 && (isSimple || traitIndices.isEmpty())) { + //Note: There must be trait/method highlight even if the initializer is empty to TraitList in GUI to work correctly + writer.startTrait(GraphTextWriter.TRAIT_SCRIPT_INITIALIZER); + writer.startMethod(script_init, null); + if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { + if (!scriptInitializerIsEmpty) { + //writer.startBlock(); + List callStack = new ArrayList<>(); + callStack.add(abc.bodies.get(bodyIndex)); + abc.bodies.get(bodyIndex).toString(callStack, abcIndex, path + "/.scriptinitializer", exportMode, abc, null, writer, new ArrayList<>(), new HashSet<>()); + //writer.endBlock(); + } else { + writer.append(""); + } + } + writer.endMethod(); + writer.endTrait(); + if (!scriptInitializerIsEmpty) { + writer.newLine(); + first = false; + } + } } /** 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 36c07e1d9..ccde64c87 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 @@ -261,12 +261,15 @@ import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NewFunctionAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.PackageAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.ReturnValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ReturnVoidAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetSlotAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetTypeAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.StoreNewActivationAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.TraitSlotConstAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.UndefinedAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ForEachInAVM2Item; @@ -278,6 +281,7 @@ import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.abc.types.Multiname; +import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; @@ -296,6 +300,7 @@ import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.decompiler.graph.GraphPart; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.ScopeStack; import com.jpexs.decompiler.graph.SecondPassException; import com.jpexs.decompiler.graph.SimpleValue; @@ -312,8 +317,10 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -1905,6 +1912,34 @@ public class AVM2Code implements Cloneable { } } } + + if (ins.definition instanceof KillIns) { + int killedReg = ins.operands[0]; + if (output.size() >= 2 && !stack.isEmpty()) { + if ((stack.peek() instanceof LocalRegAVM2Item) && (((LocalRegAVM2Item) stack.peek()).regIndex == killedReg)) { + if (output.get(output.size() - 1) instanceof SetPropertyAVM2Item) { + SetPropertyAVM2Item setProp = (SetPropertyAVM2Item) output.get(output.size() - 1); + if ((output.get(output.size() - 2) instanceof SetLocalAVM2Item) && (((SetLocalAVM2Item) output.get(output.size() - 2)).regIndex == killedReg)) { + SetLocalAVM2Item setLoc = (SetLocalAVM2Item) output.get(output.size() - 2); + AVM2Instruction insAfter = ip + 1 < code.size() ? code.get(ip + 1) : null; + if (insAfter != null && (insAfter.definition instanceof PopIns)) { + if (setProp.value instanceof LocalRegAVM2Item) { + LocalRegAVM2Item locReg = (LocalRegAVM2Item) setProp.value; + if (locReg.regIndex == killedReg) { + setProp.value = setLoc.value; + output.remove(output.size() - 2); + stack.pop(); + ip += 2; + continue; + } + } + + } + } + } + } + } + } /* if (ins.definition instanceof DupIns) { int nextPos; @@ -2480,6 +2515,10 @@ public class AVM2Code implements Cloneable { } }*/ } + + private static interface BlockVisitor { + public void visitBlock(List items); + } /** * Converts code to source - list of GraphTargetItems. @@ -2541,10 +2580,10 @@ public class AVM2Code implements Cloneable { NewFunctionAVM2Item f = (NewFunctionAVM2Item) value; f.functionName = tsc.getName(abc).getName(abc.constants, fullyQualifiedNames, true, true); } - AssignedValue av = new AssignedValue(value, initializerType, methodIndex); + AssignedValue av = new AssignedValue(ti, value, initializerType, methodIndex); convertData.assignedValues.put(tsc, av); - list.remove(i); - i--; + //list.remove(i); + //i--; continue loopi; } } @@ -2609,10 +2648,10 @@ public class AVM2Code implements Cloneable { NewFunctionAVM2Item f = (NewFunctionAVM2Item) value; f.functionName = tsc.getName(abc).getName(abc.constants, fullyQualifiedNames, true, true); } - AssignedValue av = new AssignedValue(value, initializerType, methodIndex); + AssignedValue av = new AssignedValue(ti, value, initializerType, methodIndex); convertData.assignedValues.put(tsc, av); - list.remove(i); - i--; + //list.remove(i); + //i--; continue loopi; } } @@ -2626,7 +2665,153 @@ public class AVM2Code implements Cloneable { } } } + + + int lastPos = list.size() - 1; + if (lastPos < 0) { + lastPos = 0; + } + if ((list.size() > lastPos) && (list.get(lastPos) instanceof ScriptEndItem)) { + lastPos--; + } + if (lastPos < 0) { + lastPos = 0; + } + if ((list.size() > lastPos) && (list.get(lastPos) instanceof ReturnVoidAVM2Item)) { + list.remove(lastPos); + } + if (initializerType == GraphTextWriter.TRAIT_SCRIPT_INITIALIZER) { + if ((list.size() > lastPos) && (list.get(lastPos) instanceof ReturnValueAVM2Item)) { + ReturnValueAVM2Item rv = (ReturnValueAVM2Item) list.get(lastPos); + if (rv.value instanceof LocalRegAVM2Item) { + list.remove(lastPos); + } else { + list.set(lastPos, rv.value); + } + + } + } + if (initializerType == GraphTextWriter.TRAIT_CLASS_INITIALIZER || initializerType == GraphTextWriter.TRAIT_SCRIPT_INITIALIZER) { + Map commandToAssigned = new IdentityHashMap<>(); + Map commandToTrait = new IdentityHashMap<>(); + for (TraitSlotConst tsc : convertData.assignedValues.keySet()) { + AssignedValue asv = convertData.assignedValues.get(tsc); + commandToAssigned.put(asv.command, asv); + commandToTrait.put(asv.command, tsc); + } + + for (int i = 0; i < list.size(); i++) { + GraphTargetItem ti = list.get(i); + if (commandToAssigned.containsKey(ti)) { + AssignedValue asv = commandToAssigned.get(ti); + TraitSlotConst tsc = commandToTrait.get(ti); + TraitSlotConstAVM2Item item = new TraitSlotConstAVM2Item( + ti.getSrc(), + ti.getLineStartItem(), + tsc, + asv.value, + isStatic, + scriptIndex, + classIndex, + initializerType, + methodIndex, + initTraits.traits.indexOf(tsc) + ); + list.set(i, item); + } + } + + if (initializerType == GraphTextWriter.TRAIT_SCRIPT_INITIALIZER) { + + //Eliminate all setlocals, can sometimes happen + BlockVisitor bv = new BlockVisitor() { + @Override + public void visitBlock(List items) { + + for (int i = 0; i < items.size(); i++) { + GraphTargetItem item = items.get(i); + if (item instanceof SetLocalAVM2Item) { + items.set(i, item.value); + } + + if (item instanceof Block) { + Block b = (Block) item; + for (List list : b.getSubs()) { + visitBlock(list); + } + } + } + } + }; + bv.visitBlock(list); + + PackageAVM2Item currentPkg = null; + for (int i = 0; i < list.size(); i++) { + GraphTargetItem ti = list.get(i); + if (ti instanceof TraitSlotConstAVM2Item) { + TraitSlotConstAVM2Item tsci = (TraitSlotConstAVM2Item) ti; + Namespace ns = tsci.getTrait().getName(abc).getNamespace(abc.constants); + if (ns.kind == Namespace.KIND_PACKAGE || ns.kind == Namespace.KIND_PACKAGE_INTERNAL) { + String newPkgName = ns.getName(abc.constants).toRawString(); + if (currentPkg == null) { + currentPkg = new PackageAVM2Item(new ArrayList<>(), newPkgName); + currentPkg.addItem(tsci); + list.set(i, currentPkg); + } else if (currentPkg.getPackageName().equals(newPkgName)){ + currentPkg.addItem(tsci); + list.remove(i); + i--; + } else { + currentPkg = new PackageAVM2Item(new ArrayList<>(), newPkgName); + currentPkg.addItem(tsci); + list.set(i, currentPkg); + } + } + } else if (currentPkg != null) { + final String currentPkgName = currentPkg.getPackageName(); + Reference insidePackage = new Reference<>(true); + + //Check whether the command references internal traits of other package + ti.visitRecursively(new AbstractGraphTargetVisitor() { + @Override + public void visit(GraphTargetItem item) { + if (item instanceof GetSlotAVM2Item) { + GetSlotAVM2Item gs = (GetSlotAVM2Item) item; + if ((gs.slotObject instanceof GlobalAVM2Item) && (initializerType == GraphTextWriter.TRAIT_SCRIPT_INITIALIZER)) { + for (Trait t : initTraits.traits) { + if (t instanceof TraitSlotConst) { + TraitSlotConst tsc = (TraitSlotConst) t; + if (tsc.slot_id == gs.slotIndex) { + int nsKind = tsc.getName(abc).getNamespace(abc.constants).kind; + if ( + ( + nsKind == Namespace.KIND_PACKAGE_INTERNAL + && !currentPkgName.equals(tsc.getName(abc).getNamespace(abc.constants).getRawName(abc.constants)) + ) + || (nsKind == Namespace.KIND_PRIVATE) + ) { + insidePackage.setVal(false); + } + } + } + } + } + } + } + }); + + if (insidePackage.getVal()) { + currentPkg.addItem(ti); + list.remove(i); + i--; + } else { + currentPkg = null; + } + } + } + } + List newList = new ArrayList<>(); for (GraphTargetItem ti : list) { if (!(ti instanceof ReturnVoidAVM2Item)) { @@ -2678,21 +2863,7 @@ public class AVM2Code implements Cloneable { for (int ir = 0; ir < r; ir++) { paramNamesList.add(AVM2Item.localRegName(localRegNames, ir)); } - injectDeclarations(0, paramNamesList, list, 1, d, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), abc, body); - - int lastPos = list.size() - 1; - if (lastPos < 0) { - lastPos = 0; - } - if ((list.size() > lastPos) && (list.get(lastPos) instanceof ScriptEndItem)) { - lastPos--; - } - if (lastPos < 0) { - lastPos = 0; - } - if ((list.size() > lastPos) && (list.get(lastPos) instanceof ReturnVoidAVM2Item)) { - list.remove(lastPos); - } + injectDeclarations(0, paramNamesList, list, 1, d, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), abc, body); return list; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java index 0e9886404..b6ed09353 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.decompiler.graph.model.LocalData; @@ -83,7 +84,7 @@ public class CodeStats { if (stats.stackpos > ms) { ms = stats.stackpos; } - writer.appendNoHilight(i + ":" + stats.stackpos + (deltastack >= 0 ? "+" + deltastack : deltastack) + "," + stats.scopepos + " " + stats.ins.toString(writer, LocalData.create(new ArrayList<>(), null, abc, null, fullyQualifiedNames, new HashSet<>()))).newLine(); + writer.appendNoHilight(i + ":" + stats.stackpos + (deltastack >= 0 ? "+" + deltastack : deltastack) + "," + stats.scopepos + " " + stats.ins.toString(writer, LocalData.create(new ArrayList<>(), null, abc, null, fullyQualifiedNames, new HashSet<>(), ScriptExportMode.AS))).newLine(); i++; } return writer; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java index c8d28dfe1..0dd2d897e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.model.UnparsedAVM2Item; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; @@ -48,7 +49,7 @@ public class NewClassIns extends InstructionDefinition { public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List output, String path) throws InterruptedException { int clsIndex = ins.operands[0]; HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false); - stack.pop().toString(writer, LocalData.create(localData.callStack /*??*/, localData.abcIndex, localData.abc, localData.localRegNames, localData.fullyQualifiedNames, new HashSet<>())); + stack.pop().toString(writer, LocalData.create(localData.callStack /*??*/, localData.abcIndex, localData.abc, localData.localRegNames, localData.fullyQualifiedNames, new HashSet<>(), ScriptExportMode.AS)); writer.finishHilights(); String baseType = writer.toString(); ABC abc = localData.abc; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java index fc4f65a96..a291dd300 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.types.Namespace; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.decompiler.graph.GraphSourceItem; @@ -150,13 +151,13 @@ public class FullMultinameAVM2Item extends AVM2Item { public boolean isTopLevel(String tname, ABC abc, HashMap localRegNames, List fullyQualifiedNames, Set seenMethods) throws InterruptedException { String cname; if (name != null) { - cname = name.toString(LocalData.create(new ArrayList<>(), null, abc, localRegNames, fullyQualifiedNames, seenMethods)); + cname = name.toString(LocalData.create(new ArrayList<>(), null, abc, localRegNames, fullyQualifiedNames, seenMethods, ScriptExportMode.AS)); } else { cname = (abc.constants.getMultiname(multinameIndex).getName(abc.constants, fullyQualifiedNames, true, true)); } String cns = ""; if (namespace != null) { - cns = namespace.toString(LocalData.create(new ArrayList<>(), null, abc, localRegNames, fullyQualifiedNames, seenMethods)); + cns = namespace.toString(LocalData.create(new ArrayList<>(), null, abc, localRegNames, fullyQualifiedNames, seenMethods, ScriptExportMode.AS)); } else { Namespace ns = abc.constants.getMultiname(multinameIndex).getNamespace(abc.constants); if ((ns != null) && (ns.name_index != 0)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/PackageAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/PackageAVM2Item.java new file mode 100644 index 000000000..4762c9d69 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/PackageAVM2Item.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2010-2024 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.abc.avm2.model; + +import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.DottedChain; +import com.jpexs.decompiler.graph.Graph; +import com.jpexs.decompiler.graph.GraphSourceItem; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; +import com.jpexs.decompiler.graph.model.LocalData; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class PackageAVM2Item extends AVM2Item { + + private final List items; + private final String packageName; + + public PackageAVM2Item(List items, String packageName) { + super(null, null, PRECEDENCE_PRIMARY); + this.items = items; + this.packageName = packageName; + } + + public String getPackageName() { + return packageName; + } + + public void addItem(GraphTargetItem item) { + items.add(item); + } + + @Override + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.appendNoHilight("package"); + if (!packageName.isEmpty()) { + writer.appendNoHilight(" " + DottedChain.parseWithSuffix(packageName).toPrintableString(true)); + } + writer.startBlock(); + Graph.graphToString(items, writer, localData); + writer.endBlock(); + writer.newLine(); + return writer; + } + + @Override + public boolean hasReturnValue() { + return false; + } + + @Override + public GraphTargetItem returnType() { + return null; + } + + @Override + public boolean needsSemicolon() { + return false; + } + + @Override + public void visit(GraphTargetVisitorInterface visitor) { + visitor.visitAll(items); + } + + @Override + public void visitNoBlock(GraphTargetVisitorInterface visitor) { + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/TraitSlotConstAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/TraitSlotConstAVM2Item.java new file mode 100644 index 000000000..502c5f581 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/TraitSlotConstAVM2Item.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2010-2024 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.abc.avm2.model; + +import com.jpexs.decompiler.flash.abc.types.AssignedValue; +import com.jpexs.decompiler.flash.abc.types.ConvertData; +import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; +import com.jpexs.decompiler.flash.abc.types.traits.TraitType; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.GraphSourceItem; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.model.LocalData; + +/** + * + * @author JPEXS + */ +public class TraitSlotConstAVM2Item extends AVM2Item { + + private final TraitSlotConst trait; + private final GraphTargetItem assignedValue; + private final boolean isStatic; + private final int scriptIndex; + private final int classIndex; + private final int initializer; + private final int methodIndex; + private final int traitIndex; + + + /** + * + * @param instruction + * @param lineStartIns + * @param trait + * @param isStatic + * @param assignedValue + * @param classIndex + * @param scriptIndex + * @param initializer + * @param methodIndex + * @param traitIndex + */ + public TraitSlotConstAVM2Item( + GraphSourceItem instruction, + GraphSourceItem lineStartIns, + TraitSlotConst trait, + GraphTargetItem assignedValue, + boolean isStatic, + int scriptIndex, + int classIndex, + int initializer, + int methodIndex, + int traitIndex + ) { + super(instruction, lineStartIns, PRECEDENCE_PRIMARY); + this.trait = trait; + this.assignedValue = assignedValue; + this.isStatic = isStatic; + this.scriptIndex = scriptIndex; + this.classIndex = classIndex; + this.initializer = initializer; + this.methodIndex = methodIndex; + this.traitIndex = traitIndex; + } + + @Override + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + + writer.endMethod(); + writer.endTrait(); + + int h = traitIndex; + if (initializer != GraphTextWriter.TRAIT_SCRIPT_INITIALIZER) { + h = localData.abc.getGlobalTraitId(TraitType.METHOD , isStatic, classIndex, traitIndex); + } + writer.startTrait(h); + ConvertData cd = new ConvertData(); + cd.assignedValues.put(trait, new AssignedValue(null, assignedValue, initializer, methodIndex)); + boolean insideInterface = classIndex > -1 ? localData.abc.instance_info.get(classIndex).isInterface() : false; + trait.toString( + localData.abcIndex, + + null, + cd, + "trait " + trait.getName(localData.abc), + localData.abc, + isStatic, + localData.exportMode, + scriptIndex, + classIndex, + writer, + localData.fullyQualifiedNames, + false, + insideInterface + ); + writer.endTrait(); + + writer.startTrait(initializer); + writer.startMethod(methodIndex, null); + return writer; + } + + @Override + public boolean hasReturnValue() { + return false; + } + + @Override + public GraphTargetItem returnType() { + return null; + } + + @Override + public boolean needsSemicolon() { + return false; + } + + @Override + public boolean hasSingleNewLineAround() { + return true; + } + + @Override + public boolean handlesNewLine() { + return true; + } + + public TraitSlotConst getTrait() { + return trait; + } +} 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 6661ef11a..bd66acd51 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 @@ -620,12 +620,25 @@ public class AVM2SourceGenerator implements SourceGenerator { * @param iinit Instance initializer * @param iinitVariables Instance initializer variables * @param iinitNeedsActivation Instance initializer needs activation - * @param traitItems Trait items + * @param commands Trait items * @param class_index Class index * @throws AVM2ParseException On parse error * @throws CompilationException On compilation error */ - public void generateClass(List importedClasses, List cinitVariables, boolean cinitNeedsActivation, List cinit, List openedNamespaces, int namespace, int initScope, DottedChain pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String baseClassName, String superName, GraphTargetItem extendsVal, List implementsStr, GraphTargetItem iinit, List iinitVariables, boolean iinitNeedsActivation, List traitItems, Reference class_index) throws AVM2ParseException, CompilationException { + public void generateClass(List importedClasses, List cinitVariables, boolean cinitNeedsActivation, List cinit, List openedNamespaces, int namespace, int initScope, DottedChain pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String baseClassName, String superName, GraphTargetItem extendsVal, List implementsStr, GraphTargetItem iinit, List iinitVariables, boolean iinitNeedsActivation, List commands, Reference class_index) throws AVM2ParseException, CompilationException { + List traitItems = new ArrayList<>(); + for (GraphTargetItem it : commands) { + if ((it instanceof SlotAVM2Item) + || (it instanceof ConstAVM2Item) + || (it instanceof ClassAVM2Item) + || (it instanceof InterfaceAVM2Item) + || (it instanceof MethodAVM2Item) + || (it instanceof GetterAVM2Item) + || (it instanceof SetterAVM2Item) + ) { + traitItems.add(it); + } + } localData.currentClassBaseName = baseClassName; localData.pkg = pkg; localData.privateNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PRIVATE, pkg.toRawString().isEmpty() ? baseClassName : pkg.toRawString() + ":" + baseClassName, 0, true); @@ -634,7 +647,8 @@ public class AVM2SourceGenerator implements SourceGenerator { extendsVal = new TypeItem(DottedChain.OBJECT); } ParsedSymbol s = null; - + + if (Configuration.handleSkinPartsAutomatically.get()) { Map skinParts = new HashMap<>(); @@ -772,9 +786,29 @@ public class AVM2SourceGenerator implements SourceGenerator { int cinit_index = method(true, str(""), false, false, false, new ArrayList<>(), pkg, cinitNeedsActivation, cinitVariables, initScope + (implementsStr.isEmpty() ? 0 : 1), false, 0, isInterface ? null : baseClassName, superName, false, localData, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), cinit, TypeItem.UNBOUNDED); MethodBody cinitBody = abcIndex.getSelectedAbc().findBody(cinit_index); - List sinitcode = new ArrayList<>(); + + for (int i = 0; i < cinitVariables.size(); i++) { + AssignableAVM2Item an = cinitVariables.get(i); + if (an instanceof UnresolvedAVM2Item) { + UnresolvedAVM2Item n = (UnresolvedAVM2Item) an; + if (n.resolved == null) { + String fullClass = localData.getFullClass(); + List callStack = new ArrayList<>(); + callStack.add(cinitBody); + GraphTargetItem res = n.resolve(localData, fullClass, new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, callStack, cinitVariables); + if (res instanceof AssignableAVM2Item) { + cinitVariables.set(i, (AssignableAVM2Item) res); + } else { + cinitVariables.remove(i); + i--; + } + } + } + } + + List cinitcode = new ArrayList<>(); List initcode = new ArrayList<>(); - for (GraphTargetItem ti : traitItems) { + for (GraphTargetItem ti : commands) { if ((ti instanceof SlotAVM2Item) || (ti instanceof ConstAVM2Item)) { GraphTargetItem val = null; boolean isStatic = false; @@ -798,10 +832,10 @@ public class AVM2SourceGenerator implements SourceGenerator { } } if (isStatic && val != null) { - sinitcode.add(ins(AVM2Instructions.FindProperty, traitName(ns, tname))); + cinitcode.add(ins(AVM2Instructions.FindProperty, traitName(ns, tname))); localData.isStatic = true; - sinitcode.addAll(toInsList(val.toSource(localData, this))); - sinitcode.add(ins(isConst ? AVM2Instructions.InitProperty : AVM2Instructions.SetProperty, traitName(ns, tname))); + 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 @@ -812,15 +846,23 @@ public class AVM2SourceGenerator implements SourceGenerator { 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); - initBody.insertAll(iinit == null ? 0 : 2, initcode); //after getlocal0,pushscope + initBody.getCode().code.addAll(iinit == null ? 0 : 2, initcode); //after getlocal0,pushscope if (cinitBody.getCode().code.get(cinitBody.getCode().code.size() - 1).definition instanceof ReturnVoidIns) { - cinitBody.insertAll(2, sinitcode); //after getlocal0,pushscope + cinitBody.getCode().code.addAll(2, cinitcode); //after getlocal0,pushscope } } cinitBody.markOffsets(); @@ -1305,7 +1347,7 @@ public class AVM2SourceGenerator implements SourceGenerator { continue; } - NameAVM2Item d = new NameAVM2Item(n.type, n.line, n.isAttribute(), n.getVariableName(), n.getNamespaceSuffix(), null /*NameAVM2Item.getDefaultValue("" + n.type)*/, true, n.openedNamespaces, abcIndex); + NameAVM2Item d = new NameAVM2Item(n.type, n.line, n.isAttribute(), n.getVariableName(), n.getNamespaceSuffix(), null /*NameAVM2Item.getDefaultValue("" + n.type)*/, true, n.openedNamespaces, abcIndex, n.isConst()); //no index if (needsActivation) { if (d.getSlotNumber() <= 0) { @@ -1367,9 +1409,9 @@ public class AVM2SourceGenerator implements SourceGenerator { mbody.traits.traits.add(tsc); } for (int i = 1; i < paramRegCount; i++) { - NameAVM2Item param = new NameAVM2Item(registerTypes.get(i), 0, false, registerNames.get(i), "", null, false, new ArrayList<>(), abcIndex); + NameAVM2Item param = new NameAVM2Item(registerTypes.get(i), 0, false, registerNames.get(i), "", null, false, new ArrayList<>(), abcIndex, false); param.setRegNumber(i); - NameAVM2Item d = new NameAVM2Item(registerTypes.get(i), 0, false, registerNames.get(i), "", param, true, new ArrayList<>(), abcIndex); + NameAVM2Item d = new NameAVM2Item(registerTypes.get(i), 0, false, registerNames.get(i), "", param, true, new ArrayList<>(), abcIndex, false); d.setSlotScope(slotScope); d.setSlotNumber(slotNames.indexOf(registerNames.get(i))); declarations.add(d); @@ -2099,6 +2141,10 @@ public class AVM2SourceGenerator implements SourceGenerator { /** * Generates script info. + * @param sinitVariables Script initializer variables + * @param sinitNeedsActivation Script initializer needs activation + * @param importedClasses Imported classes + * @param openedNamespaces Opened namespaces * @param scriptIndex Script index * @param scriptInfo Script info * @param allOpenedNamespaces All opened namespaces @@ -2108,14 +2154,27 @@ public class AVM2SourceGenerator implements SourceGenerator { * @throws AVM2ParseException On parse error * @throws CompilationException On compilation error */ - public void generateScriptInfo(int scriptIndex, ScriptInfo scriptInfo, List> allOpenedNamespaces, SourceGeneratorLocalData localData, List commands, int classPos) throws AVM2ParseException, CompilationException { + public void generateScriptInfo(List sinitVariables, boolean sinitNeedsActivation, List importedClasses, List openedNamespaces, int scriptIndex, ScriptInfo scriptInfo, List> allOpenedNamespaces, SourceGeneratorLocalData localData, List commands, int classPos) throws AVM2ParseException, CompilationException { + List traitsList = new ArrayList<>(); + for (GraphTargetItem it : commands) { + if ((it instanceof SlotAVM2Item) + || (it instanceof ConstAVM2Item) + || (it instanceof ClassAVM2Item) + || (it instanceof InterfaceAVM2Item) + || (it instanceof MethodAVM2Item) + || (it instanceof GetterAVM2Item) + || (it instanceof SetterAVM2Item) + ) { + traitsList.add(it); + } + } Reference class_index = new Reference<>(classPos); localData.currentScript = scriptInfo; localData.scriptIndex = scriptIndex; - Trait[] traitArr = generateTraitsPhase1(new ArrayList<>(), new ArrayList<>(), null, null, true, localData, commands, scriptInfo.traits, class_index, true); - generateTraitsPhase2(new ArrayList<>(), null/*FIXME*/, commands, traitArr, new ArrayList<>(), localData); + Trait[] traitArr = generateTraitsPhase1(new ArrayList<>(), new ArrayList<>(), null, null, true, localData, traitsList, scriptInfo.traits, class_index, true); + generateTraitsPhase2(new ArrayList<>(), null/*FIXME*/, traitsList, traitArr, new ArrayList<>(), localData); abcIndex.refreshSelected(); - generateTraitsPhase3(commands, traitArr, localData); + generateTraitsPhase3(traitsList, traitArr, localData); abcIndex.refreshSelected(); ABC abc = abcIndex.getSelectedAbc(); @@ -2194,9 +2253,67 @@ public class AVM2SourceGenerator implements SourceGenerator { abc.addMethodBody(mb); scriptInfo.init_index = mb.method_info; localData.pkg = DottedChain.EMPTY; - generateTraitsPhase4(new ArrayList<>(), new ArrayList<>(), 1/*??*/, false, null, null, true, localData, commands, scriptInfo.traits, traitArr, initScopes, class_index, true); + localData.registerVars.put("this", 0); + generateTraitsPhase4(new ArrayList<>(), new ArrayList<>(), 1/*??*/, false, null, null, true, localData, traitsList, scriptInfo.traits, traitArr, initScopes, class_index, true); - int maxSlotId = 0; + List sinitcode = new ArrayList<>(); + for (int i = 0; i < sinitVariables.size(); i++) { + AssignableAVM2Item an = sinitVariables.get(i); + if (an instanceof UnresolvedAVM2Item) { + UnresolvedAVM2Item n = (UnresolvedAVM2Item) an; + if (n.resolved == null) { + String fullClass = localData.getFullClass(); + List callStack = new ArrayList<>(); + callStack.add(mb); + GraphTargetItem res = n.resolve(localData, fullClass, new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, callStack, sinitVariables); + if (res instanceof AssignableAVM2Item) { + sinitVariables.set(i, (AssignableAVM2Item) res); + } else { + sinitVariables.remove(i); + i--; + } + } + } + } + for (GraphTargetItem ti : commands) { + if ((ti instanceof SlotAVM2Item) || (ti instanceof ConstAVM2Item)) { + GraphTargetItem val = null; + int ns = -1; + String tname = null; + boolean isConst = false; + NamespaceItem pkg = null; + if (ti instanceof SlotAVM2Item) { + val = ((SlotAVM2Item) ti).value; + pkg = ((SlotAVM2Item) ti).pkg; + ns = genNs(importedClasses, pkg.name, ((SlotAVM2Item) ti).pkg, openedNamespaces, localData, ((SlotAVM2Item) ti).line); + tname = ((SlotAVM2Item) ti).var; + } + if (ti instanceof ConstAVM2Item) { + val = ((ConstAVM2Item) ti).value; + pkg = ((ConstAVM2Item) ti).pkg; + ns = genNs(importedClasses, pkg.name, ((ConstAVM2Item) ti).pkg, openedNamespaces, localData, ((ConstAVM2Item) ti).line); + tname = ((ConstAVM2Item) ti).var; + isConst = true; + if (((ConstAVM2Item) ti).type.toString().equals("Namespace")) { + continue; + } + } + if (val != null) { + sinitcode.add(ins(AVM2Instructions.FindProperty, traitName(ns, tname))); + localData.isStatic = true; + sinitcode.addAll(toInsList(val.toSource(localData, this))); + sinitcode.add(ins(isConst ? AVM2Instructions.InitProperty : AVM2Instructions.SetProperty, traitName(ns, tname))); + } + } else { + List srcs = ti.toSourceIgnoreReturnValue(localData, this); + for (GraphSourceItem src : srcs) { + sinitcode.add((AVM2Instruction)src); + } + } + } + mbCode.addAll(sinitcode); + + /*int maxSlotId = 0; for (int k = 0; k < scriptInfo.traits.traits.size(); k++) { if (scriptInfo.traits.traits.get(k) instanceof TraitSlotConst) { TraitSlotConst ti = (TraitSlotConst) scriptInfo.traits.traits.get(k); @@ -2225,9 +2342,10 @@ public class AVM2SourceGenerator implements SourceGenerator { mbCode.add(ins(AVM2Instructions.InitProperty, nts.name_index)); } } - } + }*/ mbCode.add(ins(AVM2Instructions.ReturnVoid)); + mb.markOffsets(); mb.autoFillStats(abc, 1, false); } 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 4698e2aff..fcbdfa8c3 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 @@ -561,14 +561,14 @@ public class ActionScript3Parser { } List body = null; List subvariables = new ArrayList<>(); - subvariables.add(new NameAVM2Item(thisType, lexer.yyline(), false, "this", "", null, true, openedNamespaces, abcIndex)); + subvariables.add(new NameAVM2Item(thisType, lexer.yyline(), false, "this", "", null, true, openedNamespaces, abcIndex, false)); for (int i = 0; i < paramNames.size() - (hasRest ? 1 : 0); i++) { - subvariables.add(new NameAVM2Item(paramTypes.get(i), lexer.yyline(), false, paramNames.get(i), "", null, true, openedNamespaces, abcIndex)); + subvariables.add(new NameAVM2Item(paramTypes.get(i), lexer.yyline(), false, paramNames.get(i), "", null, true, openedNamespaces, abcIndex, false)); } if (hasRest) { - subvariables.add(new NameAVM2Item(TypeItem.UNBOUNDED, lexer.yyline(), false, paramNames.get(paramNames.size() - 1), "", null, true, openedNamespaces, abcIndex)); + subvariables.add(new NameAVM2Item(TypeItem.UNBOUNDED, lexer.yyline(), false, paramNames.get(paramNames.size() - 1), "", null, true, openedNamespaces, abcIndex, false)); } - subvariables.add(new NameAVM2Item(thisType, lexer.yyline(), false, "arguments", "", null, true, openedNamespaces, abcIndex)); + subvariables.add(new NameAVM2Item(thisType, lexer.yyline(), false, "arguments", "", null, true, openedNamespaces, abcIndex, false)); int parCnt = subvariables.size(); Reference needsActivation2 = new Reference<>(false); if (!isInterface && !isNative) { @@ -650,6 +650,10 @@ public class ActionScript3Parser { openedNamespaces.add(privateNs); openedNamespaces.add(protectedNs); openedNamespaces.add(staticProtectedNs); + + Stack cinitLoops = new Stack<>(); + Map cinitLoopLabels = new HashMap<>(); + HashMap cinitRegisterVars = new HashMap<>(); looptraits: while (true) { @@ -667,14 +671,14 @@ public class ActionScript3Parser { NamespaceItem namespace = null; ParsedSymbol s = lex(); //static class initializer - if (s.type == SymbolType.CURLY_OPEN) { + /*if (s.type == SymbolType.CURLY_OPEN) { cinit.addAll(commands(allOpenedNamespaces, thisType, pkg, cinitNeedsActivation, importedClasses, openedNamespaces, new Stack<>(), new HashMap<>(), new HashMap<>(), true, false, 0, cinitVariables, abc)); expectedType(SymbolType.CURLY_CLOSE); } else { lexer.pushback(s); - } + }*/ List>> metadata = parseMetadata(); - s = lex(); + //s = lex(); while (s.isType(SymbolType.NATIVE, SymbolType.STATIC, SymbolType.PUBLIC, SymbolType.PRIVATE, SymbolType.PROTECTED, SymbolType.OVERRIDE, SymbolType.FINAL, SymbolType.DYNAMIC, SymbolGroup.IDENTIFIER, SymbolType.INTERNAL, SymbolType.PREPROCESSOR)) { if (s.type == SymbolType.FINAL) { @@ -939,23 +943,77 @@ public class ActionScript3Parser { break; default: lexer.pushback(s); - break looptraits; + + GraphTargetItem cmd = command(allOpenedNamespaces, null, publicNs, cinitNeedsActivation, importedClasses, openedNamespaces, cinitLoops, cinitLoopLabels, cinitRegisterVars, true, false, 0, false, cinitVariables, abc); + if (cmd != null) { + traits.add(cmd); + } else { + break looptraits; + } } } } - private void scriptTraits(List> allOpenedNamespaces, int scriptIndex, String scriptName, List traits, Reference numberUsageRef, Reference numberRoundingRef, Reference numberPrecisionRef, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + private void scriptTraits( + List importedClasses, + List openedNamespaces, + List> allOpenedNamespaces, + int scriptIndex, + String scriptName, + List traits, + Reference numberUsageRef, + Reference numberRoundingRef, + Reference numberPrecisionRef, + ABC abc, + Reference sinitNeedsActivation, + List sinitVariables + ) throws AVM2ParseException, IOException, CompilationException, InterruptedException { - while (scriptTraitsBlock(allOpenedNamespaces, scriptIndex, scriptName, traits, numberUsageRef, numberRoundingRef, numberPrecisionRef, abc)) { + Stack sinitLoops = new Stack<>(); + Map sinitLoopLabels = new HashMap<>(); + + HashMap sinitRegisterVars = new HashMap<>(); + while (scriptTraitsBlock( + importedClasses, + openedNamespaces, + allOpenedNamespaces, + scriptIndex, + scriptName, + traits, + numberUsageRef, + numberRoundingRef, + numberPrecisionRef, + abc, + sinitNeedsActivation, + sinitLoops, + sinitLoopLabels, + sinitRegisterVars, + sinitVariables + )) { //empty } } - private boolean scriptTraitsBlock(List> allOpenedNamespaces, int scriptIndex, String scriptName, List traits, Reference numberUsageRef, Reference numberRoundingRef, Reference numberPrecisionRef, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + private boolean scriptTraitsBlock( + List importedClasses, + List openedNamespaces, + List> allOpenedNamespaces, + int scriptIndex, + String scriptName, + List traits, + Reference numberUsageRef, + Reference numberRoundingRef, + Reference numberPrecisionRef, + ABC abc, + Reference sinitNeedsActivation, + Stack sinitLoops, + Map sinitLoopLabels, + HashMap sinitRegisterVars, + List sinitVariables + ) throws AVM2ParseException, IOException, CompilationException, InterruptedException { ParsedSymbol s; boolean inPackage = false; s = lex(); - List sinitVariables = new ArrayList<>(); NamespaceItem publicNs; NamespaceItem packageInternalNs; DottedChain pkgName = DottedChain.TOPLEVEL; @@ -983,7 +1041,6 @@ public class ActionScript3Parser { } lexer.pushback(s); - List openedNamespaces = new ArrayList<>(); allOpenedNamespaces.add(openedNamespaces); NamespaceItem emptyNs = new NamespaceItem("", Namespace.KIND_PACKAGE); openedNamespaces.add(emptyNs); @@ -1000,7 +1057,7 @@ public class ActionScript3Parser { } } - List importedClasses = parseImportsUsages(openedNamespaces, numberUsageRef, numberPrecisionRef, numberRoundingRef, abc); + parseImportsUsages(importedClasses, openedNamespaces, numberUsageRef, numberPrecisionRef, numberRoundingRef, abc); boolean isEmpty = true; @@ -1206,7 +1263,13 @@ public class ActionScript3Parser { traits.add(new ConstAVM2Item(metadata, ns, null, true, nname, new TypeItem(DottedChain.NAMESPACE), new StringAVM2Item(null, null, nval), lexer.yyline(), generatedNs)); break; default: - lexer.pushback(s); + lexer.pushback(s); + parseImportsUsages(importedClasses, openedNamespaces, numberUsageRef, numberPrecisionRef, numberRoundingRef, abc); + GraphTargetItem cmd = command(allOpenedNamespaces, null, publicNs, sinitNeedsActivation, importedClasses, openedNamespaces, sinitLoops, sinitLoopLabels, sinitRegisterVars, true, false, 0, false, sinitVariables, abc); + if (cmd != null) { + traits.add(cmd); + isEmpty = false; + } break looptrait; } @@ -1532,6 +1595,8 @@ public class ActionScript3Parser { ret = (function(allOpenedNamespaces, new ArrayList<>(), pkg, false, false, needsActivation, importedClasses, thisType, openedNamespaces, s.value.toString(), false, variables, abc)); break; case VAR: + case CONST: + boolean isConst = s.type == SymbolType.CONST; s = lex(); expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); String varIdentifier = s.value.toString(); @@ -1546,10 +1611,10 @@ public class ActionScript3Parser { if (s.type == SymbolType.ASSIGN) { GraphTargetItem varval = (expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables, false, abc)); - ret = new NameAVM2Item(type, lexer.yyline(), false, varIdentifier, "", varval, true, openedNamespaces, abcIndex); + ret = new NameAVM2Item(type, lexer.yyline(), false, varIdentifier, "", varval, true, openedNamespaces, abcIndex, isConst); variables.add((NameAVM2Item) ret); } else { - ret = new NameAVM2Item(type, lexer.yyline(), false, varIdentifier, "", null, true, openedNamespaces, abcIndex); + ret = new NameAVM2Item(type, lexer.yyline(), false, varIdentifier, "", null, true, openedNamespaces, abcIndex, isConst); variables.add((NameAVM2Item) ret); lexer.pushback(s); } @@ -1817,7 +1882,7 @@ public class ActionScript3Parser { String enamestr = s.value.toString(); expectedType(SymbolType.COLON); GraphTargetItem etype = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables, abc); - NameAVM2Item e = new NameAVM2Item(etype, lexer.yyline(), false, enamestr, "", new ExceptionAVM2Item(null)/*?*/, true/*?*/, openedNamespaces, abcIndex); + NameAVM2Item e = new NameAVM2Item(etype, lexer.yyline(), false, enamestr, "", new ExceptionAVM2Item(null)/*?*/, true/*?*/, openedNamespaces, abcIndex, false); //variables.add(e); catchExceptions.add(e); e.setSlotNumber(1); @@ -2607,10 +2672,9 @@ public class ActionScript3Parser { private List constantPool; - private List parseImportsUsages(List openedNamespaces, Reference numberUsageRef, Reference numberPrecisionRef, Reference numberRoundingRef, ABC abc) throws IOException, AVM2ParseException, InterruptedException { + private void parseImportsUsages(List importedClasses, List openedNamespaces, Reference numberUsageRef, Reference numberPrecisionRef, Reference numberRoundingRef, ABC abc) throws IOException, AVM2ParseException, InterruptedException { - ParsedSymbol s; - List importedClasses = new ArrayList<>(); + ParsedSymbol s; s = lex(); while (s.isType(SymbolType.IMPORT, SymbolType.USE)) { @@ -2747,10 +2811,19 @@ public class ActionScript3Parser { s = lex(); } lexer.pushback(s); - return importedClasses; } - private List parseScript(List> allOpenedNamespaces, int scriptIndex, String fileName, Reference numberContextRef, ABC abc) throws IOException, AVM2ParseException, CompilationException, InterruptedException { + private List parseScript( + List importedClasses, + List openedNamespaces, + List> allOpenedNamespaces, + int scriptIndex, + String fileName, + Reference numberContextRef, + ABC abc, + Reference sinitNeedsActivation, + List sinitVariables + ) throws IOException, AVM2ParseException, CompilationException, InterruptedException { //int scriptPrivateNs; if (fileName.contains("/")) { @@ -2763,7 +2836,7 @@ public class ActionScript3Parser { Reference numberUsageRef = new Reference<>(NumberContext.USE_NUMBER); Reference numberRoundingRef = new Reference<>(NumberContext.ROUND_HALF_EVEN); Reference numberPrecisionRef = new Reference<>(34); - scriptTraits(allOpenedNamespaces, scriptIndex, fileName, items, numberUsageRef, numberRoundingRef, numberPrecisionRef, abc); + scriptTraits(importedClasses, openedNamespaces, allOpenedNamespaces, scriptIndex, fileName, items, numberUsageRef, numberRoundingRef, numberPrecisionRef, abc, sinitNeedsActivation, sinitVariables); NumberContext nc = new NumberContext(numberUsageRef.getVal(), numberPrecisionRef.getVal(), numberRoundingRef.getVal()); if (!nc.isDefault()) { @@ -2774,22 +2847,37 @@ public class ActionScript3Parser { /** * Converts string to script traits. + * @param importedClasses Imported classes + * @param openedNamespaces Opened namespaces * @param allOpenedNamespaces All opened namespaces * @param str String to parse * @param fileName File name * @param scriptIndex Script index * @param numberContextRef Number context reference * @param abc ABC + * @param sinitNeedsActivation Script initializer needs activation + * @param sinitVariables Script initializer variables * @return List of script traits * @throws AVM2ParseException On parsing error * @throws IOException On I/O error * @throws CompilationException On compilation error * @throws InterruptedException On interrupt */ - public List scriptTraitsFromString(List> allOpenedNamespaces, String str, String fileName, int scriptIndex, Reference numberContextRef, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { + public List scriptTraitsFromString( + List importedClasses, + List openedNamespaces, + List> allOpenedNamespaces, + String str, + String fileName, + int scriptIndex, + Reference numberContextRef, + ABC abc, + Reference sinitNeedsActivation, + List sinitVariables + ) throws AVM2ParseException, IOException, CompilationException, InterruptedException { lexer = new ActionScriptLexer(str); - List ret = parseScript(allOpenedNamespaces, scriptIndex, fileName, numberContextRef, abc); + List ret = parseScript(importedClasses, openedNamespaces, allOpenedNamespaces, scriptIndex, fileName, numberContextRef, abc, sinitNeedsActivation, sinitVariables); if (lexer.lex().type != SymbolType.EOF) { throw new AVM2ParseException("Parsing finisned before end of the file", lexer.yyline()); } @@ -2798,14 +2886,19 @@ public class ActionScript3Parser { /** * Adds script from tree. + * @param sinitVariables Script initializer variables + * @param sinitNeedsActivation Script initializer needs activation + * @param importedClasses Imported classes + * @param openedNamespaces Opened namespaces * @param allOpenedNamespaces All opened namespaces * @param items Items * @param classPos Class position * @param documentClass Document class + * @param numberContext Number context * @throws AVM2ParseException On parsing error * @throws CompilationException On compilation error */ - public void addScriptFromTree(List> allOpenedNamespaces, List items, int classPos, String documentClass, Integer numberContext) throws AVM2ParseException, CompilationException { + public void addScriptFromTree(List sinitVariables, boolean sinitNeedsActivation, List importedClasses, List openedNamespaces, List> allOpenedNamespaces, List items, int classPos, String documentClass, Integer numberContext) throws AVM2ParseException, CompilationException { AVM2SourceGenerator gen = new AVM2SourceGenerator(abcIndex); SourceGeneratorLocalData localData = new SourceGeneratorLocalData( new HashMap<>(), 0, Boolean.FALSE, 0); @@ -2815,8 +2908,9 @@ public class ActionScript3Parser { int scriptIndex = abcIndex.getSelectedAbc().script_info.size(); abcIndex.getSelectedAbc().script_info.add(si); try { - gen.generateScriptInfo(scriptIndex, si, allOpenedNamespaces, localData, items, classPos); + gen.generateScriptInfo(sinitVariables, sinitNeedsActivation, importedClasses, openedNamespaces, scriptIndex, si, allOpenedNamespaces, localData, items, classPos); } catch (Exception ex) { + ex.printStackTrace(); // FIXME abcIndex.getSelectedAbc().script_info.remove(si); throw ex; } @@ -2840,8 +2934,12 @@ public class ActionScript3Parser { public void addScript(String s, String fileName, int classPos, int scriptIndex, String documentClass, ABC abc) throws AVM2ParseException, IOException, CompilationException, InterruptedException { List> allOpenedNamespaces = new ArrayList<>(); Reference numberContextRef = new Reference<>(null); - List traits = scriptTraitsFromString(allOpenedNamespaces, s, fileName, scriptIndex, numberContextRef, abc); - addScriptFromTree(allOpenedNamespaces, traits, classPos, documentClass, numberContextRef.getVal()); + Reference sinitNeedsActivation = new Reference<>(false); + List sinitVariables = new ArrayList<>(); + List importedClasses = new ArrayList<>(); + List openedNamespaces = new ArrayList<>(); + List traits = scriptTraitsFromString(importedClasses, openedNamespaces, allOpenedNamespaces, s, fileName, scriptIndex, numberContextRef, abc, sinitNeedsActivation, sinitVariables); + addScriptFromTree(sinitVariables, sinitNeedsActivation.getVal(), importedClasses, openedNamespaces, allOpenedNamespaces, traits, classPos, documentClass, numberContextRef.getVal()); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java index 03a53a6bc..e29bdba38 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java @@ -93,16 +93,26 @@ public class NameAVM2Item extends AssignableAVM2Item { private AbcIndexing abcIndex; private String namespaceSuffix; + + private final boolean isConst; @Override public AssignableAVM2Item copy() { - NameAVM2Item c = new NameAVM2Item(type, line, attribute, variableName, namespaceSuffix, assignedValue, definition, openedNamespaces, abcIndex); + NameAVM2Item c = new NameAVM2Item(type, line, attribute, variableName, namespaceSuffix, assignedValue, definition, openedNamespaces, abcIndex, isConst); c.setNs(ns); c.regNumber = regNumber; c.unresolved = unresolved; c.nsKind = nsKind; return c; } + + /** + * Checks whether this name is const. + * @return Whether this name is const + */ + public boolean isConst() { + return isConst; + } /** * Is attribute. @@ -235,8 +245,9 @@ public class NameAVM2Item extends AssignableAVM2Item { * @param definition Is definition * @param openedNamespaces Opened namespaces * @param abcIndex ABC index + * @param isConst Is const */ - public NameAVM2Item(GraphTargetItem type, int line, boolean attribute, String variableName, String namespaceSuffix, GraphTargetItem storeValue, boolean definition, List openedNamespaces, AbcIndexing abcIndex) { + public NameAVM2Item(GraphTargetItem type, int line, boolean attribute, String variableName, String namespaceSuffix, GraphTargetItem storeValue, boolean definition, List openedNamespaces, AbcIndexing abcIndex, boolean isConst) { super(storeValue); this.attribute = attribute; this.variableName = variableName; @@ -247,6 +258,7 @@ public class NameAVM2Item extends AssignableAVM2Item { this.type = type; this.openedNamespaces = openedNamespaces; this.abcIndex = abcIndex; + this.isConst = isConst; } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java index bb0510402..f9f3db543 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java @@ -411,7 +411,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { if (a instanceof NameAVM2Item) { NameAVM2Item n = (NameAVM2Item) a; if (n.isDefinition() && name.get(0).equals(n.getVariableName())) { - NameAVM2Item ret = new NameAVM2Item(n.type, n.line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex); + NameAVM2Item ret = new NameAVM2Item(n.type, n.line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex, n.isConst()); ret.setSlotScope(n.getSlotScope()); ret.setSlotNumber(n.getSlotNumber()); ret.setRegNumber(n.getRegNumber()); @@ -441,7 +441,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { t = paramTypes.get(ind); } //else rest parameter - GraphTargetItem ret = new NameAVM2Item(t, line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex); + GraphTargetItem ret = new NameAVM2Item(t, line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex, false); resolved = ret; for (int i = 1; i < name.size(); i++) { resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>()); @@ -627,7 +627,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } } - NameAVM2Item ret = new NameAVM2Item(ntype, line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex); + NameAVM2Item ret = new NameAVM2Item(ntype, line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex, false); resolved = ret; for (int i = 1; i < name.size(); i++) { resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>()); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/AssignedValue.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/AssignedValue.java index cd7351d6c..88057d292 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/AssignedValue.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/AssignedValue.java @@ -25,6 +25,11 @@ import com.jpexs.decompiler.graph.GraphTargetItem; */ public class AssignedValue { + /** + * Command + */ + public GraphTargetItem command; + /** * Value */ @@ -43,11 +48,13 @@ public class AssignedValue { /** * Constructs a new assigned value. * + * @param command Command * @param value Value * @param initializer Initializer type * @param method Method index */ - public AssignedValue(GraphTargetItem value, int initializer, int method) { + public AssignedValue(GraphTargetItem command, GraphTargetItem value, int initializer, int method) { + this.command = command; this.value = value; this.initializer = initializer; this.method = method; 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 dec1c3852..39cf7bcec 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 @@ -474,7 +474,7 @@ public final class MethodBody implements Cloneable { convertedItems1 = converted.getCode().toGraphTargetItems(callStack, abcIndex, convertData.thisHasDefaultToPrimitive, convertData, path, methodIndex, isStatic, scriptIndex, classIndex, abc, converted, localRegNames, scopeStack, initializerType, fullyQualifiedNames, initTraits, 0, new HashMap<>()); //converted.getCode().visitCode(converted) } try (Statistics s = new Statistics("Graph.graphToString")) { - Graph.graphToString(convertedItems1, writer, LocalData.create(callStack, abcIndex, abc, localRegNames, fullyQualifiedNames, seenMethods)); + Graph.graphToString(convertedItems1, writer, LocalData.create(callStack, abcIndex, abc, localRegNames, fullyQualifiedNames, seenMethods, exportMode)); } convertedItems = convertedItems1; } @@ -565,7 +565,7 @@ public final class MethodBody implements Cloneable { fullyQualifiedNames2.remove(tname); } - Graph.graphToString(convertedItems, writer, LocalData.create(callStack, abcIndex, abc, localRegNames, fullyQualifiedNames2, seenMethods)); + Graph.graphToString(convertedItems, writer, LocalData.create(callStack, abcIndex, abc, localRegNames, fullyQualifiedNames2, seenMethods, exportMode)); //writer.endMethod(); } else if (convertException instanceof TimeoutException) { // exception was logged in convert method diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index 22ae95957..6ad9ac11e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; +import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.graph.DottedChain; @@ -171,6 +172,9 @@ public class ScriptInfo { for (int j = 0; j < traits.traits.size(); j++) { Trait t = traits.traits.get(j); + if (!isSimple && (t instanceof TraitSlotConst)) { + continue; + } Multiname name = t.getName(abc); int nskind = name.getSimpleNamespaceKind(abc.constants); if ((nskind == Namespace.KIND_PACKAGE_INTERNAL) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 908aa4ce8..314ac0baf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -644,13 +644,16 @@ public abstract class Trait implements Cloneable, Serializable { } } } - String nsPrefix = Namespace.getPrefix(nskind); - if (nsPrefix != null && !nsPrefix.isEmpty()) { - writer.appendNoHilight(nsPrefix).appendNoHilight(" "); + + if (!(classIndex == -1 && nskind == Namespace.KIND_PACKAGE_INTERNAL)) { + String nsPrefix = Namespace.getPrefix(nskind); + if (nsPrefix != null && !nsPrefix.isEmpty()) { + writer.appendNoHilight(nsPrefix).appendNoHilight(" "); + } } } } - if (isStatic) { + if (isStatic && classIndex > -1) { if ((this instanceof TraitSlotConst) && ((TraitSlotConst) this).isNamespace()) { //static is automatic } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 66d8d43a8..a9b4497b9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -234,7 +234,7 @@ public class TraitClass extends Trait implements TraitWithSlot { String instanceInfoName = instanceInfoMultiname.getName(abc.constants, fullyQualifiedNames, false, true); - getMetaData(parent, convertData, abc, writer); + getMetaData(this, convertData, abc, writer); boolean allowEmbed = true; @@ -284,11 +284,11 @@ public class TraitClass extends Trait implements TraitWithSlot { writer.startMethod(classInfo.cinit_index, "cinit"); if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { if (!classInitializerIsEmpty) { - writer.startBlock(); + //writer.startBlock(); List callStack = new ArrayList<>(); callStack.add(abc.bodies.get(bodyIndex)); abc.bodies.get(bodyIndex).toString(callStack, abcIndex, path + "/" + instanceInfoName + ".staticinitializer", exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); - writer.endBlock(); + //writer.endBlock(); } else { //Note: There must be trait/method highlight even if the initializer is empty to TraitList in GUI to work correctly //TODO: handle this better in GUI(?) @@ -297,9 +297,9 @@ public class TraitClass extends Trait implements TraitWithSlot { } writer.endMethod(); writer.endTrait(); - if (!classInitializerIsEmpty) { + /*if (!classInitializerIsEmpty) { writer.newLine(); - } + }*/ } else { //"/*classInitializer*/"; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index 25399f105..e44c15230 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -162,7 +162,7 @@ public class TraitFunction extends Trait implements TraitWithSlot { @Override public GraphTextWriter toString(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel, boolean insideInterface) throws InterruptedException { writeImports(abcIndex, scriptIndex, classIndex, false, abc, writer, getPackage(abc), fullyQualifiedNames); - getMetaData(parent, convertData, abc, writer); + getMetaData(this, convertData, abc, writer); writer.startMethod(method_info, getName(abc).getName(abc.constants, new ArrayList<>(), true, false)); toStringHeader(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel, insideInterface); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java index ce40768e6..96abd55eb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java @@ -240,7 +240,7 @@ public class TraitMethodGetterSetter extends Trait { if (classIndex < 0) { writeImports(abcIndex, scriptIndex, classIndex, isStatic, abc, writer, getPackage(abc), fullyQualifiedNames); } - getMetaData(parent, convertData, abc, writer); + getMetaData(this, convertData, abc, writer); writer.startMethod(method_info, getName(abc).getName(abc.constants, new ArrayList<>(), true, false)); path = path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames, false, true); toStringHeader(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel, insideInterface); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index f40cb4185..d7d282a2b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -166,14 +166,13 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { * * @param abcIndex ABC indexing * @param exportMode Export mode - * @param parent Parent * @param convertData Convert data * @param writer Writer * @param abc ABC * @param fullyQualifiedNames Fully qualified names * @throws InterruptedException On interrupt */ - public void getValueStr(AbcIndexing abcIndex, ScriptExportMode exportMode, Trait parent, ConvertData convertData, GraphTextWriter writer, ABC abc, List fullyQualifiedNames) throws InterruptedException { + public void getValueStr(AbcIndexing abcIndex, ScriptExportMode exportMode, ConvertData convertData, GraphTextWriter writer, ABC abc, List fullyQualifiedNames) throws InterruptedException { if (convertData.assignedValues.containsKey(this)) { AssignedValue assignment = convertData.assignedValues.get(this); @@ -189,7 +188,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { List callStack = new ArrayList<>(); callStack.add(abc.bodies.get(abc.findBodyIndex(assignment.method))); - assignment.value.toString(writer, LocalData.create(callStack, abcIndex, abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>())); + assignment.value.toString(writer, LocalData.create(callStack, abcIndex, abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>(), exportMode)); } writer.endMethod(); writer.endTrait(); @@ -252,7 +251,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { */ @Override public GraphTextWriter toString(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel, boolean insideInterface) throws InterruptedException { - getMetaData(parent, convertData, abc, writer); + getMetaData(this, convertData, abc, writer); Multiname n = getName(abc); boolean showModifier = true; if ((classIndex == -1) && (n != null)) { @@ -272,13 +271,13 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { List callStack = new ArrayList<>(); AssignedValue assignment = convertData.assignedValues.get(this); callStack.add(abc.bodies.get(abc.findBodyIndex(assignment.method))); - return val.toString(writer, LocalData.create(callStack, abcIndex, abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>())); + return val.toString(writer, LocalData.create(callStack, abcIndex, abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>(), exportMode)); } } getNameStr(writer, abc, fullyQualifiedNames); if (hasValueStr(abc, convertData)) { writer.appendNoHilight(" = "); - getValueStr(abcIndex, exportMode, parent, convertData, writer, abc, fullyQualifiedNames); + getValueStr(abcIndex, exportMode, convertData, writer, abc, fullyQualifiedNames); } return writer.appendNoHilight(";").newLine(); } @@ -305,7 +304,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { public void convert(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel, ScopeStack scopeStack) throws InterruptedException { getNameStr(writer, abc, fullyQualifiedNames); if (hasValueStr(abc, convertData)) { - getValueStr(abcIndex, exportMode, parent, convertData, writer, abc, fullyQualifiedNames); + getValueStr(abcIndex, exportMode, convertData, writer, abc, fullyQualifiedNames); } } 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 634c51a92..e53742566 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 @@ -316,7 +316,7 @@ public class Traits implements Cloneable, Serializable { */ public GraphTextWriter toString(AbcIndexing abcIndex, 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, List ignoredTraitNames, boolean insideInterface) throws InterruptedException { - List ordered = new ArrayList<>(traits); + /*List ordered = new ArrayList<>(traits); loopi: for (int i = 0; i < ordered.size(); i++) { for (int j = i + 1; j < ordered.size(); j++) { @@ -356,7 +356,9 @@ public class Traits implements Cloneable, Serializable { } } } - +*/ + List ordered = traits; + for (Trait trait : ordered) { int t = traits.indexOf(trait); if (traitTypes != null) { @@ -377,8 +379,13 @@ public class Traits implements Cloneable, Serializable { if (ignoredTraitNames.contains(trait.getName(abc).getName(abc.constants, new ArrayList<>(), false, false))) { continue; } - writer.newLine(); - int h = abc.getGlobalTraitId(TraitType.METHOD /*non-initializer*/, isStatic, classIndex, t); + + if ((trait instanceof TraitSlotConst) && convertData.assignedValues.containsKey((TraitSlotConst) trait)) { + continue; + } + + writer.newLine(); + int h = abc.getGlobalTraitId(TraitType.METHOD , isStatic, classIndex, t); writer.startTrait(h); if (makePackages) { trait.toStringPackaged(abcIndex, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel, insideInterface); 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 a0532d714..3445442bc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -3872,12 +3872,21 @@ public class Graph { * @throws InterruptedException On interrupt */ public static GraphTextWriter graphToString(List tree, GraphTextWriter writer, LocalData localData) throws InterruptedException { + boolean lastNewLine = false; for (GraphTargetItem ti : tree) { if (!ti.isEmpty()) { - ti.toStringSemicoloned(writer, localData); + if (ti.hasSingleNewLineAround() && !lastNewLine) { + writer.newLine(); + } + ti.toStringSemicoloned(writer, localData); if (!ti.handlesNewLine()) { writer.newLine(); } + lastNewLine = false; + if (ti.hasSingleNewLineAround()) { + writer.newLine(); + lastNewLine = true; + } } } return writer; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 73764e1a7..968b632db 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -767,6 +767,14 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { public boolean handlesNewLine() { return false; } + + /** + * Checks whether this item needs single newline before and after. + * @return True if needs + */ + public boolean hasSingleNewLineAround() { + return false; + } /** * Converts this to string with new line. diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java index 28175419f..955000cd4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.action.model.ConstantPool; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.graph.DottedChain; import java.util.HashMap; import java.util.HashSet; @@ -78,6 +79,11 @@ public class LocalData { * ABC */ public ABC abc; + + /** + * Script export mode + */ + public ScriptExportMode exportMode; /** * Creates a new local data @@ -99,9 +105,10 @@ public class LocalData { * @param localRegNames Local register names * @param fullyQualifiedNames Fully qualified names * @param seenMethods Seen methods + * @param exportMode * @return Local data */ - public static LocalData create(List callStack, AbcIndexing abcIndex, ABC abc, HashMap localRegNames, List fullyQualifiedNames, Set seenMethods) { + public static LocalData create(List callStack, AbcIndexing abcIndex, ABC abc, HashMap localRegNames, List fullyQualifiedNames, Set seenMethods, ScriptExportMode exportMode) { LocalData localData = new LocalData(); localData.abc = abc; localData.constantsAvm2 = abc.constants; @@ -110,6 +117,7 @@ public class LocalData { localData.seenMethods = seenMethods; localData.abcIndex = abcIndex; localData.callStack = callStack; + localData.exportMode = exportMode; return localData; } } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java index 37911e2d4..5712f776a 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java @@ -51,6 +51,7 @@ public class ActionScript2CompilerTest extends ActionScript2TestBase { Configuration.decompile.set(true); Configuration.registerNameFormat.set("_loc%d_"); Configuration.resolveConstants.set(true); + Configuration.showAllAddresses.set(false); swf = new SWF(new BufferedInputStream(new FileInputStream("testdata/as2/as2.swf")), false); } 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 e6d044322..484a45ddf 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 @@ -35,7 +35,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT @Test public void testActivationProps() { decompileMethod("assembled", "testActivationProps", "var myvar2:int = 10;\r\n", - false); + false); } @Test @@ -45,7 +45,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "{\r\n" + "trace(\"hey\");\r\n" + "}\r\n", - false); + false); } @Test @@ -53,7 +53,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT decompileMethod("assembled", "testDecrementPrecedence", "var _loc2_:int = 10;\r\n" + "var _loc1_:int = 5;\r\n" + "var _loc3_:* = _loc2_ & (1 << _loc1_) - 1;\r\n", - false); + false); } @Test @@ -79,21 +79,21 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "{\r\n" + "}\r\n" + "return 5;\r\n", - false); + false); } @Test public void testDoubleDup() { decompileMethod("assembled", "testDoubleDup", "var _loc10_:Rectangle = myprop(_loc5_);\r\n" + "_loc10_.mymethod(-_loc10_.width,-_loc10_.height);\r\n", - false); + false); } @Test public void testDup() { decompileMethod("assembled", "testDup", "var _loc1_:Number;\r\n" + "return 1 - (_loc1_ = 1 - _loc1_ / _loc4_) * _loc1_;\r\n", - false); + false); } @Test @@ -105,7 +105,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "{\r\n" + "trace(_loc2_);\r\n" + "}\r\n", - false); + false); } @Test @@ -121,7 +121,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "}\r\n" + "}\r\n" + "_loc3_ = 0;\r\n", - false); + false); } @Test @@ -130,14 +130,14 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "{\r\n" + "_loc6_.methodname(_loc1_,_loc2_,_loc5_);\r\n" + "}\r\n", - false); + false); } @Test public void testIncrement() { decompileMethod("assembled", "testIncrement", "super();\r\n" + "b = a++;\r\n", - false); + false); } @Test @@ -146,13 +146,13 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "{\r\n" + "somemethod();\r\n" + "}\r\n", - false); + false); } @Test public void testIncrement3() { decompileMethod("assembled", "testIncrement3", "_loc1_.length--;\r\n", - false); + false); } @Test @@ -162,7 +162,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "{\r\n" + "trace(\"I\");\r\n" + "}\r\n", - false); + false); } @Test @@ -181,7 +181,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "default:\r\n" + "return;\r\n" + "}\r\n", - false); + false); } @Test @@ -197,7 +197,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "}\r\n" + "§§pop();\r\n" + "§§pop();\r\n", - false); + false); } @Test @@ -206,14 +206,14 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "var _loc5_:int = 5;\r\n" + "myname.somemethod(\"okay\",myslot = _loc5_);\r\n" + "myname.start();\r\n", - false); + false); } @Test public void testSetSlotFindProperty() { decompileMethod("assembled", "testSetSlotFindProperty", "var myprop:int;\r\n" + "return myprop = 50;\r\n", - false); + false); } @Test @@ -221,7 +221,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT decompileMethod("assembled", "testSwapAssignment", "var _loc6_:Bitmap = MyFactory.createBitmap();\r\n" + "_loc6_.x = _loc6_.x + 5;\r\n" + "_loc6_.y = -10;\r\n", - false); + false); } @Test @@ -241,7 +241,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "_loc2_ = \"C\";\r\n" + "}\r\n" + "_loc2_ = \"after\";\r\n", - false); + false); } @Test @@ -264,7 +264,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "default:\r\n" + "_loc2_ = 100;\r\n" + "}\r\n", - false); + false); } @Test @@ -292,7 +292,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "case 2:\r\n" + "trace(\"case2\");\r\n" + "}\r\n", - false); + false); } @Test @@ -338,7 +338,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "}\r\n" + "trace(\"G\");\r\n" + "return null;\r\n", - false); + false); } @Test @@ -365,7 +365,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "_loc2_ = 1;\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -394,7 +394,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -415,7 +415,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "trace(\"in catch\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -435,7 +435,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "}\r\n" + "while(_loc5_ <= 100);\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -461,7 +461,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "return;\r\n" + "}\r\n" + "trace(\"finish\");\r\n", - false); + false); } @Test @@ -475,7 +475,7 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "{\r\n" + "return _loc5_;\r\n" + "}\r\n", - false); + false); } @Test @@ -485,6 +485,6 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT + "yyy\r\n" + ";\r\n" + "var _loc2_:* = _loc1_.b.*;\r\n", - false); + false); } } 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 e2793c597..0a4bd47c8 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 @@ -627,4 +627,86 @@ public class ActionScript3ClassTest extends ActionScript3DecompileTestBase { + " }\n" + "}"); } + + @Test + public void testScriptInitializer() { + decompileScriptPack("standard", "tests_classes.TestScriptInitializer", "package tests_classes\n" + + "{\n" + + " public class TestScriptInitializer\n" + + " {\n" + + " \n" + + " private static var sv:int;\n" + + " \n" + + " private static var sa:int = 5;\n" + + " \n" + + " private static const sc:int = Math.floor(Math.random() * 50) + sa + x;\n" + + " \n" + + " private static var sb:int = sa + 20;\n" + + " \n" + + " if(Math.random() * 10 >= 5)\n" + + " {\n" + + " sa += 100;\n" + + " }\n" + + " else\n" + + " {\n" + + " sa += 200;\n" + + " }\n" + + " if(sb > 100)\n" + + " {\n" + + " sb += 10;\n" + + " }\n" + + " else\n" + + " {\n" + + " sb += 20;\n" + + " }\n" + + " for each(sv in [1,3,5])\n" + + " {\n" + + " trace(sv);\n" + + " }\n" + + " \n" + + " public function TestScriptInitializer()\n" + + " {\n" + + " super();\n" + + " }\n" + + " \n" + + " public function test() : void\n" + + " {\n" + + " var x:int = 5;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "var v:int;\n" + + "\n" + + "var x:int = Math.random() * 100;\n" + + "\n" + + "var a:int = 5;\n" + + "\n" + + "if(Math.random() * 10 >= 5)\n" + + "{\n" + + " a = a + 100;\n" + + "}\n" + + "else\n" + + "{\n" + + " a = a + 200;\n" + + "}\n" + + "\n" + + "const c:int = Math.floor(Math.random() * 50) + a;\n" + + "\n" + + "var b:int = a + 20;\n" + + "\n" + + "if(b > 100)\n" + + "{\n" + + " b = b + 10;\n" + + "}\n" + + "else\n" + + "{\n" + + " b = b + 20;\n" + + "}\n" + + "for each(v in [1,3,5])\n" + + "{\n" + + " trace(v);\n" + + "}\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 7c5360757..b91ca6e8b 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 @@ -42,13 +42,13 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(arguments[0]);\r\n" + "}\r\n", - false); + false); } @Test public void testArguments() { decompileMethod("classic_air", "testArguments", "return arguments[0];\r\n", - false); + false); } @Test @@ -61,21 +61,21 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "var f:* = a ^ 0x0641;\r\n" + "var g:* = 0x0641 ^ a;\r\n" + "var h:int = -385;\r\n", - false); + false); } @Test public void testCallCall() { decompileMethod("classic_air", "testCallCall", "var o:* = new getDefinitionByName(\"Object\");\r\n" + "var o2:* = new (getDefinitionByName(\"Object\"))();\r\n", - false); + false); } @Test public void testCallLocal() { decompileMethod("classic_air", "testCallLocal", "var f:Function = getF();\r\n" + "var b:int = f(1,3);\r\n", - false); + false); } @Test @@ -95,7 +95,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"infinally\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -115,7 +115,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"ch\");\r\n" + "}\r\n", - false); + false); } @Test @@ -134,7 +134,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"OK: \" + f);\r\n" + "}\r\n", - false); + false); } @Test @@ -157,7 +157,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(e);\r\n" + "}\r\n" + "trace(\"y\");\r\n", - false); + false); } @Test @@ -165,7 +165,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile decompileMethod("classic_air", "testComma", "var a:int = 5;\r\n" + "var b:int = 0;\r\n" + "trace(a > 4 ? (b = 5, a) : 35);\r\n", - false); + false); } @Test @@ -173,7 +173,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile decompileMethod("classic_air", "testComplexExpressions", "var i:int = 0;\r\n" + "var j:int = 0;\r\n" + "j = i += i += i++;\r\n", - false); + false); } @Test @@ -203,7 +203,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(e.message);\r\n" + "}\r\n", - false); + false); } @Test @@ -269,7 +269,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"hello\");\r\n" + "}\r\n", - false); + false); } @Test @@ -353,7 +353,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "super.prot = int(s);\r\n" + "i = super.prot;\r\n" + "s = String(super.prot);\r\n", - false); + false); } @Test @@ -369,7 +369,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "}\r\n" + "k = 7;\r\n", - false); + false); } @Test @@ -385,7 +385,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "i = new MyClass2();\r\n" + "}\r\n" + "return i;\r\n", - false); + false); } @Test @@ -405,7 +405,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "vnumber = 0.5;\r\n" + "vnumber = 6;\r\n" + "vobject = vclass;\r\n", - false); + false); } @Test @@ -423,7 +423,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"4\");\r\n" + "}\r\n" + "trace(\"after switch\");\r\n", - false); + false); } @Test @@ -445,7 +445,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -457,7 +457,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "a++;\r\n" + "}\r\n" + "while(a < 20);\r\n", - false); + false); } @Test @@ -478,7 +478,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "while(k < 9);\r\n" + "return 2;\r\n", - false); + false); } @Test @@ -488,7 +488,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "nextChar();\r\n" + "}\r\n" + "while(ch != \"\\n\" && ch != \"\");\r\n", - false); + false); } @Test @@ -510,7 +510,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "while(k < 10);\r\n" + "trace(\"ss\");\r\n", - false); + false); } @Test @@ -521,7 +521,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"between\");\r\n" + "var g:* = k.(d.attrib++, false);\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -529,7 +529,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile decompileMethod("classic_air", "testExecutionOrder", "var m:MyClass = null;\r\n" + "m.x = (m = create() as MyClass).x + 5;\r\n" + "trace(m.x);\r\n", - false); + false); } @Test @@ -551,7 +551,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "arr[0]();\r\n" + "}\r\n" + "return i == 0;\r\n", - false); + false); } @Test @@ -573,7 +573,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "return \"hu\" + str;\r\n" + "}\r\n", - false); + false); } @Test @@ -584,7 +584,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"a=\" + a);\r\n" + "a++;\r\n" + "}\r\n", - false); + false); } @Test @@ -610,7 +610,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -625,7 +625,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"hello:\" + a);\r\n" + "a++;\r\n" + "}\r\n", - false); + false); } @Test @@ -654,7 +654,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"part5\");\r\n" + "}\r\n", - false); + false); } @Test @@ -669,7 +669,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"item #\" + item);\r\n" + "}\r\n", - false); + false); } @Test @@ -686,7 +686,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"item #\" + test[0]);\r\n" + "}\r\n", - false); + false); } @Test @@ -700,7 +700,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"item #\" + this.testPriv);\r\n" + "}\r\n", - false); + false); } @Test @@ -718,7 +718,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "return item;\r\n" + "}\r\n" + "return null;\r\n", - false); + false); } @Test @@ -741,7 +741,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "}\r\n" + "return null;\r\n", - false); + false); } @Test @@ -780,7 +780,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"before_continue\");\r\n" + "}\r\n", - false); + false); } @Test @@ -807,7 +807,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -833,7 +833,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"C\");\r\n" + "}\r\n" + "trace(\"exit\");\r\n", - false); + false); } @Test @@ -848,7 +848,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(item);\r\n" + "}\r\n", - false); + false); } @Test @@ -867,7 +867,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"forend\");\r\n" + "}\r\n", - false); + false); } @Test @@ -881,7 +881,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "return item;\r\n" + "}\r\n" + "return null;\r\n", - false); + false); } @Test @@ -902,7 +902,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"final\");\r\n" + "}\r\n", - false); + false); } @Test @@ -936,7 +936,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"C\");\r\n" + "}\r\n", - false); + false); } @Test @@ -945,7 +945,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "c.attr = 2;\r\n" + "var a:int = attr;\r\n" + "trace(a);\r\n", - false); + false); } @Test @@ -977,7 +977,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"after\");\r\n" + "}\r\n" + "return 89;\r\n", - false); + false); } @Test @@ -1001,7 +1001,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"E\");\r\n" + "}\r\n" + "return 5;\r\n", - false); + false); } @Test @@ -1029,7 +1029,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"C\");\r\n" + "}\r\n" + "trace(\"return\");\r\n", - false); + false); } @Test @@ -1050,7 +1050,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "}\r\n" + "trace(\"return\");\r\n", - false); + false); } @Test @@ -1075,7 +1075,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "j++;\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -1100,7 +1100,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"D\");\r\n" + "}\r\n" + "trace(\"finish\");\r\n", - false); + false); } @Test @@ -1130,13 +1130,13 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"before loop end\");\r\n" + "}\r\n", - false); + false); } @Test public void testHello() { decompileMethod("classic_air", "testHello", "trace(\"hello\");\r\n", - false); + false); } @Test @@ -1146,7 +1146,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"onTrue\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1160,7 +1160,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"onFalse\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1181,7 +1181,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"in finally\");\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -1205,7 +1205,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"C\");\r\n" + "return 7;\r\n", - false); + false); } @Test @@ -1230,7 +1230,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"in catch\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1252,7 +1252,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1269,20 +1269,20 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"F\");\r\n" + "}\r\n", - false); + false); } @Test public void testImportedConst() { decompileMethod("classic_air", "testImportedConst", "trace(29);\r\n", - false); + false); } @Test public void testImportedVar() { decompileMethod("classic_air", "testImportedVar", "trace(myvar);\r\n" + "myvar = 5;\r\n", - false); + false); } @Test @@ -1296,7 +1296,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "b++;\r\n" + "var c:int = 1;\r\n" + "b = c++;\r\n", - false); + false); } @Test @@ -1347,7 +1347,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"--attr\");\r\n" + "trace(--attrx);\r\n" + "--attrx;\r\n", - false); + false); } @Test @@ -1367,7 +1367,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "return first;\r\n" + "};\r\n" + "traceParameter(\"hello\");\r\n", - false); + false); } @Test @@ -1392,7 +1392,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "return a + 1;\r\n" + "})(1);\r\n", - false); + false); } @Test @@ -1403,7 +1403,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(testProm);\r\n" + "};\r\n" + "innerFunc(a);\r\n", - false); + false); } @Test @@ -1419,7 +1419,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "s = 8;\r\n" + "}\r\n" + "innerFunc(a);\r\n", - false); + false); } @Test @@ -1446,7 +1446,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"b!=7\");\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -1471,7 +1471,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"finally block\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1485,20 +1485,20 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "b = true;\r\n" + "}\r\n" + "b = (i == 0 || i == 1) && j == 0;\r\n", - false); + false); } @Test public void testManualConvert() { decompileMethod("classic_air", "testManualConvert", "trace(\"String(this).length\");\r\n" + "trace(String(this).length);\r\n", - false); + false); } @Test public void testMetadata() { decompileMethod("classic_air", "testMetadata", "trace(\"hello\");\r\n", - false); + false); } @Test @@ -1515,7 +1515,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "default:\r\n" + "jj = 3;\r\n" + "}\r\n", - false); + false); } @Test @@ -1531,7 +1531,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"onFalse\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1544,7 +1544,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "return (param1 as TestClass2).attrib1 == 5;\r\n" + "};\r\n" + "})();\r\n", - false); + false); } @Test @@ -1556,7 +1556,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(b.c);\r\n" + "var c:int = myInternal::neco;\r\n" + "var d:int = myInternal2::neco;\r\n", - false); + false); } @Test @@ -1572,21 +1572,21 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "f();\r\n" + "this.f();\r\n" + "g();\r\n", - false); + false); } @Test public void testNegate() { decompileMethod("classic_air", "testNegate", "var a:int = 5;\r\n" + "var b:int = ~a;\r\n", - false); + false); } @Test public void testNumberCall() { decompileMethod("classic_air", "testNumberCall", "var a:String = (5).toString();\r\n" + "var b:String = 5.2.toString();\r\n", - false); + false); } @Test @@ -1675,7 +1675,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "\"test\" + this.f();\r\n" + "v = undefined;\r\n" + "sr = typeof c;\r\n", - false); + false); } @Test @@ -1689,19 +1689,19 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "var d:int = 4;\r\n" + "var e:int = d + 5;\r\n" + "var i:int = h = g = f;\r\n", - false); + false); } @Test public void testParamNames() { decompileMethod("classic_air", "testParamNames", "return firstp + secondp + thirdp;\r\n", - false); + false); } @Test public void testParamsCount() { decompileMethod("classic_air", "testParamsCount", "return firstp;\r\n", - false); + false); } @Test @@ -1718,7 +1718,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "a = 6;\r\n" + "a = 0.6666666666666666;\r\n" + "trace(\"a=\" + a);\r\n", - false); + false); } @Test @@ -1728,7 +1728,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "var c:int = 3;\r\n" + "var d:* = a << (b >>> c);\r\n" + "var e:* = a << b >>> c;\r\n", - false); + false); } @Test @@ -1739,7 +1739,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "d.method(d.attrib * 5);\r\n" + "}\r\n", - false); + false); } @Test @@ -1756,14 +1756,14 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "r = n1 / n2 / n3;\r\n" + "trace(\"not a regexp 2\");\r\n" + "r /= n1 / n2;\r\n", - false); + false); } @Test public void testRest() { decompileMethod("classic_air", "testRest", "trace(\"firstRest:\" + restval[0]);\r\n" + "return firstp;\r\n", - false); + false); } @Test @@ -1778,7 +1778,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(i--);\r\n" + "trace(++i);\r\n" + "trace(--i);\r\n", - false); + false); } @Test @@ -1795,7 +1795,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "n = 1;\r\n" + "}\r\n" + "};\r\n", - false); + false); } @Test @@ -1805,14 +1805,14 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"is eight\");\r\n" + "}\r\n", - false); + false); } @Test public void testStringCoerce() { decompileMethod("classic_air", "testStringCoerce", "var text1:String = this.a[\"test\"];\r\n" + "var text2:String = String(this.a[\"test\"]);\r\n", - false); + false); } @Test @@ -1821,7 +1821,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "this.traceIt(\"hello30\");\r\n" + "this.traceIt(\"hello\" + (k - 1));\r\n" + "this.traceIt(\"hello56\");\r\n", - false); + false); } @Test @@ -1831,7 +1831,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"backslash: \\\\ \");\r\n" + "trace(\"single quotes: \\'hello!\\'\");\r\n" + "trace(\"new line \\r\\n hello!\");\r\n", - false); + false); } @Test @@ -1850,7 +1850,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "case 89:\r\n" + "trace(\"eightynine\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1867,7 +1867,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "case \"C\":\r\n" + "trace(\"is C\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1895,7 +1895,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"message shown\");\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -1917,7 +1917,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "default:\r\n" + "trace(\"default clause\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1935,7 +1935,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "break;\r\n" + "}\r\n" + "trace(\"B\");\r\n", - false); + false); } @Test @@ -1946,7 +1946,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "var d:int = 78;\r\n" + "var e:* = a == b ? (c == d ? 1 : 7) : 3;\r\n" + "trace(\"e=\" + e);\r\n", - false); + false); } @Test @@ -1971,7 +1971,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"Finally part\");\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -1989,7 +1989,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "trace(\"in catch\");\r\n" + "}\r\n", - false); + false); } @Test @@ -2017,7 +2017,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "}\r\n" + "return 4;\r\n", - false); + false); } @Test @@ -2059,7 +2059,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"after\");\r\n" + "return \"X\";\r\n", - false); + false); } @Test @@ -2080,7 +2080,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "i++;\r\n" + "}\r\n" + "f();\r\n", - false); + false); } @Test @@ -2114,7 +2114,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"after\");\r\n" + "return \"X\";\r\n", - false); + false); } @Test @@ -2124,7 +2124,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "return x + y + TestClass;\r\n" + "};\r\n", - false); + false); } @Test @@ -2135,14 +2135,14 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "var a:int = 5;\r\n" + "v[a * 8 - 39] = \"hi2\";\r\n" + "trace(v[0]);\r\n", - false); + false); } @Test public void testVector2() { decompileMethod("classic_air", "testVector2", "var a:Vector.> = new Vector.>();\r\n" + "var b:Vector. = new [10,20,30];\r\n", - false); + false); } @Test @@ -2156,7 +2156,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "a = 7;\r\n" + "b = 9;\r\n", - false); + false); } @Test @@ -2175,7 +2175,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "}\r\n" + "return \"B\";\r\n", - false); + false); } @Test @@ -2226,7 +2226,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"gg\");\r\n" + "}\r\n" + "trace(\"ss\");\r\n", - false); + false); } @Test @@ -2248,7 +2248,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "trace(\"hello2\");\r\n" + "}\r\n", - false); + false); } @Test @@ -2267,7 +2267,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "\r\n" + "}\r\n" + "trace(\"E\");\r\n", - false); + false); } @Test @@ -2297,7 +2297,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "}\r\n" + "i++;\r\n" + "}\r\n", - false); + false); } @Test @@ -2318,7 +2318,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "{\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -2346,7 +2346,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "trace(\"after_try\");\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -2490,6 +2490,6 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "\r\n" + ";\r\n" + "var m:XMLList = myXML.*;\r\n", - false); + false); } } 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 3fd476a9d..3a0f87c4f 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 @@ -42,13 +42,13 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(arguments[0]);\r\n" + "}\r\n", - false); + false); } @Test public void testArguments() { decompileMethod("classic", "testArguments", "return arguments[0];\r\n", - false); + false); } @Test @@ -61,21 +61,21 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var f:int = a ^ 0x0641;\r\n" + "var g:int = 0x0641 ^ a;\r\n" + "var h:int = ~0x0180;\r\n", - false); + false); } @Test public void testCallCall() { decompileMethod("classic", "testCallCall", "var o:* = new getDefinitionByName(\"Object\")();\r\n" + "var o2:* = new (getDefinitionByName(\"Object\"))();\r\n", - false); + false); } @Test public void testCallLocal() { decompileMethod("classic", "testCallLocal", "var f:Function = this.getF();\r\n" + "var b:int = f(1,3);\r\n", - false); + false); } @Test @@ -95,7 +95,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"infinally\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -115,7 +115,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"ch\");\r\n" + "}\r\n", - false); + false); } @Test @@ -134,7 +134,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"OK: \" + f);\r\n" + "}\r\n", - false); + false); } @Test @@ -157,7 +157,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(e);\r\n" + "}\r\n" + "trace(\"y\");\r\n", - false); + false); } @Test @@ -165,7 +165,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes decompileMethod("classic", "testComma", "var a:int = 5;\r\n" + "var b:int = 0;\r\n" + "trace(a > 4 ? (b = 5, a) : 35);\r\n", - false); + false); } @Test @@ -173,7 +173,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes decompileMethod("classic", "testComplexExpressions", "var i:int = 0;\r\n" + "var j:int = 0;\r\n" + "j = i = i + (i = i + i++);\r\n", - false); + false); } @Test @@ -204,7 +204,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(e.message);\r\n" + "}\r\n", - false); + false); } @Test @@ -268,7 +268,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"hello\");\r\n" + "}\r\n", - false); + false); } @Test @@ -352,7 +352,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "super.prot = int(s);\r\n" + "i = super.prot;\r\n" + "s = String(super.prot);\r\n", - false); + false); } @Test @@ -368,7 +368,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "}\r\n" + "k = 7;\r\n", - false); + false); } @Test @@ -384,7 +384,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "i = new MyClass2();\r\n" + "}\r\n" + "return i;\r\n", - false); + false); } @Test @@ -404,7 +404,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "vnumber = 0.5;\r\n" + "vnumber = 6;\r\n" + "vobject = vclass;\r\n", - false); + false); } @Test @@ -422,7 +422,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"4\");\r\n" + "}\r\n" + "trace(\"after switch\");\r\n", - false); + false); } @Test @@ -444,7 +444,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -456,7 +456,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "a++;\r\n" + "}\r\n" + "while(a < 20);\r\n", - false); + false); } @Test @@ -477,7 +477,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "while(k < 9);\r\n" + "return 2;\r\n", - false); + false); } @Test @@ -487,7 +487,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "this.nextChar();\r\n" + "}\r\n" + "while(this.ch != \"\\n\" && this.ch != \"\");\r\n", - false); + false); } @Test @@ -509,7 +509,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "while(k < 10);\r\n" + "trace(\"ss\");\r\n", - false); + false); } @Test @@ -523,7 +523,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"between\");\r\n" + "g = k.(++d.attrib, 0);\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -531,7 +531,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes decompileMethod("classic", "testExecutionOrder", "var m:MyClass = null;\r\n" + "m.x = (m = create() as MyClass).x + 5;\r\n" + "trace(m.x);\r\n", - false); + false); } @Test @@ -553,7 +553,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "arr[0]();\r\n" + "}\r\n" + "return i == 0;\r\n", - false); + false); } @Test @@ -575,7 +575,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "return \"hu\" + str;\r\n" + "}\r\n", - false); + false); } @Test @@ -584,7 +584,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"a=\" + a);\r\n" + "}\r\n", - false); + false); } @Test @@ -609,7 +609,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -622,7 +622,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"hello:\" + a);\r\n" + "}\r\n", - false); + false); } @Test @@ -650,7 +650,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"part5\");\r\n" + "}\r\n", - false); + false); } @Test @@ -665,7 +665,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"item #\" + item);\r\n" + "}\r\n", - false); + false); } @Test @@ -682,7 +682,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"item #\" + test[0]);\r\n" + "}\r\n", - false); + false); } @Test @@ -696,7 +696,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"item #\" + this.testPriv);\r\n" + "}\r\n", - false); + false); } @Test @@ -714,7 +714,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "return item;\r\n" + "}\r\n" + "return null;\r\n", - false); + false); } @Test @@ -738,7 +738,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "}\r\n" + "return null;\r\n", - false); + false); } @Test @@ -778,7 +778,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"before_continue\");\r\n" + "}\r\n", - false); + false); } @Test @@ -806,7 +806,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -831,7 +831,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"C\");\r\n" + "}\r\n" + "trace(\"exit\");\r\n", - false); + false); } @Test @@ -846,7 +846,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(item);\r\n" + "}\r\n", - false); + false); } @Test @@ -866,7 +866,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"forend\");\r\n" + "}\r\n", - false); + false); } @Test @@ -880,7 +880,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "return item;\r\n" + "}\r\n" + "return null;\r\n", - false); + false); } @Test @@ -903,7 +903,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"final\");\r\n" + "}\r\n", - false); + false); } @Test @@ -937,7 +937,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"C\");\r\n" + "}\r\n", - false); + false); } @Test @@ -946,7 +946,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "c.attr = 2;\r\n" + "var a:* = this.attr;\r\n" + "trace(a);\r\n", - false); + false); } @Test @@ -978,7 +978,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"after\");\r\n" + "}\r\n" + "return 89;\r\n", - false); + false); } @Test @@ -1002,7 +1002,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"E\");\r\n" + "}\r\n" + "return 5;\r\n", - false); + false); } @Test @@ -1029,7 +1029,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"C\");\r\n" + "}\r\n" + "trace(\"return\");\r\n", - false); + false); } @Test @@ -1050,7 +1050,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "}\r\n" + "trace(\"return\");\r\n", - false); + false); } @Test @@ -1074,7 +1074,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "j++;\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -1099,7 +1099,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"D\");\r\n" + "}\r\n" + "trace(\"finish\");\r\n", - false); + false); } @Test @@ -1128,13 +1128,13 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"before loop end\");\r\n" + "}\r\n", - false); + false); } @Test public void testHello() { decompileMethod("classic", "testHello", "trace(\"hello\");\r\n", - false); + false); } @Test @@ -1144,7 +1144,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"onTrue\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1158,7 +1158,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"onFalse\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1179,7 +1179,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"in finally\");\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -1203,7 +1203,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"C\");\r\n" + "return 7;\r\n", - false); + false); } @Test @@ -1227,7 +1227,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"in catch\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1249,7 +1249,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"D\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1266,20 +1266,20 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"F\");\r\n" + "}\r\n", - false); + false); } @Test public void testImportedConst() { decompileMethod("classic", "testImportedConst", "trace(myconst);\r\n", - false); + false); } @Test public void testImportedVar() { decompileMethod("classic", "testImportedVar", "trace(myvar);\r\n" + "myvar = 5;\r\n", - false); + false); } @Test @@ -1293,7 +1293,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "b++;\r\n" + "var c:* = 1;\r\n" + "b = c++;\r\n", - false); + false); } @Test @@ -1346,7 +1346,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"--attr\");\r\n" + "trace(--this.attrx);\r\n" + "--this.attrx;\r\n", - false); + false); } @Test @@ -1368,7 +1368,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "return first;\r\n" + "};\r\n" + "traceParameter(\"hello\");\r\n", - false); + false); } @Test @@ -1389,7 +1389,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "return a + 1;\r\n" + "})(1);\r\n", - false); + false); } @Test @@ -1400,7 +1400,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(testProm);\r\n" + "};\r\n" + "innerFunc(a);\r\n", - false); + false); } @Test @@ -1416,7 +1416,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "s = 8;\r\n" + "}\r\n" + "innerFunc(a);\r\n", - false); + false); } @Test @@ -1443,7 +1443,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"b!=7\");\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -1468,7 +1468,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"finally block\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1482,20 +1482,20 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "b = true;\r\n" + "}\r\n" + "b = (i == 0 || i == 1) && j == 0;\r\n", - false); + false); } @Test public void testManualConvert() { decompileMethod("classic", "testManualConvert", "trace(\"String(this).length\");\r\n" + "trace(String(this).length);\r\n", - false); + false); } @Test public void testMetadata() { decompileMethod("classic", "testMetadata", "trace(\"hello\");\r\n", - false); + false); } @Test @@ -1512,7 +1512,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "default:\r\n" + "jj = 3;\r\n" + "}\r\n", - false); + false); } @Test @@ -1528,7 +1528,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"onFalse\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1537,7 +1537,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "return (param1 as TestClass2).attrib1 == 5;\r\n" + "};\r\n", - false); + false); } @Test @@ -1549,7 +1549,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(b.c);\r\n" + "var c:* = myInternal::neco;\r\n" + "var d:* = this.myInternal2::neco;\r\n", - false); + false); } @Test @@ -1565,21 +1565,21 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "this.f();\r\n" + "this.f();\r\n" + "g();\r\n", - false); + false); } @Test public void testNegate() { decompileMethod("classic", "testNegate", "var a:int = 5;\r\n" + "var b:int = ~a;\r\n", - false); + false); } @Test public void testNumberCall() { decompileMethod("classic", "testNumberCall", "var a:String = (5).toString();\r\n" + "var b:String = 5.2.toString();\r\n", - false); + false); } @Test @@ -1661,7 +1661,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "\"test\" + this.f();\r\n" + "v = undefined;\r\n" + "sr = typeof c;\r\n", - false); + false); } @Test @@ -1675,19 +1675,19 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var d:int = 4;\r\n" + "var e:int = d + 5;\r\n" + "var i:int = h = g = f;\r\n", - false); + false); } @Test public void testParamNames() { decompileMethod("classic", "testParamNames", "return firstp + secondp + thirdp;\r\n", - false); + false); } @Test public void testParamsCount() { decompileMethod("classic", "testParamsCount", "return firstp;\r\n", - false); + false); } @Test @@ -1704,7 +1704,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "a = 1 * 2 * 3;\r\n" + "a = 1 * 2 / 3;\r\n" + "trace(\"a=\" + a);\r\n", - false); + false); } @Test @@ -1714,7 +1714,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var c:* = 3;\r\n" + "var d:* = a << (b >>> c);\r\n" + "var e:* = a << b >>> c;\r\n", - false); + false); } @Test @@ -1725,7 +1725,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "d.method(d.attrib * 5);\r\n" + "}\r\n", - false); + false); } @Test @@ -1742,14 +1742,14 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "r = n1 / n2 / n3;\r\n" + "trace(\"not a regexp 2\");\r\n" + "r /= n1 / n2;\r\n", - false); + false); } @Test public void testRest() { decompileMethod("classic", "testRest", "trace(\"firstRest:\" + restval[0]);\r\n" + "return firstp;\r\n", - false); + false); } @Test @@ -1764,7 +1764,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(i--);\r\n" + "trace(++i);\r\n" + "trace(--i);\r\n", - false); + false); } @Test @@ -1781,7 +1781,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "n = 1;\r\n" + "}\r\n" + "};\r\n", - false); + false); } @Test @@ -1791,14 +1791,14 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"is eight\");\r\n" + "}\r\n", - false); + false); } @Test public void testStringCoerce() { decompileMethod("classic", "testStringCoerce", "var text1:String = this.a[\"test\"];\r\n" + "var text2:String = String(this.a[\"test\"]);\r\n", - false); + false); } @Test @@ -1807,7 +1807,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "this.traceIt(\"hello\" + 5 * 6);\r\n" + "this.traceIt(\"hello\" + (k - 1));\r\n" + "this.traceIt(\"hello\" + 5 + 6);\r\n", - false); + false); } @Test @@ -1817,7 +1817,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"backslash: \\\\ \");\r\n" + "trace(\"single quotes: \\'hello!\\'\");\r\n" + "trace(\"new line \\r\\n hello!\");\r\n", - false); + false); } @Test @@ -1836,7 +1836,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "case 89:\r\n" + "trace(\"eightynine\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1853,7 +1853,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "case TestSwitchComma.X, \"C\":\r\n" + "trace(\"is C\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1881,7 +1881,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"message shown\");\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -1903,7 +1903,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "default:\r\n" + "trace(\"default clause\");\r\n" + "}\r\n", - false); + false); } @Test @@ -1921,7 +1921,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "}\r\n" + "trace(\"B\");\r\n", - false); + false); } @Test @@ -1932,7 +1932,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var d:* = 78;\r\n" + "var e:* = a == b ? (c == d ? 1 : 7) : 3;\r\n" + "trace(\"e=\" + e);\r\n", - false); + false); } @Test @@ -1957,7 +1957,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"Finally part\");\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -1975,7 +1975,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "trace(\"in catch\");\r\n" + "}\r\n", - false); + false); } @Test @@ -2003,7 +2003,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "}\r\n" + "return 4;\r\n", - false); + false); } @Test @@ -2050,7 +2050,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"after\");\r\n" + "return \"X\";\r\n", - false); + false); } @Test @@ -2070,7 +2070,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "i++;\r\n" + "}\r\n" + "f();\r\n", - false); + false); } @Test @@ -2106,7 +2106,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"after\");\r\n" + "return \"X\";\r\n", - false); + false); } @Test @@ -2116,7 +2116,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "return x + y + TestClass;\r\n" + "};\r\n", - false); + false); } @Test @@ -2127,14 +2127,14 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var a:int = 5;\r\n" + "v[a * 8 - 39] = \"hi2\";\r\n" + "trace(v[0]);\r\n", - false); + false); } @Test public void testVector2() { decompileMethod("classic", "testVector2", "var a:Vector.> = new Vector.>();\r\n" + "var b:Vector. = new [10,20,30];\r\n", - false); + false); } @Test @@ -2148,7 +2148,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "a = 7;\r\n" + "b = 9;\r\n", - false); + false); } @Test @@ -2167,7 +2167,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "}\r\n" + "return \"B\";\r\n", - false); + false); } @Test @@ -2218,7 +2218,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"gg\");\r\n" + "}\r\n" + "trace(\"ss\");\r\n", - false); + false); } @Test @@ -2240,7 +2240,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "trace(\"hello2\");\r\n" + "}\r\n", - false); + false); } @Test @@ -2259,7 +2259,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "\r\n" + "}\r\n" + "trace(\"E\");\r\n", - false); + false); } @Test @@ -2289,7 +2289,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "}\r\n" + "i++;\r\n" + "}\r\n", - false); + false); } @Test @@ -2310,7 +2310,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "{\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -2337,7 +2337,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "trace(\"after_try\");\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -2492,6 +2492,6 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "\r\n" + ";\r\n" + "m = myXML.*;\r\n", - false); + false); } } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileDecompileTest.java index 36d892788..0bc1b4104 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileDecompileTest.java @@ -54,7 +54,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in catch\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -69,7 +69,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"catched exception: \" + e.message);\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -90,7 +90,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in catch\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -107,7 +107,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "}\r\n" + "return 2;\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -137,7 +137,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -160,7 +160,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "{\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -197,7 +197,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "a++;\r\n" + "}\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -218,7 +218,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "a++;\r\n" + "}\r\n" + "return \"OK\";\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -244,7 +244,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"a=\" + a);\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -269,7 +269,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "i++;\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -299,7 +299,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "i++;\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -322,7 +322,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in catch\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -344,7 +344,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"a=\" + a);\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -370,7 +370,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -412,7 +412,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -441,7 +441,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in catch1c\");\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -478,7 +478,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "a++;\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -501,7 +501,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "trace(\"after\");\r\n" + "return -1;\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -524,7 +524,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -546,7 +546,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"after try\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -565,7 +565,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in finally\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -587,7 +587,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "return \"hu\" + str;\r\n" + "}\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -617,7 +617,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"after\");\r\n" + "i++;\r\n" + "}\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -647,7 +647,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"after\");\r\n" + "i++;\r\n" + "}\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -670,7 +670,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in finally\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -685,7 +685,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in finally\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -717,7 +717,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "trace(\"after\");\r\n" + "return \"RETFINAL\";\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -753,7 +753,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "trace(\"after\");\r\n" + "return \"RETEXIT\";\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -785,7 +785,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in finally1\");\r\n" + "}\r\n" + "return \"RETFINAL\";\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -837,7 +837,7 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "}\r\n" + "trace(\"after0\");\r\n" + "return \"RETFINAL\";\r\n", - false); + false); } @Test(dataProvider = "swfNamesProvider") @@ -862,6 +862,6 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi + "trace(\"in finally\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileSwfToolsDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileSwfToolsDecompileTest.java index 6df341f4a..2722d7350 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileSwfToolsDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3CrossCompileSwfToolsDecompileTest.java @@ -44,7 +44,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"in catch\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -60,7 +60,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"catched exception: \" + _loc1_.message);\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -81,7 +81,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"in catch\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -98,7 +98,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "return 2;\r\n", - false); + false); } @Test @@ -128,7 +128,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -151,7 +151,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "{\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -188,7 +188,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "_loc1_++;\r\n" + "}\r\n", - false); + false); } @Test @@ -209,7 +209,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "return \"OK\";\r\n", - false); + false); } @Test @@ -235,7 +235,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -261,7 +261,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "_loc1_++;\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -290,7 +290,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "_loc1_++;\r\n" + "}\r\n" + "trace(\"end\");\r\n", - false); + false); } @Test @@ -313,7 +313,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"in catch\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -335,7 +335,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -361,7 +361,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -403,7 +403,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -432,7 +432,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"in catch1c\");\r\n" + "}\r\n" + "}\r\n", - false); + false); } @Test @@ -469,7 +469,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "_loc1_++;\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -492,7 +492,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "trace(\"after\");\r\n" + "return -1;\r\n", - false); + false); } @Test @@ -515,7 +515,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -541,7 +541,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"after try\");\r\n" + "}\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -565,7 +565,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "trace(\"in finally\");\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -587,7 +587,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "return \"hu\" + _loc1_;\r\n" + "}\r\n", - false); + false); } @Test @@ -623,7 +623,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"after\");\r\n" + "_loc1_++;\r\n" + "}\r\n", - false); + false); } @Test @@ -653,7 +653,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"after\");\r\n" + "_loc1_++;\r\n" + "}\r\n", - false); + false); } @Test @@ -681,7 +681,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "trace(\"in finally\");\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -698,7 +698,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "trace(\"in finally\");\r\n" + "trace(\"after\");\r\n", - false); + false); } @Test @@ -736,7 +736,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"in finally\");\r\n" + "trace(\"after\");\r\n" + "return \"RETFINAL\";\r\n", - false); + false); } @Test @@ -771,7 +771,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "trace(\"after\");\r\n" + "return \"RETEXIT\";\r\n", - false); + false); } @Test @@ -812,7 +812,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "trace(\"in finally1\");\r\n" + "return \"RETFINAL\";\r\n", - false); + false); } @Test @@ -879,7 +879,7 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "trace(\"in finally0\");\r\n" + "trace(\"after0\");\r\n" + "return \"RETFINAL\";\r\n", - false); + false); } @Test @@ -910,6 +910,6 @@ public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript + "}\r\n" + "trace(\"in finally\");\r\n" + "trace(\"after\");\r\n", - false); + false); } } 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 70fc7a03f..13dffa12b 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 7f0cbbd96..5995734bf 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 a07bfb6c5..d09e272f0 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as @@ -147,6 +147,7 @@ package TestImports2; TestInitializer; TestRegexpHilight; + TestScriptInitializer; TestPropertyCoerce; TestUnaryMinus; @@ -170,6 +171,8 @@ package { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point + + new TestScriptInitializer(); } } diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestScriptInitializer.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestScriptInitializer.as new file mode 100644 index 000000000..90e892ccf --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestScriptInitializer.as @@ -0,0 +1,61 @@ + +package tests_classes +{ + public class TestScriptInitializer + { + private static var sa:int = 5; + + if (Math.random() * 10 >= 5) { + sa += 100; + } else { + sa += 200; + } + + private static const sc:int = Math.floor(Math.random() * 50) + sa + x; + + private static var sb:int = sa + 20; + if (sb > 100) { + sb += 10; + } else { + sb += 20; + } + + private static var sv:int; + + for each (sv in [1,3,5]) + { + trace(sv); + } + + public function test() : void { + const x:int = 5; + } + } + //TestImports; +} + +var x:int = Math.random() * 100; + +var a:int = 5; +if (Math.random() * 10 >= 5) { + a += 100; +} else { + a += 200; +} + +const c:int = Math.floor(Math.random() * 50) + a; + +var b:int = a + 20; +if (b > 100) { + b += 10; +} else { + b += 20; +} + +var v:int; + +for each (v in [1,3,5]) +{ + trace(v); +} + diff --git a/libsrc/ffdec_lib/testdata/compound/bin/compound.abc b/libsrc/ffdec_lib/testdata/compound/bin/compound.abc new file mode 100644 index 000000000..3c6be341d Binary files /dev/null and b/libsrc/ffdec_lib/testdata/compound/bin/compound.abc differ diff --git a/libsrc/ffdec_lib/testdata/compound/bin/compound.cpp b/libsrc/ffdec_lib/testdata/compound/bin/compound.cpp new file mode 100644 index 000000000..86b8f638b --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/bin/compound.cpp @@ -0,0 +1,74 @@ +const int compound_abc_length = 1097; +const int compound_abc_method_count = 0; +const int compound_abc_class_count = 6; +const int compound_abc_script_count = 2; +const unsigned char compound_abc_data[1097] = { +0x10, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x1c, 0x06, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00, +0x06, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x03, 0x69, 0x6e, 0x74, 0x12, 0x5f, 0x5f, 0x41, 0x53, +0x33, 0x5f, 0x5f, 0x2e, 0x76, 0x65, 0x63, 0x3a, 0x56, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x0b, 0x5f, +0x5f, 0x41, 0x53, 0x33, 0x5f, 0x5f, 0x2e, 0x76, 0x65, 0x63, 0x06, 0x56, 0x65, 0x63, 0x74, 0x6f, +0x72, 0x03, 0x4e, 0x61, 0x4e, 0x08, 0x49, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x79, 0x09, 0x75, +0x6e, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x03, 0x41, 0x53, 0x33, 0x21, 0x68, 0x74, 0x74, +0x70, 0x3a, 0x2f, 0x2f, 0x61, 0x64, 0x6f, 0x62, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, 0x53, +0x33, 0x2f, 0x32, 0x30, 0x30, 0x36, 0x2f, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69, 0x6e, 0x0d, 0x6d, +0x79, 0x70, 0x6b, 0x67, 0x3a, 0x4d, 0x79, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x04, 0x76, 0x6f, 0x69, +0x64, 0x04, 0x74, 0x65, 0x73, 0x74, 0x05, 0x6d, 0x79, 0x70, 0x6b, 0x67, 0x07, 0x4d, 0x79, 0x43, +0x6c, 0x61, 0x73, 0x73, 0x0e, 0x6d, 0x79, 0x70, 0x6b, 0x67, 0x3a, 0x4d, 0x79, 0x43, 0x6c, 0x61, +0x73, 0x73, 0x32, 0x08, 0x4d, 0x79, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x32, 0x05, 0x74, 0x72, 0x61, +0x63, 0x65, 0x01, 0x78, 0x01, 0x61, 0x01, 0x62, 0x06, 0x6d, 0x79, 0x70, 0x6b, 0x67, 0x32, 0x0d, +0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x75, 0x6e, 0x64, 0x2e, 0x61, 0x73, 0x24, 0x31, 0x01, 0x79, 0x01, +0x63, 0x14, 0x05, 0x01, 0x16, 0x02, 0x18, 0x01, 0x05, 0x03, 0x18, 0x03, 0x05, 0x04, 0x18, 0x04, +0x05, 0x05, 0x16, 0x06, 0x18, 0x05, 0x08, 0x0c, 0x05, 0x0d, 0x16, 0x10, 0x18, 0x0d, 0x05, 0x12, +0x18, 0x12, 0x17, 0x10, 0x17, 0x18, 0x05, 0x19, 0x03, 0x01, 0x02, 0x01, 0x09, 0x1d, 0x07, 0x02, +0x01, 0x07, 0x02, 0x03, 0x07, 0x02, 0x04, 0x07, 0x09, 0x07, 0x09, 0x01, 0x01, 0x09, 0x03, 0x01, +0x09, 0x04, 0x01, 0x09, 0x07, 0x02, 0x09, 0x08, 0x01, 0x07, 0x02, 0x08, 0x09, 0x09, 0x01, 0x07, +0x02, 0x09, 0x09, 0x0a, 0x01, 0x07, 0x02, 0x0a, 0x07, 0x02, 0x0b, 0x07, 0x02, 0x0e, 0x07, 0x02, +0x0f, 0x07, 0x0d, 0x11, 0x07, 0x0d, 0x13, 0x07, 0x02, 0x14, 0x07, 0x11, 0x15, 0x07, 0x11, 0x16, +0x07, 0x11, 0x17, 0x07, 0x12, 0x15, 0x07, 0x12, 0x16, 0x07, 0x12, 0x17, 0x07, 0x13, 0x1a, 0x07, +0x13, 0x1b, 0x11, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, +0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, +0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, +0x00, 0x10, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 0x02, 0x00, +0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x06, 0x01, 0x00, 0x09, 0x03, 0x00, 0x01, +0x00, 0x02, 0x01, 0x09, 0x05, 0x00, 0x03, 0x00, 0x03, 0x01, 0x09, 0x07, 0x00, 0x05, 0x00, 0x04, +0x01, 0x09, 0x0a, 0x00, 0x07, 0x00, 0x12, 0x01, 0x09, 0x0e, 0x00, 0x0c, 0x01, 0x11, 0x01, 0x02, +0x0b, 0x13, 0x01, 0x09, 0x10, 0x00, 0x0f, 0x01, 0x11, 0x01, 0x02, 0x0e, 0x00, 0x00, 0x02, 0x00, +0x04, 0x00, 0x06, 0x00, 0x0a, 0x00, 0x0d, 0x00, 0x02, 0x10, 0x0b, 0x14, 0x01, 0x01, 0x09, 0x15, +0x00, 0x01, 0x03, 0x00, 0x16, 0x00, 0x02, 0x03, 0x00, 0x17, 0x00, 0x03, 0x03, 0x00, 0x18, 0x00, +0x04, 0x03, 0x00, 0x19, 0x00, 0x05, 0x03, 0x00, 0x1a, 0x00, 0x06, 0x03, 0x00, 0x12, 0x04, 0x07, +0x04, 0x13, 0x04, 0x08, 0x05, 0x1b, 0x00, 0x09, 0x03, 0x00, 0x1c, 0x00, 0x0a, 0x03, 0x00, 0x08, +0x08, 0x0f, 0x06, 0x00, 0x00, 0x0b, 0x08, 0x01, 0x04, 0x00, 0x00, 0x02, 0x04, 0x00, 0x01, 0x03, +0x04, 0x00, 0x02, 0x04, 0x04, 0x00, 0x03, 0x0a, 0x06, 0x00, 0x02, 0x01, 0x06, 0x0c, 0x06, 0x00, +0x02, 0x02, 0x06, 0x0e, 0x06, 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0xd0, +0x30, 0x47, 0x00, 0x00, 0x01, 0x01, 0x01, 0x03, 0x04, 0x03, 0xd0, 0x30, 0x47, 0x00, 0x00, 0x02, +0x01, 0x01, 0x03, 0x04, 0x03, 0xd0, 0x30, 0x47, 0x00, 0x00, 0x03, 0x01, 0x01, 0x04, 0x05, 0x06, +0xd0, 0x30, 0xd0, 0x49, 0x00, 0x47, 0x00, 0x00, 0x04, 0x01, 0x01, 0x03, 0x04, 0x03, 0xd0, 0x30, +0x47, 0x00, 0x00, 0x05, 0x01, 0x01, 0x04, 0x05, 0x06, 0xd0, 0x30, 0xd0, 0x49, 0x00, 0x47, 0x00, +0x00, 0x06, 0x01, 0x01, 0x03, 0x04, 0x03, 0xd0, 0x30, 0x47, 0x00, 0x00, 0x07, 0x01, 0x01, 0x04, +0x05, 0x06, 0xd0, 0x30, 0xd0, 0x49, 0x00, 0x47, 0x00, 0x00, 0x08, 0x03, 0x01, 0x01, 0x03, 0x51, +0xd0, 0x30, 0x5d, 0x05, 0x20, 0x58, 0x00, 0x68, 0x01, 0x5d, 0x06, 0x5d, 0x01, 0x66, 0x01, 0x30, +0x5d, 0x01, 0x66, 0x01, 0x58, 0x01, 0x1d, 0x68, 0x02, 0x5d, 0x07, 0x5d, 0x01, 0x66, 0x01, 0x30, +0x5d, 0x01, 0x66, 0x01, 0x58, 0x02, 0x1d, 0x68, 0x03, 0x5d, 0x08, 0x5d, 0x01, 0x66, 0x01, 0x30, +0x5d, 0x01, 0x66, 0x01, 0x58, 0x03, 0x1d, 0x68, 0x04, 0x5d, 0x09, 0x24, 0x00, 0x24, 0x00, 0xa3, +0x68, 0x0a, 0x5d, 0x0b, 0x24, 0x01, 0x24, 0x00, 0xa3, 0x68, 0x0c, 0x5d, 0x0d, 0x21, 0x68, 0x0e, +0x47, 0x00, 0x00, 0x09, 0x01, 0x02, 0x01, 0x02, 0x03, 0xd0, 0x30, 0x47, 0x00, 0x00, 0x0a, 0x01, +0x01, 0x03, 0x04, 0x03, 0xd0, 0x30, 0x47, 0x00, 0x00, 0x0b, 0x01, 0x01, 0x04, 0x05, 0x03, 0xd0, +0x30, 0x47, 0x00, 0x00, 0x0c, 0x01, 0x01, 0x04, 0x05, 0x06, 0xd0, 0x30, 0xd0, 0x49, 0x00, 0x47, +0x00, 0x00, 0x0d, 0x01, 0x01, 0x03, 0x04, 0x03, 0xd0, 0x30, 0x47, 0x00, 0x00, 0x0e, 0x01, 0x01, +0x04, 0x05, 0x03, 0xd0, 0x30, 0x47, 0x00, 0x00, 0x0f, 0x01, 0x01, 0x04, 0x05, 0x06, 0xd0, 0x30, +0xd0, 0x49, 0x00, 0x47, 0x00, 0x00, 0x10, 0x02, 0x03, 0x01, 0x03, 0xda, 0x01, 0xd0, 0x30, 0x65, +0x00, 0x5d, 0x01, 0x66, 0x01, 0x30, 0x5d, 0x01, 0x66, 0x01, 0x58, 0x04, 0x1d, 0x68, 0x12, 0x65, +0x00, 0x5d, 0x01, 0x66, 0x01, 0x30, 0x5d, 0x01, 0x66, 0x01, 0x58, 0x05, 0x1d, 0x68, 0x13, 0x24, +0x07, 0x64, 0x2b, 0x6d, 0x01, 0x24, 0x01, 0x64, 0x2b, 0x6d, 0x02, 0x64, 0x6c, 0x01, 0x24, 0x05, +0x0f, 0x0e, 0x00, 0x00, 0x64, 0x6c, 0x02, 0x24, 0x64, 0xa0, 0x64, 0x2b, 0x6d, 0x02, 0x10, 0x0b, +0x00, 0x00, 0x64, 0x6c, 0x02, 0x25, 0xc8, 0x01, 0xa0, 0x64, 0x2b, 0x6d, 0x02, 0x64, 0x6c, 0x02, +0x24, 0x0a, 0xa0, 0x64, 0x2b, 0x6d, 0x03, 0x24, 0x07, 0x64, 0x2b, 0x6d, 0x04, 0x24, 0x01, 0x64, +0x2b, 0x6d, 0x05, 0x64, 0x6c, 0x04, 0x24, 0x05, 0x0f, 0x0e, 0x00, 0x00, 0x64, 0x6c, 0x05, 0x24, +0x64, 0xa0, 0x64, 0x2b, 0x6d, 0x05, 0x10, 0x0b, 0x00, 0x00, 0x64, 0x6c, 0x05, 0x25, 0xc8, 0x01, +0xa0, 0x64, 0x2b, 0x6d, 0x05, 0x64, 0x6c, 0x05, 0x24, 0x0a, 0xa0, 0x64, 0x2b, 0x6d, 0x06, 0x5d, +0x14, 0x24, 0x1d, 0x46, 0x14, 0x01, 0x82, 0xd5, 0x24, 0x01, 0x64, 0x2b, 0x6d, 0x09, 0x24, 0x01, +0x64, 0x2b, 0x6d, 0x0a, 0x64, 0x6c, 0x09, 0x24, 0x05, 0x0f, 0x15, 0x00, 0x00, 0x64, 0x6c, 0x0a, +0x24, 0x64, 0xa0, 0x2a, 0xd6, 0x64, 0x2b, 0x6d, 0x0a, 0xd2, 0x08, 0x02, 0x82, 0xd5, 0x10, 0x11, +0x00, 0x00, 0x64, 0x6c, 0x0a, 0x24, 0x64, 0xa0, 0x2a, 0xd6, 0x64, 0x2b, 0x6d, 0x0a, 0xd2, 0x08, +0x02, 0x82, 0xd5, 0xd1, 0x48, 0x08, 0x01, 0x00, 0x00 }; diff --git a/libsrc/ffdec_lib/testdata/compound/bin/compound.h b/libsrc/ffdec_lib/testdata/compound/bin/compound.h new file mode 100644 index 000000000..6ba8cdc8d --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/bin/compound.h @@ -0,0 +1,13 @@ +const int abcclass_Object = 0; +const int abcclass_Number = 1; +const int abcclass_int = 2; +const int abcclass___AS3___vec_Vector = 3; +const int abcclass_mypkg_MyClass = 4; +const int abcclass_mypkg_MyClass2 = 5; +const int abcpackage_compound_as = 0; +const int abcpackage_stubs_as = 1; +extern const int compound_abc_length; +extern const int compound_abc_method_count; +extern const int compound_abc_class_count; +extern const int compound_abc_script_count; +extern const unsigned char compound_abc_data[]; diff --git a/libsrc/ffdec_lib/testdata/compound/build_flex.bat b/libsrc/ffdec_lib/testdata/compound/build_flex.bat new file mode 100644 index 000000000..c21e6edda --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/build_flex.bat @@ -0,0 +1,2 @@ +java -cp c:\flex\lib\asc.jar macromedia.asc.embedding.ScriptCompiler -strict -builtin -outdir bin/ -out compound src/stubs.as src/compound.as>buildlog.flex.txt 2>&1 +rem call c:\flex\bin\mxmlc.bat -debug=true -output bin/compound.swf src/compound.as 1> buildlog.flex.txt 2>&1 diff --git a/libsrc/ffdec_lib/testdata/compound/src/Main.as b/libsrc/ffdec_lib/testdata/compound/src/Main.as new file mode 100644 index 000000000..25f855eb5 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/Main.as @@ -0,0 +1,27 @@ +package +{ + import flash.display.Sprite; + import flash.events.Event; + + /** + * ... + * @author Jindra + */ + public class Main extends Sprite + { + + public function Main() + { + if (stage) init(); + else addEventListener(Event.ADDED_TO_STAGE, init); + } + + private function init(e:Event = null):void + { + removeEventListener(Event.ADDED_TO_STAGE, init); + // entry point + } + + } + +} \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/compound/src/Number.as b/libsrc/ffdec_lib/testdata/compound/src/Number.as new file mode 100644 index 000000000..2982227d1 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/Number.as @@ -0,0 +1,4 @@ +package { + public class Number { + } +} diff --git a/libsrc/ffdec_lib/testdata/compound/src/Object.as b/libsrc/ffdec_lib/testdata/compound/src/Object.as new file mode 100644 index 000000000..66e32ec59 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/Object.as @@ -0,0 +1,6 @@ +package +{ + public class Object + { + } +} diff --git a/libsrc/ffdec_lib/testdata/compound/src/Toplevel.as b/libsrc/ffdec_lib/testdata/compound/src/Toplevel.as new file mode 100644 index 000000000..379bc0240 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/Toplevel.as @@ -0,0 +1,9 @@ +package { + public namespace AS3 = "http://adobe.com/AS3/2006/builtin"; + + public const NaN: Number = 0 / 0; + + public const Infinity: Number = 1 / 0; + + public const undefined = void 0; +} diff --git a/libsrc/ffdec_lib/testdata/compound/src/__AS3__/vec/Vector.as b/libsrc/ffdec_lib/testdata/compound/src/__AS3__/vec/Vector.as new file mode 100644 index 000000000..645459d7a --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/__AS3__/vec/Vector.as @@ -0,0 +1,5 @@ +package __AS3__.vec { + + public class Vector { + } +} diff --git a/libsrc/ffdec_lib/testdata/compound/src/compound.as b/libsrc/ffdec_lib/testdata/compound/src/compound.as new file mode 100644 index 000000000..192c01c17 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/compound.as @@ -0,0 +1,43 @@ +package { + public function trace(s:int) { + //print something + } +} + +package mypkg { + var x:int = 7; + var a:int = 1; + if (x >= 5) { + a += 100; + } else { + a += 200; + } + var b:int = a + 10; +} + +package mypkg2 { + var x:int = 7; + var a:int = 1; + if (x >= 5) { + a += 100; + } else { + a += 200; + } + var b:int = a + 10; +} + +package mypkg3 { + trace(29); +} + +include "mypkg/MyClass.as" +include "mypkg/MyClass2.as" + +var y:int = 1; +var c:int = 1; +if (y >= 5) { + c += 100; +} else { + c += 100; +} + diff --git a/libsrc/ffdec_lib/testdata/compound/src/int.as b/libsrc/ffdec_lib/testdata/compound/src/int.as new file mode 100644 index 000000000..8fd30a041 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/int.as @@ -0,0 +1,4 @@ +package { + public class int { + } +} diff --git a/libsrc/ffdec_lib/testdata/compound/src/mypkg/MyClass.as b/libsrc/ffdec_lib/testdata/compound/src/mypkg/MyClass.as new file mode 100644 index 000000000..0d99015df --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/mypkg/MyClass.as @@ -0,0 +1,10 @@ +package mypkg +{ + public class MyClass + { + public function test(): void + { + } + } + +} diff --git a/libsrc/ffdec_lib/testdata/compound/src/mypkg/MyClass2.as b/libsrc/ffdec_lib/testdata/compound/src/mypkg/MyClass2.as new file mode 100644 index 000000000..2b2cfa7d1 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/mypkg/MyClass2.as @@ -0,0 +1,10 @@ +package mypkg +{ + public class MyClass2 + { + public function test(): void + { + } + } + +} diff --git a/libsrc/ffdec_lib/testdata/compound/src/stubs.as b/libsrc/ffdec_lib/testdata/compound/src/stubs.as new file mode 100644 index 000000000..fe562d45e --- /dev/null +++ b/libsrc/ffdec_lib/testdata/compound/src/stubs.as @@ -0,0 +1,5 @@ +include "Object.as" +include "Number.as" +include "int.as" +include "__AS3__/vec/Vector.as" +include "TopLevel.as"