Example #1
0
        private static ushort[,] Parse(byte[] contents, int version)
        {
            if (version == 2)
            {
                int npar = contents.Length / stride / 2;
                if (npar < 8 || npar > 32 || contents.Length != npar * stride * 2)
                {
                    throw new Exception("invalid parity length");
                }
                return(ParityToSyndrome.Bytes2Syndrome(stride, 8, contents));
            }

            if (contents.Length < 8 * stride * 2 ||
                contents.Length > 8 * stride * 4)
            {
                throw new Exception("invalid length");
            }

            ReadDB rdr = new ReadDB(contents);

            int    end;
            string hdr   = rdr.ReadHDR(out end);
            uint   magic = rdr.ReadUInt();

            if (hdr != "ftyp" || magic != 0x43544442 || end != rdr.pos)
            {
                throw new Exception("invalid CTDB file");
            }
            hdr = rdr.ReadHDR(out end);
            if (hdr != "CTDB" || end != contents.Length)
            {
                throw new Exception("invalid CTDB file");
            }
            hdr = rdr.ReadHDR(out end);
            if (hdr != "HEAD")
            {
                throw new Exception("invalid CTDB file");
            }
            int endHead = end;

            while (rdr.pos < endHead)
            {
                hdr     = rdr.ReadHDR(out end);
                rdr.pos = end;
            }
            rdr.pos = endHead;
            while (rdr.pos < contents.Length)
            {
                hdr = rdr.ReadHDR(out end);
                if (hdr != "DISC")
                {
                    rdr.pos = end;
                    continue;
                }
                int endDisc = end;
                int parPos = 0, parLen = 0;
                while (rdr.pos < endDisc)
                {
                    hdr = rdr.ReadHDR(out end);
                    if (hdr == "PAR ")
                    {
                        parPos = rdr.pos;
                        parLen = end - rdr.pos;
                    }
                    rdr.pos = end;
                }
                if (parPos != 0)
                {
                    if (parLen != 8 * stride * 2)
                    {
                        throw new Exception("invalid parity length");
                    }
                    return(ParityToSyndrome.Parity2Syndrome(stride, stride, 8, 8, contents, parPos));
                }
            }
            throw new Exception("invalid CTDB file");
        }
Example #2
0
        private static ushort[,] Parse(byte[] contents, int version)
        {
            if (version == 2)
            {
                int npar = contents.Length / stride / 2;
                if (npar < 8 || npar > 32 || contents.Length != npar * stride * 2)
                    throw new Exception("invalid parity length");
                return ParityToSyndrome.Bytes2Syndrome(stride, 8, contents);
            }

            if (contents.Length < 8 * stride * 2
                || contents.Length > 8 * stride * 4)
                throw new Exception("invalid length");

            ReadDB rdr = new ReadDB(contents);

            int end;
            string hdr = rdr.ReadHDR(out end);
            uint magic = rdr.ReadUInt();
            if (hdr != "ftyp" || magic != 0x43544442 || end != rdr.pos)
                throw new Exception("invalid CTDB file");
            hdr = rdr.ReadHDR(out end);
            if (hdr != "CTDB" || end != contents.Length)
                throw new Exception("invalid CTDB file");
            hdr = rdr.ReadHDR(out end);
            if (hdr != "HEAD")
                throw new Exception("invalid CTDB file");
            int endHead = end;
            while (rdr.pos < endHead)
            {
                hdr = rdr.ReadHDR(out end);
                rdr.pos = end;
            }
            rdr.pos = endHead;
            while (rdr.pos < contents.Length)
            {
                hdr = rdr.ReadHDR(out end);
                if (hdr != "DISC")
                {
                    rdr.pos = end;
                    continue;
                }
                int endDisc = end;
                int parPos = 0, parLen = 0;
                while (rdr.pos < endDisc)
                {
                    hdr = rdr.ReadHDR(out end);
                    if (hdr == "PAR ")
                    {
                        parPos = rdr.pos;
                        parLen = end - rdr.pos;
                    }
                    rdr.pos = end;
                }
                if (parPos != 0)
                {
                    if (parLen != 8 * stride * 2)
                        throw new Exception("invalid parity length");
                    return ParityToSyndrome.Parity2Syndrome(stride, stride, 8, 8, contents, parPos);
                }
            }
            throw new Exception("invalid CTDB file");
        }