public PrcImages(Header header, PDBheader pdb) { m_FirstImageRec = header.ReadInt(108); // First image rec: Bytes 108-4 big-endian integer if (m_FirstImageRec > 0) { m_ImageArray = new ArrayList(); // Loop though images. Ignore last two records (FLIS and FCIS) for (int i = m_FirstImageRec; i < pdb.RecordCnt - 3; i++) { Image newImage; // get the next image Byte[] imageRec = pdb.GetRecord(i); // Check for various image formats (JPG,GIF,BMP etc) String jpgFlag = ReadString(imageRec, 6, 4); if (jpgFlag.Equals("JFIF")) { newImage = LoadJPEG(imageRec); m_ImageArray.Add(newImage); } String gifFlag = ReadString(imageRec, 0, 3); if (gifFlag.Equals("GIF")) { newImage = LoadGIF(imageRec); m_ImageArray.Add(newImage); } } } }
public PRCheader(Header header) { // Compression : Bytes 0-2 big-endian integer m_Compression = header.ReadShort(0); // Uncompressed Text Length: Bytes 4-4 big-endian integer m_UncompTextLen = header.ReadInt(4); m_UncompTextLen += 2; // allow for trailing CRLF // record Count : Bytes 8-2 big-endian integer m_PRCrecCnt = header.ReadShort(8); // Max record lenth : Bytes 10-2 big-endian integer m_MaxRecLen = header.ReadShort(10); // Encryption : Bytes 12-2 big-endian integer m_Encryption = header.ReadShort(12); }
//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); } }
private void LoadPRC(string fn) { m_File = new FileStream(fn, FileMode.Open, FileAccess.Read); m_Array = new Byte[m_File.Length]; m_File.Read(m_Array, 0, m_Array.Length); Header m_Header = new Header(m_Array); m_PDBheader = new PDBheader(m_Header); byte[] prcRec = m_PDBheader.GetRecord(0); m_Rec0 = new Header(prcRec); m_PRCheader = new PRCheader(m_Rec0); m_MOBIheader = new MOBIheader(m_Rec0); // Does an EXTH header exist? Byte 126 bit 6 (0x40) bool m_EXTHexists = (((int)prcRec[126] & 0x40) == 0x00); if (m_EXTHexists) { m_EXTHheader = new EXTHheader(m_Rec0); } // Images m_Images = new PrcImages(m_Rec0, m_PDBheader); }
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); }
public HuffmanDecompress(Header header) : base() { }
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; } }