예제 #1
0
        }                                                                 // 'S25'

        // in current implementation, only the first frame is returned.
        // per-frame access is provided by S25Opener class.

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new ArcView.Reader(stream))
            {
                input.ReadUInt32();
                int count = input.ReadInt32();
                if (count < 0 || count > 0xfffff)
                {
                    return(null);
                }
                uint first_offset = input.ReadUInt32();
                if (0 == first_offset)
                {
                    return(null);
                }
                input.BaseStream.Position = first_offset;
                var info = new S25MetaData();
                info.Width       = input.ReadUInt32();
                info.Height      = input.ReadUInt32();
                info.OffsetX     = input.ReadInt32();
                info.OffsetY     = input.ReadInt32();
                info.FirstOffset = first_offset + 0x14;
                info.Incremental = 0 != (input.ReadUInt32() & 0x80000000u);
                info.BPP         = 32;
                return(info);
            }
        }
예제 #2
0
        }                                                                 // 'NGP '

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Position = 0x12;
            using (var reader = new ArcView.Reader(stream))
            {
                int  packed_size = reader.ReadInt32();
                uint width       = reader.ReadUInt32();
                uint height      = reader.ReadUInt32();
                int  bpp         = reader.ReadUInt16() * 8;
                reader.BaseStream.Position = 0x100;
                int unpacked_size = reader.ReadInt32();
                if (packed_size <= 0 || unpacked_size <= 0)
                {
                    return(null);
                }
                return(new NgpMetaData
                {
                    Width = width,
                    Height = height,
                    BPP = bpp,
                    PackedSize = packed_size,
                    UnpackedSize = unpacked_size,
                });
            }
        }
예제 #3
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 4;
     using (var reader = new ArcView.Reader(stream))
     {
         int version = reader.ReadInt16();
         if (version != 1)
         {
             return(null);
         }
         int unpacked_size = reader.ReadInt32();
         int data_offset   = reader.ReadInt32();
         if (unpacked_size < 0x36 || data_offset < stream.Position)
         {
             return(null);
         }
         var header = new byte[0x20];
         stream.Position = data_offset;
         Unpack(stream, header);
         if ('B' != header[0] || 'M' != header[1])
         {
             return(null);
         }
         return(new ZbmMetaData
         {
             Width = LittleEndian.ToUInt32(header, 0x12),
             Height = LittleEndian.ToUInt32(header, 0x16),
             BPP = LittleEndian.ToInt16(header, 0x1C),
             UnpackedSize = unpacked_size,
             DataOffset = data_offset,
         });
     }
 }
예제 #4
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var file = new ArcView.Reader(stream))
     {
         stream.Seek(3, SeekOrigin.Current);
         byte id        = file.ReadByte();
         uint data_size = file.ReadUInt32();
         uint width     = file.ReadUInt32();
         uint height    = file.ReadUInt32();
         uint stride    = file.ReadUInt32();
         if (stride < width)
         {
             throw new NotSupportedException();
         }
         if (stride * height != data_size)
         {
             return(null);
         }
         return(new MfgMetaData
         {
             Width = width,
             Height = height,
             BPP = (int)(stride * 8 / width),
             Type = id,
             Stride = (int)stride,
         });
     }
 }
예제 #5
0
        }                                                                 // 'CWDP'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new ArcView.Reader(stream))
            {
                input.ReadInt32();
                uint width  = Binary.BigEndian(input.ReadUInt32());
                uint height = Binary.BigEndian(input.ReadUInt32());
                if (0 == width || 0 == height)
                {
                    return(null);
                }
                int bpp        = input.ReadByte();
                int color_type = input.ReadByte();
                switch (color_type)
                {
                case 2: bpp *= 3; break;

                case 4: bpp *= 2; break;

                case 6: bpp *= 4; break;

                case 3:
                case 0: break;

                default: return(null);
                }
                return(new ImageMetaData
                {
                    Width = width,
                    Height = height,
                    BPP = bpp,
                });
            }
        }
예제 #6
0
        }                                                                 // 'hiz'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new ArcView.Reader(stream))  // sub_4BF900
            {
                input.ReadInt32();
                int n = input.ReadInt32();
                if (100 != n)
                {
                    return(null);
                }
                uint right    = input.ReadUInt32() ^ 0xAA5A5A5A;
                uint bottom   = input.ReadUInt32() ^ 0xAC9326AF;
                int  unknown1 = input.ReadInt32(); // @0x10
                if (unknown1 == 0x375A8436)
                {
                    return(null);
                }
                uint unpacked_size = input.ReadUInt32() ^ 0x19739D6A; // @0x14
                if (unpacked_size != right * bottom * 4)
                {
                    return(null);
                }
                return(new HizMetaData
                {
                    Width = right,
                    Height = bottom,
                    BPP = 32,
                    IsPacked = true,
                    DataOffset = 0x4c,
                    UnpackedSize = unpacked_size,
                });
            }
        }
예제 #7
0
        }                                                                 // 'HG-2'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Position = 8;
            using (var header = new ArcView.Reader(stream))
            {
                var info = new Hg2MetaData();
                int type = header.ReadInt32();
                if (0x25 == type)
                {
                    info.HeaderSize = 0x58;
                }
                else if (0x20 == type)
                {
                    info.HeaderSize = 0x50;
                }
                else
                {
                    return(null);
                }
                info.Width  = header.ReadUInt32();
                info.Height = header.ReadUInt32();
                info.BPP    = header.ReadInt32();
                header.BaseStream.Seek(8, SeekOrigin.Current);
                info.DataPacked   = header.ReadInt32();
                info.DataUnpacked = header.ReadInt32();
                info.CtlPacked    = header.ReadInt32();
                info.CtlUnpacked  = header.ReadInt32();
                header.BaseStream.Seek(8, SeekOrigin.Current);
                info.CanvasWidth  = header.ReadUInt32();
                info.CanvasHeight = header.ReadUInt32();
                info.OffsetX      = header.ReadInt32();
                info.OffsetY      = header.ReadInt32();
                return(info);
            }
        }
예제 #8
0
 bool ReadFromStream(Stream input, int name_length)
 {
     m_dir.Clear();
     using (var index = new ArcView.Reader(input))
     {
         for (int i = 0; i < m_count; ++i)
         {
             if (name_length != index.Read(m_name_buffer, 0, name_length))
             {
                 return(false);
             }
             var name = Binary.GetCString(m_name_buffer, 0, name_length);
             if (string.IsNullOrWhiteSpace(name))
             {
                 return(false);
             }
             var entry = FormatCatalog.Instance.Create <PackedEntry> (name);
             entry.Offset       = index.ReadUInt32();
             entry.UnpackedSize = index.ReadUInt32();
             entry.Size         = index.ReadUInt32();
             if (!entry.CheckPlacement(m_file.MaxOffset))
             {
                 return(false);
             }
             entry.IsPacked = m_pack_type != 0 && (m_pack_type != 4 || entry.Size != entry.UnpackedSize);
             m_dir.Add(entry);
         }
         return(true);
     }
 }
