Added AS3 Display missing namespaces along traits as §§namespace("url")

Added #1892 AS3 option to select SWF dependencies to properly resolve namespaces, types, etc. (currently in GUI only)
Fixed AS3 P-code ValueKind namespaces handling
Fixed AS3 direct editation - namespace definition without explicit value
This commit is contained in:
Jindra Petřík
2023-03-05 15:31:46 +01:00
parent f24453d525
commit dc2dc32fee
25 changed files with 533 additions and 77 deletions

View File

@@ -398,7 +398,10 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
@Internal
private AbcIndexing abcIndex;
private int numAbcIndexDependencies = 0;
private static AbcIndexing playerGlobalAbcIndex;
private static AbcIndexing airGlobalAbcIndex;
@@ -460,6 +463,24 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
return abcIndex;
}
public int getNumAbcIndexDependencies() {
return numAbcIndexDependencies;
}
public void setAbcIndexDependencies(List<SWF> swfs) {
abcIndex = null;
getAbcIndex();
for (SWF swf:swfs) {
for (Tag tag:swf.tags) {
if (tag instanceof ABCContainerTag) {
abcIndex.addAbc(((ABCContainerTag)tag).getABC());
}
}
}
abcIndex.rebuildPkgToObjectsNameMap();
numAbcIndexDependencies = swfs.size();
}
public static void initPlayer() throws IOException, InterruptedException {
if (playerGlobalAbcIndex == null) {
/*if (Configuration.getPlayerSWC() == null) {

View File

@@ -2222,7 +2222,10 @@ public class ABC implements Openable {
String name = constants.getString(ns.name_index);
if (name.equals("http://adobe.com/AS3/2006/builtin")) { //TODO: This should really be resolved using ABC indexing, not hardcoded constant
return DottedChain.parseNoSuffix("AS3");
}
}
return getSwf().getAbcIndex().nsValueToName(name);
/*
for (ABCContainerTag abcTag : getAbcTags()) {
DottedChain dc = abcTag.getABC().nsValueToName(name);
nsname = dc.getLast();
@@ -2233,8 +2236,8 @@ public class ABC implements Openable {
if (!nsname.isEmpty()) {
return dc;
}
}
return null;
}*/
//return null;
}
public void clearPacksCache() {

View File

@@ -633,8 +633,9 @@ public class ASM3Parser {
value_kind = ValueKind.CONSTANT_PackageNamespace;
break;
}
lexer.pushback(type);
expected(ParsedSymbol.TYPE_PARENT_OPEN, "(", lexer);
value_index = parseNamespace(constants, lexer);
expected(ParsedSymbol.TYPE_PARENT_CLOSE, ")", lexer);
break;
default:
if (Configuration._debugMode.get()) {

View File

@@ -1875,7 +1875,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
for (int i = 0; i < paramValues.size(); i++) {
optional[i] = getValueKind(Namespace.KIND_NAMESPACE/*FIXME*/, paramTypes.get(paramTypes.size() - paramValues.size() + i), paramValues.get(i));
optional[i] = getValueKind(Namespace.KIND_NAMESPACE/*FIXME*/, paramTypes.get(paramTypes.size() - paramValues.size() + i), paramValues.get(i), false);
if (optional[i] == null) {
throw new CompilationException("Default value must be compiletime constant", line);
}
@@ -2059,7 +2059,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
return mindex;
}
public ValueKind getValueKind(int ns, GraphTargetItem type, GraphTargetItem val) {
public ValueKind getValueKind(int ns, GraphTargetItem type, GraphTargetItem val, boolean generatedNs) {
if (val instanceof BooleanAVM2Item) {
BooleanAVM2Item bi = (BooleanAVM2Item) val;
@@ -2084,7 +2084,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
if (val instanceof StringAVM2Item) {
StringAVM2Item sval = (StringAVM2Item) val;
if (isNs) {
return new ValueKind(namespace(Namespace.KIND_NAMESPACE, sval.getValue()), ValueKind.CONSTANT_Namespace);
return new ValueKind(namespace(generatedNs ? Namespace.KIND_PACKAGE_INTERNAL : Namespace.KIND_NAMESPACE, sval.getValue()), ValueKind.CONSTANT_Namespace);
} else {
return new ValueKind(str(sval.getValue()), ValueKind.CONSTANT_Utf8);
}
@@ -2394,8 +2394,10 @@ public class AVM2SourceGenerator implements SourceGenerator {
namespace = sai.pkg == null ? 0 : sai.pkg.getCpoolIndex(abcIndex);
metadata = generateMetadata(((SlotAVM2Item) item).metadata);
}
boolean generatedNs = false;
if (item instanceof ConstAVM2Item) {
ConstAVM2Item cai = (ConstAVM2Item) item;
generatedNs = cai.generatedNs;
if (cai.isStatic() != generateStatic) {
continue;
}
@@ -2415,7 +2417,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
}
tsc.type_index = isNamespace ? 0 : (type == null ? 0 : typeName(localData, type));
ValueKind vk = getValueKind(namespace, type, val);
ValueKind vk = getValueKind(namespace, type, val, generatedNs);
if (vk == null) {
tsc.value_index = ValueKind.CONSTANT_Undefined;
tsc.value_kind = ValueKind.CONSTANT_Undefined;

View File

@@ -83,6 +83,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.operations.SubtractAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.TypeOfAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.URShiftAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.SymbolType.PREPROCESSOR;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
@@ -648,6 +649,7 @@ public class ActionScript3Parser {
boolean isPrivate = false;
String customNs = null;
String rawCustomNs = null;
NamespaceItem namespace = null;
ParsedSymbol s = lex();
//static class initializer
@@ -660,7 +662,7 @@ public class ActionScript3Parser {
List<Map.Entry<String, Map<String, String>>> metadata = parseMetadata();
s = lex();
while (s.isType(SymbolType.STATIC, SymbolType.PUBLIC, SymbolType.PRIVATE, SymbolType.PROTECTED, SymbolType.OVERRIDE, SymbolType.FINAL, SymbolType.DYNAMIC, SymbolGroup.IDENTIFIER, SymbolType.INTERNAL)) {
while (s.isType(SymbolType.STATIC, SymbolType.PUBLIC, SymbolType.PRIVATE, SymbolType.PROTECTED, SymbolType.OVERRIDE, SymbolType.FINAL, SymbolType.DYNAMIC, SymbolGroup.IDENTIFIER, SymbolType.INTERNAL, SymbolType.PREPROCESSOR)) {
if (s.type == SymbolType.FINAL) {
if (isFinal) {
throw new AVM2ParseException("Only one final keyword allowed", lexer.yyline());
@@ -714,6 +716,19 @@ public class ActionScript3Parser {
case INTERNAL:
namespace = packageInternalNs;
break;
case PREPROCESSOR:
if (((String)s.value).toLowerCase().equals("namespace")) {
expectedType(SymbolType.PARENT_OPEN);
s = lex();
expected(s, lexer.yyline(), SymbolType.STRING);
namespace = new NamespaceItem((String)s.value, Namespace.KIND_NAMESPACE);
expectedType(SymbolType.PARENT_CLOSE);
} else {
lexer.pushback(s);
}
break;
}
s = lex();
}
@@ -725,7 +740,7 @@ public class ActionScript3Parser {
}
if (namespace == null && customNs != null) {
//Special: it will be resolved later:
namespace = new NamespaceItem(customNs, Namespace.KIND_NAMESPACE);
namespace = new NamespaceItem(customNs, NamespaceItem.KIND_NAMESPACE_CUSTOM);
}
switch (s.type) {
@@ -833,6 +848,7 @@ public class ActionScript3Parser {
String nval;
s = lex();
boolean generatedNs = false;
if (s.type == SymbolType.ASSIGN) {
s = lex();
expected(s, lexer.yyline(), SymbolType.STRING);
@@ -840,12 +856,13 @@ public class ActionScript3Parser {
s = lex();
} else {
nval = (pkg.name.toRawString() + ":" + classNameStr) + "/" + nname;
generatedNs = true;
}
if (s.type != SymbolType.SEMICOLON) {
lexer.pushback(s);
}
ConstAVM2Item ns = new ConstAVM2Item(metadata, namespace, customNs, true, nname, new TypeItem(DottedChain.NAMESPACE), new StringAVM2Item(null, null, nval), lexer.yyline());
ConstAVM2Item ns = new ConstAVM2Item(metadata, namespace, customNs, true, nname, new TypeItem(DottedChain.NAMESPACE), new StringAVM2Item(null, null, nval), lexer.yyline(), generatedNs);
traits.add(ns);
break;
case CONST:
@@ -887,7 +904,7 @@ public class ActionScript3Parser {
}
GraphTargetItem tar;
if (isConst) {
tar = new ConstAVM2Item(metadata, namespace, customNs, isStatic, vcname, type, value, lexer.yyline());
tar = new ConstAVM2Item(metadata, namespace, customNs, isStatic, vcname, type, value, lexer.yyline(), false);
} else {
tar = new SlotAVM2Item(metadata, namespace, customNs, isStatic, vcname, type, value, lexer.yyline());
}
@@ -1111,7 +1128,7 @@ public class ActionScript3Parser {
}
GraphTargetItem tar;
if (isConst) {
tar = new ConstAVM2Item(metadata, ns, null, false, vcname, type, value, lexer.yyline());
tar = new ConstAVM2Item(metadata, ns, null, false, vcname, type, value, lexer.yyline(), false);
} else {
tar = new SlotAVM2Item(metadata, ns, null, false, vcname, type, value, lexer.yyline());
}
@@ -1131,19 +1148,21 @@ public class ActionScript3Parser {
String nval;
s = lex();
boolean generatedNs = false;
if (s.type == SymbolType.ASSIGN) {
s = lex();
expected(s, lexer.yyline(), SymbolType.STRING);
nval = s.value.toString();
s = lex();
} else {
nval = ns + "/" + nname;
generatedNs = true;
nval = ns.name.toRawString() + ":" + nname;
}
if (s.type != SymbolType.SEMICOLON) {
lexer.pushback(s);
}
traits.add(new ConstAVM2Item(metadata, ns, null, true, nname, new TypeItem(DottedChain.NAMESPACE), new StringAVM2Item(null, null, nval), lexer.yyline()));
traits.add(new ConstAVM2Item(metadata, ns, null, true, nname, new TypeItem(DottedChain.NAMESPACE), new StringAVM2Item(null, null, nval), lexer.yyline(), generatedNs));
break;
default:
lexer.pushback(s);

View File

@@ -42,12 +42,14 @@ public class ConstAVM2Item extends AVM2Item {
public int line;
public NamespaceItem pkg;
public boolean generatedNs;
public boolean isStatic() {
return isStatic;
}
public ConstAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, String customNamespace, boolean isStatic, String var, GraphTargetItem type, GraphTargetItem value, int line) {
public ConstAVM2Item(List<Map.Entry<String, Map<String, String>>> metadata, NamespaceItem pkg, String customNamespace, boolean isStatic, String var, GraphTargetItem type, GraphTargetItem value, int line, boolean generatedNs) {
super(null, null, NOPRECEDENCE, value);
this.metadata = metadata;
@@ -57,6 +59,7 @@ public class ConstAVM2Item extends AVM2Item {
this.var = var;
this.type = type;
this.customNamespace = customNamespace;
this.generatedNs = generatedNs;
}
@Override

View File

@@ -34,6 +34,8 @@ import java.util.Objects;
*/
public class NamespaceItem {
public static final int KIND_NAMESPACE_CUSTOM = -2;
public DottedChain name;
public int kind;
@@ -89,6 +91,9 @@ public class NamespaceItem {
return;
}
if (kind == Namespace.KIND_NAMESPACE) {
nsIndex = abcIndex.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_NAMESPACE, name, 0, true);
}
if (kind == KIND_NAMESPACE_CUSTOM) {
String custom = name.toRawString();
PropertyAVM2Item prop = new PropertyAVM2Item(null, false, custom, "", abcIndex, openedNamespaces, new ArrayList<>());
Reference<ValueKind> value = new Reference<>(null);
@@ -125,7 +130,7 @@ public class NamespaceItem {
}
}
throw new CompilationException("Namespace \"" + name + "\"+not defined", -1);
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);

View File

@@ -158,7 +158,7 @@ public class ValueKind {
case CONSTANT_Undefined:
ret = "undefined";
break;
case CONSTANT_Namespace:
case CONSTANT_Namespace:
case CONSTANT_PackageInternalNs:
case CONSTANT_ProtectedNamespace:
case CONSTANT_ExplicitNamespace:
@@ -200,13 +200,34 @@ public class ValueKind {
case CONSTANT_Undefined:
ret = "Undefined()"; //"Void()" is also synonym
break;
case CONSTANT_Namespace:
case CONSTANT_Namespace:
case CONSTANT_PackageInternalNs:
case CONSTANT_ProtectedNamespace:
case CONSTANT_ExplicitNamespace:
case CONSTANT_StaticProtectedNs:
case CONSTANT_PrivateNs:
ret = constants.getNamespace(value_index).getKindStr() + "(\"" + constants.getNamespace(value_index).getName(constants).toRawString() + "\")"; //assume not null name
case CONSTANT_PrivateNs:
String nsVal = constants.getNamespace(value_index).getKindStr() + "(\"" + constants.getNamespace(value_index).getName(constants).toRawString() + "\")"; //assume not null name
switch (value_kind) {
case CONSTANT_Namespace:
ret = "Namespace(" + nsVal + ")";
break;
case CONSTANT_PackageInternalNs:
ret = "PackageInternalNs(" + nsVal + ")";
break;
case CONSTANT_ProtectedNamespace:
ret = "ProtectedNamespace(" + nsVal + ")";
break;
case CONSTANT_ExplicitNamespace:
ret = "ExplicitNamespace(" + nsVal + ")";
break;
case CONSTANT_StaticProtectedNs:
ret = "StaticProtectedNs(" + nsVal + ")";
break;
case CONSTANT_PrivateNs:
ret = "PrivateNamespace(" + nsVal + ")";
break;
}
break;
}
return ret;

View File

@@ -171,14 +171,14 @@ public abstract class Trait implements Cloneable, Serializable {
return getName(abc).getNamespace(abc.constants).getName(abc.constants);
}
public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String ignoredCustom, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
public void getDependencies(AbcIndexing abcIndex, int scriptIndex, int classIndex, boolean isStatic, String ignoredCustom, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
if (ignoredCustom == null) {
Namespace n = getName(abc).getNamespace(abc.constants);
if (n.kind == Namespace.KIND_NAMESPACE) {
ignoredCustom = n.getName(abc.constants).toRawString();
}
}
DependencyParser.parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, getName(abc), ignorePackage, fullyQualifiedNames, DependencyType.NAMESPACE);
DependencyParser.parseDependenciesFromMultiname(abcIndex, ignoredCustom, abc, dependencies, getName(abc), ignorePackage, fullyQualifiedNames, DependencyType.NAMESPACE);
//DependencyParser.parseUsagesFromMultiname(ignoredCustom, abc, dependencies, getName(abc), ignorePackage, fullyQualifiedNames, DependencyType.NAMESPACE);
}
@@ -214,7 +214,7 @@ public abstract class Trait implements Cloneable, Serializable {
if (ns.kind == Namespace.KIND_NAMESPACE) {
customNs = ns.getName(abc.constants).toRawString();
}
getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, new ArrayList<>());
getDependencies(abcIndex, scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, new ArrayList<>());
List<DottedChain> imports = new ArrayList<>();
for (Dependency d : dependencies) {
@@ -349,7 +349,11 @@ public abstract class Trait implements Cloneable, Serializable {
Namespace ns = m.getNamespace(abc.constants);
if (nsname != null) {
if (ns.kind == Namespace.KIND_NAMESPACE && nsname == null) {
writer.append("§§namespace(\"");
writer.append(Helper.escapeActionScriptString(ns.getRawName(abc.constants)));
writer.append("\") ");
} else if (nsname != null) {
String identifier = IdentifiersDeobfuscation.printIdentifier(true, nsname);
if (identifier != null && !identifier.isEmpty()) {
writer.appendNoHilight(identifier).appendNoHilight(" ");

View File

@@ -78,31 +78,31 @@ public class TraitClass extends Trait implements TraitWithSlot {
}
@Override
public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
super.getDependencies(scriptIndex, -1, false, customNs, abc, dependencies, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames);
public void getDependencies(AbcIndexing abcIndex, int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
super.getDependencies(abcIndex, scriptIndex, -1, false, customNs, abc, dependencies, 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
//DependencyParser.parseDependenciesFromMultiname(customNs, abc, dependencies, uses, abc.constants.getMultiname(instanceInfo.name_index), packageName, fullyQualifiedNames);
if (instanceInfo.super_index > 0) {
DependencyParser.parseDependenciesFromMultiname(customNs, abc, dependencies, abc.constants.getMultiname(instanceInfo.super_index), packageName, fullyQualifiedNames, DependencyType.INHERITANCE);
DependencyParser.parseDependenciesFromMultiname(abcIndex, customNs, abc, dependencies, abc.constants.getMultiname(instanceInfo.super_index), packageName, fullyQualifiedNames, DependencyType.INHERITANCE);
}
for (int i : instanceInfo.interfaces) {
DependencyParser.parseDependenciesFromMultiname(customNs, abc, dependencies, abc.constants.getMultiname(i), packageName, fullyQualifiedNames, DependencyType.INHERITANCE);
DependencyParser.parseDependenciesFromMultiname(abcIndex, customNs, abc, dependencies, abc.constants.getMultiname(i), packageName, fullyQualifiedNames, DependencyType.INHERITANCE);
}
//static
classInfo.static_traits.getDependencies(scriptIndex, class_info, true, customNs, abc, dependencies, packageName, fullyQualifiedNames);
classInfo.static_traits.getDependencies(abcIndex, scriptIndex, class_info, true, customNs, abc, dependencies, packageName, fullyQualifiedNames);
//static initializer
DependencyParser.parseDependenciesFromMethodInfo(null, scriptIndex, class_info, true, customNs, abc, classInfo.cinit_index, dependencies, packageName, fullyQualifiedNames, new ArrayList<>());
DependencyParser.parseDependenciesFromMethodInfo(abcIndex, null, scriptIndex, class_info, true, customNs, abc, classInfo.cinit_index, dependencies, packageName, fullyQualifiedNames, new ArrayList<>());
//instance
instanceInfo.instance_traits.getDependencies(scriptIndex, class_info, false, customNs, abc, dependencies, packageName, fullyQualifiedNames);
instanceInfo.instance_traits.getDependencies(abcIndex, scriptIndex, class_info, false, customNs, abc, dependencies, packageName, fullyQualifiedNames);
//instance initializer
DependencyParser.parseDependenciesFromMethodInfo(null, scriptIndex, class_info, false, customNs, abc, instanceInfo.iinit_index, dependencies, packageName, fullyQualifiedNames, new ArrayList<>());
DependencyParser.parseDependenciesFromMethodInfo(abcIndex, null, scriptIndex, class_info, false, customNs, abc, instanceInfo.iinit_index, dependencies, packageName, fullyQualifiedNames, new ArrayList<>());
}
@Override

View File

@@ -133,14 +133,14 @@ public class TraitFunction extends Trait implements TraitWithSlot {
}
@Override
public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
public void getDependencies(AbcIndexing abcIndex, int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
if (ignorePackage == null) {
ignorePackage = getPackage(abc);
}
super.getDependencies(scriptIndex, classIndex, false, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
super.getDependencies(abcIndex, scriptIndex, classIndex, false, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
//if (method_info != 0)
{
DependencyParser.parseDependenciesFromMethodInfo(this, scriptIndex, classIndex, false, customNs, abc, method_info, dependencies, ignorePackage, fullyQualifiedNames, new ArrayList<>());
DependencyParser.parseDependenciesFromMethodInfo(abcIndex, this, scriptIndex, classIndex, false, customNs, abc, method_info, dependencies, ignorePackage, fullyQualifiedNames, new ArrayList<>());
}
}

View File

@@ -63,11 +63,11 @@ public class TraitMethodGetterSetter extends Trait {
}
@Override
public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
public void getDependencies(AbcIndexing abcIndex, int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
if (ignorePackage == null) {
ignorePackage = getPackage(abc);
}
super.getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
super.getDependencies(abcIndex, scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
if (customNs == null) {
Namespace n = getName(abc).getNamespace(abc.constants);
@@ -77,7 +77,7 @@ public class TraitMethodGetterSetter extends Trait {
}
//if (method_info != 0)
{
DependencyParser.parseDependenciesFromMethodInfo(this, scriptIndex, classIndex, isStatic, customNs, abc, method_info, dependencies, ignorePackage, fullyQualifiedNames, new ArrayList<>());
DependencyParser.parseDependenciesFromMethodInfo(abcIndex, this, scriptIndex, classIndex, isStatic, customNs, abc, method_info, dependencies, ignorePackage, fullyQualifiedNames, new ArrayList<>());
}
}

View File

@@ -221,12 +221,12 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
}
@Override
public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
public void getDependencies(AbcIndexing abcIndex, int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
if (ignorePackage == null) {
ignorePackage = getPackage(abc);
}
super.getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
DependencyParser.parseDependenciesFromMultiname(customNs, abc, dependencies, abc.constants.getMultiname(type_index), getPackage(abc), fullyQualifiedNames, DependencyType.SIGNATURE);
super.getDependencies(abcIndex, scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
DependencyParser.parseDependenciesFromMultiname(abcIndex, customNs, abc, dependencies, abc.constants.getMultiname(type_index), getPackage(abc), fullyQualifiedNames, DependencyType.SIGNATURE);
}
@Override

View File

@@ -298,9 +298,9 @@ public class Traits implements Cloneable, Serializable {
}
}
public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
public void getDependencies(AbcIndexing abcIndex, int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames) throws InterruptedException {
for (Trait t : traits) {
t.getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
t.getDependencies(abcIndex, scriptIndex, classIndex, isStatic, customNs, abc, dependencies, ignorePackage, fullyQualifiedNames);
}
}

View File

@@ -10,4 +10,5 @@ public class CustomConfigurationKeys {
public static final String KEY_CHARSET = "charset";
public static final String KEY_LIBRARY = "library";
public static final String KEY_LOADED_IMPORT_ASSETS = "loadedImportAssets";
public static final String KEY_ABC_DEPENDENCIES = "abcDependencies";
}

View File

@@ -33,6 +33,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.other.SetSuperIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.AsTypeIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceIns;
import com.jpexs.decompiler.flash.abc.avm2.model.InitVectorAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing;
import com.jpexs.decompiler.flash.abc.types.ABCException;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.Multiname;
@@ -40,29 +41,26 @@ import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.abc.types.NamespaceSet;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.graph.DottedChain;
import java.util.List;
public class DependencyParser {
public static void parseDependenciesFromNS(String ignoredCustom, ABC abc, List<Dependency> dependencies, int namespace_index, DottedChain ignorePackage, String name, DependencyType dependencyType) {
public static void parseDependenciesFromNS(AbcIndexing abcIndex, String ignoredCustom, ABC abc, List<Dependency> dependencies, int namespace_index, DottedChain ignorePackage, String name, DependencyType dependencyType) {
Namespace ns = abc.constants.getNamespace(namespace_index);
if (name.isEmpty()) {
name = "*";
}
DottedChain newimport = ns.getName(abc.constants);
if (ns.kind == Namespace.KIND_NAMESPACE || ns.kind == Namespace.KIND_PACKAGE_INTERNAL) {
String nsVal = ns.getName(abc.constants).toRawString();
for (ABCContainerTag abcTag : abc.getAbcTags()) {
DottedChain nsimport = abcTag.getABC().nsValueToName(nsVal);
DottedChain nsimport = abcIndex.nsValueToName(nsVal);
if (nsimport != null) {
if (nsimport.equals(AVM2Deobfuscation.BUILTIN)) {
return; //builtin, no dependency
}
if (!nsimport.isEmpty()) {
Dependency depNs = new Dependency(nsimport, DependencyType.NAMESPACE);
if ((ignorePackage == null || !nsimport.getWithoutLast().equals(ignorePackage)) && !dependencies.contains(depNs)) {
dependencies.add(depNs);
@@ -74,7 +72,7 @@ public class DependencyParser {
}
}
}
if (ns.kind != Namespace.KIND_PACKAGE) { // && (ns.kind != Namespace.KIND_PACKAGE_INTERNAL)) {
return;
}
@@ -93,15 +91,15 @@ public class DependencyParser {
//}
}
public static void parseDependenciesFromMultiname(String ignoredCustom, ABC abc, List<Dependency> dependencies, Multiname m, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames, DependencyType dependencyType) {
public static void parseDependenciesFromMultiname(AbcIndexing abcIndex, String ignoredCustom, ABC abc, List<Dependency> dependencies, Multiname m, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames, DependencyType dependencyType) {
if (m != null) {
if (m.kind == Multiname.TYPENAME) {
if (m.qname_index != 0) {
parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames, dependencyType);
parseDependenciesFromMultiname(abcIndex, ignoredCustom, abc, dependencies, abc.constants.getMultiname(m.qname_index), ignorePackage, fullyQualifiedNames, dependencyType);
}
for (Integer i : m.params) {
if (i != 0) {
parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames, dependencyType);
parseDependenciesFromMultiname(abcIndex, ignoredCustom, abc, dependencies, abc.constants.getMultiname(i), ignorePackage, fullyQualifiedNames, dependencyType);
}
}
return;
@@ -110,35 +108,35 @@ public class DependencyParser {
String name = m.getName(abc.constants, fullyQualifiedNames, true, true);
NamespaceSet nss = m.getNamespaceSet(abc.constants);
if (ns != null) {
parseDependenciesFromNS(ignoredCustom, abc, dependencies, m.namespace_index, ignorePackage, name, dependencyType);
parseDependenciesFromNS(abcIndex, ignoredCustom, abc, dependencies, m.namespace_index, ignorePackage, name, dependencyType);
}
if (nss != null) {
for (int n : nss.namespaces) {
parseDependenciesFromNS(ignoredCustom, abc, dependencies, n, ignorePackage, nss.namespaces.length > 1 ? "" : name, dependencyType);
parseDependenciesFromNS(abcIndex, ignoredCustom, abc, dependencies, n, ignorePackage, nss.namespaces.length > 1 ? "" : name, dependencyType);
}
}
}
}
public static void parseDependenciesFromMethodInfo(Trait trait, int scriptIndex, int classIndex, boolean isStatic, String ignoredCustom, ABC abc, int method_index, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames, List<Integer> visitedMethods) throws InterruptedException {
public static void parseDependenciesFromMethodInfo(AbcIndexing abcIndex, Trait trait, int scriptIndex, int classIndex, boolean isStatic, String ignoredCustom, ABC abc, int method_index, List<Dependency> dependencies, DottedChain ignorePackage, List<DottedChain> fullyQualifiedNames, List<Integer> visitedMethods) throws InterruptedException {
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) {
parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, abc.constants.getMultiname(abc.method_info.get(method_index).ret_type), ignorePackage, fullyQualifiedNames, DependencyType.SIGNATURE);
parseDependenciesFromMultiname(abcIndex, ignoredCustom, abc, dependencies, abc.constants.getMultiname(abc.method_info.get(method_index).ret_type), ignorePackage, fullyQualifiedNames, DependencyType.SIGNATURE);
}
for (int t : abc.method_info.get(method_index).param_types) {
if (t != 0) {
parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, abc.constants.getMultiname(t), ignorePackage, fullyQualifiedNames, DependencyType.SIGNATURE);
parseDependenciesFromMultiname(abcIndex, ignoredCustom, abc, dependencies, abc.constants.getMultiname(t), ignorePackage, fullyQualifiedNames, DependencyType.SIGNATURE);
}
}
MethodBody body = abc.findBody(method_index);
if (body != null && body.convertException == null) {
body = body.convertMethodBodyCanUseLast(Configuration.autoDeobfuscate.get(), "", isStatic, scriptIndex, classIndex, abc, trait);
body.traits.getDependencies(scriptIndex, classIndex, isStatic, ignoredCustom, abc, dependencies, ignorePackage, fullyQualifiedNames);
body.traits.getDependencies(abcIndex, scriptIndex, classIndex, isStatic, ignoredCustom, abc, dependencies, ignorePackage, fullyQualifiedNames);
for (ABCException ex : body.exceptions) {
parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, abc.constants.getMultiname(ex.type_index), ignorePackage, fullyQualifiedNames, DependencyType.EXPRESSION /* or signature?*/);
parseDependenciesFromMultiname(abcIndex, ignoredCustom, abc, dependencies, abc.constants.getMultiname(ex.type_index), ignorePackage, fullyQualifiedNames, DependencyType.EXPRESSION /* or signature?*/);
}
for (AVM2Instruction ins : body.getCode().code) {
if (ins.definition instanceof AlchemyTypeIns) {
@@ -151,7 +149,7 @@ public class DependencyParser {
if (ins.definition instanceof NewFunctionIns) {
if (ins.operands[0] != method_index) {
if (!visitedMethods.contains(ins.operands[0])) {
parseDependenciesFromMethodInfo(trait, scriptIndex, classIndex, isStatic, ignoredCustom, abc, ins.operands[0], dependencies, ignorePackage, fullyQualifiedNames, visitedMethods);
parseDependenciesFromMethodInfo(abcIndex, trait, scriptIndex, classIndex, isStatic, ignoredCustom, abc, ins.operands[0], dependencies, ignorePackage, fullyQualifiedNames, visitedMethods);
}
}
}
@@ -159,12 +157,12 @@ public class DependencyParser {
if (ins.definition.operands[k] == AVM2Code.DAT_MULTINAME_INDEX) {
int m = ins.operands[k];
if (m < abc.constants.getMultinameCount()) {
parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, abc.constants.getMultiname(m), ignorePackage, fullyQualifiedNames, DependencyType.EXPRESSION);
parseDependenciesFromMultiname(abcIndex, ignoredCustom, abc, dependencies, abc.constants.getMultiname(m), ignorePackage, fullyQualifiedNames, DependencyType.EXPRESSION);
}
}
}
}
}
}
}
}

View File

@@ -165,7 +165,7 @@ public class LinkReportExporter {
List<Dependency> dependencies = new ArrayList<>();
sb.append(indent(3)).append("<dep id=\"AS3\" />").append(newLineChar); //Automatic
tc.getDependencies(scriptIndex, -1, false, null, abc, dependencies, new DottedChain(new String[]{"FAKE!PACKAGE"}), new ArrayList<>());
tc.getDependencies(swf.getAbcIndex(), scriptIndex, -1, false, null, abc, dependencies, new DottedChain(new String[]{"FAKE!PACKAGE"}), new ArrayList<>());
for (Dependency dependency : dependencies) {
DottedChain dc = dependency.getId();
if (!"*".equals(dc.getLast())) {

View File

@@ -148,7 +148,7 @@ public class SwfToSwcExporter {
sb.append(" <dep id=\"AS3\" type=\"").append(DEPENDENCY_NAMESPACE).append("\" />\n");
if (!skipDependencies) {
List<Dependency> dependencies = new ArrayList<>();
pack.abc.script_info.get(pack.scriptIndex).traits.getDependencies(pack.scriptIndex, -1, false, null, pack.abc, dependencies, new DottedChain(new String[]{"NO:PACKAGE"}), new ArrayList<>());
pack.abc.script_info.get(pack.scriptIndex).traits.getDependencies(swf.getAbcIndex(), pack.scriptIndex, -1, false, null, pack.abc, dependencies, new DottedChain(new String[]{"NO:PACKAGE"}), new ArrayList<>());
for (Dependency d : dependencies) {
if ("*".equals(d.getId().getLast())) {