summaryrefslogtreecommitdiff
path: root/ext/phar/pharzip.h
blob: 1e7d2a701532256f7c4b9b4a27ff587cf5291f4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
  +----------------------------------------------------------------------+
  | phar php single-file executable PHP extension                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 2006-2011 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.01 of the PHP license,      |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_01.txt.                                 |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors: Gregory Beaver <cellog@php.net>                             |
  |          Marcus Boerger <helly@php.net>                              |
  +----------------------------------------------------------------------+
*/

/* $Id$ */

typedef struct _phar_zip_file_header {
	char signature[4];       /* local file header signature     4 bytes  (0x04034b50) */
	char zipversion[2];      /* version needed to extract       2 bytes */
	char flags[2];        /* general purpose bit flag        2 bytes */
	char compressed[2];   /* compression method              2 bytes */
	char timestamp[2];    /* last mod file time              2 bytes */
	char datestamp[2];    /* last mod file date              2 bytes */
	char crc32[4];        /* crc-32                          4 bytes */
	char compsize[4];     /* compressed size                 4 bytes */
	char uncompsize[4];   /* uncompressed size               4 bytes */
	char filename_len[2]; /* file name length                2 bytes */
	char extra_len[2];    /* extra field length              2 bytes */
/* file name (variable size) */
/* extra field (variable size) */
} phar_zip_file_header;

/* unused in this release */
typedef struct _phar_zip_file_datadesc {
	char signature[4];  /* signature (optional)            4 bytes */
	char crc32[4];      /* crc-32                          4 bytes */
	char compsize[4];   /* compressed size                 4 bytes */
	char uncompsize[4]; /* uncompressed size               4 bytes */
} phar_zip_data_desc;

/* unused in this release */
typedef struct _phar_zip_file_datadesc_zip64 {
	char crc32[4];       /* crc-32                          4 bytes */
	char compsize[4];    /* compressed size                 8 bytes */
	char compsize2[4];
	char uncompsize[4];  /* uncompressed size               8 bytes */
	char uncompsize2[4];
} phar_zip_data_desc_zip64;

typedef struct _phar_zip_archive_extra_data_record {
	char signature[4];   /* archive extra data signature    4 bytes  (0x08064b50) */
	char len[4];      /* extra field length              4 bytes */
/* extra field data                (variable size) */
} phar_zip_archive_extra_data_record;

/* madeby/extractneeded value if bzip2 compression is used */
#define PHAR_ZIP_BZIP2 "46"
/* madeby/extractneeded value for other cases */
#define PHAR_ZIP_NORM  "20"

#define PHAR_ZIP_FLAG_ENCRYPTED 0x0001
/* data descriptor present for this file */
#define PHAR_ZIP_FLAG_DATADESC  0x0008
#define PHAR_ZIP_FLAG_UTF8      0x0400

/*
0 - The file is stored (no compression)
1 - The file is Shrunk
2 - The file is Reduced with compression factor 1
3 - The file is Reduced with compression factor 2
4 - The file is Reduced with compression factor 3
5 - The file is Reduced with compression factor 4
6 - The file is Imploded
7 - Reserved for Tokenizing compression algorithm
8 - The file is Deflated
9 - Enhanced Deflating using Deflate64(tm)
10 - PKWARE Data Compression Library Imploding (old IBM TERSE)
11 - Reserved by PKWARE
12 - File is compressed using BZIP2 algorithm
13 - Reserved by PKWARE
14 - LZMA (EFS)
15 - Reserved by PKWARE
16 - Reserved by PKWARE
17 - Reserved by PKWARE
18 - File is compressed using IBM TERSE (new)
19 - IBM LZ77 z Architecture (PFS)
97 - WavPack compressed data
98 - PPMd version I, Rev 1
*/
#define PHAR_ZIP_COMP_NONE    0
#define PHAR_ZIP_COMP_DEFLATE 8
#define PHAR_ZIP_COMP_BZIP2   12

/*
         -ASi Unix Extra Field:
          ====================

          The following is the layout of the ASi extra block for Unix.  The
          local-header and central-header versions are identical.
          (Last Revision 19960916)

          Value         Size        Description
          -----         ----        -----------
  (Unix3) 0x756e        Short       tag for this extra block type ("nu")
          TSize         Short       total data size for this block
          CRC           Long        CRC-32 of the remaining data
          Mode          Short       file permissions
          SizDev        Long        symlink'd size OR major/minor dev num
          UID           Short       user ID
          GID           Short       group ID
          (var.)        variable    symbolic link filename

          Mode is the standard Unix st_mode field from struct stat, containing
          user/group/other permissions, setuid/setgid and symlink info, etc.

          If Mode indicates that this file is a symbolic link, SizDev is the
          size of the file to which the link points.  Otherwise, if the file
          is a device, SizDev contains the standard Unix st_rdev field from
          struct stat (includes the major and minor numbers of the device).
          SizDev is undefined in other cases.

          If Mode indicates that the file is a symbolic link, the final field
          will be the name of the file to which the link points.  The file-
          name length can be inferred from TSize.

          [Note that TSize may incorrectly refer to the data size not counting
           the CRC; i.e., it may be four bytes too small.]
*/

