public EXTHheader(Header header) { // Header length, including eye catcher : Bytes 20-4 big-endian integer m_MOBIlen = header.ReadInt(20); // EXTH follows immediately after MOBI m_EXTHoffset = m_MOBIlen + 16; // EXTH eye catcher - Bytes EXTH+0-4 ASCII m_EXTH = header.ReadString(m_EXTHoffset, 4); if (!m_EXTH.Equals("EXTH")) throw new Exception("Invalid PRC file (reason 02)"); // Get the total length of the EXTH record int totLen = header.ReadInt(m_EXTHoffset + 4); // Get the count of EXTH records int recCnt = header.ReadInt(m_EXTHoffset + 8); // Loop through the rest of the EXTH records saving them int endOffset = m_EXTHoffset + totLen; int pos = m_EXTHoffset + 12; while (pos < endOffset - 1) { String value; int recType = header.ReadInt(pos); int recLen = header.ReadInt(pos + 4); switch (recType) { case 115: case 116: case 201: case 202: case 204: case 205: case 206: case 207: value = header.ReadInt(pos + 8).ToString(); break; default: value = header.ReadString(pos + 8, recLen - 8); break; } m_EXTHrecs.Add(recType, value); pos += recLen; } }
//private byte[] m_Array; public PDBheader(Header header) { int temp; if (header.Length < 80) { throw new Exception("PDB header is too small"); } m_Array = header; // Filename. Bytes 0-32 null terminated ASCII m_Filename = m_Array.ReadString(0, 32); m_Filename = m_Filename.Substring(0, m_Filename.IndexOf('\0')); // Version - Bytes 34-2 high-endian integer; m_Version = m_Array.ReadShort(34); // Creation date - Bytes 36-4 high-endian integer. Despite the comments // above, the time is based on 1-Jan-1970 not 1-Jan-1904 temp = m_Array.ReadInt(36); m_CreationDate = new DateTime(1970, 1, 1, 0, 0, 0); m_CreationDate = m_CreationDate.AddSeconds((double)temp); // Modification date - Bytes 40-4 high-endian integer. Despite the comments // above, the time is based on 1-Jan-1970 not 1-Jan-1904 temp = m_Array.ReadInt(40); m_ModificationDate = new DateTime(1970, 1, 1, 0, 0, 0); m_ModificationDate = m_ModificationDate.AddSeconds((double)temp); // Type - Bytes 60-4 ASCII m_Type = m_Array.ReadString(60, 4); // Creator - Bytes 64-4 ASCII m_Creator = m_Array.ReadString(64, 4); // Record count - Bytes 76-2 high-endian integer; m_RecordCnt = m_Array.ReadShort(76); // Build a list of pointers to records. These are held in an array // starting in bytes 78-8. m_RecPointer = new ArrayList(m_RecordCnt); for (int i = 0; i < m_RecordCnt; i++) { int offs = 78 + (i * 8); temp = m_Array.ReadInt(offs); m_RecPointer.Add(temp); } }
public MOBIheader(Header header) { // MOBI eye catcher - Bytes 16-4 ASCII m_MOBI = header.ReadString(16, 4); if (!m_MOBI.Equals("MOBI")) { throw new Exception("Invalid PRC file (reason 01)"); } // Header length, including eye catcher : Bytes 20-4 big-endian integer m_MOBIlen = header.ReadInt(20); // MOBI type : Bytes 24-4 big-endian integer m_MOBItype = header.ReadInt(24); // Encoding 1252=CP1252 65001=UTF-8 : Bytes 28-4 big-endian integer m_Encoding = header.ReadInt(28); // PRC version - mobipocket format : Bytes 36-4 big-endian integer m_PrcVersion = header.ReadInt(36); // Document Fullname: Offset into rec 0 at bytes 84-4 length 88-4 int fnOffset = header.ReadInt(84); int fnLength = header.ReadInt(88); m_Fullname = header.ReadString(fnOffset, fnLength); // Locale : Bytes 92-4 big-endian integer m_Locale = header.ReadInt(92); // First image rec: Bytes 108-4 big-endian integer m_FirstImageRec = header.ReadInt(108); // First huffman rec: Bytes 112-4 big-endian integer m_FirstHuffmanRec = header.ReadInt(112); // Huffman rec count: Bytes 116-4 big-endian integer m_HuffmanRecCnt = header.ReadInt(116); // Huffman table offset: Bytes 120-4 big-endian integer m_HuffmanTableOffset = header.ReadInt(120); // Huffman table length: Bytes 124-4 big-endian integer m_HuffmanTableLen = header.ReadInt(124); }
//private byte[] m_Array; public PDBheader(Header header) { int temp; if (header.Length < 80) throw new Exception("PDB header is too small"); m_Array = header; // Filename. Bytes 0-32 null terminated ASCII m_Filename = m_Array.ReadString(0, 32); m_Filename = m_Filename.Substring(0, m_Filename.IndexOf('\0')); // Version - Bytes 34-2 high-endian integer; m_Version = m_Array.ReadShort(34); // Creation date - Bytes 36-4 high-endian integer. Despite the comments // above, the time is based on 1-Jan-1970 not 1-Jan-1904 temp = m_Array.ReadInt(36); m_CreationDate = new DateTime(1970, 1, 1, 0, 0, 0); m_CreationDate = m_CreationDate.AddSeconds((double)temp); // Modification date - Bytes 40-4 high-endian integer. Despite the comments // above, the time is based on 1-Jan-1970 not 1-Jan-1904 temp = m_Array.ReadInt(40); m_ModificationDate = new DateTime(1970, 1, 1, 0, 0, 0); m_ModificationDate = m_ModificationDate.AddSeconds((double)temp); // Type - Bytes 60-4 ASCII m_Type = m_Array.ReadString(60, 4); // Creator - Bytes 64-4 ASCII m_Creator = m_Array.ReadString(64, 4); // Record count - Bytes 76-2 high-endian integer; m_RecordCnt = m_Array.ReadShort(76); // Build a list of pointers to records. These are held in an array // starting in bytes 78-8. m_RecPointer = new ArrayList(m_RecordCnt); for (int i = 0; i < m_RecordCnt; i++) { int offs = 78 + (i * 8); temp = m_Array.ReadInt(offs); m_RecPointer.Add(temp); } }
public MOBIheader(Header header) { // MOBI eye catcher - Bytes 16-4 ASCII m_MOBI = header.ReadString(16, 4); if (!m_MOBI.Equals("MOBI")) throw new Exception("Invalid PRC file (reason 01)"); // Header length, including eye catcher : Bytes 20-4 big-endian integer m_MOBIlen = header.ReadInt(20); // MOBI type : Bytes 24-4 big-endian integer m_MOBItype = header.ReadInt(24); // Encoding 1252=CP1252 65001=UTF-8 : Bytes 28-4 big-endian integer m_Encoding = header.ReadInt(28); // PRC version - mobipocket format : Bytes 36-4 big-endian integer m_PrcVersion = header.ReadInt(36); // Document Fullname: Offset into rec 0 at bytes 84-4 length 88-4 int fnOffset = header.ReadInt(84); int fnLength = header.ReadInt(88); m_Fullname = header.ReadString(fnOffset, fnLength); // Locale : Bytes 92-4 big-endian integer m_Locale = header.ReadInt(92); // First image rec: Bytes 108-4 big-endian integer m_FirstImageRec = header.ReadInt(108); // First huffman rec: Bytes 112-4 big-endian integer m_FirstHuffmanRec = header.ReadInt(112); // Huffman rec count: Bytes 116-4 big-endian integer m_HuffmanRecCnt = header.ReadInt(116); // Huffman table offset: Bytes 120-4 big-endian integer m_HuffmanTableOffset = header.ReadInt(120); // Huffman table length: Bytes 124-4 big-endian integer m_HuffmanTableLen = header.ReadInt(124); }