From 6a2f1027b868fe30882ccfd5601cd7b79a526352 Mon Sep 17 00:00:00 2001 From: honfika Date: Sun, 24 Aug 2014 11:07:01 +0200 Subject: [PATCH] gfx dump view fixes, FileAttributeTag fix in dumpview --- .../decompiler/flash/SWFInputStream.java | 27 ++++---- .../flash/configuration/Configuration.java | 6 +- .../flash/tags/gfx/DefineCompactedFont.java | 6 +- .../flash/tags/gfx/FontTextureInfo.java | 8 ++- .../flash/types/gfx/ContourType.java | 2 + .../decompiler/flash/types/gfx/FontType.java | 9 ++- .../flash/types/gfx/GFxInputStream.java | 3 + .../decompiler/flash/types/gfx/GlyphType.java | 2 + src/com/jpexs/helpers/ImmediateFuture.java | 61 +++++++++++++++++++ 9 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 src/com/jpexs/helpers/ImmediateFuture.java diff --git a/src/com/jpexs/decompiler/flash/SWFInputStream.java b/src/com/jpexs/decompiler/flash/SWFInputStream.java index f97bca26f..91011483e 100644 --- a/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -264,6 +264,7 @@ import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; +import com.jpexs.helpers.ImmediateFuture; import com.jpexs.helpers.MemoryInputStream; import com.jpexs.helpers.ProgressListener; import com.jpexs.helpers.utf8.Utf8Helper; @@ -1010,9 +1011,6 @@ public class SWFInputStream implements AutoCloseable { executor = Executors.newFixedThreadPool(Configuration.parallelThreadCount.get()); futureResults = new ArrayList<>(); } - int tagCnt = 0; - int faPos = 0; - FileAttributesTag fileAttributes = null; List tags = new ArrayList<>(); Tag tag; boolean isAS3 = false; @@ -1024,7 +1022,6 @@ public class SWFInputStream implements AutoCloseable { } catch (EOFException | EndOfStreamException ex) { tag = null; } - tagCnt++; DumpInfo di = dumpInfo; if (di != null && tag != null) { di.name = tag.getName(); @@ -1048,11 +1045,10 @@ public class SWFInputStream implements AutoCloseable { } else { switch (tag.getId()) { case FileAttributesTag.ID: //FileAttributes - faPos = tagCnt - 1; //should be 0, as it is first tag, but anyway if (tag instanceof TagStub) { tag = resolveTag((TagStub) tag, level, parallel, skipUnusualTags); } - fileAttributes = (FileAttributesTag) tag; + FileAttributesTag fileAttributes = (FileAttributesTag) tag; if (fileAttributes.actionScript3) { isAS3 = true; } @@ -1091,11 +1087,12 @@ public class SWFInputStream implements AutoCloseable { } } - if (parseTags && doParse && tag instanceof TagStub) { - if (parallel) { - Future future = executor.submit(new TagResolutionTask((TagStub) tag, di, level, parallel, skipUnusualTags)); - futureResults.add(future); - } + if (parseTags && doParse && parallel && tag instanceof TagStub) { + Future future = executor.submit(new TagResolutionTask((TagStub) tag, di, level, parallel, skipUnusualTags)); + futureResults.add(future); + } else { + Future future = new ImmediateFuture(tag); + futureResults.add(future); } if (tag.getId() == EndTag.ID) { @@ -1116,10 +1113,6 @@ public class SWFInputStream implements AutoCloseable { executor.shutdown(); } - //Workaround to not reading fileattributes twice. TODO:Handle this better - if (parallel && fileAttributes != null) { - tags.add(faPos, fileAttributes); - } return tags; } @@ -3296,7 +3289,9 @@ public class SWFInputStream implements AutoCloseable { public MemoryInputStream getBaseStream() throws IOException { int pos = (int) is.getPos(); - return new MemoryInputStream(is.getAllRead(), pos, is.available()); + MemoryInputStream mis = new MemoryInputStream(is.getAllRead(), 0, pos + is.available()); + mis.seek(pos); + return mis; } public SWFInputStream getLimitedStream(int limit) throws IOException { diff --git a/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/src/com/jpexs/decompiler/flash/configuration/Configuration.java index cdfd927de..14dc9985d 100644 --- a/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -452,8 +452,10 @@ public class Configuration { Map result = new HashMap<>(); for (String pair : fonts.split("::")) { - String[] splittedPair = pair.split("="); - result.put(splittedPair[0], splittedPair[1]); + if (!pair.isEmpty()) { + String[] splittedPair = pair.split("="); + result.put(splittedPair[0], splittedPair[1]); + } } return result; } diff --git a/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java b/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java index e66b01300..955b377f4 100644 --- a/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java +++ b/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java @@ -97,7 +97,11 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag { MemoryInputStream mis = sis.getBaseStream(); while (mis.available() > 0) { - fonts.add(new FontType(new GFxInputStream(mis))); + GFxInputStream gis = new GFxInputStream(mis); + gis.dumpInfo = sis.dumpInfo; + gis.newDumpLevel("fontType", "FontType"); + fonts.add(new FontType(gis)); + gis.endDumpLevel(); } rebuildShapeCache(); } diff --git a/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java b/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java index 12615d85f..da1c61633 100644 --- a/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java +++ b/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java @@ -104,14 +104,18 @@ public class FontTextureInfo extends Tag { texGlyphs = new TEXGLYPH[numTexGlyphs]; MemoryInputStream mis = sis.getBaseStream(); for (int i = 0; i < numTexGlyphs; i++) { - texGlyphs[i] = new TEXGLYPH(new GFxInputStream(mis)); + GFxInputStream gis = new GFxInputStream(mis); + gis.dumpInfo = sis.dumpInfo; + texGlyphs[i] = new TEXGLYPH(gis); } sis.skipBytes(mis.getPos()); int numFonts = sis.readUI16("numFonts"); fonts = new FONTINFO[numFonts]; mis = sis.getBaseStream(); for (int i = 0; i < numFonts; i++) { - fonts[i] = new FONTINFO(new GFxInputStream(sis.getBaseStream())); + GFxInputStream gis = new GFxInputStream(mis); + gis.dumpInfo = sis.dumpInfo; + fonts[i] = new FONTINFO(gis); } sis.skipBytes(mis.getPos()); } diff --git a/src/com/jpexs/decompiler/flash/types/gfx/ContourType.java b/src/com/jpexs/decompiler/flash/types/gfx/ContourType.java index d557348f4..fb0237169 100644 --- a/src/com/jpexs/decompiler/flash/types/gfx/ContourType.java +++ b/src/com/jpexs/decompiler/flash/types/gfx/ContourType.java @@ -85,7 +85,9 @@ public class ContourType implements Serializable { edges = new EdgeType[(int) numEdgesRef]; for (int i = 0; i < edges.length; i++) { + sis.newDumpLevel("edgeType", "EdgeType"); edges[i] = new EdgeType(sis); + sis.endDumpLevel(); } if (isReference) { sis.setPos(oldPos); diff --git a/src/com/jpexs/decompiler/flash/types/gfx/FontType.java b/src/com/jpexs/decompiler/flash/types/gfx/FontType.java index 456faa088..84feef63f 100644 --- a/src/com/jpexs/decompiler/flash/types/gfx/FontType.java +++ b/src/com/jpexs/decompiler/flash/types/gfx/FontType.java @@ -42,6 +42,7 @@ public class FontType implements Serializable { public List kerning; public FontType(GFxInputStream sis) throws IOException { + long offset = sis.getPos(); fontName = sis.readString("fontName"); flags = sis.readUI16("flags"); nominalSize = sis.readUI16("nominalSize"); @@ -54,21 +55,27 @@ public class FontType implements Serializable { sis.read(glyphBytes); glyphInfo = new ArrayList<>(); for (int i = 0; i < numGlyphs; i++) { + sis.newDumpLevel("glyphInfoType", "GlyphInfoType"); glyphInfo.add(new GlyphInfoType(sis)); + sis.endDumpLevel(); } long kerningTableSize = sis.readUI30("kerningTableSize"); kerning = new ArrayList<>(); for (int i = 0; i < kerningTableSize; i++) { + sis.newDumpLevel("kerningPairType", "KerningPairType"); kerning.add(new KerningPairType(sis)); + sis.endDumpLevel(); } long pos = sis.getPos(); glyphs = new ArrayList<>(); for (int i = 0; i < glyphInfo.size(); i++) { - sis.setPos(glyphInfo.get(i).globalOffset); + sis.setPos(glyphInfo.get(i).globalOffset + offset); + sis.newDumpLevel("glyphType", "GlyphType"); glyphs.add(new GlyphType(sis)); + sis.endDumpLevel(); } sis.setPos(pos); diff --git a/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java b/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java index f5cc2d463..24fa517d7 100644 --- a/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java +++ b/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java @@ -93,6 +93,7 @@ public class GFxInputStream { /** * Reads one SI16 (Signed 16bit integer) value from the stream * + * @param name * @return SI16 value * @throws IOException */ @@ -206,6 +207,7 @@ public class GFxInputStream { * Reads bytes from the stream * * @param count Number of bytes to read + * @param name * @return Array of read bytes * @throws IOException */ @@ -229,6 +231,7 @@ public class GFxInputStream { /** * Reads one string value from the stream * + * @param name * @return String value * @throws IOException */ diff --git a/src/com/jpexs/decompiler/flash/types/gfx/GlyphType.java b/src/com/jpexs/decompiler/flash/types/gfx/GlyphType.java index 8dfa3b5f7..80d2d84ea 100644 --- a/src/com/jpexs/decompiler/flash/types/gfx/GlyphType.java +++ b/src/com/jpexs/decompiler/flash/types/gfx/GlyphType.java @@ -69,7 +69,9 @@ public class GlyphType implements Serializable { int numContours = sis.readUI15("numContours"); contours = new ContourType[numContours]; for (int i = 0; i < numContours; i++) { + sis.newDumpLevel("contourType", "ContourType"); contours[i] = new ContourType(sis); + sis.endDumpLevel(); } } diff --git a/src/com/jpexs/helpers/ImmediateFuture.java b/src/com/jpexs/helpers/ImmediateFuture.java new file mode 100644 index 000000000..35bd8123f --- /dev/null +++ b/src/com/jpexs/helpers/ImmediateFuture.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.helpers; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * + * @author JPEXS + * @param + */ +public class ImmediateFuture implements Future { + + private final V value; + + public ImmediateFuture(V value) { + this.value = value; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public V get() throws InterruptedException, ExecutionException { + return value; + } + + @Override + public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + return value; + } +}