コード例 #1
0
        public FileVersionChunk(ref ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            var unknown  = input.ReadBytes(3); // likely varints?
            var unknown2 = input.ReadBytes(2);

            Version = input.ReadString(); //TOOD: => DirectorVersion
        }
コード例 #2
0
        public ScriptContextChunk(ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            Remnants.Enqueue(input.ReadBigEndian <int>());
            Remnants.Enqueue(input.ReadBigEndian <int>());

            int entryCount = input.ReadBigEndian <int>();

            input.ReadBigEndian <int>();

            short entryOffset = input.ReadBigEndian <short>(); //TODO: Research

            input.ReadBigEndian <short>();

            Remnants.Enqueue(input.ReadBigEndian <int>()); //0
            Type = input.ReadBigEndian <int>();            //TODO: Enum
            Remnants.Enqueue(input.ReadBigEndian <int>());

            NameListChunkId = input.ReadBigEndian <int>();

            Remnants.Enqueue(input.ReadBigEndian <short>()); //validCount
            Remnants.Enqueue(input.ReadBytes(2));            //flags, short?
            Remnants.Enqueue(input.ReadBigEndian <short>()); //freePtr

            input.Position = Header.Offset + entryOffset;

            Sections = new List <ScriptContextSection>(entryCount);
            for (int i = 0; i < entryCount; i++)
            {
                Sections.Add(new ScriptContextSection(input));
            }
        }
コード例 #3
0
        public BitmapCastProperties(ref ShockwaveReader input)
        {
            int v27 = input.ReadUInt16();

            TotalWidth = v27 & 0x7FFF; //TODO: what does that last bit even do.. some sneaky flag?
            //DIRAPI checks if TotalWidth & 0x8000 == 0

            Rectangle      = input.ReadRect();
            AlphaThreshold = input.ReadByte();
            OLE            = input.ReadBytes(7).ToArray();

            RegistrationPoint = input.ReadPoint();

            Flags = (BitmapFlags)input.ReadByte();

            if (!input.IsDataAvailable)
            {
                return;
            }
            BitDepth = input.ReadByte();

            if (!input.IsDataAvailable)
            {
                return;
            }
            Palette = input.ReadInt32();

            //TODO: PaletteRef or something
            if (!IsSystemPalette)
            {
                Palette &= 0x7FFF;
            }
        }
コード例 #4
0
        public XtraListChunk(ref ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            Remnants.Enqueue(input.ReadInt32());

            int xtraCount = input.ReadInt32();

            for (int i = 0; i < xtraCount; i++)
            {
                long xtraEndOffset = input.Position + input.ReadInt32() + 4;

                int  unk2 = input.ReadInt32();
                int  unk3 = input.ReadInt32(); //Flags or just booleans?
                Guid guid = new Guid(input.ReadBytes(16));

                int[] offsets = new int[input.ReadInt16() + 1];
                for (int j = 0; j < offsets.Length; j++)
                {
                    offsets[j] = input.ReadInt32();
                }

                do
                {
                    byte unk4 = input.ReadByte(); // 1 when kind = URL
                    byte kind = input.ReadByte(); // 2 -> Name | 0 -> URL, 5 -> File, x32 ?!? no idea

                    string str = input.ReadString();
                    input.ReadByte();
                }while (input.Position != xtraEndOffset);
            }
        }
