From e453fabfca0ff98c26b52437f423fc73671fd364 Mon Sep 17 00:00:00 2001 From: honfika Date: Sun, 24 Aug 2014 08:41:31 +0200 Subject: [PATCH] partial fix for #649 --- .../action/model/SetMemberActionItem.java | 1 - .../flash/tags/gfx/DefineCompactedFont.java | 6 ++++-- .../flash/tags/gfx/FontTextureInfo.java | 9 +++++++- .../decompiler/flash/types/gfx/FontType.java | 7 +------ .../flash/types/gfx/GFxInputStream.java | 21 +++++++++++++++++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java b/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java index d1c3cd3c0..11fffecd5 100644 --- a/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java +++ b/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; -import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.Deobfuscation; import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; diff --git a/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java b/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java index 0daaa9f63..e66b01300 100644 --- a/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java +++ b/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java @@ -39,6 +39,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.MemoryInputStream; import java.awt.Font; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -94,8 +95,9 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag { fontId = sis.readUI16("fontId"); fonts = new ArrayList<>(); - while (sis.available() > 0) { - fonts.add(new FontType(new GFxInputStream(sis.getBaseStream()))); + MemoryInputStream mis = sis.getBaseStream(); + while (mis.available() > 0) { + fonts.add(new FontType(new GFxInputStream(mis))); } rebuildShapeCache(); } diff --git a/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java b/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java index 8f912b35c..56a55e670 100644 --- a/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java +++ b/src/com/jpexs/decompiler/flash/tags/gfx/FontTextureInfo.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.types.gfx.GFxInputStream; 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; @@ -101,13 +102,19 @@ public class FontTextureInfo extends Tag { nominalGlyphSz = sis.readUI16("nominalGlyphSz"); int numTexGlyphs = sis.readUI16("numTexGlyphs"); texGlyphs = new TEXGLYPH[numTexGlyphs]; + MemoryInputStream mis = sis.getBaseStream(); for (int i = 0; i < numTexGlyphs; i++) { - texGlyphs[i] = new TEXGLYPH(new GFxInputStream(sis.getBaseStream())); + texGlyphs[i] = new TEXGLYPH(new GFxInputStream(mis)); } + // todo: honfika: add GFx data to dump view + 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())); } + // todo: honfika: add GFx data to dump view + sis.skipBytes(mis.getPos()); } } diff --git a/src/com/jpexs/decompiler/flash/types/gfx/FontType.java b/src/com/jpexs/decompiler/flash/types/gfx/FontType.java index c26f6c69b..f9fd3e050 100644 --- a/src/com/jpexs/decompiler/flash/types/gfx/FontType.java +++ b/src/com/jpexs/decompiler/flash/types/gfx/FontType.java @@ -42,12 +42,7 @@ public class FontType implements Serializable { public List kerning; public FontType(GFxInputStream sis) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - int val; - while ((val = sis.readUI8()) > 0) { - baos.write(val); - } - fontName = new String(baos.toByteArray()); + fontName = sis.readString(); flags = sis.readUI16(); nominalSize = sis.readUI16(); ascent = sis.readSI16(); diff --git a/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java b/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java index a0aeb9836..b59b7f57e 100644 --- a/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java +++ b/src/com/jpexs/decompiler/flash/types/gfx/GFxInputStream.java @@ -17,6 +17,8 @@ package com.jpexs.decompiler.flash.types.gfx; import com.jpexs.helpers.MemoryInputStream; +import com.jpexs.helpers.utf8.Utf8Helper; +import java.io.ByteArrayOutputStream; import java.io.IOException; /** @@ -161,4 +163,23 @@ public class GFxInputStream { void read(byte[] bytes) throws IOException { is.read(bytes); } + + /** + * Reads one string value from the stream + * + * @param name + * @return String value + * @throws IOException + */ + public String readString() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + int r; + while (true) { + r = readUI8(); + if (r == 0) { + return new String(baos.toByteArray(), Utf8Helper.charset); + } + baos.write(r); + } + } }