00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "pent_include.h"
00040 #define NOUNCRYPT
00041
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <string.h>
00045 #include "zlib.h"
00046 #include "unzip.h"
00047
00048 #ifdef STDC
00049 # include <stddef.h>
00050 # include <string.h>
00051 # include <stdlib.h>
00052 #endif
00053 #ifdef NO_ERRNO_H
00054 extern int errno;
00055 #else
00056 # include <errno.h>
00057 #endif
00058
00059
00060
00061 #ifndef local
00062 # define local static
00063 #endif
00064
00065
00066
00067 #ifndef CASESENSITIVITYDEFAULT_NO
00068 # if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
00069 # define CASESENSITIVITYDEFAULT_NO
00070 # endif
00071 #endif
00072
00073
00074 #ifndef UNZ_BUFSIZE
00075 #define UNZ_BUFSIZE (16384)
00076 #endif
00077
00078 #ifndef UNZ_MAXFILENAMEINZIP
00079 #define UNZ_MAXFILENAMEINZIP (256)
00080 #endif
00081
00082 #ifndef ALLOC
00083 # define ALLOC(size) (malloc(size))
00084 #endif
00085 #ifndef TRYFREE
00086 # define TRYFREE(p) {if (p) free(p);}
00087 #endif
00088
00089 #define SIZECENTRALDIRITEM (0x2e)
00090 #define SIZEZIPLOCALHEADER (0x1e)
00091
00092 namespace PentZip {
00093
00094
00095 const char unz_copyright[] =
00096 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
00097
00098
00099 typedef struct unz_file_info_internal_s
00100 {
00101 uLong offset_curfile;
00102 } unz_file_info_internal;
00103
00104
00105
00106
00107 typedef struct
00108 {
00109 char *read_buffer;
00110 z_stream stream;
00111
00112 uLong pos_in_zipfile;
00113 uLong stream_initialised;
00114
00115 uLong offset_local_extrafield;
00116 uInt size_local_extrafield;
00117 uLong pos_local_extrafield;
00118
00119 uLong crc32;
00120 uLong crc32_wait;
00121 uLong rest_read_compressed;
00122 uLong rest_read_uncompressed;
00123 zlib_filefunc_def z_filefunc;
00124 voidpf filestream;
00125 uLong compression_method;
00126 uLong byte_before_the_zipfile;
00127 int raw;
00128 } file_in_zip_read_info_s;
00129
00130
00131
00132
00133 typedef struct
00134 {
00135 zlib_filefunc_def z_filefunc;
00136 voidpf filestream;
00137 unz_global_info gi;
00138 uLong byte_before_the_zipfile;
00139 uLong num_file;
00140 uLong pos_in_central_dir;
00141 uLong current_file_ok;
00142 uLong central_pos;
00143
00144 uLong size_central_dir;
00145 uLong offset_central_dir;
00146
00147
00148 unz_file_info cur_file_info;
00149 unz_file_info_internal cur_file_info_internal;
00150 file_in_zip_read_info_s* pfile_in_zip_read;
00151
00152 int encrypted;
00153 # ifndef NOUNCRYPT
00154 unsigned long keys[3];
00155 const unsigned long* pcrc_32_tab;
00156 # endif
00157 } unz_s;
00158
00159
00160 #ifndef NOUNCRYPT
00161 #include "crypt.h"
00162 #endif
00163
00164
00165
00166
00167
00168
00169
00170
00171 local int unzlocal_getByte OF((
00172 const zlib_filefunc_def* pzlib_filefunc_def,
00173 voidpf filestream,
00174 int *pi));
00175
00176 local int unzlocal_getByte(const zlib_filefunc_def* pzlib_filefunc_def,
00177 voidpf filestream, int *pi)
00178 {
00179 unsigned char c;
00180 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
00181 if (err==1)
00182 {
00183 *pi = (int)c;
00184 return UNZ_OK;
00185 }
00186 else
00187 {
00188 if (ZERROR(*pzlib_filefunc_def,filestream))
00189 return UNZ_ERRNO;
00190 else
00191 return UNZ_EOF;
00192 }
00193 }
00194
00195
00196
00197
00198
00199 local int unzlocal_getShort OF((
00200 const zlib_filefunc_def* pzlib_filefunc_def,
00201 voidpf filestream,
00202 uLong *pX));
00203
00204 local int unzlocal_getShort (const zlib_filefunc_def* pzlib_filefunc_def,
00205 voidpf filestream, uLong *pX)
00206 {
00207 uLong x ;
00208 int i;
00209 int err;
00210
00211 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
00212 x = (uLong)i;
00213
00214 if (err==UNZ_OK)
00215 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
00216 x += ((uLong)i)<<8;
00217
00218 if (err==UNZ_OK)
00219 *pX = x;
00220 else
00221 *pX = 0;
00222 return err;
00223 }
00224
00225 local int unzlocal_getLong OF((
00226 const zlib_filefunc_def* pzlib_filefunc_def,
00227 voidpf filestream,
00228 uLong *pX));
00229
00230 local int unzlocal_getLong (const zlib_filefunc_def* pzlib_filefunc_def,
00231 voidpf filestream, uLong *pX)
00232 {
00233 uLong x ;
00234 int i;
00235 int err;
00236
00237 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
00238 x = (uLong)i;
00239
00240 if (err==UNZ_OK)
00241 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
00242 x += ((uLong)i)<<8;
00243
00244 if (err==UNZ_OK)
00245 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
00246 x += ((uLong)i)<<16;
00247
00248 if (err==UNZ_OK)
00249 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
00250 x += ((uLong)i)<<24;
00251
00252 if (err==UNZ_OK)
00253 *pX = x;
00254 else
00255 *pX = 0;
00256 return err;
00257 }
00258
00259
00260
00261 local int strcmpcasenosensitive_internal (const char* fileName1,
00262 const char* fileName2)
00263 {
00264 for (;;)
00265 {
00266 char c1=*(fileName1++);
00267 char c2=*(fileName2++);
00268 if ((c1>='a') && (c1<='z'))
00269 c1 -= 0x20;
00270 if ((c2>='a') && (c2<='z'))
00271 c2 -= 0x20;
00272 if (c1=='\0')
00273 return ((c2=='\0') ? 0 : -1);
00274 if (c2=='\0')
00275 return 1;
00276 if (c1<c2)
00277 return -1;
00278 if (c1>c2)
00279 return 1;
00280 }
00281 }
00282
00283
00284 #ifdef CASESENSITIVITYDEFAULT_NO
00285 #define CASESENSITIVITYDEFAULTVALUE 2
00286 #else
00287 #define CASESENSITIVITYDEFAULTVALUE 1
00288 #endif
00289
00290 #ifndef STRCMPCASENOSENTIVEFUNCTION
00291 #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
00292 #endif
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
00304 const char* fileName2,
00305 int iCaseSensitivity)
00306 {
00307 if (iCaseSensitivity==0)
00308 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
00309
00310 if (iCaseSensitivity==1)
00311 return strcmp(fileName1,fileName2);
00312
00313 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
00314 }
00315
00316 #ifndef BUFREADCOMMENT
00317 #define BUFREADCOMMENT (0x400)
00318 #endif
00319
00320
00321
00322
00323
00324 local uLong unzlocal_SearchCentralDir OF((
00325 const zlib_filefunc_def* pzlib_filefunc_def,
00326 voidpf filestream));
00327
00328 local uLong unzlocal_SearchCentralDir(const zlib_filefunc_def* pzlib_filefunc_def, voidpf filestream)
00329 {
00330 unsigned char* buf;
00331 uLong uSizeFile;
00332 uLong uBackRead;
00333 uLong uMaxBack=0xffff;
00334 uLong uPosFound=0;
00335
00336 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
00337 return 0;
00338
00339
00340 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
00341
00342 if (uMaxBack>uSizeFile)
00343 uMaxBack = uSizeFile;
00344
00345 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
00346 if (buf==NULL)
00347 return 0;
00348
00349 uBackRead = 4;
00350 while (uBackRead<uMaxBack)
00351 {
00352 uLong uReadSize,uReadPos ;
00353 int i;
00354 if (uBackRead+BUFREADCOMMENT>uMaxBack)
00355 uBackRead = uMaxBack;
00356 else
00357 uBackRead+=BUFREADCOMMENT;
00358 uReadPos = uSizeFile-uBackRead ;
00359
00360 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
00361 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
00362 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
00363 break;
00364
00365 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
00366 break;
00367
00368 for (i=(int)uReadSize-3; (i--)>0;)
00369 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
00370 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
00371 {
00372 uPosFound = uReadPos+i;
00373 break;
00374 }
00375
00376 if (uPosFound!=0)
00377 break;
00378 }
00379 TRYFREE(buf);
00380 return uPosFound;
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 extern unzFile ZEXPORT unzOpen2 (const char *path,
00393 zlib_filefunc_def* pzlib_filefunc_def)
00394 {
00395 unz_s us;
00396 unz_s *s;
00397 uLong central_pos,uL;
00398
00399 uLong number_disk;
00400
00401 uLong number_disk_with_CD;
00402
00403 uLong number_entry_CD;
00404
00405
00406
00407 int err=UNZ_OK;
00408
00409 if (unz_copyright[0]!=' ')
00410 return NULL;
00411
00412 if (pzlib_filefunc_def==NULL)
00413 fill_fopen_filefunc(&us.z_filefunc);
00414 else
00415 us.z_filefunc = *pzlib_filefunc_def;
00416
00417 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
00418 path,
00419 ZLIB_FILEFUNC_MODE_READ |
00420 ZLIB_FILEFUNC_MODE_EXISTING);
00421 if (us.filestream==NULL)
00422 return NULL;
00423
00424 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
00425 if (central_pos==0)
00426 err=UNZ_ERRNO;
00427
00428 if (ZSEEK(us.z_filefunc, us.filestream,
00429 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
00430 err=UNZ_ERRNO;
00431
00432
00433 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
00434 err=UNZ_ERRNO;
00435
00436
00437 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
00438 err=UNZ_ERRNO;
00439
00440
00441 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
00442 err=UNZ_ERRNO;
00443
00444
00445 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
00446 err=UNZ_ERRNO;
00447
00448
00449 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
00450 err=UNZ_ERRNO;
00451
00452 if ((number_entry_CD!=us.gi.number_entry) ||
00453 (number_disk_with_CD!=0) ||
00454 (number_disk!=0))
00455 err=UNZ_BADZIPFILE;
00456
00457
00458 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
00459 err=UNZ_ERRNO;
00460
00461
00462
00463 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
00464 err=UNZ_ERRNO;
00465
00466
00467 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
00468 err=UNZ_ERRNO;
00469
00470 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
00471 (err==UNZ_OK))
00472 err=UNZ_BADZIPFILE;
00473
00474 if (err!=UNZ_OK)
00475 {
00476 ZCLOSE(us.z_filefunc, us.filestream);
00477 return NULL;
00478 }
00479
00480 us.byte_before_the_zipfile = central_pos -
00481 (us.offset_central_dir+us.size_central_dir);
00482 us.central_pos = central_pos;
00483 us.pfile_in_zip_read = NULL;
00484 us.encrypted = 0;
00485
00486
00487 s=(unz_s*)ALLOC(sizeof(unz_s));
00488 *s=us;
00489 unzGoToFirstFile((unzFile)s);
00490 return (unzFile)s;
00491 }
00492
00493
00494 extern unzFile ZEXPORT unzOpen (const char *path)
00495 {
00496 return unzOpen2(path, NULL);
00497 }
00498
00499
00500
00501
00502
00503
00504 extern int ZEXPORT unzClose (unzFile file)
00505 {
00506 unz_s* s;
00507 if (file==NULL)
00508 return UNZ_PARAMERROR;
00509 s=(unz_s*)file;
00510
00511 if (s->pfile_in_zip_read!=NULL)
00512 unzCloseCurrentFile(file);
00513
00514 ZCLOSE(s->z_filefunc, s->filestream);
00515 TRYFREE(s);
00516 return UNZ_OK;
00517 }
00518
00519
00520
00521
00522
00523
00524 extern int ZEXPORT unzGetGlobalInfo (unzFile file,
00525 unz_global_info *pglobal_info)
00526 {
00527 unz_s* s;
00528 if (file==NULL)
00529 return UNZ_PARAMERROR;
00530 s=(unz_s*)file;
00531 *pglobal_info=s->gi;
00532 return UNZ_OK;
00533 }
00534
00535
00536
00537
00538
00539 local void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz* ptm)
00540 {
00541 uLong uDate;
00542 uDate = (uLong)(ulDosDate>>16);
00543 ptm->tm_mday = (uInt)(uDate&0x1f) ;
00544 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
00545 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
00546
00547 ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
00548 ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
00549 ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
00550 }
00551
00552
00553
00554
00555 local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
00556 unz_file_info *pfile_info,
00557 unz_file_info_internal
00558 *pfile_info_internal,
00559 char *szFileName,
00560 uLong fileNameBufferSize,
00561 void *extraField,
00562 uLong extraFieldBufferSize,
00563 char *szComment,
00564 uLong commentBufferSize));
00565
00566 local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
00567 unz_file_info *pfile_info,
00568 unz_file_info_internal *pfile_info_internal,
00569 char *szFileName,
00570 uLong fileNameBufferSize,
00571 void *extraField,
00572 uLong extraFieldBufferSize,
00573 char *szComment,
00574 uLong commentBufferSize)
00575 {
00576 unz_s* s;
00577 unz_file_info file_info;
00578 unz_file_info_internal file_info_internal;
00579 int err=UNZ_OK;
00580 uLong uMagic;
00581 long lSeek=0;
00582
00583 if (file==NULL)
00584 return UNZ_PARAMERROR;
00585 s=(unz_s*)file;
00586 if (ZSEEK(s->z_filefunc, s->filestream,
00587 s->pos_in_central_dir+s->byte_before_the_zipfile,
00588 ZLIB_FILEFUNC_SEEK_SET)!=0)
00589 err=UNZ_ERRNO;
00590
00591
00592
00593 if (err==UNZ_OK)
00594 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
00595 err=UNZ_ERRNO;
00596 else if (uMagic!=0x02014b50)
00597 err=UNZ_BADZIPFILE;
00598
00599 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
00600 err=UNZ_ERRNO;
00601
00602 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
00603 err=UNZ_ERRNO;
00604
00605 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
00606 err=UNZ_ERRNO;
00607
00608 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
00609 err=UNZ_ERRNO;
00610
00611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
00612 err=UNZ_ERRNO;
00613
00614 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
00615
00616 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
00617 err=UNZ_ERRNO;
00618
00619 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
00620 err=UNZ_ERRNO;
00621
00622 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
00623 err=UNZ_ERRNO;
00624
00625 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
00626 err=UNZ_ERRNO;
00627
00628 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
00629 err=UNZ_ERRNO;
00630
00631 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
00632 err=UNZ_ERRNO;
00633
00634 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
00635 err=UNZ_ERRNO;
00636
00637 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
00638 err=UNZ_ERRNO;
00639
00640 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
00641 err=UNZ_ERRNO;
00642
00643 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
00644 err=UNZ_ERRNO;
00645
00646 lSeek+=file_info.size_filename;
00647 if ((err==UNZ_OK) && (szFileName!=NULL))
00648 {
00649 uLong uSizeRead ;
00650 if (file_info.size_filename<fileNameBufferSize)
00651 {
00652 *(szFileName+file_info.size_filename)='\0';
00653 uSizeRead = file_info.size_filename;
00654 }
00655 else
00656 uSizeRead = fileNameBufferSize;
00657
00658 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
00659 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
00660 err=UNZ_ERRNO;
00661 lSeek -= uSizeRead;
00662 }
00663
00664
00665 if ((err==UNZ_OK) && (extraField!=NULL))
00666 {
00667 uLong uSizeRead ;
00668 if (file_info.size_file_extra<extraFieldBufferSize)
00669 uSizeRead = file_info.size_file_extra;
00670 else
00671 uSizeRead = extraFieldBufferSize;
00672
00673 if (lSeek!=0)
00674 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
00675 lSeek=0;
00676 else
00677 err=UNZ_ERRNO;
00678 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
00679 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
00680 err=UNZ_ERRNO;
00681 lSeek += file_info.size_file_extra - uSizeRead;
00682 }
00683 else
00684 lSeek+=file_info.size_file_extra;
00685
00686
00687 if ((err==UNZ_OK) && (szComment!=NULL))
00688 {
00689 uLong uSizeRead ;
00690 if (file_info.size_file_comment<commentBufferSize)
00691 {
00692 *(szComment+file_info.size_file_comment)='\0';
00693 uSizeRead = file_info.size_file_comment;
00694 }
00695 else
00696 uSizeRead = commentBufferSize;
00697
00698 if (lSeek!=0)
00699 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
00700 lSeek=0;
00701 else
00702 err=UNZ_ERRNO;
00703 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
00704 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
00705 err=UNZ_ERRNO;
00706 lSeek+=file_info.size_file_comment - uSizeRead;
00707 }
00708 else
00709 lSeek+=file_info.size_file_comment;
00710
00711 if ((err==UNZ_OK) && (pfile_info!=NULL))
00712 *pfile_info=file_info;
00713
00714 if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
00715 *pfile_info_internal=file_info_internal;
00716
00717 return err;
00718 }
00719
00720
00721
00722
00723
00724
00725
00726
00727 extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
00728 unz_file_info *pfile_info,
00729 char *szFileName,
00730 uLong fileNameBufferSize,
00731 void *extraField,
00732 uLong extraFieldBufferSize,
00733 char *szComment,
00734 uLong commentBufferSize)
00735 {
00736 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
00737 szFileName,fileNameBufferSize,
00738 extraField,extraFieldBufferSize,
00739 szComment,commentBufferSize);
00740 }
00741
00742
00743
00744
00745
00746 extern int ZEXPORT unzGoToFirstFile (unzFile file)
00747 {
00748 int err=UNZ_OK;
00749 unz_s* s;
00750 if (file==NULL)
00751 return UNZ_PARAMERROR;
00752 s=(unz_s*)file;
00753 s->pos_in_central_dir=s->offset_central_dir;
00754 s->num_file=0;
00755 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
00756 &s->cur_file_info_internal,
00757 NULL,0,NULL,0,NULL,0);
00758 s->current_file_ok = (err == UNZ_OK);
00759 return err;
00760 }
00761
00762
00763
00764
00765
00766
00767 extern int ZEXPORT unzGoToNextFile (unzFile file)
00768 {
00769 unz_s* s;
00770 int err;
00771
00772 if (file==NULL)
00773 return UNZ_PARAMERROR;
00774 s=(unz_s*)file;
00775 if (!s->current_file_ok)
00776 return UNZ_END_OF_LIST_OF_FILE;
00777 if (s->gi.number_entry != 0xffff)
00778 if (s->num_file+1==s->gi.number_entry)
00779 return UNZ_END_OF_LIST_OF_FILE;
00780
00781 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
00782 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
00783 s->num_file++;
00784 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
00785 &s->cur_file_info_internal,
00786 NULL,0,NULL,0,NULL,0);
00787 s->current_file_ok = (err == UNZ_OK);
00788 return err;
00789 }
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName,
00801 int iCaseSensitivity)
00802 {
00803 unz_s* s;
00804 int err;
00805
00806
00807
00808
00809 unz_file_info cur_file_infoSaved;
00810 unz_file_info_internal cur_file_info_internalSaved;
00811 uLong num_fileSaved;
00812 uLong pos_in_central_dirSaved;
00813
00814
00815 if (file==NULL)
00816 return UNZ_PARAMERROR;
00817
00818 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
00819 return UNZ_PARAMERROR;
00820
00821 s=(unz_s*)file;
00822 if (!s->current_file_ok)
00823 return UNZ_END_OF_LIST_OF_FILE;
00824
00825
00826 num_fileSaved = s->num_file;
00827 pos_in_central_dirSaved = s->pos_in_central_dir;
00828 cur_file_infoSaved = s->cur_file_info;
00829 cur_file_info_internalSaved = s->cur_file_info_internal;
00830
00831 err = unzGoToFirstFile(file);
00832
00833 while (err == UNZ_OK)
00834 {
00835 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
00836 err = unzGetCurrentFileInfo(file,NULL,
00837 szCurrentFileName,sizeof(szCurrentFileName)-1,
00838 NULL,0,NULL,0);
00839 if (err == UNZ_OK)
00840 {
00841 if (unzStringFileNameCompare(szCurrentFileName,
00842 szFileName,iCaseSensitivity)==0)
00843 return UNZ_OK;
00844 err = unzGoToNextFile(file);
00845 }
00846 }
00847
00848
00849
00850
00851 s->num_file = num_fileSaved ;
00852 s->pos_in_central_dir = pos_in_central_dirSaved ;
00853 s->cur_file_info = cur_file_infoSaved;
00854 s->cur_file_info_internal = cur_file_info_internalSaved;
00855 return err;
00856 }
00857
00858
00859
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877 extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos)
00878 {
00879 unz_s* s;
00880
00881 if (file==NULL || file_pos==NULL)
00882 return UNZ_PARAMERROR;
00883 s=(unz_s*)file;
00884 if (!s->current_file_ok)
00885 return UNZ_END_OF_LIST_OF_FILE;
00886
00887 file_pos->pos_in_zip_directory = s->pos_in_central_dir;
00888 file_pos->num_of_file = s->num_file;
00889
00890 return UNZ_OK;
00891 }
00892
00893 extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos)
00894 {
00895 unz_s* s;
00896 int err;
00897
00898 if (file==NULL || file_pos==NULL)
00899 return UNZ_PARAMERROR;
00900 s=(unz_s*)file;
00901
00902
00903 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
00904 s->num_file = file_pos->num_of_file;
00905
00906
00907 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
00908 &s->cur_file_info_internal,
00909 NULL,0,NULL,0,NULL,0);
00910
00911 s->current_file_ok = (err == UNZ_OK);
00912 return err;
00913 }
00914
00915
00916
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927 local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s,
00928 uInt* piSizeVar,
00929 uLong *poffset_local_extrafield,
00930 uInt *psize_local_extrafield)
00931 {
00932 uLong uMagic,uData,uFlags;
00933 uLong size_filename;
00934 uLong size_extra_field;
00935 int err=UNZ_OK;
00936
00937 *piSizeVar = 0;
00938 *poffset_local_extrafield = 0;
00939 *psize_local_extrafield = 0;
00940
00941 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
00942 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
00943 return UNZ_ERRNO;
00944
00945
00946 if (err==UNZ_OK)
00947 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
00948 err=UNZ_ERRNO;
00949 else if (uMagic!=0x04034b50)
00950 err=UNZ_BADZIPFILE;
00951
00952 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
00953 err=UNZ_ERRNO;
00954
00955
00956
00957
00958 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
00959 err=UNZ_ERRNO;
00960
00961 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
00962 err=UNZ_ERRNO;
00963 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
00964 err=UNZ_BADZIPFILE;
00965
00966 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
00967 (s->cur_file_info.compression_method!=Z_DEFLATED))
00968 err=UNZ_BADZIPFILE;
00969
00970 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
00971 err=UNZ_ERRNO;
00972
00973 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
00974 err=UNZ_ERRNO;
00975 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
00976 ((uFlags & 8)==0))
00977 err=UNZ_BADZIPFILE;
00978
00979 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
00980 err=UNZ_ERRNO;
00981 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
00982 ((uFlags & 8)==0))
00983 err=UNZ_BADZIPFILE;
00984
00985 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
00986 err=UNZ_ERRNO;
00987 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
00988 ((uFlags & 8)==0))
00989 err=UNZ_BADZIPFILE;
00990
00991
00992 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
00993 err=UNZ_ERRNO;
00994 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
00995 err=UNZ_BADZIPFILE;
00996
00997 *piSizeVar += (uInt)size_filename;
00998
00999 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
01000 err=UNZ_ERRNO;
01001 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
01002 SIZEZIPLOCALHEADER + size_filename;
01003 *psize_local_extrafield = (uInt)size_extra_field;
01004
01005 *piSizeVar += (uInt)size_extra_field;
01006
01007 return err;
01008 }
01009
01010
01011
01012
01013
01014 extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, int* level,
01015 int raw, const char* password)
01016 {
01017 int err=UNZ_OK;
01018 uInt iSizeVar;
01019 unz_s* s;
01020 file_in_zip_read_info_s* pfile_in_zip_read_info;
01021 uLong offset_local_extrafield;
01022 uInt size_local_extrafield;
01023 # ifndef NOUNCRYPT
01024 char source[12];
01025 # else
01026 if (password != NULL)
01027 return UNZ_PARAMERROR;
01028 # endif
01029
01030 if (file==NULL)
01031 return UNZ_PARAMERROR;
01032 s=(unz_s*)file;
01033 if (!s->current_file_ok)
01034 return UNZ_PARAMERROR;
01035
01036 if (s->pfile_in_zip_read != NULL)
01037 unzCloseCurrentFile(file);
01038
01039 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
01040 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
01041 return UNZ_BADZIPFILE;
01042
01043 pfile_in_zip_read_info = (file_in_zip_read_info_s*)
01044 ALLOC(sizeof(file_in_zip_read_info_s));
01045 if (pfile_in_zip_read_info==NULL)
01046 return UNZ_INTERNALERROR;
01047
01048 pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
01049 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
01050 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;