コード例 #1
0
        public new MBOBuffer ReadPaddedBuffer(uint filepos, uint length)
        {
            // allocate a buffer to hold the table
            MBOBuffer buf = new MBOBuffer(filepos, length);

            // read the table
            m_fs.Seek(filepos, SeekOrigin.Begin);
            int nBytes = m_fs.Read(buf.GetBuffer(), 0, (int)length);

            if (nBytes != length)
            {
                // check for premature EOF
                if (m_fs.Position == m_fs.Length)
                {
                    m_Validator.Error(E._GEN_E_EOFError, null);
                }
                else
                {
                    m_Validator.Error(E._GEN_E_ReadError, null);
                }

                buf = null;
            }

            return(buf);
        }
コード例 #2
0
        /******************
         * protected methods
         */


        protected static OffsetTable ReadOffsetTable(OTFileVal file, uint filepos)
        {
            // read the Offset Table from the file

            Validator v = file.GetValidator();

            const int SIZEOF_OFFSETTABLE = 12;

            OffsetTable ot = null;


            // read the offset table

            MBOBuffer buf = file.ReadPaddedBuffer(filepos, SIZEOF_OFFSETTABLE);

            if (buf != null)
            {
                if (OTFile.IsValidSfntVersion(buf.GetUint(0)))
                {
                    ot = new OffsetTable(buf);
                }
                else
                {
                    v.Error(T.T_NULL, E._OFFSET_E_InvalidSFNT, null, "0x" + buf.GetUint(0).ToString("x8"));
                }
            }


            // now read the directory entries

            if (ot != null)
            {
                const int SIZEOF_DIRECTORYENTRY = 16;


                for (int i = 0; i < ot.numTables; i++)
                {
                    uint      dirFilePos = (uint)(filepos + SIZEOF_OFFSETTABLE + i * SIZEOF_DIRECTORYENTRY);
                    MBOBuffer DirEntBuf  = file.ReadPaddedBuffer(dirFilePos, SIZEOF_DIRECTORYENTRY);

                    if (DirEntBuf != null)
                    {
                        DirectoryEntry de = new DirectoryEntry();

                        de.tag      = new OTTag(DirEntBuf.GetBuffer());
                        de.checkSum = DirEntBuf.GetUint(4);
                        de.offset   = DirEntBuf.GetUint(8);
                        de.length   = DirEntBuf.GetUint(12);

                        ot.DirectoryEntries.Add(de);

                        if (de.offset > file.GetFileLength())
                        {
                            v.Error(T.T_NULL, E._DE_E_OffsetPastEOF, de.tag, "0x" + de.offset.ToString("x8"));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(ot);
        }