From 0042d7f76fd1616b9efd230885be0918197fc6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Tue, 10 Nov 2015 11:46:26 +0100 Subject: [PATCH] AS3 direct editation bug fixes --- .../parser/script/AVM2SourceGenerator.java | 41 ++- .../abc/avm2/parser/script/AbcIndexing.java | 18 +- .../parser/script/ActionScript3Parser.java | 301 +++++++++--------- .../avm2/parser/script/PackageAVM2Item.java | 5 +- .../decompiler/flash/gui/abc/ABCPanel.java | 1 - 5 files changed, 173 insertions(+), 193 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 9722b8c8c..924c552a7 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 @@ -234,7 +234,7 @@ public class AVM2SourceGenerator implements SourceGenerator { private List generateIf(SourceGeneratorLocalData localData, GraphTargetItem expression, List onTrueCmds, List onFalseCmds, boolean ternar) throws CompilationException { List ret = new ArrayList<>(); //ret.addAll(notCondition(localData, expression)); - List onTrue = null; + List onTrue; List onFalse = null; if (ternar) { onTrue = toInsList(onTrueCmds.get(0).toSource(localData, this)); @@ -1172,7 +1172,7 @@ public class AVM2SourceGenerator implements SourceGenerator { 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); - int init = 0; + int init; if (constructor == 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*/); } else { @@ -1236,7 +1236,7 @@ public class AVM2SourceGenerator implements SourceGenerator { sinitBody.autoFillStats(abcIndex.getSelectedAbc(), initScope + (implementsStr.isEmpty() ? 0 : 1), true); classInfo.cinit_index = staticMi; - if (!isInterface) { + if (initBody != null) { initBody.autoFillStats(abcIndex.getSelectedAbc(), initScope + 1, true); } instanceInfo.interfaces = new int[implementsStr.size()]; @@ -1442,7 +1442,8 @@ public class AVM2SourceGenerator implements SourceGenerator { slotTypes.add("" + p); }*/ if (hasRest) { - slotTypes.add("*"); + registerTypes.add("Array"); + slotTypes.add("Array"); } localData.registerVars.clear(); for (AssignableAVM2Item an : subvariables) { @@ -1728,7 +1729,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } } } - if (className != null && !subMethod) { + if (!subMethod) { mbodyCode.add(0, new AVM2Instruction(0, AVM2Instructions.GetLocal0, null)); mbodyCode.add(1, new AVM2Instruction(0, AVM2Instructions.PushScope, null)); } @@ -1879,7 +1880,7 @@ public class AVM2SourceGenerator implements SourceGenerator { 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) { @@ -2120,15 +2121,16 @@ public class AVM2SourceGenerator implements SourceGenerator { traits[k] = tmgs; traits[k].metadata = generateMetadata(((MethodAVM2Item) item).metadata); - } else if (item instanceof FunctionAVM2Item) { - TraitFunction tf = new TraitFunction(); - tf.slot_id = slot_id++; - tf.kindType = Trait.TRAIT_FUNCTION; - //tf.name_index = traitName(((FunctionAVM2Item) item).namespace, ((FunctionAVM2Item) item).functionName); - ts.traits.add(tf); - traits[k] = tf; - traits[k].metadata = generateMetadata(((FunctionAVM2Item) item).metadata); - } + } /*else if (item instanceof FunctionAVM2Item) { + TraitFunction tf = new TraitFunction(); + tf.slot_id = slot_id++; + tf.kindType = Trait.TRAIT_FUNCTION; + //tf.name_index = traitName(((FunctionAVM2Item) item).namespace, ((FunctionAVM2Item) item).functionName); + ts.traits.add(tf); + traits[k] = tf; + traits[k].metadata = generateMetadata(((FunctionAVM2Item) item).metadata); + }*/ + } return traits; @@ -2267,10 +2269,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (searchPrototypeChain(protectedNs, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { return true; } - if (searchPrototypeChain(0, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc)) { - return true; - } - return false; + return searchPrototypeChain(0, instanceOnly, abc, pkg, obj, propertyName, outName, outNs, outPropNs, outPropNsKind, outPropNsIndex, outPropType, outPropValue, outPropValueAbc); } private static boolean searchPrototypeChain(int selectedNs, 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) { @@ -2380,7 +2379,7 @@ public class AVM2SourceGenerator implements SourceGenerator { TypeItem type = (TypeItem) typeItem; DottedChain dname = type.fullTypeName; - String pkg = dname.getWithoutLast().toRawString(); + DottedChain pkg = dname.getWithoutLast(); String name = dname.getLast(); /*for (InstanceInfo ii : abc.getSelectedAbc().instance_info) { Multiname mname = abc.getSelectedAbc().constants.constant_multiname.get(ii.name_index); @@ -2397,7 +2396,7 @@ public class AVM2SourceGenerator implements SourceGenerator { Multiname m = ci.abc.instance_info.get(ci.index).getName(ci.abc.constants); if (m != null) { Namespace ns = ci.abc.instance_info.get(ci.index).getName(ci.abc.constants).getNamespace(ci.abc.constants); - String n = m.getName(ci.abc.constants, new ArrayList(), true); + String n = m.getName(ci.abc.constants, new ArrayList<>(), true); String nsn = ns == null ? null : ns.getName(ci.abc.constants).toRawString(); name_index = abc.getSelectedAbc().constants.getQnameId( n, 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 602bf74ee..f4e08ffca 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 @@ -52,7 +52,7 @@ public class AbcIndexing { private AbcIndexing parent = null; - private List abcs = new ArrayList<>(); + private final List abcs = new ArrayList<>(); private ABC selectedAbc = null; @@ -114,7 +114,7 @@ public class AbcIndexing { return parent.toString() + ":" + propName + (propNsIndex > 0 ? "[ns:" + propNsIndex + "]" : ""); } - public void setPrivate(ABC abc, int propNsIndex) { + private void setPrivate(ABC abc, int propNsIndex) { this.propNsIndex = propNsIndex; this.abc = abc; } @@ -172,10 +172,7 @@ public class AbcIndexing { if (this.propNsIndex != other.propNsIndex) { return false; } - if (this.abc != other.abc) { - return false; - } - return true; + return (this.abc == other.abc); } } @@ -192,7 +189,7 @@ public class AbcIndexing { private ABC abc = null; - public void setPrivate(ABC abc, int propNsIndex) { + private void setPrivate(ABC abc, int propNsIndex) { this.propNsIndex = propNsIndex; this.abc = abc; } @@ -246,10 +243,7 @@ public class AbcIndexing { if (this.propNsIndex != other.propNsIndex) { return false; } - if (this.abc != other.abc) { - return false; - } - return true; + return (this.abc == other.abc); } } @@ -464,7 +458,7 @@ public class AbcIndexing { } if (mapNs != null) { Multiname m = abc.constants.getMultiname(t.name_index); - PropertyNsDef ndp = new PropertyNsDef(t.getName(abc).getName(abc.constants, new ArrayList<>() /*?*/, true), m == null || m.namespace_index == 0 ? DottedChain.EMPTY : m.getNamespace(abc.constants).getName(abc.constants), abc, m.namespace_index); + PropertyNsDef ndp = new PropertyNsDef(t.getName(abc).getName(abc.constants, new ArrayList<>() /*?*/, true), m == null || m.namespace_index == 0 ? DottedChain.EMPTY : m.getNamespace(abc.constants).getName(abc.constants), abc, m == null ? 0 : m.namespace_index); TraitIndex ti = new TraitIndex(t, abc, getTraitReturnType(abc, t), propValue, multinameToType(name_index, abc.constants)); if (!mapNs.containsKey(ndp)) { mapNs.put(ndp, ti); 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 ea7d47da7..8bb72e016 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 @@ -149,7 +149,7 @@ public class ActionScript3Parser { if (debugMode) { System.out.println("commands:"); } - GraphTargetItem cmd = null; + GraphTargetItem cmd; while ((cmd = command(thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, true, variables)) != null) { ret.add(cmd); } @@ -582,9 +582,33 @@ public class ActionScript3Parser { PackageAVM2Item p = parsePackage(openedNamespaces); pkg = p.packageName; inPkg = true; - publicNs = p.publicNs; + //publicNs = p.publicNs; importedClasses = p.importedClasses; s = lex(); + + //GraphTargetItem ret = null; + //ParsedSymbol s = null; + //List traits = new ArrayList<>(); + //String classNameStr = nameStr; + openedNamespaces = new ArrayList<>(openedNamespaces); + + openedNamespaces.add(publicNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, pkg, 0, true)); + //openedNamespaces.add(packageInternalNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, pkg, 0, true)); + + if (pkg != null && !pkg.isEmpty()) { + openedNamespaces.add(packageInternalNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, abcIndex.getSelectedAbc().constants.getStringId(pkg, true), 0, true)); + } else { + openedNamespaces.add(packageInternalNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, abcIndex.getSelectedAbc().constants.getStringId("", true), 0, true)); + } + if (pkg != null && !pkg.isEmpty()) { //add "" namespace if not already present + openedNamespaces.add(abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, "", 0, true)); + } + openedNamespaces.add(privateNs = abcIndex.getSelectedAbc().constants.addNamespace(new Namespace(Namespace.KIND_PRIVATE, abcIndex.getSelectedAbc().constants.getStringId(pkg == null ? "" : pkg.toRawString() + ":?"/* + nameStr*/, true)))); + + openedNamespaces.add(abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE, AS3_NAMESPACE, 0, true)); + + openedNamespaces.add(protectedNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PROTECTED, pkg == null ? (scriptName + "$0:"/*FIXME?*/ + classNameStr) : pkg.isTopLevel() ? classNameStr : pkg.toRawString() + ":" + classNameStr, 0, true)); + openedNamespaces.add(protectedStaticNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_STATIC_PROTECTED, pkg == null || pkg.isTopLevel() ? classNameStr : pkg.toRawString() + ":" + classNameStr, 0, true)); } List>> metadata = new ArrayList<>(); @@ -698,7 +722,7 @@ public class ActionScript3Parser { namespace = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE, pkg == null || pkg.isEmpty() ? classNameStr : pkg + ":" + classNameStr, 0, true); } else { if (packageInternalNs == 0) { - packageInternalNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, abcIndex.getSelectedAbc().constants.getStringId(pkg.toRawString(), true), 0, true); + packageInternalNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, abcIndex.getSelectedAbc().constants.getStringId(pkg == null ? "" : pkg.toRawString(), true), 0, true); } namespace = packageInternalNs; } @@ -712,74 +736,108 @@ public class ActionScript3Parser { traits.add(parsePackage(openedNamespaces)); break;*/ case CLASS: - List subNamespaces = new ArrayList<>(openedNamespaces); - if (classNameStr != null) { - throw new AVM2ParseException("Nested classes not supported", lexer.yyline()); - } - if (isOverride) { - throw new AVM2ParseException("Override flag not allowed for classes", lexer.yyline()); - } - - //GraphTargetItem classTypeStr = type(thisType,pkg,needsActivation, importedClasses, openedNamespaces, variables); - s = lex(); - expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); - String classTypeStr = s.value.toString(); - GraphTargetItem extendsTypeStr = null; - s = lex(); - if (s.type == SymbolType.EXTENDS) { - extendsTypeStr = type(thisType, pkg, new Reference<>(false), importedClasses, subNamespaces, new ArrayList<>()); - s = lex(); - } - List implementsTypeStrs = new ArrayList<>(); - if (s.type == SymbolType.IMPLEMENTS) { - do { - GraphTargetItem implementsTypeStr = type(thisType, pkg, new Reference<>(false), importedClasses, subNamespaces, new ArrayList<>()); - implementsTypeStrs.add(implementsTypeStr); - s = lex(); - } while (s.type == SymbolType.COMMA); - } - expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); - if (customAccess != null) { - throw new AVM2ParseException("Class cannot have custom namespace", lexer.yyline()); - } - traits.add((classTraits(metadata, scriptName, publicNs, pkg, importedClasses, isDynamic, isFinal, subNamespaces, pkg, namespace, false, classTypeStr, extendsTypeStr, implementsTypeStrs, new ArrayList<>()))); - expectedType(SymbolType.CURLY_CLOSE); - break; case INTERFACE: - if (classNameStr != null) { - throw new AVM2ParseException("Nested interfaces not supported", lexer.yyline()); - } - if (isOverride) { - throw new AVM2ParseException("Override flag not allowed for interfaces", lexer.yyline()); - } - if (isFinal) { - throw new AVM2ParseException("Final flag not allowed for interfaces", lexer.yyline()); - } - if (isDynamic) { - throw new AVM2ParseException("Dynamic flag not allowed for interfaces", lexer.yyline()); - } - //GraphTargetItem interfaceTypeStr = type(thisType,pkg,needsActivation, importedClasses, openedNamespaces, variables); - s = lex(); - expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); - String intTypeStr = s.value.toString(); - s = lex(); - List intExtendsTypeStrs = new ArrayList<>(); - if (s.type == SymbolType.EXTENDS) { - do { - GraphTargetItem intExtendsTypeStr = type(thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>()); - intExtendsTypeStrs.add(intExtendsTypeStr); + boolean nisInterface = false; + if (s.type == SymbolType.INTERFACE) { + nisInterface = true; + } + GraphTargetItem extendsTypeStr = null; + List interfaces = new ArrayList<>(); + String subNameStr = null; + List subNamespaces = new ArrayList<>(openedNamespaces); + + if (!nisInterface) { + + if (classNameStr != null) { + throw new AVM2ParseException("Nested classes not supported", lexer.yyline()); + } + if (isOverride) { + throw new AVM2ParseException("Override flag not allowed for classes", lexer.yyline()); + } + + //GraphTargetItem classTypeStr = type(thisType,pkg,needsActivation, importedClasses, openedNamespaces, variables); + s = lex(); + expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); + subNameStr = s.value.toString(); + + s = lex(); + if (s.type == SymbolType.EXTENDS) { + extendsTypeStr = type(thisType, pkg, new Reference<>(false), importedClasses, subNamespaces, new ArrayList<>()); s = lex(); - } while (s.type == SymbolType.COMMA); + } + if (s.type == SymbolType.IMPLEMENTS) { + do { + GraphTargetItem implementsTypeStr = type(thisType, pkg, new Reference<>(false), importedClasses, subNamespaces, new ArrayList<>()); + interfaces.add(implementsTypeStr); + s = lex(); + } while (s.type == SymbolType.COMMA); + } + expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); + if (customAccess != null) { + throw new AVM2ParseException("Class cannot have custom namespace", lexer.yyline()); + } + } else { + if (classNameStr != null) { + throw new AVM2ParseException("Nested interfaces not supported", lexer.yyline()); + } + if (isOverride) { + throw new AVM2ParseException("Override flag not allowed for interfaces", lexer.yyline()); + } + if (isFinal) { + throw new AVM2ParseException("Final flag not allowed for interfaces", lexer.yyline()); + } + if (isDynamic) { + throw new AVM2ParseException("Dynamic flag not allowed for interfaces", lexer.yyline()); + } + //GraphTargetItem interfaceTypeStr = type(thisType,pkg,needsActivation, importedClasses, openedNamespaces, variables); + s = lex(); + expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); + subNameStr = s.value.toString(); + s = lex(); + + if (s.type == SymbolType.EXTENDS) { + do { + GraphTargetItem intExtendsTypeStr = type(thisType, pkg, new Reference<>(false), importedClasses, subNamespaces, new ArrayList<>()); + interfaces.add(intExtendsTypeStr); + s = lex(); + } while (s.type == SymbolType.COMMA); + } + expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); + if (customAccess != null) { + throw new AVM2ParseException("Interface cannot have custom namespace", lexer.yyline()); + } + } - expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); - if (customAccess != null) { - throw new AVM2ParseException("Interface cannot have custom namespace", lexer.yyline()); + + if (extendsTypeStr != null) { + List indices = new ArrayList<>(); + List names = new ArrayList<>(); + List namespaces = new ArrayList<>(); + //FIXME for Private classes in script!!! + AVM2SourceGenerator.parentNamesAddNames(abcIndex, AVM2SourceGenerator.resolveType(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0), ((TypeItem) ((UnresolvedAVM2Item) extendsTypeStr).resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>())), abcIndex), indices, names, namespaces); + for (int i = 0; i < names.size(); i++) { + if (namespaces.get(i) == null || namespaces.get(i).isEmpty()) { + continue; + } + openedNamespaces.add(abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_STATIC_PROTECTED, namespaces.get(i) + ":" + names.get(i), 0, true)); + } } - traits.add((classTraits(metadata, scriptName, publicNs, pkg, importedClasses, false, isFinal, openedNamespaces, pkg, namespace, true, intTypeStr, null, intExtendsTypeStrs, new ArrayList<>()))); + Reference staticNeedsActivation = new Reference<>(false); + List staticInit = new ArrayList<>(); + List sinit2Variables = new ArrayList<>(); + List traits2 = new ArrayList<>(); + GraphTargetItem constr2 = traits(scriptName, false, sinit2Variables, staticNeedsActivation, staticInit, importedClasses, privateNs, protectedNs, publicNs, packageInternalNs, protectedStaticNs, subNamespaces, pkg, subNameStr, nisInterface, traits2); + + if (nisInterface) { + traits.add(new InterfaceAVM2Item(metadata, importedClasses, pkg, subNamespaces, isFinal, namespace, subNameStr, interfaces, traits2)); + } else { + traits.add(new ClassAVM2Item(metadata, importedClasses, pkg, subNamespaces, privateNs, protectedNs, isDynamic, isFinal, namespace, subNameStr, extendsTypeStr, interfaces, staticInit, staticNeedsActivation.getVal(), sinitVariables, constr2, traits2)); + } + + // traits.add((classTraits(metadata, scriptName, publicNs, pkg, importedClasses, isDynamic, isFinal, subNamespaces, pkg, namespace, false, classTypeStr, extendsTypeStr, implementsTypeStrs, new ArrayList<>()))); expectedType(SymbolType.CURLY_CLOSE); break; - case FUNCTION: if (isDynamic) { @@ -835,7 +893,10 @@ public class ActionScript3Parser { constr = (method(isPrivate, metadata, pkg, false, customAccess, new Reference<>(false), importedClasses, false, false, thisType, openedNamespaces, false, namespace, "", true, constrVariables)); } else { GraphTargetItem t; - if (classNameStr != null) { + if (classNameStr == null) { + isStatic = true; + } + { MethodAVM2Item ft = method(isPrivate, metadata, pkg, isInterface, customAccess, new Reference<>(false), importedClasses, isOverride, isFinal, thisType, openedNamespaces, isStatic, namespace, fname, true, new ArrayList<>()); if (isGetter) { @@ -865,9 +926,12 @@ public class ActionScript3Parser { t = ft; } - } else { - t = function(metadata, pkg, isInterface, new Reference(false), importedClasses, namespace, thisType, openedNamespaces, fname, false, new ArrayList()); } + //NOTE: Looks like TraitFunction does not work in FlashPlayer - use MethodTrait instead + /*else { + t = function(metadata, pkg, isInterface, new Reference(false), importedClasses, namespace, thisType, openedNamespaces, fname, false, new ArrayList()); + }*/ + traits.add(t); } //} @@ -879,7 +943,7 @@ public class ActionScript3Parser { s = lex(); expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); String nname = s.value.toString(); - String nval = ""; + String nval; s = lex(); if (s.type == SymbolType.ASSIGN) { @@ -917,7 +981,7 @@ public class ActionScript3Parser { expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); String vcname = s.value.toString(); s = lex(); - GraphTargetItem type = null; + GraphTargetItem type; if (s.type == SymbolType.COLON) { type = type(thisType, pkg, new Reference<>(false), importedClasses, openedNamespaces, new ArrayList<>()); s = lex(); @@ -963,69 +1027,6 @@ public class ActionScript3Parser { return constr; } - private GraphTargetItem classTraits(List>> metadata, String scriptName, int gpublicNs, DottedChain pkg, List importedClasses, boolean isDynamic, boolean isFinal, List openedNamespaces, DottedChain packageName, int namespace, boolean isInterface, String nameStr, GraphTargetItem extendsStr, List implementsStr, List variables) throws IOException, AVM2ParseException, CompilationException { - - GraphTargetItem ret = null; - - ParsedSymbol s = null; - List traits = new ArrayList<>(); - - String classNameStr = nameStr; - - openedNamespaces = new ArrayList<>(openedNamespaces); - - int publicNs = 0; - int privateNs = 0; - int packageInternalNs = 0; - if (pkg != null && !pkg.isEmpty()) { - openedNamespaces.add(packageInternalNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, abcIndex.getSelectedAbc().constants.getStringId(pkg, true), 0, true)); - } else { - openedNamespaces.add(packageInternalNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE_INTERNAL, abcIndex.getSelectedAbc().constants.getStringId("", true), 0, true)); - } - if (pkg != null && !pkg.isEmpty()) { - openedNamespaces.add(publicNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, "", 0, true)); - } else { - publicNs = gpublicNs; - } - - openedNamespaces.add(privateNs = abcIndex.getSelectedAbc().constants.addNamespace(new Namespace(Namespace.KIND_PRIVATE, abcIndex.getSelectedAbc().constants.getStringId(pkg.toRawString() + ":" + nameStr, true)))); - - openedNamespaces.add(abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE, AS3_NAMESPACE, 0, true)); - - //int privateNs = 0; - int protectedNs = 0; - //int publicNs = namespace; - int protectedStaticNs = 0; - - openedNamespaces.add(protectedNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PROTECTED, packageName == null ? (scriptName + "$0:"/*FIXME?*/ + classNameStr) : packageName.isTopLevel() ? classNameStr : packageName.toRawString() + ":" + classNameStr, 0, true)); - openedNamespaces.add(protectedStaticNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_STATIC_PROTECTED, packageName == null || packageName.isTopLevel() ? classNameStr : packageName.toRawString() + ":" + classNameStr, 0, true)); - - if (extendsStr != null) { - List indices = new ArrayList<>(); - List names = new ArrayList<>(); - List namespaces = new ArrayList<>(); - //FIXME for Private classes in script!!! - AVM2SourceGenerator.parentNamesAddNames(abcIndex, AVM2SourceGenerator.resolveType(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0), ((TypeItem) ((UnresolvedAVM2Item) extendsStr).resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>())), abcIndex), indices, names, namespaces); - for (int i = 0; i < names.size(); i++) { - if (namespaces.get(i) == null || namespaces.get(i).isEmpty()) { - continue; - } - openedNamespaces.add(abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_STATIC_PROTECTED, namespaces.get(i) + ":" + names.get(i), 0, true)); - } - } - - Reference staticNeedsActivation = new Reference<>(false); - List staticInit = new ArrayList<>(); - List sinitVariables = new ArrayList<>(); - GraphTargetItem constr = traits(scriptName, false, sinitVariables, staticNeedsActivation, staticInit, importedClasses, privateNs, protectedNs, publicNs, packageInternalNs, protectedStaticNs, openedNamespaces, packageName, classNameStr, isInterface, traits); - - if (isInterface) { - return new InterfaceAVM2Item(metadata, importedClasses, packageName, openedNamespaces, isFinal, namespace, classNameStr, implementsStr, traits); - } else { - return new ClassAVM2Item(metadata, importedClasses, packageName, openedNamespaces, privateNs, protectedNs, isDynamic, isFinal, namespace, classNameStr, extendsStr, implementsStr, staticInit, staticNeedsActivation.getVal(), sinitVariables, constr, traits); - } - } - private GraphTargetItem expressionCommands(ParsedSymbol s, HashMap registerVars, boolean inFunction, boolean inMethod, int forinlevel, List variables) throws IOException, AVM2ParseException { GraphTargetItem ret = null; switch (s.type) { @@ -1124,7 +1125,7 @@ public class ActionScript3Parser { } private List xmltag(TypeItem thisType, DottedChain pkg, Reference usesVars, List openedTags, Reference closedVarTags, Reference needsActivation, List importedClasses, List openedNamespaces, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException { - ParsedSymbol s = null; + ParsedSymbol s; List rets = new ArrayList<>(); //GraphTargetItem ret = null; StringBuilder sb = new StringBuilder(); @@ -1350,7 +1351,7 @@ public class ActionScript3Parser { s = lexer.lex(); expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); needsActivation.setVal(true); - ret = (function(new ArrayList>>(), pkg, false, needsActivation, importedClasses, 0/*?*/, thisType, openedNamespaces, s.value.toString(), false, variables)); + ret = (function(new ArrayList<>(), pkg, false, needsActivation, importedClasses, 0/*?*/, thisType, openedNamespaces, s.value.toString(), false, variables)); break; case VAR: s = lex(); @@ -1541,10 +1542,8 @@ public class ActionScript3Parser { List valueMapping = new ArrayList<>(); int pos = 0; while (s.type == SymbolType.CASE) { - List caseExprs = new ArrayList<>(); while (s.type == SymbolType.CASE) { GraphTargetItem curCaseExpr = expression(thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables); - caseExprs.add(curCaseExpr); expectedType(SymbolType.COLON); s = lex(); caseExprsAll.add(curCaseExpr); @@ -1664,7 +1663,7 @@ public class ActionScript3Parser { for (AssignableAVM2Item a : catchVars) { if (a instanceof UnresolvedAVM2Item) { UnresolvedAVM2Item ui = (UnresolvedAVM2Item) a; - if (ui.getVariableName().equals(e.getVariableName())) { + if (ui.getVariableName().equals(DottedChain.parse(e.getVariableName()))) { try { ui.resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables); } catch (CompilationException ex) { @@ -1687,7 +1686,7 @@ public class ActionScript3Parser { if (av instanceof UnresolvedAVM2Item) { UnresolvedAVM2Item ui = (UnresolvedAVM2Item) av; for (NameAVM2Item e : catchExceptions) { - if (ui.getVariableName().equals(e.getVariableName())) { + if (ui.getVariableName().equals(DottedChain.parse(e.getVariableName()))) { try { ui.resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables); } catch (CompilationException ex) { @@ -1773,10 +1772,7 @@ public class ActionScript3Parser { if (item instanceof PropertyAVM2Item) { return true; } - if (item instanceof IndexAVM2Item) { - return true; - } - return false; + return (item instanceof IndexAVM2Item); } private boolean isType(GraphTargetItem item) { @@ -1786,10 +1782,7 @@ public class ActionScript3Parser { while (item instanceof GetPropertyAVM2Item) { item = ((GetPropertyAVM2Item) item).object; } - if (item instanceof NameAVM2Item) { - return true; - } - return false; + return (item instanceof NameAVM2Item); } private int brackets(TypeItem thisType, DottedChain pkg, Reference needsActivation, List importedClasses, List openedNamespaces, List ret, HashMap registerVars, boolean inFunction, boolean inMethod, List variables) throws IOException, AVM2ParseException { @@ -2257,7 +2250,7 @@ public class ActionScript3Parser { lexer.pushback(s); } needsActivation.setVal(true); - ret = function(new ArrayList>>(), pkg, false, needsActivation, importedClasses, 0/*?*/, thisType, openedNamespaces, ffname, false, variables); + ret = function(new ArrayList<>(), pkg, false, needsActivation, importedClasses, 0/*?*/, thisType, openedNamespaces, ffname, false, variables); } else if (s.type == SymbolType.LOWER_THAN) { GraphTargetItem subtype = type(thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables); expectedType(SymbolType.GREATER_THAN); @@ -2376,19 +2369,17 @@ public class ActionScript3Parser { } List importedClasses = parseImports(openedNamespaces); - int publicNs; - openedNamespaces.add(publicNs = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, name, 0, true)); //traits(false, new ArrayList(), new Reference(false), new ArrayList(), importedClasses, privateNs, 0, publicNs, packageInternalNs, 0, openedNamespaces, name, null, false, items); //expectedType(SymbolType.CURLY_CLOSE); - return new PackageAVM2Item(publicNs, importedClasses, name, items); + return new PackageAVM2Item(importedClasses, name, items); } private List parseScript(String fileName) throws IOException, AVM2ParseException, CompilationException { List openedNamespaces = new ArrayList<>(); - int scriptPrivateNs = 0; + int scriptPrivateNs; if (fileName.contains("/")) { fileName = fileName.substring(fileName.lastIndexOf('/') + 1); @@ -2396,10 +2387,10 @@ 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); - } + /*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; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java index 7f43c043a..16382c122 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PackageAVM2Item.java @@ -37,11 +37,8 @@ public class PackageAVM2Item extends AVM2Item { public List importedClasses = new ArrayList<>(); - public int publicNs = 0; - - public PackageAVM2Item(int publicNs, List importedClasses, DottedChain packageName, List items) { + public PackageAVM2Item(List importedClasses, DottedChain packageName, List items) { super(null, NOPRECEDENCE); - this.publicNs = publicNs; this.importedClasses = importedClasses; this.items = items; this.packageName = packageName; diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 63d81cd8e..3ff0a1dc0 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -748,7 +748,6 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener