unzip_p.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /****************************************************************************
  2. ** Filename: unzip_p.h
  3. ** Last updated [dd/mm/yyyy]: 27/03/2011
  4. **
  5. ** pkzip 2.0 decompression.
  6. **
  7. ** Some of the code has been inspired by other open source projects,
  8. ** (mainly Info-Zip and Gilles Vollant's minizip).
  9. ** Compression and decompression actually uses the zlib library.
  10. **
  11. ** Copyright (C) 2007-2012 Angius Fabrizio. All rights reserved.
  12. **
  13. ** This file is part of the OSDaB project (http://osdab.42cows.org/).
  14. **
  15. ** This file may be distributed and/or modified under the terms of the
  16. ** GNU General Public License version 2 as published by the Free Software
  17. ** Foundation and appearing in the file LICENSE.GPL included in the
  18. ** packaging of this file.
  19. **
  20. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  21. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22. **
  23. ** See the file LICENSE.GPL that came with this software distribution or
  24. ** visit http://www.gnu.org/copyleft/gpl.html for GPL licensing information.
  25. **
  26. **********************************************************************/
  27. //
  28. // W A R N I N G
  29. // -------------
  30. //
  31. // This file is not part of the Zip/UnZip API. It exists purely as an
  32. // implementation detail. This header file may change from version to
  33. // version without notice, or even be removed.
  34. //
  35. // We mean it.
  36. //
  37. #ifndef OSDAB_UNZIP_P__H
  38. #define OSDAB_UNZIP_P__H
  39. #include "unzip.h"
  40. #include "zipentry_p.h"
  41. #include <QtCore/QObject>
  42. #include <QtCore/QtGlobal>
  43. // zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate())
  44. // we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;)
  45. #define UNZIP_READ_BUFFER (256*1024)
  46. OSDAB_BEGIN_NAMESPACE(Zip)
  47. class UnzipPrivate : public QObject
  48. {
  49. Q_OBJECT
  50. public:
  51. UnzipPrivate();
  52. // Replace this with whatever else you use to store/retrieve the password.
  53. QString password;
  54. bool skipAllEncrypted;
  55. QMap<QString,ZipEntryP*>* headers;
  56. QIODevice* device;
  57. QFile* file;
  58. char buffer1[UNZIP_READ_BUFFER];
  59. char buffer2[UNZIP_READ_BUFFER];
  60. unsigned char* uBuffer;
  61. const quint32* crcTable;
  62. // Central Directory (CD) offset
  63. quint32 cdOffset;
  64. // End of Central Directory (EOCD) offset
  65. quint32 eocdOffset;
  66. // Number of entries in the Central Directory (as to the EOCD record)
  67. quint16 cdEntryCount;
  68. // The number of detected entries that have been skipped because of a non compatible format
  69. quint16 unsupportedEntryCount;
  70. QString comment;
  71. UnZip::ErrorCode openArchive(QIODevice* device);
  72. UnZip::ErrorCode seekToCentralDirectory();
  73. UnZip::ErrorCode parseCentralDirectoryRecord();
  74. UnZip::ErrorCode parseLocalHeaderRecord(const QString& path, const ZipEntryP& entry);
  75. void closeArchive();
  76. UnZip::ErrorCode extractFile(const QString& path, const ZipEntryP& entry, const QDir& dir, UnZip::ExtractionOptions options);
  77. UnZip::ErrorCode extractFile(const QString& path, const ZipEntryP& entry, QIODevice* device, UnZip::ExtractionOptions options);
  78. UnZip::ErrorCode testPassword(quint32* keys, const QString& file, const ZipEntryP& header);
  79. bool testKeys(const ZipEntryP& header, quint32* keys);
  80. bool createDirectory(const QString& path);
  81. inline void decryptBytes(quint32* keys, char* buffer, qint64 read);
  82. inline quint32 getULong(const unsigned char* data, quint32 offset) const;
  83. inline quint64 getULLong(const unsigned char* data, quint32 offset) const;
  84. inline quint16 getUShort(const unsigned char* data, quint32 offset) const;
  85. inline int decryptByte(quint32 key2) const;
  86. inline void updateKeys(quint32* keys, int c) const;
  87. inline void initKeys(const QString& pwd, quint32* keys) const;
  88. inline QDateTime convertDateTime(const unsigned char date[2], const unsigned char time[2]) const;
  89. private slots:
  90. void deviceDestroyed(QObject*);
  91. private:
  92. UnZip::ErrorCode extractStoredFile(const quint32 szComp, quint32** keys,
  93. quint32& myCRC, QIODevice* outDev, UnZip::ExtractionOptions options);
  94. UnZip::ErrorCode inflateFile(const quint32 szComp, quint32** keys,
  95. quint32& myCRC, QIODevice* outDev, UnZip::ExtractionOptions options);
  96. void do_closeArchive();
  97. };
  98. OSDAB_END_NAMESPACE
  99. #endif // OSDAB_UNZIP_P__H