From 2cee8a73860e7cfe5f24494a951299e5bec34f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Wed, 8 Dec 2021 08:12:38 +0100 Subject: [PATCH] Fixed #1763 AS3 - function with activation - param assignment is not a declaration --- CHANGELOG.md | 1 + .../decompiler/flash/abc/avm2/AVM2Code.java | 95 +++++++++++-------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0a5087a6..a36c9a169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. - AS1/2 actioncontainers (like try) inside ifs - AS1/2 switch detection - [#1766] AS3 - direct editation - namespaces on global level without leading colon +- [#1763] AS3 - function with activation - param assignment is not a declaration ## [15.0.0] - 2021-11-29 ### Added 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 699cb8955..d3e26f2c7 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 @@ -248,6 +248,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.DXNSIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.DXNSLateIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXAttrIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXElemIns; +import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; 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; @@ -1862,7 +1863,7 @@ public class AVM2Code implements Cloneable { return assignment; } - private void injectDeclarations(List items, int minreg, DeclarationAVM2Item[] declaredRegisters, List declaredSlots, List declaredSlotsDec, List declaredProperties, List declaredPropsDec, ABC abc, MethodBody body) { + private void injectDeclarations(List paramNames, List items, int minreg, DeclarationAVM2Item[] declaredRegisters, List declaredSlots, List declaredSlotsDec, List declaredProperties, List declaredPropsDec, ABC abc, MethodBody body) { for (int i = 0; i < items.size(); i++) { GraphTargetItem currentItem = items.get(i); List itemsOnLine = new ArrayList<>(); @@ -1911,29 +1912,31 @@ public class AVM2Code implements Cloneable { if (sp.object instanceof FindPropertyAVM2Item) { if (sp.propertyName instanceof FullMultinameAVM2Item) { FullMultinameAVM2Item propName = (FullMultinameAVM2Item) sp.propertyName; - 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 (!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++; + } } } } + } else { + int idx = declaredProperties.indexOf(propName.resolvedMultinameName); + sp.setDeclaration(declaredPropsDec.get(idx)); } - } else { - int idx = declaredProperties.indexOf(propName.resolvedMultinameName); - sp.setDeclaration(declaredPropsDec.get(idx)); } } } @@ -1942,31 +1945,34 @@ public class AVM2Code implements Cloneable { SetSlotAVM2Item ssti = (SetSlotAVM2Item) subItem; if (ssti.scope instanceof NewActivationAVM2Item) { Slot sl = new Slot(ssti.scope, ssti.slotName); - if (!declaredSlots.contains(sl)) { - 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 (!paramNames.contains(sl.multiname.getName(abc.constants, new ArrayList<>(), true, false))) { + + if (!declaredSlots.contains(sl)) { + 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); + } } } - } - DeclarationAVM2Item d = new DeclarationAVM2Item(subItem, type); - ssti.setDeclaration(d); - declaredSlotsDec.add(d); - declaredSlots.add(sl); + DeclarationAVM2Item d = new DeclarationAVM2Item(subItem, type); + ssti.setDeclaration(d); + declaredSlotsDec.add(d); + declaredSlots.add(sl); + + if (subItem == currentItem) { + items.set(i, d); + } else { + d.showValue = false; + items.add(i, d); + i++; + } - if (subItem == currentItem) { - items.set(i, d); } else { - d.showValue = false; - items.add(i, d); - i++; + int idx = declaredSlots.indexOf(sl); + ssti.setDeclaration(declaredSlotsDec.get(idx)); } - - } else { - int idx = declaredSlots.indexOf(sl); - ssti.setDeclaration(declaredSlotsDec.get(idx)); } } } @@ -1975,7 +1981,7 @@ public class AVM2Code implements Cloneable { if (currentItem instanceof Block) { Block blk = (Block) currentItem; for (List sub : blk.getSubs()) { - injectDeclarations(sub, minreg, declaredRegisters, declaredSlots, declaredSlotsDec, declaredProperties, declaredPropsDec, abc, body); + injectDeclarations(paramNames, sub, minreg, declaredRegisters, declaredSlots, declaredSlotsDec, declaredProperties, declaredPropsDec, abc, body); } } } @@ -2121,7 +2127,12 @@ public class AVM2Code implements Cloneable { // //int minreg = abc.method_info.get(body.method_info).getMaxReservedReg() + 1; - injectDeclarations(list, 1, d, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), abc, body); + HashMap registerNames = body.getLocalRegNames(abc); + List paramNamesList = new ArrayList<>(); + 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); int lastPos = list.size() - 1; if (lastPos < 0) {