diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 3f2fcdc07..2ecc98a73 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -79,6 +79,8 @@ import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.helpers.CheckResources; import com.jpexs.decompiler.flash.helpers.FileTextWriter; +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.FontImporter; import com.jpexs.decompiler.flash.importers.ImageImporter; @@ -425,6 +427,11 @@ public class CommandLineArgumentParser { out.println(" ...removes a character tag from the SWF"); } + if (filter == null || filter.equals("importscript")) { + out.println(" " + (cnt++) + ") -importScript "); + out.println(" ...imports scripts to and saves the result to "); + } + if (filter == null || filter.equals("deobfuscate")) { out.println(" " + (cnt++) + ") -deobfuscate "); out.println(" ...Deobfuscates AS3 P-code in and saves result to "); @@ -649,6 +656,8 @@ public class CommandLineArgumentParser { parseRemoveCharacter(args, false); } else if (command.equals("removecharacterwithdependencies")) { parseRemoveCharacter(args, true); + } else if (command.equals("importscript")) { + parseImportScript(args); } else if (command.equals("as3compiler")) { ActionScript3Parser.compile(null /*?*/, args.pop(), args.pop(), 0); } else if (nextParam.equals("--debugtool")) { @@ -2384,6 +2393,35 @@ public class CommandLineArgumentParser { } } + private static void parseImportScript(Stack args) { + if (args.size() < 3) { + badArguments("importscript"); + } + + File inFile = new File(args.pop()); + File outFile = new File(args.pop()); + try { + try (FileInputStream is = new FileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + String scriptsFolder = Path.combine(args.pop(), ScriptExportSettings.EXPORT_FOLDER_NAME); + new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true)); + new AS3ScriptImporter().importScripts(scriptsFolder, swf.getAS3Packs()); + + try { + try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + swf.saveTo(fos); + } + } catch (IOException e) { + System.err.println("I/O error during writing"); + System.exit(2); + } + } + } catch (IOException | InterruptedException e) { + System.err.println("I/O error during reading"); + System.exit(2); + } + } + private static void replaceAS2PCode(String text, ASMSource src) throws IOException, InterruptedException { System.out.println("Replace AS1/2 PCode"); if (text.trim().startsWith(Helper.hexData)) {