Exemplo n.º 1
0
        internal static IBinaryStream OpenEncrypted(IBinaryStream input, int encrypted_length = DefaultEncryptedLength)
        {
            input.Position = 0;
            var header = input.ReadBytes(encrypted_length + 2);

            header[0] ^= 0xFF;
            header[1]  = Binary.RotByteL((byte)~header[1], 1);
            int  shift = 1;
            byte count = header[0];

            for (int i = 2; i < header.Length; ++i)
            {
                header[i] = Binary.RotByteL(header[i], shift);
                if (++shift >= 7)
                {
                    shift = 1;
                }
                if (--count == 0)
                {
                    if (shift <= 4)
                    {
                        count = header[1];
                    }
                    else
                    {
                        count = header[0];
                    }
                    shift = 1;
                }
            }
            Stream stream = new StreamRegion(input.AsStream, header.Length, true);

            stream = new PrefixStream(header, stream);
            return(new BinaryStream(stream, input.Name));
        }
Exemplo n.º 2
0
        private ImageData ReadJpeg(Stream file, SpdMetaData info)
        {
            file.Position = 0x18;
            var header = new byte[0x3C];

            if (header.Length != file.Read(header, 0, header.Length))
            {
                throw new EndOfStreamException();
            }
            unsafe
            {
                fixed(byte *raw = header)
                {
                    uint *dw = (uint *)raw;

                    for (int i = 0; i < 0xF; ++i)
                    {
                        dw[i] += 0xA8961EF1;
                    }
                }
            }
            using (var rest = new StreamRegion(file, file.Position, true))
                using (var jpeg = new PrefixStream(header, rest))
                {
                    var decoder = new JpegBitmapDecoder(jpeg,
                                                        BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    var frame = decoder.Frames[0];
                    frame.Freeze();
                    return(new ImageData(frame, info));
                }
        }
Exemplo n.º 3
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var actarc = arc as ActressArchive;

            if (null == actarc || null == actarc.Key)
            {
                return(base.OpenEntry(arc, entry));
            }
            var    header = ReadEntryHeader(actarc, entry);
            Stream input;

            if (entry.Size <= 0x20)
            {
                input = new BinMemoryStream(header, entry.Name);
            }
            else
            {
                input = new PrefixStream(header, arc.File.CreateStream(entry.Offset + 0x20, entry.Size - 0x20));
            }
            if (header.AsciiEqual("BM"))
            {
                return(input);
            }
            input.Position = 4;
            return(new LzssStream(input));
        }
Exemplo n.º 4
0
        internal IBinaryStream OpenFg(IBinaryStream fg)
        {
            var fge_name = Path.ChangeExtension(fg.Name, ".fge");

            using (var fge = VFS.OpenView(fge_name))
            {
                if (fge.MaxOffset != 0x818)
                {
                    throw new InvalidFormatException();
                }
                int  chunk1_size   = fge.View.ReadInt32(0);
                int  chunk2_offset = fge.View.ReadInt32(0x404);
                int  chunk2_size   = fge.View.ReadInt32(0x408);
                bool is_compressed = fge.View.ReadInt32(0x810) != 0;
                int  part1_size    = chunk2_offset + chunk2_size;
                var  part1         = new byte[part1_size];
                fge.View.Read(4, part1, 0, (uint)chunk1_size);
                fg.Position = 5;
                fg.Read(part1, chunk1_size, chunk2_offset - chunk1_size);
                fge.View.Read(0x40C, part1, chunk2_offset, (uint)chunk2_size);
                var    part2     = new StreamRegion(fg.AsStream, fg.Position, true);
                Stream fg_stream = new PrefixStream(part1, part2);
                if (is_compressed)
                {
                    fg_stream = new ZLibStream(fg_stream, CompressionMode.Decompress);
                    fg_stream = new SeekableStream(fg_stream);
                }
                return(new BinaryStream(fg_stream, fg.Name));
            }
        }
