merge new file

This commit is contained in:
christos 2013-03-23 16:15:57 +00:00
parent 3ca28e1323
commit c2e19894b5
36 changed files with 1088 additions and 737 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.1 2009/05/08 17:28:01 christos Exp $
# $NetBSD: Makefile,v 1.2 2013/03/23 16:15:57 christos Exp $
.include <bsd.own.mk>
.include <bsd.sys.mk>
@ -20,6 +20,9 @@ CLEANFILES+= magic.mgc
realall: file magic.mgc
.endif
LIBMAGIC!= cd ${.CURDIR}/../lib && ${PRINTOBJDIR}
CPPFLAGS+=-I${LIBMAGIC}
.if ${MKSHARE} != "no"
magic.mgc: ${TOOL_MKMAGIC}
${_MKTARGET_CREATE}

View File

@ -58,8 +58,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/visibility.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \

View File

@ -19,6 +19,81 @@ You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
# visibility.m4 serial 3 (gettext-0.18)
dnl Copyright (C) 2005, 2008-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Bruno Haible.
dnl Tests whether the compiler supports the command-line option
dnl -fvisibility=hidden and the function and variable attributes
dnl __attribute__((__visibility__("hidden"))) and
dnl __attribute__((__visibility__("default"))).
dnl Does *not* test for __visibility__("protected") - which has tricky
dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
dnl MacOS X.
dnl Does *not* test for __visibility__("internal") - which has processor
dnl dependent semantics.
dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
dnl "really only recommended for legacy code".
dnl Set the variable CFLAG_VISIBILITY.
dnl Defines and sets the variable HAVE_VISIBILITY.
AC_DEFUN([gl_VISIBILITY],
[
AC_REQUIRE([AC_PROG_CC])
CFLAG_VISIBILITY=
HAVE_VISIBILITY=0
if test -n "$GCC"; then
dnl First, check whether -Werror can be added to the command line, or
dnl whether it leads to an error because of some other option that the
dnl user has put into $CC $CFLAGS $CPPFLAGS.
AC_MSG_CHECKING([whether the -Werror option is usable])
AC_CACHE_VAL([gl_cv_cc_vis_werror], [
gl_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_TRY_COMPILE([], [],
[gl_cv_cc_vis_werror=yes],
[gl_cv_cc_vis_werror=no])
CFLAGS="$gl_save_CFLAGS"])
AC_MSG_RESULT([$gl_cv_cc_vis_werror])
dnl Now check whether visibility declarations are supported.
AC_MSG_CHECKING([for simple visibility declarations])
AC_CACHE_VAL([gl_cv_cc_visibility], [
gl_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fvisibility=hidden"
dnl We use the option -Werror and a function dummyfunc, because on some
dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
dnl "visibility attribute not supported in this configuration; ignored"
dnl at the first function definition in every compilation unit, and we
dnl don't want to use the option in this case.
if test $gl_cv_cc_vis_werror = yes; then
CFLAGS="$CFLAGS -Werror"
fi
AC_TRY_COMPILE(
[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
extern __attribute__((__visibility__("default"))) int exportedvar;
extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
extern __attribute__((__visibility__("default"))) int exportedfunc (void);
void dummyfunc (void) {}],
[],
[gl_cv_cc_visibility=yes],
[gl_cv_cc_visibility=no])
CFLAGS="$gl_save_CFLAGS"])
AC_MSG_RESULT([$gl_cv_cc_visibility])
if test $gl_cv_cc_visibility = yes; then
CFLAG_VISIBILITY="-fvisibility=hidden"
HAVE_VISIBILITY=1
fi
fi
AC_SUBST([CFLAG_VISIBILITY])
AC_SUBST([HAVE_VISIBILITY])
AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
[Define to 1 or 0, depending whether the compiler supports simple visibility declarations.])
])
# Copyright (C) 2002-2012 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
@ -1077,5 +1152,4 @@ m4_include([m4/ltoptions.m4])
m4_include([m4/ltsugar.m4])
m4_include([m4/ltversion.m4])
m4_include([m4/lt~obsolete.m4])
m4_include([m4/visibility.m4])
m4_include([acinclude.m4])

View File

@ -89,6 +89,9 @@
/* Define to 1 if you have a working `mmap' system call. */
#undef HAVE_MMAP
/* Define to 1 if you have the `pread' function. */
#undef HAVE_PREAD
/* Define to 1 if you have the <stddef.h> header file. */
#undef HAVE_STDDEF_H

