From d00acbd7dfca4075a491fc0c7e603e5e708a9362 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 14 Jun 2015 14:10:37 +0200 Subject: [PATCH] keep remaining data, when tag is not fully parsed --- .../decompiler/flash/SWFInputStream.java | 4 + .../flash/tags/CSMTextSettingsTag.java | 29 ++-- .../decompiler/flash/tags/DebugIDTag.java | 17 +- .../flash/tags/DefineBinaryDataTag.java | 21 +-- .../flash/tags/DefineBitsJPEG2Tag.java | 21 +-- .../flash/tags/DefineBitsJPEG3Tag.java | 22 +-- .../flash/tags/DefineBitsJPEG4Tag.java | 24 +-- .../flash/tags/DefineBitsLossless2Tag.java | 28 ++-- .../flash/tags/DefineBitsLosslessTag.java | 28 ++-- .../decompiler/flash/tags/DefineBitsTag.java | 18 +- .../flash/tags/DefineButton2Tag.java | 50 ++---- .../flash/tags/DefineButtonCxformTag.java | 19 +-- .../flash/tags/DefineButtonSoundTag.java | 47 +++--- .../flash/tags/DefineButtonTag.java | 30 +--- .../flash/tags/DefineEditTextTag.java | 102 ++++++------ .../decompiler/flash/tags/DefineFont2Tag.java | 135 ++++++++------- .../decompiler/flash/tags/DefineFont3Tag.java | 155 ++++++++---------- .../decompiler/flash/tags/DefineFont4Tag.java | 29 ++-- .../flash/tags/DefineFontAlignZonesTag.java | 25 +-- .../flash/tags/DefineFontInfo2Tag.java | 43 ++--- .../flash/tags/DefineFontInfoTag.java | 47 +++--- .../flash/tags/DefineFontNameTag.java | 21 +-- .../decompiler/flash/tags/DefineFontTag.java | 36 ++-- .../flash/tags/DefineMorphShape2Tag.java | 48 +++--- .../flash/tags/DefineMorphShapeTag.java | 38 ++--- .../flash/tags/DefineScalingGridTag.java | 19 +-- .../tags/DefineSceneAndFrameLabelDataTag.java | 37 ++--- .../flash/tags/DefineShape2Tag.java | 20 +-- .../flash/tags/DefineShape3Tag.java | 20 +-- .../flash/tags/DefineShape4Tag.java | 30 ++-- .../decompiler/flash/tags/DefineShapeTag.java | 20 +-- .../decompiler/flash/tags/DefineSoundTag.java | 29 ++-- .../flash/tags/DefineSpriteTag.java | 32 +--- .../flash/tags/DefineVideoStreamTag.java | 31 ++-- .../decompiler/flash/tags/DoABC2Tag.java | 28 +--- .../jpexs/decompiler/flash/tags/DoABCTag.java | 24 +-- .../decompiler/flash/tags/DoActionTag.java | 8 +- .../flash/tags/DoInitActionTag.java | 20 +-- .../flash/tags/EnableDebugger2Tag.java | 20 +-- .../flash/tags/EnableDebuggerTag.java | 19 +-- .../flash/tags/EnableTelemetryTag.java | 21 +-- .../jpexs/decompiler/flash/tags/EndTag.java | 6 +- .../flash/tags/ExportAssetsTag.java | 23 +-- .../flash/tags/FileAttributesTag.java | 33 ++-- .../decompiler/flash/tags/FrameLabelTag.java | 21 +-- .../decompiler/flash/tags/FreeAllTag.java | 6 +- .../flash/tags/FreeCharacterTag.java | 17 +- .../flash/tags/ImportAssets2Tag.java | 40 ++--- .../flash/tags/ImportAssetsTag.java | 25 +-- .../decompiler/flash/tags/JPEGTablesTag.java | 17 +- .../decompiler/flash/tags/MetadataTag.java | 17 +- .../flash/tags/NameCharacterTag.java | 19 +-- .../flash/tags/PathsArePostScriptTag.java | 6 +- .../flash/tags/PlaceObject2Tag.java | 78 ++++----- .../flash/tags/PlaceObject3Tag.java | 136 +++++++-------- .../flash/tags/PlaceObject4Tag.java | 136 +++++++-------- .../decompiler/flash/tags/PlaceObjectTag.java | 25 +-- .../decompiler/flash/tags/ProductInfoTag.java | 34 ++-- .../decompiler/flash/tags/ProtectTag.java | 19 +-- .../flash/tags/RemoveObject2Tag.java | 17 +- .../flash/tags/RemoveObjectTag.java | 19 +-- .../flash/tags/ScriptLimitsTag.java | 19 +-- .../flash/tags/SetBackgroundColorTag.java | 18 +- .../decompiler/flash/tags/SetTabIndexTag.java | 19 +-- .../decompiler/flash/tags/ShowFrameTag.java | 6 +- .../flash/tags/SoundStreamBlockTag.java | 17 +- .../flash/tags/SoundStreamHead2Tag.java | 37 ++--- .../flash/tags/SoundStreamHeadTag.java | 37 ++--- .../decompiler/flash/tags/StartSound2Tag.java | 19 +-- .../decompiler/flash/tags/StartSoundTag.java | 19 +-- .../decompiler/flash/tags/SymbolClassTag.java | 25 +-- .../decompiler/flash/tags/SyncFrameTag.java | 6 +- .../com/jpexs/decompiler/flash/tags/Tag.java | 49 +++++- .../jpexs/decompiler/flash/tags/TagStub.java | 5 +- .../decompiler/flash/tags/UnknownTag.java | 8 +- .../decompiler/flash/tags/VideoFrameTag.java | 21 +-- .../flash/tags/base/StaticTextTag.java | 57 +++---- .../flash/tags/gfx/DefineCompactedFont.java | 21 +-- .../tags/gfx/DefineExternalGradient.java | 27 +-- .../flash/tags/gfx/DefineExternalImage.java | 29 ++-- .../flash/tags/gfx/DefineExternalImage2.java | 39 ++--- .../flash/tags/gfx/DefineExternalSound.java | 41 ++--- .../tags/gfx/DefineExternalStreamSound.java | 37 ++--- .../flash/tags/gfx/DefineGradientMap.java | 21 +-- .../flash/tags/gfx/DefineSubImage.java | 27 +-- .../flash/tags/gfx/ExporterInfo.java | 45 ++--- .../flash/tags/gfx/FontTextureInfo.java | 47 +++--- 87 files changed, 1068 insertions(+), 1737 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java index 02516b570..fb4172f04 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -1484,6 +1484,10 @@ public class SWFInputStream implements AutoCloseable { ret = new UnknownTag(swf, tag.getId(), data); } } + + if (sis.available() > 0) { + ret.remainingData = sis.readBytesEx(sis.available(), "remaining"); + } } catch (IOException ex) { logger.log(Level.SEVERE, "Error during tag reading. SWF: " + swf.getShortFileName() + " ID: " + tag.getId() + " name: " + tag.getName() + " pos: " + data.getPos(), ex); ret = new TagStub(swf, tag.getId(), "ErrorTag", data, null); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/CSMTextSettingsTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/CSMTextSettingsTag.java index 4b945de23..dca935cc8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/CSMTextSettingsTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/CSMTextSettingsTag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -96,25 +94,18 @@ public class CSMTextSettingsTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(textID); - sos.writeUB(2, useFlashType); - sos.writeUB(3, gridFit); - sos.writeUB(3, reserved); - sos.writeFLOAT(thickness); //F32 = FLOAT - sos.writeFLOAT(sharpness); //F32 = FLOAT - sos.writeUI8(reserved2); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(textID); + sos.writeUB(2, useFlashType); + sos.writeUB(3, gridFit); + sos.writeUB(3, reserved); + sos.writeFLOAT(thickness); //F32 = FLOAT + sos.writeFLOAT(sharpness); //F32 = FLOAT + sos.writeUI8(reserved2); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DebugIDTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DebugIDTag.java index 7f303952f..d3e9f7b1e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DebugIDTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DebugIDTag.java @@ -22,9 +22,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -69,18 +67,11 @@ public class DebugIDTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.write(debugId); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.write(debugId); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java index 5ff2f91b4..ec28fb1df 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java @@ -28,10 +28,8 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.utf8.Utf8Helper; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.Arrays; /** @@ -93,21 +91,14 @@ public class DefineBinaryDataTag extends CharacterTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(tag); - sos.writeUI32(reserved); - sos.write(binaryData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(tag); + sos.writeUI32(reserved); + sos.write(binaryData); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java index db658f94b..3a8296efe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java @@ -33,7 +33,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; @@ -86,18 +85,16 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag { imageData = sis.readByteRangeEx(sis.available(), "imageData"); } + /** + * Gets data bytes + * + * @param sos SWF output stream + * @throws java.io.IOException + */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.write(imageData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.write(imageData); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java index 27cf9a44e..fe8b0b8eb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java @@ -34,7 +34,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; @@ -90,22 +89,15 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.writeUI32(imageData.getLength()); - sos.write(imageData); - sos.write(bitmapAlphaData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.writeUI32(imageData.getLength()); + sos.write(imageData); + sos.write(bitmapAlphaData); } private byte[] createEmptyImage() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java index 867571011..fb7d913a7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java @@ -34,7 +34,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; @@ -94,23 +93,16 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.writeUI32(imageData.getLength()); - sos.writeUI16(deblockParam); - sos.write(imageData); - sos.write(bitmapAlphaData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.writeUI32(imageData.getLength()); + sos.writeUI16(deblockParam); + sos.write(imageData); + sos.write(bitmapAlphaData); } private byte[] createEmptyImage() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java index d41a50e1b..1172b395c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java @@ -39,7 +39,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.InflaterInputStream; @@ -117,26 +116,19 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.writeUI8(bitmapFormat); - sos.writeUI16(bitmapWidth); - sos.writeUI16(bitmapHeight); - if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { - sos.writeUI8(bitmapColorTableSize); - } - sos.write(zlibBitmapData); - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.writeUI8(bitmapFormat); + sos.writeUI16(bitmapWidth); + sos.writeUI16(bitmapHeight); + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { + sos.writeUI8(bitmapColorTableSize); } - return baos.toByteArray(); + sos.write(zlibBitmapData); } private byte[] createEmptyImage() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java index 4110ce3ec..ad5a0951a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java @@ -39,7 +39,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.InflaterInputStream; @@ -119,26 +118,19 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.writeUI8(bitmapFormat); - sos.writeUI16(bitmapWidth); - sos.writeUI16(bitmapHeight); - if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { - sos.writeUI8(bitmapColorTableSize); - } - sos.write(zlibBitmapData); - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.writeUI8(bitmapFormat); + sos.writeUI16(bitmapWidth); + sos.writeUI16(bitmapHeight); + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { + sos.writeUI8(bitmapColorTableSize); } - return baos.toByteArray(); + sos.write(zlibBitmapData); } private byte[] createEmptyImage() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java index fadf45e3b..60c7d4185 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java @@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; @@ -75,20 +74,13 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.write(jpegData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.write(jpegData); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java index ff0989e6b..526a866f8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java @@ -19,8 +19,6 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.base.ASMSourceContainer; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.ButtonTag; @@ -37,10 +35,8 @@ import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -128,39 +124,27 @@ public class DefineButton2Tag extends ButtonTag implements ASMSourceContainer { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - if (Configuration.debugCopy.get()) { - ByteArrayInputStream bais = new ByteArrayInputStream(getOriginalData()); - os = new CopyOutputStream(os, bais); - } - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(buttonId); - sos.writeUB(7, reserved); - sos.writeUB(1, trackAsMenu ? 1 : 0); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(buttonId); + sos.writeUB(7, reserved); + sos.writeUB(1, trackAsMenu ? 1 : 0); - ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); - try (SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion())) { - sos2.writeBUTTONRECORDList(characters, true); - } - byte[] brdata = baos2.toByteArray(); - if ((actions == null) || (actions.isEmpty())) { - sos.writeUI16(0); - } else { - sos.writeUI16(2 + brdata.length); - } - sos.write(brdata); - sos.writeBUTTONCONDACTIONList(actions); - sos.close(); - } catch (IOException e) { - throw new Error("This should never happen.", e); + ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); + try (SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion())) { + sos2.writeBUTTONRECORDList(characters, true); } - return baos.toByteArray(); + byte[] brdata = baos2.toByteArray(); + if ((actions == null) || (actions.isEmpty())) { + sos.writeUI16(0); + } else { + sos.writeUI16(2 + brdata.length); + } + sos.write(brdata); + sos.writeBUTTONCONDACTIONList(actions); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonCxformTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonCxformTag.java index 79f4117be..76944305d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonCxformTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonCxformTag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.CXFORM; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -74,20 +72,13 @@ public class DefineButtonCxformTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(buttonId); - sos.writeCXFORM(buttonColorTransform); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(buttonId); + sos.writeCXFORM(buttonColorTransform); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonSoundTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonSoundTag.java index c0b23938a..82eb96b68 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonSoundTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonSoundTag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.SOUNDINFO; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -106,35 +104,28 @@ public class DefineButtonSoundTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(buttonId); - sos.writeUI16(buttonSoundChar0); - if (buttonSoundChar0 != 0) { - sos.writeSOUNDINFO(buttonSoundInfo0); - } - sos.writeUI16(buttonSoundChar1); - if (buttonSoundChar1 != 0) { - sos.writeSOUNDINFO(buttonSoundInfo1); - } - sos.writeUI16(buttonSoundChar2); - if (buttonSoundChar2 != 0) { - sos.writeSOUNDINFO(buttonSoundInfo2); - } - sos.writeUI16(buttonSoundChar3); - if (buttonSoundChar3 != 0) { - sos.writeSOUNDINFO(buttonSoundInfo3); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(buttonId); + sos.writeUI16(buttonSoundChar0); + if (buttonSoundChar0 != 0) { + sos.writeSOUNDINFO(buttonSoundInfo0); + } + sos.writeUI16(buttonSoundChar1); + if (buttonSoundChar1 != 0) { + sos.writeSOUNDINFO(buttonSoundInfo1); + } + sos.writeUI16(buttonSoundChar2); + if (buttonSoundChar2 != 0) { + sos.writeSOUNDINFO(buttonSoundInfo2); + } + sos.writeUI16(buttonSoundChar3); + if (buttonSoundChar3 != 0) { + sos.writeSOUNDINFO(buttonSoundInfo3); } - return baos.toByteArray(); } @Override 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 d58a91855..db9704c3a 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 @@ -20,11 +20,9 @@ import com.jpexs.decompiler.flash.DisassemblyListener; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.ActionListReader; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; @@ -44,10 +42,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; import com.jpexs.helpers.Helper; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -125,26 +120,15 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - if (Configuration.debugCopy.get()) { - os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); - } - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(buttonId); - sos.writeBUTTONRECORDList(characters, false); - sos.write(getActionBytes()); - //sos.write(Action.actionsToBytes(actions, true, version)); - sos.close(); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(buttonId); + sos.writeBUTTONRECORDList(characters, false); + sos.write(getActionBytes()); + //sos.write(Action.actionsToBytes(actions, true, version)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index 92891ff32..7ad9b8ac9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -59,9 +59,7 @@ import com.jpexs.helpers.utf8.Utf8Helper; import java.awt.Color; import java.awt.Font; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.io.StringReader; import java.util.ArrayList; import java.util.Arrays; @@ -245,63 +243,55 @@ public class DefineEditTextTag extends TextTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.writeRECT(bounds); - sos.writeUB(1, hasText ? 1 : 0); - sos.writeUB(1, wordWrap ? 1 : 0); - sos.writeUB(1, multiline ? 1 : 0); - sos.writeUB(1, password ? 1 : 0); - sos.writeUB(1, readOnly ? 1 : 0); - sos.writeUB(1, hasTextColor ? 1 : 0); - sos.writeUB(1, hasMaxLength ? 1 : 0); - sos.writeUB(1, hasFont ? 1 : 0); - sos.writeUB(1, hasFontClass ? 1 : 0); - sos.writeUB(1, autoSize ? 1 : 0); - sos.writeUB(1, hasLayout ? 1 : 0); - sos.writeUB(1, noSelect ? 1 : 0); - sos.writeUB(1, border ? 1 : 0); - sos.writeUB(1, wasStatic ? 1 : 0); - sos.writeUB(1, html ? 1 : 0); - sos.writeUB(1, useOutlines ? 1 : 0); - if (hasFont) { - sos.writeUI16(fontId); - } - if (hasFontClass) { - sos.writeString(fontClass); - } - if (hasFont) { - sos.writeUI16(fontHeight); - } - if (hasTextColor) { - sos.writeRGBA(textColor); - } - if (hasMaxLength) { - sos.writeUI16(maxLength); - } - if (hasLayout) { - sos.writeUI8(align); - sos.writeUI16(leftMargin); - sos.writeUI16(rightMargin); - sos.writeUI16(indent); - sos.writeSI16(leading); - } - sos.writeString(variableName); - if (hasText) { - sos.writeString(initialText); - } - - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.writeRECT(bounds); + sos.writeUB(1, hasText ? 1 : 0); + sos.writeUB(1, wordWrap ? 1 : 0); + sos.writeUB(1, multiline ? 1 : 0); + sos.writeUB(1, password ? 1 : 0); + sos.writeUB(1, readOnly ? 1 : 0); + sos.writeUB(1, hasTextColor ? 1 : 0); + sos.writeUB(1, hasMaxLength ? 1 : 0); + sos.writeUB(1, hasFont ? 1 : 0); + sos.writeUB(1, hasFontClass ? 1 : 0); + sos.writeUB(1, autoSize ? 1 : 0); + sos.writeUB(1, hasLayout ? 1 : 0); + sos.writeUB(1, noSelect ? 1 : 0); + sos.writeUB(1, border ? 1 : 0); + sos.writeUB(1, wasStatic ? 1 : 0); + sos.writeUB(1, html ? 1 : 0); + sos.writeUB(1, useOutlines ? 1 : 0); + if (hasFont) { + sos.writeUI16(fontId); + } + if (hasFontClass) { + sos.writeString(fontClass); + } + if (hasFont) { + sos.writeUI16(fontHeight); + } + if (hasTextColor) { + sos.writeRGBA(textColor); + } + if (hasMaxLength) { + sos.writeUI16(maxLength); + } + if (hasLayout) { + sos.writeUI8(align); + sos.writeUI16(leftMargin); + sos.writeUI16(rightMargin); + sos.writeUI16(indent); + sos.writeSI16(leading); + } + sos.writeString(variableName); + if (hasText) { + sos.writeString(initialText); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java index bd6034f7e..805eb5a07 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java @@ -197,82 +197,75 @@ public class DefineFont2Tag extends FontTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); - try { - sos.writeUI16(fontId); - sos.writeUB(1, fontFlagsHasLayout ? 1 : 0); - sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); - sos.writeUB(1, fontFlagsSmallText ? 1 : 0); - sos.writeUB(1, fontFlagsANSI ? 1 : 0); - sos.writeUB(1, fontFlagsWideOffsets ? 1 : 0); - sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); - sos.writeUB(1, fontFlagsItalic ? 1 : 0); - sos.writeUB(1, fontFlagsBold ? 1 : 0); - sos.writeLANGCODE(languageCode); - byte[] fontNameBytes = Utf8Helper.getBytes(fontName); - sos.writeUI8(fontNameBytes.length); - sos.write(fontNameBytes); - int numGlyphs = glyphShapeTable.size(); - sos.writeUI16(numGlyphs); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontId); + sos.writeUB(1, fontFlagsHasLayout ? 1 : 0); + sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); + sos.writeUB(1, fontFlagsSmallText ? 1 : 0); + sos.writeUB(1, fontFlagsANSI ? 1 : 0); + sos.writeUB(1, fontFlagsWideOffsets ? 1 : 0); + sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); + sos.writeUB(1, fontFlagsItalic ? 1 : 0); + sos.writeUB(1, fontFlagsBold ? 1 : 0); + sos.writeLANGCODE(languageCode); + byte[] fontNameBytes = Utf8Helper.getBytes(fontName); + sos.writeUI8(fontNameBytes.length); + sos.write(fontNameBytes); + int numGlyphs = glyphShapeTable.size(); + sos.writeUI16(numGlyphs); - List offsetTable = new ArrayList<>(); - ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream(); + List offsetTable = new ArrayList<>(); + ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream(); - SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion()); - for (int i = 0; i < numGlyphs; i++) { - offsetTable.add((glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + sos3.getPos()); - sos3.writeSHAPE(glyphShapeTable.get(i), 1); - } - byte[] baGlyphShapes = baosGlyphShapes.toByteArray(); - for (Long offset : offsetTable) { - if (fontFlagsWideOffsets) { - sos.writeUI32(offset); - } else { - sos.writeUI16((int) (long) offset); - } - } - if (numGlyphs > 0) { - long offset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + baGlyphShapes.length; - if (fontFlagsWideOffsets) { - sos.writeUI32(offset); - } else { - sos.writeUI16((int) offset); - } - sos.write(baGlyphShapes); - - for (int i = 0; i < numGlyphs; i++) { - if (fontFlagsWideCodes) { - sos.writeUI16(codeTable.get(i)); - } else { - sos.writeUI8(codeTable.get(i)); - } - } - } - if (fontFlagsHasLayout) { - sos.writeSI16(fontAscent); - sos.writeSI16(fontDescent); - sos.writeSI16(fontLeading); - for (int i = 0; i < numGlyphs; i++) { - sos.writeSI16(fontAdvanceTable.get(i)); - } - for (int i = 0; i < numGlyphs; i++) { - sos.writeRECT(fontBoundsTable.get(i)); - } - sos.writeUI16(fontKerningTable.size()); - for (int k = 0; k < fontKerningTable.size(); k++) { - sos.writeKERNINGRECORD(fontKerningTable.get(k), fontFlagsWideCodes); - } - } - - } catch (IOException e) { - throw new Error("This should never happen.", e); + SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion()); + for (int i = 0; i < numGlyphs; i++) { + offsetTable.add((glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + sos3.getPos()); + sos3.writeSHAPE(glyphShapeTable.get(i), 1); + } + byte[] baGlyphShapes = baosGlyphShapes.toByteArray(); + for (Long offset : offsetTable) { + if (fontFlagsWideOffsets) { + sos.writeUI32(offset); + } else { + sos.writeUI16((int) (long) offset); + } + } + if (numGlyphs > 0) { + long offset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + baGlyphShapes.length; + if (fontFlagsWideOffsets) { + sos.writeUI32(offset); + } else { + sos.writeUI16((int) offset); + } + sos.write(baGlyphShapes); + + for (int i = 0; i < numGlyphs; i++) { + if (fontFlagsWideCodes) { + sos.writeUI16(codeTable.get(i)); + } else { + sos.writeUI8(codeTable.get(i)); + } + } + } + if (fontFlagsHasLayout) { + sos.writeSI16(fontAscent); + sos.writeSI16(fontDescent); + sos.writeSI16(fontLeading); + for (int i = 0; i < numGlyphs; i++) { + sos.writeSI16(fontAdvanceTable.get(i)); + } + for (int i = 0; i < numGlyphs; i++) { + sos.writeRECT(fontBoundsTable.get(i)); + } + sos.writeUI16(fontKerningTable.size()); + for (int k = 0; k < fontKerningTable.size(); k++) { + sos.writeKERNINGRECORD(fontKerningTable.get(k), fontFlagsWideCodes); + } } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java index b6d5c0008..460b93080 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java @@ -19,8 +19,6 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.FontHelper; import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.types.BasicType; @@ -34,10 +32,8 @@ import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.utf8.Utf8Helper; import java.awt.Font; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -191,95 +187,84 @@ public class DefineFont3Tag extends FontTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - if (Configuration.debugCopy.get()) { - sos = new SWFOutputStream(new CopyOutputStream(sos, new ByteArrayInputStream(getOriginalData())), getVersion()); + public void getData(SWFOutputStream sos) throws IOException { + List offsetTable = new ArrayList<>(); + ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream(); + SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion()); + int numGlyphs = glyphShapeTable.size(); + for (int i = 0; i < numGlyphs; i++) { + offsetTable.add(sos3.getPos()); + sos3.writeSHAPE(glyphShapeTable.get(i), 1); } - try { - List offsetTable = new ArrayList<>(); - ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream(); - SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion()); - int numGlyphs = glyphShapeTable.size(); + byte[] baGlyphShapes = baosGlyphShapes.toByteArray(); + + if (!fontFlagsWideOffsets && numGlyphs > 0) { + // Set wide offsets when necessary + long maxOffset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * 2 + baGlyphShapes.length; + if (maxOffset > 65535) { + fontFlagsWideOffsets = true; + } + } + + sos.writeUI16(fontId); + sos.writeUB(1, fontFlagsHasLayout ? 1 : 0); + sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); + sos.writeUB(1, fontFlagsSmallText ? 1 : 0); + sos.writeUB(1, fontFlagsANSI ? 1 : 0); + sos.writeUB(1, fontFlagsWideOffsets ? 1 : 0); + sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); + sos.writeUB(1, fontFlagsItalic ? 1 : 0); + sos.writeUB(1, fontFlagsBold ? 1 : 0); + sos.writeLANGCODE(languageCode); + byte[] fontNameBytes = Utf8Helper.getBytes(fontName); + sos.writeUI8(fontNameBytes.length); + sos.write(fontNameBytes); + sos.writeUI16(numGlyphs); + + for (long offset : offsetTable) { + long offset2 = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + offset; + if (fontFlagsWideOffsets) { + sos.writeUI32(offset2); + } else { + sos.writeUI16((int) offset2); + } + } + if (numGlyphs > 0) { + long offset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + baGlyphShapes.length; + if (fontFlagsWideOffsets) { + sos.writeUI32(offset); + } else { + sos.writeUI16((int) offset); + } + sos.write(baGlyphShapes); + for (int i = 0; i < numGlyphs; i++) { - offsetTable.add(sos3.getPos()); - sos3.writeSHAPE(glyphShapeTable.get(i), 1); - } - byte[] baGlyphShapes = baosGlyphShapes.toByteArray(); - - if (!fontFlagsWideOffsets && numGlyphs > 0) { - // Set wide offsets when necessary - long maxOffset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * 2 + baGlyphShapes.length; - if (maxOffset > 65535) { - fontFlagsWideOffsets = true; - } - } - - sos.writeUI16(fontId); - sos.writeUB(1, fontFlagsHasLayout ? 1 : 0); - sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); - sos.writeUB(1, fontFlagsSmallText ? 1 : 0); - sos.writeUB(1, fontFlagsANSI ? 1 : 0); - sos.writeUB(1, fontFlagsWideOffsets ? 1 : 0); - sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); - sos.writeUB(1, fontFlagsItalic ? 1 : 0); - sos.writeUB(1, fontFlagsBold ? 1 : 0); - sos.writeLANGCODE(languageCode); - byte[] fontNameBytes = Utf8Helper.getBytes(fontName); - sos.writeUI8(fontNameBytes.length); - sos.write(fontNameBytes); - sos.writeUI16(numGlyphs); - - for (long offset : offsetTable) { - long offset2 = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + offset; - if (fontFlagsWideOffsets) { - sos.writeUI32(offset2); + if (fontFlagsWideCodes) { + sos.writeUI16(codeTable.get(i)); } else { - sos.writeUI16((int) offset2); + sos.writeUI8(codeTable.get(i)); } } - if (numGlyphs > 0) { - long offset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + baGlyphShapes.length; - if (fontFlagsWideOffsets) { - sos.writeUI32(offset); - } else { - sos.writeUI16((int) offset); - } - sos.write(baGlyphShapes); - - for (int i = 0; i < numGlyphs; i++) { - if (fontFlagsWideCodes) { - sos.writeUI16(codeTable.get(i)); - } else { - sos.writeUI8(codeTable.get(i)); - } - } - } - if (fontFlagsHasLayout) { - sos.writeSI16(fontAscent); - sos.writeSI16(fontDescent); - sos.writeSI16(fontLeading); - for (int i = 0; i < numGlyphs; i++) { - sos.writeSI16(fontAdvanceTable.get(i)); - } - for (int i = 0; i < numGlyphs; i++) { - sos.writeRECT(fontBoundsTable.get(i)); - } - sos.writeUI16(fontKerningTable.size()); - for (int k = 0; k < fontKerningTable.size(); k++) { - sos.writeKERNINGRECORD(fontKerningTable.get(k), fontFlagsWideCodes); - } - } - - } catch (IOException e) { - throw new Error("This should never happen.", e); } - return baos.toByteArray(); + if (fontFlagsHasLayout) { + sos.writeSI16(fontAscent); + sos.writeSI16(fontDescent); + sos.writeSI16(fontLeading); + for (int i = 0; i < numGlyphs; i++) { + sos.writeSI16(fontAdvanceTable.get(i)); + } + for (int i = 0; i < numGlyphs; i++) { + sos.writeRECT(fontBoundsTable.get(i)); + } + sos.writeUI16(fontKerningTable.size()); + for (int k = 0; k < fontKerningTable.size(); k++) { + sos.writeKERNINGRECORD(fontKerningTable.get(k), fontFlagsWideCodes); + } + } } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont4Tag.java index 0dbccd3ea..a8224373e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont4Tag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -86,25 +84,18 @@ public class DefineFont4Tag extends CharacterTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(fontID); - sos.writeUB(5, reserved); - sos.writeUB(1, fontFlagsHasFontData ? 1 : 0); - sos.writeUB(1, fontFlagsItalic ? 1 : 0); - sos.writeUB(1, fontFlagsBold ? 1 : 0); - sos.writeString(fontName); - sos.write(fontData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontID); + sos.writeUB(5, reserved); + sos.writeUB(1, fontFlagsHasFontData ? 1 : 0); + sos.writeUB(1, fontFlagsItalic ? 1 : 0); + sos.writeUB(1, fontFlagsBold ? 1 : 0); + sos.writeString(fontName); + sos.write(fontData); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontAlignZonesTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontAlignZonesTag.java index e7b7f8d04..8c2fe20eb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontAlignZonesTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontAlignZonesTag.java @@ -26,9 +26,7 @@ import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -85,24 +83,17 @@ public class DefineFontAlignZonesTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(fontID); - sos.writeUB(2, CSMTableHint); - sos.writeUB(6, reserved); - for (ZONERECORD z : zoneTable) { - sos.writeZONERECORD(z); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontID); + sos.writeUB(2, CSMTableHint); + sos.writeUB(6, reserved); + for (ZONERECORD z : zoneTable) { + sos.writeZONERECORD(z); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfo2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfo2Tag.java index b66b054a8..566161ce3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfo2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfo2Tag.java @@ -26,9 +26,7 @@ import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.utf8.Utf8Helper; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -119,33 +117,26 @@ public class DefineFontInfo2Tag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(fontID); - byte[] fontNameBytes = Utf8Helper.getBytes(fontName); - sos.writeUI8(fontNameBytes.length); - sos.write(fontNameBytes); - sos.writeUB(2, reserved); - sos.writeUB(1, fontFlagsSmallText ? 1 : 0); - sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); - sos.writeUB(1, fontFlagsANSI ? 1 : 0); - sos.writeUB(1, fontFlagsItalic ? 1 : 0); - sos.writeUB(1, fontFlagsBold ? 1 : 0); - sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); - sos.writeLANGCODE(languageCode); - for (int c : codeTable) { - sos.writeUI16(c); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontID); + byte[] fontNameBytes = Utf8Helper.getBytes(fontName); + sos.writeUI8(fontNameBytes.length); + sos.write(fontNameBytes); + sos.writeUB(2, reserved); + sos.writeUB(1, fontFlagsSmallText ? 1 : 0); + sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); + sos.writeUB(1, fontFlagsANSI ? 1 : 0); + sos.writeUB(1, fontFlagsItalic ? 1 : 0); + sos.writeUB(1, fontFlagsBold ? 1 : 0); + sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); + sos.writeLANGCODE(languageCode); + for (int c : codeTable) { + sos.writeUI16(c); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfoTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfoTag.java index ff717ca80..5ade728fb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfoTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontInfoTag.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.utf8.Utf8Helper; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -117,36 +115,29 @@ public class DefineFontInfoTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(fontId); - byte[] fontNameBytes = Utf8Helper.getBytes(fontName); - sos.writeUI8(fontNameBytes.length); - sos.write(fontNameBytes); - sos.writeUB(2, reserved); - sos.writeUB(1, fontFlagsSmallText ? 1 : 0); - sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); - sos.writeUB(1, fontFlagsANSI ? 1 : 0); - sos.writeUB(1, fontFlagsItalic ? 1 : 0); - sos.writeUB(1, fontFlagsBold ? 1 : 0); - sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); - for (int code : codeTable) { - if (fontFlagsWideCodes) { - sos.writeUI16(code); - } else { - sos.writeUI8(code); - } + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontId); + byte[] fontNameBytes = Utf8Helper.getBytes(fontName); + sos.writeUI8(fontNameBytes.length); + sos.write(fontNameBytes); + sos.writeUB(2, reserved); + sos.writeUB(1, fontFlagsSmallText ? 1 : 0); + sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0); + sos.writeUB(1, fontFlagsANSI ? 1 : 0); + sos.writeUB(1, fontFlagsItalic ? 1 : 0); + sos.writeUB(1, fontFlagsBold ? 1 : 0); + sos.writeUB(1, fontFlagsWideCodes ? 1 : 0); + for (int code : codeTable) { + if (fontFlagsWideCodes) { + sos.writeUI16(code); + } else { + sos.writeUI8(code); } - } catch (IOException e) { - throw new Error("This should never happen.", e); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java index 1260fa18d..f2c7ee680 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -70,21 +68,14 @@ public class DefineFontNameTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(fontId); - sos.writeString(fontName); - sos.writeString(fontCopyright); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontId); + sos.writeString(fontName); + sos.writeString(fontCopyright); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java index 4bfdad339..eeae28367 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java @@ -29,7 +29,6 @@ import com.jpexs.helpers.ByteArrayRange; import java.awt.Font; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -102,30 +101,23 @@ public class DefineFontTag extends FontTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(fontId); - ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); - List offsetTable = new ArrayList<>(); - SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion()); - for (SHAPE shape : glyphShapeTable) { - offsetTable.add(glyphShapeTable.size() * 2 + (int) sos2.getPos()); - sos2.writeSHAPE(shape, 1); - } - for (int offset : offsetTable) { - sos.writeUI16(offset); - } - sos.write(baos2.toByteArray()); - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontId); + ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); + List offsetTable = new ArrayList<>(); + SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion()); + for (SHAPE shape : glyphShapeTable) { + offsetTable.add(glyphShapeTable.size() * 2 + (int) sos2.getPos()); + sos2.writeSHAPE(shape, 1); } - return baos.toByteArray(); + for (int offset : offsetTable) { + sos.writeUI16(offset); + } + sos.write(baos2.toByteArray()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java index 835ce8491..7fc0537ff 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java @@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -108,35 +107,28 @@ public class DefineMorphShape2Tag extends MorphShapeTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeRECT(startBounds); - sos.writeRECT(endBounds); - sos.writeRECT(startEdgeBounds); - sos.writeRECT(endEdgeBounds); - sos.writeUB(6, reserved); - sos.writeUB(1, usesNonScalingStrokes ? 1 : 0); - sos.writeUB(1, usesScalingStrokes ? 1 : 0); - ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); - SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion()); - sos2.writeMORPHFILLSTYLEARRAY(morphFillStyles, 2); - sos2.writeMORPHLINESTYLEARRAY(morphLineStyles, 2); - sos2.writeSHAPE(startEdges, 2); - byte[] ba2 = baos2.toByteArray(); - sos.writeUI32(ba2.length); - sos.write(ba2); - sos.writeSHAPE(endEdges, 2); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeRECT(startBounds); + sos.writeRECT(endBounds); + sos.writeRECT(startEdgeBounds); + sos.writeRECT(endEdgeBounds); + sos.writeUB(6, reserved); + sos.writeUB(1, usesNonScalingStrokes ? 1 : 0); + sos.writeUB(1, usesScalingStrokes ? 1 : 0); + ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); + SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion()); + sos2.writeMORPHFILLSTYLEARRAY(morphFillStyles, 2); + sos2.writeMORPHLINESTYLEARRAY(morphLineStyles, 2); + sos2.writeSHAPE(startEdges, 2); + byte[] ba2 = baos2.toByteArray(); + sos.writeUI32(ba2.length); + sos.write(ba2); + sos.writeSHAPE(endEdges, 2); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java index d4945a3ba..faa638b6e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java @@ -29,7 +29,6 @@ import com.jpexs.decompiler.flash.types.SHAPE; import com.jpexs.helpers.ByteArrayRange; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -86,30 +85,23 @@ public class DefineMorphShapeTag extends MorphShapeTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeRECT(startBounds); - sos.writeRECT(endBounds); - ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); - SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion()); - sos2.writeMORPHFILLSTYLEARRAY(morphFillStyles, 1); - sos2.writeMORPHLINESTYLEARRAY(morphLineStyles, 1); - sos2.writeSHAPE(startEdges, 1); - byte[] ba2 = baos2.toByteArray(); - sos.writeUI32(ba2.length); - sos.write(ba2); - sos.writeSHAPE(endEdges, 1); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeRECT(startBounds); + sos.writeRECT(endBounds); + ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); + SWFOutputStream sos2 = new SWFOutputStream(baos2, getVersion()); + sos2.writeMORPHFILLSTYLEARRAY(morphFillStyles, 1); + sos2.writeMORPHLINESTYLEARRAY(morphLineStyles, 1); + sos2.writeSHAPE(startEdges, 1); + byte[] ba2 = baos2.toByteArray(); + sos.writeUI32(ba2.length); + sos.write(ba2); + sos.writeSHAPE(endEdges, 1); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineScalingGridTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineScalingGridTag.java index 093934949..6ec2c7ba7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineScalingGridTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineScalingGridTag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -67,20 +65,13 @@ public class DefineScalingGridTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeRECT(splitter); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeRECT(splitter); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSceneAndFrameLabelDataTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSceneAndFrameLabelDataTag.java index dca28fe59..b4e0f9582 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSceneAndFrameLabelDataTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSceneAndFrameLabelDataTag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.annotations.Table; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -103,29 +101,22 @@ public class DefineSceneAndFrameLabelDataTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - int sceneCount = sceneOffsets.length; - sos.writeEncodedU32(sceneCount); - for (int i = 0; i < sceneCount; i++) { - sos.writeEncodedU32(sceneOffsets[i]); - sos.writeString(sceneNames[i]); - } - int frameLabelCount = frameNums.length; - sos.writeEncodedU32(frameLabelCount); - for (int i = 0; i < frameLabelCount; i++) { - sos.writeEncodedU32(frameNums[i]); - sos.writeString(frameNames[i]); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + int sceneCount = sceneOffsets.length; + sos.writeEncodedU32(sceneCount); + for (int i = 0; i < sceneCount; i++) { + sos.writeEncodedU32(sceneOffsets[i]); + sos.writeString(sceneNames[i]); + } + int frameLabelCount = frameNums.length; + sos.writeEncodedU32(frameLabelCount); + for (int i = 0; i < frameLabelCount; i++) { + sos.writeEncodedU32(frameNums[i]); + sos.writeString(frameNames[i]); } - return baos.toByteArray(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java index bbb158f96..865dea1ce 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java @@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; /** @@ -61,26 +60,21 @@ public class DefineShape2Tag extends ShapeTag { shapes = sis.readSHAPEWITHSTYLE(getShapeNum(), false, "shapes"); } else { shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + sis.skipBytes(sis.available()); } } /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); - try { - sos.writeUI16(shapeId); - sos.writeRECT(shapeBounds); - sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(shapeId); + sos.writeRECT(shapeBounds); + sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java index 21819d97c..7d03c9757 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java @@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; /** @@ -61,26 +60,21 @@ public class DefineShape3Tag extends ShapeTag { shapes = sis.readSHAPEWITHSTYLE(getShapeNum(), false, "shapes"); } else { shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + sis.skipBytes(sis.available()); } } /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); - try { - sos.writeUI16(shapeId); - sos.writeRECT(shapeBounds); - sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(shapeId); + sos.writeRECT(shapeBounds); + sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java index d19eead3a..0574b009f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java @@ -26,7 +26,6 @@ import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; /** @@ -82,31 +81,26 @@ public class DefineShape4Tag extends ShapeTag { shapes = sis.readSHAPEWITHSTYLE(getShapeNum(), false, "shapes"); } else { shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + sis.skipBytes(sis.available()); } } /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); - try { - sos.writeUI16(shapeId); - sos.writeRECT(shapeBounds); - sos.writeRECT(edgeBounds); - sos.writeUB(5, reserved); - sos.writeUB(1, usesFillWindingRule ? 1 : 0); - sos.writeUB(1, usesNonScalingStrokes ? 1 : 0); - sos.writeUB(1, usesScalingStrokes ? 1 : 0); - sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(shapeId); + sos.writeRECT(shapeBounds); + sos.writeRECT(edgeBounds); + sos.writeUB(5, reserved); + sos.writeUB(1, usesFillWindingRule ? 1 : 0); + sos.writeUB(1, usesNonScalingStrokes ? 1 : 0); + sos.writeUB(1, usesScalingStrokes ? 1 : 0); + sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java index 12248b987..9c87f8509 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java @@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; /** @@ -61,26 +60,21 @@ public class DefineShapeTag extends ShapeTag { shapes = sis.readSHAPEWITHSTYLE(getShapeNum(), false, "shapes"); } else { shapeData = new ByteArrayRange(data.getArray(), (int) sis.getPos(), sis.available()); + sis.skipBytes(sis.available()); } } /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); - try { - sos.writeUI16(shapeId); - sos.writeRECT(shapeBounds); - sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(shapeId); + sos.writeRECT(shapeBounds); + sos.writeSHAPEWITHSTYLE(getShapes(), getShapeNum()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java index 2a815c69d..c414749a3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSoundTag.java @@ -33,7 +33,6 @@ import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -107,26 +106,18 @@ public class DefineSoundTag extends CharacterTag implements SoundTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(soundId); - sos.writeUB(4, soundFormat); - sos.writeUB(2, soundRate); - sos.writeUB(1, soundSize ? 1 : 0); - sos.writeUB(1, soundType ? 1 : 0); - sos.writeUI32(soundSampleCount); - sos.write(soundData); - - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(soundId); + sos.writeUB(4, soundFormat); + sos.writeUB(2, soundRate); + sos.writeUB(1, soundSize ? 1 : 0); + sos.writeUB(1, soundType ? 1 : 0); + sos.writeUI32(soundSampleCount); + sos.write(soundData); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index 7de474d70..0a04ec90e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -19,8 +19,6 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.commonshape.Matrix; import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter; import com.jpexs.decompiler.flash.tags.base.BoundedTag; @@ -41,10 +39,7 @@ import com.jpexs.helpers.Cache; import com.jpexs.helpers.SerializableImage; import java.awt.Shape; import java.awt.geom.AffineTransform; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -131,28 +126,17 @@ public class DefineSpriteTag extends CharacterTag implements DrawableTag, Timeli /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - if (Configuration.debugCopy.get()) { - os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(spriteId); + sos.writeUI16(frameCount); + sos.writeTags(subTags); + if (hasEndTag) { + sos.writeUI16(0); } - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(spriteId); - sos.writeUI16(frameCount); - sos.writeTags(subTags); - if (hasEndTag) { - sos.writeUI16(0); - } - sos.close(); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java index 2cd617b24..b7081817b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java @@ -26,9 +26,7 @@ import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.Set; /** @@ -110,26 +108,19 @@ public class DefineVideoStreamTag extends CharacterTag implements BoundedTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.writeUI16(numFrames); - sos.writeUI16(width); - sos.writeUI16(height); - sos.writeUB(4, reserved); - sos.writeUB(3, videoFlagsDeblocking); - sos.writeUB(1, videoFlagsSmoothing ? 1 : 0); - sos.writeUI8(codecID); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.writeUI16(numFrames); + sos.writeUI16(width); + sos.writeUI16(height); + sos.writeUB(4, reserved); + sos.writeUB(3, videoFlagsDeblocking); + sos.writeUB(1, videoFlagsSmoothing ? 1 : 0); + sos.writeUI8(codecID); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java index 3a9a6c23e..1ca6d7bc5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java @@ -21,18 +21,13 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ABCInputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFField; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Defines a series of ActionScript 3 bytecodes to be executed @@ -103,25 +98,14 @@ public class DoABC2Tag extends Tag implements ABCContainerTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - OutputStream os = bos; - if (Configuration.debugCopy.get()) { - os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); - } - try (SWFOutputStream sos = new SWFOutputStream(os, getVersion())) { - sos.writeUI32(flags); - sos.writeString(name); - abc.saveToStream(sos); - } - return bos.toByteArray(); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI32(flags); + sos.writeString(name); + abc.saveToStream(sos); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java index d40764c53..f2c4ba7ef 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java @@ -21,16 +21,11 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ABCInputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFField; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Defines a series of ActionScript 3 bytecodes to be executed @@ -83,23 +78,12 @@ public class DoABCTag extends Tag implements ABCContainerTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - OutputStream os = bos; - if (Configuration.debugCopy.get()) { - os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); - } - try (SWFOutputStream sos = new SWFOutputStream(os, getVersion())) { - abc.saveToStream(sos); - } - return bos.toByteArray(); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } + public void getData(SWFOutputStream sos) throws IOException { + abc.saveToStream(sos); } @Override 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 b3e70807f..ea5d4bf0e 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 @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.DisassemblyListener; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.ActionListReader; @@ -93,11 +94,12 @@ public class DoActionTag extends Tag implements ASMSource { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - return getActionBytes(); + public void getData(SWFOutputStream sos) throws IOException { + sos.write(getActionBytes()); } /** 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 901fb9c29..0e9dd1cf9 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 @@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -92,21 +91,14 @@ public class DoInitActionTag extends Tag implements CharacterIdTag, ASMSource { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); - try { - sos.writeUI16(spriteId); - sos.write(getActionBytes()); - //sos.write(Action.actionsToBytes(actions, true, version)); - sos.close(); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(spriteId); + sos.write(getActionBytes()); + //sos.write(Action.actionsToBytes(actions, true, version)); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebugger2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebugger2Tag.java index 2f258d003..564f46f34 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebugger2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebugger2Tag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Marks the file is not importable for editing @@ -78,20 +76,12 @@ public class EnableDebugger2Tag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(reserved); - sos.writeString(passwordHash); - - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(reserved); + sos.writeString(passwordHash); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebuggerTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebuggerTag.java index 282b0bb18..f7166822b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebuggerTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableDebuggerTag.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Marks the file is not importable for editing @@ -70,20 +68,13 @@ public class EnableDebuggerTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - if (passwordHash != null) { - sos.writeString(passwordHash); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + if (passwordHash != null) { + sos.writeString(passwordHash); } - return baos.toByteArray(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableTelemetryTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableTelemetryTag.java index 3846bba3c..e7c13df31 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableTelemetryTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EnableTelemetryTag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.types.annotations.Optional; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Enable flash profiling information @@ -80,21 +78,14 @@ public class EnableTelemetryTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUB(16, reserved); - if (passwordHash != null) { - sos.write(passwordHash); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUB(16, reserved); + if (passwordHash != null) { + sos.write(passwordHash); } - return baos.toByteArray(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EndTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EndTag.java index bdcbd2f52..6b6f579d6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EndTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/EndTag.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; import java.io.IOException; @@ -60,10 +61,9 @@ public class EndTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream */ @Override - public byte[] getData() { - return new byte[0]; + public void getData(SWFOutputStream sos) { } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ExportAssetsTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ExportAssetsTag.java index e81beddf8..1a83a5654 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ExportAssetsTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ExportAssetsTag.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.annotations.Table; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -93,22 +91,15 @@ public class ExportAssetsTag extends SymbolClassTypeTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(tags.size()); - for (int i = 0; i < tags.size(); i++) { - sos.writeUI16(tags.get(i)); - sos.writeString(names.get(i)); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(tags.size()); + for (int i = 0; i < tags.size(); i++) { + sos.writeUI16(tags.get(i)); + sos.writeString(names.get(i)); } - return baos.toByteArray(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FileAttributesTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FileAttributesTag.java index bca593d46..5f478d48f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FileAttributesTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FileAttributesTag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; public class FileAttributesTag extends Tag { @@ -87,26 +85,19 @@ public class FileAttributesTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUB(1, reserved1 ? 1 : 0); //reserved - sos.writeUB(1, useDirectBlit ? 1 : 0); - sos.writeUB(1, useGPU ? 1 : 0); - sos.writeUB(1, hasMetadata ? 1 : 0); - sos.writeUB(1, actionScript3 ? 1 : 0); - sos.writeUB(1, noCrossDomainCache ? 1 : 0); - sos.writeUB(1, reserved2 ? 1 : 0); //reserved - sos.writeUB(1, useNetwork ? 1 : 0); - sos.writeUB(24, reserved3); //reserved - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUB(1, reserved1 ? 1 : 0); //reserved + sos.writeUB(1, useDirectBlit ? 1 : 0); + sos.writeUB(1, useGPU ? 1 : 0); + sos.writeUB(1, hasMetadata ? 1 : 0); + sos.writeUB(1, actionScript3 ? 1 : 0); + sos.writeUB(1, noCrossDomainCache ? 1 : 0); + sos.writeUB(1, reserved2 ? 1 : 0); //reserved + sos.writeUB(1, useNetwork ? 1 : 0); + sos.writeUB(24, reserved3); //reserved } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FrameLabelTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FrameLabelTag.java index 771fe0d01..984980f23 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FrameLabelTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FrameLabelTag.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; public class FrameLabelTag extends Tag { @@ -62,22 +60,15 @@ public class FrameLabelTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeString(name); - if (namedAnchor) { - sos.writeUI8(1); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeString(name); + if (namedAnchor) { + sos.writeUI8(1); } - return baos.toByteArray(); } public String getLabelName() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeAllTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeAllTag.java index bb7550ca8..b1a0112e0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeAllTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeAllTag.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; import java.io.IOException; @@ -54,10 +55,9 @@ public class FreeAllTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream */ @Override - public byte[] getData() { - return new byte[0]; + public void getData(SWFOutputStream sos) { } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeCharacterTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeCharacterTag.java index 272dc135f..9697ad359 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeCharacterTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/FreeCharacterTag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -66,19 +64,12 @@ public class FreeCharacterTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java index 28d96afa3..5a5419e7f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java @@ -22,15 +22,12 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.ImportTag; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.Conditional; -import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.annotations.Table; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -115,32 +112,25 @@ public class ImportAssets2Tag extends Tag implements ImportTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeString(url); - sos.writeUI8(downloadNow); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeString(url); + sos.writeUI8(downloadNow); - if (hasDigest == 1 && sha1 != null && sha1.matches("[0-9a-fA-F]{40}")) { - sos.writeUI8(1); - sos.write(Helper.hexToByteArray(sha1)); - } else { - sos.writeUI8(0); - } - sos.writeUI16(tags.size()); - for (int i = 0; i < tags.size(); i++) { - sos.writeUI16(tags.get(i)); - sos.writeString(names.get(i)); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + if (hasDigest == 1 && sha1 != null && sha1.matches("[0-9a-fA-F]{40}")) { + sos.writeUI8(1); + sos.write(Helper.hexToByteArray(sha1)); + } else { + sos.writeUI8(0); + } + sos.writeUI16(tags.size()); + for (int i = 0; i < tags.size(); i++) { + sos.writeUI16(tags.get(i)); + sos.writeString(names.get(i)); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java index 733284bca..72a1b454a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.annotations.Table; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -98,24 +96,17 @@ public class ImportAssetsTag extends Tag implements ImportTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeString(url); - sos.writeUI16(tags.size()); - for (int i = 0; i < tags.size(); i++) { - sos.writeUI16(tags.get(i)); - sos.writeString(names.get(i)); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeString(url); + sos.writeUI16(tags.size()); + for (int i = 0; i < tags.size(); i++) { + sos.writeUI16(tags.get(i)); + sos.writeString(names.get(i)); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java index 9de207067..a23b34c61 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java @@ -21,9 +21,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; public class JPEGTablesTag extends Tag { @@ -57,18 +55,11 @@ public class JPEGTablesTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.write(jpegData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.write(jpegData); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/MetadataTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/MetadataTag.java index c6aa3baee..dcee0f2f3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/MetadataTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/MetadataTag.java @@ -21,9 +21,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.annotations.Multiline; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; public class MetadataTag extends Tag { @@ -60,18 +58,11 @@ public class MetadataTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeString(xmlMetadata); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeString(xmlMetadata); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/NameCharacterTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/NameCharacterTag.java index 0f14e5f53..4311b32e9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/NameCharacterTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/NameCharacterTag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -74,20 +72,13 @@ public class NameCharacterTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeString(name); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeString(name); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PathsArePostScriptTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PathsArePostScriptTag.java index 0ab76f2af..aa6edcd45 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PathsArePostScriptTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PathsArePostScriptTag.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; import java.io.IOException; @@ -54,10 +55,9 @@ public class PathsArePostScriptTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream */ @Override - public byte[] getData() { - return new byte[0]; + public void getData(SWFOutputStream sos) { } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java index ee939dd26..698e5698e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java @@ -19,8 +19,6 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.base.ASMSourceContainer; import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag; import com.jpexs.decompiler.flash.types.BasicType; @@ -35,10 +33,7 @@ import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -224,52 +219,41 @@ public class PlaceObject2Tag extends PlaceObjectTypeTag implements ASMSourceCont /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - if (Configuration.debugCopy.get()) { - os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUB(1, placeFlagHasClipActions ? 1 : 0); + sos.writeUB(1, placeFlagHasClipDepth ? 1 : 0); + sos.writeUB(1, placeFlagHasName ? 1 : 0); + sos.writeUB(1, placeFlagHasRatio ? 1 : 0); + sos.writeUB(1, placeFlagHasColorTransform ? 1 : 0); + sos.writeUB(1, placeFlagHasMatrix ? 1 : 0); + sos.writeUB(1, placeFlagHasCharacter ? 1 : 0); + sos.writeUB(1, placeFlagMove ? 1 : 0); + sos.writeUI16(depth); + if (placeFlagHasCharacter) { + sos.writeUI16(characterId); } - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUB(1, placeFlagHasClipActions ? 1 : 0); - sos.writeUB(1, placeFlagHasClipDepth ? 1 : 0); - sos.writeUB(1, placeFlagHasName ? 1 : 0); - sos.writeUB(1, placeFlagHasRatio ? 1 : 0); - sos.writeUB(1, placeFlagHasColorTransform ? 1 : 0); - sos.writeUB(1, placeFlagHasMatrix ? 1 : 0); - sos.writeUB(1, placeFlagHasCharacter ? 1 : 0); - sos.writeUB(1, placeFlagMove ? 1 : 0); - sos.writeUI16(depth); - if (placeFlagHasCharacter) { - sos.writeUI16(characterId); - } - if (placeFlagHasMatrix) { - sos.writeMatrix(matrix); - } - if (placeFlagHasColorTransform) { - sos.writeCXFORMWITHALPHA(colorTransform); - } - if (placeFlagHasRatio) { - sos.writeUI16(ratio); - } - if (placeFlagHasName) { - sos.writeString(name); - } - if (placeFlagHasClipDepth) { - sos.writeUI16(clipDepth); - } - if (placeFlagHasClipActions) { - sos.writeCLIPACTIONS(clipActions); - } - sos.close(); - } catch (IOException e) { - throw new Error("This should never happen.", e); + if (placeFlagHasMatrix) { + sos.writeMatrix(matrix); + } + if (placeFlagHasColorTransform) { + sos.writeCXFORMWITHALPHA(colorTransform); + } + if (placeFlagHasRatio) { + sos.writeUI16(ratio); + } + if (placeFlagHasName) { + sos.writeString(name); + } + if (placeFlagHasClipDepth) { + sos.writeUI16(clipDepth); + } + if (placeFlagHasClipActions) { + sos.writeCLIPACTIONS(clipActions); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java index dc8da668d..2d9bb0767 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java @@ -20,8 +20,6 @@ import com.jpexs.decompiler.flash.EndOfStreamException; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.base.ASMSourceContainer; import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag; import com.jpexs.decompiler.flash.types.BasicType; @@ -38,10 +36,7 @@ import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -326,81 +321,70 @@ public class PlaceObject3Tag extends PlaceObjectTypeTag implements ASMSourceCont /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - if (Configuration.debugCopy.get()) { - os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); - } - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUB(1, placeFlagHasClipActions ? 1 : 0); - sos.writeUB(1, placeFlagHasClipDepth ? 1 : 0); - sos.writeUB(1, placeFlagHasName ? 1 : 0); - sos.writeUB(1, placeFlagHasRatio ? 1 : 0); - sos.writeUB(1, placeFlagHasColorTransform ? 1 : 0); - sos.writeUB(1, placeFlagHasMatrix ? 1 : 0); - sos.writeUB(1, placeFlagHasCharacter ? 1 : 0); - sos.writeUB(1, placeFlagMove ? 1 : 0); - sos.writeUB(1, reserved ? 1 : 0); - sos.writeUB(1, placeFlagOpaqueBackground ? 1 : 0); //SWF11 - sos.writeUB(1, placeFlagHasVisible ? 1 : 0); //SWF11 - sos.writeUB(1, placeFlagHasImage ? 1 : 0); - sos.writeUB(1, placeFlagHasClassName ? 1 : 0); - sos.writeUB(1, placeFlagHasCacheAsBitmap ? 1 : 0); - sos.writeUB(1, placeFlagHasBlendMode ? 1 : 0); - sos.writeUB(1, placeFlagHasFilterList ? 1 : 0); - sos.writeUI16(depth); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUB(1, placeFlagHasClipActions ? 1 : 0); + sos.writeUB(1, placeFlagHasClipDepth ? 1 : 0); + sos.writeUB(1, placeFlagHasName ? 1 : 0); + sos.writeUB(1, placeFlagHasRatio ? 1 : 0); + sos.writeUB(1, placeFlagHasColorTransform ? 1 : 0); + sos.writeUB(1, placeFlagHasMatrix ? 1 : 0); + sos.writeUB(1, placeFlagHasCharacter ? 1 : 0); + sos.writeUB(1, placeFlagMove ? 1 : 0); + sos.writeUB(1, reserved ? 1 : 0); + sos.writeUB(1, placeFlagOpaqueBackground ? 1 : 0); //SWF11 + sos.writeUB(1, placeFlagHasVisible ? 1 : 0); //SWF11 + sos.writeUB(1, placeFlagHasImage ? 1 : 0); + sos.writeUB(1, placeFlagHasClassName ? 1 : 0); + sos.writeUB(1, placeFlagHasCacheAsBitmap ? 1 : 0); + sos.writeUB(1, placeFlagHasBlendMode ? 1 : 0); + sos.writeUB(1, placeFlagHasFilterList ? 1 : 0); + sos.writeUI16(depth); - if (placeFlagHasClassName) { - sos.writeString(className); - } - if (placeFlagHasCharacter) { - sos.writeUI16(characterId); - } - if (placeFlagHasMatrix) { - sos.writeMatrix(matrix); - } - if (placeFlagHasColorTransform) { - sos.writeCXFORMWITHALPHA(colorTransform); - } - if (placeFlagHasRatio) { - sos.writeUI16(ratio); - } - if (placeFlagHasName) { - sos.writeString(name); - } - if (placeFlagHasClipDepth) { - sos.writeUI16(clipDepth); - } - if (placeFlagHasFilterList) { - sos.writeFILTERLIST(surfaceFilterList); - } - if (placeFlagHasBlendMode) { - sos.writeUI8(blendMode); - } - if (placeFlagHasCacheAsBitmap) { - if (!bitmapCacheBug) { - sos.writeUI8(bitmapCache); - } - } - if (placeFlagHasVisible) { - sos.writeUI8(visible); - } - if (placeFlagOpaqueBackground) { - sos.writeRGBA(backgroundColor); - } - if (placeFlagHasClipActions) { - sos.writeCLIPACTIONS(clipActions); - } - sos.close(); - } catch (IOException e) { - throw new Error("This should never happen.", e); + if (placeFlagHasClassName) { + sos.writeString(className); + } + if (placeFlagHasCharacter) { + sos.writeUI16(characterId); + } + if (placeFlagHasMatrix) { + sos.writeMatrix(matrix); + } + if (placeFlagHasColorTransform) { + sos.writeCXFORMWITHALPHA(colorTransform); + } + if (placeFlagHasRatio) { + sos.writeUI16(ratio); + } + if (placeFlagHasName) { + sos.writeString(name); + } + if (placeFlagHasClipDepth) { + sos.writeUI16(clipDepth); + } + if (placeFlagHasFilterList) { + sos.writeFILTERLIST(surfaceFilterList); + } + if (placeFlagHasBlendMode) { + sos.writeUI8(blendMode); + } + if (placeFlagHasCacheAsBitmap) { + if (!bitmapCacheBug) { + sos.writeUI8(bitmapCache); + } + } + if (placeFlagHasVisible) { + sos.writeUI8(visible); + } + if (placeFlagOpaqueBackground) { + sos.writeRGBA(backgroundColor); + } + if (placeFlagHasClipActions) { + sos.writeCLIPACTIONS(clipActions); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java index b922a5b29..1c9ae79bf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java @@ -20,8 +20,6 @@ import com.jpexs.decompiler.flash.EndOfStreamException; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.abc.CopyOutputStream; -import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.base.ASMSourceContainer; import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag; import com.jpexs.decompiler.flash.types.BasicType; @@ -38,10 +36,7 @@ import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -329,81 +324,70 @@ public class PlaceObject4Tag extends PlaceObjectTypeTag implements ASMSourceCont /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - if (Configuration.debugCopy.get()) { - os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); - } - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUB(1, placeFlagHasClipActions ? 1 : 0); - sos.writeUB(1, placeFlagHasClipDepth ? 1 : 0); - sos.writeUB(1, placeFlagHasName ? 1 : 0); - sos.writeUB(1, placeFlagHasRatio ? 1 : 0); - sos.writeUB(1, placeFlagHasColorTransform ? 1 : 0); - sos.writeUB(1, placeFlagHasMatrix ? 1 : 0); - sos.writeUB(1, placeFlagHasCharacter ? 1 : 0); - sos.writeUB(1, placeFlagMove ? 1 : 0); - sos.writeUB(1, reserved ? 1 : 0); - sos.writeUB(1, placeFlagOpaqueBackground ? 1 : 0); //SWF11 - sos.writeUB(1, placeFlagHasVisible ? 1 : 0); //SWF11 - sos.writeUB(1, placeFlagHasImage ? 1 : 0); - sos.writeUB(1, placeFlagHasClassName ? 1 : 0); - sos.writeUB(1, placeFlagHasCacheAsBitmap ? 1 : 0); - sos.writeUB(1, placeFlagHasBlendMode ? 1 : 0); - sos.writeUB(1, placeFlagHasFilterList ? 1 : 0); - sos.writeUI16(depth); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUB(1, placeFlagHasClipActions ? 1 : 0); + sos.writeUB(1, placeFlagHasClipDepth ? 1 : 0); + sos.writeUB(1, placeFlagHasName ? 1 : 0); + sos.writeUB(1, placeFlagHasRatio ? 1 : 0); + sos.writeUB(1, placeFlagHasColorTransform ? 1 : 0); + sos.writeUB(1, placeFlagHasMatrix ? 1 : 0); + sos.writeUB(1, placeFlagHasCharacter ? 1 : 0); + sos.writeUB(1, placeFlagMove ? 1 : 0); + sos.writeUB(1, reserved ? 1 : 0); + sos.writeUB(1, placeFlagOpaqueBackground ? 1 : 0); //SWF11 + sos.writeUB(1, placeFlagHasVisible ? 1 : 0); //SWF11 + sos.writeUB(1, placeFlagHasImage ? 1 : 0); + sos.writeUB(1, placeFlagHasClassName ? 1 : 0); + sos.writeUB(1, placeFlagHasCacheAsBitmap ? 1 : 0); + sos.writeUB(1, placeFlagHasBlendMode ? 1 : 0); + sos.writeUB(1, placeFlagHasFilterList ? 1 : 0); + sos.writeUI16(depth); - if (placeFlagHasClassName) { - sos.writeString(className); - } - if (placeFlagHasCharacter) { - sos.writeUI16(characterId); - } - if (placeFlagHasMatrix) { - sos.writeMatrix(matrix); - } - if (placeFlagHasColorTransform) { - sos.writeCXFORMWITHALPHA(colorTransform); - } - if (placeFlagHasRatio) { - sos.writeUI16(ratio); - } - if (placeFlagHasName) { - sos.writeString(name); - } - if (placeFlagHasClipDepth) { - sos.writeUI16(clipDepth); - } - if (placeFlagHasFilterList) { - sos.writeFILTERLIST(surfaceFilterList); - } - if (placeFlagHasBlendMode) { - sos.writeUI8(blendMode); - } - if (placeFlagHasCacheAsBitmap) { - if (!bitmapCacheBug) { - sos.writeUI8(bitmapCache); - } - } - if (placeFlagHasVisible) { - sos.writeUI8(visible); - } - if (placeFlagOpaqueBackground) { - sos.writeRGBA(backgroundColor); - } - if (placeFlagHasClipActions) { - sos.writeCLIPACTIONS(clipActions); - } - sos.close(); - } catch (IOException e) { - throw new Error("This should never happen.", e); + if (placeFlagHasClassName) { + sos.writeString(className); + } + if (placeFlagHasCharacter) { + sos.writeUI16(characterId); + } + if (placeFlagHasMatrix) { + sos.writeMatrix(matrix); + } + if (placeFlagHasColorTransform) { + sos.writeCXFORMWITHALPHA(colorTransform); + } + if (placeFlagHasRatio) { + sos.writeUI16(ratio); + } + if (placeFlagHasName) { + sos.writeString(name); + } + if (placeFlagHasClipDepth) { + sos.writeUI16(clipDepth); + } + if (placeFlagHasFilterList) { + sos.writeFILTERLIST(surfaceFilterList); + } + if (placeFlagHasBlendMode) { + sos.writeUI8(blendMode); + } + if (placeFlagHasCacheAsBitmap) { + if (!bitmapCacheBug) { + sos.writeUI8(bitmapCache); + } + } + if (placeFlagHasVisible) { + sos.writeUI8(visible); + } + if (placeFlagOpaqueBackground) { + sos.writeRGBA(backgroundColor); + } + if (placeFlagHasClipActions) { + sos.writeCLIPACTIONS(clipActions); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java index 24ed5ced2..0dda52564 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java @@ -30,9 +30,7 @@ import com.jpexs.decompiler.flash.types.annotations.Optional; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.List; import java.util.Set; @@ -90,24 +88,17 @@ public class PlaceObjectTag extends PlaceObjectTypeTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeUI16(depth); - sos.writeMatrix(matrix); - if (colorTransform != null) { - sos.writeCXFORM(colorTransform); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeUI16(depth); + sos.writeMatrix(matrix); + if (colorTransform != null) { + sos.writeCXFORM(colorTransform); } - return baos.toByteArray(); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProductInfoTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProductInfoTag.java index e17342251..e3162f4aa 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProductInfoTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProductInfoTag.java @@ -22,9 +22,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; public class ProductInfoTag extends Tag { @@ -98,23 +96,21 @@ public class ProductInfoTag extends Tag { compilationDateHigh = sis.readUI32("compilationDateHigh"); } + /** + * Gets data bytes + * + * @param sos SWF output stream + * @throws java.io.IOException + */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI32(productID); - sos.writeUI32(edition); - sos.writeUI8(majorVersion); - sos.writeUI8(minorVersion); - sos.writeUI32(buildLow); - sos.writeUI32(buildHigh); - sos.writeUI32(compilationDateLow); - sos.writeUI32(compilationDateHigh); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI32(productID); + sos.writeUI32(edition); + sos.writeUI8(majorVersion); + sos.writeUI8(minorVersion); + sos.writeUI32(buildLow); + sos.writeUI32(buildHigh); + sos.writeUI32(compilationDateLow); + sos.writeUI32(compilationDateHigh); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProtectTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProtectTag.java index bc943b1cb..e40c3aba2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProtectTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ProtectTag.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Marks the file is not importable for editing @@ -74,20 +72,13 @@ public class ProtectTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - if (!"".equals(passwordHash)) { - sos.writeString(passwordHash); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + if (!"".equals(passwordHash)) { + sos.writeString(passwordHash); } - return baos.toByteArray(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java index 3e3697306..552f11fc1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.tags.base.RemoveTag; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -69,19 +67,12 @@ public class RemoveObject2Tag extends RemoveTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(depth); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(depth); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObjectTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObjectTag.java index d9fb6837d..740eda76e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObjectTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/RemoveObjectTag.java @@ -24,9 +24,7 @@ import com.jpexs.decompiler.flash.tags.base.RemoveTag; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Removes the specified character @@ -82,20 +80,13 @@ public class RemoveObjectTag extends RemoveTag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeUI16(depth); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeUI16(depth); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ScriptLimitsTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ScriptLimitsTag.java index a061aaea4..c3694c795 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ScriptLimitsTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ScriptLimitsTag.java @@ -22,9 +22,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; public class ScriptLimitsTag extends Tag { @@ -61,19 +59,12 @@ public class ScriptLimitsTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(maxRecursionDepth); - sos.writeUI16(scriptTimeoutSeconds); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(maxRecursionDepth); + sos.writeUI16(scriptTimeoutSeconds); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetBackgroundColorTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetBackgroundColorTag.java index 397df1da5..d28098611 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetBackgroundColorTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetBackgroundColorTag.java @@ -21,7 +21,6 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; public class SetBackgroundColorTag extends Tag { @@ -57,15 +56,14 @@ public class SetBackgroundColorTag extends Tag { backgroundColor = sis.readRGB("backgroundColor"); } + /** + * Gets data bytes + * + * @param sos SWF output stream + * @throws java.io.IOException + */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); - try { - sos.writeRGB(backgroundColor); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeRGB(backgroundColor); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetTabIndexTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetTabIndexTag.java index 016b7e19f..a1201332c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetTabIndexTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SetTabIndexTag.java @@ -22,9 +22,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * Sets the index of an object within the tab order. @@ -79,19 +77,12 @@ public class SetTabIndexTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(depth); - sos.writeUI16(tabIndex); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(depth); + sos.writeUI16(tabIndex); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java index 3266934d1..6b6dc0478 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; import java.util.ArrayList; import java.util.List; @@ -78,11 +79,10 @@ public class ShowFrameTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream */ @Override - public byte[] getData() { - return new byte[0]; + public void getData(SWFOutputStream sos) { } public static boolean isNestedTagType(int tagTypeId) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java index 62120ab86..32bcad492 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java @@ -21,9 +21,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -70,18 +68,11 @@ public class SoundStreamBlockTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.write(streamSoundData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.write(streamSoundData); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java index ba8f81f4c..5a347ff7b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHead2Tag.java @@ -29,10 +29,8 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -118,30 +116,23 @@ public class SoundStreamHead2Tag extends Tag implements SoundStreamHeadTypeTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUB(4, reserved); - sos.writeUB(2, playBackSoundRate); - sos.writeUB(1, playBackSoundSize ? 1 : 0); - sos.writeUB(1, playBackSoundType ? 1 : 0); - sos.writeUB(4, streamSoundCompression); - sos.writeUB(2, streamSoundRate); - sos.writeUB(1, streamSoundSize ? 1 : 0); - sos.writeUB(1, streamSoundType ? 1 : 0); - sos.writeUI16(streamSoundSampleCount); - if (streamSoundCompression == 2) { - sos.writeSI16(latencySeek); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUB(4, reserved); + sos.writeUB(2, playBackSoundRate); + sos.writeUB(1, playBackSoundSize ? 1 : 0); + sos.writeUB(1, playBackSoundType ? 1 : 0); + sos.writeUB(4, streamSoundCompression); + sos.writeUB(2, streamSoundRate); + sos.writeUB(1, streamSoundSize ? 1 : 0); + sos.writeUB(1, streamSoundType ? 1 : 0); + sos.writeUI16(streamSoundSampleCount); + if (streamSoundCompression == 2) { + sos.writeSI16(latencySeek); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java index 6dc707262..32fa41ca9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java @@ -29,10 +29,8 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -117,30 +115,23 @@ public class SoundStreamHeadTag extends Tag implements SoundStreamHeadTypeTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUB(4, reserved); - sos.writeUB(2, playBackSoundRate); - sos.writeUB(1, playBackSoundSize ? 1 : 0); - sos.writeUB(1, playBackSoundType ? 1 : 0); - sos.writeUB(4, streamSoundCompression); - sos.writeUB(2, streamSoundRate); - sos.writeUB(1, streamSoundSize ? 1 : 0); - sos.writeUB(1, streamSoundType ? 1 : 0); - sos.writeUI16(streamSoundSampleCount); - if (streamSoundCompression == 2) { - sos.writeSI16(latencySeek); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUB(4, reserved); + sos.writeUB(2, playBackSoundRate); + sos.writeUB(1, playBackSoundSize ? 1 : 0); + sos.writeUB(1, playBackSoundType ? 1 : 0); + sos.writeUB(4, streamSoundCompression); + sos.writeUB(2, streamSoundRate); + sos.writeUB(1, streamSoundSize ? 1 : 0); + sos.writeUB(1, streamSoundType ? 1 : 0); + sos.writeUI16(streamSoundSampleCount); + if (streamSoundCompression == 2) { + sos.writeSI16(latencySeek); } - return baos.toByteArray(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSound2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSound2Tag.java index ede2dd95c..d484c4e58 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSound2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSound2Tag.java @@ -21,9 +21,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.SOUNDINFO; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -71,19 +69,12 @@ public class StartSound2Tag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeString(soundClassName); - sos.writeSOUNDINFO(soundInfo); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeString(soundClassName); + sos.writeSOUNDINFO(soundInfo); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSoundTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSoundTag.java index 606ea7a18..514ba732b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSoundTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/StartSoundTag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.SOUNDINFO; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -74,19 +72,12 @@ public class StartSoundTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(soundId); - sos.writeSOUNDINFO(soundInfo); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(soundId); + sos.writeSOUNDINFO(soundInfo); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SymbolClassTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SymbolClassTag.java index be19fe3fb..eec231e25 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SymbolClassTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SymbolClassTag.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.annotations.Table; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -78,23 +76,16 @@ public class SymbolClassTag extends SymbolClassTypeTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - int numSymbols = tags.size(); - sos.writeUI16(numSymbols); - for (int i = 0; i < numSymbols; i++) { - sos.writeUI16(tags.get(i)); - sos.writeString(names.get(i)); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + int numSymbols = tags.size(); + sos.writeUI16(numSymbols); + for (int i = 0; i < numSymbols; i++) { + sos.writeUI16(tags.get(i)); + sos.writeString(names.get(i)); } - return baos.toByteArray(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SyncFrameTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SyncFrameTag.java index cf91c263c..5f879dd72 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SyncFrameTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SyncFrameTag.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; import java.io.IOException; @@ -54,10 +55,9 @@ public class SyncFrameTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream */ @Override - public byte[] getData() { - return new byte[0]; + public void getData(SWFOutputStream sos) { } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java index 0016ed560..f2158e0d8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -19,6 +19,8 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; +import com.jpexs.decompiler.flash.abc.CopyOutputStream; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; @@ -39,8 +41,10 @@ import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.Serializable; import java.util.Arrays; import java.util.HashMap; @@ -88,6 +92,9 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { private final HashSet listeners = new HashSet<>(); + @Internal + public byte[] remainingData; + /** * Constructor * @@ -349,12 +356,12 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { return swf.version; } - protected byte[] getHeader(byte[] data) { + protected byte[] getHeader(int dataLength) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { SWFOutputStream sos = new SWFOutputStream(baos, swf.version); - int tagLength = data.length; + int tagLength = dataLength; int tagID = getId(); int tagIDLength = (tagID << 6); if ((tagLength <= 62) && (!forceWriteAsLong)) { @@ -395,7 +402,7 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { public void writeTag(SWFOutputStream sos) throws IOException { if (isModified()) { byte[] newData = getData(); - byte[] newHeaderData = getHeader(newData); + byte[] newHeaderData = getHeader(newData.length); sos.write(newHeaderData); sos.write(newData); } else { @@ -439,12 +446,44 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { return getName(); } + /** + * Gets data bytes + * + * @param sos SWF output stream + * @throws java.io.IOException + */ + public abstract void getData(SWFOutputStream sos) throws IOException; + /** * Gets data bytes * * @return Bytes of data */ - public abstract byte[] getData(); + public byte[] getData() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream os = baos; + if (Configuration.debugCopy.get()) { + // todo: honfika: why only the following tags? + if (this instanceof DefineSpriteTag + || this instanceof DefineButtonTag || this instanceof DefineButton2Tag + || this instanceof DefineFont3Tag + || this instanceof DoABCTag || this instanceof DoABC2Tag + || this instanceof PlaceObject2Tag || this instanceof PlaceObject3Tag || this instanceof PlaceObject4Tag) { + os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData())); + } + } + + try (SWFOutputStream sos = new SWFOutputStream(os, getVersion())) { + getData(sos); + if (remainingData != null) { + sos.write(remainingData); + } + } catch (IOException e) { + throw new Error("This should never happen.", e); + } + + return baos.toByteArray(); + } public final ByteArrayRange getOriginalRange() { return originalRange; @@ -521,7 +560,7 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { public void createOriginalData() { byte[] data = getData(); - byte[] headerData = getHeader(data); + byte[] headerData = getHeader(data.length); byte[] tagData = new byte[data.length + headerData.length]; System.arraycopy(headerData, 0, tagData, 0, headerData.length); System.arraycopy(data, 0, tagData, headerData.length, data.length); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagStub.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagStub.java index 38ab71f68..af8543e07 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagStub.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagStub.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; import java.io.IOException; @@ -51,10 +52,10 @@ public class TagStub extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream */ @Override - public byte[] getData() { + public void getData(SWFOutputStream sos) { throw new Error("TagStub.getData call is not supported."); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/UnknownTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/UnknownTag.java index 1323a6b2a..6e4bf255c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/UnknownTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/UnknownTag.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.helpers.ByteArrayRange; import java.io.IOException; @@ -38,11 +39,12 @@ public class UnknownTag extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - return getOriginalRange().getRangeData(); + public void getData(SWFOutputStream sos) throws IOException { + sos.write(getOriginalRange().getRangeData()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/VideoFrameTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/VideoFrameTag.java index 16c411201..b9d75b4f0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/VideoFrameTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/VideoFrameTag.java @@ -23,9 +23,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -78,21 +76,14 @@ public class VideoFrameTag extends Tag implements CharacterIdTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(streamID); - sos.writeUI16(frameNum); - sos.write(videoData); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(streamID); + sos.writeUI16(frameNum); + sos.write(videoData); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/StaticTextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/StaticTextTag.java index 0c210cfde..7e173df12 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/StaticTextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/StaticTextTag.java @@ -43,9 +43,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; import com.jpexs.helpers.SerializableImage; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.io.StringReader; import java.util.ArrayList; import java.util.List; @@ -95,42 +93,35 @@ public abstract class StaticTextTag extends TextTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterID); - sos.writeRECT(textBounds); - sos.writeMatrix(textMatrix); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterID); + sos.writeRECT(textBounds); + sos.writeMatrix(textMatrix); - int glyphBits = 0; - int advanceBits = 0; - for (TEXTRECORD tr : textRecords) { - for (GLYPHENTRY ge : tr.glyphEntries) { - glyphBits = SWFOutputStream.enlargeBitCountU(glyphBits, ge.glyphIndex); - advanceBits = SWFOutputStream.enlargeBitCountS(advanceBits, ge.glyphAdvance); - } + int glyphBits = 0; + int advanceBits = 0; + for (TEXTRECORD tr : textRecords) { + for (GLYPHENTRY ge : tr.glyphEntries) { + glyphBits = SWFOutputStream.enlargeBitCountU(glyphBits, ge.glyphIndex); + advanceBits = SWFOutputStream.enlargeBitCountS(advanceBits, ge.glyphAdvance); } - - if (Configuration.debugCopy.get()) { - glyphBits = Math.max(glyphBits, this.glyphBits); - advanceBits = Math.max(advanceBits, this.advanceBits); - } - - sos.writeUI8(glyphBits); - sos.writeUI8(advanceBits); - for (TEXTRECORD tr : textRecords) { - sos.writeTEXTRECORD(tr, getTextNum(), glyphBits, advanceBits); - } - sos.writeUI8(0); - } catch (IOException e) { - throw new Error("This should never happen.", e); } - return baos.toByteArray(); + + if (Configuration.debugCopy.get()) { + glyphBits = Math.max(glyphBits, this.glyphBits); + advanceBits = Math.max(advanceBits, this.advanceBits); + } + + sos.writeUI8(glyphBits); + sos.writeUI8(advanceBits); + for (TEXTRECORD tr : textRecords) { + sos.writeTEXTRECORD(tr, getTextNum(), glyphBits, advanceBits); + } + sos.writeUI8(0); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java index 33ae27a56..e66043462 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java @@ -40,9 +40,7 @@ import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.MemoryInputStream; import java.awt.Font; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -66,22 +64,15 @@ public final class DefineCompactedFont extends FontTag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(fontId); - for (FontType ft : fonts) { - ft.write(new GFxOutputStream(sos)); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(fontId); + for (FontType ft : fonts) { + ft.write(new GFxOutputStream(sos)); } - return baos.toByteArray(); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalGradient.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalGradient.java index 4502ec6e2..4af9e867d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalGradient.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalGradient.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -52,24 +50,17 @@ public class DefineExternalGradient extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(gradientId); - sos.writeUI16(bitmapsFormat); - sos.writeUI16(gradientSize); - byte[] fileNameBytes = fileName.getBytes(); - sos.writeUI8(fileNameBytes.length); - sos.write(fileNameBytes); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(gradientId); + sos.writeUI16(bitmapsFormat); + sos.writeUI16(gradientSize); + byte[] fileNameBytes = fileName.getBytes(); + sos.writeUI8(fileNameBytes.length); + sos.write(fileNameBytes); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage.java index 73d487faf..34e10ee5e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -54,25 +52,18 @@ public class DefineExternalImage extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeUI16(bitmapFormat); - sos.writeUI16(targetWidth); - sos.writeUI16(targetHeight); - byte[] fileNameBytes = fileName.getBytes(); - sos.writeUI8(fileNameBytes.length); - sos.write(fileNameBytes); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeUI16(bitmapFormat); + sos.writeUI16(targetWidth); + sos.writeUI16(targetHeight); + byte[] fileNameBytes = fileName.getBytes(); + sos.writeUI8(fileNameBytes.length); + sos.write(fileNameBytes); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage2.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage2.java index 835b8ad86..092379235 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage2.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalImage2.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -58,31 +56,24 @@ public class DefineExternalImage2 extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI32(characterId); - sos.writeUI16(bitmapFormat); - sos.writeUI16(targetWidth); - sos.writeUI16(targetHeight); - byte[] exportNameBytes = exportName.getBytes(); - sos.writeUI8(exportNameBytes.length); - sos.write(exportNameBytes); - byte[] fileNameBytes = fileName.getBytes(); - sos.writeUI8(fileNameBytes.length); - sos.write(fileNameBytes); - if (extraData != null) { - sos.write(extraData); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI32(characterId); + sos.writeUI16(bitmapFormat); + sos.writeUI16(targetWidth); + sos.writeUI16(targetHeight); + byte[] exportNameBytes = exportName.getBytes(); + sos.writeUI8(exportNameBytes.length); + sos.write(exportNameBytes); + byte[] fileNameBytes = fileName.getBytes(); + sos.writeUI8(fileNameBytes.length); + sos.write(fileNameBytes); + if (extraData != null) { + sos.write(extraData); } - return baos.toByteArray(); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalSound.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalSound.java index 9588c5889..e3db10268 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalSound.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalSound.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -58,31 +56,24 @@ public class DefineExternalSound extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeUI16(soundFormat); - sos.writeUI16(bits); - sos.writeUI16(channels); - sos.writeUI32(sampleRate); - sos.writeUI32(sampleCount); - sos.writeUI32(seekSample); - byte[] exportNameBytes = exportName.getBytes(); - sos.writeUI8(exportNameBytes.length); - sos.write(exportNameBytes); - byte[] fileNameBytes = fileName.getBytes(); - sos.writeUI8(fileNameBytes.length); - sos.write(fileNameBytes); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeUI16(soundFormat); + sos.writeUI16(bits); + sos.writeUI16(channels); + sos.writeUI32(sampleRate); + sos.writeUI32(sampleCount); + sos.writeUI32(seekSample); + byte[] exportNameBytes = exportName.getBytes(); + sos.writeUI8(exportNameBytes.length); + sos.write(exportNameBytes); + byte[] fileNameBytes = fileName.getBytes(); + sos.writeUI8(fileNameBytes.length); + sos.write(fileNameBytes); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalStreamSound.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalStreamSound.java index ecdaaa110..90277f3d9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalStreamSound.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineExternalStreamSound.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -58,29 +56,22 @@ public class DefineExternalStreamSound extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(soundFormat); - sos.writeUI16(bits); - sos.writeUI16(channels); - sos.writeUI32(sampleRate); - sos.writeUI32(sampleCount); - sos.writeUI32(seekSample); - sos.writeUI32(startFrame); - sos.writeUI32(lastFrame); - byte[] fileNameBytes = fileName.getBytes(); - sos.writeUI8(fileNameBytes.length); - sos.write(fileNameBytes); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(soundFormat); + sos.writeUI16(bits); + sos.writeUI16(channels); + sos.writeUI32(sampleRate); + sos.writeUI32(sampleCount); + sos.writeUI32(seekSample); + sos.writeUI32(startFrame); + sos.writeUI32(lastFrame); + byte[] fileNameBytes = fileName.getBytes(); + sos.writeUI8(fileNameBytes.length); + sos.write(fileNameBytes); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineGradientMap.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineGradientMap.java index 90e432dec..4b17e5661 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineGradientMap.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineGradientMap.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -40,22 +38,15 @@ public class DefineGradientMap extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(indices.length); - for (int i = 0; i < indices.length; i++) { - sos.writeUI16(indices[i]); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(indices.length); + for (int i = 0; i < indices.length; i++) { + sos.writeUI16(indices[i]); } - return baos.toByteArray(); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineSubImage.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineSubImage.java index fae191670..582a40c0f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineSubImage.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/DefineSubImage.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -50,24 +48,17 @@ public class DefineSubImage extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI16(characterId); - sos.writeUI16(imageCharacterId); - sos.writeUI16(x1); - sos.writeUI16(y1); - sos.writeUI16(x2); - sos.writeUI16(y2); - } catch (IOException e) { - throw new Error("This should never happen.", e); - } - return baos.toByteArray(); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(characterId); + sos.writeUI16(imageCharacterId); + sos.writeUI16(x1); + sos.writeUI16(y1); + sos.writeUI16(x2); + sos.writeUI16(y2); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/ExporterInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/ExporterInfo.java index b1ba88fbe..dec5b6e9c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/ExporterInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/ExporterInfo.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.ByteArrayRange; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -64,34 +62,27 @@ public class ExporterInfo extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, version); - try { - sos.writeUI16(this.version); - if (this.version >= 0x10a) { - sos.writeUI32(flags); - } - sos.writeUI16(bitmapFormat); - sos.writeUI8(prefix.length); - sos.write(prefix); - byte[] swfNameBytes = swfName.getBytes(); - sos.writeUI8(swfNameBytes.length); - sos.write(swfNameBytes); - if (codeOffsets != null) { - sos.writeUI16(codeOffsets.size()); - for (long l : codeOffsets) { - sos.writeUI32(l); - } - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI16(this.version); + if (this.version >= 0x10a) { + sos.writeUI32(flags); + } + sos.writeUI16(bitmapFormat); + sos.writeUI8(prefix.length); + sos.write(prefix); + byte[] swfNameBytes = swfName.getBytes(); + sos.writeUI8(swfNameBytes.length); + sos.write(swfNameBytes); + if (codeOffsets != null) { + sos.writeUI16(codeOffsets.size()); + for (long l : codeOffsets) { + sos.writeUI32(l); + } } - return baos.toByteArray(); } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java index af63f4763..8e4c809c9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.types.gfx.GFxOutputStream; import com.jpexs.decompiler.flash.types.gfx.TEXGLYPH; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.MemoryInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; /** * @@ -67,35 +65,28 @@ public class FontTextureInfo extends Tag { /** * Gets data bytes * - * @return Bytes of data + * @param sos SWF output stream + * @throws java.io.IOException */ @Override - public byte[] getData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStream os = baos; - SWFOutputStream sos = new SWFOutputStream(os, getVersion()); - try { - sos.writeUI32(textureID); - sos.writeUI16(textureFormat); - byte[] fileNameBytes = fileName.getBytes(); - sos.writeUI8(fileNameBytes.length); - sos.write(fileNameBytes); - sos.writeUI16(textureWidth); - sos.writeUI16(textureHeight); - sos.writeUI8(padPixels); - sos.writeUI16(nominalGlyphSz); - sos.writeUI16(texGlyphs.length); - for (int i = 0; i < texGlyphs.length; i++) { - texGlyphs[i].write(new GFxOutputStream(sos)); - } - sos.writeUI16(fonts.length); - for (int i = 0; i < fonts.length; i++) { - fonts[i].write(new GFxOutputStream(sos)); - } - } catch (IOException e) { - throw new Error("This should never happen.", e); + public void getData(SWFOutputStream sos) throws IOException { + sos.writeUI32(textureID); + sos.writeUI16(textureFormat); + byte[] fileNameBytes = fileName.getBytes(); + sos.writeUI8(fileNameBytes.length); + sos.write(fileNameBytes); + sos.writeUI16(textureWidth); + sos.writeUI16(textureHeight); + sos.writeUI8(padPixels); + sos.writeUI16(nominalGlyphSz); + sos.writeUI16(texGlyphs.length); + for (int i = 0; i < texGlyphs.length; i++) { + texGlyphs[i].write(new GFxOutputStream(sos)); + } + sos.writeUI16(fonts.length); + for (int i = 0; i < fonts.length; i++) { + fonts[i].write(new GFxOutputStream(sos)); } - return baos.toByteArray(); } /**