예제 #9
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var header = new ArcView.Reader(stream))
            {
                var info = new EpaMetaData();
                info.Mode      = header.ReadInt32() >> 24;
                info.ColorType = header.ReadInt32() & 0xff;
                switch (info.ColorType)
                {
                case 0: info.BPP = 8; break;

                case 1: info.BPP = 24; break;

                case 2: info.BPP = 32; break;

                case 3: info.BPP = 15; break;

                case 4: info.BPP = 8; break;

                default: return(null);
                }
                info.Width  = header.ReadUInt32();
                info.Height = header.ReadUInt32();
                if (2 == info.Mode)
                {
                    info.OffsetX = header.ReadInt32();
                    info.OffsetY = header.ReadInt32();
                }
                return(info);
            }
        }
예제 #10
0
        HuffmanNode[] CreateHuffmanTree(Stream input)
        {
            var nodes = new HuffmanNode[0x200];
            var tree  = new List <int> (0x100);

            using (var reader = new ArcView.Reader(input))
            {
                m_huffman_unpacked = reader.ReadInt32();
                reader.ReadInt32(); // packed_size

                for (int i = 0; i < 0x100; i++)
                {
                    nodes[i].Freq = reader.ReadUInt32();
                    AddNode(tree, nodes, i);
                }
            }
            int last_node = 0x100;

            while (tree.Count > 1)
            {
                int l = tree[0];
                tree.RemoveAt(0);
                int r = tree[0];
                tree.RemoveAt(0);
                nodes[last_node].Freq  = nodes[l].Freq + nodes[r].Freq;
                nodes[last_node].Left  = l;
                nodes[last_node].Right = r;
                AddNode(tree, nodes, last_node++);
            }
            return(nodes);
        }
예제 #11
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Seek(5, SeekOrigin.Current);
            int bpp = stream.ReadByte();

            if (24 != bpp && 32 != bpp)
            {
                throw new NotSupportedException("Not supported CPB image format");
            }
            using (var input = new ArcView.Reader(stream))
            {
                int version = input.ReadInt16();
                if (1 != version)
                {
                    throw new NotSupportedException("Not supported CPB image version");
                }
                var info = new CpbMetaData();
                info.BPP = bpp;
                input.ReadUInt32();
                info.Width      = input.ReadUInt16();
                info.Height     = input.ReadUInt16();
                info.Channel[0] = input.ReadUInt32(); // Alpha
                info.Channel[1] = input.ReadUInt32();
                info.Channel[2] = input.ReadUInt32();
                info.Channel[3] = input.ReadUInt32();
                return(info);
            }
        }
예제 #12
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         int width  = input.ReadInt16();
         int height = input.ReadInt16();
         if (width <= 0 || height <= 0)
         {
             return(null);
         }
         int bpp = input.ReadInt32();
         if (24 != bpp && 32 != bpp && 8 != bpp)
         {
             return(null);
         }
         if (0 != input.ReadInt64())
         {
             return(null);
         }
         return(new ImageMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = bpp,
         });
     }
 }
예제 #13
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         var info = new PicMetaData();
         input.ReadUInt32();
         info.PackedSize   = input.ReadUInt32();
         info.UnpackedSize = input.ReadUInt32();
         info.HeaderSize   = input.ReadUInt32();
         if (info.HeaderSize >= stream.Length || info.PackedSize + info.HeaderSize > stream.Length)
         {
             return(null);
         }
         input.ReadUInt32();
         info.Width  = input.ReadUInt32();
         info.Height = input.ReadUInt32();
         info.BPP    = input.ReadInt32();
         if (info.HeaderSize >= 0x2C)
         {
             input.ReadInt32();
             info.OffsetX = input.ReadInt32();
             info.OffsetY = input.ReadInt32();
         }
         return(info);
     }
 }
예제 #14
0
파일: ImageMFG.cs 프로젝트: Casidi/GARbro
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as MfgMetaData;
            if (null == meta)
                throw new ArgumentException ("MfgFormat.Read should be supplied with MfgMetaData", "info");

            stream.Position = 0x14;
            if ('_' != meta.Type)
                using (var file = new ArcView.Reader (stream))
                {
                    for (uint i = 0; i < meta.Height; ++i)
                    {
                        uint n = file.ReadUInt32();
                        file.BaseStream.Seek (n*8, SeekOrigin.Current);
                    }
                }
            byte[] pixels = new byte[meta.Stride*info.Height];
            if (pixels.Length != stream.Read (pixels, 0, pixels.Length))
                throw new InvalidFormatException ("Unexpected end of file");
            PixelFormat format;
            if (24 == meta.BPP)
                format = PixelFormats.Bgr24;
            else
                format = PixelFormats.Bgra32;
            return ImageData.Create (info, format, null, pixels, meta.Stride);
        }
예제 #15
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var input = arc.File.CreateStream(entry.Offset, entry.Size);

            if (entry.Size <= 8)
            {
                return(input);
            }
            if (!entry.Name.EndsWith(".so4", StringComparison.InvariantCultureIgnoreCase) &&
                !entry.Name.EndsWith(".so5", StringComparison.InvariantCultureIgnoreCase))
            {
                return(input);
            }
            using (var header = new ArcView.Reader(input))
            {
                int packed   = header.ReadInt32();
                int unpacked = header.ReadInt32();
                if (packed + 8 != entry.Size || packed <= 0 || unpacked <= 0)
                {
                    return(input);
                }
                using (input)
                    using (var reader = new LzssReader(input, packed, unpacked))
                    {
                        reader.Unpack();
                        return(new MemoryStream(reader.Data));
                    }
            }
        }
예제 #16
0
        }                                                               // 'YGP'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Position = 4;
            using (var reader = new ArcView.Reader(stream))
            {
                int  mask_pos = reader.ReadUInt16();        // 04
                byte type     = reader.ReadByte();          // 06
                if (type != 1 && type != 2)
                {
                    return(null);
                }
                var info = new YgpMetaData {
                    Type = type, BPP = 32
                };
                info.Flags = reader.ReadByte();             // 07
                int header_size = reader.ReadInt32();       // 08
                stream.Position = header_size;
                info.DataSize   = reader.ReadInt32();       // XX+00
                info.Width      = reader.ReadUInt16();      // XX+04
                info.Height     = reader.ReadUInt16();      // XX+06
                info.DataOffset = header_size + 8;
                if (0 != (info.Flags & 4))
                {
                    stream.Position = 0x14;
                    info.OffsetX    = reader.ReadInt16();
                    info.OffsetY    = reader.ReadInt16();
                }
                return(info);
            }
        }
예제 #17
0
파일: ImageYGP.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 4;
     using (var reader = new ArcView.Reader (stream))
     {
         int mask_pos = reader.ReadUInt16();         // 04
         byte type = reader.ReadByte();              // 06
         if (type != 1 && type != 2)
             return null;
         var info = new YgpMetaData { Type = type, BPP = 32 };
         info.Flags = reader.ReadByte();             // 07
         int header_size = reader.ReadInt32();       // 08
         stream.Position = header_size;
         info.DataSize = reader.ReadInt32();         // XX+00
         info.Width = reader.ReadUInt16();           // XX+04
         info.Height = reader.ReadUInt16();          // XX+06
         info.DataOffset = header_size+8;
         if (0 != (info.Flags & 4))
         {
             stream.Position = 0x14;
             info.OffsetX = reader.ReadInt16();
             info.OffsetY = reader.ReadInt16();
         }
         return info;
     }
 }