View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for file 5.12.
# Generated by GNU Autoconf 2.69 for file 5.14.
#
# Report bugs to <christos@astron.com>.
#
@ -729,8 +729,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='file'
PACKAGE_TARNAME='file'
PACKAGE_VERSION='5.12'
PACKAGE_STRING='file 5.12'
PACKAGE_VERSION='5.14'
PACKAGE_STRING='file 5.14'
PACKAGE_BUGREPORT='christos@astron.com'
PACKAGE_URL=''
@ -1467,7 +1467,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures file 5.12 to adapt to many kinds of systems.
\`configure' configures file 5.14 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1537,7 +1537,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of file 5.12:";;
short | recursive ) echo "Configuration of file 5.14:";;
esac
cat <<\_ACEOF
@ -1648,7 +1648,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
file configure 5.12
file configure 5.14
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@ -2304,7 +2304,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by file $as_me 5.12, which was
It was created by file $as_me 5.14, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@ -3131,7 +3131,7 @@ fi
# Define the identity of the package.
PACKAGE='file'
VERSION='5.12'
VERSION='5.14'
cat >>confdefs.h <<_ACEOF
@ -11692,11 +11692,10 @@ else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
extern __attribute__((__visibility__("hidden"))) int hiddenvar;
extern __attribute__((__visibility__("default"))) int exportedvar;
extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
extern __attribute__((__visibility__("default"))) int exportedfunc (void);
void dummyfunc (void) {}
extern __attribute__((__visibility__("default"))) int exportedvar;
extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
extern __attribute__((__visibility__("default"))) int exportedfunc (void);
void dummyfunc (void) {}
int
main ()
{
@ -13408,6 +13407,19 @@ esac
fi
ac_fn_c_check_func "$LINENO" "pread" "ac_cv_func_pread"
if test "x$ac_cv_func_pread" = xyes; then :
$as_echo "#define HAVE_PREAD 1" >>confdefs.h
else
case " $LIBOBJS " in
*" pread.$ac_objext "* ) ;;
*) LIBOBJS="$LIBOBJS pread.$ac_objext"
;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gzopen in -lz" >&5
@ -14063,7 +14075,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by file $as_me 5.12, which was
This file was extended by file $as_me 5.14, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -14129,7 +14141,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
file config.status 5.12
file config.status 5.14
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"

View File

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT([file],[5.12],[christos@astron.com])
AC_INIT([file],[5.14],[christos@astron.com])
AM_INIT_AUTOMAKE([subdir-objects foreign])
AM_MAINTAINER_MODE(disable)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@ -140,7 +140,7 @@ dnl Checks for functions
AC_CHECK_FUNCS(strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof)
dnl Provide implementation of some required functions if necessary
AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r)
AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r pread)
dnl Checks for libraries
AC_CHECK_LIB(z,gzopen)

View File

@ -54,8 +54,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/visibility.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d

View File

@ -1,6 +1,6 @@
.\" $NetBSD: file.1,v 1.11 2013/01/04 15:37:53 christos Exp $
.\" $NetBSD: file.1,v 1.12 2013/03/23 16:15:57 christos Exp $
.\"
.\" $File: file.man,v 1.101 2012/11/01 04:31:53 christos Exp $
.\" $File: file.man,v 1.102 2013/01/04 15:39:22 christos Exp $
.Dd October 25, 2012
.Dt FILE 1
.Os
@ -26,7 +26,7 @@
.Nm
.Op Fl Fl help
.Sh DESCRIPTION
This manual page documents version 5.12 of the
This manual page documents version 5.14 of the
.Nm
command.
.Pp
@ -561,8 +561,8 @@ or the mailing list at
Fix output so that tests for MIME and APPLE flags are not needed all
over the place, and actual output is only done in one place.
This needs a design.
Suggestion: push possible outputs on to a list, then
pick the last-pushed (most specific, one hopes) value at the end, or
Suggestion: push possible outputs on to a list, then pick the
last-pushed (most specific, one hopes) value at the end, or
use a default if the list is empty.
This should not slow down evaluation.
.Pp
@ -572,8 +572,7 @@ See Debian BTS for a good source.
Store arbitrarily long strings, for example for %s patterns, so that
they can be printed out.
Fixes Debian bug #271672.
Would require more
complex store/load code in apprentice.
Would require more complex store/load code in apprentice.
.Pp
Add syntax for relative offsets after current level (Debian bug #466037).
.Pp
@ -587,8 +586,8 @@ Add an option to print URLs for the sources of the file descriptions.
Combine script searches and add a way to map executable names to MIME
types (e.g. have a magic value for !:mime which causes the resulting
string to be looked up in a table).
This would avoid adding the same magic repeatedly for each new hash-bang
interpreter.
This would avoid adding the same magic repeatedly for each new
hash-bang interpreter.
.Pp
Fix
.Dq name

View File

@ -1,6 +1,6 @@
.\" $NetBSD: libmagic.3,v 1.10 2012/02/22 17:53:50 christos Exp $
.\" $NetBSD: libmagic.3,v 1.11 2013/03/23 16:15:57 christos Exp $
.\"
.\" $File: libmagic.man,v 1.26 2011/12/19 17:49:31 christos Exp $
.\" $File: libmagic.man,v 1.27 2013/01/06 20:56:52 christos Exp $
.\"
.\" Copyright (c) Christos Zoulas 2003.
.\" All Rights Reserved.
@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 19, 2011
.Dd January 6, 2012
.Dt LIBMAGIC 3
.Os
.Sh NAME
@ -39,7 +39,9 @@
.Nm magic_setflags ,
.Nm magic_check ,
.Nm magic_compile ,
.Nm magic_load
.Nm magic_list ,
.Nm magic_load ,
.Nm magic_version
.Nd Magic number recognition library
.Sh LIBRARY
.Lb libmagic
@ -69,6 +71,8 @@
.Fn magic_list "magic_t cookie" "const char *filename"
.Ft int
.Fn magic_load "magic_t cookie" "const char *filename"
.Ft int
.Fn magic_version "void"
.Sh DESCRIPTION
These functions
operate on the magic database file
@ -249,6 +253,16 @@ If that variable is not set, the default database file name is
adds
.Dq .mgc
to the database filename as appropriate.
.Pp
The
.Fn magic_version
command returns the version number of this library which is compiled into
the shared library using the constant
.Dv MAGIC_VERSION
from
.In magic.h .
This can be used by client programs to verify that the version they compile
against is the same as the version that they run against.
.Sh RETURN VALUES
The function
.Fn magic_open
@ -279,6 +293,9 @@ function returns a textual description of the errors of the above
functions, or
.Dv NULL
if there was no error.
The
.Fn magic_version
always returns the version number of the library.
Finally,
.Fn magic_setflags
returns \-1 on systems that don't support

View File

@ -1,7 +1,7 @@
.\" $NetBSD: magic.5,v 1.9 2013/01/04 15:37:53 christos Exp $
.\" $NetBSD: magic.5,v 1.10 2013/03/23 16:15:57 christos Exp $
.\"
.\" $File: magic.man,v 1.76 2012/11/07 20:29:27 christos Exp $
.Dd November 7, 2012
.\" $File: magic.man,v 1.78 2013/01/09 13:04:30 christos Exp $
.Dd January 7, 2013
.Dt MAGIC 5
.Os
.\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
@ -12,7 +12,7 @@
This manual page documents the format of the magic file as
used by the
.Xr file 1
command, version 5.12.
command, version 5.14.
The
.Xr file 1
command identifies the type of a file using,
@ -267,6 +267,67 @@ This is intended to be used with the test
no other matches.
.El
.Pp
For compatibility with the Single
.Ux
Standard, the type specifiers
.Dv dC
and
.Dv d1
are equivalent to
.Dv byte ,
the type specifiers
.Dv uC
and
.Dv u1
are equivalent to
.Dv ubyte ,
the type specifiers
.Dv dS
and
.Dv d2
are equivalent to
.Dv short ,
the type specifiers
.Dv uS
and
.Dv u2
are equivalent to
.Dv ushort ,
the type specifiers
.Dv dI ,
.Dv dL ,
and
.Dv d4
are equivalent to
.Dv long ,
the type specifiers
.Dv uI ,
.Dv uL ,
and
.Dv u4
are equivalent to
.Dv ulong ,
the type specifier
.Dv d8
is equivalent to
.Dv quad ,
the type specifier
.Dv u8
is equivalent to
.Dv uquad ,
and the type specifier
.Dv s
is equivalent to
.Dv string .
In addition, the type specifier
.Dv dQ
is equivalent to
.Dv quad
and the type specifier
.Dv uQ
is equivalent to
.Dv uquad .
.Pp
Each top-level magic pattern (see below for an explanation of levels)
is classified as text or binary according to the types used.
Types
@ -572,19 +633,41 @@ The formats
.Dv melong ,
.Dv short ,
.Dv beshort ,
.Dv leshort ,
.Dv date ,
.Dv bedate ,
.Dv medate ,
.Dv ledate ,
.Dv beldate ,
.Dv leldate ,
and
.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.
.Dv leshort
do not depend on the length of the C data types
.Dv short
and
.Dv long
on the platform, even though the Single
.Ux
Specification implies that they do. However, as OS X Mountain Lion has
passed the Single
.Ux
Specification validation suite, and supplies a version of
.Xr file 1
in which they do not depend on the sizes of the C data types and that is
built for a 64-bit environment in which
.Dv long
is 8 bytes rather than 4 bytes, presumably the validation suite does not
test whether, for example
.Dv long
refers to an item with the same size as the C data type
.Dv long .
There should probably be
.Dv type
names
.Dv int8 ,
.Dv uint8 ,
.Dv int16 ,
.Dv uint16 ,
.Dv int32 ,
.Dv uint32 ,
.Dv int64 ,
and
.Dv uint64 ,
and specified-byte-order variants of them,
to make it clearer that those types have specified widths.
.\"
.\" From: guy@sun.uucp (Guy Harris)
.\" Newsgroups: net.bugs.usg

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# $NetBSD: install-sh,v 1.6 2013/01/03 23:05:37 christos Exp $
# $NetBSD: install-sh,v 1.7 2013/03/23 16:15:57 christos Exp $
# This script now also installs multiple files, but might choke on installing
# multiple files with spaces in the file names.
#

View File

@ -1,77 +0,0 @@
# visibility.m4 serial 4 (gettext-0.18.2)
dnl Copyright (C) 2005, 2008, 2010-2012 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Bruno Haible.
dnl Tests whether the compiler supports the command-line option
dnl -fvisibility=hidden and the function and variable attributes
dnl __attribute__((__visibility__("hidden"))) and
dnl __attribute__((__visibility__("default"))).
dnl Does *not* test for __visibility__("protected") - which has tricky
dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
dnl MacOS X.
dnl Does *not* test for __visibility__("internal") - which has processor
dnl dependent semantics.
dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
dnl "really only recommended for legacy code".
dnl Set the variable CFLAG_VISIBILITY.
dnl Defines and sets the variable HAVE_VISIBILITY.
AC_DEFUN([gl_VISIBILITY],
[
AC_REQUIRE([AC_PROG_CC])
CFLAG_VISIBILITY=
HAVE_VISIBILITY=0
if test -n "$GCC"; then
dnl First, check whether -Werror can be added to the command line, or
dnl whether it leads to an error because of some other option that the
dnl user has put into $CC $CFLAGS $CPPFLAGS.
AC_MSG_CHECKING([whether the -Werror option is usable])
AC_CACHE_VAL([gl_cv_cc_vis_werror], [
gl_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[]], [[]])],
[gl_cv_cc_vis_werror=yes],
[gl_cv_cc_vis_werror=no])
CFLAGS="$gl_save_CFLAGS"])
AC_MSG_RESULT([$gl_cv_cc_vis_werror])
dnl Now check whether visibility declarations are supported.
AC_MSG_CHECKING([for simple visibility declarations])
AC_CACHE_VAL([gl_cv_cc_visibility], [
gl_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fvisibility=hidden"
dnl We use the option -Werror and a function dummyfunc, because on some
dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
dnl "visibility attribute not supported in this configuration; ignored"
dnl at the first function definition in every compilation unit, and we
dnl don't want to use the option in this case.
if test $gl_cv_cc_vis_werror = yes; then
CFLAGS="$CFLAGS -Werror"
fi
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
extern __attribute__((__visibility__("default"))) int exportedvar;
extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
extern __attribute__((__visibility__("default"))) int exportedfunc (void);
void dummyfunc (void) {}
]],
[[]])],
[gl_cv_cc_visibility=yes],
[gl_cv_cc_visibility=no])
CFLAGS="$gl_save_CFLAGS"])
AC_MSG_RESULT([$gl_cv_cc_visibility])
if test $gl_cv_cc_visibility = yes; then
CFLAG_VISIBILITY="-fvisibility=hidden"
HAVE_VISIBILITY=1
fi
fi
AC_SUBST([CFLAG_VISIBILITY])
AC_SUBST([HAVE_VISIBILITY])
AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
[Define to 1 or 0, depending whether the compiler supports simple visibility declarations.])
])

View File

@ -1,5 +1,5 @@
#
# $File: Makefile.am,v 1.85 2013/01/03 16:00:42 christos Exp $
# $File: Makefile.am,v 1.89 2013/02/18 18:31:09 christos Exp $
#
MAGIC_FRAGMENT_BASE = magdir
MAGIC_DIR = $(top_srcdir)/magic
@ -18,6 +18,7 @@ $(MAGIC_FRAGMENT_DIR)/alliant \
$(MAGIC_FRAGMENT_DIR)/amanda \
$(MAGIC_FRAGMENT_DIR)/amigaos \
$(MAGIC_FRAGMENT_DIR)/animation \
$(MAGIC_FRAGMENT_DIR)/aout \
$(MAGIC_FRAGMENT_DIR)/apl \
$(MAGIC_FRAGMENT_DIR)/apple \
$(MAGIC_FRAGMENT_DIR)/applix \
@ -85,9 +86,10 @@ $(MAGIC_FRAGMENT_DIR)/gcc \
$(MAGIC_FRAGMENT_DIR)/geo \
$(MAGIC_FRAGMENT_DIR)/geos \
$(MAGIC_FRAGMENT_DIR)/gimp \
$(MAGIC_FRAGMENT_DIR)/gnome-keyring \
$(MAGIC_FRAGMENT_DIR)/gnome \
$(MAGIC_FRAGMENT_DIR)/gnu \
$(MAGIC_FRAGMENT_DIR)/gnumeric \
$(MAGIC_FRAGMENT_DIR)/gpt \
$(MAGIC_FRAGMENT_DIR)/grace \
$(MAGIC_FRAGMENT_DIR)/graphviz \
$(MAGIC_FRAGMENT_DIR)/gringotts \
@ -97,6 +99,7 @@ $(MAGIC_FRAGMENT_DIR)/hp \
$(MAGIC_FRAGMENT_DIR)/human68k \
$(MAGIC_FRAGMENT_DIR)/ibm370 \
$(MAGIC_FRAGMENT_DIR)/ibm6000 \
$(MAGIC_FRAGMENT_DIR)/icc \
$(MAGIC_FRAGMENT_DIR)/iff \
$(MAGIC_FRAGMENT_DIR)/images \
$(MAGIC_FRAGMENT_DIR)/inform \

View File

@ -55,8 +55,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/visibility.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@ -233,7 +232,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#
# $File: Makefile.am,v 1.85 2013/01/03 16:00:42 christos Exp $
# $File: Makefile.am,v 1.89 2013/02/18 18:31:09 christos Exp $
#
MAGIC_FRAGMENT_BASE = magdir
MAGIC_DIR = $(top_srcdir)/magic
@ -250,6 +249,7 @@ $(MAGIC_FRAGMENT_DIR)/alliant \
$(MAGIC_FRAGMENT_DIR)/amanda \
$(MAGIC_FRAGMENT_DIR)/amigaos \
$(MAGIC_FRAGMENT_DIR)/animation \
$(MAGIC_FRAGMENT_DIR)/aout \
$(MAGIC_FRAGMENT_DIR)/apl \
$(MAGIC_FRAGMENT_DIR)/apple \
$(MAGIC_FRAGMENT_DIR)/applix \
@ -317,9 +317,10 @@ $(MAGIC_FRAGMENT_DIR)/gcc \
$(MAGIC_FRAGMENT_DIR)/geo \
$(MAGIC_FRAGMENT_DIR)/geos \
$(MAGIC_FRAGMENT_DIR)/gimp \
$(MAGIC_FRAGMENT_DIR)/gnome-keyring \
$(MAGIC_FRAGMENT_DIR)/gnome \
$(MAGIC_FRAGMENT_DIR)/gnu \
$(MAGIC_FRAGMENT_DIR)/gnumeric \
$(MAGIC_FRAGMENT_DIR)/gpt \
$(MAGIC_FRAGMENT_DIR)/grace \
$(MAGIC_FRAGMENT_DIR)/graphviz \
$(MAGIC_FRAGMENT_DIR)/gringotts \
@ -329,6 +330,7 @@ $(MAGIC_FRAGMENT_DIR)/hp \
$(MAGIC_FRAGMENT_DIR)/human68k \
$(MAGIC_FRAGMENT_DIR)/ibm370 \
$(MAGIC_FRAGMENT_DIR)/ibm6000 \
$(MAGIC_FRAGMENT_DIR)/icc \
$(MAGIC_FRAGMENT_DIR)/iff \
$(MAGIC_FRAGMENT_DIR)/images \
$(MAGIC_FRAGMENT_DIR)/inform \

View File

@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
# $File: apple,v 1.26 2012/12/27 15:43:23 christos Exp $
# $File: apple,v 1.27 2013/03/09 22:36:00 christos Exp $
# apple: file(1) magic for Apple file formats
#
0 search/1/t FiLeStArTfIlEsTaRt binscii (apple ][) text
@ -106,8 +106,13 @@
# This is incredibly sloppy, but will be true if the program was
# written at its usual memory location of 2048 and its first line
# number is less than 256. Yuck.
# update by Joerg Jenderek at Feb 2013
0 belong&0xff00ff 0x80000 Applesoft BASIC program data
# GRR: this test is still too general as it catches also Gujin BOOT144.SYS (0xfa080000)
#0 belong&0xff00ff 0x80000 Applesoft BASIC program data
0 belong&0x00ff00ff 0x00080000
# assuming that line number must be positive
>2 leshort >0 Applesoft BASIC program data, first line number %d
#>2 leshort x \b, first line number %d
# ORCA/EZ assembler:

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# $File: archive,v 1.73 2012/11/09 22:59:30 christos Exp $
# $File: archive,v 1.79 2013/02/08 17:24:06 christos Exp $
# archive: file(1) magic for archive formats (see also "msdos" for self-
# extracting compressed archives)
#
@ -36,7 +36,60 @@
0 string 070701 ASCII cpio archive (SVR4 with no CRC)
0 string 070702 ASCII cpio archive (SVR4 with CRC)
# Debian package (needs to go before regular portable archives)
#
# Various archive formats used by various versions of the "ar"
# command.
#
#
# Original UNIX archive formats.
# They were written with binary values in host byte order, and
# the magic number was a host "int", which might have been 16 bits
# or 32 bits. We don't say "PDP-11" or "VAX", as there might have
# been ports to little-endian 16-bit-int or 32-bit-int platforms
# (x86?) using some of those formats; if none existed, feel free
# to use "PDP-11" for little-endian 16-bit and "VAX" for little-endian
# 32-bit. There might have been big-endian ports of that sort as
# well.
#
0 leshort 0177555 very old 16-bit-int little-endian archive
0 beshort 0177555 very old 16-bit-int big-endian archive
0 lelong 0177555 very old 32-bit-int little-endian archive
0 belong 0177555 very old 32-bit-int big-endian archive
0 leshort 0177545 old 16-bit-int little-endian archive
>2 string __.SYMDEF random library
0 beshort 0177545 old 16-bit-int big-endian archive
>2 string __.SYMDEF random library
0 lelong 0177545 old 32-bit-int little-endian archive
>4 string __.SYMDEF random library
0 belong 0177545 old 32-bit-int big-endian archive
>4 string __.SYMDEF random library
#
# From "pdp" (but why a 4-byte quantity?)
#
0 lelong 0x39bed PDP-11 old archive
0 lelong 0x39bee PDP-11 4.0 archive
#
# XXX - what flavor of APL used this, and was it a variant of
# some ar archive format? It's similar to, but not the same
# as, the APL workspace magic numbers in pdp.
#
0 long 0100554 apl workspace
#
# System V Release 1 portable(?) archive format.
#
0 string =<ar> System V Release 1 ar archive
!:mime application/x-archive
#
# Debian package; it's in the portable archive format, and needs to go
# before the entry for regular portable archives, as it's recognized as
# a portable archive whose first member has a name beginning with
# "debian".
#
0 string =!<arch>\ndebian
!:mime application/x-debian-package
@ -53,23 +106,14 @@
#>84 string gz \b, uses gzip compression
#>136 ledate x created: %s
0 string =!<thin>\n thin archive with
>68 belong 0 no symbol entries
>68 belong 1 %d symbol entry
>68 belong >1 %d symbol entries
# other archives
0 long 0177555 very old archive
0 short 0177555 very old PDP-11 archive
0 long 0177545 old archive
0 short 0177545 old PDP-11 archive
0 long 0100554 apl workspace
0 string =<ar> archive
!:mime application/x-archive
# MIPS archive (needs to go before regular portable archives)
#
# MIPS archive; they're in the portable archive format, and need to go
# before the entry for regular portable archives, as it's recognized as
# a portable archive whose first member has a name beginning with
# "__________E".
#
0 string =!<arch>\n__________E MIPS archive
!:mime application/x-archive
>20 string U with MIPS Ucode members
>21 string L with MIPSEL members
>21 string B with MIPSEB members
@ -80,56 +124,20 @@
0 search/1 -h- Software Tools format archive text
#
# XXX - why are there multiple <ar> thingies? Note that 0x213c6172 is
# "!<ar", so, for new-style (4.xBSD/SVR2andup) archives, we have:
#
# 0 string =!<arch> current ar archive
# 0 long 0x213c6172 archive file
#
# and for SVR1 archives, we have:
#
# 0 string \<ar> System V Release 1 ar archive
# 0 string =<ar> archive
#
# XXX - did Aegis really store shared libraries, breakpointed modules,
# and absolute code program modules in the same format as new-style
# "ar" archives?
# BSD/SVR2-and-later portable archive formats.
#
0 string =!<arch> current ar archive
!:mime application/x-archive
>8 string __.SYMDEF random library
>0 belong =65538 - pre SR9.5
>0 belong =65539 - post SR9.5
>0 beshort 2 - object archive
>0 beshort 3 - shared library module
>0 beshort 4 - debug break-pointed module
>0 beshort 5 - absolute code program module
0 string \<ar> System V Release 1 ar archive
0 string =<ar> archive
>68 string __.SYMDEF\ SORTED random library
#
# XXX - from "vax", which appears to collect a bunch of byte-swapped
# thingies, to help you recognize VAX files on big-endian machines;
# with "leshort", "lelong", and "string", that's no longer necessary....
# "Thin" archive, as can be produced by GNU ar.
#
0 belong 0x65ff0000 VAX 3.0 archive
0 belong 0x3c61723e VAX 5.0 archive
#
0 long 0x213c6172 archive file
0 lelong 0177555 very old VAX archive
0 leshort 0177555 very old PDP-11 archive
#
# XXX - "pdp" claims that 0177545 can have an __.SYMDEF member and thus
# be a random library (it said 0xff65 rather than 0177545).
#
0 lelong 0177545 old VAX archive
>8 string __.SYMDEF random library
0 leshort 0177545 old PDP-11 archive
>8 string __.SYMDEF random library
#
# From "pdp" (but why a 4-byte quantity?)
#
0 lelong 0x39bed PDP-11 old archive
0 lelong 0x39bee PDP-11 4.0 archive
0 string =!<thin>\n thin archive with
>68 belong 0 no symbol entries
>68 belong 1 %d symbol entry
>68 belong >1 %d symbol entries
# ARC archiver, from Daniel Quinlan (quinlan@yggdrasil.com)
#
@ -189,7 +197,10 @@
# SAR
3 string LH5 SAR archive data
# BSArc/BS2
0 string \212\3SB \0 BSArc/BS2 archive data
0 string \212\3SB\020\0 BSArc/BS2 archive data
# Bethesda Softworks Archive (Oblivion)
0 string BSA\0 BSArc archive data
>4 lelong x version %d
# MAR
2 string =-ah MAR archive data
# ACB
@ -214,7 +225,7 @@
# AMGC
0 string \xad6" AMGC archive data
# NuLIB
0 string NõFélå NuLIB archive data
0 string N\xc3\xb5F\xc3\xa9lx\xc3\xa5 NuLIB archive data
# PakLeo
0 string LEOLZW PAKLeo archive data
# ChArc
@ -226,7 +237,7 @@
# Freeze
0 string \x1f\x9f\x4a\x10\x0a Freeze archive data
# KBoom
0 string ¨MP¨ KBoom archive data
0 string \xc2\xa8MP\xc2\xa8 KBoom archive data
# NSQ, must go after CDC Codec
0 string \x76\xff NSQ archive data
# DPA
@ -264,7 +275,7 @@
# MP3 (archiver, not lossy audio compression)
0 string MP3\x1a MP3-Archiver archive data
# ZET
0 string OZÝ ZET archive data
0 string OZ\xc3\x9d ZET archive data
# TSComp
0 string \x65\x5d\x13\x8c\x08\x01\x03\x00 TSComp archive data
# ARQ
@ -295,7 +306,7 @@
# Xtreme
0 string ULEB\0 Xtreme archive data
# Pack Magic
0 string @â\1\0 Pack Magic archive data
0 string @\xc3\xa2\1\0 Pack Magic archive data
# BTS
0 belong&0xfeffffff 0x1a034465 BTS archive data
# ELI 5750
@ -431,7 +442,7 @@
# XPack Data
0 string xpa XPack archive data
# XPack Single Data
0 string Í\ jm XPack single archive data
0 string \xc3\x8d\ jm XPack single archive data
# TODO: missing due to unknown magic/magic at end of file:
#DWC
@ -666,11 +677,10 @@
!:mime application/vnd.oasis.opendocument.image-template
# EPUB (OEBPS) books using OCF (OEBPS Container Format)
# From: Adam Buchbinder <adam.buchbinder@gmail.com>
# http://www.idpf.org/ocf/ocf1.0/download/ocf10.htm, section 4.
# (mimetype contains "application/epub+zip")
>>50 string epub+zip EPUB ebook data
!:mime application/epub+zip
# From: Ralf Brown <ralf.brown@gmail.com>
>0x1E string mimetypeapplication/epub+zip EPUB document
!:mime application/epub+zip
# Catch other ZIP-with-mimetype formats
# In a ZIP file, the bytes immediately after a member's contents are
@ -895,14 +905,8 @@
# archive must be an uncompressed file called 'mimetype' with contents
# 'application/epub+zip'
# start by checking that this is a ZIP archive, then check for the
# proper mimetype file
# From: Ralf Brown <ralf.brown@gmail.com>
0 string PK\003\004
>0x1E string mimetypeapplication/epub+zip EPUB document
!:mime application/epub+zip
# From: "Michał Górny" <mgorny@gentoo.org>
# From: "Michael Gorny" <mgorny@gentoo.org>
# ZPAQ: http://mattmahoney.net/dc/zpaq.html
0 string zPQ ZPAQ stream
>3 byte x \b, level %d

View File

@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# $File: assembler,v 1.2 2012/10/31 18:41:42 christos Exp $
# $File: assembler,v 1.4 2013/01/04 23:31:11 christos Exp $
# make: file(1) magic for assembler source
#
0 regex \^[\020\t]*\\.asciiz assembler source text

View File

@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
# $File: elf,v 1.58 2012/11/06 20:43:52 christos Exp $
# $File: elf,v 1.59 2013/03/21 17:50:02 christos Exp $
# elf: file(1) magic for ELF executables
#
# We have to check the byte order flag to see what byte order all the
@ -17,7 +17,6 @@
0 name elf-le
>16 leshort 0 no file type,
!:strength *2
!:mime application/octet-stream
>16 leshort 1 relocatable,
!:mime application/x-object
@ -185,6 +184,7 @@
>20 lelong 1 version 1
0 string \177ELF ELF
!:strength *2
>4 byte 0 invalid class
>4 byte 1 32-bit
>4 byte 2 64-bit

View File

@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
# $File: filesystems,v 1.69 2012/12/18 17:28:43 christos Exp $
# $File: filesystems,v 1.77 2013/03/14 01:38:30 christos Exp $
# filesystems: file(1) magic for different filesystems
#
0 string \366\366\366\366 PC formatted floppy with no filesystem
@ -60,8 +60,9 @@
# x86 boot sector updated by Joerg Jenderek at Sep 2007,May 2011
# for any allowed sector sizes
30 search/481 \x55\xAA
# to display x86 boot sector (40) before old one (strength=50), SYSLINUX MBR (?) and DOS BPB information (71) like in previous file version
!:strength +40
# to display x86 boot sector (40) before old one (strength=50+21),Syslinux bootloader (71),SYSLINUX MBR (37+36),NetBSD mbr (110),AdvanceMAME mbr (111)
# DOS BPB information (70) and after DOS floppy (120) like in previous file version
!:strength +72
# for sector sizes < 512 Bytes
>11 uleshort <512
>>(11.s-2) uleshort 0xAA55 x86 boot sector
@ -70,11 +71,158 @@
# keep old x86 boot sector as dummy for mbr and bootloader displaying
# only for sector sizes with 512 or more Bytes
0x1FE leshort 0xAA55
# to display information (51) before DOS BPB (strength=71) and after DOS floppy (120) like in old file version
# to display information (50) before DOS BPB (strength=70) and after DOS floppy (120) like in old file version
!:strength +21
>2 string OSBS \b, OS/BS MBR
# J\xf6rg Jenderek <joerg dot jenderek at web dot de>
>0x8C string Invalid\ partition\ table \b, MS-DOS MBR
# added by Joerg Jenderek at Feb 2013 according to http://thestarman.pcministry.com/asm/mbr/
# and http://en.wikipedia.org/wiki/Master_Boot_Record
# test for nearly all MS-DOS Master Boot Record initial program loader (IPL) is now done by
# characteristic assembler instructions: xor ax,ax;mov ss,ax;mov sp,7c00
>0 search/2 \x33\xc0\x8e\xd0\xbc\x00\x7c MS-MBR
# Microsoft Windows 95A and early ( http://thestarman.pcministry.com/asm/mbr/STDMBR.htm )
# assembler instructions: mov si,sp;push ax;pop es;push ax;pop ds;sti;cld
>>8 ubequad 0x8bf45007501ffbfc
# http://thestarman.pcministry.com/asm/mbr/200MBR.htm
>>>0x16 ubyte 0xF3 \b,DOS 2
>>>>219 regex Author\ -\ Author:
# found "David Litton" , "A Pehrsson "
>>>>>&0 string x "%s"
>>>0x16 ubyte 0xF2
# NEC MS-DOS 3.30 Rev. 3 . See http://thestarman.pcministry.com/asm/mbr/DOS33MBR.htm
# assembler instructions: mov di,077c;cmp word ptrl[di],a55a;jnz
>>>>0x22 ubequad 0xbf7c07813d5aa575 \b,NEC 3.3
# version MS-DOS 3.30 til MS-Windows 95A (WinVer=4.00.1111)
>>>>0x22 default x \b,D0S version 3.3-7.0
# error messages are printed by assembler instructions: mov si,06nn;...;int 10 (0xBEnn06;...)
# where nn is string offset varying for different languages
# "Invalid partition table" nn=0x8b for english version
>>>>>(0x49.b) string Invalid\ partition\ table english
>>>>>(0x49.b) string Ung\201ltige\ Partitionstabelle german
>>>>>(0x49.b) string Table\ de\ partition\ invalide french
>>>>>(0x49.b) string Tabela\ de\ parti\207ao\ inv\240lida portuguese
>>>>>(0x49.b) string Tabla\ de\ partici\242n\ no\ v\240lida spanish
>>>>>(0x49.b) string Tavola\ delle\ partizioni\ non\ valida italian
>>>>>0x49 ubyte >0 at offset 0x%x
>>>>>>(0x49.b) string >\0 "%s"
# "Error loading operating system" nn=0xa3 for english version
# "Fehler beim Laden des Betriebssystems" nn=0xa7 for german version
# "Erreur en chargeant syst\212me d'exploitation" nn=0xa7 for french version
# "Erro na inicializa\207ao do sistema operacional" nn=0xa7 for portuguese Brazilian version
# "Error al cargar sistema operativo" nn=0xa8 for spanish version
# "Errore durante il caricamento del sistema operativo" nn=0xae for italian version
>>>>>0x74 ubyte >0 at offset 0x%x
>>>>>>(0x74.b) string >\0 "%s"
# "Missing operating system" nn=0xc2 for english version
# "Betriebssystem fehlt" nn=0xcd for german version
# "Syst\212me d'exploitation absent" nn=0xd2 for french version
# "Sistema operacional nao encontrado" nn=0xd4 for portuguese Brazilian version
# "Falta sistema operativo" nn=0xca for spanish version
# "Sistema operativo mancante" nn=0xe2 for italian version
>>>>>0x79 ubyte >0 at offset 0x%x
>>>>>>(0x79.b) string >\0 "%s"
# Microsoft Windows 95B to XP (http://thestarman.pcministry.com/asm/mbr/95BMEMBR.htm)
# assembler instructions: push ax;pop es;push ax;pop ds;cld;mov si,7c1b
>>8 ubequad 0x5007501ffcbe1b7c
# assembler instructions: rep;movsb;retf;mov si,07be;mov cl,04
>>>24 ubequad 0xf3a4cbbebe07b104 9M
# "Invalid partition table" nn=0x10F for english version
# "Ungültige Partitionstabelle" nn=0x10F for german version
# "Table de partition erronée" nn=0x10F for french version
# "\216\257\245\340\240\346\250\256\255\255\240\357 \341\250\341\342\245\254\240 \255\245 \255\240\251\244\245\255\240" nn=0x10F for russian version
>>>>(0x3C.b+0x0FF) string Invalid\ partition\ table english
>>>>(0x3C.b+0x0FF) string Ung\201ltige\ Partitionstabelle german
>>>>(0x3C.b+0x0FF) string Table\ de\ partition\ erron\202e french
>>>>(0x3C.b+0x0FF) string \215\245\257\340\240\242\250\253\354\255\240\357\ \342\240\241\253\250\346\240 russian
>>>>0x3C ubyte x at offset 0x%x+0xFF
>>>>(0x3C.b+0x0FF) string >\0 "%s"
# "Error loading operating system" nn=0x127 for english version
# "Fehler beim Laden des Betriebssystems" nn=0x12b for german version
# "Erreur lors du chargement du système d'exploitation" nn=0x12a for french version
# "\216\350\250\241\252\240 \257\340\250 \247\240\243\340\343\247\252\245 \256\257\245\340\240\346\250\256\255\255\256\251 \341\250\341\342\245\254\353" nn=0x12d for russian version
>>>>0xBD ubyte x at offset 0x1%x
>>>>(0xBD.b+0x100) string >\0 "%s"
# "Missing operating system" nn=0x146 for english version
# "Betriebssystem fehlt" nn=0x151 for german version
# "Système d'exploitation manquant" nn=0x15e for french version
# "\216\257\245\340\240\346\250\256\255\255\240\357 \341\250\341\342\245\254\240 \255\245 \255\240\251\244\245\255\240" nn=0x156 for russian version
>>>>0xA9 ubyte x at offset 0x1%x
>>>>(0xA9.b+0x100) string >\0 "%s"
# http://thestarman.pcministry.com/asm/mbr/Win2kmbr.htm
# assembler instructions: rep;movsb;retf;mov BP,07be;mov cl,04
>>>24 ubequad 0xf3a4cbbdbe07b104 XP
# where xxyyzz are lower bits from offsets of error messages varying for different languages
>>>>0x1B4 ubelong&0x00FFFFFF 0x002c4463 english
>>>>0x1B4 ubelong&0x00FFFFFF 0x002c486e german
# "Invalid partition table" xx=0x12C for english version
# "Ungültige Partitionstabelle" xx=0x12C for german version
>>>>0x1b5 ubyte >0 at offset 0x1%x
>>>>(0x1b5.b+0x100) string >\0 "%s"
# "Error loading operating system" yy=0x144 for english version
# "Fehler beim Laden des Betriebssystems" yy=0x148 for german version
>>>>0x1b6 ubyte >0 at offset 0x1%x
>>>>(0x1b6.b+0x100) string >\0 "%s"
# "Missing operating system" zz=0x163 for english version
# "Betriebssystem nicht vorhanden" zz=0x16e for german version
>>>>0x1b7 ubyte >0 at offset 0x1%x
>>>>(0x1b7.b+0x100) string >\0 "%s"
# Microsoft Windows Vista or 7
# assembler instructions: ..;mov ds,ax;mov si,7c00;mov di,..00
>>8 ubequad 0xc08ed8be007cbf00
# Microsoft Windows Vista (http://thestarman.pcministry.com/asm/mbr/VistaMBR.htm)
# assembler instructions: jnz 0729;cmp ebx,"TCPA"
>>>0xEC ubequad 0x753b6681fb544350 Vista
# where xxyyzz are lower bits from offsets of error messages varying for different languages
>>>>0x1B4 ubelong&0x00FFFFFF 0x00627a99 english
#>>>>0x1B4 ubelong&0x00FFFFFF ? german
# "Invalid partition table" xx=0x162 for english version
# "Ungültige Partitionstabelle" xx=0x1?? for german version
>>>>0x1b5 ubyte >0 at offset 0x1%x
>>>>(0x1b5.b+0x100) string >\0 "%s"
# "Error loading operating system" yy=0x17a for english version
# "Fehler beim Laden des Betriebssystems" yy= 0x1?? for german version
>>>>0x1b6 ubyte >0 at offset 0x1%x
>>>>(0x1b6.b+0x100) string >\0 "%s"
# "Missing operating system" zz=0x199 for english version
# "Betriebssystem nicht vorhanden" zz=0x1?? for german version
>>>>0x1b7 ubyte >0 at offset 0x1%x
>>>>(0x1b7.b+0x100) string >\0 "%s"
# Microsoft Windows 7 (http://thestarman.pcministry.com/asm/mbr/W7MBR.htm)
# assembler instructions: cmp ebx,"TCPA";cmp
>>>0xEC ubequad 0x6681fb5443504175 Windows 7
# where xxyyzz are lower bits from offsets of error messages varying for different languages
>>>>0x1B4 ubelong&0x00FFFFFF 0x00637b9a english
#>>>>0x1B4 ubelong&0x00FFFFFF ? german
# "Invalid partition table" xx=0x163 for english version
# "Ungültige Partitionstabelle" xx=0x1?? for german version
>>>>0x1b5 ubyte >0 at offset 0x1%x
>>>>(0x1b5.b+0x100) string >\0 "%s"
# "Error loading operating system" yy=0x17b for english version
# "Fehler beim Laden des Betriebssystems" yy=0x1?? for german version
>>>>0x1b6 ubyte >0 at offset 0x1%x
>>>>(0x1b6.b+0x100) string >\0 "%s"
# "Missing operating system" zz=0x19a for english version
# "Betriebssystem nicht vorhanden" zz=0x1?? for german version
>>>>0x1b7 ubyte >0 at offset 0x1%x
>>>>(0x1b7.b+0x100) string >\0 "%s"
# http://thestarman.pcministry.com/asm/mbr/Win2kmbr.htm#DiskSigs
# http://en.wikipedia.org/wiki/MBR_disk_signature#ID
>>0x1b8 ulelong >0 \b, disk signature 0x%-.4x
# driveID/timestamp for Win 95B,98,98SE and ME. See http://thestarman.pcministry.com/asm/mbr/mystery.htm
>>0xDA uleshort 0
>>>0xDC ulelong >0 \b, created
# physical drive number (0x80-0xFF) when the Windows wrote that byte to the drive
>>>>0xDC ubyte x with driveID 0x%x
# hours, minutes and seconds
>>>>0xDf ubyte x at %x
>>>>0xDe ubyte x \b:%x
>>>>0xDd ubyte x \b:%x
# special case for Microsoft MS-DOS 3.21 spanish
# assembler instructions: cli;mov $0x30,%ax;mov %ax,%ss;mov
>0 ubequad 0xfab830008ed0bc00
# assembler instructions: $0x1f00,%sp;mov $0x80cb,%di;add %cl,(%bx,%si);in (%dx),%ax;mov
>>8 ubequad 0x1fbfcb800008ed8 MS-MBR,D0S version 3.21 spanish
# Microsoft MBR IPL end
# dr-dos with some upper-, lowercase variants
>0x9D string Invalid\ partition\ table$
>>181 string No\ Operating\ System$
@ -93,30 +241,9 @@
>>>>>>358 string Press\ any\ key\ to\ continue.\n\r$
>>>>>>>387 string Copyright\ (c)\ 1984,1998
>>>>>>>>411 string Caldera\ Inc.\0 \b, DR-DOS MBR (IBMBIO.LDR)
>0x10F string Ung\201ltige\ Partitionstabelle \b, MS-DOS MBR, german version 4.10.1998, 4.10.2222
>>0x1B8 ubelong >0 \b, Serial 0x%-.4x
>0x8B string Ung\201ltige\ Partitionstabelle \b, MS-DOS MBR, german version 5.00 to 4.00.950
>271 string Invalid\ partition\ table\0
>>295 string Error\ loading\ operating\ system\0
>>>326 string Missing\ operating\ system\0 \b, mbr
#
>139 string Invalid\ partition\ table\0
>>163 string Error\ loading\ operating\ system\0
>>>194 string Missing\ operating\ system\0 \b, Microsoft Windows XP mbr
# http://www.heise.de/ct/05/09/006/ page 184
#HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices\DosDevices\?:=Serial4Bytes+8Bytes
>>>>0x1B8 ulelong >0 \b,Serial 0x%-.4x
>300 string Invalid\ partition\ table\0
>>324 string Error\ loading\ operating\ system\0
>>>355 string Missing\ operating\ system\0 \b, Microsoft Windows XP MBR
#??>>>389 string Invalid\ system\ disk
>>>>0x1B8 ulelong >0 \b, Serial 0x%-.4x
>300 string Ung\201ltige\ Partitionstabelle
#split string to avoid error: String too long
>>328 string Fehler\ beim\ Laden\
>>>346 string des\ Betriebssystems
>>>>366 string Betriebssystem\ nicht\ vorhanden \b, Microsoft Windows XP MBR (german)
>>>>>0x1B8 ulelong >0 \b, Serial 0x%-.4x
# tests for different MS-DOS Master Boot Records (MBR) moved and merged
#
#>0x145 string Default:\ F \b, FREE-DOS MBR
#>0x14B string Default:\ F \b, FREE-DOS 1.0 MBR
>0x145 search/7 Default:\ F \b, FREE-DOS MBR
@ -290,7 +417,7 @@
>242 string Bootsector\ from\ C.H.\ Hochst\204
# http://freecode.com/projects/dosfstools dosfstools-n.m/src/mkdosfs.c
# updated by Joerg Jenderek at Nov 2012. Use search directive with offset instead of string
# skip name "C.H. Hochstätter" partly because it is sometimes written without umlaut
# skip name "C.H. Hochstaetter" partly because it is sometimes written without umlaut
>242 search/127 Bootsector\ from\ C.H.\ Hochst
>>278 search/127 No\ Systemdisk.\ Booting\ from\ harddisk
# followed by variants with point,CR-NL or NL-CR
@ -787,6 +914,14 @@
>>>>>495 string RENF \b, FAT (16 bit)
# x86 bootloader end
# added by Joerg Jenderek at Feb 2013 according to http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm#FSINFO
# and http://en.wikipedia.org/wiki/File_Allocation_Table#FS_Information_Sector
>0 string RRaA
>>0x1E4 string rrAa \b, FSInfosector
#>>0x1FC uleshort =0 SHOULD BE ZERO
>>>0x1E8 ulelong <0xffffffff \b, %u free clusters
>>>0x1EC ulelong <0xffffffff \b, last allocated cluster %u
# added by Joerg Jenderek at Nov 2012
# http://www.thenakedpc.com/articles/v04/08/0408-05.html
# Symantec (Peter Norton) Image.dat file consists of variable header, bootrecord, part of FAT and root directory data
@ -865,6 +1000,8 @@
# SYSLINUX MBR updated and separated from "x86 boot sector" by Joerg Jenderek at Sep 2012
# assembler instructions: mov di,0600h;mov cx,0100h
16 search/4 \xbf\x00\x06\xb9\x00\x01
# to display SYSLINUX MBR (36) before old x86 boot sector one with partition table (strength=50+21)
!:strength +36
>94 search/249 Missing\ operating\ system
# followed by \r for versions older 3.35 , .\r for versions newer 3.52 and point for other
# skip Ranish MBR
@ -1184,7 +1321,17 @@
#>>>>>>>>>80 ulelong =0 \b, checksum 0x%x=0 (usual)
>>>>>>>>>0x258 ulelong&0x00009090 =0x00009090
>>>>>>>>>>&-92 indirect x \b; contains
### DOS boot sector end
# For 2nd NTFS sector added by Joerg Jenderek at Jan 2013
# http://thestarman.pcministry.com/asm/mbr/NTFSbrHexEd.htm
# unused assembler instructions JMP y2;NOP;NOP
0x056 ulelong&0xFFFF0FFF 0x909002EB
# unicode loadername terminated by CTRL-D
>(0.s*2) ulelong&0xFFFFFF00 0x00040000
# loadernames are NTLDR,CMLDR,PELDR,$LDR$ or BOOTMGR
>>0x002 lestring16 x Microsoft Windows XP/VISTA bootloader %-5.5s
>>0x12 string $
>>>0x0c lestring16 x \b%-2.2s
### DOS,NTFS boot sectors end
9564 lelong 0x00011954 Unix Fast File system [v1] (little-endian),
>8404 string x last mounted on %s,
@ -1351,32 +1498,40 @@
# Minix filesystems - Juan Cespedes <cespedes@debian.org>
0x410 leshort 0x137f
!:strength / 2
>0x402 beshort < 100 Minix filesystem, V1, %d zones
>0x402 beshort < 100
>0x402 beshort > -1 Minix filesystem, V1, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x137f
!:strength / 2
>0x402 beshort < 100 Minix filesystem, V1 (big endian), %d zones
>0x402 beshort < 100
>0x402 beshort > -1 Minix filesystem, V1 (big endian), %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x138f
!:strength / 2
>0x402 beshort < 100 Minix filesystem, V1, 30 char names, %d zones
>0x402 beshort < 100
>0x402 beshort > -1 Minix filesystem, V1, 30 char names, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x138f
!:strength / 2
>0x402 beshort < 100 Minix filesystem, V1, 30 char names (big endian), %d zones
>0x402 beshort < 100
>0x402 beshort > -1 Minix filesystem, V1, 30 char names (big endian), %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x2468
>0x402 beshort < 100 Minix filesystem, V2, %d zones
>0x402 beshort < 100
>>0x402 beshort > -1 Minix filesystem, V2, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x2468
>0x402 beshort < 100 Minix filesystem, V2 (big endian), %d zones
>0x402 beshort < 100
>0x402 beshort > -1 Minix filesystem, V2 (big endian), %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x2478
>0x402 beshort < 100 Minix filesystem, V2, 30 char names, %d zones
>0x402 beshort < 100
>0x402 beshort > -1 Minix filesystem, V2, 30 char names, %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x2478
>0x402 beshort < 100 Minix filesystem, V2, 30 char names, %d zones
>0x402 beshort < 100
>0x402 beshort > -1 Minix filesystem, V2, 30 char names, %d zones
>0x1e string minix \b, bootable
0x410 beshort 0x2478
>0x402 beshort !0 Minix filesystem, V2, 30 char names (big endian), %d zones
@ -1454,8 +1609,8 @@
# 10 SS, 8 SPT
# 11 DS, 8 SPT
#
# 11111001 Double density 3½ floppy disk, high density 5¼
# 11110000 High density 3½ floppy disk
# 11111001 Double density 3 1/2 floppy disk, high density 5 1/4
# 11110000 High density 3 1/2 floppy disk
# 11111000 Hard disk any format
#
@ -1642,8 +1797,6 @@
>28 leshort >3
>>8 ledate x created: %s
0 string td\000 floppy image data (TeleDisk)
# AFS Dump Magic
# From: Ty Sarna <tsarna@sarna.org>
0 string \x01\xb3\xa1\x13\x22 AFS Dump
@ -1820,3 +1973,18 @@
>60 lelong x \b address of last segment written 0x%x,
>64 lelong x \b address of next segment to write 0x%x,
>68 lelong x \b address of current segment written 0x%x
0 string td\000 floppy image data (TeleDisk, compressed)
0 string TD\000 floppy image data (TeleDisk)
0 string CQ\024 floppy image data (CopyQM,
>16 leshort x %d sectors,
>18 leshort x %d heads.)
0 string ACT\020Apricot\020disk\020image\032\004 floppy image data (ApriDisk)
0 beshort 0xAA58 floppy image data (IBM SaveDskF, old)
0 beshort 0xAA59 floppy image data (IBM SaveDskF)
0 beshort 0xAA5A floppy image data (IBM SaveDskF, compressed)
0 string \074CPM_Disk\076 disk image data (YAZE)

View File

@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
# $File: geo,v 1.2 2013/01/02 15:27:53 christos Exp $
# $File: geo,v 1.3 2013/01/04 00:47:02 christos Exp $
# Geo- files from Kurt Schwehr <schwehr@ccom.unh.edu>
######################################################################

View File

@ -1,26 +0,0 @@
#------------------------------------------------------------------------------
# $File: gnome-keyring,v 1.3 2012/06/21 01:19:51 christos Exp $
# GNOME keyring
# Contributed by Josh Triplett
# FIXME: Could be simplified if pstring supported two-byte counts
0 string GnomeKeyring\n\r\0\n GNOME keyring
>&0 ubyte 0 \b, major version 0
>>&0 ubyte 0 \b, minor version 0
>>>&0 ubyte 0 \b, crypto type 0 (AES)
>>>&0 ubyte >0 \b, crypto type %hhu (unknown)
>>>&1 ubyte 0 \b, hash type 0 (MD5)
>>>&1 ubyte >0 \b, hash type %hhu (unknown)
>>>&2 ubelong 0xFFFFFFFF \b, name NULL
>>>&2 ubelong !0xFFFFFFFF
>>>>&-4 ubelong >255 \b, name too long for file's pstring type
>>>>&-4 ubelong <256
>>>>>&-1 pstring x \b, name "%s"
>>>>>>&0 ubeqdate x \b, last modified %s
>>>>>>&8 ubeqdate x \b, created %s
>>>>>>&16 ubelong &1
>>>>>>>&0 ubelong x \b, locked if idle for %u seconds
>>>>>>&16 ubelong ^1 \b, not locked if idle
>>>>>>&24 ubelong x \b, hash iterations %u
>>>>>>&28 ubequad x \b, salt %llu
>>>>>>&52 ubelong x \b, %u item(s)

View File

@ -54,8 +54,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/visibility.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d

View File

@ -55,14 +55,13 @@ bin_PROGRAMS = file$(EXEEXT)
subdir = src
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(top_srcdir)/depcomp asctime_r.c \
asprintf.c ctime_r.c getline.c getopt_long.c strlcat.c \
asprintf.c ctime_r.c getline.c getopt_long.c pread.c strlcat.c \
strlcpy.c vasprintf.c
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/visibility.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@ -297,7 +296,12 @@ libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
libmagic_la_LIBADD = $(LTLIBOBJS) $(MINGWLIBS)
file_SOURCES = file.c
file_LDADD = libmagic.la
all: all-am
CLEANFILES = magic.h
EXTRA_DIST = magic.h.in
HDR = $(top_srcdir)/src/magic.h.in
BUILT_SOURCES = magic.h
all: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
@ -428,6 +432,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/ctime_r.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getline.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt_long.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/pread.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcat.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcpy.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/vasprintf.Plo@am__quote@
@ -596,7 +601,8 @@ distdir: $(DISTFILES)
fi; \
done
check-am: all-am
check: check-am
check: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) check-am
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS)
install-binPROGRAMS: install-libLTLIBRARIES
@ -604,7 +610,8 @@ installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
@ -626,6 +633,7 @@ install-strip:
mostlyclean-generic:
clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
@ -634,6 +642,7 @@ distclean-generic:
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
clean: clean-am
clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
@ -706,7 +715,7 @@ ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
uninstall-libLTLIBRARIES
.MAKE: install-am install-strip
.MAKE: all check install install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic clean-libLTLIBRARIES clean-libtool cscopelist \
@ -725,6 +734,9 @@ uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
uninstall-includeHEADERS uninstall-libLTLIBRARIES
magic.h: ${HDR}
sed -e "s/X.YY/$$(echo @VERSION@ | tr -d .)/" < ${HDR} > $@
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@ -1,4 +1,4 @@
/* $NetBSD: apprentice.c,v 1.8 2013/01/03 23:05:38 christos Exp $ */
/* $NetBSD: apprentice.c,v 1.9 2013/03/23 16:15:58 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -35,9 +35,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: apprentice.c,v 1.180 2012/11/21 16:27:07 christos Exp $")
FILE_RCSID("@(#)$File: apprentice.c,v 1.191 2013/02/26 21:02:48 christos Exp $")
#else
__RCSID("$NetBSD: apprentice.c,v 1.8 2013/01/03 23:05:38 christos Exp $");
__RCSID("$NetBSD: apprentice.c,v 1.9 2013/03/23 16:15:58 christos Exp $");
#endif
#endif /* lint */
@ -86,6 +86,13 @@ struct magic_entry {
uint32_t max_count;
};
struct magic_map {
void *p;
size_t len;
struct magic *magic[MAGIC_SETS];
uint32_t nmagic[MAGIC_SETS];
};
int file_formats[FILE_NAMES_SIZE];
const size_t file_nformats = FILE_NAMES_SIZE;
const char *file_names[FILE_NAMES_SIZE];
@ -102,7 +109,7 @@ private int apprentice_1(struct magic_set *, const char *, int);
private size_t apprentice_magic_strength(const struct magic *);
private int apprentice_sort(const void *, const void *);
private void apprentice_list(struct mlist *, int );
private int apprentice_load(struct magic_set *, struct magic **, uint32_t *,
private struct magic_map *apprentice_load(struct magic_set *,
const char *, int);
private struct mlist *mlist_alloc(void);
private void mlist_free(struct mlist *);
@ -112,9 +119,9 @@ private uint16_t swap2(uint16_t);
private uint32_t swap4(uint32_t);
private uint64_t swap8(uint64_t);
private char *mkdbname(struct magic_set *, const char *, int);
private int apprentice_map(struct magic_set *, struct magic **, uint32_t *,
const char *);
private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *,
private struct magic_map *apprentice_map(struct magic_set *, const char *);
private void apprentice_unmap(struct magic_map *);
private int apprentice_compile(struct magic_set *, struct magic_map *,
const char *);
private int check_format_type(const char *, int);
private int check_format(struct magic_set *, struct magic *);
@ -175,14 +182,24 @@ main(int argc, char *argv[])
}
#endif /* COMPILE_ONLY */
static const struct type_tbl_s {
struct type_tbl_s {
const char name[16];
const size_t len;
const int type;
const int format;
} type_tbl[] = {
};
/*
* XXX - the actual Single UNIX Specification says that "long" means "long",
* as in the C data type, but we treat it as meaning "4-byte integer".
* Given that the OS X version of file 5.04 did the same, I guess that passes
* the actual test; having "long" be dependent on how big a "long" is on
* the machine running "file" is silly.
*/
static const struct type_tbl_s type_tbl[] = {
# define XX(s) s, (sizeof(s) - 1)
# define XX_NULL "", 0
{ XX("invalid"), FILE_INVALID, FILE_FMT_NONE },
{ XX("byte"), FILE_BYTE, FILE_FMT_NUM },
{ XX("short"), FILE_SHORT, FILE_FMT_NUM },
{ XX("default"), FILE_DEFAULT, FILE_FMT_STR },
@ -227,19 +244,29 @@ static const struct type_tbl_s {
{ XX("qwdate"), FILE_QWDATE, FILE_FMT_STR },
{ XX("leqwdate"), FILE_LEQWDATE, FILE_FMT_STR },
{ XX("beqwdate"), FILE_BEQWDATE, FILE_FMT_STR },
{ XX("name"), FILE_NAME, FILE_FMT_NONE },
{ XX("use"), FILE_USE, FILE_FMT_NONE },
{ XX_NULL, FILE_INVALID, FILE_FMT_NONE },
};
/*
* These are not types, and cannot be preceded by "u" to make them
* unsigned.
*/
static const struct type_tbl_s special_tbl[] = {
{ XX("name"), FILE_NAME, FILE_FMT_STR },
{ XX("use"), FILE_USE, FILE_FMT_STR },
{ XX_NULL, FILE_INVALID, FILE_FMT_NONE },
};
# undef XX
# undef XX_NULL
};
private int
get_type(const char *l, const char **t)
get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
{
const struct type_tbl_s *p;
for (p = type_tbl; p->len; p++) {
for (p = tbl; p->len; p++) {
if (strncmp(l, p->name, p->len) == 0) {
if (t)
*t = l + p->len;
@ -249,6 +276,91 @@ get_type(const char *l, const char **t)
return p->type;
}
private int
get_standard_integer_type(const char *l, const char **t)
{
int type;
if (isalpha((unsigned char)l[1])) {
switch (l[1]) {
case 'C':
/* "dC" and "uC" */
type = FILE_BYTE;
break;
case 'S':
/* "dS" and "uS" */
type = FILE_SHORT;
break;
case 'I':
case 'L':
/*
* "dI", "dL", "uI", and "uL".
*
* XXX - the actual Single UNIX Specification says
* that "L" means "long", as in the C data type,
* but we treat it as meaning "4-byte integer".
* Given that the OS X version of file 5.04 did
* the same, I guess that passes the actual SUS
* validation suite; having "dL" be dependent on
* how big a "long" is on the machine running
* "file" is silly.
*/
type = FILE_LONG;
break;
case 'Q':
/* "dQ" and "uQ" */
type = FILE_QUAD;
break;
default:
/* "d{anything else}", "u{anything else}" */
return FILE_INVALID;
}
l += 2;
} else if (isdigit((unsigned char)l[1])) {
/*
* "d{num}" and "u{num}"; we only support {num} values
* of 1, 2, 4, and 8 - the Single UNIX Specification
* doesn't say anything about whether arbitrary
* values should be supported, but both the Solaris 10
* and OS X Mountain Lion versions of file passed the
* Single UNIX Specification validation suite, and
* neither of them support values bigger than 8 or
* non-power-of-2 values.
*/
if (isdigit((unsigned char)l[2])) {
/* Multi-digit, so > 9 */
return FILE_INVALID;
}
switch (l[1]) {
case '1':
type = FILE_BYTE;
break;
case '2':
type = FILE_SHORT;
break;
case '4':
type = FILE_LONG;
break;
case '8':
type = FILE_QUAD;
break;
default:
/* XXX - what about 3, 5, 6, or 7? */
return FILE_INVALID;
}
l += 2;
} else {
/*
* "d" or "u" by itself.
*/
type = FILE_LONG;
++l;
}
if (t)
*t = l;
return type;
}
private void
init_file_tables(void)
{
@ -264,19 +376,20 @@ init_file_tables(void)
file_names[p->type] = p->name;
file_formats[p->type] = p->format;
}
assert(p - type_tbl == FILE_NAMES_SIZE);
}
private int
add_mlist(struct mlist *mlp, struct magic *magic, uint32_t nmagic, int mapped)
add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
{
struct mlist *ml;
if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL)
return -1;
ml->magic = magic;
ml->nmagic = nmagic;
ml->mapped = mapped;
ml->map = idx == 0 ? map : NULL;
ml->magic = map->magic[idx];
ml->nmagic = map->nmagic[idx];
mlp->prev->next = ml;
ml->prev = mlp->prev;
@ -291,49 +404,38 @@ add_mlist(struct mlist *mlp, struct magic *magic, uint32_t nmagic, int mapped)
private int
apprentice_1(struct magic_set *ms, const char *fn, int action)
{
struct magic *magic[MAGIC_SETS] = { NULL };
uint32_t nmagic[MAGIC_SETS] = { 0 };
struct mlist *ml;
int rv = -1;
int mapped;
struct magic_map *map;
size_t i;
if (magicsize != FILE_MAGICSIZE) {
file_error(ms, 0, "magic element size %lu != %lu",
(unsigned long)sizeof(*magic[0]),
(unsigned long)sizeof(*map->magic[0]),
(unsigned long)FILE_MAGICSIZE);
return -1;
}
if (action == FILE_COMPILE) {
rv = apprentice_load(ms, magic, nmagic, fn, action);
if (rv != 0)
map = apprentice_load(ms, fn, action);
if (map == NULL)
return -1;
rv = apprentice_compile(ms, magic, nmagic, fn);
return rv;
return apprentice_compile(ms, map, fn);
}
#ifndef COMPILE_ONLY
if ((rv = apprentice_map(ms, magic, nmagic, fn)) < 0) {
if (rv == -2)
return -1;
map = apprentice_map(ms, fn);
if (map == NULL) {
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "using regular magic file `%s'", fn);
rv = apprentice_load(ms, magic, nmagic, fn, action);
if (rv != 0)
map = apprentice_load(ms, fn, action);
if (map == NULL)
return -1;
}
mapped = rv;
for (i = 0; i < MAGIC_SETS; i++) {
if (magic[i] == NULL)
continue;
if (add_mlist(ms->mlist[i], magic[i], nmagic[i], mapped) == -1)
{
i = i == 1 ? 0 : 1;
file_delmagic(magic[i], mapped, nmagic[i]);
if (add_mlist(ms->mlist[i], map, i) == -1) {
file_oomem(ms, sizeof(*ml));
apprentice_unmap(map);
return -1;
}
}
@ -398,38 +500,27 @@ free:
return NULL;
}
protected void
file_delmagic(struct magic *p, int type, size_t entries)
private void
apprentice_unmap(struct magic_map *map)
{
if (p == NULL)
if (map == NULL)
return;
if (map->p == NULL)
return;
switch (type) {
case 2:
#ifdef QUICK
p--;
(void)munmap((void *)p, sizeof(*p) * (entries + 1));
break;
#else
(void)&entries;
abort();
/*NOTREACHED*/
if (map->len)
(void)munmap(map->p, map->len);
else
#endif
case 1:
p--;
/*FALLTHROUGH*/
case 0:
free(p);
break;
default:
abort();
}
free(map->p);
free(map);
}
private struct mlist *
mlist_alloc(void)
{
struct mlist *mlist;
if ((mlist = CAST(struct mlist *, malloc(sizeof(*mlist)))) == NULL) {
if ((mlist = CAST(struct mlist *, calloc(1, sizeof(*mlist)))) == NULL) {
return NULL;
}
mlist->next = mlist->prev = mlist;
@ -446,8 +537,8 @@ mlist_free(struct mlist *mlist)
for (ml = mlist->next; ml != mlist;) {
struct mlist *next = ml->next;
struct magic *mg = ml->magic;
file_delmagic(mg, ml->mapped, ml->nmagic);
if (ml->map)
apprentice_unmap(ml->map);
free(ml);
ml = next;
}
@ -506,7 +597,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
mlist_free(ms->mlist[i]);
ms->mlist[i] = NULL;
}
file_error(ms, 0, "could not find any magic files!");
file_error(ms, 0, "could not find any valid magic files!");
return -1;
}
@ -1021,9 +1112,8 @@ magic_entry_free(struct magic_entry *me, uint32_t nme)
free(me);
}
private int
apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
const char *fn, int action)
private struct magic_map *
apprentice_load(struct magic_set *ms, const char *fn, int action)
{
int errs = 0;
struct magic_entry *mentry[MAGIC_SETS] = { NULL };
@ -1032,11 +1122,17 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
size_t files = 0, maxfiles = 0;
char **filearr = NULL, *mfn;
struct stat st;
struct magic_map *map;
DIR *dir;
struct dirent *d;
ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */
if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
file_oomem(ms, sizeof(*map));
return NULL;
}
/* print silly verbose header for USG compat. */
if (action == FILE_CHECK)
(void)fprintf(stderr, "%s\n", usg_hdr);
@ -1108,7 +1204,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
/* coalesce per file arrays into a single one */
if (coalesce_entries(ms, mentry[j], mentrycount[j],
&magicp[j], &nmagicp[j]) == -1) {
&map->magic[j], &map->nmagic[j]) == -1) {
errs++;
goto out;
}
@ -1120,15 +1216,13 @@ out:
if (errs) {
for (j = 0; j < MAGIC_SETS; j++) {
if (magicp[j]) {
free(magicp[j]);
magicp[j] = NULL;
}
nmagicp[j] = 0;
if (map->magic[j])
free(map->magic[j]);
}
return errs;
free(map);
return NULL;
}
return 0;
return map;
}
/*
@ -1377,9 +1471,13 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
char *t;
int op;
uint32_t cont_level;
int32_t diff;
cont_level = 0;
/*
* Parse the offset.
*/
while (*l == '>') {
++l; /* step over */
cont_level++;
@ -1392,9 +1490,19 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
#endif
if (cont_level != 0) {
if (me->mp == NULL) {
file_error(ms, 0, "No current entry for continuation");
file_magerror(ms, "No current entry for continuation");
return -1;
}
if (me->cont_count == 0) {
file_magerror(ms, "Continuations present with 0 count");
return -1;
}
m = &me->mp[me->cont_count - 1];
diff = (int32_t)cont_level - (int32_t)m->cont_level;
if (diff > 1)
file_magwarn(ms, "New continuation level %u is more "
"than one larger than current level %u", cont_level,
m->cont_level);
if (me->cont_count == me->max_count) {
struct magic *nm;
size_t cnt = me->max_count + ALLOC_CHUNK;
@ -1410,7 +1518,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
(void)memset(m, 0, sizeof(*m));
m->cont_level = cont_level;
} else {
size_t len = sizeof(*m) * ALLOC_CHUNK;
static const size_t len = sizeof(*m) * ALLOC_CHUNK;
if (me->mp != NULL)
return 1;
if ((m = CAST(struct magic *, malloc(len))) == NULL) {
@ -1548,12 +1656,54 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
EATAB;
#endif
if (*l == 'u' && (l[1] != 's' || l[2] != 'e')) {
++l;
m->flag |= UNSIGNED;
/*
* Parse the type.
*/
if (*l == 'u') {
/*
* Try it as a keyword type prefixed by "u"; match what
* follows the "u". If that fails, try it as an SUS
* integer type.
*/
m->type = get_type(type_tbl, l + 1, &l);
if (m->type == FILE_INVALID) {
/*
* Not a keyword type; parse it as an SUS type,
* 'u' possibly followed by a number or C/S/L.
*/
m->type = get_standard_integer_type(l, &l);
}
// It's unsigned.
if (m->type != FILE_INVALID)
m->flag |= UNSIGNED;
} else {
/*
* Try it as a keyword type. If that fails, try it as
* an SUS integer type if it begins with "d" or as an
* SUS string type if it begins with "s". In any case,
* it's not unsigned.
*/
m->type = get_type(type_tbl, l, &l);
if (m->type == FILE_INVALID) {
/*
* Not a keyword type; parse it as an SUS type,
* either 'd' possibly followed by a number or
* C/S/L, or just 's'.
*/
if (*l == 'd')
m->type = get_standard_integer_type(l, &l);
else if (*l == 's' && !isalpha((unsigned char)l[1])) {
m->type = FILE_STRING;
++l;
}
}
}
m->type = get_type(l, &l);
if (m->type == FILE_INVALID) {
/* Not found - try it as a special keyword. */
m->type = get_type(special_tbl, l, &l);
}
if (m->type == FILE_INVALID) {
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "type `%s' invalid", l);
@ -1934,6 +2084,7 @@ check_format_type(const char *ptr, int type)
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
@ -1948,6 +2099,7 @@ check_format_type(const char *ptr, int type)
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
@ -1964,6 +2116,7 @@ check_format_type(const char *ptr, int type)
case 'c':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
return 0;
@ -2403,61 +2556,67 @@ eatsize(const char **p)
/*
* handle a compiled file.
*/
private int
apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
const char *fn)
private struct magic_map *
apprentice_map(struct magic_set *ms, const char *fn)
{
int fd, ret;
int fd;
struct stat st;
uint32_t *ptr;
uint32_t version, entries, nentries;
int needsbyteswap;
char *dbname = NULL;
void *mm = NULL;
struct magic_map *map;
size_t i;
ret = -1;
fd = -1;
if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
file_oomem(ms, sizeof(*map));
goto error;
}
dbname = mkdbname(ms, fn, 0);
if (dbname == NULL)
goto error2;
goto error;
if ((fd = open(dbname, O_RDONLY|O_BINARY)) == -1)
goto error2;
goto error;
if (fstat(fd, &st) == -1) {
file_error(ms, errno, "cannot stat `%s'", dbname);
goto error1;
goto error;
}
if (st.st_size < 8) {
file_error(ms, 0, "file `%s' is too small", dbname);
goto error1;
goto error;
}
map->len = (size_t)st.st_size;
#ifdef QUICK
if ((mm = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
if ((map->p = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
file_error(ms, errno, "cannot map `%s'", dbname);
goto error1;
goto error;
}
#define RET 2
#else
if ((mm = CAST(void *, malloc((size_t)st.st_size))) == NULL) {
file_oomem(ms, (size_t)st.st_size);
goto error1;
if ((map->p = CAST(void *, malloc(map->len))) == NULL) {
file_oomem(ms, map->len);
goto error;
}
if (read(fd, mm, (size_t)st.st_size) != (ssize_t)st.st_size) {
if (read(fd, map->p, map->len) != (ssize_t)map->len) {
file_badread(ms);
goto error1;
goto error;
}
map->len = 0;
#define RET 1
#endif
(void)close(fd);
fd = -1;
ptr = CAST(uint32_t *, mm);
ptr = CAST(uint32_t *, map->p);
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
file_error(ms, 0, "bad magic in `%s'", dbname);
goto error1;
goto error;
}
needsbyteswap = 1;
} else
@ -2466,74 +2625,63 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
version = swap4(ptr[1]);
else
version = ptr[1];
ret = -2;
if (version != VERSIONNO) {
file_error(ms, 0, "File %s supports only version %d magic "
"files. `%s' is version %d", VERSION,
VERSIONNO, dbname, version);
goto error1;
goto error;
}
entries = (uint32_t)(st.st_size / sizeof(struct magic));
if ((off_t)(entries * sizeof(struct magic)) != st.st_size) {
file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu",
dbname, (unsigned long long)st.st_size,
sizeof(struct magic));
goto error1;
goto error;
}
magicp[0] = CAST(struct magic *, mm) + 1;
map->magic[0] = CAST(struct magic *, map->p) + 1;
nentries = 0;
for (i = 0; i < MAGIC_SETS; i++) {
if (needsbyteswap)
nmagicp[i] = swap4(ptr[i + 2]);
map->nmagic[i] = swap4(ptr[i + 2]);
else
nmagicp[i] = ptr[i + 2];
map->nmagic[i] = ptr[i + 2];
if (i != MAGIC_SETS - 1)
magicp[i + 1] = magicp[i] + nmagicp[i];
nentries += nmagicp[i];
map->magic[i + 1] = map->magic[i] + map->nmagic[i];
nentries += map->nmagic[i];
}
if (entries != nentries + 1) {
file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",
dbname, entries, nentries + 1);
goto error1;
goto error;
}
if (needsbyteswap)
for (i = 0; i < MAGIC_SETS; i++)
byteswap(magicp[i], nmagicp[i]);
byteswap(map->magic[i], map->nmagic[i]);
free(dbname);
return RET;
return map;
error1:
error:
if (fd != -1)
(void)close(fd);
if (mm) {
#ifdef QUICK
(void)munmap((void *)mm, (size_t)st.st_size);
#else
free(mm);
#endif
} else {
for (i = 0; i < MAGIC_SETS; i++) {
magicp[i] = NULL;
nmagicp[i] = 0;
}
}
error2:
apprentice_unmap(map);
free(dbname);
return ret;
return NULL;
}
private const uint32_t ar[] = {
MAGICNO, VERSIONNO
};
/*
* handle an mmaped file.
*/
private int
apprentice_compile(struct magic_set *ms, struct magic **magicp,
uint32_t *nmagicp, const char *fn)
apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
{
static size_t nm = sizeof(*nmagicp) * MAGIC_SETS;
static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
static const size_t m = sizeof(**map->magic);
int fd = -1;
size_t len;
char *dbname;
int rv = -1;
uint32_t i;
@ -2554,24 +2702,23 @@ apprentice_compile(struct magic_set *ms, struct magic **magicp,
goto out;
}
if (write(fd, nmagicp, nm) != (ssize_t)nm) {
if (write(fd, map->nmagic, nm) != (ssize_t)nm) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
assert(nm + sizeof(ar) < sizeof(struct magic));
assert(nm + sizeof(ar) < m);
if (lseek(fd, (off_t)sizeof(struct magic), SEEK_SET)
!= sizeof(struct magic)) {
if (lseek(fd, (off_t)m, SEEK_SET) != (off_t)m) {
file_error(ms, errno, "error seeking `%s'", dbname);
goto out;
}
for (i = 0; i < MAGIC_SETS; i++) {
if (write(fd, magicp[i], (sizeof(struct magic) * nmagicp[i]))
!= (ssize_t)(sizeof(struct magic) * nmagicp[i])) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
len = m * map->nmagic[i];
if (write(fd, map->magic[i], len) != (ssize_t)len) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
}
@ -2613,14 +2760,16 @@ mkdbname(struct magic_set *ms, const char *fn, int strip)
q++;
/* Compatibility with old code that looked in .mime */
if (ms->flags & MAGIC_MIME) {
asprintf(&buf, "%.*s.mime%s", (int)(q - fn), fn, ext);
if (asprintf(&buf, "%.*s.mime%s", (int)(q - fn), fn, ext) < 0)
return NULL;
if (access(buf, R_OK) != -1) {
ms->flags &= MAGIC_MIME_TYPE;
return buf;
}
free(buf);
}
asprintf(&buf, "%.*s%s", (int)(q - fn), fn, ext);
if (asprintf(&buf, "%.*s%s", (int)(q - fn), fn, ext) < 0)
return NULL;
/* Compatibility with old code that looked in .mime */
if (strstr(p, ".mime") != NULL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdf.c,v 1.7 2013/01/03 23:05:38 christos Exp $ */
/* $NetBSD: cdf.c,v 1.8 2013/03/23 16:15:58 christos Exp $ */
/*-
* Copyright (c) 2008 Christos Zoulas
@ -38,9 +38,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: cdf.c,v 1.51 2012/03/20 18:28:02 christos Exp $")
FILE_RCSID("@(#)$File: cdf.c,v 1.53 2013/02/26 16:20:42 christos Exp $")
#else
__RCSID("$NetBSD: cdf.c,v 1.7 2013/01/03 23:05:38 christos Exp $");
__RCSID("$NetBSD: cdf.c,v 1.8 2013/03/23 16:15:58 christos Exp $");
#endif
#endif
@ -302,10 +302,7 @@ cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len)
if (info->i_fd == -1)
return -1;
if (lseek(info->i_fd, off, SEEK_SET) == (off_t)-1)
return -1;
if (read(info->i_fd, buf, len) != (ssize_t)len)
if (pread(info->i_fd, buf, len, off) != (ssize_t)len)
return -1;
return (ssize_t)len;

View File

@ -1,4 +1,4 @@
/* $NetBSD: file.h,v 1.7 2013/01/03 23:05:38 christos Exp $ */
/* $NetBSD: file.h,v 1.8 2013/03/23 16:15:58 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -29,7 +29,7 @@
*/
/*
* file.h - definitions for file(1) program
* @(#)$File: file.h,v 1.140 2012/10/30 23:11:51 christos Exp $
* @(#)$File: file.h,v 1.144 2013/02/18 15:40:59 christos Exp $
*/
#ifndef __file_h__
@ -130,12 +130,13 @@
#endif
#define MAXMAGIS 8192 /* max entries in any one magic file
or directory */
#define MAXDESC 64 /* max leng of text description/MIME type */
#define MAXstring 64 /* max leng of "string" types */
#define MAXDESC 64 /* max len of text description/MIME type */
#define MAXMIME 80 /* max len of text MIME type */
#define MAXstring 64 /* max len of "string" types */
#define MAGICNO 0xF11E041C
#define VERSIONNO 9
#define FILE_MAGICSIZE 232
#define VERSIONNO 10
#define FILE_MAGICSIZE 248
#define FILE_LOAD 0
#define FILE_CHECK 1
@ -302,9 +303,9 @@ struct magic {
union VALUETYPE value; /* either number or string */
/* Words 17-32 */
char desc[MAXDESC]; /* description */
/* Words 33-48 */
char mimetype[MAXDESC]; /* MIME type */
/* Words 49-50 */
/* Words 33-52 */
char mimetype[MAXMIME]; /* MIME type */
/* Words 53-54 */
char apple[8];
};
@ -348,10 +349,8 @@ struct magic {
/* list of magic entries */
struct mlist {
struct magic *magic; /* array of magic entries */
uint32_t nmagic; /* number of entries in array */
int mapped; /* allocation type: 0 => apprentice_file
* 1 => apprentice_map + malloc
* 2 => apprentice_map + mmap */
uint32_t nmagic; /* number of entries in array */
void *map; /* internal resources used by entry */
struct mlist *next, *prev;
};
@ -446,7 +445,6 @@ protected int file_apprentice(struct magic_set *, const char *, int);
protected int file_magicfind(struct magic_set *, const char *, struct mlist *);
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 *, size_t);
@ -488,6 +486,9 @@ extern char *sys_errlist[];
#define strtoul(a, b, c) strtol(a, b, c)
#endif
#ifndef HAVE_PREAD
ssize_t pread(int, void *, size_t, off_t);
#endif
#ifndef HAVE_VASPRINTF
int vasprintf(char **, const char *, va_list);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsmagic.c,v 1.6 2013/01/03 23:05:38 christos Exp $ */
/* $NetBSD: fsmagic.c,v 1.7 2013/03/23 16:15:58 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -35,9 +35,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: fsmagic.c,v 1.65 2012/08/26 09:56:26 christos Exp $")
FILE_RCSID("@(#)$File: fsmagic.c,v 1.67 2013/03/17 15:43:20 christos Exp $")
#else
__RCSID("$NetBSD: fsmagic.c,v 1.6 2013/01/03 23:05:38 christos Exp $");
__RCSID("$NetBSD: fsmagic.c,v 1.7 2013/03/23 16:15:58 christos Exp $");
#endif
#endif /* lint */
@ -104,7 +104,7 @@ handle_mime(struct magic_set *ms, int mime, const char *str)
protected int
file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
{
int ret = 0, did = 0;
int ret, did = 0;
int mime = ms->flags & MAGIC_MIME;
#ifdef S_IFLNK
char buf[BUFSIZ+4];
@ -141,6 +141,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
}
ret = 1;
if (!mime) {
#ifdef S_ISUID
if (sb->st_mode & S_ISUID)
@ -166,7 +167,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
} else if (file_printf(ms, "%sdirectory", COMMA) == -1)
return -1;
return 1;
break;
#ifdef S_IFCHR
case S_IFCHR:
/*
@ -174,8 +175,10 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
* like ordinary files. Otherwise, just report that they
* are block special files and go on to the next file.
*/
if ((ms->flags & MAGIC_DEVICES) != 0)
if ((ms->flags & MAGIC_DEVICES) != 0) {
ret = 0;
break;
}
if (mime) {
if (handle_mime(ms, mime, "chardevice") == -1)
return -1;
@ -197,7 +200,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
#endif
}
return 1;
break;
#endif
#ifdef S_IFBLK
case S_IFBLK:
@ -206,8 +209,10 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
* like ordinary files. Otherwise, just report that they
* are block special files and go on to the next file.
*/
if ((ms->flags & MAGIC_DEVICES) != 0)
if ((ms->flags & MAGIC_DEVICES) != 0) {
ret = 0;
break;
}
if (mime) {
if (handle_mime(ms, mime, "blockdevice") == -1)
return -1;
@ -229,7 +234,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
#endif
}
return 1;
break;
#endif
/* TODO add code to handle V7 MUX and Blit MUX files */
#ifdef S_IFIFO
@ -241,7 +246,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
} else if (file_printf(ms, "%sfifo (named pipe)", COMMA) == -1)
return -1;
return 1;
break;
#endif
#ifdef S_IFDOOR
case S_IFDOOR:
@ -250,7 +255,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
} else if (file_printf(ms, "%sdoor", COMMA) == -1)
return -1;
return 1;
break;
#endif
#ifdef S_IFLNK
case S_IFLNK:
@ -267,7 +272,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
"%sunreadable symlink `%s' (%s)", COMMA, fn,
strerror(errno)) == -1)
return -1;
return 1;
break;
}
buf[nch] = '\0'; /* readlink(2) does not do this */
@ -296,7 +301,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
"%spath too long: `%s'", COMMA,
fn) == -1)
return -1;
return 1;
break;
}
/* take dir part */
(void)strlcpy(buf2, fn, sizeof buf2);
@ -315,7 +320,8 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
ms->flags &= MAGIC_SYMLINK;
p = magic_file(ms, buf);
ms->flags |= MAGIC_SYMLINK;
return p != NULL ? 1 : -1;
if (p == NULL)
return -1;
} else { /* just print what it points to */
if (mime) {
if (handle_mime(ms, mime, "symlink") == -1)
@ -324,7 +330,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
COMMA, buf) == -1)
return -1;
}
return 1;
break;
#endif
#ifdef S_IFSOCK
#ifndef __COHERENT__
@ -334,36 +340,42 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
} else if (file_printf(ms, "%ssocket", COMMA) == -1)
return -1;
return 1;
break;
#endif
#endif
case S_IFREG:
/*
* regular file, check next possibility
*
* If stat() tells us the file has zero length, report here that
* the file is empty, so we can skip all the work of opening and
* reading the file.
* But if the -s option has been given, we skip this
* optimization, since on some systems, stat() reports zero
* size for raw disk partitions. (If the block special device
* really has zero length, the fact that it is empty will be
* detected and reported correctly when we read the file.)
*/
if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
if (mime) {
if (handle_mime(ms, mime, "x-empty") == -1)
return -1;
} else if (file_printf(ms, "%sempty", COMMA) == -1)
return -1;
break;
}
ret = 0;
break;
default:
file_error(ms, 0, "invalid mode 0%o", sb->st_mode);
return -1;
/*NOTREACHED*/
}
/*
* regular file, check next possibility
*
* If stat() tells us the file has zero length, report here that
* the file is empty, so we can skip all the work of opening and
* reading the file.
* But if the -s option has been given, we skip this optimization,
* since on some systems, stat() reports zero size for raw disk
* partitions. (If the block special device really has zero length,
* the fact that it is empty will be detected and reported correctly
* when we read the file.)
*/
if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
if (mime) {
if (handle_mime(ms, mime, "x-empty") == -1)
return -1;
} else if (file_printf(ms, "%sempty", COMMA) == -1)
return -1;
return 1;
if (!mime && did) {
if (file_printf(ms, " ") == -1)
return -1;
}
return 0;
return ret;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: magic.c,v 1.5 2013/01/03 23:05:38 christos Exp $ */
/* $NetBSD: magic.c,v 1.6 2013/03/23 16:15:58 christos Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -36,9 +36,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: magic.c,v 1.77 2012/10/31 17:20:06 christos Exp $")
FILE_RCSID("@(#)$File: magic.c,v 1.78 2013/01/07 18:20:19 christos Exp $")
#else
__RCSID("$NetBSD: magic.c,v 1.5 2013/01/03 23:05:38 christos Exp $");
__RCSID("$NetBSD: magic.c,v 1.6 2013/03/23 16:15:58 christos Exp $");
#endif
#endif /* lint */
@ -483,3 +483,9 @@ magic_setflags(struct magic_set *ms, int flags)
ms->flags = flags;
return 0;
}
public int
magic_version(void)
{
return MAGIC_VERSION;
}

