Пример #1
0
        internal string DecryptName(ArcIndexScheme scheme)
        {
            int n;

            for (n = 0; n < m_name_buf.Length; ++n)
            {
                if (n > scheme.NameLength)
                {
                    return(null);
                }
                m_name_buf[n] ^= scheme.NameKey;
                if (0 == m_name_buf[n])
                {
                    break;
                }
                if (m_name_buf[n] < 0x20)
                {
                    return(null);
                }
            }
            if (n != 0)
            {
                return(Encodings.cp932.GetString(m_name_buf, 0, n));
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public List <Entry> Read(ArcIndexScheme scheme)
        {
            if (scheme.NameLength > m_name_buf.Length)
            {
                m_name_buf = new byte[scheme.NameLength];
            }
            m_dir.Clear();
            int  index_offset = 4;
            uint index_size   = (uint)(m_count * (scheme.NameLength + 8));

            if (index_size > m_file.View.Reserve(index_offset, index_size))
            {
                return(null);
            }
            for (int i = 0; i < m_count; ++i)
            {
                m_file.View.Read(index_offset, m_name_buf, 0, (uint)scheme.NameLength);
                string name = DecryptName(scheme);
                if (null == name)
                {
                    return(null);
                }
                index_offset += scheme.NameLength;
                var entry = FormatCatalog.Instance.Create <Entry> (name);
                entry.Size   = m_file.View.ReadUInt32(index_offset) ^ scheme.SizeKey;
                entry.Offset = m_file.View.ReadUInt32(index_offset + 4) ^ scheme.OffsetKey;
                if (entry.Offset < index_size + 4 || !entry.CheckPlacement(m_file.MaxOffset))
                {
                    return(null);
                }
                m_dir.Add(entry);
                index_offset += 8;
            }
            return(m_dir);
        }
Пример #3
0
            public List <Entry> Read(ArcIndexScheme scheme)
            {
                if (scheme.NameLength > m_name_buf.Length)
                {
                    m_name_buf = new byte[scheme.NameLength];
                }
                m_dir.Clear();
                int  index_offset = 4;
                uint index_size   = (uint)(m_count * (scheme.NameLength + 8));

                if (index_size > m_file.View.Reserve(index_offset, index_size))
                {
                    return(null);
                }
                for (int i = 0; i < m_count; ++i)
                {
                    m_file.View.Read(index_offset, m_name_buf, 0, (uint)scheme.NameLength);
                    int n;
                    for (n = 0; n < m_name_buf.Length; ++n)
                    {
                        m_name_buf[n] ^= scheme.NameKey;
                        if (0 == m_name_buf[n])
                        {
                            break;
                        }
                        if (m_name_buf[n] < 0x20)
                        {
                            return(null);
                        }
                    }
                    if (0 == n)
                    {
                        return(null);
                    }
                    string name = Encodings.cp932.GetString(m_name_buf, 0, n);
                    index_offset += scheme.NameLength;
                    var entry = FormatCatalog.Instance.Create <Entry> (name);
                    entry.Size   = m_file.View.ReadUInt32(index_offset) ^ scheme.SizeKey;
                    entry.Offset = m_file.View.ReadUInt32(index_offset + 4) ^ scheme.OffsetKey;
                    if (entry.Offset < index_size + 4 || !entry.CheckPlacement(m_file.MaxOffset))
                    {
                        return(null);
                    }
                    m_dir.Add(entry);
                    index_offset += 8;
                }
                return(m_dir);
            }
Пример #4
0
        public override ArcFile TryOpen(ArcView file)
        {
            uint key   = file.View.ReadUInt32(4);
            int  count = (int)(file.View.ReadUInt32(0) ^ key);

            if (!IsSaneCount(count))
            {
                return(null);
            }
            byte name_key = file.View.ReadByte(0x23);
            var  scheme   = new ArcIndexScheme {
                NameLength = 0x14, NameKey = name_key, SizeKey = key, OffsetKey = key
            };
            var reader = new Ai5DatIndexReader(file, count);
            var dir    = reader.Read(scheme);

            if (dir != null)
            {
                return(new ArcFile(file, this, dir));
            }
            return(null);
        }