fintp_base
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zip.cpp File Reference
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "zip.h"

Classes

struct  config
 
struct  ct_data
 
struct  tree_desc
 
class  TTreeState
 
class  TBitState
 
class  TDeflateState
 
struct  iztimes
 
struct  zlist
 
struct  TState
 
class  TZip
 
struct  TZipHandleData
 

Macros

#define EOF   (-1)
 
#define ZE_MISS   -1
 
#define ZE_OK   0
 
#define ZE_EOF   2
 
#define ZE_FORM   3
 
#define ZE_MEM   4
 
#define ZE_LOGIC   5
 
#define ZE_BIG   6
 
#define ZE_NOTE   7
 
#define ZE_TEST   8
 
#define ZE_ABORT   9
 
#define ZE_TEMP   10
 
#define ZE_READ   11
 
#define ZE_NONE   12
 
#define ZE_NAME   13
 
#define ZE_WRITE   14
 
#define ZE_CREAT   15
 
#define ZE_PARMS   16
 
#define ZE_OPEN   18
 
#define ZE_MAXERR   18
 
#define UNKNOWN   (-1)
 
#define BINARY   0
 
#define ASCII   1
 
#define BEST   -1
 
#define STORE   0
 
#define DEFLATE   8
 
#define CRCVAL_INITIAL   0L
 
#define MSDOS_HIDDEN_ATTR   0x02
 
#define MSDOS_DIR_ATTR   0x10
 
#define LOCHEAD   26
 
#define CENHEAD   42
 
#define ENDHEAD   18
 
#define EB_HEADSIZE   4 /* length of a extra field block header */
 
#define EB_LEN   2 /* offset of data length field in header */
 
#define EB_UT_MINLEN   1 /* minimal UT field contains Flags byte */
 
#define EB_UT_FLAGS   0 /* byte offset of Flags field */
 
#define EB_UT_TIME1   1 /* byte offset of 1st time value */
 
#define EB_UT_FL_MTIME   (1 << 0) /* mtime present */
 
#define EB_UT_FL_ATIME   (1 << 1) /* atime present */
 
#define EB_UT_FL_CTIME   (1 << 2) /* ctime present */
 
#define EB_UT_LEN(n)   (EB_UT_MINLEN + 4 * (n))
 
#define EB_L_UT_SIZE   (EB_HEADSIZE + EB_UT_LEN(3))
 
#define EB_C_UT_SIZE   (EB_HEADSIZE + EB_UT_LEN(1))
 
#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);}
 
#define PUTLG(a, f)   {PUTSH((a) & 0xffff,(f)) PUTSH((a) >> 16,(f))}
 
#define LOCSIG   0x04034b50L
 
#define CENSIG   0x02014b50L
 
#define ENDSIG   0x06054b50L
 
#define EXTLOCSIG   0x08074b50L
 
#define MIN_MATCH   3
 
#define MAX_MATCH   258
 
#define WSIZE   (0x8000)
 
#define MIN_LOOKAHEAD   (MAX_MATCH+MIN_MATCH+1)
 
#define MAX_DIST   (WSIZE-MIN_LOOKAHEAD)
 
#define ZIP_HANDLE   1
 
#define ZIP_FILENAME   2
 
#define ZIP_MEMORY   3
 
#define ZIP_FOLDER   4
 
#define MAX_BITS   15
 
#define MAX_BL_BITS   7
 
#define LENGTH_CODES   29
 
#define LITERALS   256
 
#define END_BLOCK   256
 
#define L_CODES   (LITERALS+1+LENGTH_CODES)
 
#define D_CODES   30
 
#define BL_CODES   19
 
#define STORED_BLOCK   0
 
#define STATIC_TREES   1
 
#define DYN_TREES   2
 
#define LIT_BUFSIZE   0x8000
 
#define DIST_BUFSIZE   LIT_BUFSIZE
 
#define REP_3_6   16
 
#define REPZ_3_10   17
 
#define REPZ_11_138   18
 
#define HEAP_SIZE   (2*L_CODES+1)
 
#define Buf_size   (8 * 2*sizeof(char))
 
#define PUTSHORT(state, w)
 
#define PUTBYTE(state, b)
 
#define HASH_BITS   15
 
#define HASH_SIZE   (unsigned)(1<<HASH_BITS)
 
#define HASH_MASK   (HASH_SIZE-1)
 
#define WMASK   (WSIZE-1)
 
#define NIL   0
 
#define FAST   4
 
#define SLOW   2
 
#define TOO_FAR   4096
 
#define EQUAL   0
 
#define H_SHIFT   ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH)
 
#define max_insert_length   max_lazy_match
 
#define send_code(state, c, tree)   send_bits(state, tree[c].fc.code, tree[c].dl.len)
 
#define d_code(dist)   ((dist) < 256 ? state.ts.dist_code[dist] : state.ts.dist_code[256+((dist)>>7)])
 
#define Max(a, b)   (a >= b ? a : b)
 
#define SMALLEST   1
 
#define pqremove(tree, top)
 
#define smaller(tree, n, m)
 
#define UPDATE_HASH(h, c)   (h = (((h)<<H_SHIFT) ^ (c)) & HASH_MASK)
 
#define INSERT_STRING(s, match_head)
 
#define check_match(state, start, match, length)
 
#define FLUSH_BLOCK(state, eof)
 
#define CRC32(c, b)   (crc_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
 
#define DO1(buf)   crc = CRC32(crc, *buf++)
 
#define DO2(buf)   DO1(buf); DO1(buf)
 
#define DO4(buf)   DO2(buf); DO2(buf)
 
#define DO8(buf)   DO4(buf); DO4(buf)
 

Typedefs

typedef unsigned char uch
 
typedef unsigned short ush
 
typedef unsigned long ulg
 
typedef size_t extent
 
typedef unsigned Pos
 
typedef unsigned IPos
 
typedef struct config config
 
typedef struct ct_data ct_data
 
typedef struct tree_desc tree_desc
 
typedef __int64 lutime_t
 
typedef struct iztimes iztimes
 
typedef struct zlist TZipFileInfo
 
typedef unsigned(* READFUNC )(TState &state, char *buf, unsigned size)
 
typedef unsigned(* FLUSHFUNC )(void *param, const char *buf, unsigned *size)
 
typedef unsigned(* WRITEFUNC )(void *param, const char *buf, unsigned size)
 

Functions

void Assert (TState &state, bool cond, const char *msg)
 
void __cdecl Trace (const char *x,...)
 
void __cdecl Tracec (bool, const char *x,...)
 
void init_block (TState &)
 
void pqdownheap (TState &, ct_data *tree, int k)
 
void gen_bitlen (TState &, tree_desc *desc)
 
void gen_codes (TState &state, ct_data *tree, int max_code)
 
void build_tree (TState &, tree_desc *desc)
 
void scan_tree (TState &, ct_data *tree, int max_code)
 
void send_tree (TState &state, ct_data *tree, int max_code)
 
int build_bl_tree (TState &)
 
void send_all_trees (TState &state, int lcodes, int dcodes, int blcodes)
 
void compress_block (TState &state, ct_data *ltree, ct_data *dtree)
 
void set_file_type (TState &)
 
void send_bits (TState &state, int value, int length)
 
unsigned bi_reverse (unsigned code, int len)
 
void bi_windup (TState &state)
 
void copy_block (TState &state, char *buf, unsigned len, int header)
 
void ct_init (TState &state, ush *attr)
 
ulg flush_block (TState &state, char *buf, ulg stored_len, int eof)
 
int ct_tally (TState &state, int dist, int lc)
 
void bi_init (TState &state, char *tgt_buf, unsigned tgt_size, int flsh_allowed)
 
void fill_window (TState &state)
 
ulg deflate_fast (TState &state)
 
int longest_match (TState &state, IPos cur_match)
 
void lm_init (TState &state, int pack_level, ush *flags)
 
ulg deflate (TState &state)
 
int putlocal (struct zlist far *z, WRITEFUNC wfunc, void *param)
 
int putextended (struct zlist far *z, WRITEFUNC wfunc, void *param)
 
int putcentral (struct zlist far *z, WRITEFUNC wfunc, void *param)
 
int putend (int n, ulg s, ulg c, extent m, char *z, WRITEFUNC wfunc, void *param)
 
ulg crc32 (ulg crc, const uch *buf, extent len)
 
void update_keys (unsigned long *keys, char c)
 
char decrypt_byte (unsigned long *keys)
 
char zencode (unsigned long *keys, char c)
 
bool HasZipSuffix (const TCHAR *fn)
 
lutime_t filetime2timet (const FILETIME ft)
 
void filetime2dosdatetime (const FILETIME ft, WORD *dosdate, WORD *dostime)
 
ZRESULT GetFileInfo (HANDLE hf, ulg *attr, long *size, iztimes *times, ulg *timestamp)
 
unsigned int FormatZipMessageZ (ZRESULT code, char *buf, unsigned int len)
 
HZIP CreateZipInternal (void *z, unsigned int len, DWORD flags, const char *password)
 
HZIP CreateZipHandle (HANDLE h, const char *password)
 
HZIP CreateZip (const TCHAR *fn, const char *password)
 
