diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java index 4ee87bbb6..d8ffef868 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java @@ -78,7 +78,7 @@ public abstract class AVM2Item extends GraphTargetItem { } } - if (!empty) { + if (!empty && object != null) { if (object.getPrecedence() > PRECEDENCE_PRIMARY) { writer.append("("); object.toString(writer, localData); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitVectorAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitVectorAVM2Item.java index ceb97a0e9..5b1ba0650 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitVectorAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitVectorAVM2Item.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.avm2.parser.script.NamespaceItem; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; @@ -61,8 +62,8 @@ public class InitVectorAVM2Item extends AVM2Item { List openedNamespaces; - private int allNsSet(ABC abc) { - return NamespaceItem.getCpoolSetIndex(abc.constants, openedNamespaces); + private int allNsSet(AbcIndexing abc) throws CompilationException { + return NamespaceItem.getCpoolSetIndex(abc, openedNamespaces); } public InitVectorAVM2Item(AVM2Instruction ins, GraphTargetItem subtype, List arguments) { @@ -113,7 +114,7 @@ public class InitVectorAVM2Item extends AVM2Item { AVM2ConstantPool constants = abc.constants; List ret = toSourceMerge(localData, generator, ins(AVM2Instructions.FindPropertyStrict, constants.getMultinameId(Multiname.createMultiname(false, constants.getStringId("Vector", true), constants.getNamespaceSetId(new int[]{constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true)}, true)), true)), - ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultiname(false, constants.getStringId("Vector", true), allNsSet(abc)), true)), + ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultiname(false, constants.getStringId("Vector", true), allNsSet(g.abcIndex)), true)), subtype, ins(AVM2Instructions.ApplyType, 1), new IntegerValueAVM2Item(null, (long) arguments.size()), @@ -124,7 +125,7 @@ public class InitVectorAVM2Item extends AVM2Item { ins(AVM2Instructions.Dup), new IntegerValueAVM2Item(null, (long) i), arguments.get(i), - ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(constants, openedNamespaces)), true)) + ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(g.abcIndex, openedNamespaces)), true)) )); } return ret; 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 0ab552421..5f7e5dd4d 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 @@ -143,7 +143,7 @@ public class AVM2SourceGenerator implements SourceGenerator { AVM2ConstantPool constants = abcIndex.getSelectedAbc().constants; int[] nssa = new int[item.openedNamespaces.size()]; for (int i = 0; i < item.openedNamespaces.size(); i++) { - nssa[i] = item.openedNamespaces.get(i).getCpoolIndex(constants); + nssa[i] = item.openedNamespaces.get(i).getCpoolIndex(abcIndex); } int nsset = constants.getNamespaceSetId(nssa, true); @@ -317,7 +317,7 @@ public class AVM2SourceGenerator implements SourceGenerator { trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, xmlListReg))); trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, counterReg))); trueBody.addAll(toInsList(AssignableAVM2Item.getTemp(localData, this, tempVal1))); - trueBody.add(ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(constants, item.openedNamespaces)), true))); + trueBody.add(ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, NamespaceItem.getCpoolSetIndex(abcIndex, item.openedNamespaces)), true))); forBody.add(ins(AVM2Instructions.IfFalse, insToBytes(trueBody).length)); forBody.addAll(trueBody); forBody.add(ins(AVM2Instructions.PopScope)); @@ -1167,13 +1167,13 @@ public class AVM2SourceGenerator implements SourceGenerator { } ParsedSymbol s = null; - Trait[] it = generateTraitsPhase1(name, superName, false, localData, traitItems, instanceInfo.instance_traits, class_index); - Trait[] st = generateTraitsPhase1(name, superName, true, localData, traitItems, classInfo.static_traits, class_index); + Trait[] it = generateTraitsPhase1(importedClasses, openedNamespaces, name, superName, false, localData, traitItems, instanceInfo.instance_traits, class_index); + Trait[] st = generateTraitsPhase1(importedClasses, openedNamespaces, name, superName, true, localData, traitItems, classInfo.static_traits, class_index); generateTraitsPhase2(importedClasses, pkg, traitItems, it, openedNamespaces, localData); generateTraitsPhase2(importedClasses, pkg, traitItems, st, openedNamespaces, localData); abcIndex.refreshSelected(); - generateTraitsPhase3(initScope, isInterface, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it, new HashMap<>(), class_index); - generateTraitsPhase3(initScope, isInterface, name, superName, true, localData, traitItems, classInfo.static_traits, st, new HashMap<>(), class_index); + generateTraitsPhase3(importedClasses, initScope, isInterface, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it, new HashMap<>(), class_index); + generateTraitsPhase3(importedClasses, initScope, isInterface, name, superName, true, localData, traitItems, classInfo.static_traits, st, new HashMap<>(), class_index); int init; if (iinit == null || isInterface) { instanceInfo.iinit_index = init = method(false, 0, false, isInterface, new ArrayList<>(), pkg, false, new ArrayList<>(), initScope + 1, false, 0, isInterface ? null : name, extendsVal != null ? extendsVal.toString() : null, true, localData, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TypeItem.UNBOUNDED/*?? FIXME*/); @@ -1198,13 +1198,13 @@ public class AVM2SourceGenerator implements SourceGenerator { if (ti instanceof SlotAVM2Item) { val = ((SlotAVM2Item) ti).value; isStatic = ((SlotAVM2Item) ti).isStatic(); - ns = genNs(importedClasses, pkg, ((SlotAVM2Item) ti).customNamespace, ((SlotAVM2Item) ti).pkg == null ? 0 : ((SlotAVM2Item) ti).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((SlotAVM2Item) ti).line); + ns = genNs(importedClasses, pkg, ((SlotAVM2Item) ti).pkg, openedNamespaces, localData, ((SlotAVM2Item) ti).line); tname = ((SlotAVM2Item) ti).var; } if (ti instanceof ConstAVM2Item) { val = ((ConstAVM2Item) ti).value; isStatic = ((ConstAVM2Item) ti).isStatic(); - ns = genNs(importedClasses, pkg, ((ConstAVM2Item) ti).customNamespace, ((ConstAVM2Item) ti).pkg == null ? 0 : ((ConstAVM2Item) ti).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((ConstAVM2Item) ti).line); + ns = genNs(importedClasses, pkg, ((ConstAVM2Item) ti).pkg, openedNamespaces, localData, ((ConstAVM2Item) ti).line); tname = ((ConstAVM2Item) ti).var; isConst = true; } @@ -1847,47 +1847,9 @@ public class AVM2SourceGenerator implements SourceGenerator { return null; } - private int genNs(List importedClasses, DottedChain pkg, String custom, int namespace, List openedNamespaces, SourceGeneratorLocalData localData, int line) throws CompilationException { - if (custom != null) { - PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, abcIndex, openedNamespaces, new ArrayList<>()); - Reference value = new Reference<>(null); - Reference outAbc = new Reference<>(null); - - prop.resolve(localData, new Reference<>(null), new Reference<>(null), new Reference<>(0), value, outAbc); - boolean resolved = true; - if (value.getVal() == null) { - resolved = false; - } - if (!resolved) { - - DottedChain fullCustom = null; - for (DottedChain imp : importedClasses) { - if (imp.getLast().equals(custom)) { - fullCustom = imp; - break; - } - } - - /*List aas = new ArrayList<>(); - aas.add(abc); - aas.addAll(allABCs);*/ - AbcIndexing.TraitIndex ti = abcIndex.findScriptProperty(fullCustom); - - if (ti != null) { - if (ti.trait instanceof TraitSlotConst) { - if (((TraitSlotConst) ti.trait).isNamespace()) { - Namespace ns = ti.abc.constants.getNamespace(((TraitSlotConst) ti.trait).value_index); - return abcIndex.getSelectedAbc().constants.getNamespaceId(ns.kind, ns.getName(ti.abc.constants), 0, true); - } - } - } - - throw new CompilationException("Namespace not defined", line); - } - namespace = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE, - outAbc.getVal().constants.getNamespace(value.getVal().value_index).getName(outAbc.getVal().constants), 0, true); - } - return namespace; + private int genNs(List importedClasses, DottedChain pkg, NamespaceItem ns, List openedNamespaces, SourceGeneratorLocalData localData, int line) throws CompilationException { + ns.resolveCustomNs(abcIndex, importedClasses, pkg, openedNamespaces, localData); + return ns.getCpoolIndex(abcIndex); } public void generateTraitsPhase2(List importedClasses, DottedChain pkg, List items, Trait[] traits, List openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException { @@ -1896,17 +1858,17 @@ public class AVM2SourceGenerator implements SourceGenerator { if (traits[k] == null) { } else if (item instanceof InterfaceAVM2Item) { - traits[k].name_index = traitName(((InterfaceAVM2Item) item).pkg == null ? 0 : ((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((InterfaceAVM2Item) item).name); + traits[k].name_index = traitName(((InterfaceAVM2Item) item).pkg == null ? 0 : ((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex), ((InterfaceAVM2Item) item).name); } else if (item instanceof ClassAVM2Item) { - traits[k].name_index = traitName(((ClassAVM2Item) item).pkg == null ? 0 : ((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((ClassAVM2Item) item).className); + traits[k].name_index = traitName(((ClassAVM2Item) item).pkg == null ? 0 : ((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex), ((ClassAVM2Item) item).className); } else if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) { - traits[k].name_index = traitName(genNs(importedClasses, pkg, ((MethodAVM2Item) item).customNamespace, ((MethodAVM2Item) item).pkg == null ? 0 : ((MethodAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((MethodAVM2Item) item).line), ((MethodAVM2Item) item).functionName); + traits[k].name_index = traitName(genNs(importedClasses, pkg, ((MethodAVM2Item) item).pkg, openedNamespaces, localData, ((MethodAVM2Item) item).line), ((MethodAVM2Item) item).functionName); } else if (item instanceof FunctionAVM2Item) { - traits[k].name_index = traitName(((FunctionAVM2Item) item).pkg == null ? 0 : ((FunctionAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), ((FunctionAVM2Item) item).functionName); + traits[k].name_index = traitName(((FunctionAVM2Item) item).pkg == null ? 0 : ((FunctionAVM2Item) item).pkg.getCpoolIndex(abcIndex), ((FunctionAVM2Item) item).functionName); } else if (item instanceof ConstAVM2Item) { - traits[k].name_index = traitName(genNs(importedClasses, pkg, ((ConstAVM2Item) item).customNamespace, ((ConstAVM2Item) item).pkg == null ? 0 : ((ConstAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((ConstAVM2Item) item).line), ((ConstAVM2Item) item).var); + traits[k].name_index = traitName(genNs(importedClasses, pkg, ((ConstAVM2Item) item).pkg, openedNamespaces, localData, ((ConstAVM2Item) item).line), ((ConstAVM2Item) item).var); } else if (item instanceof SlotAVM2Item) { - traits[k].name_index = traitName(genNs(importedClasses, pkg, ((SlotAVM2Item) item).customNamespace, ((SlotAVM2Item) item).pkg == null ? 0 : ((SlotAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), openedNamespaces, localData, ((SlotAVM2Item) item).line), ((SlotAVM2Item) item).var); + traits[k].name_index = traitName(genNs(importedClasses, pkg, ((SlotAVM2Item) item).pkg, openedNamespaces, localData, ((SlotAVM2Item) item).line), ((SlotAVM2Item) item).var); } } @@ -1922,7 +1884,7 @@ public class AVM2SourceGenerator implements SourceGenerator { Multiname.createQName( false, abcIndex.getSelectedAbc().constants.getStringId(((ClassAVM2Item) item).className, true), - ((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants)), true); + ((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex)), true); if (((ClassAVM2Item) item).extendsOp != null) { instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp); @@ -1939,7 +1901,7 @@ public class AVM2SourceGenerator implements SourceGenerator { AVM2ConstantPool constants = abc.constants; InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass) traits[k]).class_info); instanceInfo.name_index = constants.getMultinameId(Multiname.createQName(false, constants.getStringId(((InterfaceAVM2Item) item).name, true), - ((InterfaceAVM2Item) item).pkg.getCpoolIndex(constants)), true); + ((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex)), true); instanceInfo.interfaces = new int[((InterfaceAVM2Item) item).superInterfaces.size()]; for (int i = 0; i < ((InterfaceAVM2Item) item).superInterfaces.size(); i++) { @@ -1984,7 +1946,8 @@ public class AVM2SourceGenerator implements SourceGenerator { return ret; } - public void generateTraitsPhase3(int methodInitScope, boolean isInterface, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Trait[] traits, Map initScopes, Reference class_index) throws AVM2ParseException, CompilationException { + public void generateTraitsPhase3(List importedClasses, int methodInitScope, boolean isInterface, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Trait[] traits, Map initScopes, Reference class_index) throws AVM2ParseException, CompilationException { + //Note: Names must be generated first before accesed in inner subs for (int k = 0; k < items.size(); k++) { GraphTargetItem item = items.get(k); @@ -1992,17 +1955,22 @@ public class AVM2SourceGenerator implements SourceGenerator { continue; } if (item instanceof InterfaceAVM2Item) { - generateClass(((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((InterfaceAVM2Item) item).pkg.name, localData, (InterfaceAVM2Item) item, class_index); + generateClass(((InterfaceAVM2Item) item).pkg.getCpoolIndex(abcIndex), abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((InterfaceAVM2Item) item).pkg.name, localData, (InterfaceAVM2Item) item, class_index); } if (item instanceof ClassAVM2Item) { - generateClass(((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants), abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((ClassAVM2Item) item).pkg.name, localData, (ClassAVM2Item) item, class_index); + generateClass(((ClassAVM2Item) item).pkg.getCpoolIndex(abcIndex), abcIndex.getSelectedAbc().class_info.get(((TraitClass) traits[k]).class_info), abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info), initScopes.get(traits[k]), ((ClassAVM2Item) item).pkg.name, localData, (ClassAVM2Item) item, class_index); } if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) { MethodAVM2Item mai = (MethodAVM2Item) item; if (mai.isStatic() != generateStatic) { continue; } + for (List ln : mai.allOpenedNamespaces) { + for (NamespaceItem n : ln) { + n.resolveCustomNs(abcIndex, importedClasses, localData.pkg, ln, localData); + } + } ((TraitMethodGetterSetter) traits[k]).method_info = method(mai.isStatic(), methodName(mai.outsidePackage, localData.pkg, mai.functionName, mai.pkg, className, mai.customNamespace), false, isInterface, new ArrayList<>(), localData.pkg, mai.needsActivation, mai.subvariables, methodInitScope + (mai.isStatic() ? 0 : 1), mai.hasRest, mai.line, className, superName, false, localData, mai.paramTypes, mai.paramNames, mai.paramValues, mai.body, mai.retType); } else if (item instanceof FunctionAVM2Item) { FunctionAVM2Item fai = (FunctionAVM2Item) item; @@ -2028,7 +1996,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } else if (ns != null) { switch (ns.kind) { case Namespace.KIND_PACKAGE_INTERNAL: - sb.append(pkg.toRawString()); + sb.append(pkg == null ? "" /*?*/ : pkg.toRawString()); break; case Namespace.KIND_PRIVATE: @@ -2047,7 +2015,7 @@ public class AVM2SourceGenerator implements SourceGenerator { return abcIndex.getSelectedAbc().constants.getStringId(sb.toString(), true); } - public Trait[] generateTraitsPhase1(String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Reference classIndex) throws AVM2ParseException, CompilationException { + public Trait[] generateTraitsPhase1(List importedClasses, List openedNamespaces, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Reference classIndex) throws AVM2ParseException, CompilationException { Trait[] traits = new Trait[items.size()]; int slot_id = 1; int disp_id = 3; //1 and 2 are for constructor @@ -2083,17 +2051,6 @@ public class AVM2SourceGenerator implements SourceGenerator { tc.class_info = classIndex.getVal(); abcIndex.getSelectedAbc().addClass(ci, ii, classIndex.getVal()); classIndex.setVal(classIndex.getVal() + 1); - //tc.class_info = abc.instance_info.size() - 1; - - /*instanceInfo.name_index = abc.getLastAbc().constants.addMultiname(new Multiname(Multiname.QNAME, abc.getLastAbc().constants.getStringId(((ClassAVM2Item) item).className, true), - abc.getLastAbc().constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.getLastAbc().constants.getStringId(pkg.packageName, true)), 0, true), 0, 0, new ArrayList())); - */ - - /*if (((ClassAVM2Item) item).extendsOp != null) { - instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp); - } else { - instanceInfo.super_index = abc.getLastAbc().constants.getMultinameId(new Multiname(Multiname.QNAME, str("Object"), namespace(Namespace.KIND_PACKAGE, ""), 0, 0, new ArrayList()), true); - }*/ tc.kindType = Trait.TRAIT_CLASS; // tc.name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className); tc.slot_id = slot_id++; @@ -2121,7 +2078,10 @@ public class AVM2SourceGenerator implements SourceGenerator { val = sai.value; type = sai.type; isStatic = sai.isStatic(); - namespace = sai.pkg == null ? 0 : sai.pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants); + if (sai.pkg != null) { + sai.pkg.resolveCustomNs(abcIndex, importedClasses, localData.pkg, openedNamespaces, localData); + } + namespace = sai.pkg == null ? 0 : sai.pkg.getCpoolIndex(abcIndex); metadata = generateMetadata(((SlotAVM2Item) item).metadata); } if (item instanceof ConstAVM2Item) { @@ -2132,7 +2092,10 @@ public class AVM2SourceGenerator implements SourceGenerator { var = cai.var; val = cai.value; type = cai.type; - namespace = cai.pkg == null ? 0 : cai.pkg.getCpoolIndex(abcIndex.getSelectedAbc().constants); + if (cai.pkg != null) { + cai.pkg.resolveCustomNs(abcIndex, importedClasses, localData.pkg, openedNamespaces, localData); + } + namespace = cai.pkg == null ? 0 : cai.pkg.getCpoolIndex(abcIndex); isNamespace = type.toString().equals("Namespace"); isStatic = cai.isStatic(); metadata = generateMetadata(((ConstAVM2Item) item).metadata); @@ -2161,7 +2124,6 @@ public class AVM2SourceGenerator implements SourceGenerator { } TraitMethodGetterSetter tmgs = new TraitMethodGetterSetter(); tmgs.kindType = (item instanceof GetterAVM2Item) ? Trait.TRAIT_GETTER : ((item instanceof SetterAVM2Item) ? Trait.TRAIT_SETTER : Trait.TRAIT_METHOD); - //tmgs.name_index = traitName(((MethodAVM2Item) item).namespace, ((MethodAVM2Item) item).functionName); tmgs.disp_id = mai.isStatic() ? disp_id++ : 0; //For a reason, there is disp_id only for static methods (or not?) if (mai.isFinal() || (className != null && mai.isStatic())) { tmgs.kindFlags |= Trait.ATTR_Final; @@ -2188,11 +2150,11 @@ public class AVM2SourceGenerator implements SourceGenerator { return traits; } - public ScriptInfo generateScriptInfo(SourceGeneratorLocalData localData, List commands, int classPos) throws AVM2ParseException, CompilationException { + public ScriptInfo generateScriptInfo(List> allOpenedNamespaces, SourceGeneratorLocalData localData, List commands, int classPos) throws AVM2ParseException, CompilationException { Reference class_index = new Reference<>(classPos); ScriptInfo si = new ScriptInfo(); localData.currentScript = si; - Trait[] traitArr = generateTraitsPhase1(null, null, true, localData, commands, si.traits, class_index); + Trait[] traitArr = generateTraitsPhase1(new ArrayList<>(), new ArrayList<>(), null, null, true, localData, commands, si.traits, class_index); generateTraitsPhase2(new ArrayList<>(), null/*FIXME*/, commands, traitArr, new ArrayList<>(), localData); abcIndex.refreshSelected(); @@ -2263,7 +2225,7 @@ public class AVM2SourceGenerator implements SourceGenerator { abc.addMethodBody(mb); si.init_index = mb.method_info; localData.pkg = DottedChain.EMPTY; - generateTraitsPhase3(1/*??*/, false, null, null, true, localData, commands, si.traits, traitArr, initScopes, class_index); + generateTraitsPhase3(new ArrayList<>(), 1/*??*/, false, null, null, true, localData, commands, si.traits, traitArr, initScopes, class_index); int maxSlotId = 0; for (int k = 0; k < si.traits.traits.size(); k++) { @@ -2351,7 +2313,13 @@ public class AVM2SourceGenerator implements SourceGenerator { return TypeItem.UNBOUNDED; } - public static boolean searchPrototypeChain(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) { + 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; + } + } + if (searchPrototypeChain(privateNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { return true; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java index f4e08ffca..fb7538540 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AbcIndexing.java @@ -576,4 +576,17 @@ public class AbcIndexing { public ABC getSelectedAbc() { return selectedAbc; } + + public DottedChain nsValueToName(String valueStr) { + for (ABC abc : abcs) { + DottedChain ret = abc.nsValueToName(valueStr); + if (!ret.isEmpty()) { + return ret; + } + } + if (parent != null) { + return parent.nsValueToName(valueStr); + } + return null; + } } 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 88753fe99..c47846fab 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 @@ -196,7 +196,7 @@ public class ActionScript3Parser { expectedType(SymbolType.PARENT_CLOSE); break; case PARENT_OPEN: - ret = new CallAVM2Item(lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); + ret = new CallAVM2Item(openedNamespaces, lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables)); break; case DESCENDANTS: s = lex(); @@ -468,7 +468,7 @@ public class ActionScript3Parser { private MethodAVM2Item method(List> allOpenedNamespaces, boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, String customAccess, Reference needsActivation, List importedClasses, boolean override, boolean isFinal, TypeItem thisType, List openedNamespaces, boolean isStatic, String functionName, boolean isMethod, List variables) throws IOException, AVM2ParseException { FunctionAVM2Item f = function(allOpenedNamespaces, metadata, pkg, isInterface, needsActivation, importedClasses, thisType, openedNamespaces, functionName, isMethod, variables); - return new MethodAVM2Item(outsidePackage, isPrivate, f.metadata, f.pkg, f.isInterface, customAccess, f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); + return new MethodAVM2Item(allOpenedNamespaces, outsidePackage, isPrivate, f.metadata, f.pkg, f.isInterface, customAccess, f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); } private FunctionAVM2Item function(List> allOpenedNamespaces, List>> metadata, NamespaceItem pkg, boolean isInterface, Reference needsActivation, List importedClasses, TypeItem thisType, List openedNamespaces, String functionName, boolean isMethod, List variables) throws IOException, AVM2ParseException { @@ -697,6 +697,10 @@ public class ActionScript3Parser { if (namespace == protectedNs && isStatic) { namespace = staticProtectedNs; } + if (namespace == null && customNs != null) { + //Special: it will be resolved later: + namespace = new NamespaceItem(customNs, Namespace.KIND_NAMESPACE); + } switch (s.type) { case FUNCTION: @@ -766,10 +770,10 @@ public class ActionScript3Parser { } } if (isGetter) { - GetterAVM2Item g = new GetterAVM2Item(outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + GetterAVM2Item g = new GetterAVM2Item(allOpenedNamespaces, outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = g; } else if (isSetter) { - SetterAVM2Item st = new SetterAVM2Item(outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + SetterAVM2Item st = new SetterAVM2Item(allOpenedNamespaces, outsidePackage, ft.isPrivate(), ft.metadata, ft.pkg, isInterface, customNs, ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = st; } else { t = ft; @@ -859,8 +863,8 @@ public class ActionScript3Parser { } } - private void scriptTraits(int scriptIndex, String scriptName, List traits) throws AVM2ParseException, IOException, CompilationException { - List> allOpenedNamespaces = new ArrayList<>(); + private void scriptTraits(List> allOpenedNamespaces, int scriptIndex, String scriptName, List traits) throws AVM2ParseException, IOException, CompilationException { + while (scriptTraitsBlock(allOpenedNamespaces, scriptIndex, scriptName, traits)) { //empty } @@ -902,7 +906,9 @@ public class ActionScript3Parser { allOpenedNamespaces.add(openedNamespaces); NamespaceItem emptyNs = new NamespaceItem("", Namespace.KIND_PACKAGE); openedNamespaces.add(emptyNs); - openedNamespaces.add(new NamespaceItem(AS3_NAMESPACE, Namespace.KIND_NAMESPACE)); + NamespaceItem as3Ns = new NamespaceItem(AS3_NAMESPACE, Namespace.KIND_NAMESPACE); + as3Ns.forceResolve(abcIndex); + openedNamespaces.add(as3Ns); for (List ln : allOpenedNamespaces) { if (publicNs != null && !ln.contains(publicNs)) { @@ -913,7 +919,7 @@ public class ActionScript3Parser { } } - List importedClasses = parseImports(openedNamespaces); + List importedClasses = parseImportsUsages(openedNamespaces); boolean isEmpty = true; @@ -2393,37 +2399,46 @@ public class ActionScript3Parser { private List constantPool; - private List parseImports(List openedNamespaces) throws IOException, AVM2ParseException { + private List parseImportsUsages(List openedNamespaces) throws IOException, AVM2ParseException { ParsedSymbol s; List importedClasses = new ArrayList<>(); s = lex(); - while (s.type == SymbolType.IMPORT) { + while (s.isType(SymbolType.IMPORT, SymbolType.USE)) { boolean all = false; + boolean isUse = s.type == SymbolType.USE; + if (isUse) { + expectedType(SymbolType.NAMESPACE); + } s = lex(); expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); - DottedChain imp = new DottedChain(); - imp = imp.add(s.value.toString()); + DottedChain fullName = new DottedChain(); + fullName = fullName.add(s.value.toString()); s = lex(); boolean isStar = false; while (s.type == SymbolType.DOT) { s = lex(); - if (s.type == SymbolType.MULTIPLY) { + if (s.type == SymbolType.MULTIPLY && !isUse) { isStar = true; s = lex(); break; } expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); - imp = imp.add(s.value.toString()); + fullName = fullName.add(s.value.toString()); s = lex(); } if (isStar) { - openedNamespaces.add(new NamespaceItem(imp, Namespace.KIND_PACKAGE)); + openedNamespaces.add(new NamespaceItem(fullName, Namespace.KIND_PACKAGE)); } else { - importedClasses.add(imp); + if (isUse) { + //Note: in this case, fullName attribute will be changed to real NS insude NamespaceItem + openedNamespaces.add(new NamespaceItem(fullName, Namespace.KIND_NAMESPACE)); + } else { + importedClasses.add(fullName); + } } expected(s, lexer.yyline(), SymbolType.SEMICOLON); @@ -2433,7 +2448,7 @@ public class ActionScript3Parser { return importedClasses; } - private List parseScript(int scriptIndex, String fileName) throws IOException, AVM2ParseException, CompilationException { + private List parseScript(List> allOpenedNamespaces, int scriptIndex, String fileName) throws IOException, AVM2ParseException, CompilationException { //int scriptPrivateNs; if (fileName.contains("/")) { @@ -2442,42 +2457,33 @@ public class ActionScript3Parser { if (fileName.contains("\\")) { fileName = fileName.substring(fileName.lastIndexOf('\\') + 1); } - /*String className = fileName; - if (className.endsWith(".as")) { - className = className.substring(0, className.length() - 3); - }*/ - /*openedNamespaces.add(scriptPrivateNs = abcIndex.getSelectedAbc().constants.addNamespace(Namespace.KIND_PRIVATE, 0)); //abc.getLastAbc().constants.getStringId(name + ":" + className, true) - - int publicNs; - openedNamespaces.add(publicNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, "", 0, true)); - */ List items = new ArrayList<>(); - scriptTraits(scriptIndex, fileName, items); - //FIXME traits(fileName, true, new ArrayList<>(), new Reference<>(false), new ArrayList<>(), new ArrayList<>(), scriptPrivateNs, 0, publicNs, 0, 0, openedNamespaces, null, null, false, items); + scriptTraits(allOpenedNamespaces, scriptIndex, fileName, items); return items; } - public List scriptTraitsFromString(String str, String fileName, int scriptIndex) throws AVM2ParseException, IOException, CompilationException { + public List scriptTraitsFromString(List> allOpenedNamespaces, String str, String fileName, int scriptIndex) throws AVM2ParseException, IOException, CompilationException { lexer = new ActionScriptLexer(str); - List ret = parseScript(scriptIndex, fileName); + List ret = parseScript(allOpenedNamespaces, scriptIndex, fileName); if (lexer.lex().type != SymbolType.EOF) { throw new AVM2ParseException("Parsing finisned before end of the file", lexer.yyline()); } return ret; } - public void addScriptFromTree(List items, boolean documentClass, int classPos) throws AVM2ParseException, CompilationException { + public void addScriptFromTree(List> allOpenedNamespaces, List items, boolean documentClass, int classPos) throws AVM2ParseException, CompilationException { AVM2SourceGenerator gen = new AVM2SourceGenerator(abcIndex); SourceGeneratorLocalData localData = new SourceGeneratorLocalData( new HashMap<>(), 0, Boolean.FALSE, 0); localData.documentClass = documentClass; - abcIndex.getSelectedAbc().script_info.add(gen.generateScriptInfo(localData, items, classPos)); + abcIndex.getSelectedAbc().script_info.add(gen.generateScriptInfo(allOpenedNamespaces, localData, items, classPos)); } public void addScript(String s, boolean documentClass, String fileName, int classPos, int scriptIndex) throws AVM2ParseException, IOException, CompilationException { - List traits = scriptTraitsFromString(s, fileName, scriptIndex); - addScriptFromTree(traits, documentClass, classPos); + List> allOpenedNamespaces = new ArrayList<>(); + List traits = scriptTraitsFromString(allOpenedNamespaces, s, fileName, scriptIndex); + addScriptFromTree(allOpenedNamespaces, traits, documentClass, classPos); } public ActionScript3Parser(ABC abc, List otherAbcs) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java index a3d4c0f97..131ad3852 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java @@ -45,9 +45,11 @@ public class CallAVM2Item extends AVM2Item { public List arguments; public int line; + public List openedNamespaces; - public CallAVM2Item(int line, GraphTargetItem name, List arguments) { + public CallAVM2Item(List openedNamespaces, int line, GraphTargetItem name, List arguments) { super(null, NOPRECEDENCE); + this.openedNamespaces = openedNamespaces; this.name = name; this.arguments = arguments; this.line = line; @@ -82,8 +84,13 @@ public class CallAVM2Item extends AVM2Item { Reference outPropType = new Reference<>(null); Reference outPropValue = new Reference<>(null); Reference outPropValueABC = new Reference<>(null); - - if (cname != null && AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueABC)) { + List otherNs = new ArrayList<>(); + for (NamespaceItem on : openedNamespaces) { + if (on.isResolved()) { + otherNs.add(on.getCpoolIndex(g.abcIndex)); + } + } + if (cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueABC)) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), n.line, "this", null, false, n.openedNamespaces); nobj.setRegNumber(0); obj = nobj; @@ -119,7 +126,14 @@ public class CallAVM2Item extends AVM2Item { Reference outPropValue = new Reference<>(null); Reference outPropValueAbc = new Reference<>(null); - if (cname != null && AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, prop.propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) { + List otherNs = new ArrayList<>(); + for (NamespaceItem n : openedNamespaces) { + if (n.isResolved()) { + otherNs.add(n.getCpoolIndex(g.abcIndex)); + } + } + + if (cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, true, g.abcIndex, pkgName, cname, prop.propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), 0, "this", null, false, new ArrayList<>()); nobj.setRegNumber(0); obj = nobj; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java index 68ff85910..3c3f2d64e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java @@ -37,7 +37,7 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item { public List openedNamespaces; public ConstructSomethingAVM2Item(int line, List openedNamespaces, GraphTargetItem name, List arguments) { - super(line, name, arguments); + super(openedNamespaces, line, name, arguments); this.openedNamespaces = openedNamespaces; } @@ -46,13 +46,13 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item { return name.returnType(); } - private int allNsSetWithVec(ABC abc) { + private int allNsSetWithVec(AbcIndexing abc) throws CompilationException { int[] nssa = new int[openedNamespaces.size() + 1]; for (int i = 0; i < openedNamespaces.size(); i++) { - nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants); + nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc); } - nssa[nssa.length - 1] = abc.constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true); - return abc.constants.getNamespaceSetId(nssa, true); + nssa[nssa.length - 1] = abc.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true); + return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java index d3b6b6790..0f83bd2f1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java @@ -27,7 +27,7 @@ import java.util.Map; */ public class GetterAVM2Item extends MethodAVM2Item { - public GetterAVM2Item(boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { - super(outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); + public GetterAVM2Item(List> allOpenedNamespaces, boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + super(allOpenedNamespaces, outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java index 1e1d692d6..f987aa6f0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java @@ -54,12 +54,12 @@ public class IndexAVM2Item extends AssignableAVM2Item { this.attr = attr; } - private int allNsSet(ABC abc) { + private int allNsSet(AbcIndexing abc) throws CompilationException { int[] nssa = new int[openedNamespaces.size()]; for (int i = 0; i < nssa.length; i++) { - nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants); + nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc); } - return abc.constants.getNamespaceSetId(nssa, true); + return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true); } @Override @@ -88,7 +88,7 @@ public class IndexAVM2Item extends AssignableAVM2Item { Reference index_temp = new Reference<>(-1); Reference val_temp = new Reference<>(-1); AVM2SourceGenerator g = (AVM2SourceGenerator) generator; - int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex.getSelectedAbc())), true); + int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex)), true); return toSourceMerge(localData, generator, object, dupSetTemp(localData, generator, obj_temp), @@ -110,7 +110,7 @@ public class IndexAVM2Item extends AssignableAVM2Item { public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn, boolean call, List callargs, boolean delete, boolean construct) throws CompilationException { AVM2SourceGenerator g = (AVM2SourceGenerator) generator; - int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex.getSelectedAbc())), true); + int indexPropIndex = g.abcIndex.getSelectedAbc().constants.getMultinameId(Multiname.createMultinameL(attr, allNsSet(g.abcIndex)), true); Reference ret_temp = new Reference<>(-1); if (assignedValue != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java index 90a986aba..b1bf85294 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java @@ -45,10 +45,13 @@ public class MethodAVM2Item extends FunctionAVM2Item { public String customNamespace; + public List> allOpenedNamespaces; + //public boolean isInterface; - public MethodAVM2Item(boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + public MethodAVM2Item(List> allOpenedNamespaces, boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { super(metadata, pkg, isInterface, needsActivation, hasRest, line, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); this.outsidePackage = outsidePackage; + this.allOpenedNamespaces = allOpenedNamespaces; this.isStatic = isStatic; this.override = override; this.isFinal = isFinal; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespaceItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespaceItem.java index 10c9bf92f..cbf81417a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespaceItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespaceItem.java @@ -16,9 +16,15 @@ */ package com.jpexs.decompiler.flash.abc.avm2.parser.script; -import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.Namespace; +import com.jpexs.decompiler.flash.abc.types.ValueKind; +import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; +import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.DottedChain; +import com.jpexs.decompiler.graph.TypeItem; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -30,6 +36,11 @@ public class NamespaceItem { public DottedChain name; public int kind; + private int nsIndex = -1; + + public void forceResolve(AbcIndexing abcIndex) { + nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(kind, name, 0, true); + } public NamespaceItem(DottedChain name, int kind) { this.name = name; @@ -67,17 +78,76 @@ public class NamespaceItem { return (this.kind == other.kind); } - public int getCpoolIndex(AVM2ConstantPool cpool) { - return cpool.getNamespaceId(kind, name, 0, true); + public void resolveCustomNs(AbcIndexing abcIndex, List importedClasses, DottedChain pkg, List openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException { + if (nsIndex > -1) { //already resolved + return; + } + if (kind == Namespace.KIND_NAMESPACE) { + String custom = name.toRawString(); + PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, abcIndex, openedNamespaces, new ArrayList<>()); + Reference value = new Reference<>(null); + Reference outAbc = new Reference<>(null); + + prop.resolve(true, localData, new Reference<>(null), new Reference<>(null), new Reference<>(0), value, outAbc); + boolean resolved = true; + if (value.getVal() == null) { + resolved = false; + } + if (!resolved) { + DottedChain fullCustom = null; + for (DottedChain imp : importedClasses) { + if (imp.getLast().equals(custom)) { + fullCustom = imp; + break; + } + } + if (fullCustom != null) { + /*List aas = new ArrayList<>(); + aas.add(abc); + aas.addAll(allABCs);*/ + AbcIndexing.TraitIndex ti = abcIndex.findScriptProperty(fullCustom); + + if (ti != null) { + if (ti.trait instanceof TraitSlotConst) { + if (((TraitSlotConst) ti.trait).isNamespace()) { + Namespace ns = ti.abc.constants.getNamespace(((TraitSlotConst) ti.trait).value_index); + nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(ns.kind, ns.getName(ti.abc.constants), 0, true); + return; + } + } + } + } + + throw new CompilationException("Namespace \"" + name + "\"+not defined", -1); + } + nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE, + outAbc.getVal().constants.getNamespace(value.getVal().value_index).getName(outAbc.getVal().constants), 0, true); + + } } - public static int getCpoolSetIndex(AVM2ConstantPool cpool, List namespaces) { + public boolean isResolved() { + return nsIndex > -1; + } + + public int getCpoolIndex(AbcIndexing abcIndex) throws CompilationException { + if (nsIndex > -1) { + return nsIndex; + } + if (kind == Namespace.KIND_NAMESPACE) { //must set manually + throw new CompilationException("Namespace \"" + name + "\" unresolved", -1); + } + nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(kind, name, 0, true); + return nsIndex; + } + + public static int getCpoolSetIndex(AbcIndexing abcIndex, List namespaces) throws CompilationException { int[] nssa = new int[namespaces.size()]; for (int i = 0; i < nssa.length; i++) { - nssa[i] = namespaces.get(i).getCpoolIndex(cpool); + nssa[i] = namespaces.get(i).getCpoolIndex(abcIndex); } - return cpool.getNamespaceSetId(nssa, true); + return abcIndex.getSelectedAbc().constants.getNamespaceSetId(nssa, true); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java index 236be1173..25d94dedd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NamespacedAVM2Item.java @@ -62,12 +62,12 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { this.openedNamespaces = openedNamespaces; } - private int allNsSet(ABC abc) { + private int allNsSet(AbcIndexing abc) throws CompilationException { int[] nssa = new int[openedNamespaces.size()]; for (int i = 0; i < nssa.length; i++) { - nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants); + nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc); } - return abc.constants.getNamespaceSetId(nssa, true); + return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true); } @Override @@ -115,7 +115,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { //Start get original //getTemp(localData, generator, ns_temp), generateCoerce(generator, "Namespace"), ins(AVM2Instructions.FindPropertyStrict, g.abc.getLastAbc().constants.getMultinameId(new Multiname(Multiname.RTQNAME, g.abc.getLastAbc().constants.getStringId(variableName, true), 0, 0, 0, new ArrayList()), true)), //getTemp(localData, generator, ns_temp), generateCoerce(generator, "Namespace"), - ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(abc)), true)), + ins(AVM2Instructions.GetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(g.abcIndex)), true)), !isInteger ? ins(AVM2Instructions.ConvertD) : null, //End get original (!post) ? (decrement ? ins(isInteger ? AVM2Instructions.DecrementI : AVM2Instructions.Decrement) : ins(isInteger ? AVM2Instructions.IncrementI : AVM2Instructions.Increment)) : null, @@ -125,7 +125,7 @@ public class NamespacedAVM2Item extends AssignableAVM2Item { getTemp(localData, generator, name_temp), getTemp(localData, generator, ns_temp), getTemp(localData, generator, ret_temp), - ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(abc)), true)), + ins(AVM2Instructions.SetProperty, constants.getMultinameId(Multiname.createMultinameL(false, allNsSet(g.abcIndex)), true)), killTemp(localData, generator, Arrays.asList(ret_temp, name_temp, ns_temp)) ); } else { 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 edf315b91..3dadf5dbb 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 @@ -44,6 +44,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -82,13 +84,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item { return writer; } - private int allNsSet(ABC abc) { + private int allNsSet(AbcIndexing abc) throws CompilationException { int[] nssa = new int[openedNamespaces.size()]; for (int i = 0; i < nssa.length; i++) { - nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc.constants); + nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc); } - return abc.constants.getNamespaceSetId(nssa, true); + return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true); } public static GraphTargetItem multinameToType(int m_index, AVM2ConstantPool constants) { @@ -108,7 +110,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { } } - public void resolve(SourceGeneratorLocalData localData, Reference objectType, Reference propertyType, Reference propertyIndex, Reference propertyValue, Reference propertyValueABC) { + public void resolve(boolean mustExist, SourceGeneratorLocalData localData, Reference objectType, Reference propertyType, Reference propertyIndex, Reference propertyValue, Reference propertyValueABC) throws CompilationException { GraphTargetItem thisType = new TypeItem(localData.getFullClass()); GraphTargetItem objType = null; GraphTargetItem objSubType = null; @@ -219,7 +221,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outPropType = new Reference<>(null); Reference outPropValue = new Reference<>(null); Reference outPropValueAbc = new Reference<>(null); - if (AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, false, abcIndex, ftn.getWithoutLast(), ftn.getLast(), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { + List otherNs = new ArrayList<>(); + for (NamespaceItem n : openedNamespaces) { + if (n.isResolved()) { + 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)) { objType = new TypeItem(outNs.getVal().add(outName.getVal())); propType = outPropType.getVal(); propIndex = constants.getMultinameId(Multiname.createQName(false, @@ -252,7 +260,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { if (objType == null) { loopobjType: for (int i = 0; i < openedNamespaces.size(); i++) { - int nsindex = openedNamespaces.get(i).getCpoolIndex(constants); + if (!openedNamespaces.get(i).isResolved()) { + continue; + } + int nsindex = openedNamespaces.get(i).getCpoolIndex(abcIndex); int nsKind = openedNamespaces.get(i).kind; DottedChain nsname = openedNamespaces.get(i).name; @@ -317,7 +328,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { } } if (nsKind == Namespace.KIND_PACKAGE && propertyName != null) { - AbcIndexing.TraitIndex p = abcIndex.findNsProperty(new AbcIndexing.PropertyNsDef(propertyName, nsname, abc, openedNamespaces.get(i).getCpoolIndex(constants)), true, true); + AbcIndexing.TraitIndex p = abcIndex.findNsProperty(new AbcIndexing.PropertyNsDef(propertyName, nsname, abc, openedNamespaces.get(i).getCpoolIndex(abcIndex)), true, true); Reference outName = new Reference<>(""); Reference outNs = new Reference<>(DottedChain.EMPTY); @@ -328,7 +339,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outPropValue = new Reference<>(null); Reference outPropValueAbc = new Reference<>(null); if (p != null && (p.objType instanceof TypeItem)) { - if (AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, false, abcIndex, nsname, (((TypeItem) p.objType).fullTypeName.getLast()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { + List otherns = new ArrayList<>(); + for (NamespaceItem n : openedNamespaces) { + if (n.isResolved()) { + otherns.add(n.getCpoolIndex(abcIndex)); + } + } + if (AVM2SourceGenerator.searchPrototypeChain(otherns, localData.privateNs, localData.protectedNs, false, abcIndex, nsname, (((TypeItem) p.objType).fullTypeName.getLast()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { objType = new TypeItem(outNs.getVal().add(outName.getVal())); propType = p.returnType; propIndex = constants.getMultinameId(Multiname.createQName(false, @@ -353,7 +370,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { } } - if (propIndex == 0) { + if (propIndex == 0 && !mustExist) { String pname = propertyName; boolean attr = pname.startsWith("@"); if (attr) { @@ -365,7 +382,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { constants.getNamespaceSetId(new int[]{constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, localData.pkg, 0, true)}, true)); } else { int name_index = constants.getStringId("*".equals(pname) ? null : pname, true); //Note: name = * is for .@* attribute - multiname = Multiname.createMultiname(attr, name_index, allNsSet(abc)); + multiname = Multiname.createMultiname(attr, name_index, allNsSet(abcIndex)); } propIndex = constants.getMultinameId(multiname, true); propType = TypeItem.UNBOUNDED; @@ -381,13 +398,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item { objectType.setVal(objType); } - public int resolveProperty(SourceGeneratorLocalData localData) { + public int resolveProperty(SourceGeneratorLocalData localData) throws CompilationException { Reference objType = new Reference<>(null); Reference propType = new Reference<>(null); Reference propIndex = new Reference<>(0); Reference outPropValue = new Reference<>(null); Reference outPropValueAbc = new Reference<>(null); - resolve(localData, objType, propType, propIndex, outPropValue, outPropValueAbc); + resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc); return propIndex.getVal(); } @@ -552,15 +569,20 @@ public class PropertyAVM2Item extends AssignableAVM2Item { }*/ @Override public GraphTargetItem returnType() { + Reference objType = new Reference<>(null); Reference propType = new Reference<>(null); Reference propIndex = new Reference<>(0); Reference outPropValue = new Reference<>(null); Reference outPropValueAbc = new Reference<>(null); + try { + resolve(false, new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0)/*???*/, objType, propType, propIndex, outPropValue, outPropValueAbc); - resolve(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0)/*???*/, objType, propType, propIndex, outPropValue, outPropValueAbc); - - return propType.getVal(); + return propType.getVal(); + } catch (CompilationException ex) { + Logger.getLogger(PropertyAVM2Item.class.getName()).log(Level.SEVERE, null, ex); + } + return null; } public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { @@ -571,7 +593,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outPropValue = new Reference<>(null); Reference outPropValueAbc = new Reference<>(null); - resolve(localData, objType, propType, propIndex, outPropValue, outPropValueAbc); + resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc); int propertyId = propIndex.getVal(); Object obj = resolveObject(localData, generator); @@ -620,7 +642,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { return true; } - public Object resolveObject(SourceGeneratorLocalData localData, SourceGenerator generator) { + public Object resolveObject(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { Object obj = object; if (obj == null) { @@ -638,7 +660,13 @@ public class PropertyAVM2Item extends AssignableAVM2Item { /*List abcs = new ArrayList<>(); abcs.add(abc); abcs.addAll(otherABCs);*/ - if (!localData.subMethod && cname != null && AVM2SourceGenerator.searchPrototypeChain(localData.privateNs, localData.protectedNs, true, abcIndex, pkgName, cname, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) { + List otherNs = new ArrayList<>(); + for (NamespaceItem n : openedNamespaces) { + if (n.isResolved()) { + otherNs.add(n.getCpoolIndex(abcIndex)); + } + } + if (!localData.subMethod && cname != null && AVM2SourceGenerator.searchPrototypeChain(otherNs, localData.privateNs, localData.protectedNs, true, abcIndex, pkgName, cname, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc) && (localData.getFullClass().equals(outNs.getVal().add(outName.getVal()).toRawString()))) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.getFullClass()), 0, "this", null, false, openedNamespaces); nobj.setRegNumber(0); obj = nobj; @@ -649,7 +677,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference propValue = new Reference<>(null); Reference propValueAbc = new Reference<>(null); - resolve(localData, objType, propType, propIndex, outPropValue, propValueAbc); + resolve(false, localData, objType, propType, propIndex, outPropValue, propValueAbc); obj = ins(AVM2Instructions.FindPropertyStrict, propIndex.getVal()); } } @@ -665,7 +693,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outPropValue = new Reference<>(null); Reference outPropValueAbc = new Reference<>(null); - resolve(localData, objType, propType, propIndex, outPropValue, outPropValueAbc); + resolve(false, localData, objType, propType, propIndex, outPropValue, outPropValueAbc); int propertyId = propIndex.getVal(); Object obj = resolveObject(localData, generator); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java index f9afe49c3..616b86ffe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java @@ -27,7 +27,7 @@ import java.util.Map; */ public class SetterAVM2Item extends MethodAVM2Item { - public SetterAVM2Item(boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { - super(outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); + public SetterAVM2Item(List> allOpenedNamespaces, boolean outsidePackage, boolean isPrivate, List>> metadata, NamespaceItem pkg, boolean isInterface, String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + super(allOpenedNamespaces, outsidePackage, isPrivate, metadata, pkg, isInterface, customNamespace, needsActivation, hasRest, line, override, isFinal, isStatic, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); } } 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 6e3238ddc..8f6e9247d 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 @@ -353,7 +353,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { //Search for types in opened namespaces for (NamespaceItem n : openedNamespaces) { - Namespace ons = abc.getSelectedAbc().constants.getNamespace(n.getCpoolIndex(abc.getSelectedAbc().constants)); + Namespace ons = abc.getSelectedAbc().constants.getNamespace(n.getCpoolIndex(abc)); TypeItem ti = new TypeItem(ons.getName(abc.getSelectedAbc().constants).add(name.get(0))); AbcIndexing.ClassIndex ci = abc.findClass(ti); if (ci != null) { 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 9d8cd5fbc..211c3f6d7 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 @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; +import com.jpexs.decompiler.flash.abc.avm2.AVM2Deobfuscation; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.alchemy.AlchemyTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.NewFunctionIns; @@ -110,15 +111,15 @@ public abstract class Trait implements Cloneable, Serializable { return ret; } - protected void parseImportsUsagesFromMultiname(ABC abc, List imports, List uses, Multiname m, DottedChain ignorePackage, List fullyQualifiedNames) { + protected void parseImportsUsagesFromMultiname(String ignoredCustom, ABC abc, List imports, List uses, Multiname m, DottedChain ignorePackage, List fullyQualifiedNames) { if (m != null) { if (m.kind == Multiname.TYPENAME) { if (m.qname_index != 0) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames); + parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames); } for (Integer i : m.params) { if (i != 0) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames); + parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames); } } return; @@ -127,93 +128,52 @@ public abstract class Trait implements Cloneable, Serializable { String name = m.getName(abc.constants, fullyQualifiedNames, true); NamespaceSet nss = m.getNamespaceSet(abc.constants); if (ns != null) { - parseImportsUsagesFromNS(abc, imports, uses, m.namespace_index, ignorePackage, name); + parseImportsUsagesFromNS(ignoredCustom, abc, imports, uses, m.namespace_index, ignorePackage, name); } if (nss != null) { for (int n : nss.namespaces) { - parseImportsUsagesFromNS(abc, imports, uses, n, ignorePackage, nss.namespaces.length > 1 ? "" : name); + parseImportsUsagesFromNS(ignoredCustom, abc, imports, uses, n, ignorePackage, nss.namespaces.length > 1 ? "" : name); } } } } - private boolean parseUsagesFromNS(ABC abc, List imports, List uses, int namespace_index, DottedChain ignorePackage, String name) { + private boolean parseUsagesFromNS(String ignoredCustom, ABC abc, List imports, List uses, int namespace_index, DottedChain ignorePackage, String name) { Namespace ns = abc.constants.getNamespace(namespace_index); - if (name.isEmpty()) { - name = "*"; - } - boolean raw = ns.kind == Namespace.KIND_NAMESPACE; - DottedChain newimport = ns.getName(abc.constants); - //Note: Following is weird and probably wrong - FIXIT! - /*if ((ns.kind != Namespace.KIND_PACKAGE) - && (ns.kind != Namespace.KIND_NAMESPACE) - && (ns.kind != Namespace.KIND_STATIC_PROTECTED)) { - return false; - }*/ - /*if (ns.kind == Namespace.KIND_NAMESPACE)*/ { - DottedChain oldimport = newimport; - newimport = new DottedChain(); + if (ns.kind == Namespace.KIND_NAMESPACE) { + String nsVal = ns.getName(abc.constants).toRawString(); for (ABCContainerTag abcTag : abc.getAbcTags()) { - DottedChain newname = abcTag.getABC().nsValueToName(oldimport.toRawString()); /* why this? */ + DottedChain nsimport = abcTag.getABC().nsValueToName(nsVal); + if (nsimport.equals(AVM2Deobfuscation.BUILTIN)) { + return true; //handled, but import/use not added + } + if (!nsimport.isEmpty()) { - if (newname.size() == 1 && newname.get(0).equals("-")) { + if (!nsimport.getWithoutLast().equals(ignorePackage) && !imports.contains(nsimport)) { + imports.add(nsimport); + } + if (ignoredCustom != null && nsVal.equals(ignoredCustom)) { + return true; + } + if (!uses.contains(nsimport.getLast())) { + uses.add(nsimport.getLast()); + } return true; } - - if (!newname.isEmpty() && !newname.isTopLevel()) { - newimport = newname; - break; - } - } - /* if (newimport.isEmpty()) { - newimport = oldimport.add(name); - }*/ - - if (!newimport.isEmpty() && !newimport.isTopLevel()) { - /* if(ns.kind==Namespace.KIND_PACKAGE){ - newimport+=".*"; - }*/ - - if (!imports.contains(newimport)) { - //?? - /*if (newimport.contains(":")) { - return true; - }*/ - DottedChain pkg = newimport.getWithoutLast(); - String usname = newimport.getLast(); - if (ns.kind == Namespace.KIND_PACKAGE) { - if (!pkg.equals(ignorePackage)) { - if (!pkg.equals(InitVectorAVM2Item.VECTOR_PACKAGE)) { //Automatic import - imports.add(newimport); - } - } - } - if (ns.kind == Namespace.KIND_NAMESPACE) { - if (!usname.equals("*")) { - /*if (!uses.contains(usname)) { - uses.add(usname); - }*/ - if (!pkg.equals(ignorePackage)) { - imports.add(newimport); - } - } - } - } - return true; } } return false; } - protected void parseImportsUsagesFromNS(ABC abc, List imports, List uses, int namespace_index, DottedChain ignorePackage, String name) { + protected void parseImportsUsagesFromNS(String ignoredCustom, ABC abc, List imports, List uses, int namespace_index, DottedChain ignorePackage, String name) { Namespace ns = abc.constants.getNamespace(namespace_index); if (name.isEmpty()) { name = "*"; } DottedChain newimport = ns.getName(abc.constants); - if (parseUsagesFromNS(abc, imports, uses, namespace_index, ignorePackage, name)) { + if (parseUsagesFromNS(ignoredCustom, abc, imports, uses, namespace_index, ignorePackage, name)) { return; } else if ((ns.kind != Namespace.KIND_PACKAGE) && (ns.kind != Namespace.KIND_PACKAGE_INTERNAL)) { return; @@ -231,15 +191,15 @@ public abstract class Trait implements Cloneable, Serializable { //} } - protected void parseUsagesFromMultiname(ABC abc, List imports, List uses, Multiname m, DottedChain ignorePackage, List fullyQualifiedNames) { + protected void parseUsagesFromMultiname(String ignoredCustom, ABC abc, List imports, List uses, Multiname m, DottedChain ignorePackage, List fullyQualifiedNames) { if (m != null) { if (m.kind == Multiname.TYPENAME) { if (m.qname_index != 0) { - parseUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames); + parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames); } for (Integer i : m.params) { if (i != 0) { - parseUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames); + parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames); } } return; @@ -248,14 +208,14 @@ public abstract class Trait implements Cloneable, Serializable { String name = m.getName(abc.constants, fullyQualifiedNames, false); NamespaceSet nss = m.getNamespaceSet(abc.constants); if (ns != null) { - parseUsagesFromNS(abc, imports, uses, m.namespace_index, ignorePackage, name); + parseUsagesFromNS(ignoredCustom, abc, imports, uses, m.namespace_index, ignorePackage, name); } if (nss != null) { if (nss.namespaces.length == 1) { - parseUsagesFromNS(abc, imports, uses, nss.namespaces[0], ignorePackage, name); + parseUsagesFromNS(ignoredCustom, abc, imports, uses, nss.namespaces[0], ignorePackage, name); } else { for (int n : nss.namespaces) { - parseUsagesFromNS(abc, imports, uses, n, ignorePackage, ""); + parseUsagesFromNS(ignoredCustom, abc, imports, uses, n, ignorePackage, ""); } } } @@ -266,8 +226,14 @@ public abstract class Trait implements Cloneable, Serializable { return getName(abc).getNamespace(abc.constants).getName(abc.constants); } - public void getImportsUsages(ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { - parseUsagesFromMultiname(abc, imports, uses, getName(abc), ignorePackage, fullyQualifiedNames); + public void getImportsUsages(String ignoredCustom, ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + if (ignoredCustom == null) { + Namespace n = getName(abc).getNamespace(abc.constants); + if (n.kind == Namespace.KIND_NAMESPACE) { + ignoredCustom = n.getName(abc.constants).toRawString(); + } + } + parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, getName(abc), ignorePackage, fullyQualifiedNames); } private static final String[] builtInClasses = {"ArgumentError", "arguments", "Array", "Boolean", "Class", "Date", "DefinitionError", "Error", "EvalError", "Function", "int", "JSON", "Math", "Namespace", "Number", "Object", "QName", "RangeError", "ReferenceError", "RegExp", "SecurityError", "String", "SyntaxError", "TypeError", "uint", "URIError", "VerifyError", "XML", "XMLList"}; @@ -298,7 +264,12 @@ public abstract class Trait implements Cloneable, Serializable { //imports List imports = new ArrayList<>(); List uses = new ArrayList<>(); - getImportsUsages(abc, imports, uses, ignorePackage, new ArrayList<>()); + String customNs = null; + Namespace ns = getName(abc).getNamespace(abc.constants); + if (ns.kind == Namespace.KIND_NAMESPACE) { + customNs = ns.getName(abc.constants).toRawString(); + } + getImportsUsages(customNs, abc, imports, uses, ignorePackage, new ArrayList<>()); List importnames = new ArrayList<>(); importnames.addAll(namesInThisPackage); @@ -346,24 +317,24 @@ public abstract class Trait implements Cloneable, Serializable { } } - protected void parseImportsUsagesFromMethodInfo(ABC abc, int method_index, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames, List visitedMethods) { + protected void parseImportsUsagesFromMethodInfo(String ignoredCustom, ABC abc, int method_index, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames, List visitedMethods) { if ((method_index < 0) || (method_index >= abc.method_info.size())) { return; } visitedMethods.add(method_index); if (abc.method_info.get(method_index).ret_type != 0) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(abc.method_info.get(method_index).ret_type), ignorePackage, fullyQualifiedNames); + parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(abc.method_info.get(method_index).ret_type), ignorePackage, fullyQualifiedNames); } for (int t : abc.method_info.get(method_index).param_types) { if (t != 0) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(t), ignorePackage, fullyQualifiedNames); + parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(t), ignorePackage, fullyQualifiedNames); } } MethodBody body = abc.findBody(method_index); if (body != null) { - body.traits.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames); + body.traits.getImportsUsages(ignoredCustom, abc, imports, uses, ignorePackage, fullyQualifiedNames); for (ABCException ex : body.exceptions) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(ex.type_index), ignorePackage, fullyQualifiedNames); + parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(ex.type_index), ignorePackage, fullyQualifiedNames); } for (AVM2Instruction ins : body.getCode().code) { if (ins.definition instanceof AlchemyTypeIns) { @@ -375,7 +346,7 @@ public abstract class Trait implements Cloneable, Serializable { if (ins.definition instanceof NewFunctionIns) { if (ins.operands[0] != method_index) { if (!visitedMethods.contains(ins.operands[0])) { - parseImportsUsagesFromMethodInfo(abc, ins.operands[0], imports, uses, ignorePackage, fullyQualifiedNames, visitedMethods); + parseImportsUsagesFromMethodInfo(ignoredCustom, abc, ins.operands[0], imports, uses, ignorePackage, fullyQualifiedNames, visitedMethods); } } } @@ -387,7 +358,7 @@ public abstract class Trait implements Cloneable, Serializable { int m = ins.operands[0]; if (m != 0) { if (m < abc.constants.getMultinameCount()) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(m), ignorePackage, fullyQualifiedNames); + parseImportsUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(m), ignorePackage, fullyQualifiedNames); } } } else { @@ -395,7 +366,7 @@ public abstract class Trait implements Cloneable, Serializable { if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) { int multinameIndex = ins.operands[k]; if (multinameIndex < abc.constants.getMultinameCount()) { - parseUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(multinameIndex), ignorePackage, fullyQualifiedNames); + parseUsagesFromMultiname(ignoredCustom, abc, imports, uses, abc.constants.getMultiname(multinameIndex), ignorePackage, fullyQualifiedNames); } } } @@ -437,7 +408,7 @@ public abstract class Trait implements Cloneable, Serializable { } protected final DottedChain findCustomNs(int link_ns_index, ABC abc) { - String nsname = ""; + String nsname; if (link_ns_index <= 0) { return null; } 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 82425d310..4aa635337 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 @@ -87,32 +87,32 @@ public class TraitClass extends Trait implements TraitWithSlot { } @Override - public void getImportsUsages(ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { - super.getImportsUsages(abc, imports, uses, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames); + public void getImportsUsages(String customNs, ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + super.getImportsUsages(customNs, abc, imports, uses, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames); ClassInfo classInfo = abc.class_info.get(class_info); InstanceInfo instanceInfo = abc.instance_info.get(class_info); DottedChain packageName = instanceInfo.getName(abc.constants).getNamespace(abc.constants).getName(abc.constants); //assume not null name - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(instanceInfo.name_index), packageName, fullyQualifiedNames); + parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(instanceInfo.name_index), packageName, fullyQualifiedNames); if (instanceInfo.super_index > 0) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(instanceInfo.super_index), packageName, fullyQualifiedNames); + parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(instanceInfo.super_index), packageName, fullyQualifiedNames); } for (int i : instanceInfo.interfaces) { - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(i), packageName, fullyQualifiedNames); + parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(i), packageName, fullyQualifiedNames); } //static - classInfo.static_traits.getImportsUsages(abc, imports, uses, packageName, fullyQualifiedNames); + classInfo.static_traits.getImportsUsages(customNs, abc, imports, uses, packageName, fullyQualifiedNames); //static initializer - parseImportsUsagesFromMethodInfo(abc, classInfo.cinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>()); + parseImportsUsagesFromMethodInfo(customNs, abc, classInfo.cinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>()); //instance - instanceInfo.instance_traits.getImportsUsages(abc, imports, uses, packageName, fullyQualifiedNames); + instanceInfo.instance_traits.getImportsUsages(customNs, abc, imports, uses, packageName, fullyQualifiedNames); //instance initializer - parseImportsUsagesFromMethodInfo(abc, instanceInfo.iinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>()); + parseImportsUsagesFromMethodInfo(customNs, abc, instanceInfo.iinit_index, imports, uses, packageName, fullyQualifiedNames, new ArrayList<>()); } @Override @@ -178,16 +178,14 @@ public class TraitClass extends Trait implements TraitWithSlot { if (!instanceInfo.isInterface()) { String modifier = ""; Multiname m = abc.constants.getMultiname(instanceInfo.name_index); - if (m != null) { - Namespace ns = m.getNamespace(abc.constants); - if (ns != null) { - modifier = ns.getPrefix(abc) + " "; - if (modifier.equals(" ")) { - modifier = ""; - } - if (modifier.startsWith("private")) { //cannot have private constuctor - modifier = ""; - } + Namespace ns = m.getNamespace(abc.constants); + if (ns != null) { + modifier = ns.getPrefix(abc) + " "; + if (modifier.equals(" ")) { + modifier = ""; + } + if (modifier.startsWith("private")) { //cannot have private constuctor + modifier = ""; } } 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 091c38f13..694cb5396 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 @@ -119,14 +119,14 @@ public class TraitFunction extends Trait implements TraitWithSlot { } @Override - public void getImportsUsages(ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getImportsUsages(String customNs, ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { if (ignorePackage == null) { ignorePackage = getPackage(abc); } - super.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames); + super.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames); //if (method_info != 0) { - parseImportsUsagesFromMethodInfo(abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); + parseImportsUsagesFromMethodInfo(customNs, abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); } } 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 481fbac41..a5e7b4b41 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 @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; +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.flash.helpers.NulWriter; @@ -51,15 +52,21 @@ public class TraitMethodGetterSetter extends Trait { } @Override - public void getImportsUsages(ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getImportsUsages(String customNs, ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { if (ignorePackage == null) { ignorePackage = getPackage(abc); } + super.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames); - super.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames); + if (customNs == null) { + Namespace n = getName(abc).getNamespace(abc.constants); + if (n.kind == Namespace.KIND_NAMESPACE) { + customNs = n.getName(abc.constants).toRawString(); + } + } //if (method_info != 0) { - parseImportsUsagesFromMethodInfo(abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); + parseImportsUsagesFromMethodInfo(customNs, abc, method_info, imports, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); } } 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 f32f4ad3f..cdd490eee 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 @@ -192,12 +192,12 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { } @Override - public void getImportsUsages(ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getImportsUsages(String customNs, ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { if (ignorePackage == null) { ignorePackage = getPackage(abc); } - super.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames); - parseImportsUsagesFromMultiname(abc, imports, uses, abc.constants.getMultiname(type_index), getPackage(abc), fullyQualifiedNames); + super.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames); + parseImportsUsagesFromMultiname(customNs, abc, imports, uses, abc.constants.getMultiname(type_index), getPackage(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 6dcdc7a64..10a20e3d1 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 @@ -195,7 +195,7 @@ public class Traits implements Cloneable, Serializable { } } else { ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount()); - List> futureResults = null; + List> futureResults; futureResults = new ArrayList<>(); for (int t = 0; t < traits.size(); t++) { @@ -237,9 +237,9 @@ public class Traits implements Cloneable, Serializable { } } - public void getImportsUsages(ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getImportsUsages(String customNs, ABC abc, List imports, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { for (Trait t : traits) { - t.getImportsUsages(abc, imports, uses, ignorePackage, fullyQualifiedNames); + t.getImportsUsages(customNs, abc, imports, uses, ignorePackage, fullyQualifiedNames); } } }