Example #1
0
        private static int ReadEncrypted(ArcView.Frame view, Camellia enc, 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)
            {
                enc.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);
        }
Example #2
0
        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;
        }