HZIP CreateZip (void *z, unsigned int len, const char *password)
 
ZRESULT ZipAddInternal (HZIP hz, const TCHAR *dstzn, void *src, unsigned int len, DWORD flags)
 
ZRESULT ZipAdd (HZIP hz, const TCHAR *dstzn, const TCHAR *fn)
 
ZRESULT ZipAdd (HZIP hz, const TCHAR *dstzn, void *src, unsigned int len)
 
ZRESULT ZipAddHandle (HZIP hz, const TCHAR *dstzn, HANDLE h)
 
ZRESULT ZipAddHandle (HZIP hz, const TCHAR *dstzn, HANDLE h, unsigned int len)
 
ZRESULT ZipAddFolder (HZIP hz, const TCHAR *dstzn)
 
ZRESULT ZipGetMemory (HZIP hz, void **buf, unsigned long *len)
 
ZRESULT CloseZipZ (HZIP hz)
 
bool IsZipHandleZ (HZIP hz)
 

Variables

const int extra_lbits [LENGTH_CODES] = {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}
 
const int extra_dbits [D_CODES] = {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}
 
const int extra_blbits [BL_CODES] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}
 
const uch bl_order [BL_CODES] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}
 
const config configuration_table [10]
 
const ulg crc_table [256]
 
bool has_seeded =false
 
ZRESULT lasterrorZ =ZR_OK
 

Macro Definition Documentation

