/* Read the local header of the current zipfile Check the coherency of the local header and info in the end of central directory about this file store in *piSizeVar the size of extra info in local header (filename and size of extra field data) */ static int unzlocal_CheckCurrentFileCoherencyHeader(unz_s* s, uInt* piSizeVar, uLong *poffset_local_extrafield, uInt *psize_local_extrafield) { uLong uMagic,uData,uFlags; uLong size_filename; uLong size_extra_field; int err=UNZ_OK; *piSizeVar = 0; *poffset_local_extrafield = 0; *psize_local_extrafield = 0; s->_stream->seek(s->cur_file_info_internal.offset_curfile + s->byte_before_the_zipfile, SEEK_SET); if (s->_stream->err()) return UNZ_ERRNO; if (err==UNZ_OK) { if (unzlocal_getLong(s->_stream,&uMagic) != UNZ_OK) err=UNZ_ERRNO; else if (uMagic!=0x04034b50) err=UNZ_BADZIPFILE; } if (unzlocal_getShort(s->_stream,&uData) != UNZ_OK) err=UNZ_ERRNO; /* else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) err=UNZ_BADZIPFILE; */ if (unzlocal_getShort(s->_stream,&uFlags) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&uData) != UNZ_OK) err=UNZ_ERRNO; else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) err=UNZ_BADZIPFILE; if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && (s->cur_file_info.compression_method!=Z_DEFLATED)) err=UNZ_BADZIPFILE; if (unzlocal_getLong(s->_stream,&uData) != UNZ_OK) /* date/time */ err=UNZ_ERRNO; if (unzlocal_getLong(s->_stream,&uData) != UNZ_OK) /* crc */ err=UNZ_ERRNO; else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) err=UNZ_BADZIPFILE; if (unzlocal_getLong(s->_stream,&uData) != UNZ_OK) /* size compr */ err=UNZ_ERRNO; else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) err=UNZ_BADZIPFILE; if (unzlocal_getLong(s->_stream,&uData) != UNZ_OK) /* size uncompr */ err=UNZ_ERRNO; else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) err=UNZ_BADZIPFILE; if (unzlocal_getShort(s->_stream,&size_filename) != UNZ_OK) err=UNZ_ERRNO; else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) err=UNZ_BADZIPFILE; *piSizeVar += (uInt)size_filename; if (unzlocal_getShort(s->_stream,&size_extra_field) != UNZ_OK) err=UNZ_ERRNO; *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + size_filename; *psize_local_extrafield = (uInt)size_extra_field; *piSizeVar += (uInt)size_extra_field; return err; }
/* Open a Zip file. path contain the full pathname (by example, on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer "zlib/zlib109.zip". If the zipfile cannot be opened (file don't exist or in not valid), the return value is NULL. Else, the return value is a unzFile Handle, usable with other function of this unzip package. */ unzFile unzOpen(Common::SeekableReadStream *stream) { if (!stream) return NULL; unz_s *us = new unz_s; uLong central_pos,uL; uLong number_disk; /* number of the current dist, used for spaning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used for spaning ZIP, unsupported, always 0*/ uLong number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ int err=UNZ_OK; us->_stream = stream; central_pos = unzlocal_SearchCentralDir(*us->_stream); if (central_pos==0) err=UNZ_ERRNO; us->_stream->seek(central_pos, SEEK_SET); if (us->_stream->err()) err=UNZ_ERRNO; /* the signature, already checked */ if (unzlocal_getLong(us->_stream,&uL)!=UNZ_OK) err=UNZ_ERRNO; /* number of this disk */ if (unzlocal_getShort(us->_stream,&number_disk)!=UNZ_OK) err=UNZ_ERRNO; /* number of the disk with the start of the central directory */ if (unzlocal_getShort(us->_stream,&number_disk_with_CD)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir on this disk */ if (unzlocal_getShort(us->_stream,&us->gi.number_entry)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir */ if (unzlocal_getShort(us->_stream,&number_entry_CD)!=UNZ_OK) err=UNZ_ERRNO; if ((number_entry_CD!=us->gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; /* size of the central directory */ if (unzlocal_getLong(us->_stream,&us->size_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* offset of start of central directory with respect to the starting disk number */ if (unzlocal_getLong(us->_stream,&us->offset_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* zipfile comment length */ if (unzlocal_getShort(us->_stream,&us->gi.size_comment)!=UNZ_OK) err=UNZ_ERRNO; if ((central_pos<us->offset_central_dir+us->size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; if (err != UNZ_OK) { delete us->_stream; delete us; return NULL; } us->byte_before_the_zipfile = central_pos - (us->offset_central_dir+us->size_central_dir); us->central_pos = central_pos; us->pfile_in_zip_read = NULL; err = unzGoToFirstFile((unzFile)us); while (err == UNZ_OK) { // Get the file details char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; unzGetCurrentFileInfo(us, NULL, szCurrentFileName, sizeof(szCurrentFileName) - 1, NULL, 0, NULL, 0); // Save details into the hash cached_file_in_zip fe; fe.num_file = us->num_file; fe.pos_in_central_dir = us->pos_in_central_dir; fe.current_file_ok = us->current_file_ok; fe.cur_file_info = us->cur_file_info; fe.cur_file_info_internal = us->cur_file_info_internal; us->_hash[Common::String(szCurrentFileName)] = fe; // Move to the next file err = unzGoToNextFile((unzFile)us); } return (unzFile)us; }
static int unzlocal_GetCurrentFileInfoInternal(unzFile file, unz_file_info *pfile_info, unz_file_info_internal *pfile_info_internal, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize) { unz_s* s; unz_file_info file_info; unz_file_info_internal file_info_internal; int err=UNZ_OK; uLong uMagic; long lSeek=0; if (file==NULL) return UNZ_PARAMERROR; s=(unz_s*)file; s->_stream->seek(s->pos_in_central_dir+s->byte_before_the_zipfile, SEEK_SET); if (s->_stream->err()) err=UNZ_ERRNO; /* we check the magic */ if (err==UNZ_OK) { if (unzlocal_getLong(s->_stream,&uMagic) != UNZ_OK) err=UNZ_ERRNO; else if (uMagic!=0x02014b50) err=UNZ_BADZIPFILE; } if (unzlocal_getShort(s->_stream,&file_info.version) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.version_needed) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.flag) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.compression_method) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getLong(s->_stream,&file_info.dosDate) != UNZ_OK) err=UNZ_ERRNO; unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); if (unzlocal_getLong(s->_stream,&file_info.crc) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getLong(s->_stream,&file_info.compressed_size) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getLong(s->_stream,&file_info.uncompressed_size) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.size_filename) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.size_file_extra) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.size_file_comment) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.disk_num_start) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getShort(s->_stream,&file_info.internal_fa) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getLong(s->_stream,&file_info.external_fa) != UNZ_OK) err=UNZ_ERRNO; if (unzlocal_getLong(s->_stream,&file_info_internal.offset_curfile) != UNZ_OK) err=UNZ_ERRNO; lSeek+=file_info.size_filename; if ((err==UNZ_OK) && (szFileName!=NULL)) { uLong uSizeRead ; if (file_info.size_filename<fileNameBufferSize) { *(szFileName+file_info.size_filename)='\0'; uSizeRead = file_info.size_filename; } else uSizeRead = fileNameBufferSize; if ((file_info.size_filename>0) && (fileNameBufferSize>0)) if (s->_stream->read(szFileName,(uInt)uSizeRead)!=uSizeRead) err=UNZ_ERRNO; lSeek -= uSizeRead; } if ((err==UNZ_OK) && (extraField!=NULL)) { uLong uSizeRead ; if (file_info.size_file_extra<extraFieldBufferSize) uSizeRead = file_info.size_file_extra; else uSizeRead = extraFieldBufferSize; if (lSeek!=0) { s->_stream->seek(lSeek, SEEK_CUR); if (s->_stream->err()) lSeek=0; else err=UNZ_ERRNO; } if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) if (s->_stream->read(extraField,(uInt)uSizeRead)!=uSizeRead) err=UNZ_ERRNO; lSeek += file_info.size_file_extra - uSizeRead; } else lSeek+=file_info.size_file_extra; if ((err==UNZ_OK) && (szComment!=NULL)) { uLong uSizeRead ; if (file_info.size_file_comment<commentBufferSize) { *(szComment+file_info.size_file_comment)='\0'; uSizeRead = file_info.size_file_comment; } else uSizeRead = commentBufferSize; if (lSeek!=0) { s->_stream->seek(lSeek, SEEK_CUR); if (s->_stream->err()) lSeek=0; else err=UNZ_ERRNO; } if ((file_info.size_file_comment>0) && (commentBufferSize>0)) if (s->_stream->read(szComment,(uInt)uSizeRead)!=uSizeRead) err=UNZ_ERRNO; lSeek+=file_info.size_file_comment - uSizeRead; } else lSeek+=file_info.size_file_comment; if ((err==UNZ_OK) && (pfile_info!=NULL)) *pfile_info=file_info; if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) *pfile_info_internal=file_info_internal; return err; }
/* Open a Zip file. path contain the full pathname (by example, on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer "zlib/zlib109.zip". If the zipfile cannot be opened (file don't exist or in not valid), the return value is NULL. Else, the return value is a unzFile Handle, usable with other function of this unzip package. */ extern unzFile ZEXPORT unzOpen(const char *path) { unz_s us; unz_s *s; uLong central_pos,uL; FILE * fin ; uLong number_disk; /* number of the current dist, used for spaning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used for spaning ZIP, unsupported, always 0*/ uLong number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ int err=UNZ_OK; if (unz_copyright[0]!=' ') return NULL; fin=FCEUI_UTF8fopen_C(path,"rb"); //fin=fopen(path,"rb"); if (fin==NULL) return NULL; central_pos = unzlocal_SearchCentralDir(fin); if (central_pos==0) err=UNZ_ERRNO; if (fseek(fin,central_pos,SEEK_SET)!=0) err=UNZ_ERRNO; /* the signature, already checked */ if (unzlocal_getLong(fin,&uL)!=UNZ_OK) err=UNZ_ERRNO; /* number of this disk */ if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) err=UNZ_ERRNO; /* number of the disk with the start of the central directory */ if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir on this disk */ if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir */ if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) err=UNZ_ERRNO; if ((number_entry_CD!=us.gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; /* size of the central directory */ if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* offset of start of central directory with respect to the starting disk number */ if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* zipfile comment length */ if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) err=UNZ_ERRNO; if ((central_pos<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; if (err!=UNZ_OK) { fclose(fin); return NULL; } us.file=fin; us.byte_before_the_zipfile = central_pos - (us.offset_central_dir+us.size_central_dir); us.central_pos = central_pos; us.pfile_in_zip_read = NULL; s=(unz_s*)ALLOC(sizeof(unz_s)); *s=us; unzGoToFirstFile((unzFile)s); return (unzFile)s; }
/* Open a Zip file. path contain the full pathname (by example, on a Windows NT computer "c:\\test\\zlib114.zip" or on a Unix computer "zlib/zlib114.zip". If the zipfile cannot be opened (file doesn't exist or in not valid), the return value is NULL. Else, the return value is an unzFile Handle, usable with other function of this unzip package. */ unzFile ZEXPORT unzOpen2 ( const char *path, zlib_filefunc_def* pzlib_filefunc_def) { unz_s us; unz_s *s; uLong central_pos,uL; uLong number_disk; /* number of the current dist, used for spaning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used for spaning ZIP, unsupported, always 0*/ uLong number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ int err=UNZ_OK; if (unz_copyright[0]!=' ') return NULL; if (pzlib_filefunc_def==NULL) fill_fopen_filefunc(&us.z_filefunc); else us.z_filefunc = *pzlib_filefunc_def; us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, path, ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_EXISTING); if (us.filestream==NULL) return NULL; central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); if (central_pos==0) err=UNZ_ERRNO; if (ZSEEK(us.z_filefunc, us.filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) err=UNZ_ERRNO; /* the signature, already checked */ if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) err=UNZ_ERRNO; /* number of this disk */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) err=UNZ_ERRNO; /* number of the disk with the start of the central directory */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir on this disk */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) err=UNZ_ERRNO; if ((number_entry_CD!=us.gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; /* size of the central directory */ if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* offset of start of central directory with respect to the starting disk number */ if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* zipfile comment length */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) err=UNZ_ERRNO; if ((central_pos<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; if (err!=UNZ_OK) { ZCLOSE(us.z_filefunc, us.filestream); return NULL; } us.byte_before_the_zipfile = central_pos - (us.offset_central_dir+us.size_central_dir); us.central_pos = central_pos; us.pfile_in_zip_read = NULL; us.encrypted = 0; s=(unz_s*)ALLOC(sizeof(unz_s)); *s=us; unzGoToFirstFile((unzFile)s); return (unzFile)s; }
/* Open a Zip file. path contain the full pathname (by example, on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer "zlib/zlib109.zip". If the zipfile cannot be opened (file don't exist or in not valid), the return value is NULL. Else, the return value is a unzFile Handle, usable with other function of this unzip package. */ unzFile unzOpen(Common::SeekableReadStream *stream) { if (!stream) return NULL; unz_s *us = new unz_s; uLong central_pos,uL; uLong number_disk; /* number of the current dist, used for spaning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used for spaning ZIP, unsupported, always 0*/ uLong number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ int err=UNZ_OK; us->_stream = stream; central_pos = unzlocal_SearchCentralDir(*us->_stream); if (central_pos==0) err=UNZ_ERRNO; us->_stream->seek(central_pos, SEEK_SET); if (us->_stream->err()) err=UNZ_ERRNO; /* the signature, already checked */ if (unzlocal_getLong(us->_stream,&uL)!=UNZ_OK) err=UNZ_ERRNO; /* number of this disk */ if (unzlocal_getShort(us->_stream,&number_disk)!=UNZ_OK) err=UNZ_ERRNO; /* number of the disk with the start of the central directory */ if (unzlocal_getShort(us->_stream,&number_disk_with_CD)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir on this disk */ if (unzlocal_getShort(us->_stream,&us->gi.number_entry)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir */ if (unzlocal_getShort(us->_stream,&number_entry_CD)!=UNZ_OK) err=UNZ_ERRNO; if ((number_entry_CD!=us->gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; /* size of the central directory */ if (unzlocal_getLong(us->_stream,&us->size_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* offset of start of central directory with respect to the starting disk number */ if (unzlocal_getLong(us->_stream,&us->offset_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* zipfile comment length */ if (unzlocal_getShort(us->_stream,&us->gi.size_comment)!=UNZ_OK) err=UNZ_ERRNO; if ((central_pos<us->offset_central_dir+us->size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; if (err!=UNZ_OK) { delete us->_stream; delete us; return NULL; } us->byte_before_the_zipfile = central_pos - (us->offset_central_dir+us->size_central_dir); us->central_pos = central_pos; us->pfile_in_zip_read = NULL; unzGoToFirstFile((unzFile)us); return (unzFile)us; }
static int unzlocal_CheckCurrentFileCoherencyHeader(unz_s *s, DWORD *piSizeVar, DWORD *poffset_local_extrafield, DWORD *psize_local_extrafield) { DWORD uMagic, uData, uFlags; DWORD size_filename; DWORD size_extra_field; int err = UNZ_OK; *piSizeVar = 0; *poffset_local_extrafield = 0; *psize_local_extrafield = 0; if (ZSEEK(s->z_filefunc, s->filestream, s->cur_file_info_internal.offset_curfile + s->byte_before_the_zipfile, SEEK_SET) != 0) { return UNZ_ERRNO; } if (err == UNZ_OK) { if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uMagic) != UNZ_OK) { err = UNZ_ERRNO; } else if (uMagic != 0x04034b50) { err = UNZ_BADZIPFILE; } } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &uFlags) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) { err = UNZ_ERRNO; } else if ((err == UNZ_OK) && (uData != s->cur_file_info.compression_method)) { err = UNZ_BADZIPFILE; } if ((err == UNZ_OK) && (s->cur_file_info.compression_method != 0) && (s->cur_file_info.compression_method != Z_DEFLATED)) { err = UNZ_BADZIPFILE; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) // date/time { err = UNZ_ERRNO; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) // crc { err = UNZ_ERRNO; } else if ((err == UNZ_OK) && (uData != s->cur_file_info.crc) && ((uFlags &8) == 0)) { err = UNZ_BADZIPFILE; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) // size compr { err = UNZ_ERRNO; } else if ((err == UNZ_OK) && (uData != s->cur_file_info.compressed_size) && ((uFlags &8) == 0)) { err = UNZ_BADZIPFILE; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) // size uncompr { err = UNZ_ERRNO; } else if ((err == UNZ_OK) && (uData != s->cur_file_info.uncompressed_size) && ((uFlags &8) == 0)) { err = UNZ_BADZIPFILE; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &size_filename) != UNZ_OK) { err = UNZ_ERRNO; } else if ((err == UNZ_OK) && (size_filename != s->cur_file_info.size_filename)) { err = UNZ_BADZIPFILE; } *piSizeVar += (DWORD)size_filename; if (unzlocal_getShort(&s->z_filefunc, s->filestream, &size_extra_field) != UNZ_OK) { err = UNZ_ERRNO; } *poffset_local_extrafield = s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + size_filename; *psize_local_extrafield = (DWORD)size_extra_field; *piSizeVar += (DWORD)size_extra_field; return err; }
static int unzlocal_GetCurrentFileInfoInternal(unzFile file, unz_file_info *pfile_info, unz_file_info_internal *pfile_info_internal, char *szFileName, DWORD fileNameBufferSize, void *extraField, DWORD extraFieldBufferSize, char *szComment, DWORD commentBufferSize) { unz_s *s; unz_file_info file_info; unz_file_info_internal file_info_internal; int err = UNZ_OK; DWORD uMagic; long lSeek = 0; if (file == NULL) { return UNZ_PARAMERROR; } s = (unz_s*)file; if (ZSEEK(s->z_filefunc, s->filestream, s->pos_in_central_dir + s->byte_before_the_zipfile, SEEK_SET) != 0) { err = UNZ_ERRNO; } /* we check the magic */ if (err == UNZ_OK) { if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uMagic) != UNZ_OK) { err = UNZ_ERRNO; } else if (uMagic != 0x02014b50) { err = UNZ_BADZIPFILE; } } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.version) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.version_needed) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.flag) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.compression_method) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.dosDate) != UNZ_OK) { err = UNZ_ERRNO; } unzlocal_DosDateToTmuDate(file_info.dosDate, &file_info.tmu_date); if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.crc) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.compressed_size) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.uncompressed_size) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.size_filename) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.size_file_extra) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.size_file_comment) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.disk_num_start) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.internal_fa) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.external_fa) != UNZ_OK) { err = UNZ_ERRNO; } if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info_internal.offset_curfile) != UNZ_OK) { err = UNZ_ERRNO; } lSeek += file_info.size_filename; if ((err == UNZ_OK) && (szFileName != NULL)) { DWORD uSizeRead; if (file_info.size_filename < fileNameBufferSize) { *(szFileName + file_info.size_filename) = '\0'; uSizeRead = file_info.size_filename; } else { uSizeRead = fileNameBufferSize; } if ((file_info.size_filename > 0) && (fileNameBufferSize > 0)) if (ZREAD(s->z_filefunc, s->filestream, szFileName, uSizeRead) != uSizeRead) { err = UNZ_ERRNO; } lSeek -= uSizeRead; } if ((err == UNZ_OK) && (extraField != NULL)) { DWORD uSizeRead; if (file_info.size_file_extra < extraFieldBufferSize) { uSizeRead = file_info.size_file_extra; } else { uSizeRead = extraFieldBufferSize; } if (lSeek != 0) { if (ZSEEK(s->z_filefunc, s->filestream, lSeek, SEEK_CUR) == 0) { lSeek = 0; } else { err = UNZ_ERRNO; } } if ((file_info.size_file_extra > 0) && (extraFieldBufferSize > 0)) { if (ZREAD(s->z_filefunc, s->filestream, extraField, uSizeRead) != uSizeRead) { err = UNZ_ERRNO; } } lSeek += file_info.size_file_extra - uSizeRead; } else { lSeek += file_info.size_file_extra; } if ((err == UNZ_OK) && (szComment != NULL)) { DWORD uSizeRead; if (file_info.size_file_comment < commentBufferSize) { *(szComment + file_info.size_file_comment) = '\0'; uSizeRead = file_info.size_file_comment; } else { uSizeRead = commentBufferSize; } if (lSeek != 0) { if (ZSEEK(s->z_filefunc, s->filestream, lSeek, SEEK_CUR) == 0) { lSeek = 0; } else { err = UNZ_ERRNO; } } if ((file_info.size_file_comment > 0) && (commentBufferSize > 0)) { if (ZREAD(s->z_filefunc, s->filestream, szComment, uSizeRead) != uSizeRead) { err = UNZ_ERRNO; } } lSeek += file_info.size_file_comment - uSizeRead; } else { lSeek += file_info.size_file_comment; } if ((err == UNZ_OK) && (pfile_info != NULL)) { *pfile_info = file_info; } if ((err == UNZ_OK) && (pfile_info_internal != NULL)) { *pfile_info_internal = file_info_internal; } return err; }