コード例 #5
0
        private void ReadInitialLoadSegment(ref ShockwaveReader input, AfterBurnerMapEntry[] entries, Dictionary <int, ChunkItem> chunks)
        {
            //First entry in the AfterBurnerMap must be ILS.
            AfterBurnerMapEntry ilsEntry = entries[0];

            input.Advance(ilsEntry.Offset);

            //TODO: this shouldn't be here
            ReadOnlySpan <byte> compressedData = input.ReadBytes(ilsEntry.Length);

            Span <byte> decompressedData = ilsEntry.DecompressedLength <= 1024 ?
                                           stackalloc byte[ilsEntry.DecompressedLength] : new byte[ilsEntry.DecompressedLength];

            ZLib.Decompress(compressedData, decompressedData);

            ShockwaveReader ilsReader = new ShockwaveReader(decompressedData, input.IsBigEndian);

            while (ilsReader.IsDataAvailable)
            {
                int id = ilsReader.Read7BitEncodedInt();

                AfterBurnerMapEntry entry = entries.FirstOrDefault(e => e.Id == id); //TODO: Chunk entries as dictionary
                if (entry == null)
                {
                    break;
                }

                chunks.Add(id, Read(ref ilsReader, entry.Header));
            }
        }
コード例 #6
0
ファイル: LingoHandler.cs プロジェクト: gstack/Shockky
        public void Populate(ref ShockwaveReader input, int scriptChunkOffset)
        {
            input.Advance(scriptChunkOffset + _codeOffset);
            input.ReadBytes(Body.Code);

            //input.PopulateVList(scriptChunkOffset + _argumentsOffset, Arguments, input.ReadInt16);
            //input.PopulateVList(scriptChunkOffset + _localsOffset, Locals, input.ReadInt16);
            //input.PopulateVList(scriptChunkOffset + _lineOffset, new List<byte>(), input.ReadByte);
        }
コード例 #7
0
        public DeflateShockwaveReader CreateDeflateReader(ref ShockwaveReader input)
        {
            input.Advance(2); //Skip ZLib header

            int dataLeft = Header.Length - input.Position;

            byte[] compressedData = input.ReadBytes(dataLeft).ToArray();

            return(new DeflateShockwaveReader(compressedData, input.IsBigEndian));
        }
コード例 #8
0
        public static ChunkItem Read(ref ShockwaveReader input, ChunkHeader header)
        {
            ReadOnlySpan <byte> chunkSpan  = input.ReadBytes(header.Length);
            ShockwaveReader     chunkInput = new ShockwaveReader(chunkSpan, input.IsBigEndian);

            return(header.Kind switch
            {
                ChunkKind.RIFX => new FileMetadataChunk(ref chunkInput, header),

                ChunkKind.Fver => new FileVersionChunk(ref chunkInput, header),
                ChunkKind.Fcdr => new FileCompressionTypesChunk(ref chunkInput, header),
                ChunkKind.ABMP => new AfterburnerMapChunk(ref chunkInput, header),
                ChunkKind.FGEI => new FileGzipEmbeddedImageChunk(header),

                ChunkKind.imap => new InitialMapChunk(ref chunkInput, header),
                ChunkKind.mmap => new MemoryMapChunk(ref chunkInput, header),
                ChunkKind.KEYPtr => new AssociationTableChunk(ref chunkInput, header),

                ChunkKind.VWCF => new ConfigChunk(ref chunkInput, header),
                ChunkKind.DRCF => new ConfigChunk(ref chunkInput, header),

                //ChunkKind.VWSC => new ScoreChunk(ref chunkInput, header),
                ChunkKind.VWLB => new ScoreLabelChunk(ref chunkInput, header),
                ChunkKind.VWFI => new FileInfoChunk(ref chunkInput, header),

                ChunkKind.Lnam => new LingoNameChunk(ref chunkInput, header),
                ChunkKind.Lscr => new LingoScriptChunk(ref chunkInput, header),
                ChunkKind.Lctx => new LingoContextChunk(ref chunkInput, header), //TODO: StackHeight and other differences.
                ChunkKind.LctX => new LingoContextChunk(ref chunkInput, header),

                ChunkKind.CASPtr => new CastAssociationTableChunk(ref chunkInput, header),
                ChunkKind.CASt => new CastMemberPropertiesChunk(ref chunkInput, header),
                ChunkKind.MCsL => new MovieCastListChunk(ref chunkInput, header),

                //ChunkKind.Cinf => new CastInfoChunk(ref chunkInput, header),
                ChunkKind.SCRF => new ScoreReferenceChunk(ref chunkInput, header),
                ChunkKind.Sord => new SortOrderChunk(ref chunkInput, header),
                ChunkKind.CLUT => new PaletteChunk(ref chunkInput, header),
                ChunkKind.STXT => new StyledTextChunk(ref chunkInput, header),

                //ChunkKind.cupt => new CuePointsChunk(ref chunkInput, header),
                ChunkKind.snd => new SoundDataChunk(ref chunkInput, header),

                //ChunkKind.XTRl => new XtraListChunk(ref chunkInput, header),
                //ChunkKind.Fmap => new CastFontMapChunk(ref chunkInput, header),

                //ChunkKind.PUBL => new PublishSettingsChunk(ref chunkInput, header),
                ChunkKind.GRID => new GridChunk(ref chunkInput, header),
                ChunkKind.FCOL => new FavoriteColorsChunk(ref chunkInput, header),

                ChunkKind.FXmp => new FontMapChunk(ref chunkInput, header),
                ChunkKind.BITD => new BitmapDataChunk(ref chunkInput, header),

                _ => new UnknownChunk(ref chunkInput, header),
            });
コード例 #9
0
        public LingoHandler(LingoScriptChunk script, ref ShockwaveReader input)
            : this(script)
        {
            NameIndex             = input.ReadInt16();
            HandlerVectorPosition = input.ReadInt16();

            Body = new LingoHandlerBody(this, ref input);
            int codeOffset = input.ReadInt32();

            Arguments.Capacity = input.ReadInt16();
            int argumentsOffset = input.ReadInt32();

            Locals.Capacity = input.ReadInt16();
            int localsOffset = input.ReadInt32();

            input.ReadInt16(); //offset(?)
            input.ReadInt32(); //length(?)

            input.ReadInt32(); //offset?
            input.ReadInt16(); //length?

            BytesPerLine.Capacity = input.ReadInt16();
            int lineOffset = input.ReadInt32();

            Body.StackHeight = input.ReadInt32();

            int handlerEndOffset = input.Position;

            input.Position = codeOffset;
            input.ReadBytes(Body.Code);

            input.Position = argumentsOffset;
            for (int i = 0; i < Arguments.Capacity; i++)
            {
                Arguments.Add(input.ReadInt16());
            }

            input.Position = localsOffset;
            for (int i = 0; i < Locals.Capacity; i++)
            {
                Locals.Add(input.ReadInt16());
            }

            input.Position = lineOffset;
            for (int i = 0; i < BytesPerLine.Capacity; i++)
            {
                BytesPerLine.Add(input.ReadByte());
            }

            input.Position = handlerEndOffset;
        }
コード例 #10
0
        public FileInfoChunk(ref ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            /*
             * def parseSubstrings(self, data, hasHeader=True):
             *  if hasHeader:
             *          ci_offset = read32(data)
             *          unk2 = read32(data) # not int!
             *          unk3 = read32(data) # not int!
             *          entryType = read32(data)
             *          data.seek(ci_offset)
             *  else:
             *          unk2 = 0
             *          unk3 = 0
             *          entryType = 0
             *
             *  count = read16(data) + 1
             *  entries = []
             *  for i in range(count):
             *          entries.append(read32(data))
             *  rawdata = data.read(entries[-1])
             *  assert entries[0] == 0
             *  assert entries[-1] == len(rawdata)
             *
             *  strings = []
             *  for i in range(count-1):
             *          strings.append(rawdata[entries[i]:entries[i+1]])
             *
             *  return (strings, unk2, unk3, entryType)
             *
             *
             * */

            BitField = input.ReadBytes(input.ReadInt32()).ToArray();

            Offsets = new List <int>(input.ReadInt16());

            input.ReadByte();

            for (short i = 0; i < Offsets.Capacity; i++)
            {
                Offsets.Add(input.ReadInt32());
            }

            input.ReadByte();
            CreatedBy = input.ReadString();
            input.ReadByte();
            ModifiedBy = input.ReadString();
            input.ReadByte();
            FilePath = input.ReadString();
        }
コード例 #11
0
ファイル: StyledTextChunk.cs プロジェクト: jeffli678/Shockky
        public StyledTextChunk(ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            input.ReadBigEndian <int>();
            int textLength = input.ReadBigEndian <int>();

            input.ReadBigEndian <int>();

            Text = Encoding.UTF8.GetString(input.ReadBytes(textLength)); //TODO:

            Formattings = new TextFormat[input.ReadBigEndian <short>()];
            for (int i = 0; i < Formattings.Length; i++)
            {
                Formattings[i] = new TextFormat(input);
            }
        }
コード例 #12
0
        public Frame(ShockwaveReader input)
        {
            long endOffset = input.Position + input.ReadBigEndian <short>();

            if ((endOffset - input.Position) < 0)
            {
                Debugger.Break(); //We at padding of the framez I guess
            }
            while ((endOffset - input.Position) > 0)
            {
                short  channelLength = input.ReadBigEndian <short>();
                ushort channelOffset = input.ReadBigEndian <ushort>();
                byte[] data          = input.ReadBytes(channelLength);

                Debug.WriteLine($"Channel??: {channelOffset / 48} To: {channelOffset} | Len: {channelLength} | Left: {(endOffset - input.Position)}");
            }
        }
コード例 #13
0
        public void ReadValue(ShockwaveReader input, long dataOffset)
        {
            if (Kind != LiteralKind.Integer)
            {
                input.Position = dataOffset + Offset;

                int length = input.ReadBigEndian <int>();
                Value = Kind switch
                {
                    LiteralKind.String => input.ReadString(length),
                    LiteralKind.Float => input.ReadBigEndian <long>(),
                    LiteralKind.CompiledJavascript => input.ReadBytes(length)
                };
            }
            else
            {
                Value = Offset;
            }
        }
コード例 #14
0
ファイル: LingoLiteral.cs プロジェクト: gstack/Shockky
        public void ReadValue(ref ShockwaveReader input, int dataOffset)
        {
            if (Kind != LiteralKind.Integer)
            {
                input.Position = dataOffset + Offset;

                int length = input.ReadInt32();
                Value = Kind switch
                {
                    LiteralKind.String => input.ReadString(length),
                    LiteralKind.FloatingPoint => input.ReadDouble(),
                    LiteralKind.CompiledJavascript => input.ReadBytes(length).ToArray()
                };
            }
            else
            {
                Value = Offset;
            }
        }
コード例 #15
0
        public Frame(ref ShockwaveReader input)
        {
            Debug.WriteLine("## Frame start");

            long endOffset = input.Position + input.ReadInt16();

            if ((endOffset - input.Position) < 0)
            {
                Debugger.Break(); //We at padding of the framez I guess
            }
            while ((endOffset - input.Position) > 0)
            {
                short  channelLength     = input.ReadInt16();
                ushort channelOffset     = input.ReadUInt16();
                ReadOnlySpan <byte> data = input.ReadBytes(channelLength);

                Debug.WriteLine($"Channel: {channelOffset / 48} To: {channelOffset} | Len: {channelLength} | Left: {(endOffset - input.Position)}");
            }
        }
コード例 #16
0
        public FileInfoChunk(ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            int bitfieldLen = input.ReadBigEndian <int>();

            BitField = input.ReadBytes(bitfieldLen);

            Offsets = new List <int>(input.ReadBigEndian <short>());

            input.ReadByte();

            for (short i = 0; i < Offsets.Capacity; i++)
            {
                Offsets.Add(input.ReadBigEndian <int>());
            }

            input.ReadByte();
            CreatedBy = input.ReadString();
            input.ReadByte();
            ModifiedBy = input.ReadString();
            input.ReadByte();
            FilePath = input.ReadString();
        }
コード例 #17
0
        public static LingoLiteral Read(ref ShockwaveReader input, LiteralKind entryKind, int entryOffset)
        {
            if (entryKind != LiteralKind.Integer)
            {
                input.Position = entryOffset;

                int    length = input.ReadInt32();
                object value  = entryKind switch
                {
                    LiteralKind.String => input.ReadString(length),
                    LiteralKind.FloatingPoint => input.ReadDouble(),
                    LiteralKind.CompiledJavascript => input.ReadBytes(length).ToArray(),

                    _ => throw new ArgumentException(nameof(Kind))
                };

                return(new LingoLiteral(entryKind, value));
            }
            else
            {
                return(new LingoLiteral(LiteralKind.Integer, entryOffset));
            }
        }
コード例 #18
0
ファイル: BitmapChunk.cs プロジェクト: gstack/Shockky
        public void PopulateMedia(BitmapCastProperties properties)
        {
            BitDepth = properties.BitDepth;

            Flags = properties.Flags;

            TotalWidth = properties.TotalWidth;
            Width      = properties.Rectangle.Width;
            Height     = properties.Rectangle.Height;

            if (Data.Length == TotalWidth * Height)
            {
                return;
            }

            //TODO: A closer look
            Span <byte> outputSpan = TotalWidth * Height < 1024 ? stackalloc byte[TotalWidth * Height] : new byte[TotalWidth * Height];
            var         output     = new ShockwaveWriter(outputSpan, false);
            var         input      = new ShockwaveReader(Data.AsSpan());

            while (input.IsDataAvailable)
            {
                byte marker = input.ReadByte();
                if (marker >= 128)
                {
                    Span <byte> buffer = stackalloc byte[257 - marker];
                    buffer.Fill(input.ReadByte());
                    output.Write(buffer);
                }
                else
                {
                    output.Write(input.ReadBytes(marker + 1));
                }
            }

            Data = outputSpan.ToArray();
        }
コード例 #19
0
        public FileInfoChunk(ref ShockwaveReader input, ChunkHeader header)
            : base(header)
        {
            input.IsBigEndian = true;

            //TODO: VList
            BitField = input.ReadBytes(input.ReadInt32()).ToArray();

            Offsets = new List <int>(input.ReadInt16());

            input.ReadByte();

            for (short i = 0; i < Offsets.Capacity; i++)
            {
                Offsets.Add(input.ReadInt32());
            }

            input.ReadByte();
            CreatedBy = input.ReadString();
            input.ReadByte();
            ModifiedBy = input.ReadString();
            input.ReadByte();
            FilePath = input.ReadString();
        }
コード例 #20
0
ファイル: BitmapChunk.cs プロジェクト: jeffli678/Shockky
        public void PopulateMedia(BitmapCastProperties properties)
        {
            BitDepth = properties.BitDepth;

            Flags = properties.Flags;

            TotalWidth = properties.TotalWidth;
            Width      = properties.Rectangle.Width;
            Height     = properties.Rectangle.Height;

            if (Data.Length == TotalWidth * Height)
            {
                return;
            }

            using var ms     = new MemoryStream(TotalWidth * Height);
            using var output = new ShockwaveWriter(ms);
            using var input  = new ShockwaveReader(Data);

            while (input.IsDataAvailable)
            {
                byte marker = input.ReadByte();
                if (marker >= 128)
                {
                    Span <byte> buffer = stackalloc byte[257 - marker];
                    buffer.Fill(input.ReadByte());
                    output.Write(buffer);
                }
                else
                {
                    output.Write(input.ReadBytes(++marker));
                }
            }

            Data = ms.ToArray();
        }
コード例 #21
0
        public BitmapCastProperties(ChunkHeader header, ShockwaveReader input)
        {
            bool IsDataAvailable()
            => input.Position < header.Offset + header.Length;

            TotalWidth = input.ReadBigEndian <ushort>() & 0x7FFF;

            Rectangle      = input.ReadRect();
            AlphaThreshold = input.ReadByte();
            OLE            = input.ReadBytes(7); //TODO:

            short regX = input.ReadBigEndian <short>();
            short regY = input.ReadBigEndian <short>();

            RegistrationPoint = new Point(regX, regY);

            Flags = (BitmapFlags)input.ReadByte();

            if (!IsDataAvailable())
            {
                return;
            }
            BitDepth = input.ReadByte();

            if (!IsDataAvailable())
            {
                return;
            }
            Palette = input.ReadBigEndian <int>();

            //TODO: PaletteRef or something
            if (!IsSystemPalette)
            {
                Palette &= 0x7FFF;
            }
        }
コード例 #22
0
 public UnknownCastProperties(ShockwaveReader input, int length)
 {
     Data = input.ReadBytes(length);
 }
コード例 #23
0
 protected BinaryDataChunk(ShockwaveReader input, ChunkHeader header)
     : base(header)
 {
     Data = input.ReadBytes((int)header.Length);
 }
コード例 #24
0
 public UnknownCastProperties(ref ShockwaveReader input, int length)
 {
     Data = input.ReadBytes(length).ToArray();
 }
コード例 #25
0
 protected BinaryDataChunk(ref ShockwaveReader input, ChunkHeader header)
     : base(header)
 {
     Data = input.ReadBytes(header.Length).ToArray();
 }
コード例 #26
0
ファイル: UnknownChunk.cs プロジェクト: gstack/Shockky
 public UnknownChunk(ref ShockwaveReader input, ChunkHeader header)
     : base(header)
 {
     Data = input.ReadBytes(header.Length).ToArray();
 }
コード例 #27
0
 public UnknownChunk(ShockwaveReader input, ChunkHeader header)
     : base(header)
 {
     Data = input.ReadBytes((int)header.Length);
 }
コード例 #28
0
ファイル: FileVersionChunk.cs プロジェクト: jeffli678/Shockky
 public FileVersionChunk(ShockwaveReader input, ChunkHeader header)
     : base(header)
 {
     What    = input.ReadBytes(5);
     Version = input.ReadString();
 }
コード例 #29
0
        private void ReadProperty(ref ShockwaveReader input, int index, int length)
        {
            switch (index)
            {
            case 0:
                ScriptText = input.ReadString(length);
                break;

            case 1:
                Name = input.ReadString();
                break;

            case 2:
                FilePath = input.ReadString(length);
                break;

            case 3:
                FileName = input.ReadString(length);
                break;

            case 4:
                FileType = input.ReadString(length);
                break;

            case 9:
                XtraGUID = new Guid(input.ReadBytes(length));
                //XtraGUID = input.Read<Guid>();
                break;

            case 10:
                XtraName = input.ReadNullString();
                break;

            case 11:     //TODO:
                break;

            case 12:
                RegistrationPoints = new int[length / 4];
                for (int i = 0; i < RegistrationPoints.Length; i++)
                {
                    RegistrationPoints[i] = input.ReadInt32();
                }
                break;

            case 16:
                ClipboardFormat = input.ReadString(length);
                break;

            case 17:
                CreationDate = input.ReadInt32() * 1000;
                break;

            case 18:
                ModifiedDate = input.ReadInt32() * 1000;
                break;

            case 19:
                ModifiedBy = input.ReadNullString();
                break;

            case 20:
                Comments = input.ReadString(length);
                break;

            case 21:
                ReadOnlySpan <byte> imageFlags = input.ReadBytes(length);    //4

                ImageCompression = imageFlags[0] >> 4;
                ImageQuality     = imageFlags[1];
                break;

            case 7:     //TODO:
            default:
                ReadOnlySpan <byte> unknown = input.ReadBytes(length);
                break;
            }
        }