View File

@ -1,109 +0,0 @@
/* $NetBSD: magic.h,v 1.1.1.4 2013/03/23 15:49:14 christos Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice immediately at the beginning of the file, without modification,
* this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _MAGIC_H
#define _MAGIC_H
#include <sys/types.h>
#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_TYPE 0x000010 /* Return the MIME type */
#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_MIME_ENCODING 0x000400 /* Return the MIME encoding */
#define MAGIC_MIME (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
#define MAGIC_APPLE 0x000800 /* Return the Apple creator and type */
#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_TEXT 0x020000 /* Don't check for text files */
#define MAGIC_NO_CHECK_CDF 0x040000 /* Don't check for cdf files */
#define MAGIC_NO_CHECK_TOKENS 0x100000 /* Don't check tokens */
#define MAGIC_NO_CHECK_ENCODING 0x200000 /* Don't check text encodings */
/* No built-in tests; only consult the magic file */
#define MAGIC_NO_CHECK_BUILTIN ( \
MAGIC_NO_CHECK_COMPRESS | \
MAGIC_NO_CHECK_TAR | \
/* MAGIC_NO_CHECK_SOFT | */ \
MAGIC_NO_CHECK_APPTYPE | \
MAGIC_NO_CHECK_ELF | \
MAGIC_NO_CHECK_TEXT | \
MAGIC_NO_CHECK_CDF | \
MAGIC_NO_CHECK_TOKENS | \
MAGIC_NO_CHECK_ENCODING | \
)
/* Defined for backwards compatibility (renamed) */
#define MAGIC_NO_CHECK_ASCII MAGIC_NO_CHECK_TEXT
/* Defined for backwards compatibility; do nothing */
#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */
#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */
#define MAGIC_VERSION 514 /* This implementation */
#ifdef __cplusplus
extern "C" {
#endif
typedef struct magic_set *magic_t;
magic_t magic_open(int);
void magic_close(magic_t);
const char *magic_getpath(const char *, int);
const char *magic_file(magic_t, const char *);
const char *magic_descriptor(magic_t, int);
const char *magic_buffer(magic_t, const void *, size_t);
const char *magic_error(magic_t);
int magic_setflags(magic_t, int);
int magic_version(void);
int magic_load(magic_t, const char *);
int magic_compile(magic_t, const char *);
int magic_check(magic_t, const char *);
int magic_list(magic_t, const char *);
int magic_errno(magic_t);
#ifdef __cplusplus
};
#endif
#endif /* _MAGIC_H */

