xref: /PHP-7.3/ext/phar/pharzip.h (revision 8d3f8ca1)
1 /*
2   +----------------------------------------------------------------------+
3   | phar php single-file executable PHP extension                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 2006-2018 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt.                                 |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: Gregory Beaver <cellog@php.net>                             |
16   |          Marcus Boerger <helly@php.net>                              |
17   +----------------------------------------------------------------------+
18 */
19 
20 typedef struct _phar_zip_file_header {
21 	char signature[4];       /* local file header signature     4 bytes  (0x04034b50) */
22 	char zipversion[2];      /* version needed to extract       2 bytes */
23 	char flags[2];        /* general purpose bit flag        2 bytes */
24 	char compressed[2];   /* compression method              2 bytes */
25 	char timestamp[2];    /* last mod file time              2 bytes */
26 	char datestamp[2];    /* last mod file date              2 bytes */
27 	char crc32[4];        /* crc-32                          4 bytes */
28 	char compsize[4];     /* compressed size                 4 bytes */
29 	char uncompsize[4];   /* uncompressed size               4 bytes */
30 	char filename_len[2]; /* file name length                2 bytes */
31 	char extra_len[2];    /* extra field length              2 bytes */
32 /* file name (variable size) */
33 /* extra field (variable size) */
34 } phar_zip_file_header;
35 
36 /* unused in this release */
37 typedef struct _phar_zip_file_datadesc {
38 	char signature[4];  /* signature (optional)            4 bytes */
39 	char crc32[4];      /* crc-32                          4 bytes */
40 	char compsize[4];   /* compressed size                 4 bytes */
41 	char uncompsize[4]; /* uncompressed size               4 bytes */
42 } phar_zip_data_desc;
43 
44 /* unused in this release */
45 typedef struct _phar_zip_file_datadesc_zip64 {
46 	char crc32[4];       /* crc-32                          4 bytes */
47 	char compsize[4];    /* compressed size                 8 bytes */
48 	char compsize2[4];
49 	char uncompsize[4];  /* uncompressed size               8 bytes */
50 	char uncompsize2[4];
51 } phar_zip_data_desc_zip64;
52 
53 typedef struct _phar_zip_archive_extra_data_record {
54 	char signature[4];   /* archive extra data signature    4 bytes  (0x08064b50) */
55 	char len[4];      /* extra field length              4 bytes */
56 /* extra field data                (variable size) */
57 } phar_zip_archive_extra_data_record;
58 
59 /* madeby/extractneeded value if bzip2 compression is used */
60 #define PHAR_ZIP_BZIP2 "46"
61 /* madeby/extractneeded value for other cases */
62 #define PHAR_ZIP_NORM  "20"
63 
64 #define PHAR_ZIP_FLAG_ENCRYPTED 0x0001
65 /* data descriptor present for this file */
66 #define PHAR_ZIP_FLAG_DATADESC  0x0008
67 #define PHAR_ZIP_FLAG_UTF8      0x0400
68 
69 /*
70 0 - The file is stored (no compression)
71 1 - The file is Shrunk
72 2 - The file is Reduced with compression factor 1
73 3 - The file is Reduced with compression factor 2
74 4 - The file is Reduced with compression factor 3
75 5 - The file is Reduced with compression factor 4
76 6 - The file is Imploded
77 7 - Reserved for Tokenizing compression algorithm
78 8 - The file is Deflated
79 9 - Enhanced Deflating using Deflate64(tm)
80 10 - PKWARE Data Compression Library Imploding (old IBM TERSE)
81 11 - Reserved by PKWARE
82 12 - File is compressed using BZIP2 algorithm
83 13 - Reserved by PKWARE
84 14 - LZMA (EFS)
85 15 - Reserved by PKWARE
86 16 - Reserved by PKWARE
87 17 - Reserved by PKWARE
88 18 - File is compressed using IBM TERSE (new)
89 19 - IBM LZ77 z Architecture (PFS)
90 97 - WavPack compressed data
91 98 - PPMd version I, Rev 1
92 */
93 #define PHAR_ZIP_COMP_NONE    0
94 #define PHAR_ZIP_COMP_DEFLATE 8
95 #define PHAR_ZIP_COMP_BZIP2   12
96 
97 /*
98          -ASi Unix Extra Field:
99           ====================
100 
101           The following is the layout of the ASi extra block for Unix.  The
102           local-header and central-header versions are identical.
103           (Last Revision 19960916)
104 
105           Value         Size        Description
106           -----         ----        -----------
107   (Unix3) 0x756e        Short       tag for this extra block type ("nu")
108           TSize         Short       total data size for this block
109           CRC           Long        CRC-32 of the remaining data
110           Mode          Short       file permissions
111           SizDev        Long        symlink'd size OR major/minor dev num
112           UID           Short       user ID
113           GID           Short       group ID
114           (var.)        variable    symbolic link filename
115 
116           Mode is the standard Unix st_mode field from struct stat, containing
117           user/group/other permissions, setuid/setgid and symlink info, etc.
118 
119           If Mode indicates that this file is a symbolic link, SizDev is the
120           size of the file to which the link points.  Otherwise, if the file
121           is a device, SizDev contains the standard Unix st_rdev field from
122           struct stat (includes the major and minor numbers of the device).
123           SizDev is undefined in other cases.
124 
125           If Mode indicates that the file is a symbolic link, the final field
126           will be the name of the file to which the link points.  The file-
127           name length can be inferred from TSize.
128 
129           [Note that TSize may incorrectly refer to the data size not counting
130            the CRC; i.e., it may be four bytes too small.]
131 */
132 
133 typedef struct _phar_zip_extra_field_header {
134 	char tag[2];
135 	char size[2];
136 } phar_zip_extra_field_header;
137 
138 typedef struct _phar_zip_unix3 {
139 	char tag[2];            /* 0x756e        Short       tag for this extra block type ("nu") */
140 	char size[2];        /* TSize         Short       total data size for this block */
141 	char crc32[4];       /* CRC           Long        CRC-32 of the remaining data */
142 	char perms[2];       /* Mode          Short       file permissions */
143 	char symlinksize[4]; /* SizDev        Long        symlink'd size OR major/minor dev num */
144 	char uid[2];         /* UID           Short       user ID */
145 	char gid[2];         /* GID           Short       group ID */
146 /* (var.)        variable    symbolic link filename */
147 } phar_zip_unix3;
148 
149 typedef struct _phar_zip_central_dir_file {
150 	char signature[4];            /* central file header signature   4 bytes  (0x02014b50) */
151 	char madeby[2];               /* version made by                 2 bytes */
152 	char zipversion[2];           /* version needed to extract       2 bytes */
153 	char flags[2];             /* general purpose bit flag        2 bytes */
154 	char compressed[2];        /* compression method              2 bytes */
155 	char timestamp[2];         /* last mod file time              2 bytes */
156 	char datestamp[2];         /* last mod file date              2 bytes */
157 	char crc32[4];             /* crc-32                          4 bytes */
158 	char compsize[4];          /* compressed size                 4 bytes */
159 	char uncompsize[4];        /* uncompressed size               4 bytes */
160 	char filename_len[2];      /* file name length                2 bytes */
161 	char extra_len[2];         /* extra field length              2 bytes */
162 	char comment_len[2];       /* file comment length             2 bytes */
163 	char disknumber[2];        /* disk number start               2 bytes */
164 	char internal_atts[2];     /* internal file attributes        2 bytes */
165 	char external_atts[4];     /* external file attributes        4 bytes */
166 	char offset[4];            /* relative offset of local header 4 bytes */
167 
168 /* file name (variable size) */
169 /* extra field (variable size) */
170 /* file comment (variable size) */
171 } phar_zip_central_dir_file;
172 
173 typedef struct _phar_zip_dir_signature {
174 	char signature[4];  /* header signature                4 bytes  (0x05054b50) */
175 	char size[2];    /* size of data                    2 bytes */
176 } phar_zip_dir_signature;
177 
178 /* unused in this release */
179 typedef struct _phar_zip64_dir_end {
180 	char signature[4];        /* zip64 end of central dir
181                                  signature                       4 bytes  (0x06064b50) */
182 	char size1[4];         /* size of zip64 end of central
183                                  directory record                8 bytes */
184 	char size2[4];
185 	char madeby[2];           /* version made by                 2 bytes */
186 	char extractneeded[2]; /* version needed to extract       2 bytes */
187 	char disknum[4];       /* number of this disk             4 bytes */
188 	char cdir_num[4];      /* number of the disk with the
189                                  start of the central directory  4 bytes */
190 	char entries1[4];      /* total number of entries in the
191                                  central directory on this disk  8 bytes */
192 	char entries2[4];
193 	char entriestotal1[4]; /* total number of entries in the
194                                  central directory               8 bytes */
195 	char entriestotal2[4];
196 	char cdirsize1[4];     /* size of the central directory   8 bytes */
197 	char cdirsize2[4];
198 	char offset1[4];       /* offset of start of central
199                                  directory with respect to
200                                  the starting disk number        8 bytes */
201 	char offset2[4];
202 /* zip64 extensible data sector    (variable size) */
203 } phar_zip64_dir_end;
204 
205 /* unused in this release */
206 typedef struct _phar_zip64_dir_locator {
207 	char signature[4];     /* zip64 end of central dir locator
208                               signature                       4 bytes  (0x07064b50) */
209 	char disknum[4];    /* number of the disk with the
210                               start of the zip64 end of
211                               central directory               4 bytes */
212 	char diroffset1[4]; /* relative offset of the zip64
213                               end of central directory record 8 bytes */
214 	char diroffset2[4];
215 	char totaldisks[4]; /* total number of disks           4 bytes */
216 } phar_zip64_dir_locator;
217 
218 typedef struct _phar_zip_dir_end {
219 	char signature[4];           /* end of central dir signature    4 bytes  (0x06054b50) */
220 	char disknumber[2];       /* number of this disk             2 bytes */
221 	char centraldisk[2];      /* number of the disk with the
222                                     start of the central directory  2 bytes */
223 	char counthere[2];        /* total number of entries in the
224                                     central directory on this disk  2 bytes */
225 	char count[2];            /* total number of entries in
226                                     the central directory           2 bytes */
227 	char cdir_size[4];        /* size of the central directory   4 bytes */
228 	char cdir_offset[4];      /* offset of start of central
229                                     directory with respect to
230                                     the starting disk number        4 bytes */
231 	char comment_len[2];      /* .ZIP file comment length        2 bytes */
232 /* .ZIP file comment       (variable size) */
233 } phar_zip_dir_end;
234 /*
235  * Local variables:
236  * tab-width: 4
237  * c-basic-offset: 4
238  * End:
239  * vim600: noet sw=4 ts=4 fdm=marker
240  * vim<600: noet sw=4 ts=4
241  */
242