pharzip.h 11 KB

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