예제 #18
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         uint size = input.ReadUInt32();
         if (size != stream.Length)
         {
             return(null);
         }
         uint width      = input.ReadUInt32();
         uint height     = input.ReadUInt32();
         int  compressed = input.ReadInt32();
         if (compressed > 1 || 0 == compressed && (width * height + 0x410) != size)
         {
             return(null);
         }
         return(new CmMetaData {
             Width = width,
             Height = height,
             BPP = 8,
             IsCompressed = 1 == compressed,
             DataOffset = 0x10,
             DataLength = size,
         });
     }
 }
예제 #19
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = (ApsMetaData)info;

            stream.Position = meta.DataOffset;
            byte[] image_data;
            if (meta.IsPacked)
            {
                using (var reader = new LzReader(stream, meta.PackedSize, meta.UnpackedSize))
                {
                    reader.Unpack();
                    image_data = reader.Data;
                }
            }
            else
            {
                using (var reader = new ArcView.Reader(stream))
                    image_data = reader.ReadBytes((int)meta.UnpackedSize);
            }
            using (var unpacked = new MemoryStream(image_data))
            {
                var ap_info = base.ReadMetaData(unpacked);
                if (null == ap_info)
                {
                    throw new InvalidFormatException();
                }
                return(base.Read(unpacked, ap_info));
            }
        }
예제 #20
0
 public Reader(Stream input, Pt1MetaData info)
 {
     m_type         = info.Type;
     m_input        = new byte[info.PackedSize + 8];
     input.Position = 0x20;
     if ((int)info.PackedSize != input.Read(m_input, 0, (int)info.PackedSize))
     {
         throw new InvalidFormatException("Unexpected end of file");
     }
     m_width  = (int)info.Width;
     m_height = (int)info.Height;
     m_output = new byte[info.UnpackedSize];
     m_stride = m_width * 3;
     if (3 == m_type)
     {
         Format = PixelFormats.Bgra32;
         using (var reader = new ArcView.Reader(input))
         {
             int packed_size = reader.ReadInt32();
             m_alpha_packed = new byte[packed_size];
             if (packed_size != input.Read(m_alpha_packed, 0, packed_size))
             {
                 throw new EndOfStreamException();
             }
         }
     }
     else
     {
         Format = PixelFormats.Bgr24;
     }
 }
예제 #21
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader(stream))
     {
         stream.Seek(4, SeekOrigin.Current);
         int offset = reader.ReadInt32();
         if (offset <= 8)
         {
             return(null);
         }
         stream.Position = offset;
         uint signature = reader.ReadUInt32();
         if (signature != base.Signature)
         {
             return(null);
         }
         stream.Seek(-4, SeekOrigin.Current);
         var info = base.ReadMetaData(stream) as GrxMetaData;
         if (null == info)
         {
             return(null);
         }
         if (info.AlphaOffset > 0)
         {
             info.AlphaOffset += offset;
         }
         return(new SgxMetaData {
             GrxOffset = offset, GrxInfo = info
         });
     }
 }
예제 #22
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         int type = input.ReadInt32();
         if (type < 0 || type > 3)
         {
             return(null);
         }
         if (-1 != input.ReadInt32())
         {
             return(null);
         }
         int  x           = input.ReadInt32();
         int  y           = input.ReadInt32();
         uint width       = input.ReadUInt32();
         uint height      = input.ReadUInt32();
         uint comp_size   = input.ReadUInt32();
         uint uncomp_size = input.ReadUInt32();
         if (uncomp_size != width * height * 3u)
         {
             return(null);
         }
         return(new Pt1MetaData {
             Width = width,
             Height = height,
             OffsetX = x,
             OffsetY = y,
             BPP = 3 == type ? 32 : 24,
             Type = type,
             PackedSize = comp_size,
             UnpackedSize = uncomp_size
         });
     }
 }
예제 #23
0
파일: ArcNSA.cs 프로젝트: uboaa/GARbro
        protected List <Entry> ReadIndex(Stream file)
        {
            long base_offset = file.Position;

            using (var input = new ArcView.Reader(file))
            {
                int count = Binary.BigEndian(input.ReadInt16());
                if (!IsSaneCount(count))
                {
                    return(null);
                }
                base_offset += Binary.BigEndian(input.ReadUInt32());
                if (base_offset >= file.Length || base_offset < 15 * count)
                {
                    return(null);
                }

                var dir = new List <Entry>();
                for (int i = 0; i < count; ++i)
                {
                    if (base_offset - file.Position < 15)
                    {
                        return(null);
                    }
                    var name = file.ReadCString();
                    if (base_offset - file.Position < 13 || 0 == name.Length)
                    {
                        return(null);
                    }

                    var  entry            = FormatCatalog.Instance.Create <NsaEntry> (name);
                    byte compression_type = input.ReadByte();
                    entry.Offset = Binary.BigEndian(input.ReadUInt32()) + base_offset;
                    entry.Size   = Binary.BigEndian(input.ReadUInt32());
                    if (!entry.CheckPlacement(file.Length))
                    {
                        return(null);
                    }
                    entry.UnpackedSize = Binary.BigEndian(input.ReadUInt32());
                    entry.IsPacked     = compression_type != 0;
                    switch (compression_type)
                    {
                    case 0:  entry.CompressionType = Compression.None; break;

                    case 1:  entry.CompressionType = Compression.SPB; break;

                    case 2:  entry.CompressionType = Compression.LZSS; break;

                    case 4:  entry.CompressionType = Compression.NBZ; break;

                    default: entry.CompressionType = Compression.Unknown; break;
                    }
                    dir.Add(entry);
                }
                return(dir);
            }
        }
예제 #24
0
파일: ArcADS.cs 프로젝트: zxc120/GARbro
 List <Entry> ReadIndex(Stream arc, byte[] key, string arc_name)
 {
     arc.Position = 8;
     using (var reader = new ArcView.Reader(arc))
     {
         int count = reader.ReadInt32();
         if (!IsSaneCount(count))
         {
             return(null);
         }
         uint base_offset = reader.ReadUInt32();
         uint index_size  = 4u * (uint)count;
         var  max_offset  = arc.Length;
         if (base_offset >= max_offset || base_offset < (0x10 + index_size))
         {
             return(null);
         }
         var index = new List <uint> (count);
         for (int i = 0; i < count; ++i)
         {
             uint offset = reader.ReadUInt32();
             if (offset != 0xffffffff)
             {
                 if (offset >= max_offset - base_offset)
                 {
                     return(null);
                 }
                 index.Add(base_offset + offset);
             }
         }
         var name_buffer = new byte[0x20];
         var dir         = new List <Entry> (index.Count);
         for (int i = 0; i < index.Count; ++i)
         {
             long offset = index[i];
             reader.BaseStream.Position = offset;
             reader.Read(name_buffer, 0, 0x20);
             string name = Binary.GetCString(name_buffer, 0, 0x20);
             Entry  entry;
             if (0 == name.Length)
             {
                 entry = new Entry {
                     Name = string.Format("{0}#{1:D5}", arc_name, i), Type = "image"
                 }
             }
             ;
             else
             {
                 entry = FormatCatalog.Instance.Create <Entry> (name);
             }
             entry.Offset = offset + 0x24;
             entry.Size   = reader.ReadUInt32();
             dir.Add(entry);
         }
         return(dir);
     }
 }
