Fix (Parsing swf error: Failed to read past end of stream)

This commit is contained in:
2017-11-24 07:31:53 +07:00
parent 92645a0042
commit d4de173168
20 changed files with 138 additions and 23 deletions

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0af1635387aab4e9cb5b38d8722cecf0
folderAsset: yes
timeCreated: 1511462526
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 78561fafa47094aea89ba0771c70c41b
folderAsset: yes
timeCreated: 1511482664
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5cecc5a6be854444ea6d0ee1bac1925f
timeCreated: 1511482664
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 056a3e8eb97b34881be36dd1944cce02
timeCreated: 1511482664
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,6 @@
###### Version 1.3.10
* Fix (conversion error: 'Error: scaleSelection: Argument number 1 is invalid.')
* Fix (Parsing swf error: Failed to read past end of stream)
###### Version 1.3.9
* Not save generated meshes in scene

View File

@@ -198,6 +198,19 @@ namespace FTEditor.Postprocessors {
self_masks,
frame);
break;
case SwfDisplayInstanceType.Bitmap:
AddBitmapInstanceToFrame(
library,
inst as SwfDisplayBitmapInstance,
child_matrix,
child_blend_mode,
child_color_transform,
parent_masked,
parent_mask,
parent_masks,
self_masks,
frame);
break;
case SwfDisplayInstanceType.Sprite:
AddSpriteInstanceToFrame(
library,
@@ -268,6 +281,47 @@ namespace FTEditor.Postprocessors {
}
}
static void AddBitmapInstanceToFrame(
SwfLibrary library,
SwfDisplayBitmapInstance inst,
Matrix4x4 inst_matrix,
SwfBlendModeData inst_blend_mode,
SwfColorTransData inst_color_transform,
ushort parent_masked,
ushort parent_mask,
List<SwfInstanceData> parent_masks,
List<SwfInstanceData> self_masks,
SwfFrameData frame)
{
var bitmap_def = library.FindDefine<SwfLibraryBitmapDefine>(inst.Id);
if ( bitmap_def != null ) {
var frame_inst_type =
(parent_mask > 0 || inst.ClipDepth > 0)
? SwfInstanceData.Types.Mask
: (parent_masked > 0 || self_masks.Count > 0)
? SwfInstanceData.Types.Masked
: SwfInstanceData.Types.Group;
var frame_inst_clip_depth =
(parent_mask > 0)
? parent_mask
: (inst.ClipDepth > 0)
? inst.ClipDepth
: parent_masked + self_masks.Count;
frame.Instances.Add(new SwfInstanceData{
Type = frame_inst_type,
ClipDepth = (ushort)frame_inst_clip_depth,
Bitmap = inst.Id,
Matrix = SwfMatrixData.FromUMatrix(inst_matrix * Matrix4x4.Scale(new Vector3(20,20,1))),
BlendMode = inst_blend_mode,
ColorTrans = inst_color_transform});
if ( parent_mask > 0 ) {
parent_masks.Add(frame.Instances[frame.Instances.Count - 1]);
} else if ( inst.ClipDepth > 0 ) {
self_masks.Add(frame.Instances[frame.Instances.Count - 1]);
}
}
}
static void AddSpriteInstanceToFrame(
SwfLibrary library,
SwfDisplaySpriteInstance inst,

View File

@@ -71,6 +71,7 @@ namespace FTSwfTools {
public enum SwfDisplayInstanceType {
Shape,
Bitmap,
Sprite
}
@@ -93,6 +94,12 @@ namespace FTSwfTools {
}
}
public class SwfDisplayBitmapInstance : SwfDisplayInstance {
public override SwfDisplayInstanceType Type {
get { return SwfDisplayInstanceType.Bitmap; }
}
}
public class SwfDisplaySpriteInstance : SwfDisplayInstance {
public int CurrentTag = 0;
public SwfDisplayList DisplayList = new SwfDisplayList();

View File

@@ -33,10 +33,13 @@ namespace FTSwfTools {
public SwfDisplayList Visit(PlaceObjectTag tag, SwfDisplayList dl) {
var is_shape = Library.HasDefine<SwfLibraryShapeDefine >(tag.CharacterId);
var is_bitmap = Library.HasDefine<SwfLibraryBitmapDefine>(tag.CharacterId);
var is_sprite = Library.HasDefine<SwfLibrarySpriteDefine>(tag.CharacterId);
SwfDisplayInstance new_inst = null;
if ( is_shape ) {
new_inst = new SwfDisplayShapeInstance();
} else if ( is_bitmap ) {
new_inst = new SwfDisplayBitmapInstance();
} else if ( is_sprite ) {
new_inst = new SwfDisplaySpriteInstance();
}
@@ -56,6 +59,7 @@ namespace FTSwfTools {
public SwfDisplayList Visit(PlaceObject2Tag tag, SwfDisplayList dl) {
var is_shape = tag.HasCharacter && Library.HasDefine<SwfLibraryShapeDefine >(tag.CharacterId);
var is_bitmap = tag.HasCharacter && Library.HasDefine<SwfLibraryBitmapDefine>(tag.CharacterId);
var is_sprite = tag.HasCharacter && Library.HasDefine<SwfLibrarySpriteDefine>(tag.CharacterId);
if ( tag.HasCharacter ) {
SwfDisplayInstance old_inst = null;
@@ -68,6 +72,8 @@ namespace FTSwfTools {
SwfDisplayInstance new_inst = null;
if ( is_shape ) {
new_inst = new SwfDisplayShapeInstance();
} else if ( is_bitmap ) {
new_inst = new SwfDisplayBitmapInstance();
} else if ( is_sprite ) {
new_inst = new SwfDisplaySpriteInstance();
}
@@ -101,6 +107,7 @@ namespace FTSwfTools {
public SwfDisplayList Visit(PlaceObject3Tag tag, SwfDisplayList dl) {
var is_shape = tag.HasCharacter && Library.HasDefine<SwfLibraryShapeDefine >(tag.CharacterId);
var is_bitmap = tag.HasCharacter && Library.HasDefine<SwfLibraryBitmapDefine>(tag.CharacterId);
var is_sprite = tag.HasCharacter && Library.HasDefine<SwfLibrarySpriteDefine>(tag.CharacterId);
if ( tag.HasCharacter ) {
SwfDisplayInstance old_inst = null;
@@ -113,6 +120,8 @@ namespace FTSwfTools {
SwfDisplayInstance new_inst = null;
if ( is_shape ) {
new_inst = new SwfDisplayShapeInstance();
} else if ( is_bitmap ) {
new_inst = new SwfDisplayBitmapInstance();
} else if ( is_sprite ) {
new_inst = new SwfDisplaySpriteInstance();
}

View File

@@ -32,15 +32,21 @@ namespace FTSwfTools {
get { return Position >= Length; }
}
public long Length {
get { return _binaryReader.BaseStream.Length; }
public uint Length {
get {
var longLength = _binaryReader.BaseStream.Length;
return longLength < 0 ? 0 : (uint)longLength;
}
}
public long Position {
get { return _binaryReader.BaseStream.Position; }
public uint Position {
get {
var longPosition = _binaryReader.BaseStream.Position;
return longPosition < 0 ? 0 : (uint)longPosition;
}
}
public long BytesLeft {
public uint BytesLeft {
get { return Length - Position; }
}
@@ -50,7 +56,7 @@ namespace FTSwfTools {
}
public byte[] ReadRest() {
return ReadBytes((int)BytesLeft);
return ReadBytes(BytesLeft);
}
public bool ReadBit() {
@@ -66,20 +72,22 @@ namespace FTSwfTools {
return _binaryReader.ReadByte();
}
public byte[] ReadBytes(int count) {
return count <= 0
? new byte[0]
: _binaryReader.ReadBytes(count);
public byte[] ReadBytes(uint count) {
if ( count > (uint)int.MaxValue ) {
throw new IOException();
}
return _binaryReader.ReadBytes((int)count);
}
public char ReadChar() {
return _binaryReader.ReadChar();
}
public char[] ReadChars(int count) {
return count <= 0
? new char[0]
: _binaryReader.ReadChars(count);
public char[] ReadChars(uint count) {
if ( count > (uint)int.MaxValue ) {
throw new IOException();
}
return _binaryReader.ReadChars((int)count);
}
public short ReadInt16() {

View File

@@ -73,7 +73,7 @@ namespace FTSwfTools.SwfTags {
: (ushort)0;
tag.Matrix = tag.HasMatrix
? SwfMatrix.Read(reader, false)
? SwfMatrix.Read(reader)
: SwfMatrix.identity;
tag.ColorTransform = tag.HasColorTransform

View File

@@ -101,7 +101,7 @@ namespace FTSwfTools.SwfTags {
tag.HasFilterList = reader.ReadBit();
tag.Depth = reader.ReadUInt16();
tag.ClassName = (tag.HasClassName || (tag.HasImage && tag.HasCharacter))
tag.ClassName = tag.HasClassName
? reader.ReadString()
: string.Empty;
@@ -110,7 +110,7 @@ namespace FTSwfTools.SwfTags {
: (ushort)0;
tag.Matrix = tag.HasMatrix
? SwfMatrix.Read(reader, false)
? SwfMatrix.Read(reader)
: SwfMatrix.identity;
tag.ColorTransform = tag.HasColorTransform

View File

@@ -26,7 +26,7 @@ namespace FTSwfTools.SwfTags {
var tag = new PlaceObjectTag();
tag.CharacterId = reader.ReadUInt16();
tag.Depth = reader.ReadUInt16();
tag.Matrix = SwfMatrix.Read(reader, false);
tag.Matrix = SwfMatrix.Read(reader);
tag.ColorTransform = reader.IsEOF
? SwfColorTransform.identity
: SwfColorTransform.Read(reader, false);

View File

@@ -146,7 +146,7 @@
var type_and_size = reader.ReadUInt16();
var tag_id = type_and_size >> 6;
var short_size = type_and_size & 0x3f;
var size = short_size < 0x3f ? short_size : reader.ReadInt32();
var size = short_size < 0x3f ? (uint)short_size : reader.ReadUInt32();
var tag_data = reader.ReadBytes(size);
return Create(new SwfTagData{
TagId = tag_id,

View File

@@ -19,7 +19,7 @@
}
}
public static SwfMatrix Read(SwfStreamReader reader, bool fill_style) {
public static SwfMatrix Read(SwfStreamReader reader) {
var matrix = SwfMatrix.identity;
var has_scale = reader.ReadBit();
if ( has_scale ) {

View File

@@ -98,7 +98,7 @@ namespace FTSwfTools.SwfTypes {
SwfColor.Read(reader, with_alpha);
}
if ( fill_style.Type.IsGradientType ) {
SwfMatrix.Read(reader, true); // GradientMatrix
SwfMatrix.Read(reader); // GradientMatrix
switch ( fill_style.Type.Value ) {
case SwfFillStyleType.Type.LinearGradient:
case SwfFillStyleType.Type.RadialGradient:
@@ -111,7 +111,7 @@ namespace FTSwfTools.SwfTypes {
}
if ( fill_style.Type.IsBitmapType ) {
fill_style.BitmapId = reader.ReadUInt16();
fill_style.BitmapMatrix = SwfMatrix.Read(reader, true);
fill_style.BitmapMatrix = SwfMatrix.Read(reader);
} else {
throw new System.Exception(
"Imported .swf file contains vector graphics. " +

View File

@@ -1,2 +1,2 @@
m_EditorVersion: 5.3.7p2
m_EditorVersion: 5.3.7f1
m_StandardAssetsVersion: 0

View File

@@ -64,6 +64,8 @@ https://gist.github.com/talecrafter/111ea3345911bd238f4998b4d5a04bf3
**** TODO Оптимизации по скейлу не влияют на растр
**** TODO Не работает конвертация в batchmod'е
**** TODO Площадь для оптимизации вычисляется некорректно при повёрнутых клипах
**** DONE Parsing swf error: Failed to read past end of stream
Из-за помеченых для экспорта битмапов (blockers_tmp_0.fla)
**** DONE conversion error: 'Error: scaleSelection: Argument number 1 is invalid.'
HsiyaoWang/magoichi-test.fla
**** TODO Возможно проблемы с DX9

Binary file not shown.