zip 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #------------------------------------------------------------------------------
  2. # $File: zip,v 1.8 2021/10/24 15:53:56 christos Exp $
  3. # zip: file(1) magic for zip files; this is not use
  4. # Note the version of magic in archive is currently stronger, this is
  5. # just an example until negative offsets are supported better
  6. # Note: All fields unless otherwise noted are unsigned!
  7. # Zip Central Directory record
  8. 0 name zipcd
  9. >0 string PK\001\002 Zip archive data
  10. !:mime application/zip
  11. # no "made by" in local file header with PK\3\4 magic
  12. >>4 leshort x \b, made by
  13. >>4 use zipversion
  14. >>4 use ziphost
  15. # inside ./archive 1.151 called "at least" zipversion "to extract"
  16. >>6 leshort x \b, extract using at least
  17. >>6 use zipversion
  18. # This is DOS date like: ledate 21:00:48 19 Dec 2001 != DOS 00:00 1 Jan 2010 ~ 0000213C
  19. >>12 ulelong x \b, last modified
  20. >>14 lemsdosdate x \b, last modified %s
  21. >>12 lemsdostime x %s
  22. # uncompressed size of 1st entry; FFffFFff means real value stored in ZIP64 record
  23. >>24 ulelong !0xFFffFFff \b, uncompressed size %u
  24. # inside ./archive 1.151 called "compression method="zipcompression
  25. >>10 leshort x \b, method=
  26. >>10 use zipcompression
  27. # URL: https://en.wikipedia.org/wiki/Zip_(file_format)
  28. # reference: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT (Version: 6.3.9)
  29. # Zip known compressions
  30. 0 name zipcompression
  31. >0 leshort 0 \bstore
  32. >0 leshort 1 \bShrinking
  33. >0 leshort 6 \bImploding
  34. >0 leshort 7 \bTokenizing
  35. >0 leshort 8 \bdeflate
  36. >0 leshort 9 \bdeflate64
  37. >0 leshort 10 \bLibrary imploding
  38. #>0 leshort 11 \bReserved by PKWARE
  39. >0 leshort 12 \bbzip2
  40. #>0 leshort 13 \bReserved by PKWARE
  41. >0 leshort 14 \blzma
  42. #>0 leshort 15 \bReserved by PKWARE
  43. >0 leshort 16 \bCMPSC (IBM z/OS)
  44. #>0 leshort 17 \bReserved by PKWARE
  45. >0 leshort 18 \bIBM TERSE
  46. >0 leshort 19 \bIBM LZ77 (z/Architecture)
  47. >0 leshort 20 \bZstd (deprecated)
  48. >0 leshort 93 \bZstd
  49. >0 leshort 94 \bMP3
  50. >0 leshort 95 \bxz
  51. >0 leshort 96 \bJpeg
  52. >0 leshort 97 \bWavPack
  53. >0 leshort 98 \bPPMd
  54. >0 leshort 99 \bAES Encrypted
  55. >0 default x
  56. >>0 leshort x \b[%#x]
  57. # Zip known versions
  58. 0 name zipversion
  59. # The lower byte indicates the ZIP version of this file. The value/10 indicates
  60. # the major version number, and the value mod 10 is the minor version number.
  61. >0 ubyte/10 x v%u
  62. >0 ubyte%10 x \b.%u
  63. # >0 leshort 0x09 v0.9
  64. # >0 leshort 0x0a v1.0
  65. # >0 leshort 0x0b v1.1
  66. # >0 leshort 0x14 v2.0
  67. # >0 leshort 0x15 v2.1
  68. # >0 leshort 0x19 v2.5
  69. # >0 leshort 0x1b v2.7
  70. # >0 leshort 0x2d v4.5
  71. # >0 leshort 0x2e v4.6
  72. # >0 leshort 0x32 v5.0
  73. # >0 leshort 0x33 v5.1
  74. # >0 leshort 0x34 v5.2
  75. # >0 leshort 0x3d v6.1
  76. # >0 leshort 0x3e v6.2
  77. # >0 leshort 0x3f v6.3
  78. # >0 default x
  79. # >>0 leshort x v?[%#x]
  80. # display compatible host system name of ZIP archive
  81. 0 name ziphost
  82. # The upper byte indicates the compatibility of the file attribute information.
  83. # If the file is compatible with MS-DOS (v 2.04g) then this value will be zero.
  84. #>1 ubyte 0 DOS
  85. >1 ubyte 1 Amiga
  86. >1 ubyte 2 OpenVMS
  87. >1 ubyte 3 UNIX
  88. >1 ubyte 4 VM/CMS
  89. >1 ubyte 6 OS/2
  90. >1 ubyte 7 Macintosh
  91. >1 ubyte 11 MVS
  92. >1 ubyte 13 Acorn Risc
  93. >1 ubyte 16 BeOS
  94. >1 ubyte 17 Tandem
  95. # 9 untested
  96. >1 ubyte 5 Atari ST
  97. >1 ubyte 8 Z-System
  98. >1 ubyte 9 CP/M
  99. >1 ubyte 10 Windows NTFS
  100. >1 ubyte 12 VSE
  101. >1 ubyte 14 VFAT
  102. >1 ubyte 15 alternate MVS
  103. >1 ubyte 18 OS/400
  104. >1 ubyte 19 OS X
  105. # unused
  106. #>1 ubyte >19 unused %#x
  107. # Zip End Of Central Directory record
  108. # GRR: wrong for ZIP with comment archive
  109. -22 string PK\005\006
  110. #>4 uleshort !0xFFff \b, %u disks
  111. #>6 uleshort !0xFFff \b, central directory disk %u
  112. #>8 uleshort !0xFFff \b, %u central directories on this disk
  113. #>10 uleshort !0xFFff \b, %u central directories
  114. #>12 ulelong !0xFFffFFff \b, %u central directory bytes
  115. # offset of central directory
  116. #>16 ulelong x \b, central directory offset %#x
  117. >(16.l) use zipcd
  118. # archive comment length n
  119. #>>20 uleshort >0 \b, comment length %u
  120. # archive comment
  121. >>20 pstring/l >0 \b, %s