pharzip.h 11 KB

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