diff --git a/CHANGELOG.md b/CHANGELOG.md index dc002c776..414146639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - AS1/2 script export to single file maintains script order - #1088 ECMA Number to string conversion - AS3 getslot/setslot in certain situations +- #1185 AS3 Incorrect imports in obfuscated files ## [13.0.1] - 2021-02-09 ### Fixed diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 65882c3e8..341bc2f56 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -101,6 +101,12 @@ public final class MethodBody implements Cloneable { @Internal private ABC abc; + /** + * DependencyParser uses this + */ + @Internal + private MethodBody lastConvertedBody = null; + public MethodBody() { this.traits = new Traits(); this.codeBytes = SWFInputStream.BYTE_ARRAY_EMPTY; @@ -297,7 +303,7 @@ public final class MethodBody implements Cloneable { @Override public Void call() throws InterruptedException { try (Statistics s1 = new Statistics("MethodBody.convert")) { - MethodBody converted = convertMethodBody(convertData, path, isStatic, scriptIndex, classIndex, abc, trait, scopeStack, initializerType != GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, fullyQualifiedNames, initTraits); + MethodBody converted = convertMethodBody(convertData.deobfuscationMode != 0, path, isStatic, scriptIndex, classIndex, abc, trait); HashMap localRegNames = getLocalRegNames(abc); List convertedItems1; try (Statistics s = new Statistics("AVM2Code.toGraphTargetItems")) { @@ -319,7 +325,6 @@ public final class MethodBody implements Cloneable { } catch (InterruptedException ex) { throw ex; } catch (Exception | OutOfMemoryError | StackOverflowError ex) { - ex.printStackTrace(); convertException = ex; Throwable cause = ex.getCause(); if (ex instanceof ExecutionException && cause instanceof Exception) { @@ -372,19 +377,29 @@ public final class MethodBody implements Cloneable { return writer; } - public MethodBody convertMethodBody(ConvertData convertData, String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait, ScopeStack scopeStack, boolean isStaticInitializer, List fullyQualifiedNames, List initTraits) throws InterruptedException { + public MethodBody convertMethodBodyCanUseLast(boolean deobfuscate, String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait) throws InterruptedException { + if (lastConvertedBody != null) { + return lastConvertedBody; + } + return convertMethodBody(deobfuscate, path, isStatic, scriptIndex, classIndex, abc, trait); + } + + public void clearLastConverted() { + this.lastConvertedBody = null; + } + + public MethodBody convertMethodBody(boolean deobfuscate, String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait) throws InterruptedException { MethodBody body = clone(); AVM2Code code = body.getCode(); code.markVirtualAddresses(); code.fixJumps(path, body); - if (convertData.deobfuscationMode != 0) { + if (deobfuscate) { try { code.removeTraps(trait, method_info, body, abc, scriptIndex, classIndex, isStatic, path); } catch (ThreadDeath | InterruptedException ex) { throw ex; } catch (Throwable ex) { - ex.printStackTrace(); //ignore logger.log(Level.SEVERE, "Deobfuscation failed in: " + path, ex); body = clone(); @@ -394,6 +409,7 @@ public final class MethodBody implements Cloneable { } } + lastConvertedBody = body; return body; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 8e8d0a082..57478c668 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -168,7 +168,7 @@ public abstract class Trait implements Cloneable, Serializable { return getName(abc).getNamespace(abc.constants).getName(abc.constants); } - public void getDependencies(String ignoredCustom, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String ignoredCustom, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { if (ignoredCustom == null) { Namespace n = getName(abc).getNamespace(abc.constants); if (n.kind == Namespace.KIND_NAMESPACE) { @@ -189,7 +189,7 @@ public abstract class Trait implements Cloneable, Serializable { return false; } - public void writeImportsUsages(ABC abc, GraphTextWriter writer, DottedChain ignorePackage, List fullyQualifiedNames) { + public void writeImportsUsages(int scriptIndex, int classIndex, boolean isStatic, ABC abc, GraphTextWriter writer, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { List namesInThisPackage = new ArrayList<>(); for (ABCContainerTag tag : abc.getAbcTags()) { @@ -211,7 +211,7 @@ public abstract class Trait implements Cloneable, Serializable { if (ns.kind == Namespace.KIND_NAMESPACE) { customNs = ns.getName(abc.constants).toRawString(); } - getDependencies(customNs, abc, dependencies, uses, ignorePackage, new ArrayList<>()); + getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, uses, ignorePackage, new ArrayList<>()); List imports = new ArrayList<>(); for (Dependency d : dependencies) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 846e4c91d..5163a0636 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -68,8 +68,8 @@ public class TraitClass extends Trait implements TraitWithSlot { } @Override - public void getDependencies(String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { - super.getDependencies(customNs, abc, dependencies, uses, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames); + public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { + super.getDependencies(scriptIndex, -1, false, customNs, abc, dependencies, uses, ignorePackage == null ? getPackage(abc) : ignorePackage, fullyQualifiedNames); ClassInfo classInfo = abc.class_info.get(class_info); InstanceInfo instanceInfo = abc.instance_info.get(class_info); DottedChain packageName = instanceInfo.getName(abc.constants).getNamespace(abc.constants).getName(abc.constants); //assume not null name @@ -83,16 +83,16 @@ public class TraitClass extends Trait implements TraitWithSlot { } //static - classInfo.static_traits.getDependencies(customNs, abc, dependencies, uses, packageName, fullyQualifiedNames); + classInfo.static_traits.getDependencies(scriptIndex, class_info, true, customNs, abc, dependencies, uses, packageName, fullyQualifiedNames); //static initializer - DependencyParser.parseDependenciesFromMethodInfo(customNs, abc, classInfo.cinit_index, dependencies, uses, packageName, fullyQualifiedNames, new ArrayList<>()); + DependencyParser.parseDependenciesFromMethodInfo(null, scriptIndex, class_info, true, customNs, abc, classInfo.cinit_index, dependencies, uses, packageName, fullyQualifiedNames, new ArrayList<>()); //instance - instanceInfo.instance_traits.getDependencies(customNs, abc, dependencies, uses, packageName, fullyQualifiedNames); + instanceInfo.instance_traits.getDependencies(scriptIndex, class_info, false, customNs, abc, dependencies, uses, packageName, fullyQualifiedNames); //instance initializer - DependencyParser.parseDependenciesFromMethodInfo(customNs, abc, instanceInfo.iinit_index, dependencies, uses, packageName, fullyQualifiedNames, new ArrayList<>()); + DependencyParser.parseDependenciesFromMethodInfo(null, scriptIndex, class_info, false, customNs, abc, instanceInfo.iinit_index, dependencies, uses, packageName, fullyQualifiedNames, new ArrayList<>()); } @Override @@ -113,7 +113,7 @@ public class TraitClass extends Trait implements TraitWithSlot { DottedChain packageName = instanceInfoMultiname.getNamespace(abc.constants).getName(abc.constants); //assume not null name fullyQualifiedNames = new ArrayList<>(); - writeImportsUsages(abc, writer, packageName, fullyQualifiedNames); + writeImportsUsages(scriptIndex, classIndex, false, abc, writer, packageName, fullyQualifiedNames); String instanceInfoName = instanceInfoMultiname.getName(abc.constants, fullyQualifiedNames, false, true); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index 3405066bb..12502d73e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -80,7 +80,7 @@ public class TraitFunction extends Trait implements TraitWithSlot { @Override public GraphTextWriter toString(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { - writeImportsUsages(abc, writer, getPackage(abc), fullyQualifiedNames); + writeImportsUsages(scriptIndex, classIndex, false, abc, writer, getPackage(abc), fullyQualifiedNames); getMetaData(parent, convertData, abc, writer); writer.startMethod(method_info); toStringHeader(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); @@ -100,7 +100,7 @@ public class TraitFunction extends Trait implements TraitWithSlot { @Override public void convert(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { fullyQualifiedNames = new ArrayList<>(); - writeImportsUsages(abc, writer, getPackage(abc), fullyQualifiedNames); + writeImportsUsages(scriptIndex, classIndex, false, abc, writer, getPackage(abc), fullyQualifiedNames); writer.startMethod(method_info); convertHeader(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); int bodyIndex = abc.findBodyIndex(method_info); @@ -126,14 +126,14 @@ public class TraitFunction extends Trait implements TraitWithSlot { } @Override - public void getDependencies(String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { if (ignorePackage == null) { ignorePackage = getPackage(abc); } - super.getDependencies(customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); + super.getDependencies(scriptIndex, classIndex, false, customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); //if (method_info != 0) { - DependencyParser.parseDependenciesFromMethodInfo(customNs, abc, method_info, dependencies, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); + DependencyParser.parseDependenciesFromMethodInfo(this, scriptIndex, classIndex, false, customNs, abc, method_info, dependencies, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java index c7f92812b..db6138605 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java @@ -61,11 +61,11 @@ public class TraitMethodGetterSetter extends Trait { } @Override - public void getDependencies(String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { if (ignorePackage == null) { ignorePackage = getPackage(abc); } - super.getDependencies(customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); + super.getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); if (customNs == null) { Namespace n = getName(abc).getNamespace(abc.constants); @@ -75,7 +75,7 @@ public class TraitMethodGetterSetter extends Trait { } //if (method_info != 0) { - DependencyParser.parseDependenciesFromMethodInfo(customNs, abc, method_info, dependencies, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); + DependencyParser.parseDependenciesFromMethodInfo(this, scriptIndex, classIndex, isStatic, customNs, abc, method_info, dependencies, uses, ignorePackage, fullyQualifiedNames, new ArrayList<>()); } } @@ -107,7 +107,7 @@ public class TraitMethodGetterSetter extends Trait { @Override public void convert(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { if (classIndex < 0) { - writeImportsUsages(abc, writer, getPackage(abc), fullyQualifiedNames); + writeImportsUsages(scriptIndex, classIndex, isStatic, abc, writer, getPackage(abc), fullyQualifiedNames); } writer.startMethod(method_info); path = path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames, false, true); @@ -127,7 +127,7 @@ public class TraitMethodGetterSetter extends Trait { public GraphTextWriter toString(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { if (classIndex < 0) { - writeImportsUsages(abc, writer, getPackage(abc), fullyQualifiedNames); + writeImportsUsages(scriptIndex, classIndex, isStatic, abc, writer, getPackage(abc), fullyQualifiedNames); } getMetaData(parent, convertData, abc, writer); writer.startMethod(method_info); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index e0cd63d61..a9291b3c0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -201,11 +201,11 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { } @Override - public void getDependencies(String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { if (ignorePackage == null) { ignorePackage = getPackage(abc); } - super.getDependencies(customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); + super.getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); DependencyParser.parseDependenciesFromMultiname(customNs, abc, dependencies, uses, abc.constants.getMultiname(type_index), getPackage(abc), fullyQualifiedNames, DependencyType.SIGNATURE); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index a804336ef..41d43af6e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; @@ -240,9 +241,9 @@ public class Traits implements Cloneable, Serializable { } } - public void getDependencies(String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) { + public void getDependencies(int scriptIndex, int classIndex, boolean isStatic, String customNs, ABC abc, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames) throws InterruptedException { for (Trait t : traits) { - t.getDependencies(customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); + t.getDependencies(scriptIndex, classIndex, isStatic, customNs, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java index fdf93762f..da40e6eda 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/DependencyParser.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.exporters.script; import com.jpexs.decompiler.flash.abc.ABC; @@ -32,6 +33,8 @@ 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.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; @@ -92,7 +95,7 @@ public class DependencyParser { } } - public static void parseDependenciesFromMethodInfo(String ignoredCustom, ABC abc, int method_index, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames, List visitedMethods) { + public static void parseDependenciesFromMethodInfo(Trait trait, int scriptIndex, int classIndex, boolean isStatic, String ignoredCustom, ABC abc, int method_index, List dependencies, List uses, DottedChain ignorePackage, List fullyQualifiedNames, List visitedMethods) throws InterruptedException { if ((method_index < 0) || (method_index >= abc.method_info.size())) { return; } @@ -107,7 +110,8 @@ public class DependencyParser { } MethodBody body = abc.findBody(method_index); if (body != null) { - body.traits.getDependencies(ignoredCustom, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); + body = body.convertMethodBodyCanUseLast(Configuration.autoDeobfuscate.get(), "", isStatic, scriptIndex, classIndex, abc, trait); + body.traits.getDependencies(scriptIndex, classIndex, isStatic, ignoredCustom, abc, dependencies, uses, ignorePackage, fullyQualifiedNames); for (ABCException ex : body.exceptions) { parseDependenciesFromMultiname(ignoredCustom, abc, dependencies, uses, abc.constants.getMultiname(ex.type_index), ignorePackage, fullyQualifiedNames, DependencyType.EXPRESSION /* or signature?*/); } @@ -122,7 +126,7 @@ public class DependencyParser { if (ins.definition instanceof NewFunctionIns) { if (ins.operands[0] != method_index) { if (!visitedMethods.contains(ins.operands[0])) { - parseDependenciesFromMethodInfo(ignoredCustom, abc, ins.operands[0], dependencies, uses, ignorePackage, fullyQualifiedNames, visitedMethods); + parseDependenciesFromMethodInfo(trait, scriptIndex, classIndex, isStatic, ignoredCustom, abc, ins.operands[0], dependencies, uses, ignorePackage, fullyQualifiedNames, visitedMethods); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/LinkReportExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/LinkReportExporter.java index 8ba76994b..26f8bf845 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/LinkReportExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/LinkReportExporter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.exporters.script; import com.jpexs.decompiler.flash.EventListener; @@ -81,7 +82,7 @@ public class LinkReportExporter { return sb.toString(); } - public String generateReport(SWF swf, List as3scripts, EventListener evl) { + public String generateReport(SWF swf, List as3scripts, EventListener evl) throws InterruptedException { StringBuilder sb = new StringBuilder(); Set extDeps = new HashSet<>(); sb.append("").append(newLineChar); @@ -101,7 +102,7 @@ public class LinkReportExporter { ScriptInfo script = sp.abc.script_info.get(sp.scriptIndex); for (int traitIndex : sp.traitIndices) { Trait trait = script.traits.traits.get(traitIndex); - sb.append(reportTrait(extDeps, existingObjects, swf, sp.abc, trait)); + sb.append(reportTrait(sp.scriptIndex, extDeps, existingObjects, swf, sp.abc, trait)); } //how about script_init method(?) sb.append(indent(2)).append("").append(newLineChar); @@ -129,7 +130,7 @@ public class LinkReportExporter { return dc.getWithoutLast().toRawString() + ":" + dc.getLast(); } - private String reportTrait(Set externalDefs, List existingObjects, SWF swf, ABC abc, Trait t) { + private String reportTrait(int scriptIndex, Set externalDefs, List existingObjects, SWF swf, ABC abc, Trait t) throws InterruptedException { //TODO: handle externalDefs - StringBuilder sb = new StringBuilder(); if (t instanceof TraitClass) { @@ -156,17 +157,17 @@ public class LinkReportExporter { } for (Trait ct : ci.static_traits.traits) { - reportTrait(externalDefs, existingObjects, swf, abc, ct); + reportTrait(scriptIndex, externalDefs, existingObjects, swf, abc, ct); } for (Trait it : ii.instance_traits.traits) { - reportTrait(externalDefs, existingObjects, swf, abc, it); + reportTrait(scriptIndex, externalDefs, existingObjects, swf, abc, it); } List dependencies = new ArrayList<>(); List uses = new ArrayList<>(); sb.append(indent(3)).append("").append(newLineChar); //Automatic - tc.getDependencies(null, abc, dependencies, uses, new DottedChain(new String[]{"FAKE!PACKAGE"}, ""), new ArrayList<>()); + tc.getDependencies(scriptIndex, -1, false, null, abc, dependencies, uses, new DottedChain(new String[]{"FAKE!PACKAGE"}, ""), new ArrayList<>()); for (Dependency dependency : dependencies) { DottedChain dc = dependency.getId(); if (!"*".equals(dc.getLast())) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfToSwcExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfToSwcExporter.java index f4bc823b2..e4ec302dd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfToSwcExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfToSwcExporter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.exporters.swf; import com.jpexs.decompiler.flash.ReadOnlyTagList; @@ -86,7 +87,7 @@ public class SwfToSwcExporter { return dc.getWithoutLast().toRawString() + ":" + dc.getLast(); } - private String generateCatalog(SWF swf, byte[] swfBytes, boolean skipDependencies) { + private String generateCatalog(SWF swf, byte[] swfBytes, boolean skipDependencies) throws InterruptedException { StringBuilder sb = new StringBuilder(); final String libraryFileName = "library.swf"; @@ -148,7 +149,7 @@ public class SwfToSwcExporter { if (!skipDependencies) { List dependencies = new ArrayList<>(); List uses = new ArrayList<>(); - pack.abc.script_info.get(pack.scriptIndex).traits.getDependencies(null, pack.abc, dependencies, uses, new DottedChain(new String[]{"NO:PACKAGE"}, ""), new ArrayList<>()); + pack.abc.script_info.get(pack.scriptIndex).traits.getDependencies(pack.scriptIndex, -1, false, null, pack.abc, dependencies, uses, new DottedChain(new String[]{"NO:PACKAGE"}, ""), new ArrayList<>()); for (Dependency d : dependencies) { if ("*".equals(d.getId().getLast())) { @@ -207,7 +208,7 @@ public class SwfToSwcExporter { //System.out.println("time " + title + ": " + (t2 - t1)); } - public void exportSwf(SWF swf, File outSwcFile, boolean skipDependencies) throws IOException { + public void exportSwf(SWF swf, File outSwcFile, boolean skipDependencies) throws IOException, InterruptedException { long t4 = 0; //Make local copy of SWF so we do not modify original try { diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index ee3f074a1..b9e624921 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -1128,7 +1128,11 @@ public class CommandLineArgumentParser { final File swfFile = new File(args.pop()); processReadSWF(swfFile, null, (SWF swf, OutputStream stdout) -> { SwfToSwcExporter exporter = new SwfToSwcExporter(); - exporter.exportSwf(swf, outFile, false); + try { + exporter.exportSwf(swf, outFile, false); + } catch (IOException | InterruptedException ex) { + Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, null, ex); + } }); } @@ -1160,6 +1164,7 @@ public class CommandLineArgumentParser { badArguments("getinstancemetadata"); } processReadSWF(swfFile, stdOutFile, (SWF swf, OutputStream stdout) -> { + LinkReportExporter lre = new LinkReportExporter(); List reportPacks; @@ -1170,9 +1175,12 @@ public class CommandLineArgumentParser { System.exit(1); return; } - - String reportStr = lre.generateReport(swf, reportPacks, null); - stdout.write(reportStr.getBytes("UTF-8")); + try { + String reportStr = lre.generateReport(swf, reportPacks, null); + stdout.write(reportStr.getBytes("UTF-8")); + } catch (InterruptedException ex) { + System.err.println("Report generation interrupted"); + } }); }