Exemple #1
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,
         });
     }
 }
Exemple #2
0
        }                                                                   // '256G'

        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);
            }
        }
Exemple #3
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.HasExtension(".paz"))
            {
                return(null);
            }
            uint signature = file.View.ReadUInt32(0);
            // XXX encryption is queried for every .paz file
            var  scheme       = QueryEncryption(file.Name, signature);
            uint start_offset = scheme.Version > 0 ? 0x20u : 0u;
            uint index_size   = file.View.ReadUInt32(start_offset);

            start_offset += 4;
            byte xor_key = (byte)(index_size >> 24);

            if (xor_key != 0)
            {
                index_size ^= (uint)(xor_key << 24 | xor_key << 16 | xor_key << 8 | xor_key);
            }
            if (0 != (index_size & 7) || index_size + start_offset >= file.MaxOffset)
            {
                return(null);
            }

            var  arc_list   = new List <Entry>();
            var  arc_dir    = VFS.GetDirectoryName(file.Name);
            long max_offset = file.MaxOffset;

            for (char suffix = 'A'; suffix <= 'Z'; ++suffix)
            {
                var part_name = VFS.CombinePath(arc_dir, file.Name + suffix);
                if (!VFS.FileExists(part_name))
                {
                    break;
                }
                var part = VFS.FindFile(part_name);
                arc_list.Add(part);
                max_offset += part.Size;
            }
            var    arc_name = Path.GetFileNameWithoutExtension(file.Name).ToLowerInvariant();
            bool   is_audio = AudioPazNames.Contains(arc_name);
            bool   is_video = VideoPazNames.Contains(arc_name);
            Stream input    = file.CreateStream(start_offset, index_size);

            byte[]       video_key = null;
            List <Entry> dir;

            try
            {
                if (xor_key != 0)
                {
                    input = new XoredStream(input, xor_key);
                }
                var enc = new Blowfish(scheme.ArcKeys[arc_name].IndexKey);
                input = new InputCryptoStream(input, enc.CreateDecryptor());
                using (var index = new ArcView.Reader(input))
                {
                    int count = index.ReadInt32();
                    if (!IsSaneCount(count))
                    {
                        return(null);
                    }
                    if (is_video)
                    {
                        video_key = index.ReadBytes(0x100);
                    }

                    dir = new List <Entry> (count);
                    for (int i = 0; i < count; ++i)
                    {
                        var name  = index.BaseStream.ReadCString();
                        var entry = FormatCatalog.Instance.Create <PazEntry> (name);
                        entry.Offset       = index.ReadInt64();
                        entry.UnpackedSize = index.ReadUInt32();
                        entry.Size         = index.ReadUInt32();
                        entry.AlignedSize  = index.ReadUInt32();
                        if (!entry.CheckPlacement(max_offset))
                        {
                            return(null);
                        }
                        entry.IsPacked = index.ReadInt32() != 0;
                        if (string.IsNullOrEmpty(entry.Type) && is_audio)
                        {
                            entry.Type = "audio";
                        }
                        if (scheme.Version > 0)
                        {
                            string password = "";
                            if (!entry.IsPacked && scheme.TypeKeys != null)
                            {
                                password = scheme.GetTypePassword(name, is_audio);
                            }
                            if (!string.IsNullOrEmpty(password) || is_video)
                            {
                                password  = string.Format("{0} {1:X08} {2}", name.ToLowerInvariant(), entry.UnpackedSize, password);
                                entry.Key = Encodings.cp932.GetBytes(password);
                            }
                        }
                        dir.Add(entry);
                    }
                }
            }
            finally
            {
                input.Dispose();
            }
            List <ArcView> parts = null;

            if (arc_list.Count > 0)
            {
                parts = new List <ArcView> (arc_list.Count);
                try
                {
                    foreach (var arc_entry in arc_list)
                    {
                        var arc_file = VFS.OpenView(arc_entry);
                        parts.Add(arc_file);
                    }
                }
                catch
                {
                    foreach (var part in parts)
                    {
                        part.Dispose();
                    }
                    throw;
                }
            }
            if (is_video)
            {
                if (scheme.Version < 1)
                {
                    var table = new byte[0x100];
                    for (int i = 0; i < 0x100; ++i)
                    {
                        table[video_key[i]] = (byte)i;
                    }
                    video_key = table;
                }
                return(new MovPazArchive(file, this, dir, scheme.Version, xor_key, video_key, parts));
            }
            return(new PazArchive(file, this, dir, scheme.Version, xor_key, scheme.ArcKeys[arc_name].DataKey, parts));
        }
Exemple #4
0
 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;
     }
 }
Exemple #5
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,
         };
     }
 }