summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.in2
-rwxr-xr-xconfigure2
-rw-r--r--configure.in2
-rw-r--r--magic/Magdir/adi12
-rw-r--r--magic/Magdir/animation10
-rw-r--r--magic/Magdir/archive2
-rw-r--r--magic/Magdir/database1
-rw-r--r--magic/Magdir/elf1
-rw-r--r--magic/Magdir/filesystems17
-rw-r--r--magic/Magdir/macintosh93
-rw-r--r--magic/Magdir/sharc22
-rw-r--r--magic/Magdir/smalltalk23
-rw-r--r--magic/Magdir/sysex142
-rw-r--r--magic/Magdir/troff1
-rw-r--r--magic/Magdir/vorbis65
-rw-r--r--magic/magic.mime9
-rw-r--r--src/Makefile.std4
-rw-r--r--src/apprentice.c136
-rw-r--r--src/compress.c4
-rw-r--r--src/file.c29
-rw-r--r--src/file.h20
-rw-r--r--src/patchlevel.h9
-rw-r--r--src/print.c78
-rw-r--r--src/softmagic.c592
25 files changed, 1184 insertions, 94 deletions
diff --git a/Makefile.am b/Makefile.am
index ee79bece..790951f8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -53,7 +53,7 @@ magic.${fsect}: Makefile magic.man
-e s@__VERSION__@${VERSION}@g \
-e s@__MAGIC__@${MAGIC}@g $(srcdir)/magic.man > $@
-magic_FRAGMENTS = Magdir/adventure Magdir/allegro Magdir/alliant \
+magic_FRAGMENTS = Magdir/adi Magdir/adventure Magdir/allegro Magdir/alliant \
Magdir/alpha Magdir/amanda Magdir/amigaos Magdir/animation \
Magdir/apl Magdir/apple Magdir/applix Magdir/archive Magdir/asterix \
Magdir/att3b Magdir/audio Magdir/blender Magdir/blit Magdir/bsdi \
diff --git a/Makefile.in b/Makefile.in
index 69886ead..5fa1cd73 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -86,7 +86,7 @@ EXTRA_DIST = LEGAL.NOTICE MAINT PORTING Makefile.std magic2mime Localstuff Head
CLEANFILES = $(man_MANS) magic magic.mgc
-magic_FRAGMENTS = Magdir/adventure Magdir/allegro Magdir/alliant Magdir/alpha Magdir/amanda Magdir/amigaos Magdir/animation Magdir/apl Magdir/apple Magdir/applix Magdir/archive Magdir/asterix Magdir/att3b Magdir/audio Magdir/blender Magdir/blit Magdir/bsdi Magdir/c-lang Magdir/chi Magdir/cisco Magdir/claris Magdir/clipper Magdir/commands Magdir/compress Magdir/console Magdir/convex Magdir/database Magdir/diamond Magdir/diff Magdir/digital Magdir/dump Magdir/elf Magdir/encore Magdir/epoc Magdir/filesystems Magdir/flash Magdir/fonts Magdir/frame Magdir/freebsd Magdir/fsav Magdir/gimp Magdir/gnu Magdir/grace Magdir/hp Magdir/ibm370 Magdir/ibm6000 Magdir/iff Magdir/images Magdir/intel Magdir/interleaf Magdir/island Magdir/ispell Magdir/java Magdir/jpeg Magdir/karma Magdir/lecter Magdir/lex Magdir/lif Magdir/linux Magdir/lisp Magdir/mach Magdir/macintosh Magdir/magic Magdir/mail.news Magdir/maple Magdir/mathematica Magdir/mcrypt Magdir/mime Magdir/mips Magdir/mirage Magdir/mkid Magdir/mmdf Magdir/modem Magdir/motorola Magdir/msdos Magdir/msvc Magdir/ncr Magdir/netbsd Magdir/netscape Magdir/news Magdir/octave Magdir/olf Magdir/os2 Magdir/os9 Magdir/osf1 Magdir/palm Magdir/pbm Magdir/pdf Magdir/pdp Magdir/pgp Magdir/pkgadd Magdir/plus5 Magdir/printer Magdir/project Magdir/psdbms Magdir/pyramid Magdir/python Magdir/riff Magdir/rpm Magdir/rtf Magdir/sc Magdir/sccs Magdir/sendmail Magdir/sequent Magdir/sgml Magdir/sketch Magdir/sniffer Magdir/softquad Magdir/spectrum Magdir/sun Magdir/teapot Magdir/terminfo Magdir/tex Magdir/ti-8x Magdir/timezone Magdir/troff Magdir/typeset Magdir/unknown Magdir/uuencode Magdir/varied.out Magdir/vax Magdir/vicar Magdir/visx Magdir/vms Magdir/vmware Magdir/wordperfect Magdir/xdelta Magdir/xenix Magdir/zilog Magdir/zyxel
+magic_FRAGMENTS = Magdir/adi Magdir/adventure Magdir/allegro Magdir/alliant Magdir/alpha Magdir/amanda Magdir/amigaos Magdir/animation Magdir/apl Magdir/apple Magdir/applix Magdir/archive Magdir/asterix Magdir/att3b Magdir/audio Magdir/blender Magdir/blit Magdir/bsdi Magdir/c-lang Magdir/chi Magdir/cisco Magdir/claris Magdir/clipper Magdir/commands Magdir/compress Magdir/console Magdir/convex Magdir/database Magdir/diamond Magdir/diff Magdir/digital Magdir/dump Magdir/elf Magdir/encore Magdir/epoc Magdir/filesystems Magdir/flash Magdir/fonts Magdir/frame Magdir/freebsd Magdir/fsav Magdir/gimp Magdir/gnu Magdir/grace Magdir/hp Magdir/ibm370 Magdir/ibm6000 Magdir/iff Magdir/images Magdir/intel Magdir/interleaf Magdir/island Magdir/ispell Magdir/java Magdir/jpeg Magdir/karma Magdir/lecter Magdir/lex Magdir/lif Magdir/linux Magdir/lisp Magdir/mach Magdir/macintosh Magdir/magic Magdir/mail.news Magdir/maple Magdir/mathematica Magdir/mcrypt Magdir/mime Magdir/mips Magdir/mirage Magdir/mkid Magdir/mmdf Magdir/modem Magdir/motorola Magdir/msdos Magdir/msvc Magdir/ncr Magdir/netbsd Magdir/netscape Magdir/news Magdir/octave Magdir/olf Magdir/os2 Magdir/os9 Magdir/osf1 Magdir/palm Magdir/pbm Magdir/pdf Magdir/pdp Magdir/pgp Magdir/pkgadd Magdir/plus5 Magdir/printer Magdir/project Magdir/psdbms Magdir/pyramid Magdir/python Magdir/riff Magdir/rpm Magdir/rtf Magdir/sc Magdir/sccs Magdir/sendmail Magdir/sequent Magdir/sgml Magdir/sketch Magdir/sniffer Magdir/softquad Magdir/spectrum Magdir/sun Magdir/teapot Magdir/terminfo Magdir/tex Magdir/ti-8x Magdir/timezone Magdir/troff Magdir/typeset Magdir/unknown Magdir/uuencode Magdir/varied.out Magdir/vax Magdir/vicar Magdir/visx Magdir/vms Magdir/vmware Magdir/wordperfect Magdir/xdelta Magdir/xenix Magdir/zilog Magdir/zyxel
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
diff --git a/configure b/configure
index d4e93464..6488d5fa 100755
--- a/configure
+++ b/configure
@@ -697,7 +697,7 @@ fi
PACKAGE=file
-VERSION=3.35
+VERSION=3.36
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
{ echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; }
diff --git a/configure.in b/configure.in
index 15a68ee4..4699f75e 100644
--- a/configure.in
+++ b/configure.in
@@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(file.c)
-AM_INIT_AUTOMAKE(file, 3.35)
+AM_INIT_AUTOMAKE(file, 3.36)
AM_CONFIG_HEADER(config.h)
AC_MSG_CHECKING(for builtin ELF support)
diff --git a/magic/Magdir/adi b/magic/Magdir/adi
new file mode 100644
index 00000000..12d7da59
--- /dev/null
+++ b/magic/Magdir/adi
@@ -0,0 +1,12 @@
+
+#------------------------------------------------------------------------------
+# adi: file(1) magic for ADi's objects
+# From Gregory McGarry <g.mcgarry@ieee.org>
+#
+0 leshort 0x521c COFF DSP21k
+>18 lelong &02 executable,
+>18 lelong ^02
+>>18 lelong &01 static object,
+>>18 lelong ^01 relocatable object,
+>18 lelong &010 stripped
+>18 lelong ^010 not stripped
diff --git a/magic/Magdir/animation b/magic/Magdir/animation
index b2f96648..6fa689f8 100644
--- a/magic/Magdir/animation
+++ b/magic/Magdir/animation
@@ -158,3 +158,13 @@
# conti_count 4 bit 0
0 belong&0xFF5FFF1F 0x47400010 MPEG transport stream data
>188 byte !0x47 CORRUPTED
+
+# DIF digital video file format <mpruett@sgi.com>
+0 belong&0xffffff00 0x1f070000 DIF
+>4 byte &0x01 (DVCPRO) movie file
+>4 byte ^0x01 (DV) movie file
+>3 byte &0x80 (PAL)
+>3 byte ^0x80 (NTSC)
+
+# Microsoft Advanced Streaming Format (ASF) <mpruett@sgi.com>
+0 belong 0x3026b275 Microsoft ASF
diff --git a/magic/Magdir/archive b/magic/Magdir/archive
index ebc8931b..7e982406 100644
--- a/magic/Magdir/archive
+++ b/magic/Magdir/archive
@@ -182,6 +182,8 @@
2 string -lh3- LHa 2.x? archive data [lh3]
2 string -lh4- LHa (2.x) archive data [lh4]
2 string -lh5- LHa (2.x) archive data [lh5]
+2 string -lh6- LHa (2.x) archive data [lh6]
+2 string -lh7- LHa (2.x) archive data [lh7]
>20 byte x - header level %d
# RAR archiver (Greg Roelofs, newt@uchicago.edu)
diff --git a/magic/Magdir/database b/magic/Magdir/database
index 91368906..87ecac70 100644
--- a/magic/Magdir/database
+++ b/magic/Magdir/database
@@ -72,4 +72,3 @@
# Round Robin Database Tool by Tobias Oetiker <oetiker@ee.ethz.ch>
0 string RRD RRDTool DB
>4 string x version %s
-
diff --git a/magic/Magdir/elf b/magic/Magdir/elf
index c0a5be36..4b784870 100644
--- a/magic/Magdir/elf
+++ b/magic/Magdir/elf
@@ -161,6 +161,7 @@
>>18 beshort 51 Stanford MIPS-X,
>>18 beshort 52 Motorola Coldfire,
>>18 beshort 53 Motorola M68HC12,
+>>18 beshort 73 Cray NV1,
>>18 beshort 75 Digital VAX,
>>18 beshort 0x9026 Alpha (unofficial),
>>20 belong 0 invalid version
diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems
index 80b5ea3c..9b95a8ca 100644
--- a/magic/Magdir/filesystems
+++ b/magic/Magdir/filesystems
@@ -61,7 +61,7 @@
0x18b string OS/2 OS/2 Boot Manager
-9564 lelong 0x00011954 Unix Fast File system,
+9564 lelong 0x00011954 Unix Fast File system (little-endian),
>8404 string x last mounted on %s,
>9504 ledate x last checkd at %s,
>8224 ledate x last writen at %s,
@@ -76,6 +76,21 @@
>8320 lelong 0 TIME optimization
>8320 lelong 1 SPACE optimization
+9564 belong 0x00011954 Unix Fast File system (little-endian),
+>8404 string x last mounted on %s,
+>9504 bedate x last checkd at %s,
+>8224 bedate x last writen at %s,
+>8228 belong x number of blocks %d,
+>8232 belong x number of data blocks %d,
+>8236 belong x number of cylinder groups %d,
+>8240 belong x number of basic blocks %d,
+>8244 belong x number of fragment blocks %d,
+>8248 belong x minimum percentage of free blocks %d,
+>8252 belong x rotational delay %dms,
+>8256 belong x disk rotational speed %drps,
+>8320 belong 0 TIME optimization
+>8320 belong 1 SPACE optimization
+
# ext2/ext3 filesystems - Andreas Dilger <adilger@turbolabs.com>
0x438 leshort 0xEF53 Linux
>0x44c lelong x rev %d
diff --git a/magic/Magdir/macintosh b/magic/Magdir/macintosh
index b6dc91c8..1fb8241e 100644
--- a/magic/Magdir/macintosh
+++ b/magic/Magdir/macintosh
@@ -240,3 +240,96 @@
0 string $FL2 SPSS System File
>24 string x %s
+
+# Macintosh filesystem data
+# From "Tom N Harris" <telliamed@mac.com>
+# The MacOS epoch begins on 1 Jan 1904 instead of 1 Jan 1970, so these
+# entries depend on the data arithmetic added after v.35
+# There's also some Pascal strings in here, ditto...
+
+# The boot block signature, according to IM:Files, is
+# "for HFS volumes, this field always contains the value 0x4C4B."
+# But if this is true for MFS or HFS+ volumes, I don't know.
+# Alternatively, the boot block is supposed to be zeroed if it's
+# unused, so a simply >0 should suffice.
+
+0x400 beshort 0xD2D7 Macintosh MFS data
+>0 beshort 0x4C4B (bootable)
+>0x40a beshort &0x8000 (locked)
+>0x402 beldate-0x7C25B080 x created: %s,
+>0x406 beldate-0x7C25B080 >0 last backup: %s,
+>0x414 belong x block size: %d,
+>0x412 beshort x number of blocks: %d,
+>0x424 pstring x volume name: %s
+
+0x400 beshort 0x4244 Macintosh HFS data
+>0 beshort 0x4C4B (bootable)
+>0x40a beshort &0x8000 (locked)
+>0x40a beshort ^0x0100 (mounted)
+>0x40a beshort &0x0800 (unclean)
+>0x402 beldate-0x7C25B080 x created: %s,
+>0x406 beldate-0x7C25B080 x last modified: %s,
+>0x440 beldate-0x7C25B080 >0 last backup: %s,
+>0x414 belong x block size: %d,
+>0x412 beshort x number of blocks: %d,
+>0x424 pstring x volume name: %s
+#>0x480 beshort =0x482B Embedded HFS+ Volume:
+#>>((0x482*(0x414))+(0x41c*512)) x \b
+# Well, this is (theoretically) how we could do this. But it occurs to
+# me that we likely don't read in a large enough chunk. I don't have any
+# HFS+ volumes to see what a typical offset would be.
+
+0x400 beshort 0x482B Macintosh HFS Extended
+>&2 beshort x version %d data
+>0 beshort 0x4C4B (bootable)
+>&4 belong ^0x00000100 (mounted)
+>&4 belong &0x00000800 (unclean)
+>&4 belong &0x00008000 (locked)
+>&8 string x last mounted by: '%.4s',
+# really, that should be treated as a belong and we print a string
+# based on the value. TN1150 only mentions '8.10' for "MacOS 8.1"
+>&16 beldate-0x7C25B080 x created: %s,
+>&20 beldate-0x7C25B080 x last modified: %s,
+>&24 beldate-0x7C25B080 >0 last backup: %s,
+>&28 beldate-0x7C25B080 >0 last checked: %s,
+>&40 belong x block size: %d,
+>&44 belong x number of blocks: %d,
+>&48 belong x free blocks: %d
+
+# I don't think this is really necessary since it doesn't do much and
+# anything with a valid driver descriptor will also have a valid
+# partition map
+#0 beshort 0x4552 Apple Device Driver data
+#>&24 beshort =1 \b, MacOS
+
+# Is that the partition type a cstring or a pstring? Well, IM says "strings
+# shorter than 32 bytes must be terminated with NULL" so I'll treat it as a
+# cstring. Of course, partitions can contain more than four entries, but
+# what're you gonna do?
+0x200 beshort 0x504D Apple Partition data
+>&2 beshort x block size: %d
+>&48 string x first type: %s,
+>&12 belong x number of blocks: %d,
+>(&0x2.S) beshort 0x504D
+>>&48 string x second type: %s
+>>&12 belong x number of blocks: %d,
+>>(&0x2.S) beshort 0x504D
+>>>&48 string x third type: %s
+>>>&12 belong x number of blocks: %d,
+>>>(&0x2.S) beshort 0x504D
+>>>>&48 string x fourth type: %s
+>>>>&12 belong x number of blocks: %d,
+# AFAIK, only the signature is different
+0x200 beshort 0x5453 Apple Old Partition data
+>&2 beshort x block size: %d
+>&48 string x first type: %s,
+>&12 belong x number of blocks: %d,
+>(&0x2.S) beshort 0x504D
+>>&48 string x second type: %s
+>>&12 belong x number of blocks: %d,
+>>(&0x2.S) beshort 0x504D
+>>>&48 string x third type: %s
+>>>&12 belong x number of blocks: %d,
+>>>(&0x2.S) beshort 0x504D
+>>>>&48 string x fourth type: %s
+>>>>&12 belong x number of blocks: %d,
diff --git a/magic/Magdir/sharc b/magic/Magdir/sharc
new file mode 100644
index 00000000..7201e856
--- /dev/null
+++ b/magic/Magdir/sharc
@@ -0,0 +1,22 @@
+
+#------------------------------------------------------------------------
+# file(1) magic for sharc files
+#
+# SHARC DSP, MIDI SysEx and RiscOS filetype definitions added by
+# FutureGroove Music (dsp@futuregroove.de)
+
+#------------------------------------------------------------------------
+0 string Draw RiscOS Drawfile
+0 string PACK RiscOS PackdDir archive
+
+#------------------------------------------------------------------------
+# SHARC DSP stuff (based on the FGM SHARC DSP SDK)
+
+0 string ! Assembler source
+0 string Analog ADi asm listing file
+0 string .SYSTEM SHARC architecture file
+0 string .system SHARC architecture file
+
+0 leshort 0x521C SHARC COFF binary
+>2 leshort >1 , %hd sections
+>>12 lelong >0 , not stripped
diff --git a/magic/Magdir/smalltalk b/magic/Magdir/smalltalk
new file mode 100644
index 00000000..27353120
--- /dev/null
+++ b/magic/Magdir/smalltalk
@@ -0,0 +1,23 @@
+
+#-----------------------------------------------
+# GNU Smalltalk image, starting at version 1.6.2
+#
+0 string GSTIm\0\0 GNU Smalltalk
+# little-endian
+>7 byte&1 =0 LE image version
+>>10 byte x %d.
+>>9 byte x \b%d.
+>>8 byte x \b%d
+#>>12 lelong x , data: %ld
+#>>16 lelong x , table: %ld
+#>>20 lelong x , memory: %ld
+# big-endian
+>7 byte&1 =1 BE image version
+>>8 byte x %d.
+>>9 byte x \b%d.
+>>10 byte x \b%d
+#>>12 belong x , data: %ld
+#>>16 belong x , table: %ld
+#>>20 belong x , memory: %ld
+
+
diff --git a/magic/Magdir/sysex b/magic/Magdir/sysex
new file mode 100644
index 00000000..9a3fe2ec
--- /dev/null
+++ b/magic/Magdir/sysex
@@ -0,0 +1,142 @@
+#------------------------------------------------------------------------
+# sysex: file(1) magic for MIDI sysex files
+#
+#
+0 byte 0xF0 SysEx File -
+
+>1 byte 0x2f ELKA
+>>3 byte 0x09 EK-44
+
+>1 byte 0x3e Waldorf
+>>3 byte 0x7f Microwave I
+
+>1 byte 0x40 Kawai
+>>3 byte 0x22 K4
+
+>1 byte 0x41 Roland
+>>3 byte 0x14 D-50
+>>3 byte 0x2b U-220
+>>3 byte 0x02 TR-707
+
+>1 byte 0x42 Korg
+>>3 byte 0x19 M1
+
+>1 byte 0x43 Yamaha
+>1 byte 0x44 Casio
+>1 byte 0x46 Kamiya
+>1 byte 0x47 Akai
+>1 byte 0x48 Victor
+>1 byte 0x4b Fujitsu
+>1 byte 0x4c Sony
+>1 byte 0x4e Teac
+>1 byte 0x50 Matsushita
+>1 byte 0x51 Fostex
+>1 byte 0x52 Zoom
+>1 byte 0x54 Matsushita
+>1 byte 0x57 Acoustic tech. lab.
+
+>1 belong&0xffffff00 0x00007400 Ta Horng
+>1 belong&0xffffff00 0x00007500 e-Tek
+>1 belong&0xffffff00 0x00007600 E-Voice
+>1 belong&0xffffff00 0x00007700 Midisoft
+>1 belong&0xffffff00 0x00007800 Q-Sound
+>1 belong&0xffffff00 0x00007900 Westrex
+>1 belong&0xffffff00 0x00007a00 Nvidia*
+>1 belong&0xffffff00 0x00007b00 ESS
+>1 belong&0xffffff00 0x00007c00 Mediatrix
+>1 belong&0xffffff00 0x00007d00 Brooktree
+>1 belong&0xffffff00 0x00007e00 Otari
+>1 belong&0xffffff00 0x00007f00 Key Electronics
+>1 belong&0xffffff00 0x00010000 Shure
+>1 belong&0xffffff00 0x00010100 AuraSound
+>1 belong&0xffffff00 0x00010200 Crystal
+>1 belong&0xffffff00 0x00010300 Rockwell
+>1 belong&0xffffff00 0x00010400 Silicon Graphics
+>1 belong&0xffffff00 0x00010500 Midiman
+>1 belong&0xffffff00 0x00010600 PreSonus
+>1 belong&0xffffff00 0x00010800 Topaz
+>1 belong&0xffffff00 0x00010900 Cast Lightning
+>1 belong&0xffffff00 0x00010a00 Microsoft
+>1 belong&0xffffff00 0x00010b00 Sonic Foundry
+>1 belong&0xffffff00 0x00010c00 Line 6
+>1 belong&0xffffff00 0x00010d00 Beatnik Inc.
+>1 belong&0xffffff00 0x00010e00 Van Koerving
+>1 belong&0xffffff00 0x00010f00 Altech Systems
+>1 belong&0xffffff00 0x00011000 S & S Research
+>1 belong&0xffffff00 0x00011100 VLSI Technology
+>1 belong&0xffffff00 0x00011200 Chromatic
+>1 belong&0xffffff00 0x00011300 Sapphire
+>1 belong&0xffffff00 0x00011400 IDRC
+>1 belong&0xffffff00 0x00011500 Justonic Tuning
+>1 belong&0xffffff00 0x00011600 TorComp
+>1 belong&0xffffff00 0x00011700 Newtek Inc.
+>1 belong&0xffffff00 0x00011800 Sound Sculpture
+>1 belong&0xffffff00 0x00011900 Walker Technical
+>1 belong&0xffffff00 0x00011a00 Digital Harmony
+>1 belong&0xffffff00 0x00011b00 InVision
+>1 belong&0xffffff00 0x00011c00 T-Square
+>1 belong&0xffffff00 0x00011d00 Nemesys
+>1 belong&0xffffff00 0x00011e00 DBX
+>1 belong&0xffffff00 0x00011f00 Syndyne
+>1 belong&0xffffff00 0x00012000 Bitheadz
+>1 belong&0xffffff00 0x00012100 Cakewalk
+>1 belong&0xffffff00 0x00012200 Staccato
+>1 belong&0xffffff00 0x00012300 National Semicon.
+>1 belong&0xffffff00 0x00012400 Boom Theory
+>1 belong&0xffffff00 0x00012500 Virtual DSP Corp
+>1 belong&0xffffff00 0x00012600 Antares
+>1 belong&0xffffff00 0x00012700 Angel Software
+>1 belong&0xffffff00 0x00012800 St Louis Music
+>1 belong&0xffffff00 0x00012900 Lyrrus dba G-VOX
+>1 belong&0xffffff00 0x00012a00 Ashley Audio
+>1 belong&0xffffff00 0x00012b00 Vari-Lite
+>1 belong&0xffffff00 0x00012c00 Summit Audio
+>1 belong&0xffffff00 0x00012d00 Aureal Semicon.
+>1 belong&0xffffff00 0x00012e00 SeaSound
+>1 belong&0xffffff00 0x00012f00 U.S. Robotics
+>1 belong&0xffffff00 0x00013000 Aurisis
+>1 belong&0xffffff00 0x00013100 Nearfield Multimedia
+>1 belong&0xffffff00 0x00013200 FM7 Inc.
+>1 belong&0xffffff00 0x00013300 Swivel Systems
+>1 belong&0xffffff00 0x00013400 Hyperactive
+>1 belong&0xffffff00 0x00013500 MidiLite
+>1 belong&0xffffff00 0x00013600 Radical
+>1 belong&0xffffff00 0x00013700 Roger Linn
+>1 belong&0xffffff00 0x00013800 Helicon
+>1 belong&0xffffff00 0x00013900 Event
+>1 belong&0xffffff00 0x00013a00 Sonic Network
+>1 belong&0xffffff00 0x00013b00 Realtime Music
+>1 belong&0xffffff00 0x00013c00 Apogee Digital
+
+>1 belong&0xffffff00 0x00202b00 Medeli Electronics
+>1 belong&0xffffff00 0x00202c00 Charlie Lab
+>1 belong&0xffffff00 0x00202d00 Blue Chip Music
+>1 belong&0xffffff00 0x00202e00 BEE OH Corp
+>1 belong&0xffffff00 0x00202f00 LG Semicon America
+>1 belong&0xffffff00 0x00203000 TESI
+>1 belong&0xffffff00 0x00203100 EMAGIC
+>1 belong&0xffffff00 0x00203200 Behringer
+>1 belong&0xffffff00 0x00203300 Access Music
+>1 belong&0xffffff00 0x00203400 Synoptic
+>1 belong&0xffffff00 0x00203500 Hanmesoft Corp
+>1 belong&0xffffff00 0x00203600 Terratec
+>1 belong&0xffffff00 0x00203700 Proel SpA
+>1 belong&0xffffff00 0x00203800 IBK MIDI
+>1 belong&0xffffff00 0x00203900 IRCAM
+>1 belong&0xffffff00 0x00203a00 Propellerhead Software
+>1 belong&0xffffff00 0x00203b00 Red Sound Systems
+>1 belong&0xffffff00 0x00203c00 Electron ESI AB
+>1 belong&0xffffff00 0x00203d00 Sintefex Audio
+>1 belong&0xffffff00 0x00203e00 Music and More
+>1 belong&0xffffff00 0x00203f00 Amsaro
+>1 belong&0xffffff00 0x00204000 CDS Advanced Technology
+>1 belong&0xffffff00 0x00204100 Touched by Sound
+>1 belong&0xffffff00 0x00204200 DSP Arts
+>1 belong&0xffffff00 0x00204300 Phil Rees Music
+>1 belong&0xffffff00 0x00204400 Stamer Musikanlagen GmbH
+>1 belong&0xffffff00 0x00204500 Soundart
+>1 belong&0xffffff00 0x00204600 C-Mexx Software
+>1 belong&0xffffff00 0x00204700 Klavis Tech.
+>1 belong&0xffffff00 0x00204800 Noteheads AB
+
+0 string T707 Roland TR-707 Data
diff --git a/magic/Magdir/troff b/magic/Magdir/troff
index ec964e8e..01ad88a0 100644
--- a/magic/Magdir/troff
+++ b/magic/Magdir/troff
@@ -9,6 +9,7 @@
0 string '\\" troff or preprocessor input text
0 string '.\\" troff or preprocessor input text
0 string \\" troff or preprocessor input text
+0 string ''' troff or preprocessor input text
# ditroff intermediate output text
0 string x\ T ditroff output text
diff --git a/magic/Magdir/vorbis b/magic/Magdir/vorbis
new file mode 100644
index 00000000..6e4efadc
--- /dev/null
+++ b/magic/Magdir/vorbis
@@ -0,0 +1,65 @@
+
+#------------------------------------------------------------------------------
+# vorbis: file(1) magic for Ogg/Vorbis files
+#
+# From Felix von Leitner <leitner@fefe.de>
+# Extended by Beni Cherniavsky <cben@crosswinds.net>
+#
+# Most (everything but the number of channels and bitrate) is commented
+# out with `##' as it's not interesting to the average user. The most
+# probable things advanced users would want to uncomment are probably
+# the number of comments and the encoder version.
+#
+# --- Ogg Framing ---
+0 string OggS Ogg data
+>4 byte !0 UNKNOWN REVISION %u
+##>4 byte 0 revision 0
+>4 byte 0
+##>>14 lelong x (Serial %lX)
+# --- First vorbis packet - general header ---
+>>28 string \x01vorbis \b, Vorbis audio,
+>>>35 lelong !0 UNKNOWN VERSION %lu,
+##>>>35 lelong 0 version 0,
+>>>35 lelong 0
+>>>>39 ubyte 1 mono,
+>>>>39 ubyte 2 stereo,
+>>>>39 ubyte >2 %u channels,
+>>>>40 lelong x %lu Hz
+# Minimal, nominal and maximal bitrates specified when encoding
+>>>>48 string <\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \b,
+# The above tests if at least one of these is specified:
+>>>>>44 lelong !-1
+>>>>>>44 lelong x >%lu
+>>>>>48 lelong !-1
+>>>>>>48 lelong x ~%lu
+>>>>>52 lelong !-1
+>>>>>>52 lelong x <%lu
+>>>>>48 string <\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff kbps
+# -- Second vorbis header packet - the comments
+>>>102 string \x03vorbis
+# A kludge to read the vendor string. It's a counted string, not a
+# zero-terminated one, so file(1) can't read it in a generic way.
+# libVorbis is the only one existing currently, so I detect specifically
+# it. The interesting value is the cvs date (8 digits decimal).
+##>>>>113 string/c Xiphophorus\ libVorbis\ I \b, created by: Xiphophorus libVorbis I
+##>>>>>137 string >00000000 %.8s
+# Map to beta version numbers:
+##>>>>>>137 string <20000508 (<beta1 - prepublic)
+# The string has not changed from beta1 to 2 - they are indistinguishable.
+##>>>>>>137 string 20000508 (beta1/2)
+##>>>>>>137 string >20000508
+##>>>>>>>137 string <20001031 (beta2-3)
+##>>>>>>137 string 20001031 (beta3)
+##>>>>>>137 string >20001031
+##>>>>>>>137 string <20010225 (beta3-4)
+##>>>>>>137 string 20010225 (beta4)
+##>>>>>>137 string >20010225
+##>>>>>>>137 string <20010615 (beta4-RC1)
+##>>>>>>137 string 20010615 (RC1)
+##>>>>>>137 string >20010615 (>RC1)
+# Then come the comments, again length-counted (and number-counted).
+# Some looping constructs and registers would allow reading them but now
+# it's impossible. However we can print the number of comments present
+# (skipping by the vendor string length):
+##>>>>(109.l.113) lelong 0 \b, no comments
+##>>>>(109.l+113) lelong >0 \b, %lu comments
diff --git a/magic/magic.mime b/magic/magic.mime
index 687e4fbc..836942a8 100644
--- a/magic/magic.mime
+++ b/magic/magic.mime
@@ -96,6 +96,10 @@
# MPEG Layer 3 sound files
# Modified the 11/20/97 at 15:59:04 by Christophe Prud'homme <christophe.prudhomme@asci.fr>
0 belong 0xfffb audio/x-mp3
+#MP3 with ID3 tag
+0 string ID3 audio/x-mp3
+# Ogg/Vorbis
+0 string OggS audio/x-ogg
#------------------------------------------------------------------------------
# c-lang: file(1) magic for C programs or various scripts
@@ -265,6 +269,8 @@
2 string -lh3- application/x-lha lh3
2 string -lh4- application/x-lha lh4
2 string -lh5- application/x-lha lh5
+2 string -lh6- application/x-lha lh6
+2 string -lh7- application/x-lha lh7
# Shell archives
10 string #\ This\ is\ a\ shell\ archive application/octet-stream x-shell
@@ -533,4 +539,5 @@
#
0 string #\ PaCkAgE\ DaTaStReAm application/x-svr4-package
-
+#PNG Image Format
+0 string \x89PNG image/png
diff --git a/src/Makefile.std b/src/Makefile.std
index cb376e69..5a91407e 100644
--- a/src/Makefile.std
+++ b/src/Makefile.std
@@ -1,6 +1,6 @@
# Makefile for file(1) cmd.
# Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
-# @(#)$Id: Makefile.std,v 1.10 2000/11/13 00:30:49 christos Exp $
+# @(#)$Id: Makefile.std,v 1.11 2001/07/22 21:04:15 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.
@@ -22,7 +22,7 @@
#
# 4. This notice may not be removed or altered.
#
-VERSION = 3.33
+VERSION = 3.36
SHELL = /bin/sh
#MAGIC = /etc/magic
MAGIC = /usr/local/etc/magic
diff --git a/src/apprentice.c b/src/apprentice.c
index bca60124..360a6825 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -39,7 +39,7 @@
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.41 2001/06/10 02:06:20 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.42 2001/07/22 21:04:15 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
@@ -299,12 +299,16 @@ signextend(m, v)
case DATE:
case BEDATE:
case LEDATE:
+ case LDATE:
+ case BELDATE:
+ case LELDATE:
case LONG:
case BELONG:
case LELONG:
v = (int32) v;
break;
case STRING:
+ case PSTRING:
break;
default:
magwarn("can't happen: m->type=%d\n",
@@ -361,7 +365,7 @@ parse(magicp, nmagicp, l, action)
}
if (m->cont_level != 0 && *l == '&') {
++l; /* step over */
- m->flag |= ADD;
+ m->flag |= OFFADD;
}
/* get offset, then skip over it */
@@ -405,12 +409,46 @@ parse(magicp, nmagicp, l, action)
}
l++;
}
- s = l;
- if (*l == '+' || *l == '-') l++;
- if (isdigit((unsigned char)*l)) {
- m->in_offset = strtoul(l, &t, 0);
- if (*s == '-') m->in_offset = - m->in_offset;
+ if (*l == '~') {
+ m->in_op = OPINVERSE;
+ l++;
}
+ switch (*l) {
+ case '&':
+ m->in_op |= OPAND;
+ l++;
+ break;
+ case '|':
+ m->in_op |= OPOR;
+ l++;
+ break;
+ case '^':
+ m->in_op |= OPXOR;
+ l++;
+ break;
+ case '+':
+ m->in_op |= OPADD;
+ l++;
+ break;
+ case '-':
+ m->in_op |= OPMINUS;
+ l++;
+ break;
+ case '*':
+ m->in_op |= OPMULTIPLY;
+ l++;
+ break;
+ case '/':
+ m->in_op |= OPDIVIDE;
+ l++;
+ break;
+ case '%':
+ m->in_op |= OPMODULO;
+ l++;
+ break;
+ }
+ if (isdigit((unsigned char)*l))
+ m->in_offset = strtoul(l, &t, 0);
else
t = l;
if (*t++ != ')')
@@ -434,6 +472,10 @@ parse(magicp, nmagicp, l, action)
#define NLESHORT 7
#define NLELONG 6
#define NLEDATE 6
+#define NPSTRING 7
+#define NLDATE 5
+#define NBELDATE 7
+#define NLELDATE 7
if (*l == 'u') {
++l;
@@ -477,18 +519,80 @@ parse(magicp, nmagicp, l, action)
} else if (strncmp(l, "ledate", NLEDATE)==0) {
m->type = LEDATE;
l += NLEDATE;
+ } else if (strncmp(l, "pstring", NPSTRING)==0) {
+ m->type = PSTRING;
+ l += NPSTRING;
+ } else if (strncmp(l, "ldate", NLDATE)==0) {
+ m->type = LDATE;
+ l += NLDATE;
+ } else if (strncmp(l, "beldate", NBELDATE)==0) {
+ m->type = BELDATE;
+ l += NBELDATE;
+ } else if (strncmp(l, "leldate", NLELDATE)==0) {
+ m->type = LELDATE;
+ l += NLELDATE;
} else {
magwarn("type %s invalid", l);
return -1;
}
/* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */
- if (*l == '&') {
+ /* New and improved: ~ & | ^ + - * / % -- exciting, isn't it? */
+ if (*l == '~') {
+ if (STRING != m->type && PSTRING != m->type)
+ m->mask_op = OPINVERSE;
+ ++l;
+ }
+ switch (*l) {
+ case '&':
+ m->mask_op |= OPAND;
+ ++l;
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
+ break;
+ case '|':
+ m->mask_op |= OPOR;
+ ++l;
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
+ break;
+ case '^':
+ m->mask_op |= OPXOR;
+ ++l;
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
+ break;
+ case '+':
+ m->mask_op |= OPADD;
+ ++l;
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
+ break;
+ case '-':
+ m->mask_op |= OPMINUS;
++l;
m->mask = signextend(m, strtoul(l, &l, 0));
eatsize(&l);
- } else if (STRING == m->type) {
- m->mask = 0L;
- if (*l == '/') {
+ break;
+ case '*':
+ m->mask_op |= OPMULTIPLY;
+ ++l;
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
+ break;
+ case '%':
+ m->mask_op |= OPMODULO;
+ ++l;
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
+ break;
+ case '/':
+ if (STRING != m->type && PSTRING != m->type) {
+ m->mask_op |= OPDIVIDE;
+ ++l;
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
+ } else {
+ m->mask = 0L;
while (!isspace(*++l)) {
switch (*l) {
case CHAR_IGNORE_LOWERCASE:
@@ -508,8 +612,10 @@ parse(magicp, nmagicp, l, action)
}
}
}
- } else
- m->mask = ~0L;
+ break;
+ }
+ /* We used to set mask to all 1's here, instead let's just not do anything
+ if mask = 0 (unless you have a better idea) */
EATAB;
switch (*l) {
@@ -527,7 +633,7 @@ parse(magicp, nmagicp, l, action)
}
break;
case '!':
- if (m->type != STRING) {
+ if (m->type != STRING && m->type != PSTRING) {
m->reln = *l;
++l;
break;
@@ -589,7 +695,7 @@ getvalue(m, p)
{
int slen;
- if (m->type == STRING) {
+ if (m->type == STRING || m->type == PSTRING) {
*p = getstr(*p, m->value.s, sizeof(m->value.s), &slen);
m->vallen = slen;
} else
diff --git a/src/compress.c b/src/compress.c
index e84d62d2..80d24e01 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -16,7 +16,7 @@
#include <sys/wait.h>
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: compress.c,v 1.19 2001/03/20 04:22:02 christos Exp $")
+FILE_RCSID("@(#)$Id: compress.c,v 1.20 2001/07/22 21:04:15 christos Exp $")
#endif
@@ -35,7 +35,7 @@ static struct {
{ "\037\240", 2, { "gzip", "-cdq", NULL }, 1 }, /* SCO LZH */
/* the standard pack utilities do not accept standard input */
{ "\037\036", 2, { "gzip", "-cdq", NULL }, 0 }, /* packed */
- { "BZh", 3, { "bzip2", "-d", NULL }, 1 }, /* bzip2-ed */
+ { "BZh", 3, { "bzip2", "-cd", NULL }, 1 }, /* bzip2-ed */
};
static int ncompr = sizeof(compr) / sizeof(compr[0]);
diff --git a/src/file.c b/src/file.c
index 5ebcf388..236591c2 100644
--- a/src/file.c
+++ b/src/file.c
@@ -56,14 +56,14 @@
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: file.c,v 1.57 2001/04/27 23:59:52 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.58 2001/07/22 21:04:15 christos Exp $")
#endif /* lint */
#ifdef S_IFLNK
-# define USAGE "Usage: %s [-bciknvzL] [-f namefile] [-m magicfiles] file...\n"
+# define USAGE "Usage: %s [-bciknsvzL] [-f namefile] [-m magicfiles] file...\n"
#else
-# define USAGE "Usage: %s [-bciknvz] [-f namefile] [-m magicfiles] file...\n"
+# define USAGE "Usage: %s [-bciknsvz] [-f namefile] [-m magicfiles] file...\n"
#endif
#ifndef MAGIC
@@ -89,7 +89,7 @@ int /* Misc globals */
struct magic *magic; /* array of magic entries */
-const char *magicfile; /* where magic be found */
+const char *magicfile = 0; /* where the magic is */
const char *default_magicfile = MAGIC;
char *progname; /* used throughout */
@@ -115,7 +115,8 @@ main(argc, argv)
{
int c;
int action = 0, didsomefiles = 0, errflg = 0, ret = 0, app = 0;
- char *mime;
+ char *mime, *home, *usermagic;
+ struct stat sb;
#ifdef LC_CTYPE
setlocale(LC_CTYPE, ""); /* makes islower etc work for other langs */
@@ -126,8 +127,20 @@ main(argc, argv)
else
progname = argv[0];
- if (!(magicfile = getenv("MAGIC")))
- magicfile = default_magicfile;
+ magicfile = default_magicfile;
+ if ((usermagic = getenv("MAGIC")) != NULL)
+ magicfile = usermagic;
+ else
+ if (home = getenv("HOME")) {
+ if ((usermagic = malloc(strlen(home) + 8)) != NULL) {
+ (void)strcpy(usermagic, home);
+ (void)strcat(usermagic, "/.magic");
+ if (stat(usermagic, &sb)<0)
+ free(usermagic);
+ else
+ magicfile = usermagic;
+ }
+ }
while ((c = getopt(argc, argv, "bcdf:ikm:nsvzCL")) != EOF)
switch (c) {
@@ -155,7 +168,7 @@ main(argc, argv)
break;
case 'i':
iflag++;
- if ((mime = malloc(strlen(magicfile) + 5)) != NULL) {
+ if ((mime = malloc(strlen(magicfile) + 6)) != NULL) {
(void)strcpy(mime, magicfile);
(void)strcat(mime, ".mime");
magicfile = mime;
diff --git a/src/file.h b/src/file.h
index 498d436a..6800e2f4 100644
--- a/src/file.h
+++ b/src/file.h
@@ -1,6 +1,6 @@
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.36 2001/04/27 23:59:52 christos Exp $
+ * @(#)$Id: file.h,v 1.37 2001/07/22 21:04:15 christos Exp $
*
* Copyright (c) Ian F. Darwin, 1987.
* Written by Ian F. Darwin.
@@ -59,7 +59,7 @@ struct magic {
uint8 flag;
#define INDIR 1 /* if '>(...)' appears, */
#define UNSIGNED 2 /* comparison is unsigned */
-#define ADD 4 /* if '>&' appears, */
+#define OFFADD 4 /* if '>&' appears, */
uint8 reln; /* relation (0=eq, '>'=gt, etc) */
uint8 vallen; /* length of string value, if any */
uint8 type; /* int, short, long or string. */
@@ -75,6 +75,21 @@ struct magic {
#define LESHORT 10
#define LELONG 11
#define LEDATE 12
+#define PSTRING 13
+#define LDATE 14
+#define BELDATE 15
+#define LELDATE 16
+ uint8 in_op; /* operator for indirection */
+ uint8 mask_op; /* operator for mask */
+#define OPAND 1
+#define OPOR 2
+#define OPXOR 3
+#define OPADD 4
+#define OPMINUS 5
+#define OPMULTIPLY 6
+#define OPDIVIDE 7
+#define OPMODULO 8
+#define OPINVERSE 0x80
int32 offset; /* offset to magic number */
int32 in_offset; /* offset from indirection */
union VALUETYPE {
@@ -123,6 +138,7 @@ extern void error __P((const char *, ...));
extern void ckfputs __P((const char *, FILE *));
struct stat;
extern int fsmagic __P((const char *, struct stat *));
+extern char *fmttime __P((long, int));
extern int is_compress __P((const unsigned char *, int *));
extern int is_tar __P((unsigned char *, int));
extern void magwarn __P((const char *, ...));
diff --git a/src/patchlevel.h b/src/patchlevel.h
index ef561261..5b5be297 100644
--- a/src/patchlevel.h
+++ b/src/patchlevel.h
@@ -1,11 +1,16 @@
#define FILE_VERSION_MAJOR 3
-#define patchlevel 35
+#define patchlevel 36
/*
* Patchlevel file for Ian Darwin's MAGIC command.
- * $Id: patchlevel.h,v 1.35 2001/04/24 14:40:25 christos Exp $
+ * $Id: patchlevel.h,v 1.36 2001/07/22 21:04:15 christos Exp $
*
* $Log: patchlevel.h,v $
+ * Revision 1.36 2001/07/22 21:04:15 christos
+ * - magic fixes
+ * - add new operators, pascal strings, UTC date printing, $HOME/.magic
+ * [from "Tom N Harris" <telliamed@mac.com>]
+ *
* Revision 1.35 2001/04/24 14:40:25 christos
* - rename magic file sgi to mips and fix it
* - add support for building magic.mgc
diff --git a/src/print.c b/src/print.c
index d6ae6e61..bf2c6679 100644
--- a/src/print.c
+++ b/src/print.c
@@ -41,7 +41,7 @@
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.32 2001/03/11 20:29:16 christos Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.33 2001/07/22 21:04:15 christos Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -53,26 +53,38 @@ mdump(m)
static const char *typ[] = { "invalid", "byte", "short", "invalid",
"long", "string", "date", "beshort",
"belong", "bedate", "leshort", "lelong",
- "ledate" };
+ "ledate", "pstring", "ldate", "beldate",
+ "leldate" };
+ static const char optyp[] = { '@', '&', '|', '^', '+', '-',
+ '*', '/', '%' };
(void) fputc('[', stderr);
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
m->offset);
- if (m->flag & INDIR)
- (void) fprintf(stderr, "(%s,%d),",
- /* Note: in.type is unsigned */
+ if (m->flag & INDIR) {
+ (void) fprintf(stderr, "(%s,",
+ /* Note: type is unsigned */
(m->in_type < SZOF(typ)) ?
- typ[m->in_type] : "*bad*",
- m->in_offset);
-
+ typ[m->in_type] : "*bad*");
+ if (m->in_op & OPINVERSE)
+ (void) fputc('~', stderr);
+ (void) fprintf(stderr, "%c%d),",
+ ((m->in_op&0x7F) < SZOF(optyp)) ?
+ optyp[m->in_op&0x7F] : '?',
+ m->in_offset);
+ }
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
/* Note: type is unsigned */
(m->type < SZOF(typ)) ? typ[m->type] : "*bad*");
- if (m->mask != ~((uint32)0)) {
- if(STRING != m->type)
- (void) fprintf(stderr, " & %.8x", m->mask);
+ if (m->mask_op & OPINVERSE)
+ (void) fputc('~', stderr);
+ if (m->mask) {
+ ((m->mask_op&0x7F) < SZOF(optyp)) ?
+ (void) fputc(optyp[m->mask_op&0x7F], stderr) :
+ (void) fputc('?', stderr);
+ if(STRING != m->type || PSTRING != m->type)
+ (void) fprintf(stderr, "%.8x", m->mask);
else {
- (void) fputc('/', stderr);
if (m->mask & STRING_IGNORE_LOWERCASE)
(void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
if (m->mask & STRING_COMPACT_BLANK)
@@ -97,21 +109,18 @@ mdump(m)
(void) fprintf(stderr, "%d", m->value.l);
break;
case STRING:
+ case PSTRING:
showstr(stderr, m->value.s, -1);
break;
case DATE:
case LEDATE:
case BEDATE:
- {
- time_t t = m->value.l;
- char *rt, *pp = ctime(&t);
-
- if ((rt = strchr(pp, '\n')) != NULL)
- *rt = '\0';
- (void) fprintf(stderr, "%s,", pp);
- if (rt)
- *rt = '\n';
- }
+ (void)fprintf(stderr, "%s,", fmttime(m->value.l, 1));
+ break;
+ case LDATE:
+ case LELDATE:
+ case BELDATE:
+ (void)fprintf(stderr, "%s,", fmttime(m->value.l, 0));
break;
default:
(void) fputs("*bad*", stderr);
@@ -122,7 +131,7 @@ mdump(m)
}
/*
- * ckfputs - futs, but with error checking
+ * ckfputs - fputs, but with error checking
* ckfprintf - fprintf, but with error checking
*/
void
@@ -216,3 +225,26 @@ magwarn(va_alist)
va_end(va);
fputc('\n', stderr);
}
+
+
+char *
+fmttime(v, local)
+ long v;
+ int local;
+{
+ char *pp, *rt;
+ time_t t = (time_t)v;
+ if (local) {
+ pp = ctime(&t);
+ } else {
+ struct tm *tm;
+ if (daylight)
+ t += 3600;
+ tm = gmtime(&t);
+ pp = asctime(tm);
+ }
+
+ if ((rt = strchr(pp, '\n')) != NULL)
+ *rt = '\0';
+ return pp;
+}
diff --git a/src/softmagic.c b/src/softmagic.c
index a32e2323..1085dee4 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.44 2001/03/17 19:32:50 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.45 2001/07/22 21:04:15 christos Exp $")
#endif /* lint */
static int match __P((struct magic *, uint32, unsigned char *, int));
@@ -157,7 +157,7 @@ match(magic, nmagic, s, nbytes)
*/
cont_level = magic[magindex].cont_level;
}
- if (magic[magindex].flag & ADD) {
+ if (magic[magindex].flag & OFFADD) {
oldoff=magic[magindex].offset;
magic[magindex].offset +=
tmpoff[cont_level-1];
@@ -195,7 +195,7 @@ match(magic, nmagic, s, nbytes)
tmplen += 20)) == NULL)
error("out of memory\n");
}
- if (magic[magindex].flag & ADD) {
+ if (magic[magindex].flag & OFFADD) {
magic[magindex].offset = oldoff;
}
}
@@ -215,6 +215,7 @@ mprint(p, m)
struct magic *m;
{
char *pp, *rt;
+ char *oldtz, tz[16];
uint32 v;
time_t curtime;
int32 t=0 ;
@@ -222,8 +223,7 @@ mprint(p, m)
switch (m->type) {
case BYTE:
- v = p->b;
- v = signextend(m, v) & m->mask;
+ v = signextend(m, p->b);
(void) printf(m->desc, (unsigned char) v);
t = m->offset + sizeof(char);
break;
@@ -231,8 +231,7 @@ mprint(p, m)
case SHORT:
case BESHORT:
case LESHORT:
- v = p->h;
- v = signextend(m, v) & m->mask;
+ v = signextend(m, p->h);
(void) printf(m->desc, (unsigned short) v);
t = m->offset + sizeof(short);
break;
@@ -240,13 +239,13 @@ mprint(p, m)
case LONG:
case BELONG:
case LELONG:
- v = p->l;
- v = signextend(m, v) & m->mask;
+ v = signextend(m, p->l);
(void) printf(m->desc, (uint32) v);
t = m->offset + sizeof(int32);
break;
case STRING:
+ case PSTRING:
if (m->reln == '=') {
(void) printf(m->desc, m->value.s);
t = m->offset + strlen(m->value.s);
@@ -265,11 +264,14 @@ mprint(p, m)
case DATE:
case BEDATE:
case LEDATE:
- curtime = p->l;
- pp = ctime(&curtime);
- if ((rt = strchr(pp, '\n')) != NULL)
- *rt = '\0';
- (void) printf(m->desc, pp);
+ (void) printf(m->desc, fmttime(p->l, 1));
+ t = m->offset + sizeof(time_t);
+ break;
+
+ case LDATE:
+ case BELDATE:
+ case LELDATE:
+ (void) printf(m->desc, fmttime(p->l, 0));
t = m->offset + sizeof(time_t);
break;
@@ -282,6 +284,8 @@ mprint(p, m)
/*
* Convert the byte order of the data we are looking at
+ * While we're here, let's apply the mask operation
+ * (unless you have a better idea)
*/
static int
mconvert(p, m)
@@ -290,35 +294,259 @@ mconvert(p, m)
{
switch (m->type) {
case BYTE:
+ if (m->mask)
+ switch (m->mask_op&0x7F) {
+ case OPAND:
+ p->b &= m->mask;
+ break;
+ case OPOR:
+ p->b |= m->mask;
+ break;
+ case OPXOR:
+ p->b ^= m->mask;
+ break;
+ case OPADD:
+ p->b += m->mask;
+ break;
+ case OPMINUS:
+ p->b -= m->mask;
+ break;
+ case OPMULTIPLY:
+ p->b *= m->mask;
+ break;
+ case OPDIVIDE:
+ p->b /= m->mask;
+ break;
+ case OPMODULO:
+ p->b %= m->mask;
+ break;
+ }
+ if (m->mask_op & OPINVERSE)
+ p->b = ~p->b;
+ return 1;
case SHORT:
+ if (m->mask)
+ switch (m->mask_op&0x7F) {
+ case OPAND:
+ p->h &= m->mask;
+ break;
+ case OPOR:
+ p->h |= m->mask;
+ break;
+ case OPXOR:
+ p->h ^= m->mask;
+ break;
+ case OPADD:
+ p->h += m->mask;
+ break;
+ case OPMINUS:
+ p->h -= m->mask;
+ break;
+ case OPMULTIPLY:
+ p->h *= m->mask;
+ break;
+ case OPDIVIDE:
+ p->h /= m->mask;
+ break;
+ case OPMODULO:
+ p->h %= m->mask;
+ break;
+ }
+ if (m->mask_op & OPINVERSE)
+ p->h = ~p->h;
+ return 1;
case LONG:
case DATE:
+ case LDATE:
+ if (m->mask)
+ switch (m->mask_op&0x7F) {
+ case OPAND:
+ p->l &= m->mask;
+ break;
+ case OPOR:
+ p->l |= m->mask;
+ break;
+ case OPXOR:
+ p->l ^= m->mask;
+ break;
+ case OPADD:
+ p->l += m->mask;
+ break;
+ case OPMINUS:
+ p->l -= m->mask;
+ break;
+ case OPMULTIPLY:
+ p->l *= m->mask;
+ break;
+ case OPDIVIDE:
+ p->l /= m->mask;
+ break;
+ case OPMODULO:
+ p->l %= m->mask;
+ break;
+ }
+ if (m->mask_op & OPINVERSE)
+ p->l = ~p->l;
return 1;
case STRING:
{
char *ptr;
+ int n;
- /* Null terminate and eat the return */
+ /* Null terminate and eat *trailing* return */
p->s[sizeof(p->s) - 1] = '\0';
- if ((ptr = strchr(p->s, '\n')) != NULL)
- *ptr = '\0';
+ n = strlen(p->s) - 1;
+ if (p->s[n] == '\n')
+ p->s[n] = '\0';
+ return 1;
+ }
+ case PSTRING:
+ {
+ char *ptr1 = p->s, *ptr2 = ptr1 + 1;
+ int n = *p->s;
+ if (n >= sizeof(p->s))
+ n = sizeof(p->s) - 1;
+ while (n--)
+ *ptr1++ = *ptr2++;
+ *ptr1 = '\0';
+ n = strlen(p->s) - 1;
+ if (p->s[n] == '\n')
+ p->s[n] = '\0';
return 1;
}
case BESHORT:
p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
+ if (m->mask)
+ switch (m->mask_op&0x7F) {
+ case OPAND:
+ p->h &= m->mask;
+ break;
+ case OPOR:
+ p->h |= m->mask;
+ break;
+ case OPXOR:
+ p->h ^= m->mask;
+ break;
+ case OPADD:
+ p->h += m->mask;
+ break;
+ case OPMINUS:
+ p->h -= m->mask;
+ break;
+ case OPMULTIPLY:
+ p->h *= m->mask;
+ break;
+ case OPDIVIDE:
+ p->h /= m->mask;
+ break;
+ case OPMODULO:
+ p->h %= m->mask;
+ break;
+ }
+ if (m->mask_op & OPINVERSE)
+ p->h = ~p->h;
return 1;
case BELONG:
case BEDATE:
+ case BELDATE:
p->l = (int32)
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
+ if (m->mask)
+ switch (m->mask_op&0x7F) {
+ case OPAND:
+ p->l &= m->mask;
+ break;
+ case OPOR:
+ p->l |= m->mask;
+ break;
+ case OPXOR:
+ p->l ^= m->mask;
+ break;
+ case OPADD:
+ p->l += m->mask;
+ break;
+ case OPMINUS:
+ p->l -= m->mask;
+ break;
+ case OPMULTIPLY:
+ p->l *= m->mask;
+ break;
+ case OPDIVIDE:
+ p->l /= m->mask;
+ break;
+ case OPMODULO:
+ p->l %= m->mask;
+ break;
+ }
+ if (m->mask_op & OPINVERSE)
+ p->l = ~p->l;
return 1;
case LESHORT:
p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
+ if (m->mask)
+ switch (m->mask_op&0x7F) {
+ case OPAND:
+ p->h &= m->mask;
+ break;
+ case OPOR:
+ p->h |= m->mask;
+ break;
+ case OPXOR:
+ p->h ^= m->mask;
+ break;
+ case OPADD:
+ p->h += m->mask;
+ break;
+ case OPMINUS:
+ p->h -= m->mask;
+ break;
+ case OPMULTIPLY:
+ p->h *= m->mask;
+ break;
+ case OPDIVIDE:
+ p->h /= m->mask;
+ break;
+ case OPMODULO:
+ p->h %= m->mask;
+ break;
+ }
+ if (m->mask_op & OPINVERSE)
+ p->h = ~p->h;
return 1;
case LELONG:
case LEDATE:
+ case LELDATE:
p->l = (int32)
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
+ if (m->mask)
+ switch (m->mask_op&0x7F) {
+ case OPAND:
+ p->l &= m->mask;
+ break;
+ case OPOR:
+ p->l |= m->mask;
+ break;
+ case OPXOR:
+ p->l ^= m->mask;
+ break;
+ case OPADD:
+ p->l += m->mask;
+ break;
+ case OPMINUS:
+ p->l -= m->mask;
+ break;
+ case OPMULTIPLY:
+ p->l *= m->mask;
+ break;
+ case OPDIVIDE:
+ p->l /= m->mask;
+ break;
+ case OPMODULO:
+ p->l %= m->mask;
+ break;
+ }
+ if (m->mask_op & OPINVERSE)
+ p->l = ~p->l;
return 1;
default:
error("invalid type %d in mconvert().\n", m->type);
@@ -371,31 +599,324 @@ mget(p, s, m, nbytes)
switch (m->in_type) {
case BYTE:
- offset = p->b + m->in_offset;
+ if (m->in_offset)
+ switch (m->in_op&0x7F) {
+ case OPAND:
+ offset = p->b & m->in_offset;
+ break;
+ case OPOR:
+ offset = p->b | m->in_offset;
+ break;
+ case OPXOR:
+ offset = p->b ^ m->in_offset;
+ break;
+ case OPADD:
+ offset = p->b + m->in_offset;
+ break;
+ case OPMINUS:
+ offset = p->b - m->in_offset;
+ break;
+ case OPMULTIPLY:
+ offset = p->b * m->in_offset;
+ break;
+ case OPDIVIDE:
+ offset = p->b / m->in_offset;
+ break;
+ case OPMODULO:
+ offset = p->b % m->in_offset;
+ break;
+ }
+ if (m->in_op & OPINVERSE)
+ offset = ~offset;
break;
case BESHORT:
- offset = (short)((p->hs[0]<<8)|(p->hs[1]))+
- m->in_offset;
+ if (m->in_offset)
+ switch (m->in_op&0x7F) {
+ case OPAND:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) &
+ m->in_offset;
+ break;
+ case OPOR:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) |
+ m->in_offset;
+ break;
+ case OPXOR:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) ^
+ m->in_offset;
+ break;
+ case OPADD:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) +
+ m->in_offset;
+ break;
+ case OPMINUS:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) -
+ m->in_offset;
+ break;
+ case OPMULTIPLY:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) *
+ m->in_offset;
+ break;
+ case OPDIVIDE:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) /
+ m->in_offset;
+ break;
+ case OPMODULO:
+ offset = (short)((p->hs[0]<<8)|
+ (p->hs[1])) %
+ m->in_offset;
+ break;
+ }
+ if (m->in_op & OPINVERSE)
+ offset = ~offset;
break;
case LESHORT:
- offset = (short)((p->hs[1]<<8)|(p->hs[0]))+
- m->in_offset;
+ if (m->in_offset)
+ switch (m->in_op&0x7F) {
+ case OPAND:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) &
+ m->in_offset;
+ break;
+ case OPOR:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) |
+ m->in_offset;
+ break;
+ case OPXOR:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) ^
+ m->in_offset;
+ break;
+ case OPADD:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) +
+ m->in_offset;
+ break;
+ case OPMINUS:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) -
+ m->in_offset;
+ break;
+ case OPMULTIPLY:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) *
+ m->in_offset;
+ break;
+ case OPDIVIDE:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) /
+ m->in_offset;
+ break;
+ case OPMODULO:
+ offset = (short)((p->hs[1]<<8)|
+ (p->hs[0])) %
+ m->in_offset;
+ break;
+ }
+ if (m->in_op & OPINVERSE)
+ offset = ~offset;
break;
case SHORT:
- offset = p->h + m->in_offset;
+ if (m->in_offset)
+ switch (m->in_op&0x7F) {
+ case OPAND:
+ offset = p->h & m->in_offset;
+ break;
+ case OPOR:
+ offset = p->h | m->in_offset;
+ break;
+ case OPXOR:
+ offset = p->h ^ m->in_offset;
+ break;
+ case OPADD:
+ offset = p->h + m->in_offset;
+ break;
+ case OPMINUS:
+ offset = p->h - m->in_offset;
+ break;
+ case OPMULTIPLY:
+ offset = p->h * m->in_offset;
+ break;
+ case OPDIVIDE:
+ offset = p->h / m->in_offset;
+ break;
+ case OPMODULO:
+ offset = p->h % m->in_offset;
+ break;
+ }
+ if (m->in_op & OPINVERSE)
+ offset = ~offset;
break;
case BELONG:
- offset = (int32)((p->hl[0]<<24)|(p->hl[1]<<16)|
- (p->hl[2]<<8)|(p->hl[3]))+
- m->in_offset;
+ if (m->in_offset)
+ switch (m->in_op&0x7F) {
+ case OPAND:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) &
+ m->in_offset;
+ break;
+ case OPOR:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) |
+ m->in_offset;
+ break;
+ case OPXOR:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) ^
+ m->in_offset;
+ break;
+ case OPADD:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) +
+ m->in_offset;
+ break;
+ case OPMINUS:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) -
+ m->in_offset;
+ break;
+ case OPMULTIPLY:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) *
+ m->in_offset;
+ break;
+ case OPDIVIDE:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) /
+ m->in_offset;
+ break;
+ case OPMODULO:
+ offset = (int32)((p->hl[0]<<24)|
+ (p->hl[1]<<16)|
+ (p->hl[2]<<8)|
+ (p->hl[3])) %
+ m->in_offset;
+ break;
+ }
+ if (m->in_op & OPINVERSE)
+ offset = ~offset;
break;
case LELONG:
- offset = (int32)((p->hl[3]<<24)|(p->hl[2]<<16)|
- (p->hl[1]<<8)|(p->hl[0]))+
- m->in_offset;
+ if (m->in_offset)
+ switch (m->in_op&0x7F) {
+ case OPAND:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) &
+ m->in_offset;
+ break;
+ case OPOR:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) |
+ m->in_offset;
+ break;
+ case OPXOR:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) ^
+ m->in_offset;
+ break;
+ case OPADD:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) +
+ m->in_offset;
+ break;
+ case OPMINUS:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) -
+ m->in_offset;
+ break;
+ case OPMULTIPLY:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) *
+ m->in_offset;
+ break;
+ case OPDIVIDE:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) /
+ m->in_offset;
+ break;
+ case OPMODULO:
+ offset = (int32)((p->hl[3]<<24)|
+ (p->hl[2]<<16)|
+ (p->hl[1]<<8)|
+ (p->hl[0])) %
+ m->in_offset;
+ break;
+ }
+ if (m->in_op & OPINVERSE)
+ offset = ~offset;
break;
case LONG:
- offset = p->l + m->in_offset;
+ if (m->in_offset)
+ switch (m->in_op&0x7F) {
+ case OPAND:
+ offset = p->l & m->in_offset;
+ break;
+ case OPOR:
+ offset = p->l | m->in_offset;
+ break;
+ case OPXOR:
+ offset = p->l ^ m->in_offset;
+ break;
+ case OPADD:
+ offset = p->l + m->in_offset;
+ break;
+ case OPMINUS:
+ offset = p->l - m->in_offset;
+ break;
+ case OPMULTIPLY:
+ offset = p->l * m->in_offset;
+ break;
+ case OPDIVIDE:
+ offset = p->l / m->in_offset;
+ break;
+ case OPMODULO:
+ offset = p->l % m->in_offset;
+ break;
+ /* case TOOMANYSWITCHBLOCKS:
+ * ugh = p->eye % m->strain;
+ * rub;
+ * case BEER:
+ * off = p->tab & m->in_gest;
+ * sleep;
+ */
+ }
+ if (m->in_op & OPINVERSE)
+ offset = ~offset;
break;
}
@@ -446,10 +967,15 @@ mcheck(p, m)
case DATE:
case BEDATE:
case LEDATE:
+ case LDATE:
+ case BELDATE:
+ case LELDATE:
v = p->l;
break;
- case STRING: {
+ case STRING:
+ case PSTRING:
+ {
/*
* What we want here is:
* v = strncmp(m->value.s, p->s, m->vallen);
@@ -499,8 +1025,8 @@ mcheck(p, m)
return 0;/*NOTREACHED*/
}
- if(m->type != STRING)
- v = signextend(m, v) & m->mask;
+ if(m->type != STRING && m->type != PSTRING)
+ v = signextend(m, v);
switch (m->reln) {
case 'x':