Browse Source

Import upstream version 3.24

Christos Zoulas 26 years ago
parent
commit
4d593e3827
83 changed files with 3696 additions and 1297 deletions
  1. 2 2
      MAINT
  2. 2 2
      Magdir/Header
  3. 5 0
      Magdir/alpha
  4. 7 0
      Magdir/amanda
  5. 10 0
      Magdir/amigaos
  6. 5 1
      Magdir/animation
  7. 4 2
      Magdir/apple
  8. 12 13
      Magdir/archive
  9. 17 0
      Magdir/asterix
  10. 5 4
      Magdir/att3b
  11. 41 9
      Magdir/audio
  12. 7 0
      Magdir/bsdi
  13. 10 0
      Magdir/cisco
  14. 24 0
      Magdir/commands
  15. 29 9
      Magdir/compress
  16. 64 2
      Magdir/convex
  17. 12 10
      Magdir/database
  18. 41 0
      Magdir/digital
  19. 2 2
      Magdir/dump
  20. 38 16
      Magdir/elf
  21. 30 0
      Magdir/filesystems
  22. 10 0
      Magdir/fonts
  23. 1 0
      Magdir/frame
  24. 81 48
      Magdir/freebsd
  25. 62 23
      Magdir/hp
  26. 28 0
      Magdir/ibm370
  27. 2 1
      Magdir/ibm6000
  28. 17 1
      Magdir/images
  29. 1 1
      Magdir/intel
  30. 9 0
      Magdir/island
  31. 9 2
      Magdir/java
  32. 4 0
      Magdir/lecter
  33. 10 3
      Magdir/linux
  34. 8 0
      Magdir/lisp
  35. 79 0
      Magdir/macintosh
  36. 3 3
      Magdir/mail.news
  37. 7 0
      Magdir/mime
  38. 33 0
      Magdir/modem
  39. 99 7
      Magdir/msdos
  40. 30 13
      Magdir/netbsd
  41. 86 0
      Magdir/os9
  42. 7 0
      Magdir/osf1
  43. 21 2
      Magdir/printer
  44. 20 11
      Magdir/sgi
  45. 79 0
      Magdir/sniffer
  46. 21 0
      Magdir/sun
  47. 36 0
      Magdir/ti-8x
  48. 2 0
      Magdir/timezone
  49. 6 0
      Magdir/varied.out
  50. 26 0
      Magdir/vgetty
  51. 1 1
      Magdir/microsoft
  52. 33 31
      Makefile
  53. 11 8
      orig/Makefile
  54. 22 20
      README
  55. 7 12
      apprentice.c
  56. 9 7
      ascmagic.c
  57. 6 1
      compress.c
  58. 16 0
      config.h.in
  59. 1393 0
      configure
  60. 15 0
      configure.in
  61. 0 20
      file-3.20.1.lsm
  62. 39 62
      file.c
  63. 26 8
      file.h
  64. 13 9
      file.man
  65. 21 5
      fsmagic.c
  66. 238 0
      install-sh
  67. 82 0
      internat.c
  68. 6 6
      is_tar.c
  69. 68 0
      magic2mime
  70. 17 9
      names.h
  71. 0 61
      orig/Magdir_elf
  72. 0 26
      orig/Magdir_fonts
  73. 0 0
      orig/Magdir_freebsd
  74. 0 224
      orig/Magdir_images
  75. 0 35
      orig/Magdir_intel
  76. 0 73
      orig/Magdir_linux
  77. 0 79
      orig/README
  78. 0 365
      orig/file.man
  79. 42 2
      patchlevel.h
  80. 7 5
      print.c
  81. 315 0
      readelf.c
  82. 95 2
      readelf.h
  83. 50 39
      softmagic.c

+ 2 - 2
MAINT

@@ -1,4 +1,4 @@
-$Id: MAINT,v 1.2 1993/09/23 21:47:01 christos Exp $
+$Id: MAINT,v 1.3 1997/11/05 16:03:18 christos Exp $
 
 Maintenance notes:
 
@@ -30,4 +30,4 @@ your changed version.
 Thank you for your assistance and cooperation.
 
 Mark Moraes		Christos Zoulas
-moraes@deshaw.com	christos@deshaw.com
+moraes@deshaw.com	christos@astron.com

+ 2 - 2
Magdir/Header

@@ -1,5 +1,5 @@
 #! file
 # Magic data for file(1) command.
-# Machine-genererated from src/cmd/file/magdir/*; edit there only!
+# Machine-generated from src/cmd/file/magdir/*; edit there only!
 # Format is described in magic(files), where:
-# files is 4 on V7 and BSD, 4 on SV, and ?? in the SVID.
+# files is 5 on V7 and BSD, 4 on SV, and ?? in the SVID.

+ 5 - 0
Magdir/alpha

@@ -14,3 +14,8 @@
 >27	byte		x		- version %d
 >26	byte		x		.%d
 >28	byte		x		-%d
+
+# Basic recognition of Digital UNIX core dumps - Mike Bremford <mike@opac.bl.uk>
+#
+0	string		Core\001	Alpha COFF format core dump (Digital UNIX)
+>24	string		>\0		\b, from '%s'

+ 7 - 0
Magdir/amanda

@@ -0,0 +1,7 @@
+#------------------------------------------------------------------------------
+# amanda:  file(1) magic for amanda file format
+#
+0       string          AMANDA:\ TAPESTART\ DATE     AMANDA dump header file,
+>23     string          X
+>>25    string          >\                           Unused %s
+>23     string          >\                           DATE %s

+ 10 - 0
Magdir/amigaos

@@ -0,0 +1,10 @@
+#------------------------------------------------------------------------------
+# amigaos:  file(1) magic for AmigaOS binary formats:
+
+#
+# From ignatios@cs.uni-bonn.de (Ignatios Souvatzis)
+# Some formats are still missing: AmigaOS special IFF's, e.g.: FORM....CTLG
+# (the others should be seperate, anyway)
+#
+0	belong		0x000003f3	AmigaOS loadseg()ble executable/binary
+0	belong		0x000003e7	AmigaOS object/library data

+ 5 - 1
Magdir/animation

@@ -7,7 +7,11 @@
 # FLC, SGI, Apple originally from Daniel Quinlan (quinlan@yggdrasil.com)
 
 # MPEG animation format
-0	string		\000\000\001\263	MPEG file
+0	belong		0x000001b3		MPEG video stream data
+#>4	beshort&0xfff0	x			(%d x
+#>5	beshort&0x0fff  x			%d)
+0	belong		0x000001ba		MPEG system stream data
+0	beshort&0xfff0	0xfff0			MPEG audio stream data
 
 # FLI animation format
 4	leshort		0xAF11			FLI file

+ 4 - 2
Magdir/apple

@@ -1,10 +1,12 @@
 
 #------------------------------------------------------------------------------
-# apple:  file(1) magic for Apple II file formats
+# apple:  file(1) magic for Apple file formats
 #
 0	string		FiLeStArTfIlEsTaRt	binscii (apple ][) text
 0	string		\x0aGL			Binary II (apple ][) data
 0	string		\x76\xff		Squeezed (apple ][) data
-0	string		SIT!			StuffIt (macintosh) text
 0	string		NuFile			NuFile archive (apple ][) data
 0	string		N\xf5F\xe9l\xe5		NuFile archive (apple ][) data
+0	belong		0x00051600		AppleSingle encoded Macintosh file
+0	belong		0x00051607		AppleDouble encoded Macintosh file
+

+ 12 - 13
Magdir/archive

@@ -27,6 +27,14 @@
 0	string		070701		ASCII cpio archive (SVR4 with no CRC)
 0	string		070702		ASCII cpio archive (SVR4 with CRC)
 
+# Debian package (needs to go before regular portable archives)
+#
+0	string		!<arch>\ndebian
+>8	string		debian-split	part of multipart Debian package
+>8	string		debian-binary	Debian binary package
+>68	string		>\n		(format %s)
+>136	ledate		x		created: %s
+
 # other archives
 0	long		0177555		very old archive
 0	short		0177555		very old PDP-11 archive
@@ -35,7 +43,7 @@
 0	long		0100554		apl workspace
 0	string		=<ar>		archive
 
-# MIPS archive (needs to go first)
+# MIPS archive (needs to go before regular portable archives)
 #
 0	string	!<arch>\n__________E	MIPS archive
 >20	string	U			with MIPS Ucode members
@@ -45,8 +53,6 @@
 >19	string	B			and an EB hash table
 >22	string	X			-- out of date
 
-0	string		!<arch>		archive
->8	string		__.SYMDEF	random library
 0	string		-h-		Software Tools format archive text
 
 #
@@ -56,11 +62,10 @@
 # 0	string		!<arch>		current ar archive
 # 0	long		0x213c6172	archive file
 #
-# and for SVR3.1 archives, we have:
+# and for SVR1 archives, we have:
 #
 # 0	string		\<ar>		System V Release 1 ar archive
 # 0	string		=<ar>		archive
-# 0	string		=<ar>		archive
 #
 # XXX - did Aegis really store shared libraries, breakpointed modules,
 # and absolute code program modules in the same format as new-style
@@ -68,8 +73,6 @@
 #
 0	string		!<arch>		current ar archive
 >8	string		__.SYMDEF	random library
->8	string		debian-split	part of multipart Debian package
->8	string		debian-binary	Debian binary package
 >0	belong		=65538		- pre SR9.5
 >0	belong		=65539		- post SR9.5
 >0	beshort		2		- object archive
@@ -98,14 +101,10 @@
 0	leshort		0177545		old PDP-11 archive
 >8	string		__.SYMDEF	random library
 #
-0	string		=<ar>		archive
-#
-# From "pdp":
+# From "pdp" (but why a 4-byte quantity?)
 #
 0	lelong		0x39bed		PDP-11 old archive
 0	lelong		0x39bee		PDP-11 4.0 archive
-#
-0	string		-h-		Software Tools format archive text
 
 # ARC archiver, from Daniel Quinlan (quinlan@yggdrasil.com)
 #
@@ -177,7 +176,7 @@
 2	string		-lz5-		LHarc 1.x archive data [lz5]
 #	[never seen any but the last; -lh4- reported in comp.compression:]
 2	string		-lzs-		LHa 2.x? archive data [lzs]
-2	string		-lh -		LHa 2.x? archive data [lh ]
+2	string		-lh\40-		LHa 2.x? archive data [lh ]
 2	string		-lhd-		LHa 2.x? archive data [lhd]
 2	string		-lh2-		LHa 2.x? archive data [lh2]
 2	string		-lh3-		LHa 2.x? archive data [lh3]

+ 17 - 0
Magdir/asterix

@@ -0,0 +1,17 @@
+
+#------------------------------------------------------------------------------
+# asterix:  file(1) magic for Aster*x; SunOS 5.5.1 gave the 4-character
+# strings as "long" - we assume they're just strings:
+# From: guy@netapp.com (Guy Harris)
+#
+0	string		*STA		Aster*x
+>7	string		WORD			Words Document
+>7	string		GRAP			Graphic
+>7	string		SPRE			Spreadsheet
+>7	string		MACR			Macro
+0	string		2278		Aster*x Version 2
+>29	byte		0x36			Words Document
+>29	byte		0x35			Graphic
+>29	byte		0x32			Spreadsheet
+>29	byte		0x38			Macro
+

+ 5 - 4
Magdir/att3b

@@ -7,11 +7,12 @@
 #
 # 3B20
 #
-0	beshort		0550		3b20 COFF executable
->12	belong		>0		not stripped
+# The 3B20 conflicts with SCCS.
+#0	beshort		0550		3b20 COFF executable
+#>12	belong		>0		not stripped
 #>22	beshort		>0		- version %ld
-0	beshort		0551		3b20 COFF executable (TV)
->12	belong		>0		not stripped
+#0	beshort		0551		3b20 COFF executable (TV)
+#>12	belong		>0		not stripped
 #>22	beshort		>0		- version %ld
 #
 # WE32K

+ 41 - 9
Magdir/audio

@@ -16,6 +16,10 @@
 >12	belong		6		32-bit IEEE floating point,
 >12	belong		7		64-bit IEEE floating point,
 >12	belong		23		8-bit ISDN u-law compressed (CCITT G.721 ADPCM voice data encoding),
+>12	belong		24		compressed (8-bit G.722 ADPCM)
+>12	belong		25		compressed (3-bit G.723 ADPCM),
+>12	belong		26		compressed (5-bit G.723 ADPCM),
+>12	belong		27		8-bit A-law,
 >20	belong		1		mono,
 >20	belong		2		stereo,
 >20	belong		4		quad,
@@ -54,14 +58,13 @@
 >4	belong		x		- version %ld
 
 # Microsoft WAVE format (*.wav)
-# [GRR 950115:  probably all of the shorts and longs should be leshort/lelong]
 0	string		RIFF		Microsoft RIFF
 >8	string		WAVE		\b, WAVE audio data
->>34	short		>0		\b, %d bit
->>22	short		=1		\b, mono
->>22	short		=2		\b, stereo
->>22	short		>2		\b, %d channels
->>24	long		>0		%d Hz
+>>34	leshort		>0		\b, %d bit
+>>22	leshort		=1		\b, mono
+>>22	leshort		=2		\b, stereo
+>>22	leshort		>2		\b, %d channels
+>>24	lelong		>0		%d Hz
 # AVI == Audio Video Interleave
 >8      string          AVI\            \b, AVI data
 
@@ -77,9 +80,6 @@
 # Real Audio (Magic .ra\0375)
 0	belong		0x2e7261fd	realaudio sound file
 
-# Real Audio (Magic .ra\0375)
-0	belong		0x2e7261fd	realaudio sound file
-
 # MTM/669/FAR/S3M/ULT/XM format checking [Aaron Eppert, aeppert@dialin.ind.net]
 # Oct 31, 1995
 0	string		MTM		MultiTracker Module sound file
@@ -88,3 +88,35 @@
 0	string		MAS_U		ULT(imate) Module sound data
 0x2c	string		SCRM		ScreamTracker III Module sound data
 0	string		Extended Module	Extended Module sound data
+
+# Gravis UltraSound patches
+# From <ache@nagual.ru>
+
+0	string		GF1PATCH110\0ID#000002\0	GUS patch
+0	string		GF1PATCH100\0ID#000002\0	Old GUS	patch
+
+#
+# Taken from loader code from mikmod version 2.14
+# by Steve McIntyre (stevem@chiark.greenend.org.uk)
+0	string	JN		extended 669 module data
+0	string	MAS_UTrack_V00
+>14	string	>/0		ultratracker V1.%.1s module sound data
+0	string	UN05		MikMod UNI format module sound data
+0	string	Extended\ Module: Fasttracker II module sound data
+21	string	!SCREAM!	Screamtracker 2 module sound data
+1080	string	M.K.		4-channel Protracker module sound data
+1080	string	M!K!		4-channel Protracker module sound data
+1080	string	FLT4		4-channel Startracker module sound data
+1080	string	4CHN		4-channel Fasttracker module sound data
+1080	string	6CHN		6-channel Fasttracker module sound data
+1080	string	8CHN		8-channel Fasttracker module sound data
+1080	string	CD81		8-channel Oktalyzer module sound data
+1080	string	OKTA		8-channel Oktalyzer module sound data
+1082	string	CH
+>1080	string	>/0		%.2s-channel Fasttracker "oktalyzer" module sound data
+1080	string	16CN		16-channel Taketracker module sound data
+1080	string	32CN		32-channel Taketracker module sound data
+
+# TOC sound files -Trevor Johnson <trevor@jpj.net>
+#
+0       string          TOC             TOC sound file

+ 7 - 0
Magdir/bsdi

@@ -0,0 +1,7 @@
+
+#------------------------------------------------------------------------------
+# bsdi:  file(1) magic for BSD/OS (from BSDI) objects
+#
+0	lelong			000000314	BSD/OS i386 compact demand paged executable
+>16	lelong			>0		not stripped
+>32	byte			0x6a		(uses shared libs)

+ 10 - 0
Magdir/cisco

@@ -0,0 +1,10 @@
+#------------------------------------------------------------------------------
+# cisco:  file(1) magic for cisco Systems routers
+#
+# Most cisco file-formats are covered by the generic elf code
+#
+# Microcode files are non-ELF, 0x8501 conflicts with NetBSD/alpha.
+0	belong&0xffffff00	0x85011400  cisco IOS microcode
+>7	string		>\0		    for '%s'
+0	belong&0xffffff00	0x8501cb00  cisco IOS experimental microcode
+>7	string		>\0		    for '%s'

+ 24 - 0
Magdir/commands

@@ -5,42 +5,58 @@
 0	string		:\ shell archive or commands for antique kernel text
 0	string		#!/bin/sh		Bourne shell script text
 0	string		#!\ /bin/sh		Bourne shell script text
+0	string		#!\	/bin/sh		Bourne shell script text
 0	string		#!/bin/csh		C shell script text
 0	string		#!\ /bin/csh		C shell script text
+0	string		#!\	/bin/csh	C shell script text
 # korn shell magic, sent by George Wu, gwu@clyde.att.com
 0	string		#!/bin/ksh		Korn shell script text
 0	string		#!\ /bin/ksh		Korn shell script text
+0	string		#!\	/bin/ksh	Korn shell script text
 0	string	 	#!/bin/tcsh		Tenex C shell script text
 0	string	 	#!\ /bin/tcsh		Tenex C shell script text
+0	string	 	#!\	/bin/tcsh	Tenex C shell script text
 0	string		#!/usr/local/tcsh	Tenex C shell script text
 0	string	 	#!\ /usr/local/tcsh	Tenex C shell script text
 0	string		#!/usr/local/bin/tcsh	Tenex C shell script text
 0	string		#!\ /usr/local/bin/tcsh	Tenex C shell script text
+0	string		#!\	/usr/local/bin/tcsh	Tenex C shell script text
 #
 # zsh/ash/ae/nawk/gawk magic from cameron@cs.unsw.oz.au (Cameron Simpson)
 0	string		#!/usr/local/bin/zsh	Paul Falstad's zsh
 0	string		#!\ /usr/local/bin/zsh	Paul Falstad's zsh
+0	string		#!\	/usr/local/bin/zsh	Paul Falstad's zsh
 0	string		#!/usr/local/bin/ash	Neil Brown's ash
 0	string		#!\ /usr/local/bin/ash	Neil Brown's ash
+0	string		#!\	/usr/local/bin/ash	Neil Brown's ash
 0	string		#!/usr/local/bin/ae	Neil Brown's ae
 0	string		#!\ /usr/local/bin/ae	Neil Brown's ae
+0	string		#!\	/usr/local/bin/ae	Neil Brown's ae
 0	string		#!/bin/nawk		new awk script text
 0	string		#!\ /bin/nawk		new awk script text
+0	string		#!\	/bin/nawk		new awk script text
 0	string		#!/usr/bin/nawk		new awk script text
 0	string		#!\ /usr/bin/nawk	new awk script text
+0	string		#!\	/usr/bin/nawk	new awk script text
 0	string		#!/usr/local/bin/nawk	new awk script text
 0	string		#!\ /usr/local/bin/nawk	new awk script text
+0	string		#!\	/usr/local/bin/nawk	new awk script text
 0	string		#!/bin/gawk		GNU awk script text
 0	string		#!\ /bin/gawk		GNU awk script text
+0	string		#!\	/bin/gawk		GNU awk script text
 0	string		#!/usr/bin/gawk		GNU awk script text
 0	string		#!\ /usr/bin/gawk	GNU awk script text
+0	string		#!\	/usr/bin/gawk	GNU awk script text
 0	string		#!/usr/local/bin/gawk	GNU awk script text
 0	string		#!\ /usr/local/bin/gawk	GNU awk script text
+0	string		#!\	/usr/local/bin/gawk	GNU awk script text
 #
 0	string		#!/bin/awk		awk commands text
 0	string		#!\ /bin/awk		awk commands text
+0	string		#!\	/bin/awk		awk commands text
 0	string		#!/usr/bin/awk		awk commands text
 0	string		#!\ /usr/bin/awk	awk commands text
+0	string		#!\	/usr/bin/awk	awk commands text
 0	string		BEGIN			awk commands text
 
 # For Larry Wall's perl language.  The ``eval'' line recognizes an
@@ -48,27 +64,35 @@
 #				Keith Waclena <keith@cerberus.uchicago.edu>
 0	string		#!/bin/perl			perl commands text
 0	string		#!\ /bin/perl			perl commands text
+0	string		#!\	/bin/perl		perl commands text
 0	string		eval\ "exec\ /bin/perl		perl commands text
 0	string		#!/usr/bin/perl			perl commands text
 0	string		#!\ /usr/bin/perl		perl commands text
+0	string		#!\	/usr/bin/perl		perl commands text
 0	string		eval\ "exec\ /usr/bin/perl	perl commands text
 0	string		#!/usr/local/bin/perl		perl commands text
 0	string		#!\ /usr/local/bin/perl		perl commands text
+0	string		#!\	/usr/local/bin/perl	perl commands text
 0	string		eval\ "exec\ /usr/local/bin/perl	perl commands text
 
 # AT&T Bell Labs' Plan 9 shell
 0	string		#!/bin/rc	Plan 9 rc shell script text
 0	string		#!\ /bin/rc	Plan 9 rc shell script text
+0	string		#!\	/bin/rc	Plan 9 rc shell script text
 
 # bash shell magic, from Peter Tobias (tobias@server.et-inf.fho-emden.de)
 0	string		#!/bin/bash	Bourne-Again shell script text
 0	string		#!\ /bin/bash	Bourne-Again shell script text
+0	string		#!\	/bin/bash	Bourne-Again shell script text
 0	string		#!/usr/local/bin/bash	Bourne-Again shell script text
 0	string		#!\ /usr/local/bin/bash	Bourne-Again shell script text
+0	string		#!\	/usr/local/bin/bash	Bourne-Again shell script text
 
 # generic shell magic
 0	string		#!\ /			a
 >3	string		>\0			%s script text
+0	string		#!\	/		a
+>3	string		>\0			%s script text
 0	string		#!/			a
 >2	string		>\0			%s script text
 0	string		#!\ 			commands text

+ 29 - 9
Magdir/compress

@@ -55,13 +55,18 @@
 0	string		\377\037	compacted data
 0	short		0145405		huf output
 
-# Squeeze and Crunch...
-# These numbers were gleaned from the Unix versions of the programs to
-# handle these formats.  Note that I can only uncrunch, not crunch, and
-# I didn't have a crunched file handy, so the crunch number is untested.
-#				Keith Waclena <keith@cerberus.uchicago.edu>
-0	leshort		0x76FF		squeezed data (CP/M, DOS)
-0	leshort		0x76FE		crunched data (CP/M, DOS)
+# bzip2
+0	string		BZh		bzip2 compressed data
+>3	byte		>47		\b, block size = %c00k
+
+# squeeze and crunch
+# Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
+0	leshort		0xFF76		squeezed data,
+>4	string		x		original name %s
+0	leshort		0xFE76		crunched data,
+>2	string		x		original name %s
+0	leshort		0xFD76		LZH compressed data,
+>2	string		x		original name %s
 
 # Freeze
 0	string		\037\237	frozen file 2.1
@@ -79,8 +84,23 @@
 #
 # This will cause very short GSM files to be declared as data and
 # mismatches to be declared as data too!
-#0	byte&0xF0	0xd0	data
+#0	byte&0xF0	0xd0		data
 #>33	byte&0xF0	0xd0
 #>66	byte&0xF0	0xd0
 #>99	byte&0xF0	0xd0
-#>132	byte&0xF0	0xd0	GSM 06.10 compressed audio
+#>132	byte&0xF0	0xd0		GSM 06.10 compressed audio
+
+# bzip	a block-sorting file compressor
+#	by Julian Seward <sewardj@cs.man.ac.uk> and others
+#
+0	string		BZ		bzip compressed	data
+>2	byte		x		\b, version: %c
+>3	string		=1		\b, compression block size 100k
+>3	string		=2		\b, compression block size 200k
+>3	string		=3		\b, compression block size 300k
+>3	string		=4		\b, compression block size 400k
+>3	string		=5		\b, compression block size 500k
+>3	string		=6		\b, compression block size 600k
+>3	string		=7		\b, compression block size 700k
+>3	string		=8		\b, compression block size 800k
+>3	string		=9		\b, compression block size 900k

+ 64 - 2
Magdir/convex

