1 /* 2 +----------------------------------------------------------------------+ 3 | phar php single-file executable PHP extension | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 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 | https://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 /* See https://libzip.org/specifications/extrafld.txt */ 150 typedef struct _phar_zip_unix_time { 151 phar_zip_extra_field_header header; 152 char flags; /* flags 1 byte */ 153 char time[4]; /* time in standard Unix format 4 bytes */ 154 } phar_zip_unix_time; 155 156 typedef struct _phar_zip_central_dir_file { 157 char signature[4]; /* central file header signature 4 bytes (0x02014b50) */ 158 char madeby[2]; /* version made by 2 bytes */ 159 char zipversion[2]; /* version needed to extract 2 bytes */ 160 char flags[2]; /* general purpose bit flag 2 bytes */ 161 char compressed[2]; /* compression method 2 bytes */ 162 char timestamp[2]; /* last mod file time 2 bytes */ 163 char datestamp[2]; /* last mod file date 2 bytes */ 164 char crc32[4]; /* crc-32 4 bytes */ 165 char compsize[4]; /* compressed size 4 bytes */ 166 char uncompsize[4]; /* uncompressed size 4 bytes */ 167 char filename_len[2]; /* file name length 2 bytes */ 168 char extra_len[2]; /* extra field length 2 bytes */ 169 char comment_len[2]; /* file comment length 2 bytes */ 170 char disknumber[2]; /* disk number start 2 bytes */ 171 char internal_atts[2]; /* internal file attributes 2 bytes */ 172 char external_atts[4]; /* external file attributes 4 bytes */ 173 char offset[4]; /* relative offset of local header 4 bytes */ 174 175 /* file name (variable size) */ 176 /* extra field (variable size) */ 177 /* file comment (variable size) */ 178 } phar_zip_central_dir_file; 179 180 typedef struct _phar_zip_dir_signature { 181 char signature[4]; /* header signature 4 bytes (0x05054b50) */ 182 char size[2]; /* size of data 2 bytes */ 183 } phar_zip_dir_signature; 184 185 /* unused in this release */ 186 typedef struct _phar_zip64_dir_end { 187 char signature[4]; /* zip64 end of central dir 188 signature 4 bytes (0x06064b50) */ 189 char size1[4]; /* size of zip64 end of central 190 directory record 8 bytes */ 191 char size2[4]; 192 char madeby[2]; /* version made by 2 bytes */ 193 char extractneeded[2]; /* version needed to extract 2 bytes */ 194 char disknum[4]; /* number of this disk 4 bytes */ 195 char cdir_num[4]; /* number of the disk with the 196 start of the central directory 4 bytes */ 197 char entries1[4]; /* total number of entries in the 198 central directory on this disk 8 bytes */ 199 char entries2[4]; 200 char entriestotal1[4]; /* total number of entries in the 201 central directory 8 bytes */ 202 char entriestotal2[4]; 203 char cdirsize1[4]; /* size of the central directory 8 bytes */ 204 char cdirsize2[4]; 205 char offset1[4]; /* offset of start of central 206 directory with respect to 207 the starting disk number 8 bytes */ 208 char offset2[4]; 209 /* zip64 extensible data sector (variable size) */ 210 } phar_zip64_dir_end; 211 212 /* unused in this release */ 213 typedef struct _phar_zip64_dir_locator { 214 char signature[4]; /* zip64 end of central dir locator 215 signature 4 bytes (0x07064b50) */ 216 char disknum[4]; /* number of the disk with the 217 start of the zip64 end of 218 central directory 4 bytes */ 219 char diroffset1[4]; /* relative offset of the zip64 220 end of central directory record 8 bytes */ 221 char diroffset2[4]; 222 char totaldisks[4]; /* total number of disks 4 bytes */ 223 } phar_zip64_dir_locator; 224 225 typedef struct _phar_zip_dir_end { 226 char signature[4]; /* end of central dir signature 4 bytes (0x06054b50) */ 227 char disknumber[2]; /* number of this disk 2 bytes */ 228 char centraldisk[2]; /* number of the disk with the 229 start of the central directory 2 bytes */ 230 char counthere[2]; /* total number of entries in the 231 central directory on this disk 2 bytes */ 232 char count[2]; /* total number of entries in 233 the central directory 2 bytes */ 234 char cdir_size[4]; /* size of the central directory 4 bytes */ 235 char cdir_offset[4]; /* offset of start of central 236 directory with respect to 237 the starting disk number 4 bytes */ 238 char comment_len[2]; /* .ZIP file comment length 2 bytes */ 239 /* .ZIP file comment (variable size) */ 240 } phar_zip_dir_end; 241