From f96fb33c4d0c295f52acef62c1db77278a454da7 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 2 Jul 2015 09:07:55 +0200 Subject: [PATCH] AS2 script import: import pcode/constants --- .../com/jpexs/decompiler/flash/abc/ABC.java | 4 +- .../decompiler/flash/abc/ScriptPack.java | 16 +++-- .../decompiler/flash/abc/avm2/AVM2Code.java | 6 +- ...ptParser.java => ActionScript3Parser.java} | 10 +-- .../jpexs/decompiler/flash/action/Action.java | 29 ++++++++ ...ptParser.java => ActionScript2Parser.java} | 4 +- .../settings/ScriptExportSettings.java | 2 + ...ptImporter.java => AS2ScriptImporter.java} | 46 ++++++++++-- .../flash/importers/AS3ScriptImporter.java | 44 ++++++++++++ .../flash/tags/DefineButtonTag.java | 9 ++- .../decompiler/flash/tags/DoActionTag.java | 8 ++- .../flash/tags/DoInitActionTag.java | 8 ++- .../decompiler/flash/tags/base/ASMSource.java | 10 +-- .../flash/types/BUTTONCONDACTION.java | 8 ++- .../flash/types/CLIPACTIONRECORD.java | 8 ++- .../console/CommandLineArgumentParser.java | 71 +++++++++++++++++-- .../jpexs/decompiler/flash/gui/MainPanel.java | 15 ++-- .../flash/gui/action/ActionPanel.java | 30 +------- 18 files changed, 255 insertions(+), 73 deletions(-) rename libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/{ActionScriptParser.java => ActionScript3Parser.java} (99%) rename libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/{ActionScriptParser.java => ActionScript2Parser.java} (99%) rename libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/{ScriptImporter.java => AS2ScriptImporter.java} (61%) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java index 95678a188..e1b934290 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -25,7 +25,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallPropertyIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushStringIns; import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException; -import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScriptParser; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScript3Parser; import com.jpexs.decompiler.flash.abc.types.ABCException; import com.jpexs.decompiler.flash.abc.types.ClassInfo; import com.jpexs.decompiler.flash.abc.types.InstanceInfo; @@ -1247,7 +1247,7 @@ public class ABC { } List otherAbcs = new ArrayList<>(pack.allABCs); otherAbcs.remove(this); - ActionScriptParser.compile(as, this, otherAbcs, isDocumentClass, scriptName, newClassIndex); + ActionScript3Parser.compile(as, this, otherAbcs, isDocumentClass, scriptName, newClassIndex); // Move newly added script to its position script_info.set(oldIndex, script_info.get(newIndex)); script_info.remove(newIndex); 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 684204afe..d65a131c1 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 @@ -104,6 +104,15 @@ public class ScriptPack extends AS3ClassTreeItem { return scriptName; } + public File getExportFile(String directory, ScriptExportSettings exportSettings) throws IOException { + String scriptName = getPathScriptName(); + String packageName = getPathPackage(); + File outDir = new File(directory + File.separatorChar + makeDirPath(packageName)); + Path.createDirectorySafe(outDir); + String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + exportSettings.getFileExtension(); + return new File(fileName); + } + /*public String getPath() { String packageName = ""; String scriptName = ""; @@ -197,12 +206,7 @@ public class ScriptPack extends AS3ClassTreeItem { File file = null; if (!exportSettings.singleFile) { - String scriptName = getPathScriptName(); - String packageName = getPathPackage(); - File outDir = new File(directory + File.separatorChar + makeDirPath(packageName)); - Path.createDirectorySafe(outDir); - String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + exportSettings.getFileExtension(); - file = new File(fileName); + file = getExportFile(directory, exportSettings); } try (FileTextWriter writer = exportSettings.singleFile ? null : new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(file))) { 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 8653f2fb3..862fbf048 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 @@ -903,6 +903,7 @@ public class AVM2Code implements Cloneable { writer.newLine(); } } + if (info != null) { writer.appendNoHilight("method").newLine(); writer.appendNoHilight("name "); @@ -1049,7 +1050,7 @@ public class AVM2Code implements Cloneable { if (exportMode == ScriptExportMode.HEX) { Helper.byteArrayToHexWithHeader(writer, getBytes()); - } else { + } else if (exportMode == ScriptExportMode.PCODE || exportMode == ScriptExportMode.PCODE_HEX) { for (AVM2Instruction ins : code) { long ofs = ins.offset; if (exportMode == ScriptExportMode.PCODE_HEX) { @@ -1124,7 +1125,10 @@ public class AVM2Code implements Cloneable { } ip++; } + } else if (exportMode == ScriptExportMode.CONSTANTS) { + writer.appendNoHilight("Constant export mode is not supported.").newLine(); } + return writer; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java similarity index 99% rename from libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java index f20e46a4c..782302715 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java @@ -125,7 +125,7 @@ import java.util.logging.Logger; * * @author JPEXS */ -public class ActionScriptParser { +public class ActionScript3Parser { private long uniqLast = 0; @@ -2376,7 +2376,7 @@ public class ActionScriptParser { addScriptFromTree(traits, documentClass, classPos); } - public ActionScriptParser(ABC abc, List otherABCs) { + public ActionScript3Parser(ABC abc, List otherABCs) { this.abc = abc; this.otherABCs = otherABCs; } @@ -2401,7 +2401,7 @@ public class ActionScriptParser { initPlayer(); parABCs.addAll(playerABCs); parABCs.addAll(otherABCs); - ActionScriptParser parser = new ActionScriptParser(abc, parABCs); + ActionScript3Parser parser = new ActionScript3Parser(abc, parABCs); parser.addScript(src, documentClass, fileName, classPos); } @@ -2410,13 +2410,13 @@ public class ActionScriptParser { try { initPlayer(); ABC abc = new ABC(null); - ActionScriptParser parser = new ActionScriptParser(abc, playerABCs); + ActionScript3Parser parser = new ActionScript3Parser(abc, playerABCs); parser.addScript(new String(Helper.readFile(src), Utf8Helper.charset), true, src, classPos); try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(dst)))) { abc.saveToStream(fos); } } catch (Exception ex) { - Logger.getLogger(ActionScriptParser.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(ActionScript3Parser.class.getName()).log(Level.SEVERE, null, ex); } System.exit(0); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index 294e6371c..1e5ec49df 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -75,6 +75,7 @@ import com.jpexs.decompiler.graph.model.IfItem; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.decompiler.graph.model.NotItem; import com.jpexs.decompiler.graph.model.ScriptEndItem; +import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.io.ByteArrayOutputStream; @@ -370,6 +371,34 @@ public abstract class Action implements GraphSourceItem { return baos.toByteArray(); } + public static ByteArrayRange actionsToByteArrayRange(List list, boolean addZero, int version) { + byte[] bytes = Action.actionsToBytes(list, addZero, version); + return new ByteArrayRange(bytes); + } + + public static void setConstantPools(ASMSource src, List> constantPools) { + try { + ActionList actions = src.getActions(); + int poolIdx = 0; + for (Action action : actions) { + if (action instanceof ActionConstantPool) { + ActionConstantPool cPool = (ActionConstantPool) action; + List constantPool = constantPools.get(poolIdx); + cPool.constantPool = constantPool; + + poolIdx++; + if (constantPools.size() <= poolIdx) { + break; + } + } + } + + src.setActions(actions); + } catch (InterruptedException ex) { + logger.log(Level.SEVERE, null, ex); + } + } + /** * Set addresses of actions in the list * diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java similarity index 99% rename from libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java index 10776133a..b5eb0a780 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java @@ -155,11 +155,11 @@ import java.util.List; * * @author JPEXS */ -public class ActionScriptParser { +public class ActionScript2Parser { private final int swfVersion; - public ActionScriptParser(int swfVersion) { + public ActionScript2Parser(int swfVersion) { this.swfVersion = swfVersion; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java index e663c961c..b75426fc6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/ScriptExportSettings.java @@ -47,6 +47,8 @@ public class ScriptExportSettings { return ".pcode"; case HEX: return ".hex"; + case CONSTANTS: + return ".txt"; default: throw new Error("Unsupported script export mode: " + mode); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS2ScriptImporter.java similarity index 61% rename from libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS2ScriptImporter.java index 60d7c5ff8..479a49a5e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ScriptImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS2ScriptImporter.java @@ -17,6 +17,8 @@ package com.jpexs.decompiler.flash.importers; import com.jpexs.decompiler.flash.action.parser.ActionParseException; +import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; +import com.jpexs.decompiler.flash.action.parser.script.ActionScript2Parser; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.helpers.Helper; @@ -34,9 +36,9 @@ import java.util.logging.Logger; * * @author JPEXS */ -public class ScriptImporter { +public class AS2ScriptImporter { - private static final Logger logger = Logger.getLogger(ScriptImporter.class.getName()); + private static final Logger logger = Logger.getLogger(AS2ScriptImporter.class.getName()); public int importScripts(String scriptsFolder, Map asms) { if (!scriptsFolder.endsWith(File.separator)) { @@ -68,11 +70,11 @@ public class ScriptImporter { String fileName = Path.combine(currentOutDir, name) + ".as"; if (new File(fileName).exists()) { - String as = Helper.readTextFile(fileName); + String txt = Helper.readTextFile(fileName); - com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser par = new com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser(asm.getSwf().version); + ActionScript2Parser par = new ActionScript2Parser(asm.getSwf().version); try { - asm.setActions(par.actionsFromString(as)); + asm.setActions(par.actionsFromString(txt)); } catch (ActionParseException ex) { logger.log(Level.SEVERE, "%error% on line %line%, file: %file%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)).replace("%file%", fileName), ex); } catch (CompilationException ex) { @@ -84,6 +86,40 @@ public class ScriptImporter { asm.setModified(); importCount++; } + + fileName = Path.combine(currentOutDir, name) + ".pcode"; + if (new File(fileName).exists()) { + String txt = Helper.readTextFile(fileName); + + try { + asm.setActions(ASMParser.parse(0, true, txt, asm.getSwf().version, false)); + } catch (IOException ex) { + logger.log(Level.SEVERE, "error during script import, file: %file%".replace("%file%", fileName), ex); + } catch (ActionParseException ex) { + logger.log(Level.SEVERE, "%error% on line %line%, file: %file%".replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)).replace("%file%", fileName), ex); + } + + asm.setModified(); + importCount++; + } + + fileName = Path.combine(currentOutDir, name) + ".hex"; + if (new File(fileName).exists()) { + String txt = Helper.readTextFile(fileName); + + asm.setActionBytes(Helper.getBytesFromHexaText(txt)); + asm.setModified(); + importCount++; + } + + fileName = Path.combine(currentOutDir, name) + ".txt"; + if (new File(fileName).exists()) { + String txt = Helper.readTextFile(fileName); + + asm.setConstantPools(Helper.getConstantPoolsFromText(txt)); + asm.setModified(); + importCount++; + } } return importCount; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java new file mode 100644 index 000000000..e3e2b6939 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.importers; + +import com.jpexs.decompiler.flash.abc.ScriptPack; +import java.io.File; +import java.util.List; +import java.util.logging.Logger; + +/** + * + * @author JPEXS + */ +public class AS3ScriptImporter { + + private static final Logger logger = Logger.getLogger(AS3ScriptImporter.class.getName()); + + public int importScripts(String scriptsFolder, List packs) { + if (!scriptsFolder.endsWith(File.separator)) { + scriptsFolder += File.separator; + } + + int importCount = 0; + for (ScriptPack pack : packs) { + // todo honfika + } + + return importCount; + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index 9a08e8223..0f78cfcd9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -200,8 +200,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { @Override public void setActions(List actions) { - byte[] bytes = Action.actionsToBytes(actions, true, swf.version); - actionBytes = new ByteArrayRange(bytes, 0, bytes.length); + actionBytes = Action.actionsToByteArrayRange(actions, true, swf.version); } @Override @@ -214,6 +213,11 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { this.actionBytes = new ByteArrayRange(actionBytes); } + @Override + public void setConstantPools(List> constantPools) { + Action.setConstantPools(this, constantPools); + } + @Override public void setModified() { setModified(true); @@ -437,5 +441,4 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { public void setSourceTag(Tag t) { //nothing } - } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java index e714264f3..20499336a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java @@ -151,8 +151,7 @@ public class DoActionTag extends Tag implements ASMSource { @Override public void setActions(List actions) { - byte[] bytes = Action.actionsToBytes(actions, true, swf.version); - actionBytes = new ByteArrayRange(bytes); + actionBytes = Action.actionsToByteArrayRange(actions, true, swf.version); } @Override @@ -165,6 +164,11 @@ public class DoActionTag extends Tag implements ASMSource { this.actionBytes = new ByteArrayRange(actionBytes); } + @Override + public void setConstantPools(List> constantPools) { + Action.setConstantPools(this, constantPools); + } + @Override public void setModified() { setModified(true); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index 2ecd2c212..96d4067ad 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -149,8 +149,7 @@ public class DoInitActionTag extends Tag implements CharacterIdTag, ASMSource { @Override public void setActions(List actions) { - byte[] bytes = Action.actionsToBytes(actions, true, swf.version); - actionBytes = new ByteArrayRange(bytes); + actionBytes = Action.actionsToByteArrayRange(actions, true, swf.version); } @Override @@ -163,6 +162,11 @@ public class DoInitActionTag extends Tag implements CharacterIdTag, ASMSource { this.actionBytes = new ByteArrayRange(actionBytes); } + @Override + public void setConstantPools(List> constantPools) { + Action.setConstantPools(this, constantPools); + } + @Override public void setModified() { setModified(true); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java index 8fdf1ee41..675b0462f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java @@ -1,23 +1,22 @@ /* * Copyright (C) 2010-2015 JPEXS, All rights reserved. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library. */ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.DisassemblyListener; -import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; @@ -71,6 +70,8 @@ public interface ASMSource extends Exportable { public void setActionBytes(byte[] actionBytes); + public void setConstantPools(List> constantPools); + public GraphTextWriter getActionBytesAsHex(GraphTextWriter writer); public void addDisassemblyListener(DisassemblyListener listener); @@ -88,5 +89,4 @@ public interface ASMSource extends Exportable { public Tag getSourceTag(); public void setSourceTag(Tag t); - } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java index e3a1bc5ce..dfc3ed7df 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java @@ -226,8 +226,7 @@ public class BUTTONCONDACTION implements ASMSource, Serializable { @Override public void setActions(List actions) { - byte[] bytes = Action.actionsToBytes(actions, true, swf.version); - actionBytes = new ByteArrayRange(bytes); + actionBytes = Action.actionsToByteArrayRange(actions, true, swf.version); } @Override @@ -240,6 +239,11 @@ public class BUTTONCONDACTION implements ASMSource, Serializable { this.actionBytes = new ByteArrayRange(actionBytes); } + @Override + public void setConstantPools(List> constantPools) { + Action.setConstantPools(this, constantPools); + } + @Override public void setModified() { if (tag != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java index 2e567e2e5..a58f5e5c1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java @@ -212,8 +212,7 @@ public class CLIPACTIONRECORD implements ASMSource, Serializable { @Override public void setActions(List actions) { - byte[] bytes = Action.actionsToBytes(actions, true, swf.version); - actionBytes = new ByteArrayRange(bytes); + actionBytes = Action.actionsToByteArrayRange(actions, true, swf.version); } @Override @@ -226,6 +225,11 @@ public class CLIPACTIONRECORD implements ASMSource, Serializable { this.actionBytes = new ByteArrayRange(actionBytes); } + @Override + public void setConstantPools(List> constantPools) { + Action.setConstantPools(this, constantPools); + } + @Override public void setModified() { if (tag != null) { diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 380b78f64..2eef8685f 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -31,11 +31,12 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException; import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.ASM3Parser; import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.MissingSymbolHandler; -import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScriptParser; +import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScript3Parser; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.action.parser.ActionParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; +import com.jpexs.decompiler.flash.action.parser.script.ActionScript2Parser; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.configuration.ConfigurationItem; import com.jpexs.decompiler.flash.exporters.BinaryDataExporter; @@ -80,7 +81,10 @@ import com.jpexs.decompiler.flash.importers.BinaryDataImporter; import com.jpexs.decompiler.flash.importers.ImageImporter; import com.jpexs.decompiler.flash.importers.SwfXmlImporter; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; +import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag; +import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag; import com.jpexs.decompiler.flash.tags.DefineSpriteTag; +import com.jpexs.decompiler.flash.tags.JPEGTablesTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.ButtonTag; @@ -476,7 +480,7 @@ public class CommandLineArgumentParser { } else if (command.equals("replace")) { parseReplace(args); } else if (command.equals("as3compiler")) { - ActionScriptParser.compile(null /*?*/, args.pop(), args.pop(), 0); + ActionScript3Parser.compile(null /*?*/, args.pop(), args.pop(), 0); } else if (nextParam.equals("-help") || nextParam.equals("--help") || nextParam.equals("/?") || nextParam.equals("\\_") /* /? translates as this on windows */) { printHeader(); printCmdLineUsage(); @@ -834,7 +838,7 @@ public class CommandLineArgumentParser { private static void parseDebugTool(Stack args) { String cmd = args.pop().toLowerCase(); switch (cmd) { - case "findtag": + case "findtag": { String folder = args.pop(); String tagIdOrName = args.pop(); int tagId; @@ -876,13 +880,70 @@ public class CommandLineArgumentParser { } catch (IOException | InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } - } System.setOut(oldOut); System.setErr(oldErr); Main.initLogging(Configuration.debugMode.get()); break; + } + case "finderrorheader": { + String folder = args.pop(); + + PrintStream oldOut = System.out; + PrintStream oldErr = System.err; + PrintStream nullStream = new PrintStream(new OutputStream() { + @Override + public void write(int b) { + } + }); + System.setOut(nullStream); + System.setErr(nullStream); + Main.initLogging(Configuration.debugMode.get()); + + File[] files = new File(folder).listFiles(getSwfFilter()); + for (File file : files) { + SWFSourceInfo sourceInfo = new SWFSourceInfo(null, file.getAbsolutePath(), file.getName()); + try { + SWF swf = new SWF(new FileInputStream(file), sourceInfo.getFile(), sourceInfo.getFileTitle(), Configuration.parallelSpeedUp.get()); + swf.swfList = new SWFList(); + swf.swfList.sourceInfo = sourceInfo; + boolean found = false; + for (Tag tag : swf.tags) { + if (tag instanceof JPEGTablesTag) { + JPEGTablesTag jtt = (JPEGTablesTag) tag; + if (ImageTag.hasErrorHeader(jtt.jpegData)) { + found = true; + break; + } + } else if (tag instanceof DefineBitsJPEG2Tag) { + DefineBitsJPEG2Tag jpeg = (DefineBitsJPEG2Tag) tag; + if (ImageTag.hasErrorHeader(jpeg.imageData)) { + found = true; + break; + } + } else if (tag instanceof DefineBitsJPEG3Tag) { + DefineBitsJPEG3Tag jpeg = (DefineBitsJPEG3Tag) tag; + if (ImageTag.hasErrorHeader(jpeg.imageData)) { + found = true; + break; + } + } + } + + if (found) { + oldOut.println("Tag found in file: " + file.getAbsolutePath()); + } + } catch (IOException | InterruptedException ex) { + logger.log(Level.SEVERE, null, ex); + } + } + + System.setOut(oldOut); + System.setErr(oldErr); + Main.initLogging(Configuration.debugMode.get()); + break; + } } } @@ -1713,7 +1774,7 @@ public class CommandLineArgumentParser { private static void replaceAS2(String as, ASMSource src) throws IOException, InterruptedException { System.out.println("Replace AS1/2"); System.out.println("Warning: This feature is EXPERIMENTAL"); - com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser par = new com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser(src.getSwf().version); + ActionScript2Parser par = new ActionScript2Parser(src.getSwf().version); try { src.setActions(par.actionsFromString(as)); } catch (ActionParseException ex) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index c57024fc5..930916306 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -86,9 +86,10 @@ import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel; import com.jpexs.decompiler.flash.gui.timeline.TimelineViewPanel; import com.jpexs.decompiler.flash.helpers.FileTextWriter; import com.jpexs.decompiler.flash.helpers.Freed; +import com.jpexs.decompiler.flash.importers.AS2ScriptImporter; +import com.jpexs.decompiler.flash.importers.AS3ScriptImporter; import com.jpexs.decompiler.flash.importers.BinaryDataImporter; import com.jpexs.decompiler.flash.importers.ImageImporter; -import com.jpexs.decompiler.flash.importers.ScriptImporter; import com.jpexs.decompiler.flash.importers.ShapeImporter; import com.jpexs.decompiler.flash.importers.SwfXmlImporter; import com.jpexs.decompiler.flash.importers.SymbolClassImporter; @@ -1960,11 +1961,17 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath(); String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME); - int count = new ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true)); - if (count == 0 && swf.isAS3()) { + int countAs2 = new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true)); + int countAs3 = new AS3ScriptImporter().importScripts(scriptsFolder, swf.getAS3Packs()); + + if (countAs3 > 0) { + updateClassesList(); + } + + if (countAs2 == 0 && countAs3 == 0 && swf.isAS3()) { View.showMessageDialog(this, translate("import.script.as12warning")); } else { - View.showMessageDialog(this, translate("import.script.result").replace("%count%", Integer.toString(count))); + View.showMessageDialog(this, translate("import.script.result").replace("%count%", Integer.toString(countAs2))); reload(true); } } diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 6b8f4f6ec..b068d64a1 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -24,13 +24,12 @@ import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.CachedScript; import com.jpexs.decompiler.flash.action.parser.ActionParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; +import com.jpexs.decompiler.flash.action.parser.script.ActionScript2Parser; import com.jpexs.decompiler.flash.action.parser.script.ActionScriptLexer; -import com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser; import com.jpexs.decompiler.flash.action.parser.script.ParsedSymbol; import com.jpexs.decompiler.flash.action.parser.script.SymbolType; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; -import com.jpexs.decompiler.flash.action.swf5.ActionConstantPool; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.gui.AppStrings; @@ -794,7 +793,7 @@ public class ActionPanel extends JPanel implements SearchListener> constantPools) { - try { - ActionList actions = src.getActions(); - int poolIdx = 0; - for (Action action : actions) { - if (action instanceof ActionConstantPool) { - ActionConstantPool cPool = (ActionConstantPool) action; - List constantPool = constantPools.get(poolIdx); - cPool.constantPool = constantPool; - - poolIdx++; - if (constantPools.size() <= poolIdx) { - break; - } - } - } - - src.setActions(actions); - } catch (InterruptedException ex) { - logger.log(Level.SEVERE, null, ex); - } - } - private void editDecompiledButtonActionPerformed(ActionEvent evt) { if (View.showConfirmDialog(null, AppStrings.translate("message.confirm.experimental.function"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, Configuration.warningExperimentalAS12Edit, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) { setDecompiledEditMode(true); @@ -852,7 +828,7 @@ public class ActionPanel extends JPanel implements SearchListener