68typedef unsigned char uch;
69typedef unsigned short ush;
70typedef unsigned long ulg;
113#define CRCVAL_INITIAL 0L
116#define MSDOS_HIDDEN_ATTR 0x02
117#define MSDOS_DIR_ATTR 0x10
127#define EB_UT_MINLEN 1
130#define EB_UT_FL_MTIME (1 << 0)
131#define EB_UT_FL_ATIME (1 << 1)
132#define EB_UT_FL_CTIME (1 << 2)
133#define EB_UT_LEN(n) (EB_UT_MINLEN + 4 * (n))
134#define EB_L_UT_SIZE (EB_HEADSIZE + EB_UT_LEN(3))
135#define EB_C_UT_SIZE (EB_HEADSIZE + EB_UT_LEN(1))
139#define PUTSH(a,f) {char _putsh_c=(char)((a)&0xff); wfunc(param,&_putsh_c,1); _putsh_c=(char)((a)>>8); wfunc(param,&_putsh_c,1);}
140#define PUTLG(a,f) {PUTSH((a) & 0xffff,(f)) PUTSH((a) >> 16,(f))}
145#define LOCSIG 0x04034b50L
146#define CENSIG 0x02014b50L
147#define ENDSIG 0x06054b50L
148#define EXTLOCSIG 0x08074b50L
156#define WSIZE (0x8000)
162#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
167#define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
174#define ZIP_FILENAME 2
190#define LENGTH_CODES 29
199#define L_CODES (LITERALS+1+LENGTH_CODES)
209#define STORED_BLOCK 0
210#define STATIC_TREES 1
214#define LIT_BUFSIZE 0x8000
215#define DIST_BUFSIZE LIT_BUFSIZE
243#define REPZ_11_138 18
246#define HEAP_SIZE (2*L_CODES+1)
254#define Buf_size (8 * 2*sizeof(char))
259#define PUTSHORT(state,w) \
260 { if (state.bs.out_offset >= state.bs.out_size-1) \
261 state.flush_outbuf(state.param,state.bs.out_buf, &state.bs.out_offset); \
262 state.bs.out_buf[state.bs.out_offset++] = (char) ((w) & 0xff); \
263 state.bs.out_buf[state.bs.out_offset++] = (char) ((ush)(w) >> 8); \
266#define PUTBYTE(state,b) \
267 { if (state.bs.out_offset >= state.bs.out_size) \
268 state.flush_outbuf(state.param,state.bs.out_buf, &state.bs.out_offset); \
269 state.bs.out_buf[state.bs.out_offset++] = (char) (b); \
277#define HASH_SIZE (unsigned)(1<<HASH_BITS)
278#define HASH_MASK (HASH_SIZE-1)
279#define WMASK (WSIZE-1)
301#define H_SHIFT ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH)
307#define max_insert_length max_lazy_match
315 = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
318 = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
321 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
323const uch bl_order[
BL_CODES] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
353 {32, 128, 258, 1024},
630void __cdecl
Trace(
const char* x, ...)
633 va_start(paramList, x);
637void __cdecl
Tracec(
bool,
const char* x, ...)
640 va_start(paramList, x);
668#define send_code(state, c, tree) send_bits(state, tree[c].fc.code, tree[c].dl.len)
676#define d_code(dist) ((dist) < 256 ? state.ts.dist_code[dist] : state.ts.dist_code[256+((dist)>>7)])
680#define Max(a,b) (a >= b ? a : b)
713 Assert(state, length == 256,
"ct_init: length != 256");
722 for (code = 0 ; code < 16; code++)
730 Assert(state, dist == 256,
"ct_init: dist != 256");
732 for ( ; code <
D_CODES; code++)
735 for (n = 0; n < (1 << (
extra_dbits[code] - 7)); n++)
740 Assert(state, dist == 256,
"ct_init: 256+dist != 512");
793#define pqremove(tree, top) \
795 top = state.ts.heap[SMALLEST]; \
796 state.ts.heap[SMALLEST] = state.ts.heap[state.ts.heap_len--]; \
797 pqdownheap(state,tree, SMALLEST); \
804#define smaller(tree, n, m) \
805 (tree[n].fc.freq < tree[m].fc.freq || \
806 (tree[n].fc.freq == tree[m].fc.freq && state.ts.depth[n] <= state.ts.depth[m]))
827 if (
smaller(tree, v, htemp))
break;
875 if (
bits > max_length)
bits = max_length, overflow++;
879 if (n > max_code)
continue;
883 if (n >= base) xbits = extra[n - base];
888 if (overflow == 0)
return;
890 Trace(
"\nbit length overflow\n");
896 bits = max_length - 1;
906 while (overflow > 0);
919 if (m > max_code)
continue;
922 Trace(
"code %d bits %d->%d\n", m, tree[m].dl.
len,
bits);
957 "inconsistent bit counts");
958 Trace(
"\ngen_codes: max_code %d ", max_code);
960 for (n = 0; n <= max_code; n++)
962 int len = tree[n].
dl.
len;
963 if (len == 0)
continue;
983 int elems = desc->
elems;
994 for (n = 0; n < elems; n++)
996 if (tree[n].fc.
freq != 0)
1014 int newcp = state.
ts.
heap[++state.
ts.
heap_len] = (max_code < 2 ? ++max_code : 0);
1072 int nextlen = tree[0].
dl.
len;
1077 if (nextlen == 0) max_count = 138, min_count = 3;
1078 tree[max_code + 1].
dl.
len = (
ush) - 1;
1080 for (n = 0; n <= max_code; n++)
1083 nextlen = tree[n + 1].
dl.
len;
1084 if (++count < max_count && curlen == nextlen)
1088 else if (count < min_count)
1092 else if (curlen != 0)
1097 else if (count <= 10)
1109 max_count = 138, min_count = 3;
1111 else if (curlen == nextlen)
1113 max_count = 6, min_count = 3;
1117 max_count = 7, min_count = 4;
1131 int nextlen = tree[0].
dl.
len;
1137 if (nextlen == 0) max_count = 138, min_count = 3;
1139 for (n = 0; n <= max_code; n++)
1142 nextlen = tree[n + 1].
dl.
len;
1143 if (++count < max_count && curlen == nextlen)
1147 else if (count < min_count)
1153 while (--count != 0);
1156 else if (curlen != 0)
1158 if (curlen != prevlen)
1163 Assert(state, count >= 3 && count <= 6,
" 3_6?");
1168 else if (count <= 10)
1183 max_count = 138, min_count = 3;
1185 else if (curlen == nextlen)
1187 max_count = 6, min_count = 3;
1191 max_count = 7, min_count = 4;
1218 for (max_blindex =
BL_CODES - 1; max_blindex >= 3; max_blindex--)
1223 state.
ts.
opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
1238 Assert(state, lcodes >= 257 && dcodes >= 1 && blcodes >= 4,
"not enough codes");
1241 Trace(
"\nbl counts: ");
1246 for (rank = 0; rank < blcodes; rank++)
1267 ulg opt_lenb, static_lenb;
1291 opt_lenb = (state.
ts.
opt_len + 3 + 7) >> 3;
1295 Trace(
"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
1299 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
1316 if (stored_len + 4 <= opt_lenb && buf != (
char*)NULL)
1329 copy_block(state, buf, (
unsigned)stored_len, 1);
1331 else if (static_lenb == opt_lenb)
1403 for (dcode = 0; dcode <
D_CODES; dcode++)
1408 Trace(
"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
1410 100L - out_length * 100L / in_length);
1436 if ((lx & 7) == 0) flag = state.
ts.
flag_buf[fx++];
1438 if ((flag & 1) == 0)
1482 unsigned ascii_freq = 0;
1483 unsigned bin_freq = 0;
1512 Assert(state, length > 0 && length <= 15,
"invalid length");
1536 register unsigned res = 0;
1540 code >>= 1, res <<= 1;
1590 Assert(state,
false,
"output buffer too small for in-memory compression");
1623#define UPDATE_HASH(h,c) (h = (((h)<<H_SHIFT) ^ (c)) & HASH_MASK)
1633#define INSERT_STRING(s, match_head) \
1634 (UPDATE_HASH(state.ds.ins_h, state.ds.window[(s) + (MIN_MATCH-1)]), \
1635 state.ds.prev[(s) & WMASK] = match_head = state.ds.head[state.ds.ins_h], \
1636 state.ds.head[state.ds.ins_h] = (s))
1649 register unsigned j;
1651 Assert(state, pack_level >= 1 && pack_level <= 8,
"bad pack level");
1675 if (pack_level <= 2)
1679 else if (pack_level >= 8)
1741 register uch scan_end1 = scan[best_len - 1];
1742 register uch scan_end = scan[best_len];
1755 match = state.
ds.
window + cur_match;
1760 if (match[best_len] != scan_end ||
1761 match[best_len - 1] != scan_end1 ||
1763 *++match != scan[1])
continue;
1779 while (*++scan == *++match && *++scan == *++match &&
1780 *++scan == *++match && *++scan == *++match &&
1781 *++scan == *++match && *++scan == *++match &&
1782 *++scan == *++match && *++scan == *++match &&
1796 scan_end1 = scan[best_len - 1];
1797 scan_end = scan[best_len];
1800 while ((cur_match = state.
ds.
prev[cur_match &
WMASK]) > limit
1801 && --chain_length != 0);
1808#define check_match(state,start, match, length)
1836 register unsigned n, m;
1846 if (more == (
unsigned)
EOF)
1875 for (n = 0; n <
WSIZE; n++)
1898 Assert(state, more >= 2,
"more < 2");
1902 if (n == 0 || n == (
unsigned)
EOF)
1918#define FLUSH_BLOCK(state,eof) \
1919 flush_block(state,state.ds.block_start >= 0L ? (char*)&state.ds.window[(unsigned)state.ds.block_start] : \
1920 (char*)NULL, (long)state.ds.strstart - state.ds.block_start, (eof))
1932 unsigned match_length = 0;
1971 if (match_length <= state.
ds.max_insert_length
1983 while (--match_length != 0);
1992 Assert(state,
MIN_MATCH == 3,
"Call UPDATE_HASH() MIN_MATCH-3 more times");
2024 int match_available = 0;
2025 register unsigned match_length =
MIN_MATCH - 1;
2093 match_available = 0;
2099 else if (match_available)
2117 match_available = 1;
2159 size_t res = (size_t)wfunc(param, z->iname, (
unsigned int)z->nam);
2160 if (res != z->nam)
return ZE_TEMP;
2163 res = (size_t)wfunc(param, z->extra, (
unsigned int)z->ext);
2164 if (res != z->ext)
return ZE_TEMP;
2198 if ((
size_t)wfunc(param, z->iname, (
unsigned int)z->nam) != z->nam ||
2199 (z->cext && (
size_t)wfunc(param, z->cextra, (
unsigned int)z->cext) != z->cext) ||
2200 (z->com && (
size_t)wfunc(param, z->comment, (
unsigned int)z->com) != z->com))
2218 if (m && wfunc(param, z, (
unsigned int)m) != m)
return ZE_TEMP;
2229 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
2230 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
2231 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
2232 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
2233 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
2234 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
2235 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
2236 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
2237 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
2238 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
2239 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
2240 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
2241 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
2242 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
2243 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
2244 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
2245 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
2246 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
2247 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
2248 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
2249 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
2250 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
2251 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
2252 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
2253 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
2254 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
2255 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
2256 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
2257 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
2258 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
2259 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
2260 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
2261 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
2262 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
2263 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
2264 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
2265 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
2266 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
2267 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
2268 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
2269 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
2270 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
2271 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
2272 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
2273 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
2274 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
2275 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
2276 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
2277 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
2278 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
2279 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
2283#define CRC32(c, b) (crc_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
2284#define DO1(buf) crc = CRC32(crc, *buf++)
2285#define DO2(buf) DO1(buf); DO1(buf)
2286#define DO4(buf) DO2(buf); DO2(buf)
2287#define DO8(buf) DO4(buf); DO4(buf)
2291 if (buf == NULL)
return 0L;
2292 crc = crc ^ 0xffffffffL;
2303 return crc ^ 0xffffffffL;
2309 keys[0] =
CRC32(keys[0], c);
2310 keys[1] += keys[0] & 0xFF;
2311 keys[1] = keys[1] * 134775813L + 1;
2312 keys[2] =
CRC32(keys[2], keys[1] >> 24);
2316 unsigned temp = ((unsigned)keys[2] & 0xffff) | 2;
2317 return (
char)(((temp * (temp ^ 1)) >> 8) & 0xff);
2323 return (
char)(t ^ c);
2334 const TCHAR* ext = fn + _tcslen(fn);
2335 while (ext > fn && *ext !=
'.') ext--;
2336 if (ext == fn && *ext !=
'.')
return false;
2337 if (_tcsicmp(ext,
_T(
".Z")) == 0)
return true;
2338 if (_tcsicmp(ext,
_T(
".zip")) == 0)
return true;
2339 if (_tcsicmp(ext,
_T(
".zoo")) == 0)
return true;
2340 if (_tcsicmp(ext,
_T(
".arc")) == 0)
return true;
2341 if (_tcsicmp(ext,
_T(
".lzh")) == 0)
return true;
2342 if (_tcsicmp(ext,
_T(
".arj")) == 0)
return true;
2343 if (_tcsicmp(ext,
_T(
".gz")) == 0)
return true;
2344 if (_tcsicmp(ext,
_T(
".tgz")) == 0)
return true;
2351 __int64 i = *(__int64*)&ft;
2352 return (
lutime_t)((i - 116444736000000000) / 10000000);
2360 FileTimeToSystemTime(&ft, &st);
2361 *dosdate = (WORD)(((st.wYear - 1980) & 0x7f) << 9);
2362 *dosdate |= (WORD)((st.wMonth & 0xf) << 5);
2363 *dosdate |= (WORD)((st.wDay & 0x1f));
2364 *dostime = (WORD)((st.wHour & 0x1f) << 11);
2365 *dostime |= (WORD)((st.wMinute & 0x3f) << 5);
2366 *dostime |= (WORD)((st.wSecond * 2) & 0x1f);
2378 BY_HANDLE_FILE_INFORMATION bhi;
2379 BOOL res = GetFileInformationByHandle(hf, &bhi);
2381 DWORD fa = bhi.dwFileAttributes;
2384 if (fa & FILE_ATTRIBUTE_READONLY) a |= 0x01;
2385 if (fa & FILE_ATTRIBUTE_HIDDEN) a |= 0x02;
2386 if (fa & FILE_ATTRIBUTE_SYSTEM) a |= 0x04;
2387 if (fa & FILE_ATTRIBUTE_DIRECTORY)a |= 0x10;
2388 if (fa & FILE_ATTRIBUTE_ARCHIVE) a |= 0x20;
2390 if (fa & FILE_ATTRIBUTE_DIRECTORY)a |= 0x40000000;
2391 else a |= 0x80000000;
2393 if (fa & FILE_ATTRIBUTE_READONLY) {}
2394 else a |= 0x00800000;
2396 DWORD red, hsize = GetFileSize(hf, NULL);
2399 SetFilePointer(hf, 0, NULL, FILE_BEGIN);
2400 unsigned short magic;
2401 ReadFile(hf, &magic,
sizeof(magic), &red, NULL);
2402 SetFilePointer(hf, 36, NULL, FILE_BEGIN);
2404 ReadFile(hf, &hpos,
sizeof(hpos), &red, NULL);
2405 if (magic == 0x54AD && hsize > hpos + 4 + 20 + 28)
2407 SetFilePointer(hf, hpos, NULL, FILE_BEGIN);
2408 unsigned long signature;
2409 ReadFile(hf, &signature,
sizeof(signature), &red, NULL);
2410 if (signature == IMAGE_DOS_SIGNATURE || signature == IMAGE_OS2_SIGNATURE
2411 || signature == IMAGE_OS2_SIGNATURE_LE || signature == IMAGE_NT_SIGNATURE)
2418 if (attr != NULL) *attr = a;
2419 if (size != NULL) *size = hsize;
2428 if (timestamp != NULL)
2430 WORD dosdate, dostime;
2432 *timestamp = (WORD)dostime | (((DWORD)dosdate) << 16);
2447 TZip(
const char* pwd) :
hfout(0),
mustclosehfout(false),
hmapout(0),
zfis(0),
obuf(0),
hfin(0),
writ(0),
oerr(false),
hasputcen(false),
ooffset(0),
encwriting(false),
encbuf(0),
password(0),
state(0)
2449 if (pwd != 0 && *pwd != 0)
2451 password =
new char[strlen(pwd) + 1];
2488 static unsigned sflush(
void* param,
const char*
buf,
unsigned* size);
2489 static unsigned swrite(
void* param,
const char*
buf,
unsigned size);
2490 unsigned int write(
const char*
buf,
unsigned int size);
2491 bool oseek(
unsigned int pos);
2519 unsigned read(
char*
buf,
unsigned size);
2525 ZRESULT Add(
const TCHAR* odstzn,
void* src,
unsigned int len, DWORD flags);
2538 HANDLE hf = (HANDLE)z;
2541#ifdef DuplicateHandle
2542 BOOL res = DuplicateHandle(GetCurrentProcess(), hf, GetCurrentProcess(), &
hfout, 0,
FALSE, DUPLICATE_SAME_ACCESS);
2543 if (res) mustclosehandle =
true;
2547 DWORD res = SetFilePointer(
hfout, 0, 0, FILE_CURRENT);
2555 const TCHAR* fn = (
const TCHAR*)z;
2556 hfout = CreateFile(fn, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2557 if (
hfout == INVALID_HANDLE_VALUE)
2569 unsigned int size = len;
2571 if (z != 0)
obuf = (
char*)z;
2574 hmapout = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, NULL);
2576 obuf = (
char*)MapViewOfFile(
hmapout, FILE_MAP_ALL_ACCESS, 0, 0, size);
2595 if (*size == 0)
return 0;
2598 if (
writ != 0) *size = 0;
2604 if (size == 0)
return 0;
2610 const char* srcbuf =
buf;
2620 encbuf =
new char[size * 2];
2638 else if (
hfout != 0)
2641 WriteFile(
hfout, srcbuf, size, &
writ, NULL);
2665 else if (
hfout != 0)
2667 SetFilePointer(
hfout, pos +
ooffset, NULL, FILE_BEGIN);
2681 if (pbuf != NULL) *pbuf = (
void*)
obuf;
2682 if (plen != NULL) *plen =
writ;
2717 HANDLE hf = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
2718 if (hf == INVALID_HANDLE_VALUE)
return ZR_NOFILE;
2737 if (hf == 0 || hf == INVALID_HANDLE_VALUE)
return ZR_ARGS;
2738 DWORD res = SetFilePointer(
hfout, 0, 0, FILE_CURRENT);
2739 if (res != 0xFFFFFFFF)
2742 if (res !=
ZR_OK)
return res;
2743 SetFilePointer(hf, 0, NULL, FILE_BEGIN);
2752 if (len != 0)
isize = len;
2757 SystemTimeToFileTime(&st, &ft);
2758 WORD dosdate, dostime;
2763 timestamp = (WORD)dostime | (((DWORD)dosdate) << 16);
2771 bufin = (
const char*)src;
2779 if (src == 0 || len == 0)
return ZR_ARGS;
2786 SystemTimeToFileTime(&st, &ft);
2787 WORD dosdate, dostime;
2792 timestamp = (WORD)dostime | (((DWORD)dosdate) << 16);
2810 SystemTimeToFileTime(&st, &ft);
2811 WORD dosdate, dostime;
2816 timestamp = (WORD)dostime | (((DWORD)dosdate) << 16);
2833 if (red > size) red = size;
2843 BOOL ok = ReadFile(
hfin,
buf, size, &red, NULL);
2901 unsigned int cin =
read(
buf, 16384);
2902 if (cin <= 0 || cin == (
unsigned int)
EOF)
break;
2903 unsigned int cout =
write(
buf, cin);
2926 TCHAR dstzn[MAX_PATH];
2927 _tcscpy(dstzn, odstzn);
2928 if (*dstzn == 0)
return ZR_ARGS;
2932 if (*d ==
'\\') *d =
'/';
2936 bool needs_trailing_slash = (isdir && dstzn[_tcslen(dstzn) - 1] !=
'/');
2947 if (openres !=
ZR_OK)
return openres;
2955 strcpy(zfi.
name,
"");
2957 WideCharToMultiByte(CP_UTF8, 0, dstzn, -1, zfi.
iname, MAX_PATH, 0, 0);
2959 strcpy(zfi.
iname, dstzn);
2962 if (needs_trailing_slash)
2964 strcat(zfi.
iname,
"/");
2967 strcpy(zfi.
zname,
"");
3036 keys[0] = 305419896L;
3037 keys[1] = 591751049L;
3038 keys[2] = 878082192L;
3041 if (!
has_seeded) srand(GetTickCount() ^ (
unsigned long)GetDesktopWindow());
3043 for (
int i = 0; i < 12; i++)
encbuf[i] = (
char)((rand() >> 7) & 0xff);
3044 encbuf[11] = (char)((zfi.
tim >> 8) & 0xff);
3056 else if (!isdir && method ==
STORE) writeres =
istore();
3057 else if (isdir)
csize = 0;
3065 bool first_header_has_size_right = (zfi.
siz ==
csize + passex);
3072 if ((zfi.
flg & 1) == 0) zfi.
flg &= ~8;
3091 char* cextra =
new char[zfi.
cext];
3095 memcpy(pzfi, &zfi,
sizeof(zfi));
3100 while (z->
nxt != NULL) z = z->
nxt;
3110 ulg pos_at_start_of_central =
writ;
3118 if (res !=
ZE_OK) okay =
false;
3120 writ += 4 +
CENHEAD + (
unsigned int)zfi->nam + (
unsigned int)zfi->cext + (
unsigned int)zfi->com;
3126 if (zfi->cextra != 0)
delete[] zfi->cextra;
3130 ulg center_size =
writ - pos_at_start_of_central;
3133 int res =
putend(numentries, center_size, pos_at_start_of_central +
ooffset, 0, NULL,
swrite,
this);
3134 if (res !=
ZE_OK) okay =
false;
3150 const char* msg =
"unknown zip result code";
3157 msg =
"Culdn't duplicate handle";
3160 msg =
"Couldn't create/open file";
3163 msg =
"Failed to allocate memory";
3166 msg =
"Error writing to file";
3169 msg =
"File not found in the zipfile";
3172 msg =
"Still more data to unzip";
3175 msg =
"Zipfile is corrupt or not a zipfile";
3178 msg =
"Error reading file";
3181 msg =
"Caller: faulty arguments";
3184 msg =
"Caller: the file had already been partially unzipped";
3187 msg =
"Caller: can only get memory of a memory zipfile";
3190 msg =
"Caller: not enough space allocated for memory zipfile";
3193 msg =
"Caller: there was a previous error";
3196 msg =
"Caller: additions to the zip have already been ended";
3199 msg =
"Caller: mixing creation and opening of zip";
3202 msg =
"Zip-bug: internal initialisation not completed";
3205 msg =
"Zip-bug: trying to seek the unseekable";
3208 msg =
"Zip-bug: the anticipated size turned out wrong";
3211 msg =
"Zip-bug: tried to change mind, but not allowed";
3214 msg =
"Zip-bug: an internal error during flation";
3217 unsigned int mlen = (
unsigned int)strlen(msg);
3218 if (buf == 0 || len == 0)
return mlen;
3219 unsigned int n = mlen;
3220 if (n + 1 > len) n = len - 1;
3221 strncpy(buf, msg, n);
3257HZIP
CreateZip(
void* z,
unsigned int len,
const char* password)
3307 if (buf != 0) *buf = 0;
3308 if (len != 0) *len = 0;
3345 if (hz == 0)
return false;
3347 return (han->
flag == 2);
unsigned max_chain_length
unsigned int max_lazy_match
ush far d_buf[DIST_BUFSIZE]
ct_data bl_tree[2 *BL_CODES+1]
ct_data static_ltree[L_CODES+2]
ct_data dyn_dtree[2 *D_CODES+1]
int base_length[LENGTH_CODES]
uch length_code[MAX_MATCH - MIN_MATCH+1]
uch far l_buf[LIT_BUFSIZE]
uch flag_buf[(LIT_BUFSIZE/8)]
ct_data static_dtree[D_CODES]
ct_data dyn_ltree[HEAP_SIZE]
static unsigned sflush(void *param, const char *buf, unsigned *size)
unsigned int write(const char *buf, unsigned int size)
bool oseek(unsigned int pos)
static unsigned swrite(void *param, const char *buf, unsigned size)
ZRESULT GetMemory(void **pbuf, unsigned long *plen)
unsigned read(char *buf, unsigned size)
ZRESULT open_mem(void *src, unsigned int len)
ZRESULT open_file(const TCHAR *fn)
ZRESULT ideflate(TZipFileInfo *zfi)
static unsigned sread(TState &s, char *buf, unsigned size)
ZRESULT open_handle(HANDLE hf, unsigned int len)
ZRESULT Add(const TCHAR *odstzn, void *src, unsigned int len, DWORD flags)
ZRESULT Create(void *z, unsigned int len, DWORD flags)
if(nReturnType==EIGENVALUES)
for(unsigned int i=0;i< _mMatrix.rows();i++)
CONSTDATA solar_hijri::month far
unsigned __int32 lutime_t
void fill_window(TState &state)
void Assert(TState &state, bool cond, const char *msg)
char decrypt_byte(unsigned long *keys)
const config configuration_table[10]
#define PUTBYTE(state, b)
char zencode(unsigned long *keys, char c)
int putlocal(struct zlist far *z, WRITEFUNC wfunc, void *param)
#define pqremove(tree, top)
int putcentral(struct zlist far *z, WRITEFUNC wfunc, void *param)
ZRESULT ZipAddHandle(HZIP hz, const TCHAR *dstzn, HANDLE h)
const int extra_blbits[BL_CODES]
bool HasZipSuffix(const TCHAR *fn)
#define send_code(state, c, tree)
ulg deflate_fast(TState &state)
void bi_windup(TState &state)
#define INSERT_STRING(s, match_head)
void scan_tree(TState &, ct_data *tree, int max_code)
struct tree_desc tree_desc
ZRESULT ZipAddInternal(HZIP hz, const TCHAR *dstzn, void *src, unsigned int len, DWORD flags)
unsigned int FormatZipMessageZ(ZRESULT code, char *buf, unsigned int len)
ulg flush_block(TState &state, char *buf, ulg stored_len, int eof)
struct zlist TZipFileInfo
HZIP CreateZipInternal(void *z, unsigned int len, DWORD flags, const char *password)
unsigned(* READFUNC)(TState &state, char *buf, unsigned size)
void __cdecl Trace(const char *x,...)
unsigned bi_reverse(unsigned code, int len)
#define smaller(tree, n, m)
HZIP CreateZipHandle(HANDLE h, const char *password)
ulg crc32(ulg crc, const uch *buf, extent len)
ulg deflate(TState &state)
void build_tree(TState &, tree_desc *desc)
int putextended(struct zlist far *z, WRITEFUNC wfunc, void *param)
ZRESULT ZipGetMemory(HZIP hz, void **buf, unsigned long *len)
const int extra_lbits[LENGTH_CODES]
const int extra_dbits[D_CODES]
void gen_bitlen(TState &, tree_desc *desc)
void init_block(TState &)
void copy_block(TState &state, char *buf, unsigned len, int header)
unsigned(* FLUSHFUNC)(void *param, const char *buf, unsigned *size)
#define PUTSHORT(state, w)
void gen_codes(TState &state, ct_data *tree, int max_code)
#define UPDATE_HASH(h, c)
const uch bl_order[BL_CODES]
void send_tree(TState &state, ct_data *tree, int max_code)
#define check_match(state, start, match, length)
void pqdownheap(TState &, ct_data *tree, int k)
void lm_init(TState &state, int pack_level, ush *flags)
ZRESULT ZipAddFolder(HZIP hz, const TCHAR *dstzn)
void send_all_trees(TState &state, int lcodes, int dcodes, int blcodes)
int longest_match(TState &state, IPos cur_match)
ZRESULT CloseZipZ(HZIP hz)
ZRESULT ZipAdd(HZIP hz, const TCHAR *dstzn, const TCHAR *fn)
int putend(int n, ulg s, ulg c, extent m, char *z, WRITEFUNC wfunc, void *param)
ZRESULT GetFileInfo(HANDLE hf, ulg *attr, long *size, iztimes *times, ulg *timestamp)
void ct_init(TState &state, ush *attr)
lutime_t filetime2timet(const FILETIME ft)
HZIP CreateZip(const TCHAR *fn, const char *password)
void filetime2dosdatetime(const FILETIME ft, WORD *dosdate, WORD *dostime)
bool IsZipHandleZ(HZIP hz)
void compress_block(TState &state, ct_data *ltree, ct_data *dtree)
void set_file_type(TState &)
int ct_tally(TState &state, int dist, int lc)
void bi_init(TState &state, char *tgt_buf, unsigned tgt_size, int flsh_allowed)
void __cdecl Tracec(bool, const char *x,...)
void update_keys(unsigned long *keys, char c)
int build_bl_tree(TState &)
unsigned(* WRITEFUNC)(void *param, const char *buf, unsigned size)
void send_bits(TState &state, int value, int length)
#define FLUSH_BLOCK(state, eof)