Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | // --------------------------------------------------------------------------- |
2 | |||
3 | #ifndef UnzSupH |
||
4 | #define UnzSupH |
||
5 | /* |
||
6 | |||
7 | Copyright (c) 1990-2007 Info-ZIP. All rights reserved. |
||
8 | |||
9 | See the accompanying file LICENSE, version 2007-Mar-4 or later |
||
10 | (the contents of which are also included in zip.h) for terms of use. |
||
11 | If, for some reason, all these files are missing, the Info-ZIP license |
||
12 | also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
||
13 | |||
14 | parts Copyright (C) 1997 Mike White, Eric W. Engler |
||
15 | ************************************************************************ |
||
16 | Copyright (C) 2009, 2010 by Russell J. Peters, Roger Aelbrecht |
||
17 | |||
18 | This file is part of TZipMaster Version 1.9. |
||
19 | |||
20 | TZipMaster is free software: you can redistribute it and/or modify |
||
21 | it under the terms of the GNU Lesser General Public License as published by |
||
22 | the Free Software Foundation, either version 3 of the License, or |
||
23 | (at your option) any later version. |
||
24 | |||
25 | TZipMaster is distributed in the hope that it will be useful, |
||
26 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
28 | GNU Lesser General Public License for more details. |
||
29 | |||
30 | You should have received a copy of the GNU Lesser General Public License |
||
31 | along with TZipMaster. If not, see <http://www.gnu.org/licenses/>. |
||
32 | |||
33 | contact: problems@delphizip.org (include ZipMaster in the subject). |
||
34 | updates: http://www.delphizip.org |
||
35 | DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip |
||
36 | *********************************************************************** */ |
||
37 | #include "dzoper.h" |
||
38 | #include "crypt.h" |
||
39 | #include "helpers.h" |
||
40 | |||
41 | #define SAFE_MAX_PATH ((MAX_PATH * 3) / 2) |
||
42 | #define SAFE_FILNAMSIZ (FILNAMSIZ + (FILNAMSIZ / 4)) |
||
43 | |||
44 | /* GRR 960218: testing a new feature...definitely *not* ready for primetime */ |
||
45 | #ifdef TIMESTAMP |
||
46 | # undef TIMESTAMP |
||
47 | #endif |
||
48 | |||
49 | /* Predefined, Machine-specific Macros */ |
||
50 | |||
51 | #if (!defined(MSDOS)) |
||
52 | # define MSDOS |
||
53 | #endif |
||
54 | |||
55 | // By defining COPYRIGHT_CLEAN, we lose support for these 2 compression |
||
56 | // types: tokenizing (which was never popular) |
||
57 | // and reducing (which was only used in pre-v1 beta releases of PKZIP |
||
58 | // #ifndef COPYRIGHT_CLEAN |
||
59 | # define COPYRIGHT_CLEAN |
||
60 | // #endif |
||
61 | |||
62 | # define NO_MULTIPART |
||
63 | |||
64 | #if (defined ASM_INFLATECODES) |
||
65 | # undef ASM_INFLATECODES |
||
66 | #endif |
||
67 | |||
68 | // EWE note: All platforms need this VMS version: |
||
69 | #define VMS_UNZIP_VERSION 42 |
||
70 | /* --------------------------------------------------------------------------- |
||
71 | Win32 section: |
||
72 | --------------------------------------------------------------------------- */ |
||
73 | |||
74 | /** ********** */ |
||
75 | |||
76 | /* Defines */ |
||
77 | |||
78 | /** ********** */ |
||
79 | #define UNZIP_VERSION 45 /* 20 / * compatible with PKUNZIP 2.0 */ |
||
80 | |||
81 | /* clean up with a few defaults */ |
||
82 | # define DATE_FORMAT DF_MDY /* defaults to US convention */ |
||
83 | |||
84 | /* Max. value of signed (>=32 bit) time_t */ |
||
85 | # define S_TIME_T_MAX ((time_t)(ulg)0x7FFFFFFFL) |
||
86 | |||
87 | /* Max. value of unsigned (>=32 bit) time_t */ |
||
88 | # define U_TIME_T_MAX ((time_t)(ulg)0xFFFFFFFFL) |
||
89 | |||
90 | #ifdef DOSDATE_2038_01_18 |
||
91 | # undef DOSDATE_2038_01_18 |
||
92 | #endif |
||
93 | #define DOSDATE_2038_01_18 ((ush)0x7432) |
||
94 | |||
95 | // defines for extraction |
||
96 | # define NEXTBYTE (--fincnt >= 0 ? (int)(*finptr++) : readbyte()) |
||
97 | |||
98 | #if (defined(SFX) && !defined(NO_ZIPINFO)) |
||
99 | # define NO_ZIPINFO |
||
100 | #endif |
||
101 | |||
102 | /* If <limits.h> exists on most systems, should include that, since it may |
||
103 | * define some or all of the following: NAME_MAX, PATH_MAX, _POSIX_NAME_MAX, |
||
104 | * _POSIX_PATH_MAX. |
||
105 | */ |
||
106 | #include <limits.h> |
||
107 | |||
108 | #ifndef PATH_MAX |
||
109 | # define PATH_MAX 1024 |
||
110 | #endif /* !PATH_MAX */ |
||
111 | |||
112 | #if __BORLANDC__ < 0x0560 |
||
113 | #define INVALID_FILE_ATTRIBUTES ((DWORD) -1) |
||
114 | #endif |
||
115 | |||
116 | #define FILNAMSIZ PATH_MAX |
||
117 | |||
118 | #define ZSUFX ".zip" |
||
119 | |||
120 | /* 9 and 10 not yet implemented */ |
||
121 | |||
122 | #define PK_OK 0 /* no error */ |
||
123 | #define PK_COOL 0 /* no error */ |
||
124 | #define PK_GNARLY 0 /* no error */ |
||
125 | #define PK_WARN DZ_ERR_WARNING //1 /* warning error */ |
||
126 | |||
127 | #define PK_ISWARN(e) (DZ_ERR(e) == DZ_ERR_WARNING) |
||
128 | #define PK_ERR_NOWARN(e) (DZ_ERR(e) && DZ_ERR(e) != DZ_ERR_WARNING) |
||
129 | |||
130 | int PK_Rank(int err); |
||
131 | #define PK_ERR DZ_ERM_GENERAL //2 /* error in zipfile */ |
||
132 | #define PK_BADERR DZ_ERM_INVAL_ZIP //3 /* severe error in zipfile */ |
||
133 | // #define PK_MEM 4 /* insufficient memory */ |
||
134 | // #define PK_MEM2 5 /* insufficient memory */ |
||
135 | // #define PK_MEM3 6 /* insufficient memory */ |
||
136 | // #define PK_MEM4 7 /* insufficient memory */ |
||
137 | // #define PK_MEM5 8 /* insufficient memory */ |
||
138 | #define PK_NOZIP DZ_ERM_INVAL_ZIP // 9 /* zipfile not found */ |
||
139 | // #define PK_PARAM DZ_ERM_BAD_OPTIONS // 10 /* bad or illegal parameters specified */ |
||
140 | #define PK_FIND DZ_ERM_MISS // 11 /* no files found */ |
||
141 | #define PK_DISKFULL DZ_ERM_ERROR_WRITE // 50 /* disk full */ |
||
142 | #define PK_EOF DZ_ERM_ZIP_EOF // 51 /* unexpected EOF */ |
||
143 | #define PK_DISK DZ_ERM_ERROR_CREATE // 52 // disk error |
||
144 | #define PK_NODEL DZ_ERM_ERROR_DELETE // 54 // could no delete old file |
||
145 | |||
146 | #define IZ_DIR 76 /* potential zipfile is a directory */ |
||
147 | // #define IZ_CREATED_DIR 77 /* directory created: set time and permissions */ |
||
148 | #define IZ_VOL_LABEL 78 /* volume label, but can't set on hard disk */ |
||
149 | // #define IZ_EF_TRUNC 79 /* local extra field truncated (PKZIP'd) */ |
||
150 | // #define IZ_SKIPPED 80 // 1.75 skipped file |
||
151 | #define IZ_CREATED_DIR -2 /* directory created: set time and permissions */ |
||
152 | #define IZ_SKIP_DIR -3 // directory exists: nothing to do |
||
153 | |||
154 | /* return codes of password fetches (negative = user abort; positive = error) */ |
||
155 | #define IZ_PW_ENTERED 0 /* got some password string; use/try it */ |
||
156 | #define IZ_PW_CANCEL -1 /* no password available (for this entry) */ |
||
157 | #define IZ_PW_CANCELALL -2 /* no password, skip any further pwd. request */ |
||
158 | // #define IZ_PW_ERROR 5 /* = PK_MEM2 : failure (no mem, no tty, ...) */ |
||
159 | |||
160 | #define DF_MDY 0 /* date format 10/26/91 (USA only) */ |
||
161 | #define DF_DMY 1 /* date format 26/10/91 (most of the world) */ |
||
162 | #define DF_YMD 2 /* date format 91/10/26 (a few countries) */ |
||
163 | |||
164 | class UnzFileSpec |
||
165 | { |
||
166 | TCHAR *fFileSpec; |
||
167 | unsigned fHash; |
||
168 | DZStrW fExcludes; |
||
169 | const char *fPassword; // pointer to list |
||
170 | const BaseRec *fBase; // pointer to list |
||
171 | inline const TCHAR* GetFileSpec(void)const |
||
172 | { |
||
173 | return(const TCHAR*)fFileSpec; |
||
174 | } |
||
175 | |||
176 | // void __fastcall SetFileSpec(const TCHAR *value); |
||
177 | inline DZStrW GetSpec(void)const |
||
178 | { |
||
179 | return DZStrW(fFileSpec); |
||
180 | } |
||
181 | void __fastcall SetSpec(const DZStrW& value); |
||
182 | |||
183 | inline const char* GetPassword(void)const |
||
184 | { |
||
185 | return(const char*)fPassword; |
||
186 | } |
||
187 | |||
188 | inline DZStrA GetPassw(void)const |
||
189 | { |
||
190 | return DZStrA(fPassword); |
||
191 | } |
||
192 | void __fastcall SetPassw(const DZStrA& value); |
||
193 | |||
194 | inline DZStrW GetExtBase(void)const |
||
195 | { |
||
196 | return DZStrW(fBase->Base); |
||
197 | } |
||
198 | |||
199 | inline DZStrW& GetExcludes(void) |
||
200 | { |
||
201 | return fExcludes; |
||
202 | } |
||
203 | inline void SetExcludes(const DZStrW& value) |
||
204 | { |
||
205 | fExcludes = value; |
||
206 | } |
||
207 | |||
208 | public: |
||
209 | long Match; |
||
210 | // used by extract for searches |
||
211 | UnzFileSpec(); |
||
212 | ~UnzFileSpec(); |
||
213 | __property const TCHAR *FileSpec = |
||
214 | { |
||
215 | read = GetFileSpec |
||
216 | }; // ,write=SetFileSpec}; |
||
217 | __property DZStrW Spec = |
||
218 | { |
||
219 | read = GetSpec, write = SetSpec |
||
220 | }; |
||
221 | __property const char *Password = |
||
222 | { |
||
223 | read = GetPassword, write = fPassword |
||
224 | }; |
||
225 | __property DZStrA Passw = |
||
226 | { |
||
227 | read = GetPassw, write = SetPassw |
||
228 | }; |
||
229 | __property const BaseRec* Base = |
||
230 | { |
||
231 | read = fBase, write = fBase |
||
232 | }; |
||
233 | __property DZStrW ExtBase = |
||
234 | { |
||
235 | read = GetExtBase |
||
236 | }; |
||
237 | __property unsigned Hash = |
||
238 | { |
||
239 | read = fHash |
||
240 | }; |
||
241 | __property DZStrW Excludes = |
||
242 | { |
||
243 | read = GetExcludes, write = SetExcludes |
||
244 | }; |
||
245 | }; |
||
246 | |||
247 | class CHdrInfo |
||
248 | { |
||
249 | private: |
||
250 | char* fhname; // header name field |
||
251 | const TCHAR* fxname; |
||
252 | |||
253 | void __fastcall Setxname(const TCHAR *value); |
||
254 | |||
255 | inline DZStrW GetXName(void)const |
||
256 | { |
||
257 | return DZStrW(fxname); |
||
258 | } |
||
259 | |||
260 | inline void __fastcall SetXName(const DZStrW& value) |
||
261 | { |
||
262 | Setxname(value.c_str()); |
||
263 | } |
||
264 | |||
265 | inline const char* Gethname(void)const |
||
266 | { |
||
267 | return(const char*)fhname; |
||
268 | } |
||
269 | void __fastcall Sethname(const char* value); |
||
270 | |||
271 | inline DZStrA GetHName(void)const |
||
272 | { |
||
273 | return DZStrA(fhname); |
||
274 | } |
||
275 | |||
276 | inline void __fastcall SetHName(const DZStrA& value) |
||
277 | { |
||
278 | Sethname(value.c_str()); |
||
279 | } |
||
280 | bool __fastcall GetIsFolder(void)const; |
||
281 | |||
282 | public: |
||
283 | ZInt64 offset; |
||
284 | ZInt64 compr_size; // compressed size (needed if extended header) |
||
285 | ZInt64 uncomp_size; // new - limit output size |
||
286 | ulg crc; // crc (needed if extended header) |
||
287 | unsigned file_attr; |
||
288 | // local flavor, as used by creat(), chmod()... |
||
289 | union |
||
290 | { |
||
291 | struct |
||
292 | { |
||
293 | // unsigned file_attr; // local flavor, as used by creat(), chmod()... |
||
294 | unsigned host : 16; |
||
295 | // unsigned hostnum: 8; |
||
296 | // unsigned hostver: 8; |
||
297 | unsigned encrypted : 1; // file encrypted: decrypt before uncompressing |
||
298 | unsigned ExtLocHdr : 1; // use time instead of CRC for decrypt check |
||
299 | unsigned textfile : 1; // file is text (according to zip) |
||
300 | unsigned textmode : 1; // file is to be extracted as text |
||
301 | unsigned vollabel : 1; // "file" is an MS-DOS volume (disk) label |
||
302 | unsigned UTF8flag : 1; // set if flag utf8 flag set |
||
303 | // unsigned PKZflag: 1; // possible made by PKZIP |
||
304 | unsigned UNIXflag : 1; // possible made on unix |
||
305 | // unsigned nouse: 11; //10; |
||
306 | }; |
||
307 | unsigned long _flags; |
||
308 | }; |
||
309 | |||
310 | unsigned chdrseq; |
||
311 | // unsigned hash; // hash of uppercase filename |
||
312 | const XNTFSData *ntfs_data; |
||
313 | UnzFileSpec *spec; // the spec line |
||
314 | CHdrInfo *next; |
||
315 | |||
316 | CHdrInfo(); |
||
317 | ~CHdrInfo(); |
||
318 | void Clear(void); |
||
319 | DZStrW __fastcall FullPath(void)const; // full path of name |
||
320 | __property const TCHAR *xname = |
||
321 | { |
||
322 | read = fxname, write = Setxname |
||
323 | }; |
||
324 | __property DZStrW XName = |
||
325 | { |
||
326 | read = GetXName, write = SetXName |
||
327 | }; |
||
328 | __property const char *hname = |
||
329 | { |
||
330 | read = Gethname, write = Sethname |
||
331 | }; |
||
332 | __property DZStrA HName = |
||
333 | { |
||
334 | read = GetHName, write = SetHName |
||
335 | }; |
||
336 | __property bool IsFolder = |
||
337 | { |
||
338 | read = GetIsFolder |
||
339 | }; |
||
340 | }; |
||
341 | |||
342 | class UnzSup : public DZOp |
||
343 | { |
||
344 | private: |
||
345 | UnzSup(void); |
||
346 | UnzSup(const UnzSup&); |
||
347 | UnzSup& operator = (const UnzSup&); |
||
348 | |||
349 | protected: |
||
350 | bool fredirect_data; // redirect data to memory buffer |
||
351 | ZInt64 fMax_Write; // maximum bytes to write |
||
352 | unsigned f_wsize; |
||
353 | uch *fredirect_pointer; |
||
354 | uch *fredirect_buffer; |
||
355 | unsigned fredirect_size; |
||
356 | unsigned fbuffer_size; |
||
357 | |||
358 | CHdrInfo *chdrList; |
||
359 | CHdrInfo *fpInfo; |
||
360 | int chdrCount; |
||
361 | bool Encrypted; // current file setting |
||
362 | |||
363 | ZInt64 fcsize; /* used by list_files(), NEXTBYTE: must be signed */ |
||
364 | ZInt64 fucsize; /* used by list_files(), unReduce(), explode() */ |
||
365 | ZInt64 fused_csize; /* used by extract_or_test_member(), explode() */ |
||
366 | ZInt64 fcur_zipfile_bufstart; /* extract_or_test, readbuf, ReadByte */ |
||
367 | |||
368 | int fincnt_leftover; /* so improved NEXTBYTE does not waste input */ |
||
369 | uch *finptr_leftover; |
||
370 | uch *foutbufptr; /* extract.c static */ |
||
371 | ulg foutsize; /* extract.c static */ |
||
372 | int freported_backslash; /* extract.c static */ |
||
373 | |||
374 | ulg fcrc32val; /* CRC shift reg. (was static in funzip) */ |
||
375 | |||
376 | uch *finbuf; /* input buffer (any size is OK) */ |
||
377 | uch *finptr; /* pointer into input buffer */ |
||
378 | int fincnt; |
||
379 | ulg fbitbuf; |
||
380 | int fbits_left; /* unreduce and unshrink only */ |
||
381 | int fzipeof; |
||
382 | DZStrW fzipfn; |
||
383 | ZStreamIO *fUnzInfile; // zipfile |
||
384 | ZStreamIO *fUnzOutfile; // stream being written |
||
385 | ZInt64 fextra_bytes; |
||
386 | Keys fkeys; /* crypt static: keys defining pseudo-random sequence */ |
||
387 | |||
388 | int fmem_mode; |
||
389 | uch *foutbuf; |
||
390 | uch *frealbuf; |
||
391 | |||
392 | uch *foutbuf2; /* main() (never changes); else malloc'd */ |
||
393 | uch *foutptr; |
||
394 | ulg foutcnt; /* number of chars stored in outbuf */ |
||
395 | int fnewfile; |
||
396 | bool InProgress; |
||
397 | |||
398 | char fTextLast; // last text convert buffer character |
||
399 | int fsol; /* fileio static: at start of line */ |
||
400 | int fdisk_full; |
||
401 | DZStrW ffilename; |
||
402 | |||
403 | int readbyte(void); |
||
404 | int part_flush(uch * rawbuf, ulg size, int unshrink); |
||
405 | int flush(uch * rawbuf, ulg size, int unshrink); |
||
406 | int vclRead(void * buf, unsigned LenToRead); |
||
407 | int zlseek(ZInt64 abs_offset); |
||
408 | void undefer_input(void); |
||
409 | void defer_leftover_input(void); |
||
410 | unsigned __fastcall readbuf(char * buf, unsigned size); |
||
411 | |||
412 | public: |
||
413 | int fqflag; /* -q: produce a lot less output */ |
||
414 | int ftflag; |
||
415 | /* -t: test (unzip) or totals line (zipinfo) */ |
||
416 | UnzSup(const DllCommands *C); |
||
417 | ~UnzSup(void); |
||
418 | DZStrW __fastcall FullPath(const CHdrInfo* info)const; |
||
419 | |||
420 | private: |
||
421 | int disk_error(void); |
||
422 | }; |
||
423 | |||
424 | unsigned HashFunc(const DZStrW & strng); |
||
425 | |||
426 | #endif |