예제 #25
0
 public AgReader(Stream stream, ImageMetaData info)
 {
     m_width         = (int)info.Width;
     m_height        = (int)info.Height;
     stream.Position = 0x0c;
     using (var input = new ArcView.Reader(stream))
     {
         uint offset1 = input.ReadUInt32();
         int  size1   = input.ReadInt32();
         uint offset2 = input.ReadUInt32();
         int  size2   = input.ReadInt32();
         uint offset3 = input.ReadUInt32();
         int  size3   = input.ReadInt32();
         uint offset4 = input.ReadUInt32();
         int  size4   = input.ReadInt32();
         uint offset5 = input.ReadUInt32();
         int  size5   = input.ReadInt32();
         uint offset6 = input.ReadUInt32();
         int  size6   = input.ReadInt32();
         input.Read(m_first, 0, 3);
         if (size1 != 0)
         {
             in1 = ReadSection(stream, offset1, size1);
         }
         if (size2 != 0)
         {
             in2 = ReadSection(stream, offset2, size2);
         }
         if (size3 != 0)
         {
             in3 = ReadSection(stream, offset3, size3);
         }
         if (size4 != 0)
         {
             in4 = ReadSection(stream, offset4, size4);
         }
         if (size5 != 0)
         {
             in5 = ReadSection(stream, offset5, size5);
         }
         if (size6 != 0)
         {
             input.BaseStream.Position = offset6;
             m_alpha = new byte[m_height * m_width];
             RleDecode(input, m_alpha);
             Format       = PixelFormats.Bgra32;
             m_pixel_size = 4;
         }
         else
         {
             Format       = PixelFormats.Bgr24;
             m_pixel_size = 3;
         }
         m_output = new byte[m_width * m_height * m_pixel_size];
     }
 }
예제 #26
0
파일: ArcGPC.cs 프로젝트: tenyuhuang/GARbro
 void DetectFileTypes(ArcView file, List <Entry> dir)
 {
     using (var input = file.CreateStream())
         using (var reader = new ArcView.Reader(input))
         {
             var buffer = new byte[0x10];
             foreach (PackedEntry entry in dir)
             {
                 input.Position = entry.Offset;
                 uint packed_size = reader.ReadUInt32();
                 entry.UnpackedSize = reader.ReadUInt32();
                 entry.Offset      += 8;
                 if (0 == packed_size)
                 {
                     entry.Size = entry.UnpackedSize;
                 }
                 else
                 {
                     entry.IsPacked = true;
                     entry.Size     = packed_size;
                 }
                 if (entry.Size < 0x10)
                 {
                     continue;
                 }
                 uint signature;
                 if (entry.IsPacked)
                 {
                     UnpackEntry(input, buffer);
                     signature = LittleEndian.ToUInt32(buffer, 0);
                 }
                 else
                 {
                     signature = reader.ReadUInt32();
                 }
                 IResource res;
                 if (0x020000 == signature || 0x0A0000 == signature)
                 {
                     res = ImageFormat.Tga;
                 }
                 else
                 {
                     res = AutoEntry.DetectFileType(signature);
                 }
                 if (null != res)
                 {
                     entry.Type = res.Type;
                     var ext = res.Extensions.FirstOrDefault();
                     if (!string.IsNullOrEmpty(ext))
                     {
                         entry.Name = Path.ChangeExtension(entry.Name, ext);
                     }
                 }
             }
         }
 }
예제 #27
0
        public AbmReader(Stream file, AbmImageData info)
        {
            m_info = info;
            if (2 == m_info.Mode)
            {
                m_bpp         = 32;
                file.Position = m_info.BaseOffset;
                using (var base_frame = new ArcView.Reader(file))
                    m_output = UnpackV2(base_frame);
            }
            else if (1 == m_info.Mode || 32 == m_info.Mode || 24 == m_info.Mode)
            {
                if (1 == m_info.Mode)
                {
                    m_bpp = 24;
                }
                else
                {
                    m_bpp = m_info.Mode;
                }

                int total_length = (int)(m_info.Width * m_info.Height * m_bpp / 8);
                m_output      = new byte[total_length];
                file.Position = m_info.BaseOffset;
                if (1 == m_info.Mode)
                {
                    if (total_length != file.Read(m_output, 0, (total_length)))
                    {
                        throw new EndOfStreamException();
                    }
                }
                else
                {
                    using (var base_frame = new ArcView.Reader(file))
                    {
                        if (24 == m_bpp)
                        {
                            UnpackStream24(base_frame, m_output, total_length);
                        }
                        else
                        {
                            UnpackStream32(base_frame, m_output, total_length);
                        }
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
            if (0 != m_info.FrameOffset)
            {
                m_input = new ArcView.Reader(file);
            }
        }
예제 #28
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader(stream))
     {
         int count = reader.ReadInt16();
         if (count <= 0 || count >= 0x100)
         {
             return(null);
         }
         int offset;
         if (count > 1)
         {
             offset = reader.ReadInt32();
             if (offset != 2 + count * 4)
             {
                 return(null);
             }
         }
         else
         {
             offset = 2;
         }
         stream.Position = offset;
         int unpacked_size = reader.ReadInt32();
         int packed_size   = reader.ReadInt32();
         offset += 8;
         if (offset + packed_size > stream.Length)
         {
             return(null);
         }
         byte[] header = new byte[0x36];
         if (0x36 != MgrOpener.Decompress(stream, header) ||
             header[0] != 'B' || header[1] != 'M')
         {
             return(null);
         }
         using (var bmp = new MemoryStream(header))
         {
             var info = Bmp.ReadMetaData(bmp);
             if (null == info)
             {
                 return(null);
             }
             return(new MgrMetaData
             {
                 Width = info.Width,
                 Height = info.Height,
                 BPP = info.BPP,
                 Offset = offset,
                 PackedSize = packed_size,
                 UnpackedSize = unpacked_size,
             });
         }
     }
 }
예제 #29
0
 public BmrDecoder(Stream input)
 {
     input.Position = 3;
     using (var header = new ArcView.Reader(input))
     {
         m_step       = header.ReadByte();
         m_final_size = header.ReadInt32();
         m_key        = header.ReadInt32();
         int unpacked_size = header.ReadInt32();
         m_output = new byte[unpacked_size];
         m_input  = new MsbBitStream(input, true);
     }
 }
예제 #30
0
        public override ArcFile TryOpen(ArcView file)
        {
            int count = file.View.ReadInt32(8);

            if (!IsSaneCount(count))
            {
                return(null);
            }
            uint base_offset = file.View.ReadUInt32(0xC);

            if (base_offset <= 0x18 || base_offset >= file.MaxOffset)
            {
                return(null);
            }
            uint packed_size = file.View.ReadUInt32(0x10);
            int  index_size  = file.View.ReadInt32(0x14);

            if (packed_size > file.MaxOffset || index_size / IndexEntrySize != count)
            {
                return(null);
            }
            var name_buffer = new byte[30];

            using (var packed = file.CreateStream(0x18, packed_size))
                using (var lzss = new LzssStream(packed))
                    using (var index = new ArcView.Reader(lzss))
                    {
                        var dir = new List <Entry> (count);
                        for (int i = 0; i < count; ++i)
                        {
                            if (name_buffer.Length != index.Read(name_buffer, 0, name_buffer.Length))
                            {
                                return(null);
                            }
                            var name  = Binary.GetCString(name_buffer, 0, name_buffer.Length);
                            var entry = FormatCatalog.Instance.Create <Entry> (name);
                            if (name.EndsWith(".acd", StringComparison.InvariantCultureIgnoreCase))
                            {
                                entry.Type = "script";
                            }
                            entry.Offset = index.ReadUInt32() + base_offset;
                            entry.Size   = index.ReadUInt32();
                            if (!entry.CheckPlacement(file.MaxOffset))
                            {
                                return(null);
                            }
                            dir.Add(entry);
                        }
                        return(new ArcFile(file, this, dir));
                    }
        }
예제 #31
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader(stream))
     {
         int count = reader.ReadInt16();
         if (count <= 0)
         {
             return(null);
         }
         var tiles = new Tile[count];
         for (int i = 0; i < count; ++i)
         {
             var tile = new Tile();
             tile.Left = reader.ReadInt16();
             tile.Top  = reader.ReadInt16();
             if (tile.Left < 0 || tile.Top < 0)
             {
                 return(null);
             }
             tile.Right  = reader.ReadInt16();
             tile.Bottom = reader.ReadInt16();
             if (tile.Right <= tile.Left || tile.Bottom <= tile.Top)
             {
                 return(null);
             }
             tiles[i] = tile;
         }
         int width  = reader.ReadInt16();
         int height = reader.ReadInt16();
         if (width <= 0 || height <= 0)
         {
             return(null);
         }
         foreach (var tile in tiles)
         {
             if (tile.Right > width || tile.Bottom > height)
             {
                 return(null);
             }
         }
         return(new SplMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = 24,
             Tiles = tiles,
             DataOffset = stream.Position,
         });
     }
 }
