xref: /dflybsd-src/contrib/file/doc/magic.man (revision 614728ca5ae8ce18ba7b320c92e6acb210aedf6e)
1*614728caSSascha Wildner.\" $File: magic.man,v 1.99 2021/05/09 22:37:23 christos Exp $
2*614728caSSascha Wildner.Dd May 9, 2021
3327e51cbSPeter Avalos.Dt MAGIC __FSECTION__
4327e51cbSPeter Avalos.Os
579343712SPeter Avalos.\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
6327e51cbSPeter Avalos.Sh NAME
7327e51cbSPeter Avalos.Nm magic
879343712SPeter Avalos.Nd file command's magic pattern file
9327e51cbSPeter Avalos.Sh DESCRIPTION
10c30bd091SSascha WildnerThis manual page documents the format of magic files as
11327e51cbSPeter Avalosused by the
12327e51cbSPeter Avalos.Xr file __CSECTION__
13327e51cbSPeter Avaloscommand, version __VERSION__.
14327e51cbSPeter AvalosThe
15327e51cbSPeter Avalos.Xr file __CSECTION__
16327e51cbSPeter Avaloscommand identifies the type of a file using,
17327e51cbSPeter Avalosamong other tests,
1879343712SPeter Avalosa test for whether the file contains certain
1979343712SPeter Avalos.Dq "magic patterns" .
20c30bd091SSascha WildnerThe database of these
21c30bd091SSascha Wildner.Dq "magic patterns"
22c30bd091SSascha Wildneris usually located in a binary file in
23c30bd091SSascha Wildner.Pa __MAGIC__.mgc
24c30bd091SSascha Wildneror a directory of source text magic pattern fragment files in
25c30bd091SSascha Wildner.Pa __MAGIC__ .
26c30bd091SSascha WildnerThe database specifies what patterns are to be tested for, what message or
2779343712SPeter AvalosMIME type to print if a particular pattern is found,
28327e51cbSPeter Avalosand additional information to extract from the file.
29327e51cbSPeter Avalos.Pp
30c30bd091SSascha WildnerThe format of the source fragment files that are used to build this database
31c30bd091SSascha Wildneris as follows:
32c30bd091SSascha WildnerEach line of a fragment file specifies a test to be performed.
33327e51cbSPeter AvalosA test compares the data starting at a particular offset
3479343712SPeter Avalosin the file with a byte value, a string or a numeric value.
35327e51cbSPeter AvalosIf the test succeeds, a message is printed.
36327e51cbSPeter AvalosThe line consists of the following fields:
37327e51cbSPeter Avalos.Bl -tag -width ".Dv message"
38327e51cbSPeter Avalos.It Dv offset
396fca56fbSSascha WildnerA number specifying the offset (in bytes) into the file of the data
40327e51cbSPeter Avaloswhich is to be tested.
416fca56fbSSascha WildnerThis offset can be a negative number if it is:
426fca56fbSSascha Wildner.Bl -bullet  -compact
436fca56fbSSascha Wildner.It
446fca56fbSSascha WildnerThe first direct offset of the magic entry (at continuation level 0),
456fca56fbSSascha Wildnerin which case it is interpreted an offset from end end of the file
466fca56fbSSascha Wildnergoing backwards.
476fca56fbSSascha WildnerThis works only when a file descriptor to the file is available and it
486fca56fbSSascha Wildneris a regular file.
496fca56fbSSascha Wildner.It
506fca56fbSSascha WildnerA continuation offset relative to the end of the last up-level field
516fca56fbSSascha Wildner.Dv ( \*[Am] ) .
526fca56fbSSascha Wildner.El
53327e51cbSPeter Avalos.It Dv type
54327e51cbSPeter AvalosThe type of the data to be tested.
55327e51cbSPeter AvalosThe possible values are:
56327e51cbSPeter Avalos.Bl -tag -width ".Dv lestring16"
57327e51cbSPeter Avalos.It Dv byte
58327e51cbSPeter AvalosA one-byte value.
59327e51cbSPeter Avalos.It Dv short
6079343712SPeter AvalosA two-byte value in this machine's native byte order.
61327e51cbSPeter Avalos.It Dv long
6279343712SPeter AvalosA four-byte value in this machine's native byte order.
63327e51cbSPeter Avalos.It Dv quad
6479343712SPeter AvalosAn eight-byte value in this machine's native byte order.
65327e51cbSPeter Avalos.It Dv float
6679343712SPeter AvalosA 32-bit single precision IEEE floating point number in this machine's native byte order.
67327e51cbSPeter Avalos.It Dv double
6879343712SPeter AvalosA 64-bit double precision IEEE floating point number in this machine's native byte order.
69327e51cbSPeter Avalos.It Dv string
70327e51cbSPeter AvalosA string of bytes.
71327e51cbSPeter AvalosThe string type specification can be optionally followed
72*614728caSSascha Wildnerby /[WwcCtbTf]*.
73327e51cbSPeter AvalosThe
74884044a5SPeter Avalos.Dq W
75327e51cbSPeter Avalosflag compacts whitespace in the target, which must
76327e51cbSPeter Avaloscontain at least one whitespace character.
77327e51cbSPeter AvalosIf the magic has
78327e51cbSPeter Avalos.Dv n
79327e51cbSPeter Avalosconsecutive blanks, the target needs at least
80327e51cbSPeter Avalos.Dv n
81327e51cbSPeter Avalosconsecutive blanks to match.
82327e51cbSPeter AvalosThe
83884044a5SPeter Avalos.Dq w
849f86ab30SPeter Avalosflag treats every blank in the magic as an optional blank.
85884044a5SPeter AvalosThe
86*614728caSSascha Wildner.Dq f
87*614728caSSascha Wildnerflags requires that the matched string is a full word, not a partial word match.
88*614728caSSascha WildnerThe
89327e51cbSPeter Avalos.Dq c
909f86ab30SPeter Avalosflag specifies case insensitive matching: lower case
91327e51cbSPeter Avaloscharacters in the magic match both lower and upper case characters in the
9279343712SPeter Avalostarget, whereas upper case characters in the magic only match upper case
93327e51cbSPeter Avaloscharacters in the target.
94884044a5SPeter AvalosThe
95884044a5SPeter Avalos.Dq C
969f86ab30SPeter Avalosflag specifies case insensitive matching: upper case
97884044a5SPeter Avaloscharacters in the magic match both lower and upper case characters in the
98884044a5SPeter Avalostarget, whereas lower case characters in the magic only match upper case
99884044a5SPeter Avaloscharacters in the target.
100884044a5SPeter AvalosTo do a complete case insensitive match, specify both
101884044a5SPeter Avalos.Dq c
102884044a5SPeter Avalosand
103884044a5SPeter Avalos.Dq C .
104884044a5SPeter AvalosThe
105884044a5SPeter Avalos.Dq t
1069f86ab30SPeter Avalosflag forces the test to be done for text files, while the
107884044a5SPeter Avalos.Dq b
1089f86ab30SPeter Avalosflag forces the test to be done for binary files.
109e8af9738SPeter AvalosThe
110e8af9738SPeter Avalos.Dq T
111e8af9738SPeter Avalosflag causes the string to be trimmed, i.e. leading and trailing whitespace
112e8af9738SPeter Avalosis deleted before the string is printed.
113327e51cbSPeter Avalos.It Dv pstring
114e8af9738SPeter AvalosA Pascal-style string where the first byte/short/int is interpreted as the
115327e51cbSPeter Avalosunsigned length.
116e4d4ce0cSPeter AvalosThe length defaults to byte and can be specified as a modifier.
117e4d4ce0cSPeter AvalosThe following modifiers are supported:
118e4d4ce0cSPeter Avalos.Bl -tag -compact -width B
119e4d4ce0cSPeter Avalos.It B
120e4d4ce0cSPeter AvalosA byte length (default).
121e4d4ce0cSPeter Avalos.It H
122c30bd091SSascha WildnerA 2 byte big endian length.
1236fca56fbSSascha Wildner.It h
124c30bd091SSascha WildnerA 2 byte little endian length.
1256fca56fbSSascha Wildner.It L
1266fca56fbSSascha WildnerA 4 byte big endian length.
1276fca56fbSSascha Wildner.It l
1286fca56fbSSascha WildnerA 4 byte little endian length.
129e4d4ce0cSPeter Avalos.It J
130e4d4ce0cSPeter AvalosThe length includes itself in its count.
131e4d4ce0cSPeter Avalos.El
132327e51cbSPeter AvalosThe string is not NUL terminated.
133e4d4ce0cSPeter Avalos.Dq J
134e4d4ce0cSPeter Avalosis used rather than the more
135e4d4ce0cSPeter Avalosvaluable
136e4d4ce0cSPeter Avalos.Dq I
137e4d4ce0cSPeter Avalosbecause this type of length is a feature of the JPEG
138e4d4ce0cSPeter Avalosformat.
139327e51cbSPeter Avalos.It Dv date
140327e51cbSPeter AvalosA four-byte value interpreted as a UNIX date.
141327e51cbSPeter Avalos.It Dv qdate
1426fca56fbSSascha WildnerAn eight-byte value interpreted as a UNIX date.
143327e51cbSPeter Avalos.It Dv ldate
144327e51cbSPeter AvalosA four-byte value interpreted as a UNIX-style date, but interpreted as
145327e51cbSPeter Avaloslocal time rather than UTC.
146327e51cbSPeter Avalos.It Dv qldate
147327e51cbSPeter AvalosAn eight-byte value interpreted as a UNIX-style date, but interpreted as
148327e51cbSPeter Avaloslocal time rather than UTC.
149e8af9738SPeter Avalos.It Dv qwdate
150e8af9738SPeter AvalosAn eight-byte value interpreted as a Windows-style date.
15179343712SPeter Avalos.It Dv beid3
15279343712SPeter AvalosA 32-bit ID3 length in big-endian byte order.
153327e51cbSPeter Avalos.It Dv beshort
15479343712SPeter AvalosA two-byte value in big-endian byte order.
155327e51cbSPeter Avalos.It Dv belong
15679343712SPeter AvalosA four-byte value in big-endian byte order.
157327e51cbSPeter Avalos.It Dv bequad
15879343712SPeter AvalosAn eight-byte value in big-endian byte order.
159327e51cbSPeter Avalos.It Dv befloat
16079343712SPeter AvalosA 32-bit single precision IEEE floating point number in big-endian byte order.
161327e51cbSPeter Avalos.It Dv bedouble
16279343712SPeter AvalosA 64-bit double precision IEEE floating point number in big-endian byte order.
163327e51cbSPeter Avalos.It Dv bedate
16479343712SPeter AvalosA four-byte value in big-endian byte order,
165327e51cbSPeter Avalosinterpreted as a Unix date.
166327e51cbSPeter Avalos.It Dv beqdate
16779343712SPeter AvalosAn eight-byte value in big-endian byte order,
168327e51cbSPeter Avalosinterpreted as a Unix date.
169327e51cbSPeter Avalos.It Dv beldate
17079343712SPeter AvalosA four-byte value in big-endian byte order,
171327e51cbSPeter Avalosinterpreted as a UNIX-style date, but interpreted as local time rather
172327e51cbSPeter Avalosthan UTC.
173327e51cbSPeter Avalos.It Dv beqldate
17479343712SPeter AvalosAn eight-byte value in big-endian byte order,
175327e51cbSPeter Avalosinterpreted as a UNIX-style date, but interpreted as local time rather
176327e51cbSPeter Avalosthan UTC.
177e8af9738SPeter Avalos.It Dv beqwdate
178e8af9738SPeter AvalosAn eight-byte value in big-endian byte order,
179e8af9738SPeter Avalosinterpreted as a Windows-style date.
180327e51cbSPeter Avalos.It Dv bestring16
181327e51cbSPeter AvalosA two-byte unicode (UCS16) string in big-endian byte order.
18279343712SPeter Avalos.It Dv leid3
18379343712SPeter AvalosA 32-bit ID3 length in little-endian byte order.
184327e51cbSPeter Avalos.It Dv leshort
18579343712SPeter AvalosA two-byte value in little-endian byte order.
186327e51cbSPeter Avalos.It Dv lelong
18779343712SPeter AvalosA four-byte value in little-endian byte order.
188327e51cbSPeter Avalos.It Dv lequad
18979343712SPeter AvalosAn eight-byte value in little-endian byte order.
190327e51cbSPeter Avalos.It Dv lefloat
19179343712SPeter AvalosA 32-bit single precision IEEE floating point number in little-endian byte order.
192327e51cbSPeter Avalos.It Dv ledouble
19379343712SPeter AvalosA 64-bit double precision IEEE floating point number in little-endian byte order.
194327e51cbSPeter Avalos.It Dv ledate
19579343712SPeter AvalosA four-byte value in little-endian byte order,
196327e51cbSPeter Avalosinterpreted as a UNIX date.
197327e51cbSPeter Avalos.It Dv leqdate
19879343712SPeter AvalosAn eight-byte value in little-endian byte order,
199327e51cbSPeter Avalosinterpreted as a UNIX date.
200327e51cbSPeter Avalos.It Dv leldate
20179343712SPeter AvalosA four-byte value in little-endian byte order,
202327e51cbSPeter Avalosinterpreted as a UNIX-style date, but interpreted as local time rather
203327e51cbSPeter Avalosthan UTC.
204327e51cbSPeter Avalos.It Dv leqldate
20579343712SPeter AvalosAn eight-byte value in little-endian byte order,
206327e51cbSPeter Avalosinterpreted as a UNIX-style date, but interpreted as local time rather
207327e51cbSPeter Avalosthan UTC.
208e8af9738SPeter Avalos.It Dv leqwdate
209e8af9738SPeter AvalosAn eight-byte value in little-endian byte order,
210e8af9738SPeter Avalosinterpreted as a Windows-style date.
211327e51cbSPeter Avalos.It Dv lestring16
212327e51cbSPeter AvalosA two-byte unicode (UCS16) string in little-endian byte order.
213327e51cbSPeter Avalos.It Dv melong
21479343712SPeter AvalosA four-byte value in middle-endian (PDP-11) byte order.
215327e51cbSPeter Avalos.It Dv medate
21679343712SPeter AvalosA four-byte value in middle-endian (PDP-11) byte order,
217327e51cbSPeter Avalosinterpreted as a UNIX date.
218327e51cbSPeter Avalos.It Dv meldate
21979343712SPeter AvalosA four-byte value in middle-endian (PDP-11) byte order,
220327e51cbSPeter Avalosinterpreted as a UNIX-style date, but interpreted as local time rather
221327e51cbSPeter Avalosthan UTC.
22279343712SPeter Avalos.It Dv indirect
22379343712SPeter AvalosStarting at the given offset, consult the magic database again.
224c30bd091SSascha WildnerThe offset of the
22582c5fa3eSPeter Avalos.Dv indirect
22682c5fa3eSPeter Avalosmagic is by default absolute in the file, but one can specify
22782c5fa3eSPeter Avalos.Dv /r
22882c5fa3eSPeter Avalosto indicate that the offset is relative from the beginning of the entry.
229e8af9738SPeter Avalos.It Dv name
230e8af9738SPeter AvalosDefine a
231e8af9738SPeter Avalos.Dq named
232e8af9738SPeter Avalosmagic instance that can be called from another
233e8af9738SPeter Avalos.Dv use
234e8af9738SPeter Avalosmagic entry, like a subroutine call.
235e8af9738SPeter AvalosNamed instance direct magic offsets are relative to the offset of the
236e8af9738SPeter Avalosprevious matched entry, but indirect offsets are relative to the beginning
237e8af9738SPeter Avalosof the file as usual.
238e8af9738SPeter AvalosNamed magic entries always match.
239e8af9738SPeter Avalos.It Dv use
240e8af9738SPeter AvalosRecursively call the named magic starting from the current offset.
241e8af9738SPeter AvalosIf the name of the referenced begins with a
242e8af9738SPeter Avalos.Dv ^
243e8af9738SPeter Avalosthen the endianness of the magic is switched; if the magic mentioned
244e8af9738SPeter Avalos.Dv leshort
245e8af9738SPeter Avalosfor example,
246e8af9738SPeter Avalosit is treated as
247e8af9738SPeter Avalos.Dv beshort
248e8af9738SPeter Avalosand vice versa.
249e8af9738SPeter AvalosThis is useful to avoid duplicating the rules for different endianness.
250327e51cbSPeter Avalos.It Dv regex
251327e51cbSPeter AvalosA regular expression match in extended POSIX regular expression syntax
252a96e001bSPeter Avalos(like egrep).
253a96e001bSPeter AvalosRegular expressions can take exponential time to process, and their
254a96e001bSPeter Avalosperformance is hard to predict, so their use is discouraged.
255a96e001bSPeter AvalosWhen used in production environments, their performance
256a96e001bSPeter Avalosshould be carefully checked.
25782c5fa3eSPeter AvalosThe size of the string to search should also be limited by specifying
25882c5fa3eSPeter Avalos.Dv /<length> ,
25982c5fa3eSPeter Avalosto avoid performance issues scanning long files.
26082c5fa3eSPeter AvalosThe type specification can also be optionally followed by
26182c5fa3eSPeter Avalos.Dv /[c][s][l] .
262327e51cbSPeter AvalosThe
263327e51cbSPeter Avalos.Dq c
264327e51cbSPeter Avalosflag makes the match case insensitive, while the
265327e51cbSPeter Avalos.Dq s
26679343712SPeter Avalosflag update the offset to the start offset of the match, rather than the end.
26782c5fa3eSPeter AvalosThe
26882c5fa3eSPeter Avalos.Dq l
26982c5fa3eSPeter Avalosmodifier, changes the limit of length to mean number of lines instead of a
27082c5fa3eSPeter Avalosbyte count.
27182c5fa3eSPeter AvalosLines are delimited by the platforms native line delimiter.
27282c5fa3eSPeter AvalosWhen a line count is specified, an implicit byte count also computed assuming
27382c5fa3eSPeter Avaloseach line is 80 characters long.
27482c5fa3eSPeter AvalosIf neither a byte or line count is specified, the search is limited automatically
27582c5fa3eSPeter Avalosto 8KiB.
276327e51cbSPeter Avalos.Dv ^
277327e51cbSPeter Avalosand
278327e51cbSPeter Avalos.Dv $
27979343712SPeter Avalosmatch the beginning and end of individual lines, respectively,
280327e51cbSPeter Avalosnot beginning and end of file.
281327e51cbSPeter Avalos.It Dv search
282a96e001bSPeter AvalosA literal string search starting at the given offset.
283a96e001bSPeter AvalosThe same modifier flags can be used as for string patterns.
284e8af9738SPeter AvalosThe search expression must contain the range in the form
285e8af9738SPeter Avalos.Dv /number,
286e8af9738SPeter Avalosthat is the number of positions at which the match will be
287a96e001bSPeter Avalosattempted, starting from the start offset.
288a96e001bSPeter AvalosThis is suitable for
28979343712SPeter Avalossearching larger binary expressions with variable offsets, using
290327e51cbSPeter Avalos.Dv \e
291a96e001bSPeter Avalosescapes for special characters.
292e8af9738SPeter AvalosThe order of modifier and number is not relevant.
293327e51cbSPeter Avalos.It Dv default
29479343712SPeter AvalosThis is intended to be used with the test
29579343712SPeter Avalos.Em x
296e8af9738SPeter Avalos(which is always true) and it has no type.
297e8af9738SPeter AvalosIt matches when no other test at that continuation level has matched before.
298e8af9738SPeter AvalosClearing that matched tests for a continuation level, can be done using the
299e8af9738SPeter Avalos.Dv clear
300e8af9738SPeter Avalostest.
301e8af9738SPeter Avalos.It Dv clear
302e8af9738SPeter AvalosThis test is always true and clears the match flag for that continuation level.
303e8af9738SPeter AvalosIt is intended to be used with the
304e8af9738SPeter Avalos.Dv default
305e8af9738SPeter Avalostest.
306c990e5baSDaniel Fojt.It Dv der
307c990e5baSDaniel FojtParse the file as a DER Certificate file.
308c990e5baSDaniel FojtThe test field is used as a der type that needs to be matched.
309c990e5baSDaniel FojtThe DER types are:
310c990e5baSDaniel Fojt.Dv eoc ,
311c990e5baSDaniel Fojt.Dv bool ,
312c990e5baSDaniel Fojt.Dv int ,
313c990e5baSDaniel Fojt.Dv bit_str ,
314c990e5baSDaniel Fojt.Dv octet_str ,
315c990e5baSDaniel Fojt.Dv null ,
316c990e5baSDaniel Fojt.Dv obj_id ,
317c990e5baSDaniel Fojt.Dv obj_desc ,
318c990e5baSDaniel Fojt.Dv ext ,
319c990e5baSDaniel Fojt.Dv real ,
320c990e5baSDaniel Fojt.Dv enum ,
321c990e5baSDaniel Fojt.Dv embed ,
322c990e5baSDaniel Fojt.Dv utf8_str ,
323c990e5baSDaniel Fojt.Dv rel_oid ,
324c990e5baSDaniel Fojt.Dv time ,
325c990e5baSDaniel Fojt.Dv res2 ,
326c990e5baSDaniel Fojt.Dv seq ,
327c990e5baSDaniel Fojt.Dv set ,
328c990e5baSDaniel Fojt.Dv num_str ,
329c990e5baSDaniel Fojt.Dv prt_str ,
330c990e5baSDaniel Fojt.Dv t61_str ,
331c990e5baSDaniel Fojt.Dv vid_str ,
332c990e5baSDaniel Fojt.Dv ia5_str ,
333c990e5baSDaniel Fojt.Dv utc_time ,
334c990e5baSDaniel Fojt.Dv gen_time ,
335c990e5baSDaniel Fojt.Dv gr_str ,
336c990e5baSDaniel Fojt.Dv vis_str ,
337c990e5baSDaniel Fojt.Dv gen_str ,
338c990e5baSDaniel Fojt.Dv univ_str ,
339c990e5baSDaniel Fojt.Dv char_str ,
340c990e5baSDaniel Fojt.Dv bmp_str ,
341c990e5baSDaniel Fojt.Dv date ,
342c990e5baSDaniel Fojt.Dv tod ,
343c990e5baSDaniel Fojt.Dv datetime ,
344c990e5baSDaniel Fojt.Dv duration ,
345c990e5baSDaniel Fojt.Dv oid-iri ,
346c990e5baSDaniel Fojt.Dv rel-oid-iri .
347c990e5baSDaniel FojtThese types can be followed by an optional numeric size, which indicates
348c990e5baSDaniel Fojtthe field width in bytes.
349c990e5baSDaniel Fojt.It Dv guid
350c990e5baSDaniel FojtA Globally Unique Identifier, parsed and printed as
351c990e5baSDaniel FojtXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
352c990e5baSDaniel FojtIt's format is a string.
353c990e5baSDaniel Fojt.It Dv offset
354c990e5baSDaniel FojtThis is a quad value indicating the current offset of the file.
355c990e5baSDaniel FojtIt can be used to determine the size of the file or the magic buffer.
356c990e5baSDaniel FojtFor example the magic entries:
357c990e5baSDaniel Fojt.Bd -literal -offset indent
358c990e5baSDaniel Fojt-0	offset	x	this file is %lld bytes
359c990e5baSDaniel Fojt-0	offset	<=100	must be more than 100 \e
360c990e5baSDaniel Fojt    bytes and is only %lld
361c990e5baSDaniel Fojt.Ed
362327e51cbSPeter Avalos.El
36379343712SPeter Avalos.Pp
364e8af9738SPeter AvalosFor compatibility with the Single
365e8af9738SPeter Avalos.Ux
366e8af9738SPeter AvalosStandard, the type specifiers
367e8af9738SPeter Avalos.Dv dC
368e8af9738SPeter Avalosand
369e8af9738SPeter Avalos.Dv d1
370e8af9738SPeter Avalosare equivalent to
371e8af9738SPeter Avalos.Dv byte ,
372e8af9738SPeter Avalosthe type specifiers
373e8af9738SPeter Avalos.Dv uC
374e8af9738SPeter Avalosand
375e8af9738SPeter Avalos.Dv u1
376e8af9738SPeter Avalosare equivalent to
377e8af9738SPeter Avalos.Dv ubyte ,
378e8af9738SPeter Avalosthe type specifiers
379e8af9738SPeter Avalos.Dv dS
380e8af9738SPeter Avalosand
381e8af9738SPeter Avalos.Dv d2
382e8af9738SPeter Avalosare equivalent to
383e8af9738SPeter Avalos.Dv short ,
384e8af9738SPeter Avalosthe type specifiers
385e8af9738SPeter Avalos.Dv uS
386e8af9738SPeter Avalosand
387e8af9738SPeter Avalos.Dv u2
388e8af9738SPeter Avalosare equivalent to
389e8af9738SPeter Avalos.Dv ushort ,
390e8af9738SPeter Avalosthe type specifiers
391e8af9738SPeter Avalos.Dv dI ,
392e8af9738SPeter Avalos.Dv dL ,
393e8af9738SPeter Avalosand
394e8af9738SPeter Avalos.Dv d4
395e8af9738SPeter Avalosare equivalent to
396e8af9738SPeter Avalos.Dv long ,
397e8af9738SPeter Avalosthe type specifiers
398e8af9738SPeter Avalos.Dv uI ,
399e8af9738SPeter Avalos.Dv uL ,
400e8af9738SPeter Avalosand
401e8af9738SPeter Avalos.Dv u4
402e8af9738SPeter Avalosare equivalent to
403e8af9738SPeter Avalos.Dv ulong ,
404e8af9738SPeter Avalosthe type specifier
405e8af9738SPeter Avalos.Dv d8
406e8af9738SPeter Avalosis equivalent to
407e8af9738SPeter Avalos.Dv quad ,
408e8af9738SPeter Avalosthe type specifier
409e8af9738SPeter Avalos.Dv u8
410e8af9738SPeter Avalosis equivalent to
411e8af9738SPeter Avalos.Dv uquad ,
412e8af9738SPeter Avalosand the type specifier
413e8af9738SPeter Avalos.Dv s
414e8af9738SPeter Avalosis equivalent to
415e8af9738SPeter Avalos.Dv string .
416e8af9738SPeter AvalosIn addition, the type specifier
417e8af9738SPeter Avalos.Dv dQ
418e8af9738SPeter Avalosis equivalent to
419e8af9738SPeter Avalos.Dv quad
420e8af9738SPeter Avalosand the type specifier
421e8af9738SPeter Avalos.Dv uQ
422e8af9738SPeter Avalosis equivalent to
423e8af9738SPeter Avalos.Dv uquad .
424e8af9738SPeter Avalos.Pp
42579343712SPeter AvalosEach top-level magic pattern (see below for an explanation of levels)
426a96e001bSPeter Avalosis classified as text or binary according to the types used.
427a96e001bSPeter AvalosTypes
42879343712SPeter Avalos.Dq regex
42979343712SPeter Avalosand
43079343712SPeter Avalos.Dq search
43179343712SPeter Avalosare classified as text tests, unless non-printable characters are used
432a96e001bSPeter Avalosin the pattern.
433a96e001bSPeter AvalosAll other tests are classified as binary.
434a96e001bSPeter AvalosA top-level
43579343712SPeter Avalospattern is considered to be a test text when all its patterns are text
436a96e001bSPeter Avalospatterns; otherwise, it is considered to be a binary pattern.
437a96e001bSPeter AvalosWhen
43879343712SPeter Avalosmatching a file, binary patterns are tried first; if no match is
43979343712SPeter Avalosfound, and the file looks like text, then its encoding is determined
44079343712SPeter Avalosand the text patterns are tried.
441327e51cbSPeter Avalos.Pp
442327e51cbSPeter AvalosThe numeric types may optionally be followed by
443327e51cbSPeter Avalos.Dv \*[Am]
444327e51cbSPeter Avalosand a numeric value,
445327e51cbSPeter Avalosto specify that the value is to be AND'ed with the
446327e51cbSPeter Avalosnumeric value before any comparisons are done.
447327e51cbSPeter AvalosPrepending a
448327e51cbSPeter Avalos.Dv u
449327e51cbSPeter Avalosto the type indicates that ordered comparisons should be unsigned.
450327e51cbSPeter Avalos.It Dv test
451327e51cbSPeter AvalosThe value to be compared with the value from the file.
452327e51cbSPeter AvalosIf the type is
453327e51cbSPeter Avalosnumeric, this value
454327e51cbSPeter Avalosis specified in C form; if it is a string, it is specified as a C string
455327e51cbSPeter Avaloswith the usual escapes permitted (e.g. \en for new-line).
456327e51cbSPeter Avalos.Pp
457327e51cbSPeter AvalosNumeric values
458327e51cbSPeter Avalosmay be preceded by a character indicating the operation to be performed.
459327e51cbSPeter AvalosIt may be
460327e51cbSPeter Avalos.Dv = ,
461327e51cbSPeter Avalosto specify that the value from the file must equal the specified value,
462327e51cbSPeter Avalos.Dv \*[Lt] ,
463327e51cbSPeter Avalosto specify that the value from the file must be less than the specified
464327e51cbSPeter Avalosvalue,
465327e51cbSPeter Avalos.Dv \*[Gt] ,
466327e51cbSPeter Avalosto specify that the value from the file must be greater than the specified
467327e51cbSPeter Avalosvalue,
468327e51cbSPeter Avalos.Dv \*[Am] ,
469327e51cbSPeter Avalosto specify that the value from the file must have set all of the bits
470327e51cbSPeter Avalosthat are set in the specified value,
471327e51cbSPeter Avalos.Dv ^ ,
472327e51cbSPeter Avalosto specify that the value from the file must have clear any of the bits
473327e51cbSPeter Avalosthat are set in the specified value, or
474327e51cbSPeter Avalos.Dv ~ ,
475327e51cbSPeter Avalosthe value specified after is negated before tested.
476327e51cbSPeter Avalos.Dv x ,
477327e51cbSPeter Avalosto specify that any value will match.
478327e51cbSPeter AvalosIf the character is omitted, it is assumed to be
479327e51cbSPeter Avalos.Dv = .
480327e51cbSPeter AvalosOperators
481327e51cbSPeter Avalos.Dv \*[Am] ,
482327e51cbSPeter Avalos.Dv ^ ,
483327e51cbSPeter Avalosand
484327e51cbSPeter Avalos.Dv ~
485327e51cbSPeter Avalosdon't work with floats and doubles.
48679343712SPeter AvalosThe operator
48779343712SPeter Avalos.Dv !\&
488327e51cbSPeter Avalosspecifies that the line matches if the test does
489327e51cbSPeter Avalos.Em not
490327e51cbSPeter Avalossucceed.
491327e51cbSPeter Avalos.Pp
492327e51cbSPeter AvalosNumeric values are specified in C form; e.g.
493327e51cbSPeter Avalos.Dv 13
494327e51cbSPeter Avalosis decimal,
495327e51cbSPeter Avalos.Dv 013
496327e51cbSPeter Avalosis octal, and
497327e51cbSPeter Avalos.Dv 0x13
498327e51cbSPeter Avalosis hexadecimal.
499327e51cbSPeter Avalos.Pp
50082c5fa3eSPeter AvalosNumeric operations are not performed on date types, instead the numeric
50182c5fa3eSPeter Avalosvalue is interpreted as an offset.
50282c5fa3eSPeter Avalos.Pp
50379343712SPeter AvalosFor string values, the string from the
50479343712SPeter Avalosfile must match the specified string.
505327e51cbSPeter AvalosThe operators
506327e51cbSPeter Avalos.Dv = ,
507327e51cbSPeter Avalos.Dv \*[Lt]
508327e51cbSPeter Avalosand
509327e51cbSPeter Avalos.Dv \*[Gt]
510327e51cbSPeter Avalos(but not
511327e51cbSPeter Avalos.Dv \*[Am] )
512327e51cbSPeter Avaloscan be applied to strings.
513327e51cbSPeter AvalosThe length used for matching is that of the string argument
514327e51cbSPeter Avalosin the magic file.
51579343712SPeter AvalosThis means that a line can match any non-empty string (usually used to
51679343712SPeter Avalosthen print the string), with
517327e51cbSPeter Avalos.Em \*[Gt]\e0
51879343712SPeter Avalos(because all non-empty strings are greater than the empty string).
519327e51cbSPeter Avalos.Pp
520e8af9738SPeter AvalosDates are treated as numerical values in the respective internal
521e8af9738SPeter Avalosrepresentation.
522e8af9738SPeter Avalos.Pp
523327e51cbSPeter AvalosThe special test
524327e51cbSPeter Avalos.Em x
525327e51cbSPeter Avalosalways evaluates to true.
526e4d4ce0cSPeter Avalos.It Dv message
527327e51cbSPeter AvalosThe message to be printed if the comparison succeeds.
528327e51cbSPeter AvalosIf the string contains a
529327e51cbSPeter Avalos.Xr printf 3
530327e51cbSPeter Avalosformat specification, the value from the file (with any specified masking
531327e51cbSPeter Avalosperformed) is printed using the message as the format string.
53279343712SPeter AvalosIf the string begins with
53379343712SPeter Avalos.Dq \eb ,
53479343712SPeter Avalosthe message printed is the remainder of the string with no whitespace
53579343712SPeter Avalosadded before it: multiple matches are normally separated by a single
53679343712SPeter Avalosspace.
537327e51cbSPeter Avalos.El
538327e51cbSPeter Avalos.Pp
53979343712SPeter AvalosAn APPLE 4+4 character APPLE creator and type can be specified as:
54079343712SPeter Avalos.Bd -literal -offset indent
54179343712SPeter Avalos!:apple	CREATYPE
54279343712SPeter Avalos.Ed
54379343712SPeter Avalos.Pp
54479343712SPeter AvalosA MIME type is given on a separate line, which must be the next
54579343712SPeter Avalosnon-blank or comment line after the magic line that identifies the
54679343712SPeter Avalosfile type, and has the following format:
54779343712SPeter Avalos.Bd -literal -offset indent
54879343712SPeter Avalos!:mime	MIMETYPE
54979343712SPeter Avalos.Ed
55079343712SPeter Avalos.Pp
55179343712SPeter Avalosi.e. the literal string
55279343712SPeter Avalos.Dq !:mime
55379343712SPeter Avalosfollowed by the MIME type.
55479343712SPeter Avalos.Pp
55579343712SPeter AvalosAn optional strength can be supplied on a separate line which refers to
55679343712SPeter Avalosthe current magic description using the following format:
55779343712SPeter Avalos.Bd -literal -offset indent
55879343712SPeter Avalos!:strength OP VALUE
55979343712SPeter Avalos.Ed
56079343712SPeter Avalos.Pp
56179343712SPeter AvalosThe operand
56279343712SPeter Avalos.Dv OP
56379343712SPeter Avaloscan be:
56479343712SPeter Avalos.Dv + ,
56579343712SPeter Avalos.Dv - ,
56679343712SPeter Avalos.Dv * ,
56779343712SPeter Avalosor
56879343712SPeter Avalos.Dv /
56979343712SPeter Avalosand
57079343712SPeter Avalos.Dv VALUE
57179343712SPeter Avalosis a constant between 0 and 255.
57279343712SPeter AvalosThis constant is applied using the specified operand
57379343712SPeter Avalosto the currently computed default magic strength.
57479343712SPeter Avalos.Pp
575327e51cbSPeter AvalosSome file formats contain additional information which is to be printed
576327e51cbSPeter Avalosalong with the file type or need additional tests to determine the true
577327e51cbSPeter Avalosfile type.
578327e51cbSPeter AvalosThese additional tests are introduced by one or more
579327e51cbSPeter Avalos.Em \*[Gt]
580327e51cbSPeter Avaloscharacters preceding the offset.
581327e51cbSPeter AvalosThe number of
582327e51cbSPeter Avalos.Em \*[Gt]
583327e51cbSPeter Avaloson the line indicates the level of the test; a line with no
584327e51cbSPeter Avalos.Em \*[Gt]
585327e51cbSPeter Avalosat the beginning is considered to be at level 0.
586327e51cbSPeter AvalosTests are arranged in a tree-like hierarchy:
587e4d4ce0cSPeter Avalosif the test on a line at level
588327e51cbSPeter Avalos.Em n
589327e51cbSPeter Avalossucceeds, all following tests at level
590327e51cbSPeter Avalos.Em n+1
591e4d4ce0cSPeter Avalosare performed, and the messages printed if the tests succeed, until a line
592327e51cbSPeter Avaloswith level
593327e51cbSPeter Avalos.Em n
594327e51cbSPeter Avalos(or less) appears.
595327e51cbSPeter AvalosFor more complex files, one can use empty messages to get just the
596327e51cbSPeter Avalos"if/then" effect, in the following way:
597327e51cbSPeter Avalos.Bd -literal -offset indent
598327e51cbSPeter Avalos0      string   MZ
599327e51cbSPeter Avalos\*[Gt]0x18  leshort  \*[Lt]0x40   MS-DOS executable
600327e51cbSPeter Avalos\*[Gt]0x18  leshort  \*[Gt]0x3f   extended PC executable (e.g., MS Windows)
601327e51cbSPeter Avalos.Ed
602327e51cbSPeter Avalos.Pp
603327e51cbSPeter AvalosOffsets do not need to be constant, but can also be read from the file
604327e51cbSPeter Avalosbeing examined.
605327e51cbSPeter AvalosIf the first character following the last
606327e51cbSPeter Avalos.Em \*[Gt]
607327e51cbSPeter Avalosis a
608e4d4ce0cSPeter Avalos.Em \&(
609327e51cbSPeter Avalosthen the string after the parenthesis is interpreted as an indirect offset.
610327e51cbSPeter AvalosThat means that the number after the parenthesis is used as an offset in
611327e51cbSPeter Avalosthe file.
612327e51cbSPeter AvalosThe value at that offset is read, and is used again as an offset
613327e51cbSPeter Avalosin the file.
614327e51cbSPeter AvalosIndirect offsets are of the form:
6156fca56fbSSascha Wildner.Em (( x [[.,][bBcCeEfFgGhHiIlmsSqQ]][+\-][ y ]) .
616327e51cbSPeter AvalosThe value of
617327e51cbSPeter Avalos.Em x
618327e51cbSPeter Avalosis used as an offset in the file.
61979343712SPeter AvalosA byte, id3 length, short or long is read at that offset depending on the
6206fca56fbSSascha Wildner.Em [bBcCeEfFgGhHiIlmsSqQ]
621327e51cbSPeter Avalostype specifier.
622c30bd091SSascha WildnerThe value is treated as signed if
623c30bd091SSascha Wildner.Dq ,
624c30bd091SSascha Wildneris specified or unsigned if
625c30bd091SSascha Wildner.Dq .
626c30bd091SSascha Wildneris specified.
627327e51cbSPeter AvalosThe capitalized types interpret the number as a big endian
628327e51cbSPeter Avalosvalue, whereas the small letter versions interpret the number as a little
629327e51cbSPeter Avalosendian value;
630327e51cbSPeter Avalosthe
631327e51cbSPeter Avalos.Em m
632327e51cbSPeter Avalostype interprets the number as a middle endian (PDP-11) value.
633327e51cbSPeter AvalosTo that number the value of
634327e51cbSPeter Avalos.Em y
635327e51cbSPeter Avalosis added and the result is used as an offset in the file.
636327e51cbSPeter AvalosThe default type if one is not specified is long.
6376fca56fbSSascha WildnerThe following types are recognized:
6386fca56fbSSascha Wildner.Bl -column -offset indent "Type" "Half/Short" "Little" "Size"
6396fca56fbSSascha Wildner.It Sy Type	Sy Mnemonic	Sy Endian	Sy Size
6406fca56fbSSascha Wildner.It bcBc	Byte/Char	N/A	1
6416fca56fbSSascha Wildner.It efg	Double	Little	8
6426fca56fbSSascha Wildner.It EFG	Double	Big	8
6436fca56fbSSascha Wildner.It hs	Half/Short	Little	2
6446fca56fbSSascha Wildner.It HS	Half/Short	Big	2
6456fca56fbSSascha Wildner.It i	ID3	Little	4
6466fca56fbSSascha Wildner.It I	ID3	Big	4
6476fca56fbSSascha Wildner.It m	Middle	Middle	4
6486fca56fbSSascha Wildner.It q	Quad	Little	8
6496fca56fbSSascha Wildner.It Q	Quad	Big	8
6506fca56fbSSascha Wildner.El
651327e51cbSPeter Avalos.Pp
652327e51cbSPeter AvalosThat way variable length structures can be examined:
653327e51cbSPeter Avalos.Bd -literal -offset indent
654327e51cbSPeter Avalos# MS Windows executables are also valid MS-DOS executables
655327e51cbSPeter Avalos0           string  MZ
656327e51cbSPeter Avalos\*[Gt]0x18       leshort \*[Lt]0x40   MZ executable (MS-DOS)
657327e51cbSPeter Avalos# skip the whole block below if it is not an extended executable
658327e51cbSPeter Avalos\*[Gt]0x18       leshort \*[Gt]0x3f
659327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l)  string  PE\e0\e0  PE executable (MS-Windows)
660327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l)  string  LX\e0\e0  LX executable (OS/2)
661327e51cbSPeter Avalos.Ed
662327e51cbSPeter Avalos.Pp
663c30bd091SSascha WildnerThis strategy of examining has a drawback: you must make sure that you
664c30bd091SSascha Wildnereventually print something, or users may get empty output (such as when
665c30bd091SSascha Wildnerthere is neither PE\e0\e0 nor LE\e0\e0 in the above example).
666327e51cbSPeter Avalos.Pp
66779343712SPeter AvalosIf this indirect offset cannot be used directly, simple calculations are
668327e51cbSPeter Avalospossible: appending
66979343712SPeter Avalos.Em [+-*/%\*[Am]|^]number
670327e51cbSPeter Avalosinside parentheses allows one to modify
671327e51cbSPeter Avalosthe value read from the file before it is used as an offset:
672327e51cbSPeter Avalos.Bd -literal -offset indent
673327e51cbSPeter Avalos# MS Windows executables are also valid MS-DOS executables
674327e51cbSPeter Avalos0           string  MZ
675327e51cbSPeter Avalos# sometimes, the value at 0x18 is less that 0x40 but there's still an
676327e51cbSPeter Avalos# extended executable, simply appended to the file
677327e51cbSPeter Avalos\*[Gt]0x18       leshort \*[Lt]0x40
678327e51cbSPeter Avalos\*[Gt]\*[Gt](4.s*512) leshort 0x014c  COFF executable (MS-DOS, DJGPP)
679327e51cbSPeter Avalos\*[Gt]\*[Gt](4.s*512) leshort !0x014c MZ executable (MS-DOS)
680327e51cbSPeter Avalos.Ed
681327e51cbSPeter Avalos.Pp
682327e51cbSPeter AvalosSometimes you do not know the exact offset as this depends on the length or
683327e51cbSPeter Avalosposition (when indirection was used before) of preceding fields.
684327e51cbSPeter AvalosYou can specify an offset relative to the end of the last up-level
685327e51cbSPeter Avalosfield using
686327e51cbSPeter Avalos.Sq \*[Am]
687327e51cbSPeter Avalosas a prefix to the offset:
688327e51cbSPeter Avalos.Bd -literal -offset indent
689327e51cbSPeter Avalos0           string  MZ
690327e51cbSPeter Avalos\*[Gt]0x18       leshort \*[Gt]0x3f
691327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l)  string  PE\e0\e0    PE executable (MS-Windows)
692327e51cbSPeter Avalos# immediately following the PE signature is the CPU type
693327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am]0       leshort 0x14c     for Intel 80386
694327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am]0       leshort 0x184     for DEC Alpha
695327e51cbSPeter Avalos.Ed
696327e51cbSPeter Avalos.Pp
697327e51cbSPeter AvalosIndirect and relative offsets can be combined:
698327e51cbSPeter Avalos.Bd -literal -offset indent
699327e51cbSPeter Avalos0             string  MZ
700327e51cbSPeter Avalos\*[Gt]0x18         leshort \*[Lt]0x40
701327e51cbSPeter Avalos\*[Gt]\*[Gt](4.s*512)   leshort !0x014c MZ executable (MS-DOS)
702327e51cbSPeter Avalos# if it's not COFF, go back 512 bytes and add the offset taken
703327e51cbSPeter Avalos# from byte 2/3, which is yet another way of finding the start
704327e51cbSPeter Avalos# of the extended executable
705327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am](2.s-514) string  LE      LE executable (MS Windows VxD driver)
706327e51cbSPeter Avalos.Ed
707327e51cbSPeter Avalos.Pp
708327e51cbSPeter AvalosOr the other way around:
709327e51cbSPeter Avalos.Bd -literal -offset indent
710327e51cbSPeter Avalos0                 string  MZ
711327e51cbSPeter Avalos\*[Gt]0x18             leshort \*[Gt]0x3f
712327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l)        string  LE\e0\e0  LE executable (MS-Windows)
713327e51cbSPeter Avalos# at offset 0x80 (-4, since relative offsets start at the end
714327e51cbSPeter Avalos# of the up-level match) inside the LE header, we find the absolute
715327e51cbSPeter Avalos# offset to the code area, where we look for a specific signature
716327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt](\*[Am]0x7c.l+0x26) string  UPX     \eb, UPX compressed
717327e51cbSPeter Avalos.Ed
718327e51cbSPeter Avalos.Pp
719327e51cbSPeter AvalosOr even both!
720327e51cbSPeter Avalos.Bd -literal -offset indent
721327e51cbSPeter Avalos0                string  MZ
722327e51cbSPeter Avalos\*[Gt]0x18            leshort \*[Gt]0x3f
723327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l)       string  LE\e0\e0 LE executable (MS-Windows)
724327e51cbSPeter Avalos# at offset 0x58 inside the LE header, we find the relative offset
725327e51cbSPeter Avalos# to a data area where we look for a specific signature
726327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am](\*[Am]0x54.l-3)  string  UNACE  \eb, ACE self-extracting archive
727327e51cbSPeter Avalos.Ed
728327e51cbSPeter Avalos.Pp
729e8af9738SPeter AvalosIf you have to deal with offset/length pairs in your file, even the
730327e51cbSPeter Avalossecond value in a parenthesized expression can be taken from the file itself,
731327e51cbSPeter Avalosusing another set of parentheses.
732327e51cbSPeter AvalosNote that this additional indirect offset is always relative to the
733327e51cbSPeter Avalosstart of the main indirect offset.
734327e51cbSPeter Avalos.Bd -literal -offset indent
735327e51cbSPeter Avalos0                 string       MZ
736327e51cbSPeter Avalos\*[Gt]0x18             leshort      \*[Gt]0x3f
737327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l)        string       PE\e0\e0 PE executable (MS-Windows)
738327e51cbSPeter Avalos# search for the PE section called ".idata"...
739327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am]0xf4          search/0x140 .idata
740327e51cbSPeter Avalos# ...and go to the end of it, calculated from start+length;
741327e51cbSPeter Avalos# these are located 14 and 10 bytes after the section name
742327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Gt](\*[Am]0xe.l+(-4)) string       PK\e3\e4 \eb, ZIP self-extracting archive
743327e51cbSPeter Avalos.Ed
744e8af9738SPeter Avalos.Pp
745c30bd091SSascha WildnerIf you have a list of known values at a particular continuation level,
746e8af9738SPeter Avalosand you want to provide a switch-like default case:
747e8af9738SPeter Avalos.Bd -literal -offset indent
748e8af9738SPeter Avalos# clear that continuation level match
749e8af9738SPeter Avalos\*[Gt]18	clear
750e8af9738SPeter Avalos\*[Gt]18	lelong	1	one
751e8af9738SPeter Avalos\*[Gt]18	lelong	2	two
752e8af9738SPeter Avalos\*[Gt]18	default	x
753e8af9738SPeter Avalos# print default match
754e8af9738SPeter Avalos\*[Gt]\*[Gt]18	lelong	x	unmatched 0x%x
755e8af9738SPeter Avalos.Ed
756327e51cbSPeter Avalos.Sh SEE ALSO
757327e51cbSPeter Avalos.Xr file __CSECTION__
758327e51cbSPeter Avalos\- the command that reads this file.
759327e51cbSPeter Avalos.Sh BUGS
760327e51cbSPeter AvalosThe formats
761327e51cbSPeter Avalos.Dv long ,
762327e51cbSPeter Avalos.Dv belong ,
763327e51cbSPeter Avalos.Dv lelong ,
764327e51cbSPeter Avalos.Dv melong ,
765327e51cbSPeter Avalos.Dv short ,
766327e51cbSPeter Avalos.Dv beshort ,
767327e51cbSPeter Avalosand
768e8af9738SPeter Avalos.Dv leshort
769e8af9738SPeter Avalosdo not depend on the length of the C data types
770e8af9738SPeter Avalos.Dv short
771e8af9738SPeter Avalosand
772e8af9738SPeter Avalos.Dv long
773e8af9738SPeter Avaloson the platform, even though the Single
774e8af9738SPeter Avalos.Ux
775e8af9738SPeter AvalosSpecification implies that they do.  However, as OS X Mountain Lion has
776e8af9738SPeter Avalospassed the Single
777e8af9738SPeter Avalos.Ux
778e8af9738SPeter AvalosSpecification validation suite, and supplies a version of
779e8af9738SPeter Avalos.Xr file __CSECTION__
780e8af9738SPeter Avalosin which they do not depend on the sizes of the C data types and that is
781e8af9738SPeter Avalosbuilt for a 64-bit environment in which
782e8af9738SPeter Avalos.Dv long
783e8af9738SPeter Avalosis 8 bytes rather than 4 bytes, presumably the validation suite does not
784e8af9738SPeter Avalostest whether, for example
785e8af9738SPeter Avalos.Dv long
786e8af9738SPeter Avalosrefers to an item with the same size as the C data type
787e8af9738SPeter Avalos.Dv long .
788e8af9738SPeter AvalosThere should probably be
789e8af9738SPeter Avalos.Dv type
790e8af9738SPeter Avalosnames
791e8af9738SPeter Avalos.Dv int8 ,
792e8af9738SPeter Avalos.Dv uint8 ,
793e8af9738SPeter Avalos.Dv int16 ,
794e8af9738SPeter Avalos.Dv uint16 ,
795e8af9738SPeter Avalos.Dv int32 ,
796e8af9738SPeter Avalos.Dv uint32 ,
797e8af9738SPeter Avalos.Dv int64 ,
798e8af9738SPeter Avalosand
799e8af9738SPeter Avalos.Dv uint64 ,
800e8af9738SPeter Avalosand specified-byte-order variants of them,
801e8af9738SPeter Avalosto make it clearer that those types have specified widths.
802327e51cbSPeter Avalos.\"
803327e51cbSPeter Avalos.\" From: guy@sun.uucp (Guy Harris)
804327e51cbSPeter Avalos.\" Newsgroups: net.bugs.usg
805327e51cbSPeter Avalos.\" Subject: /etc/magic's format isn't well documented
806327e51cbSPeter Avalos.\" Message-ID: <2752@sun.uucp>
807327e51cbSPeter Avalos.\" Date: 3 Sep 85 08:19:07 GMT
808327e51cbSPeter Avalos.\" Organization: Sun Microsystems, Inc.
809327e51cbSPeter Avalos.\" Lines: 136
810327e51cbSPeter Avalos.\"
811327e51cbSPeter Avalos.\" Here's a manual page for the format accepted by the "file" made by adding
812327e51cbSPeter Avalos.\" the changes I posted to the S5R2 version.
813327e51cbSPeter Avalos.\"
814327e51cbSPeter Avalos.\" Modified for Ian Darwin's version of the file command.
815