From 68dcce0a5fd8599ba21f7a12f1fb0759edda19e1 Mon Sep 17 00:00:00 2001 From: honfika Date: Mon, 28 Jul 2014 21:03:14 +0200 Subject: [PATCH] added missing getData functions --- .../flash/gui/GenericTagTreePanel.java | 11 +++++--- .../flash/tags/DefineFontNameTag.java | 22 +++++++++++++++ .../flash/tags/DefineShape2Tag.java | 22 +++++++++++++++ .../flash/tags/DefineShape3Tag.java | 22 +++++++++++++++ .../flash/tags/DefineShape4Tag.java | 27 +++++++++++++++++++ .../jpexs/decompiler/flash/tags/EndTag.java | 1 + .../decompiler/flash/tags/JPEGTablesTag.java | 20 ++++++++++++++ .../flash/tags/RemoveObject2Tag.java | 20 ++++++++++++++ .../decompiler/flash/tags/ShowFrameTag.java | 10 +++++++ .../flash/tags/SoundStreamBlockTag.java | 20 ++++++++++++++ src/com/jpexs/decompiler/flash/tags/Tag.java | 12 ++++----- .../jpexs/decompiler/flash/tags/TagStub.java | 10 +++++++ .../decompiler/flash/tags/UnknownTag.java | 11 +++++++- 13 files changed, 197 insertions(+), 11 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index dc17f3364..52f924778 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -48,6 +48,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -662,10 +663,14 @@ public class GenericTagTreePanel extends GenericTagPanel { this.tag = tag; SWF swf = tag.getSwf(); try { - if (tag instanceof TagStub) { - this.editedTag = SWFInputStream.resolveTag((TagStub)tag, 0, false, true, swf.gfx); - } + byte[] data = tag.getData(); + SWFInputStream tagDataStream = new SWFInputStream(swf, data, 0, data.length); + TagStub copy = new TagStub(swf, tag.getId(), "Unresolved", tag.getOriginalRange(), tagDataStream); + copy.forceWriteAsLong = tag.forceWriteAsLong; + this.editedTag = SWFInputStream.resolveTag(copy, 0, false, true, swf.gfx); } catch (InterruptedException ex) { + } catch (IOException ex) { + Logger.getLogger(GenericTagTreePanel.class.getName()).log(Level.SEVERE, null, ex); } tree.setEditable(edit); if (!edit) { diff --git a/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java b/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java index 528aa6849..4ca136d0f 100644 --- a/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java +++ b/src/com/jpexs/decompiler/flash/tags/DefineFontNameTag.java @@ -17,10 +17,13 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; +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 DefineFontNameTag extends Tag { @@ -36,4 +39,23 @@ public class DefineFontNameTag extends Tag { fontName = sis.readString("fontName"); fontCopyright = sis.readString("fontCopyright"); } + + /** + * Gets data bytes + * + * @return Bytes of data + */ + @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) { + } + return baos.toByteArray(); + } } diff --git a/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java b/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java index 1c84b53a2..74fe9cbf8 100644 --- a/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java +++ b/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.BasicType; @@ -24,7 +25,9 @@ import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; 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; public class DefineShape2Tag extends ShapeTag { @@ -76,6 +79,25 @@ public class DefineShape2Tag extends ShapeTag { shapes = sis.readSHAPEWITHSTYLE(2, false, "shapes"); } + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream os = baos; + SWFOutputStream sos = new SWFOutputStream(os, getVersion()); + try { + sos.writeUI16(shapeId); + sos.writeRECT(shapeBounds); + sos.writeSHAPEWITHSTYLE(shapes, 2); + } catch (IOException e) { + } + return baos.toByteArray(); + } + @Override public int getNumFrames() { return 1; diff --git a/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java b/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java index 0e65c53a5..6018bf647 100644 --- a/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java +++ b/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.BasicType; @@ -24,7 +25,9 @@ import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; 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; public class DefineShape3Tag extends ShapeTag { @@ -76,6 +79,25 @@ public class DefineShape3Tag extends ShapeTag { shapes = sis.readSHAPEWITHSTYLE(3, false, "shapes"); } + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream os = baos; + SWFOutputStream sos = new SWFOutputStream(os, getVersion()); + try { + sos.writeUI16(shapeId); + sos.writeRECT(shapeBounds); + sos.writeSHAPEWITHSTYLE(shapes, 3); + } catch (IOException e) { + } + return baos.toByteArray(); + } + @Override public int getNumFrames() { return 1; diff --git a/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java b/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java index 689faa45a..072dd289f 100644 --- a/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java +++ b/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.BasicType; @@ -25,7 +26,9 @@ 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; +import java.io.OutputStream; import java.util.Set; public class DefineShape4Tag extends ShapeTag { @@ -89,6 +92,30 @@ public class DefineShape4Tag extends ShapeTag { shapes = sis.readSHAPEWITHSTYLE(4, false, "shapes"); } + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream os = baos; + SWFOutputStream sos = new SWFOutputStream(os, getVersion()); + try { + sos.writeUI16(shapeId); + sos.writeRECT(shapeBounds); + sos.writeRECT(edgeBounds); + sos.writeUB(5, reserved); + sos.writeUB(1, usesFillWindingRule ? 1 : 0); + sos.writeUB(5, usesNonScalingStrokes ? 1 : 0); + sos.writeUB(5, usesScalingStrokes ? 1 : 0); + sos.writeSHAPEWITHSTYLE(shapes, 4); + } catch (IOException e) { + } + return baos.toByteArray(); + } + @Override public int getNumFrames() { return 1; diff --git a/src/com/jpexs/decompiler/flash/tags/EndTag.java b/src/com/jpexs/decompiler/flash/tags/EndTag.java index 5ee9863a9..c025fb0e4 100644 --- a/src/com/jpexs/decompiler/flash/tags/EndTag.java +++ b/src/com/jpexs/decompiler/flash/tags/EndTag.java @@ -36,6 +36,7 @@ public class EndTag extends Tag { public byte[] getData() { return new byte[0]; } + public static final int ID = 0; /** diff --git a/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java b/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java index 1d81284ab..c6f0fff62 100644 --- a/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java +++ b/src/com/jpexs/decompiler/flash/tags/JPEGTablesTag.java @@ -17,9 +17,12 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.helpers.ByteArrayRange; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.OutputStream; public class JPEGTablesTag extends Tag { @@ -31,4 +34,21 @@ public class JPEGTablesTag extends Tag { super(sis.getSwf(), ID, "JPEGTables", data); jpegData = sis.readBytesEx(sis.available(), "jpegData"); } + + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream os = baos; + SWFOutputStream sos = new SWFOutputStream(os, getVersion()); + try { + sos.write(jpegData); + } catch (IOException e) { + } + return baos.toByteArray(); + } } diff --git a/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java b/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java index 33a143b5c..328232034 100644 --- a/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java +++ b/src/com/jpexs/decompiler/flash/tags/RemoveObject2Tag.java @@ -17,11 +17,14 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; 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; public class RemoveObject2Tag extends Tag implements RemoveTag { @@ -34,6 +37,23 @@ public class RemoveObject2Tag extends Tag implements RemoveTag { depth = sis.readUI16("depth"); } + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream os = baos; + SWFOutputStream sos = new SWFOutputStream(os, getVersion()); + try { + sos.writeUI16(depth); + } catch (IOException e) { + } + return baos.toByteArray(); + } + @Override public int getDepth() { return depth; diff --git a/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java b/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java index 82c3a966e..0e5473886 100644 --- a/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java +++ b/src/com/jpexs/decompiler/flash/tags/ShowFrameTag.java @@ -62,6 +62,16 @@ public class ShowFrameTag extends Tag { super(swf, ID, "ShowFrame", null); } + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + return new byte[0]; + } + public static boolean isNestedTagType(int tagTypeId) { return nestedTagTypeIds.contains(tagTypeId); } diff --git a/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java b/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java index 4922f5562..06485b9e5 100644 --- a/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java +++ b/src/com/jpexs/decompiler/flash/tags/SoundStreamBlockTag.java @@ -17,9 +17,12 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.helpers.ByteArrayRange; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.OutputStream; /** * @@ -45,4 +48,21 @@ public class SoundStreamBlockTag extends Tag { //all data is streamSoundData streamSoundData = sis.readBytesEx(sis.available(), "streamSoundData"); } + + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream os = baos; + SWFOutputStream sos = new SWFOutputStream(os, getVersion()); + try { + sos.write(streamSoundData); + } catch (IOException e) { + } + return baos.toByteArray(); + } } diff --git a/src/com/jpexs/decompiler/flash/tags/Tag.java b/src/com/jpexs/decompiler/flash/tags/Tag.java index 50981f219..9873179af 100644 --- a/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -131,8 +131,8 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem, } private static final Object lockObject = new Object(); - private static List knownTagIds; - private static List requiredTagIds; + private volatile static List knownTagIds; + private volatile static List requiredTagIds; public static List getKnownTags() { if (knownTagIds == null) { @@ -349,10 +349,8 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem, * * @return Bytes of data */ - public byte[] getData() { - return getOriginalData().getRangeData(); - } - + public abstract byte[] getData(); + public final ByteArrayRange getOriginalRange() { return originalRange; } @@ -375,7 +373,7 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem, return originalRange.length - (isLongOriginal() ? 6 : 2); } - private final boolean isLongOriginal() { + private boolean isLongOriginal() { int shortLength = originalRange.array[(int) originalRange.pos] & 0x003F; return shortLength == 0x3f; } diff --git a/src/com/jpexs/decompiler/flash/tags/TagStub.java b/src/com/jpexs/decompiler/flash/tags/TagStub.java index 84415d9a0..5cece4c0f 100644 --- a/src/com/jpexs/decompiler/flash/tags/TagStub.java +++ b/src/com/jpexs/decompiler/flash/tags/TagStub.java @@ -43,6 +43,16 @@ public class TagStub extends Tag { dataStream = sis; } + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + return getOriginalData().getRangeData(); + } + public SWFInputStream getDataStream() { return dataStream; } diff --git a/src/com/jpexs/decompiler/flash/tags/UnknownTag.java b/src/com/jpexs/decompiler/flash/tags/UnknownTag.java index cab7aac9c..acc4f58dc 100644 --- a/src/com/jpexs/decompiler/flash/tags/UnknownTag.java +++ b/src/com/jpexs/decompiler/flash/tags/UnknownTag.java @@ -29,9 +29,18 @@ public class UnknownTag extends Tag { super(swf, id, "Unknown", data); } + /** + * Gets data bytes + * + * @return Bytes of data + */ + @Override + public byte[] getData() { + return getOriginalRange().getRangeData(); + } + @Override public String toString() { return super.toString() + " (ID=" + id + ")"; } - }