Exemplo n.º 5
0
        public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
        {
            if (!entry.Name.HasExtension(".tga"))
            {
                return(base.OpenImage(arc, entry));
            }
            var input = arc.OpenBinaryEntry(entry);

            try
            {
                var header = input.ReadHeader(18);
                if (0 == header[16])
                {
                    header[16] = 32;
                }
                if (0 == header[17] && 32 == header[16])
                {
                    header[17] = 8;
                }
                Stream tga_input = new StreamRegion(input.AsStream, 18);
                tga_input = new PrefixStream(header.ToArray(), tga_input);
                var tga  = new BinaryStream(tga_input, entry.Name);
                var info = ImageFormat.Tga.ReadMetaData(tga);
                if (info != null)
                {
                    tga.Position = 0;
                    return(new ImageFormatDecoder(tga, ImageFormat.Tga, info));
                }
            }
            catch { /* ignore errors */ }
            input.Position = 0;
            return(ImageFormatDecoder.Create(input));
        }
Exemplo n.º 6
0
        public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
        {
            var header = arc.File.View.ReadBytes(entry.Offset, 2);

            if (header[0] != 0 || header[1] != 0)
            {
                return(base.OpenImage(arc, entry));
            }
            header[0] = (byte)'B';
            header[1] = (byte)'M';
            Stream input = arc.File.CreateStream(entry.Offset + 2, entry.Size - 2);

            try
            {
                input = new PrefixStream(header, input);
                var bmp  = new BinaryStream(input, entry.Name);
                var info = ImageFormat.Bmp.ReadMetaData(bmp);
                if (null == info)
                {
                    throw new InvalidFormatException();
                }
                bmp.Position = 0;
                return(new ImageFormatDecoder(bmp, ImageFormat.Bmp, info));
            }
            catch
            {
                input.Dispose();
                throw;
            }
        }
Exemplo n.º 7
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            uint key    = entry.Size / 8 + 0x22;
            var  header = new byte[Math.Min(4, entry.Size)];

            arc.File.View.Read(entry.Offset, header, 0, (uint)header.Length);
            for (int i = 0; i < header.Length; ++i)
            {
                header[i] ^= (byte)key;
                key      <<= 3;
            }
            var pent = entry as PackedEntry;

            if (null != pent && !pent.IsPacked && entry.Size >= 8)
            {
                pent.IsPacked     = true;
                pent.UnpackedSize = arc.File.View.ReadUInt32(entry.Offset + entry.Size - 4);
            }
            Stream input;

            if (header.Length == entry.Size)
            {
                input = new MemoryStream(header);
            }
            else
            {
                input = arc.File.CreateStream(entry.Offset + 4, entry.Size - 8);
                input = new PrefixStream(header, input);
            }
            return(new ZLibStream(input, CompressionMode.Decompress));
        }
Exemplo n.º 8
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var header = arc.File.View.ReadBytes(entry.Offset, 25);

            if (header[0] < 'B' || header[0] > 'E' || header[1] != '1')
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            if ('E' == header[0])
            {
                byte t = header[17];
                header[17] = header[23];
                header[23] = t;
                t          = header[19];
                header[19] = header[24];
                header[24] = t;
            }
            int    unpacked_size = header.ToInt32(6);
            var    data          = new byte[unpacked_size];
            Stream input         = arc.File.CreateStream(entry.Offset + header.Length, entry.Size - (uint)header.Length);

            input          = new PrefixStream(header, input);
            input.Position = 10;
            using (input = new LzssStream(input))
                input.Read(data, 0, unpacked_size);
            if (data.AsciiEqual("BPR01"))
            {
                return(new PackedStream <BprDecompressor> (Stream.Null, new BprDecompressor(data)));
            }
            else
            {
                return(new BinMemoryStream(data, entry.Name));
            }
        }
Exemplo n.º 9
0
        }                                                               // 'PAD'

        public override SoundInput TryOpen(IBinaryStream file)
        {
            var wav_header = file.ReadHeader(0x2c).ToArray();
            int pcm_size   = LittleEndian.ToInt32(wav_header, 0x28);
            int channels   = LittleEndian.ToUInt16(wav_header, 0x16);

            wav_header[0] = (byte)'R';
            wav_header[1] = (byte)'I';
            wav_header[2] = (byte)'F';
            wav_header[3] = (byte)'F';
            LittleEndian.Pack(pcm_size + 0x24, wav_header, 4);

            var decoder = new PadDecoder(file.AsStream, pcm_size, channels);

            decoder.Unpack();
            var data = new MemoryStream(decoder.Data, 0, pcm_size);
            var wav  = new PrefixStream(wav_header, data);

            try
            {
                return(new WaveInput(wav));
            }
            catch
            {
                wav.Dispose();
                throw;
            }
        }
Exemplo n.º 10
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as YkgMetaData;

            if (null == meta)
            {
                throw new ArgumentException("YkgFormat.Read should be supplied with YkgMetaData", "info");
            }

            switch (meta.Format)
            {
            case YkgImage.Bmp:
                using (var bmp = new StreamRegion(stream, meta.DataOffset, meta.DataSize, true))
                    return(Bmp.Read(bmp, info));

            case YkgImage.Png:
                using (var png = new StreamRegion(stream, meta.DataOffset, meta.DataSize, true))
                    return(Png.Read(png, info));

            case YkgImage.Gnp:
                using (var body = new StreamRegion(stream, meta.DataOffset + 4, meta.DataSize - 4, true))
                    using (var png = new PrefixStream(PngPrefix, body))
                        return(Png.Read(png, info));

            default:
                throw new InvalidFormatException();
            }
        }
Exemplo n.º 11
0
 public override ImageData Read(Stream stream, ImageMetaData info)
 {
     var header = PngHeader.Clone() as byte[];
     using (var data = new StreamRegion (stream, 8, stream.Length - 8, true))
     using (var png = new PrefixStream (header, data))
         return base.Read (png, info);
 }
Exemplo n.º 12
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var rent = entry as RepiEntry;

            if (null == rent || !rent.HasEncryptionKey)
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            var  key        = rent.CreateKey();
            uint enc_length = Math.Min((uint)key.Length, entry.Size);

            byte[] encrypted = arc.File.View.ReadBytes(entry.Offset, enc_length);
            DecryptEntry(encrypted, key);
            Stream input;

            if (enc_length == entry.Size)
            {
                input = new BinMemoryStream(encrypted, entry.Name);
            }
            else
            {
                input = arc.File.CreateStream(entry.Offset + enc_length, entry.Size - enc_length);
                input = new PrefixStream(encrypted, input);
            }
            if (rent.IsPacked)
            {
                input = new LzssStream(input);
            }
            return(input);
        }
Exemplo n.º 13
0
        IBinaryStream DeobfuscateStream(IBinaryStream file)
        {
            var body = new StreamRegion(file.AsStream, 8, file.Length - 8, true);
            var png  = new PrefixStream(HeaderBytes, body);

            return(new BinaryStream(png, file.Name));
        }
Exemplo n.º 14
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (YkgMetaData)info;

            switch (meta.Format)
            {
            case YkgImage.Bmp:
                using (var reg = new StreamRegion(stream.AsStream, meta.DataOffset, meta.DataSize, true))
                    using (var bmp = new BinaryStream(reg, stream.Name))
                        return(Bmp.Read(bmp, info));

            case YkgImage.Png:
                using (var reg = new StreamRegion(stream.AsStream, meta.DataOffset, meta.DataSize, true))
                    using (var png = new BinaryStream(reg, stream.Name))
                        return(Png.Read(png, info));

            case YkgImage.Gnp:
                using (var body = new StreamRegion(stream.AsStream, meta.DataOffset + 4, meta.DataSize - 4, true))
                    using (var pre = new PrefixStream(PngPrefix, body))
                        using (var png = new BinaryStream(pre, stream.Name))
                            return(Png.Read(png, info));

            default:
                throw new InvalidFormatException();
            }
        }
Exemplo n.º 15
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var header = PngHeader.Clone() as byte[];

            using (var data = new StreamRegion(stream, 8, stream.Length - 8, true))
                using (var png = new PrefixStream(header, data))
                    return(base.Read(png, info));
        }
Exemplo n.º 16
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var header = HeaderBytes.Clone() as byte[];

            using (var data = new StreamRegion(stream.AsStream, 8, true))
                using (var pre = new PrefixStream(header, data))
                    using (var png = new BinaryStream(pre, stream.Name))
                        return(base.Read(png, info));
        }
Exemplo n.º 17
0
        IBinaryStream OpenAsBitmap(IBinaryStream input)
        {
            var header = new byte[2] {
                (byte)'B', (byte)'M'
            };
            Stream stream = new StreamRegion(input.AsStream, 2, true);

            stream = new PrefixStream(header, stream);
            return(new BinaryStream(stream, input.Name));
        }
Exemplo n.º 18
0
        IBinaryStream DeobfuscateStream(IBinaryStream file)
        {
            var header = file.ReadHeader(4).ToArray();

            header[0] = 0x89;
            var body = new StreamRegion(file.AsStream, 4, true);
            var png  = new PrefixStream(header, body);

            return(new BinaryStream(png, file.Name));
        }
Exemplo n.º 19
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            ushort signature = arc.File.View.ReadUInt16(entry.Offset);

            // C1/D1/E1/F1
            if (0x3146 != signature && 0x3143 != signature && 0x3144 != signature && 0x3145 != signature)
            {
                return(base.OpenEntry(arc, entry));
            }
            var            mkarc  = arc as MkArchive;
            ScrambleScheme scheme = mkarc != null ? mkarc.Scheme : DefaultScheme;

            uint packed_size = arc.File.View.ReadUInt32(entry.Offset + 2);

            if (packed_size < scheme.ScrambledSize || packed_size > entry.Size - 10)
            {
                return(base.OpenEntry(arc, entry));
            }

            Stream input;

            // XXX scrambling might be applicable for 'E1' signatures only
            if (scheme.ScrambledSize > 0)
            {
                var prefix = arc.File.View.ReadBytes(entry.Offset + 10, scheme.ScrambledSize);
                foreach (var pair in scheme.ScrambleMap)
                {
                    byte t = prefix[pair.Item1];
                    prefix[pair.Item1] = prefix[pair.Item2];
                    prefix[pair.Item2] = t;
                }
                input = arc.File.CreateStream(entry.Offset + 10 + scheme.ScrambledSize, packed_size - scheme.ScrambledSize);
                input = new PrefixStream(prefix, input);
            }
            else
            {
                input = arc.File.CreateStream(entry.Offset + 10, packed_size);
            }
            input = new LzssStream(input);

            var header = new byte[5];

            input.Read(header, 0, 5);
            if (Binary.AsciiEqual(header, "BPR02"))
            {
                return(new PackedStream <Bpr02Decompressor> (input));
            }
            if (Binary.AsciiEqual(header, "BPR01"))
            {
                return(new PackedStream <Bpr01Decompressor> (input));
            }
            return(new PrefixStream(header, input));
        }
Exemplo n.º 20
0
        IBinaryStream OpenAsBitmap(IBinaryStream input)
        {
            var header = new byte[HeaderSize];

            header[0] = (byte)'B';
            header[1] = (byte)'M';
            LittleEndian.Pack((uint)input.Length, header, 2);
            Stream stream = new StreamRegion(input.AsStream, HeaderSize, true);

            stream = new PrefixStream(header, stream);
            return(new BinaryStream(stream, input.Name));
        }
Exemplo n.º 21
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var header = new byte[Math.Min(0xE1F, file.Length)];

            if (0x10 != file.Read(header, 0, 0x10))
            {
                return(null);
            }
            var signature = LittleEndian.ToUInt32(header, 0);

            byte[] key;
            if (!KnownKeys.TryGetValue(signature, out key))
            {
                signature = LittleEndian.ToUInt32(header, 0xC);
                if (!KnownKeys.TryGetValue(signature, out key))
                {
                    return(null);
                }
                file.Read(header, 4, 0xC);
            }
            header[0] = (byte)'O';
            header[1] = (byte)'g';
            header[2] = (byte)'g';
            header[3] = (byte)'S';
            file.Read(header, 0x10, header.Length - 0x10);
            int k = 0;

            for (int i = 4; i < header.Length; ++i)
            {
                header[i] ^= key[k++];
                if (k >= key.Length)
                {
                    k = 1;
                }
            }
            Stream input;

            if (header.Length >= file.Length)
            {
                input = new MemoryStream(header);
            }
            else
            {
                input = new PrefixStream(header, new StreamRegion(file.AsStream, file.Position));
            }
            var sound = new OggInput(input);

            if (header.Length >= file.Length)
            {
                file.Dispose();
            }
            return(sound);
        }
Exemplo n.º 22
0
        internal IBinaryStream DeobfuscateStream(IBinaryStream file)
        {
            var header = file.ReadHeader(0x20).ToArray();

            for (int i = 0; i < 0x20; ++i)
            {
                header[i] ^= 0xFF;
            }
            Stream stream = new StreamRegion(file.AsStream, 0x20, true);

            stream = new PrefixStream(header, stream);
            return(new BinaryStream(stream, file.Name));
        }
Exemplo n.º 23
0
        public static IBinaryStream DecryptStream(IBinaryStream input, byte[] key, bool leave_open = false)
        {
            input.Position = 0x10;
            var header = input.ReadBytes(key.Length);

            for (int i = 0; i < key.Length; ++i)
            {
                header[i] ^= key[i];
            }
            var result = new PrefixStream(header, new StreamRegion(input.AsStream, input.Position, leave_open));

            return(new BinaryStream(result, input.Name));
        }
Exemplo n.º 24
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var    gent  = (GpkEntry)entry;
            Stream input = arc.File.CreateStream(entry.Offset, entry.Size);

            if (gent.Header != null)
            {
                input = new PrefixStream(gent.Header, input);
            }
            if (gent.IsPacked)
            {
                input = new ZLibStream(input, CompressionMode.Decompress);
            }
            return(input);
        }
Exemplo n.º 25
0
        IBinaryStream DeobfuscateStream(IBinaryStream stream)
        {
            var png_header = new byte[0x10];

            stream.Read(png_header, 5, 11);
            System.Buffer.BlockCopy(PngHeader, 0, png_header, 0, 8);
            for (int i = 0; i < 8; ++i)
            {
                png_header[i + 8] ^= (byte)"PGAECODE"[i];
            }
            var png_body = new StreamRegion(stream.AsStream, 11, true);
            var pre      = new PrefixStream(png_header, png_body);

            return(new BinaryStream(pre, stream.Name));
        }
Exemplo n.º 26
0
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            var header = stream.ReadHeader(8).ToArray();

            if (!Binary.AsciiEqual(header, "MalieGF"))
            {
                return(null);
            }
            Buffer.BlockCopy(HeaderBytes, 0, header, 0, 8);

            using (var data = new StreamRegion(stream.AsStream, 8, true))
                using (var pre = new PrefixStream(header, data))
                    using (var png = new BinaryStream(pre, stream.Name))
                        return(base.ReadMetaData(png));
        }
Exemplo n.º 27
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var header = file.ReadHeader(0x12);

            if (!header.AsciiEqual("\0\0\0\0"))
            {
                return(null);
            }
            int riff_length = header.ToInt32(4);

            if (file.Length != riff_length + 8)
            {
                return(null);
            }
            if (!header.AsciiEqual(8, "\0\0\0\0\0\0\0\0"))
            {
                return(null);
            }
            int header_length = header.ToUInt16(0x10);

            if (header_length < 0x10 || header_length > riff_length)
            {
                return(null);
            }
            header = file.ReadHeader(0x18 + header_length);
            if (!header.AsciiEqual(0x14 + header_length, "data"))
            {
                return(null);
            }
            var header_bytes = new byte[0x10] {
                (byte)'R', (byte)'I', (byte)'F', (byte)'F', header[4], header[5], header[6], header[7],
                (byte)'W', (byte)'A', (byte)'V', (byte)'E', (byte)'f', (byte)'m', (byte)'t', (byte)' '
            };
            Stream riff = new StreamRegion(file.AsStream, 0x10);

            riff = new PrefixStream(header_bytes, riff);
            var wav = new BinaryStream(riff, file.Name);

            try
            {
                return(Wav.TryOpen(wav));
            }
            catch
            {
                wav.Dispose();
                throw;
            }
        }
Exemplo n.º 28
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var header = file.ReadHeader(100).ToArray();

            for (int i = 0; i < header.Length; ++i)
            {
                header[i] ^= 0xFF;
            }
            using (var rest = new StreamRegion(file.AsStream, 100, true))
                using (var input = new PrefixStream(header, rest))
                {
                    var decoder = new BmpBitmapDecoder(input, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    var frame   = decoder.Frames[0];
                    frame.Freeze();
                    return(new ImageData(frame, info));
                }
        }
Exemplo n.º 29
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            var header = new byte[8];

            if (8 != stream.Read(header, 0, 8))
            {
                return(null);
            }
            if (!Binary.AsciiEqual(header, "MalieGF"))
            {
                return(null);
            }
            Buffer.BlockCopy(PngHeader, 0, header, 0, 8);

            using (var data = new StreamRegion(stream, 8, stream.Length - 8, true))
                using (var png = new PrefixStream(header, data))
                    return(base.ReadMetaData(png));
        }
Exemplo n.º 30
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            ushort signature = arc.File.View.ReadUInt16(entry.Offset);

            // C1/D1/E1/F1
            if (0x3146 != signature && 0x3143 != signature && 0x3144 != signature && 0x3145 != signature)
            {
                return(base.OpenEntry(arc, entry));
            }
            uint packed_size = arc.File.View.ReadUInt32(entry.Offset + 2);

            if (packed_size < 14 || packed_size > entry.Size - 10)
            {
                return(base.OpenEntry(arc, entry));
            }

            // XXX scrambling might be applicable for 'E1' signatures only
            var  prefix = arc.File.View.ReadBytes(entry.Offset + 10, 14);
            byte t      = prefix[7];

            prefix[7]  = prefix[11];
            prefix[11] = t;
            t          = prefix[9];
            prefix[9]  = prefix[12];
            prefix[12] = t;

            Stream input = arc.File.CreateStream(entry.Offset + 24, packed_size - 14);

            input = new PrefixStream(prefix, input);
            input = new LzssStream(input);

            var header = new byte[5];

            input.Read(header, 0, 5);
            if (Binary.AsciiEqual(header, "BPR02"))
            {
                return(new PackedStream <Bpr02Decompressor> (input));
            }
            if (Binary.AsciiEqual(header, "BPR01"))
            {
                return(new PackedStream <Bpr01Decompressor> (input));
            }
            return(new PrefixStream(header, input));
        }
Exemplo n.º 31
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var header = file.ReadHeader(0x38);
            var format = new WaveFormat {
                FormatTag             = 2,
                Channels              = header.ToUInt16(6),
                SamplesPerSecond      = header.ToUInt32(8),
                AverageBytesPerSecond = header.ToUInt32(0xC),
                BlockAlign            = header.ToUInt16(0x10),
                BitsPerSample         = header.ToUInt16(0x12),
                ExtraSize             = 0x20,
            };
            var codec_data   = header.Skip(0x14).Take(format.ExtraSize).ToArray();
            int adpcm_length = header.ToInt32(0x34);

            byte[] wav_header;
            using (var wav = new MemoryStream())
                using (var buffer = new BinaryWriter(wav, Encoding.ASCII, true))
                {
                    buffer.Write(Wav.Signature);
                    buffer.Write(adpcm_length + 0x46);
                    buffer.Write(0x45564157); // 'WAVE'
                    buffer.Write(0x20746d66); // 'fmt '
                    buffer.Write(0x32);
                    buffer.Write(format.FormatTag);
                    buffer.Write(format.Channels);
                    buffer.Write(format.SamplesPerSecond);
                    buffer.Write(format.AverageBytesPerSecond);
                    buffer.Write(format.BlockAlign);
                    buffer.Write(format.BitsPerSample);
                    buffer.Write(format.ExtraSize);
                    buffer.Write(codec_data);
                    buffer.Write(0x61746164); // 'data'
                    buffer.Write(adpcm_length);
                    buffer.Flush();
                    wav_header = wav.ToArray();
                }
            Stream input = new StreamRegion(file.AsStream, file.Position);

            input = new PrefixStream(wav_header, input);
            return(new WaveInput(input));
        }
