diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index ad243b200..e99627d68 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -1066,7 +1066,7 @@ public class AVM2SourceGenerator implements SourceGenerator { return abc; } - public void generateClass(int namespace, int initScope, PackageAVM2Item pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List implementsStr, GraphTargetItem constructor, List traitItems) throws ParseException, CompilationException { + public void generateClass(List openedNamespaces,int namespace, int initScope, PackageAVM2Item pkg, ClassInfo classInfo, InstanceInfo instanceInfo, SourceGeneratorLocalData localData, boolean isInterface, String name, String superName, GraphTargetItem extendsVal, List implementsStr, GraphTargetItem constructor, List traitItems) throws ParseException, CompilationException { localData.currentClass = pkg.packageName.isEmpty() ? name : pkg.packageName + "." + name; List ret = new ArrayList<>(); if (extendsVal == null && !isInterface) { @@ -1076,8 +1076,9 @@ public class AVM2SourceGenerator implements SourceGenerator { Trait[] it = generateTraitsPhase1(pkg, name, superName, false, localData, traitItems, instanceInfo.instance_traits); Trait[] st = generateTraitsPhase1(pkg, name, superName, true, localData, traitItems, classInfo.static_traits); - generateTraitsPhase2(initScope, pkg, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it); - generateTraitsPhase2(initScope, pkg, name, superName, true, localData, traitItems, classInfo.static_traits, st); + generateTraitsPhase2(pkg.packageName,traitItems, it, openedNamespaces, localData); + generateTraitsPhase3(initScope, pkg, name, superName, false, localData, traitItems, instanceInfo.instance_traits, it); + generateTraitsPhase3(initScope, pkg, name, superName, true, localData, traitItems, classInfo.static_traits, st); if (constructor == null) { instanceInfo.iinit_index = method(new ArrayList(), pkg.packageName, false, new ArrayList(), initScope + 1, false, 0, name, extendsVal != null ? extendsVal.toString() : null, true, localData, new ArrayList(), new ArrayList(), new ArrayList(), new ArrayList(), TypeItem.UNBOUNDED/*?? FIXME*/); } else { @@ -1142,7 +1143,7 @@ public class AVM2SourceGenerator implements SourceGenerator { */ if (cls instanceof ClassAVM2Item) { ClassAVM2Item cai = (ClassAVM2Item) cls; - generateClass(namespace, initScope, pkg, ci, ii, localData, false, cai.className, cai.extendsOp.toString(), cai.extendsOp, cai.implementsOp, cai.constructor, cai.traits); + generateClass(cai.openedNamespaces,namespace, initScope, pkg, ci, ii, localData, false, cai.className, cai.extendsOp.toString(), cai.extendsOp, cai.implementsOp, cai.constructor, cai.traits); if (!cai.isDynamic) { ii.flags |= InstanceInfo.CLASS_SEALED; } @@ -1154,7 +1155,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } if (cls instanceof InterfaceAVM2Item) { InterfaceAVM2Item iai = (InterfaceAVM2Item) cls; - generateClass(namespace, initScope, pkg, ci, ii, localData, true, iai.name, null, null, iai.superInterfaces, null, iai.methods); + generateClass(iai.openedNamespaces,namespace, initScope, pkg, ci, ii, localData, true, iai.name, null, null, iai.superInterfaces, null, iai.methods); ii.flags |= InstanceInfo.CLASS_INTERFACE; } @@ -1629,13 +1630,78 @@ public class AVM2SourceGenerator implements SourceGenerator { return null; } - public void generateTraitsPhase2(int initScope, PackageAVM2Item pkg, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Trait[] traits) throws ParseException, CompilationException { + private int genNs(String custom,int namespace, List openedNamespaces, SourceGeneratorLocalData localData){ + if(custom!=null){ + PropertyAVM2Item prop = new PropertyAVM2Item(null, custom, null, abc, allABCs, openedNamespaces, new ArrayList()); + Reference value=new Reference<>(null); + prop.resolve(localData, new Reference(""), new Reference(""), new Reference(0), value); + namespace = value.getVal().value_index; + } + return namespace; + } + + public void generateTraitsPhase2(String pkg,List items,Trait[] traits, List openedNamespaces, SourceGeneratorLocalData localData) throws CompilationException{ + for (int k = 0; k < items.size(); k++) { + GraphTargetItem item = items.get(k); + if (traits[k] == null) { + continue; + } else if (item instanceof InterfaceAVM2Item) { + traits[k].name_index = traitName(((InterfaceAVM2Item)item).namespace,((InterfaceAVM2Item)item).name); + } else if (item instanceof ClassAVM2Item) { + traits[k].name_index = traitName(((ClassAVM2Item)item).namespace,((ClassAVM2Item)item).className); + } else if ((item instanceof MethodAVM2Item) || (item instanceof GetterAVM2Item) || (item instanceof SetterAVM2Item)) { + traits[k].name_index = traitName(genNs(((MethodAVM2Item)item).customNamespace,((MethodAVM2Item)item).namespace, openedNamespaces, localData),((MethodAVM2Item)item).functionName); + } else if (item instanceof FunctionAVM2Item) { + traits[k].name_index = traitName(((FunctionAVM2Item)item).namespace,((FunctionAVM2Item)item).functionName); + } else if(item instanceof ConstAVM2Item){ + traits[k].name_index = traitName(genNs(((ConstAVM2Item)item).customNamespace,((ConstAVM2Item)item).getNamespace(), openedNamespaces, localData),((ConstAVM2Item)item).var); + } else if(item instanceof SlotAVM2Item){ + traits[k].name_index = traitName(genNs(((SlotAVM2Item)item).customNamespace,((SlotAVM2Item)item).getNamespace(), openedNamespaces, localData),((SlotAVM2Item)item).var); + } + } + + for (int k = 0; k < items.size(); k++) { + GraphTargetItem item = items.get(k); + if (traits[k] == null) { + continue; + } + if (item instanceof ClassAVM2Item) { + InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass)traits[k]).class_info); + instanceInfo.name_index = abc.constants.addMultiname(new Multiname(Multiname.QNAME, abc.constants.getStringId(((ClassAVM2Item) item).className, true), + abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg, 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.constants.getMultinameId(new Multiname(Multiname.QNAME, str("Object"), namespace(Namespace.KIND_PACKAGE, ""), 0, 0, new ArrayList()), true); + } + instanceInfo.interfaces = new int[((ClassAVM2Item) item).implementsOp.size()]; + for(int i=0;i<((ClassAVM2Item) item).implementsOp.size();i++) + { + instanceInfo.interfaces[i] = typeName(localData,((ClassAVM2Item) item).implementsOp.get(i)); + } + } + if (item instanceof InterfaceAVM2Item) { + InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass)traits[k]).class_info); + instanceInfo.name_index = abc.constants.addMultiname(new Multiname(Multiname.QNAME, abc.constants.getStringId(((ClassAVM2Item) item).className, true), + abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg, true)), 0, true), 0, 0, new ArrayList())); + + instanceInfo.interfaces = new int[((InterfaceAVM2Item) item).superInterfaces.size()]; + for(int i=0;i<((InterfaceAVM2Item) item).superInterfaces.size();i++) + { + instanceInfo.interfaces[i] = typeName(localData,((InterfaceAVM2Item) item).superInterfaces.get(i)); + } + } + } + } + + public void generateTraitsPhase3(int initScope, PackageAVM2Item pkg, String className, String superName, boolean generateStatic, SourceGeneratorLocalData localData, List items, Traits ts, Trait[] traits) throws ParseException, 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); if (traits[k] == null) { continue; - } + } if (item instanceof InterfaceAVM2Item) { generateClass(((InterfaceAVM2Item) item).namespace, abc.class_info.get(((TraitClass) traits[k]).class_info), abc.instance_info.get(((TraitClass) traits[k]).class_info), initScope, pkg, localData, (InterfaceAVM2Item) item); } @@ -1669,7 +1735,7 @@ public class AVM2SourceGenerator implements SourceGenerator { abc.instance_info.add(ii); tc.class_info = abc.instance_info.size() - 1; tc.kindType = Trait.TRAIT_CLASS; - tc.name_index = traitName(((InterfaceAVM2Item) item).namespace, ((InterfaceAVM2Item) item).name); + //tc.name_index = traitName(((InterfaceAVM2Item) item).namespace, ((InterfaceAVM2Item) item).name); tc.slot_id = slot_id++; ts.traits.add(tc); traits[k] = tc; @@ -1683,17 +1749,18 @@ public class AVM2SourceGenerator implements SourceGenerator { abc.instance_info.add(instanceInfo); tc.class_info = abc.instance_info.size() - 1; - instanceInfo.name_index = abc.constants.addMultiname(new Multiname(Multiname.QNAME, abc.constants.getStringId(((ClassAVM2Item) item).className, true), + /*instanceInfo.name_index = abc.constants.addMultiname(new Multiname(Multiname.QNAME, abc.constants.getStringId(((ClassAVM2Item) item).className, true), abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.getStringId(pkg.packageName, true)), 0, true), 0, 0, new ArrayList())); + */ - if (((ClassAVM2Item) item).extendsOp != null) { + /*if (((ClassAVM2Item) item).extendsOp != null) { instanceInfo.super_index = typeName(localData, ((ClassAVM2Item) item).extendsOp); - } else if (true) { //(!isInterface) { + } else { instanceInfo.super_index = abc.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.name_index = traitName(((ClassAVM2Item) item).namespace, ((ClassAVM2Item) item).className); tc.slot_id = slot_id++; ts.traits.add(tc); traits[k] = tc; @@ -1731,7 +1798,9 @@ public class AVM2SourceGenerator implements SourceGenerator { isNamespace = type.toString().equals("Namespace"); isStatic = cai.isStatic(); } - tsc.name_index = traitName(namespace, var); + if(isNamespace){ + tsc.name_index = traitName(namespace, var); + } tsc.type_index = isNamespace ? 0 : (type == null ? 0 : typeName(localData, type)); ValueKind vk = getValueKind(abc.constants.constant_namespace.get(namespace).kind, type, val); @@ -1752,7 +1821,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } TraitMethodGetterSetter tmgs = new TraitMethodGetterSetter(); tmgs.kindType = (item instanceof MethodAVM2Item) ? Trait.TRAIT_METHOD : ((item instanceof GetterAVM2Item) ? Trait.TRAIT_GETTER : Trait.TRAIT_SETTER); - tmgs.name_index = traitName(((MethodAVM2Item) item).namespace, ((MethodAVM2Item) item).functionName); + //tmgs.name_index = traitName(((MethodAVM2Item) item).namespace, ((MethodAVM2Item) item).functionName); tmgs.disp_id = 0; //0 = disable override optimization; TODO: handle this if (mai.isFinal()) { tmgs.kindFlags |= Trait.ATTR_Final; @@ -1767,11 +1836,11 @@ public class AVM2SourceGenerator implements SourceGenerator { TraitFunction tf = new TraitFunction(); tf.slot_id = slot_id++; tf.kindType = Trait.TRAIT_FUNCTION; - tf.name_index = traitName(((FunctionAVM2Item) item).namespace, ((FunctionAVM2Item) item).functionName); + //tf.name_index = traitName(((FunctionAVM2Item) item).namespace, ((FunctionAVM2Item) item).functionName); ts.traits.add(tf); traits[k] = tf; } - } + } return traits; } @@ -1779,7 +1848,7 @@ public class AVM2SourceGenerator implements SourceGenerator { public ScriptInfo generateScriptInfo(PackageAVM2Item pkg, SourceGeneratorLocalData localData, List commands, boolean documentClass) throws ParseException, CompilationException { ScriptInfo si = new ScriptInfo(); Trait[] traitArr = generateTraitsPhase1(pkg, null, null, false, localData, commands, si.traits); - + generateTraitsPhase2(pkg.packageName,commands, traitArr, new ArrayList(), localData); MethodInfo mi = new MethodInfo(new int[0], 0, 0, 0, new ValueKind[0], new int[0]); MethodBody mb = new MethodBody(); mb.method_info = abc.addMethodInfo(mi); @@ -1820,7 +1889,7 @@ public class AVM2SourceGenerator implements SourceGenerator { abc.addMethodBody(mb); si.init_index = mb.method_info; localData.pkg = pkg.packageName; - generateTraitsPhase2(traitScope, pkg, null, null, false, localData, commands, si.traits, traitArr); + generateTraitsPhase3(traitScope, pkg, null, null, false, localData, commands, si.traits, traitArr); return si; } @@ -1869,7 +1938,7 @@ public class AVM2SourceGenerator implements SourceGenerator { return TypeItem.UNBOUNDED; } - public static boolean searchPrototypeChain(boolean instanceOnly, List abcs, String pkg, String obj, String propertyName, Reference outName, Reference outNs, Reference outPropNs, Reference outPropNsKind, Reference outPropType) { + public static boolean searchPrototypeChain(boolean instanceOnly, List abcs, String pkg, String obj, String propertyName, Reference outName, Reference outNs, Reference outPropNs, Reference outPropNsKind, Reference outPropType, Reference outPropValue) { for (ABC abc : abcs) { if (!instanceOnly) { @@ -1882,6 +1951,10 @@ public class AVM2SourceGenerator implements SourceGenerator { outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants)); outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind); outPropType.setVal(getTraitReturnType(abc, t).toString()); + if(t instanceof TraitSlotConst){ + TraitSlotConst tsc=(TraitSlotConst)t; + outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind)); + } return true; } } @@ -1902,6 +1975,10 @@ public class AVM2SourceGenerator implements SourceGenerator { outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants)); outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind); outPropType.setVal(getTraitReturnType(abc, t).toString()); + if(t instanceof TraitSlotConst){ + TraitSlotConst tsc=(TraitSlotConst)t; + outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind)); + } return true; } } @@ -1914,6 +1991,10 @@ public class AVM2SourceGenerator implements SourceGenerator { outPropNs.setVal(t.getName(abc).getNamespace(abc.constants).getName(abc.constants)); outPropNsKind.setVal(t.getName(abc).getNamespace(abc.constants).kind); outPropType.setVal(getTraitReturnType(abc, t).toString()); + if(t instanceof TraitSlotConst){ + TraitSlotConst tsc=(TraitSlotConst)t; + outPropValue.setVal(new ValueKind(tsc.value_index, tsc.value_kind)); + } return true; } } @@ -1921,7 +2002,7 @@ public class AVM2SourceGenerator implements SourceGenerator { Multiname superName = abc.constants.constant_multiname.get(ii.super_index); if (superName != null) { - return searchPrototypeChain(instanceOnly, abcs, superName.getNamespace(abc.constants).getName(abc.constants), superName.getName(abc.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType); + return searchPrototypeChain(instanceOnly, abcs, superName.getNamespace(abc.constants).getName(abc.constants), superName.getName(abc.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue); } else { return false; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java index 060cb76ba..01d76a541 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java @@ -73,6 +73,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.operations.URShiftAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.Namespace; +import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.ABCContainerTag; @@ -296,9 +297,9 @@ public class ActionScriptParser { return ret; } - private MethodAVM2Item method(Reference needsActivation, List importedClasses, boolean override, boolean isFinal, GraphTargetItem thisType, List openedNamespaces, boolean isStatic, int namespace, boolean withBody, String functionName, boolean isMethod, List variables) throws IOException, ParseException { + private MethodAVM2Item method(String customAccess, Reference needsActivation, List importedClasses, boolean override, boolean isFinal, GraphTargetItem thisType, List openedNamespaces, boolean isStatic, int namespace, boolean withBody, String functionName, boolean isMethod, List variables) throws IOException, ParseException { FunctionAVM2Item f = function(needsActivation, importedClasses, namespace, thisType, openedNamespaces, withBody, functionName, isMethod, variables); - return new MethodAVM2Item(f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, f.namespace, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); + return new MethodAVM2Item(customAccess,f.needsActivation, f.hasRest, f.line, override, isFinal, isStatic, f.namespace, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); } private FunctionAVM2Item function(Reference needsActivation, List importedClasses, int namespace, GraphTargetItem thisType, List openedNamespaces, boolean withBody, String functionName, boolean isMethod, List variables) throws IOException, ParseException { @@ -391,27 +392,28 @@ public class ActionScriptParser { boolean isOverride = false; boolean isFinal = false; boolean isDynamic = false; + String customAccess = null; //TODO: namespace name //TODO: final, dynamic - while (s.isType(SymbolType.STATIC, SymbolType.PUBLIC, SymbolType.PRIVATE, SymbolType.PROTECTED, SymbolType.OVERRIDE, SymbolType.FINAL, SymbolType.DYNAMIC)) { + while (s.isType(SymbolType.STATIC, SymbolType.PUBLIC, SymbolType.PRIVATE, SymbolType.PROTECTED, SymbolType.OVERRIDE, SymbolType.FINAL, SymbolType.DYNAMIC, SymbolType.IDENTIFIER)) { if (s.type == SymbolType.FINAL) { if (isFinal) { throw new ParseException("Only one final keyword allowed", lexer.yyline()); } isFinal = true; - } + }else if (s.type == SymbolType.DYNAMIC) { if (isDynamic) { throw new ParseException("Only one dynamic keyword allowed", lexer.yyline()); } isDynamic = true; - } + }else if (s.type == SymbolType.OVERRIDE) { if (isOverride) { throw new ParseException("Only one override keyword allowed", lexer.yyline()); } isOverride = true; - } + }else if (s.type == SymbolType.STATIC) { if (isInterface) { throw new ParseException("Interface cannot have static traits", lexer.yyline()); @@ -423,6 +425,9 @@ public class ActionScriptParser { throw new ParseException("Only one static keyword allowed", lexer.yyline()); } isStatic = true; + } else if(s.type == SymbolType.IDENTIFIER){ + customAccess = s.value.toString(); + namespace = -2; } else { if (namespace != -1) { throw new ParseException("Only one access identifier allowed", lexer.yyline()); @@ -475,6 +480,9 @@ public class ActionScriptParser { } while (s.type == SymbolType.COMMA); } expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); + if(customAccess!=null){ + throw new ParseException("Class cannot have custom namespace", lexer.yyline()); + } traits.add((classTraits(packageInternalNs, importedClasses, privateNs, isDynamic, isFinal, openedNamespaces, packageName, namespace, false, classTypeStr, extendsTypeStr, implementsTypeStrs, variables))); expectedType(SymbolType.CURLY_CLOSE); break; @@ -506,6 +514,9 @@ public class ActionScriptParser { } while (s.type == SymbolType.COMMA); } expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); + if(customAccess!=null){ + throw new ParseException("Interface cannot have custom namespace", lexer.yyline()); + } traits.add((classTraits(packageInternalNs, importedClasses, privateNs, false, isFinal, openedNamespaces, packageName, namespace, true, intTypeStr, null, intExtendsTypeStrs, variables))); expectedType(SymbolType.CURLY_CLOSE); break; @@ -545,29 +556,29 @@ public class ActionScriptParser { if (isFinal) { throw new ParseException("Final flag not allowed for constructor", lexer.yyline()); } - constr = (method(new Reference(false), importedClasses, false, false, thisType, openedNamespaces, false, namespace, !isInterface, "", true, variables)); + constr = (method(customAccess,new Reference(false), importedClasses, false, false, thisType, openedNamespaces, false, namespace, !isInterface, "", true, variables)); } else { if (isStatic) { GraphTargetItem t; - MethodAVM2Item ft = method(new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, !isInterface, fname, true, variables); + MethodAVM2Item ft = method(customAccess,new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, !isInterface, fname, true, variables); traits.add(ft); if (isGetter || isSetter) { throw new ParseException("Getter or Setter cannot be static", lexer.yyline()); } } else { - MethodAVM2Item ft = method(new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, !isInterface, fname, true, variables); + MethodAVM2Item ft = method(customAccess,new Reference(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, !isInterface, fname, true, variables); GraphTargetItem t; if (isGetter) { if (!ft.paramTypes.isEmpty()) { throw new ParseException("Getter can't have any parameters", lexer.yyline()); } - GetterAVM2Item g = new GetterAVM2Item(ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + GetterAVM2Item g = new GetterAVM2Item(customAccess,ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = g; } else if (isSetter) { if (ft.paramTypes.size() != 1) { throw new ParseException("Getter must have exactly one parameter", lexer.yyline()); } - SetterAVM2Item st = new SetterAVM2Item(ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + SetterAVM2Item st = new SetterAVM2Item(customAccess,ft.needsActivation, ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespace, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = st; } else { t = ft; @@ -597,7 +608,7 @@ public class ActionScriptParser { lexer.pushback(s); } - ConstAVM2Item ns = new ConstAVM2Item(true, namespace, nname, new TypeItem("Namespace"), new StringAVM2Item(null, nval)); + ConstAVM2Item ns = new ConstAVM2Item(customAccess,true, namespace, nname, new TypeItem("Namespace"), new StringAVM2Item(null, nval)); traits.add(ns); break; case CONST: @@ -631,9 +642,9 @@ public class ActionScriptParser { } GraphTargetItem tar; if (isConst) { - tar = new ConstAVM2Item(isStatic, namespace, vcname, type, value); + tar = new ConstAVM2Item(customAccess,isStatic, namespace, vcname, type, value); } else { - tar = new SlotAVM2Item(isStatic, namespace, vcname, type, value); + tar = new SlotAVM2Item(customAccess,isStatic, namespace, vcname, type, value); } traits.add(tar); if (s.type != SymbolType.SEMICOLON) { @@ -683,9 +694,9 @@ public class ActionScriptParser { GraphTargetItem constr = traits(importedClasses, privateNs, protectedNs, publicNs, packageInternalNs, protectedStaticNs, openedNamespaces, packageName, classNameStr, isInterface, traits); if (isInterface) { - return new InterfaceAVM2Item(isFinal, namespace, classNameStr, implementsStr, traits); + return new InterfaceAVM2Item(openedNamespaces,isFinal, namespace, classNameStr, implementsStr, traits); } else { - return new ClassAVM2Item(protectedNs, isDynamic, isFinal, namespace, classNameStr, extendsStr, implementsStr, constr, traits); + return new ClassAVM2Item(openedNamespaces,protectedNs, isDynamic, isFinal, namespace, classNameStr, extendsStr, implementsStr, constr, traits); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java index 1ad2ebbbe..70043f2e8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallPropertyIn import com.jpexs.decompiler.flash.abc.avm2.instructions.other.FindPropertyStrictIns; import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.flash.abc.types.ValueKind; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; @@ -82,7 +83,8 @@ public class CallAVM2Item extends AVM2Item { Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); Reference outPropType = new Reference<>(""); - if (AVM2SourceGenerator.searchPrototypeChain(true, allAbcs, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropType)) { + Reference outPropValue = new Reference<>(null); + if (AVM2SourceGenerator.searchPrototypeChain(true, allAbcs, pkgName, cname, n.getVariableName(), outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.currentClass), n.line, "this", null, false, n.openedNamespaces); nobj.setRegNumber(0); obj = nobj; @@ -112,7 +114,8 @@ public class CallAVM2Item extends AVM2Item { Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); Reference outPropType = new Reference<>(""); - if (AVM2SourceGenerator.searchPrototypeChain(true, allAbcs, pkgName, cname, prop.propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType)) { + Reference outPropValue = new Reference<>(null); + if (AVM2SourceGenerator.searchPrototypeChain(true, allAbcs, pkgName, cname, prop.propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.currentClass), 0, "this", null, false, new ArrayList()); nobj.setRegNumber(0); obj = nobj; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java index be3b72331..c32797a76 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ClassAVM2Item.java @@ -37,6 +37,7 @@ public class ClassAVM2Item extends AVM2Item implements Block { public int protectedNs; public boolean isDynamic; public boolean isFinal; + public List openedNamespaces; @Override public List> getSubs() { @@ -47,7 +48,7 @@ public class ClassAVM2Item extends AVM2Item implements Block { return ret; } - public ClassAVM2Item(int protectedNs, boolean isDynamic, boolean isFinal, int namespace, String className, GraphTargetItem extendsOp, List implementsOp, GraphTargetItem constructor, List traits) { + public ClassAVM2Item(List openedNamespaces, int protectedNs, boolean isDynamic, boolean isFinal, int namespace, String className, GraphTargetItem extendsOp, List implementsOp, GraphTargetItem constructor, List traits) { super(null, NOPRECEDENCE); this.protectedNs = protectedNs; this.className = className; @@ -58,6 +59,7 @@ public class ClassAVM2Item extends AVM2Item implements Block { this.namespace = namespace; this.isDynamic = isDynamic; this.isFinal = isFinal; + this.openedNamespaces = openedNamespaces; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java index 051fbb73f..133595bde 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstAVM2Item.java @@ -31,6 +31,7 @@ public class ConstAVM2Item extends AVM2Item { private boolean isStatic; public String var; public GraphTargetItem type; + public String customNamespace; public int getNamespace() { return namespace; @@ -40,13 +41,14 @@ public class ConstAVM2Item extends AVM2Item { return isStatic; } - public ConstAVM2Item(boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value) { + public ConstAVM2Item(String customNamespace,boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value) { super(null, NOPRECEDENCE); this.namespace = namespace; this.value = value; this.isStatic = isStatic; this.var = var; this.type = type; + this.customNamespace = customNamespace; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java index fe9347f60..7aca01a65 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/GetterAVM2Item.java @@ -25,8 +25,8 @@ import java.util.List; */ public class GetterAVM2Item extends MethodAVM2Item { - public GetterAVM2Item(boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { - super(needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); + public GetterAVM2Item(String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + super(customNamespace,needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java index 53782051e..53fd6ffc8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/InterfaceAVM2Item.java @@ -34,14 +34,16 @@ public class InterfaceAVM2Item extends AVM2Item { public List methods; public int namespace; public boolean isFinal; + public List openedNamespaces; - public InterfaceAVM2Item(boolean isFinal, int namespace, String name, List superInterfaces, List traits) { + public InterfaceAVM2Item(List openedNamespaces, boolean isFinal, int namespace, String name, List superInterfaces, List traits) { super(null, NOPRECEDENCE); this.name = name; this.superInterfaces = superInterfaces; this.methods = traits; this.namespace = namespace; this.isFinal = isFinal; + this.openedNamespaces = openedNamespaces; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java index 878d8cfa7..1f10b0ee9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java @@ -30,12 +30,14 @@ public class MethodAVM2Item extends FunctionAVM2Item { private boolean isStatic; private boolean isFinal; private boolean override; + public String customNamespace; - public MethodAVM2Item(boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + public MethodAVM2Item(String customNamespace, boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { super(needsActivation, namespace, hasRest, line, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); this.isStatic = isStatic; this.override = override; this.isFinal = isFinal; + this.customNamespace = customNamespace; } public boolean isOverride() { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java index 60713a5c9..d998d816c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java @@ -36,6 +36,7 @@ import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.NamespaceSet; +import com.jpexs.decompiler.flash.abc.types.ValueKind; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -93,9 +94,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { return abc.constants.getNamespaceSetId(new NamespaceSet(nssa), true); } - private void resolve(SourceGeneratorLocalData localData, Reference objectType, Reference propertyType, Reference propertyIndex) { + public void resolve(SourceGeneratorLocalData localData, Reference objectType, Reference propertyType, Reference propertyIndex, Reference propertyValue) { String objType = null; String objSubType = null; + ValueKind propValue = null; if(object != null){ GraphTargetItem oretType = object.returnType(); if(oretType instanceof UnresolvedAVM2Item){ @@ -194,6 +196,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { objType = abc.instance_info.get(c).getName(abc.constants).getNameWithNamespace(abc.constants); propType = AVM2SourceGenerator.getTraitReturnType(abc, t).toString(); propIndex = t.name_index; + if(t instanceof TraitSlotConst){ + TraitSlotConst tsc=(TraitSlotConst)t; + propValue = new ValueKind(tsc.value_index, tsc.value_kind); + } break loopobjType; } } @@ -202,6 +208,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { objType = abc.instance_info.get(c).getName(abc.constants).getNameWithNamespace(abc.constants); propType = AVM2SourceGenerator.getTraitReturnType(abc, t).toString(); propIndex = t.name_index; + if(t instanceof TraitSlotConst){ + TraitSlotConst tsc=(TraitSlotConst)t; + propValue = new ValueKind(tsc.value_index, tsc.value_kind); + } break loopobjType; } } @@ -222,14 +232,15 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); Reference outPropType = new Reference<>(""); - if (AVM2SourceGenerator.searchPrototypeChain(false, abcs, nsname, n.getName(a.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType)) { + Reference outPropValue = new Reference<>(null); + if (AVM2SourceGenerator.searchPrototypeChain(false, abcs, nsname, n.getName(a.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { objType = "".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal(); propType = outPropType.getVal(); propIndex = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(propertyName, true), abc.constants.getNamespaceId(new Namespace(outPropNsKind.getVal(), abc.constants.getStringId(outPropNs.getVal(), true)), 0, true), 0, 0, new ArrayList()), true ); - + propValue = outPropValue.getVal(); break loopobjType; } } @@ -263,13 +274,15 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); Reference outPropType = new Reference<>(""); - if (AVM2SourceGenerator.searchPrototypeChain(false, abcs, m.getNamespace(a.constants).getName(a.constants), m.getName(a.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType)) { + Reference outPropValue = new Reference<>(null); + if (AVM2SourceGenerator.searchPrototypeChain(false, abcs, m.getNamespace(a.constants).getName(a.constants), m.getName(a.constants, new ArrayList()), propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType,outPropValue)) { objType = "".equals(outNs.getVal()) ? outName.getVal() : outNs.getVal() + "." + outName.getVal(); propType = outPropType.getVal(); propIndex = abc.constants.getMultinameId(new Multiname(Multiname.QNAME, abc.constants.getStringId(propertyName, true), abc.constants.getNamespaceId(new Namespace(outPropNsKind.getVal(), abc.constants.getStringId(outPropNs.getVal(), true)), 0, true), 0, 0, new ArrayList()), true ); + propValue = outPropValue.getVal(); break loopa; } @@ -285,8 +298,10 @@ public class PropertyAVM2Item extends AssignableAVM2Item { allNsSet(), 0, new ArrayList()), true); propType = "*"; objType = "*"; + propValue = null; } + propertyValue.setVal(propValue); propertyIndex.setVal(propIndex); propertyType.setVal(propType); objectType.setVal(objType); @@ -296,7 +311,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference objType = new Reference<>(""); Reference propType = new Reference<>(""); Reference propIndex = new Reference<>(0); - resolve(localData, objType, propType, propIndex); + Reference outPropValue = new Reference<>(null); + resolve(localData, objType, propType, propIndex, outPropValue); return propIndex.getVal(); } @@ -467,7 +483,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference objType = new Reference<>(""); Reference propType = new Reference<>(""); Reference propIndex = new Reference<>(0); - resolve(null, objType, propType, propIndex); + Reference outPropValue = new Reference<>(null); + resolve(null, objType, propType, propIndex, outPropValue); return new TypeItem(propType.getVal()); } @@ -477,7 +494,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference objType = new Reference<>(""); Reference propType = new Reference<>(""); Reference propIndex = new Reference<>(0); - resolve(localData, objType, propType, propIndex); + Reference outPropValue = new Reference<>(null); + resolve(localData, objType, propType, propIndex,outPropValue); int propertyId = propIndex.getVal(); Object obj = resolveObject(localData, generator); @@ -538,10 +556,11 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference outPropNs = new Reference<>(""); Reference outPropNsKind = new Reference<>(1); Reference outPropType = new Reference<>(""); + Reference outPropValue = new Reference<>(null); List abcs = new ArrayList<>(); abcs.add(abc); abcs.addAll(otherABCs); - if (cname != null && AVM2SourceGenerator.searchPrototypeChain(true, abcs, pkgName, cname, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType)) { + if (cname != null && AVM2SourceGenerator.searchPrototypeChain(true, abcs, pkgName, cname, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropType, outPropValue)) { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.currentClass), 0, "this", null, false, openedNamespaces); nobj.setRegNumber(0); obj = nobj; @@ -549,7 +568,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference objType = new Reference<>(""); Reference propType = new Reference<>(""); Reference propIndex = new Reference<>(0); - resolve(localData, objType, propType, propIndex); + Reference propValue = new Reference<>(null); + resolve(localData, objType, propType, propIndex, outPropValue); obj = ins(new FindPropertyStrictIns(), propIndex.getVal()); } } @@ -562,7 +582,8 @@ public class PropertyAVM2Item extends AssignableAVM2Item { Reference objType = new Reference<>(""); Reference propType = new Reference<>(""); Reference propIndex = new Reference<>(0); - resolve(localData, objType, propType, propIndex); + Reference outPropValue = new Reference<>(null); + resolve(localData, objType, propType, propIndex, outPropValue); int propertyId = propIndex.getVal(); Object obj = resolveObject(localData, generator); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java index b4ff4b571..e4aad43ab 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SetterAVM2Item.java @@ -25,8 +25,8 @@ import java.util.List; */ public class SetterAVM2Item extends MethodAVM2Item { - public SetterAVM2Item(boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { - super(needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); + public SetterAVM2Item(String customNamespace,boolean needsActivation, boolean hasRest, int line, boolean override, boolean isFinal, boolean isStatic, int namespace, String methodName, List paramTypes, List paramNames, List paramValues, List body, List subvariables, GraphTargetItem retType) { + super(customNamespace,needsActivation, hasRest, line, override, isFinal, isStatic, namespace, methodName, paramTypes, paramNames, paramValues, body, subvariables, retType); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java index 33a51f4ff..aaa63cf6b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/SlotAVM2Item.java @@ -31,6 +31,7 @@ public class SlotAVM2Item extends AVM2Item { private boolean isStatic; public String var; public GraphTargetItem type; + public String customNamespace; public int getNamespace() { return namespace; @@ -40,13 +41,14 @@ public class SlotAVM2Item extends AVM2Item { return isStatic; } - public SlotAVM2Item(boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value) { + public SlotAVM2Item(String customNamespace, boolean isStatic, int namespace, String var, GraphTargetItem type, GraphTargetItem value) { super(null, NOPRECEDENCE); this.namespace = namespace; this.value = value; this.isStatic = isStatic; this.var = var; this.type = type; + this.customNamespace = customNamespace; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt index 8e38be43f..1f0772e1b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt @@ -1,5 +1,4 @@ TODO List for AS3 parser/compiler: ------------------------------ - E4X (XML) -- default xml namespace -- custom namespace modifiers \ No newline at end of file +- default xml namespace \ No newline at end of file