diff --git a/CHANGELOG.md b/CHANGELOG.md index a4c19fc40..c61b17d65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. ### Added - Translator tool for easier localization +### Fixed +- [#1769] Missing some body trait variable declaration + ## [17.0.2] - 2022-11-22 ### Fixed - [#1882] Close button on the menu toolbar @@ -2512,6 +2515,8 @@ All notable changes to this project will be documented in this file. ### Added - Initial public release +[Unreleased]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.2...dev +[17.0.2]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.1...version17.0.2 [17.0.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version17.0.0...version17.0.1 [17.0.0]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.3.1...version17.0.0 [16.3.1]: https://github.com/jindrapetrik/jpexs-decompiler/compare/version16.3.0...version16.3.1 @@ -2643,6 +2648,7 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#1769]: https://www.free-decompiler.com/flash/issues/1769 [#1882]: https://www.free-decompiler.com/flash/issues/1882 [#1880]: https://www.free-decompiler.com/flash/issues/1880 [#1881]: https://www.free-decompiler.com/flash/issues/1881 @@ -2723,7 +2729,6 @@ All notable changes to this project will be documented in this file. [#1763]: https://www.free-decompiler.com/flash/issues/1763 [#1766]: https://www.free-decompiler.com/flash/issues/1766 [#1773]: https://www.free-decompiler.com/flash/issues/1773 -[#1769]: https://www.free-decompiler.com/flash/issues/1769 [#1750]: https://www.free-decompiler.com/flash/issues/1750 [#1485]: https://www.free-decompiler.com/flash/issues/1485 [#1681]: https://www.free-decompiler.com/flash/issues/1681 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 b5243368d..f24c527b9 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 @@ -253,16 +253,20 @@ import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.InitPropertyAVM2Item; 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.NumberValueAVM2Item; 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.StringAVM2Item; 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; @@ -296,7 +300,9 @@ import com.jpexs.decompiler.graph.ScopeStack; import com.jpexs.decompiler.graph.SimpleValue; import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.decompiler.graph.TypeItem; +import com.jpexs.decompiler.graph.model.FalseItem; import com.jpexs.decompiler.graph.model.ScriptEndItem; +import com.jpexs.decompiler.graph.model.TrueItem; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Reference; import com.jpexs.helpers.ReflectionTools; @@ -308,6 +314,8 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -1805,7 +1813,7 @@ public class AVM2Code implements Cloneable { public boolean equals(Object obj) { if (obj instanceof Slot) { Slot slot = (Slot) obj; - return (slot.scope.getThroughRegister() == scope.getThroughRegister()) + return (Objects.equals(slot.scope.getThroughRegister(), scope.getThroughRegister())) && (slot.multiname == multiname); } return false; @@ -1863,7 +1871,92 @@ public class AVM2Code implements Cloneable { return assignment; } - private void injectDeclarations(List paramNames, List items, int minreg, DeclarationAVM2Item[] declaredRegisters, List declaredSlots, List declaredSlotsDec, List declaredProperties, List declaredPropsDec, ABC abc, MethodBody body) { + private int slotListIndexOf(List list, String propertyName, ABC abc) { + int index = 0; + for (Slot s : list) { + if (propertyName.equals(abc.constants.getString(s.multiname.name_index))) { + return index; + } + index++; + } + return -1; + } + + private void injectDeclarations(int level, List paramNames, List items, int minreg, DeclarationAVM2Item[] declaredRegisters, List declaredSlots, List declaredSlotsDec, List declaredProperties, List declaredPropsDec, ABC abc, MethodBody body) { + //boolean hasActivation = abc.method_info.get(body.method_info).flagNeed_activation(); + Map traits = new LinkedHashMap<>(); + for (Trait t : body.traits.traits) { + if (t instanceof TraitSlotConst) { + TraitSlotConst tsc = (TraitSlotConst) t; + Multiname tratMultiname = abc.constants.getMultiname(tsc.name_index); + String bodyTraitName = tratMultiname.getName(abc.constants, new ArrayList<>(), true, true); + traits.put(bodyTraitName, tsc); + } + } + if (level == 0) { + Set beginDeclaredSlotsNames = new LinkedHashSet<>(); + + for (int i = 0; i < items.size(); i++) { + GraphTargetItem item = items.get(i); + String propNameStr = null; + GraphTargetItem value = null; + if (item instanceof SetSlotAVM2Item) { + SetSlotAVM2Item ss = (SetSlotAVM2Item) item; + propNameStr = ss.slotName.getName(abc.constants, new ArrayList<>(), true, true); + value = ss.value; + } else if (item instanceof SetPropertyAVM2Item) { + SetPropertyAVM2Item sp = (SetPropertyAVM2Item) item; + if (sp.object instanceof FindPropertyAVM2Item) { + if (sp.propertyName instanceof FullMultinameAVM2Item) { + FullMultinameAVM2Item propName = (FullMultinameAVM2Item) sp.propertyName; + propNameStr = propName.resolvedMultinameName; + value = sp.value; + } else { + break; + } + } else { + break; + } + } else { + break; + } + + value = value.getNotCoerced(); + if (!((value instanceof NumberValueAVM2Item) + || (value instanceof StringAVM2Item) + || (value instanceof TrueItem) + || (value instanceof FalseItem) + || (value instanceof UndefinedAVM2Item) + || (value instanceof NullAVM2Item) + || (value instanceof NewFunctionAVM2Item) + )) { + break; + } + + beginDeclaredSlotsNames.add(propNameStr); + } + + int pos = 0; + for (String traitName : traits.keySet()) { + if (!paramNames.contains(traitName)) { + if (!beginDeclaredSlotsNames.contains(traitName)) { + Slot sl = new Slot(new NewActivationAVM2Item(null, null), abc.constants.getMultiname(traits.get(traitName).name_index)); + TraitSlotConst tsc = (TraitSlotConst) traits.get(traitName); + GraphTargetItem type = PropertyAVM2Item.multinameToType(tsc.type_index, abc.constants); + DeclarationAVM2Item d = new DeclarationAVM2Item(new GetLexAVM2Item(null, null, sl.multiname, abc.constants), type); + declaredSlotsDec.add(d); + declaredSlots.add(sl); + + d.showValue = false; + items.add(pos, d); + pos++; + + declaredPropsDec.add(d); + declaredProperties.add(traitName); + } + } + } + } for (int i = 0; i < items.size(); i++) { GraphTargetItem currentItem = items.get(i); List itemsOnLine = new ArrayList<>(); @@ -1892,6 +1985,48 @@ public class AVM2Code implements Cloneable { } } + for (GraphTargetItem subItem : itemsOnLine) { + Multiname propertyMultiName; + String propertyName; + if (subItem instanceof GetPropertyAVM2Item) { + GetPropertyAVM2Item propItem = (GetPropertyAVM2Item) subItem; + if (propItem.object instanceof FindPropertyAVM2Item) { + propertyMultiName = abc.constants.getMultiname(((FullMultinameAVM2Item) propItem.propertyName).multinameIndex); + } else { + continue; + } + } else if (subItem instanceof GetLexAVM2Item) { + GetLexAVM2Item lex = (GetLexAVM2Item) subItem; + propertyMultiName = lex.propertyName; + } else { + continue; + } + propertyName = propertyMultiName.getName(abc.constants, new ArrayList<>(), true, true); + + if (traits.containsKey(propertyName)) { + Slot sl = new Slot(new NewActivationAVM2Item(null, null), propertyMultiName); + if (!paramNames.contains(propertyName)) { + + if (slotListIndexOf(declaredSlots, propertyName, abc) == -1) { + TraitSlotConst tsc = traits.get(propertyName); + GraphTargetItem type = PropertyAVM2Item.multinameToType(tsc.type_index, abc.constants); + DeclarationAVM2Item d = new DeclarationAVM2Item(subItem, type); + declaredSlotsDec.add(d); + declaredSlots.add(sl); + + if (subItem == currentItem) { + items.set(i, d); + } else { + d.showValue = false; + items.add(i, d); + i++; + } + + } + } + } + } + for (GraphTargetItem subItem : itemsOnLine) { if (subItem instanceof SetLocalAVM2Item) { SetLocalAVM2Item setLocal = (SetLocalAVM2Item) subItem; @@ -1914,23 +2049,19 @@ public class AVM2Code implements Cloneable { FullMultinameAVM2Item propName = (FullMultinameAVM2Item) sp.propertyName; if (!paramNames.contains(propName.resolvedMultinameName)) { if (!declaredProperties.contains(propName.resolvedMultinameName)) { - for (int t = 0; t < body.traits.traits.size(); t++) { - if (body.traits.traits.get(t).getName(abc).getName(abc.constants, new ArrayList(), true, false) - .equals(propName.resolvedMultinameName)) { - if (body.traits.traits.get(t) instanceof TraitSlotConst) { - GraphTargetItem type = PropertyAVM2Item.multinameToType(((TraitSlotConst) body.traits.traits.get(t)).type_index, abc.constants); - DeclarationAVM2Item d = new DeclarationAVM2Item(subItem, type); - sp.setDeclaration(d); - declaredPropsDec.add(d); - declaredProperties.add(propName.resolvedMultinameName); - if (subItem == currentItem) { - items.set(i, d); - } else { - d.showValue = false; - items.add(i, d); - i++; - } - } + if (traits.containsKey(propName.resolvedMultinameName)) { + TraitSlotConst tsc = traits.get(propName.resolvedMultinameName); + GraphTargetItem type = PropertyAVM2Item.multinameToType(tsc.type_index, abc.constants); + DeclarationAVM2Item d = new DeclarationAVM2Item(subItem, type); + sp.setDeclaration(d); + declaredPropsDec.add(d); + declaredProperties.add(propName.resolvedMultinameName); + if (subItem == currentItem) { + items.set(i, d); + } else { + d.showValue = false; + items.add(i, d); + i++; } } } else { @@ -1945,16 +2076,14 @@ public class AVM2Code implements Cloneable { SetSlotAVM2Item ssti = (SetSlotAVM2Item) subItem; if (ssti.scope instanceof NewActivationAVM2Item) { Slot sl = new Slot(ssti.scope, ssti.slotName); - if (!paramNames.contains(sl.multiname.getName(abc.constants, new ArrayList<>(), true, false))) { + String slotPropertyName = sl.multiname.getName(abc.constants, new ArrayList<>(), true, false); + if (!paramNames.contains(slotPropertyName)) { - if (!declaredSlots.contains(sl)) { + int index = slotListIndexOf(declaredSlots, slotPropertyName, abc); + if (index == -1) { GraphTargetItem type = TypeItem.UNBOUNDED; - for (int t = 0; t < body.traits.traits.size(); t++) { - if (body.traits.traits.get(t).getName(abc) == sl.multiname) { - if (body.traits.traits.get(t) instanceof TraitSlotConst) { - type = PropertyAVM2Item.multinameToType(((TraitSlotConst) body.traits.traits.get(t)).type_index, abc.constants); - } - } + if (traits.containsKey(slotPropertyName)) { + type = PropertyAVM2Item.multinameToType(traits.get(slotPropertyName).type_index, abc.constants); } DeclarationAVM2Item d = new DeclarationAVM2Item(subItem, type); ssti.setDeclaration(d); @@ -1970,8 +2099,7 @@ public class AVM2Code implements Cloneable { } } else { - int idx = declaredSlots.indexOf(sl); - ssti.setDeclaration(declaredSlotsDec.get(idx)); + ssti.setDeclaration(declaredSlotsDec.get(index)); } } } @@ -1981,10 +2109,30 @@ public class AVM2Code implements Cloneable { if (currentItem instanceof Block) { Block blk = (Block) currentItem; for (List sub : blk.getSubs()) { - injectDeclarations(paramNames, sub, minreg, declaredRegisters, declaredSlots, declaredSlotsDec, declaredProperties, declaredPropsDec, abc, body); + injectDeclarations(level + 1, paramNames, sub, minreg, declaredRegisters, declaredSlots, declaredSlotsDec, declaredProperties, declaredPropsDec, abc, body); } } } + + /*if (level == 0) { + int pos = 0; + for (String propertyName : traits.keySet()) { + if (!paramNames.contains(propertyName)) { + Slot sl = new Slot(new NewActivationAVM2Item(null, null), abc.constants.getMultiname(traits.get(propertyName).name_index)); + if (!declaredSlots.contains(sl) && !declaredProperties.contains(propertyName)) { + TraitSlotConst tsc = traits.get(propertyName); + GraphTargetItem type = PropertyAVM2Item.multinameToType(tsc.type_index, abc.constants); + DeclarationAVM2Item d = new DeclarationAVM2Item(new GetLexAVM2Item(null, null, sl.multiname, abc.constants), type); + declaredSlotsDec.add(d); + declaredSlots.add(sl); + + d.showValue = false; + items.add(pos, d); + pos++; + } + } + } + }*/ } public List toGraphTargetItems(boolean thisHasDefaultToPrimitive, ConvertData convertData, String path, int methodIndex, boolean isStatic, int scriptIndex, int classIndex, ABC abc, MethodBody body, HashMap localRegNames, ScopeStack scopeStack, int initializerType, List fullyQualifiedNames, List initTraits, int staticOperation, HashMap localRegAssigmentIps, HashMap> refs) throws InterruptedException { @@ -2132,7 +2280,7 @@ public class AVM2Code implements Cloneable { for (int ir = 0; ir < r; ir++) { paramNamesList.add(AVM2Item.localRegName(localRegNames, ir)); } - injectDeclarations(paramNamesList, list, 1, d, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), abc, body); + injectDeclarations(0, paramNamesList, list, 1, d, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), abc, body); int lastPos = list.size() - 1; if (lastPos < 0) { @@ -2455,19 +2603,19 @@ public class AVM2Code implements Cloneable { public int removeTraps(Trait trait, int methodInfo, MethodBody body, ABC abc, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException { SWFDecompilerPlugin.fireAvm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body); - try (Statistics s = new Statistics("AVM2DeobfuscatorGetSet")) { + try ( Statistics s = new Statistics("AVM2DeobfuscatorGetSet")) { new AVM2DeobfuscatorGetSet().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body); } - try (Statistics s = new Statistics("AVM2DeobfuscatorSimple")) { + try ( Statistics s = new Statistics("AVM2DeobfuscatorSimple")) { new AVM2DeobfuscatorSimpleOld().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body); } - try (Statistics s = new Statistics("AVM2DeobfuscatorRegisters")) { + try ( Statistics s = new Statistics("AVM2DeobfuscatorRegisters")) { new AVM2DeobfuscatorRegistersOld().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body); } - try (Statistics s = new Statistics("AVM2DeobfuscatorJumps")) { + try ( Statistics s = new Statistics("AVM2DeobfuscatorJumps")) { new AVM2DeobfuscatorJumps().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body); } - try (Statistics s = new Statistics("AVM2DeobfuscatorZeroJumpsNullPushes")) { + try ( Statistics s = new Statistics("AVM2DeobfuscatorZeroJumpsNullPushes")) { new AVM2DeobfuscatorZeroJumpsNullPushes().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body); } return 1; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index 0624f141f..5b44c8d8b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -51,9 +51,11 @@ import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ConstructAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FilteredCheckAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.FloatValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.GetSlotAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.HasNextAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.InAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item; @@ -62,16 +64,19 @@ 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.NextNameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NextValueAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.NumberValueAVM2Item; 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.StringAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ThrowAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.WithAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.WithEndAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.WithObjectAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ExceptionAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.FilterAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ForEachInAVM2Item; @@ -80,6 +85,9 @@ import com.jpexs.decompiler.flash.abc.avm2.model.clauses.TryAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.StrictEqAVM2Item; import com.jpexs.decompiler.flash.abc.types.ABCException; import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.flash.abc.types.Multiname; +import com.jpexs.decompiler.flash.abc.types.traits.Trait; +import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.graph.AbstractGraphTargetVisitor; import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.decompiler.graph.Graph; @@ -95,6 +103,7 @@ import com.jpexs.decompiler.graph.ScopeStack; import com.jpexs.decompiler.graph.StopPartKind; import com.jpexs.decompiler.graph.ThrowState; import com.jpexs.decompiler.graph.TranslateStack; +import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.AnyItem; import com.jpexs.decompiler.graph.model.BreakItem; import com.jpexs.decompiler.graph.model.CommaExpressionItem; @@ -107,6 +116,7 @@ import com.jpexs.decompiler.graph.model.LoopItem; import com.jpexs.decompiler.graph.model.NotItem; import com.jpexs.decompiler.graph.model.PushItem; import com.jpexs.decompiler.graph.model.SwitchItem; +import com.jpexs.decompiler.graph.model.TrueItem; import com.jpexs.decompiler.graph.model.WhileItem; import com.jpexs.helpers.Reference; import java.util.ArrayList; @@ -2039,10 +2049,10 @@ public class AVM2Graph extends Graph { } } } - } + } } } - } + } } List ret = list; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewActivationAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewActivationAVM2Item.java index f4f31e4b2..ab82ec4a7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewActivationAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewActivationAVM2Item.java @@ -27,6 +27,7 @@ import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.LocalData; import java.util.HashMap; import java.util.List; +import java.util.Objects; /** * @@ -59,4 +60,26 @@ public class NewActivationAVM2Item extends AVM2Item { public boolean hasReturnValue() { return true; } + + @Override + public int hashCode() { + int hash = 7; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + return true; + } + + } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java index cc7499796..7aef53534 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java @@ -68,7 +68,9 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As public void visit(GraphTargetVisitorInterface visitor) { visitor.visit(object); visitor.visit(propertyName); - visitor.visit(value); + if (value != null) { + visitor.visit(value); + } } public SetPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, GraphTargetItem propertyName, GraphTargetItem value) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java index 4fb1b6bc0..d17040182 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java @@ -52,6 +52,9 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign public void visit(GraphTargetVisitorInterface visitor) { visitor.visit(scope); visitor.visit(slotObject); + if (value != null) { + visitor.visit(value); + } } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java index dbdb4f5a4..b575b3821 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java @@ -185,7 +185,11 @@ public class DeclarationAVM2Item extends AVM2Item { } writer.append("var "); - return assignment.toString(writer, localData); + assignment.toString(writer, localData); + writer.append(":"); + + type.appendTry(writer, localData); + return writer; } @Override diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ABCStreamTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ABCStreamTest.java index 232c56894..079d3539e 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ABCStreamTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ABCStreamTest.java @@ -65,12 +65,10 @@ public class ABCStreamTest { @Test public void testU30() { for (long number : getTestNumbers(0, (1L << 30) - 1)) { - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ABCOutputStream aos = new ABCOutputStream(baos);) { + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream(); ABCOutputStream aos = new ABCOutputStream(baos);) { aos.writeU30(number); aos.close(); - try (MemoryInputStream mis = new MemoryInputStream(baos.toByteArray()); - ABCInputStream ais = new ABCInputStream(mis);) { + try ( MemoryInputStream mis = new MemoryInputStream(baos.toByteArray()); ABCInputStream ais = new ABCInputStream(mis);) { assertEquals(number, ais.readU30("test")); assertEquals(0, mis.available()); } @@ -83,12 +81,10 @@ public class ABCStreamTest { @Test public void testU32() { for (long number : getTestNumbers(0, (1L << 32) - 1)) { - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ABCOutputStream aos = new ABCOutputStream(baos);) { + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream(); ABCOutputStream aos = new ABCOutputStream(baos);) { aos.writeU32(number); aos.close(); - try (MemoryInputStream mis = new MemoryInputStream(baos.toByteArray()); - ABCInputStream ais = new ABCInputStream(mis);) { + try ( MemoryInputStream mis = new MemoryInputStream(baos.toByteArray()); ABCInputStream ais = new ABCInputStream(mis);) { assertEquals(number, ais.readU32("test")); assertEquals(0, mis.available()); } @@ -101,12 +97,10 @@ public class ABCStreamTest { @Test public void testS32() { for (long number : getTestNumbers(-(1L << 31), (1 << 31) - 1)) { - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ABCOutputStream aos = new ABCOutputStream(baos);) { + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream(); ABCOutputStream aos = new ABCOutputStream(baos);) { aos.writeS32(number); aos.close(); - try (MemoryInputStream mis = new MemoryInputStream(baos.toByteArray()); - ABCInputStream ais = new ABCInputStream(mis);) { + try ( MemoryInputStream mis = new MemoryInputStream(baos.toByteArray()); ABCInputStream ais = new ABCInputStream(mis);) { assertEquals(number, ais.readS32("test")); assertEquals(0, mis.available()); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java index ac8cfb42a..2f79b9452 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java @@ -438,7 +438,7 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { + "label_2:Jump label_3\n" + "label_3:Jump label_4\n" + "label_4:"; - ActionJump jump = new ActionJump(0, Utf8Helper.charsetName ); + ActionJump jump = new ActionJump(0, Utf8Helper.charsetName); jump.setAddress(9); jump.setJumpOffset(24 - 9 - 5); testAddActionNormal(actionsString, expectedResult, jump, 3); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java index 10eea8333..4666c6780 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java @@ -80,7 +80,7 @@ public class ActionScript3AssemblerTest extends ActionScriptTestBase { @Override public void setABC(ABC abc) { - } + } }); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java index ec9c09bda..e3b6f2aed 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java @@ -90,7 +90,7 @@ public class ActionScript3DeobfuscatorTest extends ActionScriptTestBase { @Override public void setABC(ABC abc) { - } + } }); MethodBody b = new MethodBody(abc, new Traits(), new byte[0], new ABCException[0]); AVM2Code code = ASM3Parser.parse(abc, new StringReader(str), null, b, new MethodInfo()); @@ -125,7 +125,7 @@ public class ActionScript3DeobfuscatorTest extends ActionScriptTestBase { @Override public void setABC(ABC abc) { - } + } }); ActionScript3Parser par = new ActionScript3Parser(abc, new ArrayList<>(), false); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java index 3459aea8e..8592aeb03 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java @@ -125,14 +125,14 @@ public class DirectEditingTest extends FileTestBase { try { asm.setActions(par.actionsFromString(as2, Utf8Helper.charsetName)); } catch (ActionParseException | CompilationException ex) { - fail("Unable to parse: " + asm.getSwf().getTitleOrShortFileName()+ "/" + asm.toString(), ex); + fail("Unable to parse: " + asm.getSwf().getTitleOrShortFileName() + "/" + asm.toString(), ex); } writer = new HighlightedTextWriter(new CodeFormatting(), false); asm.getActionScriptSource(writer, null); String as3 = writer.toString(); //as3 = asm.removePrefixAndSuffix(as3); if (!as3.equals(as2)) { - fail("ActionScript is different: " + asm.getSwf().getTitleOrShortFileName()+ "/" + asm.toString()); + fail("ActionScript is different: " + asm.getSwf().getTitleOrShortFileName() + "/" + asm.toString()); } asm.setModified(); } catch (InterruptedException | IOException | OutOfMemoryError | TranslateException | StackOverflowError ex) { @@ -142,7 +142,7 @@ public class DirectEditingTest extends FileTestBase { String nFilePath = filePath.substring(0, filePath.length() - 4); //remove .swf nFilePath += ".recompiled.swf"; - try (FileOutputStream fos = new FileOutputStream(nFilePath)) { + try ( FileOutputStream fos = new FileOutputStream(nFilePath)) { swf.saveTo(fos); } //TODO: try tu run it in debug flashplayer (?) diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java index ad9218393..37d6979b7 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java @@ -50,7 +50,7 @@ public class RecompileTest extends FileTestBase { public void testAS3InstructionParsing(String filePath) { try { Configuration._debugCopy.set(false); - try (FileInputStream fis = new FileInputStream(filePath)) { + try ( FileInputStream fis = new FileInputStream(filePath)) { SWF swf = new SWF(new BufferedInputStream(fis), false); for (ABCContainerTag abcTag : swf.getAbcList()) { ABC abc = abcTag.getABC(); @@ -69,7 +69,7 @@ public class RecompileTest extends FileTestBase { @Test(dataProvider = "provideFiles") public void testRecompile(String filePath) { try { - try (FileInputStream fis = new FileInputStream(filePath)) { + try ( FileInputStream fis = new FileInputStream(filePath)) { Configuration._debugCopy.set(true); SWF swf = new SWF(new BufferedInputStream(fis), false); swf.saveTo(new ByteArrayOutputStream()); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SWFStreamTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SWFStreamTest.java index d2789fef2..cf659983f 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SWFStreamTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SWFStreamTest.java @@ -54,10 +54,10 @@ public class SWFStreamTest { public void testFB() throws IOException { double f = 5.25; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { + try ( SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { sos.writeFB(20, f); } - try (SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { + try ( SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { assertTrue(Double.compare(f, sis.readFB(20, "test")) == 0); } } @@ -65,14 +65,14 @@ public class SWFStreamTest { @Test public void testUB() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { + try ( SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { sos.writeUB(5, 1); sos.writeUB(6, 2); sos.writeUB(7, 3); sos.writeUB(8, 4); sos.writeUB(9, 5); } - try (SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { + try ( SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { assertEquals(1, sis.readUB(5, "test")); assertEquals(2, sis.readUB(6, "test")); assertEquals(3, sis.readUB(7, "test")); @@ -84,14 +84,14 @@ public class SWFStreamTest { @Test public void testSB() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { + try ( SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { sos.writeSB(5, -1); sos.writeSB(6, 2); sos.writeSB(7, -3); sos.writeSB(8, 4); sos.writeSB(9, -5); } - try (SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { + try ( SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { assertEquals(-1, sis.readSB(5, "test")); assertEquals(2, sis.readSB(6, "test")); assertEquals(-3, sis.readSB(7, "test")); @@ -185,11 +185,11 @@ public class SWFStreamTest { public void testRECT() throws IOException { RECT rect; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { + try ( SWFOutputStream sos = new SWFOutputStream(baos, SWF.DEFAULT_VERSION, Utf8Helper.charsetName)) { rect = new RECT(-0x80000000, 0x7FFFFFFF, -0x80000000, 0x7FFFFFFF); sos.writeRECT(rect); } - try (SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { + try ( SWFInputStream sis = new SWFInputStream(null, baos.toByteArray())) { RECT readRECT = sis.readRECT("test"); assertEquals(readRECT.Xmin, -0x3FFFFFFF); assertEquals(readRECT.Xmax, 0x3FFFFFFF); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SwfXmlExportImportTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SwfXmlExportImportTest.java index 7a2c91e33..d2e7fb890 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SwfXmlExportImportTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/SwfXmlExportImportTest.java @@ -97,7 +97,7 @@ public class SwfXmlExportImportTest extends FileTestBase { new SwfXmlExporter().exportXml(swf, outFile); SWF swf2 = new SWF(); - try (FileInputStream fis = new FileInputStream(outFile)) { + try ( FileInputStream fis = new FileInputStream(outFile)) { new SwfXmlImporter().importSwf(swf2, fis); } 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 e501d315d..172ea0c2b 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 @@ -24,7 +24,8 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT @Test public void testDeclareReg() { - decompileMethod("assembled", "testDeclareReg", "with(other)\r\n" + decompileMethod("assembled", "testDeclareReg", "var other:XML;\r\n" + + "with(other)\r\n" + "{\r\n" + "trace(\"hey\");\r\n" + "}\r\n", @@ -155,8 +156,8 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT @Test public void testSetSlotDup() { - decompileMethod("assembled", "testSetSlotDup", "var _loc5_:int = 5;\r\n" - + "var myslot:int;\r\n" + decompileMethod("assembled", "testSetSlotDup", "var myslot:int;\r\n" + + "var _loc5_:int = 5;\r\n" + "myname.somemethod(\"okay\",myslot = _loc5_);\r\n" + "myname.start();\r\n", false); @@ -338,8 +339,9 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT @Test public void testTryDoWhile2() { - decompileMethod("assembled", "testTryDoWhile2", "trace(\"hello\");\r\n" - + "var _loc5_:* = Math.random();\r\n" + decompileMethod("assembled", "testTryDoWhile2", "var _loc5_:*;\r\n" + + "trace(\"hello\");\r\n" + + "_loc5_ = Math.random();\r\n" + "do\r\n" + "{\r\n" + "try\r\n" @@ -357,9 +359,12 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT @Test public void testTryWhile() { - decompileMethod("assembled", "testTryWhile", "try\r\n" + decompileMethod("assembled", "testTryWhile", "var a:String;\r\n" + + "var b:String;\r\n" + + "var c:String;\r\n" + + "try\r\n" + "{\r\n" - + "var c:String = \"aa\";\r\n" + + "c = \"aa\";\r\n" + "while(c)\r\n" + "{\r\n" + "if(b)\r\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 29e4e3be4..261ee0960 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 @@ -1066,9 +1066,10 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile decompileMethod("classic_air", "testInlineFunctions", "var first:String = \"value1\";\r\n" + "var traceParameter:Function = function(aParam:String):String\r\n" + "{\r\n" + + "var traceParam2:Function;\r\n" + "var second:String = \"value2\";\r\n" + "second = second + \"cc\";\r\n" - + "var traceParam2:Function = function(bParam:String):String\r\n" + + "traceParam2 = function(bParam:String):String\r\n" + "{\r\n" + "trace(bParam + \",\" + aParam);\r\n" + "return first + second + aParam + bParam;\r\n" @@ -1216,7 +1217,8 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile @Test public void testNamedAnonFunctions() { - decompileMethod("classic_air", "testNamedAnonFunctions", "var test:* = new (function():*\r\n" + decompileMethod("classic_air", "testNamedAnonFunctions", "var test:*;\r\n" + + "test = new (function():*\r\n" + "{\r\n" + "var testFunc:Function;\r\n" + "return testFunc = function(param1:*, param2:int, param3:Array):Boolean\r\n" @@ -1548,6 +1550,27 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile false); } + @Test + public void testUndefined() { + decompileMethod("classic_air", "testUndefined", "var i:int;\r\n" + + "var j:int;\r\n" + + "var c:int;\r\n" + + "var f:*;\r\n" + + "c = 5 + i;\r\n" + + "f = function():*\r\n" + + "{\r\n" + + "trace(c);\r\n" + + "trace(j);\r\n" + + "};\r\n" + + "while(i < 10)\r\n" + + "{\r\n" + + "trace(i);\r\n" + + "i++;\r\n" + + "}\r\n" + + "f();\r\n", + false); + } + @Test public void testUsagesTry() { decompileMethod("classic_air", "testUsagesTry", "var k:int = 5;\r\n" 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 fcaf0c30a..24fbda760 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 @@ -120,13 +120,16 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testCompoundAssignments() { - decompileMethod("classic", "testCompoundAssignments", "var b:* = [10,20,30];\r\n" - + "var a:int = 0;\r\n" + decompileMethod("classic", "testCompoundAssignments", "var b:*;\r\n" + + "var a:int;\r\n" + + "var t:MyTest;\r\n" + + "b = [10,20,30];\r\n" + + "a = 0;\r\n" + "trace(\"a += 5\");\r\n" + "a += 5;\r\n" + "trace(\"arr[call()] = arr[call()] + 2;\");\r\n" + "b[this.calc()] = b[this.calc()] + 2;\r\n" - + "var t:MyTest = new MyTest();\r\n" + + "t = new MyTest();\r\n" + "trace(\"t.attr *= 10\");\r\n" + "t.attr *= 10;\r\n" + "trace(\"attr -= 5\");\r\n" @@ -390,7 +393,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testFinallyZeroJump() { - decompileMethod("classic", "testFinallyZeroJump", "var str:String = param1;\r\n" + decompileMethod("classic", "testFinallyZeroJump", "var str:String;\r\n" + + "str = param1;\r\n" + "try\r\n" + "{\r\n" + "}\r\n" @@ -648,18 +652,24 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testForXml() { - decompileMethod("classic", "testForXml", "var c:int = 0;\r\n" + decompileMethod("classic", "testForXml", "var myXML:XML;\r\n" + + "var k:*;\r\n" + + "var len:int;\r\n" + + "var a:int;\r\n" + + "var b:int;\r\n" + + "var i:int;\r\n" + + "var c:int = 0;\r\n" + "var name:String = \"ahoj\";\r\n" - + "var myXML:XML = \r\n" + + "myXML = \r\n" + "\r\n" + "{name}\r\n" + "\r\n" + ";\r\n" - + "var k:* = null;\r\n" - + "var len:int = 5;\r\n" - + "var a:int = 5;\r\n" - + "var b:int = 6;\r\n" - + "for(var i:int = 0; i < len; k = myXML.book.(@isbn == \"12345\"))\r\n" + + "k = null;\r\n" + + "len = 5;\r\n" + + "a = 5;\r\n" + + "b = 6;\r\n" + + "for(i = 0; i < len; k = myXML.book.(@isbn == \"12345\"))\r\n" + "{\r\n" + "c = 1;\r\n" + "if(c == 2)\r\n" @@ -893,7 +903,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testIfFinally() { - decompileMethod("classic", "testIfFinally", "var a:int = Math.random();\r\n" + decompileMethod("classic", "testIfFinally", "var a:int;\r\n" + + "a = Math.random();\r\n" + "if(a == 5)\r\n" + "{\r\n" + "try\r\n" @@ -1062,10 +1073,11 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "first = \"value1\";\r\n" + "var traceParameter:Function = function(aParam:String):String\r\n" + "{\r\n" + + "var traceParam2:Function;\r\n" + "var second:String = null;\r\n" + "second = \"value2\";\r\n" + "second += \"cc\";\r\n" - + "var traceParam2:Function = function(bParam:String):String\r\n" + + "traceParam2 = function(bParam:String):String\r\n" + "{\r\n" + "trace(bParam + \",\" + aParam);\r\n" + "return first + second + aParam + bParam;\r\n" @@ -1213,7 +1225,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testNamedAnonFunctions() { - decompileMethod("classic", "testNamedAnonFunctions", "var test:* = new function testFunc(param1:*, param2:int, param3:Array):Boolean\r\n" + decompileMethod("classic", "testNamedAnonFunctions", "var test:*;\r\n" + + "test = new function testFunc(param1:*, param2:int, param3:Array):Boolean\r\n" + "{\r\n" + "return (param1 as TestClass2).attrib1 == 5;\r\n" + "};\r\n", @@ -1454,7 +1467,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testTryIf() { - decompileMethod("classic", "testTryIf", "var a:int = Math.random();\r\n" + decompileMethod("classic", "testTryIf", "var a:int;\r\n" + + "a = Math.random();\r\n" + "try\r\n" + "{\r\n" + "if(a > 5 && a < 50)\r\n" @@ -1500,13 +1514,17 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testTryReturn2() { - decompileMethod("classic", "testTryReturn2", "var c:Boolean = false;\r\n" + decompileMethod("classic", "testTryReturn2", "var a:Boolean;\r\n" + + "var b:Boolean;\r\n" + + "var d:Boolean;\r\n" + + "var e:Boolean;\r\n" + + "var c:Boolean = false;\r\n" + "trace(\"before\");\r\n" - + "var a:Boolean = true;\r\n" - + "var b:Boolean = false;\r\n" + + "a = true;\r\n" + + "b = false;\r\n" + "c = true;\r\n" - + "var d:Boolean = false;\r\n" - + "var e:Boolean = true;\r\n" + + "d = false;\r\n" + + "e = true;\r\n" + "try\r\n" + "{\r\n" + "if(a)\r\n" @@ -1541,9 +1559,32 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes false); } + @Test + public void testUndefined() { + decompileMethod("classic", "testUndefined", "var f:*;\r\n" + + "var i:int = 0;\r\n" + + "var j:int = 0;\r\n" + + "var c:int = 0;\r\n" + + "c = 5 + i;\r\n" + + "f = function():*\r\n" + + "{\r\n" + + "trace(c);\r\n" + + "trace(j);\r\n" + + "};\r\n" + + "while(i < 10)\r\n" + + "{\r\n" + + "trace(i);\r\n" + + "i++;\r\n" + + "}\r\n" + + "f();\r\n", + false); + } + @Test public void testUsagesTry() { - decompileMethod("classic", "testUsagesTry", "var k:int = 5;\r\n" + decompileMethod("classic", "testUsagesTry", "var a:Boolean;\r\n" + + "var b:Boolean;\r\n" + + "var k:int = 5;\r\n" + "switch(k)\r\n" + "{\r\n" + "case 0:\r\n" @@ -1552,8 +1593,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "case 1:\r\n" + "trace(\"2\");\r\n" + "}\r\n" - + "var a:Boolean = true;\r\n" - + "var b:Boolean = true;\r\n" + + "a = true;\r\n" + + "b = true;\r\n" + "try\r\n" + "{\r\n" + "if(b)\r\n" @@ -1673,8 +1714,10 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testWhileTry2() { - decompileMethod("classic", "testWhileTry2", "var j:* = undefined;\r\n" - + "for(var i:* = 0; i < 100; i++)\r\n" + decompileMethod("classic", "testWhileTry2", "var j:*;\r\n" + + "var i:*;\r\n" + + "j = undefined;\r\n" + + "for(i = 0; i < 100; i++)\r\n" + "{\r\n" + "try\r\n" + "{\r\n" @@ -1699,17 +1742,20 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testXml() { - decompileMethod("classic", "testXml", "var g:XML = null;\r\n" + decompileMethod("classic", "testXml", "var myXML:XML;\r\n" + + "var k:*;\r\n" + + "var all:String;\r\n" + + "var g:XML = null;\r\n" + "var testCdata:XML = null;\r\n" + "var testComment:XML = null;\r\n" + "var name:String = \"ahoj\";\r\n" - + "var myXML:XML = \r\n" + + "myXML = \r\n" + "\r\n" + "{name}\r\n" + "\r\n" + ";\r\n" - + "var k:* = myXML.@id;\r\n" - + "var all:String = myXML.@*.toXMLString();\r\n" + + "k = myXML.@id;\r\n" + + "all = myXML.@*.toXMLString();\r\n" + "k = myXML.book;\r\n" + "k = myXML.book.(@isbn == \"12345\");\r\n" + "g =