3 * Guido Draheim <guidod@gmx.de>
5 * Copyright (c) 2000,2001,2002,2003 Guido Draheim
7 * use under the restrictions of the
8 * Lesser GNU General Public License
9 * or alternatively the restrictions
10 * of the Mozilla Public License 1.1
12 * The information was taken from appnote-981119-iz.zip
13 * at http://www.freesoftware.com/pub/infozip/doc/
14 * which in turn is based on PKWARE's appnote.txt
16 #ifndef _ZZIP_FORMAT_H /* zzipformat.h */
17 #define _ZZIP_FORMAT_H
20 /* we have ICO C 9X types defined */
23 * Overall zipfile format
24 * [local file header + file data + data descriptr] ... [central directory] [EOD record]
28 # pragma pack(push, 1)
35 } __attribute__((packed));
41 } __attribute__((packed));
43 #define ZZIP_CHECKMAGIC(__p,__A,__B,__C,__D) \
44 ( (((char*)(__p))[0]==(__A)) && \
45 (((char*)(__p))[1]==(__B)) && \
46 (((char*)(__p))[2]==(__C)) && \
47 (((char*)(__p))[3]==(__D)) )
49 /* A. Local file header */
50 struct zzip_file_header
52 # define ZZIP_FILE_HEADER_MAGIC 0x04034b50
53 # define ZZIP_FILE_HEADER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\3','\4')
54 char z_magic[4]; /* local file header signature (0x04034b50) */
55 struct zzip_version z_extract; /* version needed to extract */
56 char z_flags[2]; /* general purpose bit flag */
57 char z_compr[2]; /* compression method */
58 struct zzip_dostime z_dostime; /* last mod file time (dos format) */
59 char z_crc32[4]; /* crc-32 */
60 char z_csize[4]; /* compressed size */
61 char z_usize[4]; /* uncompressed size */
62 char z_namlen[2]; /* filename length (null if stdin) */
63 char z_extras[2]; /* extra field length */
64 /* followed by filename (of variable size) */
65 /* followed by extra field (of variable size) */
66 } __attribute__((packed));
69 * the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned
70 * and immediately follows the last byte of compressed data. It is only used if
71 * the output media of the compressor was not seekable, eg. standard output.
73 struct zzip_file_trailer
75 # define ZZIP_FILE_TRAILER_MAGIC 0x08074B50
76 # define ZZIP_FILE_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\7','\8')
77 uint32_t z_magic; /* data descriptor signature (0x08074b50) */
78 uint32_t z_crc32; /* crc-32 */
79 uint32_t z_csize; /* compressed size */
80 uint32_t z_usize; /* uncompressed size */
81 } __attribute__((packed));
83 /* C. central directory structure:
84 [file header] . . . end of central dir record
87 /* directory file header
88 * - a single entry including filename, extras and comment may not exceed 64k.
91 struct zzip_root_dirent
93 # define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50
94 # define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2')
95 char z_magic[4]; /* central file header signature (0x02014b50) */
96 struct zzip_version z_encoder; /* version made by */
97 struct zzip_version z_extract; /* version need to extract */
98 char z_flags[2]; /* general purpose bit flag */
99 char z_compr[2]; /* compression method */
100 struct zzip_dostime z_dostime; /* last mod file time&date (dos format) */
101 char z_crc32[4]; /* crc-32 */
102 char z_csize[4]; /* compressed size */
103 char z_usize[4]; /* uncompressed size */
104 char z_namlen[2]; /* filename length (null if stdin) */
105 char z_extras[2]; /* extra field length */
106 char z_comment[2]; /* file comment length */
107 char z_diskstart[2]; /* disk number of start (if spanning zip over multiple disks) */
108 char z_filetype[2]; /* internal file attributes, bit0 = ascii */
109 char z_filemode[4]; /* extrnal file attributes, eg. msdos attrib byte */
110 char z_off[4]; /* relative offset of local file header, seekval if singledisk */
111 /* followed by filename (of variable size) */
112 /* followed by extra field (of variable size) */
113 /* followed by file comment (of variable size) */
114 } __attribute__((packed));
116 /* end of central dir record */
117 struct zzip_disk_trailer
119 # define ZZIP_DISK_TRAILER_MAGIC 0x06054b50
120 # define ZZIP_DISK_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\5','\6')
121 char z_magic[4]; /* end of central dir signature (0x06054b50) */
122 char z_disk[2]; /* number of this disk */
123 char z_finaldisk[2]; /* number of the disk with the start of the central dir */
124 char z_entries[2]; /* total number of entries in the central dir on this disk */
125 char z_finalentries[2]; /* total number of entries in the central dir */
126 char z_rootsize[4]; /* size of the central directory */
127 char z_rootseek[4]; /* offset of start of central directory with respect to *
128 * the starting disk number */
129 char z_comment[2]; /* zipfile comment length */
130 /* followed by zipfile comment (of variable size) */
131 } __attribute__((packed));
134 #define ZZIP_IS_ENCRYPTED(p) ((*(unsigned char*)p)&1)
135 #define ZZIP_IS_COMPRLEVEL(p) (((*(unsigned char*)p)>>1)&3)
136 #define ZZIP_IS_STREAMED(p) (((*(unsigned char*)p)>>3)&1)
139 #define ZZIP_IS_STORED 0
140 #define ZZIP_IS_SHRUNK 1
141 #define ZZIP_IS_REDUCEDx1 2
142 #define ZZIP_IS_REDUCEDx2 3
143 #define ZZIP_IS_REDUCEDx3 4
144 #define ZZIP_IS_REDUCEDx4 5
145 #define ZZIP_IS_IMPLODED 6
146 #define ZZIP_IS_TOKENIZED 7
147 #define ZZIP_IS_DEFLATED 8
148 #define ZZIP_IS_DEFLATED_BETTER 9
149 #define ZZIP_IS_IMPLODED_BETTER 10
155 #endif /* _ZZIPFORMAT_H */