#define ASCII   1
#define BEST   -1
#define BINARY   0
#define BL_CODES   19
#define Buf_size   (8 * 2*sizeof(char))
#define CENHEAD   42
#define CENSIG   0x02014b50L
#define check_match (   state,
  start,
  match,
  length 
)
#define CRC32 (   c,
 
)    (crc_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
#define CRCVAL_INITIAL   0L
#define d_code (   dist)    ((dist) < 256 ? state.ts.dist_code[dist] : state.ts.dist_code[256+((dist)>>7)])
#define D_CODES   30
#define DEFLATE   8
#define DIST_BUFSIZE   LIT_BUFSIZE
#define DO1 (   buf)    crc = CRC32(crc, *buf++)
#define DO2 (   buf)    DO1(buf); DO1(buf)
#define DO4 (   buf)    DO2(buf); DO2(buf)
#define DO8 (   buf)    DO4(buf); DO4(buf)
#define DYN_TREES   2
#define EB_C_UT_SIZE   (EB_HEADSIZE + EB_UT_LEN(1))
#define EB_HEADSIZE   4 /* length of a extra field block header */
#define EB_L_UT_SIZE   (EB_HEADSIZE + EB_UT_LEN(3))
#define EB_LEN   2 /* offset of data length field in header */
#define EB_UT_FL_ATIME   (1 << 1) /* atime present */
#define EB_UT_FL_CTIME   (1 << 2) /* ctime present */
#define EB_UT_FL_MTIME   (1 << 0) /* mtime present */
#define EB_UT_FLAGS   0 /* byte offset of Flags field */
#define EB_UT_LEN (   n)    (EB_UT_MINLEN + 4 * (n))
#define EB_UT_MINLEN   1 /* minimal UT field contains Flags byte */
#define EB_UT_TIME1   1 /* byte offset of 1st time value */
#define END_BLOCK   256
#define ENDHEAD   18
#define ENDSIG   0x06054b50L
#define EOF   (-1)
#define EQUAL   0
#define EXTLOCSIG   0x08074b50L
#define FAST   4
#define FLUSH_BLOCK (   state,
  eof 
)
Value:
flush_block(state,state.ds.block_start >= 0L ? (char*)&state.ds.window[(unsigned)state.ds.block_start] : \
(char*)NULL, (long)state.ds.strstart - state.ds.block_start, (eof))
#define H_SHIFT   ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH)
#define HASH_BITS   15
#define HASH_MASK   (HASH_SIZE-1)
#define HASH_SIZE   (unsigned)(1<<HASH_BITS)
#define HEAP_SIZE   (2*L_CODES+1)
#define INSERT_STRING (   s,
  match_head 
)
Value:
(UPDATE_HASH(state.ds.ins_h, state.ds.window[(s) + (MIN_MATCH-1)]), \
state.ds.prev[(s) & WMASK] = match_head = state.ds.head[state.ds.ins_h], \
state.ds.head[state.ds.ins_h] = (s))
#define L_CODES   (LITERALS+1+LENGTH_CODES)
#define LENGTH_CODES   29
#define LIT_BUFSIZE   0x8000
#define LITERALS   256
#define LOCHEAD   26
#define LOCSIG   0x04034b50L
#define Max (   a,
 
)    (a >= b ? a : b)
#define MAX_BITS   15
#define MAX_BL_BITS   7
#define MAX_DIST   (WSIZE-MIN_LOOKAHEAD)
#define max_insert_length   max_lazy_match
#define MAX_MATCH   258
#define MIN_LOOKAHEAD   (MAX_MATCH+MIN_MATCH+1)
#define MIN_MATCH   3
#define MSDOS_DIR_ATTR   0x10
#define MSDOS_HIDDEN_ATTR   0x02
#define NIL   0
#define pqremove (   tree,
  top 
)
Value:
{\
top = state.ts.heap[SMALLEST]; \
state.ts.heap[SMALLEST] = state.ts.heap[state.ts.heap_len--]; \
pqdownheap(state,tree, SMALLEST); \
}
#define PUTBYTE (   state,
 
)
Value:
{ if (state.bs.out_offset >= state.bs.out_size) \
state.flush_outbuf(state.param,state.bs.out_buf, &state.bs.out_offset); \
state.bs.out_buf[state.bs.out_offset++] = (char) (b); \
}
#define PUTLG (   a,
 
)    {PUTSH((a) & 0xffff,(f)) PUTSH((a) >> 16,(f))}
#define PUTSH (   a,
 
)    {char _putsh_c=(char)((a)&0xff); wfunc(param,&_putsh_c,1); _putsh_c=(char)((a)>>8); wfunc(param,&_putsh_c,1);}
#define PUTSHORT (   state,
 
)
Value:
{ if (state.bs.out_offset >= state.bs.out_size-1) \
state.flush_outbuf(state.param,state.bs.out_buf, &state.bs.out_offset); \
state.bs.out_buf[state.bs.out_offset++] = (char) ((w) & 0xff); \
state.bs.out_buf[state.bs.out_offset++] = (char) ((ush)(w) >> 8); \
}
#define REP_3_6   16
#define REPZ_11_138   18
#define REPZ_3_10   17
#define send_code (   state,
  c,
  tree 
)    send_bits(state, tree[c].fc.code, tree[c].dl.len)
#define SLOW   2
#define smaller (   tree,
  n,
 
)
Value:
(tree[n].fc.freq < tree[m].fc.freq || \
(tree[n].fc.freq == tree[m].fc.freq && state.ts.depth[n] <= state.ts.depth[m]))
#define SMALLEST   1
#define STATIC_TREES   1
#define STORE   0
#define STORED_BLOCK   0
#define TOO_FAR   4096
#define UNKNOWN   (-1)
#define UPDATE_HASH (   h,
 
)    (h = (((h)<<H_SHIFT) ^ (c)) & HASH_MASK)
#define WMASK   (WSIZE-1)
#define WSIZE   (0x8000)
#define ZE_ABORT   9
#define ZE_BIG   6
#define ZE_CREAT   15
#define ZE_EOF   2
#define ZE_FORM   3
#define ZE_LOGIC   5
#define ZE_MAXERR   18
#define ZE_MEM   4
#define ZE_MISS   -1
#define ZE_NAME   13
#define ZE_NONE   12
#define ZE_NOTE   7
#define ZE_OK   0
#define ZE_OPEN   18
#define ZE_PARMS   16
#define ZE_READ   11
#define ZE_TEMP   10
#define ZE_TEST   8
#define ZE_WRITE   14
#define ZIP_FILENAME   2
#define ZIP_FOLDER   4
#define ZIP_HANDLE   1
#define ZIP_MEMORY   3

Typedef Documentation

typedef struct config config
typedef struct ct_data ct_data
typedef size_t extent
typedef unsigned(* FLUSHFUNC)(void *param, const char *buf, unsigned *size)
typedef unsigned IPos
typedef struct iztimes iztimes
typedef __int64 lutime_t
typedef unsigned Pos
typedef unsigned(* READFUNC)(TState &state, char *buf, unsigned size)
typedef struct tree_desc tree_desc
typedef struct zlist TZipFileInfo
typedef unsigned char uch
typedef unsigned long ulg
typedef unsigned short ush
typedef unsigned(* WRITEFUNC)(void *param, const char *buf, unsigned size)

Function Documentation

