示例#1
0
        void UpdateCrc(int page_length)
        {
            LittleEndian.Pack(0, m_page, 0x16);
            uint crc = Crc32Normal.UpdateCrc(0, m_page, 0, page_length);

            LittleEndian.Pack(crc, m_page, 0x16);
        }
示例#2
0
        public void SetChecksum()
        {
            Header[22] = Header[23] = Header[24] = Header[25] = 0;

            uint crc = Crc32Normal.UpdateCrc(0, Header, 0, HeaderLength);

            crc = Crc32Normal.UpdateCrc(crc, Body, BodyStart, BodyLength);

            LittleEndian.Pack(crc, Header, 22);
        }
示例#3
0
        public void Decrypt2(byte[] data, int index, uint length)
        {
            if (length < 0x400 || null == m_scheme.DecodeBin)
            {
                return;
            }
            uint crc = Crc32Normal.UpdateCrc(0xFFFFFFFF, data, index, 0x100);

            index += 0x100;
            for (int i = 0; i < 0x40; ++i)
            {
                uint src = LittleEndian.ToUInt32(data, index) & 0x1ffcu;
                src = LittleEndian.ToUInt32(m_scheme.DecodeBin, (int)src);
                uint key = src ^ crc;
                data[index++ + 0x100] ^= (byte)key;
                data[index++ + 0x100] ^= (byte)(key >> 8);
                data[index++ + 0x100] ^= (byte)(key >> 16);
                data[index++ + 0x100] ^= (byte)(key >> 24);
            }
        }
示例#4
0
        void NextPage()
        {
            m_page_pos    = 0;
            m_page_length = BaseStream.Read(m_page, 0, 0x1B);
            if (0 == m_page_length)
            {
                m_eof = true;
                return;
            }
            if (m_page_length < 0x1B || !m_page.AsciiEqual("OggS"))
            {
                m_ogg_ended = true;
                return;
            }
            int segment_count = m_page[0x1A];

            m_page[0x16] = 0;
            m_page[0x17] = 0;
            m_page[0x18] = 0;
            m_page[0x19] = 0;
            if (segment_count != 0)
            {
                int table_length = BaseStream.Read(m_page, 0x1B, segment_count);
                m_page_length += table_length;
                if (table_length != segment_count)
                {
                    m_ogg_ended = true;
                    return;
                }
                int segments_length = 0;
                int segment_table   = 0x1B;
                for (int i = 0; i < segment_count; ++i)
                {
                    segments_length += m_page[segment_table++];
                }
                m_page_length += BaseStream.Read(m_page, 0x1B + segment_count, segments_length);
            }
            uint crc = Crc32Normal.UpdateCrc(0, m_page, 0, m_page_length);

            LittleEndian.Pack(crc, m_page, 0x16);
        }
示例#5
0
        Stream RestoreOggStream(ArcFile arc, Entry entry)
        {
            var data      = arc.File.View.ReadBytes(entry.Offset, entry.Size);
            int remaining = data.Length;
            int src       = 0;

            while (remaining > 0x1B && Binary.AsciiEqual(data, src, "OggS"))
            {
                int segment_count = data[src + 0x1A];
                data[src + 0x16] = 0;
                data[src + 0x17] = 0;
                data[src + 0x18] = 0;
                data[src + 0x19] = 0;
                int page_size = segment_count + 0x1B;
                if (segment_count != 0)
                {
                    if (remaining < page_size)
                    {
                        break;
                    }
                    int segment_table = src + 0x1B;
                    for (int i = 0; i < segment_count; ++i)
                    {
                        page_size += data[segment_table++];
                    }
                }
                remaining -= page_size;
                if (remaining < 0)
                {
                    break;
                }
                uint crc = Crc32Normal.UpdateCrc(0, data, src, page_size);
                LittleEndian.Pack(crc, data, src + 0x16);
                src += page_size;
            }
            return(new BinMemoryStream(data, entry.Name));
        }