crunch cornflakes

This commit is contained in:
pooka 2007-06-07 11:32:44 +00:00
parent 40ad27db84
commit 9afe6367b3
23 changed files with 229 additions and 169 deletions

View File

@ -1,5 +1,5 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* $NetBSD: config.h.in,v 1.12 2007/03/04 15:22:07 pooka Exp $ */
/* $NetBSD: config.h.in,v 1.13 2007/06/07 11:32:44 pooka Exp $ */
/* Autoheader needs me */
#undef PACKAGE
@ -89,6 +89,9 @@
/* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H

5
dist/file/configure vendored
View File

@ -1808,7 +1808,7 @@ fi
# Define the identity of the package.
PACKAGE=file
VERSION=4.20
VERSION=4.21
cat >>confdefs.h <<_ACEOF
@ -20670,7 +20670,8 @@ done
for ac_header in utime.h wchar.h wctype.h
for ac_header in utime.h wchar.h wctype.h limits.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then

View File

@ -1,7 +1,7 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT
AC_CONFIG_SRCDIR([src/file.c])
AM_INIT_AUTOMAKE(file, 4.20)
AM_INIT_AUTOMAKE(file, 4.21)
AM_CONFIG_HEADER([config.h])
AM_MAINTAINER_MODE
@ -80,7 +80,7 @@ AC_HEADER_MAJOR
AC_HEADER_SYS_WAIT
AC_HEADER_STDINT
AC_CHECK_HEADERS(fcntl.h locale.h stdint.h inttypes.h unistd.h getopt.h)
AC_CHECK_HEADERS(utime.h wchar.h wctype.h)
AC_CHECK_HEADERS(utime.h wchar.h wctype.h limits.h)
AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h)
dnl Checks for typedefs, structures, and compiler characteristics.

View File

@ -1,4 +1,4 @@
.\" $NetBSD: file.1,v 1.14 2007/03/04 15:22:08 pooka Exp $
.\" $NetBSD: file.1,v 1.15 2007/06/07 11:32:45 pooka Exp $
.\"
.\" $File: file.man,v 1.65 2007/01/25 21:05:46 christos Exp $
.Dd January 8, 2007
@ -18,7 +18,7 @@
.Fl C
.Op Fl m Ar magicfile
.Sh DESCRIPTION
This manual page documents version 4.20 of the
This manual page documents version 4.21 of the
.Nm
command.
.Pp

View File

@ -1,4 +1,4 @@
.\" $NetBSD: libmagic.3,v 1.7 2007/03/04 15:22:08 pooka Exp $
.\" $NetBSD: libmagic.3,v 1.8 2007/06/07 11:32:45 pooka Exp $
.\"
.\" Copyright (c) Christos Zoulas 2003.
.\" All Rights Reserved.

148
dist/file/doc/magic.5 vendored
View File

@ -1,6 +1,6 @@
.\" $NetBSD: magic.5,v 1.14 2007/03/04 15:22:08 pooka Exp $
.\" $NetBSD: magic.5,v 1.15 2007/06/07 11:32:45 pooka Exp $
.\"
.\" $File: magic.man,v 1.36 2007/01/10 22:56:49 christos Exp $
.\" $File: magic.man,v 1.38 2007/01/27 00:52:08 ljt Exp $
.Dd January 10, 2007
.Dt MAGIC 5
.Os
@ -12,7 +12,7 @@
This manual page documents the format of the magic file as
used by the
.Xr file 1
command, version 4.20.
command, version 4.21.
The
.Xr file 1
command identifies the type of a file using,
@ -51,7 +51,7 @@ An eight-byte value (on most systems) in this machine's native byte order.
A string of bytes.
The string type specification can be optionally followed
by /[Bbc]*.
The
The
.Dq B
flag compacts whitespace in the target, which must
contain at least one whitespace character.
@ -60,7 +60,7 @@ If the magic has
consecutive blanks, the target needs at least
.Dv n
consecutive blanks to match.
The
The
.Dq b
flag treats every blank in the target as an optional blank.
Finally the
@ -71,7 +71,8 @@ targer, whereas upper case characters in the magic, only much uppercase
characters in the target.
.It Dv pstring
A pascal style string where the first byte is interpreted as the an
unsigned length. The string is not NUL terminated.
unsigned length.
The string is not NUL terminated.
.It Dv date
A four-byte value interpreted as a UNIX date.
.It Dv qdate
@ -139,7 +140,7 @@ than UTC.
A regular expression match in extended POSIX regular expression syntax
(much like egrep).
The type specification can be optionally followed by /[cse]*.
The
The
.Dq c
flag makes the match case insensitive, while the
.Dq s
@ -160,14 +161,15 @@ and
will match the beginning and end of individual lines, respectively,
not beginning and end of file.
.It Dv search
A literal string search starting at the given offset. It must be followed by
.Dv /<number>
A literal string search starting at the given offset.
It must be followed by
.Dv \*[Lt]number\*[Gt]
which specifies how many matches shall be attempted (the range).
This is suitable for searching larger binary expressions with variable
offsets, using
.Dv \e
escapes for special characters.
.It Dv default
.It Dv default
This is intended to be used with the text
.Dv x
(which is always true) and a message that is to be used if there are
@ -176,7 +178,7 @@ no other matches.
.El
.Pp
The numeric types may optionally be followed by
.Dv &
.Dv \*[Am]
and a numeric value,
to specify that the value is to be AND'ed with the
numeric value before any comparisons are done.
@ -196,13 +198,13 @@ may be preceded by a character indicating the operation to be performed.
It may be
.Dv = ,
to specify that the value from the file must equal the specified value,
.Dv < ,
.Dv \*[Lt] ,
to specify that the value from the file must be less than the specified
value,
.Dv > ,
.Dv \*[Gt] ,
to specify that the value from the file must be greater than the specified
value,
.Dv & ,
.Dv \*[Am] ,
to specify that the value from the file must have set all of the bits
that are set in the specified value,
.Dv ^ ,
@ -217,7 +219,7 @@ If the character is omitted, it is assumed to be
For all tests except
.Em string
and
.Em regex,
.Em regex ,
operation
.Dv !
specifies that the line matches if the test does
@ -236,25 +238,25 @@ For string values, the byte string from the
file must match the specified byte string.
The operators
.Dv = ,
.Dv <
.Dv \*[Lt]
and
.Dv >
.Dv \*[Gt]
(but not
.Dv & )
.Dv \*[Am] )
can be applied to strings.
The length used for matching is that of the string argument
in the magic file.
This means that a line can match any string, and
then presumably print that string, by doing
.Em >\e0
.Em \*[Gt]\e0
(because all strings are greater than the null string).
.Pp
The special test
.Em x
always evaluates to true.
.Dv message
The message to be printed if the comparison succeeds. If the string
contains a
The message to be printed if the comparison succeeds.
If the string contains a
.Xr printf 3
format specification, the value from the file (with any specified masking
performed) is printed using the message as the format string.
@ -267,12 +269,12 @@ Some file formats contain additional information which is to be printed
along with the file type or need additional tests to determine the true
file type.
These additional tests are introduced by one or more
.Em >
.Em \*[Gt]
characters preceding the offset.
The number of
.Em >
.Em \*[Gt]
on the line indicates the level of the test; a line with no
.Em >
.Em \*[Gt]
at the beginning is considered to be at level 0.
Tests are arranged in a tree-like hierarchy:
If a the test on a line at level
@ -285,16 +287,16 @@ with level
(or less) appears.
For more complex files, one can use empty messages to get just the
"if/then" effect, in the following way:
.Bd -literal -offset indent
.Bd -literal -offset indent
0 string MZ
>0x18 leshort <0x40 MS-DOS executable
>0x18 leshort >0x3f extended PC executable (e.g., MS Windows)
\*[Gt]0x18 leshort \*[Lt]0x40 MS-DOS executable
\*[Gt]0x18 leshort \*[Gt]0x3f extended PC executable (e.g., MS Windows)
.Ed
.Pp
Offsets do not need to be constant, but can also be read from the file
being examined.
If the first character following the last
.Em >
.Em \*[Gt]
is a
.Em (
then the string after the parenthesis is interpreted as an indirect offset.
@ -303,11 +305,11 @@ the file.
The value at that offset is read, and is used again as an offset
in the file.
Indirect offsets are of the form:
.Em (( x [.[bslBSL]][+\-][ y ]).
.Em (( x [.[bslBSL]][+\-][ y ]) .
The value of
.Em x
is used as an offset in the file. A byte, short or long is read at that offset
depending on the
is used as an offset in the file.
A byte, short or long is read at that offset depending on the
.Em [bslBSLm]
type specifier.
The capitalized types interpret the number as a big endian
@ -322,14 +324,14 @@ is added and the result is used as an offset in the file.
The default type if one is not specified is long.
.Pp
That way variable length structures can be examined:
.Bd -literal -offset indent
.Bd -literal -offset indent
# MS Windows executables are also valid MS-DOS executables
0 string MZ
>0x18 leshort <0x40 MZ executable (MS-DOS)
\*[Gt]0x18 leshort \*[Lt]0x40 MZ executable (MS-DOS)
# skip the whole block below if it is not an extended executable
>0x18 leshort >0x3f
>>(0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
>>(0x3c.l) string LX\e0\e0 LX executable (OS/2)
\*[Gt]0x18 leshort \*[Gt]0x3f
\*[Gt]\*[Gt](0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
\*[Gt]\*[Gt](0x3c.l) string LX\e0\e0 LX executable (OS/2)
.Ed
.Pp
This strategy of examining has one drawback: You must make sure that
@ -338,79 +340,84 @@ there is neither PE\e0\e0 nor LE\e0\e0 in the above example)
.Pp
If this indirect offset cannot be used as-is, there are simple calculations
possible: appending
.Em [+-*/%&|^]<number>
.Em [+-*/%\*[Am]|^]\*[Lt]number\*[Gt]
inside parentheses allows one to modify
the value read from the file before it is used as an offset:
.Bd -literal -offset indent
.Bd -literal -offset indent
# MS Windows executables are also valid MS-DOS executables
0 string MZ
# sometimes, the value at 0x18 is less that 0x40 but there's still an
# extended executable, simply appended to the file
>0x18 leshort <0x40
>>(4.s*512) leshort 0x014c COFF executable (MS-DOS, DJGPP)
>>(4.s*512) leshort !0x014c MZ executable (MS-DOS)
\*[Gt]0x18 leshort \*[Lt]0x40
\*[Gt]\*[Gt](4.s*512) leshort 0x014c COFF executable (MS-DOS, DJGPP)
\*[Gt]\*[Gt](4.s*512) leshort !0x014c MZ executable (MS-DOS)
.Ed
.Pp
Sometimes you do not know the exact offset as this depends on the length or
position (when indirection was used before) of preceding fields. You can
specify an offset relative to the end of the last up-level field using
.Sq &
position (when indirection was used before) of preceding fields.
You can specify an offset relative to the end of the last up-level
field using
.Sq \*[Am]
as a prefix to the offset:
.Bd -literal -offset indent
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
\*[Gt]0x18 leshort \*[Gt]0x3f
\*[Gt]\*[Gt](0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
# immediately following the PE signature is the CPU type
>>>&0 leshort 0x14c for Intel 80386
>>>&0 leshort 0x184 for DEC Alpha
\*[Gt]\*[Gt]\*[Gt]\*[Am]0 leshort 0x14c for Intel 80386
\*[Gt]\*[Gt]\*[Gt]\*[Am]0 leshort 0x184 for DEC Alpha
.Ed
.Pp
Indirect and relative offsets can be combined:
.Bd -literal -offset indent
.Bd -literal -offset indent
0 string MZ
>0x18 leshort <0x40
>>(4.s*512) leshort !0x014c MZ executable (MS-DOS)
\*[Gt]0x18 leshort \*[Lt]0x40
\*[Gt]\*[Gt](4.s*512) leshort !0x014c MZ executable (MS-DOS)
# if it's not COFF, go back 512 bytes and add the offset taken
# from byte 2/3, which is yet another way of finding the start
# of the extended executable
>>>&(2.s-514) string LE LE executable (MS Windows VxD driver)
\*[Gt]\*[Gt]\*[Gt]\*[Am](2.s-514) string LE LE executable (MS Windows VxD driver)
.Ed
.Pp
Or the other way around:
.Bd -literal -offset indent
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string LE\e0\e0 LE executable (MS-Windows)
\*[Gt]0x18 leshort \*[Gt]0x3f
\*[Gt]\*[Gt](0x3c.l) string LE\e0\e0 LE executable (MS-Windows)
# at offset 0x80 (-4, since relative offsets start at the end
# of the up-level match) inside the LE header, we find the absolute
# offset to the code area, where we look for a specific signature
>>>(&0x7c.l+0x26) string UPX \eb, UPX compressed
\*[Gt]\*[Gt]\*[Gt](\*[Am]0x7c.l+0x26) string UPX \eb, UPX compressed
.Ed
.Pp
Or even both!
.Bd -literal -offset indent
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string LE\e0\e0 LE executable (MS-Windows)
\*[Gt]0x18 leshort \*[Gt]0x3f
\*[Gt]\*[Gt](0x3c.l) string LE\e0\e0 LE executable (MS-Windows)
# at offset 0x58 inside the LE header, we find the relative offset
# to a data area where we look for a specific signature
>>>&(&0x54.l-3) string UNACE \eb, ACE self-extracting archive
\*[Gt]\*[Gt]\*[Gt]\*[Am](\*[Am]0x54.l-3) string UNACE \eb, ACE self-extracting archive
.Ed
.Pp
Finally, if you have to deal with offset/length pairs in your file, even the
second value in a parenthesized expression can be taken from the file itself,
using another set of parentheses. Note that this additional indirect offset
is always relative to the start of the main indirect offset.
.Bd -literal -offset indent
using another set of parentheses.
Note that this additional indirect offset is always relative to the
start of the main indirect offset.
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
\*[Gt]0x18 leshort \*[Gt]0x3f
\*[Gt]\*[Gt](0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
# search for the PE section called ".idata"...
>>>&0xf4 search/0x140 .idata
\*[Gt]\*[Gt]\*[Gt]\*[Am]0xf4 search/0x140 .idata
# ...and go to the end of it, calculated from start+length;
# these are located 14 and 10 bytes after the section name
>>>>(&0xe.l+(-4)) string PK\e3\e4 \eb, ZIP self-extracting archive
\*[Gt]\*[Gt]\*[Gt]\*[Gt](\*[Am]0xe.l+(-4)) string PK\e3\e4 \eb, ZIP self-extracting archive
.Ed
.Sh SEE ALSO
.Xr file 1
\- the command that reads this file.
.Sh BUGS
The formats
.Dv long ,
@ -432,9 +439,6 @@ are system-dependent; perhaps they should be specified as a number
of bytes (2B, 4B, etc),
since the files being recognized typically come from
a system on which the lengths are invariant.
.Sh SEE ALSO
.Xr file 1
\- the command that reads this file.
.\"
.\" From: guy@sun.uucp (Guy Harris)
.\" Newsgroups: net.bugs.usg
@ -448,4 +452,4 @@ a system on which the lengths are invariant.
.\" the changes I posted to the S5R2 version.
.\"
.\" Modified for Ian Darwin's version of the file command.
.\" @(#)Id: magic.man,v 1.37 2007/01/12 17:38:27 christos Exp
.\" @(#)Id: magic.man,v 1.38 2007/01/27 00:52:08 ljt Exp

11
dist/file/file2netbsd vendored
View File

@ -1,6 +1,6 @@
#! /bin/sh
#
# $NetBSD: file2netbsd,v 1.16 2007/03/04 15:22:08 pooka Exp $
# $NetBSD: file2netbsd,v 1.17 2007/06/07 11:32:45 pooka Exp $
#
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
@ -41,7 +41,7 @@
#
# edit this
file_vers='4.20'
file_vers='4.21'
#
# (usually) NO NEED TO EDIT BELOW THIS LINE
@ -111,10 +111,7 @@ wq' | ed Makefile.in > /dev/null 2>&1
echo done
echo You can import now.
echo Path: src/dist/file
echo Vendor: CHRISTOS
echo Versiontag: FILE4_XY
echo You can import now. Use the following command:
echo cvs import src/dist/file CHRISTOS FILE${file_vers%.*}_${file_vers#*.}
exit 0

View File

@ -722,3 +722,11 @@
>14 byte 0x54 end slice
>14 beshort 0x4e4e multi-part
>14 beshort 0x4e53 multi-part, with -S
# Symbian installation files
# http://www.thouky.co.uk/software/psifs/sis.html
# http://developer.symbian.com/main/downloads/papers/SymbianOSv91/softwareinstallsis.pdf
8 lelong 0x10000419 Symbian installation file
>4 lelong 0x1000006D (EPOC release 3/4/5)
>4 lelong 0x10003A12 (EPOC release 6)
0 lelong 0x10201A7A Symbian installation file (Symbian OS 9.x)

View File

@ -552,3 +552,7 @@
# http://download.ncl.ie/doc/api/ie/ncl/media/music/IMelody.html
# http://www.wx800.com/msg/download/irda/iMelody.pdf
0 string BEGIN:IMELODY iMelody Ringtone Format
# From: Matthew Flaschen <matthew.flaschen@gatech.edu>
0 string #EXTM3U M3U playlist text

View File

@ -1185,15 +1185,28 @@
>>>>>>>>&0 bedate =0 full dump
>>>>>>>>&0 bedate !0 incremental since: %s
#----------------------------------------------------------
# VMS backup savesets - gerardo.cacciari@gmail.com
# had to comment out GEM Image and G3 raw data entries due to conflict
#0 byte x
#>(0.s+16) string \x01\x01
#>>&(&0.b+8) byte 0x42 OpenVMS backup saveset data
#>>>40 lelong x (block size %d
#>>>49 string >\0 original name '%s')
#
4 string \x01\x00\x01\x00\x01\x00
>(0.s+16) string \x01\x01
>>&(&0.b+8) byte 0x42 OpenVMS backup saveset data
>>>40 lelong x (block size %d,
>>>49 string >\0 original name '%s',
>>>2 short 1024 VAX generated)
>>>2 short 2048 AXP generated)
>>>2 short 4096 I64 generated)
# Compaq/HP RILOE floppy image
# From: Dirk Jagdmann <doj@cubic.org>
0 string CPQRFBLO Compaq/HP RILOE floppy image
#------------------------------------------------------------------------------
# Files-11 On-Disk Structure (OpenVMS file system) - gerardo.cacciari@gmail.com
# These bits come from LBN 1 (home block) of ODS-2 and ODS-5 volumes, which is
# mapped to VBN 2 of [000000]INDEXF.SYS;1
#
1008 string DECFILE11B Files-11 On-Disk Structure
>525 byte x Level %d
>525 byte x (ODS-%d OpenVMS file system),
>984 string x volume label is '%-12.12s'

View File

@ -14,6 +14,10 @@
# OS/2 batch files are REXX. the second regex is a bit generic, oh well
# the matched commands seem to be common in REXX and uncommon elsewhere
100 regex/c =^[\ \t]{0,10}call[\ \t]{1,10}rxfunc OS/2 REXX batch file text
100 regex/c =^[\ \t]{0,10}say\ ['"] OS/2 REXX batch file text
100 regex/c =^\\s*call\\s+rxfuncadd.*sysloadfu OS/2 REXX batch file text
100 regex/c =^\\s*say\ ['"] OS/2 REXX batch file text
@ -558,6 +562,9 @@
# Outlook Personal Folders
0 lelong 0x4E444221 Microsoft Outlook binary email folder
>10 leshort 0x0e (Outlook <=2002)
>10 leshort 0x17 (Outlook >=2003)
# From: Dirk Jagdmann <doj@cubic.org>
0 lelong 0x00035f3f Windows 3.x help file

View File

@ -951,3 +951,7 @@
#
128 string DICM application/dicom
# Symbian installation files
8 lelong 0x10000419 application/vnd.symbian.install
0 lelong 0x10201A7A x-epoc/x-sisx-app

View File

@ -1,4 +1,4 @@
/* $NetBSD: apprentice.c,v 1.15 2007/05/16 20:53:49 christos Exp $ */
/* $NetBSD: apprentice.c,v 1.16 2007/06/07 11:32:46 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -49,9 +49,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: apprentice.c,v 1.104 2007/01/19 19:54:39 christos Exp $")
FILE_RCSID("@(#)$File: apprentice.c,v 1.105 2007/05/16 20:51:40 christos Exp $")
#else
__RCSID("$NetBSD: apprentice.c,v 1.15 2007/05/16 20:53:49 christos Exp $");
__RCSID("$NetBSD: apprentice.c,v 1.16 2007/06/07 11:32:46 pooka Exp $");
#endif
#endif /* lint */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ascmagic.c,v 1.5 2007/03/04 15:22:09 pooka Exp $ */
/* $NetBSD: ascmagic.c,v 1.6 2007/06/07 11:32:46 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -52,9 +52,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: ascmagic.c,v 1.49 2007/01/25 21:05:46 christos Exp $")
FILE_RCSID("@(#)$File: ascmagic.c,v 1.50 2007/03/15 14:51:00 christos Exp $")
#else
__RCSID("$NetBSD: ascmagic.c,v 1.5 2007/03/04 15:22:09 pooka Exp $");
__RCSID("$NetBSD: ascmagic.c,v 1.6 2007/06/07 11:32:46 pooka Exp $");
#endif
#endif /* lint */
@ -173,7 +173,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
* I believe Plan 9 troff allows non-ASCII characters in the names
* of macros, so this test might possibly fail on such a file.
*/
if ((ms->flags & MAGIC_NO_CHECK_TROFF) != 0 && *ubuf == '.') {
if ((ms->flags & MAGIC_NO_CHECK_TROFF) == 0 && *ubuf == '.') {
unichar *tp = ubuf + 1;
while (ISSPC(*tp))
@ -190,7 +190,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
}
}
if ((ms->flags & MAGIC_NO_CHECK_FORTRAN) &&
if ((ms->flags & MAGIC_NO_CHECK_FORTRAN) == 0 &&
(*buf == 'c' || *buf == 'C') && ISSPC(buf[1])) {
subtype_mime = "text/fortran";
subtype = "fortran program";

View File

@ -1,4 +1,4 @@
/* $NetBSD: compress.c,v 1.6 2007/03/04 15:25:10 pooka Exp $ */
/* $NetBSD: compress.c,v 1.7 2007/06/07 11:32:46 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -58,9 +58,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: compress.c,v 1.50 2007/03/01 22:14:54 christos Exp $")
FILE_RCSID("@(#)$File: compress.c,v 1.51 2007/03/05 02:41:29 christos Exp $")
#else
__RCSID("$NetBSD: compress.c,v 1.6 2007/03/04 15:25:10 pooka Exp $");
__RCSID("$NetBSD: compress.c,v 1.7 2007/06/07 11:32:46 pooka Exp $");
#endif
#endif

18
dist/file/src/file.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: file.c,v 1.17 2007/03/04 15:22:10 pooka Exp $ */
/* $NetBSD: file.c,v 1.18 2007/06/07 11:32:46 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -74,9 +74,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: file.c,v 1.107 2007/01/25 21:05:46 christos Exp $")
FILE_RCSID("@(#)$File: file.c,v 1.111 2007/05/08 14:44:18 christos Exp $")
#else
__RCSID("$NetBSD: file.c,v 1.17 2007/03/04 15:22:10 pooka Exp $");
__RCSID("$NetBSD: file.c,v 1.18 2007/06/07 11:32:46 pooka Exp $");
#endif
#endif /* lint */
@ -134,7 +134,7 @@ main(int argc, char *argv[])
char *home, *usermagic;
struct stat sb;
static const char hmagic[] = "/.magic";
#define OPTSTRING "bcCdf:F:hikLm:nNprsvz0"
#define OPTSTRING "bcCde:f:F:hikLm:nNprsvz0"
#ifdef HAVE_GETOPT_LONG
int longindex;
static const struct option long_options[] =
@ -144,7 +144,7 @@ main(int argc, char *argv[])
{"brief", 0, 0, 'b'},
{"checking-printout", 0, 0, 'c'},
{"debug", 0, 0, 'd'},
{"exclude", 0, 0, 'e' },
{"exclude", 1, 0, 'e' },
{"files-from", 1, 0, 'f'},
{"separator", 1, 0, 'F'},
{"mime", 0, 0, 'i'},
@ -364,9 +364,9 @@ main(int argc, char *argv[])
private void
/*ARGSUSED*/
load(const char *m __unused, int flags)
load(const char *m, int flags)
{
if (magic)
if (magic || m == NULL)
return;
magic = magic_open(flags);
if (magic == NULL) {
@ -582,8 +582,12 @@ help(void)
" -r, --raw don't translate unprintable chars to \\ooo\n"
" -s, --special-files treat special (block/char devices) files as\n"
" ordinary ones\n"
"or\n"
" --help display this help and exit\n"
"or\n"
" --version output version information and exit\n"
"or\n"
" -C, --compile compile file specified by -m\n"
);
exit(0);
}

14
dist/file/src/file.h vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: file.h,v 1.14 2007/03/04 15:22:10 pooka Exp $ */
/* $NetBSD: file.h,v 1.15 2007/06/07 11:32:46 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -29,7 +29,7 @@
*/
/*
* file.h - definitions for file(1) program
* @(#)$File: file.h,v 1.89 2007/03/01 22:14:54 christos Exp $
* @(#)$File: file.h,v 1.91 2007/03/25 03:13:47 christos Exp $
*/
#ifndef __file_h__
@ -85,14 +85,6 @@
#endif
#endif
#ifndef __unused
#if __GNUC_PREREQ__(2, 7)
#define __unused __attribute__((__unused__))
#else
#define __unused /* delete */
#endif
#endif
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
@ -338,9 +330,7 @@ protected void file_showstr(FILE *, const char *, size_t);
protected size_t file_mbswidth(const char *);
protected const char *file_getbuffer(struct magic_set *);
protected ssize_t sread(int, void *, size_t, int);
#ifdef ENABLE_CONDITIONALS
protected int file_check_mem(struct magic_set *, unsigned int);
#endif
#ifndef COMPILE_ONLY
extern const char *file_names[];

44
dist/file/src/funcs.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: funcs.c,v 1.7 2007/03/04 15:22:10 pooka Exp $ */
/* $NetBSD: funcs.c,v 1.8 2007/06/07 11:32:46 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -28,7 +28,6 @@
*/
#include "file.h"
#include "magic.h"
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@ -39,12 +38,22 @@
#if defined(HAVE_WCTYPE_H)
#include <wctype.h>
#endif
#if defined(HAVE_LIMITS_H)
#include <limits.h>
#endif
#ifndef SIZE_T_MAX
#ifdef __LP64__
#define SIZE_T_MAX (size_t)0xfffffffffffffffffU
#else
#define SIZE_T_MAX (size_t)0xffffffffU
#endif
#endif
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: funcs.c,v 1.28 2007/03/01 22:14:54 christos Exp $")
FILE_RCSID("@(#)$File: funcs.c,v 1.32 2007/05/24 17:22:27 christos Exp $")
#else
__RCSID("$NetBSD: funcs.c,v 1.7 2007/03/04 15:22:10 pooka Exp $");
__RCSID("$NetBSD: funcs.c,v 1.8 2007/06/07 11:32:46 pooka Exp $");
#endif
#endif /* lint */
@ -225,6 +234,7 @@ file_reset(struct magic_set *ms)
return -1;
}
ms->o.ptr = ms->o.buf;
ms->o.left = ms->o.size;
ms->haderr = 0;
ms->error = -1;
return 0;
@ -252,8 +262,11 @@ file_getbuffer(struct magic_set *ms)
len = ms->o.size - ms->o.left;
/* * 4 is for octal representation, + 1 is for NUL */
if (len > (SIZE_T_MAX - 1) / 4) {
file_oomem(ms, len);
return NULL;
}
psize = len * 4 + 1;
assert(psize > len);
if (ms->o.psize < psize) {
if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
file_oomem(ms, psize);
@ -313,6 +326,27 @@ file_getbuffer(struct magic_set *ms)
return ms->o.pbuf;
}
protected int
file_check_mem(struct magic_set *ms, unsigned int level)
{
size_t len;
if (level >= ms->c.len) {
len = (ms->c.len += 20) * sizeof(*ms->c.li);
ms->c.li = (ms->c.li == NULL) ? malloc(len) :
realloc(ms->c.li, len);
if (ms->c.li == NULL) {
file_oomem(ms, len);
return -1;
}
}
ms->c.li[level].got_match = 0;
#ifdef ENABLE_CONDITIONALS
ms->c.li[level].last_match = 0;
ms->c.li[level].last_cond = COND_NONE;
#endif /* ENABLE_CONDITIONALS */
return 0;
}
/*
* Yes these wrappers suffer from buffer overflows, but if your OS does not
* have the real functions, maybe you should consider replacing your OS?

10
dist/file/src/magic.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: magic.c,v 1.16 2007/03/04 15:22:10 pooka Exp $ */
/* $NetBSD: magic.c,v 1.17 2007/06/07 11:32:46 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -66,9 +66,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: magic.c,v 1.40 2007/03/01 22:14:55 christos Exp $")
FILE_RCSID("@(#)$File: magic.c,v 1.41 2007/03/26 17:59:50 christos Exp $")
#else
__RCSID("$NetBSD: magic.c,v 1.16 2007/03/04 15:22:10 pooka Exp $");
__RCSID("$NetBSD: magic.c,v 1.17 2007/06/07 11:32:46 pooka Exp $");
#endif
#endif /* lint */
@ -92,7 +92,7 @@ magic_open(int flags)
{
struct magic_set *ms;
if ((ms = malloc(sizeof(struct magic_set))) == NULL)
if ((ms = calloc((size_t)1, sizeof(struct magic_set))) == NULL)
return NULL;
if (magic_setflags(ms, flags) == -1) {
@ -115,6 +115,8 @@ magic_open(int flags)
ms->haderr = 0;
ms->error = -1;
ms->mlist = NULL;
ms->file = "unknown";
ms->line = 0;
return ms;
free3:
free(ms->o.pbuf);

View File

@ -1,4 +1,4 @@
/* $NetBSD: names.h,v 1.4 2007/03/04 15:22:10 pooka Exp $ */
/* $NetBSD: names.h,v 1.5 2007/06/07 11:32:47 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -34,7 +34,7 @@
* appear at fixed offsets into the file. Don't make HOWMANY
* too high unless you have a very fast CPU.
*
* $File: names.h,v 1.26 2007/01/12 17:38:28 christos Exp $
* $File: names.h,v 1.27 2007/05/08 16:47:03 christos Exp $
*/
/*
@ -169,6 +169,8 @@ static struct names {
{".text", L_MACH},
{"clr", L_MACH},
{"(input,", L_PAS},
{"program", L_PAS},
{"record", L_PAS},
{"dcl", L_PLI},
{"Received:", L_MAIL},
{">From", L_MAIL},

View File

@ -1,13 +1,16 @@
/* $NetBSD: patchlevel.h,v 1.6 2007/03/04 15:22:10 pooka Exp $ */
/* $NetBSD: patchlevel.h,v 1.7 2007/06/07 11:32:47 pooka Exp $ */
#define FILE_VERSION_MAJOR 4
#define patchlevel 20
#define patchlevel 21
/*
* Patchlevel file for Ian Darwin's MAGIC command.
* $File: patchlevel.h,v 1.64 2007/03/01 22:14:55 christos Exp $
* $File: patchlevel.h,v 1.65 2007/05/24 17:22:27 christos Exp $
*
* Log: patchlevel.h,v
* Revision 1.65 2007/05/24 17:22:27 christos
* Welcome to 4.21
*
* Revision 1.64 2007/03/01 22:14:55 christos
* welcome to 4.20
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: print.c,v 1.7 2007/03/04 21:50:43 pooka Exp $ */
/* $NetBSD: print.c,v 1.8 2007/06/07 11:32:47 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -44,9 +44,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: print.c,v 1.58 2007/01/16 14:58:48 ljt Exp $")
FILE_RCSID("@(#)$File: print.c,v 1.59 2007/03/05 02:41:29 christos Exp $")
#else
__RCSID("$NetBSD: print.c,v 1.7 2007/03/04 21:50:43 pooka Exp $");
__RCSID("$NetBSD: print.c,v 1.8 2007/06/07 11:32:47 pooka Exp $");
#endif
#endif /* lint */

View File

@ -1,4 +1,4 @@
/* $NetBSD: softmagic.c,v 1.8 2007/03/04 15:22:10 pooka Exp $ */
/* $NetBSD: softmagic.c,v 1.9 2007/06/07 11:32:47 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -41,9 +41,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: softmagic.c,v 1.91 2007/01/18 05:29:33 ljt Exp $")
FILE_RCSID("@(#)$File: softmagic.c,v 1.99 2007/05/08 14:44:18 christos Exp $")
#else
__RCSID("$NetBSD: softmagic.c,v 1.8 2007/03/04 15:22:10 pooka Exp $");
__RCSID("$NetBSD: softmagic.c,v 1.9 2007/06/07 11:32:47 pooka Exp $");
#endif
#endif /* lint */
@ -80,32 +80,6 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
return 0;
}
#ifdef ENABLE_CONDITIONALS
protected int
#else
private int
#endif
file_check_mem(struct magic_set *ms, unsigned int level)
{
size_t len;
if (level >= ms->c.len) {
len = (ms->c.len += 20) * sizeof(*ms->c.li);
ms->c.li = (ms->c.li == NULL) ? malloc(len) :
realloc(ms->c.li, len);
if (ms->c.li == NULL) {
file_oomem(ms, len);
return -1;
}
}
ms->c.li[level].got_match = 0;
#ifdef ENABLE_CONDITIONALS
ms->c.li[level].last_match = 0;
ms->c.li[level].last_cond = COND_NONE;
#endif /* ENABLE_CONDITIONALS */
return 0;
}
/*
* Go through the whole list, stopping if you find a match. Process all
* the continuations of that match before returning.
@ -1529,10 +1503,20 @@ magiccheck(struct magic_set *ms, struct magic *m)
}
else {
regmatch_t pmatch[1];
#ifndef REG_STARTEND
#define REG_STARTEND 0
size_t l = ms->search.s_len - 1;
char c = ms->search.s[l];
((char *)(intptr_t)ms->search.s)[l] = '\0';
#else
pmatch[0].rm_so = 0;
pmatch[0].rm_eo = ms->search.s_len;
#endif
rc = regexec(&rx, (const char *)ms->search.s,
1, pmatch, REG_STARTEND);
#if REG_STARTEND == 0
((char *)(intptr_t)ms->search.s)[l] = c;
#endif
switch (rc) {
case 0:
ms->search.s += (int)pmatch[0].rm_so;