diff --git a/lib/ffdec_lib.jar b/lib/ffdec_lib.jar deleted file mode 100644 index 5c3357a81..000000000 Binary files a/lib/ffdec_lib.jar and /dev/null differ diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/BinaryDataImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/BinaryDataImporter.java new file mode 100644 index 000000000..2bf3a579f --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/BinaryDataImporter.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 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.tags.DefineBinaryDataTag; + +/** + * + * @author JPEXS + */ +public class BinaryDataImporter extends TagImporter { + + public void importData(DefineBinaryDataTag binaryDataTag, byte[] newData) { + binaryDataTag.binaryData = newData; + binaryDataTag.setModified(true); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java new file mode 100644 index 000000000..74c6eb2c7 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 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.SWF; +import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag; +import com.jpexs.decompiler.flash.tags.DefineBitsTag; +import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; +import java.io.IOException; + +/** + * + * @author JPEXS + */ +public class ImageImporter extends TagImporter { + + public Tag importImage(ImageTag it, byte[] newData) throws IOException { + if (it instanceof DefineBitsTag) { + SWF swf = it.getSwf(); + DefineBitsJPEG2Tag jpeg2Tag = new DefineBitsJPEG2Tag(swf, it.getOriginalRange(), it.getCharacterId(), newData); + jpeg2Tag.setModified(true); + swf.tags.set(swf.tags.indexOf(it), jpeg2Tag); + swf.updateCharacters(); + return jpeg2Tag; + } else { + it.setImage(newData); + } + return null; + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TagImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TagImporter.java new file mode 100644 index 000000000..30eea0f35 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TagImporter.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2014 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; + +/** + * + * @author JPEXS + */ +public class TagImporter { + +} diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 8df86c69e..73209384c 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -56,11 +56,14 @@ import com.jpexs.decompiler.flash.exporters.settings.ShapeExportSettings; import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.gui.Main; +import com.jpexs.decompiler.flash.importers.BinaryDataImporter; +import com.jpexs.decompiler.flash.importers.ImageImporter; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineSpriteTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.xfl.FLAVersion; @@ -223,7 +226,7 @@ public class CommandLineArgumentParser { System.out.println(" " + (cnt++) + ") -zoom "); System.out.println(" ...apply zoom during export (currently for FlashPaper conversion only)"); System.out.println(" " + (cnt++) + ") -replaceBinaryData "); - System.out.println(" ...replaces the specified BinaryData tag"); + System.out.println(" ...replaces the binary data of the specified BinaryData or Image tag"); System.out.println(); System.out.println("Examples:"); System.out.println("java -jar ffdec.jar myfile.swf"); @@ -1264,15 +1267,20 @@ public class CommandLineArgumentParser { System.err.println("CharacterId not exits"); badArguments(); } + CharacterTag characterTag = swf.characters.get(characterId); - if (!(characterTag instanceof DefineBinaryDataTag)) { - System.err.println("The specified CharacterId it not a BinaryData tag"); + byte[] data = Helper.readFile(args.remove()); + if (characterTag instanceof DefineBinaryDataTag) { + DefineBinaryDataTag defineBinaryData = (DefineBinaryDataTag) characterTag; + new BinaryDataImporter().importData(defineBinaryData, data); + } else if (characterTag instanceof ImageTag) { + ImageTag imageTag = (ImageTag) characterTag; + new ImageImporter().importImage(imageTag, data); + } else { + System.err.println("The specified tag type it not supported for import"); badArguments(); } - DefineBinaryDataTag defineBinaryData = (DefineBinaryDataTag) characterTag; - byte[] data = Helper.readFile(args.remove()); - defineBinaryData.binaryData = data; - defineBinaryData.setModified(true); + try { try (FileOutputStream fos = new FileOutputStream(outFile)) { swf.saveTo(fos); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 88cc9a79c..5131e7783 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -68,6 +68,8 @@ import com.jpexs.decompiler.flash.gui.treenodes.SWFBundleNode; import com.jpexs.decompiler.flash.gui.treenodes.SWFNode; import com.jpexs.decompiler.flash.gui.treenodes.StringNode; import com.jpexs.decompiler.flash.helpers.Freed; +import com.jpexs.decompiler.flash.importers.BinaryDataImporter; +import com.jpexs.decompiler.flash.importers.ImageImporter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag; @@ -2032,15 +2034,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec byte[] data = Helper.readFile(selfile.getAbsolutePath()); try { SWF swf = it.getSwf(); - if (it instanceof DefineBitsTag) { - DefineBitsJPEG2Tag jpeg2Tag = new DefineBitsJPEG2Tag(swf, it.getOriginalRange(), it.getCharacterId(), data); - jpeg2Tag.setModified(true); - swf.tags.set(swf.tags.indexOf(it), jpeg2Tag); - swf.updateCharacters(); + Tag newTag = new ImageImporter().importImage(it, data); + if (newTag != null) { refreshTree(); - setTagTreeSelectedNode(jpeg2Tag); - } else { - it.setImage(data); + setTagTreeSelectedNode(newTag); } SWF.clearImageCache(); } catch (IOException ex) { @@ -2062,8 +2059,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath()); File selfile = Helper.fixDialogFile(fc.getSelectedFile()); byte[] data = Helper.readFile(selfile.getAbsolutePath()); - bt.binaryData = data; - bt.setModified(true); + new BinaryDataImporter().importData(bt, data); reload(true); } }