@@ -1,7 +1,69 @@
-
 #------------------------------------------------------------------------------
 # convex:  file(1) magic for Convex boxes
 #
 # Convexes are big-endian.
 #
-0	long		0513		Convex executable
+# /*\
+#  * Below are the magic numbers and tests added for Convex.
+#  * Added at beginning, because they are expected to be used most.
+# \*/
+0	belong	0507	Convex old-style object
+>16	belong	>0	not stripped
+0	belong	0513	Convex old-style demand paged executable
+>16	belong	>0	not stripped
+0	belong	0515	Convex old-style pre-paged executable
+>16	belong	>0	not stripped
+0	belong	0517	Convex old-style pre-paged, non-swapped executable
+>16	belong	>0	not stripped
+0	belong	0x011257	Core file
+#
+# The following are a series of dump format magic numbers.  Each one
+# corresponds to a drastically different dump format.  The first on is
+# the original dump format on a 4.1 BSD or earlier file system.  The
+# second marks the change between the 4.1 file system and the 4.2 file
+# system.  The Third marks the changing of the block size from 1K
+# to 2K to be compatible with an IDC file system.  The fourth indicates
+# a dump that is dependent on Convex Storage Manager, because data in
+# secondary storage is not physically contained within the dump.
+# The restore program uses these number to determine how the data is
+# to be extracted.
+#
+24	belong	=60011	dump format, 4.1 BSD or earlier
+24	belong	=60012	dump format, 4.2 or 4.3 BSD without IDC
+24	belong	=60013	dump format, 4.2 or 4.3 BSD (IDC compatible)
+24	belong	=60014	dump format, Convex Storage Manager by-reference dump
+#
+# what follows is a bunch of bit-mask checks on the flags field of the opthdr.
+# If there is no `=' sign, assume just checking for whether the bit is set?
+#
+0	belong	0601		Convex SOFF
+>88	belong&0x000f0000	=0x00000000	c1
+>88	belong			&0x00010000	c2
+>88	belong			&0x00020000	c2mp
+>88	belong			&0x00040000	parallel
+>88	belong			&0x00080000	intrinsic
+>88	belong			&0x00000001	demand paged
+>88	belong			&0x00000002	pre-paged
+>88	belong			&0x00000004	non-swapped
+>88	belong			&0x00000008	POSIX
+#
+>84	belong			&0x80000000	executable
+>84	belong			&0x40000000	object
+>84	belong&0x20000000	=0		not stripped
+>84	belong&0x18000000	=0x00000000	native fpmode
+>84	belong&0x18000000	=0x10000000	ieee fpmode
+>84	belong&0x18000000	=0x18000000	undefined fpmode
+#
+0	belong			0605		Convex SOFF core
+#
+0	belong			0607		Convex SOFF checkpoint
+>88	belong&0x000f0000	=0x00000000	c1
+>88	belong			&0x00010000	c2
+>88	belong			&0x00020000	c2mp
+>88	belong			&0x00040000	parallel
+>88	belong			&0x00080000	intrinsic
+>88	belong			&0x00000008	POSIX
+#
+>84	belong&0x18000000	=0x00000000	native fpmode
+>84	belong&0x18000000	=0x10000000	ieee fpmode
+>84	belong&0x18000000	=0x18000000	undefined fpmode

+ 12 - 10
Magdir/database

@@ -17,16 +17,18 @@
 >8	belong	1234		Little Endian,
 >8	belong	4321		Big Endian,
 >12	belong	x		Bucket Size %d,
