apply conflict therapy for 4.20 import

This commit is contained in:
pooka 2007-03-04 15:22:07 +00:00
parent 5b23251544
commit 17dbe768ca
36 changed files with 2448 additions and 1490 deletions

View File

@ -1,4 +1,4 @@
Id: LEGAL.NOTICE,v 1.15 2006/05/03 18:48:33 christos Exp
$File: LEGAL.NOTICE,v 1.15 2006/05/03 18:48:33 christos Exp $
Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
Software written by Ian F. Darwin and others;
maintained 1994- Christos Zoulas.

12
dist/file/MAINT vendored
View File

@ -1,20 +1,10 @@
Id: MAINT,v 1.7 2006/06/01 18:19:41 ian Exp
$File: MAINT,v 1.9 2007/01/19 21:15:27 christos Exp $
Maintenance notes:
I am continuing to maintain the file command. I welcome your help,
but to make my life easier I'd like to request the following:
- Don't change the version numbers!
If your changes are extensive, I will have to work hard to
integrate them into my version. If you check it into SCCS locally,
the version numbers will likely be kept. IF you check it into RCS
or CVS locally, please use -k to keep the version numbers, and
please use branch deltas (1.21.1, 1.21.2, ...). If you don't do
this, I will likely be unable to use your changes; life's just too
short.
- Do not distribute changed versions.
People trying to be helpful occasionally put up their hacked versions

2
dist/file/README vendored
View File

@ -1,5 +1,5 @@
** README for file(1) Command **
@(#) Id: README,v 1.34 2006/05/03 18:48:33 christos Exp
@(#) $File: README,v 1.34 2006/05/03 18:48:33 christos Exp $
This is Release 4.x of Ian Darwin's (copyright but distributable)
file(1) command. This version is the standard "file" command for Linux,

View File

@ -1,5 +1,5 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* $NetBSD: config.h.in,v 1.11 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: config.h.in,v 1.12 2007/03/04 15:22:07 pooka Exp $ */
/* Autoheader needs me */
#undef PACKAGE
@ -128,6 +128,9 @@
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strndup' function. */
#undef HAVE_STRNDUP
/* Define to 1 if you have the `strtoul' function. */
#undef HAVE_STRTOUL
@ -144,6 +147,9 @@
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H

8
dist/file/configure vendored
View File

@ -1808,7 +1808,7 @@ fi
# Define the identity of the package.
PACKAGE=file
VERSION=4.18
VERSION=4.20
cat >>confdefs.h <<_ACEOF
@ -20823,7 +20823,8 @@ done
for ac_header in sys/mman.h sys/stat.h sys/types.h sys/utime.h
for ac_header in sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
@ -22612,7 +22613,8 @@ _ACEOF
for ac_func in mmap strerror strtoul mbrtowc mkstemp getopt_long utimes utime wcwidth snprintf vsnprintf
for ac_func in mmap strerror strndup strtoul mbrtowc mkstemp getopt_long utimes utime wcwidth snprintf vsnprintf
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5

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.18)
AM_INIT_AUTOMAKE(file, 4.20)
AM_CONFIG_HEADER([config.h])
AM_MAINTAINER_MODE
@ -81,7 +81,7 @@ 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(sys/mman.h sys/stat.h sys/types.h sys/utime.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.
AC_C_CONST
@ -119,7 +119,7 @@ AC_CHECK_SIZEOF_STDC_HEADERS(uint32_t, 0)
AC_CHECK_SIZEOF_STDC_HEADERS(uint64_t, 0)
dnl Checks for functions
AC_CHECK_FUNCS(mmap strerror strtoul mbrtowc mkstemp getopt_long utimes utime wcwidth snprintf vsnprintf)
AC_CHECK_FUNCS(mmap strerror strndup strtoul mbrtowc mkstemp getopt_long utimes utime wcwidth snprintf vsnprintf)
dnl Checks for libraries
AC_CHECK_LIB(z,gzopen)

583
dist/file/doc/file.1 vendored
View File

@ -1,80 +1,75 @@
.\" $NetBSD: file.1,v 1.13 2006/10/31 21:16:23 pooka Exp $
.\" $NetBSD: file.1,v 1.14 2007/03/04 15:22:08 pooka Exp $
.\"
.TH FILE 1 "Copyright but distributable"
.\" Id: file.man,v 1.58 2006/05/03 19:20:25 christos Exp
.SH NAME
file
\- determine file type
.SH SYNOPSIS
.B file
[
.B \-bchikLnNprsvz
]
[
.B \-f
.I namefile
]
[
.B \-F
.I separator
]
[
.B \-m
.I magicfiles
]
.I file
\&...
.br
.B file
.B -C
[
.B \-m
magicfile ]
.SH DESCRIPTION
This manual page documents version 4.18 of the
.B file
.\" $File: file.man,v 1.65 2007/01/25 21:05:46 christos Exp $
.Dd January 8, 2007
.Dt FILE 1
.Os
.Sh NAME
.Nm file
.Nd determine file type
.Sh SYNOPSIS
.Nm
.Op Fl bchikLnNprsvz
.Op Fl f Ar namefile
.Op Fl F Ar separator
.Op Fl m Ar magicfiles
.Ar file
.Nm
.Fl C
.Op Fl m Ar magicfile
.Sh DESCRIPTION
This manual page documents version 4.20 of the
.Nm
command.
.PP
.B File
.Pp
.Nm
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
.Em first
test that succeeds causes the file type to be printed.
.PP
.Pp
The type printed will usually contain one of the words
.B text
.Em text
(the file contains only
printing characters and a few common control
characters and is probably safe to read on an
.SM ASCII
.Dv ASCII
terminal),
.B executable
.Em executable
(the file contains the result of compiling a program
in a form understandable to some \s-1UNIX\s0 kernel or another),
in a form understandable to some
.Dv UNIX
kernel or another),
or
.B data
meaning anything else (data is usually `binary' or non-printable).
.Em data
meaning anything else (data is usually
.Sq 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 /usr/share/misc/magic
or the program itself,
.B "preserve these keywords" .
.Pa /usr/share/misc/magic
or the program itself, make sure to
.Em "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 and change ``shell commands text''
to ``shell script''.
have the word
.Dq text
printed.
Don't do as Berkeley did and change
.Dq shell commands text
to
.Dq shell script .
Note that the file
.I /usr/share/misc/magic
.Pa /usr/share/misc/magic
is built mechanically from a large number of small files in
the subdirectory
.I Magdir
.Pa Magdir
in the source distribution of this program.
.PP
.Pp
The filesystem tests are based on examining the return from a
.BR stat (2)
.Xr stat 2
system call.
The program checks to see if the file is empty,
or if it's some sort of special file.
@ -83,36 +78,42 @@ Any known file types appropriate to the system you are running on
implement them)
are intuited if they are defined in
the system header file
.IR <sys/stat.h> .
.PP
.In 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
.Dv a.out
file, whose format is defined in
.I a.out.h
.In elf.h ,
.In a.out.h
and possibly
.I exec.h
.In 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
These files have a
.Sq "magic number"
stored in a particular place
near the beginning of the file that tells the
.Dv UNIX 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.
The concept of a
.Sq "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 identifying these files is read from the compiled
magic file
.I /usr/share/misc/magic.mgc ,
.Pa /usr/share/misc/magic.mgc ,
or
.I /usr/share/misc/magic
.Pa /usr/share/misc/magic
if the compile file does not exist. In addition
.B file
.Nm
will look in
.I $HOME/.magic.mgc ,
.Pa $HOME/.magic.mgc ,
or
.I $HOME/.magic
.Pa $HOME/.magic
for magic entries.
.PP
.Pp
If a file does not match any of the entries in the magic file,
it is examined to see if it seems to be a text file.
ASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets
@ -123,204 +124,241 @@ ranges and sequences of bytes that constitute printable text
in each set.
If a file passes any of these tests, its character set is reported.
ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified
as ``text'' because they will be mostly readable on nearly any terminal;
UTF-16 and EBCDIC are only ``character data'' because, while
as
.Dq text
because they will be mostly readable on nearly any terminal;
UTF-16 and EBCDIC are only
.Dq character data
because, while
they contain text, it is text that will require translation
before it can be read.
In addition,
.B file
.Nm
will attempt to determine other characteristics of text-type files.
If the lines of a file are terminated by CR, CRLF, or NEL, instead
of the Unix-standard LF, this will be reported.
Files that contain embedded escape sequences or overstriking
will also be identified.
.PP
.Pp
Once
.B file
.Nm
has determined the character set used in a text-type file,
it will
attempt to determine in what language the file is written.
The language tests look for particular strings (cf
.IR names.h )
.In names.h
that can appear anywhere in the first few blocks of a file.
For example, the keyword
.B .br
.Em .br
indicates that the file is most likely a
.BR troff (1)
.Xr troff 1
input file, just as the keyword
.B struct
.Em 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)
.Xr tar 1
archives).
.PP
.Pp
Any file that cannot be identified as having been written
in any of the character sets listed above is simply said to be ``data''.
.SH OPTIONS
.TP 8
.B "\-b, \-\-brief"
.Sh OPTIONS
.Bl -tag -width indent
.It Fl b , -brief
Do not prepend filenames to output lines (brief mode).
.TP 8
.B "\-c, \-\-checking\-printout"
.It Fl c , -checking-printout
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 "\-C, \-\-compile"
Write a magic.mgc output file that contains a pre-parsed version of
file.
.TP 8
.BI "\-f, \-\-files\-from" " namefile"
This is usually used in conjunction with the
.Fl m
flag to debug a new magic file before installing it.
.It Fl C , -compile
Write a
.Pa magic.mgc
output file that contains a pre-parsed version of the magic file.
.It Fl e , -exclude Ar testname
Exclude the test named in
.Ar testname
from the list of tests made to determine the file type. Valid test names
are:
.Bl -tag -width
.It apptype
Check for
.Dv EMX
application type (only on EMX).
.It ascii
Check for various types of ascii files.
.It compress
Don't look for, or inside compressed files.
.It elf
Don't print elf details.
.It fortran
Don't look for fortran sequences inside ascii files.
.It soft
Don't consult magic files.
.It tar
Don't examine tar files.
.It token
Don't look for known tokens inside ascii files.
.It troff
Don't look for troff sequences inside ascii files.
.El
.It Fl f , -files-from Ar namefile
Read the names of the files to be examined from
.I namefile
.Ar namefile
(one per line)
before the argument list.
Either
.I namefile
.Ar namefile
or at least one filename argument must be present;
to test the standard input, use ``\-'' as a filename argument.
.TP 8
.BI "\-F, \-\-separator" " separator"
to test the standard input, use
.Sq -
as a filename argument.
.It Fl F , -separator Ar separator
Use the specified string as the separator between the filename and the
file result returned. Defaults to ``:''.
.TP 8
.B "\-h, \-\-no-dereference"
file result returned. Defaults to
.Sq \&: .
.It Fl h , -no-dereference
option causes symlinks not to be followed
(on systems that support symbolic links). This is the default if the
environment variable
.I POSIXLY_CORRECT
.Dv POSIXLY_CORRECT
is not defined.
.TP 8
.B "\-i, \-\-mime"
.It Fl i , -mime
Causes the file command to output mime type strings rather than the more
traditional human readable ones. Thus it may say
``text/plain; charset=us-ascii''
.Dq text/plain; charset=us-ascii
rather
than ``ASCII text''.
than
.Dq ASCII text .
In order for this option to work, file changes the way
it handles files recognized by the command itself (such as many of the
text file types, directories etc), and makes use of an alternative
``magic'' file.
(See ``FILES'' section, below).
.TP 8
.B "\-k, \-\-keep\-going"
.Dq magic
file.
(See
.Dq FILES
section, below).
.It Fl k , -keep-going
Don't stop at the first match, keep going.
.TP 8
.B "\-L, \-\-dereference"
.It Fl L , -dereference
option causes symlinks to be followed, as the like-named option in
.BR ls (1)
.Xr ls 1
(on systems that support symbolic links).
This is the default if the environment variable
.I POSIXLY_CORRECT
.Dv POSIXLY_CORRECT
is defined.
.TP 8
.BI "\-m, \-\-magic\-file" " list"
.It Fl m , -magic-file Ar list
Specify an alternate list of files containing magic numbers.
This can be a single file, or a colon-separated list of files.
If a compiled magic file is found alongside, it will be used instead.
With the \-i or \-\-mime option, the program adds ".mime" to each file name.
.TP 8
.B "\-n, \-\-no\-buffer"
With the
.Fl i or
.Fl "mime"
option, the program adds
.Dq .mime
to each file name.
.It Fl n , -no-buffer
Force stdout to be flushed after checking each file.
This is only useful if checking a list of files.
It is intended to be used by programs that want filetype output from a pipe.
.TP 8
.B "\-N, \-\-no\-pad"
.It Fl N , -no-pad
Don't pad filenames so that they align in the output.
.TP 8
.B "\-p, \-\-preserve\-date"
.It Fl p , -preserve-date
On systems that support
.BR utime (2)
.Xr utime 2
or
.BR utimes(2),
.Xr utimes 2 ,
attempt to preserve the access time of files analyzed, to pretend that
.BR file (2)
.Nm
never read them.
.TP 8
.B "\-r, \-\-raw"
.It Fl r , -raw
Don't translate unprintable characters to \eooo.
Normally
.B file
.Nm
translates unprintable characters to their octal representation.
.TP 8
.B "\-s, \-\-special\-files"
.It Fl s , -special-files
Normally,
.B file
.Nm
only attempts to read and determine the type of argument files which
.BR stat (2)
.Xr stat 2
reports are ordinary files.
This prevents problems, because reading special files may have peculiar
consequences.
Specifying the
.BR \-s
.Fl s
option causes
.B file
.Nm
to also read argument files which are block or character special files.
This is useful for determining the filesystem types of the data in raw
disk partitions, which are block special files.
This option also causes
.B file
.Nm
to disregard the file size as reported by
.BR stat (2)
.Xr stat 2
since on some systems it reports a zero size for raw disk partitions.
.TP 8
.B "\-v, \-\-version"
.It Fl v , -version
Print the version of the program and exit.
.TP 8
.B "\-z, \-\-uncompress"
.It Fl z , -uncompress
Try to look inside compressed files.
.TP 8
.B "\-\-help"
.It Fl 0 , -print0
Output a null character
.Sq \e0
after the end of the filename. Nice to
.Xr cut 1
the output. This does not affect the separator which is still printed.
.It Fl -help
Print a help message and exit.
.SH FILES
.TP
.I /usr/share/misc/magic.mgc
.El
.Sh FILES
.Bl -tag -width /usr/share/misc/magic.mime.mgc -compact
.It Pa /usr/share/misc/magic.mgc
Default compiled list of magic numbers
.TP
.I /usr/share/misc/magic
.It Pa /usr/share/misc/magic
Default list of magic numbers
.TP
.I /usr/share/misc/magic.mime.mgc
.It Pa /usr/share/misc/magic.mime.mgc
Default compiled list of magic numbers, used to output mime types when
the -i option is specified.
.TP
.I /usr/share/misc/magic.mime
Default list of magic numbers, used to output mime types when the -i option
is specified.
.SH ENVIRONMENT
the
.Fl i
option is specified.
.It Pa /usr/share/misc/magic.mime
Default list of magic numbers, used to output mime types when the
.Fl i
option is specified.
.El
.Sh ENVIRONMENT
The environment variable
.B MAGIC
.Dv MAGIC
can be used to set the default magic number file name.
If that variable is set, then
.B file
.Nm
will not attempt to open
.B $HOME/.magic .
.B file
adds ".mime" and/or ".mgc" to the value of this variable as appropriate.
.Pa $HOME/.magic .
.Nm
adds
.Dq .mime
and/or
.Dq .mgc
to the value of this variable as appropriate.
The environment variable
.B POSIXLY_CORRECT
.Dv POSIXLY_CORRECT
controls (on systems that support symbolic links), if
.B file
.Nm
will attempt to follow symlinks or not. If set, then
.B file
.Nm
follows symlink, otherwise it does not. This is also controlled
by the
.B L
.Fl L
and
.B h
.Fl h
options.
.SH SEE ALSO
.BR magic (5)
\- description of magic file format.
.br
.BR strings (1), " od" (1), " hexdump(1)"
\- tools for examining non-textfiles.
.SH STANDARDS CONFORMANCE
.Sh SEE ALSO
.Xr magic 5 ,
.Xr strings 1 ,
.Xr od 1 ,
.Xr hexdump 1
.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.
@ -328,69 +366,68 @@ Its behavior 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.
.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
.PP
.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
.Bd -literal -offset indent
>10 string language impress\ (imPRESS data)
.br
.Ed
.Pp
in an existing magic file would have to be changed to
.br
.Bd -literal -offset indent
>10 string language\e impress (imPRESS data)
.br
.Ed
.Pp
In addition, in this version, if a pattern string contains a backslash,
it must be escaped.
For example
.br
.Bd -literal -offset indent
0 string \ebegindata Andrew Toolkit document
.br
.Ed
.Pp
in an existing magic file would have to be changed to
.br
.Bd -literal -offset indent
0 string \e\ebegindata Andrew Toolkit document
.br
.PP
.Ed
.Pp
SunOS releases 3.2 and later from Sun Microsystems include a
.BR file (1)
.Nm
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,
It includes the extension of the
.Sq &
operator, used as,
for example,
.br
.Bd -literal -offset indent
>16 long&0x7fffffff >0 not stripped
.SH MAGIC DIRECTORY
.Ed
.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
.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
.Nm
command uses a magic file,
keep the old magic file around for comparison purposes
(rename it to
.IR /usr/share/misc/magic.orig ).
.SH EXAMPLES
.nf
.Pa /usr/share/misc/magic.orig ).
.Sh EXAMPLES
.Bd -literal -offset indent
$ file file.c obj/file /dev/wd0a
file.c: ASCII C program text
.fi
.na
obj/file: ELF 32-bit LSB executable,
Intel 80386,
version 1 (SYSV),
for NetBSD,
dynamically linked (uses shared libs),
not stripped
.br
.nf
file.c: C program text
obj/file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
for NetBSD 4.99.12, dynamically linked (uses shared libs),
not stripped
/dev/wd0a: block special (0/0)
# file -s /dev/rwd0[abe]
@ -412,125 +449,143 @@ minimum percentage of free blocks 5,
rotational delay 0ms,
disk rotational speed 60rps,
TIME optimization
.ad
.SH HISTORY
.Ed
.Sh HISTORY
There has been a
.B file
command in every \s-1UNIX\s0 since at least Research Version 4
.Nm
command in every
.Dv UNIX since at least Research Version 4
(man page dated November, 1973).
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
.Pp
This program, based on the System V version,
was written by Ian Darwin <ian@darwinsys.com>
without looking at anybody else's source code.
.PP
.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.
Contributions by the `&' operator by Rob McMahon, cudcv@warwick.ac.uk, 1989.
.PP
.Pp
Guy Harris, guy@netapp.com, made many changes from 1993 to the present.
.PP
.Pp
Primary development and maintenance from 1990 to the present by
Christos Zoulas (christos@astron.com).
.PP
.Pp
Altered by Chris Lowth, chris@lowth.com, 2000:
Handle the ``-i'' option to output mime type strings and using an alternative
Handle the
.Fl i
option to output mime type strings and using an alternative
magic file and internal logic.
.PP
.Pp
Altered by Eric Fischer (enf@pobox.com), July, 2000,
to identify character codes and attempt to identify the languages
of non-ASCII files.
.PP
.Pp
The list of contributors to the "Magdir" directory (source for the
.I /usr/share/misc/magic
.Pa /usr/share/misc/magic
file) is too long to include here.
You know who you are; thank you.
.SH LEGAL NOTICE
.Sh LEGAL NOTICE
Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
Covered by the standard Berkeley Software Distribution copyright; see the file
LEGAL.NOTICE in the source distribution.
.PP
.Pp
The files
.I tar.h
.Dv tar.h
and
.I is_tar.c
.Dv is_tar.c
were written by John Gilmore from his public-domain
.B tar
.Xr tar 1
program, and are not covered by the above license.
.SH BUGS
.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
.\" Compilation support has been done
.\" Better yet, the magic file should be compiled into binary (say,
.\" .Xr ndbm 3
.\" or, better yet, fixed-length
.\" .Dv 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
.Nm
uses several algorithms that favor speed over accuracy,
thus it can be misled about the contents of
text
files.
.PP
The support for
text
files (primarily for programming languages)
.Pp
The support for text 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.
.\" Else support has been done
.\" There should be an
.\" .Dv else
.\" clause to follow a series of continuation lines.
.\" .Pp
.\" Regular expression support has been done
.\" The magic file and keywords should have regular expression support.
Their use of
.SM "ASCII TAB"
.Dv ASCII TAB
as a field delimiter is ugly and makes
it hard to edit the files, but is entrenched.
.PP
.Pp
It might be advisable to allow upper-case letters in keywords
for e.g.,
.BR troff (1)
.Xr 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
.Pp
The program doesn't grok
.Dv FORTRAN .
It should be able to figure
.Dv FORTRAN
by seeing some keywords which
appear indented at the start of line.
Regular expression support would make this easy.
.PP
.Pp
The list of keywords in
.I ascmagic
.Dv ascmagic
probably belongs in the Magic file.
This could be done by using some keyword like `*' for the offset value.
.PP
Another optimization 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.
This could be done by using some keyword like
.Sq *
for the offset value.
.Pp
.\" Sorting has been done.
.\" Another optimization 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
.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:'').
of
.Dq how good
a guess is.
We end up removing guesses (e.g.
.Dq From\
as first 5 chars of file) because
they are not as good as other guesses (e.g.
.Dq Newsgroups:
versus
.Dq Return-Path:
).
Still, if the others don't pan out, it should be possible to use the
first guess.
.PP
.Pp
This program is slower than some vendors' file commands.
The new support for multiple character codes makes it even slower.
.PP
.Pp
This manual page, and particularly this section, is too long.
.SH AVAILABILITY
.Sh AVAILABILITY
You can obtain the original author's latest version by anonymous FTP
on
.B ftp.astron.com
.Dv ftp.astron.com
in the directory
.I /pub/file/file-X.YZ.tar.gz
.Dv /pub/file/file-X.YZ.tar.gz

View File

@ -1,4 +1,4 @@
.\" $NetBSD: libmagic.3,v 1.6 2006/10/31 21:17:15 pooka Exp $
.\" $NetBSD: libmagic.3,v 1.7 2007/03/04 15:22:08 pooka Exp $
.\"
.\" Copyright (c) Christos Zoulas 2003.
.\" All Rights Reserved.
@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd March 22, 2003
.Dd November 15, 2006
.Dt MAGIC 3
.Os
.Sh NAME
@ -105,6 +105,26 @@ Don't translate unprintable characters to a \eooo octal representation.
.It Dv MAGIC_ERROR
Treat operating system errors while trying to open files and follow symlinks
as real errors, instead of printing them in the magic buffer.
.It Dv MAGIC_NO_CHECK_APPTYPE
Check for
.Dv EMX
application type (only on EMX).
.It Dv MAGIC_NO_CHECK_ASCII
Check for various types of ascii files.
.It Dv MAGIC_NO_CHECK_COMPRESS
Don't look for, or inside compressed files.
.It Dv MAGIC_NO_CHECK_ELF
Don't print elf details.
.It Dv MAGIC_NO_CHECK_FORTRAN
Don't look for fortran sequences inside ascii files.
.It Dv MAGIC_NO_CHECK_SOFT
Don't consult magic files.
.It Dv MAGIC_NO_CHECK_TAR
Don't examine tar files.
.It Dv MAGIC_NO_CHECK_TOKENS
Don't look for known tokens inside ascii files.
.It Dv MAGIC_NO_CHECK_TROFF
Don't look for troff sequences inside ascii files.
.El
.Pp
The

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

@ -1,415 +1,439 @@
.\" $NetBSD: magic.5,v 1.13 2006/10/31 21:16:23 pooka Exp $
.\" $NetBSD: magic.5,v 1.14 2007/03/04 15:22:08 pooka Exp $
.\"
.TH MAGIC 5 "Public Domain"
.\" $File: magic.man,v 1.36 2007/01/10 22:56:49 christos Exp $
.Dd January 10, 2007
.Dt MAGIC 5
.Os
.\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
.SH NAME
magic \- file command's magic number file
.SH DESCRIPTION
.Sh NAME
.Nm magic
.Nd file command's magic number file
.Sh DESCRIPTION
This manual page documents the format of the magic file as
used by the
.BR file (1)
command, version 4.18.
.Xr file 1
command, version 4.20.
The
.BR file
.Xr file 1
command identifies the type of a file using,
among other tests,
a test for whether the file begins with a certain
.IR "magic number" .
.Dq "magic number" .
The file
.I /usr/share/misc/magic
.Pa /usr/share/misc/magic
specifies what magic numbers are to be tested for,
what message to print if a particular magic number is found,
and additional information to extract from the file.
.PP
.Pp
Each line of the file specifies a test to be performed.
A test compares the data starting at a particular offset
in the file with a 1-byte, 2-byte, or 4-byte numeric value or
a string.
If the test succeeds, a message is printed.
The line consists of the following fields:
.IP offset \w'message'u+2n
.Bl -tag -width ".Dv message"
.It Dv offset
A number specifying the offset, in bytes, into the file of the data
which is to be tested.
.IP type
.It Dv type
The type of the data to be tested.
The possible values are:
.RS
.IP byte \w'message'u+2n
.Bl -tag -width ".Dv lestring16"
.It Dv byte
A one-byte value.
.IP short
.It Dv short
A two-byte value (on most systems) in this machine's native byte order.
.IP long
.It Dv long
A four-byte value (on most systems) in this machine's native byte order.
.IP quad
.It Dv quad
An eight-byte value (on most systems) in this machine's native byte order.
.IP string
.It Dv string
A string of bytes.
The string type specification can be optionally followed
by /[Bbc]*.
The ``B'' flag compacts whitespace in the target, which must
The
.Dq B
flag compacts whitespace in the target, which must
contain at least one whitespace character.
If the magic has
.I n
.Dv n
consecutive blanks, the target needs at least
.I n
.Dv n
consecutive blanks to match.
The ``b'' flag treats every blank in the target as an optional blank.
Finally the ``c'' flag, specifies case insensitive matching: lowercase
The
.Dq b
flag treats every blank in the target as an optional blank.
Finally the
.Dq c
flag, specifies case insensitive matching: lowercase
characters in the magic match both lower and upper case characters in the
targer, whereas upper case characters in the magic, only much uppercase
characters in the target.
.IP pstring
.It Dv pstring
A pascal style string where the first byte is interpreted as the an
unsigned length. The string is not NUL terminated.
.IP date
.It Dv date
A four-byte value interpreted as a UNIX date.
.IP qdate
.It Dv qdate
A eight-byte value interpreted as a UNIX date.
.IP ldate
.It Dv ldate
A four-byte value interpreted as a UNIX-style date, but interpreted as
local time rather than UTC.
.IP qldate
.It Dv qldate
An eight-byte value interpreted as a UNIX-style date, but interpreted as
local time rather than UTC.
.IP beshort
.It Dv beshort
A two-byte value (on most systems) in big-endian byte order.
.IP belong
.It Dv belong
A four-byte value (on most systems) in big-endian byte order.
.IP bequad
.It Dv bequad
An eight-byte value (on most systems) in big-endian byte order.
.IP bedate
.It Dv bedate
A four-byte value (on most systems) in big-endian byte order,
interpreted as a Unix date.
.IP beqdate
.It Dv beqdate
An eight-byte value (on most systems) in big-endian byte order,
interpreted as a Unix date.
.IP beldate
.It Dv beldate
A four-byte value (on most systems) in big-endian byte order,
interpreted as a UNIX-style date, but interpreted as local time rather
than UTC.
.IP beqldate
.It Dv beqldate
An eight-byte value (on most systems) in big-endian byte order,
interpreted as a UNIX-style date, but interpreted as local time rather
than UTC.
.IP bestring16
.It Dv bestring16
A two-byte unicode (UCS16) string in big-endian byte order.
.IP leshort
.It Dv leshort
A two-byte value (on most systems) in little-endian byte order.
.IP lelong
.It Dv lelong
A four-byte value (on most systems) in little-endian byte order.
.IP lequad
.It Dv lequad
An eight-byte value (on most systems) in little-endian byte order.
.IP ledate
.It Dv ledate
A four-byte value (on most systems) in little-endian byte order,
interpreted as a UNIX date.
.IP leqdate
.It Dv leqdate
An eight-byte value (on most systems) in little-endian byte order,
interpreted as a UNIX date.
.IP leldate
.It Dv leldate
A four-byte value (on most systems) in little-endian byte order,
interpreted as a UNIX-style date, but interpreted as local time rather
than UTC.
.IP leqldate
.It Dv leqldate
An eight-byte value (on most systems) in little-endian byte order,
interpreted as a UNIX-style date, but interpreted as local time rather
than UTC.
.IP lestring16
.It Dv lestring16
A two-byte unicode (UCS16) string in little-endian byte order.
.IP melong
.It Dv melong
A four-byte value (on most systems) in middle-endian (PDP-11) byte order.
.IP medate
.It Dv medate
A four-byte value (on most systems) in middle-endian (PDP-11) byte order,
interpreted as a UNIX date.
.IP meldate
.It Dv meldate
A four-byte value (on most systems) in middle-endian (PDP-11) byte order,
interpreted as a UNIX-style date, but interpreted as local time rather
than UTC.
.IP regex
.It Dv regex
A regular expression match in extended POSIX regular expression syntax
(much like egrep).
The type specification can be optionally followed by
.B /c
for case-insensitive matches.
The regular expression is always
tested against the first
.B N
The type specification can be optionally followed by /[cse]*.
The
.Dq c
flag makes the match case insensitive, while the
.Dq s
or
.Dq e
flags update the offset to the starting or ending offsets of the
match (only one should be used).
By default, regex does not update the offset.
The regular expression is always tested against the first
.Dv N
lines, where
.B N
.Dv N
is the given offset, thus it
is only useful for (single-byte encoded) text.
.B ^
.Dv ^
and
.B $
.Dv $
will match the beginning and end of individual lines, respectively,
not beginning and end of file.
.IP search
.It Dv search
A literal string search starting at the given offset. It must be followed by
.B /<number>
.Dv /<number>
which specifies how many matches shall be attempted (the range).
This is suitable for searching larger binary expressions with variable
offsets, using
.B \e
.Dv \e
escapes for special characters.
.RE
.PP
.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
no other matches.
.El
.El
.Pp
The numeric types may optionally be followed by
.B &
.Dv &
and a numeric value,
to specify that the value is to be AND'ed with the
numeric value before any comparisons are done.
Prepending a
.B u
.Dv u
to the type indicates that ordered comparisons should be unsigned.
.IP test
.Bl -tag -width ".Dv message"
.It Dv test
The value to be compared with the value from the file.
If the type is
numeric, this value
is specified in C form; if it is a string, it is specified as a C string
with the usual escapes permitted (e.g. \en for new-line).
.IP
.Pp
Numeric values
may be preceded by a character indicating the operation to be performed.
It may be
.BR = ,
.Dv = ,
to specify that the value from the file must equal the specified value,
.BR < ,
.Dv < ,
to specify that the value from the file must be less than the specified
value,
.BR > ,
.Dv > ,
to specify that the value from the file must be greater than the specified
value,
.BR & ,
.Dv & ,
to specify that the value from the file must have set all of the bits
that are set in the specified value,
.BR ^ ,
.Dv ^ ,
to specify that the value from the file must have clear any of the bits
that are set in the specified value, or
.BR ~ ,
.Dv ~ ,
the value specified after is negated before tested.
.BR x ,
.Dv x ,
to specify that any value will match.
If the character is omitted, it is assumed to be
.BR = .
.Dv = .
For all tests except
.B string
.Em string
and
.B regex,
.Em regex,
operation
.BR !
.Dv !
specifies that the line matches if the test does
.B not
.Em not
succeed.
.IP
.Pp
Numeric values are specified in C form; e.g.
.B 13
.Dv 13
is decimal,
.B 013
.Dv 013
is octal, and
.B 0x13
.Dv 0x13
is hexadecimal.
.IP
.Pp
For string values, the byte string from the
file must match the specified byte string.
The operators
.BR = ,
.B <
.Dv = ,
.Dv <
and
.B >
.Dv >
(but not
.BR & )
.Dv & )
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
.B >\e0
.Em >\e0
(because all strings are greater than the null string).
.IP message
.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
.BR printf (3)
.Xr printf 3
format specification, the value from the file (with any specified masking
performed) is printed using the message as the format string.
.PP
If the string begins with ``\\b'', the message printed is the
remainder of the string with no whitespace added before it: multiple
matches are normally separated by a single space.
.El
.Pp
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
.B >
.Em >
characters preceding the offset.
The number of
.B >
.Em >
on the line indicates the level of the test; a line with no
.B >
.Em >
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
.IB n
.Em n
succeeds, all following tests at level
.IB n+1
.Em n+1
are performed, and the messages printed if the tests succeed, untile a line
with level
.IB n
.Em n
(or less) appears.
For more complex files, one can use empty messages to get just the
"if/then" effect, in the following way:
.sp
.nf
0 string MZ
>0x18 leshort <0x40 MS-DOS executable
>0x18 leshort >0x3f extended PC executable (e.g., MS Windows)
.fi
.PP
.Bd -literal -offset indent
0 string MZ
>0x18 leshort <0x40 MS-DOS executable
>0x18 leshort >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
.B >
.Em >
is a
.B (
.Em (
then the string after the parenthesis is interpreted as an indirect offset.
That means that the number after the parenthesis is used as an offset in
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:
.BI (( x [.[bslBSL]][+\-][ y ]).
.Em (( x [.[bslBSL]][+\-][ y ]).
The value of
.I x
.Em x
is used as an offset in the file. A byte, short or long is read at that offset
depending on the
.B [bslBSLm]
.Em [bslBSLm]
type specifier.
The capitalized types interpret the number as a big endian
value, whereas the small letter versions interpret the number as a little
endian value;
the
.B m
.Em m
type interprets the number as a middle endian (PDP-11) value.
To that number the value of
.I y
.Em y
is added and the result is used as an offset in the file.
The default type if one is not specified is long.
.PP
.Pp
That way variable length structures can be examined:
.sp
.nf
# MS Windows executables are also valid MS-DOS executables
0 string MZ
>0x18 leshort <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)
.fi
.PP
.Bd -literal -offset indent
# MS Windows executables are also valid MS-DOS executables
0 string MZ
>0x18 leshort <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)
.Ed
.Pp
This strategy of examining has one drawback: You must make sure that
you eventually print something, or users may get empty output (like, when
there is neither PE\e0\e0 nor LE\e0\e0 in the above example)
.PP
.Pp
If this indirect offset cannot be used as-is, there are simple calculations
possible: appending
.BI [+-*/%&|^]<number>
.Em [+-*/%&|^]<number>
inside parentheses allows one to modify
the value read from the file before it is used as an offset:
.sp
.nf
# 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)
.fi
.PP
.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)
.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
.BI &
.Sq &
as a prefix to the offset:
.sp
.nf
0 string MZ
>0x18 leshort >0x3f
>>(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
.fi
.PP
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(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
.Ed
.Pp
Indirect and relative offsets can be combined:
.sp
.nf
0 string MZ
>0x18 leshort <0x40
>>(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)
.fi
.PP
.Bd -literal -offset indent
0 string MZ
>0x18 leshort <0x40
>>(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)
.Ed
.Pp
Or the other way around:
.sp
.nf
0 string MZ
>0x18 leshort >0x3f
>>(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
.fi
.PP
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(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
.Ed
.Pp
Or even both!
.sp
.nf
0 string MZ
>0x18 leshort >0x3f
>>(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
.fi
.PP
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(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
.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.
.sp
.nf
0 string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
# search for the PE section called ".idata"...
>>>&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
.fi
.SH BUGS
.Bd -literal -offset indent
0 string MZ
>0x18 leshort >0x3f
>>(0x3c.l) string PE\e0\e0 PE executable (MS-Windows)
# search for the PE section called ".idata"...
>>>&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
.Ed
.Sh BUGS
The formats
.IR long ,
.IR belong ,
.IR lelong ,
.IR melong ,
.IR short ,
.IR beshort ,
.IR leshort ,
.IR date ,
.IR bedate ,
.IR medate ,
.IR ledate ,
.IR beldate ,
.IR leldate ,
.Dv long ,
.Dv belong ,
.Dv lelong ,
.Dv melong ,
.Dv short ,
.Dv beshort ,
.Dv leshort ,
.Dv date ,
.Dv bedate ,
.Dv medate ,
.Dv ledate ,
.Dv beldate ,
.Dv leldate ,
and
.I meldate
.Dv meldate
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
.BR file (1)
.Sh SEE ALSO
.Xr file 1
\- the command that reads this file.
.\"
.\" From: guy@sun.uucp (Guy Harris)
@ -424,4 +448,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.33 2006/10/31 19:37:16 christos Exp
.\" @(#)Id: magic.man,v 1.37 2007/01/12 17:38:27 christos Exp

View File

@ -1,6 +1,6 @@
#! /bin/sh
#
# $NetBSD: file2netbsd,v 1.15 2006/10/31 21:16:23 pooka Exp $
# $NetBSD: file2netbsd,v 1.16 2007/03/04 15:22:08 pooka Exp $
#
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
@ -41,7 +41,7 @@
#
# edit this
file_vers='4.18'
file_vers='4.20'
#
# (usually) NO NEED TO EDIT BELOW THIS LINE

View File

@ -336,6 +336,7 @@ Magdir/troff \
Magdir/tuxedo \
Magdir/typeset \
Magdir/unknown \
Magdir/unicode \
Magdir/uuencode \
Magdir/varied.out \
Magdir/varied.script \

View File

@ -478,7 +478,7 @@
0 string HPAK HPACK archive data
# JAM Archive volume format, by Dmitry.Kohmanyuk@UA.net
0 string \351,\001JAM\ JAM archive,
0 string \351,\001JAM\ JAM archive,
>7 string >\0 version %.4s
>0x26 byte =0x27 -
>>0x2b string >\0 label %.11s,

View File

@ -475,10 +475,6 @@
# From: Emanuel Haupt <ehaupt@critical.ch>
0 string ZXAYEMUL Spectrum 128 tune
# From: Alex Beregszaszi <alex@fsn.hu>
0 string MP+ Musepack
>3 byte&0x0f x SV%d
0 string \0BONK BONK,
#>5 byte x version %d
>14 byte x %d channel(s),
@ -504,13 +500,13 @@
# Since I saw only eqf files with version v1.1 I think that it's OK
>23 string x \b%.4s
# .preset
0 string \[Equalizer\ preset\] XMMS equalizer preset
0 string [Equalizer\ preset] XMMS equalizer preset
# .m3u
0 string \#EXTM3U M3U playlist
0 string #EXTM3U M3U playlist
# .pls
0 string \[playlist\] PLS playlist
0 string [playlist] PLS playlist
# licq.conf
1 string \[licq\] LICQ configuration file
1 string [licq] LICQ configuration file
# Atari ST audio files by Dirk Jagdmann <doj@cubic.org>
0 string ICE! SNDH Atari ST music
@ -549,3 +545,10 @@
>>27 byte 113 \b, Alpha 1.13
>>27 byte 114 \b, Beta 1.14
>>27 byte 115 \b, Alpha 1.15
# IMY
# from http://filext.com/detaillist.php?extdetail=IMY
# http://cellphones.about.com/od/cellularfaqs/f/rf_imelody.htm
# 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

View File

@ -53,4 +53,4 @@
0 string Zend\x00 PHP script Zend Optimizer data
0 string \$! DCL command file
0 string $! DCL command file

View File

@ -5,22 +5,25 @@
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
0774 beshort 0xdabe
# modified by Joerg Jenderek, because original test
# succeeds for Cabinet archive dao360.dl_ with negative blocks
>0770 long >0 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
# Joerg Jenderek: Smart Boot Manager backup file is 41 byte header + first sectors of disc
@ -100,75 +103,140 @@
>>96 string read\ error\ while\ reading\ drive \b, FREE-DOS Beta 0.9 MBR
>271 string Operating\ system\ loading
>>296 string error\r \b, SYSLINUX MBR (2.10)
# http://www.acronis.de/
>362 string MBR\ Error\ \0\r
>>376 string ress\ any\ key\ to\
>>>392 string boot\ from\ floppy...\0 \b, Acronis MBR
# added by Joerg Jenderek
# http://www.visopsys.org/
# http://partitionlogic.org.uk/
>309 string No\ bootable\ partition\ found\r
>>339 string I/O\ Error\ reading\ boot\ sector\r \b, Visopsys MBR
>349 string No\ bootable\ partition\ found\r
>>379 string I/O\ Error\ reading\ boot\ sector\r \b, simple Visopsys MBR
# bootloader, bootmanager
>43 string SMART\ BTMGRFAT12\ \ \
>>430 string SBMK\ Bad!\r
>>>3 string SBM \b, Smart Boot Manager
>>>>6 string >\0 \b, version %s
>0x40 string SBML
# label with 11 characters of FAT 12 bit filesystem
>>43 string SMART\ BTMGR
>>>430 string SBMK\ Bad!\r
>>>>3 string SBM \b, Smart Boot Manager
>>>>>6 string >\0 \b, version %s
>382 string XOSLLOADXCF \b, eXtended Operating System Loader
>6 string LILO \b, LInux i386 boot LOader
>>120 string LILO \b, version 22.3.4 SuSe
>>172 string LILO \b, version 22.5.8 Debian
>402 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>394 string stage1 \b, GRand Unified Bootloader (0.5.95)
>343 string Geom\0Read\0\ Error\0
>>321 string Loading\ stage1.5 \b, Grand Unified Bootloader
>380 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>374 string GRUB\ \0 \b, GRand Unified Bootloader
>382 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>376 string GRUB\ \0 \b, GRand Unified Bootloader (0.93)
>383 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>377 string GRUB\ \0 \b, GRand Unified Bootloader (0.94)
>385 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>379 string GRUB\ \0 \b, GRand Unified Bootloader (0.95)
# updated by Joerg Jenderek
# variables according to grub-0.97/stage1/stage1.S or
# http://www.gnu.org/software/grub/manual/grub.html#Embedded-data
# usual values are marked with comments to get only informations of strange GRUB loaders
>0 ulelong 0x009048EB
>>0x41 ubyte <2
>>>0x3E ubyte >2 \b; GRand Unified Bootloader
# 0x3 for 0.5.95,0.93,0.94,0.96 0x4 for 1.90
>>>>0x3E ubyte x \b, stage1 version 0x%x
#If it is 0xFF, use a drive passed by BIOS
>>>>0x40 ubyte <0xFF \b, boot drive 0x%x
# in most case 0,1,0x2e for GRUB 0.5.95
>>>>0x41 ubyte >0 \b, LBA flag 0x%x
>>>>0x42 uleshort <0x8000 \b, stage2 address 0x%x
#>>>>0x42 uleshort =0x8000 \b, stage2 address 0x%x (usual)
>>>>0x42 uleshort >0x8000 \b, stage2 address 0x%x
#>>>>0x44 ulelong =1 \b, 1st sector stage2 0x%x (default)
>>>>0x44 ulelong >1 \b, 1st sector stage2 0x%x
>>>>0x48 uleshort <0x800 \b, stage2 segment 0x%x
#>>>>0x48 uleshort =0x800 \b, stage2 segment 0x%x (usual)
>>>>0x48 uleshort >0x800 \b, stage2 segment 0x%x
>>>>402 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>>>>394 string stage1 \b, GRUB version 0.5.95
>>>>382 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>>>>376 string GRUB\ \0 \b, GRUB version 0.93 or 1.94
>>>>383 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>>>>377 string GRUB\ \0 \b, GRUB version 0.94
>>>>385 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>>>>379 string GRUB\ \0 \b, GRUB version 0.95 or 0.96
>>>>391 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>>>>385 string GRUB\ \0 \b, GRUB version 0.97
#unkown version
>>>343 string Geom\0Read\0\ Error\0
>>>>321 string Loading\ stage1.5 \b, GRUB version x.y
>>>380 string Geom\0Hard\ Disk\0Read\0\ Error\0
>>>>374 string GRUB\ \0 \b, GRUB version n.m
# http://syslinux.zytor.com/
>478 string Boot\ failed\r
>>495 string LDLINUX\ SYS \b, SYSLINUX bootloader (1.62)
>480 string Boot\ failed\r
>>495 string LDLINUX\ SYS \b, SYSLINUX bootloader (2.06)
>>495 string LDLINUX\ SYS \b, SYSLINUX bootloader (2.06 or 2.11)
>484 string Boot\ error\r \b, SYSLINUX bootloader (3.11)
>395 string chksum\0\ ERROR!\0 \b, Gujin bootloader
# mbr partion table entries, if not fat boot secor, activ flag 0 or 0x80 and type > 0
# http://www.bcdwb.de/bcdw/index_e.htm
>3 string BCDL
>>498 string BCDL\ \ \ \ BIN \b, Bootable CD Loader (1.50Z)
# mbr partion table entries
# OEM-ID not Microsoft,SYSLINUX,or MTOOLs
>3 string !MS
>>3 string !SYSLINUX
>>>82 string !FAT32
>>>>446 ubyte <0x81
>>>>>446 ubyte&0x7F 0
>>>>>>450 ubyte >0 \b; partition 1: ID=0x%x
>>>>>>>446 ubyte 0x80 \b, active
>>>>>>>447 ubyte x \b, starthead %u
#>>>>>>>448 ubyte x \b, start C_S: 0x%x
#>>>>>>448 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>454 ulelong x \b, startsector %u
>>>>>>>458 ulelong x \b, %u sectors
>>>3 string !MTOOL
# not FAT (32 bit)
>>>>82 string !FAT32
#not IO.SYS
>>>>>472 string !IO\ \ \ \ \ \ SYS
#not Linux kernel
>>>>>>514 string !HdrS
# active flag 0 or 0x80 and type > 0
>>>>>>>446 ubyte <0x81
>>>>>>>>446 ubyte&0x7F 0
>>>>>>>>>>>450 ubyte >0 \b; partition 1: ID=0x%x
>>>>>>>>>>446 ubyte 0x80 \b, active
>>>>>>>>>>447 ubyte x \b, starthead %u
#>>>>>>>>>>448 ubyte x \b, start C_S: 0x%x
#>>>>>>>>>>448 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>>>>454 ulelong x \b, startsector %u
>>>>>>>>>>458 ulelong x \b, %u sectors
#
>>>>462 ubyte <0x81
>>>>>462 ubyte&0x7F 0
>>>>>>466 ubyte >0 \b; partition 2: ID=0x%x
>>>>>>>462 ubyte 0x80 \b, active
>>>>>>>463 ubyte x \b, starthead %u
#>>>>>>>464 ubyte x \b, start C_S: 0x%x
#>>>>>>>464 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>470 ulelong x \b, startsector %u
>>>>>>>474 ulelong x \b, %u sectors
>>>>>>>462 ubyte <0x81
>>>>>>>>462 ubyte&0x7F 0
>>>>>>>>>466 ubyte >0 \b; partition 2: ID=0x%x
>>>>>>>>>>462 ubyte 0x80 \b, active
>>>>>>>>>>463 ubyte x \b, starthead %u
#>>>>>>>>>>464 ubyte x \b, start C_S: 0x%x
#>>>>>>>>>>464 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>>>>470 ulelong x \b, startsector %u
>>>>>>>>>>474 ulelong x \b, %u sectors
#
>>>>478 ubyte <0x81
>>>>>478 ubyte&0x7F 0
>>>>>>482 ubyte >0 \b; partition 3: ID=0x%x
>>>>>>>478 ubyte 0x80 \b, active
>>>>>>>479 ubyte x \b, starthead %u
#>>>>>>>480 ubyte x \b, start C_S: 0x%x
#>>>>>>>481 ubyte x \b, start C2S: 0x%x
#>>>>>>>480 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>486 ulelong x \b, startsector %u
>>>>>>>490 ulelong x \b, %u sectors
>>>>>>>478 ubyte <0x81
>>>>>>>>478 ubyte&0x7F 0
>>>>>>>>>482 ubyte >0 \b; partition 3: ID=0x%x
>>>>>>>>>>478 ubyte 0x80 \b, active
>>>>>>>>>>479 ubyte x \b, starthead %u
#>>>>>>>>>>480 ubyte x \b, start C_S: 0x%x
#>>>>>>>>>>481 ubyte x \b, start C2S: 0x%x
#>>>>>>>>>>480 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>>>>486 ulelong x \b, startsector %u
>>>>>>>>>>490 ulelong x \b, %u sectors
#
>>>>494 ubyte <0x81
>>>>>494 ubyte&0x7F 0
>>>>>>498 ubyte >0 \b; partition 4: ID=0x%x
>>>>>>>494 ubyte 0x80 \b, active
>>>>>>>495 ubyte x \b, starthead %u
#>>>>>>>496 ubyte x \b, start C_S: 0x%x
#>>>>>>>496 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>502 ulelong x \b, startsector %u
>>>>>>>506 ulelong x \b, %u sectors
>>>>>>>494 ubyte <0x81
>>>>>>>>494 ubyte&0x7F 0
>>>>>>>>>498 ubyte >0 \b; partition 4: ID=0x%x
>>>>>>>>>>494 ubyte 0x80 \b, active
>>>>>>>>>>495 ubyte x \b, starthead %u
#>>>>>>>>>>496 ubyte x \b, start C_S: 0x%x
#>>>>>>>>>>496 ubeshort&1023 x \b, startcylinder? %d
>>>>>>>>>>502 ulelong x \b, startsector %u
>>>>>>>>>>506 ulelong x \b, %u sectors
# mbr partion table entries end
# http://www.acronis.de/
#FAT label=ACRONIS\ SZ
#OEM-ID=BOOTWIZ0
>442 string Non-system\ disk,\
>>459 string press\ any\ key...\x7\0 \b, Acronis Startup Recovery Loader
# DOS names like F11.SYS are 8 right space padded bytes+3 bytes
>>>477 ubyte&0xDF >0
>>>>477 string x \b %-.3s
>>>>>480 ubyte&0xDF >0
>>>>>>480 string x \b%-.5s
>>>>485 ubyte&0xDF >0
>>>>>485 string x \b.%-.3s
#
>185 string FDBOOT\ Version\
>>204 string \rNo\ Systemdisk.\
>>>220 string Booting\ from\ harddisk.\n\r
@ -251,13 +319,12 @@
>>>>>>>422 string x \b%-.3s
>>>>>425 ubyte&0xDF >0
>>>>>>425 string >\ \b.%-.3s
#
>>>>368 ubyte&0xDF >0
>>>>>368 string x %-.5s
>>>>>>373 ubyte&0xDF >0
>>>>>>>373 string x \b%-.3s
>>>>>376 ubyte&0xDF >0
>>>>>>376 string x \b.%-.3s
# offset variant
>>>>379 string \0
>>>>>368 ubyte&0xDF >0
>>>>>>368 string x %-.5s
>>>>>>>373 ubyte&0xDF >0
>>>>>>>>373 string x \b%-.3s
#
>430 string NTLDR\ fehlt\xFF\r\n
>>444 string Datentr\204gerfehler\xFF\r\n
@ -528,6 +595,90 @@
>>>>>>>>504 string x \b%-.1s
>>>>505 ubyte&0xDF >0
>>>>>505 string x \b.%-.3s
# added by Joerg Jenderek
# http://www.visopsys.org/
# http://partitionlogic.org.uk/
# OEM-ID=Visopsys
>478 ulelong 0
>>(1.b+326) string I/O\ Error\ reading\
>>>(1.b+344) string Visopsys\ loader\r
>>>>(1.b+361) string Press\ any\ key\ to\ continue.\r \b, Visopsys loader
# http://alexfru.chat.ru/epm.html#bootprog
>494 ubyte >0x4D
>>495 string >E
>>>495 string <S
#OEM-ID is not reliable
>>>>3 string BootProg
# It just looks for a program file name at the root directory
# and loads corresponding file with following execution.
# DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes
>>>>499 ubyte&0xDF >0 \b, COM/EXE Bootloader
>>>>>499 string x \b %-.1s
>>>>>>500 ubyte&0xDF >0
>>>>>>>500 string x \b%-.1s
>>>>>>>>501 ubyte&0xDF >0
>>>>>>>>>501 string x \b%-.1s
>>>>>>>>>>502 ubyte&0xDF >0
>>>>>>>>>>>502 string x \b%-.1s
>>>>>>>>>>>>503 ubyte&0xDF >0
>>>>>>>>>>>>>503 string x \b%-.1s
>>>>>>>>>>>>>>504 ubyte&0xDF >0
>>>>>>>>>>>>>>>504 string x \b%-.1s
>>>>>>>>>>>>>>>>505 ubyte&0xDF >0
>>>>>>>>>>>>>>>>>505 string x \b%-.1s
>>>>>>>>>>>>>>>>>>506 ubyte&0xDF >0
>>>>>>>>>>>>>>>>>>>506 string x \b%-.1s
#name extension
>>>>>507 ubyte&0xDF >0 \b.
>>>>>>507 string x \b%-.1s
>>>>>>>508 ubyte&0xDF >0
>>>>>>>>508 string x \b%-.1s
>>>>>>>>>509 ubyte&0xDF >0
>>>>>>>>>>509 string x \b%-.1s
#If the boot sector fails to read any other sector,
#it prints a very short message ("RE") to the screen and hangs the computer.
#If the boot sector fails to find needed program in the root directory,
#it also hangs with another message ("NF").
>>>>>492 string RENF \b, FAT (12 bit)
>>>>>495 string RENF \b, FAT (16 bit)
# http://alexfru.chat.ru/epm.html#bootprog
>494 ubyte >0x4D
>>495 string >E
>>>495 string <S
#OEM-ID is not reliable
>>>>3 string BootProg
# It just looks for a program file name at the root directory
# and loads corresponding file with following execution.
# DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes
>>>>499 ubyte&0xDF >0 \b, COM/EXE Bootloader
>>>>>499 string x \b %-.1s
>>>>>>500 ubyte&0xDF >0
>>>>>>>500 string x \b%-.1s
>>>>>>>>501 ubyte&0xDF >0
>>>>>>>>>501 string x \b%-.1s
>>>>>>>>>>502 ubyte&0xDF >0
>>>>>>>>>>>502 string x \b%-.1s
>>>>>>>>>>>>503 ubyte&0xDF >0
>>>>>>>>>>>>>503 string x \b%-.1s
>>>>>>>>>>>>>>504 ubyte&0xDF >0
>>>>>>>>>>>>>>>504 string x \b%-.1s
>>>>>>>>>>>>>>>>505 ubyte&0xDF >0
>>>>>>>>>>>>>>>>>505 string x \b%-.1s
>>>>>>>>>>>>>>>>>>506 ubyte&0xDF >0
>>>>>>>>>>>>>>>>>>>506 string x \b%-.1s
#name extension
>>>>>507 ubyte&0xDF >0 \b.
>>>>>>507 string x \b%-.1s
>>>>>>>508 ubyte&0xDF >0
>>>>>>>>508 string x \b%-.1s
>>>>>>>>>509 ubyte&0xDF >0
>>>>>>>>>>509 string x \b%-.1s
#If the boot sector fails to read any other sector,
#it prints a very short message ("RE") to the screen and hangs the computer.
#If the boot sector fails to find needed program in the root directory,
#it also hangs with another message ("NF").
>>>>>492 string RENF \b, FAT (12 bit)
>>>>>495 string RENF \b, FAT (16 bit)
# loader end
# Joerg Jenderek
>446 ubyte 0
@ -658,6 +809,61 @@
0x18b string OS/2 OS/2 Boot Manager
# added by Joerg Jenderek
# In the second sector (+0x200) are variables according to grub-0.97/stage2/asm.S or
# grub-1.94/kern/i386/pc/startup.S
# http://www.gnu.org/software/grub/manual/grub.html#Embedded-data
# usual values are marked with comments to get only informations of strange GRUB loaders
0x200 uleshort 0x70EA
# found only version 3.{1,2}
>0x206 ubeshort >0x0300
# GRUB version (0.5.)95,0.93,0.94,0.96,0.97 > "00"
>>0x212 ubyte >0x29
>>>0x213 ubyte >0x29
# not iso9660_stage1_5
#>>>0 ulelong&0x00BE5652 0x00BE5652
>>>>0x213 ubyte >0x29 GRand Unified Bootloader
# config_file for stage1_5 is 0xffffffff + default "/boot/grub/stage2"
>>>>0x217 ubyte 0xFF stage1_5
>>>>0x217 ubyte <0xFF stage2
>>>>0x206 ubyte x \b version %u
>>>>0x207 ubyte x \b.%u
# module_size for 1.94
>>>>0x208 ulelong <0xffffff \b, installed partition %u
#>>>>0x208 ulelong =0xffffff \b, %u (default)
>>>>0x208 ulelong >0xffffff \b, installed partition %u
# GRUB 0.5.95 unofficial
>>>>0x20C ulelong&0x2E300000 0x2E300000
# 0=stage2 1=ffs 2=e2fs 3=fat 4=minix 5=reiserfs
>>>>>0x20C ubyte x \b, identifier 0x%x
#>>>>>0x20D ubyte =0 \b, LBA flag 0x%x (default)
>>>>>0x20D ubyte >0 \b, LBA flag 0x%x
# GRUB version as string
>>>>>0x20E string >\0 \b, GRUB version %-s
# for stage1_5 is 0xffffffff + config_file "/boot/grub/stage2" default
>>>>>>0x215 ulong 0xffffffff
>>>>>>>0x219 string >\0 \b, configuration file %-s
>>>>>>0x215 ulong !0xffffffff
>>>>>>>0x215 string >\0 \b, configuration file %-s
# newer GRUB versions
>>>>0x20C ulelong&0x2E300000 !0x2E300000
##>>>>>0x20C ulelong =0 \b, saved entry %d (usual)
>>>>>0x20C ulelong >0 \b, saved entry %d
# for 1.94 contains kernel image size
# for 0.93,0.94,0.96,0.97
# 0=stage2 1=ffs 2=e2fs 3=fat 4=minix 5=reiserfs 6=vstafs 7=jfs 8=xfs 9=iso9660 a=ufs2
>>>>>0x210 ubyte x \b, identifier 0x%x
# The flag for LBA forcing is in most cases 0
#>>>>>0x211 ubyte =0 \b, LBA flag 0x%x (default)
>>>>>0x211 ubyte >0 \b, LBA flag 0x%x
# GRUB version as string
>>>>>0x212 string >\0 \b, GRUB version %-s
# for stage1_5 is 0xffffffff + config_file "/boot/grub/stage2" default
>>>>>0x217 ulong 0xffffffff
>>>>>>0x21b string >\0 \b, configuration file %-s
>>>>>0x217 ulong !0xffffffff
>>>>>>0x217 string >\0 \b, configuration file %-s
9564 lelong 0x00011954 Unix Fast File system [v1] (little-endian),
>8404 string x last mounted on %s,
#>9504 ledate x last checked at %s,
@ -923,15 +1129,15 @@
0 string VoIP\ Startup\ and Aculab VoIP firmware
>35 string x format %s
# PPCBoot image file
# u-boot/PPCBoot image file
# From: Mark Brown <broonie@sirena.org.uk>
0 belong 0x27051956 PPCBoot image
0 belong 0x27051956 u-boot/PPCBoot image
>4 string PPCBoot
>>12 string x version %s
# JFFS2 file system
0 leshort 0x1984 Linux old jffs2 filesystem data little endian
0 lelong 0xe0011985 Linux jffs2 filesystem data little endian
0 leshort 0x1984 Linux old jffs2 filesystem data little endian
0 leshort 0x1985 Linux jffs2 filesystem data little endian
# Squashfs
0 string sqsh Squashfs filesystem, big endian,
@ -986,3 +1192,8 @@
#>>&(&0.b+8) byte 0x42 OpenVMS backup saveset data
#>>>40 lelong x (block size %d
#>>>49 string >\0 original name '%s')
# Compaq/HP RILOE floppy image
# From: Dirk Jagdmann <doj@cubic.org>
0 string CPQRFBLO Compaq/HP RILOE floppy image

View File

@ -14,7 +14,7 @@
# 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 =^\\s*call\s+rxfuncadd.*sysloadfu 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
0 leshort 0x14c MS Windows COFF Intel 80386 object file
@ -592,10 +592,16 @@
>>(64.l) lestring16 >0 Description: %15.15s
# From: Alex Beregszaszi <alex@fsn.hu>
0 string COWD VMWare3 disk image
>12 belong x %d bytes
0 string COWD VMWare3
>4 byte 3 disk image
>>32 lelong x (%d/
>>36 lelong x \b%d/
>>40 lelong x \b%d)
>4 byte 2 undoable disk image
>>32 string >\0 (%s)
0 string VMDK VMware4 disk image
0 string KDMV VMware4 disk image
0 belong 0x514649fb QEMU Copy-On-Write disk image
>4 belong x version %d,

View File

@ -13,10 +13,18 @@
0 string eval\ "exec\ /usr/local/bin/perl perl script text executable
0 string eval\ '(exit\ $?0)'\ &&\ eval\ 'exec perl script text
# a couple more, by me
# XXX: christos matches
#0 regex package Perl5 module source text (via regex)
0 string package Perl5 module source text
# by Dmitry V. Levin and Alexey Tourbin
# check the first line
0 string package
>1 regex \^package[\ \t]+[A-Za-z_]
>>1 regex \^package[\ \t]+[0-9A-Za-z_:]*\ *; Perl5 module source text
# not 'p', check other lines
0 byte !0x70
>0 regex \^package[\ \t]+[0-9A-Za-z_:]+\ *;
>>0 regex \^1\ *;|\^(use|sub|my)\ .*[(;{=] Perl5 module source text
# Perl POD documents
# From: Tom Hukins <tom@eborcom.com>

View File

@ -122,6 +122,7 @@
>>>>>>>(104.l+132) string/c iv50 Indeo 5.0
>>>>>>>(104.l+132) string/c mp42 Microsoft MPEG-4 v2
>>>>>>>(104.l+132) string/c mp43 Microsoft MPEG-4 v3
>>>>>>>(104.l+132) string/c fmp4 FFMpeg MPEG-4
>>>>>>>(104.l+132) string/c mjpg Motion JPEG
>>>>>>>(104.l+132) string/c div3 DivX 3
>>>>>>>>112 string/c div3 Low-Motion

View File

@ -99,9 +99,7 @@
# svg
0 string \<?xml
# text/xml
>38 string \<\!DOCTYPE\040svg image/svg+xml
38 string \<\!DOCTYPE\040svg image/svg+xml
# xml
@ -111,8 +109,8 @@
#------------------------------------------------------------------------------
# Java
0 short 0xcafe
>2 short 0xbabe application/java
0 beshort 0xcafe
>2 beshort 0xbabe application/java
#------------------------------------------------------------------------------
# audio: file(1) magic for sound formats
@ -135,7 +133,7 @@
# DEC systems (e.g. DECstation 5000) use a variant of the Sun/NeXT format
# that uses little-endian encoding and has a different magic number
# (0x0064732E in little-endian encoding).
0 lelong 0x0064732E
0 lelong 0x0064732E
>12 lelong 1 audio/x-dec-basic
>12 lelong 2 audio/x-dec-basic
>12 lelong 3 audio/x-dec-basic
@ -148,25 +146,25 @@
# Bytes 0-3 of AIFF, AIFF-C, & 8SVX audio files are "FORM"
# AIFF audio data
8 string AIFF audio/x-aiff
8 string AIFF audio/x-aiff
# AIFF-C audio data
8 string AIFC audio/x-aiff
8 string AIFC audio/x-aiff
# IFF/8SVX audio data
8 string 8SVX audio/x-aiff
8 string 8SVX audio/x-aiff
# Creative Labs AUDIO stuff
# Standard MIDI data
0 string MThd audio/unknown
0 string MThd audio/unknown
#>9 byte >0 (format %d)
#>11 byte >1 using %d channels
# Creative Music (CMF) data
0 string CTMF audio/unknown
0 string CTMF audio/unknown
# SoundBlaster instrument data
0 string SBI audio/unknown
0 string SBI audio/unknown
# Creative Labs voice data
0 string Creative\ Voice\ File audio/unknown
0 string Creative\ Voice\ File audio/unknown
## is this next line right? it came this way...
#>19 byte 0x1A
#>23 byte >0 - version %d
@ -195,7 +193,12 @@
0 beshort 0x4De1 audio/MP4A-LATM
# MPEG Layer 3 sound files
0 beshort &0xffe0 audio/mpeg
# modified by Joerg Jenderek
# GRR the original test are too common for many DOS files
# so test 1 <= kbits nibble <= E
0 beshort &0xffe0
>2 ubyte&0xF0 >0x0F
>>2 ubyte&0xF0 <0xE1 audio/mpeg
#MP3 with ID3 tag
0 string ID3 audio/mpeg
# Ogg/Vorbis
@ -408,10 +411,7 @@
0 string \<!-- text/html
0 string \<h1 text/html
0 string \<H1 text/html
0 string \<!doctype\ HTML text/html
0 string \<!DOCTYPE\ HTML text/html
0 string \<!doctype\ html text/html
0 string \<!doctype\ HTML text/html
0 string/c \<!doctype\ html text/html
#------------------------------------------------------------------------------
# images: file(1) magic for image formats (see also "c-lang" for XPM bitmaps)
@ -530,7 +530,11 @@
#
0 string \376\067\0\043 application/msword
0 string \320\317\021\340\241\261 application/msword
# disable this one because it applies also to other
# Office/OLE documents for which msword is not correct. See PR#2608.
# from magic file of the apache
#0 string \320\317\021\340\241\261 application/msword
512 string \354\245\301 application/msword
0 string \333\245-\0\0\0 application/msword
@ -566,7 +570,7 @@
#0 string \367\203 TeX generic font data
#0 string \367\131 TeX packed font data
#0 string \367\312 TeX virtual font data
#0 string This\ is\ TeX, TeX transcript text
#0 string This\ is\ TeX, TeX transcript text
#0 string This\ is\ METAFONT, METAFONT transcript text
# There is no way to detect TeX Font Metric (*.tfm) files without
@ -588,6 +592,14 @@
# RTF - Rich Text Format
0 string {\\rtf text/rtf
# TeX documents, from Daniel Quinlan (quinlan@yggdrasil.com)
0 search/400 \\input text/x-tex
0 search/400 \\section text/x-tex
0 search/400 \\setlength text/x-tex
0 search/400 \\documentstyle text/x-tex
0 search/400 \\chapter text/x-tex
0 search/400 \\documentclass text/x-tex
#------------------------------------------------------------------------------
# animation: file(1) magic for animation/movie formats
#
@ -603,7 +615,7 @@
0 belong 0x000001B3 video/mpv
0 belong&0xFF5FFF1F 0x47400010 video/mp2t
0 belong 0x00000001
>4 byte&1F 0x07 video/h264
>4 byte&0x1F 0x07 video/h264
# FLI animation format
0 leshort 0xAF11 video/fli
@ -658,7 +670,7 @@
#
# Executables
#
0 string \177ELF
0 string \177ELF
>16 leshort 0 application/octet-stream
>16 leshort 1 application/x-object
>16 leshort 2 application/x-executable
@ -675,9 +687,9 @@
#
# KDE
0 string [KDE\ Desktop\ Entry] application/x-kdelnk
0 string \#\ KDE\ Config\ File application/x-kdelnk
0 string #\ KDE\ Config\ File application/x-kdelnk
# xmcd database file for kscd
0 string \#\ xmcd text/xmcd
0 string #\ xmcd text/xmcd
#------------------------------------------------------------------------------
# pkgadd: file(1) magic for SysV R4 PKG Datastreams
@ -712,19 +724,19 @@
4 string Standard\ Jet\ DB application/msaccess
## magic for XBase files
#0 byte 0x02
#0 byte 0x02
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
#0 byte 0x03
#0 byte 0x03
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
#0 byte 0x04
#0 byte 0x04
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
#0 byte 0x05
#0 byte 0x05
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
@ -740,7 +752,7 @@
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
#0 byte 0x83
#0 byte 0x83
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
@ -748,7 +760,7 @@
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
#0 byte 0x8e
#0 byte 0x8e
#>8 leshort >0
#>>12 leshort 0 application/x-dbf
#
@ -769,7 +781,7 @@
0 beshort 0x9501 text/PGP key security ring
0 beshort 0x9500 text/PGP key security ring
0 beshort 0xa600 text/PGP encrypted data
0 string -----BEGIN\040PGP text/PGP armored data
0 string -----BEGIN\040PGP text/PGP armored data
>15 string PUBLIC\040KEY\040BLOCK- public key block
>15 string MESSAGE- message
>15 string SIGNED\040MESSAGE- signed message
@ -777,7 +789,7 @@
0 beshort 0x8501 data
#
# GnuPG Magic:
#
#
0 beshort 0x9901 text/GnuPG key public ring
0 beshort 0x8501 text/OpenPGP data
@ -787,7 +799,7 @@
#
# http://www.macromedia.com/software/flash/open/
#
0 string FWS
0 string FWS
>3 byte x application/x-shockwave-flash
# The following paramaters are created for Namazu.
@ -862,6 +874,8 @@
# miscellaneous formats
0 string LZ application/octet-stream
# DOS device drivers by Joerg Jenderek
0 belong 0xffffffff application/octet-stream
# .EXE formats (Greg Roelofs, newt@uchicago.edu)
#
@ -914,7 +928,7 @@
#0 string \000\000\001\000 image/x-ico
# Quark Xpress 3 Files:
# (made the mimetype up)
# (made the mimetype up)
0 string \0\0MMXPR3\0 application/x-quark-xpress-3
# EET archive
@ -924,3 +938,16 @@
# From: Denis Knauf, via gentoo.
0 string fLaC audio/x-flac
0 string CWS application/x-shockwave-flash
# Hangul Document Files:
# Reversed-engineered HWP magic numbers
# From: Won-Kyu Park <wkpark@kldp.org>
512 string R\0o\0o\0t\0 application/x-hwp
0 string/c BEGIN:VCARD text/x-vcard
0 string WordPro\0 application/vnd.lotus-wordpro
0 string WordPro\r\373 application/vnd.lotus-wordpro
0 string CPC\262 image/cpi
#
128 string DICM application/dicom

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: ascmagic.c,v 1.4 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: ascmagic.c,v 1.5 2007/03/04 15:22:09 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -52,9 +52,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: ascmagic.c,v 1.46 2006/10/20 21:04:15 christos Exp")
FILE_RCSID("@(#)$File: ascmagic.c,v 1.49 2007/01/25 21:05:46 christos Exp $")
#else
__RCSID("$NetBSD: ascmagic.c,v 1.4 2006/10/31 21:16:23 pooka Exp $");
__RCSID("$NetBSD: ascmagic.c,v 1.5 2007/03/04 15:22:09 pooka Exp $");
#endif
#endif /* lint */
@ -98,7 +98,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
int n_cr = 0;
int n_nel = 0;
int last_line_end = -1;
size_t last_line_end = (size_t)-1;
int has_long_lines = 0;
/*
@ -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 (*ubuf == '.') {
if ((ms->flags & MAGIC_NO_CHECK_TROFF) != 0 && *ubuf == '.') {
unichar *tp = ubuf + 1;
while (ISSPC(*tp))
@ -190,7 +190,8 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
}
}
if ((*buf == 'c' || *buf == 'C') && ISSPC(buf[1])) {
if ((ms->flags & MAGIC_NO_CHECK_FORTRAN) &&
(*buf == 'c' || *buf == 'C') && ISSPC(buf[1])) {
subtype_mime = "text/fortran";
subtype = "fortran program";
goto subtype_identified;
@ -198,6 +199,9 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
/* look for tokens from names.h - this is expensive! */
if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
goto subtype_identified;
i = 0;
while (i < ulen) {
size_t end;
@ -467,7 +471,7 @@ private int
looks_ascii(const unsigned char *buf, size_t nbytes, unichar *ubuf,
size_t *ulen)
{
int i;
size_t i;
*ulen = 0;
@ -486,7 +490,7 @@ looks_ascii(const unsigned char *buf, size_t nbytes, unichar *ubuf,
private int
looks_latin1(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
{
int i;
size_t i;
*ulen = 0;
@ -506,7 +510,7 @@ private int
looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
size_t *ulen)
{
int i;
size_t i;
*ulen = 0;
@ -525,7 +529,8 @@ looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
private int
looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
{
int i, n;
size_t i;
int n;
unichar c;
int gotone = 0;
@ -589,7 +594,7 @@ looks_unicode(const unsigned char *buf, size_t nbytes, unichar *ubuf,
size_t *ulen)
{
int bigend;
int i;
size_t i;
if (nbytes < 2)
return 0;
@ -708,7 +713,7 @@ private unsigned char ebcdic_1047_to_8859[] = {
private void
from_ebcdic(const unsigned char *buf, size_t nbytes, unsigned char *out)
{
int i;
size_t i;
for (i = 0; i < nbytes; i++) {
out[i] = ebcdic_to_ascii[buf[i]];

View File

@ -1,4 +1,4 @@
/* $NetBSD: compress.c,v 1.4 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: compress.c,v 1.5 2007/03/04 15:22:09 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -48,15 +48,19 @@
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif
#ifdef HAVE_LIBZ
#include <zlib.h>
#endif
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: compress.c,v 1.45 2006/10/31 19:37:17 christos Exp")
FILE_RCSID("@(#)$File: compress.c,v 1.50 2007/03/01 22:14:54 christos Exp $")
#else
__RCSID("$NetBSD: compress.c,v 1.4 2006/10/31 21:16:23 pooka Exp $");
__RCSID("$NetBSD: compress.c,v 1.5 2007/03/04 15:22:09 pooka Exp $");
#endif
#endif
@ -80,7 +84,7 @@ private struct {
{ "BZh", 3, { "bzip2", "-cd", NULL }, 1 }, /* bzip2-ed */
};
private int ncompr = sizeof(compr) / sizeof(compr[0]);
private size_t ncompr = sizeof(compr) / sizeof(compr[0]);
#define NODATA ((size_t)~0)
@ -94,8 +98,8 @@ private size_t uncompressgzipped(struct magic_set *, const unsigned char *,
#endif
protected int
file_zmagic(struct magic_set *ms, int fd, const unsigned char *buf,
size_t nbytes)
file_zmagic(struct magic_set *ms, int fd, const char *name,
const unsigned char *buf, size_t nbytes)
{
unsigned char *newbuf = NULL;
size_t i, nsz;
@ -112,11 +116,11 @@ file_zmagic(struct magic_set *ms, int fd, const unsigned char *buf,
nbytes)) != NODATA) {
ms->flags &= ~MAGIC_COMPRESS;
rv = -1;
if (file_buffer(ms, -1, newbuf, nsz) == -1)
if (file_buffer(ms, -1, name, newbuf, nsz) == -1)
goto error;
if (file_printf(ms, " (") == -1)
goto error;
if (file_buffer(ms, -1, buf, nbytes) == -1)
if (file_buffer(ms, -1, NULL, buf, nbytes) == -1)
goto error;
if (file_printf(ms, ")") == -1)
goto error;
@ -160,9 +164,9 @@ swrite(int fd, const void *buf, size_t n)
* `safe' read for sockets and pipes.
*/
protected ssize_t
sread(int fd, void *buf, size_t n)
sread(int fd, void *buf, size_t n, int canbepipe)
{
int rv;
int rv, cnt;
#ifdef FIONREAD
int t = 0;
#endif
@ -172,11 +176,12 @@ sread(int fd, void *buf, size_t n)
goto nocheck;
#ifdef FIONREAD
if ((ioctl(fd, FIONREAD, &t) < 0) || (t == 0)) {
if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1) || (t == 0)) {
#ifdef FD_ZERO
for (;;) {
for (cnt = 0;; cnt++) {
fd_set check;
struct timeval tout = {0, 100 * 1000};
int rv;
FD_ZERO(&check);
FD_SET(fd, &check);
@ -185,12 +190,14 @@ sread(int fd, void *buf, size_t n)
* Avoid soft deadlock: do not read if there
* is nothing to read from sockets and pipes.
*/
if (select(fd + 1, &check, NULL, NULL, &tout) <= 0) {
rv = select(fd + 1, &check, NULL, NULL, &tout);
if (rv == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;
} else if (rv == 0 && cnt >= 5) {
return 0;
}
break;
} else
break;
}
#endif
(void)ioctl(fd, FIONREAD, &t);
@ -251,7 +258,7 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
if (swrite(tfd, startbuf, nbytes) != (ssize_t)nbytes)
r = 1;
else {
while ((r = sread(fd, buf, sizeof(buf))) > 0)
while ((r = sread(fd, buf, sizeof(buf), 1)) > 0)
if (swrite(tfd, buf, (size_t)r) != r)
break;
}
@ -347,7 +354,7 @@ uncompressgzipped(struct magic_set *ms, const unsigned char *old,
}
n = (size_t)z.total_out;
inflateEnd(&z);
(void)inflateEnd(&z);
/* let's keep the nul-terminate tradition */
(*newch)[n] = '\0';
@ -395,8 +402,8 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
(void)close(2);
#endif
execvp(compr[method].argv[0],
(char *const *)(intptr_t)compr[method].argv);
(void)execvp(compr[method].argv[0],
(char *const *)(intptr_t)compr[method].argv);
#ifdef DEBUG
(void)fprintf(stderr, "exec `%s' failed (%s)\n",
compr[method].argv[0], strerror(errno));
@ -418,7 +425,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
switch (fork()) {
case 0: /* child */
(void)close(fdout[0]);
if (swrite(fdin[1], old, n) != n) {
if (swrite(fdin[1], old, n) != (ssize_t)n) {
#ifdef DEBUG
(void)fprintf(stderr,
"Write failed (%s)\n",
@ -452,7 +459,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
n = 0;
goto err;
}
if ((r = sread(fdout[0], *newch, HOWMANY)) <= 0) {
if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
#ifdef DEBUG
(void)fprintf(stderr, "Read failed (%s)\n",
strerror(errno));

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

@ -1,4 +1,4 @@
/* $NetBSD: file.c,v 1.16 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: file.c,v 1.17 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -74,9 +74,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: file.c,v 1.102 2006/06/02 00:07:58 ian Exp")
FILE_RCSID("@(#)$File: file.c,v 1.107 2007/01/25 21:05:46 christos Exp $")
#else
__RCSID("$NetBSD: file.c,v 1.16 2006/10/31 21:16:23 pooka Exp $");
__RCSID("$NetBSD: file.c,v 1.17 2007/03/04 15:22:10 pooka Exp $");
#endif
#endif /* lint */
@ -87,7 +87,7 @@ __RCSID("$NetBSD: file.c,v 1.16 2006/10/31 21:16:23 pooka Exp $");
#define SYMLINKFLAG ""
#endif
# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n"
# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n"
#ifndef MAXPATHLEN
#define MAXPATHLEN 512
@ -96,7 +96,8 @@ __RCSID("$NetBSD: file.c,v 1.16 2006/10/31 21:16:23 pooka Exp $");
private int /* Global command-line options */
bflag = 0, /* brief output format */
nopad = 0, /* Don't pad output */
nobuffer = 0; /* Do not buffer stdout */
nobuffer = 0, /* Do not buffer stdout */
nulsep = 0; /* Append '\0' to the separator */
private const char *magicfile = 0; /* where the magic is */
private const char *default_magicfile = MAGIC;
@ -127,13 +128,13 @@ private void load(const char *, int);
int
main(int argc, char *argv[])
{
int c;
int c, i;
int action = 0, didsomefiles = 0, errflg = 0;
int flags = 0;
char *home, *usermagic;
struct stat sb;
static const char hmagic[] = "/.magic";
#define OPTSTRING "bcCdf:F:hikLm:nNprsvz"
#define OPTSTRING "bcCdf:F:hikLm:nNprsvz0"
#ifdef HAVE_GETOPT_LONG
int longindex;
static const struct option long_options[] =
@ -143,6 +144,7 @@ main(int argc, char *argv[])
{"brief", 0, 0, 'b'},
{"checking-printout", 0, 0, 'c'},
{"debug", 0, 0, 'd'},
{"exclude", 0, 0, 'e' },
{"files-from", 1, 0, 'f'},
{"separator", 1, 0, 'F'},
{"mime", 0, 0, 'i'},
@ -161,10 +163,26 @@ main(int argc, char *argv[])
{"no-pad", 0, 0, 'N'},
{"special-files", 0, 0, 's'},
{"compile", 0, 0, 'C'},
{"print0", 0, 0, '0'},
{0, 0, 0, 0},
};
#endif
static const struct {
const char *name;
int value;
} nv[] = {
{ "apptype", MAGIC_NO_CHECK_APPTYPE },
{ "ascii", MAGIC_NO_CHECK_ASCII },
{ "compress", MAGIC_NO_CHECK_COMPRESS },
{ "elf", MAGIC_NO_CHECK_ELF },
{ "fortran", MAGIC_NO_CHECK_FORTRAN },
{ "soft", MAGIC_NO_CHECK_SOFT },
{ "tar", MAGIC_NO_CHECK_TAR },
{ "tokens", MAGIC_NO_CHECK_TOKENS },
{ "troff", MAGIC_NO_CHECK_TROFF },
};
#ifdef LC_CTYPE
/* makes islower etc work for other langs */
(void)setlocale(LC_CTYPE, "");
@ -212,6 +230,9 @@ main(int argc, char *argv[])
help();
break;
#endif
case '0':
nulsep = 1;
break;
case 'b':
++bflag;
break;
@ -224,6 +245,17 @@ main(int argc, char *argv[])
case 'd':
flags |= MAGIC_DEBUG|MAGIC_CHECK;
break;
case 'e':
for (i = 0; i < sizeof(nv) / sizeof(nv[0]); i++)
if (strcmp(nv[i].name, optarg) == 0)
break;
if (i == sizeof(nv) / sizeof(nv[0]))
errflg++;
else
flags |= nv[i].value;
break;
case 'f':
if(action)
usage();
@ -332,7 +364,7 @@ main(int argc, char *argv[])
private void
/*ARGSUSED*/
load(const char *m, int flags)
load(const char *m __unused, int flags)
{
if (magic)
return;
@ -402,9 +434,15 @@ process(const char *inname, int wid)
const char *type;
int std_in = strcmp(inname, "-") == 0;
if (wid > 0 && !bflag)
(void)printf("%s%s%*s ", std_in ? "/dev/stdin" : inname,
separator, (int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
if (wid > 0 && !bflag) {
(void)printf("%s", std_in ? "/dev/stdin" : inname);
if (nulsep)
(void)putc('\0', stdout);
else
(void)printf("%s", separator);
(void)printf("%*s ",
(int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
}
type = magic_file(magic, std_in ? NULL : inname);
if (type == NULL)
@ -530,6 +568,9 @@ help(void)
" -c, --checking-printout print the parsed form of the magic file, use in\n"
" conjunction with -m to debug a new magic file\n"
" before installing it\n"
" -e, --exclude exclude test from the list of test to be\n"
" performed for file. Valid tests are:\n"
" ascii, apptype, elf, compress, soft, tar\n"
" -f, --files-from FILE read the filenames to be examined from FILE\n"
" -F, --separator string use string as separator instead of `:'\n"
" -i, --mime output mime type strings\n"

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

@ -1,4 +1,4 @@
/* $NetBSD: file.h,v 1.13 2006/10/31 21:50:54 pooka Exp $ */
/* $NetBSD: file.h,v 1.14 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -29,7 +29,7 @@
*/
/*
* file.h - definitions for file(1) program
* @(#)Id: file.h,v 1.80 2006/10/31 20:57:45 christos Exp
* @(#)$File: file.h,v 1.89 2007/03/01 22:14:54 christos Exp $
*/
#ifndef __file_h__
@ -52,10 +52,13 @@
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include <regex.h>
#include <sys/types.h>
/* Do this here and now, because struct stat gets re-defined on solaris */
#include <sys/stat.h>
#define ENABLE_CONDITIONALS
#ifndef MAGIC
#define MAGIC "/etc/magic"
#endif
@ -72,6 +75,28 @@
#endif
#define public
#ifndef __GNUC_PREREQ__
#ifdef __GNUC__
#define __GNUC_PREREQ__(x, y) \
((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
(__GNUC__ > (x)))
#else
#define __GNUC_PREREQ__(x, y) 0
#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
#ifndef HOWMANY
# define HOWMANY (256 * 1024) /* how much of the file to look at */
#endif
@ -80,7 +105,7 @@
#define MAXstring 32 /* max leng of "string" types */
#define MAGICNO 0xF11E041C
#define VERSIONNO 3
#define VERSIONNO 4
#define FILE_MAGICSIZE (32 * 4)
#define FILE_LOAD 0
@ -92,17 +117,20 @@ struct magic {
uint16_t cont_level; /* level of ">" */
uint8_t nospflag; /* supress space character */
uint8_t flag;
#define INDIR 1 /* if '>(...)' appears, */
#define UNSIGNED 2 /* comparison is unsigned */
#define OFFADD 4 /* if '>&' appears, */
#define INDIROFFADD 8 /* if '>&(' appears, */
#define INDIR 1 /* if '(...)' appears */
#define OFFADD 2 /* if '>&' or '>...(&' appears */
#define INDIROFFADD 4 /* if '>&(' appears */
#define UNSIGNED 8 /* comparison is unsigned */
/* Word 2 */
uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
uint8_t vallen; /* length of string value, if any */
uint8_t type; /* int, short, long or string. */
uint8_t in_type; /* type of indirrection */
#define FILE_INVALID 0
#define FILE_BYTE 1
#define FILE_SHORT 2
#define FILE_DEFAULT 3
#define FILE_LONG 4
#define FILE_STRING 5
#define FILE_DATE 6
@ -132,89 +160,33 @@ struct magic {
#define FILE_QLDATE 30
#define FILE_LEQLDATE 31
#define FILE_BEQLDATE 32
#define FILE_NAMES_SIZE 33/* size of array to contain all names */
#define FILE_FORMAT_NAME \
/* 0 */ "invalid 0", \
/* 1 */ "byte", \
/* 2 */ "short", \
/* 3 */ "invalid 3", \
/* 4 */ "long", \
/* 5 */ "string", \
/* 6 */ "date", \
/* 7 */ "beshort", \
/* 8 */ "belong", \
/* 9 */ "bedate", \
/* 10 */ "leshort", \
/* 11 */ "lelong", \
/* 12 */ "ledate", \
/* 13 */ "pstring", \
/* 14 */ "ldate", \
/* 15 */ "beldate", \
/* 16 */ "leldate", \
/* 17 */ "regex", \
/* 18 */ "bestring16", \
/* 19 */ "lestring16", \
/* 20 */ "search", \
/* 21 */ "medate", \
/* 22 */ "meldate", \
/* 23 */ "melong", \
/* 24 */ "quad", \
/* 25 */ "lequad", \
/* 26 */ "bequad", \
/* 27 */ "qdate", \
/* 28 */ "leqdate", \
/* 29 */ "beqdate", \
/* 30 */ "qldate", \
/* 31 */ "leqldate", \
/* 32 */ "beqldate",
#define IS_STRING(t) \
((t) == FILE_STRING || \
(t) == FILE_PSTRING || \
(t) == FILE_BESTRING16 || \
(t) == FILE_LESTRING16 || \
(t) == FILE_REGEX || \
(t) == FILE_SEARCH || \
(t) == FILE_DEFAULT)
#define FILE_FMT_NONE 0
#define FILE_FMT_NUM 1 /* "cduxXi" */
#define FILE_FMT_STR 2 /* "s" */
#define FILE_FMT_QUAD 3 /* "ll" */
#define FILE_FORMAT_STRING \
/* 0 */ FILE_FMT_NONE, \
/* 1 */ FILE_FMT_NUM, \
/* 2 */ FILE_FMT_NUM, \
/* 3 */ FILE_FMT_NONE, \
/* 4 */ FILE_FMT_NUM, \
/* 5 */ FILE_FMT_STR, \
/* 6 */ FILE_FMT_STR, \
/* 7 */ FILE_FMT_NUM, \
/* 8 */ FILE_FMT_NUM, \
/* 9 */ FILE_FMT_STR, \
/* 10 */ FILE_FMT_NUM, \
/* 11 */ FILE_FMT_NUM, \
/* 12 */ FILE_FMT_STR, \
/* 13 */ FILE_FMT_STR, \
/* 14 */ FILE_FMT_STR, \
/* 15 */ FILE_FMT_STR, \
/* 16 */ FILE_FMT_STR, \
/* 17 */ FILE_FMT_STR, \
/* 18 */ FILE_FMT_STR, \
/* 19 */ FILE_FMT_STR, \
/* 20 */ FILE_FMT_STR, \
/* 21 */ FILE_FMT_STR, \
/* 22 */ FILE_FMT_STR, \
/* 23 */ FILE_FMT_NUM, \
/* 24 */ FILE_FMT_QUAD, \
/* 25 */ FILE_FMT_QUAD, \
/* 26 */ FILE_FMT_QUAD, \
/* 27 */ FILE_FMT_STR, \
/* 28 */ FILE_FMT_STR, \
/* 29 */ FILE_FMT_STR, \
/* 30 */ FILE_FMT_STR, \
/* 31 */ FILE_FMT_STR, \
/* 32 */ FILE_FMT_STR,
/* Word 3 */
uint8_t in_op; /* operator for indirection */
uint8_t mask_op; /* operator for mask */
#ifdef ENABLE_CONDITIONALS
uint8_t cond; /* conditional type */
uint8_t dummy1;
#else
uint8_t dummy1;
uint8_t dummy2;
#endif
#define FILE_OPS "&|^+-*/%"
#define FILE_OPAND 0
#define FILE_OPOR 1
@ -224,42 +196,65 @@ struct magic {
#define FILE_OPMULTIPLY 5
#define FILE_OPDIVIDE 6
#define FILE_OPMODULO 7
#define FILE_OPS_MASK 0x07 /* mask for above ops */
#define FILE_UNUSED_1 0x08
#define FILE_UNUSED_2 0x10
#define FILE_UNUSED_3 0x20
#define FILE_OPINVERSE 0x40
#define FILE_OPINDIRECT 0x80
#ifdef ENABLE_CONDITIONALS
#define COND_NONE 0
#define COND_IF 1
#define COND_ELIF 2
#define COND_ELSE 3
#endif /* ENABLE_CONDITIONALS */
/* Word 4 */
uint32_t offset; /* offset to magic number */
/* Word 5 */
int32_t in_offset; /* offset from indirection */
/* Word 6 */
uint32_t dummy4;
uint32_t lineno; /* line number in magic file */
/* Word 7,8 */
uint64_t mask; /* mask before comparison with value */
union {
uint64_t _mask; /* for use with numeric and date types */
struct {
uint32_t _count; /* repeat/line count */
uint32_t _flags; /* modifier flags */
} _s; /* for use with string types */
} _u;
#define num_mask _u._mask
#define str_count _u._s._count
#define str_flags _u._s._flags
/* Words 9-16 */
union VALUETYPE {
uint8_t b;
uint16_t h;
uint32_t l;
uint64_t q;
char s[MAXstring];
struct {
char *buf;
size_t buflen;
} search;
uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */
char s[MAXstring]; /* the search string or regex pattern */
} value; /* either number or string */
/* Words 17..31 */
char desc[MAXDESC]; /* description */
};
#define BIT(A) (1 << (A))
#define STRING_IGNORE_LOWERCASE BIT(0)
#define STRING_COMPACT_BLANK BIT(1)
#define STRING_COMPACT_OPTIONAL_BLANK BIT(2)
#define CHAR_IGNORE_LOWERCASE 'c'
#define STRING_COMPACT_BLANK BIT(0)
#define STRING_COMPACT_OPTIONAL_BLANK BIT(1)
#define STRING_IGNORE_LOWERCASE BIT(2)
#define STRING_IGNORE_UPPERCASE BIT(3)
#define REGEX_OFFSET_START BIT(4)
#define CHAR_COMPACT_BLANK 'B'
#define CHAR_COMPACT_OPTIONAL_BLANK 'b'
#define CHAR_IGNORE_LOWERCASE 'c'
#define CHAR_IGNORE_UPPERCASE 'C'
#define CHAR_REGEX_OFFSET_START 's'
#define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
/* list of magic entries */
@ -273,53 +268,79 @@ struct mlist {
};
struct magic_set {
struct mlist *mlist;
struct cont {
size_t len;
int32_t *off;
} c;
struct out {
/* Accumulation buffer */
char *buf;
char *ptr;
size_t len;
size_t size;
/* Printable buffer */
char *pbuf;
size_t psize;
} o;
int error;
int flags;
int haderr;
const char *file;
size_t line;
struct mlist *mlist;
struct cont {
size_t len;
struct level_info {
int32_t off;
int got_match;
#ifdef ENABLE_CONDITIONALS
int last_match;
int last_cond; /* used for error checking by parse() */
#endif
} *li;
} c;
struct out {
/* Accumulation buffer */
char *buf;
char *ptr;
size_t left;
size_t size;
/* Printable buffer */
char *pbuf;
size_t psize;
} o;
uint32_t offset;
int error;
int flags;
int haderr;
const char *file;
size_t line; /* current magic line number */
/* data for searches */
struct {
const char *s; /* start of search in original source */
size_t s_len; /* length of search region */
size_t offset; /* starting offset in source: XXX - should this be off_t? */
size_t rm_len; /* match length */
} search;
union VALUETYPE ms_value; /* either number or string */
};
struct stat;
protected const char *file_fmttime(uint32_t, int);
protected int file_buffer(struct magic_set *, int, const void *, size_t);
protected int file_buffer(struct magic_set *, int, const char *, const void *,
size_t);
protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
protected int file_printf(struct magic_set *, const char *, ...);
protected int file_reset(struct magic_set *);
protected int file_tryelf(struct magic_set *, int, const unsigned char *, size_t);
protected int file_zmagic(struct magic_set *, int, const unsigned char *, size_t);
protected int file_tryelf(struct magic_set *, int, const unsigned char *,
size_t);
protected int file_zmagic(struct magic_set *, int, const char *,
const unsigned char *, size_t);
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t);
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
protected uint64_t file_signextend(struct magic_set *, struct magic *, uint64_t);
protected uint64_t file_signextend(struct magic_set *, struct magic *,
uint64_t);
protected void file_delmagic(struct magic *, int type, size_t entries);
protected void file_badread(struct magic_set *);
protected void file_badseek(struct magic_set *);
protected void file_oomem(struct magic_set *);
protected void file_oomem(struct magic_set *, size_t);
protected void file_error(struct magic_set *, int, const char *, ...);
protected void file_magerror(struct magic_set *, const char *, ...);
protected void file_magwarn(struct magic_set *, const char *, ...);
protected void file_mdump(struct magic *);
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);
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[];

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsmagic.c,v 1.5 2005/10/17 18:00:00 pooka Exp $ */
/* $NetBSD: fsmagic.c,v 1.6 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -60,9 +60,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: fsmagic.c,v 1.46 2005/06/25 15:52:14 christos Exp")
FILE_RCSID("@(#)$File: fsmagic.c,v 1.47 2007/01/12 17:38:28 christos Exp $")
#else
__RCSID("$NetBSD: fsmagic.c,v 1.5 2005/10/17 18:00:00 pooka Exp $");
__RCSID("$NetBSD: fsmagic.c,v 1.6 2007/03/04 15:22:10 pooka Exp $");
#endif
#endif /* lint */

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

@ -1,4 +1,4 @@
/* $NetBSD: funcs.c,v 1.6 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: funcs.c,v 1.7 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -28,6 +28,7 @@
*/
#include "file.h"
#include "magic.h"
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@ -41,9 +42,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: funcs.c,v 1.22 2006/10/31 19:37:17 christos Exp")
FILE_RCSID("@(#)$File: funcs.c,v 1.28 2007/03/01 22:14:54 christos Exp $")
#else
__RCSID("$NetBSD: funcs.c,v 1.6 2006/10/31 21:16:23 pooka Exp $");
__RCSID("$NetBSD: funcs.c,v 1.7 2007/03/04 15:22:10 pooka Exp $");
#endif
#endif /* lint */
@ -58,28 +59,32 @@ protected int
file_printf(struct magic_set *ms, const char *fmt, ...)
{
va_list ap;
size_t len;
size_t len, size;
char *buf;
va_start(ap, fmt);
if ((len = vsnprintf(ms->o.ptr, ms->o.len, fmt, ap)) >= ms->o.len) {
if ((len = vsnprintf(ms->o.ptr, ms->o.left, fmt, ap)) >= ms->o.left) {
long diff; /* XXX: really ptrdiff_t */
va_end(ap);
if ((buf = realloc(ms->o.buf, len + 1024)) == NULL) {
file_oomem(ms);
size = (ms->o.size - ms->o.left) + len + 1024;
if ((buf = realloc(ms->o.buf, size)) == NULL) {
file_oomem(ms, size);
return -1;
}
ms->o.ptr = buf + (ms->o.ptr - ms->o.buf);
diff = ms->o.ptr - ms->o.buf;
ms->o.ptr = buf + diff;
ms->o.buf = buf;
ms->o.len = ms->o.size - (ms->o.ptr - ms->o.buf);
ms->o.size = len + 1024;
ms->o.left = size - diff;
ms->o.size = size;
va_start(ap, fmt);
len = vsnprintf(ms->o.ptr, ms->o.len, fmt, ap);
len = vsnprintf(ms->o.ptr, ms->o.left, fmt, ap);
}
ms->o.ptr += len;
ms->o.len -= len;
va_end(ap);
ms->o.ptr += len;
ms->o.left -= len;
return 0;
}
@ -87,18 +92,22 @@ file_printf(struct magic_set *ms, const char *fmt, ...)
* error - print best error message possible
*/
/*VARARGS*/
protected void
file_error(struct magic_set *ms, int error, const char *f, ...)
private void
file_error_core(struct magic_set *ms, int error, const char *f, va_list va,
uint32_t lineno)
{
va_list va;
size_t len;
/* Only the first error is ok */
if (ms->haderr)
return;
va_start(va, f);
(void)vsnprintf(ms->o.buf, ms->o.size, f, va);
va_end(va);
len = 0;
if (lineno != 0) {
(void)snprintf(ms->o.buf, ms->o.size, "line %u: ", lineno);
len = strlen(ms->o.buf);
}
(void)vsnprintf(ms->o.buf + len, ms->o.size - len, f, va);
if (error > 0) {
size_t len = strlen(ms->o.buf);
len = strlen(ms->o.buf);
(void)snprintf(ms->o.buf + len, ms->o.size - len, " (%s)",
strerror(error));
}
@ -106,11 +115,33 @@ file_error(struct magic_set *ms, int error, const char *f, ...)
ms->error = error;
}
/*VARARGS*/
protected void
file_error(struct magic_set *ms, int error, const char *f, ...)
{
va_list va;
va_start(va, f);
file_error_core(ms, error, f, va, 0);
va_end(va);
}
/*
* Print an error with magic line number.
*/
/*VARARGS*/
protected void
file_magerror(struct magic_set *ms, const char *f, ...)
{
va_list va;
va_start(va, f);
file_error_core(ms, 0, f, va, ms->line);
va_end(va);
}
protected void
file_oomem(struct magic_set *ms)
file_oomem(struct magic_set *ms, size_t len)
{
file_error(ms, errno, "cannot allocate memory");
file_error(ms, errno, "cannot allocate %zu bytes", len);
}
protected void
@ -127,17 +158,36 @@ file_badread(struct magic_set *ms)
#ifndef COMPILE_ONLY
protected int
file_buffer(struct magic_set *ms, int fd, const void *buf, size_t nb)
file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf,
size_t nb)
{
int m;
#ifdef __EMX__
if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) {
switch (file_os2_apptype(ms, inname, buf, nb)) {
case -1:
return -1;
case 0:
break;
default:
return 1;
}
}
#endif
/* try compression stuff */
if ((m = file_zmagic(ms, fd, buf, nb)) == 0) {
if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) != 0 ||
(m = file_zmagic(ms, fd, inname, buf, nb)) == 0) {
/* Check if we have a tar file */
if ((m = file_is_tar(ms, buf, nb)) == 0) {
if ((ms->flags & MAGIC_NO_CHECK_TAR) != 0 ||
(m = file_is_tar(ms, buf, nb)) == 0) {
/* try tests in /etc/magic (or surrogate magic file) */
if ((m = file_softmagic(ms, buf, nb)) == 0) {
if ((ms->flags & MAGIC_NO_CHECK_SOFT) != 0 ||
(m = file_softmagic(ms, buf, nb)) == 0) {
/* try known keywords, check whether it is ASCII */
if ((m = file_ascmagic(ms, buf, nb)) == 0) {
if ((ms->flags & MAGIC_NO_CHECK_ASCII) != 0 ||
(m = file_ascmagic(ms, buf, nb)) == 0) {
/* abandon hope, all ye who remain here */
if (file_printf(ms, ms->flags & MAGIC_MIME ?
(nb ? "application/octet-stream" :
@ -150,6 +200,19 @@ file_buffer(struct magic_set *ms, int fd, const void *buf, size_t nb)
}
}
}
#ifdef BUILTIN_ELF
if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 && nb > 5 && fd != -1) {
/*
* We matched something in the file, so this *might*
* be an ELF file, and the file is at least 5 bytes
* long, so if it's an ELF file it has at least one
* byte past the ELF magic number - try extracting
* information from the ELF headers that cannot easily
* be extracted with rules in the magic file.
*/
(void)file_tryelf(ms, fd, buf, nb);
}
#endif
return m;
}
#endif
@ -178,8 +241,8 @@ file_reset(struct magic_set *ms)
protected const char *
file_getbuffer(struct magic_set *ms)
{
char *nbuf, *op, *np;
size_t nsize;
char *pbuf, *op, *np;
size_t psize, len;
if (ms->haderr)
return NULL;
@ -187,14 +250,17 @@ file_getbuffer(struct magic_set *ms)
if (ms->flags & MAGIC_RAW)
return ms->o.buf;
nsize = ms->o.len * 4 + 1;
if (ms->o.psize < nsize) {
if ((nbuf = realloc(ms->o.pbuf, nsize)) == NULL) {
file_oomem(ms);
len = ms->o.size - ms->o.left;
/* * 4 is for octal representation, + 1 is for NUL */
psize = len * 4 + 1;
assert(psize > len);
if (ms->o.psize < psize) {
if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
file_oomem(ms, psize);
return NULL;
}
ms->o.psize = nsize;
ms->o.pbuf = nbuf;
ms->o.psize = psize;
ms->o.pbuf = pbuf;
}
#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
@ -248,8 +314,8 @@ file_getbuffer(struct magic_set *ms)
}
/*
* Yes these wrappers suffer from buffer overflows, but if your OS does not have
* the real functions, maybe you should consider replacing your OS?
* Yes these wrappers suffer from buffer overflows, but if your OS does not
* have the real functions, maybe you should consider replacing your OS?
*/
#ifndef HAVE_VSNPRINTF
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: is_tar.c,v 1.4 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: is_tar.c,v 1.5 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -48,9 +48,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: is_tar.c,v 1.26 2006/05/03 15:19:25 christos Exp")
FILE_RCSID("@(#)$File: is_tar.c,v 1.27 2007/01/12 17:38:28 christos Exp $")
#else
__RCSID("$NetBSD: is_tar.c,v 1.4 2006/10/31 21:16:23 pooka Exp $");
__RCSID("$NetBSD: is_tar.c,v 1.5 2007/03/04 15:22:10 pooka Exp $");
#endif
#endif

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

@ -1,4 +1,4 @@
/* $NetBSD: magic.c,v 1.15 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: magic.c,v 1.16 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -66,9 +66,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: magic.c,v 1.35 2006/10/31 19:37:17 christos Exp")
FILE_RCSID("@(#)$File: magic.c,v 1.40 2007/03/01 22:14:55 christos Exp $")
#else
__RCSID("$NetBSD: magic.c,v 1.15 2006/10/31 21:16:23 pooka Exp $");
__RCSID("$NetBSD: magic.c,v 1.16 2007/03/04 15:22:10 pooka Exp $");
#endif
#endif /* lint */
@ -100,7 +100,7 @@ magic_open(int flags)
goto free1;
}
ms->o.ptr = ms->o.buf = malloc(ms->o.size = 1024);
ms->o.ptr = ms->o.buf = malloc(ms->o.left = ms->o.size = 1024);
if (ms->o.buf == NULL)
goto free1;
@ -108,11 +108,10 @@ magic_open(int flags)
if (ms->o.pbuf == NULL)
goto free2;
ms->c.off = malloc((ms->c.len = 10) * sizeof(*ms->c.off));
if (ms->c.off == NULL)
ms->c.li = malloc((ms->c.len = 10) * sizeof(*ms->c.li));
if (ms->c.li == NULL)
goto free3;
ms->o.len = 0;
ms->haderr = 0;
ms->error = -1;
ms->mlist = NULL;
@ -168,7 +167,7 @@ magic_close(struct magic_set *ms)
free_mlist(ms->mlist);
free(ms->o.pbuf);
free(ms->o.buf);
free(ms->c.off);
free(ms->c.li);
free(ms);
}
@ -311,7 +310,7 @@ magic_file(struct magic_set *ms, const char *inname)
ssize_t r = 0;
while ((r = sread(fd, (void *)&buf[nbytes],
(size_t)(HOWMANY - nbytes))) > 0) {
(size_t)(HOWMANY - nbytes), 1)) > 0) {
nbytes += r;
if (r < PIPE_BUF) break;
}
@ -340,32 +339,8 @@ magic_file(struct magic_set *ms, const char *inname)
goto done;
} else {
(void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */
#ifdef __EMX__
switch (file_os2_apptype(ms, inname, buf, nbytes)) {
case -1:
if (file_buffer(ms, fd, inname, buf, (size_t)nbytes) == -1)
goto done;
case 0:
break;
default:
rv = 0;
goto done;
}
#endif
if (file_buffer(ms, fd, buf, (size_t)nbytes) == -1)
goto done;
#ifdef BUILTIN_ELF
if (nbytes > 5) {
/*
* We matched something in the file, so this *might*
* be an ELF file, and the file is at least 5 bytes
* long, so if it's an ELF file it has at least one
* byte past the ELF magic number - try extracting
* information from the ELF headers that cannot easily
* be extracted with rules in the magic file.
*/
file_tryelf(ms, fd, buf, (size_t)nbytes);
}
#endif
}
rv = 0;
done:
@ -384,7 +359,7 @@ magic_buffer(struct magic_set *ms, const void *buf, size_t nb)
* The main work is done here!
* We have the file name and/or the data buffer to be identified.
*/
if (file_buffer(ms, -1, buf, nb) == -1) {
if (file_buffer(ms, -1, NULL, buf, nb) == -1) {
return NULL;
}
return file_getbuffer(ms);

33
dist/file/src/magic.h vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: magic.h,v 1.3 2005/10/17 18:00:00 pooka Exp $ */
/* $NetBSD: magic.h,v 1.4 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -31,17 +31,26 @@
#include <sys/types.h>
#define MAGIC_NONE 0x000 /* No flags */
#define MAGIC_DEBUG 0x001 /* Turn on debugging */
#define MAGIC_SYMLINK 0x002 /* Follow symlinks */
#define MAGIC_COMPRESS 0x004 /* Check inside compressed files */
#define MAGIC_DEVICES 0x008 /* Look at the contents of devices */
#define MAGIC_MIME 0x010 /* Return a mime string */
#define MAGIC_CONTINUE 0x020 /* Return all matches */
#define MAGIC_CHECK 0x040 /* Print warnings to stderr */
#define MAGIC_PRESERVE_ATIME 0x080 /* Restore access time on exit */
#define MAGIC_RAW 0x100 /* Don't translate unprintable chars */
#define MAGIC_ERROR 0x200 /* Handle ENOENT etc as real errors */
#define MAGIC_NONE 0x000000 /* No flags */
#define MAGIC_DEBUG 0x000001 /* Turn on debugging */
#define MAGIC_SYMLINK 0x000002 /* Follow symlinks */
#define MAGIC_COMPRESS 0x000004 /* Check inside compressed files */
#define MAGIC_DEVICES 0x000008 /* Look at the contents of devices */
#define MAGIC_MIME 0x000010 /* Return a mime string */
#define MAGIC_CONTINUE 0x000020 /* Return all matches */
#define MAGIC_CHECK 0x000040 /* Print warnings to stderr */
#define MAGIC_PRESERVE_ATIME 0x000080 /* Restore access time on exit */
#define MAGIC_RAW 0x000100 /* Don't translate unprintable chars */
#define MAGIC_ERROR 0x000200 /* Handle ENOENT etc as real errors */
#define MAGIC_NO_CHECK_COMPRESS 0x001000 /* Don't check for compressed files */
#define MAGIC_NO_CHECK_TAR 0x002000 /* Don't check for tar files */
#define MAGIC_NO_CHECK_SOFT 0x004000 /* Don't check magic entries */
#define MAGIC_NO_CHECK_APPTYPE 0x008000 /* Don't check application type */
#define MAGIC_NO_CHECK_ELF 0x010000 /* Don't check for elf details */
#define MAGIC_NO_CHECK_ASCII 0x020000 /* Don't check for ascii files */
#define MAGIC_NO_CHECK_TROFF 0x040000 /* Don't check ascii/troff */
#define MAGIC_NO_CHECK_FORTRAN 0x080000 /* Don't check ascii/fortran */
#define MAGIC_NO_CHECK_TOKENS 0x100000 /* Don't check ascii/tokens */
#ifdef __cplusplus
extern "C" {

View File

@ -1,4 +1,4 @@
/* $NetBSD: names.h,v 1.3 2005/10/17 18:00:00 pooka Exp $ */
/* $NetBSD: names.h,v 1.4 2007/03/04 15:22:10 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.
*
* Id: names.h,v 1.25 2004/09/11 19:15:57 christos Exp
* $File: names.h,v 1.26 2007/01/12 17:38:28 christos Exp $
*/
/*

View File

@ -1,13 +1,25 @@
/* $NetBSD: patchlevel.h,v 1.5 2006/10/31 21:39:08 pooka Exp $ */
/* $NetBSD: patchlevel.h,v 1.6 2007/03/04 15:22:10 pooka Exp $ */
#define FILE_VERSION_MAJOR 4
#define patchlevel 18
#define patchlevel 20
/*
* Patchlevel file for Ian Darwin's MAGIC command.
* Id: patchlevel.h,v 1.60 2006/03/02 22:15:12 christos Exp
* $File: patchlevel.h,v 1.64 2007/03/01 22:14:55 christos Exp $
*
* Log: patchlevel.h,v
* Revision 1.64 2007/03/01 22:14:55 christos
* welcome to 4.20
*
* Revision 1.63 2007/01/12 17:38:28 christos
* Use File id.
*
* Revision 1.62 2006/12/11 21:49:58 christos
* time for 4.19
*
* Revision 1.61 2006/10/31 21:18:09 christos
* bump
*
* Revision 1.60 2006/03/02 22:15:12 christos
* welcome to 4.17
*

60
dist/file/src/print.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: print.c,v 1.5 2006/11/01 00:33:40 dogcow Exp $ */
/* $NetBSD: print.c,v 1.6 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -44,9 +44,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: print.c,v 1.54 2006/10/31 19:37:17 christos Exp")
FILE_RCSID("@(#)$File: print.c,v 1.58 2007/01/16 14:58:48 ljt Exp $")
#else
__RCSID("$NetBSD: print.c,v 1.5 2006/11/01 00:33:40 dogcow Exp $");
__RCSID("$NetBSD: print.c,v 1.6 2007/03/04 15:22:10 pooka Exp $");
#endif
#endif /* lint */
@ -58,7 +58,7 @@ file_mdump(struct magic *m)
{
private const char optyp[] = { FILE_OPS };
(void) fputc('[', stderr);
(void) fprintf(stderr, "[%zu", m->lineno);
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
m->offset);
@ -70,8 +70,8 @@ file_mdump(struct magic *m)
if (m->in_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
(void) fprintf(stderr, "%c%d),",
((m->in_op&0x7F) < SZOF(optyp)) ?
optyp[m->in_op&0x7F] : '?',
((m->in_op & FILE_OPS_MASK) < SZOF(optyp)) ?
optyp[m->in_op & FILE_OPS_MASK] : '?',
m->in_offset);
}
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
@ -79,24 +79,36 @@ file_mdump(struct magic *m)
(m->type < file_nnames) ? file_names[m->type] : "*bad*");
if (m->mask_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
if (m->mask) {
if ((m->mask_op & 0x7F) < SZOF(optyp))
fputc(optyp[m->mask_op&0x7F], stderr);
else
fputc('?', stderr);
if (FILE_STRING != m->type || FILE_PSTRING != m->type)
(void) fprintf(stderr, "%.8" PRIx64, m->mask);
else {
if (m->mask & STRING_IGNORE_LOWERCASE)
(void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
if (m->mask & STRING_COMPACT_BLANK)
if (IS_STRING(m->type)) {
if (m->str_flags) {
(void) fputc('/', stderr);
if (m->str_flags & STRING_COMPACT_BLANK)
(void) fputc(CHAR_COMPACT_BLANK, stderr);
if (m->mask & STRING_COMPACT_OPTIONAL_BLANK)
if (m->str_flags & STRING_COMPACT_OPTIONAL_BLANK)
(void) fputc(CHAR_COMPACT_OPTIONAL_BLANK,
stderr);
stderr);
if (m->str_flags & STRING_IGNORE_LOWERCASE)
(void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
if (m->str_flags & STRING_IGNORE_UPPERCASE)
(void) fputc(CHAR_IGNORE_UPPERCASE, stderr);
if (m->str_flags & REGEX_OFFSET_START)
(void) fputc(CHAR_REGEX_OFFSET_START, stderr);
}
if (m->str_count)
(void) fprintf(stderr, "/%u", m->str_count);
}
else {
if ((m->mask_op & FILE_OPS_MASK) < SZOF(optyp))
(void) fputc(optyp[m->mask_op & FILE_OPS_MASK], stderr);
else
(void) fputc('?', stderr);
if (m->num_mask) {
(void) fprintf(stderr, "%.8llx",
(unsigned long long)m->num_mask);
}
}
(void) fprintf(stderr, ",%c", m->reln);
if (m->reln != 'x') {
@ -114,7 +126,8 @@ file_mdump(struct magic *m)
case FILE_BEQUAD:
case FILE_LEQUAD:
case FILE_QUAD:
(void) fprintf(stderr, "%" PRId64, m->value.q);
(void) fprintf(stderr, "%lld",
(unsigned long long)m->value.q);
break;
case FILE_PSTRING:
case FILE_STRING:
@ -150,6 +163,9 @@ file_mdump(struct magic *m)
(void)fprintf(stderr, "%s,",
file_fmttime((uint32_t)m->value.q, 0));
break;
case FILE_DEFAULT:
/* XXX - do anything here? */
break;
default:
(void) fputs("*bad*", stderr);
break;
@ -173,7 +189,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...)
(unsigned long)ms->line);
(void) vfprintf(stderr, f, va);
va_end(va);
fputc('\n', stderr);
(void) fputc('\n', stderr);
}
protected const char *

View File

@ -1,4 +1,4 @@
/* $NetBSD: readelf.c,v 1.12 2006/11/14 14:12:24 martin Exp $ */
/* $NetBSD: readelf.c,v 1.13 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -40,9 +40,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: readelf.c,v 1.59 2006/10/31 19:37:17 christos Exp")
FILE_RCSID("@(#)$File: readelf.c,v 1.63 2007/01/16 14:56:45 ljt Exp $")
#else
__RCSID("$NetBSD: readelf.c,v 1.12 2006/11/14 14:12:24 martin Exp $");
__RCSID("$NetBSD: readelf.c,v 1.13 2007/03/04 15:22:10 pooka Exp $");
#endif
#endif
@ -161,7 +161,7 @@ getu64(int swap, uint64_t value)
#define xph_type (class == ELFCLASS32 \
? getu32(swap, ph32.p_type) \
: getu32(swap, ph64.p_type))
#define xph_offset (class == ELFCLASS32 \
#define xph_offset (off_t)(class == ELFCLASS32 \
? getu32(swap, ph32.p_offset) \
: getu64(swap, ph64.p_offset))
#define xph_align (size_t)((class == ELFCLASS32 \
@ -299,7 +299,7 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
if (lseek(fd, (off_t)xph_offset, SEEK_SET) == (off_t)-1) {
if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
}
@ -864,7 +864,7 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
if (lseek(fd, (off_t)xph_offset, SEEK_SET)
if (lseek(fd, xph_offset, SEEK_SET)
== (off_t)-1) {
file_badseek(ms);
return -1;

File diff suppressed because it is too large Load Diff

74
dist/file/src/tar.h vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: tar.h,v 1.4 2006/10/31 21:16:23 pooka Exp $ */
/* $NetBSD: tar.h,v 1.5 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -34,7 +34,7 @@
*
* Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
*
* Id: tar.h,v 1.9 2006/05/03 15:19:25 christos Exp # checkin only
* $File: tar.h,v 1.11 2007/01/16 14:56:45 ljt Exp $ # checkin only
*/
/*
@ -108,52 +108,6 @@ union record {
#define EX_BADARCH 3 /* bad archive */
#define EX_SYSTEM 4 /* system gave unexpected error */
/*
* Global variables
*/
TAR_EXTERN union record *ar_block; /* Start of block of archive */
TAR_EXTERN union record *ar_record; /* Current record of archive */
TAR_EXTERN union record *ar_last; /* Last+1 record of archive block */
TAR_EXTERN char ar_reading; /* 0 writing, !0 reading archive */
TAR_EXTERN int blocking; /* Size of each block, in records */
TAR_EXTERN int blocksize; /* Size of each block, in bytes */
TAR_EXTERN char *ar_file; /* File containing archive */
TAR_EXTERN char *name_file; /* File containing names to work on */
TAR_EXTERN char *tar; /* Name of this program */
/*
* Flags from the command line
*/
TAR_EXTERN char f_reblock; /* -B */
TAR_EXTERN char f_create; /* -c */
TAR_EXTERN char f_debug; /* -d */
TAR_EXTERN char f_sayblock; /* -D */
TAR_EXTERN char f_follow_links; /* -h */
TAR_EXTERN char f_ignorez; /* -i */
TAR_EXTERN char f_keep; /* -k */
TAR_EXTERN char f_modified; /* -m */
TAR_EXTERN char f_oldarch; /* -o */
TAR_EXTERN char f_use_protection; /* -p */
TAR_EXTERN char f_sorted_names; /* -s */
TAR_EXTERN char f_list; /* -t */
TAR_EXTERN char f_namefile; /* -T */
TAR_EXTERN char f_verbose; /* -v */
TAR_EXTERN char f_extract; /* -x */
TAR_EXTERN char f_compress; /* -z */
/*
* We now default to Unix Standard format rather than 4.2BSD tar format.
* The code can actually produce all three:
* f_standard ANSI standard
* f_oldarch V7
* neither 4.2BSD
* but we don't bother, since 4.2BSD can read ANSI standard format anyway.
* The only advantage to the "neither" option is that we can cmp(1) our
* output to the output of 4.2BSD tar, for debugging.
*/
#define f_standard (!f_oldarch)
/*
* Structure for keeping track of filenames and lists thereof.
*/
@ -164,12 +118,6 @@ struct name {
char name[NAMSIZ+1];
};
TAR_EXTERN struct name *namelist; /* Points to first name in list */
TAR_EXTERN struct name *namelast; /* Points to last name in list */
TAR_EXTERN int archive; /* File descriptor for archive file */
TAR_EXTERN int errors; /* # of files in error */
/*
*
* Due to the next struct declaration, each routine that includes
@ -187,21 +135,3 @@ struct link {
short linkcount;
char name[NAMSIZ+1];
};
TAR_EXTERN struct link *linklist; /* Points to first link in list */
/*
* Error recovery stuff
*/
TAR_EXTERN char read_error_flag;
#if 0
/*
* Declarations of functions available to the world.
*/
/*LINTLIBRARY*/
#define annorec(stream, msg) anno(stream, msg, 0) /* Cur rec */
#define annofile(stream, msg) anno(stream, msg, 1) /* Saved rec */
#endif

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

@ -1,4 +1,4 @@
/* $NetBSD: test.c,v 1.3 2005/10/17 18:00:00 pooka Exp $ */
/* $NetBSD: test.c,v 1.4 2007/03/04 15:22:10 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -41,19 +41,19 @@ main(int argc, char **argv)
ms = magic_open(MAGIC_NONE);
if (ms == NULL) {
printf("ERROR: out of memory\n");
(void) printf("ERROR: out of memory\n");
return 1;
}
if (magic_load(ms, NULL) == -1) {
printf("ERROR: %s\n", magic_error(ms));
(void) printf("ERROR: %s\n", magic_error(ms));
return 1;
}
for (i = 1; i < argc; i++) {
if ((m = magic_file(ms, argv[i])) == NULL)
printf("ERROR: %s\n", magic_error(ms));
(void) printf("ERROR: %s\n", magic_error(ms));
else
printf("%s: %s\n", argv[i], m);
(void) printf("%s: %s\n", argv[i], m);
}
magic_close(ms);