void Assert ( TState state,
bool  cond,
const char *  msg 
)
void bi_init ( TState state,
char *  tgt_buf,
unsigned  tgt_size,
int  flsh_allowed 
)
unsigned bi_reverse ( unsigned  code,
int  len 
)
void bi_windup ( TState state)
int build_bl_tree ( TState state)
void build_tree ( TState state,
tree_desc desc 
)
ZRESULT CloseZipZ ( HZIP  hz)
void compress_block ( TState state,
ct_data ltree,
ct_data dtree 
)
void copy_block ( TState state,
char *  buf,
unsigned  len,
int  header 
)
ulg crc32 ( ulg  crc,
const uch buf,
extent  len 
)
HZIP CreateZip ( const TCHAR *  fn,
const char *  password 
)
HZIP CreateZip ( void *  z,
unsigned int  len,
const char *  password 
)
HZIP CreateZipHandle ( HANDLE  h,
const char *  password 
)
HZIP CreateZipInternal ( void *  z,
unsigned int  len,
DWORD  flags,
const char *  password 
)
void ct_init ( TState state,
ush attr 
)
int ct_tally ( TState state,
int  dist,
int  lc 
)
char decrypt_byte ( unsigned long *  keys)
ulg deflate ( TState state)
ulg deflate_fast ( TState state)
void filetime2dosdatetime ( const FILETIME  ft,
WORD *  dosdate,
WORD *  dostime 
)
lutime_t filetime2timet ( const FILETIME  ft)
void fill_window ( TState state)
ulg flush_block ( TState state,
char *  buf,
ulg  stored_len,
int  eof 
)
unsigned int FormatZipMessageZ ( ZRESULT  code,
char *  buf,
unsigned int  len 
)
void gen_bitlen ( TState state,
tree_desc desc 
)
void gen_codes ( TState state,
ct_data tree,
int  max_code 
)
ZRESULT GetFileInfo ( HANDLE  hf,
ulg attr,
long *  size,
iztimes times,
ulg timestamp 
)
bool HasZipSuffix ( const TCHAR *  fn)
void init_block ( TState state)
bool IsZipHandleZ ( HZIP  hz)
void lm_init ( TState state,
int  pack_level,
ush flags 
)
int longest_match ( TState state,
IPos  cur_match 
)
void pqdownheap ( TState state,
ct_data tree,
int  k 
)
int putcentral ( struct zlist far *  z,
WRITEFUNC  wfunc,
void *  param 
)
int putend ( int  n,
ulg  s,
ulg  c,
extent  m,
char *  z,
WRITEFUNC  wfunc,
void *  param 
)
int putextended ( struct zlist far *  z,
WRITEFUNC  wfunc,
void *  param 
)
int putlocal ( struct zlist far *  z,
WRITEFUNC  wfunc,
void *  param 
)
void scan_tree ( TState state,
ct_data tree,
int  max_code 
)
void send_all_trees ( TState state,
int  lcodes,
int  dcodes,
int  blcodes 
)
void send_bits ( TState state,
int  value,
int  length 
)
void send_tree ( TState state,
ct_data tree,
int  max_code 
)
void set_file_type ( TState state)
void __cdecl Trace ( const char *  x,
  ... 
)
void __cdecl Tracec ( bool  ,
const char *  x,
  ... 
)
void update_keys ( unsigned long *  keys,
char  c 
)
char zencode ( unsigned long *  keys,
char  c 
)
ZRESULT ZipAdd ( HZIP  hz,
const TCHAR *  dstzn,
const TCHAR *  fn 
)
ZRESULT ZipAdd ( HZIP  hz,
const TCHAR *  dstzn,
void *  src,
unsigned int  len 
)
ZRESULT ZipAddFolder ( HZIP  hz,
const TCHAR *  dstzn 
)
ZRESULT ZipAddHandle ( HZIP  hz,
const TCHAR *  dstzn,
HANDLE  h 
)
ZRESULT ZipAddHandle ( HZIP  hz,
const TCHAR *  dstzn,
HANDLE  h,
unsigned int  len 
)
ZRESULT ZipAddInternal ( HZIP  hz,
const TCHAR *  dstzn,
void *  src,
unsigned int  len,
DWORD  flags 
)
ZRESULT ZipGetMemory ( HZIP  hz,
void **  buf,
unsigned long *  len 
)

Variable Documentation

const uch bl_order[BL_CODES] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}
const config configuration_table[10]
Initial value:
= {
{0, 0, 0, 0},
{4, 4, 8, 4},
{4, 5, 16, 8},
{4, 6, 32, 32},
{4, 4, 16, 16},
{8, 16, 32, 32},
{8, 16, 128, 128},
{8, 32, 128, 256},
{32, 128, 258, 1024},
{32, 258, 258, 4096}}
const ulg crc_table[256]
const int extra_blbits[BL_CODES] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}
const int extra_dbits[D_CODES] = {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}
const int extra_lbits[LENGTH_CODES] = {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}
bool has_seeded =false
ZRESULT lasterrorZ =ZR_OK