コード例 #1
0
        public override int Read(byte[] buf, int index, int count)
        {
            int  total_read    = 0;
            bool refill_buffer = !(m_position >= m_current_block_position && m_position < m_current_block_position + m_current_block_length);

            while (count > 0 && m_position < m_max_offset)
            {
                if (refill_buffer)
                {
                    int block_num = (int)(m_position / BlockLength);
                    m_current_block_position = m_position & ~((long)BlockLength - 1);
                    m_current_block_length   = m_view.Read(m_current_block_position, m_current_block, 0, (uint)BlockLength);
                    DecryptBlock(block_num);
                }
                int src_offset = (int)m_position & (BlockLength - 1);
                int available  = Math.Min(count, m_current_block_length - src_offset);
                Buffer.BlockCopy(m_current_block, src_offset, buf, index, available);
                m_position   += available;
                total_read   += available;
                index        += available;
                count        -= available;
                refill_buffer = true;
            }
            return(total_read);
        }
コード例 #2
0
ファイル: ArcLIB.cs プロジェクト: binlee1990/GARbro
 private void FillBuffer()
 {
     m_current_block_length = m_view.Read(m_current_block_position, m_current_block, 0, (uint)BlockLength);
     for (int offset = 0; offset < m_current_block_length; offset += 0x10)
     {
         m_enc.DecryptBlock(m_current_block_position + offset, m_current_block, offset);
     }
 }
コード例 #3
0
ファイル: ArcNEKO.cs プロジェクト: y111303tut/GARbro
        static byte[] ReadBlock(ArcView.Frame view, INekoFormat enc, long offset, out int length)
        {
            uint hash = view.ReadUInt32(offset);

            length = view.ReadInt32(offset + 4);

            int aligned_size = (length + 7) & ~7;

            byte[] buffer = new byte[aligned_size];
            length = view.Read(offset + 8, buffer, 0, (uint)length);
            if (0 != hash)
            {
                enc.Decrypt(hash, buffer, 0, aligned_size);
            }
            return(buffer);
        }
コード例 #4
0
ファイル: ArcCSAF.cs プロジェクト: ziyuejun/GARbro
 bool ReadBlock()
 {
     if (m_position >= m_length)
     {
         return(false);
     }
     m_block_start  = m_position & ~0xFFFL;
     m_block_length = m_view.Read(m_block_start, m_block, 0, 0x1000);
     if (m_block_length != 0x1000)
     {
         return(false);
     }
     using (var decryptor = m_encryption.CreateDecryptor((int)(m_block_start >> 12)))
         using (var enc = new BinMemoryStream(m_block))
             using (var dec = new InputCryptoStream(enc, decryptor))
                 dec.Read(m_block, 0, m_block_length);
     return(true);
 }
コード例 #5
0
ファイル: ArcNEKO.cs プロジェクト: tenyuhuang/GARbro
        static byte[] ReadBlock(ArcView.Frame view, INekoEncryption enc, long offset, out int length)
        {
            uint hash = view.ReadUInt32(offset);

            length = view.ReadInt32(offset + 4);
            // parity check
//            if (CalcParity (((NekoEncryption32bit)enc).Parity, (uint)length) != hash)
//                throw new InvalidFormatException();

            int aligned_size = (length + 7) & ~7;

            byte[] buffer = new byte[aligned_size];
            length = view.Read(offset + 8, buffer, 0, (uint)length);
            if (0 != hash)
            {
                enc.Decrypt(hash, buffer, 0, aligned_size);
            }
            return(buffer);
        }
コード例 #6
0
ファイル: ArcLIB.cs プロジェクト: y111303tut/GARbro
        private static int ReadEncrypted(ArcView.Frame view, IMalieDecryptor dec, long offset, byte[] buffer, int index, int length)
        {
            int offset_pad  = (int)offset & 0xF;
            int aligned_len = (offset_pad + length + 0xF) & ~0xF;

            byte[] aligned_buf;
            int    block = 0;

            if (aligned_len == length)
            {
                aligned_buf = buffer;
                block       = index;
            }
            else
            {
                aligned_buf = new byte[aligned_len];
            }

            int read = view.Read(offset - offset_pad, aligned_buf, block, (uint)aligned_len);

            if (read < offset_pad)
            {
                return(0);
            }

            for (int block_count = aligned_len / 0x10; block_count > 0; --block_count)
            {
                dec.DecryptBlock(offset, aligned_buf, block);
                block  += 0x10;
                offset += 0x10;
            }
            if (aligned_buf != buffer)
            {
                Buffer.BlockCopy(aligned_buf, offset_pad, buffer, index, length);
            }
            return(Math.Min(length, read - offset_pad));
        }