Beispiel #1
0
        private bool ReadHeader()
        {
            // Read file signature
            this.signature = Encoding.ASCII.GetString(this.swf.ReadUI8(3));     // "FWS" or "CWS" for ZLIB compressed (v6.0 or later)
            if (this.signature != "FWS" &&
                this.signature != "CWS")
            {
                Trace.WriteLine("Not a valid SWF (Flash) file signature");
                return(false);
            }
            TraceManager.Add(String.Format("Signature   : {0}", this.Signature));

            // Read file version
            this.version = this.swf.ReadUI8();
            TraceManager.Add(String.Format("Version     : {0}", this.Version));

            // File length
            this.fileLength = this.swf.ReadUI32();
            TraceManager.Add(String.Format("File length : {0} bytes", this.FileLength));

            // If the file is compressed, this is where the ZLIB decompression ("inflate") begins
            if (this.signature == "CWS")
            {
                // Begin inflating stream
                ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream inflatedStream =
                    new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(this.stream);
                swf.Stream = inflatedStream;
            }

            // Frame size
            Rect frameSize = new Rect(swf);

            this.frameWidth  = frameSize.XMax;
            this.frameHeight = frameSize.YMax;
            TraceManager.Add(String.Format("Frame width : {0} twips ({1} pixels)", this.FrameWidth, this.FrameWidth / 20));
            TraceManager.Add(String.Format("Frame height: {0} twips ({1} pixels)", this.FrameHeight, this.FrameHeight / 20));

            // Frame rate (stored in UI8.UI8 format)
            ushort frameRateMinor = swf.ReadUI8();
            ushort frameRateMajor = swf.ReadUI8();

            this.frameRate = Convert.ToSingle(String.Format("{0}.{1}", frameRateMajor, frameRateMinor));    // TODO: Improve this later
            TraceManager.Add(String.Format("Frame rate  : {0} fps", this.FrameRate));

            // Frame count
            this.frameCount = swf.ReadUI16();
            TraceManager.Add(String.Format("Frame count : {0}", this.FrameCount));

            return(true);
        }
Beispiel #2
0
        public Tag(SWFReader swf)
        {
            ushort tagInfo = swf.ReadUI16();
            this.id = (ushort)(tagInfo >> 6);
            this.length = (ulong)(tagInfo & 0x3f);

            // Is this a long data block?
            if (this.length == 0x3f)
            {
                this.length = swf.ReadUI32();
            }
            Trace.WriteLine(String.Format("Tag         : {0}", GetType(this.ID)));

            // For now, just skip the remainder of the tag
            // ** This is normally where you'd process each tag in the file **
            for (ulong index = 0; index < length; index++)
            {
                swf.Stream.ReadByte();
            }
        }
Beispiel #3
0
        public Tag(SWFReader swf)
        {
            ushort tagInfo = swf.ReadUI16();

            this.id     = (ushort)(tagInfo >> 6);
            this.length = (ulong)(tagInfo & 0x3f);

            // Is this a long data block?
            if (this.length == 0x3f)
            {
                this.length = swf.ReadUI32();
            }
            Trace.WriteLine(String.Format("Tag         : {0}", GetType(this.ID)));

            // For now, just skip the remainder of the tag
            // ** This is normally where you'd process each tag in the file **
            for (ulong index = 0; index < length; index++)
            {
                swf.Stream.ReadByte();
            }
        }