예제 #32
0
        }                                                                  // 'AGd'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var file = new ArcView.Reader(stream))
            {
                file.ReadUInt32();
                var info = new ImageMetaData();
                info.Width  = file.ReadUInt32();
                info.Height = file.ReadUInt32();
                file.BaseStream.Position = 0x38;
                int alpha_size = file.ReadInt32();
                info.BPP = 0 == alpha_size ? 24 : 32;
                return(info);
            }
        }
예제 #33
0
파일: ImageEGN.cs 프로젝트: Casidi/GARbro
 public override ImageData Read(Stream stream, ImageMetaData info)
 {
     var meta = info as EgnMetaData;
     if (null == meta)
         throw new ArgumentException ("EgnFormat.Read should be supplied with EgnMetaData", "info");
     stream.Position = meta.DataOffset;
     using (var input = new ArcView.Reader (stream))
     {
         var reader = new Reader (input, meta.UnpackedSize, meta.Mode, meta.Flag);
         reader.Unpack();
         using (var bmp = new MemoryStream (reader.Data))
             return base.Read (bmp, info);
     }
 }
예제 #34
0
파일: ImageDGC.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         input.ReadInt32();
         var info = new DgcMetaData();
         info.Flags  = input.ReadUInt32();
         info.Width  = input.ReadUInt16();
         info.Height = input.ReadUInt16();
         if (info.Width > 0x7fff || info.Height > 0x7fff)
             return null;
         info.BPP    = 0 == (info.Flags & Reader.FlagAlphaChannel) ? 24 : 32;
         return info;
     }
 }
예제 #35
0
파일: ImageYGP.cs 프로젝트: Casidi/GARbro
 public override ImageData Read(Stream stream, ImageMetaData info)
 {
     var meta = (YgpMetaData)info;
     stream.Position = meta.DataOffset;
     int stride = (int)meta.Width * 4;
     var pixels = new byte[stride * (int)meta.Height];
     if (0 != (meta.Flags & 1))
     {
         using (var reader = new ArcView.Reader (stream))
             Unpack (reader, meta.DataSize, pixels);
     }
     else
         stream.Read (pixels, 0, pixels.Length);
     return ImageData.Create (info, PixelFormats.Bgra32, null, pixels);
 }
예제 #36
0
파일: ImageAO.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     int A = stream.ReadByte();
     int O = stream.ReadByte();
     if ('A' != A || 'O' != O)
         return null;
     using (var file = new ArcView.Reader (stream))
     {
         var info = new ImageMetaData();
         info.Width = file.ReadUInt32();
         info.Height = file.ReadUInt32();
         info.BPP = file.ReadInt16();
         info.OffsetX = file.ReadInt32();
         info.OffsetY = file.ReadInt32();
         if (info.Width > 0x8000 || info.Height > 0x8000 || !(32 == info.BPP || 24 == info.BPP))
             return null;
         return info;
     }
 }
예제 #37
0
파일: ImageEGN.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         int signature = ~input.ReadInt32();
         int mode = (signature & 0x70) >> 4; // v6
         if (0 != (mode & 4))
             return null;
         int flag = signature & 0xF; // v7
         int data_size, data_offset;
         if (0 != (signature & 0x80))
         {
             data_offset = 4;
             data_size = Binary.BigEndian (signature) & 0xFFFFFF;
         }
         else
         {
             data_offset = 8;
             data_size = Binary.BigEndian (input.ReadInt32());
         }
         if (data_size <= 0 || data_size > 0xFFFFFF) // arbitrary max BMP size
             return null;
         var reader = new Reader (input, 0x36, mode, flag); // size of BMP header
         reader.Unpack();
         using (var bmp = new MemoryStream (reader.Data))
         {
             var info = base.ReadMetaData (bmp);
             if (null == info)
                 return null;
             return new EgnMetaData
             {
                 Width = info.Width,
                 Height = info.Height,
                 BPP = info.BPP,
                 Mode = mode,
                 Flag = flag,
                 DataOffset = data_offset,
                 UnpackedSize = data_size,
             };
         }
     }
 }
예제 #38
0
파일: ImageAKB.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader (stream))
     {
         reader.ReadInt32();
         var info = new AkbMetaData();
         info.Width = reader.ReadUInt16();
         info.Height = reader.ReadUInt16();
         int flags = reader.ReadInt32() & 0xFFFF;
         info.BPP = 0 == flags ? 32 : 24;
         info.Background = reader.ReadBytes (4);
         info.OffsetX = reader.ReadInt32();
         info.OffsetY = reader.ReadInt32();
         info.InnerWidth = reader.ReadInt32() - info.OffsetX;
         info.InnerHeight = reader.ReadInt32() - info.OffsetY;
         if (info.InnerWidth > info.Width || info.InnerHeight > info.Height)
             return null;
         return info;
     }
 }