View File

@ -1,4 +1,4 @@
/* $NetBSD: print.c,v 1.5 2013/01/03 23:05:38 christos Exp $ */
/* $NetBSD: print.c,v 1.6 2013/03/23 16:15:58 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -35,9 +35,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: print.c,v 1.75 2012/10/30 23:11:51 christos Exp $")
FILE_RCSID("@(#)$File: print.c,v 1.76 2013/02/26 18:25:00 christos Exp $")
#else
__RCSID("$NetBSD: print.c,v 1.5 2013/01/03 23:05:38 christos Exp $");
__RCSID("$NetBSD: print.c,v 1.6 2013/03/23 16:15:58 christos Exp $");
#endif
#endif /* lint */
@ -65,20 +65,19 @@ file_mdump(struct magic *m)
if (m->flag & INDIR) {
(void) fprintf(stderr, "(%s,",
/* Note: type is unsigned */
(m->in_type < file_nnames) ?
file_names[m->in_type] : "*bad*");
/* Note: type is unsigned */
(m->in_type < file_nnames) ? file_names[m->in_type] :
"*bad in_type*");
if (m->in_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
(void) fprintf(stderr, "%c%u),",
((size_t)(m->in_op & FILE_OPS_MASK) <
SZOF(optyp)) ?
optyp[m->in_op & FILE_OPS_MASK] : '?',
m->in_offset);
((size_t)(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" : "",
/* Note: type is unsigned */
(m->type < file_nnames) ? file_names[m->type] : "*bad*");
/* Note: type is unsigned */
(m->type < file_nnames) ? file_names[m->type] : "*bad type");
if (m->mask_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
@ -141,6 +140,7 @@ file_mdump(struct magic *m)
case FILE_MELONG:
case FILE_BESHORT:
case FILE_BELONG:
case FILE_INDIRECT:
(void) fprintf(stderr, "%d", m->value.l);
break;
case FILE_BEQUAD:
@ -206,7 +206,7 @@ file_mdump(struct magic *m)
(void) fprintf(stderr, "'%s'", m->value.s);
break;
default:
(void) fputs("*bad*", stderr);
(void) fprintf(stderr, "*bad type %d*", m->type);
break;
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: readelf.c,v 1.5 2013/01/03 23:05:38 christos Exp $ */
/* $NetBSD: readelf.c,v 1.6 2013/03/23 16:15:58 christos Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -30,9 +30,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: readelf.c,v 1.94 2012/12/13 13:48:31 christos Exp $")
FILE_RCSID("@(#)$File: readelf.c,v 1.97 2013/03/06 03:35:30 christos Exp $")
#else
__RCSID("$NetBSD: readelf.c,v 1.5 2013/01/03 23:05:38 christos Exp $");
__RCSID("$NetBSD: readelf.c,v 1.6 2013/03/23 16:15:58 christos Exp $");
#endif
#endif
@ -54,7 +54,7 @@ private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
off_t, int *, int);
private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
off_t, int *, int);
off_t, int *, int, int);
private size_t donote(struct magic_set *, void *, size_t, size_t, int,
int, size_t, int *);
@ -64,9 +64,7 @@ private size_t donote(struct magic_set *, void *, size_t, size_t, int,
private uint16_t getu16(int, uint16_t);
private uint32_t getu32(int, uint32_t);
#ifndef USE_ARRAY_FOR_64BIT_TYPES
private uint64_t getu64(int, uint64_t);
#endif
private uint16_t
getu16(int swap, uint16_t value)
@ -108,7 +106,6 @@ getu32(int swap, uint32_t value)
return value;
}
#ifndef USE_ARRAY_FOR_64BIT_TYPES
private uint64_t
getu64(int swap, uint64_t value)
{
@ -133,25 +130,18 @@ getu64(int swap, uint64_t value)
} else
return value;
}
#endif
#define elf_getu16(swap, value) getu16(swap, value)
#define elf_getu32(swap, value) getu32(swap, value)
#ifdef USE_ARRAY_FOR_64BIT_TYPES
# define elf_getu64(swap, array) \
((swap ? ((uint64_t)elf_getu32(swap, array[0])) << 32 : elf_getu32(swap, array[0])) + \
(swap ? elf_getu32(swap, array[1]) : ((uint64_t)elf_getu32(swap, array[1]) << 32)))
#else
# define elf_getu64(swap, value) getu64(swap, value)
#endif
#define elf_getu64(swap, value) getu64(swap, value)
#define xsh_addr (clazz == ELFCLASS32 \
? (void *) &sh32 \
: (void *) &sh64)
? (void *)&sh32 \
: (void *)&sh64)
#define xsh_sizeof (clazz == ELFCLASS32 \
? sizeof sh32 \
: sizeof sh64)
#define xsh_size (clazz == ELFCLASS32 \
? sizeof(sh32) \
: sizeof(sh64))
#define xsh_size (size_t)(clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_size) \
: elf_getu64(swap, sh64.sh_size))
#define xsh_offset (off_t)(clazz == ELFCLASS32 \
@ -160,12 +150,15 @@ getu64(int swap, uint64_t value)
#define xsh_type (clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_type) \
: elf_getu32(swap, sh64.sh_type))
#define xsh_name (clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_name) \
: elf_getu32(swap, sh64.sh_name))
#define xph_addr (clazz == ELFCLASS32 \
? (void *) &ph32 \
: (void *) &ph64)
#define xph_sizeof (clazz == ELFCLASS32 \
? sizeof ph32 \
: sizeof ph64)
? sizeof(ph32) \
: sizeof(ph64))
#define xph_type (clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_type) \
: elf_getu32(swap, ph64.p_type))
@ -181,8 +174,8 @@ getu64(int swap, uint64_t value)
? elf_getu32(swap, ph32.p_filesz) \
: elf_getu64(swap, ph64.p_filesz)))
#define xnh_addr (clazz == ELFCLASS32 \
? (void *) &nh32 \
: (void *) &nh64)
? (void *)&nh32 \
: (void *)&nh64)
#define xph_memsz (size_t)((clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_memsz) \
: elf_getu64(swap, ph64.p_memsz)))
@ -202,8 +195,8 @@ getu64(int swap, uint64_t value)
? prpsoffsets32[i] \
: prpsoffsets64[i])
#define xcap_addr (clazz == ELFCLASS32 \
? (void *) &cap32 \
: (void *) &cap64)
? (void *)&cap32 \
: (void *)&cap64)
#define xcap_sizeof (clazz == ELFCLASS32 \
? sizeof cap32 \
: sizeof cap64)
@ -305,7 +298,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
size_t offset;
size_t offset, len;
unsigned char nbuf[BUFSIZ];
ssize_t bufsize;
@ -319,11 +312,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* Loop through all the program headers.
*/
for ( ; num; num--) {
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
}
if (read(fd, xph_addr, xph_sizeof) == -1) {
if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
file_badread(ms);
return -1;
}
@ -341,13 +330,8 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
}
bufsize = read(fd, nbuf,
((xph_filesz < sizeof(nbuf)) ? xph_filesz : sizeof(nbuf)));
if (bufsize == -1) {
len = xph_filesz < sizeof(nbuf) ? xph_filesz : sizeof(nbuf);
if ((bufsize = pread(fd, nbuf, len, xph_offset)) == -1) {
file_badread(ms);
return -1;
}
@ -857,15 +841,16 @@ static const cap_desc_t cap_desc_386[] = {
private int
doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
size_t size, off_t fsize, int *flags, int mach)
size_t size, off_t fsize, int *flags, int mach, int strtab)
{
Elf32_Shdr sh32;
Elf64_Shdr sh64;
int stripped = 1;
void *nbuf;
off_t noff, coff;
off_t noff, coff, name_off;
uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */
char name[50];
if (size != xsh_sizeof) {
if (file_printf(ms, ", corrupted section header size") == -1)
@ -873,12 +858,24 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
return 0;
}
/* Read offset of name section to be able to read section names later */
if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) {
file_badread(ms);
return -1;
}
name_off = xsh_offset;
for ( ; num; num--) {
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
/* Read the name of this section. */
if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) {
file_badread(ms);
return -1;
}
if (read(fd, xsh_addr, xsh_sizeof) == -1) {
name[sizeof(name) - 1] = '\0';
if (strcmp(name, ".debug_info") == 0)
stripped = 0;
if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {
file_badread(ms);
return -1;
}
@ -903,31 +900,23 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
/* Things we can determine when we seek */
switch (xsh_type) {
case SHT_NOTE:
if ((nbuf = malloc((size_t)xsh_size)) == NULL) {
if ((nbuf = malloc(xsh_size)) == NULL) {
file_error(ms, errno, "Cannot allocate memory"
" for note");
return -1;
}
if ((noff = lseek(fd, (off_t)xsh_offset, SEEK_SET)) ==
(off_t)-1) {
if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {
file_badread(ms);
free(nbuf);
return -1;
}
if (read(fd, nbuf, (size_t)xsh_size) !=
(ssize_t)xsh_size) {
free(nbuf);
file_badread(ms);
return -1;
}
noff = 0;
for (;;) {
if (noff >= (off_t)xsh_size)
break;
noff = donote(ms, nbuf, (size_t)noff,
(size_t)xsh_size, clazz, swap, 4,
flags);
xsh_size, clazz, swap, 4, flags);
if (noff == 0)
break;
}
@ -945,8 +934,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
goto skip;
}
if (lseek(fd, (off_t)xsh_offset, SEEK_SET) ==
(off_t)-1) {
if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
}
@ -1069,7 +1057,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
const char *shared_libraries = "";
unsigned char nbuf[BUFSIZ];
ssize_t bufsize;
size_t offset, align;
size_t offset, align, len;
if (size != xph_sizeof) {
if (file_printf(ms, ", corrupted program header size") == -1)
@ -1078,13 +1066,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
for ( ; num; num--) {
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
}
if (read(fd, xph_addr, xph_sizeof) == -1) {
file_badread(ms);
if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
file_badread(ms);
return -1;
}
@ -1122,12 +1105,9 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
file_badseek(ms);
return -1;
}
bufsize = read(fd, nbuf, ((xph_filesz < sizeof(nbuf)) ?
xph_filesz : sizeof(nbuf)));
len = xph_filesz < sizeof(nbuf) ? xph_filesz
: sizeof(nbuf);
bufsize = pread(fd, nbuf, len, xph_offset);
if (bufsize == -1) {
file_badread(ms);
return -1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: softmagic.c,v 1.8 2013/01/04 17:03:13 christos Exp $ */
/* $NetBSD: softmagic.c,v 1.9 2013/03/23 16:15:58 christos Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -35,9 +35,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)$File: softmagic.c,v 1.155 2012/11/01 04:21:27 christos Exp $")
FILE_RCSID("@(#)$File: softmagic.c,v 1.165 2013/03/07 02:22:24 christos Exp $")
#else
__RCSID("$NetBSD: softmagic.c,v 1.8 2013/01/04 17:03:13 christos Exp $");
__RCSID("$NetBSD: softmagic.c,v 1.9 2013/03/23 16:15:58 christos Exp $");
#endif
#endif /* lint */
@ -49,9 +49,11 @@ __RCSID("$NetBSD: softmagic.c,v 1.8 2013/01/04 17:03:13 christos Exp $");
private int match(struct magic_set *, struct magic *, uint32_t,
const unsigned char *, size_t, size_t, int, int, int, int *);
const unsigned char *, size_t, size_t, int, int, int, int, int *, int *,
int *);
private int mget(struct magic_set *, const unsigned char *,
struct magic *, size_t, size_t, unsigned int, int, int, int, int *);
struct magic *, size_t, size_t, unsigned int, int, int, int, int, int *,
int *, int *);
private int magiccheck(struct magic_set *, struct magic *);
private int32_t mprint(struct magic_set *, struct magic *);
private int32_t moffset(struct magic_set *, struct magic *);
@ -76,10 +78,11 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
int mode, int text)
{
struct mlist *ml;
int rv;
int rv, printed_something = 0, need_separator = 0;
for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
text, 0, NULL)) != 0)
text, 0, 0, &printed_something, &need_separator,
NULL)) != 0)
return rv;
return 0;
@ -115,14 +118,13 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
private int
match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,
int flip, int *returnval)
int flip, int recursion_level, int *printed_something, int *need_separator,
int *returnval)
{
uint32_t magindex = 0;
unsigned int cont_level = 0;
int need_separator = 0;
int returnvalv = 0, e; /* if a match is found it is set to 1*/
int firstline = 1; /* a flag to print X\n X\n- X */
int printed_something = 0;
int print = (ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0;
if (returnval == NULL)
@ -137,8 +139,9 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
if (m->type != FILE_NAME)
if ((IS_STRING(m->type) &&
((text && (m->str_flags & (STRING_BINTEST | STRING_TEXTTEST)) == STRING_BINTEST) ||
(!text && (m->str_flags & (STRING_TEXTTEST | STRING_BINTEST)) == STRING_TEXTTEST))) ||
#define FLT (STRING_BINTEST | STRING_TEXTTEST)
((text && (m->str_flags & FLT) == STRING_BINTEST) ||
(!text && (m->str_flags & FLT) == STRING_TEXTTEST))) ||
(m->flag & mode) != mode) {
/* Skip sub-tests */
while (magindex + 1 < nmagic &&
@ -153,7 +156,8 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
/* if main entry matches, print it... */
switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
flip, returnval)) {
flip, recursion_level + 1, printed_something,
need_separator, returnval)) {
case -1:
return -1;
case 0:
@ -195,8 +199,8 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* a blank before we print something else.
*/
if (*m->desc) {
need_separator = 1;
printed_something = 1;
*need_separator = 1;
*printed_something = 1;
if (print_sep(ms, firstline) == -1)
return -1;
}
@ -239,7 +243,8 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
}
#endif
switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
text, flip, returnval)) {
text, flip, recursion_level + 1, printed_something,
need_separator, returnval)) {
case -1:
return -1;
case 0:
@ -281,8 +286,8 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* make sure that we have a separator first.
*/
if (*m->desc) {
if (!printed_something) {
printed_something = 1;
if (!*printed_something) {
*printed_something = 1;
if (print_sep(ms, firstline)
== -1)
return -1;
@ -295,13 +300,13 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* this item isn't empty.
*/
/* space if previous printed */
if (need_separator
if (*need_separator
&& ((m->flag & NOSPACE) == 0)
&& *m->desc) {
if (print &&
file_printf(ms, " ") == -1)
return -1;
need_separator = 0;
*need_separator = 0;
}
if (print && mprint(ms, m) == -1)
return -1;
@ -309,7 +314,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
ms->c.li[cont_level].off = moffset(ms, m);
if (*m->desc)
need_separator = 1;
*need_separator = 1;
/*
* If we see any continuations
@ -321,12 +326,12 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
break;
}
}
if (printed_something) {
if (*printed_something) {
firstline = 0;
if (print)
*returnval = 1;
}
if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
if ((ms->flags & MAGIC_CONTINUE) == 0 && *printed_something) {
return *returnval; /* don't keep searching */
}
}
@ -1003,7 +1008,7 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
private void
mdebug(uint32_t offset, const char *str, size_t len)
{
(void) fprintf(stderr, "mget @%d: ", offset);
(void) fprintf(stderr, "mget/%zu @%d: ", len, offset);
file_showstr(stderr, str, len);
(void) fputc('\n', stderr);
(void) fputc('\n', stderr);
@ -1070,8 +1075,8 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
if (type == FILE_BESTRING16)
src++;
/* check for pointer overflow */
if (src < s) {
/* check that offset is within range */
if (offset >= nbytes) {
file_magerror(ms, "invalid offset %u in mcopy()",
offset);
return -1;
@ -1122,20 +1127,29 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
private int
mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,
int flip, int *returnval)
int flip, int recursion_level, int *printed_something,
int *need_separator, int *returnval)
{
uint32_t offset = ms->offset;
uint32_t soffset, offset = ms->offset;
uint32_t count = m->str_range;
int rv;
int rv, oneed_separator;
char *sbuf, *rbuf;
union VALUETYPE *p = &ms->ms_value;
struct mlist ml;
if (recursion_level >= 20) {
file_error(ms, 0, "recursion nesting exceeded");
return -1;
}
if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),
(uint32_t)(nbytes - o), count) == -1)
(uint32_t)nbytes, count) == -1)
return -1;
if ((ms->flags & MAGIC_DEBUG) != 0) {
fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%zu, "
"nbytes=%zu, count=%u)\n", m->type, m->flag, offset, o,
nbytes, count);
mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
#ifndef COMPILE_ONLY
file_mdump(m);
@ -1620,6 +1634,12 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
if (m->flag & INDIROFFADD) {
offset += ms->c.li[cont_level-1].off;
if (offset == 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr,
"indirect *zero* offset\n");
return 0;
}
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "indirect +offs=%u\n", offset);
}
@ -1692,23 +1712,24 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
if (nbytes < offset)
return 0;
sbuf = ms->o.buf;
soffset = ms->offset;
ms->o.buf = NULL;
ms->offset = 0;
rv = file_softmagic(ms, s + offset, nbytes - offset,
BINTEST, text);
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
rbuf = ms->o.buf;
ms->o.buf = sbuf;
ms->offset = soffset;
if (rv == 1) {
rbuf = ms->o.buf;
ms->o.buf = sbuf;
if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
file_printf(ms, m->desc, offset) == -1)
return -1;
if (file_printf(ms, "%s", rbuf) == -1)
return -1;
free(rbuf);
} else
ms->o.buf = sbuf;
}
return rv;
case FILE_USE:
@ -1717,15 +1738,22 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
sbuf = m->value.s;
if (*sbuf == '^') {
sbuf++;
flip = 1;
} else
flip = 0;
flip = !flip;
}
if (file_magicfind(ms, sbuf, &ml) == -1) {
file_error(ms, 0, "cannot find entry `%s'", sbuf);
return -1;
}
return match(ms, ml.magic, ml.nmagic, s, nbytes, offset,
mode, text, flip, returnval);
oneed_separator = *need_separator;
if (m->flag & NOSPACE)
*need_separator = 0;
rv = match(ms, ml.magic, ml.nmagic, s, nbytes, offset + o,
mode, text, flip, recursion_level, printed_something,
need_separator, returnval);
if (rv != 1)
*need_separator = oneed_separator;
return rv;
case FILE_NAME:
if (file_printf(ms, "%s", m->desc) == -1)