->16	belong	x		Directory Size %d,
->20	belong	x		Segment Size %d,
->24	belong	x		Segment Shift %d,
->28	belong	x		Overflow Point %d,
->32	belong	x		Last Freed %d,
->36	belong	x		Max Bucket %d,
->40	belong	x		High Mask 0x%x,
->44	belong	x		Low Mask 0x%x,
->48	belong	x		Fill Factor %d,
->52	belong	x		Number of Keys %d)
+>16	belong	x		Bucket Shift %d,
+>20	belong	x		Directory Size %d,
+>24	belong	x		Segment Size %d,
+>28	belong	x		Segment Shift %d,
+>32	belong	x		Overflow Point %d,
+>36	belong	x		Last Freed %d,
+>40	belong	x		Max Bucket %d,
+>44	belong	x		High Mask 0x%x,
+>48	belong	x		Low Mask 0x%x,
+>52	belong	x		Fill Factor %d,
+>56	belong	x		Number of Keys %d)
+#
 #
 0	belong	0x053162	Berkeley DB Btree file
 >4	belong	>0		(Version %d,

+ 41 - 0
Magdir/digital

@@ -0,0 +1,41 @@
+#  Digital UNIX - Info
+#
+0	string	!<arch>\n________64E	Alpha archive
+>22	string	X			-- out of date
+#
+# Alpha COFF Based Executables
+# The stripped stuff really needs to be an 8 byte (64 bit) compare,
+# but this works
+0	leshort		0x183		COFF format alpha
+>22	leshort&020000	&010000		sharable library,
+>22	leshort&020000	^010000		dynamically linked,
+>24	leshort		0410		pure
+>24	leshort		0413		demand paged
+>8	lelong		>0		executable or object module, not stripped
+>8	lelong		0
+>>12	lelong		0		executable or object module, stripped
+>>12	lelong		>0		executable or object module, not stripped
+>27     byte            >0              - version %d.
+>26     byte            >0              %d-
+>28     leshort         >0              %d
+#
+# The next is incomplete, we could tell more about this format,
+# but its not worth it.
+0	leshort		0x188	Alpha compressed COFF
+0	leshort		0x18f	Alpha u-code object
+#
+#
+# Some other interesting Digital formats,
+0	string	\377\377\177		ddis/ddif
+0	string	\377\377\174		ddis/dots archive
+0	string	\377\377\176		ddis/dtif table data
+0	string	\033c\033		LN03 output
+0	long	04553207		X image
+#
+0	string	!<PDF>!\n		profiling data file
+#
+# Locale data tables (MIPS and Alpha).
+#
+0	short		0x0501		locale data table
+>6	short		0x24		for MIPS
+>6	short		0x40		for Alpha

+ 2 - 2
Magdir/dump

@@ -43,8 +43,8 @@
 >888	belong	>0		Flags %x
 
 24	lelong	60012		new-fs dump file (little endian),
->4	ledate	x		Previous dump %s,
->8	ledate	x		This dump %s,
+>4	ledate	x		This dump %s,
+>8	ledate	x		Previous dump %s,
 >12	lelong	>0		Volume %ld,
 >692	lelong	0		Level zero, type:
 >692	lelong	>0		Level %d, type:

+ 38 - 16
Magdir/elf

@@ -5,8 +5,8 @@
 # We have to check the byte order flag to see what byte order all the
 # other stuff in the header is in.
 #
-# Byte order is probably big-endian for MIPS RS3000 and Amdahl.
-# MIPS RS3000 may also be for MIPS RS2000.
+# MIPS R3000 may also be for MIPS R2000.
+# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?
 #
 # updated by Daniel Quinlan (quinlan@yggdrasil.com)
 0	string		\177ELF		ELF
@@ -20,42 +20,64 @@
 >>16	leshort		2		executable,
 >>16	leshort		3		shared object,
 # Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>
+# corrections by Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
 >>16	leshort		4		core file
->>>576  string          >\0             of '%s'
->>>400  lelong          >0              (signal %d),
+>>>(0x38+0xcc) string	>\0		of '%s'
+>>>(0x38+0x10) lelong	>0		(signal %d),
 >>16	leshort		&0xff00		processor-specific,
 >>18	leshort		0		no machine,
 >>18	leshort		1		AT&T WE32100 - invalid byte order,
 >>18	leshort		2		SPARC - invalid byte order,
->>18	leshort		3		Intel 386,
+>>18	leshort		3		Intel 80386,
 >>18	leshort		4		Motorola 68000 - invalid byte order,
 >>18	leshort		5		Motorola 88000 - invalid byte order,
->>18	leshort		6		Intel 486,
->>18	leshort		7		Intel 860,
->>18	leshort		8		MIPS RS3000,
->>18	leshort		9		Amdahl,
+>>18	leshort		6		Intel 80486,
+>>18	leshort		7		Intel 80860,
+>>18	leshort		8		MIPS R3000_BE - invalid byte order,
+>>18	leshort		9		Amdahl - invalid byte order,
+>>18	leshort		10		MIPS R3000_LE,
+>>18	leshort		11		RS6000 - invalid byte order,
+>>18	leshort		15		PA-RISC - invalid byte order,
+>>18	leshort		16		nCUBE,
+>>18	leshort		17		VPP500,
+>>18	leshort		18		SPARC32PLUS,
+>>18	leshort		20		PowerPC,
+>>18	leshort		0x9026		Alpha,
 >>20	lelong		0		invalid version
 >>20	lelong		1		version 1
 >>36	lelong		1		MathCoPro/FPU/MAU Required
+>8	string		>\0		(%s)
 >5	byte		2		MSB
 >>16	beshort		0		no file type,
 >>16	beshort		1		relocatable,
 >>16	beshort		2		executable,
 >>16	beshort		3		shared object,
 >>16	beshort		4		core file,
->>>576	string		>\0		of '%s'
->>>400	lelong		>0		(signal %d),
+>>>(0x38+0xcc) string	>\0		of '%s'
+>>>(0x38+0x10) belong	>0		(signal %d),
 >>16	beshort		&0xff00		processor-specific,
 >>18	beshort		0		no machine,
 >>18	beshort		1		AT&T WE32100,
 >>18	beshort		2		SPARC,
->>18	beshort		3		Intel 386 - invalid byte order,
+>>18	beshort		3		Intel 80386 - invalid byte order,
 >>18	beshort		4		Motorola 68000,
 >>18	beshort		5		Motorola 88000,
->>18	beshort		6		Intel 486 - invalid byte order,
->>18	beshort		7		Intel 860,
->>18	beshort		8		MIPS RS3000,
->>18	leshort		9		Amdahl,
+>>18	beshort		6		Intel 80486 - invalid byte order,
+>>18	beshort		7		Intel 80860,
+>>18	beshort		8		MIPS R3000_BE,
+>>18	beshort		9		Amdahl,
+>>18	beshort		10		MIPS R3000_LE - invalid byte order,
+>>18	beshort		11		RS6000,
+>>18	beshort		15		PA-RISC,
+>>18	beshort		16		nCUBE,
+>>18	beshort		17		VPP500,
+>>18	beshort		18		SPARC32PLUS,
+>>18	beshort		20		PowerPC or cisco 4500,
+>>18	beshort		21		cisco 7500,
+>>18	beshort		24		cisco SVIP,
+>>18	beshort		25		cisco 7200,
+>>18	beshort		36		cisco 12000,
+>>18	beshort		0x9026		Alpha,
 >>20	belong		0		invalid version
 >>20	belong		1		version 1
 >>36	belong		1		MathCoPro/FPU/MAU Required

+ 30 - 0
Magdir/filesystems

@@ -4,3 +4,33 @@
 #
 0x438	leshort	0xEF53			Linux/i386 ext2 filesystem
 0	string	\366\366\366\366	PC formatted floppy with no filesystem
+# Sun disk labels
+# From /usr/include/sun/dklabel.h:
+0774	beshort		0xdabe		Sun disk label
+>0	string		x		'%s
+>>31  	string		>\0		\b%s
+>>>63  	string		>\0		\b%s
+>>>>95 	string		>\0		\b%s
+>0	string		x		\b'
+>0734	short		>0		%d rpm,
+>0736	short		>0		%d phys cys,
+>0740	short		>0		%d alts/cyl,
+>0746	short		>0		%d interleave,
+>0750	short		>0		%d data cyls,
+>0752	short		>0		%d alt cyls,
+>0754	short		>0		%d heads/partition,
+>0756	short		>0		%d sectors/track,
+>0764	long		>0		start cyl %ld,
+>0770	long		x		%ld blocks
+# Is there a boot block written 1 sector in?
+>512    belong&077777777	0600407	\b, boot block present
+0x1FE	leshort	0xAA55			x86 boot sector
+>2	string	OSBS			\b, OS/BS MBR
+>0x8C	string	Invalid\ partition\ table	\b, MS-DOS MBR
+>0	string	\0\0\0\0		\b, extended partition table
+>0	leshort 0x3CEB			\b, system
+>>3	string	>\0			%s
+>>0x36	string	FAT			\b, %s
+>>>0x39	string	12			(%s bit)
+>>>0x39	string	16			(%s bit)
+>0x200	lelong	0x82564557		\b, BSD disklabel

+ 10 - 0
Magdir/fonts

@@ -25,6 +25,15 @@
 >12	byte		0x0a			\b, MSB first
 0	string		D1.0\015		X11 Speedo font data
 
+#------------------------------------------------------------------------------
+# FIGlet fonts and controlfiles
+# From figmagic supplied with Figlet version 2.2
+# "David E. O'Brien" <obrien@FreeBSD.ORG>
+0	string		flf		FIGlet font
+>3	string		>2a		version %-2.2s
+0	string		flc		FIGlet controlfile
+>3	string		>2a		version %-2.2s
+
 # libGrx graphics lib fonts, from Albert Cahalan (acahalan@cs.uml.edu)
 # Used with djgpp (DOS Gnu C++), sometimes Linux or Turbo C++
 0	belong		0x14025919	libGrx font data,
@@ -36,3 +45,4 @@
 7	belong		0x00454741	DOS code page font data
 7	belong		0x00564944	DOS code page font data (from Linux?)
 4098	string		DOSFONT		DOSFONT2 encrypted font data
+

+ 1 - 0
Magdir/frame

@@ -6,6 +6,7 @@
 # copyright, but this file is "published" as witness the following:
 #
 0	string		\<MakerFile	FrameMaker document
+>11	string		5.0		 (5.0
 >11	string		4.0		 (4.0
 >11	string		3.0		 (3.0
 >11	string		2.0		 (2.0

+ 81 - 48
Magdir/freebsd

@@ -1,6 +1,79 @@
-# the following are for BSD/i386 (FreeBSD, NetBSD, etc.)
 
-0	lelong&0377777777	041400407	BSD/i386
+#------------------------------------------------------------------------------
+# freebsd:  file(1) magic for FreeBSD objects
+#
+# All new-style FreeBSD magic numbers are in host byte order (i.e.,
+# little-endian on x86).
+#
+# XXX - this comes from the file "freebsd" in a recent FreeBSD version of
+# "file"; it, and the NetBSD stuff in "netbsd", appear to use different
+# schemes for distinguishing between executable images, shared libraries,
+# and object files.
+#
+# FreeBSD says:
+#
+#    Regardless of whether it's pure, demand-paged, or none of the
+#    above:
+#
+#	if the entry point is < 4096, then it's a shared library if
+#	the "has run-time loader information" bit is set, and is
+#	position-independent if the "is position-independent" bit
+#	is set;
+#
+#	if the entry point is >= 4096 (or >4095, same thing), then it's
+#	an executable, and is dynamically-linked if the "has run-time
+#	loader information" bit is set.
+#
+# On x86, NetBSD says:
+#
+#    If it's neither pure nor demand-paged:
+#
+#	if it has the "has run-time loader information" bit set, it's
+#	a dynamically-linked executable;
+#
+#	if it doesn't have that bit set, then:
+#
+#	    if it has the "is position-independent" bit set, it's
+#	    position-independent;
+#
+#	    if the entry point is non-zero, it's an executable, otherwise
+#	    it's an object file.
+#
+#    If it's pure:
+#
+#	if it has the "has run-time loader information" bit set, it's
+#	a dynamically-linked executable, otherwise it's just an
+#	executable.
+#
+#    If it's demand-paged:
+#
+#	if it has the "has run-time loader information" bit set,
+#	then:
+#
+#	    if the entry point is < 4096, it's a shared library;
+#
+#	    if the entry point is = 4096 or > 4096 (i.e., >= 4096),
+#	    it's a dynamically-linked executable);
+#
+#	if it doesn't have the "has run-time loader information" bit
+#	set, then it's just an executable.
+#
+# (On non-x86, NetBSD does much the same thing, except that it uses
+# 8192 on 68K - except for "68k4k", which is presumably "68K with 4K
+# pages - SPARC, and MIPS, presumably because Sun-3's and Sun-4's
+# had 8K pages; dunno about MIPS.)
+#
+# I suspect the two will differ only in perverse and uninteresting cases
+# ("shared" libraries that aren't demand-paged and whose pages probably
+# won't actually be shared, executables with entry points <4096).
+#
+# I leave it to those more familiar with FreeBSD and NetBSD to figure out
+# what the right answer is (although using ">4095", FreeBSD-style, is
+# probably better than separately checking for "=4096" and ">4096",
+# NetBSD-style).  (The old "netbsd" file analyzed FreeBSD demand paged
+# executables using the NetBSD technique.)
+#
+0	lelong&0377777777	041400407	FreeBSD/i386
 >20	lelong			<4096
 >>3	byte&0xC0		&0x80		shared library
 >>3	byte&0xC0		0x40		PIC object
@@ -10,7 +83,7 @@
 >>3	byte&0x80		0x00		executable
 >16	lelong			>0		not stripped
 
-0	lelong&0377777777	041400410	BSD/i386 pure
+0	lelong&0377777777	041400410	FreeBSD/i386 pure
 >20	lelong			<4096
 >>3	byte&0xC0		&0x80		shared library
 >>3	byte&0xC0		0x40		PIC object
@@ -20,7 +93,7 @@
 >>3	byte&0x80		0x00		executable
 >16	lelong			>0		not stripped
 
-0	lelong&0377777777	041400413	BSD/i386 demand paged
+0	lelong&0377777777	041400413	FreeBSD/i386 demand paged
 >20	lelong			<4096
 >>3	byte&0xC0		&0x80		shared library
 >>3	byte&0xC0		0x40		PIC object
@@ -30,7 +103,7 @@
 >>3	byte&0x80		0x00		executable
 >16	lelong			>0		not stripped
 
-0	lelong&0377777777	041400314	BSD/i386 compact demand paged
+0	lelong&0377777777	041400314	FreeBSD/i386 compact demand paged
 >20	lelong			<4096
 >>3	byte&0xC0		&0x80		shared library
 >>3	byte&0xC0		0x40		PIC object
@@ -40,46 +113,6 @@
 >>3	byte&0x80		0x00		executable
 >16	lelong			>0		not stripped
 
-0	belong&0377777777	041400407	BSD/i386
->20	belong			<4096
->>0	byte&0xC0		&0x80		shared library
->>0	byte&0xC0		0x40		PIC object
->>0	byte&0xC0		0x00		object
->20	belong			>4095
->>0	byte&0x80		0x80		dynamically linked executable
->>0	byte&0x80		0x00		executable
->16	belong			>0		not stripped
-
-0	belong&0377777777	041400410	BSD/i386 pure
->20	belong			<4096
->>0	byte&0xC0		&0x80		shared library
->>0	byte&0xC0		0x40		PIC object
->>0	byte&0xC0		0x00		object
->20	belong			>4095
->>0	byte&0x80		0x80		dynamically linked executable
->>0	byte&0x80		0x00		executable
->16	belong			>0		not stripped
-
-0	belong&0377777777	041400413	BSD/i386 demand paged
->20	belong			<4096
->>0	byte&0xC0		&0x80		shared library
->>0	byte&0xC0		0x40		PIC object
->>0	byte&0xC0		0x00		object
->20	belong			>4095
->>0	byte&0x80		0x80		dynamically linked executable
->>0	byte&0x80		0x00		executable
->16	belong			>0		not stripped
-
-0	belong&0377777777	041400314	BSD/i386 compact demand paged
->20	belong			<4096
->>0	byte&0xC0		&0x80		shared library
->>0	byte&0xC0		0x40		PIC object
->>0	byte&0xC0		0x00		object
->20	belong			>4095
->>0	byte&0x80		0x80		dynamically linked executable
->>0	byte&0x80		0x00		executable
->16	belong			>0		not stripped
-
 # XXX gross hack to identify core files
 # cores start with a struct tss; we take advantage of the following:
 # byte 7:     highest byte of the kernel stack pointer, always 0xfe
@@ -88,10 +121,10 @@
 #      28:    low order byte of the current PTD entry, always 0 since the
 #             PTD is page-aligned
 #
-7	string	\357\020\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0	BSD i386 a.out core file
->1031	string	>\0	from "%s"
+7	string	\357\020\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0	FreeBSD/i386 a.out core file
+>1039	string	>\0	from '%s'
 
 # /var/run/ld.so.hints
 # What are you laughing about?
-0	lelong			011421044151	BSD ld.so hints file
+0	lelong			011421044151	ld.so hints file
 >4	lelong			>0		(version %d)

+ 62 - 23
Magdir/hp

@@ -6,12 +6,6 @@
 # applied to the "TML" stuff; I'm assuming the Apollo stuff is
 # big-endian as it was mostly 68K-based.
 #
-# HP-PA is big-endian, so it (and "800", which is *also* HP-PA-based; I
-# assume "HPPA-RISC1.1" really means "HP-PA Version 1.1", which first
-# showed up in the 700 series, although later 800 series machines are,
-# I think, based on the PA7100 which implements HP-PA 1.1) are flagged
-# as big-endian.
-#
 # I think the 500 series was the old stack-based machines, running a
 # UNIX environment atop the "SUN kernel"; dunno whether it was
 # big-endian or little-endian.
@@ -21,10 +15,23 @@
 # HP magic is useful for reference, but using "long" magic is a better
 # practice in order to avoid collisions.
 #
+# Guy Harris (guy@netapp.com): some additions to this list came from
+# HP-UX 10.0's "/usr/include/sys/unistd.h" (68030, 68040, PA-RISC 1.1,
+# 1.2, and 2.0).  The 1.2 and 2.0 stuff isn't in the HP-UX 10.0
+# "/etc/magic", though, except for the "archive file relocatable library"
+# stuff, and the 68030 and 68040 stuff isn't there at all - are they not
+# used in executables, or have they just not yet updated "/etc/magic"
+# completely?
+#
 # 0	beshort		200		hp200 (68010) BSD binary
 # 0	beshort		300		hp300 (68020+68881) BSD binary
 # 0	beshort		0x20c		hp200/300 HP-UX binary
-# 0	beshort		0x20b		hp800 HP-UX binary
+# 0	beshort		0x20d		hp400 (68030) HP-UX binary
+# 0	beshort		0x20e		hp400 (68040?) HP-UX binary
+# 0	beshort		0x20b		PA-RISC1.0 HP-UX binary
+# 0	beshort		0x210		PA-RISC1.1 HP-UX binary
+# 0	beshort		0x211		PA-RISC1.2 HP-UX binary
+# 0	beshort		0x214		PA-RISC2.0 HP-UX binary
 
 #
 # The "misc" stuff needs a byte order; the archives look suspiciously
@@ -41,49 +48,82 @@
 0       long            01702407010     TML 1032 byte-order format
 0       long            01003405017     TML 2301 byte-order format
 0       long            01602007412     TML 3210 byte-order format
-#### HPPA
-0	belong 		0x02100106	HPPA-RISC1.1 relocatable object
-0	belong 		0x02100107	HPPA-RISC1.1 executable
+#### PA-RISC 1.1
+0	belong 		0x02100106	PA-RISC1.1 relocatable object
+0	belong 		0x02100107	PA-RISC1.1 executable
+>168	belong		&=0x00000004	dynamically linked
 >(144)	belong		0x054ef630	dynamically linked
 >96	belong		>0		- not stripped
 
-0	belong 		0x02100108	HPPA-RISC1.1 shared executable
+0	belong 		0x02100108	PA-RISC1.1 shared executable
+>168	belong&0x4	0x4		dynamically linked
 >(144)	belong		0x054ef630	dynamically linked
 >96	belong		>0		- not stripped
 
-0	belong 		0x0210010b	HPPA-RISC1.1 demand-load executable
+0	belong 		0x0210010b	PA-RISC1.1 demand-load executable
+>168	belong&0x4	0x4		dynamically linked
 >(144)	belong		0x054ef630	dynamically linked
 >96	belong		>0		- not stripped
 
-0	belong 		0x0210010e	HPPA-RISC1.1 shared library
+0	belong 		0x0210010e	PA-RISC1.1 shared library
 >96	belong		>0		- not stripped
 
-0	belong 		0x0210010d	HPPA-RISC1.1 dynamic load library
+0	belong 		0x0210010d	PA-RISC1.1 dynamic load library
+>96	belong		>0		- not stripped
+
+#### PA-RISC 2.0
+0	belong		0x02140106	PA-RISC2.0 relocatable object
+
+0       belong		0x02140107	PA-RISC2.0 executable
+>168	belong		&=0x00000004	dynamically linked
+>(144)	belong		0x054ef630	dynamically linked
+>96	belong		>0		- not stripped
+
+0       belong		0x02140108	PA-RISC2.0 shared executable
+>168	belong		&=0x00000004	dynamically linked
+>(144)	belong		0x054ef630	dynamically linked
+>96	belong		>0		- not stripped
+
+0       belong		0x0214010b	PA-RISC2.0 demand-load executable
+>168	belong		&=0x00000004	dynamically linked
+>(144)	belong		0x054ef630	dynamically linked
+>96	belong		>0		- not stripped
+
+0       belong		0x0214010e	PA-RISC2.0 shared library
+>96	belong		>0		- not stripped
+
+0       belong		0x0214010d	PA-RISC2.0 dynamic load library
 >96	belong		>0		- not stripped
 
 #### 800
-0	belong 		0x020b0106	HP s800 relocatable object
+0	belong 		0x020b0106	PA-RISC1.0 relocatable object
 
-0	belong 		0x020b0107	HP s800 executable
+0	belong 		0x020b0107	PA-RISC1.0 executable
+>168	belong&0x4	0x4		dynamically linked
 >(144)	belong		0x054ef630	dynamically linked
 >96	belong		>0		- not stripped
 
-0	belong 		0x020b0108	HP s800 shared executable
+0	belong 		0x020b0108	PA-RISC1.0 shared executable
+>168	belong&0x4	0x4		dynamically linked
 >(144)	belong		0x054ef630	dynamically linked
 >96	belong		>0		- not stripped
 
-0	belong 		0x020b010b	HP s800 demand-load executable
+0	belong 		0x020b010b	PA-RISC1.0 demand-load executable
+>168	belong&0x4	0x4		dynamically linked
 >(144)	belong		0x054ef630	dynamically linked
 >96	belong		>0		- not stripped
 
-0	belong 		0x020b010e	HP s800 shared library
+0	belong 		0x020b010e	PA-RISC1.0 shared library
 >96	belong		>0		- not stripped
 
-0	belong 		0x020b010d	HP s800 dynamic load library
+0	belong 		0x020b010d	PA-RISC1.0 dynamic load library
 >96	belong		>0		- not stripped
 
 0	belong		0x213c6172	archive file
->68	belong 		0x020b0619	- HP s800 relocatable library
+>68	belong 		0x020b0619	- PA-RISC1.0 relocatable library
+>68	belong	 	0x02100619	- PA-RISC1.1 relocatable library
+>68	belong 		0x02110619	- PA-RISC1.2 relocatable library
+>68	belong 		0x02140619	- PA-RISC2.0 relocatable library
 
 #### 500
 0	long		0x02080106	HP s500 relocatable executable
@@ -156,7 +196,7 @@
 
 0	string		IMGfile	CIS 	compimg HP Bitmapfile
 # XXX - see "lif"
-0	short		0x8000		lif file
+#0	short		0x8000		lif file
 0	long		0x020c010c	compiled Lisp
 
 0	string		msgcat01	HP NLS message catalog,
@@ -209,4 +249,3 @@
 >2	beshort		0407		impure binary
 >2	beshort		0410		read-only binary
 >2	beshort		0413		demand paged binary
-

+ 28 - 0
Magdir/ibm370

@@ -4,7 +4,35 @@
 #
 # "ibm370" said that 0x15d == 0535 was "ibm 370 pure executable".
 # What the heck *is* "USS/370"?
+# AIX 4.1's "/etc/magic" has
 #
+#	0	short		0535		370 sysV executable 
+#	>12	long		>0		not stripped
+#	>22	short		>0		- version %d
+#	>30	long		>0		- 5.2 format
+#	0	short		0530		370 sysV pure executable 
+#	>12	long		>0		not stripped
+#	>22	short		>0		- version %d
+#	>30	long		>0		- 5.2 format
+#
+# instead of the "USS/370" versions of the same magic numbers.
+#
+0	beshort		0537		370 XA sysV executable 
+>12	belong		>0		not stripped
+>22	beshort		>0		- version %d
+>30	belong		>0		- 5.2 format
+0	beshort		0532		370 XA sysV pure executable 
+>12	belong		>0		not stripped
+>22	beshort		>0		- version %d
+>30	belong		>0		- 5.2 format
+0	beshort		054001		370 sysV pure executable
+>12	belong		>0		not stripped
+0	beshort		055001		370 XA sysV pure executable
+>12	belong		>0		not stripped
+0	beshort		056401		370 sysV executable
+>12	belong		>0		not stripped
+0	beshort		057401		370 XA sysV executable
+>12	belong		>0		not stripped
 0       beshort		0531		SVR2 executable (Amdahl-UTS)
 >12	belong		>0		not stripped
 >24     belong		>0		- version %ld

+ 2 - 1
Magdir/ibm6000

@@ -12,5 +12,6 @@
 0	beshort		0x0104		shared library
 0	beshort		0x0105		ctab data
 0	beshort		0xfe04		structured file
-0	string		0xabcdef	message catalog
+0	string		0xabcdef	AIX message catalog
+0	belong		0x000001f9	AIX compiled message catalog
 0	string		\<aiaff>	archive

+ 17 - 1
Magdir/images

@@ -30,10 +30,11 @@
 # PNG [Portable Network Graphics, or "PNG's Not GIF"] images
 # (Greg Roelofs, newt@uchicago.edu)
 # (Albert Cahalan, acahalan@cs.uml.edu)
+#
 # 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
 #
 0	string		\x89PNG		PNG image data,
->4	belong		!0x0d0a1a0a	CORRUPTED
+>4	belong		!0x0d0a1a0a	CORRUPTED,
 >4	belong		0x0d0a1a0a
 >>16	belong		x		%ld x
 >>20	belong		x		%ld,
@@ -118,6 +119,13 @@
 >29	byte		1		\b, fine resolution (204x196 DPI)
 
 # JPEG images
+# SunOS 5.5.1 had
+#
+#	0	string		\377\330\377\340	JPEG file
+#	0	string		\377\330\377\356	JPG file
+#
+# both of which turn into "JPEG image data" here.
+#
 0	beshort		0xffd8		JPEG image data
 >6	string		JFIF		\b, JFIF standard
 # HSI is Handmade Software's proprietary JPEG encoding scheme
@@ -224,3 +232,11 @@
 # other images
 0	string	This\ is\ a\ BitMap\ file	Lisp Machine bit-array-file
 0	string		!!		Bennet Yee's "face" format
+
+# From SunOS 5.5.1 "/etc/magic" - appeared right before Sun raster image
+# stuff.
+#
+0	beshort		0x1010		PEX Binary Archive
+
+# Visio drawings
+03000	string	Visio\ (TM)\ Drawing			%s

+ 1 - 1
Magdir/intel

@@ -30,6 +30,6 @@
 >12	lelong		>0		not stripped
 #>22	leshort		>0		- version %ld
 # SGI labeled the next entry as "iAPX 386 executable" --Dan Quinlan
-0	leshort		=0514		386 COFF executable
+0	leshort		=0514		80386 COFF executable
 >12	lelong		>0		not stripped
 >22	leshort		>0		- version %ld

+ 9 - 0
Magdir/island

@@ -0,0 +1,9 @@
+
+#------------------------------------------------------------------------------
+# island:  file(1) magic for IslandWite/IslandDraw, from SunOS 5.5.1
+# "/etc/magic":
+# From: guy@netapp.com (Guy Harris)
+#
+4	string		pgscriptver	IslandWrite document
+13	string		DrawFile	IslandDraw document
+

+ 9 - 2
Magdir/java

@@ -1,4 +1,11 @@
 #------------------------------------------------------------
 # Java ByteCode
-0	belong		0xcafebabe
->4	belong		0x0003002d	Java bytecode
+# From Larry Schwimmer (schwim@cs.stanford.edu)
+0	belong		0xcafebabe	compiled Java class data,
+>6	beshort x	version %d.
+>4	beshort x	\b%d
+#------------------------------------------------------------
+# Java serialization
+# From Martin Pool (m.pool@pharos.com.au)
+0	beshort		0xaced		Java serialization data
+>2	beshort		>0x0004		\b, version %d

+ 4 - 0
Magdir/lecter

@@ -0,0 +1,4 @@
+#------------------------------------------------------------------------------
+# DEC SRC Virtual Paper: Lectern files
+# Karl M. Hegbloom <karlheg@inetarena.com>
+0	string	lect	DEC SRC Virtual Paper Lectern file

+ 10 - 3
Magdir/linux

@@ -24,7 +24,7 @@
 0	string		\007\001\000	Linux/i386 object file
 >20	lelong		>0x1020		\b, DLL library
 # message catalogs, from Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
-0	string		*nazgul*	compiled message catalog
+0	string		*nazgul*	Linux compiled message catalog
 >8	lelong		>0		\b, version %ld
 # core dump file, from Bill Reynolds <bill@goshawk.lanl.gov>
 216	lelong		0421		Linux/i386 core file
@@ -37,7 +37,7 @@
 #
 # Debian Packages, from Peter Tobias <tobias@server.et-inf.fho-emden.de>
 0	string		0.9
->8	byte		0x0a		Debian Binary Package
+>8	byte		0x0a		old Debian Binary Package
 >>3	byte		>0		\b, created by dpkg 0.9%c
 >>4	byte		>0		pl%c
 # PSF fonts, from H. Peter Anvin <hpa@yggdrasil.com>
@@ -63,9 +63,10 @@
 >8	long		>0		not stripped
 >8	long		0		stripped
 >23	leshort		>0		- version %ld.
-
+#
 # Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>
 # and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>
+# and Nicolas Lichtmaier <nick@debian.org>
 # All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29
 514		string	HdrS		Linux kernel
 >518		leshort	>0
@@ -79,7 +80,13 @@
 >>0x048c	string	x		version %s
 >0x0493		byte	0x32
 >>0x0493	string	x		version %s
+>0x04df		byte	0x32
+>>0x04df	string	x		version %s
+>0x04fb		byte	0x32
+>>0x04fb	string	x		version %s
 # This also matches new kernels, which were caught above by "HdrS".
 0		belong	0xb8c0078e	Linux kernel
 >0x1e3		string	Loading		version 1.3.79 or older
 >0x1e9		string	Loading		from prehistoric times
+# LSM entries - Nicolas Lichtmaier <nick@feedback.com.ar>
+0	string	Begin3	Linux Software Map entry text

+ 8 - 0
Magdir/lisp

@@ -8,3 +8,11 @@
 0	string	\012(			byte-compiled Emacs-Lisp program data
 # Emacs 19
 0	string	;ELC\023\000\000\000	byte-compiled Emacs-Lisp program data
+#
+# Files produced by CLISP Common Lisp From: Bruno Haible <haible@ilog.fr>
+0	string	(SYSTEM::VERSION\040'	CLISP byte-compiled Lisp program text
+0	long	0x70768BD2		CLISP memory image data
+0	long	0xD28B7670		CLISP memory image data, other endian
+# Files produced by GNU gettext
+0	long	0xDE120495		GNU-format message catalog data
+0	long	0x950412DE		GNU-format message catalog data

+ 79 - 0
Magdir/macintosh

@@ -0,0 +1,79 @@
+
+#------------------------------------------------------------------------------
+# macintosh description
+#
+# BinHex is the Macintosh ASCII-encoded file format (see also "apple")
+# Daniel Quinlan, quinlan@yggdrasil.com
+11	string	must\ be\ converted\ with\ BinHex	BinHex binary text
+>41	string	x					\b, version %.3s
+
+# Stuffit archives are the de facto standard of compression for Macintosh
+# files obtained from most archives. (franklsm@tuns.ca)
+0	string		SIT!			StuffIt Archive (data)
+>2	string		x			: %s
+65	string		SIT!			StuffIt Archive (rsrc + data)
+>2	string		x			: %s
+0	string		SITD			StuffIt Deluxe (data)
+>2	string		x			: %s
+65	string		SITD			StuffIt Deluxe (rsrc + data)
+>2	string		x			: %s
+0	string		Seg			StuffIt Deluxe Segment (data)
+>2	string		x			: %s
+65	string		Seg			StuffIt Deluxe Segment (rsrc + data)
+>2	string		x			: %s
+
+# Macintosh Applications and Installation binaries (franklsm@tuns.ca)
+0	string		APPL			Macintosh Application (data)
+>2	string		x			: %s
+65	string		APPL			Macintosh Application (rsrc + data)
+>2	string		x			: %s
+
+# Macintosh System files (franklsm@tuns.ca)
+0	string		zsys			Macintosh System File (data)
+65	string		zsys			Macintosh System File(rsrc + data)
+0	string		FNDR			Macintosh Finder (data)
+65	string		FNDR			Macintosh Finder(rsrc + data)
+0	string		libr			Macintosh Library (data)
+>2	string		x			: %s
+65	string		libr			Macintosh Library(rsrc + data)
+>2	string		x			: %s
+0	string		shlb			Macintosh Shared Library (data)
+>2	string		x			: %s
+65	string		shlb			Macintosh Shared Library(rsrc + data)
+>2	string		x			: %s
+0	string		cdev			Macintosh Control Panel (data)
+>2	string		x			: %s
+65	string		cdev			Macintosh Control Panel(rsrc + data)
+>2	string		x			: %s
+0	string		INIT			Macintosh Extension (data)
+>2	string		x			: %s
+65	string		INIT			Macintosh Extension(rsrc + data)
+>2	string		x			: %s
+0	string		FFIL			Macintosh Truetype Font (data)
+>2	string		x			: %s
+65	string		FFIL			Macintosh Truetype Font(rsrc + data)
+>2	string		x			: %s
+0	string		LWFN			Macintosh Postscript Font (data)
+>2	string		x			: %s
+65	string		LWFN			Macintosh Postscript Font(rsrc + data)
+>2	string		x			: %s
+
+# Additional Macintosh Files (franklsm@tuns.ca)
+
+0	string		PACT			Macintosh Compact Pro Archive (data)
+>2	string		x			: %s
+65	string		PACT			Macintosh Compact Pro Archive(rsrc + data)
+>2	string		x			: %s
+0	string		ttro			Macintosh TeachText File (data)
+>2	string		x			: %s
+65	string		ttro			Macintosh TeachText File(rsrc + data)
+>2	string		x			: %s
+0	string		TEXT			Macintosh TeachText File (data)
+>2	string		x			: %s
+65	string		TEXT			Macintosh TeachText File(rsrc + data)
+>2	string		x			: %s
+0	string		PDF			Macintosh PDF File (data)
+>2	string		x			: %s
+65	string		PDF			Macintosh PDF File(rsrc + data)
+>2	string		x			: %s
+

+ 3 - 3
Magdir/mail.news

@@ -16,6 +16,6 @@
 0	string		From:		news or mail text
 0	string		Article 	saved news text
 0	string		BABYL		Emacs RMAIL text
-0	string		Received:	RFC 822 mail message
-0	string		MIME-Version:	MIME entity
-0	string		Content-	MIME entity
+0	string		Received:	RFC 822 mail text
+0	string		MIME-Version:	MIME entity text
+#0	string		Content-	MIME entity text

+ 7 - 0
Magdir/mime

@@ -0,0 +1,7 @@
+#------------------------------------------------------------------------------
+# mime:  file(1) magic for MIME encoded files
+#
+0	string		Content-Type:\
+>14	string		>\0		%s
+0	string		Content-Type:
+>13	string		>\0		%s

+ 33 - 0
Magdir/modem

@@ -0,0 +1,33 @@
+#------------------------------------------------------------------------------
+# modem:  file(1) magic for modem programs
+#
+# From: Florian La Roche <florian@knorke.saar.de>
+4	string		Research,	Digifax-G3-File
+>29	byte		1		, fine resolution
+>29	byte		0		, normal resolution
+
+0	short		0x0100		raw G3 data, byte-padded
+0	short		0x1400		raw G3 data
+#
+# Magic data for vgetty voice formats
+# (Martin Seine & Marc Eberhard)
+
+#
+# raw modem data version 1
+#
+0    string    RMD1      raw modem data
+>4   string    >\0       (%s /
+>20  short     >0        compression type 0x%04x)
+
+#
+# portable voice format 1
+#
+0    string    PVF1\n         portable voice format
+>5   string    >\0       (binary %s)
+
+#
+# portable voice format 2
+#
+0    string    PVF2\n         portable voice format
+>5   string >\0          (ascii %s)
+

+ 99 - 7
Magdir/msdos

@@ -6,10 +6,85 @@
 # .BAT files (Daniel Quinlan, quinlan@yggdrasil.com)
 0	string	@echo\ off	MS-DOS batch file text
 
+# XXX - according to Microsoft's spec, at an offset of 0x3c in a
+# PE-format executable is the offset in the file of the PE header;
+# unfortunately, that's a little-endian offset, and there's no way
+# to specify an indirect offset with a specified byte order.
+# So, for now, we assume the standard MS-DOS stub, which puts the
+# PE header at 0x80 = 128.
+#
+# Required OS version and subsystem version were 4.0 on some NT 3.51
+# executables built with Visual C++ 4.0, so it's not clear that
+# they're interesting.  The user version was 0.0, but there's
+# probably some linker directive to set it.  The linker version was
+# 3.0, except for one ".exe" which had it as 4.20 (same damn linker!).
+#
+128	string		PE\0\0	MS Windows PE
+>150	leshort&0x0100	>0	32-bit
+>132	leshort		0x0	unknown processor
+>132	leshort		0x14c	Intel 80386
+>132	leshort		0x166	MIPS R4000
+>132	leshort		0x184	Alpha
+>132	leshort		0x268	Motorola 68000
+>132	leshort		0x1f0	PowerPC
+>132	leshort		0x290	PA-RISC
+>148	leshort		>27
+>>220	leshort		0	unknown subsystem
+>>220	leshort		1	native
+>>220	leshort		2	GUI
+>>220	leshort		3	console
+>>220	leshort		7	POSIX
+>150	leshort&0x2000	=0	executable
+#>>136	ledate		x	stamp %s,
+>>150	leshort&0x0001	>0	not relocatable
+#>>150	leshort&0x0004	=0	with line numbers,
+#>>150	leshort&0x0008	=0	with local symbols,
+#>>150	leshort&0x0200	=0	with debug symbols,
+>>150	leshort&0x1000	>0	system file
+#>>148	leshort		>0
+#>>>154	byte		x	linker %d
+#>>>155	byte		x	\b.%d,
+#>>148	leshort		>27
+#>>>192	leshort		x	requires OS %d
+#>>>194	leshort		x	\b.%d,
+#>>>196	leshort		x	user version %d
+#>>>198	leshort		x	\b.%d,
+#>>>200	leshort		x	subsystem version %d
+#>>>202	leshort		x	\b.%d,
+>150	leshort&0x2000	>0	DLL
+#>>136	ledate		x	stamp %s,
+>>150	leshort&0x0001	>0	not relocatable
+#>>150	leshort&0x0004	=0	with line numbers,
+#>>150	leshort&0x0008	=0	with local symbols,
+#>>150	leshort&0x0200	=0	with debug symbols,
+>>150	leshort&0x1000	>0	system file
+#>>148	leshort		>0
+#>>>154	byte		x	linker %d
+#>>>155	byte		x	\b.%d,
+#>>148	leshort		>27
+#>>>192	leshort		x	requires OS %d
+#>>>194	leshort		x	\b.%d,
+#>>>196	leshort		x	user version %d
+#>>>198	leshort		x	\b.%d,
+#>>>200	leshort		x	subsystem version %d
+#>>>202	leshort		x	\b.%d,
+0	leshort		0x14c	MS Windows COFF Intel 80386 object file
+#>4	ledate		x	stamp %s
+0	leshort		0x166	MS Windows COFF MIPS R4000 object file
+#>4	ledate		x	stamp %s
+0	leshort		0x184	MS Windows COFF Alpha object file
+#>4	ledate		x	stamp %s
+0	leshort		0x268	MS Windows COFF Motorola 68000 object file
+#>4	ledate		x	stamp %s
+0	leshort		0x1f0	MS Windows COFF PowerPC object file
+#>4	ledate		x	stamp %s
+0	leshort		0x290	MS Windows COFF PA-RISC object file
+#>4	ledate		x	stamp %s
+
 # .EXE formats (Greg Roelofs, newt@uchicago.edu)
 #
 0	string	MZ		MS-DOS executable (EXE)
->24	string	@		\b, OS/2 or Windows
+>24	string	@		\b, OS/2 or MS Windows
 >1638	string	-lh5-		\b, LHa SFX archive v2.13S
 >7195	string	Rar!		\b, RAR self-extracting archive
 #
@@ -55,19 +130,36 @@
 #0	byte		0xf0		MS-DOS program library data
 #
 
+#
+# Windows NT Registry files.
+#
+0	string		regf		Windows NT Registry file
+
 # Popular applications
 2080	string	Microsoft\ Word\ 6.0\ Document	%s
+2080	string	Documento\ Microsoft\ Word\ 6 Spanish Microsoft Word 6 document data
+# Pawel Wiecek <coven@i17linuxb.ists.pwr.wroc.pl> (for polish Word)
+2112	string	MSWordDoc	Microsoft Word document data
 #
 0	belong	0x31be0000	Microsoft Word Document
 #
+0       string  PO^Q`           Microsoft Word 6.0 Document
+#
 2080	string	Microsoft\ Excel\ 5.0\ Worksheet	%s
 #
+# Pawel Wiecek <coven@i17linuxb.ists.pwr.wroc.pl> (for polish Excel)
+2114	string	Biff5		Microsoft Excel 5.0 Worksheet
+#
 0	belong	0x00001a00	Lotus 1-2-3
->4	belong	0x00100400	wk3 document
->4	belong	0x02100400	wk4 document
->4	belong	0x07800100	fm3 or fmb document
->4	belong	0x07800000	fm3 or fmb document
+>4	belong	0x00100400	wk3 document data
+>4	belong	0x02100400	wk4 document data
+>4	belong	0x07800100	fm3 or fmb document data
+>4	belong	0x07800000	fm3 or fmb document data
 #
 0	belong	0x00000200 	Lotus 1-2-3
->4	belong	0x06040600	wk1 document
->4	belong	0x06800200	fmt document
+>4	belong	0x06040600	wk1 document data
+>4	belong	0x06800200	fmt document data
+
+# WordPerfect documents - Trevor Johnson <trevor@jpj.net>
+#
+1       string          WPC             WordPerfect document

+ 30 - 13
Magdir/netbsd

@@ -4,19 +4,6 @@
 #
 # All new-style magic numbers are in network byte order.
 #
-0	lelong			000000413	386BSD demand paged executable
->16	lelong			>0		not stripped
-0	lelong			000000314	BSDI demand paged executable
->16	lelong			>0		not stripped
->32	byte			0x6a		(uses shared libs)
-
-0	lelong&077777777	041400314	FreeBSD/i386 demand paged
->3	byte			&0x80
->>20	lelong			<4096		shared library
->>20	lelong			=4096		dynamically linked executable
->>20	lelong			>4096		dynamically linked executable
->3	byte			^0x80		executable
->16	lelong			>0		not stripped
 
 0	lelong			000000407	NetBSD little-endian object file
 >16	lelong			>0		not stripped
@@ -170,6 +157,15 @@
 0	belong&0377777777	043000507	NetBSD/vax core
 >12	string			>\0		from '%s'
 
+# NetBSD/alpha does not support (and has never supported) a.out objects,
+# so no rules are provided for them.  NetBSD/alpha ELF objects are 
+# dealt with in "elf".
+0	lelong		0x00070185		ECOFF NetBSD/alpha binary
+>10	leshort		0x0001			not stripped
+>10	leshort		0x0000			stripped
+0	belong&0377777777	043200507	NetBSD/alpha core
+>12	string			>\0		from '%s'
+
 0	belong&0377777777	043400413	NetBSD/mips demand paged
 >0	byte			&0x80		
 >>20	belong			<8192		shared library
@@ -190,3 +186,24 @@
 >16	belong			>0		not stripped
 0	belong&0377777777	043400507	NetBSD/mips core
 >12	string			>\0		from '%s'
+
+0	belong&0377777777	043600413	NetBSD/arm32 demand paged
+>0	byte			&0x80
+>>20	lelong			<8192		shared library
+>>20	lelong			=8192		dynamically linked executable
+>>20	lelong			>8192		dynamically linked executable
+>0	byte			^0x80		executable
+>16	lelong			>0		not stripped
+0	belong&0377777777	043600410	NetBSD/arm32 pure
+>0	byte			&0x80		dynamically linked executable
+>0	byte			^0x80		executable
+>16	lelong			>0		not stripped
+0	belong&0377777777	043600407	NetBSD/arm32
+>0	byte			&0x80		dynamically linked executable
+>0	byte			^0x80
+>>0	byte			&0x40		position independent
+>>20	lelong			!0		executable
+>>20	lelong			=0		object file
+>16	lelong			>0		not stripped
+0	belong&0377777777	043600507	NetBSD/arm32 core
+>12	string			>\0		from '%s'

+ 86 - 0
Magdir/os9

@@ -0,0 +1,86 @@
+#
+#	$NetBSD: os9,v 1.2 1997/01/09 20:19:04 tls Exp $
+#
+# Copyright (c) 1996 Ignatios Souvatzis. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#      This product includes software developed by Ignatios Souvatzis for
+#      the NetBSD project.
+# 4. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission.
+#
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#
+#
+# OS9/6809 module descriptions:
+#
+0	beshort		0x87CD	OS9/6809 module:
+#
+>6	byte&0x0f	0x00	non-executable
+>6	byte&0x0f	0x01	machine language
+>6	byte&0x0f	0x02	BASIC I-code
+>6	byte&0x0f	0x03	P-code
+>6	byte&0x0f	0x04	C I-code
+>6	byte&0x0f	0x05	COBOL I-code
+>6	byte&0x0f	0x06	FORTRAN I-code
+#
+>6	byte&0xf0	0x10	program executable
+>6	byte&0xf0	0x20	subroutine
+>6	byte&0xf0	0x30	multi-module
+>6	byte&0xf0	0x40	data module
+#
+>6	byte&0xf0	0xC0	system module
+>6	byte&0xf0	0xD0	file manager
+>6	byte&0xf0	0xE0	device driver
+>6	byte&0xf0	0xF0	device descriptor
+#
+# OS9/m68k stuff (to be continued)
+#
+0	beshort		0x4AFC	OS9/68K module:
+#
+# attr
+>14	byte&0x80	0x80	re-entrant
+>14	byte&0x40	0x40	ghost
+>14	byte&0x20	0x20	system-state
+#
+# lang:
+#
+>13	byte		1	machine language
+>13	byte		2	BASIC I-code
+>13	byte		3	P-code
+>13	byte		4	C I-code
+>13	byte		5	COBOL I-code
+>13	byte		6	Fortran I-code
+#
+#
+# type:
+#
+>12	byte		1	program executable
+>12	byte		2	subroutine
+>12	byte		3	multi-module
+>12	byte		4	data module
+>12	byte		11	trap library
+>12	byte		12	system module
+>12	byte		13	file manager
+>12	byte		14	device driver
+>12	byte		15	device descriptor

+ 7 - 0
Magdir/osf1

@@ -0,0 +1,7 @@
+#
+# Mach magic number info
+#
+0	long		0xefbe	OSF/Rose object
+# I386 magic number info
+#
+0	short		0565	i386 COFF object

+ 21 - 2
Magdir/printer

@@ -18,10 +18,29 @@
 >>>16	string		Query		- type %s
 >>>16	string		ExitServer	- type %s
 
+# Adobe's PostScript Printer Description (PPD) files
+#       Yves Arrouye <arrouye@marin.fdn.fr>
+#
+0      string          *PPD-Adobe:    PPD file
+>13    string          x              \b, ve
+
+# HP Printer Job Language
+0	string		\033%-12345X@PJL	HP Printer Job Language data
 # HP Printer Job Language
+# The header found on Win95 HP plot files is the "Silliest Thing possible" 
+# (TM)
+# Every driver puts the language at some random position, with random case
+# (LANGUAGE and Language)
+# For example the LaserJet 5L driver puts the "PJL ENTER LANGUAGE" in line 10
+# From: Uwe Bonnes <bon@elektron.ikp.physik.th-darmstadt.de>
+# 
 0	string		\033%-12345X@PJL	HP Printer Job Language data
->15	string		\ ENTER\ LANGUAGE\ =
->31	string		PostScript		Postscript
+>&0	string		>\0			%s			
+>>&0	string		>\0			%s			
+>>>&0	string		>\0			%s		
+>>>>&0	string		>\0			%s		
+#>15	string		\ ENTER\ LANGUAGE\ =
+#>31	string		PostScript		PostScript
 
 # HP Printer Control Language, Daniel Quinlan (quinlan@yggdrasil.com)
 0	string		\033E\033	HP PCL printer data

+ 20 - 11
Magdir/sgi

@@ -1,12 +1,16 @@
 
 #------------------------------------------------------------------------------
 # sgi:  file(1) magic for Silicon Graphics (MIPS, IRIS, IRIX, etc.)
-#
+#                         Dec Ultrix (MIPS)
 # all of SGI's *current* machines and OSes run in big-endian mode on the
 # MIPS machines, as far as I know.
 #
 # XXX - what is the blank "-" line?
 #
+# kbd file definitions
+0	string	kbd!map		kbd map file
+>8	byte	>0		Ver %d:
+>10	short	>0		with %d table(s)
 0	belong	0407		old SGI 68020 executable
 0	belong	0410		old SGI 68020 pure executable
 0	beshort	0x8765		disk quotas file
@@ -47,8 +51,8 @@
 >20	beshort	05401		(paged)
 >8	belong	>0		not stripped
 >8	belong	0		stripped
->22	byte	x		- version %d
->23	byte	x		.%ld
+>23	byte	x		- version %d
+>22	byte	x		.%ld
 #
 0	beshort	0x6201		MIPSEL-LE COFF executable
 >20	beshort	03401		(impure)
@@ -56,8 +60,8 @@
 >20	beshort	05401		(paged)
 >8	belong	>0		not stripped
 >8	belong	0		stripped
->22	byte	x		- version %ld
->23	byte	x		.%ld
+>23	byte	x		- version %ld
+>22	byte	x		.%ld
 #
 # MIPS 2 additions
 #
@@ -86,7 +90,7 @@
 >8	belong	>0		not stripped
 >8	belong	0		stripped
 >23	byte	x		- version %ld
->23	byte	x		.%ld
+>22	byte	x		.%ld
 #
 0	beshort	0x6601		MIPSEL-LE MIPS-II COFF executable
 >20	beshort	03401		(impure)
@@ -95,7 +99,7 @@
 >8	belong	>0		not stripped
 >8	belong	0		stripped
 >23	byte	x		- version %ld
->23	byte	x		.%ld
+>22	byte	x		.%ld
 #
 # MIPS 3 additions
 #
@@ -124,7 +128,7 @@
 >8	belong	>0		not stripped
 >8	belong	0		stripped
 >23	byte	x		- version %ld
->23	byte	x		.%ld
+>22	byte	x		.%ld
 #
 0	beshort	0x4201		MIPSEL-LE MIPS-III COFF executable
 >20	beshort	03401		(impure)
@@ -133,7 +137,7 @@
 >8	belong	>0		not stripped
 >8	belong	0		stripped
 >23	byte	x		- version %ld
->23	byte	x		.%ld
+>22	byte	x		.%ld
 #
 0	beshort	0x180		MIPSEB Ucode
 0	beshort	0x182		MIPSEL Ucode
@@ -145,6 +149,10 @@
 0	belong	0xdeadad40	IRIX 64-bit core dump
 >4	belong	1		of
 >16	string	>\0		'%s'
+# N32bit core file
+0       belong	0xbabec0bb	IRIX N32 core dump
+>4      belong	1               of
+>16     string	>\0             '%s'
 # New style crash dump file
 0	string	\x43\x72\x73\x68\x44\x75\x6d\x70	IRIX vmcore dump of
 >36	string	>\0					'%s'
@@ -152,12 +160,13 @@
 0	string	SGIAUDIT	SGI Audit file
 >8	byte	x		- version %d
 >9	byte	x		.%ld
-# Are these three SGI-based file types or general ones?
+#
 0	string	WNGZWZSC	Wingz compiled script
 0	string	WNGZWZSS	Wingz spreadsheet
 0	string	WNGZWZHP	Wingz help file
 #
-0	string	\#Inventor V	IRIS Inventor file
+0	string	\#Inventor V	IRIS Inventor 1.0 file
+0	string	\#Inventor V2	Open Inventor 2.0 file
 # XXX - I don't know what next thing is!  It is likely to be an image
 # (or movie) format
 0	string	glfHeadMagic();		GLF_TEXT

+ 79 - 0
Magdir/sniffer

@@ -0,0 +1,79 @@
+
+#------------------------------------------------------------------------------
+# sniffer:  file(1) magic for packet captured files
+#
+# From: guy@netapp.com (Guy Harris)
+#
+# Microsoft NetMon (packet capture/display program) capture files.
+#
+0	string		RTSS		NetMon capture file
+>4	byte		x		- version %d
+>5	byte		x		\b.%d
+>6	leshort		0		(Unknown)
+>6	leshort		1		(Ethernet)
+>6	leshort		2		(Token Ring)
+>6	leshort		3		(FDDI)
+
+#
+# Network General Sniffer capture files.
+#
+0	string		TRSNIFF\ data\ \ \ \ \032	Sniffer capture file
+>23	leshort		x		- version %d
+>25	leshort		x		\b.%d
+>33	byte		x		(Format %d,
+>32	byte		0		Token ring)
+>32	byte		1		Ethernet)
+>32	byte		2		ARCNET)
+>32	byte		3		StarLAN)
+>32	byte		4		PC Network broadband)
+>32	byte		5		LocalTalk)
+>32	byte		6		Znet)
+#
+# Cinco Networks NetXRay capture files.
+#
+0	string		XCP\0		NetXRay capture file
+>4	string		>\0		- version %s
+#
+# "libpcap" capture files.
+# (We call them "tcpdump capture file(s)" for now, as "tcpdump" is
+# the main program that uses that format, but there's also "tcpview",
+# and there may be others in the future.)
+#
+0	ubelong		0xa1b2c3d4	tcpdump capture file (big-endian)
+>4	beshort		x		- version %d
+>6	beshort		x		\b.%d
+>20	belong		0		(No link-layer encapsulation
+>20	belong		1		(Ethernet
+>20	belong		2		(3Mb Ethernet
+>20	belong		3		(AX.25
+>20	belong		4		(ProNET
+>20	belong		5		(CHAOS
+>20	belong		6		(IEEE 802.x network
+>20	belong		7		(ARCNET
+>20	belong		8		(SLIP
+>20	belong		9		(PPP
+>20	belong		10		(FDDI
+>20	belong		11		(RFC 1483 ATM
+>20	belong		12		(raw IP
+>20	belong		13		(BSD/OS SLIP
+>20	belong		14		(BSD/OS PPP
+>16	belong		x		\b, capture length %d)
+0	ulelong		0xa1b2c3d4	tcpdump capture file (little-endian)
+>4	leshort		x		- version %d
+>6	leshort		x		\b.%d
+>20	lelong		0		(No link-layer encapsulation
+>20	lelong		1		(Ethernet
+>20	lelong		2		(3Mb Ethernet
+>20	lelong		3		(AX.25
+>20	lelong		4		(ProNET
+>20	lelong		5		(CHAOS
+>20	lelong		6		(IEEE 802.x network
+>20	lelong		7		(ARCNET
+>20	lelong		8		(SLIP
+>20	lelong		9		(PPP
+>20	lelong		10		(FDDI
+>20	lelong		11		(RFC 1483 ATM
+>20	lelong		12		(raw IP
+>20	lelong		13		(BSD/OS SLIP
+>20	lelong		14		(BSD/OS PPP
+>16	lelong		x		\b, capture length %d)

+ 21 - 0
Magdir/sun

@@ -84,3 +84,24 @@
 >>128	string		>\0		from '%s'
 >4	belong		456		(SPARC 4.x BCP)
 >>152	string		>\0		from '%s'
+# Sun SunPC
+0	long		0xfa33c08e	SunPC 4.0 Hard Disk
+0	string		#SUNPC_CONFIG	SunPC 4.0 Properties Values
+# Sun snoop (see RFC 1761, which describes the capture file format).
+#
+0	string		snoop		Snoop capture file
+>8	belong		>0		- version %ld
+>12	belong		0		(IEEE 802.3)
+>12	belong		1		(IEEE 802.4)
+>12	belong		2		(IEEE 802.5)
+>12	belong		3		(IEEE 802.6)
+>12	belong		4		(Ethernet)
+>12	belong		5		(HDLC)
+>12	belong		6		(Character synchronous)
+>12	belong		7		(IBM channel-to-channel adapter)
+>12	belong		8		(FDDI)
+>12	belong		9		(Unknown)
+# Sun KCMS
+36	string		acsp		Kodak Color Management System, ICC Profile
+
+

+ 36 - 0
Magdir/ti-8x

@@ -0,0 +1,36 @@
+# ------------------------------------------------------------------------
+# ti-8x: file(1) magic for the TI-8x and TI-92 Graphing Calculators.
+#
+# From: Ryan McGuire (rmcguire@freenet.columbus.oh.us).
+#
+# NOTE: This list is not complete.
+#
+# Magic Numbers for the TI-82
+#
+0               string          **TI82**        TI-82 Graphing Calculator
+>0x000037       byte            0x0B            TI-BASIC Group/Program File.
+#
+# Magic Numbers for the TI-83
+#
+0               string          **TI83**        TI-83 Graphing Calculator
+>0x000037       byte            0x0B            TI-BASIC Group/Program File.
+#
+# Magic Numbers for the TI-85
+#
+0               string          **TI85**        TI-85 Graphing Calculator
+>11             string          Backup          Backup File.
+>0x000032       string          ZS4             - ZShell Version 4 File.
+>0x000032       string          ZS3             - ZShell Version 3 File.
+>0x00000B       string          GDatabase       Graphics Database.
+>0x00003B       byte            0x12            TI-BASIC Group/Program File.
+#
+# Magic Numbers for the TI-92
+#
+0               string          **TI92**        TI-92 Graphing Calculator
+>0x000058       byte            0x12            TI-BASIC Group File.
+>0x000012       string          Function        Function.
+>0x000048       byte            0x12            TI-BASIC Program.
+# Files for the TI-80 and TI-81 are pretty rare. I'm not going to put the
+# program/group magic numbers in here because I cannot find any.
+0               string          **TI80**        TI-80 Graphing Calculator File.
+0               string          **TI81**        TI-81 Graphing Calculator File.

+ 2 - 0
Magdir/timezone

@@ -4,6 +4,8 @@
 #
 # from Daniel Quinlan (quinlan@yggdrasil.com)
 # this should work on Linux, SunOS, and maybe others
+# Added new official magic number for recent versions of the Olson code
+0	string	TZif	timezone data
 0	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0	timezone data
 0	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\2\0	timezone data
 0	string  \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0	timezone data

+ 6 - 0
Magdir/varied.out

@@ -13,3 +13,9 @@
 0	beshort		0160007		amd 29k coff archive
 # Cray
 6	beshort		0407		unicos (cray) executable
+# Ultrix 4.3
+596	string		\130\337\377\377	Ultrix core file
+>600	string		>\0	'%s'
+# BeOS and MAcOS PEF executables
+# From: hplus@zilker.net (Jon Watte)
+0	string		Joy!peffpwpc	header for PowerPC PEF executable

+ 26 - 0
Magdir/vgetty

@@ -0,0 +1,26 @@
+#
+# Magic data for vgetty voice formats
+# (Martin Seine & Marc Eberhard)
+#
+
+#
+# raw modem data version 1
+#
+
+0    string    RMD1      raw modem data
+>4   string    >\0       (%s /
+>20  short     >0        compression type 0x%04x)
+
+#
+# portable voice format 1
+#
+
+0    string    PVF1\n         portable voice format
+>5   string    >\0       (binary %s)
+
+#
+# portable voice format 2
+#
+
+0    string    PVF2\n         portable voice format
+>5   string >\0          (ascii %s)

+ 1 - 1
Magdir/microsoft

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# microsoft:  file(1) magic for Microsoft Xenix
+# xenix:  file(1) magic for Microsoft Xenix
 #
 # "Middle model" stuff, and "Xenix 8086 relocatable or 80286 small
 # model" lifted from "magic.xenix", with comment "derived empirically;

+ 33 - 31
Makefile

@@ -1,6 +1,6 @@
 # Makefile for file(1) cmd. 
 # Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
-# @(#)$Id: Makefile,v 1.51 1996/06/22 22:05:07 christos Exp $
+# @(#)$Id: Makefile.in,v 1.3 1998/02/15 23:21:17 christos Exp $
 #
 # This software is not subject to any license of the American Telephone
 # and Telegraph Company or of the Regents of the University of California.
@@ -21,30 +21,26 @@
 #    ever read sources, credits must appear in the documentation.
 #
 # 4. This notice may not be removed or altered.
-
-# Optimized for Linux because sunsite.unc.edu, tsx-11.mit.edu,
-# ftp.redhat.com, ftp.funet.fi, and other Linux sites never get
-# a copy uploaded to them. Most still had 3.15 + a patch at the
-# time of this hack.  --  Albert Cahalan <acahalan@cs.uml.edu>
-
-# Was 3.20, number changed as requested.
-VERSION	= 3.20.1
+VERSION	= 3.24
 SHELL	= /bin/sh
-MAGIC	= /etc/magic
-#MAGIC	= /usr/local/etc/magic
-
-DEFS	= -DMAGIC='"$(MAGIC)"' # -Dvoid=int
-CC	= gcc
-COPTS	= -s -O2 -fno-strength-reduce -fomit-frame-pointer
-CFLAGS	= $(COPTS) $(DEFS)
-LDFLAGS	= $(COPTS) # -Bstatic	# older gdb couldn't handle shared libs
-
+#MAGIC	= /etc/magic
+prefix = @prefix@
+INSTALLCMD = @INSTALL@
+MAGICDIR = @datadir@
+MAGIC	= $(MAGICDIR)/magic
+DEFS	= -DMAGIC='"$(MAGIC)"' -DBUILTIN_ELF -DHAVE_CONFIG_H
+CPPFLAGS = $(DEFS)
+CC	= @CC@
+#COPTS	= -O -g		# newer compilers allow both; else drop -O
+# For truly antique environments, use this for (dummy) include files:
+#COPTS	= -O # -Ilocalinc
+#CFLAGS	= $(COPTS) $(DEFS)
+CFLAGS = @CFLAGS@
+#LDFLAGS	= $(COPTS) # -Bstatic	# older gdb couldn't handle shared libs
 SHAR	= bundle
 OFILE	= /usr/bin/file		# old or distributed version, for comparison
-
 # Where new binary lives; typically /usr/local (BSD), /usr/lbin (USG).
-BINDIR	= /usr/bin
-
+BINDIR	= @exec_prefix@/bin
 # For installing our man pages; 
 # MANCxxx is manual section for Commands, MANFxxx is section for file formats.
 # MANxDIR is directory names; MANxEXT is the filename extention. Usual values:
@@ -63,10 +59,10 @@ BINDIR	= /usr/bin
 # MANCDIR			/usr/man/local/man1
 # MANCEXT			1
 
-MANCDIR	= /usr/local/man/man1
+MANCDIR	= @mandir@/man1
 MANCEXT	= 1
-MANFDIR	= /usr/local/man/man5
-MANFEXT	= 5
+MANFDIR	= @mandir@/man4
+MANFEXT	= 4
 
 # There are no system-dependant configuration options (except maybe CFLAGS).
 # Uncomment any of these that is missing from your "standard" library.
@@ -79,14 +75,16 @@ LOCALOBJS = # localsrc/getopt.o localsrc/strtol.o \
 LOCALINC = # localinc/*.h localinc/sys/*.h
 
 SRCS = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \
-	compress.c is_tar.c \
+	compress.c is_tar.c readelf.c internat.c \
 	print.c $(LOCALSRCS) $(LOCALINC)
 OBJS = file.o apprentice.o fsmagic.o softmagic.o ascmagic.o \
-	compress.o is_tar.o \
+	compress.o is_tar.o readelf.o internat.o \
 	print.o $(LOCALOBJS)
+HDRS = file.h names.h patchlevel.h readelf.h tar.h
 
-ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) *.h \
-	 Makefile file.man magic.man 
+AUTOSRC=configure configure.in install-sh config.h.in Makefile.in
+ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) $(HDRS) \
+	 Makefile.std file.man magic.man magic2mime $(AUTOSRC)
 ALLMAGIC =   Magdir/Makefile Magdir/Localstuff Magdir/Header Magdir/[a-z]*
 
 all:		file magic file.${MANCEXT} magic.${MANFEXT}
@@ -112,8 +110,11 @@ ascmagic.o:	names.h
 compress.o apprentice.o ascmagic.o file.o fsmagic.o print.o softmagic.o: file.h
 
 install:	file magic
-		cp file	$(BINDIR)/file
-		cp magic $(MAGIC)
+		-mkdir $(BINDIR) $(MAGICDIR) $(MANCDIR) $(MANFDIR)
+		$(INSTALLCMD) file	$(BINDIR)/file
+		$(INSTALLCMD) magic $(MAGIC)
+		$(INSTALLCMD) file.${MANCEXT} $(MANCDIR)/file.$(MANCEXT)
+		$(INSTALLCMD) magic.${MANFEXT} $(MANFDIR)/magic.$(MANFEXT)
 
 install.man: file.${MANCEXT} magic.${MANFEXT}
 		cp file.${MANCEXT} $(MANCDIR)/file.$(MANCEXT)
@@ -121,7 +122,8 @@ install.man: file.${MANCEXT} magic.${MANFEXT}
 
 clean:
 		rm -f *.o core file magic lint dist.* MANIFEST \
-		      magic.${MANFEXT} file.${MANCEXT}
+		      magic.${MANFEXT} file.${MANCEXT} \
+		      config.h config.status config.cache config.log
 clobber:
 		cd tst; $(MAKE) clean
 

+ 11 - 8
orig/Makefile

@@ -1,6 +1,6 @@
 # Makefile for file(1) cmd. 
 # Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
-# @(#)$Id: Makefile,v 1.51 1996/06/22 22:05:07 christos Exp $
+# @(#)$Id: Makefile.std,v 1.3 1998/02/15 23:21:17 christos Exp $
 #
 # This software is not subject to any license of the American Telephone
 # and Telegraph Company or of the Regents of the University of California.
@@ -21,11 +21,11 @@
 #    ever read sources, credits must appear in the documentation.
 #
 # 4. This notice may not be removed or altered.
-VERSION	= 3.20
+VERSION	= 3.24
 SHELL	= /bin/sh
 #MAGIC	= /etc/magic
 MAGIC	= /usr/local/etc/magic
-DEFS	= -DMAGIC='"$(MAGIC)"' # -Dvoid=int
+DEFS	= -DMAGIC='"$(MAGIC)"' -DBUILTIN_ELF # -Dvoid=int
 CC	= cc
 COPTS	= -O -g		# newer compilers allow both; else drop -O
 # For truly antique environments, use this for (dummy) include files:
@@ -70,14 +70,16 @@ LOCALOBJS = # localsrc/getopt.o localsrc/strtol.o \
 LOCALINC = # localinc/*.h localinc/sys/*.h
 
 SRCS = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \
-	compress.c is_tar.c \
+	compress.c is_tar.c readelf.c internat.c \
 	print.c $(LOCALSRCS) $(LOCALINC)
 OBJS = file.o apprentice.o fsmagic.o softmagic.o ascmagic.o \
-	compress.o is_tar.o \
+	compress.o is_tar.o readelf.o internat.o \
 	print.o $(LOCALOBJS)
+HDRS = file.h names.h patchlevel.h readelf.h tar.h
 
-ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) *.h \
-	 Makefile file.man magic.man 
+AUTOSRC=configure configure.in install-sh config.h.in Makefile.in
+ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) $(HDRS) \
+	 Makefile.std file.man magic.man magic2mime $(AUTOSRC)
 ALLMAGIC =   Magdir/Makefile Magdir/Localstuff Magdir/Header Magdir/[a-z]*
 
 all:		file magic file.${MANCEXT} magic.${MANFEXT}
@@ -112,7 +114,8 @@ install.man: file.${MANCEXT} magic.${MANFEXT}
 
 clean:
 		rm -f *.o core file magic lint dist.* MANIFEST \
-		      magic.${MANFEXT} file.${MANCEXT}
+		      magic.${MANFEXT} file.${MANCEXT} \
+		      config.h config.status config.cache config.log
 clobber:
 		cd tst; $(MAKE) clean
 

+ 22 - 20
README

@@ -1,21 +1,9 @@
 ** README for file(1) Command **
-@(#) $Id: README,v 1.20 1993/09/23 21:47:01 christos Exp $
-
-This is release 3.20.1 of the file(1) command for Linux. It was hacked
-out of version 3.20 (Ian Darwin and Christos Zoulas) by Albert Cahalan
-because the default compiler options were poor and because they refused
-to upload it to any Linux archive site. Linux archives ended up with
-version 3.15 + a patch to fix a bug. (Linux users: please help keep the
-archives updated. Remember to use the C compiler options I put in the
-Makefile, increase the version by 0.0.1 as requested, and add yourself
-to the documentation as requested. Archive sites include sunsite.unc.edu,
-tsx-11.mit.edu, ftp.funet.fi, and ftp.redhat.com) <acahalan@cs.uml.edu>
+@(#) $Id: README,v 1.22 1997/11/05 16:03:18 christos Exp $
 
 This is Release 3.x of Ian Darwin's (copyright but distributable)
-file(1) command.  Release 3.x is scheduled for inclusion in the
-4.4 BSD (Berkeley Software Distribution) of UNIX-like
-software, and is the standard "file" command for Linux, 386bsd,
-and other systems. (See "patchlevel.h" for the exact release number).
+file(1) command. This version is the standard "file" command for Linux,
+*BSD, and other systems. (See "patchlevel.h" for the exact release number).
 
 UNIX is a trademark of UNIX System Laboratories.
 
@@ -68,17 +56,31 @@ magic.4 - man page for the magic file, courtesy Guy Harris.
 file.c - main program
 file.h - header file
 fsmagic.c - first set of tests the program runs, based on filesystem info
-is_tar.c - knows about tarchives (courtesy John Gilmore).
+is_tar.c, tar.h - knows about tarchives (courtesy John Gilmore).
 magdir - directory of /etc/magic pieces
 	magdir/Makefile - ADJUST THIS FOR YOUR CONFIGURATION
 names.h - header file for ascmagic.c
 softmagic.c - 2nd set of tests, based on /etc/magic
-strtok.c, getopt.c - in case you them (courtesy of Henry Spencer).
-strtol.c, strchr.c - in case you need them - public domain.
-tst - simple test suite, built from tst/Makefile
+readelf.[ch] - Standalone elf parsing code.
+compress.c - on-the-fly decompression.
+internat.c - recognize international `text' files.
+print.c - print results, errors, warnings.
 
+If your gzip sometimes fails to decompress things complaining about a short
+file, apply this patch [which is going to be in the next version of gzip]:
+*** -   Tue Oct 29 02:06:35 1996
+--- util.c      Sun Jul 21 21:51:38 1996
+*** 106,111 ****
+--- 108,114 ----
+  
+      if (insize == 0) {
+        if (eof_ok) return EOF;
++       flush_window();
+        read_error();
+      }
+      bytes_in += (ulg)insize;
 
-E-mail: christos@deshaw.com, moraes@deshaw.com
+E-mail: christos@astron.com, moraes@deshaw.com
 
 Phone: Do not even think of telephoning me about this program. Send cash first!
 

+ 7 - 12
apprentice.c

@@ -34,7 +34,7 @@
 
 #ifndef	lint
 static char *moduleid = 
-	"@(#)$Id: apprentice.c,v 1.24 1996/06/22 22:04:22 christos Exp $";
+	"@(#)$Id: apprentice.c,v 1.25 1997/01/15 17:23:24 christos Exp $";
 #endif	/* lint */
 
 #define	EATAB {while (isascii((unsigned char) *l) && \
@@ -133,10 +133,10 @@ int check;			/* non-zero? checking-only run. */
 /*
  * extend the sign bit if the comparison is to be signed
  */
-unsigned long
+uint32
 signextend(m, v)
 struct magic *m;
-unsigned long v;
+uint32 v;
 {
 	if (!(m->flag & UNSIGNED))
 		switch(m->type) {
@@ -159,7 +159,7 @@ unsigned long v;
 		case LONG:
 		case BELONG:
 		case LELONG:
-			v = (long) v;
+			v = (int32) v;
 			break;
 		case STRING:
 			break;
@@ -495,21 +495,16 @@ int	plen, *slen;
 				*p++ = (char)val;
 				break;
 
-			/* \x and up to 3 hex digits */
+			/* \x and up to 2 hex digits */
 			case 'x':
 				val = 'x';	/* Default if no digits */
 				c = hextoint(*s++);	/* Get next char */
 				if (c >= 0) {
 					val = c;
 					c = hextoint(*s++);
-					if (c >= 0) {
+					if (c >= 0)
 						val = (val << 4) + c;
-						c = hextoint(*s++);
-						if (c >= 0) {
-							val = (val << 4) + c;
-						} else
-							--s;
-					} else
+					else
 						--s;
 				} else
 					--s;

+ 9 - 7
ascmagic.c

@@ -28,6 +28,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <memory.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -36,7 +37,7 @@
 
 #ifndef	lint
 static char *moduleid = 
-	"@(#)$Id: ascmagic.c,v 1.20 1995/05/20 22:09:21 christos Exp $";
+	"@(#)$Id: ascmagic.c,v 1.22 1998/02/15 23:18:53 christos Exp $";
 #endif	/* lint */
 
 			/* an optimisation over plain strcmp() */
@@ -88,6 +89,13 @@ int nbytes;	/* size actually read */
 		return 1;
 	}
 
+
+	/* Make sure we are dealing with ascii text before looking for tokens */
+	for (i = 0; i < nbytes; i++) {
+		if (!isascii(buf[i]))
+			return 0;	/* not all ASCII */
+	}
+
 	/* look for tokens from names.h - this is expensive! */
 	/* make a copy of the buffer here because strtok() will destroy it */
 	s = (unsigned char*) memcpy(nbuf, buf, nbytes);
@@ -106,12 +114,6 @@ int nbytes;	/* size actually read */
 		}
 	}
 
-
-	for (i = 0; i < nbytes; i++) {
-		if (!isascii(buf[i]))
-			return 0;	/* not all ASCII */
-	}
-
 	/* all else fails, but it is ASCII... */
 	ckfputs("ASCII text", stdout);
 	if (has_escapes) {

+ 6 - 1
compress.c

@@ -4,13 +4,18 @@
  *		   information if recognized
  *	uncompress(method, old, n, newch) - uncompress old into new, 
  *					    using method, return sizeof new
- * $Id: compress.c,v 1.9 1995/05/20 22:09:21 christos Exp $
+ * $Id: compress.c,v 1.10 1998/02/15 23:18:53 christos Exp $
  */
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 #include "file.h"
 

+ 16 - 0
config.h.in

@@ -0,0 +1,16 @@
+/* config.h.in.  Generated automatically from configure.in by autoheader.  */
+
+/* Define to empty if the keyword does not work.  */
+#undef const
+
+/* Define if your struct stat has st_rdev.  */
+#undef HAVE_ST_RDEV
+
+/* Define to `long' if <sys/types.h> doesn't define.  */
+#undef off_t
+
+/* Define to `unsigned' if <sys/types.h> doesn't define.  */
+#undef size_t
+
+/* Define if you have the ANSI C header files.  */
+#undef STDC_HEADERS

File diff suppressed because it is too large
+ 1393 - 0
configure


+ 15 - 0
configure.in

@@ -0,0 +1,15 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(file.c)
+
+dnl Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_LN_S
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_STRUCT_ST_RDEV
+
+AC_OUTPUT(Makefile config.h)

+ 0 - 20
file-3.20.1.lsm

@@ -1,20 +0,0 @@
-Begin3
-Title:          file(1): C sources
-Version:        3.20.1
-Entered-date:   29JUL96
-Description:    These are the sources to Darwin's file(1) utility and master
-                magic(4) file, now maintained by Christos Zoulas. The file(1)
-                utility is used to determine the types of various files;
-                file prints a one-line summary for each argument it is given.
-Keywords:       /etc/magic file identify magic /usr/bin/file source
-Author:         ian@sq.com (Ian F. Darwin)
-Maintained-by:  acahalan@cs.uml.edu (Albert Cahalan)
-                christos@ee.cornell.edu (Christos Zoulas)
-                moraes@deshaw.com (Mark Moraes)
-Primary-site:   sunsite.unc.edu pub/Linux/utils/file
-                70kB file-3.20.1.tgz
-Alternate-site: tsx-11.mit.edu
-Original-site:  ftp.deshaw.com /pub/file
-Platforms:      Linux
-Copying-policy: Free and copyrighted
-End

+ 39 - 62
file.c

@@ -26,7 +26,7 @@
  */
 #ifndef	lint
 static char *moduleid = 
-	"@(#)$Id: file.c,v 1.35 1996/06/22 22:04:22 christos Exp $";
+	"@(#)$Id: file.c,v 1.39 1998/02/15 23:18:53 christos Exp $";
 #endif	/* lint */
 
 #include <stdio.h>
@@ -37,22 +37,25 @@ static char *moduleid =
 #include <sys/stat.h>
 #include <fcntl.h>	/* for open() */
 #if (__COHERENT__ >= 0x420)
-#include <sys/utime.h>
+# include <sys/utime.h>
 #else
-#include <utime.h>
+# ifdef USE_UTIMES
+#  include <sys/time.h>
+# else
+#  include <utime.h>
+# endif
 #endif
 #include <unistd.h>	/* for read() */
 
-#include "readelf.h"
 #include <netinet/in.h>		/* for byte swapping */
 
 #include "patchlevel.h"
 #include "file.h"
 
 #ifdef S_IFLNK
-# define USAGE  "Usage: %s [-vczL] [-f namefile] [-m magicfiles] file...\n"
+# define USAGE  "Usage: %s [-vbczL] [-f namefile] [-m magicfiles] file...\n"
 #else
-# define USAGE  "Usage: %s [-vcz] [-f namefile] [-m magicfiles] file...\n"
+# define USAGE  "Usage: %s [-vbcz] [-f namefile] [-m magicfiles] file...\n"
 #endif
 
 #ifndef MAGIC
@@ -62,6 +65,7 @@ static char *moduleid =
 int 			/* Global command-line options 		*/
 	debug = 0, 	/* debugging 				*/
 	lflag = 0,	/* follow Symlinks (BSD only) 		*/
+	bflag = 0,	/* brief output format	 		*/
 	zflag = 0;	/* follow (uncompress) compressed files */
 
 int			/* Misc globals				*/
@@ -76,8 +80,10 @@ int lineno;		/* line number in the magic file	*/
 
 
 static void	unwrap		__P((char *fn));
+#if 0
 static int	byteconv4	__P((int, int, int));
 static short	byteconv2	__P((int, int, int));
+#endif
 
 /*
  * main - parse arguments and handle options
@@ -98,12 +104,15 @@ char *argv[];
 	if (!(magicfile = getenv("MAGIC")))
 		magicfile = MAGIC;
 
-	while ((c = getopt(argc, argv, "vcdf:Lm:z")) != EOF)
+	while ((c = getopt(argc, argv, "vbcdf:Lm:z")) != EOF)
 		switch (c) {
 		case 'v':
 			(void) fprintf(stdout, "%s-%d.%d\n", progname,
 				       FILE_VERSION_MAJOR, patchlevel);
 			return 1;
+		case 'b':
+			++bflag;
+			break;
 		case 'c':
 			++check;
 			break;
@@ -208,6 +217,7 @@ char *fn;
 }
 
 
+#if 0
 /*
  * byteconv4
  * Input:
@@ -270,6 +280,7 @@ byteconv2(from, same, big_endian)
   else
     return ntohs(from);		/* msb -> lsb conversion on lsb */
 }
+#endif
 
 /*
  * process - process input file
@@ -282,7 +293,6 @@ int wid;
 	int	fd = 0;
 	static  const char stdname[] = "standard input";
 	unsigned char	buf[HOWMANY+1];	/* one extra for terminating '\0' */
-	struct utimbuf  utbuf;
 	struct stat	sb;
 	int nbytes = 0;	/* number of bytes read from a datafile */
 	char match = '\0';
@@ -296,7 +306,7 @@ int wid;
 		inname = stdname;
 	}
 
-	if (wid > 0)
+	if (wid > 0 && !bflag)
 	     (void) printf("%s:%*s ", inname, 
 			   (int) (wid - strlen(inname)), "");
 
@@ -335,67 +345,30 @@ int wid;
 		match = tryit(buf, nbytes, zflag);
 	}
 
-	/*
-	 * ELF executables have multiple section headers in arbitrary
-	 * file locations and thus file(1) cannot determine it from easily.
-	 * Instead we traverse thru all section headers until a symbol table
-	 * one is found or else the binary is stripped.
-	 */
-
-	if (match == 's' && nbytes > sizeof (Elf32_Ehdr) &&
-	    buf[EI_MAG0] == ELFMAG0 &&
-	    buf[EI_MAG1] == ELFMAG1 &&
-	    buf[EI_MAG2] == ELFMAG2 &&
-	    buf[EI_MAG3] == ELFMAG3) {
-
-		union {
-			int l;
-			char c[sizeof (int)];
-		} u;
-
-		Elf32_Ehdr elfhdr;
-		int stripped = 1;
-		int be,same;
-		short shnum;
-
-		u.l = 1;
-		(void) memcpy(&elfhdr, buf, sizeof elfhdr);
-
-		/*
-		 * If the system byteorder does not equal the object byteorder
-		 * then need to do byte-swapping.
-		 */
-		be = u.c[sizeof(int) - 1] == 1; /* are we big endian? */
-		same = (u.c[sizeof(int) - 1] + 1) == elfhdr.e_ident[5];
-				/* are we the same endianness? */;
-
-		if (lseek(fd, byteconv4(elfhdr.e_shoff,same,be), SEEK_SET)<0)
-			error("lseek failed (%s).\n", strerror(errno));
-
-		for (shnum = byteconv2(elfhdr.e_shnum,same,be);
-		     shnum; shnum--) {
-		    if (read(fd, buf,
-			     byteconv2(elfhdr.e_shentsize,same,be))<0)
-			error("read failed (%s).\n", strerror(errno));
-		    if (byteconv4(((Elf32_Shdr *)buf)->sh_type,same,be)
-			== SHT_SYMTAB) {
-			stripped = 0;
-			break;
-		    }
-		}
-		if (stripped)
-		    (void) printf (", stripped");
-		else
-		    (void) printf (", not stripped");
-	}
+#ifdef BUILTIN_ELF
+	if (match == 's' && nbytes > 5)
+		tryelf(fd, buf, nbytes);
+#endif
 
 	if (inname != stdname) {
+#ifdef RESTORE_TIME
 		/*
 		 * Try to restore access, modification times if read it.
 		 */
+# ifdef USE_UTIMES
+		struct timeval  utsbuf[2];
+		utsbuf[0].tv_sec = sb.st_atime;
+		utsbuf[1].tv_sec = sb.st_mtime;
+
+		(void) utimes(inname, utsbuf); /* don't care if loses */
+# else
+		struct utimbuf  utbuf;
+
 		utbuf.actime = sb.st_atime;
 		utbuf.modtime = sb.st_mtime;
 		(void) utime(inname, &utbuf); /* don't care if loses */
+# endif
+#endif
 		(void) close(fd);
 	}
 	(void) putchar('\n');
@@ -419,6 +392,10 @@ int nb, zflag;
 	if (ascmagic(buf, nb))
 		return 'a';
 
+	/* see if it's international language text */
+	if (internatmagic(buf, nb))
+		return 'i';
+
 	/* abandon hope, all ye who remain here */
 	ckfputs("data", stdout);
 		return '\0';

+ 26 - 8
file.h

@@ -1,6 +1,6 @@
 /*
  * file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.23 1996/06/22 22:04:22 christos Exp $
+ * @(#)$Id: file.h,v 1.25 1997/01/15 19:28:35 christos Exp $
  *
  * Copyright (c) Ian F. Darwin, 1987.
  * Written by Ian F. Darwin.
@@ -26,6 +26,12 @@
  * 4. This notice may not be removed or altered.
  */
 
+#ifndef __file_h__
+#define __file_h__
+
+typedef int int32;
+typedef unsigned int uint32;
+
 #ifndef HOWMANY
 # define HOWMANY 8192		/* how much of the file to look at */
 #endif
@@ -41,9 +47,9 @@ struct magic {
 	short cont_level;	/* level of ">" */
 	struct {
 		char type;	/* byte short long */
-		long offset;	/* offset from indirection */
+		int32 offset;	/* offset from indirection */
 	} in;
-	long offset;		/* offset to magic number */
+	int32 offset;		/* offset to magic number */
 	unsigned char reln;	/* relation (0=eq, '>'=gt, etc) */
 	char type;		/* int, short, long or string. */
 	char vallen;		/* length of string value, if any */
@@ -61,12 +67,12 @@ struct magic {
 	union VALUETYPE {
 		unsigned char b;
 		unsigned short h;
-		unsigned long l;
+		uint32 l;
 		char s[MAXstring];
 		unsigned char hs[2];	/* 2 bytes of a fixed-endian "short" */
 		unsigned char hl[4];	/* 2 bytes of a fixed-endian "long" */
 	} value;		/* either number or string */
-	unsigned long mask;	/* mask before comparison with value */
+	uint32 mask;	/* mask before comparison with value */
 	char nospflag;		/* supress space character */
 	char desc[MAXDESC];	/* description */
 };
@@ -98,8 +104,9 @@ extern int   softmagic		__P((unsigned char *, int));
 extern int   tryit		__P((unsigned char *, int, int));
 extern int   zmagic		__P((unsigned char *, int));
 extern void  ckfprintf		__P((FILE *, const char *, ...));
-extern unsigned long signextend	__P((struct magic *, unsigned long));
-
+extern uint32 signextend	__P((struct magic *, unsigned int32));
+extern int internatmagic	__P((unsigned char *, int));
+extern void tryelf		__P((int, char *, int));
 
 
 extern int errno;		/* Some unixes don't define this..	*/
@@ -119,7 +126,16 @@ extern int lflag;		/* follow symbolic links?		*/
 extern int optind;		/* From getopt(3)			*/
 extern char *optarg;
 
-#if !defined(__STDC__) || defined(sun) || defined(__sun__) || defined(__convex__)
+#if defined(sun) || defined(__sun__) || defined (__sun)
+# if defined(__svr4) || defined (__SVR4) || defined(__svr4__)
+#  define SOLARIS
+# else
+#  define SUNOS
+# endif
+#endif
+
+
+#if !defined(__STDC__) || defined(SUNOS) || defined(__convex__)
 extern int sys_nerr;
 extern char *sys_errlist[];
 #define strerror(e) \
@@ -130,3 +146,5 @@ extern char *sys_errlist[];
 #ifndef MAXPATHLEN
 #define	MAXPATHLEN	512
 #endif
+
+#endif /* __file_h__ */

+ 13 - 9
file.man

@@ -1,12 +1,12 @@
 .TH FILE __CSECTION__ "Copyright but distributable"
-.\" $Id: file.man,v 1.27 1996/06/22 22:05:07 christos Exp $
+.\" $Id: file.man,v 1.31 1998/02/15 23:18:53 christos Exp $
 .SH NAME
 file
 \- determine file type
 .SH SYNOPSIS
 .B file
 [
-.B \-vczL
+.B \-vbczL
 ]
 [
 .B \-f
@@ -115,6 +115,9 @@ This can be a single file, or a colon-separated list of files.
 .B \-z
 Try to look inside compressed files.
 .TP 8
+.B \-b
+Do not prepend filenames to output lines (brief mode).
+.TP 8
 .B \-c
 Cause a checking printout of the parsed form of the magic file.
 This is usually used in conjunction with 
@@ -146,7 +149,7 @@ can be used to set the default magic number files.
 .BR magic (__FSECTION__)
 \- description of magic file format.
 .br
-.BR strings (1), " od" (1)
+.BR strings (1), " od" (1), " hexdump(1)"
 \- tools for examining non-textfiles.
 .SH STANDARDS CONFORMANCE
 This program is believed to exceed the System V Interface Definition
@@ -228,7 +231,7 @@ postal address: P.O. Box 603, Station F, Toronto, Ontario, CANADA M4Y 2L8.
 Altered by Rob McMahon, cudcv@warwick.ac.uk, 1989, to extend the `&' operator
 from simple `x&y != 0' to `x&y op z'.
 .PP
-Altered by Guy Harris, guy@auspex.com, 1993, to:
+Altered by Guy Harris, guy@netapp.com, 1993, to:
 .RS
 .PP
 put the ``old-style'' `&'
@@ -248,7 +251,7 @@ the process running
 .RE
 .PP
 Changes by Ian Darwin and various authors including
-Christos Zoulas (christos@ee.cornell.edu), 1990-1992.
+Christos Zoulas (christos@astron.com), 1990-1997.
 .SH LEGAL NOTICE
 Copyright (c) Ian F. Darwin, Toronto, Canada,
 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993.
@@ -358,7 +361,8 @@ This program is slower than some vendors' file commands.
 .PP
 This manual page, and particularly this section, is too long.
 .SH AVAILABILITY
-You should be able to obtain the original author's latest version
-from ftp://tesla.ee.cornell.edu/pub/, but that might not work.
-You can also try ftp://ftp.deshaw.com/pub/file/ or (as a last resort)
-ftp://ftp.uu.net/pub/FreeBSD/FreeBSD-current/src/usr.bin/file/.
+You can obtain the original author's latest version by anonymous FTP
+on
+.B ftp.astron.com
+in the directory
+.I /pub/file/file-X.YY.tar.gz

+ 21 - 5
fsmagic.c

@@ -31,6 +31,14 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifndef major
+# if defined(__SVR4) || defined(_SVR4_SOURCE)
+#  include <sys/mkdev.h>
+# endif
+#endif
 #ifndef	major			/* if `major' not defined in types.h, */
 #include <sys/sysmacros.h>	/* try this one. */
 #endif
@@ -46,7 +54,7 @@
 
 #ifndef	lint
 static char *moduleid = 
-	"@(#)$Id: fsmagic.c,v 1.23 1995/01/21 21:03:35 christos Exp $";
+	"@(#)$Id: fsmagic.c,v 1.26 1998/02/15 23:18:53 christos Exp $";
 #endif	/* lint */
 
 int
@@ -84,12 +92,20 @@ struct stat *sb;
 		ckfputs("directory", stdout);
 		return 1;
 	case S_IFCHR:
-		(void) printf("character special (%d/%d)",
-			major(sb->st_rdev), minor(sb->st_rdev));
+#ifdef HAVE_ST_RDEV
+		(void) printf("character special (%ld/%ld)",
+			(long) major(sb->st_rdev), (long) minor(sb->st_rdev));
+#else
+		(void) printf("character special");
+#endif
 		return 1;
 	case S_IFBLK:
-		(void) printf("block special (%d/%d)",
-			major(sb->st_rdev), minor(sb->st_rdev));
+#ifdef HAVE_ST_RDEV
+		(void) printf("block special (%ld/%ld)",
+			(long) major(sb->st_rdev), (long) minor(sb->st_rdev));
+#else
+		(void) printf("block special");
+#endif
 		return 1;
 	/* TODO add code to handle V7 MUX and Blit MUX files */
 #ifdef	S_IFIFO

+ 238 - 0
install-sh

@@ -0,0 +1,238 @@
+#! /bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+#
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+tranformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+	-c) instcmd="$cpprog"
+	    shift
+	    continue;;
+
+	-d) dir_arg=true
+	    shift
+	    continue;;
+
+	-m) chmodcmd="$chmodprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-o) chowncmd="$chownprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-g) chgrpcmd="$chgrpprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-s) stripcmd="$stripprog"
+	    shift
+	    continue;;
+
+	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
+	    shift
+	    continue;;
+
+	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+	    shift
+	    continue;;
+
+	*)  if [ x"$src" = x ]
+	    then
+		src=$1
+	    else
+		# this colon is to work around a 386BSD /bin/sh bug
+		:
+		dst=$1
+	    fi
+	    shift
+	    continue;;
+    esac
+done
+
+if [ x"$src" = x ]
+then
+	echo "install:	no input file specified"
+	exit 1
+else
+	true
+fi
+
+if [ x"$dir_arg" != x ]; then
+	dst=$src
+	src=""
+	
+	if [ -d $dst ]; then
+		instcmd=:
+	else
+		instcmd=mkdir
+	fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad 
+# if $src (and thus $dsttmp) contains '*'.
+
+	if [ -f $src -o -d $src ]
+	then
+		true
+	else
+		echo "install:  $src does not exist"
+		exit 1
+	fi
+	
+	if [ x"$dst" = x ]
+	then
+		echo "install:	no destination specified"
+		exit 1
+	else
+		true
+	fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+	if [ -d $dst ]
+	then
+		dst="$dst"/`basename $src`
+	else
+		true
+	fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+#  this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='	
+'
+IFS="${IFS-${defaultIFS}}"
+
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+	pathcomp="${pathcomp}${1}"
+	shift
+
+	if [ ! -d "${pathcomp}" ] ;
+        then
+		$mkdirprog "${pathcomp}"
+	else
+		true
+	fi
+
+	pathcomp="${pathcomp}/"
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+	$doit $instcmd $dst &&
+
+	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
+	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
+	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
+	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+	if [ x"$transformarg" = x ] 
+	then
+		dstfile=`basename $dst`
+	else
+		dstfile=`basename $dst $transformbasename | 
+			sed $transformarg`$transformbasename
+	fi
+
+# don't allow the sed command to completely eliminate the filename
+
+	if [ x"$dstfile" = x ] 
+	then
+		dstfile=`basename $dst`
+	else
+		true
+	fi
+
+# Make a temp file name in the proper directory.
+
+	dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+	$doit $instcmd $src $dsttmp &&
+
+	trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing.  If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
+	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
+	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
+	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
+
+# Now rename the file to the real destination.
+
+	$doit $rmcmd -f $dstdir/$dstfile &&
+	$doit $mvcmd $dsttmp $dstdir/$dstfile 
+
+fi &&
+
+
+exit 0

+ 82 - 0
internat.c

@@ -0,0 +1,82 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <joerg@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.   Joerg Wunsch
+ * ----------------------------------------------------------------------------
+ */
+
+#include "file.h"
+
+#include <string.h>
+#include <memory.h>
+
+#define F 0
+#define T 1
+
+/*
+ * List of characters that look "reasonable" in international
+ * language texts.  That's almost all characters :), except a
+ * few in the control range of ASCII (all the known international
+ * charactersets share the bottom half with ASCII).
+ */
+static char maybe_internat[256] = {
+	F, F, F, F, F, F, F, F, T, T, T, T, T, T, F, F,  /* 0x0X */
+	F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F,  /* 0x1X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x2X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x3X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x4X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x5X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x6X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F,  /* 0x7X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x8X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0x9X */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xaX */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xbX */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xcX */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xdX */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,  /* 0xeX */
+	T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T   /* 0xfX */
+};
+
+/* Maximal length of a line we consider "reasonable". */
+#define MAXLINELEN 300
+
+int
+internatmagic(buf, nbytes)
+	unsigned char *buf;
+	int nbytes;
+{
+	int i;
+	unsigned char *cp;
+
+	nbytes--;
+
+	/* First, look whether there are "unreasonable" characters. */
+	for (i = 0, cp = buf; i < nbytes; i++, cp++)
+		if (!maybe_internat[*cp])
+			return 0;
+
+	/*
+	 * Now, look whether the file consists of lines of
+	 * "reasonable" length.
+	 */
+
+	for (i = 0; i < nbytes;) {
+		cp = (unsigned char *) memchr(buf, '\n', nbytes - i);
+		if (cp == NULL) {
+			/* Don't fail if we hit the end of buffer. */
+			if (i + MAXLINELEN >= nbytes)
+				break;
+			else
+				return 0;
+		}
+		if (cp - buf > MAXLINELEN)
+			return 0;
+		i += (cp - buf + 1);
+		buf = cp + 1;
+	}
+	ckfputs("International language text", stdout);
+	return 1;
+}

+ 6 - 6
is_tar.c

@@ -5,7 +5,7 @@
  * Pubic Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu).
  *
  * @(#)list.c 1.18 9/23/86 Public Domain - gnu
- * $Id: is_tar.c,v 1.8 1993/09/16 21:09:35 christos Exp $
+ * $Id: is_tar.c,v 1.9 1997/01/15 17:23:24 christos Exp $
  *
  * Comments changed and some code/comments reformatted
  * for file command by Ian Darwin.
@@ -19,9 +19,9 @@
 #define	isodigit(c)	( ((c) >= '0') && ((c) <= '7') )
 
 #if	defined(__STDC__) || defined(__cplusplus)
-static long from_oct(int, char*);	/* Decode octal number */
+static int from_oct(int, char*);	/* Decode octal number */
 #else
-static long from_oct();
+static int from_oct();
 #endif
 
 /*
@@ -37,7 +37,7 @@ int nbytes;
 {
 	register union record *header = (union record *)buf;
 	register int	i;
-	register long	sum, recsum;
+	register int	sum, recsum;
 	register char	*p;
 
 	if (nbytes < sizeof(union record))
@@ -75,12 +75,12 @@ int nbytes;
  *
  * Result is -1 if the field is invalid (all blank, or nonoctal).
  */
-static long
+static int
 from_oct(digs, where)
 	register int	digs;
 	register char	*where;
 {
-	register long	value;
+	register int	value;
 
 	while (isspace(*where)) {		/* Skip spaces */
 		where++;

+ 68 - 0
magic2mime

@@ -0,0 +1,68 @@
+#! /usr/local/bin/perl
+# -*- PERL -*-
+# $Id: magic2mime,v 1.1 1998/02/15 23:18:53 christos Exp $
+# Copyright (c) 1996, 1997 vax@linkdead.paranoia.com (VaX#n8)
+#
+# Usage: echo 'your-file-output-here' | file_to_ctype.pl
+#        file -b files... | file_to_ctype.pl
+# It acts like a filter, reading from STDIN and any files on the command
+# line, printing to STDOUT.
+
+## refs
+# http://www.faqs.org/faqs/mail/mime-faq/part1/index.html
+#  comp.mail.mime FAQ
+# ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types
+#  assigned content-types
+# ftp://ftp.uu.net/inet/rfc/rfc-index
+#  RFC index; search for MIME
+
+@mapping =
+(
+	# defaults
+    'data', 'application/octet-stream',
+    'text', 'text/plain',
+	# more specific
+	'^Rich Text Format data', 'text/richtext',
+	'^HTML document text', 'text/html',
+	'^exported SGML document text', 'text/sgml',
+	'mail text', 'message/rfc822',
+	'news text', 'message/news',
+	'^PostScript document text', 'application/postscript',
+	'^BinHex binary text', 'application/mac-binhex40',
+	'^Zip archive data', 'application/zip',
+	'^Microsoft Word', 'application/msword',
+	'^PGP key', 'application/pgp-keys',
+	'^PGP encrypted', 'application/pgp-encrypted',
+	'^PGP armored data signature', 'application/pgp-signature',
+    '^JPEG image', 'image/jpeg',
+    '^GIF image', 'image/gif',
+	'^PNG image', 'image/png',
+    '^TIFF image', 'image/tiff',
+	'Computer Graphics Metafile', 'image/cgf',
+	'^Sun/NeXT audio data', 'audio/basic',
+    '^MPEG', 'video/mpeg',
+    '^Apple QuickTime movie', 'video/quicktime',
+	# made up by me
+    '^bitmap', 'image/x-bitmap',
+    '^PC bitmap data, Windows 3.x format', 'image/x-msw3bmp',
+    '^FLI', 'video/x-fli',
+    '^FLC', 'video/x-flc',
+    'AVI data', 'video/x-avi',
+    'WAVE', 'audio/x-wav',
+    'VOC', 'audio/x-voc',
+);
+
+local($mimetype,$index,$regexp);
+while (<>)
+  {
+    chop;
+    $index = $#mapping - 1;
+    while ($index > -1 && !defined($mimetype))
+      {
+         $mimetype = $mapping[$index + 1] if (/$mapping[$index]/);
+         $index -= 2;
+      }
+    print "$mimetype\n";
+	undef $mimetype; # hack
+  }
+0;

+ 17 - 9
names.h

@@ -10,22 +10,24 @@
  *
  * See LEGAL.NOTICE
  *
- * $Id: names.h,v 1.12 1995/04/28 17:29:13 christos Exp $
+ * $Id: names.h,v 1.13 1997/01/15 17:23:24 christos Exp $
  */
 
 /* these types are used to index the table 'types': keep em in sync! */
 #define L_C	0		/* first and foremost on UNIX */
-#define	L_FORT	1		/* the oldest one */
-#define L_MAKE	2		/* Makefiles */
-#define L_PLI	3		/* PL/1 */
-#define L_MACH	4		/* some kinda assembler */
-#define L_ENG	5		/* English */
-#define	L_PAS	6		/* Pascal */
-#define	L_MAIL	7		/* Electronic mail */
-#define	L_NEWS	8		/* Usenet Netnews */
+#define L_CC	1		/* Bjarne's postincrement */
+#define	L_FORT	2		/* the oldest one */
+#define L_MAKE	3		/* Makefiles */
+#define L_PLI	4		/* PL/1 */
+#define L_MACH	5		/* some kinda assembler */
+#define L_ENG	6		/* English */
+#define	L_PAS	7		/* Pascal */
+#define	L_MAIL	8		/* Electronic mail */
+#define	L_NEWS	9		/* Usenet Netnews */
 
 static char *types[] = {
 	"C program text",
+	"C++ program text",
 	"FORTRAN program text",
 	"make commands text" ,
 	"PL/1 program text",
@@ -43,6 +45,12 @@ static struct names {
 } names[] = {
 	/* These must be sorted by eye for optimal hit rate */
 	/* Add to this list only after substantial meditation */
+	{"//",		L_CC},
+	{"template",	L_CC},
+	{"virtual",	L_CC},
+	{"class",	L_CC},
+	{"public:",	L_CC},
+	{"private:",	L_CC},
 	{"/*",		L_C},	/* must precede "The", "the", etc. */
 	{"#include",	L_C},
 	{"char",	L_C},

+ 0 - 61
orig/Magdir_elf

@@ -1,61 +0,0 @@
-
-#------------------------------------------------------------------------------
-# elf:  file(1) magic for ELF executables
-#
-# We have to check the byte order flag to see what byte order all the
-# other stuff in the header is in.
-#
-# Byte order is probably big-endian for MIPS RS3000 and Amdahl.
-# MIPS RS3000 may also be for MIPS RS2000.
-#
-# updated by Daniel Quinlan (quinlan@yggdrasil.com)
-0	string		\177ELF		ELF
->4	byte		0		invalid class
->4	byte		1		32-bit
->4	byte		2		64-bit
->5	byte		0		invalid byte order
->5	byte		1		LSB
->>16	leshort		0		no file type,
->>16	leshort		1		relocatable,
->>16	leshort		2		executable,
->>16	leshort		3		shared object,
-# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>
->>16	leshort		4		core file
->>>576  string          >\0             of '%s'
->>>400  lelong          >0              (signal %d),
->>16	leshort		&0xff00		processor-specific,
->>18	leshort		0		no machine,
->>18	leshort		1		AT&T WE32100 - invalid byte order,
->>18	leshort		2		SPARC - invalid byte order,
->>18	leshort		3		Intel 80386,
->>18	leshort		4		Motorola 68000 - invalid byte order,
->>18	leshort		5		Motorola 88000 - invalid byte order,
->>18	leshort		6		Intel 80486,
->>18	leshort		7		Intel 80860,
->>18	leshort		8		MIPS RS3000,
->>18	leshort		9		Amdahl,
->>20	lelong		0		invalid version
->>20	lelong		1		version 1
->>36	lelong		1		MathCoPro/FPU/MAU Required
->5	byte		2		MSB
->>16	beshort		0		no file type,
->>16	beshort		1		relocatable,
->>16	beshort		2		executable,
->>16	beshort		3		shared object,
->>16	beshort		4		core file,
->>>576	string		>\0		of '%s'
->>>400	lelong		>0		(signal %d),
->>16	beshort		&0xff00		processor-specific,
->>18	beshort		0		no machine,
->>18	beshort		1		AT&T WE32100,
->>18	beshort		2		SPARC,
->>18	beshort		3		Intel 80386 - invalid byte order,
->>18	beshort		4		Motorola 68000,
->>18	beshort		5		Motorola 88000,
->>18	beshort		6		Intel 80486 - invalid byte order,
->>18	beshort		7		Intel 80860,
->>18	beshort		8		MIPS RS3000,
->>18	leshort		9		Amdahl,
->>20	belong		0		invalid version
->>20	belong		1		version 1
->>36	belong		1		MathCoPro/FPU/MAU Required

+ 0 - 26
orig/Magdir_fonts

@@ -1,26 +0,0 @@
-
-#------------------------------------------------------------------------------
-# fonts:  file(1) magic for font data
-#
-0	string		FONT		ASCII vfont text
-0	short		0436		Berkeley vfont data
-0	short		017001		byte-swapped Berkeley vfont data
-
-# PostScript fonts (must precede "printer" entries), quinlan@yggdrasil.com
-0	string		%!PS-AdobeFont-1.0	PostScript Type 1 font text
->20	string		>\0			(%s)
-6	string		%!PS-AdobeFont-1.0	PostScript Type 1 font program data
-
-# X11 font files in SNF (Server Natural Format) format
-0	belong		00000004		X11 SNF font data, MSB first
-0	lelong		00000004		X11 SNF font data, LSB first
-
-# X11 Bitmap Distribution Format, from Daniel Quinlan (quinlan@yggdrasil.com)
-0	string		STARTFONT\040		X11 BDF font text
-
-# X11 fonts, from Daniel Quinlan (quinlan@yggdrasil.com)
-# PCF must come before SGI additions ("MIPSEL MIPS-II COFF" collides)
-0	string		\001fcp			X11 Portable Compiled Font data
->12	byte		0x02			\b, LSB first
->12	byte		0x0a			\b, MSB first
-0	string		D1.0\015		X11 Speedo font data

+ 0 - 0
orig/Magdir_freebsd


+ 0 - 224
orig/Magdir_images

@@ -1,224 +0,0 @@
-
-#------------------------------------------------------------------------------
-# images:  file(1) magic for image formats (see also "iff")
-#
-# originally from jef@helios.ee.lbl.gov (Jef Poskanzer),
-# additions by janl@ifi.uio.no as well as others. Jan also suggested
-# merging several one- and two-line files into here.
-#
-# little magic: PCX (first byte is 0x0a)
-# no magic: Targa
-
-# PBMPLUS images
-# The next byte following the magic is always whitespace.
-0	string		P1		PBM image text
-0	string		P2		PGM image text
-0	string		P3		PPM image text
-0	string		P4		PBM "rawbits" image data
-0	string		P5		PGM "rawbits" image data
-0	string		P6		PPM "rawbits" image data
-
-# NIFF (Navy Interchange File Format, a modification of TIFF) images
-0	string		IIN1		NIFF image data
-
-# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)
-# The second word of TIFF files is the TIFF version number, 42, which has
-# never changed.  The TIFF specification recommends testing for it.
-0	string		MM\x00\x2a	TIFF image data, big-endian
-0	string		II\x2a\x00	TIFF image data, little-endian
-
-# PNG [Portable Network Graphics, or "PNG's Not GIF"] images
-# (Greg Roelofs, newt@uchicago.edu)
-#
-# 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
-#
-0	string		\x89PNG		PNG image data,
->4	belong		!0x0d0a1a0a	CORRUPTED,
->16	belong		x		%ld x
->20	belong		x		%ld,
->24	byte		x		%d-bit
->25	byte		0		grayscale,
->25	byte		2		\b/color RGB,
->25	byte		3		colormap,
->25	byte		4		gray+alpha,
->25	byte		6		\b/color RGBA,
-#>26	byte		0		deflate/32K,
->28	byte		0		non-interlaced
->28	byte		1		interlaced
-
-# GIF
-0	string		GIF8		GIF image data
->4	string		7a		\b, version 8%s,
->4	string		9a		\b, version 8%s,
->6	leshort		>0		%hd x
->8	leshort		>0		%hd,
-#>10	byte		&0x80		color mapped,
-#>10	byte&0x07	=0x00		2 colors
-#>10	byte&0x07	=0x01		4 colors
-#>10	byte&0x07	=0x02		8 colors
-#>10	byte&0x07	=0x03		16 colors
-#>10	byte&0x07	=0x04		32 colors
-#>10	byte&0x07	=0x05		64 colors
-#>10	byte&0x07	=0x06		128 colors
-#>10	byte&0x07	=0x07		256 colors
-
-# ITC (CMU WM) raster files.  It is essentially a byte-reversed Sun raster,
-# 1 plane, no encoding.
-0	string		\361\0\100\273	CMU window manager raster image data
->4	lelong		>0		%d x
->8	lelong		>0		%d,
->12	lelong		>0		%d-bit
-
-# Magick Image File Format
-0	string		id=ImageMagick	MIFF image data
-
-# Artisan
-0	long		1123028772	Artisan image data
->4	long		1		\b, rectangular 24-bit
->4	long		2		\b, rectangular 8-bit with colormap
->4	long		3		\b, rectangular 32-bit (24-bit with matte)
-
-# FIG (Facility for Interactive Generation of figures), an object-based format
-0	string		#FIG		FIG image text
->5	string		x		\b, version %.3s
-
-# PHIGS
-0	string		ARF_BEGARF		PHIGS clear text archive
-0	string		@(#)SunPHIGS		SunPHIGS
-# version number follows, in the form m.n
->40	string		SunBin			binary
->32	string		archive			archive
-
-# GKS (Graphics Kernel System)
-0	string		GKSM		GKS Metafile
->24	string		SunGKS		\b, SunGKS
-
-# CGM image files
-0	string		BEGMF		clear text Computer Graphics Metafile
-# XXX - questionable magic
-0	beshort&0xffe0	0x0020		binary Computer Graphics Metafile
-0	beshort		0x3020		character Computer Graphics Metafile
-
-# MGR bitmaps  (Michael Haardt, u31b3hs@pool.informatik.rwth-aachen.de)
-0	string	yz	MGR bitmap, modern format, 8-bit aligned
-0	string	zz	MGR bitmap, old format, 1-bit deep, 16-bit aligned
-0	string	xz	MGR bitmap, old format, 1-bit deep, 32-bit aligned
-0	string	yx	MGR bitmap, modern format, squeezed
-
-# Fuzzy Bitmap (FBM) images
-0	string		%bitmap\0	FBM image data
->30	long		0x31		\b, mono
->30	long		0x33		\b, color
-
-# facsimile data
-1	string		PC\ Research,\ Inc	group 3 fax data
->29	byte		0		\b, normal resolution (204x98 DPI)
->29	byte		1		\b, fine resolution (204x196 DPI)
-
-# JPEG images
-0	beshort		0xffd8		JPEG image data
->6	string		JFIF		\b, JFIF standard
-# HSI is Handmade Software's proprietary JPEG encoding scheme
-0	string		hsi1		JPEG image data, HSI proprietary
-
-# PC bitmaps (OS/2, Windoze BMP files)  (Greg Roelofs, newt@uchicago.edu)
-0	string		BM		PC bitmap data
->14	leshort		12		\b, OS/2 1.x format
->>18	leshort		x		\b, %d x
->>20	leshort		x		%d
->14	leshort		64		\b, OS/2 2.x format
->>18	leshort		x		\b, %d x
->>20	leshort		x		%d
->14	leshort		40		\b, Windows 3.x format
->>18	lelong		x		\b, %d x
->>22	lelong		x		%d x
->>28	leshort		x		%d
-0	string		IC		PC icon data
-0	string		PI		PC pointer image data
-0	string		CI		PC color icon data
-0	string		CP		PC color pointer image data
-# Conflicts with other entries [BABYL]
-#0	string		BA		PC bitmap array data
-
-# XPM icons (Greg Roelofs, newt@uchicago.edu)
-# note possible collision with C/REXX entry in c-lang; currently commented out
-0	string		/*\ XPM\ */	X pixmap image text
-
-# Utah Raster Toolkit RLE images (janl@ifi.uio.no)
-0	leshort		0xcc52		RLE image data,
->6	leshort		x		%d x
->8	leshort		x		%d
->2	leshort		>0		\b, lower left corner: %d
->4	leshort		>0		\b, lower right corner: %d
->10	byte&0x1	=0x1		\b, clear first
->10	byte&0x2	=0x2		\b, no background
->10	byte&0x4	=0x4		\b, alpha channel
->10	byte&0x8	=0x8		\b, comment
->11	byte		>0		\b, %d color channels
->12	byte		>0		\b, %d bits per pixel
->13	byte		>0		\b, %d color map channels
-
-# image file format (Robert Potter, potter@cs.rochester.edu)
-0	string		Imagefile\ version-	iff image data
-# this adds the whole header (inc. version number), informative but longish
->10	string		>\0		%s
-
-# Sun raster images, from Daniel Quinlan (quinlan@yggdrasil.com)
-0	belong		0x59a66a95	Sun raster image data
->4	belong		>0		\b, %d x
->8	belong		>0		%d,
->12	belong		>0		%d-bit,
-#>16	belong		>0		%d bytes long,
->20	belong		0		old format,
-#>20	belong		1		standard,
->20	belong		2		compressed,
->20	belong		3		RGB,
->20	belong		4		TIFF,
->20	belong		5		IFF,
->20	belong		0xffff		reserved for testing,
->24	belong		0		no colormap
->24	belong		1		RGB colormap
->24	belong		2		raw colormap
-#>28	belong		>0		colormap is %d bytes long
-
-# SGI image file format, from Daniel Quinlan (quinlan@yggdrasil.com)
-# file://sgi.com/graphics/SGIIMAGESPEC
-0	beshort		474		SGI image data
-#>2	byte		0		\b, verbatim
->2	byte		1		\b, RLE
-#>3	byte		1		\b, normal precision
->3	byte		2		\b, high precision
->4	beshort		x		\b, %d-D
->6	beshort		x		\b, %d x
->8	beshort		x		%d
->10	beshort		x		\b, %d channel
->10	beshort		!1		\bs
->80	string		>0		\b, "%s"
-
-0	string		IT01		FIT image data
->4	belong		x		\b, %d x
->8	belong		x		%d x
->12	belong		x		%d
-#
-0	string		IT02		FIT image data
->4	belong		x		\b, %d x
->8	belong		x		%d x
->12	belong		x		%d
-#
-2048	string		PCD_IPI		Kodak Photo CD image pack file
-0	string		PCD_OPA		Kodak Photo CD overview pack file
-
-# FITS format.  Jeff Uphoff <juphoff@tarsier.cv.nrao.edu>
-# FITS is the Flexible Image Transport System, the de facto standard for
-# data and image transfer, storage, etc., for the astronomical community.
-# (FITS floating point formats are big-endian.)
-0	string	SIMPLE\ \ =	FITS image data
->109	string	8		\b, 8-bit, character or unsigned binary integer
->108	string	16		\b, 16-bit, two's complement binary integer
->107	string	\ 32		\b, 32-bit, two's complement binary integer
->107	string	-32		\b, 32-bit, floating point, single precision
->107	string	-64		\b, 64-bit, floating point, double precision
-
-# other images
-0	string	This\ is\ a\ BitMap\ file	Lisp Machine bit-array-file
-0	string		!!		Bennet Yee's "face" format

+ 0 - 35
orig/Magdir_intel

@@ -1,35 +0,0 @@
-
-#------------------------------------------------------------------------------
-# intel:  file(1) magic for x86 Unix
-#
-# Various flavors of x86 UNIX executable/object (other than Xenix, which
-# is in "microsoft").  DOS is in "msdos"; the ambitious soul can do
-# Windows as well.
-#
-# Windows NT belongs elsewhere, as you need x86 and MIPS and Alpha and
-# whatever comes next (HP-PA Hummingbird?).  OS/2 may also go elsewhere
-# as well, if, as, and when IBM makes it portable.
-#
-# The `versions' should be un-commented if they work for you.
-# (Was the problem just one of endianness?)
-#
-0	leshort		0502		basic-16 executable
->12	lelong		>0		not stripped
-#>22	leshort		>0		- version %ld
-0	leshort		0503		basic-16 executable (TV)
->12	lelong		>0		not stripped
-#>22	leshort		>0		- version %ld
-0	leshort		0510		x86 executable
->12	lelong		>0		not stripped
-0	leshort		0511		x86 executable (TV)
->12	lelong		>0		not stripped
-0	leshort		=0512		iAPX 286 executable small model (COFF)
->12	lelong		>0		not stripped
-#>22	leshort		>0		- version %ld
-0	leshort		=0522		iAPX 286 executable large model (COFF)
->12	lelong		>0		not stripped
-#>22	leshort		>0		- version %ld
-# SGI labeled the next entry as "iAPX 386 executable" --Dan Quinlan
-0	leshort		=0514		80386 COFF executable
->12	lelong		>0		not stripped
->22	leshort		>0		- version %ld

+ 0 - 73
orig/Magdir_linux

@@ -1,73 +0,0 @@
-
-#------------------------------------------------------------------------------
-# linux:  file(1) magic for Linux files
-#
-# Values for Linux/i386 binaries, from Daniel Quinlan <quinlan@yggdrasil.com>
-# The following basic Linux magic is useful for reference, but using
-# "long" magic is a better practice in order to avoid collisions.
-#
-# 2	leshort		100		Linux/i386
-# >0	leshort		0407		impure executable (OMAGIC)
-# >0	leshort		0410		pure executable (NMAGIC)
-# >0	leshort		0413		demand-paged executable (ZMAGIC)
-# >0	leshort		0314		demand-paged executable (QMAGIC)
-#
-0	lelong		0x00640107	Linux/i386 impure executable (OMAGIC)
->16	lelong		0		\b, stripped
-0	lelong		0x00640108	Linux/i386 pure executable (NMAGIC)
->16	lelong		0		\b, stripped
-0	lelong		0x0064010b	Linux/i386 demand-paged executable (ZMAGIC)
->16	lelong		0		\b, stripped
-0	lelong		0x006400cc	Linux/i386 demand-paged executable (QMAGIC)
->16	lelong		0		\b, stripped
-#
-0	string		\007\001\000	Linux/i386 object file
->20	lelong		>0x1020		\b, DLL library
-# message catalogs, from Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
-0	string		*nazgul*	compiled message catalog
->8	lelong		>0		\b, version %ld
-# core dump file, from Bill Reynolds <bill@goshawk.lanl.gov>
-216	lelong		0421		Linux/i386 core file
->220	string		>\0		of '%s'
->200	lelong		>0		(signal %d)
-#
-# LILO boot/chain loaders, from Daniel Quinlan <quinlan@yggdrasil.com>
-# this can be overridden by the DOS executable (COM) entry
-2	string		LILO		Linux/i386 LILO boot/chain loader
-#
-# Debian Packages, from Peter Tobias <tobias@server.et-inf.fho-emden.de>
-0	string		0.9
->8	byte		0x0a		Debian Binary Package
->>3	byte		>0		\b, created by dpkg 0.9%c
->>4	byte		>0		pl%c
-# PSF fonts, from H. Peter Anvin <hpa@yggdrasil.com>
-0	leshort		0x0436		Linux/i386 PC Screen Font data,
->2	byte		0		256 characters, no directory,
->2	byte		1		512 characters, no directory,
->2	byte		2		256 characters, Unicode directory,
->2	byte		3		512 characters, Unicode directory,
->3	byte		>0		8x%d
-# Linux swap file, from Daniel Quinlan <quinlan@yggdrasil.com>
-4086	string		SWAP-SPACE	Linux/i386 swap file
-# ECOFF magic for OSF/1 and Linux (only tested under Linux though)
-#
-#	from Erik Troan (ewt@redhat.com) examining od dumps, so this
-#		could be wrong
-#      updated by David Mosberger (davidm@azstarnet.com) based on
-#      GNU BFD and MIPS info found below.
-#
-0	leshort		0x0183		ECOFF alpha
->24	leshort		0407		executable
->24	leshort		0410		pure
->24	leshort		0413		demand paged
->8	long		>0		not stripped
->8	long		0		stripped
->23	leshort		>0		- version %ld.
-# linux Kernel images version 1.3.80 - ?
-# from Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>
-0       belong          0xb8c0078e      Linux/x86 kernel image,
->0x048c byte            0x31
->>0x048c string         x               version %s
->0x0493 byte            0x31
->>0x0493 string         x               version %s
-#

+ 0 - 79
orig/README

@@ -1,79 +0,0 @@
-** README for file(1) Command **
-@(#) $Id: README,v 1.20 1993/09/23 21:47:01 christos Exp $
-
-This is Release 3.x of Ian Darwin's (copyright but distributable)
-file(1) command.  Release 3.x is scheduled for inclusion in the
-4.4 BSD (Berkeley Software Distribution) of UNIX-like
-software, and is the standard "file" command for Linux, 386bsd,
-and other systems. (See "patchlevel.h" for the exact release number).
-
-UNIX is a trademark of UNIX System Laboratories.
-
-The prime contributor to Release 3.8 was Guy Harris, who put in megachanges
-including byte-order independance.
-
-The prime contributor to Release 3.0 was Christos Zoulas, who put
-in hundreds of lines of source code changes, including his own
-ANSIfication of the code (I liked my own ANSIfication better, but
-his (__P()) is the "Berkeley standard" way of doing it, and I wanted UCB
-to include the code...), his HP-like "indirection" (a feature of
-the HP file command, I think), and his mods that finally got the
-uncompress (-z) mode finished and working.
-
-This release has compiled in numerous environments; see PORTING
-for a list and problems.
-
-This fine freeware file(1) follows the USG (System V) model of the file
-command, rather than the Research (V7) version or the V7-derived 4.[23]
-Berkeley one. That is, the file /etc/magic contains much of the ritual
-information that is the source of this program's power. My version
-knows a little more magic (including tar archives) than System V; the
-/etc/magic parsing seems to be compatible with the (poorly documented)
-System V /etc/magic format (with one exception; see the man page).
-
-In addition, the /etc/magic file is built from a subdirectory
-for easier(?) maintenance.  I will act as a clearinghouse for
-magic numbers assigned to all sorts of data files that
-are in reasonable circulation. Send your magic numbers,
-in magic(4) format please, to the maintainer, Christos Zoulas.
-
-LEGAL.NOTICE - read this first.
-README - read this second (you are currently reading this file).
-PORTING - read this only if the program won't compile.
-Makefile - read this next, adapt it as needed (particularly
-	the location of the old existing file command and
-	the man page layouts), type "make" to compile, 
-	"make try" to try it out against your old version.
-	Expect some diffs, particularly since your original
-	file(1) may not grok the imbedded-space ("\ ") in
-	the current magic file, or may even not use the
-	magic file.
-apprentice.c - parses /etc/magic to learn magic
-ascmagic.c - third & last set of tests, based on hardwired assumptions.
-core - not included in distribution due to mailer limitations.
-debug.c - includes -c printout routine
-file.1 - man page for the command
-magic.4 - man page for the magic file, courtesy Guy Harris.
-	Install as magic.4 on USG and magic.5 on V7 or Berkeley; cf Makefile.
-file.c - main program
-file.h - header file
-fsmagic.c - first set of tests the program runs, based on filesystem info
-is_tar.c - knows about tarchives (courtesy John Gilmore).
-magdir - directory of /etc/magic pieces
-	magdir/Makefile - ADJUST THIS FOR YOUR CONFIGURATION
-names.h - header file for ascmagic.c
-softmagic.c - 2nd set of tests, based on /etc/magic
-strtok.c, getopt.c - in case you them (courtesy of Henry Spencer).
-strtol.c, strchr.c - in case you need them - public domain.
-tst - simple test suite, built from tst/Makefile
-
-
-E-mail: christos@deshaw.com, moraes@deshaw.com
-
-Phone: Do not even think of telephoning me about this program. Send cash first!
-
-Parts of this software were developed at SoftQuad Inc., 56 Aberfoyle
-Cres, # 810, Toronto, Ontario CANADA M8X 2W4.  Phone: 416-239-4801 or
-800-387-2777. Email: mail@sq.com.  Call for information on SGML editing
-and browsing, Unix text processing, and customised products on Unix,
-DOS and Mac.

+ 0 - 365
orig/file.man

@@ -1,365 +0,0 @@
-.TH FILE __CSECTION__ "Copyright but distributable"
-.\" $Id: file.man,v 1.27 1996/06/22 22:05:07 christos Exp $
-.SH NAME
-file
-\- determine file type
-.SH SYNOPSIS
-.B file
-[
-.B \-vczL
-]
-[
-.B \-f
-namefile ]
-[
-.B \-m 
-magicfiles ]
-file ...
-.SH DESCRIPTION
-This manual page documents version __VERSION__ of the
-.B file
-command.
-.B File
-tests each argument in an attempt to classify it.
-There are three sets of tests, performed in this order:
-filesystem tests, magic number tests, and language tests.
-The
-.I first
-test that succeeds causes the file type to be printed.
-.PP
-The type printed will usually contain one of the words
-.B text
-(the file contains only
-.SM ASCII
-characters and is probably safe to read on an
-.SM ASCII
-terminal),
-.B executable
-(the file contains the result of compiling a program
-in a form understandable to some \s-1UNIX\s0 kernel or another),
-or
-.B data
-meaning anything else (data is usually `binary' or non-printable).
-Exceptions are well-known file formats (core files, tar archives)
-that are known to contain binary data.
-When modifying the file
-.I __MAGIC__
-or the program itself, 
-.B "preserve these keywords" .
-People depend on knowing that all the readable files in a directory
-have the word ``text'' printed.
-Don't do as Berkeley did \- change ``shell commands text''
-to ``shell script''.
-.PP
-The filesystem tests are based on examining the return from a
-.BR stat (2)
-system call.
-The program checks to see if the file is empty,
-or if it's some sort of special file.
-Any known file types appropriate to the system you are running on
-(sockets, symbolic links, or named pipes (FIFOs) on those systems that
-implement them)
-are intuited if they are defined in
-the system header file
-.IR sys/stat.h  .
-.PP
-The magic number tests are used to check for files with data in
-particular fixed formats.
-The canonical example of this is a binary executable (compiled program)
-.I a.out
-file, whose format is defined in 
-.I a.out.h
-and possibly
-.I exec.h
-in the standard include directory.
-These files have a `magic number' stored in a particular place
-near the beginning of the file that tells the \s-1UNIX\s0 operating system
-that the file is a binary executable, and which of several types thereof.
-The concept of `magic number' has been applied by extension to data files.
-Any file with some invariant identifier at a small fixed
-offset into the file can usually be described in this way.
-The information in these files is read from the magic file
-.I __MAGIC__.
-.PP
-If an argument appears to be an
-.SM ASCII 
-file,
-.B file
-attempts to guess its language.
-The language tests look for particular strings (cf
-.IR names.h )
-that can appear anywhere in the first few blocks of a file.
-For example, the keyword
-.B .br
-indicates that the file is most likely a
-.BR troff (1)
-input file, just as the keyword 
-.B struct
-indicates a C program.
-These tests are less reliable than the previous
-two groups, so they are performed last.
-The language test routines also test for some miscellany
-(such as 
-.BR tar (1)
-archives) and determine whether an unknown file should be
-labelled as `ascii text' or `data'. 
-.SH OPTIONS
-.TP 8
-.B \-v
-Print the version of the program and exit.
-.TP 8
-.B \-m list
-Specify an alternate list of files containing magic numbers.
-This can be a single file, or a colon-separated list of files.
-.TP 8
-.B \-z
-Try to look inside compressed files.
-.TP 8
-.B \-c
-Cause a checking printout of the parsed form of the magic file.
-This is usually used in conjunction with 
-.B \-m
-to debug a new magic file before installing it.
-.TP 8
-.B \-f namefile
-Read the names of the files to be examined from 
-.I namefile
-(one per line) 
-before the argument list.
-Either 
-.I namefile
-or at least one filename argument must be present;
-to test the standard input, use ``-'' as a filename argument.
-.TP 8
-.B \-L
-option causes symlinks to be followed, as the like-named option in
-.BR ls (1).
-(on systems that support symbolic links).
-.SH FILES
-.I __MAGIC__
-\- default list of magic numbers
-.SH ENVIRONMENT
-The environment variable
-.B MAGIC
-can be used to set the default magic number files.
-.SH SEE ALSO
-.BR magic (__FSECTION__)
-\- description of magic file format.
-.br
-.BR strings (1), " od" (1)
-\- tools for examining non-textfiles.
-.SH STANDARDS CONFORMANCE
-This program is believed to exceed the System V Interface Definition
-of FILE(CMD), as near as one can determine from the vague language
-contained therein. 
-Its behaviour is mostly compatible with the System V program of the same name.
-This version knows more magic, however, so it will produce
-different (albeit more accurate) output in many cases. 
-.PP
-The one significant difference 
-between this version and System V
-is that this version treats any white space
-as a delimiter, so that spaces in pattern strings must be escaped.
-For example,
-.br
->10	string	language impress\ 	(imPRESS data)
-.br
-in an existing magic file would have to be changed to
-.br
->10	string	language\e impress	(imPRESS data)
-.br
-In addition, in this version, if a pattern string contains a backslash,
-it must be escaped.  For example
-.br
-0	string		\ebegindata	Andrew Toolkit document
-.br
-in an existing magic file would have to be changed to
-.br
-0	string		\e\ebegindata	Andrew Toolkit document
-.br
-.PP
-SunOS releases 3.2 and later from Sun Microsystems include a
-.BR file (1)
-command derived from the System V one, but with some extensions.
-My version differs from Sun's only in minor ways.
-It includes the extension of the `&' operator, used as,
-for example,
-.br
->16	long&0x7fffffff	>0		not stripped
-.SH MAGIC DIRECTORY
-The magic file entries have been collected from various sources,
-mainly USENET, and contributed by various authors.
-Christos Zoulas (address below) will collect additional
-or corrected magic file entries.
-A consolidation of magic file entries 
-will be distributed periodically.
-.PP
-The order of entries in the magic file is significant.
-Depending on what system you are using, the order that
-they are put together may be incorrect.
-If your old
-.B file
-command uses a magic file,
-keep the old magic file around for comparison purposes
-(rename it to 
-.IR __MAGIC__.orig ).
-.SH HISTORY
-There has been a 
-.B file
-command in every \s-1UNIX\s0 since at least Research Version 6
-(man page dated January, 1975).
-The System V version introduced one significant major change:
-the external list of magic number types.
-This slowed the program down slightly but made it a lot more flexible.
-.PP
-This program, based on the System V version,
-was written by Ian Darwin without looking at anybody else's source code.
-.PP
-John Gilmore revised the code extensively, making it better than
-the first version.
-Geoff Collyer found several inadequacies
-and provided some magic file entries.
-The program has undergone continued evolution since.
-.SH AUTHOR
-Written by Ian F. Darwin, UUCP address {utzoo | ihnp4}!darwin!ian,
-Internet address ian@sq.com,
-postal address: P.O. Box 603, Station F, Toronto, Ontario, CANADA M4Y 2L8.
-.PP
-Altered by Rob McMahon, cudcv@warwick.ac.uk, 1989, to extend the `&' operator
-from simple `x&y != 0' to `x&y op z'.
-.PP
-Altered by Guy Harris, guy@auspex.com, 1993, to:
-.RS
-.PP
-put the ``old-style'' `&'
-operator back the way it was, because 1) Rob McMahon's change broke the
-previous style of usage, 2) the SunOS ``new-style'' `&' operator,
-which this version of
-.B file
-supports, also handles `x&y op z', and 3) Rob's change wasn't documented
-in any case;
-.PP
-put in multiple levels of `>';
-.PP
-put in ``beshort'', ``leshort'', etc. keywords to look at numbers in the
-file in a specific byte order, rather than in the native byte order of
-the process running
-.BR file .
-.RE
-.PP
-Changes by Ian Darwin and various authors including
-Christos Zoulas (christos@ee.cornell.edu), 1990-1992.
-.SH LEGAL NOTICE
-Copyright (c) Ian F. Darwin, Toronto, Canada,
-1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993.
-.PP
-This software is not subject to and may not be made subject to any
-license of the American Telephone and Telegraph Company, Sun
-Microsystems Inc., Digital Equipment Inc., Lotus Development Inc., the
-Regents of the University of California, The X Consortium or MIT, or
-The Free Software Foundation.
-.PP
-This software is not subject to any export provision of the United States
-Department of Commerce, and may be exported to any country or planet.
-.PP
-Permission is granted to anyone to use this software for any purpose on
-any computer system, and to alter it and redistribute it freely, subject
-to the following restrictions:
-.PP 
-1. The author is not responsible for the consequences of use of this
-software, no matter how awful, even if they arise from flaws in it.
-.PP
-2. The origin of this software must not be misrepresented, either by
-explicit claim or by omission.  Since few users ever read sources,
-credits must appear in the documentation.
-.PP
-3. Altered versions must be plainly marked as such, and must not be
-misrepresented as being the original software.  Since few users
-ever read sources, credits must appear in the documentation.
-.PP
-4. This notice may not be removed or altered.
-.PP
-A few support files (\fIgetopt\fP, \fIstrtok\fP)
-distributed with this package
-are by Henry Spencer and are subject to the same terms as above.
-.PP
-A few simple support files (\fIstrtol\fP, \fIstrchr\fP)
-distributed with this package
-are in the public domain; they are so marked.
-.PP
-The files
-.I tar.h
-and
-.I is_tar.c
-were written by John Gilmore from his public-domain
-.B tar
-program, and are not covered by the above restrictions.
-.SH BUGS
-There must be a better way to automate the construction of the Magic
-file from all the glop in Magdir. What is it?
-Better yet, the magic file should be compiled into binary (say,
-.BR ndbm (3)
-or, better yet, fixed-length
-.SM ASCII
-strings for use in heterogenous network environments) for faster startup.
-Then the program would run as fast as the Version 7 program of the same name,
-with the flexibility of the System V version.
-.PP
-.B File
-uses several algorithms that favor speed over accuracy,
-thus it can be misled about the contents of
-.SM ASCII
-files.
-.PP
-The support for
-.SM ASCII
-files (primarily for programming languages)
-is simplistic, inefficient and requires recompilation to update.
-.PP
-There should be an ``else'' clause to follow a series of continuation lines.
-.PP
-The magic file and keywords should have regular expression support.
-Their use of
-.SM "ASCII TAB"
-as a field delimiter is ugly and makes
-it hard to edit the files, but is entrenched.
-.PP
-It might be advisable to allow upper-case letters in keywords
-for e.g.,
-.BR troff (1)
-commands vs man page macros.
-Regular expression support would make this easy.
-.PP
-The program doesn't grok \s-2FORTRAN\s0.
-It should be able to figure \s-2FORTRAN\s0 by seeing some keywords which 
-appear indented at the start of line.
-Regular expression support would make this easy.
-.PP
-The list of keywords in 
-.I ascmagic
-probably belongs in the Magic file.
-This could be done by using some keyword like `*' for the offset value.
-.PP
-Another optimisation would be to sort
-the magic file so that we can just run down all the
-tests for the first byte, first word, first long, etc, once we
-have fetched it.  Complain about conflicts in the magic file entries.
-Make a rule that the magic entries sort based on file offset rather
-than position within the magic file?
-.PP
-The program should provide a way to give an estimate 
-of ``how good'' a guess is.
-We end up removing guesses (e.g. ``From '' as first 5 chars of file) because
-they are not as good as other guesses (e.g. ``Newsgroups:'' versus
-"Return-Path:").  Still, if the others don't pan out, it should be
-possible to use the first guess.  
-.PP
-This program is slower than some vendors' file commands.
-.PP
-This manual page, and particularly this section, is too long.
-.SH AVAILABILITY
-You can obtain the original author's latest version by anonymous FTP
-on
-.B tesla.ee.cornell.edu
-in the directory
-.I /pub/file-X.YY.tar.gz

+ 42 - 2
patchlevel.h

@@ -1,11 +1,51 @@
 #define	FILE_VERSION_MAJOR	3
-#define	patchlevel		20
+#define	patchlevel		24
 
 /*
  * Patchlevel file for Ian Darwin's MAGIC command.
- * $Id: patchlevel.h,v 1.20 1996/06/22 22:15:52 christos Exp $
+ * $Id: patchlevel.h,v 1.24 1998/02/15 23:20:38 christos Exp $
  *
  * $Log: patchlevel.h,v $
+ * Revision 1.24  1998/02/15 23:20:38  christos
+ * Autoconf patch: Felix von Leitner <leitner@math.fu-berlin.de>
+ * More magic fixes
+ * Elf64 fixes
+ *
+ * Revision 1.23  1997/11/05 16:03:37  christos
+ * - correct elf prps offset for SunOS-2.5.1 [guy@netapp.com]
+ * - handle 64 bit time_t's correctly [ewt@redhat.com]
+ * - new mime style magic [clarosse@netvista.net]
+ * - new TI calculator magic [rmcguire@freenet.columbus.oh.us]
+ * - new figlet fonts [obrien@freebsd.org]
+ * - new cisco magic, and elf fixes [jhawk@bbnplanet.com]
+ * - -b flag addition, and x86 filesystem magic [vax@linkhead.paranoia.com]
+ * - s/Mpeg/MPEG, header and elf typo fixes [guy@netapp.com]
+ * - Windows/NT registry files, audio code [guy@netapp.com]
+ * - libGrx graphics lib fonts [guy@netapp.com]
+ * - PNG fixes [guy@netapp.com]
+ * - more m$ document magic [guy@netapp.com]
+ * - PPD files [guy@netapp.com]
+ * - archive magic cleanup [guy@netapp.com]
+ * - linux kernel magic cleanup [guy@netapp.com]
+ * - lecter magic [guy@netapp.com]
+ * - vgetty magic [guy@netapp.com]
+ * - sniffer additions [guy@netapp.com]
+ *
+ * Revision 1.22  1997/01/15 17:23:24  christos
+ * - add support for elf core files: find the program name under SVR4 [Ken Pizzini]
+ * - print strings only up to the first carriage return [various]
+ * - freebsd international ascii support [J Wunsch]
+ * - magic fixes and additions [Guy Harris]
+ * - 64 bit fixes [Larry Schwimmer]
+ * - support for both utime and utimes, but don't restore file access times
+ *   by default [various]
+ * - \xXX only takes 2 hex digits, not 3.
+ * - re-implement support for core files [Guy Harris]
+ *
+ * Revision 1.21  1996/10/05 18:15:29  christos
+ * Segregate elf stuff and conditionally enable it with -DBUILTIN_ELF
+ * More magic fixes
+ *
  * Revision 1.20  1996/06/22  22:15:52  christos
  * - support relative offsets of the form >&
  * - fix bug with truncating magic strings that contain \n

+ 7 - 5
print.c

@@ -40,7 +40,7 @@
 
 #ifndef lint
 static char *moduleid =
-	"@(#)$Id: print.c,v 1.22 1995/05/20 22:09:21 christos Exp $";
+	"@(#)$Id: print.c,v 1.24 1997/04/13 18:28:30 christos Exp $";
 #endif  /* lint */
 
 #define SZOF(a)	(sizeof(a) / sizeof(a[0]))
@@ -58,7 +58,7 @@ struct magic *m;
 		       m->offset);
 
 	if (m->flag & INDIR)
-		(void) fprintf(stderr, "(%s,%ld),",
+		(void) fprintf(stderr, "(%s,%d),",
 			       (m->in.type >= 0 && m->in.type < SZOF(typ)) ? 
 					typ[(unsigned char) m->in.type] :
 					"*bad*",
@@ -69,7 +69,7 @@ struct magic *m;
 				typ[(unsigned char) m->type] : 
 				"*bad*");
 	if (m->mask != ~0L)
-		(void) fprintf(stderr, " & %.8lx", m->mask);
+		(void) fprintf(stderr, " & %.8x", m->mask);
 
 	(void) fprintf(stderr, ",%c", m->reln);
 
@@ -82,7 +82,7 @@ struct magic *m;
 	    case LELONG:
 	    case BESHORT:
 	    case BELONG:
-		    (void) fprintf(stderr, "%ld", m->value.l);
+		    (void) fprintf(stderr, "%d", m->value.l);
 		    break;
 	    case STRING:
 		    showstr(stderr, m->value.s, -1);
@@ -91,7 +91,9 @@ struct magic *m;
 	    case LEDATE:
 	    case BEDATE:
 		    {
-			    char *rt, *pp = ctime((time_t*) &m->value.l);
+			    time_t t = m->value.l;
+			    char *rt, *pp = ctime(&t);
+
 			    if ((rt = strchr(pp, '\n')) != NULL)
 				    *rt = '\0';
 			    (void) fprintf(stderr, "%s,", pp);

+ 315 - 0
readelf.c

@@ -0,0 +1,315 @@
+
+#ifdef BUILTIN_ELF
+#include <sys/types.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "readelf.h"
+#include "file.h"
+
+static void
+doshn(fd, off, num, size, buf)
+	int fd;
+	off_t off;
+	int num;
+	size_t size;
+	char *buf;
+{
+	/*
+	 * This works for both 32-bit and 64-bit ELF formats,
+	 * because it looks only at the "sh_type" field, which is
+	 * always 32 bits, and is preceded only by the "sh_name"
+	 * field which is also always 32 bits, and because it uses
+	 * the shdr size from the ELF header rather than using
+	 * the size of an "Elf32_Shdr".
+	 */
+	Elf32_Shdr *sh = (Elf32_Shdr *) buf;
+
+	if (lseek(fd, off, SEEK_SET) == -1)
+		error("lseek failed (%s).\n", strerror(errno));
+
+	for ( ; num; num--) {
+		if (read(fd, buf, size) == -1)
+			error("read failed (%s).\n", strerror(errno));
+		if (sh->sh_type == SHT_SYMTAB) {
+			(void) printf (", not stripped");
+			return;
+		}
+	}
+	(void) printf (", stripped");
+}
+
+/*
+ * Look through the program headers of an executable image, searching
+ * for a PT_INTERP section; if one is found, it's dynamically linked,
+ * otherwise it's statically linked.
+ */
+static void
+dophn_exec(fd, off, num, size, buf)
+	int fd;
+	off_t off;
+	int num;
+	size_t size;
+	char *buf;
+{
+	/* I am not sure if this works for 64 bit elf formats */
+	Elf32_Phdr *ph = (Elf32_Phdr *) buf;
+
+	if (lseek(fd, off, SEEK_SET) == -1)
+		error("lseek failed (%s).\n", strerror(errno));
+
+  	for ( ; num; num--) {
+  		if (read(fd, buf, size) == -1)
+  			error("read failed (%s).\n", strerror(errno));
+		if (ph->p_type == PT_INTERP) {
+			/*
+			 * Has an interpreter - must be a dynamically-linked
+			 * executable.
+			 */
+			printf(", dynamically linked");
+			return;
+		}
+	}
+	printf(", statically linked");
+}
+
+size_t	prpsoffsets[] = {
+	84,		/* SunOS 5.x */
+	32,		/* Linux */
+};
+
+#define	NOFFSETS	(sizeof prpsoffsets / sizeof prpsoffsets[0])
+
+/*
+ * Look through the program headers of an executable image, searching
+ * for a PT_NOTE section of type NT_PRPSINFO, with a name "CORE"; if one
+ * is found, try looking in various places in its contents for a 16-character
+ * string containing only printable characters - if found, that string
+ * should be the name of the program that dropped core.
+ * Note: right after that 16-character string is, at least in SunOS 5.x
+ * (and possibly other SVR4-flavored systems) and Linux, a longer string
+ * (80 characters, in 5.x, probably other SVR4-flavored systems, and Linux)
+ * containing the start of the command line for that program.
+ */
+static void
+dophn_core(fd, off, num, size, buf)
+	int fd;
+	off_t off;
+	int num;
+	size_t size;
+	char *buf;
+{
+	/*
+	 * This doesn't work for 64-bit ELF, as the "p_offset" field is
+	 * 64 bits in 64-bit ELF.
+	 */
+	Elf32_Phdr *ph = (Elf32_Phdr *) buf;
+	Elf32_Nhdr *nh;
+	size_t offset, noffset, reloffset;
+	unsigned char c;
+	int i, j;
+	char nbuf[BUFSIZ];
+	int bufsize;
+
+	for ( ; num; num--) {
+		if (lseek(fd, off, SEEK_SET) == -1)
+			error("lseek failed (%s).\n", strerror(errno));
+		if (read(fd, buf, size) == -1)
+			error("read failed (%s).\n", strerror(errno));
+		off += size;
+		if (ph->p_type != PT_NOTE)
+			continue;
+		if (lseek(fd, ph->p_offset, SEEK_SET) == -1)
+			error("lseek failed (%s).\n", strerror(errno));
+		bufsize = read(fd, nbuf, BUFSIZ);
+		if (bufsize == -1)
+			error("read failed (%s).\n", strerror(errno));
+		offset = 0;
+		for (;;) {
+			if (offset >= bufsize)
+				break;
+			nh = (Elf32_Nhdr *)&nbuf[offset];
+			offset += sizeof *nh;
+
+			/*
+			 * If this note isn't an NT_PRPSINFO note, it's
+			 * not what we're looking for.
+			 */
+			if (nh->n_type != NT_PRPSINFO) {
+				offset += nh->n_namesz;
+				offset = ((offset + 3)/4)*4;
+				offset += nh->n_descsz;
+				offset = ((offset + 3)/4)*4;
+				continue;
+			}
+
+			/*
+			 * Make sure this note has the name "CORE".
+			 */
+			if (offset + nh->n_namesz >= bufsize) {
+				/*
+				 * We're past the end of the buffer.
+				 */
+				break;
+			}
+			if (nh->n_namesz != 5
+			    || strcmp(&nbuf[offset], "CORE") != 0)
+				continue;
+			offset += nh->n_namesz;
+			offset = ((offset + 3)/4)*4;
+
+			/*
+			 * Extract the program name.  We assume it to be
+			 * 16 characters (that's what it is in SunOS 5.x
+			 * and Linux).
+			 *
+			 * Unfortunately, it's at a different offset in
+			 * SunOS 5.x and Linux, so try multiple offsets.
+			 * If the characters aren't all printable, reject
+			 * it.
+			 */
+			for (i = 0; i < NOFFSETS; i++) {
+				reloffset = prpsoffsets[i];
+				noffset = offset + reloffset;
+				for (j = 0; j < 16;
+				    j++, noffset++, reloffset++) {
+					/*
+					 * Make sure we're not past the end
+					 * of the buffer; if we are, just
+					 * give up.
+					 */
+					if (noffset >= bufsize)
+						return;
+
+					/*
+					 * Make sure we're not past the
+					 * end of the contents; if we
+					 * are, this obviously isn't
+					 * the right offset.
+					 */
+					if (reloffset >= nh->n_descsz)
+						goto tryanother;
+
+					c = nbuf[noffset];
+					if (c != '\0' && !isprint(c))
+						goto tryanother;
+				}
+
+				/*
+				 * Well, that worked.
+				 */
+				printf(", from '%.16s'",
+				    &nbuf[offset + prpsoffsets[i]]);
+				return;
+
+			tryanother:
+				;
+			}
+			offset += nh->n_descsz;
+			offset = ((offset + 3)/4)*4;
+		}
+	}
+}
+
+void
+tryelf(fd, buf, nbytes)
+	int fd;
+	char *buf;
+	int nbytes;
+{
+	union {
+		int32 l;
+		char c[sizeof (int32)];
+	} u;
+
+	/*
+	 * ELF executables have multiple section headers in arbitrary
+	 * file locations and thus file(1) cannot determine it from easily.
+	 * Instead we traverse thru all section headers until a symbol table
+	 * one is found or else the binary is stripped.
+	 */
+	if (buf[EI_MAG0] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1
+	    || buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
+	    return;
+
+
+	if (buf[4] == ELFCLASS32) {
+		Elf32_Ehdr elfhdr;
+		if (nbytes <= sizeof (Elf32_Ehdr))
+			return;
+
+
+		u.l = 1;
+		(void) memcpy(&elfhdr, buf, sizeof elfhdr);
+		/*
+		 * If the system byteorder does not equal the
+		 * object byteorder then don't test.
+		 * XXX - we could conceivably fix up the "dophn_XXX()" and
+		 * "doshn()" routines to extract stuff in the right
+		 * byte order....
+		 */
+		if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
+			if (elfhdr.e_type == ET_CORE) 
+				dophn_core(fd, elfhdr.e_phoff, elfhdr.e_phnum, 
+				      elfhdr.e_phentsize, buf);
+			else {
+				if (elfhdr.e_type == ET_EXEC) {
+					dophn_exec(fd, elfhdr.e_phoff,
+					    elfhdr.e_phnum, 
+					      elfhdr.e_phentsize, buf);
+				}
+				doshn(fd, elfhdr.e_shoff, elfhdr.e_shnum,
+				      elfhdr.e_shentsize, buf);
+			}
+		}
+		return;
+	}
+
+        if (buf[4] == ELFCLASS64) {
+		Elf64_Ehdr elfhdr;
+		if (nbytes <= sizeof (Elf64_Ehdr))
+			return;
+
+
+		u.l = 1;
+		(void) memcpy(&elfhdr, buf, sizeof elfhdr);
+
+		/*
+		 * If the system byteorder does not equal the
+		 * object byteorder then don't test.
+		 * XXX - we could conceivably fix up the "dophn_XXX()" and
+		 * "doshn()" routines to extract stuff in the right
+		 * byte order....
+		 */
+		if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
+#ifdef notyet
+			if (elfhdr.e_type == ET_CORE) 
+				dophn_core(fd, elfhdr.e_phoff[1],
+					   elfhdr.e_phnum, 
+					   elfhdr.e_phentsize, buf);
+			else
+#endif
+			{
+#ifdef notyet
+				if (elfhdr.e_type == ET_EXEC) {
+					dophn_exec(fd, elfhdr.e_phoff[1],
+						   elfhdr.e_phnum, 
+						   elfhdr.e_phentsize, buf);
+				}
+#endif
+				doshn(fd, elfhdr.e_shoff[1],
+				      elfhdr.e_shnum,
+				      elfhdr.e_shentsize, buf);
+			}
+		}
+		return;
+	}
+}
+#endif

+ 95 - 2
readelf.h

@@ -1,6 +1,6 @@
 /*
  * readelf.h 
- * @(#)$Id: readelf.h,v 1.1 1996/06/22 22:04:22 christos Exp $
+ * @(#)$Id: readelf.h,v 1.4 1997/01/15 17:23:24 christos Exp $
  *
  * Provide elf data structures for non-elf machines, allowing file
  * non-elf hosts to determine if an elf binary is stripped.
@@ -15,9 +15,16 @@ typedef unsigned int	Elf32_Off;
 typedef unsigned int	Elf32_Word;
 typedef unsigned char	Elf32_Char;
 
+/* XXX: We need 64 bit numbers here */
+typedef unsigned int	Elf64_Addr[2];
+typedef unsigned short	Elf64_Half;
+typedef unsigned int	Elf64_Off[2];
+typedef unsigned int	Elf64_Word;
+typedef unsigned char	Elf64_Char;
+
 #define EI_NIDENT	16
 
-typedef struct elfhdr{
+typedef struct {
     Elf32_Char	e_ident[EI_NIDENT];
     Elf32_Half	e_type;
     Elf32_Half	e_machine;
@@ -34,14 +41,41 @@ typedef struct elfhdr{
     Elf32_Half	e_shstrndx;
 } Elf32_Ehdr;
 
+typedef struct {
+    Elf64_Char	e_ident[EI_NIDENT];
+    Elf64_Half	e_type;
+    Elf64_Half	e_machine;
+    Elf64_Word	e_version;
+    Elf64_Addr	e_entry;  /* Entry point */
+    Elf64_Off	e_phoff;
+    Elf64_Off	e_shoff;
+    Elf64_Word	e_flags;
+    Elf64_Half	e_ehsize;
+    Elf64_Half	e_phentsize;
+    Elf64_Half	e_phnum;
+    Elf64_Half	e_shentsize;
+    Elf64_Half	e_shnum;
+    Elf64_Half	e_shstrndx;
+} Elf64_Ehdr;
+
+/* e_type */
+#define ET_EXEC		2
+#define ET_CORE		4
+
 /* sh_type */
 #define SHT_SYMTAB	2
+#define SHT_NOTE	7
 
 /* elf type */
 #define ELFDATANONE	0		/* e_ident[EI_DATA] */
 #define ELFDATA2LSB	1
 #define ELFDATA2MSB	2
 
+/* elf class */
+#define ELFCLASSNONE	0
+#define ELFCLASS32	1
+#define ELFCLASS64	2
+
 /* magic number */
 #define	EI_MAG0		0		/* e_ident[] indexes */
 #define	EI_MAG1		1
@@ -59,6 +93,26 @@ typedef struct elfhdr{
 #define	ELFMAG		"\177ELF"
 
 typedef struct {
+    Elf32_Word	p_type;
+    Elf32_Off	p_offset;
+    Elf32_Addr	p_vaddr;
+    Elf32_Addr	p_paddr;
+    Elf32_Word	p_filesz;
+    Elf32_Word	p_memsz;
+    Elf32_Word	p_flags;
+    Elf32_Word	p_align;
+} Elf32_Phdr;
+
+#define	PT_NULL		0		/* p_type */
+#define	PT_LOAD		1
+#define	PT_DYNAMIC	2
+#define	PT_INTERP	3
+#define	PT_NOTE		4
+#define	PT_SHLIB	5
+#define	PT_PHDR		6
+#define	PT_NUM		7
+
+typedef struct {
     Elf32_Word	sh_name;
     Elf32_Word	sh_type;
     Elf32_Word	sh_flags;
@@ -71,4 +125,43 @@ typedef struct {
     Elf32_Word	sh_entsize;
 } Elf32_Shdr;
 
+typedef struct {
+    Elf64_Word	sh_name;
+    Elf64_Word	sh_type;
+    Elf64_Off	sh_flags;
+    Elf64_Addr	sh_addr;
+    Elf64_Off	sh_offset;
+    Elf64_Off	sh_size;
+    Elf64_Word	sh_link;
+    Elf64_Word	sh_info;
+    Elf64_Off	sh_addralign;
+    Elf64_Off	sh_entsize;
+} Elf64_Shdr;
+
+/* Notes used in ET_CORE */
+#define NT_PRSTATUS	1
+#define NT_PRFPREG	2
+#define NT_PRPSINFO	3
+#define NT_TASKSTRUCT	4
+
+/* Note header in a PT_NOTE section */
+typedef struct elf_note {
+  Elf32_Word	n_namesz;	/* Name size */
+  Elf32_Word	n_descsz;	/* Content size */
+  Elf32_Word	n_type;		/* Content type */
+} Elf32_Nhdr;
+
+typedef struct {
+    Elf64_Word	n_namesz;
+    Elf64_Word	n_descsz;
+    Elf64_Word	n_type;
+} Elf64_Nhdr;
+
+#define	NT_PRSTATUS	1
+#define	NT_PRFPREG	2
+#define	NT_PRPSINFO	3
+#define	NT_PRXREG	4
+#define	NT_PLATFORM	5
+#define	NT_AUXV		6
+
 #endif

+ 50 - 39
softmagic.c

@@ -27,22 +27,26 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <time.h>
 #include <sys/types.h>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include "file.h"
 
 #ifndef	lint
 static char *moduleid = 
-	"@(#)$Id: softmagic.c,v 1.31 1996/06/22 22:04:22 christos Exp $";
+	"@(#)$Id: softmagic.c,v 1.36 1998/02/15 23:18:53 christos Exp $";
 #endif	/* lint */
 
 static int match	__P((unsigned char *, int));
 static int mget		__P((union VALUETYPE *,
 			     unsigned char *, struct magic *, int));
 static int mcheck	__P((union VALUETYPE *, struct magic *));
-static long mprint	__P((union VALUETYPE *, struct magic *));
-static void mdebug	__P((long, char *, int));
+static int32 mprint	__P((union VALUETYPE *, struct magic *));
+static void mdebug	__P((int32, char *, int));
 static int mconvert	__P((union VALUETYPE *, struct magic *));
 
 /*
@@ -98,12 +102,12 @@ int nbytes;
 	int cont_level = 0;
 	int need_separator = 0;
 	union VALUETYPE p;
-	static long *tmpoff = NULL;
+	static int32 *tmpoff = NULL;
 	static size_t tmplen = 0;
-	long oldoff = 0;
+	int32 oldoff = 0;
 
 	if (tmpoff == NULL)
-		if ((tmpoff = (long *) malloc(tmplen = 20)) == NULL)
+		if ((tmpoff = (int32 *) malloc(tmplen = 20)) == NULL)
 			error("out of memory\n");
 
 	for (magindex = 0; magindex < nmagic; magindex++) {
@@ -129,7 +133,7 @@ int nbytes;
 			need_separator = 1;
 		/* and any continuations that match */
 		if (++cont_level >= tmplen)
-			if ((tmpoff = (long *) realloc(tmpoff,
+			if ((tmpoff = (int32 *) realloc(tmpoff,
 						       tmplen += 20)) == NULL)
 				error("out of memory\n");
 		while (magic[magindex+1].cont_level != 0 && 
@@ -174,7 +178,7 @@ int nbytes;
 					 */
 					if (++cont_level >= tmplen)
 						if ((tmpoff = 
-						    (long *) realloc(tmpoff,
+						    (int32 *) realloc(tmpoff,
 						    tmplen += 20)) == NULL)
 							error("out of memory\n");
 				}
@@ -188,14 +192,15 @@ int nbytes;
 	return 0;			/* no match at all */
 }
 
-static long
+static int32
 mprint(p, m)
 union VALUETYPE *p;
 struct magic *m;
 {
 	char *pp, *rt;
-	unsigned long v;
-	long t=0 ;
+	uint32 v;
+	time_t time;
+	int32 t=0 ;
 
 
   	switch (m->type) {
@@ -220,8 +225,8 @@ struct magic *m;
   	case LELONG:
 		v = p->l;
 		v = signextend(m, v) & m->mask;
-		(void) printf(m->desc, (unsigned long) v);
-		t = m->offset + sizeof(long);
+		(void) printf(m->desc, (uint32) v);
+		t = m->offset + sizeof(int32);
   		break;
 
   	case STRING:
@@ -230,6 +235,11 @@ struct magic *m;
 			t = m->offset + strlen(m->value.s);
 		}
 		else {
+			if (*m->value.s == '\0') {
+				char *cp = strchr(p->s,'\n');
+				if (cp)
+					*cp = '\0';
+			}
 			(void) printf(m->desc, p->s);
 			t = m->offset + strlen(p->s);
 		}
@@ -238,12 +248,14 @@ struct magic *m;
 	case DATE:
 	case BEDATE:
 	case LEDATE:
-		pp = ctime((time_t*) &p->l);
+		time = p->l;
+		pp = ctime(&time);
 		if ((rt = strchr(pp, '\n')) != NULL)
 			*rt = '\0';
 		(void) printf(m->desc, pp);
 		t = m->offset + sizeof(time_t);
-		return;
+		break;
+
 	default:
 		error("invalid m->type (%d) in mprint().\n", m->type);
 		/*NOTREACHED*/
@@ -267,13 +279,12 @@ struct magic *m;
 		return 1;
 	case STRING:
 		{
-			size_t len;
+			char *ptr;
 
 			/* Null terminate and eat the return */
 			p->s[sizeof(p->s) - 1] = '\0';
-			len = strlen(p->s);
-			if (len > 0 && p->s[len - 1] == '\n')
-				p->s[len - 1] = '\0';
+			if ((ptr = strchr(p->s, '\n')) != NULL)
+				*ptr = '\0';
 			return 1;
 		}
 	case BESHORT:
@@ -281,7 +292,7 @@ struct magic *m;
 		return 1;
 	case BELONG:
 	case BEDATE:
-		p->l = (long)
+		p->l = (int32)
 		    ((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
 		return 1;
 	case LESHORT:
@@ -289,7 +300,7 @@ struct magic *m;
 		return 1;
 	case LELONG:
 	case LEDATE:
-		p->l = (long)
+		p->l = (int32)
 		    ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
 		return 1;
 	default:
@@ -301,11 +312,11 @@ struct magic *m;
 
 static void
 mdebug(offset, str, len)
-long offset;
+int32 offset;
 char *str;
 int len;
 {
-	(void) fprintf(stderr, "mget @%ld: ", offset);
+	(void) fprintf(stderr, "mget @%d: ", offset);
 	showstr(stderr, (char *) str, len);
 	(void) fputc('\n', stderr);
 	(void) fputc('\n', stderr);
@@ -318,7 +329,7 @@ unsigned char	*s;
 struct magic *m;
 int nbytes;
 {
-	long offset = m->offset;
+	int32 offset = m->offset;
 
 	if (offset + sizeof(union VALUETYPE) <= nbytes)
 		memcpy(p, s + offset, sizeof(union VALUETYPE));
@@ -327,7 +338,7 @@ int nbytes;
 		 * the usefulness of padding with zeroes eludes me, it
 		 * might even cause problems
 		 */
-		long have = nbytes - offset;
+		int32 have = nbytes - offset;
 		memset(p, 0, sizeof(union VALUETYPE));
 		if (have > 0)
 			memcpy(p, s + offset, have);
@@ -377,8 +388,8 @@ mcheck(p, m)
 union VALUETYPE* p;
 struct magic *m;
 {
-	register unsigned long l = m->value.l;
-	register unsigned long v;
+	register uint32 l = m->value.l;
+	register uint32 v;
 	int matched;
 
 	if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) {
@@ -421,7 +432,7 @@ struct magic *m;
 			register int len = m->vallen;
 
 			while (--len >= 0)
-				if ((v = *b++ - *a++) != 0)
+				if ((v = *b++ - *a++) != '\0')
 					break;
 		}
 		break;
@@ -435,21 +446,21 @@ struct magic *m;
 	switch (m->reln) {
 	case 'x':
 		if (debug)
-			(void) fprintf(stderr, "%lu == *any* = 1\n", v);
+			(void) fprintf(stderr, "%u == *any* = 1\n", v);
 		matched = 1;
 		break;
 
 	case '!':
 		matched = v != l;
 		if (debug)
-			(void) fprintf(stderr, "%lu != %lu = %d\n",
+			(void) fprintf(stderr, "%u != %u = %d\n",
 				       v, l, matched);
 		break;
 
 	case '=':
 		matched = v == l;
 		if (debug)
-			(void) fprintf(stderr, "%lu == %lu = %d\n",
+			(void) fprintf(stderr, "%u == %u = %d\n",
 				       v, l, matched);
 		break;
 
@@ -457,13 +468,13 @@ struct magic *m;
 		if (m->flag & UNSIGNED) {
 			matched = v > l;
 			if (debug)
-				(void) fprintf(stderr, "%lu > %lu = %d\n",
+				(void) fprintf(stderr, "%u > %u = %d\n",
 					       v, l, matched);
 		}
 		else {
-			matched = (long) v > (long) l;
+			matched = (int32) v > (int32) l;
 			if (debug)
-				(void) fprintf(stderr, "%ld > %ld = %d\n",
+				(void) fprintf(stderr, "%d > %d = %d\n",
 					       v, l, matched);
 		}
 		break;
@@ -472,13 +483,13 @@ struct magic *m;
 		if (m->flag & UNSIGNED) {
 			matched = v < l;
 			if (debug)
-				(void) fprintf(stderr, "%lu < %lu = %d\n",
+				(void) fprintf(stderr, "%u < %u = %d\n",
 					       v, l, matched);
 		}
 		else {
-			matched = (long) v < (long) l;
+			matched = (int32) v < (int32) l;
 			if (debug)
-				(void) fprintf(stderr, "%ld < %ld = %d\n",
+				(void) fprintf(stderr, "%d < %d = %d\n",
 					       v, l, matched);
 		}
 		break;
@@ -486,14 +497,14 @@ struct magic *m;
 	case '&':
 		matched = (v & l) == l;
 		if (debug)
-			(void) fprintf(stderr, "((%lx & %lx) == %lx) = %d\n",
+			(void) fprintf(stderr, "((%x & %x) == %x) = %d\n",
 				       v, l, l, matched);
 		break;
 
 	case '^':
 		matched = (v & l) != l;
 		if (debug)
-			(void) fprintf(stderr, "((%lx & %lx) != %lx) = %d\n",
+			(void) fprintf(stderr, "((%x & %x) != %x) = %d\n",
 				       v, l, l, matched);
 		break;