1*3b9cdfa3SAntonio Huete Jimenez.\" $File: magic.man,v 1.100 2022/09/10 13:19:26 christos Exp $ 2*3b9cdfa3SAntonio Huete Jimenez.Dd September 10, 2022 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 72614728caSSascha 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 86614728caSSascha Wildner.Dq f 87614728caSSascha Wildnerflags requires that the matched string is a full word, not a partial word match. 88614728caSSascha 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 362*3b9cdfa3SAntonio Huete Jimenez.It Dv octal 363*3b9cdfa3SAntonio Huete JimenezA string representing an octal number. 364*3b9cdfa3SAntonio Huete Jimenez.El 365327e51cbSPeter Avalos.El 36679343712SPeter Avalos.Pp 367e8af9738SPeter AvalosFor compatibility with the Single 368e8af9738SPeter Avalos.Ux 369e8af9738SPeter AvalosStandard, the type specifiers 370e8af9738SPeter Avalos.Dv dC 371e8af9738SPeter Avalosand 372e8af9738SPeter Avalos.Dv d1 373e8af9738SPeter Avalosare equivalent to 374e8af9738SPeter Avalos.Dv byte , 375e8af9738SPeter Avalosthe type specifiers 376e8af9738SPeter Avalos.Dv uC 377e8af9738SPeter Avalosand 378e8af9738SPeter Avalos.Dv u1 379e8af9738SPeter Avalosare equivalent to 380e8af9738SPeter Avalos.Dv ubyte , 381e8af9738SPeter Avalosthe type specifiers 382e8af9738SPeter Avalos.Dv dS 383e8af9738SPeter Avalosand 384e8af9738SPeter Avalos.Dv d2 385e8af9738SPeter Avalosare equivalent to 386e8af9738SPeter Avalos.Dv short , 387e8af9738SPeter Avalosthe type specifiers 388e8af9738SPeter Avalos.Dv uS 389e8af9738SPeter Avalosand 390e8af9738SPeter Avalos.Dv u2 391e8af9738SPeter Avalosare equivalent to 392e8af9738SPeter Avalos.Dv ushort , 393e8af9738SPeter Avalosthe type specifiers 394e8af9738SPeter Avalos.Dv dI , 395e8af9738SPeter Avalos.Dv dL , 396e8af9738SPeter Avalosand 397e8af9738SPeter Avalos.Dv d4 398e8af9738SPeter Avalosare equivalent to 399e8af9738SPeter Avalos.Dv long , 400e8af9738SPeter Avalosthe type specifiers 401e8af9738SPeter Avalos.Dv uI , 402e8af9738SPeter Avalos.Dv uL , 403e8af9738SPeter Avalosand 404e8af9738SPeter Avalos.Dv u4 405e8af9738SPeter Avalosare equivalent to 406e8af9738SPeter Avalos.Dv ulong , 407e8af9738SPeter Avalosthe type specifier 408e8af9738SPeter Avalos.Dv d8 409e8af9738SPeter Avalosis equivalent to 410e8af9738SPeter Avalos.Dv quad , 411e8af9738SPeter Avalosthe type specifier 412e8af9738SPeter Avalos.Dv u8 413e8af9738SPeter Avalosis equivalent to 414e8af9738SPeter Avalos.Dv uquad , 415e8af9738SPeter Avalosand the type specifier 416e8af9738SPeter Avalos.Dv s 417e8af9738SPeter Avalosis equivalent to 418e8af9738SPeter Avalos.Dv string . 419e8af9738SPeter AvalosIn addition, the type specifier 420e8af9738SPeter Avalos.Dv dQ 421e8af9738SPeter Avalosis equivalent to 422e8af9738SPeter Avalos.Dv quad 423e8af9738SPeter Avalosand the type specifier 424e8af9738SPeter Avalos.Dv uQ 425e8af9738SPeter Avalosis equivalent to 426e8af9738SPeter Avalos.Dv uquad . 427e8af9738SPeter Avalos.Pp 42879343712SPeter AvalosEach top-level magic pattern (see below for an explanation of levels) 429a96e001bSPeter Avalosis classified as text or binary according to the types used. 430a96e001bSPeter AvalosTypes 43179343712SPeter Avalos.Dq regex 43279343712SPeter Avalosand 43379343712SPeter Avalos.Dq search 43479343712SPeter Avalosare classified as text tests, unless non-printable characters are used 435a96e001bSPeter Avalosin the pattern. 436a96e001bSPeter AvalosAll other tests are classified as binary. 437a96e001bSPeter AvalosA top-level 43879343712SPeter Avalospattern is considered to be a test text when all its patterns are text 439a96e001bSPeter Avalospatterns; otherwise, it is considered to be a binary pattern. 440a96e001bSPeter AvalosWhen 44179343712SPeter Avalosmatching a file, binary patterns are tried first; if no match is 44279343712SPeter Avalosfound, and the file looks like text, then its encoding is determined 44379343712SPeter Avalosand the text patterns are tried. 444327e51cbSPeter Avalos.Pp 445327e51cbSPeter AvalosThe numeric types may optionally be followed by 446327e51cbSPeter Avalos.Dv \*[Am] 447327e51cbSPeter Avalosand a numeric value, 448327e51cbSPeter Avalosto specify that the value is to be AND'ed with the 449327e51cbSPeter Avalosnumeric value before any comparisons are done. 450327e51cbSPeter AvalosPrepending a 451327e51cbSPeter Avalos.Dv u 452327e51cbSPeter Avalosto the type indicates that ordered comparisons should be unsigned. 453327e51cbSPeter Avalos.It Dv test 454327e51cbSPeter AvalosThe value to be compared with the value from the file. 455327e51cbSPeter AvalosIf the type is 456327e51cbSPeter Avalosnumeric, this value 457327e51cbSPeter Avalosis specified in C form; if it is a string, it is specified as a C string 458327e51cbSPeter Avaloswith the usual escapes permitted (e.g. \en for new-line). 459327e51cbSPeter Avalos.Pp 460327e51cbSPeter AvalosNumeric values 461327e51cbSPeter Avalosmay be preceded by a character indicating the operation to be performed. 462327e51cbSPeter AvalosIt may be 463327e51cbSPeter Avalos.Dv = , 464327e51cbSPeter Avalosto specify that the value from the file must equal the specified value, 465327e51cbSPeter Avalos.Dv \*[Lt] , 466327e51cbSPeter Avalosto specify that the value from the file must be less than the specified 467327e51cbSPeter Avalosvalue, 468327e51cbSPeter Avalos.Dv \*[Gt] , 469327e51cbSPeter Avalosto specify that the value from the file must be greater than the specified 470327e51cbSPeter Avalosvalue, 471327e51cbSPeter Avalos.Dv \*[Am] , 472327e51cbSPeter Avalosto specify that the value from the file must have set all of the bits 473327e51cbSPeter Avalosthat are set in the specified value, 474327e51cbSPeter Avalos.Dv ^ , 475327e51cbSPeter Avalosto specify that the value from the file must have clear any of the bits 476327e51cbSPeter Avalosthat are set in the specified value, or 477327e51cbSPeter Avalos.Dv ~ , 478327e51cbSPeter Avalosthe value specified after is negated before tested. 479327e51cbSPeter Avalos.Dv x , 480327e51cbSPeter Avalosto specify that any value will match. 481327e51cbSPeter AvalosIf the character is omitted, it is assumed to be 482327e51cbSPeter Avalos.Dv = . 483327e51cbSPeter AvalosOperators 484327e51cbSPeter Avalos.Dv \*[Am] , 485327e51cbSPeter Avalos.Dv ^ , 486327e51cbSPeter Avalosand 487327e51cbSPeter Avalos.Dv ~ 488327e51cbSPeter Avalosdon't work with floats and doubles. 48979343712SPeter AvalosThe operator 49079343712SPeter Avalos.Dv !\& 491327e51cbSPeter Avalosspecifies that the line matches if the test does 492327e51cbSPeter Avalos.Em not 493327e51cbSPeter Avalossucceed. 494327e51cbSPeter Avalos.Pp 495327e51cbSPeter AvalosNumeric values are specified in C form; e.g. 496327e51cbSPeter Avalos.Dv 13 497327e51cbSPeter Avalosis decimal, 498327e51cbSPeter Avalos.Dv 013 499327e51cbSPeter Avalosis octal, and 500327e51cbSPeter Avalos.Dv 0x13 501327e51cbSPeter Avalosis hexadecimal. 502327e51cbSPeter Avalos.Pp 50382c5fa3eSPeter AvalosNumeric operations are not performed on date types, instead the numeric 50482c5fa3eSPeter Avalosvalue is interpreted as an offset. 50582c5fa3eSPeter Avalos.Pp 50679343712SPeter AvalosFor string values, the string from the 50779343712SPeter Avalosfile must match the specified string. 508327e51cbSPeter AvalosThe operators 509327e51cbSPeter Avalos.Dv = , 510327e51cbSPeter Avalos.Dv \*[Lt] 511327e51cbSPeter Avalosand 512327e51cbSPeter Avalos.Dv \*[Gt] 513327e51cbSPeter Avalos(but not 514327e51cbSPeter Avalos.Dv \*[Am] ) 515327e51cbSPeter Avaloscan be applied to strings. 516327e51cbSPeter AvalosThe length used for matching is that of the string argument 517327e51cbSPeter Avalosin the magic file. 51879343712SPeter AvalosThis means that a line can match any non-empty string (usually used to 51979343712SPeter Avalosthen print the string), with 520327e51cbSPeter Avalos.Em \*[Gt]\e0 52179343712SPeter Avalos(because all non-empty strings are greater than the empty string). 522327e51cbSPeter Avalos.Pp 523e8af9738SPeter AvalosDates are treated as numerical values in the respective internal 524e8af9738SPeter Avalosrepresentation. 525e8af9738SPeter Avalos.Pp 526327e51cbSPeter AvalosThe special test 527327e51cbSPeter Avalos.Em x 528327e51cbSPeter Avalosalways evaluates to true. 529e4d4ce0cSPeter Avalos.It Dv message 530327e51cbSPeter AvalosThe message to be printed if the comparison succeeds. 531327e51cbSPeter AvalosIf the string contains a 532327e51cbSPeter Avalos.Xr printf 3 533327e51cbSPeter Avalosformat specification, the value from the file (with any specified masking 534327e51cbSPeter Avalosperformed) is printed using the message as the format string. 53579343712SPeter AvalosIf the string begins with 53679343712SPeter Avalos.Dq \eb , 53779343712SPeter Avalosthe message printed is the remainder of the string with no whitespace 53879343712SPeter Avalosadded before it: multiple matches are normally separated by a single 53979343712SPeter Avalosspace. 540327e51cbSPeter Avalos.El 541327e51cbSPeter Avalos.Pp 54279343712SPeter AvalosAn APPLE 4+4 character APPLE creator and type can be specified as: 54379343712SPeter Avalos.Bd -literal -offset indent 54479343712SPeter Avalos!:apple CREATYPE 54579343712SPeter Avalos.Ed 54679343712SPeter Avalos.Pp 54779343712SPeter AvalosA MIME type is given on a separate line, which must be the next 54879343712SPeter Avalosnon-blank or comment line after the magic line that identifies the 54979343712SPeter Avalosfile type, and has the following format: 55079343712SPeter Avalos.Bd -literal -offset indent 55179343712SPeter Avalos!:mime MIMETYPE 55279343712SPeter Avalos.Ed 55379343712SPeter Avalos.Pp 55479343712SPeter Avalosi.e. the literal string 55579343712SPeter Avalos.Dq !:mime 55679343712SPeter Avalosfollowed by the MIME type. 55779343712SPeter Avalos.Pp 55879343712SPeter AvalosAn optional strength can be supplied on a separate line which refers to 55979343712SPeter Avalosthe current magic description using the following format: 56079343712SPeter Avalos.Bd -literal -offset indent 56179343712SPeter Avalos!:strength OP VALUE 56279343712SPeter Avalos.Ed 56379343712SPeter Avalos.Pp 56479343712SPeter AvalosThe operand 56579343712SPeter Avalos.Dv OP 56679343712SPeter Avaloscan be: 56779343712SPeter Avalos.Dv + , 56879343712SPeter Avalos.Dv - , 56979343712SPeter Avalos.Dv * , 57079343712SPeter Avalosor 57179343712SPeter Avalos.Dv / 57279343712SPeter Avalosand 57379343712SPeter Avalos.Dv VALUE 57479343712SPeter Avalosis a constant between 0 and 255. 57579343712SPeter AvalosThis constant is applied using the specified operand 57679343712SPeter Avalosto the currently computed default magic strength. 57779343712SPeter Avalos.Pp 578327e51cbSPeter AvalosSome file formats contain additional information which is to be printed 579327e51cbSPeter Avalosalong with the file type or need additional tests to determine the true 580327e51cbSPeter Avalosfile type. 581327e51cbSPeter AvalosThese additional tests are introduced by one or more 582327e51cbSPeter Avalos.Em \*[Gt] 583327e51cbSPeter Avaloscharacters preceding the offset. 584327e51cbSPeter AvalosThe number of 585327e51cbSPeter Avalos.Em \*[Gt] 586327e51cbSPeter Avaloson the line indicates the level of the test; a line with no 587327e51cbSPeter Avalos.Em \*[Gt] 588327e51cbSPeter Avalosat the beginning is considered to be at level 0. 589327e51cbSPeter AvalosTests are arranged in a tree-like hierarchy: 590e4d4ce0cSPeter Avalosif the test on a line at level 591327e51cbSPeter Avalos.Em n 592327e51cbSPeter Avalossucceeds, all following tests at level 593327e51cbSPeter Avalos.Em n+1 594e4d4ce0cSPeter Avalosare performed, and the messages printed if the tests succeed, until a line 595327e51cbSPeter Avaloswith level 596327e51cbSPeter Avalos.Em n 597327e51cbSPeter Avalos(or less) appears. 598327e51cbSPeter AvalosFor more complex files, one can use empty messages to get just the 599327e51cbSPeter Avalos"if/then" effect, in the following way: 600327e51cbSPeter Avalos.Bd -literal -offset indent 601327e51cbSPeter Avalos0 string MZ 602327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Lt]0x40 MS-DOS executable 603327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Gt]0x3f extended PC executable (e.g., MS Windows) 604327e51cbSPeter Avalos.Ed 605327e51cbSPeter Avalos.Pp 606327e51cbSPeter AvalosOffsets do not need to be constant, but can also be read from the file 607327e51cbSPeter Avalosbeing examined. 608327e51cbSPeter AvalosIf the first character following the last 609327e51cbSPeter Avalos.Em \*[Gt] 610327e51cbSPeter Avalosis a 611e4d4ce0cSPeter Avalos.Em \&( 612327e51cbSPeter Avalosthen the string after the parenthesis is interpreted as an indirect offset. 613327e51cbSPeter AvalosThat means that the number after the parenthesis is used as an offset in 614327e51cbSPeter Avalosthe file. 615327e51cbSPeter AvalosThe value at that offset is read, and is used again as an offset 616327e51cbSPeter Avalosin the file. 617327e51cbSPeter AvalosIndirect offsets are of the form: 6186fca56fbSSascha Wildner.Em (( x [[.,][bBcCeEfFgGhHiIlmsSqQ]][+\-][ y ]) . 619327e51cbSPeter AvalosThe value of 620327e51cbSPeter Avalos.Em x 621327e51cbSPeter Avalosis used as an offset in the file. 62279343712SPeter AvalosA byte, id3 length, short or long is read at that offset depending on the 6236fca56fbSSascha Wildner.Em [bBcCeEfFgGhHiIlmsSqQ] 624327e51cbSPeter Avalostype specifier. 625c30bd091SSascha WildnerThe value is treated as signed if 626c30bd091SSascha Wildner.Dq , 627c30bd091SSascha Wildneris specified or unsigned if 628c30bd091SSascha Wildner.Dq . 629c30bd091SSascha Wildneris specified. 630327e51cbSPeter AvalosThe capitalized types interpret the number as a big endian 631327e51cbSPeter Avalosvalue, whereas the small letter versions interpret the number as a little 632327e51cbSPeter Avalosendian value; 633327e51cbSPeter Avalosthe 634327e51cbSPeter Avalos.Em m 635327e51cbSPeter Avalostype interprets the number as a middle endian (PDP-11) value. 636327e51cbSPeter AvalosTo that number the value of 637327e51cbSPeter Avalos.Em y 638327e51cbSPeter Avalosis added and the result is used as an offset in the file. 639327e51cbSPeter AvalosThe default type if one is not specified is long. 6406fca56fbSSascha WildnerThe following types are recognized: 6416fca56fbSSascha Wildner.Bl -column -offset indent "Type" "Half/Short" "Little" "Size" 6426fca56fbSSascha Wildner.It Sy Type Sy Mnemonic Sy Endian Sy Size 6436fca56fbSSascha Wildner.It bcBc Byte/Char N/A 1 6446fca56fbSSascha Wildner.It efg Double Little 8 6456fca56fbSSascha Wildner.It EFG Double Big 8 6466fca56fbSSascha Wildner.It hs Half/Short Little 2 6476fca56fbSSascha Wildner.It HS Half/Short Big 2 6486fca56fbSSascha Wildner.It i ID3 Little 4 6496fca56fbSSascha Wildner.It I ID3 Big 4 6506fca56fbSSascha Wildner.It m Middle Middle 4 651*3b9cdfa3SAntonio Huete Jimenez.It o Octal Textual Variable 6526fca56fbSSascha Wildner.It q Quad Little 8 6536fca56fbSSascha Wildner.It Q Quad Big 8 6546fca56fbSSascha Wildner.El 655327e51cbSPeter Avalos.Pp 656327e51cbSPeter AvalosThat way variable length structures can be examined: 657327e51cbSPeter Avalos.Bd -literal -offset indent 658327e51cbSPeter Avalos# MS Windows executables are also valid MS-DOS executables 659327e51cbSPeter Avalos0 string MZ 660327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Lt]0x40 MZ executable (MS-DOS) 661327e51cbSPeter Avalos# skip the whole block below if it is not an extended executable 662327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Gt]0x3f 663327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l) string PE\e0\e0 PE executable (MS-Windows) 664327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l) string LX\e0\e0 LX executable (OS/2) 665327e51cbSPeter Avalos.Ed 666327e51cbSPeter Avalos.Pp 667c30bd091SSascha WildnerThis strategy of examining has a drawback: you must make sure that you 668c30bd091SSascha Wildnereventually print something, or users may get empty output (such as when 669c30bd091SSascha Wildnerthere is neither PE\e0\e0 nor LE\e0\e0 in the above example). 670327e51cbSPeter Avalos.Pp 67179343712SPeter AvalosIf this indirect offset cannot be used directly, simple calculations are 672327e51cbSPeter Avalospossible: appending 67379343712SPeter Avalos.Em [+-*/%\*[Am]|^]number 674327e51cbSPeter Avalosinside parentheses allows one to modify 675327e51cbSPeter Avalosthe value read from the file before it is used as an offset: 676327e51cbSPeter Avalos.Bd -literal -offset indent 677327e51cbSPeter Avalos# MS Windows executables are also valid MS-DOS executables 678327e51cbSPeter Avalos0 string MZ 679327e51cbSPeter Avalos# sometimes, the value at 0x18 is less that 0x40 but there's still an 680327e51cbSPeter Avalos# extended executable, simply appended to the file 681327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Lt]0x40 682327e51cbSPeter Avalos\*[Gt]\*[Gt](4.s*512) leshort 0x014c COFF executable (MS-DOS, DJGPP) 683327e51cbSPeter Avalos\*[Gt]\*[Gt](4.s*512) leshort !0x014c MZ executable (MS-DOS) 684327e51cbSPeter Avalos.Ed 685327e51cbSPeter Avalos.Pp 686327e51cbSPeter AvalosSometimes you do not know the exact offset as this depends on the length or 687327e51cbSPeter Avalosposition (when indirection was used before) of preceding fields. 688327e51cbSPeter AvalosYou can specify an offset relative to the end of the last up-level 689327e51cbSPeter Avalosfield using 690327e51cbSPeter Avalos.Sq \*[Am] 691327e51cbSPeter Avalosas a prefix to the offset: 692327e51cbSPeter Avalos.Bd -literal -offset indent 693327e51cbSPeter Avalos0 string MZ 694327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Gt]0x3f 695327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l) string PE\e0\e0 PE executable (MS-Windows) 696327e51cbSPeter Avalos# immediately following the PE signature is the CPU type 697327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am]0 leshort 0x14c for Intel 80386 698327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am]0 leshort 0x184 for DEC Alpha 699327e51cbSPeter Avalos.Ed 700327e51cbSPeter Avalos.Pp 701327e51cbSPeter AvalosIndirect and relative offsets can be combined: 702327e51cbSPeter Avalos.Bd -literal -offset indent 703327e51cbSPeter Avalos0 string MZ 704327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Lt]0x40 705327e51cbSPeter Avalos\*[Gt]\*[Gt](4.s*512) leshort !0x014c MZ executable (MS-DOS) 706327e51cbSPeter Avalos# if it's not COFF, go back 512 bytes and add the offset taken 707327e51cbSPeter Avalos# from byte 2/3, which is yet another way of finding the start 708327e51cbSPeter Avalos# of the extended executable 709327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am](2.s-514) string LE LE executable (MS Windows VxD driver) 710327e51cbSPeter Avalos.Ed 711327e51cbSPeter Avalos.Pp 712327e51cbSPeter AvalosOr the other way around: 713327e51cbSPeter Avalos.Bd -literal -offset indent 714327e51cbSPeter Avalos0 string MZ 715327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Gt]0x3f 716327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l) string LE\e0\e0 LE executable (MS-Windows) 717327e51cbSPeter Avalos# at offset 0x80 (-4, since relative offsets start at the end 718327e51cbSPeter Avalos# of the up-level match) inside the LE header, we find the absolute 719327e51cbSPeter Avalos# offset to the code area, where we look for a specific signature 720327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt](\*[Am]0x7c.l+0x26) string UPX \eb, UPX compressed 721327e51cbSPeter Avalos.Ed 722327e51cbSPeter Avalos.Pp 723327e51cbSPeter AvalosOr even both! 724327e51cbSPeter Avalos.Bd -literal -offset indent 725327e51cbSPeter Avalos0 string MZ 726327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Gt]0x3f 727327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l) string LE\e0\e0 LE executable (MS-Windows) 728327e51cbSPeter Avalos# at offset 0x58 inside the LE header, we find the relative offset 729327e51cbSPeter Avalos# to a data area where we look for a specific signature 730327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am](\*[Am]0x54.l-3) string UNACE \eb, ACE self-extracting archive 731327e51cbSPeter Avalos.Ed 732327e51cbSPeter Avalos.Pp 733e8af9738SPeter AvalosIf you have to deal with offset/length pairs in your file, even the 734327e51cbSPeter Avalossecond value in a parenthesized expression can be taken from the file itself, 735327e51cbSPeter Avalosusing another set of parentheses. 736327e51cbSPeter AvalosNote that this additional indirect offset is always relative to the 737327e51cbSPeter Avalosstart of the main indirect offset. 738327e51cbSPeter Avalos.Bd -literal -offset indent 739327e51cbSPeter Avalos0 string MZ 740327e51cbSPeter Avalos\*[Gt]0x18 leshort \*[Gt]0x3f 741327e51cbSPeter Avalos\*[Gt]\*[Gt](0x3c.l) string PE\e0\e0 PE executable (MS-Windows) 742327e51cbSPeter Avalos# search for the PE section called ".idata"... 743327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Am]0xf4 search/0x140 .idata 744327e51cbSPeter Avalos# ...and go to the end of it, calculated from start+length; 745327e51cbSPeter Avalos# these are located 14 and 10 bytes after the section name 746327e51cbSPeter Avalos\*[Gt]\*[Gt]\*[Gt]\*[Gt](\*[Am]0xe.l+(-4)) string PK\e3\e4 \eb, ZIP self-extracting archive 747327e51cbSPeter Avalos.Ed 748e8af9738SPeter Avalos.Pp 749c30bd091SSascha WildnerIf you have a list of known values at a particular continuation level, 750e8af9738SPeter Avalosand you want to provide a switch-like default case: 751e8af9738SPeter Avalos.Bd -literal -offset indent 752e8af9738SPeter Avalos# clear that continuation level match 753e8af9738SPeter Avalos\*[Gt]18 clear 754e8af9738SPeter Avalos\*[Gt]18 lelong 1 one 755e8af9738SPeter Avalos\*[Gt]18 lelong 2 two 756e8af9738SPeter Avalos\*[Gt]18 default x 757e8af9738SPeter Avalos# print default match 758e8af9738SPeter Avalos\*[Gt]\*[Gt]18 lelong x unmatched 0x%x 759e8af9738SPeter Avalos.Ed 760327e51cbSPeter Avalos.Sh SEE ALSO 761327e51cbSPeter Avalos.Xr file __CSECTION__ 762327e51cbSPeter Avalos\- the command that reads this file. 763327e51cbSPeter Avalos.Sh BUGS 764327e51cbSPeter AvalosThe formats 765327e51cbSPeter Avalos.Dv long , 766327e51cbSPeter Avalos.Dv belong , 767327e51cbSPeter Avalos.Dv lelong , 768327e51cbSPeter Avalos.Dv melong , 769327e51cbSPeter Avalos.Dv short , 770327e51cbSPeter Avalos.Dv beshort , 771327e51cbSPeter Avalosand 772e8af9738SPeter Avalos.Dv leshort 773e8af9738SPeter Avalosdo not depend on the length of the C data types 774e8af9738SPeter Avalos.Dv short 775e8af9738SPeter Avalosand 776e8af9738SPeter Avalos.Dv long 777e8af9738SPeter Avaloson the platform, even though the Single 778e8af9738SPeter Avalos.Ux 779e8af9738SPeter AvalosSpecification implies that they do. However, as OS X Mountain Lion has 780e8af9738SPeter Avalospassed the Single 781e8af9738SPeter Avalos.Ux 782e8af9738SPeter AvalosSpecification validation suite, and supplies a version of 783e8af9738SPeter Avalos.Xr file __CSECTION__ 784e8af9738SPeter Avalosin which they do not depend on the sizes of the C data types and that is 785e8af9738SPeter Avalosbuilt for a 64-bit environment in which 786e8af9738SPeter Avalos.Dv long 787e8af9738SPeter Avalosis 8 bytes rather than 4 bytes, presumably the validation suite does not 788e8af9738SPeter Avalostest whether, for example 789e8af9738SPeter Avalos.Dv long 790e8af9738SPeter Avalosrefers to an item with the same size as the C data type 791e8af9738SPeter Avalos.Dv long . 792e8af9738SPeter AvalosThere should probably be 793e8af9738SPeter Avalos.Dv type 794e8af9738SPeter Avalosnames 795e8af9738SPeter Avalos.Dv int8 , 796e8af9738SPeter Avalos.Dv uint8 , 797e8af9738SPeter Avalos.Dv int16 , 798e8af9738SPeter Avalos.Dv uint16 , 799e8af9738SPeter Avalos.Dv int32 , 800e8af9738SPeter Avalos.Dv uint32 , 801e8af9738SPeter Avalos.Dv int64 , 802e8af9738SPeter Avalosand 803e8af9738SPeter Avalos.Dv uint64 , 804e8af9738SPeter Avalosand specified-byte-order variants of them, 805e8af9738SPeter Avalosto make it clearer that those types have specified widths. 806327e51cbSPeter Avalos.\" 807327e51cbSPeter Avalos.\" From: guy@sun.uucp (Guy Harris) 808327e51cbSPeter Avalos.\" Newsgroups: net.bugs.usg 809327e51cbSPeter Avalos.\" Subject: /etc/magic's format isn't well documented 810327e51cbSPeter Avalos.\" Message-ID: <2752@sun.uucp> 811327e51cbSPeter Avalos.\" Date: 3 Sep 85 08:19:07 GMT 812327e51cbSPeter Avalos.\" Organization: Sun Microsystems, Inc. 813327e51cbSPeter Avalos.\" Lines: 136 814327e51cbSPeter Avalos.\" 815327e51cbSPeter Avalos.\" Here's a manual page for the format accepted by the "file" made by adding 816327e51cbSPeter Avalos.\" the changes I posted to the S5R2 version. 817327e51cbSPeter Avalos.\" 818327e51cbSPeter Avalos.\" Modified for Ian Darwin's version of the file command. 819