From 76724b9375f8790c311e8c955fdda0e379df0396 Mon Sep 17 00:00:00 2001 From: nename0 <26363498+nename0@users.noreply.github.com> Date: Sun, 21 Apr 2019 18:09:25 +0200 Subject: [PATCH] Fix access to protected members with super (#75) * fix access to protected members with super * prevent overridden function to be found before the overriding --- .../parser/script/AVM2SourceGenerator.java | 14 +++++++----- .../avm2/parser/script/PropertyAVM2Item.java | 22 ++++++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) 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 7f216b0c2..f716a4d9b 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 @@ -2516,18 +2516,20 @@ public class AVM2SourceGenerator implements SourceGenerator { } public static boolean searchPrototypeChain(List otherNs, int privateNs, int protectedNs, boolean instanceOnly, AbcIndexing abc, DottedChain pkg, String obj, String propertyName, Reference outName, Reference outNs, Reference outPropNs, Reference outPropNsKind, Reference outPropNsIndex, Reference outPropType, Reference outPropValue, Reference outPropValueAbc) { - for (int ns : otherNs) { - if (searchPrototypeChain(ns, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { - return true; - } - } - + // private and protected namespaces first so we find overriding functions before overridden functions if (searchPrototypeChain(privateNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { return true; } if (searchPrototypeChain(protectedNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { return true; } + + for (int ns : otherNs) { + if (searchPrototypeChain(ns, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { + return true; + } + } + return searchPrototypeChain(0, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java index 0f06f88d4..608fc09ef 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java @@ -249,7 +249,27 @@ public class PropertyAVM2Item extends AssignableAVM2Item { otherNs.add(n.getCpoolIndex(abcIndex)); } } - if (AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, false, abcIndex, ftn.getWithoutLast(), ftn.getLast(), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { + if ((object instanceof NameAVM2Item) && "super".equals(((NameAVM2Item) object).getVariableName())) + { + // super is special cause its static type is the super class, but it still allows access to protected members + // so for super to work we need to also allow the protected namespace of the super class + // however this namespace is in the ABC of the super class and not in abcIndex.getSelectedAbc() + AbcIndexing.ClassIndex ci = abcIndex.findClass(objType); + int superProtectedNs = ci.abc.instance_info.get(ci.index).protectedNS; + AbcIndexing.TraitIndex sp = abcIndex.findProperty(new AbcIndexing.PropertyDef(propertyName, objType, ci.abc, superProtectedNs), false, true); + if (sp != null) { + objType = sp.objType; + Namespace ns = sp.trait.getName(sp.abc).getNamespace(sp.abc.constants); + propIndex = constants.getMultinameId(Multiname.createQName(false, + constants.getStringId(propertyName, true), + constants.getNamespaceId(ns.kind, ns.getName(sp.abc.constants), sp.abc == abc ? abc.constants.getNamespaceSubIndex(sp.trait.getName(sp.abc).namespace_index) : 0, true)), true + ); + propType = sp.returnType; + propValue = sp.value; + propValueAbc = sp.abc; + } + } + if (propType == null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, false, abcIndex, ftn.getWithoutLast(), ftn.getLast(), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { objType = new TypeItem(outNs.getVal().addWithSuffix(outName.getVal())); propType = outPropType.getVal(); propIndex = constants.getMultinameId(Multiname.createQName(false,