Exemplo n.º 32
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as YkgMetaData;
            if (null == meta)
                throw new ArgumentException ("YkgFormat.Read should be supplied with YkgMetaData", "info");

            switch (meta.Format)
            {
            case YkgImage.Bmp:
                using (var bmp = new StreamRegion (stream, meta.DataOffset, meta.DataSize, true))
                    return Bmp.Read (bmp, info);
            case YkgImage.Png:
                using (var png = new StreamRegion (stream, meta.DataOffset, meta.DataSize, true))
                    return Png.Read (png, info);
            case YkgImage.Gnp:
                using (var body = new StreamRegion (stream, meta.DataOffset+4, meta.DataSize-4, true))
                using (var png = new PrefixStream (PngPrefix, body))
                    return Png.Read (png, info);
            default:
                throw new InvalidFormatException();
            }
        }
Exemplo n.º 33
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            var header = new byte[8];
            if (8 != stream.Read (header, 0, 8))
                return null;
            if (!Binary.AsciiEqual (header, "MalieGF"))
                return null;
            Buffer.BlockCopy (PngHeader, 0, header, 0, 8);

            using (var data = new StreamRegion (stream, 8, stream.Length - 8, true))
            using (var png = new PrefixStream (header, data))
                return base.ReadMetaData (png);
        }
Exemplo n.º 34
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     var header = new byte[0x40];
     if (header.Length != stream.Read (header, 0, header.Length))
         return null;
     if (!Binary.AsciiEqual (header, 4, "00\0\0"))
         return null;
     var ykg = new YkgMetaData {
         DataOffset = LittleEndian.ToUInt32 (header, 0x28),
         DataSize   = LittleEndian.ToUInt32 (header, 0x2C)
     };
     if (0 == ykg.DataOffset)
         ykg.DataOffset = LittleEndian.ToUInt32 (header, 8);
     if (ykg.DataOffset < 0x30)
         return null;
     if (0 == ykg.DataSize)
         ykg.DataSize = (uint)(stream.Length - ykg.DataOffset);
     ImageMetaData info = null;
     using (var img = new StreamRegion (stream, ykg.DataOffset, ykg.DataSize, true))
     {
         if (4 != img.Read (header, 0, 4))
             return null;
         if (Binary.AsciiEqual (header, "BM"))
         {
             img.Position = 0;
             info = ImageFormat.Bmp.ReadMetaData (img);
             ykg.Format = YkgImage.Bmp;
         }
         else if (Binary.AsciiEqual (header, "\x89PNG"))
         {
             img.Position = 0;
             info = Png.ReadMetaData (img);
             ykg.Format = YkgImage.Png;
         }
         else if (Binary.AsciiEqual (header, "\x89GNP"))
         {
             using (var body = new StreamRegion (stream, ykg.DataOffset+4, ykg.DataSize-4, true))
             using (var png = new PrefixStream (PngPrefix, body))
                 info = Png.ReadMetaData (png);
             ykg.Format = YkgImage.Gnp;
         }
     }
     if (null == info)
         return null;
     ykg.Width = info.Width;
     ykg.Height = info.Height;
     ykg.BPP = info.BPP;
     ykg.OffsetX = info.OffsetX;
     ykg.OffsetY = info.OffsetY;
     return ykg;
 }