diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index ee6ebe28f..8c8ed7042 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -246,8 +246,8 @@ public class SWF { } } - public SWF(InputStream is) throws IOException { - this(is, null); + public SWF(InputStream is, boolean paralelRead) throws IOException { + this(is, null, paralelRead); } /** @@ -256,7 +256,7 @@ public class SWF { * @param is Stream to read SWF from * @throws IOException */ - public SWF(InputStream is, PercentListener listener) throws IOException { + public SWF(InputStream is, PercentListener listener, boolean paralelRead) throws IOException { byte hdr[] = new byte[3]; is.read(hdr); String shdr = new String(hdr); @@ -303,7 +303,7 @@ public class SWF { int tmpFirstByetOfFrameRate = sis.readUI8(); frameRate = sis.readUI8(); frameCount = sis.readUI16(); - tags = sis.readTagList(0); + tags = sis.readTagList(0, paralelRead); assignClassesToSymbols(); } @@ -422,7 +422,7 @@ public class SWF { return true; } - public boolean exportAS3Class(String className, String outdir, boolean isPcode) throws Exception { + public boolean exportAS3Class(String className, String outdir, boolean isPcode, boolean paralel) throws Exception { List abcTags = new ArrayList<>(); for (Tag t : tags) { @@ -441,14 +441,14 @@ public class SWF { } String exStr = "Exporting " + "tag " + (i + 1) + "/" + abcTags.size() + " " + cnt + scr.getPath() + " ..."; informListeners("export", exStr); - scr.export(outdir, abcTags, isPcode); + scr.export(outdir, abcTags, isPcode, paralel); return true; } } return false; } - public boolean exportActionScript(String outdir, boolean isPcode) throws Exception { + public boolean exportActionScript(String outdir, boolean isPcode, boolean paralel) throws Exception { boolean asV3Found = false; final EventListener evl = new EventListener() { @Override @@ -468,7 +468,7 @@ public class SWF { for (int i = 0; i < abcTags.size(); i++) { ABCContainerTag t = abcTags.get(i); t.getABC().addEventListener(evl); - t.getABC().export(outdir, isPcode, abcTags, "tag " + (i + 1) + "/" + abcTags.size() + " "); + t.getABC().export(outdir, isPcode, abcTags, "tag " + (i + 1) + "/" + abcTags.size() + " ", paralel); } if (!asV3Found) { @@ -1308,12 +1308,12 @@ public class SWF { return ret; } - public void exportFla(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion) { - XFLConverter.convertSWF(this, swfName, outfile, true, generator, generatorVerName, generatorVersion); + public void exportFla(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion, boolean paralel) { + XFLConverter.convertSWF(this, swfName, outfile, true, generator, generatorVerName, generatorVersion, paralel); } - public void exportXfl(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion) { - XFLConverter.convertSWF(this, swfName, outfile, false, generator, generatorVerName, generatorVersion); + public void exportXfl(String outfile, String swfName, String generator, String generatorVerName, String generatorVersion, boolean paralel) { + XFLConverter.convertSWF(this, swfName, outfile, false, generator, generatorVerName, generatorVersion, paralel); } public static float twipToPixel(int twip) { diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index db416791c..1985561e0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -1141,16 +1141,18 @@ public class SWFInputStream extends InputStream { private final Tag tag; private final int version; private final int level; + private boolean paralel; - public TagResolutionTask(Tag tag, int version, int level) { + public TagResolutionTask(Tag tag, int version, int level, boolean paralel) { this.tag = tag; this.version = version; this.level = level; + this.paralel = paralel; } @Override public Tag call() throws Exception { - return SWFInputStream.resolveTag(tag, version, level); + return SWFInputStream.resolveTag(tag, version, level, paralel); } } @@ -1161,8 +1163,13 @@ public class SWFInputStream extends InputStream { * @return List of tags * @throws IOException */ - public List readTagList(int level) throws IOException { - ExecutorService executor = Executors.newCachedThreadPool(); + public List readTagList(int level, boolean paralel) throws IOException { + ExecutorService executor = null; + if (paralel) { + executor = Executors.newFixedThreadPool(20); + } else { + executor = Executors.newFixedThreadPool(1); + } List> futureResults = new ArrayList<>(); List tags = new ArrayList<>(); Tag tag; @@ -1170,7 +1177,7 @@ public class SWFInputStream extends InputStream { while (true) { long pos = getPos(); try { - tag = readTag(level, pos, false); + tag = readTag(level, pos, false, paralel); } catch (EndOfStreamException ex) { tag = null; } @@ -1183,7 +1190,7 @@ public class SWFInputStream extends InputStream { tag.previousTag = previousTag; previousTag = tag; - Future future = executor.submit(new TagResolutionTask(tag, version, level)); + Future future = executor.submit(new TagResolutionTask(tag, version, level, paralel)); futureResults.add(future); } @@ -1198,7 +1205,7 @@ public class SWFInputStream extends InputStream { return tags; } - public static Tag resolveTag(Tag tag, int version, int level) { + public static Tag resolveTag(Tag tag, int version, int level, boolean paralel) { Tag ret; byte data[] = tag.getData(version); @@ -1307,7 +1314,7 @@ public class SWFInputStream extends InputStream { break; //case 38: case 39: - ret = new DefineSpriteTag(data, version, level, pos); + ret = new DefineSpriteTag(data, version, level, pos, paralel); break; //case 40: case 41: @@ -1440,8 +1447,8 @@ public class SWFInputStream extends InputStream { * @return Tag or null when End tag * @throws IOException */ - public Tag readTag(int level, long pos) throws IOException { - return readTag(level, pos, true); + public Tag readTag(int level, long pos, boolean paralel) throws IOException { + return readTag(level, pos, true, paralel); } /** @@ -1451,7 +1458,7 @@ public class SWFInputStream extends InputStream { * @return Tag or null when End tag * @throws IOException */ - public Tag readTag(int level, long pos, boolean resolve) throws IOException { + public Tag readTag(int level, long pos, boolean resolve, boolean paralel) throws IOException { int tagIDTagLength = readUI16(); int tagID = (tagIDTagLength) >> 6; if (tagID == 0) { @@ -1500,7 +1507,7 @@ public class SWFInputStream extends InputStream { } } if (resolve) { - return resolveTag(ret, version, level); + return resolveTag(ret, version, level, paralel); } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index b42a9e539..a98c084f9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -563,8 +563,8 @@ public class ABC { } } - public void export(String directory, boolean pcode, List abcList) throws IOException { - export(directory, pcode, abcList, ""); + public void export(String directory, boolean pcode, List abcList, boolean paralel) throws IOException { + export(directory, pcode, abcList, "", paralel); } private class ExportPackTask implements Runnable { @@ -577,8 +577,9 @@ public class ABC { String path; AtomicInteger index; int count; + boolean paralel; - public ExportPackTask(AtomicInteger index, int count, String path, ScriptPack pack, String directory, List abcList, boolean pcode, String informStr) { + public ExportPackTask(AtomicInteger index, int count, String path, ScriptPack pack, String directory, List abcList, boolean pcode, String informStr, boolean paralel) { this.pack = pack; this.directory = directory; this.abcList = abcList; @@ -587,12 +588,13 @@ public class ABC { this.path = path; this.index = index; this.count = count; + this.paralel = paralel; } @Override public void run() { try { - pack.export(directory, abcList, pcode); + pack.export(directory, abcList, pcode, paralel); } catch (IOException ex) { Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, ex); } @@ -602,13 +604,13 @@ public class ABC { } } - public void export(String directory, boolean pcode, List abcList, String abcStr) throws IOException { + public void export(String directory, boolean pcode, List abcList, String abcStr, boolean paralel) throws IOException { ExecutorService executor = Executors.newFixedThreadPool(20); AtomicInteger cnt = new AtomicInteger(1); for (int i = 0; i < script_info.length; i++) { HashMap packs = script_info[i].getPacks(this, i); for (String path : packs.keySet()) { - executor.execute(new ExportPackTask(cnt, script_info.length, path, packs.get(path), directory, abcList, pcode, abcStr)); + executor.execute(new ExportPackTask(cnt, script_info.length, path, packs.get(path), directory, abcList, pcode, abcStr, paralel)); } } try { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index ad98a6d68..86eba5e67 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -55,7 +55,7 @@ public class ScriptPack { return packageName + "." + scriptName; } - public void export(String directory, List abcList, boolean pcode) throws IOException { + public void export(String directory, List abcList, boolean pcode, boolean paralel) throws IOException { String path = getPath(); String scriptName = path.substring(path.lastIndexOf(".") + 1); String packageName = path.substring(0, path.lastIndexOf(".")); @@ -69,9 +69,9 @@ public class ScriptPack { Multiname name = abc.script_info[scriptIndex].traits.traits[t].getName(abc); Namespace ns = name.getNamespace(abc.constants); if ((ns.kind == Namespace.KIND_PACKAGE) || (ns.kind == Namespace.KIND_PACKAGE_INTERNAL)) { - fos.write(abc.script_info[scriptIndex].traits.traits[t].convertPackaged("", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList()).getBytes()); + fos.write(abc.script_info[scriptIndex].traits.traits[t].convertPackaged("", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList(), paralel).getBytes()); } else { - fos.write(abc.script_info[scriptIndex].traits.traits[t].convert("", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList()).getBytes()); + fos.write(abc.script_info[scriptIndex].traits.traits[t].convert("", abcList, abc, false, pcode, scriptIndex, -1, false, new ArrayList(), paralel).getBytes()); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java index 7ea1418a1..299c3254a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.gui; +import com.jpexs.decompiler.flash.Configuration; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; @@ -293,7 +294,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } if (!cache.contains(scriptLeaf)) { for (int scriptTraitIndex : scriptLeaf.traitIndices) { - hilightedCodeBuf.append(script.traits.traits[scriptTraitIndex].convertPackaged("", abcList, abc, false, false, scriptIndex, -1, true, new ArrayList())); + hilightedCodeBuf.append(script.traits.traits[scriptTraitIndex].convertPackaged("", abcList, abc, false, false, scriptIndex, -1, true, new ArrayList(), (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE))); } hilightedCode = hilightedCodeBuf.toString(); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsListItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsListItem.java index 96bd35e61..cec09abdc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsListItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsListItem.java @@ -64,9 +64,9 @@ public class TraitsListItem { @Override public String toString() { if ((type != Type.INITIALIZER) && isStatic) { - return abc.class_info[classIndex].static_traits.traits[index].convertHeader("", abcTags, abc, true, false, scriptIndex, classIndex, false, new ArrayList()); + return abc.class_info[classIndex].static_traits.traits[index].convertHeader("", abcTags, abc, true, false, scriptIndex, classIndex, false, new ArrayList(), false); } else if ((type != Type.INITIALIZER) && (!isStatic)) { - return abc.instance_info[classIndex].instance_traits.traits[index].convertHeader("", abcTags, abc, false, false, scriptIndex, classIndex, false, new ArrayList()); + return abc.instance_info[classIndex].instance_traits.traits[index].convertHeader("", abcTags, abc, false, false, scriptIndex, classIndex, false, new ArrayList(), false); } else if (!isStatic) { return STR_INSTANCE_INITIALIZER; } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index ccc330b27..4a4a983ae 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -79,14 +79,14 @@ public class ScriptInfo { return "method_index=" + init_index + "\r\n" + traits.toString(abc, fullyQualifiedNames); } - public String convert(List abcTags, ABC abc, boolean pcode, boolean highlighting, int scriptIndex) { - return traits.convert("", abcTags, abc, false, pcode, true, scriptIndex, -1, highlighting, new ArrayList()); + public String convert(List abcTags, ABC abc, boolean pcode, boolean highlighting, int scriptIndex, boolean paralel) { + return traits.convert("", abcTags, abc, false, pcode, true, scriptIndex, -1, highlighting, new ArrayList(), paralel); } - public void export(ABC abc, List abcList, String directory, boolean pcode, int scriptIndex) throws IOException { + public void export(ABC abc, List abcList, String directory, boolean pcode, int scriptIndex, boolean paralel) throws IOException { HashMap packs = getPacks(abc, scriptIndex); for (ScriptPack pack : packs.values()) { - pack.export(directory, abcList, pcode); + pack.export(directory, abcList, pcode, paralel); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 633be193f..23e999e2a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -114,16 +114,16 @@ public abstract class Trait implements Serializable { return abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata); } - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { return abc.constants.constant_multiname[name_index].toString(abc.constants, fullyQualifiedNames) + " kind=" + kindType + " metadata=" + Helper.intArrToString(metadata); } - public String convertPackaged(String path, List abcTags, ABC abc, boolean isStatic, boolean pcod, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { - return makePackageFromIndex(abc, name_index, convert(path, abcTags, abc, isStatic, pcod, scriptIndex, classIndex, highlight, fullyQualifiedNames)); + public String convertPackaged(String path, List abcTags, ABC abc, boolean isStatic, boolean pcod, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { + return makePackageFromIndex(abc, name_index, convert(path, abcTags, abc, isStatic, pcod, scriptIndex, classIndex, highlight, fullyQualifiedNames, paralel)); } - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { - return convert(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames).trim(); + public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { + return convert(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, paralel).trim(); } protected String makePackageFromIndex(ABC abc, int name_index, String value) { @@ -153,7 +153,7 @@ public abstract class Trait implements Serializable { return packageName + "." + objectName; } - public void export(String directory, ABC abc, List abcList, boolean pcode, int scriptIndex, int classIndex, boolean isStatic) throws IOException { + public void export(String directory, ABC abc, List abcList, boolean pcode, int scriptIndex, int classIndex, boolean isStatic, boolean paralel) throws IOException { Multiname name = getName(abc); Namespace ns = name.getNamespace(abc.constants); String packageName = ns.getName(abc.constants); @@ -164,7 +164,7 @@ public abstract class Trait implements Serializable { } String fileName = outDir.toString() + File.separator + objectName + ".as"; try (FileOutputStream fos = new FileOutputStream(fileName)) { - fos.write(convertPackaged("", abcList, abc, isStatic, pcode, scriptIndex, classIndex, false, new ArrayList()).getBytes()); + fos.write(convertPackaged("", abcList, abc, isStatic, pcode, scriptIndex, classIndex, false, new ArrayList(), paralel).getBytes()); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index 0404cc04b..f4f9ddcaa 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -324,13 +324,13 @@ public class TraitClass extends Trait implements TraitWithSlot { } @Override - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { String classHeader = abc.instance_info[class_info].getClassHeaderStr(abc, fullyQualifiedNames); return classHeader; } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { if (!highlight) { //Highlighting.doHighlight = false; @@ -501,9 +501,9 @@ public class TraitClass extends Trait implements TraitWithSlot { //} //static variables,constants & methods - outTraits.add(abc.class_info[class_info].static_traits.convert(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, true, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames)); + outTraits.add(abc.class_info[class_info].static_traits.convert(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, true, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames, paralel)); - outTraits.add(abc.instance_info[class_info].instance_traits.convert(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, false, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames)); + outTraits.add(abc.instance_info[class_info].instance_traits.convert(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames), abcTags, abc, false, pcode, false, scriptIndex, class_info, highlight, fullyQualifiedNames, paralel)); StringBuilder bui = new StringBuilder(); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index 5b21451af..32e9e620a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -41,7 +41,7 @@ public class TraitFunction extends Trait implements TraitWithSlot { } @Override - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; @@ -51,11 +51,11 @@ public class TraitFunction extends Trait implements TraitWithSlot { } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { if (!Configuration.DO_DECOMPILE) { return ""; } - String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames); + String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, paralel); String bodyStr = ""; int bodyIndex = abc.findBodyIndex(method_info); if (bodyIndex != -1) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java index f17e00acc..5afd630da 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java @@ -35,7 +35,7 @@ public class TraitMethodGetterSetter extends Trait { } @Override - public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convertHeader(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; @@ -53,12 +53,12 @@ public class TraitMethodGetterSetter extends Trait { } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { if (debugMode) { System.err.println("Decompiling " + path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames)); } - String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames); + String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, paralel); String bodyStr = ""; int bodyIndex = abc.findBodyIndex(method_info); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index 4a0ba01b6..3e97b9e6b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -110,7 +110,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { } @Override - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames, boolean paralel) { String modifier = getModifiers(abcTags, abc, isStatic) + " "; if (modifier.equals(" ")) { modifier = ""; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index 10c909087..c6c840f36 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java @@ -79,8 +79,9 @@ public class Traits implements Serializable { boolean highlighting; List fullyQualifiedNames; int traitIndex; + boolean paralel; - public TraitConvertTask(Trait trait, boolean makePackages, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames, int traitIndex) { + public TraitConvertTask(Trait trait, boolean makePackages, String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames, int traitIndex, boolean paralel) { this.trait = trait; this.makePackages = makePackages; this.path = path; @@ -93,15 +94,16 @@ public class Traits implements Serializable { this.highlighting = highlighting; this.fullyQualifiedNames = fullyQualifiedNames; this.traitIndex = traitIndex; + this.paralel = paralel; } @Override public String call() throws Exception { String plus; if (makePackages) { - plus = trait.convertPackaged(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames); + plus = trait.convertPackaged(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, paralel); } else { - plus = trait.convert(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames); + plus = trait.convert(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, paralel); } if (highlighting) { int h = traitIndex; @@ -120,12 +122,12 @@ public class Traits implements Serializable { } } - public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, boolean makePackages, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames) { + public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, boolean makePackages, int scriptIndex, int classIndex, boolean highlighting, List fullyQualifiedNames, boolean paralel) { String s = ""; - ExecutorService executor = Executors.newFixedThreadPool(Trait.debugMode ? 1 : 20); + ExecutorService executor = Executors.newFixedThreadPool(paralel ? 20 : 1); List> futureResults = new ArrayList<>(); for (int t = 0; t < traits.length; t++) { - Future future = executor.submit(new TraitConvertTask(traits[t], makePackages, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, t)); + Future future = executor.submit(new TraitConvertTask(traits[t], makePackages, path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlighting, fullyQualifiedNames, t, paralel)); futureResults.add(future); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java index 2d723fd21..5678492c5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java @@ -39,10 +39,10 @@ public abstract class ConstVarMultinameUsage extends TraitMultinameUsage { return super.toString(abcTags, abc) + " " + (parentTraitIndex > -1 ? (isStatic - ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList())) - : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList()))) + ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)) + : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false))) : "") - + ((TraitSlotConst) traits.traits[traitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList()); + + ((TraitSlotConst) traits.traits[traitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false); } public int getTraitIndex() { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java index cc650649a..e8c8ee0f6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java @@ -48,10 +48,10 @@ public abstract class MethodMultinameUsage extends TraitMultinameUsage { : "instance initializer") : ((parentTraitIndex > -1 ? (isStatic - ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList())) - : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList()))) + " " + ? (((TraitMethodGetterSetter) abc.class_info[classIndex].static_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)) + : (((TraitMethodGetterSetter) abc.instance_info[classIndex].instance_traits.traits[parentTraitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false))) + " " : "") - + (((TraitMethodGetterSetter) traits.traits[traitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList())))); + + (((TraitMethodGetterSetter) traits.traits[traitIndex]).convertHeader("", abcTags, abc, isStatic, false, -1/*FIXME*/, classIndex, false, new ArrayList(), false)))); } public int getTraitIndex() { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index 513d692c9..c8cccd4aa 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -174,7 +174,7 @@ public class Main { public void percent(int p) { startWork("Reading SWF", p); } - }); + }, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); locswf.addEventListener(new EventListener() { @Override public void handleEvent(String event, Object data) { @@ -492,7 +492,7 @@ public class Main { boolean exportOK; try { printHeader(); - SWF exfile = new SWF(new FileInputStream(inFile)); + SWF exfile = new SWF(new FileInputStream(inFile), (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); exfile.addEventListener(new EventListener() { @Override public void handleEvent(String event, Object data) { @@ -507,7 +507,7 @@ public class Main { System.out.println("Exporting shapes..."); exfile.exportShapes(outDir.getAbsolutePath() + File.separator + "shapes"); System.out.println("Exporting scripts..."); - exfile.exportActionScript(outDir.getAbsolutePath() + File.separator + "scripts", false); + exfile.exportActionScript(outDir.getAbsolutePath() + File.separator + "scripts", false, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); System.out.println("Exporting movies..."); exfile.exportMovies(outDir.getAbsolutePath() + File.separator + "movies"); System.out.println("Exporting sounds..."); @@ -527,10 +527,10 @@ public class Main { if ((pos + 5 < args.length) && (args[pos + 4].equals("-selectas3class"))) { exportOK = true; for (int i = pos + 5; i < args.length; i++) { - exportOK = exportOK && exfile.exportAS3Class(args[i], outDir.getAbsolutePath(), exportFormat.equals("pcode")); + exportOK = exportOK && exfile.exportAS3Class(args[i], outDir.getAbsolutePath(), exportFormat.equals("pcode"), (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); } } else { - exportOK = exfile.exportActionScript(outDir.getAbsolutePath(), exportFormat.equals("pcode")); + exportOK = exfile.exportActionScript(outDir.getAbsolutePath(), exportFormat.equals("pcode"), (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); } } else if (exportFormat.equals("movie")) { exfile.exportMovies(outDir.getAbsolutePath()); @@ -548,10 +548,10 @@ public class Main { exfile.exportTexts(outDir.getAbsolutePath(), false); exportOK = true; } else if (exportFormat.equals("fla")) { - exfile.exportFla(outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version); + exfile.exportFla(outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); exportOK = true; } else if (exportFormat.equals("xfl")) { - exfile.exportXfl(outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version); + exfile.exportXfl(outDir.getAbsolutePath(), inFile.getName(), applicationName, applicationVerName, version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); exportOK = true; } else { exportOK = false; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index a0e367f3c..e2e52cf27 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -193,6 +193,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi private JButton imageReplaceButton; private JPanel imageButtonsPanel; private JCheckBoxMenuItem miInternalViewer; + private JCheckBoxMenuItem miParallelSpeedUp; public void setPercent(int percent) { progressBar.setValue(percent); @@ -385,6 +386,12 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi miInternalViewer.addActionListener(this); menuTools.add(miInternalViewer); + miParallelSpeedUp = new JCheckBoxMenuItem("Parallel SpeedUp"); + miParallelSpeedUp.setSelected((Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); + miParallelSpeedUp.setActionCommand("PARALLELSPEEDUP"); + miParallelSpeedUp.addActionListener(this); + menuTools.add(miParallelSpeedUp); + menuTools.add(miProxy); //menuTools.add(menuDeobfuscation); @@ -1176,6 +1183,19 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi @Override public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("PARALLELSPEEDUP")) { + String confStr = "Parallelism can speed up loading and decompilation but uses more memory.\r\n"; + if (miParallelSpeedUp.isSelected()) { + confStr += " Do you want to turn this ON?"; + } else { + confStr += " Do you want to turn this OFF?"; + } + if (JOptionPane.showConfirmDialog(null, confStr, "Parallelism", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { + Configuration.setConfig("paralelSpeedUp", (Boolean) miParallelSpeedUp.isSelected()); + } else { + miParallelSpeedUp.setSelected(!miParallelSpeedUp.isSelected()); + } + } if (e.getActionCommand().equals("INTERNALVIEWERSWITCH")) { Configuration.setConfig("internalFlashViewer", (Boolean) miInternalViewer.isSelected()); } @@ -1419,9 +1439,9 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi @Override public void run() { if (compressed) { - swf.exportFla(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version); + swf.exportFla(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); } else { - swf.exportXfl(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version); + swf.exportXfl(selfile.getAbsolutePath(), new File(Main.file).getName(), Main.applicationName, Main.applicationVerName, Main.version, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); } Main.stopWork(); } @@ -1508,7 +1528,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi for (int i = 0; i < tlsList.size(); i++) { ScriptPack tls = tlsList.get(i); Main.startWork("Exporting " + (i + 1) + "/" + tlsList.size() + " " + tls.getPath() + " ..."); - tls.export(selFile, abcList, isPcode); + tls.export(selFile, abcList, isPcode, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); } } else { List allNodes = new ArrayList<>(); @@ -1527,7 +1547,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi swf.exportMovies(selFile + File.separator + "movies"); swf.exportSounds(selFile + File.separator + "sounds", isMp3OrWav, isMp3OrWav); swf.exportBinaryData(selFile + File.separator + "binaryData"); - swf.exportActionScript(selFile, isPcode); + swf.exportActionScript(selFile, isPcode, (Boolean) Configuration.getConfig("paralelSpeedUp", Boolean.TRUE)); } } catch (Exception ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "Error during export", ex); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index 3714d3f2b..6c1cac4bb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -150,12 +150,12 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT * @param version SWF version * @throws IOException */ - public DefineSpriteTag(byte[] data, int version, int level, long pos) throws IOException { + public DefineSpriteTag(byte[] data, int version, int level, long pos, boolean paralel) throws IOException { super(39, "DefineSprite", data, pos); SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version, pos); spriteId = sis.readUI16(); frameCount = sis.readUI16(); - subTags = sis.readTagList(level + 1); + subTags = sis.readTagList(level + 1, paralel); } static int c = 0; diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index caf22f889..bf92de664 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -2445,7 +2445,7 @@ public class XFLConverter { return ret; } - public static void convertSWF(SWF swf, String swfFileName, String outfile, boolean compressed, String generator, String generatorVerName, String generatorVersion) { + public static void convertSWF(SWF swf, String swfFileName, String outfile, boolean compressed, String generator, String generatorVerName, String generatorVersion, boolean paralel) { String domDocument = ""; String baseName = swfFileName; File f = new File(baseName); @@ -2739,7 +2739,7 @@ public class XFLConverter { File outF = new File(outfile); File outDir = outF.getParentFile(); try { - swf.exportActionScript(outDir.getAbsolutePath(), false); + swf.exportActionScript(outDir.getAbsolutePath(), false, paralel); } catch (Exception ex) { Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, "Error during ActionScript3 export", ex); }