typedef struct _phar_zip_extra_field_header {
	char tag[2];
	char size[2];
} phar_zip_extra_field_header;

typedef struct _phar_zip_unix3 {
	char tag[2];            /* 0x756e        Short       tag for this extra block type ("nu") */
	char size[2];        /* TSize         Short       total data size for this block */
	char crc32[4];       /* CRC           Long        CRC-32 of the remaining data */
	char perms[2];       /* Mode          Short       file permissions */
	char symlinksize[4]; /* SizDev        Long        symlink'd size OR major/minor dev num */
	char uid[2];         /* UID           Short       user ID */
	char gid[2];         /* GID           Short       group ID */
/* (var.)        variable    symbolic link filename */
} phar_zip_unix3;

typedef struct _phar_zip_central_dir_file {
	char signature[4];            /* central file header signature   4 bytes  (0x02014b50) */
	char madeby[2];               /* version made by                 2 bytes */
	char zipversion[2];           /* version needed to extract       2 bytes */
	char flags[2];             /* general purpose bit flag        2 bytes */
	char compressed[2];        /* compression method              2 bytes */
	char timestamp[2];         /* last mod file time              2 bytes */
	char datestamp[2];         /* last mod file date              2 bytes */
	char crc32[4];             /* crc-32                          4 bytes */
	char compsize[4];          /* compressed size                 4 bytes */
	char uncompsize[4];        /* uncompressed size               4 bytes */
	char filename_len[2];      /* file name length                2 bytes */
	char extra_len[2];         /* extra field length              2 bytes */
	char comment_len[2];       /* file comment length             2 bytes */
	char disknumber[2];        /* disk number start               2 bytes */
	char internal_atts[2];     /* internal file attributes        2 bytes */
	char external_atts[4];     /* external file attributes        4 bytes */
	char offset[4];            /* relative offset of local header 4 bytes */

/* file name (variable size) */
/* extra field (variable size) */
/* file comment (variable size) */
} phar_zip_central_dir_file;

typedef struct _phar_zip_dir_signature {
	char signature[4];  /* header signature                4 bytes  (0x05054b50) */
	char size[2];    /* size of data                    2 bytes */
} phar_zip_dir_signature;

/* unused in this release */
typedef struct _phar_zip64_dir_end {
	char signature[4];        /* zip64 end of central dir 
                                 signature                       4 bytes  (0x06064b50) */
	char size1[4];         /* size of zip64 end of central
                                 directory record                8 bytes */
	char size2[4];
	char madeby[2];           /* version made by                 2 bytes */
	char extractneeded[2]; /* version needed to extract       2 bytes */
	char disknum[4];       /* number of this disk             4 bytes */
	char cdir_num[4];      /* number of the disk with the 
                                 start of the central directory  4 bytes */
	char entries1[4];      /* total number of entries in the
                                 central directory on this disk  8 bytes */
	char entries2[4];
	char entriestotal1[4]; /* total number of entries in the
                                 central directory               8 bytes */
	char entriestotal2[4];
	char cdirsize1[4];     /* size of the central directory   8 bytes */
	char cdirsize2[4];
	char offset1[4];       /* offset of start of central
                                 directory with respect to
                                 the starting disk number        8 bytes */
	char offset2[4];
/* zip64 extensible data sector    (variable size) */
} phar_zip64_dir_end;

/* unused in this release */
typedef struct _phar_zip64_dir_locator {
	char signature[4];     /* zip64 end of central dir locator 
                              signature                       4 bytes  (0x07064b50) */
	char disknum[4];    /* number of the disk with the
                              start of the zip64 end of 
                              central directory               4 bytes */
	char diroffset1[4]; /* relative offset of the zip64
                              end of central directory record 8 bytes */
	char diroffset2[4];
	char totaldisks[4]; /* total number of disks           4 bytes */
} phar_zip64_dir_locator;

typedef struct _phar_zip_dir_end {
	char signature[4];           /* end of central dir signature    4 bytes  (0x06054b50) */
	char disknumber[2];       /* number of this disk             2 bytes */
	char centraldisk[2];      /* number of the disk with the
                                    start of the central directory  2 bytes */
	char counthere[2];        /* total number of entries in the
                                    central directory on this disk  2 bytes */
	char count[2];            /* total number of entries in
                                    the central directory           2 bytes */
	char cdir_size[4];        /* size of the central directory   4 bytes */
	char cdir_offset[4];      /* offset of start of central
                                    directory with respect to
                                    the starting disk number        4 bytes */
	char comment_len[2];      /* .ZIP file comment length        2 bytes */
/* .ZIP file comment       (variable size) */
} phar_zip_dir_end;
/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */