├── 3rd ├── md5 │ ├── md5.c │ └── md5.h └── zlib │ ├── README │ ├── adler32.c │ ├── crc32.c │ ├── crc32.h │ ├── crypt.h │ ├── deflate.c │ ├── deflate.h │ ├── gzguts.h │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── ioapi.c │ ├── ioapi.h │ ├── trees.c │ ├── trees.h │ ├── unzip.c │ ├── unzip.h │ ├── zconf.h │ ├── zip.c │ ├── zip.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h ├── Android.mk ├── Makefile ├── Makefile_Linux ├── README.md ├── doc ├── android签名证书文件的解析和签名校验的加强.pdf └── 格式解析图.png ├── example-apk └── CrackMe.apk ├── example.cpp ├── pkcs7.cpp └── pkcs7.h /3rd/md5/md5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * RFC 1321 compliant MD5 implementation 3 | * 4 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved 5 | * 6 | * This file is part of mbed TLS (https://tls.mbed.org) 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along 19 | * with this program; if not, write to the Free Software Foundation, Inc., 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | */ 22 | /* 23 | * The MD5 algorithm was designed by Ron Rivest in 1991. 24 | * 25 | * http://www.ietf.org/rfc/rfc1321.txt 26 | */ 27 | 28 | 29 | 30 | #include 31 | #include 32 | 33 | #include "md5.h" 34 | 35 | 36 | /* Implementation that should never be optimized out by the compiler */ 37 | static void mbedtls_zeroize( void *v, size_t n ) { 38 | volatile unsigned char *p = v; while( n-- ) *p++ = 0; 39 | } 40 | 41 | #if !defined(MBEDTLS_MD5_ALT) 42 | 43 | /* 44 | * 32-bit integer manipulation macros (little endian) 45 | */ 46 | #ifndef GET_UINT32_LE 47 | #define GET_UINT32_LE(n,b,i) \ 48 | { \ 49 | (n) = ( (uint32_t) (b)[(i) ] ) \ 50 | | ( (uint32_t) (b)[(i) + 1] << 8 ) \ 51 | | ( (uint32_t) (b)[(i) + 2] << 16 ) \ 52 | | ( (uint32_t) (b)[(i) + 3] << 24 ); \ 53 | } 54 | #endif 55 | 56 | #ifndef PUT_UINT32_LE 57 | #define PUT_UINT32_LE(n,b,i) \ 58 | { \ 59 | (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \ 60 | (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \ 61 | (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \ 62 | (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \ 63 | } 64 | #endif 65 | 66 | void mbedtls_md5_init( mbedtls_md5_context *ctx ) 67 | { 68 | memset( ctx, 0, sizeof( mbedtls_md5_context ) ); 69 | } 70 | 71 | void mbedtls_md5_free( mbedtls_md5_context *ctx ) 72 | { 73 | if( ctx == NULL ) 74 | return; 75 | 76 | mbedtls_zeroize( ctx, sizeof( mbedtls_md5_context ) ); 77 | } 78 | 79 | void mbedtls_md5_clone( mbedtls_md5_context *dst, 80 | const mbedtls_md5_context *src ) 81 | { 82 | *dst = *src; 83 | } 84 | 85 | /* 86 | * MD5 context setup 87 | */ 88 | void mbedtls_md5_starts( mbedtls_md5_context *ctx ) 89 | { 90 | ctx->total[0] = 0; 91 | ctx->total[1] = 0; 92 | 93 | ctx->state[0] = 0x67452301; 94 | ctx->state[1] = 0xEFCDAB89; 95 | ctx->state[2] = 0x98BADCFE; 96 | ctx->state[3] = 0x10325476; 97 | } 98 | 99 | #if !defined(MBEDTLS_MD5_PROCESS_ALT) 100 | void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] ) 101 | { 102 | uint32_t X[16], A, B, C, D; 103 | 104 | GET_UINT32_LE( X[ 0], data, 0 ); 105 | GET_UINT32_LE( X[ 1], data, 4 ); 106 | GET_UINT32_LE( X[ 2], data, 8 ); 107 | GET_UINT32_LE( X[ 3], data, 12 ); 108 | GET_UINT32_LE( X[ 4], data, 16 ); 109 | GET_UINT32_LE( X[ 5], data, 20 ); 110 | GET_UINT32_LE( X[ 6], data, 24 ); 111 | GET_UINT32_LE( X[ 7], data, 28 ); 112 | GET_UINT32_LE( X[ 8], data, 32 ); 113 | GET_UINT32_LE( X[ 9], data, 36 ); 114 | GET_UINT32_LE( X[10], data, 40 ); 115 | GET_UINT32_LE( X[11], data, 44 ); 116 | GET_UINT32_LE( X[12], data, 48 ); 117 | GET_UINT32_LE( X[13], data, 52 ); 118 | GET_UINT32_LE( X[14], data, 56 ); 119 | GET_UINT32_LE( X[15], data, 60 ); 120 | 121 | #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) 122 | 123 | #define P(a,b,c,d,k,s,t) \ 124 | { \ 125 | a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \ 126 | } 127 | 128 | A = ctx->state[0]; 129 | B = ctx->state[1]; 130 | C = ctx->state[2]; 131 | D = ctx->state[3]; 132 | 133 | #define F(x,y,z) (z ^ (x & (y ^ z))) 134 | 135 | P( A, B, C, D, 0, 7, 0xD76AA478 ); 136 | P( D, A, B, C, 1, 12, 0xE8C7B756 ); 137 | P( C, D, A, B, 2, 17, 0x242070DB ); 138 | P( B, C, D, A, 3, 22, 0xC1BDCEEE ); 139 | P( A, B, C, D, 4, 7, 0xF57C0FAF ); 140 | P( D, A, B, C, 5, 12, 0x4787C62A ); 141 | P( C, D, A, B, 6, 17, 0xA8304613 ); 142 | P( B, C, D, A, 7, 22, 0xFD469501 ); 143 | P( A, B, C, D, 8, 7, 0x698098D8 ); 144 | P( D, A, B, C, 9, 12, 0x8B44F7AF ); 145 | P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); 146 | P( B, C, D, A, 11, 22, 0x895CD7BE ); 147 | P( A, B, C, D, 12, 7, 0x6B901122 ); 148 | P( D, A, B, C, 13, 12, 0xFD987193 ); 149 | P( C, D, A, B, 14, 17, 0xA679438E ); 150 | P( B, C, D, A, 15, 22, 0x49B40821 ); 151 | 152 | #undef F 153 | 154 | #define F(x,y,z) (y ^ (z & (x ^ y))) 155 | 156 | P( A, B, C, D, 1, 5, 0xF61E2562 ); 157 | P( D, A, B, C, 6, 9, 0xC040B340 ); 158 | P( C, D, A, B, 11, 14, 0x265E5A51 ); 159 | P( B, C, D, A, 0, 20, 0xE9B6C7AA ); 160 | P( A, B, C, D, 5, 5, 0xD62F105D ); 161 | P( D, A, B, C, 10, 9, 0x02441453 ); 162 | P( C, D, A, B, 15, 14, 0xD8A1E681 ); 163 | P( B, C, D, A, 4, 20, 0xE7D3FBC8 ); 164 | P( A, B, C, D, 9, 5, 0x21E1CDE6 ); 165 | P( D, A, B, C, 14, 9, 0xC33707D6 ); 166 | P( C, D, A, B, 3, 14, 0xF4D50D87 ); 167 | P( B, C, D, A, 8, 20, 0x455A14ED ); 168 | P( A, B, C, D, 13, 5, 0xA9E3E905 ); 169 | P( D, A, B, C, 2, 9, 0xFCEFA3F8 ); 170 | P( C, D, A, B, 7, 14, 0x676F02D9 ); 171 | P( B, C, D, A, 12, 20, 0x8D2A4C8A ); 172 | 173 | #undef F 174 | 175 | #define F(x,y,z) (x ^ y ^ z) 176 | 177 | P( A, B, C, D, 5, 4, 0xFFFA3942 ); 178 | P( D, A, B, C, 8, 11, 0x8771F681 ); 179 | P( C, D, A, B, 11, 16, 0x6D9D6122 ); 180 | P( B, C, D, A, 14, 23, 0xFDE5380C ); 181 | P( A, B, C, D, 1, 4, 0xA4BEEA44 ); 182 | P( D, A, B, C, 4, 11, 0x4BDECFA9 ); 183 | P( C, D, A, B, 7, 16, 0xF6BB4B60 ); 184 | P( B, C, D, A, 10, 23, 0xBEBFBC70 ); 185 | P( A, B, C, D, 13, 4, 0x289B7EC6 ); 186 | P( D, A, B, C, 0, 11, 0xEAA127FA ); 187 | P( C, D, A, B, 3, 16, 0xD4EF3085 ); 188 | P( B, C, D, A, 6, 23, 0x04881D05 ); 189 | P( A, B, C, D, 9, 4, 0xD9D4D039 ); 190 | P( D, A, B, C, 12, 11, 0xE6DB99E5 ); 191 | P( C, D, A, B, 15, 16, 0x1FA27CF8 ); 192 | P( B, C, D, A, 2, 23, 0xC4AC5665 ); 193 | 194 | #undef F 195 | 196 | #define F(x,y,z) (y ^ (x | ~z)) 197 | 198 | P( A, B, C, D, 0, 6, 0xF4292244 ); 199 | P( D, A, B, C, 7, 10, 0x432AFF97 ); 200 | P( C, D, A, B, 14, 15, 0xAB9423A7 ); 201 | P( B, C, D, A, 5, 21, 0xFC93A039 ); 202 | P( A, B, C, D, 12, 6, 0x655B59C3 ); 203 | P( D, A, B, C, 3, 10, 0x8F0CCC92 ); 204 | P( C, D, A, B, 10, 15, 0xFFEFF47D ); 205 | P( B, C, D, A, 1, 21, 0x85845DD1 ); 206 | P( A, B, C, D, 8, 6, 0x6FA87E4F ); 207 | P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); 208 | P( C, D, A, B, 6, 15, 0xA3014314 ); 209 | P( B, C, D, A, 13, 21, 0x4E0811A1 ); 210 | P( A, B, C, D, 4, 6, 0xF7537E82 ); 211 | P( D, A, B, C, 11, 10, 0xBD3AF235 ); 212 | P( C, D, A, B, 2, 15, 0x2AD7D2BB ); 213 | P( B, C, D, A, 9, 21, 0xEB86D391 ); 214 | 215 | #undef F 216 | 217 | ctx->state[0] += A; 218 | ctx->state[1] += B; 219 | ctx->state[2] += C; 220 | ctx->state[3] += D; 221 | } 222 | #endif /* !MBEDTLS_MD5_PROCESS_ALT */ 223 | 224 | /* 225 | * MD5 process buffer 226 | */ 227 | void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen ) 228 | { 229 | size_t fill; 230 | uint32_t left; 231 | 232 | if( ilen == 0 ) 233 | return; 234 | 235 | left = ctx->total[0] & 0x3F; 236 | fill = 64 - left; 237 | 238 | ctx->total[0] += (uint32_t) ilen; 239 | ctx->total[0] &= 0xFFFFFFFF; 240 | 241 | if( ctx->total[0] < (uint32_t) ilen ) 242 | ctx->total[1]++; 243 | 244 | if( left && ilen >= fill ) 245 | { 246 | memcpy( (void *) (ctx->buffer + left), input, fill ); 247 | mbedtls_md5_process( ctx, ctx->buffer ); 248 | input += fill; 249 | ilen -= fill; 250 | left = 0; 251 | } 252 | 253 | while( ilen >= 64 ) 254 | { 255 | mbedtls_md5_process( ctx, input ); 256 | input += 64; 257 | ilen -= 64; 258 | } 259 | 260 | if( ilen > 0 ) 261 | { 262 | memcpy( (void *) (ctx->buffer + left), input, ilen ); 263 | } 264 | } 265 | 266 | static const unsigned char md5_padding[64] = 267 | { 268 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 269 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 270 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 271 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 272 | }; 273 | 274 | /* 275 | * MD5 final digest 276 | */ 277 | void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] ) 278 | { 279 | uint32_t last, padn; 280 | uint32_t high, low; 281 | unsigned char msglen[8]; 282 | 283 | high = ( ctx->total[0] >> 29 ) 284 | | ( ctx->total[1] << 3 ); 285 | low = ( ctx->total[0] << 3 ); 286 | 287 | PUT_UINT32_LE( low, msglen, 0 ); 288 | PUT_UINT32_LE( high, msglen, 4 ); 289 | 290 | last = ctx->total[0] & 0x3F; 291 | padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); 292 | 293 | mbedtls_md5_update( ctx, md5_padding, padn ); 294 | mbedtls_md5_update( ctx, msglen, 8 ); 295 | 296 | PUT_UINT32_LE( ctx->state[0], output, 0 ); 297 | PUT_UINT32_LE( ctx->state[1], output, 4 ); 298 | PUT_UINT32_LE( ctx->state[2], output, 8 ); 299 | PUT_UINT32_LE( ctx->state[3], output, 12 ); 300 | } 301 | 302 | #endif /* !MBEDTLS_MD5_ALT */ 303 | 304 | /* 305 | * output = MD5( input buffer ) 306 | */ 307 | void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] ) 308 | { 309 | mbedtls_md5_context ctx; 310 | 311 | mbedtls_md5_init( &ctx ); 312 | mbedtls_md5_starts( &ctx ); 313 | mbedtls_md5_update( &ctx, input, ilen ); 314 | mbedtls_md5_finish( &ctx, output ); 315 | mbedtls_md5_free( &ctx ); 316 | } 317 | 318 | 319 | /*int main() 320 | { 321 | int i; 322 | char result[16]={0}; 323 | unsigned char input[] = "admin"; 324 | mbedtls_md5(input, strlen(input), result); 325 | for (i = 0; i < 15; i++) 326 | printf("%02ux ", result[i]); 327 | 328 | }*/ 329 | 330 | -------------------------------------------------------------------------------- /3rd/md5/md5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mbedtls_md5.h 3 | * 4 | * \brief MD5 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved 7 | * 8 | * This file is part of mbed TLS (https://tls.mbed.org) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | #ifndef MBEDTLS_MD5_H 25 | #define MBEDTLS_MD5_H 26 | 27 | #include 28 | #include 29 | 30 | #if !defined(MBEDTLS_MD5_ALT) 31 | // Regular implementation 32 | // 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** 39 | * \brief MD5 context structure 40 | */ 41 | typedef struct 42 | { 43 | uint32_t total[2]; /*!< number of bytes processed */ 44 | uint32_t state[4]; /*!< intermediate digest state */ 45 | unsigned char buffer[64]; /*!< data block being processed */ 46 | } 47 | mbedtls_md5_context; 48 | 49 | /** 50 | * \brief Initialize MD5 context 51 | * 52 | * \param ctx MD5 context to be initialized 53 | */ 54 | void mbedtls_md5_init( mbedtls_md5_context *ctx ); 55 | 56 | /** 57 | * \brief Clear MD5 context 58 | * 59 | * \param ctx MD5 context to be cleared 60 | */ 61 | void mbedtls_md5_free( mbedtls_md5_context *ctx ); 62 | 63 | /** 64 | * \brief Clone (the state of) an MD5 context 65 | * 66 | * \param dst The destination context 67 | * \param src The context to be cloned 68 | */ 69 | void mbedtls_md5_clone( mbedtls_md5_context *dst, 70 | const mbedtls_md5_context *src ); 71 | 72 | /** 73 | * \brief MD5 context setup 74 | * 75 | * \param ctx context to be initialized 76 | */ 77 | void mbedtls_md5_starts( mbedtls_md5_context *ctx ); 78 | 79 | /** 80 | * \brief MD5 process buffer 81 | * 82 | * \param ctx MD5 context 83 | * \param input buffer holding the data 84 | * \param ilen length of the input data 85 | */ 86 | void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen ); 87 | 88 | /** 89 | * \brief MD5 final digest 90 | * 91 | * \param ctx MD5 context 92 | * \param output MD5 checksum result 93 | */ 94 | void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] ); 95 | 96 | /* Internal use */ 97 | void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] ); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | 104 | #endif /* MBEDTLS_MD5_ALT */ 105 | 106 | #ifdef __cplusplus 107 | extern "C" { 108 | #endif 109 | 110 | /** 111 | * \brief Output = MD5( input buffer ) 112 | * 113 | * \param input buffer holding the data 114 | * \param ilen length of the input data 115 | * \param output MD5 checksum result 116 | */ 117 | void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] ); 118 | 119 | /** 120 | * \brief Checkup routine 121 | * 122 | * \return 0 if successful, or 1 if the test failed 123 | */ 124 | int mbedtls_md5_self_test( int verbose ); 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif /* mbedtls_md5.h */ -------------------------------------------------------------------------------- /3rd/zlib/README: -------------------------------------------------------------------------------- 1 | ZLIB DATA COMPRESSION LIBRARY 2 | 3 | zlib 1.2.8 is a general purpose data compression library. All the code is 4 | thread safe. The data format used by the zlib library is described by RFCs 5 | (Request for Comments) 1950 to 1952 in the files 6 | http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and 7 | rfc1952 (gzip format). 8 | 9 | All functions of the compression library are documented in the file zlib.h 10 | (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example 11 | of the library is given in the file test/example.c which also tests that 12 | the library is working correctly. Another example is given in the file 13 | test/minigzip.c. The compression library itself is composed of all source 14 | files in the root directory. 15 | 16 | To compile all files and run the test program, follow the instructions given at 17 | the top of Makefile.in. In short "./configure; make test", and if that goes 18 | well, "make install" should work for most flavors of Unix. For Windows, use 19 | one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use 20 | make_vms.com. 21 | 22 | Questions about zlib should be sent to , or to Gilles Vollant 23 | for the Windows DLL version. The zlib home page is 24 | http://zlib.net/ . Before reporting a problem, please check this site to 25 | verify that you have the latest version of zlib; otherwise get the latest 26 | version and check whether the problem still exists or not. 27 | 28 | PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. 29 | 30 | Mark Nelson wrote an article about zlib for the Jan. 1997 31 | issue of Dr. Dobb's Journal; a copy of the article is available at 32 | http://marknelson.us/1997/01/01/zlib-engine/ . 33 | 34 | The changes made in version 1.2.8 are documented in the file ChangeLog. 35 | 36 | Unsupported third party contributions are provided in directory contrib/ . 37 | 38 | zlib is available in Java using the java.util.zip package, documented at 39 | http://java.sun.com/developer/technicalArticles/Programming/compression/ . 40 | 41 | A Perl interface to zlib written by Paul Marquess is available 42 | at CPAN (Comprehensive Perl Archive Network) sites, including 43 | http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . 44 | 45 | A Python interface to zlib written by A.M. Kuchling is 46 | available in Python 1.5 and later versions, see 47 | http://docs.python.org/library/zlib.html . 48 | 49 | zlib is built into tcl: http://wiki.tcl.tk/4610 . 50 | 51 | An experimental package to read and write files in .zip format, written on top 52 | of zlib by Gilles Vollant , is available in the 53 | contrib/minizip directory of zlib. 54 | 55 | 56 | Notes for some targets: 57 | 58 | - For Windows DLL versions, please see win32/DLL_FAQ.txt 59 | 60 | - For 64-bit Irix, deflate.c must be compiled without any optimization. With 61 | -O, one libpng test fails. The test works in 32 bit mode (with the -n32 62 | compiler flag). The compiler bug has been reported to SGI. 63 | 64 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works 65 | when compiled with cc. 66 | 67 | - On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is 68 | necessary to get gzprintf working correctly. This is done by configure. 69 | 70 | - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with 71 | other compilers. Use "make test" to check your compiler. 72 | 73 | - gzdopen is not supported on RISCOS or BEOS. 74 | 75 | - For PalmOs, see http://palmzlib.sourceforge.net/ 76 | 77 | 78 | Acknowledgments: 79 | 80 | The deflate format used by zlib was defined by Phil Katz. The deflate and 81 | zlib specifications were written by L. Peter Deutsch. Thanks to all the 82 | people who reported problems and suggested various improvements in zlib; they 83 | are too numerous to cite here. 84 | 85 | Copyright notice: 86 | 87 | (C) 1995-2013 Jean-loup Gailly and Mark Adler 88 | 89 | This software is provided 'as-is', without any express or implied 90 | warranty. In no event will the authors be held liable for any damages 91 | arising from the use of this software. 92 | 93 | Permission is granted to anyone to use this software for any purpose, 94 | including commercial applications, and to alter it and redistribute it 95 | freely, subject to the following restrictions: 96 | 97 | 1. The origin of this software must not be misrepresented; you must not 98 | claim that you wrote the original software. If you use this software 99 | in a product, an acknowledgment in the product documentation would be 100 | appreciated but is not required. 101 | 2. Altered source versions must be plainly marked as such, and must not be 102 | misrepresented as being the original software. 103 | 3. This notice may not be removed or altered from any source distribution. 104 | 105 | Jean-loup Gailly Mark Adler 106 | jloup@gzip.org madler@alumni.caltech.edu 107 | 108 | If you use the zlib library in a product, we would appreciate *not* receiving 109 | lengthy legal documents to sign. The sources are provided for free but without 110 | warranty of any kind. The library has been entirely written by Jean-loup 111 | Gailly and Mark Adler; it does not include third-party code. 112 | 113 | If you redistribute modified sources, we would appreciate that you include in 114 | the file ChangeLog history information documenting your changes. Please read 115 | the FAQ for more information on the distribution of modified source versions. 116 | -------------------------------------------------------------------------------- /3rd/zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2011 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | #define local static 11 | 12 | local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 13 | 14 | #define BASE 65521 /* largest prime smaller than 65536 */ 15 | #define NMAX 5552 16 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 17 | 18 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 19 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 20 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 21 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 22 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 23 | 24 | /* use NO_DIVIDE if your processor does not do division in hardware -- 25 | try it both ways to see which is faster */ 26 | #ifdef NO_DIVIDE 27 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15 28 | (thank you to John Reiser for pointing this out) */ 29 | # define CHOP(a) \ 30 | do { \ 31 | unsigned long tmp = a >> 16; \ 32 | a &= 0xffffUL; \ 33 | a += (tmp << 4) - tmp; \ 34 | } while (0) 35 | # define MOD28(a) \ 36 | do { \ 37 | CHOP(a); \ 38 | if (a >= BASE) a -= BASE; \ 39 | } while (0) 40 | # define MOD(a) \ 41 | do { \ 42 | CHOP(a); \ 43 | MOD28(a); \ 44 | } while (0) 45 | # define MOD63(a) \ 46 | do { /* this assumes a is not negative */ \ 47 | z_off64_t tmp = a >> 32; \ 48 | a &= 0xffffffffL; \ 49 | a += (tmp << 8) - (tmp << 5) + tmp; \ 50 | tmp = a >> 16; \ 51 | a &= 0xffffL; \ 52 | a += (tmp << 4) - tmp; \ 53 | tmp = a >> 16; \ 54 | a &= 0xffffL; \ 55 | a += (tmp << 4) - tmp; \ 56 | if (a >= BASE) a -= BASE; \ 57 | } while (0) 58 | #else 59 | # define MOD(a) a %= BASE 60 | # define MOD28(a) a %= BASE 61 | # define MOD63(a) a %= BASE 62 | #endif 63 | 64 | /* ========================================================================= */ 65 | uLong ZEXPORT adler32(adler, buf, len) 66 | uLong adler; 67 | const Bytef *buf; 68 | uInt len; 69 | { 70 | unsigned long sum2; 71 | unsigned n; 72 | 73 | /* split Adler-32 into component sums */ 74 | sum2 = (adler >> 16) & 0xffff; 75 | adler &= 0xffff; 76 | 77 | /* in case user likes doing a byte at a time, keep it fast */ 78 | if (len == 1) { 79 | adler += buf[0]; 80 | if (adler >= BASE) 81 | adler -= BASE; 82 | sum2 += adler; 83 | if (sum2 >= BASE) 84 | sum2 -= BASE; 85 | return adler | (sum2 << 16); 86 | } 87 | 88 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 89 | if (buf == Z_NULL) 90 | return 1L; 91 | 92 | /* in case short lengths are provided, keep it somewhat fast */ 93 | if (len < 16) { 94 | while (len--) { 95 | adler += *buf++; 96 | sum2 += adler; 97 | } 98 | if (adler >= BASE) 99 | adler -= BASE; 100 | MOD28(sum2); /* only added so many BASE's */ 101 | return adler | (sum2 << 16); 102 | } 103 | 104 | /* do length NMAX blocks -- requires just one modulo operation */ 105 | while (len >= NMAX) { 106 | len -= NMAX; 107 | n = NMAX / 16; /* NMAX is divisible by 16 */ 108 | do { 109 | DO16(buf); /* 16 sums unrolled */ 110 | buf += 16; 111 | } while (--n); 112 | MOD(adler); 113 | MOD(sum2); 114 | } 115 | 116 | /* do remaining bytes (less than NMAX, still just one modulo) */ 117 | if (len) { /* avoid modulos if none remaining */ 118 | while (len >= 16) { 119 | len -= 16; 120 | DO16(buf); 121 | buf += 16; 122 | } 123 | while (len--) { 124 | adler += *buf++; 125 | sum2 += adler; 126 | } 127 | MOD(adler); 128 | MOD(sum2); 129 | } 130 | 131 | /* return recombined sums */ 132 | return adler | (sum2 << 16); 133 | } 134 | 135 | /* ========================================================================= */ 136 | local uLong adler32_combine_(adler1, adler2, len2) 137 | uLong adler1; 138 | uLong adler2; 139 | z_off64_t len2; 140 | { 141 | unsigned long sum1; 142 | unsigned long sum2; 143 | unsigned rem; 144 | 145 | /* for negative len, return invalid adler32 as a clue for debugging */ 146 | if (len2 < 0) 147 | return 0xffffffffUL; 148 | 149 | /* the derivation of this formula is left as an exercise for the reader */ 150 | MOD63(len2); /* assumes len2 >= 0 */ 151 | rem = (unsigned)len2; 152 | sum1 = adler1 & 0xffff; 153 | sum2 = rem * sum1; 154 | MOD(sum2); 155 | sum1 += (adler2 & 0xffff) + BASE - 1; 156 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 157 | if (sum1 >= BASE) sum1 -= BASE; 158 | if (sum1 >= BASE) sum1 -= BASE; 159 | if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); 160 | if (sum2 >= BASE) sum2 -= BASE; 161 | return sum1 | (sum2 << 16); 162 | } 163 | 164 | /* ========================================================================= */ 165 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 166 | uLong adler1; 167 | uLong adler2; 168 | z_off_t len2; 169 | { 170 | return adler32_combine_(adler1, adler2, len2); 171 | } 172 | 173 | uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 174 | uLong adler1; 175 | uLong adler2; 176 | z_off64_t len2; 177 | { 178 | return adler32_combine_(adler1, adler2, len2); 179 | } 180 | -------------------------------------------------------------------------------- /3rd/zlib/crc32.c: -------------------------------------------------------------------------------- 1 | /* crc32.c -- compute the CRC-32 of a data stream 2 | * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | * 5 | * Thanks to Rodney Brown for his contribution of faster 6 | * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing 7 | * tables for updating the shift register in one step with three exclusive-ors 8 | * instead of four steps with four exclusive-ors. This results in about a 9 | * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. 10 | */ 11 | 12 | /* @(#) $Id$ */ 13 | 14 | /* 15 | Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore 16 | protection on the static variables used to control the first-use generation 17 | of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should 18 | first call get_crc_table() to initialize the tables before allowing more than 19 | one thread to use crc32(). 20 | 21 | DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. 22 | */ 23 | 24 | #ifdef MAKECRCH 25 | # include 26 | # ifndef DYNAMIC_CRC_TABLE 27 | # define DYNAMIC_CRC_TABLE 28 | # endif /* !DYNAMIC_CRC_TABLE */ 29 | #endif /* MAKECRCH */ 30 | 31 | #include "zutil.h" /* for STDC and FAR definitions */ 32 | 33 | #define local static 34 | 35 | /* Definitions for doing the crc four data bytes at a time. */ 36 | #if !defined(NOBYFOUR) && defined(Z_U4) 37 | # define BYFOUR 38 | #endif 39 | #ifdef BYFOUR 40 | local unsigned long crc32_little OF((unsigned long, 41 | const unsigned char FAR *, unsigned)); 42 | local unsigned long crc32_big OF((unsigned long, 43 | const unsigned char FAR *, unsigned)); 44 | # define TBLS 8 45 | #else 46 | # define TBLS 1 47 | #endif /* BYFOUR */ 48 | 49 | /* Local functions for crc concatenation */ 50 | local unsigned long gf2_matrix_times OF((unsigned long *mat, 51 | unsigned long vec)); 52 | local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); 53 | local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); 54 | 55 | 56 | #ifdef DYNAMIC_CRC_TABLE 57 | 58 | local volatile int crc_table_empty = 1; 59 | local z_crc_t FAR crc_table[TBLS][256]; 60 | local void make_crc_table OF((void)); 61 | #ifdef MAKECRCH 62 | local void write_table OF((FILE *, const z_crc_t FAR *)); 63 | #endif /* MAKECRCH */ 64 | /* 65 | Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: 66 | x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. 67 | 68 | Polynomials over GF(2) are represented in binary, one bit per coefficient, 69 | with the lowest powers in the most significant bit. Then adding polynomials 70 | is just exclusive-or, and multiplying a polynomial by x is a right shift by 71 | one. If we call the above polynomial p, and represent a byte as the 72 | polynomial q, also with the lowest power in the most significant bit (so the 73 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 74 | where a mod b means the remainder after dividing a by b. 75 | 76 | This calculation is done using the shift-register method of multiplying and 77 | taking the remainder. The register is initialized to zero, and for each 78 | incoming bit, x^32 is added mod p to the register if the bit is a one (where 79 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 80 | x (which is shifting right by one and adding x^32 mod p if the bit shifted 81 | out is a one). We start with the highest power (least significant bit) of 82 | q and repeat for all eight bits of q. 83 | 84 | The first table is simply the CRC of all possible eight bit values. This is 85 | all the information needed to generate CRCs on data a byte at a time for all 86 | combinations of CRC register values and incoming bytes. The remaining tables 87 | allow for word-at-a-time CRC calculation for both big-endian and little- 88 | endian machines, where a word is four bytes. 89 | */ 90 | local void make_crc_table() 91 | { 92 | z_crc_t c; 93 | int n, k; 94 | z_crc_t poly; /* polynomial exclusive-or pattern */ 95 | /* terms of polynomial defining this crc (except x^32): */ 96 | static volatile int first = 1; /* flag to limit concurrent making */ 97 | static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 98 | 99 | /* See if another task is already doing this (not thread-safe, but better 100 | than nothing -- significantly reduces duration of vulnerability in 101 | case the advice about DYNAMIC_CRC_TABLE is ignored) */ 102 | if (first) { 103 | first = 0; 104 | 105 | /* make exclusive-or pattern from polynomial (0xedb88320UL) */ 106 | poly = 0; 107 | for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) 108 | poly |= (z_crc_t)1 << (31 - p[n]); 109 | 110 | /* generate a crc for every 8-bit value */ 111 | for (n = 0; n < 256; n++) { 112 | c = (z_crc_t)n; 113 | for (k = 0; k < 8; k++) 114 | c = c & 1 ? poly ^ (c >> 1) : c >> 1; 115 | crc_table[0][n] = c; 116 | } 117 | 118 | #ifdef BYFOUR 119 | /* generate crc for each value followed by one, two, and three zeros, 120 | and then the byte reversal of those as well as the first table */ 121 | for (n = 0; n < 256; n++) { 122 | c = crc_table[0][n]; 123 | crc_table[4][n] = ZSWAP32(c); 124 | for (k = 1; k < 4; k++) { 125 | c = crc_table[0][c & 0xff] ^ (c >> 8); 126 | crc_table[k][n] = c; 127 | crc_table[k + 4][n] = ZSWAP32(c); 128 | } 129 | } 130 | #endif /* BYFOUR */ 131 | 132 | crc_table_empty = 0; 133 | } 134 | else { /* not first */ 135 | /* wait for the other guy to finish (not efficient, but rare) */ 136 | while (crc_table_empty) 137 | ; 138 | } 139 | 140 | #ifdef MAKECRCH 141 | /* write out CRC tables to crc32.h */ 142 | { 143 | FILE *out; 144 | 145 | out = fopen("crc32.h", "w"); 146 | if (out == NULL) return; 147 | fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); 148 | fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); 149 | fprintf(out, "local const z_crc_t FAR "); 150 | fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); 151 | write_table(out, crc_table[0]); 152 | # ifdef BYFOUR 153 | fprintf(out, "#ifdef BYFOUR\n"); 154 | for (k = 1; k < 8; k++) { 155 | fprintf(out, " },\n {\n"); 156 | write_table(out, crc_table[k]); 157 | } 158 | fprintf(out, "#endif\n"); 159 | # endif /* BYFOUR */ 160 | fprintf(out, " }\n};\n"); 161 | fclose(out); 162 | } 163 | #endif /* MAKECRCH */ 164 | } 165 | 166 | #ifdef MAKECRCH 167 | local void write_table(out, table) 168 | FILE *out; 169 | const z_crc_t FAR *table; 170 | { 171 | int n; 172 | 173 | for (n = 0; n < 256; n++) 174 | fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", 175 | (unsigned long)(table[n]), 176 | n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); 177 | } 178 | #endif /* MAKECRCH */ 179 | 180 | #else /* !DYNAMIC_CRC_TABLE */ 181 | /* ======================================================================== 182 | * Tables of CRC-32s of all single-byte values, made by make_crc_table(). 183 | */ 184 | #include "crc32.h" 185 | #endif /* DYNAMIC_CRC_TABLE */ 186 | 187 | /* ========================================================================= 188 | * This function can be used by asm versions of crc32() 189 | */ 190 | const z_crc_t FAR * ZEXPORT get_crc_table() 191 | { 192 | #ifdef DYNAMIC_CRC_TABLE 193 | if (crc_table_empty) 194 | make_crc_table(); 195 | #endif /* DYNAMIC_CRC_TABLE */ 196 | return (const z_crc_t FAR *)crc_table; 197 | } 198 | 199 | /* ========================================================================= */ 200 | #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) 201 | #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 202 | 203 | /* ========================================================================= */ 204 | unsigned long ZEXPORT crc32(crc, buf, len) 205 | unsigned long crc; 206 | const unsigned char FAR *buf; 207 | uInt len; 208 | { 209 | if (buf == Z_NULL) return 0UL; 210 | 211 | #ifdef DYNAMIC_CRC_TABLE 212 | if (crc_table_empty) 213 | make_crc_table(); 214 | #endif /* DYNAMIC_CRC_TABLE */ 215 | 216 | #ifdef BYFOUR 217 | if (sizeof(void *) == sizeof(ptrdiff_t)) { 218 | z_crc_t endian; 219 | 220 | endian = 1; 221 | if (*((unsigned char *)(&endian))) 222 | return crc32_little(crc, buf, len); 223 | else 224 | return crc32_big(crc, buf, len); 225 | } 226 | #endif /* BYFOUR */ 227 | crc = crc ^ 0xffffffffUL; 228 | while (len >= 8) { 229 | DO8; 230 | len -= 8; 231 | } 232 | if (len) do { 233 | DO1; 234 | } while (--len); 235 | return crc ^ 0xffffffffUL; 236 | } 237 | 238 | #ifdef BYFOUR 239 | 240 | /* ========================================================================= */ 241 | #define DOLIT4 c ^= *buf4++; \ 242 | c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ 243 | crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] 244 | #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 245 | 246 | /* ========================================================================= */ 247 | local unsigned long crc32_little(crc, buf, len) 248 | unsigned long crc; 249 | const unsigned char FAR *buf; 250 | unsigned len; 251 | { 252 | register z_crc_t c; 253 | register const z_crc_t FAR *buf4; 254 | 255 | c = (z_crc_t)crc; 256 | c = ~c; 257 | while (len && ((ptrdiff_t)buf & 3)) { 258 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 259 | len--; 260 | } 261 | 262 | buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 263 | while (len >= 32) { 264 | DOLIT32; 265 | len -= 32; 266 | } 267 | while (len >= 4) { 268 | DOLIT4; 269 | len -= 4; 270 | } 271 | buf = (const unsigned char FAR *)buf4; 272 | 273 | if (len) do { 274 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 275 | } while (--len); 276 | c = ~c; 277 | return (unsigned long)c; 278 | } 279 | 280 | /* ========================================================================= */ 281 | #define DOBIG4 c ^= *++buf4; \ 282 | c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ 283 | crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] 284 | #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 285 | 286 | /* ========================================================================= */ 287 | local unsigned long crc32_big(crc, buf, len) 288 | unsigned long crc; 289 | const unsigned char FAR *buf; 290 | unsigned len; 291 | { 292 | register z_crc_t c; 293 | register const z_crc_t FAR *buf4; 294 | 295 | c = ZSWAP32((z_crc_t)crc); 296 | c = ~c; 297 | while (len && ((ptrdiff_t)buf & 3)) { 298 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 299 | len--; 300 | } 301 | 302 | buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 303 | buf4--; 304 | while (len >= 32) { 305 | DOBIG32; 306 | len -= 32; 307 | } 308 | while (len >= 4) { 309 | DOBIG4; 310 | len -= 4; 311 | } 312 | buf4++; 313 | buf = (const unsigned char FAR *)buf4; 314 | 315 | if (len) do { 316 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 317 | } while (--len); 318 | c = ~c; 319 | return (unsigned long)(ZSWAP32(c)); 320 | } 321 | 322 | #endif /* BYFOUR */ 323 | 324 | #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ 325 | 326 | /* ========================================================================= */ 327 | local unsigned long gf2_matrix_times(mat, vec) 328 | unsigned long *mat; 329 | unsigned long vec; 330 | { 331 | unsigned long sum; 332 | 333 | sum = 0; 334 | while (vec) { 335 | if (vec & 1) 336 | sum ^= *mat; 337 | vec >>= 1; 338 | mat++; 339 | } 340 | return sum; 341 | } 342 | 343 | /* ========================================================================= */ 344 | local void gf2_matrix_square(square, mat) 345 | unsigned long *square; 346 | unsigned long *mat; 347 | { 348 | int n; 349 | 350 | for (n = 0; n < GF2_DIM; n++) 351 | square[n] = gf2_matrix_times(mat, mat[n]); 352 | } 353 | 354 | /* ========================================================================= */ 355 | local uLong crc32_combine_(crc1, crc2, len2) 356 | uLong crc1; 357 | uLong crc2; 358 | z_off64_t len2; 359 | { 360 | int n; 361 | unsigned long row; 362 | unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ 363 | unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ 364 | 365 | /* degenerate case (also disallow negative lengths) */ 366 | if (len2 <= 0) 367 | return crc1; 368 | 369 | /* put operator for one zero bit in odd */ 370 | odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ 371 | row = 1; 372 | for (n = 1; n < GF2_DIM; n++) { 373 | odd[n] = row; 374 | row <<= 1; 375 | } 376 | 377 | /* put operator for two zero bits in even */ 378 | gf2_matrix_square(even, odd); 379 | 380 | /* put operator for four zero bits in odd */ 381 | gf2_matrix_square(odd, even); 382 | 383 | /* apply len2 zeros to crc1 (first square will put the operator for one 384 | zero byte, eight zero bits, in even) */ 385 | do { 386 | /* apply zeros operator for this bit of len2 */ 387 | gf2_matrix_square(even, odd); 388 | if (len2 & 1) 389 | crc1 = gf2_matrix_times(even, crc1); 390 | len2 >>= 1; 391 | 392 | /* if no more bits set, then done */ 393 | if (len2 == 0) 394 | break; 395 | 396 | /* another iteration of the loop with odd and even swapped */ 397 | gf2_matrix_square(odd, even); 398 | if (len2 & 1) 399 | crc1 = gf2_matrix_times(odd, crc1); 400 | len2 >>= 1; 401 | 402 | /* if no more bits set, then done */ 403 | } while (len2 != 0); 404 | 405 | /* return combined crc */ 406 | crc1 ^= crc2; 407 | return crc1; 408 | } 409 | 410 | /* ========================================================================= */ 411 | uLong ZEXPORT crc32_combine(crc1, crc2, len2) 412 | uLong crc1; 413 | uLong crc2; 414 | z_off_t len2; 415 | { 416 | return crc32_combine_(crc1, crc2, len2); 417 | } 418 | 419 | uLong ZEXPORT crc32_combine64(crc1, crc2, len2) 420 | uLong crc1; 421 | uLong crc2; 422 | z_off64_t len2; 423 | { 424 | return crc32_combine_(crc1, crc2, len2); 425 | } 426 | -------------------------------------------------------------------------------- /3rd/zlib/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile 2 | 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | 8 | This code is a modified version of crypting code in Infozip distribution 9 | 10 | The encryption/decryption parts of this source code (as opposed to the 11 | non-echoing password parts) were originally written in Europe. The 12 | whole source package can be freely distributed, including from the USA. 13 | (Prior to January 2000, re-export from the US was a violation of US law.) 14 | 15 | This encryption code is a direct transcription of the algorithm from 16 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 17 | file (appnote.txt) is distributed with the PKZIP program (even in the 18 | version without encryption capabilities). 19 | 20 | If you don't need crypting in your application, just define symbols 21 | NOCRYPT and NOUNCRYPT. 22 | 23 | This code support the "Traditional PKWARE Encryption". 24 | 25 | The new AES encryption added on Zip format by Winzip (see the page 26 | http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong 27 | Encryption is not supported. 28 | */ 29 | 30 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 31 | 32 | /*********************************************************************** 33 | * Return the next byte in the pseudo-random sequence 34 | */ 35 | static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) 36 | { 37 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 38 | * unpredictable manner on 16-bit systems; not a problem 39 | * with any known compiler so far, though */ 40 | 41 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 42 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 43 | } 44 | 45 | /*********************************************************************** 46 | * Update the encryption keys with the next byte of plain text 47 | */ 48 | static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c) 49 | { 50 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 51 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 52 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 53 | { 54 | register int keyshift = (int)((*(pkeys+1)) >> 24); 55 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 56 | } 57 | return c; 58 | } 59 | 60 | 61 | /*********************************************************************** 62 | * Initialize the encryption keys and the random header according to 63 | * the given password. 64 | */ 65 | static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab) 66 | { 67 | *(pkeys+0) = 305419896L; 68 | *(pkeys+1) = 591751049L; 69 | *(pkeys+2) = 878082192L; 70 | while (*passwd != '\0') { 71 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 72 | passwd++; 73 | } 74 | } 75 | 76 | #define zdecode(pkeys,pcrc_32_tab,c) \ 77 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 78 | 79 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 80 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 81 | 82 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 83 | 84 | #define RAND_HEAD_LEN 12 85 | /* "last resort" source for second part of crypt seed pattern */ 86 | # ifndef ZCR_SEED2 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 88 | # endif 89 | 90 | static int crypthead(const char* passwd, /* password string */ 91 | unsigned char* buf, /* where to write header */ 92 | int bufSize, 93 | unsigned long* pkeys, 94 | const z_crc_t* pcrc_32_tab, 95 | unsigned long crcForCrypting) 96 | { 97 | int n; /* index in random header */ 98 | int t; /* temporary */ 99 | int c; /* random byte */ 100 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 101 | static unsigned calls = 0; /* ensure different random header each time */ 102 | 103 | if (bufSize> 7) & 0xff; 118 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 119 | } 120 | /* Encrypt random header (last two bytes is high word of crc) */ 121 | init_keys(passwd, pkeys, pcrc_32_tab); 122 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 123 | { 124 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 125 | } 126 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 127 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 128 | return n; 129 | } 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /3rd/zlib/deflate.h: -------------------------------------------------------------------------------- 1 | /* deflate.h -- internal compression state 2 | * Copyright (C) 1995-2012 Jean-loup Gailly 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef DEFLATE_H 14 | #define DEFLATE_H 15 | 16 | #include "zutil.h" 17 | 18 | /* define NO_GZIP when compiling if you want to disable gzip header and 19 | trailer creation by deflate(). NO_GZIP would be used to avoid linking in 20 | the crc code when it is not needed. For shared libraries, gzip encoding 21 | should be left enabled. */ 22 | #ifndef NO_GZIP 23 | # define GZIP 24 | #endif 25 | 26 | /* =========================================================================== 27 | * Internal compression state. 28 | */ 29 | 30 | #define LENGTH_CODES 29 31 | /* number of length codes, not counting the special END_BLOCK code */ 32 | 33 | #define LITERALS 256 34 | /* number of literal bytes 0..255 */ 35 | 36 | #define L_CODES (LITERALS+1+LENGTH_CODES) 37 | /* number of Literal or Length codes, including the END_BLOCK code */ 38 | 39 | #define D_CODES 30 40 | /* number of distance codes */ 41 | 42 | #define BL_CODES 19 43 | /* number of codes used to transfer the bit lengths */ 44 | 45 | #define HEAP_SIZE (2*L_CODES+1) 46 | /* maximum heap size */ 47 | 48 | #define MAX_BITS 15 49 | /* All codes must not exceed MAX_BITS bits */ 50 | 51 | #define Buf_size 16 52 | /* size of bit buffer in bi_buf */ 53 | 54 | #define INIT_STATE 42 55 | #define EXTRA_STATE 69 56 | #define NAME_STATE 73 57 | #define COMMENT_STATE 91 58 | #define HCRC_STATE 103 59 | #define BUSY_STATE 113 60 | #define FINISH_STATE 666 61 | /* Stream status */ 62 | 63 | 64 | /* Data structure describing a single value and its code string. */ 65 | typedef struct ct_data_s { 66 | union { 67 | ush freq; /* frequency count */ 68 | ush code; /* bit string */ 69 | } fc; 70 | union { 71 | ush dad; /* father node in Huffman tree */ 72 | ush len; /* length of bit string */ 73 | } dl; 74 | } FAR ct_data; 75 | 76 | #define Freq fc.freq 77 | #define Code fc.code 78 | #define Dad dl.dad 79 | #define Len dl.len 80 | 81 | typedef struct static_tree_desc_s static_tree_desc; 82 | 83 | typedef struct tree_desc_s { 84 | ct_data *dyn_tree; /* the dynamic tree */ 85 | int max_code; /* largest code with non zero frequency */ 86 | static_tree_desc *stat_desc; /* the corresponding static tree */ 87 | } FAR tree_desc; 88 | 89 | typedef ush Pos; 90 | typedef Pos FAR Posf; 91 | typedef unsigned IPos; 92 | 93 | /* A Pos is an index in the character window. We use short instead of int to 94 | * save space in the various tables. IPos is used only for parameter passing. 95 | */ 96 | 97 | typedef struct internal_state { 98 | z_streamp strm; /* pointer back to this zlib stream */ 99 | int status; /* as the name implies */ 100 | Bytef *pending_buf; /* output still pending */ 101 | ulg pending_buf_size; /* size of pending_buf */ 102 | Bytef *pending_out; /* next pending byte to output to the stream */ 103 | uInt pending; /* nb of bytes in the pending buffer */ 104 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 105 | gz_headerp gzhead; /* gzip header information to write */ 106 | uInt gzindex; /* where in extra, name, or comment */ 107 | Byte method; /* can only be DEFLATED */ 108 | int last_flush; /* value of flush param for previous deflate call */ 109 | 110 | /* used by deflate.c: */ 111 | 112 | uInt w_size; /* LZ77 window size (32K by default) */ 113 | uInt w_bits; /* log2(w_size) (8..16) */ 114 | uInt w_mask; /* w_size - 1 */ 115 | 116 | Bytef *window; 117 | /* Sliding window. Input bytes are read into the second half of the window, 118 | * and move to the first half later to keep a dictionary of at least wSize 119 | * bytes. With this organization, matches are limited to a distance of 120 | * wSize-MAX_MATCH bytes, but this ensures that IO is always 121 | * performed with a length multiple of the block size. Also, it limits 122 | * the window size to 64K, which is quite useful on MSDOS. 123 | * To do: use the user input buffer as sliding window. 124 | */ 125 | 126 | ulg window_size; 127 | /* Actual size of window: 2*wSize, except when the user input buffer 128 | * is directly used as sliding window. 129 | */ 130 | 131 | Posf *prev; 132 | /* Link to older string with same hash index. To limit the size of this 133 | * array to 64K, this link is maintained only for the last 32K strings. 134 | * An index in this array is thus a window index modulo 32K. 135 | */ 136 | 137 | Posf *head; /* Heads of the hash chains or NIL. */ 138 | 139 | uInt ins_h; /* hash index of string to be inserted */ 140 | uInt hash_size; /* number of elements in hash table */ 141 | uInt hash_bits; /* log2(hash_size) */ 142 | uInt hash_mask; /* hash_size-1 */ 143 | 144 | uInt hash_shift; 145 | /* Number of bits by which ins_h must be shifted at each input 146 | * step. It must be such that after MIN_MATCH steps, the oldest 147 | * byte no longer takes part in the hash key, that is: 148 | * hash_shift * MIN_MATCH >= hash_bits 149 | */ 150 | 151 | long block_start; 152 | /* Window position at the beginning of the current output block. Gets 153 | * negative when the window is moved backwards. 154 | */ 155 | 156 | uInt match_length; /* length of best match */ 157 | IPos prev_match; /* previous match */ 158 | int match_available; /* set if previous match exists */ 159 | uInt strstart; /* start of string to insert */ 160 | uInt match_start; /* start of matching string */ 161 | uInt lookahead; /* number of valid bytes ahead in window */ 162 | 163 | uInt prev_length; 164 | /* Length of the best match at previous step. Matches not greater than this 165 | * are discarded. This is used in the lazy match evaluation. 166 | */ 167 | 168 | uInt max_chain_length; 169 | /* To speed up deflation, hash chains are never searched beyond this 170 | * length. A higher limit improves compression ratio but degrades the 171 | * speed. 172 | */ 173 | 174 | uInt max_lazy_match; 175 | /* Attempt to find a better match only when the current match is strictly 176 | * smaller than this value. This mechanism is used only for compression 177 | * levels >= 4. 178 | */ 179 | # define max_insert_length max_lazy_match 180 | /* Insert new strings in the hash table only if the match length is not 181 | * greater than this length. This saves time but degrades compression. 182 | * max_insert_length is used only for compression levels <= 3. 183 | */ 184 | 185 | int level; /* compression level (1..9) */ 186 | int strategy; /* favor or force Huffman coding*/ 187 | 188 | uInt good_match; 189 | /* Use a faster search when the previous match is longer than this */ 190 | 191 | int nice_match; /* Stop searching when current match exceeds this */ 192 | 193 | /* used by trees.c: */ 194 | /* Didn't use ct_data typedef below to suppress compiler warning */ 195 | struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ 196 | struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ 197 | struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ 198 | 199 | struct tree_desc_s l_desc; /* desc. for literal tree */ 200 | struct tree_desc_s d_desc; /* desc. for distance tree */ 201 | struct tree_desc_s bl_desc; /* desc. for bit length tree */ 202 | 203 | ush bl_count[MAX_BITS+1]; 204 | /* number of codes at each bit length for an optimal tree */ 205 | 206 | int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ 207 | int heap_len; /* number of elements in the heap */ 208 | int heap_max; /* element of largest frequency */ 209 | /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. 210 | * The same heap array is used to build all trees. 211 | */ 212 | 213 | uch depth[2*L_CODES+1]; 214 | /* Depth of each subtree used as tie breaker for trees of equal frequency 215 | */ 216 | 217 | uchf *l_buf; /* buffer for literals or lengths */ 218 | 219 | uInt lit_bufsize; 220 | /* Size of match buffer for literals/lengths. There are 4 reasons for 221 | * limiting lit_bufsize to 64K: 222 | * - frequencies can be kept in 16 bit counters 223 | * - if compression is not successful for the first block, all input 224 | * data is still in the window so we can still emit a stored block even 225 | * when input comes from standard input. (This can also be done for 226 | * all blocks if lit_bufsize is not greater than 32K.) 227 | * - if compression is not successful for a file smaller than 64K, we can 228 | * even emit a stored file instead of a stored block (saving 5 bytes). 229 | * This is applicable only for zip (not gzip or zlib). 230 | * - creating new Huffman trees less frequently may not provide fast 231 | * adaptation to changes in the input data statistics. (Take for 232 | * example a binary file with poorly compressible code followed by 233 | * a highly compressible string table.) Smaller buffer sizes give 234 | * fast adaptation but have of course the overhead of transmitting 235 | * trees more frequently. 236 | * - I can't count above 4 237 | */ 238 | 239 | uInt last_lit; /* running index in l_buf */ 240 | 241 | ushf *d_buf; 242 | /* Buffer for distances. To simplify the code, d_buf and l_buf have 243 | * the same number of elements. To use different lengths, an extra flag 244 | * array would be necessary. 245 | */ 246 | 247 | ulg opt_len; /* bit length of current block with optimal trees */ 248 | ulg static_len; /* bit length of current block with static trees */ 249 | uInt matches; /* number of string matches in current block */ 250 | uInt insert; /* bytes at end of window left to insert */ 251 | 252 | #ifdef DEBUG 253 | ulg compressed_len; /* total bit length of compressed file mod 2^32 */ 254 | ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ 255 | #endif 256 | 257 | ush bi_buf; 258 | /* Output buffer. bits are inserted starting at the bottom (least 259 | * significant bits). 260 | */ 261 | int bi_valid; 262 | /* Number of valid bits in bi_buf. All bits above the last valid bit 263 | * are always zero. 264 | */ 265 | 266 | ulg high_water; 267 | /* High water mark offset in window for initialized bytes -- bytes above 268 | * this are set to zero in order to avoid memory check warnings when 269 | * longest match routines access bytes past the input. This is then 270 | * updated to the new high water mark. 271 | */ 272 | 273 | } FAR deflate_state; 274 | 275 | /* Output a byte on the stream. 276 | * IN assertion: there is enough room in pending_buf. 277 | */ 278 | #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} 279 | 280 | 281 | #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) 282 | /* Minimum amount of lookahead, except at the end of the input file. 283 | * See deflate.c for comments about the MIN_MATCH+1. 284 | */ 285 | 286 | #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) 287 | /* In order to simplify the code, particularly on 16 bit machines, match 288 | * distances are limited to MAX_DIST instead of WSIZE. 289 | */ 290 | 291 | #define WIN_INIT MAX_MATCH 292 | /* Number of bytes after end of data in window to initialize in order to avoid 293 | memory checker errors from longest match routines */ 294 | 295 | /* in trees.c */ 296 | void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); 297 | int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 298 | void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, 299 | ulg stored_len, int last)); 300 | void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); 301 | void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); 302 | void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, 303 | ulg stored_len, int last)); 304 | 305 | #define d_code(dist) \ 306 | ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) 307 | /* Mapping from a distance to a distance code. dist is the distance - 1 and 308 | * must not have side effects. _dist_code[256] and _dist_code[257] are never 309 | * used. 310 | */ 311 | 312 | #ifndef DEBUG 313 | /* Inline versions of _tr_tally for speed: */ 314 | 315 | #if defined(GEN_TREES_H) || !defined(STDC) 316 | extern uch ZLIB_INTERNAL _length_code[]; 317 | extern uch ZLIB_INTERNAL _dist_code[]; 318 | #else 319 | extern const uch ZLIB_INTERNAL _length_code[]; 320 | extern const uch ZLIB_INTERNAL _dist_code[]; 321 | #endif 322 | 323 | # define _tr_tally_lit(s, c, flush) \ 324 | { uch cc = (c); \ 325 | s->d_buf[s->last_lit] = 0; \ 326 | s->l_buf[s->last_lit++] = cc; \ 327 | s->dyn_ltree[cc].Freq++; \ 328 | flush = (s->last_lit == s->lit_bufsize-1); \ 329 | } 330 | # define _tr_tally_dist(s, distance, length, flush) \ 331 | { uch len = (length); \ 332 | ush dist = (distance); \ 333 | s->d_buf[s->last_lit] = dist; \ 334 | s->l_buf[s->last_lit++] = len; \ 335 | dist--; \ 336 | s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ 337 | s->dyn_dtree[d_code(dist)].Freq++; \ 338 | flush = (s->last_lit == s->lit_bufsize-1); \ 339 | } 340 | #else 341 | # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) 342 | # define _tr_tally_dist(s, distance, length, flush) \ 343 | flush = _tr_tally(s, distance, length) 344 | #endif 345 | 346 | #endif /* DEFLATE_H */ 347 | -------------------------------------------------------------------------------- /3rd/zlib/gzguts.h: -------------------------------------------------------------------------------- 1 | /* gzguts.h -- zlib internal header definitions for gz* operations 2 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #ifdef _LARGEFILE64_SOURCE 7 | # ifndef _LARGEFILE_SOURCE 8 | # define _LARGEFILE_SOURCE 1 9 | # endif 10 | # ifdef _FILE_OFFSET_BITS 11 | # undef _FILE_OFFSET_BITS 12 | # endif 13 | #endif 14 | 15 | #ifdef HAVE_HIDDEN 16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 17 | #else 18 | # define ZLIB_INTERNAL 19 | #endif 20 | 21 | #include 22 | #include "zlib.h" 23 | #ifdef STDC 24 | # include 25 | # include 26 | # include 27 | #endif 28 | #include 29 | 30 | #ifdef _WIN32 31 | # include 32 | #endif 33 | 34 | #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) 35 | # include 36 | #endif 37 | 38 | #ifdef WINAPI_FAMILY 39 | # define open _open 40 | # define read _read 41 | # define write _write 42 | # define close _close 43 | #endif 44 | 45 | #ifdef NO_DEFLATE /* for compatibility with old definition */ 46 | # define NO_GZCOMPRESS 47 | #endif 48 | 49 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 50 | # ifndef HAVE_VSNPRINTF 51 | # define HAVE_VSNPRINTF 52 | # endif 53 | #endif 54 | 55 | #if defined(__CYGWIN__) 56 | # ifndef HAVE_VSNPRINTF 57 | # define HAVE_VSNPRINTF 58 | # endif 59 | #endif 60 | 61 | #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) 62 | # ifndef HAVE_VSNPRINTF 63 | # define HAVE_VSNPRINTF 64 | # endif 65 | #endif 66 | 67 | #ifndef HAVE_VSNPRINTF 68 | # ifdef MSDOS 69 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 70 | but for now we just assume it doesn't. */ 71 | # define NO_vsnprintf 72 | # endif 73 | # ifdef __TURBOC__ 74 | # define NO_vsnprintf 75 | # endif 76 | # ifdef WIN32 77 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 78 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 79 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) 80 | # define vsnprintf _vsnprintf 81 | # endif 82 | # endif 83 | # endif 84 | # ifdef __SASC 85 | # define NO_vsnprintf 86 | # endif 87 | # ifdef VMS 88 | # define NO_vsnprintf 89 | # endif 90 | # ifdef __OS400__ 91 | # define NO_vsnprintf 92 | # endif 93 | # ifdef __MVS__ 94 | # define NO_vsnprintf 95 | # endif 96 | #endif 97 | 98 | /* unlike snprintf (which is required in C99, yet still not supported by 99 | Microsoft more than a decade later!), _snprintf does not guarantee null 100 | termination of the result -- however this is only used in gzlib.c where 101 | the result is assured to fit in the space provided */ 102 | #ifdef _MSC_VER 103 | # define snprintf _snprintf 104 | #endif 105 | 106 | #ifndef local 107 | # define local static 108 | #endif 109 | /* compile with -Dlocal if your debugger can't find static symbols */ 110 | 111 | /* gz* functions always use library allocation functions */ 112 | #ifndef STDC 113 | extern voidp malloc OF((uInt size)); 114 | extern void free OF((voidpf ptr)); 115 | #endif 116 | 117 | /* get errno and strerror definition */ 118 | #if defined UNDER_CE 119 | # include 120 | # define zstrerror() gz_strwinerror((DWORD)GetLastError()) 121 | #else 122 | # ifndef NO_STRERROR 123 | # include 124 | # define zstrerror() strerror(errno) 125 | # else 126 | # define zstrerror() "stdio error (consult errno)" 127 | # endif 128 | #endif 129 | 130 | /* provide prototypes for these when building zlib without LFS */ 131 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 132 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 133 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 134 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 135 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 136 | #endif 137 | 138 | /* default memLevel */ 139 | #if MAX_MEM_LEVEL >= 8 140 | # define DEF_MEM_LEVEL 8 141 | #else 142 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 143 | #endif 144 | 145 | /* default i/o buffer size -- double this for output when reading (this and 146 | twice this must be able to fit in an unsigned type) */ 147 | #define GZBUFSIZE 8192 148 | 149 | /* gzip modes, also provide a little integrity check on the passed structure */ 150 | #define GZ_NONE 0 151 | #define GZ_READ 7247 152 | #define GZ_WRITE 31153 153 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ 154 | 155 | /* values for gz_state how */ 156 | #define LOOK 0 /* look for a gzip header */ 157 | #define COPY 1 /* copy input directly */ 158 | #define GZIP 2 /* decompress a gzip stream */ 159 | 160 | /* internal gzip file state data structure */ 161 | typedef struct { 162 | /* exposed contents for gzgetc() macro */ 163 | struct gzFile_s x; /* "x" for exposed */ 164 | /* x.have: number of bytes available at x.next */ 165 | /* x.next: next output data to deliver or write */ 166 | /* x.pos: current position in uncompressed data */ 167 | /* used for both reading and writing */ 168 | int mode; /* see gzip modes above */ 169 | int fd; /* file descriptor */ 170 | char *path; /* path or fd for error messages */ 171 | unsigned size; /* buffer size, zero if not allocated yet */ 172 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ 173 | unsigned char *in; /* input buffer */ 174 | unsigned char *out; /* output buffer (double-sized when reading) */ 175 | int direct; /* 0 if processing gzip, 1 if transparent */ 176 | /* just for reading */ 177 | int how; /* 0: get header, 1: copy, 2: decompress */ 178 | z_off64_t start; /* where the gzip data started, for rewinding */ 179 | int eof; /* true if end of input file reached */ 180 | int past; /* true if read requested past end */ 181 | /* just for writing */ 182 | int level; /* compression level */ 183 | int strategy; /* compression strategy */ 184 | /* seek request */ 185 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ 186 | int seek; /* true if seek request pending */ 187 | /* error information */ 188 | int err; /* error code */ 189 | char *msg; /* error message */ 190 | /* zlib inflate or deflate stream */ 191 | z_stream strm; /* stream structure in-place (not a pointer) */ 192 | } gz_state; 193 | typedef gz_state FAR *gz_statep; 194 | 195 | /* shared functions */ 196 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); 197 | #if defined UNDER_CE 198 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); 199 | #endif 200 | 201 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t 202 | value -- needed when comparing unsigned to z_off64_t, which is signed 203 | (possible z_off64_t types off_t, off64_t, and long are all signed) */ 204 | #ifdef INT_MAX 205 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) 206 | #else 207 | unsigned ZLIB_INTERNAL gz_intmax OF((void)); 208 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) 209 | #endif 210 | -------------------------------------------------------------------------------- /3rd/zlib/inffast.c: -------------------------------------------------------------------------------- 1 | /* inffast.c -- fast decoding 2 | * Copyright (C) 1995-2008, 2010, 2013 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "inftrees.h" 8 | #include "inflate.h" 9 | #include "inffast.h" 10 | 11 | #ifndef ASMINF 12 | 13 | /* Allow machine dependent optimization for post-increment or pre-increment. 14 | Based on testing to date, 15 | Pre-increment preferred for: 16 | - PowerPC G3 (Adler) 17 | - MIPS R5000 (Randers-Pehrson) 18 | Post-increment preferred for: 19 | - none 20 | No measurable difference: 21 | - Pentium III (Anderson) 22 | - M68060 (Nikl) 23 | */ 24 | #ifdef POSTINC 25 | # define OFF 0 26 | # define PUP(a) *(a)++ 27 | #else 28 | # define OFF 1 29 | # define PUP(a) *++(a) 30 | #endif 31 | 32 | /* 33 | Decode literal, length, and distance codes and write out the resulting 34 | literal and match bytes until either not enough input or output is 35 | available, an end-of-block is encountered, or a data error is encountered. 36 | When large enough input and output buffers are supplied to inflate(), for 37 | example, a 16K input buffer and a 64K output buffer, more than 95% of the 38 | inflate execution time is spent in this routine. 39 | 40 | Entry assumptions: 41 | 42 | state->mode == LEN 43 | strm->avail_in >= 6 44 | strm->avail_out >= 258 45 | start >= strm->avail_out 46 | state->bits < 8 47 | 48 | On return, state->mode is one of: 49 | 50 | LEN -- ran out of enough output space or enough available input 51 | TYPE -- reached end of block code, inflate() to interpret next block 52 | BAD -- error in block data 53 | 54 | Notes: 55 | 56 | - The maximum input bits used by a length/distance pair is 15 bits for the 57 | length code, 5 bits for the length extra, 15 bits for the distance code, 58 | and 13 bits for the distance extra. This totals 48 bits, or six bytes. 59 | Therefore if strm->avail_in >= 6, then there is enough input to avoid 60 | checking for available input while decoding. 61 | 62 | - The maximum bytes that a single length/distance pair can output is 258 63 | bytes, which is the maximum length that can be coded. inflate_fast() 64 | requires strm->avail_out >= 258 for each loop to avoid checking for 65 | output space. 66 | */ 67 | void ZLIB_INTERNAL inflate_fast(strm, start) 68 | z_streamp strm; 69 | unsigned start; /* inflate()'s starting value for strm->avail_out */ 70 | { 71 | struct inflate_state FAR *state; 72 | z_const unsigned char FAR *in; /* local strm->next_in */ 73 | z_const unsigned char FAR *last; /* have enough input while in < last */ 74 | unsigned char FAR *out; /* local strm->next_out */ 75 | unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ 76 | unsigned char FAR *end; /* while out < end, enough space available */ 77 | #ifdef INFLATE_STRICT 78 | unsigned dmax; /* maximum distance from zlib header */ 79 | #endif 80 | unsigned wsize; /* window size or zero if not using window */ 81 | unsigned whave; /* valid bytes in the window */ 82 | unsigned wnext; /* window write index */ 83 | unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ 84 | unsigned long hold; /* local strm->hold */ 85 | unsigned bits; /* local strm->bits */ 86 | code const FAR *lcode; /* local strm->lencode */ 87 | code const FAR *dcode; /* local strm->distcode */ 88 | unsigned lmask; /* mask for first level of length codes */ 89 | unsigned dmask; /* mask for first level of distance codes */ 90 | code here; /* retrieved table entry */ 91 | unsigned op; /* code bits, operation, extra bits, or */ 92 | /* window position, window bytes to copy */ 93 | unsigned len; /* match length, unused bytes */ 94 | unsigned dist; /* match distance */ 95 | unsigned char FAR *from; /* where to copy match from */ 96 | 97 | /* copy state to local variables */ 98 | state = (struct inflate_state FAR *)strm->state; 99 | in = strm->next_in - OFF; 100 | last = in + (strm->avail_in - 5); 101 | out = strm->next_out - OFF; 102 | beg = out - (start - strm->avail_out); 103 | end = out + (strm->avail_out - 257); 104 | #ifdef INFLATE_STRICT 105 | dmax = state->dmax; 106 | #endif 107 | wsize = state->wsize; 108 | whave = state->whave; 109 | wnext = state->wnext; 110 | window = state->window; 111 | hold = state->hold; 112 | bits = state->bits; 113 | lcode = state->lencode; 114 | dcode = state->distcode; 115 | lmask = (1U << state->lenbits) - 1; 116 | dmask = (1U << state->distbits) - 1; 117 | 118 | /* decode literals and length/distances until end-of-block or not enough 119 | input data or output space */ 120 | do { 121 | if (bits < 15) { 122 | hold += (unsigned long)(PUP(in)) << bits; 123 | bits += 8; 124 | hold += (unsigned long)(PUP(in)) << bits; 125 | bits += 8; 126 | } 127 | here = lcode[hold & lmask]; 128 | dolen: 129 | op = (unsigned)(here.bits); 130 | hold >>= op; 131 | bits -= op; 132 | op = (unsigned)(here.op); 133 | if (op == 0) { /* literal */ 134 | Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 135 | "inflate: literal '%c'\n" : 136 | "inflate: literal 0x%02x\n", here.val)); 137 | PUP(out) = (unsigned char)(here.val); 138 | } 139 | else if (op & 16) { /* length base */ 140 | len = (unsigned)(here.val); 141 | op &= 15; /* number of extra bits */ 142 | if (op) { 143 | if (bits < op) { 144 | hold += (unsigned long)(PUP(in)) << bits; 145 | bits += 8; 146 | } 147 | len += (unsigned)hold & ((1U << op) - 1); 148 | hold >>= op; 149 | bits -= op; 150 | } 151 | Tracevv((stderr, "inflate: length %u\n", len)); 152 | if (bits < 15) { 153 | hold += (unsigned long)(PUP(in)) << bits; 154 | bits += 8; 155 | hold += (unsigned long)(PUP(in)) << bits; 156 | bits += 8; 157 | } 158 | here = dcode[hold & dmask]; 159 | dodist: 160 | op = (unsigned)(here.bits); 161 | hold >>= op; 162 | bits -= op; 163 | op = (unsigned)(here.op); 164 | if (op & 16) { /* distance base */ 165 | dist = (unsigned)(here.val); 166 | op &= 15; /* number of extra bits */ 167 | if (bits < op) { 168 | hold += (unsigned long)(PUP(in)) << bits; 169 | bits += 8; 170 | if (bits < op) { 171 | hold += (unsigned long)(PUP(in)) << bits; 172 | bits += 8; 173 | } 174 | } 175 | dist += (unsigned)hold & ((1U << op) - 1); 176 | #ifdef INFLATE_STRICT 177 | if (dist > dmax) { 178 | strm->msg = (char *)"invalid distance too far back"; 179 | state->mode = BAD; 180 | break; 181 | } 182 | #endif 183 | hold >>= op; 184 | bits -= op; 185 | Tracevv((stderr, "inflate: distance %u\n", dist)); 186 | op = (unsigned)(out - beg); /* max distance in output */ 187 | if (dist > op) { /* see if copy from window */ 188 | op = dist - op; /* distance back in window */ 189 | if (op > whave) { 190 | if (state->sane) { 191 | strm->msg = 192 | (char *)"invalid distance too far back"; 193 | state->mode = BAD; 194 | break; 195 | } 196 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 197 | if (len <= op - whave) { 198 | do { 199 | PUP(out) = 0; 200 | } while (--len); 201 | continue; 202 | } 203 | len -= op - whave; 204 | do { 205 | PUP(out) = 0; 206 | } while (--op > whave); 207 | if (op == 0) { 208 | from = out - dist; 209 | do { 210 | PUP(out) = PUP(from); 211 | } while (--len); 212 | continue; 213 | } 214 | #endif 215 | } 216 | from = window - OFF; 217 | if (wnext == 0) { /* very common case */ 218 | from += wsize - op; 219 | if (op < len) { /* some from window */ 220 | len -= op; 221 | do { 222 | PUP(out) = PUP(from); 223 | } while (--op); 224 | from = out - dist; /* rest from output */ 225 | } 226 | } 227 | else if (wnext < op) { /* wrap around window */ 228 | from += wsize + wnext - op; 229 | op -= wnext; 230 | if (op < len) { /* some from end of window */ 231 | len -= op; 232 | do { 233 | PUP(out) = PUP(from); 234 | } while (--op); 235 | from = window - OFF; 236 | if (wnext < len) { /* some from start of window */ 237 | op = wnext; 238 | len -= op; 239 | do { 240 | PUP(out) = PUP(from); 241 | } while (--op); 242 | from = out - dist; /* rest from output */ 243 | } 244 | } 245 | } 246 | else { /* contiguous in window */ 247 | from += wnext - op; 248 | if (op < len) { /* some from window */ 249 | len -= op; 250 | do { 251 | PUP(out) = PUP(from); 252 | } while (--op); 253 | from = out - dist; /* rest from output */ 254 | } 255 | } 256 | while (len > 2) { 257 | PUP(out) = PUP(from); 258 | PUP(out) = PUP(from); 259 | PUP(out) = PUP(from); 260 | len -= 3; 261 | } 262 | if (len) { 263 | PUP(out) = PUP(from); 264 | if (len > 1) 265 | PUP(out) = PUP(from); 266 | } 267 | } 268 | else { 269 | from = out - dist; /* copy direct from output */ 270 | do { /* minimum length is three */ 271 | PUP(out) = PUP(from); 272 | PUP(out) = PUP(from); 273 | PUP(out) = PUP(from); 274 | len -= 3; 275 | } while (len > 2); 276 | if (len) { 277 | PUP(out) = PUP(from); 278 | if (len > 1) 279 | PUP(out) = PUP(from); 280 | } 281 | } 282 | } 283 | else if ((op & 64) == 0) { /* 2nd level distance code */ 284 | here = dcode[here.val + (hold & ((1U << op) - 1))]; 285 | goto dodist; 286 | } 287 | else { 288 | strm->msg = (char *)"invalid distance code"; 289 | state->mode = BAD; 290 | break; 291 | } 292 | } 293 | else if ((op & 64) == 0) { /* 2nd level length code */ 294 | here = lcode[here.val + (hold & ((1U << op) - 1))]; 295 | goto dolen; 296 | } 297 | else if (op & 32) { /* end-of-block */ 298 | Tracevv((stderr, "inflate: end of block\n")); 299 | state->mode = TYPE; 300 | break; 301 | } 302 | else { 303 | strm->msg = (char *)"invalid literal/length code"; 304 | state->mode = BAD; 305 | break; 306 | } 307 | } while (in < last && out < end); 308 | 309 | /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ 310 | len = bits >> 3; 311 | in -= len; 312 | bits -= len << 3; 313 | hold &= (1U << bits) - 1; 314 | 315 | /* update state and return */ 316 | strm->next_in = in + OFF; 317 | strm->next_out = out + OFF; 318 | strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); 319 | strm->avail_out = (unsigned)(out < end ? 320 | 257 + (end - out) : 257 - (out - end)); 321 | state->hold = hold; 322 | state->bits = bits; 323 | return; 324 | } 325 | 326 | /* 327 | inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): 328 | - Using bit fields for code structure 329 | - Different op definition to avoid & for extra bits (do & for table bits) 330 | - Three separate decoding do-loops for direct, window, and wnext == 0 331 | - Special case for distance > 1 copies to do overlapped load and store copy 332 | - Explicit branch predictions (based on measured branch probabilities) 333 | - Deferring match copy and interspersed it with decoding subsequent codes 334 | - Swapping literal/length else 335 | - Swapping window/direct else 336 | - Larger unrolled copy loops (three is about right) 337 | - Moving len -= 3 statement into middle of loop 338 | */ 339 | 340 | #endif /* !ASMINF */ 341 | -------------------------------------------------------------------------------- /3rd/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /3rd/zlib/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. 6 | It is part of the implementation of this library and is 7 | subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /3rd/zlib/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2009 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY_, /* i/o: same as COPY below, but only first time in */ 36 | COPY, /* i/o: waiting for input or output to copy stored block */ 37 | TABLE, /* i: waiting for dynamic block table lengths */ 38 | LENLENS, /* i: waiting for code length code lengths */ 39 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 40 | LEN_, /* i: same as LEN below, but only first time in */ 41 | LEN, /* i: waiting for length/lit/eob code */ 42 | LENEXT, /* i: waiting for length extra bits */ 43 | DIST, /* i: waiting for distance code */ 44 | DISTEXT, /* i: waiting for distance extra bits */ 45 | MATCH, /* o: waiting for output space to copy string */ 46 | LIT, /* o: waiting for output space to write literal */ 47 | CHECK, /* i: waiting for 32-bit check value */ 48 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 49 | DONE, /* finished check, done -- remain here until reset */ 50 | BAD, /* got a data error -- remain here until reset */ 51 | MEM, /* got an inflate() memory error -- remain here until reset */ 52 | SYNC /* looking for synchronization bytes to restart inflate() */ 53 | } inflate_mode; 54 | 55 | /* 56 | State transitions between above modes - 57 | 58 | (most modes can go to BAD or MEM on error -- not shown for clarity) 59 | 60 | Process header: 61 | HEAD -> (gzip) or (zlib) or (raw) 62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 63 | HCRC -> TYPE 64 | (zlib) -> DICTID or TYPE 65 | DICTID -> DICT -> TYPE 66 | (raw) -> TYPEDO 67 | Read deflate blocks: 68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 69 | STORED -> COPY_ -> COPY -> TYPE 70 | TABLE -> LENLENS -> CODELENS -> LEN_ 71 | LEN_ -> LEN 72 | Read deflate codes in fixed or dynamic block: 73 | LEN -> LENEXT or LIT or TYPE 74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 75 | LIT -> LEN 76 | Process trailer: 77 | CHECK -> LENGTH -> DONE 78 | */ 79 | 80 | /* state maintained between inflate() calls. Approximately 10K bytes. */ 81 | struct inflate_state { 82 | inflate_mode mode; /* current inflate mode */ 83 | int last; /* true if processing last block */ 84 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 85 | int havedict; /* true if dictionary provided */ 86 | int flags; /* gzip header method and flags (0 if zlib) */ 87 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 88 | unsigned long check; /* protected copy of check value */ 89 | unsigned long total; /* protected copy of output count */ 90 | gz_headerp head; /* where to save gzip header information */ 91 | /* sliding window */ 92 | unsigned wbits; /* log base 2 of requested window size */ 93 | unsigned wsize; /* window size or zero if not using window */ 94 | unsigned whave; /* valid bytes in the window */ 95 | unsigned wnext; /* window write index */ 96 | unsigned char FAR *window; /* allocated sliding window, if needed */ 97 | /* bit accumulator */ 98 | unsigned long hold; /* input bit accumulator */ 99 | unsigned bits; /* number of bits in "in" */ 100 | /* for string and stored block copying */ 101 | unsigned length; /* literal or length of data to copy */ 102 | unsigned offset; /* distance back to copy string from */ 103 | /* for table and code decoding */ 104 | unsigned extra; /* extra bits needed */ 105 | /* fixed and dynamic code tables */ 106 | code const FAR *lencode; /* starting table for length/literal codes */ 107 | code const FAR *distcode; /* starting table for distance codes */ 108 | unsigned lenbits; /* index bits for lencode */ 109 | unsigned distbits; /* index bits for distcode */ 110 | /* dynamic table building */ 111 | unsigned ncode; /* number of code length code lengths */ 112 | unsigned nlen; /* number of length code lengths */ 113 | unsigned ndist; /* number of distance code lengths */ 114 | unsigned have; /* number of code lengths in lens[] */ 115 | code FAR *next; /* next available space in codes[] */ 116 | unsigned short lens[320]; /* temporary storage for code lengths */ 117 | unsigned short work[288]; /* work area for code table building */ 118 | code codes[ENOUGH]; /* space for code tables */ 119 | int sane; /* if false, allow invalid distance too far */ 120 | int back; /* bits back of last unprocessed length/lit */ 121 | unsigned was; /* initial length of match */ 122 | }; 123 | -------------------------------------------------------------------------------- /3rd/zlib/inftrees.c: -------------------------------------------------------------------------------- 1 | /* inftrees.c -- generate Huffman trees for efficient decoding 2 | * Copyright (C) 1995-2013 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "inftrees.h" 8 | 9 | #define MAXBITS 15 10 | 11 | const char inflate_copyright[] = 12 | " inflate 1.2.8 Copyright 1995-2013 Mark Adler "; 13 | /* 14 | If you use the zlib library in a product, an acknowledgment is welcome 15 | in the documentation of your product. If for some reason you cannot 16 | include such an acknowledgment, I would appreciate that you keep this 17 | copyright string in the executable of your product. 18 | */ 19 | 20 | /* 21 | Build a set of tables to decode the provided canonical Huffman code. 22 | The code lengths are lens[0..codes-1]. The result starts at *table, 23 | whose indices are 0..2^bits-1. work is a writable array of at least 24 | lens shorts, which is used as a work area. type is the type of code 25 | to be generated, CODES, LENS, or DISTS. On return, zero is success, 26 | -1 is an invalid code, and +1 means that ENOUGH isn't enough. table 27 | on return points to the next available entry's address. bits is the 28 | requested root table index bits, and on return it is the actual root 29 | table index bits. It will differ if the request is greater than the 30 | longest code or if it is less than the shortest code. 31 | */ 32 | int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) 33 | codetype type; 34 | unsigned short FAR *lens; 35 | unsigned codes; 36 | code FAR * FAR *table; 37 | unsigned FAR *bits; 38 | unsigned short FAR *work; 39 | { 40 | unsigned len; /* a code's length in bits */ 41 | unsigned sym; /* index of code symbols */ 42 | unsigned min, max; /* minimum and maximum code lengths */ 43 | unsigned root; /* number of index bits for root table */ 44 | unsigned curr; /* number of index bits for current table */ 45 | unsigned drop; /* code bits to drop for sub-table */ 46 | int left; /* number of prefix codes available */ 47 | unsigned used; /* code entries in table used */ 48 | unsigned huff; /* Huffman code */ 49 | unsigned incr; /* for incrementing code, index */ 50 | unsigned fill; /* index for replicating entries */ 51 | unsigned low; /* low bits for current root entry */ 52 | unsigned mask; /* mask for low root bits */ 53 | code here; /* table entry for duplication */ 54 | code FAR *next; /* next available space in table */ 55 | const unsigned short FAR *base; /* base value table to use */ 56 | const unsigned short FAR *extra; /* extra bits table to use */ 57 | int end; /* use base and extra for symbol > end */ 58 | unsigned short count[MAXBITS+1]; /* number of codes of each length */ 59 | unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ 60 | static const unsigned short lbase[31] = { /* Length codes 257..285 base */ 61 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 62 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 63 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 64 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 65 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; 66 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 67 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 68 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 69 | 8193, 12289, 16385, 24577, 0, 0}; 70 | static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ 71 | 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 72 | 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 73 | 28, 28, 29, 29, 64, 64}; 74 | 75 | /* 76 | Process a set of code lengths to create a canonical Huffman code. The 77 | code lengths are lens[0..codes-1]. Each length corresponds to the 78 | symbols 0..codes-1. The Huffman code is generated by first sorting the 79 | symbols by length from short to long, and retaining the symbol order 80 | for codes with equal lengths. Then the code starts with all zero bits 81 | for the first code of the shortest length, and the codes are integer 82 | increments for the same length, and zeros are appended as the length 83 | increases. For the deflate format, these bits are stored backwards 84 | from their more natural integer increment ordering, and so when the 85 | decoding tables are built in the large loop below, the integer codes 86 | are incremented backwards. 87 | 88 | This routine assumes, but does not check, that all of the entries in 89 | lens[] are in the range 0..MAXBITS. The caller must assure this. 90 | 1..MAXBITS is interpreted as that code length. zero means that that 91 | symbol does not occur in this code. 92 | 93 | The codes are sorted by computing a count of codes for each length, 94 | creating from that a table of starting indices for each length in the 95 | sorted table, and then entering the symbols in order in the sorted 96 | table. The sorted table is work[], with that space being provided by 97 | the caller. 98 | 99 | The length counts are used for other purposes as well, i.e. finding 100 | the minimum and maximum length codes, determining if there are any 101 | codes at all, checking for a valid set of lengths, and looking ahead 102 | at length counts to determine sub-table sizes when building the 103 | decoding tables. 104 | */ 105 | 106 | /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ 107 | for (len = 0; len <= MAXBITS; len++) 108 | count[len] = 0; 109 | for (sym = 0; sym < codes; sym++) 110 | count[lens[sym]]++; 111 | 112 | /* bound code lengths, force root to be within code lengths */ 113 | root = *bits; 114 | for (max = MAXBITS; max >= 1; max--) 115 | if (count[max] != 0) break; 116 | if (root > max) root = max; 117 | if (max == 0) { /* no symbols to code at all */ 118 | here.op = (unsigned char)64; /* invalid code marker */ 119 | here.bits = (unsigned char)1; 120 | here.val = (unsigned short)0; 121 | *(*table)++ = here; /* make a table to force an error */ 122 | *(*table)++ = here; 123 | *bits = 1; 124 | return 0; /* no symbols, but wait for decoding to report error */ 125 | } 126 | for (min = 1; min < max; min++) 127 | if (count[min] != 0) break; 128 | if (root < min) root = min; 129 | 130 | /* check for an over-subscribed or incomplete set of lengths */ 131 | left = 1; 132 | for (len = 1; len <= MAXBITS; len++) { 133 | left <<= 1; 134 | left -= count[len]; 135 | if (left < 0) return -1; /* over-subscribed */ 136 | } 137 | if (left > 0 && (type == CODES || max != 1)) 138 | return -1; /* incomplete set */ 139 | 140 | /* generate offsets into symbol table for each length for sorting */ 141 | offs[1] = 0; 142 | for (len = 1; len < MAXBITS; len++) 143 | offs[len + 1] = offs[len] + count[len]; 144 | 145 | /* sort symbols by length, by symbol order within each length */ 146 | for (sym = 0; sym < codes; sym++) 147 | if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; 148 | 149 | /* 150 | Create and fill in decoding tables. In this loop, the table being 151 | filled is at next and has curr index bits. The code being used is huff 152 | with length len. That code is converted to an index by dropping drop 153 | bits off of the bottom. For codes where len is less than drop + curr, 154 | those top drop + curr - len bits are incremented through all values to 155 | fill the table with replicated entries. 156 | 157 | root is the number of index bits for the root table. When len exceeds 158 | root, sub-tables are created pointed to by the root entry with an index 159 | of the low root bits of huff. This is saved in low to check for when a 160 | new sub-table should be started. drop is zero when the root table is 161 | being filled, and drop is root when sub-tables are being filled. 162 | 163 | When a new sub-table is needed, it is necessary to look ahead in the 164 | code lengths to determine what size sub-table is needed. The length 165 | counts are used for this, and so count[] is decremented as codes are 166 | entered in the tables. 167 | 168 | used keeps track of how many table entries have been allocated from the 169 | provided *table space. It is checked for LENS and DIST tables against 170 | the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in 171 | the initial root table size constants. See the comments in inftrees.h 172 | for more information. 173 | 174 | sym increments through all symbols, and the loop terminates when 175 | all codes of length max, i.e. all codes, have been processed. This 176 | routine permits incomplete codes, so another loop after this one fills 177 | in the rest of the decoding tables with invalid code markers. 178 | */ 179 | 180 | /* set up for code type */ 181 | switch (type) { 182 | case CODES: 183 | base = extra = work; /* dummy value--not used */ 184 | end = 19; 185 | break; 186 | case LENS: 187 | base = lbase; 188 | base -= 257; 189 | extra = lext; 190 | extra -= 257; 191 | end = 256; 192 | break; 193 | default: /* DISTS */ 194 | base = dbase; 195 | extra = dext; 196 | end = -1; 197 | } 198 | 199 | /* initialize state for loop */ 200 | huff = 0; /* starting code */ 201 | sym = 0; /* starting code symbol */ 202 | len = min; /* starting code length */ 203 | next = *table; /* current table to fill in */ 204 | curr = root; /* current table index bits */ 205 | drop = 0; /* current bits to drop from code for index */ 206 | low = (unsigned)(-1); /* trigger new sub-table when len > root */ 207 | used = 1U << root; /* use root table entries */ 208 | mask = used - 1; /* mask for comparing low */ 209 | 210 | /* check available table space */ 211 | if ((type == LENS && used > ENOUGH_LENS) || 212 | (type == DISTS && used > ENOUGH_DISTS)) 213 | return 1; 214 | 215 | /* process all codes and make table entries */ 216 | for (;;) { 217 | /* create table entry */ 218 | here.bits = (unsigned char)(len - drop); 219 | if ((int)(work[sym]) < end) { 220 | here.op = (unsigned char)0; 221 | here.val = work[sym]; 222 | } 223 | else if ((int)(work[sym]) > end) { 224 | here.op = (unsigned char)(extra[work[sym]]); 225 | here.val = base[work[sym]]; 226 | } 227 | else { 228 | here.op = (unsigned char)(32 + 64); /* end of block */ 229 | here.val = 0; 230 | } 231 | 232 | /* replicate for those indices with low len bits equal to huff */ 233 | incr = 1U << (len - drop); 234 | fill = 1U << curr; 235 | min = fill; /* save offset to next table */ 236 | do { 237 | fill -= incr; 238 | next[(huff >> drop) + fill] = here; 239 | } while (fill != 0); 240 | 241 | /* backwards increment the len-bit code huff */ 242 | incr = 1U << (len - 1); 243 | while (huff & incr) 244 | incr >>= 1; 245 | if (incr != 0) { 246 | huff &= incr - 1; 247 | huff += incr; 248 | } 249 | else 250 | huff = 0; 251 | 252 | /* go to next symbol, update count, len */ 253 | sym++; 254 | if (--(count[len]) == 0) { 255 | if (len == max) break; 256 | len = lens[work[sym]]; 257 | } 258 | 259 | /* create new sub-table if needed */ 260 | if (len > root && (huff & mask) != low) { 261 | /* if first time, transition to sub-tables */ 262 | if (drop == 0) 263 | drop = root; 264 | 265 | /* increment past last table */ 266 | next += min; /* here min is 1 << curr */ 267 | 268 | /* determine length of next table */ 269 | curr = len - drop; 270 | left = (int)(1 << curr); 271 | while (curr + drop < max) { 272 | left -= count[curr + drop]; 273 | if (left <= 0) break; 274 | curr++; 275 | left <<= 1; 276 | } 277 | 278 | /* check for enough space */ 279 | used += 1U << curr; 280 | if ((type == LENS && used > ENOUGH_LENS) || 281 | (type == DISTS && used > ENOUGH_DISTS)) 282 | return 1; 283 | 284 | /* point entry in root table to sub-table */ 285 | low = huff & mask; 286 | (*table)[low].op = (unsigned char)curr; 287 | (*table)[low].bits = (unsigned char)root; 288 | (*table)[low].val = (unsigned short)(next - *table); 289 | } 290 | } 291 | 292 | /* fill in remaining table entry if code is incomplete (guaranteed to have 293 | at most one remaining entry, since if the code is incomplete, the 294 | maximum code length that was allowed to get this far is one bit) */ 295 | if (huff != 0) { 296 | here.op = (unsigned char)64; /* invalid code marker */ 297 | here.bits = (unsigned char)(len - drop); 298 | here.val = (unsigned short)0; 299 | next[huff] = here; 300 | } 301 | 302 | /* set return parameters */ 303 | *table += used; 304 | *bits = root; 305 | return 0; 306 | } 307 | -------------------------------------------------------------------------------- /3rd/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /3rd/zlib/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 5 | 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 | 9 | For more info read MiniZip_info.txt 10 | 11 | */ 12 | 13 | #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) 14 | #define _CRT_SECURE_NO_WARNINGS 15 | #endif 16 | 17 | #if defined(__APPLE__) || defined(IOAPI_NO_64) 18 | // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions 19 | #define FOPEN_FUNC(filename, mode) fopen(filename, mode) 20 | #define FTELLO_FUNC(stream) ftello(stream) 21 | #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) 22 | #else 23 | #define FOPEN_FUNC(filename, mode) fopen64(filename, mode) 24 | #define FTELLO_FUNC(stream) ftello64(stream) 25 | #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) 26 | #endif 27 | 28 | 29 | #include "ioapi.h" 30 | 31 | voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) 32 | { 33 | if (pfilefunc->zfile_func64.zopen64_file != NULL) 34 | return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); 35 | else 36 | { 37 | return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); 38 | } 39 | } 40 | 41 | long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) 42 | { 43 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 44 | return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); 45 | else 46 | { 47 | uLong offsetTruncated = (uLong)offset; 48 | if (offsetTruncated != offset) 49 | return -1; 50 | else 51 | return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); 52 | } 53 | } 54 | 55 | ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) 56 | { 57 | if (pfilefunc->zfile_func64.zseek64_file != NULL) 58 | return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); 59 | else 60 | { 61 | uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); 62 | if ((tell_uLong) == MAXU32) 63 | return (ZPOS64_T)-1; 64 | else 65 | return tell_uLong; 66 | } 67 | } 68 | 69 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) 70 | { 71 | p_filefunc64_32->zfile_func64.zopen64_file = NULL; 72 | p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; 73 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 74 | p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; 75 | p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; 76 | p_filefunc64_32->zfile_func64.ztell64_file = NULL; 77 | p_filefunc64_32->zfile_func64.zseek64_file = NULL; 78 | p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; 79 | p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; 80 | p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; 81 | p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; 82 | p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; 83 | } 84 | 85 | 86 | 87 | static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); 88 | static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 89 | static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); 90 | static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); 91 | static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 92 | static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); 93 | static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); 94 | 95 | static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) 96 | { 97 | FILE* file = NULL; 98 | const char* mode_fopen = NULL; 99 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 100 | mode_fopen = "rb"; 101 | else 102 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 103 | mode_fopen = "r+b"; 104 | else 105 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 106 | mode_fopen = "wb"; 107 | 108 | if ((filename!=NULL) && (mode_fopen != NULL)) 109 | file = fopen(filename, mode_fopen); 110 | return file; 111 | } 112 | 113 | static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) 114 | { 115 | FILE* file = NULL; 116 | const char* mode_fopen = NULL; 117 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 118 | mode_fopen = "rb"; 119 | else 120 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 121 | mode_fopen = "r+b"; 122 | else 123 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 124 | mode_fopen = "wb"; 125 | 126 | if ((filename!=NULL) && (mode_fopen != NULL)) 127 | file = FOPEN_FUNC((const char*)filename, mode_fopen); 128 | return file; 129 | } 130 | 131 | 132 | static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) 133 | { 134 | uLong ret; 135 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 136 | return ret; 137 | } 138 | 139 | static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) 140 | { 141 | uLong ret; 142 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 143 | return ret; 144 | } 145 | 146 | static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) 147 | { 148 | long ret; 149 | ret = ftell((FILE *)stream); 150 | return ret; 151 | } 152 | 153 | 154 | static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) 155 | { 156 | ZPOS64_T ret; 157 | ret = FTELLO_FUNC((FILE *)stream); 158 | return ret; 159 | } 160 | 161 | static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) 162 | { 163 | int fseek_origin=0; 164 | long ret; 165 | switch (origin) 166 | { 167 | case ZLIB_FILEFUNC_SEEK_CUR : 168 | fseek_origin = SEEK_CUR; 169 | break; 170 | case ZLIB_FILEFUNC_SEEK_END : 171 | fseek_origin = SEEK_END; 172 | break; 173 | case ZLIB_FILEFUNC_SEEK_SET : 174 | fseek_origin = SEEK_SET; 175 | break; 176 | default: return -1; 177 | } 178 | ret = 0; 179 | if (fseek((FILE *)stream, offset, fseek_origin) != 0) 180 | ret = -1; 181 | return ret; 182 | } 183 | 184 | static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) 185 | { 186 | int fseek_origin=0; 187 | long ret; 188 | switch (origin) 189 | { 190 | case ZLIB_FILEFUNC_SEEK_CUR : 191 | fseek_origin = SEEK_CUR; 192 | break; 193 | case ZLIB_FILEFUNC_SEEK_END : 194 | fseek_origin = SEEK_END; 195 | break; 196 | case ZLIB_FILEFUNC_SEEK_SET : 197 | fseek_origin = SEEK_SET; 198 | break; 199 | default: return -1; 200 | } 201 | ret = 0; 202 | 203 | if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) 204 | ret = -1; 205 | 206 | return ret; 207 | } 208 | 209 | 210 | static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) 211 | { 212 | int ret; 213 | ret = fclose((FILE *)stream); 214 | return ret; 215 | } 216 | 217 | static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) 218 | { 219 | int ret; 220 | ret = ferror((FILE *)stream); 221 | return ret; 222 | } 223 | 224 | void fill_fopen_filefunc (pzlib_filefunc_def) 225 | zlib_filefunc_def* pzlib_filefunc_def; 226 | { 227 | pzlib_filefunc_def->zopen_file = fopen_file_func; 228 | pzlib_filefunc_def->zread_file = fread_file_func; 229 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 230 | pzlib_filefunc_def->ztell_file = ftell_file_func; 231 | pzlib_filefunc_def->zseek_file = fseek_file_func; 232 | pzlib_filefunc_def->zclose_file = fclose_file_func; 233 | pzlib_filefunc_def->zerror_file = ferror_file_func; 234 | pzlib_filefunc_def->opaque = NULL; 235 | } 236 | 237 | void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) 238 | { 239 | pzlib_filefunc_def->zopen64_file = fopen64_file_func; 240 | pzlib_filefunc_def->zread_file = fread_file_func; 241 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 242 | pzlib_filefunc_def->ztell64_file = ftell64_file_func; 243 | pzlib_filefunc_def->zseek64_file = fseek64_file_func; 244 | pzlib_filefunc_def->zclose_file = fclose_file_func; 245 | pzlib_filefunc_def->zerror_file = ferror_file_func; 246 | pzlib_filefunc_def->opaque = NULL; 247 | } 248 | -------------------------------------------------------------------------------- /3rd/zlib/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 5 | 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 | 9 | For more info read MiniZip_info.txt 10 | 11 | Changes 12 | 13 | Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) 14 | Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. 15 | More if/def section may be needed to support other platforms 16 | Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. 17 | (but you should use iowin32.c for windows instead) 18 | 19 | */ 20 | 21 | #ifndef _ZLIBIOAPI64_H 22 | #define _ZLIBIOAPI64_H 23 | 24 | #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 25 | 26 | // Linux needs this to support file operation on files larger then 4+GB 27 | // But might need better if/def to select just the platforms that needs them. 28 | 29 | #ifndef __USE_FILE_OFFSET64 30 | #define __USE_FILE_OFFSET64 31 | #endif 32 | #ifndef __USE_LARGEFILE64 33 | #define __USE_LARGEFILE64 34 | #endif 35 | #ifndef _LARGEFILE64_SOURCE 36 | #define _LARGEFILE64_SOURCE 37 | #endif 38 | #ifndef _FILE_OFFSET_BIT 39 | #define _FILE_OFFSET_BIT 64 40 | #endif 41 | 42 | #endif 43 | 44 | #include 45 | #include 46 | #include "zlib.h" 47 | 48 | #define USE_FILE32API // add for android 49 | 50 | #if defined(USE_FILE32API) 51 | #define fopen64 fopen 52 | #define ftello64 ftell 53 | #define fseeko64 fseek 54 | #else 55 | #ifdef __FreeBSD__ 56 | #define fopen64 fopen 57 | #define ftello64 ftello 58 | #define fseeko64 fseeko 59 | #endif 60 | #ifdef _MSC_VER 61 | #define fopen64 fopen 62 | #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 63 | #define ftello64 _ftelli64 64 | #define fseeko64 _fseeki64 65 | #else // old MSC 66 | #define ftello64 ftell 67 | #define fseeko64 fseek 68 | #endif 69 | #endif 70 | #endif 71 | 72 | /* 73 | #ifndef ZPOS64_T 74 | #ifdef _WIN32 75 | #define ZPOS64_T fpos_t 76 | #else 77 | #include 78 | #define ZPOS64_T uint64_t 79 | #endif 80 | #endif 81 | */ 82 | 83 | #ifdef HAVE_MINIZIP64_CONF_H 84 | #include "mz64conf.h" 85 | #endif 86 | 87 | /* a type choosen by DEFINE */ 88 | #ifdef HAVE_64BIT_INT_CUSTOM 89 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 90 | #else 91 | #ifdef HAS_STDINT_H 92 | #include "stdint.h" 93 | typedef uint64_t ZPOS64_T; 94 | #else 95 | 96 | /* Maximum unsigned 32-bit value used as placeholder for zip64 */ 97 | #define MAXU32 0xffffffff 98 | 99 | #if defined(_MSC_VER) || defined(__BORLANDC__) 100 | typedef unsigned __int64 ZPOS64_T; 101 | #else 102 | typedef unsigned long long int ZPOS64_T; 103 | #endif 104 | #endif 105 | #endif 106 | 107 | 108 | 109 | #ifdef __cplusplus 110 | extern "C" { 111 | #endif 112 | 113 | 114 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 115 | #define ZLIB_FILEFUNC_SEEK_END (2) 116 | #define ZLIB_FILEFUNC_SEEK_SET (0) 117 | 118 | #define ZLIB_FILEFUNC_MODE_READ (1) 119 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 120 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 121 | 122 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 123 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 124 | 125 | 126 | #ifndef ZCALLBACK 127 | #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 128 | #define ZCALLBACK CALLBACK 129 | #else 130 | #define ZCALLBACK 131 | #endif 132 | #endif 133 | 134 | 135 | 136 | 137 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 138 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 139 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 140 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 141 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 142 | 143 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 144 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 145 | 146 | 147 | /* here is the "old" 32 bits structure structure */ 148 | typedef struct zlib_filefunc_def_s 149 | { 150 | open_file_func zopen_file; 151 | read_file_func zread_file; 152 | write_file_func zwrite_file; 153 | tell_file_func ztell_file; 154 | seek_file_func zseek_file; 155 | close_file_func zclose_file; 156 | testerror_file_func zerror_file; 157 | voidpf opaque; 158 | } zlib_filefunc_def; 159 | 160 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 161 | typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 162 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 163 | 164 | typedef struct zlib_filefunc64_def_s 165 | { 166 | open64_file_func zopen64_file; 167 | read_file_func zread_file; 168 | write_file_func zwrite_file; 169 | tell64_file_func ztell64_file; 170 | seek64_file_func zseek64_file; 171 | close_file_func zclose_file; 172 | testerror_file_func zerror_file; 173 | voidpf opaque; 174 | } zlib_filefunc64_def; 175 | 176 | void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 177 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 178 | 179 | /* now internal definition, only for zip.c and unzip.h */ 180 | typedef struct zlib_filefunc64_32_def_s 181 | { 182 | zlib_filefunc64_def zfile_func64; 183 | open_file_func zopen32_file; 184 | tell_file_func ztell32_file; 185 | seek_file_func zseek32_file; 186 | } zlib_filefunc64_32_def; 187 | 188 | 189 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 190 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 191 | //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) 192 | //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) 193 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 194 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 195 | 196 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 197 | long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 198 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 199 | 200 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); 201 | 202 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 203 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 204 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | #endif 211 | -------------------------------------------------------------------------------- /3rd/zlib/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /3rd/zlib/unzip.h: -------------------------------------------------------------------------------- 1 | /* unzip.h -- IO for uncompress .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 | 7 | Modifications of Unzip for Zip64 8 | Copyright (C) 2007-2008 Even Rouault 9 | 10 | Modifications for Zip64 support on both zip and unzip 11 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 12 | 13 | For more info read MiniZip_info.txt 14 | 15 | --------------------------------------------------------------------------------- 16 | 17 | Condition of use and distribution are the same than zlib : 18 | 19 | This software is provided 'as-is', without any express or implied 20 | warranty. In no event will the authors be held liable for any damages 21 | arising from the use of this software. 22 | 23 | Permission is granted to anyone to use this software for any purpose, 24 | including commercial applications, and to alter it and redistribute it 25 | freely, subject to the following restrictions: 26 | 27 | 1. The origin of this software must not be misrepresented; you must not 28 | claim that you wrote the original software. If you use this software 29 | in a product, an acknowledgment in the product documentation would be 30 | appreciated but is not required. 31 | 2. Altered source versions must be plainly marked as such, and must not be 32 | misrepresented as being the original software. 33 | 3. This notice may not be removed or altered from any source distribution. 34 | 35 | --------------------------------------------------------------------------------- 36 | 37 | Changes 38 | 39 | See header of unzip64.c 40 | 41 | */ 42 | 43 | #ifndef _unz64_H 44 | #define _unz64_H 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #ifndef _ZLIB_H 51 | #include "zlib.h" 52 | #endif 53 | 54 | #ifndef _ZLIBIOAPI_H 55 | #include "ioapi.h" 56 | #endif 57 | 58 | #ifdef HAVE_BZIP2 59 | #include "bzlib.h" 60 | #endif 61 | 62 | #define Z_BZIP2ED 12 63 | 64 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 65 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 66 | from (void*) without cast */ 67 | typedef struct TagunzFile__ { int unused; } unzFile__; 68 | typedef unzFile__ *unzFile; 69 | #else 70 | typedef voidp unzFile; 71 | #endif 72 | 73 | 74 | #define UNZ_OK (0) 75 | #define UNZ_END_OF_LIST_OF_FILE (-100) 76 | #define UNZ_ERRNO (Z_ERRNO) 77 | #define UNZ_EOF (0) 78 | #define UNZ_PARAMERROR (-102) 79 | #define UNZ_BADZIPFILE (-103) 80 | #define UNZ_INTERNALERROR (-104) 81 | #define UNZ_CRCERROR (-105) 82 | 83 | /* tm_unz contain date/time info */ 84 | typedef struct tm_unz_s 85 | { 86 | uInt tm_sec; /* seconds after the minute - [0,59] */ 87 | uInt tm_min; /* minutes after the hour - [0,59] */ 88 | uInt tm_hour; /* hours since midnight - [0,23] */ 89 | uInt tm_mday; /* day of the month - [1,31] */ 90 | uInt tm_mon; /* months since January - [0,11] */ 91 | uInt tm_year; /* years - [1980..2044] */ 92 | } tm_unz; 93 | 94 | /* unz_global_info structure contain global data about the ZIPfile 95 | These data comes from the end of central dir */ 96 | typedef struct unz_global_info64_s 97 | { 98 | ZPOS64_T number_entry; /* total number of entries in 99 | the central dir on this disk */ 100 | uLong size_comment; /* size of the global comment of the zipfile */ 101 | } unz_global_info64; 102 | 103 | typedef struct unz_global_info_s 104 | { 105 | uLong number_entry; /* total number of entries in 106 | the central dir on this disk */ 107 | uLong size_comment; /* size of the global comment of the zipfile */ 108 | } unz_global_info; 109 | 110 | /* unz_file_info contain information about a file in the zipfile */ 111 | typedef struct unz_file_info64_s 112 | { 113 | uLong version; /* version made by 2 bytes */ 114 | uLong version_needed; /* version needed to extract 2 bytes */ 115 | uLong flag; /* general purpose bit flag 2 bytes */ 116 | uLong compression_method; /* compression method 2 bytes */ 117 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 118 | uLong crc; /* crc-32 4 bytes */ 119 | ZPOS64_T compressed_size; /* compressed size 8 bytes */ 120 | ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ 121 | uLong size_filename; /* filename length 2 bytes */ 122 | uLong size_file_extra; /* extra field length 2 bytes */ 123 | uLong size_file_comment; /* file comment length 2 bytes */ 124 | 125 | uLong disk_num_start; /* disk number start 2 bytes */ 126 | uLong internal_fa; /* internal file attributes 2 bytes */ 127 | uLong external_fa; /* external file attributes 4 bytes */ 128 | 129 | tm_unz tmu_date; 130 | } unz_file_info64; 131 | 132 | typedef struct unz_file_info_s 133 | { 134 | uLong version; /* version made by 2 bytes */ 135 | uLong version_needed; /* version needed to extract 2 bytes */ 136 | uLong flag; /* general purpose bit flag 2 bytes */ 137 | uLong compression_method; /* compression method 2 bytes */ 138 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 139 | uLong crc; /* crc-32 4 bytes */ 140 | uLong compressed_size; /* compressed size 4 bytes */ 141 | uLong uncompressed_size; /* uncompressed size 4 bytes */ 142 | uLong size_filename; /* filename length 2 bytes */ 143 | uLong size_file_extra; /* extra field length 2 bytes */ 144 | uLong size_file_comment; /* file comment length 2 bytes */ 145 | 146 | uLong disk_num_start; /* disk number start 2 bytes */ 147 | uLong internal_fa; /* internal file attributes 2 bytes */ 148 | uLong external_fa; /* external file attributes 4 bytes */ 149 | 150 | tm_unz tmu_date; 151 | } unz_file_info; 152 | 153 | extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 154 | const char* fileName2, 155 | int iCaseSensitivity)); 156 | /* 157 | Compare two filename (fileName1,fileName2). 158 | If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 159 | If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 160 | or strcasecmp) 161 | If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 162 | (like 1 on Unix, 2 on Windows) 163 | */ 164 | 165 | 166 | extern unzFile ZEXPORT unzOpen OF((const char *path)); 167 | extern unzFile ZEXPORT unzOpen64 OF((const void *path)); 168 | /* 169 | Open a Zip file. path contain the full pathname (by example, 170 | on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 171 | "zlib/zlib113.zip". 172 | If the zipfile cannot be opened (file don't exist or in not valid), the 173 | return value is NULL. 174 | Else, the return value is a unzFile Handle, usable with other function 175 | of this unzip package. 176 | the "64" function take a const void* pointer, because the path is just the 177 | value passed to the open64_file_func callback. 178 | Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 179 | is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* 180 | does not describe the reality 181 | */ 182 | 183 | 184 | extern unzFile ZEXPORT unzOpen2 OF((const char *path, 185 | zlib_filefunc_def* pzlib_filefunc_def)); 186 | /* 187 | Open a Zip file, like unzOpen, but provide a set of file low level API 188 | for read/write the zip file (see ioapi.h) 189 | */ 190 | 191 | extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, 192 | zlib_filefunc64_def* pzlib_filefunc_def)); 193 | /* 194 | Open a Zip file, like unz64Open, but provide a set of file low level API 195 | for read/write the zip file (see ioapi.h) 196 | */ 197 | 198 | extern int ZEXPORT unzClose OF((unzFile file)); 199 | /* 200 | Close a ZipFile opened with unzOpen. 201 | If there is files inside the .Zip opened with unzOpenCurrentFile (see later), 202 | these files MUST be closed with unzCloseCurrentFile before call unzClose. 203 | return UNZ_OK if there is no problem. */ 204 | 205 | extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 206 | unz_global_info *pglobal_info)); 207 | 208 | extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, 209 | unz_global_info64 *pglobal_info)); 210 | /* 211 | Write info about the ZipFile in the *pglobal_info structure. 212 | No preparation of the structure is needed 213 | return UNZ_OK if there is no problem. */ 214 | 215 | 216 | extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 217 | char *szComment, 218 | uLong uSizeBuf)); 219 | /* 220 | Get the global comment string of the ZipFile, in the szComment buffer. 221 | uSizeBuf is the size of the szComment buffer. 222 | return the number of byte copied or an error code <0 223 | */ 224 | 225 | 226 | /***************************************************************************/ 227 | /* Unzip package allow you browse the directory of the zipfile */ 228 | 229 | extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 230 | /* 231 | Set the current file of the zipfile to the first file. 232 | return UNZ_OK if there is no problem 233 | */ 234 | 235 | extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 236 | /* 237 | Set the current file of the zipfile to the next file. 238 | return UNZ_OK if there is no problem 239 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 240 | */ 241 | 242 | extern int ZEXPORT unzLocateFile OF((unzFile file, 243 | const char *szFileName, 244 | int iCaseSensitivity)); 245 | /* 246 | Try locate the file szFileName in the zipfile. 247 | For the iCaseSensitivity signification, see unzStringFileNameCompare 248 | 249 | return value : 250 | UNZ_OK if the file is found. It becomes the current file. 251 | UNZ_END_OF_LIST_OF_FILE if the file is not found 252 | */ 253 | 254 | 255 | /* ****************************************** */ 256 | /* Ryan supplied functions */ 257 | /* unz_file_info contain information about a file in the zipfile */ 258 | typedef struct unz_file_pos_s 259 | { 260 | uLong pos_in_zip_directory; /* offset in zip file directory */ 261 | uLong num_of_file; /* # of file */ 262 | } unz_file_pos; 263 | 264 | extern int ZEXPORT unzGetFilePos( 265 | unzFile file, 266 | unz_file_pos* file_pos); 267 | 268 | extern int ZEXPORT unzGoToFilePos( 269 | unzFile file, 270 | unz_file_pos* file_pos); 271 | 272 | typedef struct unz64_file_pos_s 273 | { 274 | ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ 275 | ZPOS64_T num_of_file; /* # of file */ 276 | } unz64_file_pos; 277 | 278 | extern int ZEXPORT unzGetFilePos64( 279 | unzFile file, 280 | unz64_file_pos* file_pos); 281 | 282 | extern int ZEXPORT unzGoToFilePos64( 283 | unzFile file, 284 | const unz64_file_pos* file_pos); 285 | 286 | /* ****************************************** */ 287 | 288 | extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, 289 | unz_file_info64 *pfile_info, 290 | char *szFileName, 291 | uLong fileNameBufferSize, 292 | void *extraField, 293 | uLong extraFieldBufferSize, 294 | char *szComment, 295 | uLong commentBufferSize)); 296 | 297 | extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 298 | unz_file_info *pfile_info, 299 | char *szFileName, 300 | uLong fileNameBufferSize, 301 | void *extraField, 302 | uLong extraFieldBufferSize, 303 | char *szComment, 304 | uLong commentBufferSize)); 305 | /* 306 | Get Info about the current file 307 | if pfile_info!=NULL, the *pfile_info structure will contain somes info about 308 | the current file 309 | if szFileName!=NULL, the filemane string will be copied in szFileName 310 | (fileNameBufferSize is the size of the buffer) 311 | if extraField!=NULL, the extra field information will be copied in extraField 312 | (extraFieldBufferSize is the size of the buffer). 313 | This is the Central-header version of the extra field 314 | if szComment!=NULL, the comment string of the file will be copied in szComment 315 | (commentBufferSize is the size of the buffer) 316 | */ 317 | 318 | 319 | /** Addition for GDAL : START */ 320 | 321 | extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); 322 | 323 | /** Addition for GDAL : END */ 324 | 325 | 326 | /***************************************************************************/ 327 | /* for reading the content of the current zipfile, you can open it, read data 328 | from it, and close it (you can close it before reading all the file) 329 | */ 330 | 331 | extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 332 | /* 333 | Open for reading data the current file in the zipfile. 334 | If there is no error, the return value is UNZ_OK. 335 | */ 336 | 337 | extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, 338 | const char* password)); 339 | /* 340 | Open for reading data the current file in the zipfile. 341 | password is a crypting password 342 | If there is no error, the return value is UNZ_OK. 343 | */ 344 | 345 | extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, 346 | int* method, 347 | int* level, 348 | int raw)); 349 | /* 350 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 351 | if raw==1 352 | *method will receive method of compression, *level will receive level of 353 | compression 354 | note : you can set level parameter as NULL (if you did not want known level, 355 | but you CANNOT set method parameter as NULL 356 | */ 357 | 358 | extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, 359 | int* method, 360 | int* level, 361 | int raw, 362 | const char* password)); 363 | /* 364 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 365 | if raw==1 366 | *method will receive method of compression, *level will receive level of 367 | compression 368 | note : you can set level parameter as NULL (if you did not want known level, 369 | but you CANNOT set method parameter as NULL 370 | */ 371 | 372 | 373 | extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 374 | /* 375 | Close the file in zip opened with unzOpenCurrentFile 376 | Return UNZ_CRCERROR if all the file was read but the CRC is not good 377 | */ 378 | 379 | extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 380 | voidp buf, 381 | unsigned len)); 382 | /* 383 | Read bytes from the current file (opened by unzOpenCurrentFile) 384 | buf contain buffer where data must be copied 385 | len the size of buf. 386 | 387 | return the number of byte copied if somes bytes are copied 388 | return 0 if the end of file was reached 389 | return <0 with error code if there is an error 390 | (UNZ_ERRNO for IO error, or zLib error for uncompress error) 391 | */ 392 | 393 | extern z_off_t ZEXPORT unztell OF((unzFile file)); 394 | 395 | extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); 396 | /* 397 | Give the current position in uncompressed data 398 | */ 399 | 400 | extern int ZEXPORT unzeof OF((unzFile file)); 401 | /* 402 | return 1 if the end of file was reached, 0 elsewhere 403 | */ 404 | 405 | extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 406 | voidp buf, 407 | unsigned len)); 408 | /* 409 | Read extra field from the current file (opened by unzOpenCurrentFile) 410 | This is the local-header version of the extra field (sometimes, there is 411 | more info in the local-header version than in the central-header) 412 | 413 | if buf==NULL, it return the size of the local extra field 414 | 415 | if buf!=NULL, len is the size of the buffer, the extra header is copied in 416 | buf. 417 | the return value is the number of bytes copied in buf, or (if <0) 418 | the error code 419 | */ 420 | 421 | /***************************************************************************/ 422 | 423 | /* Get the current file offset */ 424 | extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); 425 | extern uLong ZEXPORT unzGetOffset (unzFile file); 426 | 427 | /* Set the current file offset */ 428 | extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); 429 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 430 | 431 | 432 | 433 | #ifdef __cplusplus 434 | } 435 | #endif 436 | 437 | #endif /* _unz64_H */ 438 | -------------------------------------------------------------------------------- /3rd/zlib/zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2013 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* 12 | * If you *really* need a unique prefix for all types and library functions, 13 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 | * Even better than compiling with -DZ_PREFIX would be to use configure to set 15 | * this permanently in zconf.h using "./configure --zprefix". 16 | */ 17 | #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 18 | # define Z_PREFIX_SET 19 | 20 | /* all linked symbols */ 21 | # define _dist_code z__dist_code 22 | # define _length_code z__length_code 23 | # define _tr_align z__tr_align 24 | # define _tr_flush_bits z__tr_flush_bits 25 | # define _tr_flush_block z__tr_flush_block 26 | # define _tr_init z__tr_init 27 | # define _tr_stored_block z__tr_stored_block 28 | # define _tr_tally z__tr_tally 29 | # define adler32 z_adler32 30 | # define adler32_combine z_adler32_combine 31 | # define adler32_combine64 z_adler32_combine64 32 | # ifndef Z_SOLO 33 | # define compress z_compress 34 | # define compress2 z_compress2 35 | # define compressBound z_compressBound 36 | # endif 37 | # define crc32 z_crc32 38 | # define crc32_combine z_crc32_combine 39 | # define crc32_combine64 z_crc32_combine64 40 | # define deflate z_deflate 41 | # define deflateBound z_deflateBound 42 | # define deflateCopy z_deflateCopy 43 | # define deflateEnd z_deflateEnd 44 | # define deflateInit2_ z_deflateInit2_ 45 | # define deflateInit_ z_deflateInit_ 46 | # define deflateParams z_deflateParams 47 | # define deflatePending z_deflatePending 48 | # define deflatePrime z_deflatePrime 49 | # define deflateReset z_deflateReset 50 | # define deflateResetKeep z_deflateResetKeep 51 | # define deflateSetDictionary z_deflateSetDictionary 52 | # define deflateSetHeader z_deflateSetHeader 53 | # define deflateTune z_deflateTune 54 | # define deflate_copyright z_deflate_copyright 55 | # define get_crc_table z_get_crc_table 56 | # ifndef Z_SOLO 57 | # define gz_error z_gz_error 58 | # define gz_intmax z_gz_intmax 59 | # define gz_strwinerror z_gz_strwinerror 60 | # define gzbuffer z_gzbuffer 61 | # define gzclearerr z_gzclearerr 62 | # define gzclose z_gzclose 63 | # define gzclose_r z_gzclose_r 64 | # define gzclose_w z_gzclose_w 65 | # define gzdirect z_gzdirect 66 | # define gzdopen z_gzdopen 67 | # define gzeof z_gzeof 68 | # define gzerror z_gzerror 69 | # define gzflush z_gzflush 70 | # define gzgetc z_gzgetc 71 | # define gzgetc_ z_gzgetc_ 72 | # define gzgets z_gzgets 73 | # define gzoffset z_gzoffset 74 | # define gzoffset64 z_gzoffset64 75 | # define gzopen z_gzopen 76 | # define gzopen64 z_gzopen64 77 | # ifdef _WIN32 78 | # define gzopen_w z_gzopen_w 79 | # endif 80 | # define gzprintf z_gzprintf 81 | # define gzvprintf z_gzvprintf 82 | # define gzputc z_gzputc 83 | # define gzputs z_gzputs 84 | # define gzread z_gzread 85 | # define gzrewind z_gzrewind 86 | # define gzseek z_gzseek 87 | # define gzseek64 z_gzseek64 88 | # define gzsetparams z_gzsetparams 89 | # define gztell z_gztell 90 | # define gztell64 z_gztell64 91 | # define gzungetc z_gzungetc 92 | # define gzwrite z_gzwrite 93 | # endif 94 | # define inflate z_inflate 95 | # define inflateBack z_inflateBack 96 | # define inflateBackEnd z_inflateBackEnd 97 | # define inflateBackInit_ z_inflateBackInit_ 98 | # define inflateCopy z_inflateCopy 99 | # define inflateEnd z_inflateEnd 100 | # define inflateGetHeader z_inflateGetHeader 101 | # define inflateInit2_ z_inflateInit2_ 102 | # define inflateInit_ z_inflateInit_ 103 | # define inflateMark z_inflateMark 104 | # define inflatePrime z_inflatePrime 105 | # define inflateReset z_inflateReset 106 | # define inflateReset2 z_inflateReset2 107 | # define inflateSetDictionary z_inflateSetDictionary 108 | # define inflateGetDictionary z_inflateGetDictionary 109 | # define inflateSync z_inflateSync 110 | # define inflateSyncPoint z_inflateSyncPoint 111 | # define inflateUndermine z_inflateUndermine 112 | # define inflateResetKeep z_inflateResetKeep 113 | # define inflate_copyright z_inflate_copyright 114 | # define inflate_fast z_inflate_fast 115 | # define inflate_table z_inflate_table 116 | # ifndef Z_SOLO 117 | # define uncompress z_uncompress 118 | # endif 119 | # define zError z_zError 120 | # ifndef Z_SOLO 121 | # define zcalloc z_zcalloc 122 | # define zcfree z_zcfree 123 | # endif 124 | # define zlibCompileFlags z_zlibCompileFlags 125 | # define zlibVersion z_zlibVersion 126 | 127 | /* all zlib typedefs in zlib.h and zconf.h */ 128 | # define Byte z_Byte 129 | # define Bytef z_Bytef 130 | # define alloc_func z_alloc_func 131 | # define charf z_charf 132 | # define free_func z_free_func 133 | # ifndef Z_SOLO 134 | # define gzFile z_gzFile 135 | # endif 136 | # define gz_header z_gz_header 137 | # define gz_headerp z_gz_headerp 138 | # define in_func z_in_func 139 | # define intf z_intf 140 | # define out_func z_out_func 141 | # define uInt z_uInt 142 | # define uIntf z_uIntf 143 | # define uLong z_uLong 144 | # define uLongf z_uLongf 145 | # define voidp z_voidp 146 | # define voidpc z_voidpc 147 | # define voidpf z_voidpf 148 | 149 | /* all zlib structs in zlib.h and zconf.h */ 150 | # define gz_header_s z_gz_header_s 151 | # define internal_state z_internal_state 152 | 153 | #endif 154 | 155 | #if defined(__MSDOS__) && !defined(MSDOS) 156 | # define MSDOS 157 | #endif 158 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 159 | # define OS2 160 | #endif 161 | #if defined(_WINDOWS) && !defined(WINDOWS) 162 | # define WINDOWS 163 | #endif 164 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 165 | # ifndef WIN32 166 | # define WIN32 167 | # endif 168 | #endif 169 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 170 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 171 | # ifndef SYS16BIT 172 | # define SYS16BIT 173 | # endif 174 | # endif 175 | #endif 176 | 177 | /* 178 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 179 | * than 64k bytes at a time (needed on systems with 16-bit int). 180 | */ 181 | #ifdef SYS16BIT 182 | # define MAXSEG_64K 183 | #endif 184 | #ifdef MSDOS 185 | # define UNALIGNED_OK 186 | #endif 187 | 188 | #ifdef __STDC_VERSION__ 189 | # ifndef STDC 190 | # define STDC 191 | # endif 192 | # if __STDC_VERSION__ >= 199901L 193 | # ifndef STDC99 194 | # define STDC99 195 | # endif 196 | # endif 197 | #endif 198 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 199 | # define STDC 200 | #endif 201 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 202 | # define STDC 203 | #endif 204 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 205 | # define STDC 206 | #endif 207 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 208 | # define STDC 209 | #endif 210 | 211 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 212 | # define STDC 213 | #endif 214 | 215 | #ifndef STDC 216 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 217 | # define const /* note: need a more gentle solution here */ 218 | # endif 219 | #endif 220 | 221 | #if defined(ZLIB_CONST) && !defined(z_const) 222 | # define z_const const 223 | #else 224 | # define z_const 225 | #endif 226 | 227 | /* Some Mac compilers merge all .h files incorrectly: */ 228 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 229 | # define NO_DUMMY_DECL 230 | #endif 231 | 232 | /* Maximum value for memLevel in deflateInit2 */ 233 | #ifndef MAX_MEM_LEVEL 234 | # ifdef MAXSEG_64K 235 | # define MAX_MEM_LEVEL 8 236 | # else 237 | # define MAX_MEM_LEVEL 9 238 | # endif 239 | #endif 240 | 241 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 242 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 243 | * created by gzip. (Files created by minigzip can still be extracted by 244 | * gzip.) 245 | */ 246 | #ifndef MAX_WBITS 247 | # define MAX_WBITS 15 /* 32K LZ77 window */ 248 | #endif 249 | 250 | /* The memory requirements for deflate are (in bytes): 251 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 252 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 253 | plus a few kilobytes for small objects. For example, if you want to reduce 254 | the default memory requirements from 256K to 128K, compile with 255 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 256 | Of course this will generally degrade compression (there's no free lunch). 257 | 258 | The memory requirements for inflate are (in bytes) 1 << windowBits 259 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 260 | for small objects. 261 | */ 262 | 263 | /* Type declarations */ 264 | 265 | #ifndef OF /* function prototypes */ 266 | # ifdef STDC 267 | # define OF(args) args 268 | # else 269 | # define OF(args) () 270 | # endif 271 | #endif 272 | 273 | #ifndef Z_ARG /* function prototypes for stdarg */ 274 | # if defined(STDC) || defined(Z_HAVE_STDARG_H) 275 | # define Z_ARG(args) args 276 | # else 277 | # define Z_ARG(args) () 278 | # endif 279 | #endif 280 | 281 | /* The following definitions for FAR are needed only for MSDOS mixed 282 | * model programming (small or medium model with some far allocations). 283 | * This was tested only with MSC; for other MSDOS compilers you may have 284 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 285 | * just define FAR to be empty. 286 | */ 287 | #ifdef SYS16BIT 288 | # if defined(M_I86SM) || defined(M_I86MM) 289 | /* MSC small or medium model */ 290 | # define SMALL_MEDIUM 291 | # ifdef _MSC_VER 292 | # define FAR _far 293 | # else 294 | # define FAR far 295 | # endif 296 | # endif 297 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 298 | /* Turbo C small or medium model */ 299 | # define SMALL_MEDIUM 300 | # ifdef __BORLANDC__ 301 | # define FAR _far 302 | # else 303 | # define FAR far 304 | # endif 305 | # endif 306 | #endif 307 | 308 | #if defined(WINDOWS) || defined(WIN32) 309 | /* If building or using zlib as a DLL, define ZLIB_DLL. 310 | * This is not mandatory, but it offers a little performance increase. 311 | */ 312 | # ifdef ZLIB_DLL 313 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 314 | # ifdef ZLIB_INTERNAL 315 | # define ZEXTERN extern __declspec(dllexport) 316 | # else 317 | # define ZEXTERN extern __declspec(dllimport) 318 | # endif 319 | # endif 320 | # endif /* ZLIB_DLL */ 321 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 322 | * define ZLIB_WINAPI. 323 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 324 | */ 325 | # ifdef ZLIB_WINAPI 326 | # ifdef FAR 327 | # undef FAR 328 | # endif 329 | # include 330 | /* No need for _export, use ZLIB.DEF instead. */ 331 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 332 | # define ZEXPORT WINAPI 333 | # ifdef WIN32 334 | # define ZEXPORTVA WINAPIV 335 | # else 336 | # define ZEXPORTVA FAR CDECL 337 | # endif 338 | # endif 339 | #endif 340 | 341 | #if defined (__BEOS__) 342 | # ifdef ZLIB_DLL 343 | # ifdef ZLIB_INTERNAL 344 | # define ZEXPORT __declspec(dllexport) 345 | # define ZEXPORTVA __declspec(dllexport) 346 | # else 347 | # define ZEXPORT __declspec(dllimport) 348 | # define ZEXPORTVA __declspec(dllimport) 349 | # endif 350 | # endif 351 | #endif 352 | 353 | #ifndef ZEXTERN 354 | # define ZEXTERN extern 355 | #endif 356 | #ifndef ZEXPORT 357 | # define ZEXPORT 358 | #endif 359 | #ifndef ZEXPORTVA 360 | # define ZEXPORTVA 361 | #endif 362 | 363 | #ifndef FAR 364 | # define FAR 365 | #endif 366 | 367 | #if !defined(__MACTYPES__) 368 | typedef unsigned char Byte; /* 8 bits */ 369 | #endif 370 | typedef unsigned int uInt; /* 16 bits or more */ 371 | typedef unsigned long uLong; /* 32 bits or more */ 372 | 373 | #ifdef SMALL_MEDIUM 374 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 375 | # define Bytef Byte FAR 376 | #else 377 | typedef Byte FAR Bytef; 378 | #endif 379 | typedef char FAR charf; 380 | typedef int FAR intf; 381 | typedef uInt FAR uIntf; 382 | typedef uLong FAR uLongf; 383 | 384 | #ifdef STDC 385 | typedef void const *voidpc; 386 | typedef void FAR *voidpf; 387 | typedef void *voidp; 388 | #else 389 | typedef Byte const *voidpc; 390 | typedef Byte FAR *voidpf; 391 | typedef Byte *voidp; 392 | #endif 393 | 394 | #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 395 | # include 396 | # if (UINT_MAX == 0xffffffffUL) 397 | # define Z_U4 unsigned 398 | # elif (ULONG_MAX == 0xffffffffUL) 399 | # define Z_U4 unsigned long 400 | # elif (USHRT_MAX == 0xffffffffUL) 401 | # define Z_U4 unsigned short 402 | # endif 403 | #endif 404 | 405 | #ifdef Z_U4 406 | typedef Z_U4 z_crc_t; 407 | #else 408 | typedef unsigned long z_crc_t; 409 | #endif 410 | 411 | #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 412 | # define Z_HAVE_UNISTD_H 413 | #endif 414 | 415 | #ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 416 | # define Z_HAVE_STDARG_H 417 | #endif 418 | 419 | #ifdef STDC 420 | # ifndef Z_SOLO 421 | # include /* for off_t */ 422 | # endif 423 | #endif 424 | 425 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 426 | # ifndef Z_SOLO 427 | # include /* for va_list */ 428 | # endif 429 | #endif 430 | 431 | #ifdef _WIN32 432 | # ifndef Z_SOLO 433 | # include /* for wchar_t */ 434 | # endif 435 | #endif 436 | 437 | /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 438 | * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 439 | * though the former does not conform to the LFS document), but considering 440 | * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 441 | * equivalently requesting no 64-bit operations 442 | */ 443 | #if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 444 | # undef _LARGEFILE64_SOURCE 445 | #endif 446 | 447 | #if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 448 | # define Z_HAVE_UNISTD_H 449 | #endif 450 | #ifndef Z_SOLO 451 | # if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) 452 | # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 453 | # ifdef VMS 454 | # include /* for off_t */ 455 | # endif 456 | # ifndef z_off_t 457 | # define z_off_t off_t 458 | # endif 459 | # endif 460 | #endif 461 | 462 | #if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 463 | # define Z_LFS64 464 | #endif 465 | 466 | #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 467 | # define Z_LARGE64 468 | #endif 469 | 470 | #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 471 | # define Z_WANT64 472 | #endif 473 | 474 | #if !defined(SEEK_SET) && !defined(Z_SOLO) 475 | # define SEEK_SET 0 /* Seek from beginning of file. */ 476 | # define SEEK_CUR 1 /* Seek from current position. */ 477 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 478 | #endif 479 | 480 | #ifndef z_off_t 481 | # define z_off_t long 482 | #endif 483 | 484 | #if !defined(_WIN32) && defined(Z_LARGE64) 485 | # define z_off64_t off64_t 486 | #else 487 | # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 488 | # define z_off64_t __int64 489 | # else 490 | # define z_off64_t z_off_t 491 | # endif 492 | #endif 493 | 494 | /* MVS linker does not support external names larger than 8 bytes */ 495 | #if defined(__MVS__) 496 | #pragma map(deflateInit_,"DEIN") 497 | #pragma map(deflateInit2_,"DEIN2") 498 | #pragma map(deflateEnd,"DEEND") 499 | #pragma map(deflateBound,"DEBND") 500 | #pragma map(inflateInit_,"ININ") 501 | #pragma map(inflateInit2_,"ININ2") 502 | #pragma map(inflateEnd,"INEND") 503 | #pragma map(inflateSync,"INSY") 504 | #pragma map(inflateSetDictionary,"INSEDI") 505 | #pragma map(compressBound,"CMBND") 506 | #pragma map(inflate_table,"INTABL") 507 | #pragma map(inflate_fast,"INFA") 508 | #pragma map(inflate_copyright,"INCOPY") 509 | #endif 510 | 511 | #endif /* ZCONF_H */ 512 | -------------------------------------------------------------------------------- /3rd/zlib/zip.h: -------------------------------------------------------------------------------- 1 | /* zip.h -- IO on .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 6 | 7 | Modifications for Zip64 support 8 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 9 | 10 | For more info read MiniZip_info.txt 11 | 12 | --------------------------------------------------------------------------- 13 | 14 | Condition of use and distribution are the same than zlib : 15 | 16 | This software is provided 'as-is', without any express or implied 17 | warranty. In no event will the authors be held liable for any damages 18 | arising from the use of this software. 19 | 20 | Permission is granted to anyone to use this software for any purpose, 21 | including commercial applications, and to alter it and redistribute it 22 | freely, subject to the following restrictions: 23 | 24 | 1. The origin of this software must not be misrepresented; you must not 25 | claim that you wrote the original software. If you use this software 26 | in a product, an acknowledgment in the product documentation would be 27 | appreciated but is not required. 28 | 2. Altered source versions must be plainly marked as such, and must not be 29 | misrepresented as being the original software. 30 | 3. This notice may not be removed or altered from any source distribution. 31 | 32 | --------------------------------------------------------------------------- 33 | 34 | Changes 35 | 36 | See header of zip.h 37 | 38 | */ 39 | 40 | #ifndef _zip12_H 41 | #define _zip12_H 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | //#define HAVE_BZIP2 48 | 49 | #ifndef _ZLIB_H 50 | #include "zlib.h" 51 | #endif 52 | 53 | #ifndef _ZLIBIOAPI_H 54 | #include "ioapi.h" 55 | #endif 56 | 57 | #ifdef HAVE_BZIP2 58 | #include "bzlib.h" 59 | #endif 60 | 61 | #define Z_BZIP2ED 12 62 | 63 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 64 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 65 | from (void*) without cast */ 66 | typedef struct TagzipFile__ { int unused; } zipFile__; 67 | typedef zipFile__ *zipFile; 68 | #else 69 | typedef voidp zipFile; 70 | #endif 71 | 72 | #define ZIP_OK (0) 73 | #define ZIP_EOF (0) 74 | #define ZIP_ERRNO (Z_ERRNO) 75 | #define ZIP_PARAMERROR (-102) 76 | #define ZIP_BADZIPFILE (-103) 77 | #define ZIP_INTERNALERROR (-104) 78 | 79 | #ifndef DEF_MEM_LEVEL 80 | # if MAX_MEM_LEVEL >= 8 81 | # define DEF_MEM_LEVEL 8 82 | # else 83 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 84 | # endif 85 | #endif 86 | /* default memLevel */ 87 | 88 | /* tm_zip contain date/time info */ 89 | typedef struct tm_zip_s 90 | { 91 | uInt tm_sec; /* seconds after the minute - [0,59] */ 92 | uInt tm_min; /* minutes after the hour - [0,59] */ 93 | uInt tm_hour; /* hours since midnight - [0,23] */ 94 | uInt tm_mday; /* day of the month - [1,31] */ 95 | uInt tm_mon; /* months since January - [0,11] */ 96 | uInt tm_year; /* years - [1980..2044] */ 97 | } tm_zip; 98 | 99 | typedef struct 100 | { 101 | tm_zip tmz_date; /* date in understandable format */ 102 | uLong dosDate; /* if dos_date == 0, tmu_date is used */ 103 | /* uLong flag; */ /* general purpose bit flag 2 bytes */ 104 | 105 | uLong internal_fa; /* internal file attributes 2 bytes */ 106 | uLong external_fa; /* external file attributes 4 bytes */ 107 | } zip_fileinfo; 108 | 109 | typedef const char* zipcharpc; 110 | 111 | 112 | #define APPEND_STATUS_CREATE (0) 113 | #define APPEND_STATUS_CREATEAFTER (1) 114 | #define APPEND_STATUS_ADDINZIP (2) 115 | 116 | extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 117 | extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); 118 | /* 119 | Create a zipfile. 120 | pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on 121 | an Unix computer "zlib/zlib113.zip". 122 | if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip 123 | will be created at the end of the file. 124 | (useful if the file contain a self extractor code) 125 | if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will 126 | add files in existing zip (be sure you don't add file that doesn't exist) 127 | If the zipfile cannot be opened, the return value is NULL. 128 | Else, the return value is a zipFile Handle, usable with other function 129 | of this zip package. 130 | */ 131 | 132 | /* Note : there is no delete function into a zipfile. 133 | If you want delete file into a zipfile, you must open a zipfile, and create another 134 | Of couse, you can use RAW reading and writing to copy the file you did not want delte 135 | */ 136 | 137 | extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, 138 | int append, 139 | zipcharpc* globalcomment, 140 | zlib_filefunc_def* pzlib_filefunc_def)); 141 | 142 | extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, 143 | int append, 144 | zipcharpc* globalcomment, 145 | zlib_filefunc64_def* pzlib_filefunc_def)); 146 | 147 | extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, 148 | const char* filename, 149 | const zip_fileinfo* zipfi, 150 | const void* extrafield_local, 151 | uInt size_extrafield_local, 152 | const void* extrafield_global, 153 | uInt size_extrafield_global, 154 | const char* comment, 155 | int method, 156 | int level)); 157 | 158 | extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, 159 | const char* filename, 160 | const zip_fileinfo* zipfi, 161 | const void* extrafield_local, 162 | uInt size_extrafield_local, 163 | const void* extrafield_global, 164 | uInt size_extrafield_global, 165 | const char* comment, 166 | int method, 167 | int level, 168 | int zip64)); 169 | 170 | /* 171 | Open a file in the ZIP for writing. 172 | filename : the filename in zip (if NULL, '-' without quote will be used 173 | *zipfi contain supplemental information 174 | if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local 175 | contains the extrafield data the the local header 176 | if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global 177 | contains the extrafield data the the local header 178 | if comment != NULL, comment contain the comment string 179 | method contain the compression method (0 for store, Z_DEFLATED for deflate) 180 | level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 181 | zip64 is set to 1 if a zip64 extended information block should be added to the local file header. 182 | this MUST be '1' if the uncompressed size is >= 0xffffffff. 183 | 184 | */ 185 | 186 | 187 | extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, 188 | const char* filename, 189 | const zip_fileinfo* zipfi, 190 | const void* extrafield_local, 191 | uInt size_extrafield_local, 192 | const void* extrafield_global, 193 | uInt size_extrafield_global, 194 | const char* comment, 195 | int method, 196 | int level, 197 | int raw)); 198 | 199 | 200 | extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, 201 | const char* filename, 202 | const zip_fileinfo* zipfi, 203 | const void* extrafield_local, 204 | uInt size_extrafield_local, 205 | const void* extrafield_global, 206 | uInt size_extrafield_global, 207 | const char* comment, 208 | int method, 209 | int level, 210 | int raw, 211 | int zip64)); 212 | /* 213 | Same than zipOpenNewFileInZip, except if raw=1, we write raw file 214 | */ 215 | 216 | extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, 217 | const char* filename, 218 | const zip_fileinfo* zipfi, 219 | const void* extrafield_local, 220 | uInt size_extrafield_local, 221 | const void* extrafield_global, 222 | uInt size_extrafield_global, 223 | const char* comment, 224 | int method, 225 | int level, 226 | int raw, 227 | int windowBits, 228 | int memLevel, 229 | int strategy, 230 | const char* password, 231 | uLong crcForCrypting)); 232 | 233 | extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, 234 | const char* filename, 235 | const zip_fileinfo* zipfi, 236 | const void* extrafield_local, 237 | uInt size_extrafield_local, 238 | const void* extrafield_global, 239 | uInt size_extrafield_global, 240 | const char* comment, 241 | int method, 242 | int level, 243 | int raw, 244 | int windowBits, 245 | int memLevel, 246 | int strategy, 247 | const char* password, 248 | uLong crcForCrypting, 249 | int zip64 250 | )); 251 | 252 | /* 253 | Same than zipOpenNewFileInZip2, except 254 | windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 255 | password : crypting password (NULL for no crypting) 256 | crcForCrypting : crc of file to compress (needed for crypting) 257 | */ 258 | 259 | extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, 260 | const char* filename, 261 | const zip_fileinfo* zipfi, 262 | const void* extrafield_local, 263 | uInt size_extrafield_local, 264 | const void* extrafield_global, 265 | uInt size_extrafield_global, 266 | const char* comment, 267 | int method, 268 | int level, 269 | int raw, 270 | int windowBits, 271 | int memLevel, 272 | int strategy, 273 | const char* password, 274 | uLong crcForCrypting, 275 | uLong versionMadeBy, 276 | uLong flagBase 277 | )); 278 | 279 | 280 | extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, 281 | const char* filename, 282 | const zip_fileinfo* zipfi, 283 | const void* extrafield_local, 284 | uInt size_extrafield_local, 285 | const void* extrafield_global, 286 | uInt size_extrafield_global, 287 | const char* comment, 288 | int method, 289 | int level, 290 | int raw, 291 | int windowBits, 292 | int memLevel, 293 | int strategy, 294 | const char* password, 295 | uLong crcForCrypting, 296 | uLong versionMadeBy, 297 | uLong flagBase, 298 | int zip64 299 | )); 300 | /* 301 | Same than zipOpenNewFileInZip4, except 302 | versionMadeBy : value for Version made by field 303 | flag : value for flag field (compression level info will be added) 304 | */ 305 | 306 | 307 | extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, 308 | const void* buf, 309 | unsigned len)); 310 | /* 311 | Write data in the zipfile 312 | */ 313 | 314 | extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); 315 | /* 316 | Close the current file in the zipfile 317 | */ 318 | 319 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, 320 | uLong uncompressed_size, 321 | uLong crc32)); 322 | 323 | extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, 324 | ZPOS64_T uncompressed_size, 325 | uLong crc32)); 326 | 327 | /* 328 | Close the current file in the zipfile, for file opened with 329 | parameter raw=1 in zipOpenNewFileInZip2 330 | uncompressed_size and crc32 are value for the uncompressed size 331 | */ 332 | 333 | extern int ZEXPORT zipClose OF((zipFile file, 334 | const char* global_comment)); 335 | /* 336 | Close the zipfile 337 | */ 338 | 339 | 340 | extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); 341 | /* 342 | zipRemoveExtraInfoBlock - Added by Mathias Svensson 343 | 344 | Remove extra information block from a extra information data for the local file header or central directory header 345 | 346 | It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode. 347 | 348 | 0x0001 is the signature header for the ZIP64 extra information blocks 349 | 350 | usage. 351 | Remove ZIP64 Extra information from a central director extra field data 352 | zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001); 353 | 354 | Remove ZIP64 Extra information from a Local File Header extra field data 355 | zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001); 356 | */ 357 | 358 | #ifdef __cplusplus 359 | } 360 | #endif 361 | 362 | #endif /* _zip64_H */ 363 | -------------------------------------------------------------------------------- /3rd/zlib/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | #ifndef Z_SOLO 10 | # include "gzguts.h" 11 | #endif 12 | 13 | #ifndef NO_DUMMY_DECL 14 | struct internal_state {int dummy;}; /* for buggy compilers */ 15 | #endif 16 | 17 | z_const char * const z_errmsg[10] = { 18 | "need dictionary", /* Z_NEED_DICT 2 */ 19 | "stream end", /* Z_STREAM_END 1 */ 20 | "", /* Z_OK 0 */ 21 | "file error", /* Z_ERRNO (-1) */ 22 | "stream error", /* Z_STREAM_ERROR (-2) */ 23 | "data error", /* Z_DATA_ERROR (-3) */ 24 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 25 | "buffer error", /* Z_BUF_ERROR (-5) */ 26 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 27 | ""}; 28 | 29 | 30 | const char * ZEXPORT zlibVersion() 31 | { 32 | return ZLIB_VERSION; 33 | } 34 | 35 | uLong ZEXPORT zlibCompileFlags() 36 | { 37 | uLong flags; 38 | 39 | flags = 0; 40 | switch ((int)(sizeof(uInt))) { 41 | case 2: break; 42 | case 4: flags += 1; break; 43 | case 8: flags += 2; break; 44 | default: flags += 3; 45 | } 46 | switch ((int)(sizeof(uLong))) { 47 | case 2: break; 48 | case 4: flags += 1 << 2; break; 49 | case 8: flags += 2 << 2; break; 50 | default: flags += 3 << 2; 51 | } 52 | switch ((int)(sizeof(voidpf))) { 53 | case 2: break; 54 | case 4: flags += 1 << 4; break; 55 | case 8: flags += 2 << 4; break; 56 | default: flags += 3 << 4; 57 | } 58 | switch ((int)(sizeof(z_off_t))) { 59 | case 2: break; 60 | case 4: flags += 1 << 6; break; 61 | case 8: flags += 2 << 6; break; 62 | default: flags += 3 << 6; 63 | } 64 | #ifdef DEBUG 65 | flags += 1 << 8; 66 | #endif 67 | #if defined(ASMV) || defined(ASMINF) 68 | flags += 1 << 9; 69 | #endif 70 | #ifdef ZLIB_WINAPI 71 | flags += 1 << 10; 72 | #endif 73 | #ifdef BUILDFIXED 74 | flags += 1 << 12; 75 | #endif 76 | #ifdef DYNAMIC_CRC_TABLE 77 | flags += 1 << 13; 78 | #endif 79 | #ifdef NO_GZCOMPRESS 80 | flags += 1L << 16; 81 | #endif 82 | #ifdef NO_GZIP 83 | flags += 1L << 17; 84 | #endif 85 | #ifdef PKZIP_BUG_WORKAROUND 86 | flags += 1L << 20; 87 | #endif 88 | #ifdef FASTEST 89 | flags += 1L << 21; 90 | #endif 91 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 92 | # ifdef NO_vsnprintf 93 | flags += 1L << 25; 94 | # ifdef HAS_vsprintf_void 95 | flags += 1L << 26; 96 | # endif 97 | # else 98 | # ifdef HAS_vsnprintf_void 99 | flags += 1L << 26; 100 | # endif 101 | # endif 102 | #else 103 | flags += 1L << 24; 104 | # ifdef NO_snprintf 105 | flags += 1L << 25; 106 | # ifdef HAS_sprintf_void 107 | flags += 1L << 26; 108 | # endif 109 | # else 110 | # ifdef HAS_snprintf_void 111 | flags += 1L << 26; 112 | # endif 113 | # endif 114 | #endif 115 | return flags; 116 | } 117 | 118 | #ifdef DEBUG 119 | 120 | # ifndef verbose 121 | # define verbose 0 122 | # endif 123 | int ZLIB_INTERNAL z_verbose = verbose; 124 | 125 | void ZLIB_INTERNAL z_error (m) 126 | char *m; 127 | { 128 | fprintf(stderr, "%s\n", m); 129 | exit(1); 130 | } 131 | #endif 132 | 133 | /* exported to allow conversion of error code to string for compress() and 134 | * uncompress() 135 | */ 136 | const char * ZEXPORT zError(err) 137 | int err; 138 | { 139 | return ERR_MSG(err); 140 | } 141 | 142 | #if defined(_WIN32_WCE) 143 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 144 | * errno. We define it as a global variable to simplify porting. 145 | * Its value is always 0 and should not be used. 146 | */ 147 | int errno = 0; 148 | #endif 149 | 150 | #ifndef HAVE_MEMCPY 151 | 152 | void ZLIB_INTERNAL zmemcpy(dest, source, len) 153 | Bytef* dest; 154 | const Bytef* source; 155 | uInt len; 156 | { 157 | if (len == 0) return; 158 | do { 159 | *dest++ = *source++; /* ??? to be unrolled */ 160 | } while (--len != 0); 161 | } 162 | 163 | int ZLIB_INTERNAL zmemcmp(s1, s2, len) 164 | const Bytef* s1; 165 | const Bytef* s2; 166 | uInt len; 167 | { 168 | uInt j; 169 | 170 | for (j = 0; j < len; j++) { 171 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 172 | } 173 | return 0; 174 | } 175 | 176 | void ZLIB_INTERNAL zmemzero(dest, len) 177 | Bytef* dest; 178 | uInt len; 179 | { 180 | if (len == 0) return; 181 | do { 182 | *dest++ = 0; /* ??? to be unrolled */ 183 | } while (--len != 0); 184 | } 185 | #endif 186 | 187 | #ifndef Z_SOLO 188 | 189 | #ifdef SYS16BIT 190 | 191 | #ifdef __TURBOC__ 192 | /* Turbo C in 16-bit mode */ 193 | 194 | # define MY_ZCALLOC 195 | 196 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 197 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 198 | * must fix the pointer. Warning: the pointer must be put back to its 199 | * original form in order to free it, use zcfree(). 200 | */ 201 | 202 | #define MAX_PTR 10 203 | /* 10*64K = 640K */ 204 | 205 | local int next_ptr = 0; 206 | 207 | typedef struct ptr_table_s { 208 | voidpf org_ptr; 209 | voidpf new_ptr; 210 | } ptr_table; 211 | 212 | local ptr_table table[MAX_PTR]; 213 | /* This table is used to remember the original form of pointers 214 | * to large buffers (64K). Such pointers are normalized with a zero offset. 215 | * Since MSDOS is not a preemptive multitasking OS, this table is not 216 | * protected from concurrent access. This hack doesn't work anyway on 217 | * a protected system like OS/2. Use Microsoft C instead. 218 | */ 219 | 220 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) 221 | { 222 | voidpf buf = opaque; /* just to make some compilers happy */ 223 | ulg bsize = (ulg)items*size; 224 | 225 | /* If we allocate less than 65520 bytes, we assume that farmalloc 226 | * will return a usable pointer which doesn't have to be normalized. 227 | */ 228 | if (bsize < 65520L) { 229 | buf = farmalloc(bsize); 230 | if (*(ush*)&buf != 0) return buf; 231 | } else { 232 | buf = farmalloc(bsize + 16L); 233 | } 234 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 235 | table[next_ptr].org_ptr = buf; 236 | 237 | /* Normalize the pointer to seg:0 */ 238 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 239 | *(ush*)&buf = 0; 240 | table[next_ptr++].new_ptr = buf; 241 | return buf; 242 | } 243 | 244 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 245 | { 246 | int n; 247 | if (*(ush*)&ptr != 0) { /* object < 64K */ 248 | farfree(ptr); 249 | return; 250 | } 251 | /* Find the original pointer */ 252 | for (n = 0; n < next_ptr; n++) { 253 | if (ptr != table[n].new_ptr) continue; 254 | 255 | farfree(table[n].org_ptr); 256 | while (++n < next_ptr) { 257 | table[n-1] = table[n]; 258 | } 259 | next_ptr--; 260 | return; 261 | } 262 | ptr = opaque; /* just to make some compilers happy */ 263 | Assert(0, "zcfree: ptr not found"); 264 | } 265 | 266 | #endif /* __TURBOC__ */ 267 | 268 | 269 | #ifdef M_I86 270 | /* Microsoft C in 16-bit mode */ 271 | 272 | # define MY_ZCALLOC 273 | 274 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 275 | # define _halloc halloc 276 | # define _hfree hfree 277 | #endif 278 | 279 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) 280 | { 281 | if (opaque) opaque = 0; /* to make compiler happy */ 282 | return _halloc((long)items, size); 283 | } 284 | 285 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 286 | { 287 | if (opaque) opaque = 0; /* to make compiler happy */ 288 | _hfree(ptr); 289 | } 290 | 291 | #endif /* M_I86 */ 292 | 293 | #endif /* SYS16BIT */ 294 | 295 | 296 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 297 | 298 | #ifndef STDC 299 | extern voidp malloc OF((uInt size)); 300 | extern voidp calloc OF((uInt items, uInt size)); 301 | extern void free OF((voidpf ptr)); 302 | #endif 303 | 304 | voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) 305 | voidpf opaque; 306 | unsigned items; 307 | unsigned size; 308 | { 309 | if (opaque) items += size - size; /* make compiler happy */ 310 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 311 | (voidpf)calloc(items, size); 312 | } 313 | 314 | void ZLIB_INTERNAL zcfree (opaque, ptr) 315 | voidpf opaque; 316 | voidpf ptr; 317 | { 318 | free(ptr); 319 | if (opaque) return; /* make compiler happy */ 320 | } 321 | 322 | #endif /* MY_ZCALLOC */ 323 | 324 | #endif /* !Z_SOLO */ 325 | -------------------------------------------------------------------------------- /3rd/zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2013 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #ifdef HAVE_HIDDEN 17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 | #else 19 | # define ZLIB_INTERNAL 20 | #endif 21 | 22 | #include "zlib.h" 23 | 24 | #if defined(STDC) && !defined(Z_SOLO) 25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 26 | # include 27 | # endif 28 | # include 29 | # include 30 | #endif 31 | 32 | #ifdef Z_SOLO 33 | typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ 34 | #endif 35 | 36 | #ifndef local 37 | # define local static 38 | #endif 39 | /* compile with -Dlocal if your debugger can't find static symbols */ 40 | 41 | typedef unsigned char uch; 42 | typedef uch FAR uchf; 43 | typedef unsigned short ush; 44 | typedef ush FAR ushf; 45 | typedef unsigned long ulg; 46 | 47 | extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 48 | /* (size given to avoid silly warnings with Visual C++) */ 49 | 50 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 51 | 52 | #define ERR_RETURN(strm,err) \ 53 | return (strm->msg = ERR_MSG(err), (err)) 54 | /* To be used only when the state is known to be valid */ 55 | 56 | /* common constants */ 57 | 58 | #ifndef DEF_WBITS 59 | # define DEF_WBITS MAX_WBITS 60 | #endif 61 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 62 | 63 | #if MAX_MEM_LEVEL >= 8 64 | # define DEF_MEM_LEVEL 8 65 | #else 66 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 67 | #endif 68 | /* default memLevel */ 69 | 70 | #define STORED_BLOCK 0 71 | #define STATIC_TREES 1 72 | #define DYN_TREES 2 73 | /* The three kinds of block type */ 74 | 75 | #define MIN_MATCH 3 76 | #define MAX_MATCH 258 77 | /* The minimum and maximum match lengths */ 78 | 79 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 80 | 81 | /* target dependencies */ 82 | 83 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 84 | # define OS_CODE 0x00 85 | # ifndef Z_SOLO 86 | # if defined(__TURBOC__) || defined(__BORLANDC__) 87 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 88 | /* Allow compilation with ANSI keywords only enabled */ 89 | void _Cdecl farfree( void *block ); 90 | void *_Cdecl farmalloc( unsigned long nbytes ); 91 | # else 92 | # include 93 | # endif 94 | # else /* MSC or DJGPP */ 95 | # include 96 | # endif 97 | # endif 98 | #endif 99 | 100 | #ifdef AMIGA 101 | # define OS_CODE 0x01 102 | #endif 103 | 104 | #if defined(VAXC) || defined(VMS) 105 | # define OS_CODE 0x02 106 | # define F_OPEN(name, mode) \ 107 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 108 | #endif 109 | 110 | #if defined(ATARI) || defined(atarist) 111 | # define OS_CODE 0x05 112 | #endif 113 | 114 | #ifdef OS2 115 | # define OS_CODE 0x06 116 | # if defined(M_I86) && !defined(Z_SOLO) 117 | # include 118 | # endif 119 | #endif 120 | 121 | #if defined(MACOS) || defined(TARGET_OS_MAC) 122 | # define OS_CODE 0x07 123 | # ifndef Z_SOLO 124 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 125 | # include /* for fdopen */ 126 | # else 127 | # ifndef fdopen 128 | # define fdopen(fd,mode) NULL /* No fdopen() */ 129 | # endif 130 | # endif 131 | # endif 132 | #endif 133 | 134 | #ifdef TOPS20 135 | # define OS_CODE 0x0a 136 | #endif 137 | 138 | #ifdef WIN32 139 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 140 | # define OS_CODE 0x0b 141 | # endif 142 | #endif 143 | 144 | #ifdef __50SERIES /* Prime/PRIMOS */ 145 | # define OS_CODE 0x0f 146 | #endif 147 | 148 | #if defined(_BEOS_) || defined(RISCOS) 149 | # define fdopen(fd,mode) NULL /* No fdopen() */ 150 | #endif 151 | 152 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 153 | # if defined(_WIN32_WCE) 154 | # define fdopen(fd,mode) NULL /* No fdopen() */ 155 | # ifndef _PTRDIFF_T_DEFINED 156 | typedef int ptrdiff_t; 157 | # define _PTRDIFF_T_DEFINED 158 | # endif 159 | # else 160 | # define fdopen(fd,type) _fdopen(fd,type) 161 | # endif 162 | #endif 163 | 164 | #if defined(__BORLANDC__) && !defined(MSDOS) 165 | #pragma warn -8004 166 | #pragma warn -8008 167 | #pragma warn -8066 168 | #endif 169 | 170 | /* provide prototypes for these when building zlib without LFS */ 171 | #if !defined(_WIN32) && \ 172 | (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 173 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 174 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 175 | #endif 176 | 177 | /* common defaults */ 178 | 179 | #ifndef OS_CODE 180 | # define OS_CODE 0x03 /* assume Unix */ 181 | #endif 182 | 183 | #ifndef F_OPEN 184 | # define F_OPEN(name, mode) fopen((name), (mode)) 185 | #endif 186 | 187 | /* functions */ 188 | 189 | #if defined(pyr) || defined(Z_SOLO) 190 | # define NO_MEMCPY 191 | #endif 192 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 193 | /* Use our own functions for small and medium model with MSC <= 5.0. 194 | * You may have to use the same strategy for Borland C (untested). 195 | * The __SC__ check is for Symantec. 196 | */ 197 | # define NO_MEMCPY 198 | #endif 199 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 200 | # define HAVE_MEMCPY 201 | #endif 202 | #ifdef HAVE_MEMCPY 203 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 204 | # define zmemcpy _fmemcpy 205 | # define zmemcmp _fmemcmp 206 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 207 | # else 208 | # define zmemcpy memcpy 209 | # define zmemcmp memcmp 210 | # define zmemzero(dest, len) memset(dest, 0, len) 211 | # endif 212 | #else 213 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 214 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 215 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 216 | #endif 217 | 218 | /* Diagnostic functions */ 219 | #ifdef DEBUG 220 | # include 221 | extern int ZLIB_INTERNAL z_verbose; 222 | extern void ZLIB_INTERNAL z_error OF((char *m)); 223 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 224 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 225 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 226 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 227 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 228 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 229 | #else 230 | # define Assert(cond,msg) 231 | # define Trace(x) 232 | # define Tracev(x) 233 | # define Tracevv(x) 234 | # define Tracec(c,x) 235 | # define Tracecv(c,x) 236 | #endif 237 | 238 | #ifndef Z_SOLO 239 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 240 | unsigned size)); 241 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 242 | #endif 243 | 244 | #define ZALLOC(strm, items, size) \ 245 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 246 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 247 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 248 | 249 | /* Reverse the bytes in a 32-bit value */ 250 | #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 251 | (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 252 | 253 | #endif /* ZUTIL_H */ 254 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwugang/pkcs7/466b87c370bbf04d8138f87373e0f34e55a1e50c/Android.mk -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ZLIBPATH = ./3rd/zlib 2 | MD5PATH = ./3rd/md5 3 | 4 | ZLIBOBJS = $(ZLIBPATH)/crc32.obj $(ZLIBPATH)/adler32.obj $(ZLIBPATH)/inffast.obj $(ZLIBPATH)/zip.obj $(ZLIBPATH)/deflate.obj\ 5 | $(ZLIBPATH)/inflate.obj $(ZLIBPATH)/inftrees.obj $(ZLIBPATH)/ioapi.obj $(ZLIBPATH)/unzip.obj $(ZLIBPATH)/zutil.obj $(ZLIBPATH)/trees.obj 6 | OBJS = example.obj pkcs7.obj $(MD5PATH)/md5.obj $(ZLIBOBJS) 7 | 8 | ALL:$(OBJS) 9 | link /subsystem:console *.obj -out:example.exe 10 | .c.obj:: 11 | cl -c -O2 $< 12 | 13 | .cpp.obj:: 14 | cl -c -O2 $< 15 | 16 | 17 | 18 | 19 | clean: 20 | erase *.obj 21 | erase *.exe -------------------------------------------------------------------------------- /Makefile_Linux: -------------------------------------------------------------------------------- 1 | ZLIBPATH = ./3rd/zlib 2 | MD5PATH = ./3rd/md5 3 | 4 | ZLIBOBJS = $(ZLIBPATH)/crc32.o $(ZLIBPATH)/adler32.o $(ZLIBPATH)/inffast.o $(ZLIBPATH)/zip.o $(ZLIBPATH)/deflate.o\ 5 | $(ZLIBPATH)/inflate.o $(ZLIBPATH)/inftrees.o $(ZLIBPATH)/ioapi.o $(ZLIBPATH)/unzip.o $(ZLIBPATH)/zutil.o $(ZLIBPATH)/trees.o 6 | OBJS = example.o pkcs7.o $(MD5PATH)/md5.o $(ZLIBOBJS) 7 | 8 | ALL:$(OBJS) 9 | g++ -o example $(OBJS) 10 | 11 | clean: 12 | rm *.o 13 | rm $(ZLIBPATH)/*.o 14 | rm $(MD5PATH)/*.o 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pkcs7 2 | 该项目有: 3 | * 对签名证书文件的解析,可以提供apk、jar包或者文件; 4 | * 获取证书部分的MD5; 5 | * 提供修改该文件的API,详细介绍可以见文档。 -------------------------------------------------------------------------------- /doc/android签名证书文件的解析和签名校验的加强.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwugang/pkcs7/466b87c370bbf04d8138f87373e0f34e55a1e50c/doc/android签名证书文件的解析和签名校验的加强.pdf -------------------------------------------------------------------------------- /doc/格式解析图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwugang/pkcs7/466b87c370bbf04d8138f87373e0f34e55a1e50c/doc/格式解析图.png -------------------------------------------------------------------------------- /example-apk/CrackMe.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liwugang/pkcs7/466b87c370bbf04d8138f87373e0f34e55a1e50c/example-apk/CrackMe.apk -------------------------------------------------------------------------------- /example.cpp: -------------------------------------------------------------------------------- 1 | #include "pkcs7.h" 2 | 3 | int main(int argc, char **argv) 4 | { 5 | char name[512]; 6 | if (argc >= 2) 7 | strcpy(name, argv[1]); 8 | else { 9 | printf("Plearse input file name:"); 10 | scanf("%s", name); 11 | } 12 | pkcs7 test; 13 | if (test.open_file(name)) { 14 | test.print(); 15 | //test.change_contentType(1); 16 | //test.add_data((unsigned char *)"hello world", strlen("hello world"), 0); 17 | printf("MD5: %s\n", test.get_MD5()); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /pkcs7.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __PKCS7__ 3 | #define __PKCS7__ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "3rd/md5/md5.h" 10 | #include "3rd/zlib/unzip.h" 11 | #include "3rd/zlib/zip.h" 12 | 13 | #ifdef _WIN32 14 | # define STRCASECMP stricmp 15 | # define FUNCTION_NAME __FUNCTION__ 16 | #else 17 | # define STRCASECMP strcasecmp 18 | # define FUNCTION_NAME __func__ 19 | #endif 20 | 21 | #ifdef _WIN32 22 | #pragma warning(disable:4996) 23 | #endif 24 | 25 | #define TAG_INTEGER 0x02 26 | #define TAG_BITSTRING 0x03 27 | #define TAG_OCTETSTRING 0x04 28 | #define TAG_OBJECTID 0x06 29 | #define TAG_UTCTIME 0x17 30 | #define TAG_GENERALIZEDTIME 0x18 31 | #define TAG_SEQUENCE 0x30 32 | #define TAG_SET 0x31 33 | 34 | #define TAG_OPTIONAL 0xA0 35 | 36 | 37 | #define NAME_LEN 63 38 | 39 | typedef struct element { 40 | unsigned char tag; 41 | char name[NAME_LEN]; 42 | int begin; 43 | int len; 44 | int level; 45 | struct element *next; 46 | }element; 47 | 48 | class pkcs7 { 49 | public: 50 | pkcs7(); 51 | ~pkcs7(); 52 | bool open_file(char *file_name); 53 | void print(); 54 | char* get_MD5(); 55 | 56 | bool add_data(unsigned char *data, int len, int tail = 1, const char * save_name = NULL); 57 | bool change_contentType(int type = 1); 58 | 59 | private: 60 | int len_num(unsigned char lenbyte); 61 | int num_from_len(int len); 62 | int tag_offset(element *p); 63 | 64 | int get_length(unsigned char lenbyte, int pos); 65 | int put_length(unsigned char* buffer, int length); 66 | 67 | bool get_from_apk(char *file_name); 68 | bool get_content(char *file_name); 69 | 70 | int create_element(unsigned char tag, char *name, int level); 71 | element *get_element(const char *name, element *begin); 72 | 73 | bool parse_content(int level); 74 | bool parse_pkcs7(); 75 | bool parse_certificate(int level); 76 | bool parse_signerInfo(int level); 77 | 78 | bool parse_time(element *p_val); 79 | 80 | bool save_apk(unsigned char *buffer, int length, const char *save_name); 81 | 82 | 83 | 84 | private: 85 | unsigned char * m_content; 86 | int m_length; 87 | int m_pos; 88 | struct element *head; 89 | struct element *tail; 90 | struct element *p_cert; 91 | struct element *p_signer; 92 | 93 | char *apk_file; 94 | char *cert_file; 95 | }; 96 | 97 | 98 | 99 | #endif //__PKCS7__ --------------------------------------------------------------------------------