View File

@ -56,8 +56,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/visibility.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d

View File

@ -90,6 +90,9 @@
/* Define to 1 if you have a working `mmap' system call. */
#define HAVE_MMAP 1
/* Define to 1 if you have the `pread' function. */
#define HAVE_PREAD 1
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
@ -233,7 +236,7 @@
#define PACKAGE_NAME "file"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "file 5.12"
#define PACKAGE_STRING "file 5.14"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "file"
@ -242,7 +245,7 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "5.12"
#define PACKAGE_VERSION "5.14"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
@ -273,7 +276,7 @@
/* Version number of package */
#define VERSION "5.12"
#define VERSION "5.14"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.2 2011/08/14 09:06:12 christos Exp $
# $NetBSD: Makefile,v 1.3 2013/03/23 16:15:59 christos Exp $
#
USE_FORT?= yes # data driven bugs?
@ -9,6 +9,7 @@ USE_FORT?= yes # data driven bugs?
LIB= magic
LIBDPLIBS+= z ${NETBSDSRCDIR}/lib/libz
CPPFLAGS+=-I.
.if ${MACHINE_ARCH} == "i386"
# Set lint to exit on warnings
@ -34,4 +35,9 @@ INCSDIR= /usr/include
COPTS.softmagic.c = -Wno-format-nonliteral
magic.c: magic.h
magic.h: magic.h.in
${TOOL_SED} -e "s/X.YY/514/" < ${.ALLSRC} > ${.TARGET}
.include <bsd.lib.mk>

View File

@ -1,4 +1,4 @@
# $NetBSD: shlib_version,v 1.3 2013/01/03 23:18:10 christos Exp $
# $NetBSD: shlib_version,v 1.4 2013/03/23 16:15:59 christos Exp $
#
major=4
major=5
minor=0