예제 #39
0
파일: ImageCPB.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Seek (4, SeekOrigin.Current);
     int type = stream.ReadByte();
     int bpp = stream.ReadByte();
     if (24 != bpp && 32 != bpp)
         throw new NotSupportedException ("Not supported CPB image format");
     using (var input = new ArcView.Reader (stream))
     {
         int version = input.ReadInt16 ();
         if (1 != version && 0 != version)
             throw new NotSupportedException ("Not supported CPB image version");
         var info = new CpbMetaData {
             Type = type,
             Version = version,
             BPP = bpp,
         };
         if (1 == version)
         {
             input.ReadUInt32();
             info.Width  = input.ReadUInt16();
             info.Height = input.ReadUInt16();
             info.Channel[0] = input.ReadUInt32();
             info.Channel[1] = input.ReadUInt32();
             info.Channel[2] = input.ReadUInt32();
             info.Channel[3] = input.ReadUInt32();
         }
         else
         {
             info.Width  = input.ReadUInt16();
             info.Height = input.ReadUInt16();
             input.ReadUInt32();
             info.Channel[0] = input.ReadUInt32();
             info.Channel[1] = input.ReadUInt32();
             info.Channel[2] = input.ReadUInt32();
             info.Channel[3] = input.ReadUInt32();
         }
         info.DataOffset = (uint)stream.Position;
         return info;
     }
 }
예제 #40
0
파일: ImagePB3.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 4;
     using (var reader = new ArcView.Reader (stream))
     {
         int input_size = reader.ReadInt32();
         stream.Position = 0x18;
         int t2 = reader.ReadInt32();
         int t1 = reader.ReadUInt16();
         uint width = reader.ReadUInt16();
         uint height = reader.ReadUInt16();
         int bpp = reader.ReadUInt16();
         return new Pb3MetaData
         {
             Width       = width,
             Height      = height,
             BPP         = bpp,
             Type        = t1,
             SubType     = t2,
             InputSize   = input_size,
         };
     }
 }
예제 #41
0
파일: ImageS25.cs 프로젝트: Casidi/GARbro
 // in current implementation, only the first frame is returned.
 // per-frame access is provided by S25Opener class.
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         input.ReadUInt32();
         int count = input.ReadInt32();
         if (count < 0 || count > 0xfffff)
             return null;
         uint first_offset = input.ReadUInt32();
         if (0 == first_offset)
             return null;
         input.BaseStream.Position = first_offset;
         var info = new S25MetaData();
         info.Width = input.ReadUInt32();
         info.Height = input.ReadUInt32();
         info.OffsetX = input.ReadInt32();
         info.OffsetY = input.ReadInt32();
         info.FirstOffset = first_offset+0x14;
         info.Incremental = 0 != (input.ReadUInt32() & 0x80000000u);
         info.BPP = 32;
         return info;
     }
 }
예제 #42
0
파일: ImageELG.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Seek (3, SeekOrigin.Current);
     using (var input = new ArcView.Reader (stream))
     {
         int bpp = input.ReadByte();
         int x = 0;
         int y = 0;
         int type = bpp;
         int header_size = 8;
         if (2 == type)
         {
             bpp = input.ReadByte();
             header_size = 13;
         }
         else if (1 == type)
         {
             bpp = input.ReadByte();
             x = input.ReadInt16();
             y = input.ReadInt16();
             header_size = 13;
         }
         else
             type = 0;
         if (8 != bpp && 24 != bpp && 32 != bpp)
             return null;
         uint w = input.ReadUInt16();
         uint h = input.ReadUInt16();
         if (2 == type)
         {
             x = input.ReadInt16();
             y = input.ReadInt16();
         }
         return new ElgMetaData
         {
             Width = w,
             Height = h,
             OffsetX = x,
             OffsetY = y,
             BPP = bpp,
             Type = type,
             HeaderSize = header_size,
         };
     }
 }
예제 #43
0
파일: ArcNPK.cs 프로젝트: Casidi/GARbro
 public override ArcFile TryOpen(ArcView file)
 {
     int count = file.View.ReadInt32 (0x18);
     if (!IsSaneCount (count))
         return null;
     var key = QueryEncryption();
     if (null == key)
         return null;
     var aes = Aes.Create();
     try
     {
         aes.Mode = CipherMode.CBC;
         aes.Padding = PaddingMode.PKCS7;
         aes.Key = key;
         aes.IV = file.View.ReadBytes (8, 0x10);
         uint index_size = file.View.ReadUInt32 (0x1C);
         using (var decryptor = aes.CreateDecryptor())
         using (var enc_index = file.CreateStream (0x20, index_size))
         using (var dec_index = new CryptoStream (enc_index, decryptor, CryptoStreamMode.Read))
         using (var index = new ArcView.Reader (dec_index))
         {
             var dir = ReadIndex (index, count, file.MaxOffset);
             if (null == dir)
                 return null;
             var arc = new NpkArchive (file, this, dir, aes);
             aes = null; // object ownership passed to NpkArchive, don't dispose
             return arc;
         }
     }
     finally
     {
         if (aes != null)
             aes.Dispose();
     }
 }
예제 #44
0
파일: ImageMGR.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader (stream))
     {
         int count = reader.ReadInt16();
         if (count <= 0 || count >= 0x100)
             return null;
         int offset;
         if (count > 1)
         {
             offset = reader.ReadInt32();
             if (offset != 2 + count * 4)
                 return null;
         }
         else
             offset = 2;
         stream.Position = offset;
         int unpacked_size = reader.ReadInt32();
         int packed_size = reader.ReadInt32();
         offset += 8;
         if (offset + packed_size > stream.Length)
             return null;
         byte[] header = new byte[0x36];
         if (0x36 != MgrOpener.Decompress (stream, header)
             || header[0] != 'B' || header[1] != 'M')
             return null;
         using (var bmp = new MemoryStream (header))
         {
             var info = Bmp.ReadMetaData (bmp);
             if (null == info)
                 return null;
             return new MgrMetaData
             {
                 Width = info.Width,
                 Height = info.Height,
                 BPP = info.BPP,
                 Offset = offset,
                 PackedSize = packed_size,
                 UnpackedSize = unpacked_size,
             };
         }
     }
 }
예제 #45
0
파일: ImageEPA.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var header = new ArcView.Reader (stream))
     {
         var info = new EpaMetaData();
         info.Mode = header.ReadInt32() >> 24;
         info.ColorType = header.ReadInt32() & 0xff;
         switch (info.ColorType)
         {
         case 0: info.BPP = 8; break;
         case 1: info.BPP = 24; break;
         case 2: info.BPP = 32; break;
         case 3: info.BPP = 15; break;
         case 4: info.BPP = 8; break;
         default: return null;
         }
         info.Width = header.ReadUInt32();
         info.Height = header.ReadUInt32();
         if (2 == info.Mode)
         {
             info.OffsetX = header.ReadInt32();
             info.OffsetY = header.ReadInt32();
         }
         return info;
     }
 }
