Beispiel #1
0
        public byte[] getRawML()
        {
            CheckDRM();

            Decompressor decomp;

            switch (PDH.Compression)
            {
            case (1):
                decomp = new UncompressedReader();
                break;

            case (2):
                decomp = new PalmDOCReader();
                break;

            case (17480):
                HUFFCDICReader reader = new HUFFCDICReader();
                try
                {
                    int    recOffset = (int)mobiHeader.HuffmanRecordOffset;
                    byte[] huffSect  = new byte[PDB._recInfo[recOffset + 1].RecordDataOffset - PDB._recInfo[recOffset].RecordDataOffset];
                    _fs.Seek(PDB._recInfo[recOffset].RecordDataOffset, SeekOrigin.Begin);
                    _fs.Read(huffSect, 0, huffSect.Length);
                    reader.loadHuff(huffSect);
                    int recCount = (int)mobiHeader.HuffmanRecordCount;
                    for (int i = 1; i < recCount; i++)
                    {
                        huffSect = new byte[PDB._recInfo[recOffset + i + 1].RecordDataOffset - PDB._recInfo[recOffset + i].RecordDataOffset];
                        _fs.Seek(PDB._recInfo[recOffset + i].RecordDataOffset, SeekOrigin.Begin);
                        _fs.Read(huffSect, 0, huffSect.Length);
                        reader.loadCdic(huffSect);
                    }
                } catch (Exception ex)
                {
                    throw new Exception("Error in HUFF/CDIC decompression: " + ex.Message + "\r\n" + ex.StackTrace);
                }
                decomp = reader;
                break;

            default:
                throw new Exception("Unknown compression type " + PDH.Compression + ".");
            }
            byte[] rawML     = new byte[0];
            int    endRecord = _startRecord + PDH.RecordCount - 1;

            for (int i = _startRecord; i <= endRecord; i++)
            {
                byte[] buffer = new byte[PDB._recInfo[i + 1].RecordDataOffset - PDB._recInfo[i].RecordDataOffset];
                _fs.Seek(PDB._recInfo[i].RecordDataOffset, SeekOrigin.Begin);
                _fs.Read(buffer, 0, buffer.Length);
                buffer = trimTrailingDataEntries(buffer);
                byte[] result = decomp.unpack(buffer);
                buffer = new byte[rawML.Length + result.Length];
                Buffer.BlockCopy(rawML, 0, buffer, 0, rawML.Length);
                Buffer.BlockCopy(result, 0, buffer, rawML.Length, result.Length);
                rawML = buffer;
            }
            return(rawML);
        }
Beispiel #2
0
        public byte[] getRawML(FileStream fs)
        {
            if (PDH.EncryptionType != 0)
            {
                throw new Exception("This book has DRM (it is encrypted). X-Ray Builder will only work on books that do not have DRM.");
            }

            Decompressor decomp;

            switch (PDH.Compression)
            {
            case (1):
                decomp = new UncompressedReader();
                break;

            case (2):
                decomp = new PalmDOCReader();
                break;

            case (17480):
                HUFFCDICReader reader = new HUFFCDICReader();
                try
                {
                    int    recOffset = (int)mobiHeader.HuffmanRecordOffset;
                    byte[] huffSect  = new byte[PDB._recInfo[recOffset + 1].RecordDataOffset - PDB._recInfo[recOffset].RecordDataOffset];
                    fs.Seek(PDB._recInfo[recOffset].RecordDataOffset, SeekOrigin.Begin);
                    fs.Read(huffSect, 0, huffSect.Length);
                    reader.loadHuff(huffSect);
                    int recCount = (int)mobiHeader.HuffmanRecordCount;
                    for (int i = 1; i < recCount; i++)
                    {
                        huffSect = new byte[PDB._recInfo[recOffset + i + 1].RecordDataOffset - PDB._recInfo[recOffset + i].RecordDataOffset];
                        fs.Seek(PDB._recInfo[recOffset + i].RecordDataOffset, SeekOrigin.Begin);
                        fs.Read(huffSect, 0, huffSect.Length);
                        reader.loadCdic(huffSect);
                    }
                } catch (Exception ex)
                {
                    throw new Exception("Error in HUFF/CDIC decompression: " + ex.Message);
                }
                decomp = reader;
                break;

            default:
                throw new Exception("Unknown compression type " + PDH.Compression + ".");
            }
            byte[] rawML     = new byte[0];
            int    endRecord = _startRecord + PDH.RecordCount - 1;

            for (int i = _startRecord; i <= endRecord; i++)
            {
                byte[] buffer = new byte[PDB._recInfo[i + 1].RecordDataOffset - PDB._recInfo[i].RecordDataOffset];
                fs.Seek(PDB._recInfo[i].RecordDataOffset, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
                buffer = trimTrailingDataEntries(buffer);
                byte[] result = decomp.unpack(buffer, PDB.MobiHeaderSize);
                rawML = rawML.Concat(result).ToArray();
            }
            return(rawML);
        }
        public byte[] getRawML(FileStream fs)
        {
            if (PDH.EncryptionType != 0)
                throw new Exception("This book has DRM (it is encrypted). X-Ray Builder will only work on books that do not have DRM.");

            Decompressor decomp;
            switch (PDH.Compression)
            {
                case (1):
                    decomp = new UncompressedReader();
                    break;
                case (2):
                    decomp = new PalmDOCReader();
                    break;
                case (17480):
                    HUFFCDICReader reader = new HUFFCDICReader();
                    try
                    {
                        int recOffset = (int)mobiHeader.HuffmanRecordOffset;
                        byte[] huffSect = new byte[PDB._recInfo[recOffset + 1].RecordDataOffset - PDB._recInfo[recOffset].RecordDataOffset];
                        fs.Seek(PDB._recInfo[recOffset].RecordDataOffset, SeekOrigin.Begin);
                        fs.Read(huffSect, 0, huffSect.Length);
                        reader.loadHuff(huffSect);
                        int recCount = (int)mobiHeader.HuffmanRecordCount;
                        for (int i = 1; i < recCount; i++)
                        {
                            huffSect = new byte[PDB._recInfo[recOffset + i + 1].RecordDataOffset - PDB._recInfo[recOffset + i].RecordDataOffset];
                            fs.Seek(PDB._recInfo[recOffset + i].RecordDataOffset, SeekOrigin.Begin);
                            fs.Read(huffSect, 0, huffSect.Length);
                            reader.loadCdic(huffSect);
                        }
                    } catch (Exception ex)
                    {
                        throw new Exception("Error in HUFF/CDIC decompression: " + ex.Message);
                    }
                    decomp = reader;
                    break;
                default:
                    throw new Exception("Unknown compression type " + PDH.Compression + ".");
            }
            byte[] rawML = new byte[0];
            int endRecord = _startRecord + PDH.RecordCount -1;
            for (int i = _startRecord; i <= endRecord; i++)
            {
                byte[] buffer = new byte[PDB._recInfo[i + 1].RecordDataOffset - PDB._recInfo[i].RecordDataOffset];
                fs.Seek(PDB._recInfo[i].RecordDataOffset, SeekOrigin.Begin);
                fs.Read(buffer, 0, buffer.Length);
                buffer = trimTrailingDataEntries(buffer);
                byte[] result = decomp.unpack(buffer, PDB.MobiHeaderSize);
                rawML = rawML.Concat(result).ToArray();
            }
            return rawML;
        }