50 # define VERSIONMADEBY (0x0)
54 #define Z_BUFSIZE (64*1024)
57 #ifndef Z_MAXFILENAMEINZIP
58 #define Z_MAXFILENAMEINZIP (256)
62 # define ALLOC(size) (malloc(size))
65 # define TRYFREE(p) {if (p) free(p);}
77 #define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
92 #if MAX_MEM_LEVEL >= 8
93 # define DEF_MEM_LEVEL 8
95 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
98 const char zip_copyright[] =
" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
101 #define SIZEDATA_INDATABLOCK (4096-(4*4))
103 #define LOCALHEADERMAGIC (0x04034b50)
104 #define CENTRALHEADERMAGIC (0x02014b50)
105 #define ENDHEADERMAGIC (0x06054b50)
106 #define ZIP64ENDHEADERMAGIC (0x6064b50)
107 #define ZIP64ENDLOCHEADERMAGIC (0x7064b50)
109 #define FLAG_LOCALHEADER_OFFSET (0x06)
110 #define CRC_LOCALHEADER_OFFSET (0x0e)
112 #define SIZECENTRALHEADER (0x2e)
177 #ifndef NO_ADDFILEINEXISTINGZIP
185 #define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
228 const unsigned char* from_copy;
241 from_copy = (
unsigned char*)
buf;
247 unsigned char* to_copy;
265 for (
i=0;
i<copy_this;
i++)
266 *(to_copy+
i)=*(from_copy+
i);
270 from_copy += copy_this ;
280 #ifndef NO_ADDFILEINEXISTINGZIP
289 unsigned char buf[8];
291 for (
n = 0;
n < nbByte;
n++)
293 buf[
n] = (
unsigned char)(
x & 0xff);
298 for (
n = 0;
n < nbByte;
n++)
313 unsigned char*
buf=(
unsigned char*)
dest;
315 for (
n = 0;
n < nbByte;
n++) {
316 buf[
n] = (
unsigned char)(
x & 0xff);
322 for (
n = 0;
n < nbByte;
n++)
360 if (
ZERROR64(*pzlib_filefunc_def,filestream))
471 #ifndef BUFREADCOMMENT
472 #define BUFREADCOMMENT (0x400)
492 uSizeFile =
ZTELL64(*pzlib_filefunc_def,filestream);
494 if (uMaxBack>uSizeFile)
495 uMaxBack = uSizeFile;
502 while (uBackRead<uMaxBack)
508 uBackRead = uMaxBack;
511 uReadPos = uSizeFile-uBackRead ;
518 if (
ZREAD64(*pzlib_filefunc_def,filestream,
buf,uReadSize)!=uReadSize)
521 for (
i=(
int)uReadSize-3; (
i--)>0;)
522 if (((*(
buf+
i))==0x50) && ((*(
buf+
i+1))==0x4b) &&
523 ((*(
buf+
i+2))==0x05) && ((*(
buf+
i+3))==0x06))
555 uSizeFile =
ZTELL64(*pzlib_filefunc_def,filestream);
557 if (uMaxBack>uSizeFile)
558 uMaxBack = uSizeFile;
565 while (uBackRead<uMaxBack)
571 uBackRead = uMaxBack;
574 uReadPos = uSizeFile-uBackRead ;
581 if (
ZREAD64(*pzlib_filefunc_def,filestream,
buf,uReadSize)!=uReadSize)
584 for (
i=(
int)uReadSize-3; (
i--)>0;)
587 if (((*(
buf+
i))==0x50) && ((*(
buf+
i+1))==0x4b) && ((*(
buf+
i+2))==0x06) && ((*(
buf+
i+3))==0x07))
634 if (uL != 0x06064b50)
637 return relativeOffset;
652 uLong number_disk_with_CD;
662 int hasZIP64Record = 0;
670 else if(central_pos == 0)
718 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
764 number_entry_CD = uL;
766 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
770 size_central_dir = 0;
774 size_central_dir = uL;
777 offset_central_dir = 0;
781 offset_central_dir = uL;
789 if ((central_pos<offset_central_dir+size_central_dir) &&
809 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
813 ZPOS64_T size_central_dir_to_read = size_central_dir;
819 while ((size_central_dir_to_read>0) && (
err==
ZIP_OK))
822 if (read_this > size_central_dir_to_read)
823 read_this = size_central_dir_to_read;
831 size_central_dir_to_read-=read_this;
835 pziinit->
begin_pos = byte_before_the_zipfile;
857 if (pzlib_filefunc64_32_def==
NULL)
891 # ifndef NO_ADDFILEINEXISTINGZIP
907 # ifndef NO_ADDFILEINEXISTINGZIP
922 if (pzlib_filefunc32_def !=
NULL)
934 if (pzlib_filefunc_def !=
NULL)
937 zlib_filefunc64_32_def_fill.
zfile_func64 = *pzlib_filefunc_def;
963 uInt size_extrafield = size_extrafield_local;
1007 size_extrafield += 20;
1013 if ((
err==
ZIP_OK) && (size_filename > 0))
1019 if ((
err==
ZIP_OK) && (size_extrafield_local > 0))
1030 short DataSize = 16;
1056 const void* extrafield_local,
uInt size_extrafield_local,
1057 const void* extrafield_global,
uInt size_extrafield_global,
1058 const char* comment,
int method,
int level,
int raw,
1059 int windowBits,
int memLevel,
int strategy,
1060 const char* password,
uLong crcForCrypting,
1061 uLong versionMadeBy,
uLong flagBase,
int zip64)
1071 if (password !=
NULL)
1101 size_comment = (
uInt)strlen(comment);
1122 if (password !=
NULL)
1169 for (
i=0;
i<size_filename;
i++)
1172 for (
i=0;
i<size_extrafield_global;
i++)
1174 *(((
const char*)extrafield_global)+
i);
1176 for (
i=0;
i<size_comment;
i++)
1178 size_extrafield_global+
i) = *(comment+
i);
1190 zi->
ci.bstream.avail_in = (
uInt)0;
1193 zi->
ci.bstream.total_in_hi32 = 0;
1194 zi->
ci.bstream.total_in_lo32 = 0;
1195 zi->
ci.bstream.total_out_hi32 = 0;
1196 zi->
ci.bstream.total_out_lo32 = 0;
1219 windowBits = -windowBits;
1230 zi->
ci.bstream.bzalloc = 0;
1231 zi->
ci.bstream.bzfree = 0;
1234 err = BZ2_bzCompressInit(&zi->
ci.bstream,
level, 0,35);
1246 unsigned char bufHead[RAND_HEAD_LEN];
1247 unsigned int sizeHead;
1252 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->
ci.
keys,zi->
ci.
pcrc_32_tab,crcForCrypting);
1266 const void* extrafield_local,
uInt size_extrafield_local,
1267 const void* extrafield_global,
uInt size_extrafield_global,
1268 const char* comment,
int method,
int level,
int raw,
1269 int windowBits,
int memLevel,
int strategy,
1270 const char* password,
uLong crcForCrypting,
1274 extrafield_local, size_extrafield_local,
1275 extrafield_global, size_extrafield_global,
1276 comment, method,
level, raw,
1277 windowBits, memLevel, strategy,
1278 password, crcForCrypting, versionMadeBy, flagBase, 0);
1282 const void* extrafield_local,
uInt size_extrafield_local,
1283 const void* extrafield_global,
uInt size_extrafield_global,
1284 const char* comment,
int method,
int level,
int raw,
1285 int windowBits,
int memLevel,
int strategy,
1286 const char* password,
uLong crcForCrypting)
1289 extrafield_local, size_extrafield_local,
1290 extrafield_global, size_extrafield_global,
1291 comment, method,
level, raw,
1292 windowBits, memLevel, strategy,
1297 const void* extrafield_local,
uInt size_extrafield_local,
1298 const void* extrafield_global,
uInt size_extrafield_global,
1299 const char* comment,
int method,
int level,
int raw,
1300 int windowBits,
int memLevel,
int strategy,
1301 const char* password,
uLong crcForCrypting,
int zip64)
1304 extrafield_local, size_extrafield_local,
1305 extrafield_global, size_extrafield_global,
1306 comment, method,
level, raw,
1307 windowBits, memLevel, strategy,
1312 const void* extrafield_local,
uInt size_extrafield_local,
1313 const void* extrafield_global,
uInt size_extrafield_global,
1314 const char* comment,
int method,
int level,
int raw)
1317 extrafield_local, size_extrafield_local,
1318 extrafield_global, size_extrafield_global,
1319 comment, method,
level, raw,
1325 const void* extrafield_local,
uInt size_extrafield_local,
1326 const void* extrafield_global,
uInt size_extrafield_global,
1327 const char* comment,
int method,
int level,
int raw,
int zip64)
1330 extrafield_local, size_extrafield_local,
1331 extrafield_global, size_extrafield_global,
1332 comment, method,
level, raw,
1338 const void* extrafield_local,
uInt size_extrafield_local,
1339 const void*extrafield_global,
uInt size_extrafield_global,
1340 const char* comment,
int method,
int level,
int zip64)
1343 extrafield_local, size_extrafield_local,
1344 extrafield_global, size_extrafield_global,
1345 comment, method,
level, 0,
1351 const void* extrafield_local,
uInt size_extrafield_local,
1352 const void*extrafield_global,
uInt size_extrafield_global,
1353 const char* comment,
int method,
int level)
1356 extrafield_local, size_extrafield_local,
1357 extrafield_global, size_extrafield_global,
1358 comment, method,
level, 0,
1386 zi->
ci.bstream.total_in_lo32 = 0;
1387 zi->
ci.bstream.total_in_hi32 = 0;
1419 zi->
ci.bstream.next_in = (
void*)
buf;
1420 zi->
ci.bstream.avail_in =
len;
1423 while ((
err==BZ_RUN_OK) && (zi->
ci.bstream.avail_in>0))
1425 if (zi->
ci.bstream.avail_out == 0)
1434 if(
err != BZ_RUN_OK)
1439 uLong uTotalOutBefore_lo = zi->
ci.bstream.total_out_lo32;
1441 err=BZ2_bzCompress(&zi->
ci.bstream, BZ_RUN);
1447 if(
err == BZ_RUN_OK)
1490 for (
i = 0;
i < copy_this;
i++)
1518 uLong invalidValue = 0xffffffff;
1519 unsigned datasize = 0;
1534 uLong uTotalOutBefore;
1551 while (
err==BZ_FINISH_OK)
1553 uLong uTotalOutBefore;
1554 if (zi->
ci.bstream.avail_out == 0)
1561 uTotalOutBefore = zi->
ci.bstream.total_out_lo32;
1562 err=BZ2_bzCompress(&zi->
ci.bstream, BZ_FINISH);
1563 if(
err == BZ_STREAM_END)
1569 if(
err == BZ_FINISH_OK)
1593 int tmperr = BZ2_bzCompressEnd(&zi->
ci.bstream);
1781 uLong Zip64DataSize = 44;
1853 if(
pos >= 0xffffffff)
1867 uInt size_global_comment = 0;
1869 if(global_comment !=
NULL)
1870 size_global_comment = (
uInt)strlen(global_comment);
1874 if (
err ==
ZIP_OK && size_global_comment > 0)
1886 uLong size_centraldir = 0;
1900 #ifndef NO_ADDFILEINEXISTINGZIP
1901 if (global_comment==
NULL)
1943 #ifndef NO_ADDFILEINEXISTINGZIP
1962 if(pData ==
NULL || *dataLen < 4)
1965 pNewHeader = (
char*)
ALLOC((
unsigned)*dataLen);
1968 while(
p < (pData + *dataLen))
1971 dataSize = *(((
short*)
p)+1);
1980 memcpy(pTmp,
p, dataSize + 4);
1982 size += dataSize + 4;
1990 memset(pData,0, *dataLen);
#define zencode(pkeys, pcrc_32_tab, c, t)
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT deflate(z_streamp strm, int flush)
static st64 buf_read(RzBuffer *b, ut8 *buf, ut64 len)
RZ_API void Ht_() free(HtName_(Ht) *ht)
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
#define ZERROR64(filefunc, filestream)
#define ZLIB_FILEFUNC_MODE_EXISTING
#define ZOPEN64(filefunc, filename, mode)
#define ZSEEK64(filefunc, filestream, pos, mode)
#define ZLIB_FILEFUNC_SEEK_SET
#define ZREAD64(filefunc, filestream, buf, size)
#define ZCLOSE64(filefunc, filestream)
#define ZTELL64(filefunc, filestream)
#define ZLIB_FILEFUNC_MODE_CREATE
#define ZLIB_FILEFUNC_MODE_WRITE
#define ZLIB_FILEFUNC_SEEK_END
#define ZWRITE64(filefunc, filestream, buf, size)
#define ZLIB_FILEFUNC_MODE_READ
unsigned long long int ZPOS64_T
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char pathname
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
#define header(is_bt, len_min, ret_op)
static struct @218 keys[]
Byte buffered_data[Z_BUFSIZE]
uInt pos_in_buffered_data
ZPOS64_T pos_zip64extrainfo
unsigned crypt_header_size
ZPOS64_T pos_local_header
uLong size_centralExtraFree
ZPOS64_T totalCompressedData
const z_crc_t * pcrc_32_tab
ZPOS64_T totalUncompressedData
linkedlist_datablock_internal * last_block
linkedlist_datablock_internal * first_block
unsigned char data[SIZEDATA_INDATABLOCK]
uLong avail_in_this_block
struct linkedlist_datablock_internal_s * next_datablock
uLong filled_in_this_block
ZPOS64_T add_position_when_writing_offset
linkedlist_data central_dir
zlib_filefunc64_32_def z_filefunc
seek_file_func zseek32_file
zlib_filefunc64_def zfile_func64
tell_file_func ztell32_file
uint64_t uncompressed_size
if(dbg->bits==RZ_SYS_BITS_64)
int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc32_def)
struct linkedlist_data_s linkedlist_data
int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level)
int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int zip64)
int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase)
#define SIZECENTRALHEADER
int zip64local_putValue OF((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte))
int Write_EndOfCentralDirectoryRecord(zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
#define ZIP64ENDHEADERMAGIC
const char zip_copyright[]
int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
int ZEXPORT zipRemoveExtraInfoBlock(char *pData, int *dataLen, short sHeader)
int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
uLong zip64local_TmzDateToDosDate(const tm_zip *ptm)
int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal *zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32)
int LoadCentralDirectoryRecord(zip64_internal *pziinit)
void zip64local_putValue_inmemory(void *dest, ZPOS64_T x, int nbByte)
int ZEXPORT zipClose(zipFile file, const char *global_comment)
ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
void free_datablock(linkedlist_datablock_internal *ldi)
int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)
#define CENTRALHEADERMAGIC
int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting)
int Write_LocalFileHeader(zip64_internal *zi, const char *filename, uInt size_extrafield_local, const void *extrafield_local)
int zip64FlushWriteBuffer(zip64_internal *zi)
zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def)
#define SIZEDATA_INDATABLOCK
struct linkedlist_datablock_internal_s linkedlist_datablock_internal
zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment, zlib_filefunc64_def *pzlib_filefunc_def)
ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal *zi, ZPOS64_T zip64eocd_pos_inzip)
int zip64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
void init_linkedlist(linkedlist_data *ll)
int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
void free_linkedlist(linkedlist_data *ll)
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int zip64)
int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting, int zip64)
zipFile ZEXPORT zipOpen(const char *pathname, int append)
int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw)
int ZEXPORT zipCloseFileInZip(zipFile file)
linkedlist_datablock_internal * allocate_new_datablock()
int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
#define ZIP64ENDLOCHEADERMAGIC
int Write_GlobalComment(zip64_internal *zi, const char *global_comment)
zipFile ZEXPORT zipOpen64(const void *pathname, int append)
#define APPEND_STATUS_ADDINZIP
#define ZIP_INTERNALERROR
#define APPEND_STATUS_CREATEAFTER
#define APPEND_STATUS_CREATE
const z_crc_t FAR *ZEXPORT get_crc_table()
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
#define Z_DEFAULT_STRATEGY
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)