예제 #46
0
파일: ArcABM.cs 프로젝트: Casidi/GARbro
        public AbmReader(Stream file, AbmImageData info)
        {
            m_info = info;
            if (2 == m_info.Mode)
            {
                m_bpp = 32;
                file.Position = m_info.BaseOffset;
                using (var base_frame = new ArcView.Reader (file))
                    m_output = UnpackV2 (base_frame);
            }
            else if (1 == m_info.Mode || 32 == m_info.Mode || 24 == m_info.Mode)
            {
                if (1 == m_info.Mode)
                    m_bpp = 24;
                else
                    m_bpp = m_info.Mode;

                int total_length = (int)(m_info.Width * m_info.Height * m_bpp / 8);
                m_output = new byte[total_length];
                file.Position = m_info.BaseOffset;
                if (1 == m_info.Mode)
                {
                    if (total_length != file.Read (m_output, 0, (total_length)))
                        throw new EndOfStreamException();
                }
                else
                {
                    using (var base_frame = new ArcView.Reader (file))
                    {
                        if (24 == m_bpp)
                            UnpackStream24 (base_frame, m_output, total_length);
                        else
                            UnpackStream32 (base_frame, m_output, total_length);
                    }
                }
            }
            else
                throw new NotImplementedException();
            if (0 != m_info.FrameOffset)
            {
                m_input = new ArcView.Reader (file);
            }
        }
예제 #47
0
파일: ImageNGP.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 0x12;
     using (var reader = new ArcView.Reader (stream))
     {
         int packed_size = reader.ReadInt32();
         uint width      = reader.ReadUInt32();
         uint height     = reader.ReadUInt32();
         int bpp         = reader.ReadUInt16() * 8;
         reader.BaseStream.Position = 0x100;
         int unpacked_size = reader.ReadInt32();
         if (packed_size <= 0 || unpacked_size <= 0)
             return null;
         return new NgpMetaData
         {
             Width = width,
             Height = height,
             BPP = bpp,
             PackedSize = packed_size,
             UnpackedSize = unpacked_size,
         };
     }
 }
예제 #48
0
파일: ArcDX.cs 프로젝트: Casidi/GARbro
        byte[] Unpack(Stream stream)
        {
            using (var input = new ArcView.Reader (stream))
            {
                uint unpacked_size = input.ReadUInt32();
                int remaining = input.ReadInt32() - 9;
                var output = new byte[unpacked_size];
                byte control_code = input.ReadByte();
                int dst = 0;
                while (remaining > 0)
                {
                    byte b = input.ReadByte();
                    --remaining;
                    if (b != control_code)
                    {
                        output[dst++] = b;
                        continue;
                    }
                    b = input.ReadByte();
                    --remaining;
                    if (b == control_code)
                    {
                        output[dst++] = b;
                        continue;
                    }
                    if (b > control_code)
                        --b;
                    int count = b >> 3;
                    if (0 != (b & 4))
                    {
                        count |= input.ReadByte() << 5;
                        --remaining;
                    }
                    count += 4;
                    int offset;
                    switch (b & 3)
                    {
                    case 0:
                        offset = input.ReadByte();
                        --remaining;
                        break;

                    case 1:
                        offset = input.ReadUInt16();
                        remaining -= 2;
                        break;

                    case 2:
                        offset = input.ReadUInt16();
                        offset |= input.ReadByte() << 16;
                        remaining -= 3;
                        break;

                    default:
                        throw new InvalidFormatException ("DX decompression failed");
                    }
                    ++offset;
                    Binary.CopyOverlapped (output, dst - offset, dst, count);
                    dst += count;
                }
                return output;
            }
        }
예제 #49
0
파일: ImageMAI.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         uint size = input.ReadUInt32();
         if (size != stream.Length)
             return null;
         uint width = input.ReadUInt32();
         uint height = input.ReadUInt32();
         int compressed = input.ReadInt32();
         if (compressed > 1 || 0 == compressed && (width*height + 0x410) != size)
             return null;
         return new CmMetaData {
             Width = width,
             Height = height,
             BPP = 8,
             IsCompressed = 1 == compressed,
             DataOffset = 0x10,
             DataLength = size,
         };
     }
 }
예제 #50
0
파일: ArcGPC.cs 프로젝트: Casidi/GARbro
 void DetectFileTypes(ArcView file, List<Entry> dir)
 {
     using (var input = file.CreateStream())
     using (var reader = new ArcView.Reader (input))
     {
         var buffer = new byte[0x10];
         foreach (PackedEntry entry in dir)
         {
             input.Position = entry.Offset;
             uint packed_size = reader.ReadUInt32();
             entry.UnpackedSize = reader.ReadUInt32();
             entry.Offset += 8;
             if (0 == packed_size)
             {
                 entry.Size = entry.UnpackedSize;
             }
             else
             {
                 entry.IsPacked = true;
                 entry.Size = packed_size;
             }
             if (entry.Size < 0x10)
                 continue;
             uint signature;
             if (entry.IsPacked)
             {
                 UnpackEntry (input, buffer);
                 signature = LittleEndian.ToUInt32 (buffer, 0);
             }
             else
                 signature = reader.ReadUInt32();
             IResource res;
             if (0x020000 == signature || 0x0A0000 == signature)
                 res = ImageFormat.Tga;
             else
                 res = AutoEntry.DetectFileType (signature);
             if (null != res)
             {
                 entry.Type = res.Type;
                 var ext = res.Extensions.FirstOrDefault();
                 if (!string.IsNullOrEmpty (ext))
                     entry.Name = Path.ChangeExtension (entry.Name, ext);
             }
         }
     }
 }
예제 #51
0
파일: ImageDRG.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         input.ReadUInt32();
         var info = new GgdMetaData { BPP = 8 };
         info.HeaderSize = input.ReadUInt32();
         info.Width = input.ReadUInt32();
         int height = input.ReadInt32();
         if (height < 0)
         {
             height = -height;
             info.Flipped = true;
         }
         info.Height = (uint)height;
         input.ReadInt64();
         info.BitmapSize = input.ReadUInt32();
         return info;
     }
 }
예제 #52
0
파일: ImageMFG.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var file = new ArcView.Reader (stream))
     {
         stream.Seek (3, SeekOrigin.Current);
         byte id = file.ReadByte();
         uint data_size = file.ReadUInt32();
         uint width = file.ReadUInt32();
         uint height = file.ReadUInt32();
         uint stride = file.ReadUInt32();
         if (stride < width)
             throw new NotSupportedException();
         if (stride*height != data_size)
             return null;
         return new MfgMetaData
         {
             Width = width,
             Height = height,
             BPP = (int)(stride*8/width),
             Type = id,
             Stride = (int)stride,
         };
     }
 }
