compress 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #------------------------------------------------------------------------------
  2. # $File: compress,v 1.73 2018/09/01 13:52:39 christos Exp $
  3. # compress: file(1) magic for pure-compression formats (no archives)
  4. #
  5. # compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc.
  6. #
  7. # Formats for various forms of compressed data
  8. # Formats for "compress" proper have been moved into "compress.c",
  9. # because it tries to uncompress it to figure out what's inside.
  10. # standard unix compress
  11. 0 string \037\235 compress'd data
  12. !:mime application/x-compress
  13. !:apple LZIVZIVU
  14. >2 byte&0x80 >0 block compressed
  15. >2 byte&0x1f x %d bits
  16. # gzip (GNU zip, not to be confused with Info-ZIP or PKWARE zip archiver)
  17. # Edited by Chris Chittleborough <cchittleborough@yahoo.com.au>, March 2002
  18. # * Original filename is only at offset 10 if "extra field" absent
  19. # * Produce shorter output - notably, only report compression methods
  20. # other than 8 ("deflate", the only method defined in RFC 1952).
  21. 0 string \037\213 gzip compressed data
  22. !:mime application/x-gzip
  23. !:strength * 2
  24. >2 byte <8 \b, reserved method
  25. >2 byte >8 \b, unknown method
  26. >3 byte &0x01 \b, ASCII
  27. >3 byte &0x02 \b, has CRC
  28. >3 byte &0x04 \b, extra field
  29. >3 byte&0xC =0x08
  30. >>10 string x \b, was "%s"
  31. >3 byte &0x10 \b, has comment
  32. >3 byte &0x20 \b, encrypted
  33. >4 ledate >0 \b, last modified: %s
  34. >8 byte 2 \b, max compression
  35. >8 byte 4 \b, max speed
  36. >9 byte =0x00 \b, from FAT filesystem (MS-DOS, OS/2, NT)
  37. >9 byte =0x01 \b, from Amiga
  38. >9 byte =0x02 \b, from VMS
  39. >9 byte =0x03 \b, from Unix
  40. >9 byte =0x04 \b, from VM/CMS
  41. >9 byte =0x05 \b, from Atari
  42. >9 byte =0x06 \b, from HPFS filesystem (OS/2, NT)
  43. >9 byte =0x07 \b, from MacOS
  44. >9 byte =0x08 \b, from Z-System
  45. >9 byte =0x09 \b, from CP/M
  46. >9 byte =0x0A \b, from TOPS/20
  47. >9 byte =0x0B \b, from NTFS filesystem (NT)
  48. >9 byte =0x0C \b, from QDOS
  49. >9 byte =0x0D \b, from Acorn RISCOS
  50. >-4 lelong x \b, original size %u
  51. # packed data, Huffman (minimum redundancy) codes on a byte-by-byte basis
  52. 0 string \037\036 packed data
  53. !:mime application/octet-stream
  54. >2 belong >1 \b, %d characters originally
  55. >2 belong =1 \b, %d character originally
  56. #
  57. # This magic number is byte-order-independent.
  58. 0 short 0x1f1f old packed data
  59. !:mime application/octet-stream
  60. # XXX - why *two* entries for "compacted data", one of which is
  61. # byte-order independent, and one of which is byte-order dependent?
  62. #
  63. 0 short 0x1fff compacted data
  64. !:mime application/octet-stream
  65. # This string is valid for SunOS (BE) and a matching "short" is listed
  66. # in the Ultrix (LE) magic file.
  67. 0 string \377\037 compacted data
  68. !:mime application/octet-stream
  69. 0 short 0145405 huf output
  70. !:mime application/octet-stream
  71. # bzip2
  72. 0 string BZh bzip2 compressed data
  73. !:mime application/x-bzip2
  74. >3 byte >47 \b, block size = %c00k
  75. # bzip a block-sorting file compressor
  76. # by Julian Seward <sewardj@cs.man.ac.uk> and others
  77. 0 string BZ0 bzip compressed data
  78. !:mime application/x-bzip
  79. >3 byte >47 \b, block size = %c00k
  80. # lzip
  81. 0 string LZIP lzip compressed data
  82. !:mime application/x-lzip
  83. >4 byte x \b, version: %d
  84. # squeeze and crunch
  85. # Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
  86. 0 beshort 0x76FF squeezed data,
  87. >4 string x original name %s
  88. 0 beshort 0x76FE crunched data,
  89. >2 string x original name %s
  90. 0 beshort 0x76FD LZH compressed data,
  91. >2 string x original name %s
  92. # Freeze
  93. 0 string \037\237 frozen file 2.1
  94. 0 string \037\236 frozen file 1.0 (or gzip 0.5)
  95. # SCO compress -H (LZH)
  96. 0 string \037\240 SCO compress -H (LZH) data
  97. # European GSM 06.10 is a provisional standard for full-rate speech
  98. # transcoding, prI-ETS 300 036, which uses RPE/LTP (residual pulse
  99. # excitation/long term prediction) coding at 13 kbit/s.
  100. #
  101. # There's only a magic nibble (4 bits); that nibble repeats every 33
  102. # bytes. This isn't suited for use, but maybe we can use it someday.
  103. #
  104. # This will cause very short GSM files to be declared as data and
  105. # mismatches to be declared as data too!
  106. #0 byte&0xF0 0xd0 data
  107. #>33 byte&0xF0 0xd0
  108. #>66 byte&0xF0 0xd0
  109. #>99 byte&0xF0 0xd0
  110. #>132 byte&0xF0 0xd0 GSM 06.10 compressed audio
  111. # lzop from <markus.oberhumer@jk.uni-linz.ac.at>
  112. 0 string \x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a lzop compressed data
  113. >9 beshort <0x0940
  114. >>9 byte&0xf0 =0x00 - version 0.
  115. >>9 beshort&0x0fff x \b%03x,
  116. >>13 byte 1 LZO1X-1,
  117. >>13 byte 2 LZO1X-1(15),
  118. >>13 byte 3 LZO1X-999,
  119. ## >>22 bedate >0 last modified: %s,
  120. >>14 byte =0x00 os: MS-DOS
  121. >>14 byte =0x01 os: Amiga
  122. >>14 byte =0x02 os: VMS
  123. >>14 byte =0x03 os: Unix
  124. >>14 byte =0x05 os: Atari
  125. >>14 byte =0x06 os: OS/2
  126. >>14 byte =0x07 os: MacOS
  127. >>14 byte =0x0A os: Tops/20
  128. >>14 byte =0x0B os: WinNT
  129. >>14 byte =0x0E os: Win32
  130. >9 beshort >0x0939
  131. >>9 byte&0xf0 =0x00 - version 0.
  132. >>9 byte&0xf0 =0x10 - version 1.
  133. >>9 byte&0xf0 =0x20 - version 2.
  134. >>9 beshort&0x0fff x \b%03x,
  135. >>15 byte 1 LZO1X-1,
  136. >>15 byte 2 LZO1X-1(15),
  137. >>15 byte 3 LZO1X-999,
  138. ## >>25 bedate >0 last modified: %s,
  139. >>17 byte =0x00 os: MS-DOS
  140. >>17 byte =0x01 os: Amiga
  141. >>17 byte =0x02 os: VMS
  142. >>17 byte =0x03 os: Unix
  143. >>17 byte =0x05 os: Atari
  144. >>17 byte =0x06 os: OS/2
  145. >>17 byte =0x07 os: MacOS
  146. >>17 byte =0x0A os: Tops/20
  147. >>17 byte =0x0B os: WinNT
  148. >>17 byte =0x0E os: Win32
  149. # 4.3BSD-Quasijarus Strong Compression
  150. # http://minnie.tuhs.org/Quasijarus/compress.html
  151. 0 string \037\241 Quasijarus strong compressed data
  152. # From: Cory Dikkers <cdikkers@swbell.net>
  153. 0 string XPKF Amiga xpkf.library compressed data
  154. 0 string PP11 Power Packer 1.1 compressed data
  155. 0 string PP20 Power Packer 2.0 compressed data,
  156. >4 belong 0x09090909 fast compression
  157. >4 belong 0x090A0A0A mediocre compression
  158. >4 belong 0x090A0B0B good compression
  159. >4 belong 0x090A0C0C very good compression
  160. >4 belong 0x090A0C0D best compression
  161. # 7-zip archiver, from Thomas Klausner (wiz@danbala.tuwien.ac.at)
  162. # http://www.7-zip.org or DOC/7zFormat.txt
  163. #
  164. 0 string 7z\274\257\047\034 7-zip archive data,
  165. >6 byte x version %d
  166. >7 byte x \b.%d
  167. !:mime application/x-7z-compressed
  168. !:ext 7z/cb7
  169. # Type: LZMA
  170. 0 lelong&0xffffff =0x5d
  171. >12 leshort 0xff LZMA compressed data,
  172. !:mime application/x-lzma
  173. >>5 lequad =0xffffffffffffffff streamed
  174. >>5 lequad !0xffffffffffffffff non-streamed, size %lld
  175. >12 leshort 0 LZMA compressed data,
  176. >>5 lequad =0xffffffffffffffff streamed
  177. >>5 lequad !0xffffffffffffffff non-streamed, size %lld
  178. # http://tukaani.org/xz/xz-file-format.txt
  179. 0 ustring \xFD7zXZ\x00 XZ compressed data
  180. !:strength * 2
  181. !:mime application/x-xz
  182. # https://github.com/ckolivas/lrzip/blob/master/doc/magic.header.txt
  183. 0 string LRZI LRZIP compressed data
  184. >4 byte x - version %d
  185. >5 byte x \b.%d
  186. !:mime application/x-lrzip
  187. # http://fastcompression.blogspot.fi/2013/04/lz4-streaming-format-final.html
  188. 0 lelong 0x184d2204 LZ4 compressed data (v1.4+)
  189. !:mime application/x-lz4
  190. # Added by osm0sis@xda-developers.com
  191. 0 lelong 0x184c2103 LZ4 compressed data (v1.0-v1.3)
  192. !:mime application/x-lz4
  193. 0 lelong 0x184c2102 LZ4 compressed data (v0.1-v0.9)
  194. !:mime application/x-lz4
  195. # Zstandard/LZ4 skippable frames
  196. # https://github.com/facebook/zstd/blob/dev/zstd_compression_format.md
  197. 0 lelong&0xFFFFFFF0 0x184D2A50
  198. >(4.l+8) indirect x
  199. # Zstandard Dictionary ID subroutine
  200. 0 name zstd-dictionary-id
  201. # Single Segment = True
  202. >0 byte &0x20 \b, Dictionary ID:
  203. >>0 byte&0x03 0 None
  204. >>0 byte&0x03 1
  205. >>>1 byte x %u
  206. >>0 byte&0x03 2
  207. >>>1 leshort x %u
  208. >>0 byte&0x03 3
  209. >>>1 lelong x %u
  210. # Single Segment = False
  211. >0 byte ^0x20 \b, Dictionary ID:
  212. >>0 byte&0x03 0 None
  213. >>0 byte&0x03 1
  214. >>>2 byte x %u
  215. >>0 byte&0x03 2
  216. >>>2 leshort x %u
  217. >>0 byte&0x03 3
  218. >>>2 lelong x %u
  219. # Zstandard compressed data
  220. # https://github.com/facebook/zstd/blob/dev/zstd_compression_format.md
  221. 0 lelong 0xFD2FB522 Zstandard compressed data (v0.2)
  222. !:mime application/x-zstd
  223. 0 lelong 0xFD2FB523 Zstandard compressed data (v0.3)
  224. !:mime application/x-zstd
  225. 0 lelong 0xFD2FB524 Zstandard compressed data (v0.4)
  226. !:mime application/x-zstd
  227. 0 lelong 0xFD2FB525 Zstandard compressed data (v0.5)
  228. !:mime application/x-zstd
  229. 0 lelong 0xFD2FB526 Zstandard compressed data (v0.6)
  230. !:mime application/x-zstd
  231. 0 lelong 0xFD2FB527 Zstandard compressed data (v0.7)
  232. !:mime application/x-zstd
  233. >4 use zstd-dictionary-id
  234. 0 lelong 0xFD2FB528 Zstandard compressed data (v0.8+)
  235. !:mime application/x-zstd
  236. >4 use zstd-dictionary-id
  237. # https://github.com/facebook/zstd/blob/dev/zstd_compression_format.md
  238. 0 lelong 0xEC30A437 Zstandard dictionary
  239. !:mime application/x-zstd-dictionary
  240. >4 lelong x (ID %u)
  241. # AFX compressed files (Wolfram Kleff)
  242. 2 string -afx- AFX compressed file data
  243. # Supplementary magic data for the file(1) command to support
  244. # rzip(1). The format is described in magic(5).
  245. #
  246. # Copyright (C) 2003 by Andrew Tridgell. You may do whatever you want with
  247. # this file.
  248. #
  249. 0 string RZIP rzip compressed data
  250. >4 byte x - version %d
  251. >5 byte x \b.%d
  252. >6 belong x (%d bytes)
  253. 0 string ArC\x01 FreeArc archive <http://freearc.org>
  254. # Type: DACT compressed files
  255. 0 long 0x444354C3 DACT compressed data
  256. >4 byte >-1 (version %i.
  257. >5 byte >-1 %i.
  258. >6 byte >-1 %i)
  259. >7 long >0 , original size: %i bytes
  260. >15 long >30 , block size: %i bytes
  261. # Valve Pack (VPK) files
  262. 0 lelong 0x55aa1234 Valve Pak file
  263. >0x4 lelong x \b, version %u
  264. >0x8 lelong x \b, %u entries
  265. # Snappy framing format
  266. # http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt
  267. 0 string \377\006\0\0sNaPpY snappy framed data
  268. !:mime application/x-snappy-framed
  269. # qpress, http://www.quicklz.com/
  270. 0 string qpress10 qpress compressed data
  271. !:mime application/x-qpress
  272. # Zlib https://www.ietf.org/rfc/rfc6713.txt
  273. 0 string/b x
  274. >0 beshort%31 =0
  275. >>0 byte&0xf =8
  276. >>>0 byte&0x80 =0 zlib compressed data
  277. !:mime application/zlib
  278. # BWC compression
  279. 0 string BWC
  280. >3 byte 0 BWC compressed data
  281. # UCL compression
  282. 0 bequad 0x00e955434cff011a UCL compressed data
  283. # Softlib archive
  284. 0 string SLIB Softlib archive
  285. >4 leshort x \b, version %d
  286. >6 leshort x (contains %d files)
  287. # URL: https://github.com/lzfse/lzfse/blob/master/src/lzfse_internal.h#L276
  288. # From: Eric Hall <eric.hall@darkart.com>
  289. 0 string bvx- lzfse encoded, no compression
  290. 0 string bvx1 lzfse compressed, uncompressed tables
  291. 0 string bvx2 lzfse compressed, compressed tables
  292. 0 string bvxn lzfse encoded, lzvn compressed