unzip_p.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Filename: unzip_p.h
00003 ** Last updated [dd/mm/yyyy]: 28/01/2007
00004 **
00005 ** pkzip 2.0 decompression.
00006 **
00007 ** Some of the code has been inspired by other open source projects,
00008 ** (mainly Info-Zip and Gilles Vollant's minizip).
00009 ** Compression and decompression actually uses the zlib library.
00010 **
00011 ** Copyright (C) 2007 Angius Fabrizio. All rights reserved.
00012 **
00013 ** This file is part of the OSDaB project (http://osdab.sourceforge.net/).
00014 **
00015 ** This file may be distributed and/or modified under the terms of the
00016 ** GNU General Public License version 2 as published by the Free Software
00017 ** Foundation and appearing in the file LICENSE.GPL included in the
00018 ** packaging of this file.
00019 **
00020 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022 **
00023 ** See the file LICENSE.GPL that came with this software distribution or
00024 ** visit http://www.gnu.org/copyleft/gpl.html for GPL licensing information.
00025 **
00026 **********************************************************************/
00027 
00028 //
00029 //  W A R N I N G
00030 //  -------------
00031 //
00032 // This file is not part of the Zip/UnZip API.  It exists purely as an
00033 // implementation detail. This header file may change from version to
00034 // version without notice, or even be removed.
00035 //
00036 // We mean it.
00037 //
00038 
00039 #ifndef OSDAB_UNZIP_P__H
00040 #define OSDAB_UNZIP_P__H
00041 
00042 #include "unzip.h"
00043 #include "zipentry_p.h"
00044 
00045 #include <QtGlobal>
00046 
00047 // zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate())
00048 // we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;)
00049 #define UNZIP_READ_BUFFER (256*1024)
00050 
00051 class UnzipPrivate
00052 {
00053 public:
00054     UnzipPrivate();
00055 
00056     // Replace this with whatever else you use to store/retrieve the password.
00057     QString password;
00058 
00059     bool skipAllEncrypted;
00060 
00061     QMap<QString,ZipEntryP*>* headers;
00062 
00063     QIODevice* device;
00064 
00065     char buffer1[UNZIP_READ_BUFFER];
00066     char buffer2[UNZIP_READ_BUFFER];
00067 
00068     unsigned char* uBuffer;
00069     const quint32* crcTable;
00070 
00071     // Central Directory (CD) offset
00072     quint32 cdOffset;
00073     // End of Central Directory (EOCD) offset
00074     quint32 eocdOffset;
00075 
00076     // Number of entries in the Central Directory (as to the EOCD record)
00077     quint16 cdEntryCount;
00078 
00079     // The number of detected entries that have been skipped because of a non compatible format
00080     quint16 unsupportedEntryCount;
00081 
00082     QString comment;
00083 
00084     UnZip::ErrorCode openArchive(QIODevice* device);
00085 
00086     UnZip::ErrorCode seekToCentralDirectory();
00087     UnZip::ErrorCode parseCentralDirectoryRecord();
00088     UnZip::ErrorCode parseLocalHeaderRecord(const QString& path, ZipEntryP& entry);
00089 
00090     void closeArchive();
00091 
00092     UnZip::ErrorCode extractFile(const QString& path, ZipEntryP& entry, const QDir& dir, UnZip::ExtractionOptions options);
00093     UnZip::ErrorCode extractFile(const QString& path, ZipEntryP& entry, QIODevice* device, UnZip::ExtractionOptions options);
00094 
00095     UnZip::ErrorCode testPassword(quint32* keys, const QString& file, const ZipEntryP& header);
00096     bool testKeys(const ZipEntryP& header, quint32* keys);
00097 
00098     bool createDirectory(const QString& path);
00099 
00100     inline void decryptBytes(quint32* keys, char* buffer, qint64 read);
00101 
00102     inline quint32 getULong(const unsigned char* data, quint32 offset) const;
00103     inline quint64 getULLong(const unsigned char* data, quint32 offset) const;
00104     inline quint16 getUShort(const unsigned char* data, quint32 offset) const;
00105     inline int decryptByte(quint32 key2) const;
00106     inline void updateKeys(quint32* keys, int c) const;
00107     inline void initKeys(const QString& pwd, quint32* keys) const;
00108 
00109     inline QDateTime convertDateTime(const unsigned char date[2], const unsigned char time[2]) const;
00110 };
00111 
00112 #endif // OSDAB_UNZIP_P__H