예제 #53
0
파일: ArcNSA.cs 프로젝트: Casidi/GARbro
        protected List<Entry> ReadIndex(Stream file)
        {
            long base_offset = file.Position;
            using (var input = new ArcView.Reader (file))
            {
                int count = Binary.BigEndian (input.ReadInt16());
                if (!IsSaneCount (count))
                    return null;
                base_offset += Binary.BigEndian (input.ReadUInt32());
                if (base_offset >= file.Length || base_offset < 15 * count)
                    return null;

                var dir = new List<Entry>();
                for (int i = 0; i < count; ++i)
                {
                    if (base_offset - file.Position < 15)
                        return null;
                    var name = file.ReadCString();
                    if (base_offset - file.Position < 13 || 0 == name.Length)
                        return null;

                    var entry = FormatCatalog.Instance.Create<NsaEntry> (name);
                    byte compression_type = input.ReadByte();
                    entry.Offset = Binary.BigEndian (input.ReadUInt32()) + base_offset;
                    entry.Size   = Binary.BigEndian (input.ReadUInt32());
                    if (!entry.CheckPlacement (file.Length))
                        return null;
                    entry.UnpackedSize = Binary.BigEndian (input.ReadUInt32());
                    entry.IsPacked = compression_type != 0;
                    switch (compression_type)
                    {
                    case 0:  entry.CompressionType = Compression.None; break;
                    case 1:  entry.CompressionType = Compression.SPB; break;
                    case 2:  entry.CompressionType = Compression.LZSS; break;
                    case 4:  entry.CompressionType = Compression.NBZ; break;
                    default: entry.CompressionType = Compression.Unknown; break;
                    }
                    dir.Add (entry);
                }
                return dir;
            }
        }
예제 #54
0
파일: ImageHIZ.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream)) // sub_4BF900
     {
         input.ReadInt32();
         int n = input.ReadInt32();
         if (100 != n)
             return null;
         uint right = input.ReadUInt32() ^ 0xAA5A5A5A;
         uint bottom = input.ReadUInt32() ^ 0xAC9326AF;
         int unknown1 = input.ReadInt32(); // @0x10
         if (unknown1 == 0x375A8436)
             return null;
         uint unpacked_size = input.ReadUInt32() ^ 0x19739D6A; // @0x14
         if (unpacked_size != right*bottom*4)
             return null;
         return new HizMetaData
         {
             Width = right,
             Height = bottom,
             BPP = 32,
             IsPacked = true,
             DataOffset = 0x4c,
             UnpackedSize = unpacked_size,
         };
     }
 }
예제 #55
0
파일: ImageAinos.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     int sig = stream.ReadByte();
     if (sig >= 0x20)
         return null;
     using (var input = new ArcView.Reader (stream))
     {
         int width  = input.ReadInt16();
         int height = input.ReadInt16();
         if (width <= 0 || height <= 0 || width > 4096 || height > 4096)
             return null;
         var meta = new CgMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = 24,
             Type = sig,
         };
         if (0 != (sig & 7))
         {
             meta.OffsetX = input.ReadInt16();
             meta.OffsetY = input.ReadInt16();
             meta.Right   = input.ReadInt16();
             meta.Bottom  = input.ReadInt16();
             if (meta.OffsetX > meta.Right || meta.OffsetY > meta.Bottom ||
                 meta.Right > width || meta.Bottom > height ||
                 meta.OffsetX < 0 || meta.OffsetY < 0)
                 return null;
         }
         return meta;
     }
 }
예제 #56
0
파일: ImagePGX.cs 프로젝트: Casidi/GARbro
        static void LzssUnpack(Stream input, byte[] output)
        {
            var frame = new byte[0x1000];
            int frame_pos = 0xFEE;
            using (var lz = new ArcView.Reader (input))
            {
                int dst = 0;
                int bits = 1;
                while (dst < output.Length)
                {
                    if (1 == bits)
                        bits = lz.ReadByte() | 0x100;

                    if (0 != (bits & 1))
                    {
                        byte b = lz.ReadByte();
                        output[dst++] = b;
                        frame[frame_pos++] = b;
                        frame_pos &= 0xFFF;
                    }
                    else
                    {
                        byte lo = lz.ReadByte();
                        byte hi = lz.ReadByte();
                        int offset = (hi & 0xF0) << 4 | lo;
                        int count = Math.Min ((~hi & 0xF) + 3, output.Length-dst);
                        for (int i = 0; i < count; ++i)
                        {
                            byte b = frame[offset++ & 0xFFF];
                            output[dst++] = b;
                            frame[frame_pos++] = b;
                            frame_pos &= 0xFFF;
                        }
                    }
                    bits >>= 1;
                }
            }
        }
예제 #57
0
파일: ArcLINK.cs 프로젝트: Casidi/GARbro
 public BmrDecoder(Stream input)
 {
     input.Position = 3;
     using (var header = new ArcView.Reader (input))
     {
         m_step = header.ReadByte();
         m_final_size = header.ReadInt32();
         m_key = header.ReadInt32();
         int unpacked_size = header.ReadInt32();
         m_output = new byte[unpacked_size];
         m_input = new MsbBitStream (input, true);
     }
 }
예제 #58
0
파일: ImageGP8.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         int x = input.ReadInt16();
         int y = input.ReadInt16();
         int w = input.ReadInt16();
         int h = input.ReadInt16();
         if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000
             || x < 0 || x > 0x800 || y < 0 || y > 0x800)
             return null;
         return new ImageMetaData {
             Width = (uint)w,
             Height = (uint)h,
             OffsetX = x,
             OffsetY = y,
             BPP = 8,
         };
     }
 }
예제 #59
0
파일: ImageGS.cs 프로젝트: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         var info = new PicMetaData();
         input.ReadUInt32();
         info.PackedSize = input.ReadUInt32();
         info.UnpackedSize = input.ReadUInt32();
         info.HeaderSize = input.ReadUInt32();
         if (info.HeaderSize >= stream.Length || info.PackedSize + info.HeaderSize > stream.Length)
             return null;
         input.ReadUInt32();
         info.Width = input.ReadUInt32();
         info.Height = input.ReadUInt32();
         info.BPP = input.ReadInt32();
         if (info.HeaderSize >= 0x2C)
         {
             input.ReadInt32();
             info.OffsetX = input.ReadInt32();
             info.OffsetY = input.ReadInt32();
         }
         return info;
     }
 }
예제 #60
0
파일: ArcGPC.cs 프로젝트: Casidi/GARbro
 public override Stream OpenEntry(ArcFile arc, Entry entry)
 {
     var pent = entry as PackedEntry;
     Stream input = arc.File.CreateStream (entry.Offset, entry.Size);
     if (null != pent && pent.IsPacked)
     {
         Stream unpacked;
         using (input)
         {
             var data = new byte[pent.UnpackedSize];
             UnpackEntry (input, data);
             unpacked = new MemoryStream (data);
         }
         input = unpacked;
     }
     if (input.Length > 4 && input.Length < 0x10000)
     {
         using (var reader = new ArcView.Reader (input))
         {
             int unpacked_size = reader.ReadUInt16();
             int packed_size = reader.ReadUInt16();
             if (packed_size == input.Length-4)
             {
                 using (input)
                 {
                     var data = new byte[unpacked_size];
                     UnpackLz77 (input, data);
                     return new MemoryStream (data);
                 }
             }
             input.Position = 0;
         }
     }
     return input;
 }