diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java index 13f1bff19..7a53a5167 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ScriptPack; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.action.ActionList; @@ -89,7 +90,7 @@ public class DecompilerPool { return submit(callable); } - public Future submitTask(ScriptPack pack, ScriptDecompiledListener listener) { + public Future submitTask(AbcIndexing abcIndex, ScriptPack pack, ScriptDecompiledListener listener) { Callable callable = new Callable() { @Override public HighlightedText call() throws Exception { @@ -104,7 +105,7 @@ public class DecompilerPool { } boolean parallel = Configuration.parallelSpeedUp.get(); HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true); - pack.toSource(writer, script == null ? null : script.traits.traits, new ConvertData(), ScriptExportMode.AS, parallel, false); + pack.toSource(abcIndex, writer, script == null ? null : script.traits.traits, new ConvertData(), ScriptExportMode.AS, parallel, false); HighlightedText result = new HighlightedText(writer); Openable openable = pack.getOpenable(); @@ -179,8 +180,8 @@ public class DecompilerPool { return null; } - public HighlightedText decompile(ScriptPack pack) throws InterruptedException { - Future future = submitTask(pack, null); + public HighlightedText decompile(AbcIndexing abcIndex, ScriptPack pack) throws InterruptedException { + Future future = submitTask(abcIndex, pack, null); Openable openable = pack.getOpenable(); if (!openableToFutures.containsKey(openable)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 4a763355e..0bf9f70cb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -33,6 +33,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.NewArrayAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NewObjectAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.StringAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.Multiname; @@ -73,6 +74,8 @@ import com.jpexs.decompiler.flash.cache.AS2Cache; import com.jpexs.decompiler.flash.cache.AS3Cache; import com.jpexs.decompiler.flash.cache.ScriptDecompiledListener; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.configuration.CustomConfigurationKeys; +import com.jpexs.decompiler.flash.configuration.SwfSpecificCustomConfiguration; import com.jpexs.decompiler.flash.dumpview.DumpInfo; import com.jpexs.decompiler.flash.dumpview.DumpInfoSwfNode; import com.jpexs.decompiler.flash.ecma.Null; @@ -181,6 +184,7 @@ import java.awt.geom.AffineTransform; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -380,6 +384,13 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { private static final DecompilerPool decompilerPool = new DecompilerPool(); + @Internal + private AbcIndexing abcIndex; + + private static AbcIndexing playerGlobalAbcIndex; + + private static AbcIndexing airGlobalAbcIndex; + public static final String AS2_PKG_PREFIX = "__Packages."; public static List swfSignatures = Arrays.asList( @@ -396,6 +407,43 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { */ public static final Color ERROR_COLOR = Color.red; + public static final int LIBRARY_AIR = 0; + public static final int LIBRARY_FLASH = 1; + + public static AbcIndexing getPlayerGlobalAbcIndex() { + return playerGlobalAbcIndex; + } + + public static AbcIndexing getAirGlobalAbcIndex() { + return airGlobalAbcIndex; + } + + public AbcIndexing getAbcIndex() { + return abcIndex; + } + + + public static void initPlayer() throws IOException, InterruptedException { + if (playerGlobalAbcIndex == null) { + /*if (Configuration.getPlayerSWC() == null) { + throw new IOException("Player SWC library not found, please place it to " + Configuration.getFlashLibPath()); + }*/ + + if (Configuration.getPlayerSWC() != null) { + SWC swc = new SWC(new FileInputStream(Configuration.getPlayerSWC())); + SWF swf = new SWF(swc.getOpenable("library.swf"), true); + playerGlobalAbcIndex = new AbcIndexing(swf); + } + } + if (airGlobalAbcIndex == null) { + if (Configuration.getAirSWC() != null) { + SWC swc = new SWC(new FileInputStream(Configuration.getAirSWC())); + SWF swf = new SWF(swc.getOpenable("library.swf"), true); + airGlobalAbcIndex = new AbcIndexing(swf); + } + } + } + public String getCharset() { return charset; } @@ -986,7 +1034,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { byte[] uncompressedData = saveToByteArray(); compress(new ByteArrayInputStream(uncompressedData), os, compression, lzmaProperties); } - + public void saveTo(OutputStream os, boolean gfx) throws IOException { checkCharset(); byte[] uncompressedData = saveToByteArray(gfx); @@ -1413,6 +1461,20 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { } getASMs(true); // Add scriptNames to ASMs + + boolean air = false; + SwfSpecificCustomConfiguration conf = Configuration.getSwfSpecificCustomConfiguration(getShortPathTitle()); + if (conf != null) { + if (conf.getCustomData(CustomConfigurationKeys.KEY_LIBRARY, "" + LIBRARY_FLASH).equals("" + LIBRARY_AIR)) { + air = true; + } + } + abcIndex = new AbcIndexing(air ? SWF.getAirGlobalAbcIndex() : SWF.getPlayerGlobalAbcIndex()); + for (Tag tag:tags) { + if (tag instanceof ABCContainerTag) { + abcIndex.addAbc(((ABCContainerTag)tag).getABC()); + } + } } private void resolveImported(UrlResolver resolver) { @@ -1974,7 +2036,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { } else if (treeItem instanceof AS2Package) { AS2Package as2Package = (AS2Package) treeItem; for (TreeItem subItem : as2Package.subPackages.values()) { - if ((subItem instanceof AS2Package) && ((AS2Package)subItem).isDefaultPackage()) { + if ((subItem instanceof AS2Package) && ((AS2Package) subItem).isDefaultPackage()) { getASMs(exportFileNames, subItem, nodesToExport, exportAll, asmsToExport, path); } else { getASMs(exportFileNames, subItem, nodesToExport, exportAll, asmsToExport, path + File.separator + getASMPath(exportFileNames, subItem)); @@ -1998,8 +2060,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { return String.join(File.separator, parts); } } - - + if (!exportFileName) { return treeItem.toString(); } @@ -2893,7 +2954,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { public static void uncache(ScriptPack pack) { if (pack != null) { Openable openable = pack.getOpenable(); - SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC)openable).getSwf(); + SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf(); if (swf != null) { swf.as3Cache.remove(pack); } @@ -2925,7 +2986,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { public static boolean isCached(ScriptPack pack) { if (pack != null) { Openable openable = pack.getOpenable(); - SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC)openable).getSwf(); + SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf(); if (swf != null) { return swf.as3Cache.isCached(pack); } @@ -2959,7 +3020,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { public static HighlightedText getFromCache(ScriptPack pack) { if (pack != null) { Openable openable = pack.getOpenable(); - SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC)openable).getSwf(); + SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf(); if (swf != null) { return swf.as3Cache.get(pack); } @@ -3020,7 +3081,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { public static HighlightedText getCached(ScriptPack pack) throws InterruptedException { Openable openable = pack.getOpenable(); - SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC)openable).getSwf(); + SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf(); HighlightedText res; if (swf != null) { res = swf.as3Cache.get(pack); @@ -3029,7 +3090,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { } } - return decompilerPool.decompile(pack); + return decompilerPool.decompile(swf.abcIndex, pack); } public static Future getCachedFuture(ASMSource src, ActionList actions, ScriptDecompiledListener listener) throws InterruptedException { @@ -3051,7 +3112,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { public static Future getCachedFuture(ScriptPack pack, ScriptDecompiledListener listener) throws InterruptedException { Openable openable = pack.getOpenable(); - SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC)openable).getSwf(); + SWF swf = (openable instanceof SWF) ? (SWF) openable : ((ABC) openable).getSwf(); HighlightedText res; if (swf != null) { res = swf.as3Cache.get(pack); @@ -3064,7 +3125,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { } } - return decompilerPool.submitTask(pack, listener); + return decompilerPool.submitTask(swf.abcIndex, pack, listener); } public DecompilerPool getDecompilerPool() { @@ -3975,7 +4036,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { int mi = ((TraitMethodGetterSetter) t).method_info; try { - documentPack.abc.findBody(mi).convert(new ConvertData(), "??", ScriptExportMode.AS, true, mi, documentPack.scriptIndex, cindex, documentPack.abc, t, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); + documentPack.abc.findBody(mi).convert(abcIndex, new ConvertData(), "??", ScriptExportMode.AS, true, mi, documentPack.scriptIndex, cindex, documentPack.abc, t, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); List infos = documentPack.abc.findBody(mi).convertedItems; if (!infos.isEmpty()) { if (infos.get(0) instanceof IfItem) { @@ -4051,7 +4112,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { if (tr instanceof TraitClass) { int ci = ((TraitClass) tr).class_info; int cinit = p.abc.class_info.get(ci).cinit_index; - p.abc.findBody(cinit).convert(new ConvertData(), "??", ScriptExportMode.AS, true, cinit, p.scriptIndex, cindex, p.abc, t, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); + p.abc.findBody(cinit).convert(abcIndex, new ConvertData(), "??", ScriptExportMode.AS, true, cinit, p.scriptIndex, cindex, p.abc, t, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); List cinitBody = p.abc.findBody(cinit).convertedItems; for (GraphTargetItem cit : cinitBody) { if (cit instanceof SetPropertyAVM2Item) { @@ -4172,5 +4233,5 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { @Override public OpenableList getOpenableList() { return openableList; - } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java index d4615063f..e0fe8729c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/AVM2LocalData.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.BaseLocalData; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.CodeStats; +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.InstanceInfo; import com.jpexs.decompiler.flash.abc.types.MethodBody; @@ -53,6 +54,8 @@ public class AVM2LocalData extends BaseLocalData { public MethodBody methodBody; public ABC abc; + + public AbcIndexing abcIndex; public HashMap localRegNames; @@ -141,6 +144,7 @@ public class AVM2LocalData extends BaseLocalData { scopeStack = localData.scopeStack; methodBody = localData.methodBody; abc = localData.abc; + abcIndex = localData.abcIndex; localRegNames = localData.localRegNames; fullyQualifiedNames = localData.fullyQualifiedNames; parsedExceptions = localData.parsedExceptions; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 399eb930c..a44099446 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; import com.jpexs.decompiler.flash.abc.avm2.instructions.debug.DebugFileIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.debug.DebugIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.debug.DebugLineIns; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.Multiname; @@ -176,7 +177,7 @@ public class ScriptPack extends AS3ClassTreeItem { } return packageName.equals("") ? scriptName : packageName + "." + scriptName; }*/ - public void convert(final NulWriter writer, final List traits, final ConvertData convertData, final ScriptExportMode exportMode, final boolean parallel) throws InterruptedException { + public void convert(AbcIndexing abcIndex, final NulWriter writer, final List traits, final ConvertData convertData, final ScriptExportMode exportMode, final boolean parallel) throws InterruptedException { int sinit_index = abc.script_info.get(scriptIndex).init_index; int sinit_bodyIndex = abc.findBodyIndex(sinit_index); @@ -190,7 +191,7 @@ public class ScriptPack extends AS3ClassTreeItem { } ts.add(abc.script_info.get(scriptIndex).traits); writer.mark(); - abc.bodies.get(sinit_bodyIndex).convert(convertData, path +/*packageName +*/ "/.scriptinitializer", exportMode, true, sinit_index, scriptIndex, -1, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<>(), ts, true, new HashSet<>()); + abc.bodies.get(sinit_bodyIndex).convert(abcIndex, convertData, path +/*packageName +*/ "/.scriptinitializer", exportMode, true, sinit_index, scriptIndex, -1, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<>(), ts, true, new HashSet<>()); scriptInitializerIsEmpty = !writer.getMark(); } @@ -199,14 +200,14 @@ public class ScriptPack extends AS3ClassTreeItem { Multiname name = trait.getName(abc); Namespace ns = name.getNamespace(abc.constants); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { - trait.convertPackaged(null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); + trait.convertPackaged(abcIndex, null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); } else { - trait.convert(null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); + trait.convert(abcIndex, null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); } } } - private void appendTo(GraphTextWriter writer, List traits, ConvertData convertData, ScriptExportMode exportMode, boolean parallel) throws InterruptedException { + private void appendTo(AbcIndexing abcIndex, GraphTextWriter writer, List traits, ConvertData convertData, ScriptExportMode exportMode, boolean parallel) throws InterruptedException { boolean first = true; //script initializer int script_init = abc.script_info.get(scriptIndex).init_index; @@ -219,7 +220,7 @@ public class ScriptPack extends AS3ClassTreeItem { if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { if (!scriptInitializerIsEmpty) { writer.startBlock(); - abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/.scriptinitializer", exportMode, abc, null, writer, new ArrayList<>(), new HashSet<>()); + abc.bodies.get(bodyIndex).toString(abcIndex, path +/*packageName +*/ "/.scriptinitializer", exportMode, abc, null, writer, new ArrayList<>(), new HashSet<>()); writer.endBlock(); } else { writer.append(" "); @@ -248,9 +249,9 @@ public class ScriptPack extends AS3ClassTreeItem { Multiname name = trait.getName(abc); Namespace ns = name.getNamespace(abc.constants); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { - trait.toStringPackaged(null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); + trait.toStringPackaged(abcIndex, null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); } else { - trait.toString(null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); + trait.toString(abcIndex, null, convertData, "", abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<>(), parallel); } if (!(trait instanceof TraitClass)) { writer.endTrait(); @@ -259,14 +260,14 @@ public class ScriptPack extends AS3ClassTreeItem { } } - public void toSource(GraphTextWriter writer, final List traits, final ConvertData convertData, final ScriptExportMode exportMode, final boolean parallel, boolean ignoreFrameScripts) throws InterruptedException { + public void toSource(AbcIndexing abcIndex, GraphTextWriter writer, final List traits, final ConvertData convertData, final ScriptExportMode exportMode, final boolean parallel, boolean ignoreFrameScripts) throws InterruptedException { writer.suspendMeasure(); int timeout = Configuration.decompilationTimeoutFile.get(); try { CancellableWorker.call(new Callable() { @Override public Void call() throws Exception { - convert(new NulWriter(), traits, convertData, exportMode, parallel); + convert(abcIndex, new NulWriter(), traits, convertData, exportMode, parallel); return null; } }, timeout, TimeUnit.SECONDS); @@ -297,10 +298,10 @@ public class ScriptPack extends AS3ClassTreeItem { } writer.continueMeasure(); - appendTo(writer, traits, convertData, exportMode, parallel); + appendTo(abcIndex, writer, traits, convertData, exportMode, parallel); } - public File export(File file, ScriptExportSettings exportSettings, boolean parallel) throws IOException, InterruptedException { + public File export(AbcIndexing abcIndex, File file, ScriptExportSettings exportSettings, boolean parallel) throws IOException, InterruptedException { if (!exportSettings.singleFile) { if (file.exists() && !Configuration.overwriteExistingFiles.get()) { return file; @@ -315,7 +316,7 @@ public class ScriptPack extends AS3ClassTreeItem { FileTextWriter writer2 = exportSettings.singleFile ? exportSettings.singleFileWriter : writer; ConvertData convertData = new ConvertData(); convertData.ignoreFrameScripts = exportSettings.ignoreFrameScripts; - toSource(writer2, abc.script_info.get(scriptIndex).traits.traits, convertData, exportSettings.mode, parallel, exportSettings.ignoreFrameScripts); + toSource(abcIndex, writer2, abc.script_info.get(scriptIndex).traits.traits, convertData, exportSettings.mode, parallel, exportSettings.ignoreFrameScripts); } catch (FileNotFoundException ex) { logger.log(Level.SEVERE, "The file path is probably too long", ex); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index ec6bcf749..77bfd4357 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -271,6 +271,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.UndefinedAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ForEachInAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ForInAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.avm2.parser.script.PropertyAVM2Item; import com.jpexs.decompiler.flash.abc.types.ABCException; import com.jpexs.decompiler.flash.abc.types.AssignedValue; @@ -2126,7 +2127,7 @@ public class AVM2Code implements Cloneable { }*/ } - public List toGraphTargetItems(boolean thisHasDefaultToPrimitive, ConvertData convertData, String path, int methodIndex, boolean isStatic, int scriptIndex, int classIndex, ABC abc, MethodBody body, HashMap localRegNames, ScopeStack scopeStack, int initializerType, List fullyQualifiedNames, List initTraits, int staticOperation, HashMap localRegAssigmentIps, HashMap> refs) throws InterruptedException { + public List toGraphTargetItems(AbcIndexing abcIndex, boolean thisHasDefaultToPrimitive, ConvertData convertData, String path, int methodIndex, boolean isStatic, int scriptIndex, int classIndex, ABC abc, MethodBody body, HashMap localRegNames, ScopeStack scopeStack, int initializerType, List fullyQualifiedNames, List initTraits, int staticOperation, HashMap localRegAssigmentIps, HashMap> refs) throws InterruptedException { initToSource(); List list; HashMap localRegs = new HashMap<>(); @@ -2137,7 +2138,7 @@ public class AVM2Code implements Cloneable { } //try { - list = AVM2Graph.translateViaGraph(path, this, abc, body, isStatic, scriptIndex, classIndex, localRegs, scopeStack, localRegNames, fullyQualifiedNames, staticOperation, localRegAssigmentIps, refs, thisHasDefaultToPrimitive); + list = AVM2Graph.translateViaGraph(abcIndex, path, this, abc, body, isStatic, scriptIndex, classIndex, localRegs, scopeStack, localRegNames, fullyQualifiedNames, staticOperation, localRegAssigmentIps, refs, thisHasDefaultToPrimitive); if (initTraits != null) { loopi: diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java index 0a888eda2..8ada73806 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java @@ -52,7 +52,7 @@ public class CodeStats { if (stats.stackpos > ms) { ms = stats.stackpos; } - writer.appendNoHilight(i + ":" + stats.stackpos + (deltastack >= 0 ? "+" + deltastack : deltastack) + "," + stats.scopepos + " " + stats.ins.toString(writer, LocalData.create(abc, null, fullyQualifiedNames, new HashSet<>()))).newLine(); + writer.appendNoHilight(i + ":" + stats.stackpos + (deltastack >= 0 ? "+" + deltastack : deltastack) + "," + stats.scopepos + " " + stats.ins.toString(writer, LocalData.create(null, abc, null, fullyQualifiedNames, new HashSet<>()))).newLine(); i++; } return writer; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index 5b44c8d8b..a6a83e04a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -83,6 +83,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ForEachInAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ForInAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.TryAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.operations.StrictEqAVM2Item; +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; @@ -146,6 +147,8 @@ public class AVM2Graph extends Graph { private final ABC abc; private final MethodBody body; + + private final AbcIndexing abcIndex; private final Logger logger = Logger.getLogger(AVM2Graph.class.getName()); @@ -167,11 +170,12 @@ public class AVM2Graph extends Graph { return ret; } - public AVM2Graph(AVM2Code code, ABC abc, MethodBody body, boolean isStatic, int scriptIndex, int classIndex, HashMap localRegs, ScopeStack scopeStack, HashMap localRegNames, List fullyQualifiedNames, HashMap localRegAssigmentIps, HashMap> refs) { + public AVM2Graph(AbcIndexing abcIndex, AVM2Code code, ABC abc, MethodBody body, boolean isStatic, int scriptIndex, int classIndex, HashMap localRegs, ScopeStack scopeStack, HashMap localRegNames, List fullyQualifiedNames, HashMap localRegAssigmentIps, HashMap> refs) { super(new AVM2GraphSource(code, isStatic, scriptIndex, classIndex, localRegs, scopeStack, abc, body, localRegNames, fullyQualifiedNames, localRegAssigmentIps, refs), getExceptionEntries(body)); this.avm2code = code; this.abc = abc; this.body = body; + this.abcIndex = abcIndex; /*heads = makeGraph(code, new ArrayList(), body); this.code = code; this.abc = abc; @@ -629,8 +633,8 @@ public class AVM2Graph extends Graph { return setLocalPosToGetLocalPos; } - public static List translateViaGraph(String path, AVM2Code code, ABC abc, MethodBody body, boolean isStatic, int scriptIndex, int classIndex, HashMap localRegs, ScopeStack scopeStack, HashMap localRegNames, List fullyQualifiedNames, int staticOperation, HashMap localRegAssigmentIps, HashMap> refs, boolean thisHasDefaultToPrimitive) throws InterruptedException { - AVM2Graph g = new AVM2Graph(code, abc, body, isStatic, scriptIndex, classIndex, localRegs, scopeStack, localRegNames, fullyQualifiedNames, localRegAssigmentIps, refs); + public static List translateViaGraph(AbcIndexing abcIndex, String path, AVM2Code code, ABC abc, MethodBody body, boolean isStatic, int scriptIndex, int classIndex, HashMap localRegs, ScopeStack scopeStack, HashMap localRegNames, List fullyQualifiedNames, int staticOperation, HashMap localRegAssigmentIps, HashMap> refs, boolean thisHasDefaultToPrimitive) throws InterruptedException { + AVM2Graph g = new AVM2Graph(abcIndex, code, abc, body, isStatic, scriptIndex, classIndex, localRegs, scopeStack, localRegNames, fullyQualifiedNames, localRegAssigmentIps, refs); AVM2LocalData localData = new AVM2LocalData(); localData.thisHasDefaultToPrimitive = thisHasDefaultToPrimitive; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java index 618f68c51..033fbfb1b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewClassIns.java @@ -44,7 +44,7 @@ public class NewClassIns extends InstructionDefinition { public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List output, String path) throws InterruptedException { int clsIndex = ins.operands[0]; HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false); - stack.pop().toString(writer, LocalData.create(localData.abc, localData.localRegNames, localData.fullyQualifiedNames, new HashSet<>())); + stack.pop().toString(writer, LocalData.create(localData.abcIndex, localData.abc, localData.localRegNames, localData.fullyQualifiedNames, new HashSet<>())); String baseType = writer.toString(); ABC abc = localData.abc; stack.push(new UnparsedAVM2Item(ins, localData.lineStartInstruction, "§§newclass(" + abc.constants.getMultiname(abc.instance_info.get(clsIndex).name_index).getName(localData.getConstants(), localData.fullyQualifiedNames, false, true) + "," + baseType + ")")); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java index 78fffbb3b..6c8dfa389 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/FullMultinameAVM2Item.java @@ -92,13 +92,13 @@ public class FullMultinameAVM2Item extends AVM2Item { public boolean isTopLevel(String tname, ABC abc, HashMap localRegNames, List fullyQualifiedNames, Set seenMethods) throws InterruptedException { String cname; if (name != null) { - cname = name.toString(LocalData.create(abc, localRegNames, fullyQualifiedNames, seenMethods)); + cname = name.toString(LocalData.create(null, abc, localRegNames, fullyQualifiedNames, seenMethods)); } else { cname = (abc.constants.getMultiname(multinameIndex).getName(abc.constants, fullyQualifiedNames, true, true)); } String cns = ""; if (namespace != null) { - cns = namespace.toString(LocalData.create(abc, localRegNames, fullyQualifiedNames, seenMethods)); + cns = namespace.toString(LocalData.create(null, abc, localRegNames, fullyQualifiedNames, seenMethods)); } else { Namespace ns = abc.constants.getMultiname(multinameIndex).getNamespace(abc.constants); if ((ns != null) && (ns.name_index != 0)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java index e61d90e60..9c3bf932b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.AVM2LocalData; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.configuration.Configuration; @@ -93,8 +94,8 @@ public class NewFunctionAVM2Item extends AVM2Item { abc.method_info.get(methodIndex).getReturnTypeStr(writer, abc.constants, fullyQualifiedNames); writer.startBlock(); if (body != null) { - body.convert(new ConvertData(), path + "/inner", ScriptExportMode.AS, isStatic, methodIndex, scriptIndex, classIndex, abc, null, new ScopeStack(), 0, new NulWriter(), fullyQualifiedNames, null, false, new HashSet<>(localData.seenMethods)); - body.toString(path + "/inner", ScriptExportMode.AS, abc, null, writer, fullyQualifiedNames, new HashSet<>(localData.seenMethods)); + body.convert(localData.abcIndex, new ConvertData(), path + "/inner", ScriptExportMode.AS, isStatic, methodIndex, scriptIndex, classIndex, abc, null, new ScopeStack(), 0, new NulWriter(), fullyQualifiedNames, null, false, new HashSet<>(localData.seenMethods)); + body.toString(localData.abcIndex, path + "/inner", ScriptExportMode.AS, abc, null, writer, fullyQualifiedNames, new HashSet<>(localData.seenMethods)); } writer.endBlock(); writer.endMethod(); 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 d9cad1222..25a3bae04 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 @@ -1314,7 +1314,7 @@ public class AVM2SourceGenerator implements SourceGenerator { initt.add(ci.abc.class_info.get(ci.index).static_traits); try { - pcinit.convert(d, "-", ScriptExportMode.AS, true, mi, -1, ci.index, ci.abc, null, new ScopeStack(), GraphTextWriter.TRAIT_CLASS_INITIALIZER, new NulWriter(), new ArrayList<>(), initt, false, new HashSet<>()); + pcinit.convert(null, d, "-", ScriptExportMode.AS, true, mi, -1, ci.index, ci.abc, null, new ScopeStack(), GraphTextWriter.TRAIT_CLASS_INITIALIZER, new NulWriter(), new ArrayList<>(), initt, false, new HashSet<>()); //FIXME! Add skinparts from _skinParts attribute of parent class!!! } catch (InterruptedException ex) { Logger.getLogger(AVM2SourceGenerator.class.getName()).log(Level.SEVERE, "Getting parent skinparts interrupted", ex); 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 6748885a9..a11476162 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,9 +149,7 @@ public class ActionScript3Parser { // private final AbcIndexing otherABCs; //private static final List playerABCs = new ArrayList<>(); - private static AbcIndexing playerGlobalAbcIndex; - private static AbcIndexing airGlobalAbcIndex; private long uniqId() { uniqLast++; @@ -2602,9 +2600,9 @@ public class ActionScript3Parser { } public ActionScript3Parser(ABC abc, List otherAbcs, boolean air) throws IOException, InterruptedException { - initPlayer(); + SWF.initPlayer(); - abcIndex = new AbcIndexing(air ? airGlobalAbcIndex : playerGlobalAbcIndex); + abcIndex = new AbcIndexing(air ? SWF.getAirGlobalAbcIndex() : SWF.getPlayerGlobalAbcIndex()); for (ABC a : otherAbcs) { abcIndex.addAbc(a); } @@ -2612,29 +2610,11 @@ public class ActionScript3Parser { abcIndex.addAbc(abc); } - private static void initPlayer() throws IOException, InterruptedException { - if (playerGlobalAbcIndex == null) { - if (Configuration.getPlayerSWC() == null) { - throw new IOException("Player SWC library not found, please place it to " + Configuration.getFlashLibPath()); - } - - SWC swc = new SWC(new FileInputStream(Configuration.getPlayerSWC())); - SWF swf = new SWF(swc.getOpenable("library.swf"), true); - playerGlobalAbcIndex = new AbcIndexing(swf); - } - if (airGlobalAbcIndex == null) { - if (Configuration.getAirSWC() == null) { - return; - } - SWC swc = new SWC(new FileInputStream(Configuration.getAirSWC())); - SWF swf = new SWF(swc.getOpenable("library.swf"), true); - airGlobalAbcIndex = new AbcIndexing(swf); - } - } + public static void compile(String src, ABC abc, List otherABCs, String fileName, int classPos, int scriptIndex, boolean air) throws AVM2ParseException, IOException, InterruptedException, CompilationException { //List parABCs = new ArrayList<>(); - initPlayer(); + SWF.initPlayer(); ActionScript3Parser parser = new ActionScript3Parser(abc, otherABCs, air); boolean success = false; ABC originalAbc = ((ABCContainerTag) ((Tag) abc.parentTag).cloneTag()).getABC(); @@ -2659,7 +2639,7 @@ public class ActionScript3Parser { public static void compile(SWF swf, String src, String dst, int classPos, int scriptIndex, boolean air) { System.err.println("WARNING: AS3 compiler is not finished yet. This is only used for debuggging!"); try { - initPlayer(); + SWF.initPlayer(); ABC abc = new ABC(null); ActionScript3Parser parser = new ActionScript3Parser(abc, new ArrayList<>(), air); parser.addScript(new String(Helper.readFile(src), Utf8Helper.charset), src, classPos, scriptIndex); 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 6de0e8f9b..6851e4257 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 @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.abc.avm2.CodeStats; import com.jpexs.decompiler.flash.abc.avm2.UnknownInstructionCode; import com.jpexs.decompiler.flash.abc.avm2.deobfuscation.DeobfuscationLevel; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.configuration.Configuration; @@ -286,7 +287,7 @@ public final class MethodBody implements Cloneable { return ret; } - public void convert(final ConvertData convertData, final String path, ScriptExportMode exportMode, final boolean isStatic, final int methodIndex, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final ScopeStack scopeStack, final int initializerType, final NulWriter writer, final List fullyQualifiedNames, final List initTraits, boolean firstLevel, Set seenMethods) throws InterruptedException { + public void convert(AbcIndexing abcIndex, final ConvertData convertData, final String path, ScriptExportMode exportMode, final boolean isStatic, final int methodIndex, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final ScopeStack scopeStack, final int initializerType, final NulWriter writer, final List fullyQualifiedNames, final List initTraits, boolean firstLevel, Set seenMethods) throws InterruptedException { seenMethods.add(this.method_info); if (debugMode) { System.err.println("Decompiling " + path); @@ -309,10 +310,10 @@ public final class MethodBody implements Cloneable { HashMap localRegNames = getLocalRegNames(abc); List convertedItems1; try (Statistics s = new Statistics("AVM2Code.toGraphTargetItems")) { - convertedItems1 = converted.getCode().toGraphTargetItems(convertData.thisHasDefaultToPrimitive, convertData, path, methodIndex, isStatic, scriptIndex, classIndex, abc, converted, localRegNames, scopeStack, initializerType, fullyQualifiedNames, initTraits, Graph.SOP_USE_STATIC, new HashMap<>(), converted.getCode().visitCode(converted)); + convertedItems1 = converted.getCode().toGraphTargetItems(abcIndex, convertData.thisHasDefaultToPrimitive, convertData, path, methodIndex, isStatic, scriptIndex, classIndex, abc, converted, localRegNames, scopeStack, initializerType, fullyQualifiedNames, initTraits, Graph.SOP_USE_STATIC, new HashMap<>(), converted.getCode().visitCode(converted)); } try (Statistics s = new Statistics("Graph.graphToString")) { - Graph.graphToString(convertedItems1, writer, LocalData.create(abc, localRegNames, fullyQualifiedNames, seenMethods)); + Graph.graphToString(convertedItems1, writer, LocalData.create(abcIndex, abc, localRegNames, fullyQualifiedNames, seenMethods)); } convertedItems = convertedItems1; } @@ -344,7 +345,7 @@ public final class MethodBody implements Cloneable { } } - public GraphTextWriter toString(final String path, ScriptExportMode exportMode, final ABC abc, final Trait trait, final GraphTextWriter writer, final List fullyQualifiedNames, Set seenMethods) throws InterruptedException { + public GraphTextWriter toString(AbcIndexing abcIndex, final String path, ScriptExportMode exportMode, final ABC abc, final Trait trait, final GraphTextWriter writer, final List fullyQualifiedNames, Set seenMethods) throws InterruptedException { seenMethods.add(method_info); if (exportMode != ScriptExportMode.AS) { @@ -369,7 +370,7 @@ public final class MethodBody implements Cloneable { writer.appendNoHilight(this.method_info); writer.newLine(); } - Graph.graphToString(convertedItems, writer, LocalData.create(abc, localRegNames, fullyQualifiedNames, seenMethods)); + Graph.graphToString(convertedItems, writer, LocalData.create(abcIndex, abc, localRegNames, fullyQualifiedNames, seenMethods)); //writer.endMethod(); } else if (convertException instanceof TimeoutException) { // exception was logged in convert method @@ -419,14 +420,14 @@ public final class MethodBody implements Cloneable { return body; } - public String toSource(int scriptIndex, Set seenMethods) { + public String toSource(AbcIndexing abcIndex, int scriptIndex, Set seenMethods) { ConvertData convertData = new ConvertData(); convertData.deobfuscationMode = 0; try { - convert(convertData, "", ScriptExportMode.AS, false, method_info, 0, 0, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, seenMethods); + convert(abcIndex, convertData, "", ScriptExportMode.AS, false, method_info, 0, 0, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, seenMethods); HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false); writer.indent().indent().indent(); - toString("", ScriptExportMode.AS, abc, null, writer, new ArrayList<>(), seenMethods); + toString(abcIndex, "", ScriptExportMode.AS, abc, null, writer, new ArrayList<>(), seenMethods); writer.unindent().unindent().unindent(); return writer.toString(); } catch (InterruptedException ex) { 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 650ab0b29..b3f432cba 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 @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.avm2.model.NameValuePair; import com.jpexs.decompiler.flash.abc.avm2.model.NewObjectAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.StringAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; @@ -362,12 +363,12 @@ public abstract class Trait implements Cloneable, Serializable { return abc.constants.getMultiname(name_index).toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata); } - 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 { + public GraphTextWriter toString(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { writer.appendNoHilight(abc.constants.getMultiname(name_index).toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata)); return writer; } - 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 { + public void convert(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { } public abstract GraphTextWriter convertTraitHeader(ABC abc, GraphTextWriter writer); @@ -438,7 +439,7 @@ public abstract class Trait implements Cloneable, Serializable { return writer; } - public GraphTextWriter toStringPackaged(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { + public GraphTextWriter toStringPackaged(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { Namespace ns = abc.constants.getMultiname(name_index).getNamespace(abc.constants); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { String nsname = ns.getName(abc.constants).toPrintableString(true); @@ -447,28 +448,28 @@ public abstract class Trait implements Cloneable, Serializable { writer.appendNoHilight(" " + nsname); //assume not null name } writer.startBlock(); - toString(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + toString(abcIndex, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); writer.endBlock(); writer.newLine(); } return writer; } - public void convertPackaged(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { + public void convertPackaged(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { Namespace ns = abc.constants.getMultiname(name_index).getNamespace(abc.constants); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { String nsname = ns.getName(abc.constants).toPrintableString(true); - convert(parent, convertData, path + nsname, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + convert(abcIndex, parent, convertData, path + nsname, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } } public GraphTextWriter toStringHeader(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { - toString(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + toString(null, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); return writer; } public void convertHeader(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { - convert(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + convert(null, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } public final Multiname getName(ABC abc) { 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 5d2cfc498..4b8184f53 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 @@ -116,7 +116,7 @@ public class TraitClass 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 { + public GraphTextWriter toString(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { InstanceInfo instanceInfo = abc.instance_info.get(class_info); Multiname instanceInfoMultiname = instanceInfo.getName(abc.constants); @@ -136,7 +136,7 @@ public class TraitClass extends Trait implements TraitWithSlot { //static variables & constants ClassInfo classInfo = abc.class_info.get(class_info); - classInfo.static_traits.toString(new Class[]{TraitSlotConst.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, true, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, new ArrayList<>()); + classInfo.static_traits.toString(abcIndex, new Class[]{TraitSlotConst.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, true, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, new ArrayList<>()); //static initializer int bodyIndex = abc.findBodyIndex(classInfo.cinit_index); @@ -146,7 +146,7 @@ public class TraitClass extends Trait implements TraitWithSlot { if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { if (!classInitializerIsEmpty) { writer.startBlock(); - abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); + abc.bodies.get(bodyIndex).toString(abcIndex, path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); writer.endBlock(); } else { //Note: There must be trait/method highlight even if the initializer is empty to TraitList in GUI to work correctly @@ -164,7 +164,7 @@ public class TraitClass extends Trait implements TraitWithSlot { } //instance variables - instanceInfo.instance_traits.toString(new Class[]{TraitSlotConst.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, false, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, new ArrayList<>()); + instanceInfo.instance_traits.toString(abcIndex, new Class[]{TraitSlotConst.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, false, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, new ArrayList<>()); //instance initializer - constructor if (!instanceInfo.isInterface()) { @@ -194,7 +194,7 @@ public class TraitClass extends Trait implements TraitWithSlot { writer.appendNoHilight(")").startBlock(); if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { if (body != null) { - body.toString(path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); + body.toString(abcIndex, path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); } } @@ -204,10 +204,10 @@ public class TraitClass extends Trait implements TraitWithSlot { } //static methods - classInfo.static_traits.toString(new Class[]{TraitClass.class, TraitFunction.class, TraitMethodGetterSetter.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, true, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, new ArrayList<>()); + classInfo.static_traits.toString(abcIndex, new Class[]{TraitClass.class, TraitFunction.class, TraitMethodGetterSetter.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, true, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, new ArrayList<>()); //instance methods - instanceInfo.instance_traits.toString(new Class[]{TraitClass.class, TraitFunction.class, TraitMethodGetterSetter.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, false, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, convertData.ignoreFrameScripts ? frameTraitNames : new ArrayList<>()); + instanceInfo.instance_traits.toString(abcIndex, new Class[]{TraitClass.class, TraitFunction.class, TraitMethodGetterSetter.class}, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, false, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel, convertData.ignoreFrameScripts ? frameTraitNames : new ArrayList<>()); writer.endBlock(); // class writer.endClass(); @@ -216,7 +216,7 @@ public class TraitClass 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 { + public void convert(AbcIndexing abcIndex, 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<>(); @@ -244,7 +244,7 @@ public class TraitClass extends Trait implements TraitWithSlot { writer.mark(); List ts = new ArrayList<>(); ts.add(classInfo.static_traits); - abc.bodies.get(bodyIndex).convert(convertData, path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, true, classInfo.cinit_index, scriptIndex, class_info, abc, this, new ScopeStack(), GraphTextWriter.TRAIT_CLASS_INITIALIZER, writer, fullyQualifiedNames, ts, true, new HashSet<>()); + abc.bodies.get(bodyIndex).convert(abcIndex, convertData, path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, true, classInfo.cinit_index, scriptIndex, class_info, abc, this, new ScopeStack(), GraphTextWriter.TRAIT_CLASS_INITIALIZER, writer, fullyQualifiedNames, ts, true, new HashSet<>()); classInitializerIsEmpty = !writer.getMark(); } @@ -255,7 +255,7 @@ public class TraitClass extends Trait implements TraitWithSlot { List ts = new ArrayList<>(); ts.add(instanceInfo.instance_traits); MethodBody constructorBody = abc.bodies.get(bodyIndex); - constructorBody.convert(convertData, path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, false, instanceInfo.iinit_index, scriptIndex, class_info, abc, this, new ScopeStack(), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, writer, fullyQualifiedNames, ts, true, new HashSet<>()); + constructorBody.convert(abcIndex, convertData, path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, false, instanceInfo.iinit_index, scriptIndex, class_info, abc, this, new ScopeStack(), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, writer, fullyQualifiedNames, ts, true, new HashSet<>()); if (convertData.ignoreFrameScripts) { //find all addFrameScript(xx,this.method) in constructor @@ -310,9 +310,9 @@ public class TraitClass extends Trait implements TraitWithSlot { } //static variables,constants & methods - classInfo.static_traits.convert(this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, true, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); + classInfo.static_traits.convert(abcIndex, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, true, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); - instanceInfo.instance_traits.convert(this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, false, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); + instanceInfo.instance_traits.convert(abcIndex, this, convertData, path +/*packageName +*/ "/" + instanceInfoName, abc, false, exportMode, false, scriptIndex, class_info, writer, fullyQualifiedNames, parallel); } @Override 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 04f8075aa..07a61f5d2 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 @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; @@ -80,7 +81,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 { + public GraphTextWriter toString(AbcIndexing abcIndex, 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(scriptIndex, classIndex, false, abc, writer, getPackage(abc), fullyQualifiedNames); getMetaData(parent, convertData, abc, writer); writer.startMethod(method_info); @@ -89,7 +90,7 @@ public class TraitFunction extends Trait implements TraitWithSlot { writer.startBlock(); int bodyIndex = abc.findBodyIndex(method_info); if (bodyIndex != -1) { - abc.bodies.get(bodyIndex).toString(path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false, true), exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); + abc.bodies.get(bodyIndex).toString(abcIndex,path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false, true), exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); } writer.endBlock(); @@ -99,14 +100,14 @@ 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 { + public void convert(AbcIndexing abcIndex, 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(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); if (bodyIndex != -1) { - abc.bodies.get(bodyIndex).convert(convertData, path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false, true), exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true, new HashSet<>()); + abc.bodies.get(bodyIndex).convert(abcIndex, convertData, path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false, true), exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true, new HashSet<>()); } writer.endMethod(); } 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 087421c70..c7c726f88 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 @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -106,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 { + public void convert(AbcIndexing abcIndex, 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(scriptIndex, classIndex, isStatic, abc, writer, getPackage(abc), fullyQualifiedNames); } @@ -117,7 +118,7 @@ public class TraitMethodGetterSetter extends Trait { if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { if (!(classIndex != -1 && abc.instance_info.get(classIndex).isInterface() || bodyIndex == -1)) { if (bodyIndex != -1) { - abc.bodies.get(bodyIndex).convert(convertData, path, exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true, new HashSet<>()); + abc.bodies.get(bodyIndex).convert(abcIndex, convertData, path, exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true, new HashSet<>()); } } } @@ -125,7 +126,7 @@ public class TraitMethodGetterSetter extends Trait { } @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 { + public GraphTextWriter toString(AbcIndexing abcIndex, 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(scriptIndex, classIndex, isStatic, abc, writer, getPackage(abc), fullyQualifiedNames); @@ -144,7 +145,7 @@ public class TraitMethodGetterSetter extends Trait { convertTraitHeader(abc, writer); } if (bodyIndex != -1) { - abc.bodies.get(bodyIndex).toString(path, exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); + abc.bodies.get(bodyIndex).toString(abcIndex, path, exportMode, abc, this, writer, fullyQualifiedNames, new HashSet<>()); } } else { String retTypeRaw = abc.method_info.get(method_info).getReturnTypeRaw(abc.constants, fullyQualifiedNames); 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 839d257da..3f2e1bf94 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 @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.model.NewFunctionAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.AssignedValue; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.Multiname; @@ -108,7 +109,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { return writer; } - public void getValueStr(ScriptExportMode exportMode, Trait parent, ConvertData convertData, GraphTextWriter writer, ABC abc, List fullyQualifiedNames) throws InterruptedException { + public void getValueStr(AbcIndexing abcIndex, ScriptExportMode exportMode, Trait parent, ConvertData convertData, GraphTextWriter writer, ABC abc, List fullyQualifiedNames) throws InterruptedException { if (convertData.assignedValues.containsKey(this)) { AssignedValue assignment = convertData.assignedValues.get(this); @@ -122,7 +123,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { writer.newLine(); } if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { - assignment.value.toString(writer, LocalData.create(abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>())); + assignment.value.toString(writer, LocalData.create(abcIndex, abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>())); } writer.endMethod(); writer.endTrait(); @@ -144,7 +145,7 @@ public class TraitSlotConst 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 { + public GraphTextWriter toString(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { getMetaData(parent, convertData, abc, writer); Multiname n = getName(abc); boolean showModifier = true; @@ -162,22 +163,22 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { if (convertData.assignedValues.containsKey(this)) { GraphTargetItem val = convertData.assignedValues.get(this).value; if (val instanceof NewFunctionAVM2Item) { - return val.toString(writer, LocalData.create(abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>())); + return val.toString(writer, LocalData.create(abcIndex, abc, new HashMap<>(), fullyQualifiedNames, new HashSet<>())); } } getNameStr(writer, abc, fullyQualifiedNames); if (value_kind != 0 || convertData.assignedValues.containsKey(this)) { writer.appendNoHilight(" = "); - getValueStr(exportMode, parent, convertData, writer, abc, fullyQualifiedNames); + getValueStr(abcIndex, exportMode, parent, convertData, writer, abc, fullyQualifiedNames); } return writer.appendNoHilight(";").newLine(); } @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 { + public void convert(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { getNameStr(writer, abc, fullyQualifiedNames); if (value_kind != 0 || convertData.assignedValues.containsKey(this)) { - getValueStr(exportMode, parent, convertData, writer, abc, fullyQualifiedNames); + getValueStr(abcIndex,exportMode, parent, convertData, writer, abc, fullyQualifiedNames); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index 628b68a67..26f69f7f9 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 @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.configuration.Configuration; @@ -130,8 +131,10 @@ public class Traits implements Cloneable, Serializable { Trait parent; ConvertData convertData; + + AbcIndexing abcIndex; - public TraitConvertTask(Trait trait, Trait parent, ConvertData convertData, boolean makePackages, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, int traitIndex, boolean parallel) { + public TraitConvertTask(AbcIndexing abcIndex, Trait trait, Trait parent, ConvertData convertData, boolean makePackages, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, int traitIndex, boolean parallel) { this.trait = trait; this.parent = parent; this.convertData = convertData; @@ -146,20 +149,21 @@ public class Traits implements Cloneable, Serializable { this.fullyQualifiedNames = fullyQualifiedNames; this.traitIndex = traitIndex; this.parallel = parallel; + this.abcIndex = abcIndex; } @Override public Void call() throws InterruptedException { if (makePackages) { - trait.convertPackaged(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + trait.convertPackaged(abcIndex, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } else { - trait.convert(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + trait.convert(abcIndex, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } return null; } } - public GraphTextWriter toString(Class[] traitTypes, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, boolean makePackages, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel, List ignoredTraitNames) throws InterruptedException { + public GraphTextWriter toString(AbcIndexing abcIndex, Class[] traitTypes, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, boolean makePackages, int scriptIndex, int classIndex, GraphTextWriter writer, List fullyQualifiedNames, boolean parallel, List ignoredTraitNames) throws InterruptedException { List ordered = new ArrayList<>(traits); loopi: @@ -231,9 +235,9 @@ public class Traits implements Cloneable, Serializable { writer.startTrait(h); } if (makePackages) { - trait.toStringPackaged(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + trait.toStringPackaged(abcIndex, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } else { - trait.toString(parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); + trait.toString(abcIndex, parent, convertData, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel); } if (trait instanceof TraitClass) { writer.endClass(); @@ -244,10 +248,10 @@ public class Traits implements Cloneable, Serializable { return writer; } - public void convert(Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, boolean makePackages, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { + public void convert(AbcIndexing abcIndex, Trait parent, ConvertData convertData, String path, ABC abc, boolean isStatic, ScriptExportMode exportMode, boolean makePackages, int scriptIndex, int classIndex, NulWriter writer, List fullyQualifiedNames, boolean parallel) throws InterruptedException { if (!parallel || traits.size() < 2) { for (int t = 0; t < traits.size(); t++) { - TraitConvertTask task = new TraitConvertTask(traits.get(t), parent, convertData, makePackages, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, t, parallel); + TraitConvertTask task = new TraitConvertTask(abcIndex, traits.get(t), parent, convertData, makePackages, path, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, t, parallel); task.call(); } } else { @@ -257,7 +261,7 @@ public class Traits implements Cloneable, Serializable { futureResults = new ArrayList<>(); for (int t = 0; t < traits.size(); t++) { // each convert task needs a separate NulWriter, because they are executed parallel - TraitConvertTask task = new TraitConvertTask(traits.get(t), parent, convertData, makePackages, path, abc, isStatic, exportMode, scriptIndex, classIndex, new NulWriter(), fullyQualifiedNames, t, parallel); + TraitConvertTask task = new TraitConvertTask(abcIndex, traits.get(t), parent, convertData, makePackages, path, abc, isStatic, exportMode, scriptIndex, classIndex, new NulWriter(), fullyQualifiedNames, t, parallel); Future future = executor.submit(task); futureResults.add(future); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java index d30094145..2e016aa6f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java @@ -32,6 +32,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ThisAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.DeclarationAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.traits.Trait; @@ -102,11 +103,11 @@ public class AS3ScriptExporter { } } - private String handleMxmlMethod(Map namespaces, ScriptPack pack, int cindex, TraitMethodGetterSetter t) { + private String handleMxmlMethod(AbcIndexing abcIndex, Map namespaces, ScriptPack pack, int cindex, TraitMethodGetterSetter t) { StringBuilder out = new StringBuilder(); int method = t.method_info; try { - pack.abc.findBody(method).convert(new ConvertData(), "??", ScriptExportMode.AS, false, method, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); + pack.abc.findBody(method).convert(abcIndex, new ConvertData(), "??", ScriptExportMode.AS, false, method, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); List ci = pack.abc.findBody(method).convertedItems; if (!ci.isEmpty()) { @@ -135,7 +136,7 @@ public class AS3ScriptExporter { int name2 = ((FullMultinameAVM2Item) cap.propertyName).multinameIndex; for (Trait ct : pack.abc.instance_info.get(cindex).instance_traits.traits) { if (ct.name_index == name2 && (ct instanceof TraitMethodGetterSetter)) { - tagContent.append(handleMxmlMethod(namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); + tagContent.append(handleMxmlMethod(abcIndex,namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); } } } @@ -175,11 +176,11 @@ public class AS3ScriptExporter { return out.toString(); } - private String handleMxmlArrMethod(Map namespaces, ScriptPack pack, int cindex, TraitMethodGetterSetter t) { + private String handleMxmlArrMethod(AbcIndexing abcIndex, Map namespaces, ScriptPack pack, int cindex, TraitMethodGetterSetter t) { StringBuilder out = new StringBuilder(); int method = t.method_info; try { - pack.abc.findBody(method).convert(new ConvertData(), "??", ScriptExportMode.AS, false, method, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()/*??*/); + pack.abc.findBody(method).convert(abcIndex, new ConvertData(), "??", ScriptExportMode.AS, false, method, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()/*??*/); List ci = pack.abc.findBody(method).convertedItems; if (!ci.isEmpty() && (ci.get(0) instanceof DeclarationAVM2Item)) { @@ -195,7 +196,7 @@ public class AS3ScriptExporter { int name = ((FullMultinameAVM2Item) cp.propertyName).multinameIndex; for (Trait ct : pack.abc.instance_info.get(cindex).instance_traits.traits) { if (ct.name_index == name && (ct instanceof TraitMethodGetterSetter)) { - out.append(handleMxmlMethod(namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); + out.append(handleMxmlMethod(abcIndex, namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); } } } @@ -248,7 +249,7 @@ public class AS3ScriptExporter { return ns + ":" + parentName; } - private String generateMxml(ScriptPack pack) { + private String generateMxml(AbcIndexing abcIndex, ScriptPack pack) { StringBuilder out = new StringBuilder(); StringBuilder tagProp = new StringBuilder(); StringBuilder tagContent = new StringBuilder(); @@ -270,7 +271,7 @@ public class AS3ScriptExporter { int iinit = pack.abc.instance_info.get(cindex).iinit_index; try { - pack.abc.findBody(iinit).convert(new ConvertData(), "??", ScriptExportMode.AS, false, iinit, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); + pack.abc.findBody(iinit).convert(abcIndex, new ConvertData(), "??", ScriptExportMode.AS, false, iinit, pack.scriptIndex, cindex, pack.abc, t, new ScopeStack(), 0/*?*/, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); List iinitBody = pack.abc.findBody(iinit).convertedItems; for (GraphTargetItem it : iinitBody) { if (it instanceof InitPropertyAVM2Item) { @@ -286,7 +287,7 @@ public class AS3ScriptExporter { int name = ((FullMultinameAVM2Item) cp.propertyName).multinameIndex; for (Trait ct : pack.abc.instance_info.get(cindex).instance_traits.traits) { if (ct.name_index == name && (ct instanceof TraitMethodGetterSetter)) { - tagContent.append(handleMxmlMethod(namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); + tagContent.append(handleMxmlMethod(abcIndex, namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); } } tagContent.append(""); @@ -304,7 +305,7 @@ public class AS3ScriptExporter { int name = ((FullMultinameAVM2Item) gp.propertyName).multinameIndex; for (Trait ct : pack.abc.instance_info.get(cindex).instance_traits.traits) { if (ct.name_index == name && (ct instanceof TraitMethodGetterSetter)) { - tagContent.append(handleMxmlArrMethod(namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); + tagContent.append(handleMxmlArrMethod(abcIndex, namespaces, pack, cindex, (TraitMethodGetterSetter) ct)); } } } @@ -368,7 +369,7 @@ public class AS3ScriptExporter { if (flexClass != null && item.getClassPath().toRawString().equals(flexClass)) { File file = item.getExportFile(outdir, ".mxml"); String filePath = file.getPath(); - String mxml = generateMxml(item); + String mxml = generateMxml(swf.getAbcIndex(), item); if (mxml != null) { Helper.writeFile(filePath, Utf8Helper.getBytes(mxml)); files.add(filePath.toLowerCase()); @@ -396,7 +397,7 @@ public class AS3ScriptExporter { files.add(filePath.toLowerCase()); } - tasks.add(new ExportPackTask(handler, cnt++, packs.size(), item.getClassPath(), item, file, exportSettings, parallel, evl)); + tasks.add(new ExportPackTask(swf.getAbcIndex(), handler, cnt++, packs.size(), item.getClassPath(), item, file, exportSettings, parallel, evl)); } if (!parallel || tasks.size() < 2) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java index 9c5663f0d..8c8a75147 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.RetryTask; import com.jpexs.decompiler.flash.RunnableIOExResult; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.helpers.Helper; import java.io.File; @@ -55,8 +56,10 @@ public class ExportPackTask implements Callable { long stopTime; EventListener eventListener; + + AbcIndexing abcIndex; - public ExportPackTask(AbortRetryIgnoreHandler handler, int index, int count, ClassPath path, ScriptPack pack, File file, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) { + public ExportPackTask(AbcIndexing abcIndex, AbortRetryIgnoreHandler handler, int index, int count, ClassPath path, ScriptPack pack, File file, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) { this.pack = pack; this.file = file; this.exportSettings = exportSettings; @@ -66,6 +69,7 @@ public class ExportPackTask implements Callable { this.parallel = parallel; this.handler = handler; this.eventListener = evl; + this.abcIndex = abcIndex; } @Override @@ -74,7 +78,7 @@ public class ExportPackTask implements Callable { @Override public void run() throws IOException, InterruptedException { startTime = System.currentTimeMillis(); - this.result = pack.export(file, exportSettings, parallel); + this.result = pack.export(abcIndex, file, exportSettings, parallel); stopTime = System.currentTimeMillis(); } }; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java index 0493b7c1b..f9fae2a10 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.exporters.script; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.graph.AVM2Graph; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.action.ActionGraph; import com.jpexs.decompiler.flash.action.ActionList; @@ -85,8 +86,8 @@ public class PcodeGraphVizExporter { export(gr, writer); } - public void exportAs3(ABC abc, MethodBody body, GraphTextWriter writer) throws InterruptedException { - AVM2Graph gr = new AVM2Graph(body.getCode(), abc, body, false, -1, -1, new HashMap<>(), new ScopeStack(), new HashMap<>(), new ArrayList<>(), new HashMap<>(), body.getCode().visitCode(body)); + public void exportAs3(AbcIndexing abcIndex, ABC abc, MethodBody body, GraphTextWriter writer) throws InterruptedException { + AVM2Graph gr = new AVM2Graph(abcIndex, body.getCode(), abc, body, false, -1, -1, new HashMap<>(), new ScopeStack(), new HashMap<>(), new ArrayList<>(), new HashMap<>(), body.getCode().visitCode(body)); export(gr, writer); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index 0797de262..49d5e9ed1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.GetLexAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.GetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ThisAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.InstanceInfo; import com.jpexs.decompiler.flash.abc.types.MethodBody; @@ -1715,7 +1716,7 @@ public class XFLConverter { continue; } final ScriptPack spriteScriptPack = characterScriptPacks.containsKey(sprite.spriteId) ? characterScriptPacks.get(sprite.spriteId) : null; - convertTimeline(sprite.spriteId, nonLibraryShapes, backgroundColor, tags, sprite.getTags(), characters, "Symbol " + symbol.getCharacterId(), flaVersion, files, symbolStr, spriteScriptPack); + convertTimeline(swf.getAbcIndex(), sprite.spriteId, nonLibraryShapes, backgroundColor, tags, sprite.getTags(), characters, "Symbol " + symbol.getCharacterId(), flaVersion, files, symbolStr, spriteScriptPack); } else if (symbol instanceof ShapeTag) { itemIcon = "1"; @@ -2616,7 +2617,7 @@ public class XFLConverter { return -1; } - private static Map getFrameScriptsFromPack(ScriptPack pack) { + private static Map getFrameScriptsFromPack(AbcIndexing abcIndex, ScriptPack pack) { Map ret = new HashMap<>(); int classIndex = getPackMainClassId(pack); if (classIndex > -1) { @@ -2625,7 +2626,7 @@ public class XFLConverter { int constructorMethodIndex = instanceInfo.iinit_index; MethodBody constructorBody = abc.findBody(constructorMethodIndex); try { - constructorBody.convert(new ConvertData(), "??", ScriptExportMode.AS, false, constructorMethodIndex, pack.scriptIndex, classIndex, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); + constructorBody.convert(abcIndex, new ConvertData(), "??", ScriptExportMode.AS, false, constructorMethodIndex, pack.scriptIndex, classIndex, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); Map frameToTraitMultiname = new HashMap<>(); @@ -2691,9 +2692,9 @@ public class XFLConverter { MethodBody frameBody = abc.findBody(methodIndex); StringBuilder scriptBuilder = new StringBuilder(); - frameBody.convert(new ConvertData(), "??", ScriptExportMode.AS, false, methodIndex, pack.scriptIndex, classIndex, abc, methodTrait, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); + frameBody.convert(abcIndex, new ConvertData(), "??", ScriptExportMode.AS, false, methodIndex, pack.scriptIndex, classIndex, abc, methodTrait, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true, new HashSet<>()); StringBuilderTextWriter writer = new StringBuilderTextWriter(Configuration.getCodeFormatting(), scriptBuilder); - frameBody.toString("??", ScriptExportMode.AS, abc, methodTrait, writer, new ArrayList<>(), new HashSet<>()); + frameBody.toString(abcIndex, "??", ScriptExportMode.AS, abc, methodTrait, writer, new ArrayList<>(), new HashSet<>()); String script = scriptBuilder.toString(); ret.put(frame, script); @@ -2707,7 +2708,7 @@ public class XFLConverter { return ret; } - private boolean convertActionScriptLayer(int spriteId, ReadOnlyTagList tags, ReadOnlyTagList timeLineTags, String backgroundColor, XFLXmlWriter writer, ScriptPack scriptPack) throws XMLStreamException { + private boolean convertActionScriptLayer(AbcIndexing abcIndex, int spriteId, ReadOnlyTagList tags, ReadOnlyTagList timeLineTags, String backgroundColor, XFLXmlWriter writer, ScriptPack scriptPack) throws XMLStreamException { boolean hasScript = false; String script = ""; @@ -2728,7 +2729,7 @@ public class XFLConverter { Map frameToScriptMap = new HashMap<>(); if (scriptPack != null) { - frameToScriptMap = getFrameScriptsFromPack(scriptPack); + frameToScriptMap = getFrameScriptsFromPack(abcIndex, scriptPack); } for (Tag t : timeLineTags) { @@ -2943,12 +2944,12 @@ public class XFLConverter { return outlineColor.toHexRGB(); } - private void convertTimeline(int spriteId, List nonLibraryShapes, String backgroundColor, ReadOnlyTagList tags, ReadOnlyTagList timelineTags, HashMap characters, String name, FLAVersion flaVersion, HashMap files, XFLXmlWriter writer, ScriptPack scriptPack) throws XMLStreamException { + private void convertTimeline(AbcIndexing abcIndex, int spriteId, List nonLibraryShapes, String backgroundColor, ReadOnlyTagList tags, ReadOnlyTagList timelineTags, HashMap characters, String name, FLAVersion flaVersion, HashMap files, XFLXmlWriter writer, ScriptPack scriptPack) throws XMLStreamException { writer.writeStartElement("DOMTimeline", new String[]{"name", name}); writer.writeStartElement("layers"); boolean hasLabel = convertLabelsLayer(spriteId, tags, timelineTags, backgroundColor, writer); - boolean hasScript = convertActionScriptLayer(spriteId, tags, timelineTags, backgroundColor, writer, scriptPack); + boolean hasScript = convertActionScriptLayer(abcIndex, spriteId, tags, timelineTags, backgroundColor, writer, scriptPack); int index = 0; @@ -3612,7 +3613,7 @@ public class XFLConverter { domDocument.writeStartElement("timelines"); ScriptPack documentScriptPack = characterScriptPacks.containsKey(0) ? characterScriptPacks.get(0) : null; - convertTimeline(0, nonLibraryShapes, backgroundColor, swf.getTags(), swf.getTags(), characters, "Scene 1", flaVersion, files, domDocument, documentScriptPack); + convertTimeline(swf.getAbcIndex(), 0, nonLibraryShapes, backgroundColor, swf.getTags(), swf.getTags(), characters, "Scene 1", flaVersion, files, domDocument, documentScriptPack); domDocument.writeEndElement(); if (hasAmfMetadata) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java index c7e9ac1c3..567f8ad46 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/model/LocalData.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.graph.model; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.AbcIndexing; import com.jpexs.decompiler.flash.action.model.ConstantPool; import com.jpexs.decompiler.graph.DottedChain; import java.util.HashMap; @@ -36,6 +37,8 @@ public class LocalData { public ConstantPool constants; public AVM2ConstantPool constantsAvm2; + + public AbcIndexing abcIndex; public HashMap localRegNames; @@ -51,13 +54,14 @@ public class LocalData { return localData; } - public static LocalData create(ABC abc, HashMap localRegNames, List fullyQualifiedNames, Set seenMethods) { + public static LocalData create(AbcIndexing abcIndex, ABC abc, HashMap localRegNames, List fullyQualifiedNames, Set seenMethods) { LocalData localData = new LocalData(); localData.abc = abc; localData.constantsAvm2 = abc.constants; localData.localRegNames = localRegNames; localData.fullyQualifiedNames = fullyQualifiedNames; localData.seenMethods = seenMethods; + localData.abcIndex = abcIndex; return localData; } } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DecompileTestBase.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DecompileTestBase.java index ddcec8478..7ff00cea9 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DecompileTestBase.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DecompileTestBase.java @@ -108,9 +108,9 @@ public abstract class ActionScript3DecompileTestBase extends ActionScriptTestBas Configuration.autoDeobfuscate.set(methodName.toLowerCase().contains("obfus")); - abc.bodies.get(bodyIndex).convert(new ConvertData(), "run", ScriptExportMode.AS, isStatic, abc.bodies.get(bodyIndex).method_info, scriptIndex, clsIndex, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), ts, true, new HashSet<>()); + abc.bodies.get(bodyIndex).convert(swf.getAbcIndex(), new ConvertData(), "run", ScriptExportMode.AS, isStatic, abc.bodies.get(bodyIndex).method_info, scriptIndex, clsIndex, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), ts, true, new HashSet<>()); writer = new HighlightedTextWriter(new CodeFormatting(), false); - abc.bodies.get(bodyIndex).toString("run", ScriptExportMode.AS, abc, null, writer, new ArrayList<>(), new HashSet<>()); + abc.bodies.get(bodyIndex).toString(swf.getAbcIndex(), "run", ScriptExportMode.AS, abc, null, writer, new ArrayList<>(), new HashSet<>()); } catch (InterruptedException ex) { fail(); return; diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java index e3b6f2aed..208e54fb6 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java @@ -131,7 +131,7 @@ public class ActionScript3DeobfuscatorTest extends ActionScriptTestBase { HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); par.addScript(str, "Test.as", 0, 0); - abc.script_info.get(0).getPacks(abc, 0, "", new ArrayList<>()).get(0).toSource(writer, abc.script_info.get(0).traits.traits, new ConvertData(), ScriptExportMode.AS, false, false); + abc.script_info.get(0).getPacks(abc, 0, "", new ArrayList<>()).get(0).toSource(swf.getAbcIndex(), writer, abc.script_info.get(0).traits.traits, new ConvertData(), ScriptExportMode.AS, false, false); return writer.toString(); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java index 8592aeb03..7c5c104b5 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java @@ -91,7 +91,7 @@ public class DirectEditingTest extends FileTestBase { System.out.println("Recompiling:" + classPathString + "..."); try { - en.toSource(htw, abc.script_info.get(s).traits.traits, new ConvertData(), ScriptExportMode.AS, false, false); + en.toSource(swf.getAbcIndex(), htw, abc.script_info.get(s).traits.traits, new ConvertData(), ScriptExportMode.AS, false, false); String original = htw.toString(); abc.replaceScriptPack(As3ScriptReplacerFactory.createFFDec() /*TODO: test the otherone*/, en, original); } catch (As3ScriptReplaceException ex) { diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java index a283637f7..789febd93 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.as3decompile; import com.jpexs.decompiler.flash.ActionScript3DecompileTestBase; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.ConvertData; @@ -50,7 +51,8 @@ public class ActionScript3ClassTest extends ActionScript3DecompileTestBase { DoABC2Tag tag = null; ABC abc = null; ScriptPack scriptPack = null; - for (Tag t : getSwf(swfId).getTags()) { + SWF swf = getSwf(swfId); + for (Tag t : swf.getTags()) { if (t instanceof DoABC2Tag) { tag = (DoABC2Tag) t; abc = tag.getABC(); @@ -65,7 +67,7 @@ public class ActionScript3ClassTest extends ActionScript3DecompileTestBase { HighlightedTextWriter writer = null; try { writer = new HighlightedTextWriter(new CodeFormatting(), false); - scriptPack.toSource(writer, abc.script_info.get(scriptPack.scriptIndex).traits.traits, new ConvertData(), ScriptExportMode.AS, false, false); + scriptPack.toSource(swf.getAbcIndex(), writer, abc.script_info.get(scriptPack.scriptIndex).traits.traits, new ConvertData(), ScriptExportMode.AS, false, false); } catch (InterruptedException ex) { fail(); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java index 6175e9332..cfa2aa708 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/generators/AS3Generator.java @@ -145,8 +145,8 @@ public class AS3Generator { Configuration.autoDeobfuscate.set(clsName.toLowerCase().contains("obfus")); - b.convert(new ConvertData(), "", ScriptExportMode.AS, false, ((TraitMethodGetterSetter) t).method_info, pack.scriptIndex, classId, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), ts, true, new HashSet<>()); - b.toString("", ScriptExportMode.AS, abc, null, src, new ArrayList<>(), new HashSet<>()); + b.convert(swf.getAbcIndex(),new ConvertData(), "", ScriptExportMode.AS, false, ((TraitMethodGetterSetter) t).method_info, pack.scriptIndex, classId, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), ts, true, new HashSet<>()); + b.toString(swf.getAbcIndex(), "", ScriptExportMode.AS, abc, null, src, new ArrayList<>(), new HashSet<>()); String[] srcs = src.toString().split("[\r\n]+"); for (int i = 0; i < srcs.length; i++) { String ss = srcs[i]; diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 8057d9038..d355c8584 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -213,15 +213,14 @@ public class Main { public static CancellableWorker deobfuscatePCodeWorker = null; public static CancellableWorker swfPrepareWorker = null; - public static final int LIBRARY_AIR = 0; - public static final int LIBRARY_FLASH = 1; + public static boolean isSwfAir(Openable openable) { SwfSpecificCustomConfiguration conf = Configuration.getSwfSpecificCustomConfiguration(openable.getShortPathTitle()); if (conf != null) { - String libraryAsStr = conf.getCustomData(CustomConfigurationKeys.KEY_LIBRARY, "" + LIBRARY_FLASH); + String libraryAsStr = conf.getCustomData(CustomConfigurationKeys.KEY_LIBRARY, "" + SWF.LIBRARY_FLASH); int libraryAsInt = Integer.parseInt(libraryAsStr); - return libraryAsInt == LIBRARY_AIR; + return libraryAsInt == SWF.LIBRARY_AIR; } return false; } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index a0254aa96..48f1fb8a1 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -243,9 +243,9 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener(); libraryComboBox.addItem("AIR (airglobal.swc)"); libraryComboBox.addItem("Flash (playerglobal.swc)"); - libraryComboBox.setSelectedIndex(Main.LIBRARY_FLASH); + libraryComboBox.setSelectedIndex(SWF.LIBRARY_FLASH); libraryComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 313ac887f..358f3982f 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -247,7 +247,7 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi public void graph() { try { - AVM2Graph gr = new AVM2Graph(abc.bodies.get(bodyIndex).getCode(), abc, abc.bodies.get(bodyIndex), false, -1, -1, new HashMap<>(), new ScopeStack(), new HashMap<>(), new ArrayList<>(), new HashMap<>(), abc.bodies.get(bodyIndex).getCode().visitCode(abc.bodies.get(bodyIndex))); + AVM2Graph gr = new AVM2Graph(null /*?*/, abc.bodies.get(bodyIndex).getCode(), abc, abc.bodies.get(bodyIndex), false, -1, -1, new HashMap<>(), new ScopeStack(), new HashMap<>(), new ArrayList<>(), new HashMap<>(), abc.bodies.get(bodyIndex).getCode().visitCode(abc.bodies.get(bodyIndex))); (new GraphDialog(getAbcPanel().getMainPanel().getMainFrame().getWindow(), gr, name)).setVisible(true); } catch (InterruptedException ex) { Logger.getLogger(ASMSourceEditorPane.class.getName()).log(Level.SEVERE, null, ex);