]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/file/magic.5
This commit was generated by cvs2svn to compensate for changes in r131440,
[FreeBSD/FreeBSD.git] / usr.bin / file / magic.5
1 .\"
2 .\" $FreeBSD$
3 .\"
4 .\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
5 .\"
6 .Dd February 27, 2003
7 .Dt MAGIC 5 "Public Domain"
8 .Os
9 .Sh NAME
10 .Nm magic
11 .Nd file command's magic number file
12 .Sh DESCRIPTION
13 This manual page documents the format of the magic file as
14 used by the
15 .Nm
16 command, version 3.41.
17 The
18 .Nm file
19 command identifies the type of a file using,
20 among other tests,
21 a test for whether the file begins with a certain
22 .Em "magic number" .
23 The file
24 .Pa /usr/share/misc/magic
25 specifies what magic numbers are to be tested for,
26 what message to print if a particular magic number is found,
27 and additional information to extract from the file.
28 .Pp
29 Each line of the file specifies a test to be performed.
30 A test compares the data starting at a particular offset
31 in the file with a 1-byte, 2-byte, or 4-byte numeric value or
32 a string.
33 If the test succeeds, a message is printed.
34 The line consists of the following fields:
35 .Bl -tag -width indent
36 .It offset
37 A number specifying the offset, in bytes, into the file of the data
38 which is to be tested.
39 .It type
40 The type of the data to be tested.
41 The possible values are:
42 .Bl -tag -width indent
43 .It byte
44 A one-byte value.
45 .It short
46 A two-byte value (on most systems) in this machine's native byte order.
47 .It long
48 A four-byte value (on most systems) in this machine's native byte order.
49 .It string
50 A string of bytes.
51 The string type specification can be optionally followed
52 by /[Bbc]*.
53 The
54 .Dq B
55 flag compacts whitespace in the target, which must contain
56 at least one whitespace character.
57 If the magic has "n" consecutive blanks, the target needs
58 at least "n" consecutive blanks to match.
59 The
60 .Dq b
61 flag treats every blank in the target as an optional blank.
62 Finally the
63 .Dq c
64 flag, specifies case insensitive matching: lowercase characters
65 in the magic match both lower and upper case characters in the
66 targer, whereas upper case characters in the magic, only much
67 uppercase characters in the target.
68 .It date
69 A four-byte value interpreted as a
70 .Ux
71 date.
72 .It ldate
73 A four-byte value interpreted as a
74 .Ux Ns -style
75 date, but interpreted as
76 local time rather than UTC.
77 .It beshort
78 A two-byte value (on most systems) in big-endian byte order.
79 .It belong
80 A four-byte value (on most systems) in big-endian byte order.
81 .It bedate
82 A four-byte value (on most systems) in big-endian byte order,
83 interpreted as a
84 .Ux
85 date.
86 .It leshort
87 A two-byte value (on most systems) in little-endian byte order.
88 .It lelong
89 A four-byte value (on most systems) in little-endian byte order.
90 .It ledate
91 A four-byte value (on most systems) in little-endian byte order,
92 interpreted as a
93 .Ux
94 date.
95 .It leldate
96 A four-byte value (on most systems) in little-endian byte order,
97 interpreted as a
98 .Ux Ns -style
99 date, but interpreted as local time rather
100 than UTC.
101 .El
102 .El
103 .Pp
104 The numeric types may optionally be followed by
105 .Em &
106 and a numeric value,
107 to specify that the value is to be AND'ed with the
108 numeric value before any comparisons are done.  Prepending a
109 .Em u
110 to the type indicates that ordered comparisons should be unsigned.
111 .Bl -tag -width indent
112 .It test
113 The value to be compared with the value from the file.  If the type is
114 numeric, this value
115 is specified in C form; if it is a string, it is specified as a C string
116 with the usual escapes permitted (e.g. \en for new-line).
117 .It ""
118 Numeric values
119 may be preceded by a character indicating the operation to be performed.
120 It may be
121 .Em = ,
122 to specify that the value from the file must equal the specified value,
123 .Em < ,
124 to specify that the value from the file must be less than the specified
125 value,
126 .Em > ,
127 to specify that the value from the file must be greater than the specified
128 value,
129 .Em & ,
130 to specify that the value from the file must have set all of the bits
131 that are set in the specified value,
132 .Em ^ ,
133 to specify that the value from the file must have clear any of the bits
134 that are set in the specified value, or
135 .Em x ,
136 to specify that any value will match.
137 If the character is omitted,
138 it is assumed to be
139 .Em = .
140 .It ""
141 Numeric values are specified in C form; e.g.\&
142 .Em 13
143 is decimal,
144 .Em 013
145 is octal, and
146 .Em 0x13
147 is hexadecimal.
148 .It ""
149 For string values, the byte string from the
150 file must match the specified byte string.
151 The operators
152 .Em = ,
153 .Em <
154 and
155 .Em >
156 (but not
157 .Em & )
158 can be applied to strings.
159 The length used for matching is that of the string argument
160 in the magic file.  This means that a line can match any string, and
161 then presumably print that string, by doing
162 .Em >\e0
163 (because all strings are greater than the null string).
164 .It message
165 The message to be printed if the comparison succeeds.  If the string
166 contains a
167 .Xr printf 3
168 format specification, the value from the file (with any specified masking
169 performed) is printed using the message as the format string.
170 .El
171 .Pp
172 Some file formats contain additional information which is to be printed
173 along with the file type.  A line which begins with the character
174 .Em >
175 indicates additional tests and messages to be printed.  The number of
176 .Em >
177 on the line indicates the level of the test; a line with no
178 .Em >
179 at the beginning is considered to be at level 0.
180 Each line at level
181 .Em n+1
182 is under the control of the line at level
183 .Em n
184 most closely preceding it in the magic file.
185 If the test on a line at level
186 .Em n
187 succeeds, the tests specified in all the subsequent lines at level
188 .Em n+1
189 are performed, and the messages printed if the tests succeed.  The next
190 line at level
191 .Em n
192 terminates this.
193 If the first character following the last
194 .Em >
195 is a
196 .Em \&(
197 then the string after the parenthesis is interpreted as an indirect offset.
198 That means that the number after the parenthesis is used as an offset in
199 the file.
200 The value at that offset is read, and is used again as an offset
201 in the file.
202 Indirect offsets are of the form:
203 .Em (x[.[bslBSL]][+-][y]) .
204 The value of
205 .Em x
206 is used as an offset in the file.
207 A byte, short or long is read at that offset
208 depending on the
209 .Em [bslBSL]
210 type specifier.
211 The capitalized types interpret the number as a big endian value, whereas
212 a small letter versions interpret the number as a little endian value.
213 To that number the value of
214 .Em y
215 is added and the result is used as an offset in the file.
216 The default type
217 if one is not specified is long.
218 .Pp
219 Sometimes you do not know the exact offset as this depends on the length of
220 preceding fields.
221 You can specify an offset relative to the end of the
222 last uplevel field (of course this may only be done for sublevel tests, i.e.\&
223 test beginning with
224 .Em > Ns ) .
225 Such a relative offset is specified using
226 .Em &
227 as a prefix to the offset.
228 .Sh BUGS
229 The formats
230 .Em long ,
231 .Em belong ,
232 .Em lelong ,
233 .Em short ,
234 .Em beshort ,
235 .Em leshort ,
236 .Em date ,
237 .Em bedate ,
238 and
239 .Em ledate
240 are system-dependent; perhaps they should be specified as a number
241 of bytes (2B, 4B, etc),
242 since the files being recognized typically come from
243 a system on which the lengths are invariant.
244 .Pp
245 There is (currently) no support for specified-endian data to be used in
246 indirect offsets.
247 .Sh SEE ALSO
248 .Xr file 1
249 .\"
250 .\" From: guy@sun.uucp (Guy Harris)
251 .\" Newsgroups: net.bugs.usg
252 .\" Subject: /etc/magic's format isn't well documented
253 .\" Message-ID: <2752@sun.uucp>
254 .\" Date: 3 Sep 85 08:19:07 GMT
255 .\" Organization: Sun Microsystems, Inc.
256 .\" Lines: 136
257 .\"
258 .\" Here's a manual page for the format accepted by the "file" made by adding
259 .\" the changes I posted to the S5R2 version.
260 .\"
261 .\" Modified for Ian Darwin's version of the file command.
262 .\" @(#)$Id: magic.man,v 1.21 2003/02/27 20:47:46 christos Exp $