예제 #1
0
파일: ArcQLIE.cs 프로젝트: ziyuejun/GARbro
        public List <Entry> Read(IEncryption enc, byte[] key_file, bool use_pack_keyfile)
        {
            m_dir.Clear();
            m_index.Position = 0;
            bool read_pack_keyfile = 3 == m_pack_version.Major && use_pack_keyfile;

            for (int i = 0; i < m_count; ++i)
            {
                int name_length = m_index.ReadUInt16();
                if (enc.IsUnicode)
                {
                    name_length *= 2;
                }
                if (name_length > m_name_buffer.Length)
                {
                    m_name_buffer = new byte[name_length];
                }
                if (name_length != m_index.Read(m_name_buffer, 0, name_length))
                {
                    return(null);
                }
                var name  = enc.DecryptName(m_name_buffer, name_length);
                var entry = m_fmt.Create <QlieEntry> (name);
                if (use_pack_keyfile)
                {
                    entry.RawName = m_name_buffer.Take(name_length).ToArray();
                }

                entry.Offset = m_index.ReadInt64();           // [+00]
                entry.Size   = m_index.ReadUInt32();          // [+08]
                if (!entry.CheckPlacement(m_file.MaxOffset))
                {
                    return(null);
                }
                entry.UnpackedSize     = m_index.ReadUInt32();     // [+0C]
                entry.IsPacked         = 0 != m_index.ReadInt32(); // [+10]
                entry.EncryptionMethod = m_index.ReadInt32();      // [+14]
                if (m_pack_version.Major > 1)
                {
                    entry.Hash = m_index.ReadUInt32();            // [+18]
                }
                entry.KeyFile = key_file;
                if (read_pack_keyfile && entry.Name.Contains("pack_keyfile"))
                {
                    // note that 'pack_keyfile' itself is encrypted using 'key.fkey' file contents.
                    key_file          = m_fmt.ReadEntryBytes(m_file, entry, enc);
                    read_pack_keyfile = false;
                }
                m_dir.Add(entry);
            }
            return(m_dir);
        }