MythTV  master
unzip_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Filename: unzip_p.h
3 ** Last updated [dd/mm/yyyy]: 28/01/2007
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-2008 Angius Fabrizio. All rights reserved.
12 **
13 ** This file is part of the OSDaB project (http://osdab.sourceforge.net/).
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 //
29 // W A R N I N G
30 // -------------
31 //
32 // This file is not part of the Zip/UnZip API. It exists purely as an
33 // implementation detail. This header file may change from version to
34 // version without notice, or even be removed.
35 //
36 // We mean it.
37 //
38 
39 #ifndef OSDAB_UNZIP_P_H
40 #define OSDAB_UNZIP_P_H
41 
42 #include "unzip.h"
43 #include "zipentry_p.h"
44 
45 #include <QtGlobal>
46 
47 using keyset = std::array<quint32,3>;
48 
49 // zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate())
50 // we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;)
51 #define UNZIP_READ_BUFFER (256*1024)
52 
54 {
55 public:
56  UnzipPrivate();
57 
58  // Replace this with whatever else you use to store/retrieve the password.
59  QString password;
60 
61  bool skipAllEncrypted {false};
62 
63  QMap<QString,ZipEntryP*>* headers {nullptr};
64 
65  QIODevice* device {nullptr};
66 
69 
70  unsigned char* uBuffer;
71  const quint32* crcTable;
72 
73  // Central Directory (CD) offset
74  quint32 cdOffset {0};
75  // End of Central Directory (EOCD) offset
76  quint32 eocdOffset {0};
77 
78  // Number of entries in the Central Directory (as to the EOCD record)
79  quint16 cdEntryCount {0};
80 
81  // The number of detected entries that have been skipped because of a non compatible format
82  quint16 unsupportedEntryCount {0};
83 
84  QString comment;
85 
87 
90  UnZip::ErrorCode parseLocalHeaderRecord(const QString& path, ZipEntryP& entry);
91 
92  void closeArchive();
93 
94  UnZip::ErrorCode extractFile(const QString& path, ZipEntryP& entry, const QDir& dir, UnZip::ExtractionOptions options);
95  UnZip::ErrorCode extractFile(const QString& path, ZipEntryP& entry, QIODevice* device, UnZip::ExtractionOptions options);
96 
97  UnZip::ErrorCode testPassword(keyset keys, const QString& file, const ZipEntryP& header);
98  bool testKeys(const ZipEntryP& header, keyset keys);
99 
100  bool createDirectory(const QString& path);
101 
102  inline void decryptBytes(keyset keys, char* buffer, qint64 read) const;
103 
104  static inline quint32 getULong(const unsigned char* data, quint32 offset) ;
105  static inline quint64 getULLong(const unsigned char* data, quint32 offset) ;
106  static inline quint16 getUShort(const unsigned char* data, quint32 offset) ;
107  static inline int decryptByte(quint32 key2) ;
108  inline void updateKeys(keyset keys, int c) const;
109  inline void initKeys(const QString& pwd, keyset keys) const;
110 
111  static inline QDateTime convertDateTime(const std::array<uint8_t,2> &date, const std::array<uint8_t,2> &time) ;
112 };
113 
114 #endif // OSDAB_UNZIP_P_H
UnzipPrivate::device
QIODevice * device
Definition: unzip_p.h:65
UnzipPrivate::password
QString password
Definition: unzip_p.h:59
UnzipPrivate::comment
QString comment
Definition: unzip_p.h:84
UnzipPrivate::getUShort
static quint16 getUShort(const unsigned char *data, quint32 offset)
Definition: unzip.cpp:1266
discid.disc.read
def read(device=None, features=[])
Definition: disc.py:35
keyset
std::array< quint32, 3 > keyset
Definition: unzip_p.h:47
UnzipPrivate::createDirectory
bool createDirectory(const QString &path)
Definition: unzip.cpp:1212
UnzipPrivate::skipAllEncrypted
bool skipAllEncrypted
Definition: unzip_p.h:61
UnzipPrivate::getULLong
static quint64 getULLong(const unsigned char *data, quint32 offset)
Definition: unzip.cpp:1249
UnzipPrivate::closeArchive
void closeArchive()
Definition: unzip.cpp:965
unzip.h
ZipEntryP
Definition: zipentry_p.h:48
build_compdb.file
file
Definition: build_compdb.py:55
UnzipPrivate::getULong
static quint32 getULong(const unsigned char *data, quint32 offset)
Definition: unzip.cpp:1236
UnzipPrivate
Definition: unzip_p.h:54
UnzipPrivate::decryptBytes
void decryptBytes(keyset keys, char *buffer, qint64 read) const
Definition: unzip.cpp:1352
UNZIP_READ_BUFFER
#define UNZIP_READ_BUFFER
Definition: unzip_p.h:51
UnzipPrivate::cdOffset
quint32 cdOffset
Definition: unzip_p.h:74
UnzipPrivate::unsupportedEntryCount
quint16 unsupportedEntryCount
Definition: unzip_p.h:82
UnzipPrivate::UnzipPrivate
UnzipPrivate()
Definition: unzip.cpp:520
UnzipPrivate::openArchive
UnZip::ErrorCode openArchive(QIODevice *device)
Definition: unzip.cpp:527
zipentry_p.h
UnzipPrivate::uBuffer
unsigned char * uBuffer
Definition: unzip_p.h:70
UnzipPrivate::testKeys
bool testKeys(const ZipEntryP &header, keyset keys)
Definition: unzip.cpp:1333
UnzipPrivate::testPassword
UnZip::ErrorCode testPassword(keyset keys, const QString &file, const ZipEntryP &header)
Definition: unzip.cpp:1314
UnzipPrivate::initKeys
void initKeys(const QString &pwd, keyset keys) const
Definition: unzip.cpp:1295
UnZip::ErrorCode
ErrorCode
Definition: unzip.h:53
UnzipPrivate::parseCentralDirectoryRecord
UnZip::ErrorCode parseCentralDirectoryRecord()
Definition: unzip.cpp:856
UnzipPrivate::extractFile
UnZip::ErrorCode extractFile(const QString &path, ZipEntryP &entry, const QDir &dir, UnZip::ExtractionOptions options)
Definition: unzip.cpp:989
UnzipPrivate::parseLocalHeaderRecord
UnZip::ErrorCode parseLocalHeaderRecord(const QString &path, ZipEntryP &entry)
Definition: unzip.cpp:597
UnzipPrivate::updateKeys
void updateKeys(keyset keys, int c) const
Definition: unzip.cpp:1283
UnzipPrivate::crcTable
const quint32 * crcTable
Definition: unzip_p.h:71
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1174
UnzipPrivate::convertDateTime
static QDateTime convertDateTime(const std::array< uint8_t, 2 > &date, const std::array< uint8_t, 2 > &time)
Definition: unzip.cpp:1361
UnzipPrivate::cdEntryCount
quint16 cdEntryCount
Definition: unzip_p.h:79
UnzipPrivate::eocdOffset
quint32 eocdOffset
Definition: unzip_p.h:76
UnzipPrivate::decryptByte
static int decryptByte(quint32 key2)
Definition: unzip.cpp:1274
UnzipPrivate::buffer1
char buffer1[UNZIP_READ_BUFFER]
Definition: unzip_p.h:67
UnzipPrivate::headers
QMap< QString, ZipEntryP * > * headers
Definition: unzip_p.h:63
UnzipPrivate::buffer2
char buffer2[UNZIP_READ_BUFFER]
Definition: unzip_p.h:68
UnzipPrivate::seekToCentralDirectory
UnZip::ErrorCode seekToCentralDirectory()
Definition: unzip.cpp:732
build_compdb.options
options
Definition: build_compdb.py:11