1a77ebd86Schristos## README for file(1) Command and the libmagic(3) library ## 2a77ebd86Schristos 3*e15daa8bSchristos @(#) $File: README.md,v 1.5 2023/05/28 13:59:47 christos Exp $ 4a77ebd86Schristos 5a77ebd86Schristos- Bug Tracker: <https://bugs.astron.com/> 6a77ebd86Schristos- Build Status: <https://travis-ci.org/file/file> 7a77ebd86Schristos- Download link: <ftp://ftp.astron.com/pub/file/> 8a77ebd86Schristos- E-mail: <christos@astron.com> 9a77ebd86Schristos- Fuzzing link: <https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:file> 10a77ebd86Schristos- Home page: https://www.darwinsys.com/file/ 11a77ebd86Schristos- Mailing List archives: <https://mailman.astron.com/pipermail/file/> 12a77ebd86Schristos- Mailing List: <file@astron.com> 13a77ebd86Schristos- Public repo: <https://github.com/file/file> 14a77ebd86Schristos- Test framework: <https://github.com/file/file-tests> 15a77ebd86Schristos 16a77ebd86SchristosPhone: Do not even think of telephoning me about this program. Send 17a77ebd86Schristoscash first! 18a77ebd86Schristos 19a77ebd86SchristosThis is Release 5.x of Ian Darwin's (copyright but distributable) 20a77ebd86Schristosfile(1) command, an implementation of the Unix File(1) command. 21a77ebd86SchristosIt knows the 'magic number' of several thousands of file types. 22a77ebd86SchristosThis version is the standard "file" command for Linux, *BSD, and 23a77ebd86Schristosother systems. (See "patchlevel.h" for the exact release number). 24a77ebd86Schristos 25a77ebd86SchristosThe major changes for 5.x are CDF file parsing, indirect magic, 26a77ebd86Schristosname/use (recursion) and overhaul in mime and ascii encoding 27a77ebd86Schristoshandling. 28a77ebd86Schristos 29a77ebd86SchristosThe major feature of 4.x is the refactoring of the code into a 30a77ebd86Schristoslibrary, and the re-write of the file command in terms of that 31a77ebd86Schristoslibrary. The library itself, libmagic can be used by 3rd party 32a77ebd86Schristosprograms that wish to identify file types without having to fork() 33a77ebd86Schristosand exec() file. The prime contributor for 4.0 was Mans Rullgard. 34a77ebd86Schristos 35a77ebd86SchristosUNIX is a trademark of UNIX System Laboratories. 36a77ebd86Schristos 37a77ebd86SchristosThe prime contributor to Release 3.8 was Guy Harris, who put in 38a77ebd86Schristosmegachanges including byte-order independence. 39a77ebd86Schristos 40a77ebd86SchristosThe prime contributor to Release 3.0 was Christos Zoulas, who put 41a77ebd86Schristosin hundreds of lines of source code changes, including his own 42a77ebd86SchristosANSIfication of the code (I liked my own ANSIfication better, but 43a77ebd86Schristoshis (__P()) is the "Berkeley standard" way of doing it, and I wanted 44a77ebd86SchristosUCB to include the code...), his HP-like "indirection" (a feature 45a77ebd86Schristosof the HP file command, I think), and his mods that finally got 46a77ebd86Schristosthe uncompress (-z) mode finished and working. 47a77ebd86Schristos 48a77ebd86SchristosThis release has compiled in numerous environments; see PORTING 49a77ebd86Schristosfor a list and problems. 50a77ebd86Schristos 51a77ebd86SchristosThis fine freeware file(1) follows the USG (System V) model of the 52a77ebd86Schristosfile command, rather than the Research (V7) version or the V7-derived 53a77ebd86Schristos4.[23] Berkeley one. That is, the file /etc/magic contains much of 54a77ebd86Schristosthe ritual information that is the source of this program's power. 55a77ebd86SchristosMy version knows a little more magic (including tar archives) than 56a77ebd86SchristosSystem V; the /etc/magic parsing seems to be compatible with the 57a77ebd86Schristos(poorly documented) System V /etc/magic format (with one exception; 58a77ebd86Schristossee the man page). 59a77ebd86Schristos 60a77ebd86SchristosIn addition, the /etc/magic file is built from a subdirectory 61a77ebd86Schristosfor easier(?) maintenance. I will act as a clearinghouse for 62a77ebd86Schristosmagic numbers assigned to all sorts of data files that 63a77ebd86Schristosare in reasonable circulation. Send your magic numbers, 64a77ebd86Schristosin magic(5) format please, to the maintainer, Christos Zoulas. 65a77ebd86Schristos 66a77ebd86SchristosCOPYING - read this first. 67a77ebd86Schristos* `README` - read this second (you are currently reading this file). 68a77ebd86Schristos* `INSTALL` - read on how to install 69a77ebd86Schristos* `src/apprentice.c` - parses /etc/magic to learn magic 70a77ebd86Schristos* `src/apptype.c` - used for OS/2 specific application type magic 71a77ebd86Schristos* `src/ascmagic.c` - third & last set of tests, based on hardwired assumptions. 72a77ebd86Schristos* `src/asctime_r.c` - replacement for OS's that don't have it. 73a77ebd86Schristos* `src/asprintf.c` - replacement for OS's that don't have it. 74a77ebd86Schristos* `src/buffer.c` - buffer handling functions. 75a77ebd86Schristos* `src/cdf.[ch]` - parser for Microsoft Compound Document Files 76a77ebd86Schristos* `src/cdf_time.c` - time converter for CDF. 77a77ebd86Schristos* `src/compress.c` - handles decompressing files to look inside. 78a77ebd86Schristos* `src/ctime_r.c` - replacement for OS's that don't have it. 79a77ebd86Schristos* `src/der.[ch]` - parser for Distinguished Encoding Rules 80a77ebd86Schristos* `src/dprintf.c` - replacement for OS's that don't have it. 81a77ebd86Schristos* `src/elfclass.h` - common code for elf 32/64. 82a77ebd86Schristos* `src/encoding.c` - handles unicode encodings 83a77ebd86Schristos* `src/file.c` - the main program 84a77ebd86Schristos* `src/file.h` - header file 85a77ebd86Schristos* `src/file_opts.h` - list of options 86a77ebd86Schristos* `src/fmtcheck.c` - replacement for OS's that don't have it. 87a77ebd86Schristos* `src/fsmagic.c` - first set of tests the program runs, based on filesystem info 88a77ebd86Schristos* `src/funcs.c` - utilility functions 89a77ebd86Schristos* `src/getline.c` - replacement for OS's that don't have it. 90a77ebd86Schristos* `src/getopt_long.c` - replacement for OS's that don't have it. 91a77ebd86Schristos* `src/gmtime_r.c` - replacement for OS's that don't have it. 92a77ebd86Schristos* `src/is_csv.c` - knows about Comma Separated Value file format (RFC 4180). 93a77ebd86Schristos* `src/is_json.c` - knows about JavaScript Object Notation format (RFC 8259). 94*e15daa8bSchristos* `src/is_simh.c` - knows about SIMH tape file format. 95a77ebd86Schristos* `src/is_tar.c, tar.h` - knows about Tape ARchive format (courtesy John Gilmore). 96a77ebd86Schristos* `src/localtime_r.c` - replacement for OS's that don't have it. 97a77ebd86Schristos* `src/magic.h.in` - source file for magic.h 98a77ebd86Schristos* `src/mygetopt.h` - replacement for OS's that don't have it. 99a77ebd86Schristos* `src/magic.c` - the libmagic api 100a77ebd86Schristos* `src/names.h` - header file for ascmagic.c 101a77ebd86Schristos* `src/pread.c` - replacement for OS's that don't have it. 102a77ebd86Schristos* `src/print.c` - print results, errors, warnings. 103a77ebd86Schristos* `src/readcdf.c` - CDF wrapper. 104a77ebd86Schristos* `src/readelf.[ch]` - Stand-alone elf parsing code. 105a77ebd86Schristos* `src/softmagic.c` - 2nd set of tests, based on /etc/magic 106a77ebd86Schristos* `src/mygetopt.h` - replacement for OS's that don't have it. 107a77ebd86Schristos* `src/strcasestr.c` - replacement for OS's that don't have it. 108a77ebd86Schristos* `src/strlcat.c` - replacement for OS's that don't have it. 109a77ebd86Schristos* `src/strlcpy.c` - replacement for OS's that don't have it. 110a77ebd86Schristos* `src/strndup.c` - replacement for OS's that don't have it. 111a77ebd86Schristos* `src/tar.h` - tar file definitions 112a77ebd86Schristos* `src/vasprintf.c` - for systems that don't have it. 113a77ebd86Schristos* `doc/file.man` - man page for the command 114a77ebd86Schristos* `doc/magic.man` - man page for the magic file, courtesy Guy Harris. 115a77ebd86Schristos Install as magic.4 on USG and magic.5 on V7 or Berkeley; cf Makefile. 116a77ebd86Schristos 117a77ebd86SchristosMagdir - directory of /etc/magic pieces 118a77ebd86Schristos------------------------------------------------------------------------------ 119a77ebd86Schristos 120a77ebd86SchristosIf you submit a new magic entry please make sure you read the following 121a77ebd86Schristosguidelines: 122a77ebd86Schristos 123a77ebd86Schristos- Initial match is preferably at least 32 bits long, and is a _unique_ match 124a77ebd86Schristos- If this is not feasible, use additional check 125a77ebd86Schristos- Match of <= 16 bits are not accepted 126a77ebd86Schristos- Delay printing string as much as possible, don't print output too early 127a77ebd86Schristos- Avoid printf arbitrary byte as string, which can be a source of 128a77ebd86Schristos crash and buffer overflow 129a77ebd86Schristos 130a77ebd86Schristos- Provide complete information with entry: 131a77ebd86Schristos * One line short summary 132a77ebd86Schristos * Optional long description 133a77ebd86Schristos * File extension, if applicable 134a77ebd86Schristos * Full name and contact method (for discussion when entry has problem) 135a77ebd86Schristos * Further reference, such as documentation of format 136a77ebd86Schristos 137a77ebd86Schristosgpg for dummies: 138a77ebd86Schristos------------------------------------------------------------------------------ 139a77ebd86Schristos 140a77ebd86Schristos``` 141a77ebd86Schristos$ gpg --verify file-X.YY.tar.gz.asc file-X.YY.tar.gz 142a77ebd86Schristosgpg: assuming signed data in `file-X.YY.tar.gz' 143a77ebd86Schristosgpg: Signature made WWW MMM DD HH:MM:SS YYYY ZZZ using DSA key ID KKKKKKKK 144a77ebd86Schristos``` 145a77ebd86Schristos 146a77ebd86SchristosTo download the key: 147a77ebd86Schristos 148a77ebd86Schristos``` 149a77ebd86Schristos$ gpg --keyserver hkp://keys.gnupg.net --recv-keys KKKKKKKK 150a77ebd86Schristos``` 151a77ebd86Schristos------------------------------------------------------------------------------ 152a77ebd86Schristos 153a77ebd86Schristos 154a77ebd86SchristosParts of this software were developed at SoftQuad Inc., developers 155a77ebd86Schristosof SGML/HTML/XML publishing software, in Toronto, Canada. 156a77ebd86SchristosSoftQuad was swallowed up by Corel in 2002 and does not exist any longer. 157