magic.man 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. .TH MAGIC __FSECTION__ "Public Domain"
  2. .\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
  3. .SH NAME
  4. magic \- file command's magic number file
  5. .SH DESCRIPTION
  6. This manual page documents the format of the magic file as
  7. used by the
  8. .BR file (__CSECTION__)
  9. command, version __VERSION__. The
  10. .B file
  11. command identifies the type of a file using,
  12. among other tests,
  13. a test for whether the file begins with a certain
  14. .IR "magic number" .
  15. The file
  16. .I __MAGIC__
  17. specifies what magic numbers are to be tested for,
  18. what message to print if a particular magic number is found,
  19. and additional information to extract from the file.
  20. .PP
  21. Each line of the file specifies a test to be performed.
  22. A test compares the data starting at a particular offset
  23. in the file with a 1-byte, 2-byte, or 4-byte numeric value or
  24. a string. If the test succeeds, a message is printed.
  25. The line consists of the following fields:
  26. .IP offset \w'message'u+2n
  27. A number specifying the offset, in bytes, into the file of the data
  28. which is to be tested.
  29. .IP type
  30. The type of the data to be tested. The possible values are:
  31. .RS
  32. .IP byte \w'message'u+2n
  33. A one-byte value.
  34. .IP short
  35. A two-byte value (on most systems) in this machine's native byte order.
  36. .IP long
  37. A four-byte value (on most systems) in this machine's native byte order.
  38. .IP string
  39. A string of bytes.
  40. .IP date
  41. A four-byte value interpreted as a unix date.
  42. .IP beshort
  43. A two-byte value (on most systems) in big-endian byte order.
  44. .IP belong
  45. A four-byte value (on most systems) in big-endian byte order.
  46. .IP bedate
  47. A four-byte value (on most systems) in big-endian byte order,
  48. interpreted as a unix date.
  49. .IP leshort
  50. A two-byte value (on most systems) in little-endian byte order.
  51. .IP lelong
  52. A four-byte value (on most systems) in little-endian byte order.
  53. .IP ledate
  54. A four-byte value (on most systems) in little-endian byte order,
  55. interpreted as a unix date.
  56. .RE
  57. .PP
  58. The numeric types may optionally be followed by
  59. .B &
  60. and a numeric value,
  61. to specify that the value is to be AND'ed with the
  62. numeric value before any comparisons are done. Prepending a
  63. .B u
  64. to the type indicates that ordered comparisons should be unsigned.
  65. .IP test
  66. The value to be compared with the value from the file. If the type is
  67. numeric, this value
  68. is specified in C form; if it is a string, it is specified as a C string
  69. with the usual escapes permitted (e.g. \en for new-line).
  70. .IP
  71. Numeric values
  72. may be preceded by a character indicating the operation to be performed.
  73. It may be
  74. .BR = ,
  75. to specify that the value from the file must equal the specified value,
  76. .BR < ,
  77. to specify that the value from the file must be less than the specified
  78. value,
  79. .BR > ,
  80. to specify that the value from the file must be greater than the specified
  81. value,
  82. .BR & ,
  83. to specify that the value from the file must have set all of the bits
  84. that are set in the specified value,
  85. .BR ^ ,
  86. to specify that the value from the file must have clear any of the bits
  87. that are set in the specified value, or
  88. .BR x ,
  89. to specify that any value will match. If the character is omitted,
  90. it is assumed to be
  91. .BR = .
  92. .IP
  93. Numeric values are specified in C form; e.g.
  94. .B 13
  95. is decimal,
  96. .B 013
  97. is octal, and
  98. .B 0x13
  99. is hexadecimal.
  100. .IP
  101. For string values, the byte string from the
  102. file must match the specified byte string.
  103. The operators
  104. .BR = ,
  105. .B <
  106. and
  107. .B >
  108. (but not
  109. .BR & )
  110. can be applied to strings.
  111. The length used for matching is that of the string argument
  112. in the magic file. This means that a line can match any string, and
  113. then presumably print that string, by doing
  114. .B >\e0
  115. (because all strings are greater than the null string).
  116. .IP message
  117. The message to be printed if the comparison succeeds. If the string
  118. contains a
  119. .BR printf (3S)
  120. format specification, the value from the file (with any specified masking
  121. performed) is printed using the message as the format string.
  122. .PP
  123. Some file formats contain additional information which is to be printed
  124. along with the file type. A line which begins with the character
  125. .B >
  126. indicates additional tests and messages to be printed. The number of
  127. .B >
  128. on the line indicates the level of the test; a line with no
  129. .B >
  130. at the beginning is considered to be at level 0.
  131. Each line at level
  132. .IB n \(pl1
  133. is under the control of the line at level
  134. .IB n
  135. most closely preceding it in the magic file.
  136. If the test on a line at level
  137. .I n
  138. succeeds, the tests specified in all the subsequent lines at level
  139. .IB n \(pl1
  140. are performed, and the messages printed if the tests succeed. The next
  141. line at level
  142. .I n
  143. terminates this.
  144. If the first character following the last
  145. .B >
  146. is a
  147. .B (
  148. then the string after the parenthesis is interpreted as an indirect offset.
  149. That means that the number after the parenthesis is used as an offset in
  150. the file. The value at that offset is read, and is used again as an offset
  151. in the file. Indirect offsets are of the form:
  152. .BI (( x [.[bslBSL]][+-][ y ]).
  153. The value of
  154. .I x
  155. is used as an offset in the file. A byte, short or long is read at that offset
  156. depending on the
  157. .B [bslBSL]
  158. type specifier. The capitalized types interpret the number as a big endian
  159. value, whereas the small letter versions interpet the number as a little
  160. endian value. To that number the value of
  161. .I y
  162. is added and the result is used as an offset in the file. The default type
  163. if one is not specified is long.
  164. .PP
  165. Sometimes you do not know the exact offset as this depends on the length of
  166. preceding fields. You can specify an offset relative to the end of the
  167. last uplevel field (of course this may only be done for sublevel tests, i.e.
  168. test beginning with
  169. .B >
  170. ). Such a relative offset is specified using
  171. .B &
  172. as a prefix to the offset.
  173. .SH BUGS
  174. The formats
  175. .IR long ,
  176. .IR belong ,
  177. .IR lelong ,
  178. .IR short ,
  179. .IR beshort ,
  180. .IR leshort ,
  181. .IR date ,
  182. .IR bedate ,
  183. and
  184. .I ledate
  185. are system-dependent; perhaps they should be specified as a number
  186. of bytes (2B, 4B, etc),
  187. since the files being recognized typically come from
  188. a system on which the lengths are invariant.
  189. .PP
  190. There is (currently) no support for specified-endian data to be used in
  191. indirect offsets.
  192. .SH SEE ALSO
  193. .BR file (__CSECTION__)
  194. \- the command that reads this file.
  195. .\"
  196. .\" From: guy@sun.uucp (Guy Harris)
  197. .\" Newsgroups: net.bugs.usg
  198. .\" Subject: /etc/magic's format isn't well documented
  199. .\" Message-ID: <2752@sun.uucp>
  200. .\" Date: 3 Sep 85 08:19:07 GMT
  201. .\" Organization: Sun Microsystems, Inc.
  202. .\" Lines: 136
  203. .\"
  204. .\" Here's a manual page for the format accepted by the "file" made by adding
  205. .\" the changes I posted to the S5R2 version.
  206. .\"
  207. .\" Modified for Ian Darwin's version of the file command.
  208. .\" @(#)$Id: magic.man,v 1.15 1998/08/13 17:32:24 christos Exp $