Browse Source

Import upstream version 4.25

Christos Zoulas 15 years ago
parent
commit
0755f6a5d2
58 changed files with 2274 additions and 405 deletions
  1. 71 1
      ChangeLog
  2. 2 1
      Makefile.in
  3. 23 2
      README
  4. 34 0
      aclocal.m4
  5. 142 0
      compile
  6. 3 0
      config.h.in
  7. 163 37
      configure
  8. 2 1
      configure.ac
  9. 40 24
      magic/Magdir/animation
  10. 4 4
      magic/Magdir/archive
  11. 1 1
      magic/Magdir/audio
  12. 3 1
      magic/Magdir/cafebabe
  13. 26 21
      magic/Magdir/commands
  14. 2 2
      magic/Magdir/compress
  15. 6 6
      magic/Magdir/console
  16. 1 1
      magic/Magdir/database
  17. 5 0
      magic/Magdir/diff
  18. 18 9
      magic/Magdir/elf
  19. 38 0
      magic/Magdir/filesystems
  20. 2 2
      magic/Magdir/freebsd
  21. 0 2
      magic/Magdir/fsav
  22. 92 0
      magic/Magdir/games
  23. 4 0
      magic/Magdir/gimp
  24. 4 0
      magic/Magdir/gnu
  25. 33 10
      magic/Magdir/hp
  26. 28 16
      magic/Magdir/images
  27. 16 1
      magic/Magdir/linux
  28. 10 5
      magic/Magdir/lisp
  29. 8 1
      magic/Magdir/misctools
  30. 119 146
      magic/Magdir/msdos
  31. 7 7
      magic/Magdir/perl
  32. 6 4
      magic/Magdir/printer
  33. 1 1
      magic/Magdir/psion
  34. 1 1
      magic/Magdir/riff
  35. 10 0
      magic/Magdir/ruby
  36. 6 0
      magic/Magdir/sgml
  37. 3 1
      magic/Magdir/vorbis
  38. 15 0
      magic/Magdir/weak
  39. 115 0
      magic/Magdir/windows
  40. 9 1
      magic/Makefile.am
  41. 10 1
      magic/Makefile.in
  42. 5 1
      src/Makefile.am
  43. 13 5
      src/Makefile.in
  44. 170 52
      src/apprentice.c
  45. 1 2
      src/ascmagic.c
  46. 43 0
      src/asprintf.c
  47. 4 2
      src/elfclass.h
  48. 2 2
      src/file.c
  49. 21 11
      src/file.h
  50. 2 2
      src/fsmagic.c
  51. 15 7
      src/funcs.c
  52. 1 2
      src/magic.c
  53. 5 2
      src/patchlevel.h
  54. 177 5
      src/readelf.c
  55. 76 0
      src/readelf.h
  56. 638 0
      src/vasprintf.c
  57. 1 0
      tests/Makefile.am
  58. 17 2
      tests/Makefile.in

+ 71 - 1
ChangeLog

@@ -1,4 +1,74 @@
-	
+2008-07-02 11:15  Christos Zoulas  <christos@astron.com>
+
+	* add !:strength op to adjust magic strength (experimental)
+
+2008-06-16 21:41  Reuben Thomas  <rrt@sc3d.org>
+
+	* Fix automake error in configure.ac.
+
+	* Add MIME type for Psion Sketch files.
+
+2008-06-05 08:59  Christos Zoulas  <christos@astron.com>
+
+	* Don't print warnings about bad namesize in stripped
+	  binaries with PT_NOTE is still there, and the actual
+	  note is gone (Jakub Jelinek)
+
+2008-05-28 15:12  Robert Byrnes  <byrnes@wildpumpkin.net>
+
+	* magic/Magdir/elf:
+	  Note invalid byte order for little-endian SPARC32PLUS.
+	  Add SPARC V9 vendor extensions and memory model.
+
+	* src/elfclass.h:
+	  Pass target machine to doshn (for Solaris hardware capabilities).
+
+	* src/readelf.c (doshn):
+	  Add support for Solaris hardware/software capabilities.
+
+	* src/readelf.h:
+	  Ditto.
+
+	* src/vasprintf.c (dispatch):
+	  Add support for ll modifier.
+
+2008-05-16 10:25  Christos Zoulas  <christos@astron.com>
+
+	* Fix compiler warnings.
+
+	* remove stray printf, and fix a vprintf bug. (Martin Dorey)
+
+2008-05-06 00:13  Robert Byrnes  <byrnes@wildpumpkin.net>
+
+        * src/Makefile.am:
+	  Ensure that getopt_long and [v]asprintf are included in libmagic,
+	  as needed.
+
+	  Remove unnecessary EXTRA_DIST.
+
+        * src/Makefile.in:
+	  Rerun automake.
+
+        * src/vasprintf.c (dispatch):
+	  Fix variable precision bug: be sure to step past '*'.
+
+        * src/vasprintf.c (core):
+	  Remove unreachable code.
+
+        * src/apprentice.c (set_test_type):
+	  Add cast to avoid compiler warning.
+
+2008-04-22 23:45  Christos Zoulas  <christos@astron.com>
+
+	* Add magic submission guidelines (Abel Cheung)
+
+	* split msdos and windows magic (Abel Cheung)
+
+2008-04-04 11:00  Christos Zoulas  <christos@astron.com>
+
+        * >= <= is not supported, so fix the magic and warn about it.
+	  reported by: Thien-Thi Nguyen <ttn@gnuvola.org>
+
 2008-03-27 16:16  Robert Byrnes  <byrnes@wildpumpkin.net>
 
         * src/readelf.c (donote):

+ 2 - 1
Makefile.in

@@ -35,7 +35,8 @@ subdir = .
 DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
 	$(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
-	config.guess config.sub depcomp install-sh ltmain.sh missing
+	compile config.guess config.sub depcomp install-sh ltmain.sh \
+	missing
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
 	$(top_srcdir)/configure.ac

+ 23 - 2
README

@@ -1,5 +1,5 @@
 ** README for file(1) Command **
-@(#) $File: README,v 1.39 2008/02/14 20:22:20 christos Exp $
+@(#) $File: README,v 1.40 2008/04/23 03:45:20 christos Exp $
 
 E-mail: christos@astron.com
 Mailing List: file@mx.gw.com
@@ -46,7 +46,7 @@ magic numbers assigned to all sorts of data files that
 are in reasonable circulation. Send your magic numbers,
 in magic(5) format please, to the maintainer, Christos Zoulas.
 
-LEGAL.NOTICE - read this first.
+COPYING - read this first.
 README - read this second (you are currently reading this file).
 PORTING - read this only if the program won't compile.
 Makefile - read this next, adapt it as needed (particularly
@@ -76,6 +76,27 @@ readelf.[ch] - Stand-alone elf parsing code.
 compress.c - on-the-fly decompression.
 print.c - print results, errors, warnings.
 
+------------------------------------------------------------------------------
+
+If you submit a new magic entry please make sure you read the following
+guidelines:
+
+- Initial match is preferably at least 32 bits long, and is a _unique_ match
+- If this is not feasible, use additional check
+- Match of <= 16 bits are not accepted
+- Delay printing string as much as possible, don't print output too early
+- Avoid printf arbitrary byte as string, which can be a source of
+  crash and buffer overflow
+
+- Provide complete information with entry:
+  * One line short summary
+  * Optional long description
+  * File extension, if applicable
+  * Full name and contact method (for discussion when entry has problem)
+  * Further reference, such as documentation of format
+
+------------------------------------------------------------------------------
+
 You can download the latest version of file from:
 
 	ftp://ftp.astron.com/pub/file/

+ 34 - 0
aclocal.m4

@@ -6737,6 +6737,40 @@ AC_MSG_RESULT([$_am_result])
 rm -f confinc confmf
 ])
 
+# Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
+
+# AM_PROG_CC_C_O
+# --------------
+# Like AC_PROG_CC_C_O, but changed for automake.
+AC_DEFUN([AM_PROG_CC_C_O],
+[AC_REQUIRE([AC_PROG_CC_C_O])dnl
+AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([compile])dnl
+# FIXME: we rely on the cache variable name because
+# there is no other way.
+set dummy $CC
+ac_cc=`echo $[2] | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']`
+if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" != yes"; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
+dnl Make sure AC_PROG_CC is never called again, or it will override our
+dnl setting of CC.
+m4_define([AC_PROG_CC],
+          [m4_fatal([AC_PROG_CC cannot be called after AM_PROG_CC_C_O])])
+])
+
 # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
 
 # Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005

+ 142 - 0
compile

@@ -0,0 +1,142 @@
+#! /bin/sh
+# Wrapper for compilers which do not understand `-c -o'.
+
+scriptversion=2005-05-14.22
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
+# Written by Tom Tromey <tromey@cygnus.com>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: compile [--help] [--version] PROGRAM [ARGS]
+
+Wrapper for compilers which do not understand `-c -o'.
+Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
+arguments, and rename the output as expected.
+
+If you are trying to build a whole package this is not the
+right script to run: please start by reading the file `INSTALL'.
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "compile $scriptversion"
+    exit $?
+    ;;
+esac
+
+ofile=
+cfile=
+eat=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+	# configure might choose to run compile as `compile cc -o foo foo.c'.
+	# So we strip `-o arg' only if arg is an object.
+	eat=1
+	case $2 in
+	  *.o | *.obj)
+	    ofile=$2
+	    ;;
+	  *)
+	    set x "$@" -o "$2"
+	    shift
+	    ;;
+	esac
+	;;
+      *.c)
+	cfile=$1
+	set x "$@" "$1"
+	shift
+	;;
+      *)
+	set x "$@" "$1"
+	shift
+	;;
+    esac
+  fi
+  shift
+done
+
+if test -z "$ofile" || test -z "$cfile"; then
+  # If no `-o' option was seen then we might have been invoked from a
+  # pattern rule where we don't need one.  That is ok -- this is a
+  # normal compilation that the losing compiler can handle.  If no
+  # `.c' file was seen then we are probably linking.  That is also
+  # ok.
+  exec "$@"
+fi
+
+# Name of file we expect compiler to create.
+cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
+
+# Create the lock directory.
+# Note: use `[/.-]' here to ensure that we don't use the same name
+# that we are using for the .o file.  Also, base the name on the expected
+# object file name, since that is what matters with a parallel build.
+lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
+while true; do
+  if mkdir "$lockdir" >/dev/null 2>&1; then
+    break
+  fi
+  sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir '$lockdir'; exit 1" 1 2 15
+
+# Run the compile.
+"$@"
+ret=$?
+
+if test -f "$cofile"; then
+  mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  mv "${cofile}bj" "$ofile"
+fi
+
+rmdir "$lockdir"
+exit $ret
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:

+ 3 - 0
config.h.in

@@ -158,6 +158,9 @@
    <sysmacros.h>. */
 #undef MAJOR_IN_SYSMACROS
 
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+#undef NO_MINUS_C_MINUS_O
+
 /* Name of package */
 #undef PACKAGE
 

+ 163 - 37
configure

@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for file 4.24.
+# Generated by GNU Autoconf 2.61 for file 4.25.
 #
 # Report bugs to <christos@astron.com>.
 #
@@ -728,8 +728,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='file'
 PACKAGE_TARNAME='file'
-PACKAGE_VERSION='4.24'
-PACKAGE_STRING='file 4.24'
+PACKAGE_VERSION='4.25'
+PACKAGE_STRING='file 4.25'
 PACKAGE_BUGREPORT='christos@astron.com'
 
 # Factoring default headers for most tests.
@@ -1394,7 +1394,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 4.24 to adapt to many kinds of systems.
+\`configure' configures file 4.25 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1464,7 +1464,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of file 4.24:";;
+     short | recursive ) echo "Configuration of file 4.25:";;
    esac
   cat <<\_ACEOF
 
@@ -1570,7 +1570,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-file configure 4.24
+file configure 4.25
 generated by GNU Autoconf 2.61
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1584,7 +1584,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 4.24, which was
+It was created by file $as_me 4.25, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   $ $0 $@
@@ -2274,7 +2274,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='file'
- VERSION='4.24'
+ VERSION='4.25'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -3610,6 +3610,132 @@ else
 fi
 
 
+if test "x$CC" != xcc; then
+  { echo "$as_me:$LINENO: checking whether $CC and cc understand -c and -o together" >&5
+echo $ECHO_N "checking whether $CC and cc understand -c and -o together... $ECHO_C" >&6; }
+else
+  { echo "$as_me:$LINENO: checking whether cc understands -c and -o together" >&5
+echo $ECHO_N "checking whether cc understands -c and -o together... $ECHO_C" >&6; }
+fi
+set dummy $CC; ac_cc=`echo $2 |
+		      sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'`
+if { as_var=ac_cv_prog_cc_${ac_cc}_c_o; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+# Make sure it works both with $CC and with simple cc.
+# We do the test twice because some compilers refuse to overwrite an
+# existing .o file with -o, though they will create one.
+ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&5'
+rm -f conftest2.*
+if { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+   test -f conftest2.$ac_objext && { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); };
+then
+  eval ac_cv_prog_cc_${ac_cc}_c_o=yes
+  if test "x$CC" != xcc; then
+    # Test first that cc exists at all.
+    if { ac_try='cc -c conftest.$ac_ext >&5'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+      ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&5'
+      rm -f conftest2.*
+      if { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 test -f conftest2.$ac_objext && { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); };
+      then
+	# cc works too.
+	:
+      else
+	# cc exists but doesn't like -o.
+	eval ac_cv_prog_cc_${ac_cc}_c_o=no
+      fi
+    fi
+  fi
+else
+  eval ac_cv_prog_cc_${ac_cc}_c_o=no
+fi
+rm -f core conftest*
+
+fi
+if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then
+  { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define NO_MINUS_C_MINUS_O 1
+_ACEOF
+
+fi
+
+# FIXME: we rely on the cache variable name because
+# there is no other way.
+set dummy $CC
+ac_cc=`echo $2 | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'`
+if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" != yes"; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
+
+
 # Find a good install program.  We prefer a C program (faster),
 # so one script is as good as another.  But avoid the broken or
 # incompatible versions:
@@ -4472,7 +4598,7 @@ ia64-*-hpux*)
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 4475 "configure"' > conftest.$ac_ext
+  echo '#line 4601 "configure"' > conftest.$ac_ext
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -7218,11 +7344,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7221: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7347: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7225: \$? = $ac_status" >&5
+   echo "$as_me:7351: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -7480,11 +7606,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7483: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7609: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:7487: \$? = $ac_status" >&5
+   echo "$as_me:7613: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -7542,11 +7668,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7545: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:7671: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:7549: \$? = $ac_status" >&5
+   echo "$as_me:7675: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -9745,7 +9871,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 9748 "configure"
+#line 9874 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -9843,7 +9969,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 9846 "configure"
+#line 9972 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12087,11 +12213,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:12090: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:12216: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:12094: \$? = $ac_status" >&5
+   echo "$as_me:12220: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -12149,11 +12275,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:12152: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:12278: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:12156: \$? = $ac_status" >&5
+   echo "$as_me:12282: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -13485,7 +13611,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 13488 "configure"
+#line 13614 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13583,7 +13709,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 13586 "configure"
+#line 13712 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14468,11 +14594,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14471: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14597: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:14475: \$? = $ac_status" >&5
+   echo "$as_me:14601: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -14530,11 +14656,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14533: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14659: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:14537: \$? = $ac_status" >&5
+   echo "$as_me:14663: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -16647,11 +16773,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16650: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:16776: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:16654: \$? = $ac_status" >&5
+   echo "$as_me:16780: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -16909,11 +17035,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16912: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:17038: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:16916: \$? = $ac_status" >&5
+   echo "$as_me:17042: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -16971,11 +17097,11 @@ else
    -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16974: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:17100: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:16978: \$? = $ac_status" >&5
+   echo "$as_me:17104: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -19174,7 +19300,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 19177 "configure"
+#line 19303 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19272,7 +19398,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 19275 "configure"
+#line 19401 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -24159,7 +24285,7 @@ exec 6>&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 4.24, which was
+This file was extended by file $as_me 4.25, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -24212,7 +24338,7 @@ Report bugs to <bug-autoconf@gnu.org>."
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-file config.status 4.24
+file config.status 4.25
 configured by $0, generated by GNU Autoconf 2.61,
   with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 

+ 2 - 1
configure.ac

@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT(file, 4.24, christos@astron.com)
+AC_INIT(file, 4.25, christos@astron.com)
 AM_INIT_AUTOMAKE
 AM_CONFIG_HEADER(config.h)
 
@@ -51,6 +51,7 @@ AC_GNU_SOURCE
 
 dnl Checks for programs.
 AC_PROG_CC
+AM_PROG_CC_C_O
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_LIBTOOL

+ 40 - 24
magic/Magdir/animation

@@ -63,23 +63,23 @@
 
 # MPEG sequences
 # Scans for all common MPEG header start codes
-0        belong             0x00000001     JVT NAL sequence
->4       byte&0x1F          0x07           \b, H.264 video
+0	 belong		    0x00000001     
+>4	 byte&0x1F	    0x07	   JVT NAL sequence, H.264 video
 >>5      byte               66             \b, baseline
 >>5      byte               77             \b, main
 >>5      byte               88             \b, extended
 >>7      byte               x              \b @ L %u
-0        string             \000\000\001   MPEG sequence
->3       byte               0xBA
+0        belong&0xFFFFFF00  0x00000100     
+>3       byte               0xBA           MPEG sequence
 >>4      byte               &0x40          \b, v2, program multiplex
 >>4      byte               ^0x40          \b, v1, system multiplex
->3       byte               0xBB           \b, v1/2, multiplex (missing pack header)
->3       byte&0x1F          0x07           \b, H.264 video
+>3       byte               0xBB           MPEG sequence, v1/2, multiplex (missing pack header)
+>3       byte&0x1F          0x07           MPEG sequence, H.264 video
 >>4      byte               66             \b, baseline
 >>4      byte               77             \b, main
 >>4      byte               88             \b, extended
 >>6      byte               x              \b @ L %u
->3       byte               0xB0           \b, v4
+>3       byte               0xB0           MPEG sequence, v4
 >>5      belong             0x000001B5
 >>>9     byte               &0x80
 >>>>10   byte&0xF0          16             \b, video
@@ -148,7 +148,7 @@
 >>4      byte               251            \b, FGS @ L3
 >>4      byte               252            \b, FGS @ L4
 >>4      byte               253            \b, FGS @ L5
->3       byte               0xB5           \b, v4
+>3       byte               0xB5           MPEG sequence, v4
 >>4      byte               &0x80
 >>>5     byte&0xF0          16             \b, video (missing profile header)
 >>>5     byte&0xF0          32             \b, still texture (missing profile header)
@@ -158,7 +158,7 @@
 >>4      byte&0xF8          16             \b, still texture (missing profile header)
 >>4      byte&0xF8          24             \b, mesh (missing profile header)
 >>4      byte&0xF8          32             \b, face (missing profile header)
->3       byte               0xB3
+>3       byte               0xB3           MPEG sequence
 >>12     belong             0x000001B8     \b, v1, progressive Y'CbCr 4:2:0 video
 >>12     belong             0x000001B2     \b, v1, progressive Y'CbCr 4:2:0 video
 >>12     belong             0x000001B5     \b, v2,
@@ -276,7 +276,7 @@
 # modified by Joerg Jenderek
 # GRR the original test are too common for many DOS files
 # so don't accept as MP3 until we've tested the rate
-0       beshort&0xFFFE
+0       beshort&0xFFFE  0xFFFA
 # rates
 >2      byte&0xF0       0x10           MPEG ADTS, layer III, v1,  32 kbps
 !:mime	audio/mpeg
@@ -361,6 +361,7 @@
 # updated by Joerg Jenderek
 # GRR the original test are too common for many DOS files, so test 32 <= kbits <= 448
 # GRR this test is still too general as it catches a BOM of UTF-16 files (0xFFFE)
+# FIXME: Almost all little endian UTF-16 text with BOM are clobbered by these entries
 #0	beshort&0xFFFE		0xFFFE	
 #>2	ubyte&0xF0	>0x0F		
 #>>2	ubyte&0xF0	<0xE1		MPEG ADTS, layer I, v1
@@ -616,22 +617,30 @@
 #0       beshort         0x4DE1         MPEG-4 LO-EP audio stream
 #!:mime	audio/x-mp4a-latm
 
-# FLI animation format
-4	leshort		0xAF11			FLI file
+# Summary: FLI animation format
+# Created by: Daniel Quinlan <quinlan@yggdrasil.com>
+# Modified by (1): Abel Cheung <abelcheung@gmail.com> (avoid over-generic detection)
+4	leshort		0xAF11
+# standard FLI always has 320x200 resolution and 8 bit color
+>8	leshort		320
+>>10	leshort		200
+>>>12	leshort		8			FLI animation, 320x200x8
 !:mime	video/x-fli
->6	leshort		x			- %d frames,
->8	leshort		x			width=%d pixels,
->10	leshort		x			height=%d pixels,
->12	leshort		x			depth=%d,
->16	leshort		x			ticks/frame=%d
-# FLC animation format
-4	leshort		0xAF12			FLC file
+>>>>6	leshort		x			\b, %d frames
+# frame speed is multiple of 1/70s
+>>>>16	leshort		x			\b, %d/70s per frame
+
+# Summary: FLC animation format
+# Created by: Daniel Quinlan <quinlan@yggdrasil.com>
+# Modified by (1): Abel Cheung <abelcheung@gmail.com> (avoid over-generic detection)
+4	leshort		0xAF12
+# standard FLC always use 8 bit color
+>12	leshort		8			FLC animation
 !:mime	video/x-flc
->6	leshort		x			- %d frames
->8	leshort		x			width=%d pixels,
->10	leshort		x			height=%d pixels,
->12	leshort		x			depth=%d,
->16	leshort		x			ticks/frame=%d
+>>8	leshort		x			\b, %d
+>>10	leshort		x			\bx%dx8
+>>6	uleshort	x			\b, %d frames
+>>16	uleshort	x			\b, %dms per frame
 
 # DL animation format
 # XXX - collision with most `mips' magic
@@ -712,6 +721,13 @@
 0	string/b	#VRML\ V2.0\ utf8	ISO/IEC 14772 VRML 97 file
 !:mime	model/vrml
 
+# X3D (Extensible 3D) [http://www.web3d.org/specifications/x3d-3.0.dtd]
+# From Michel Briand <michelbriand@free.fr>
+0	string		\<?xml\ version="
+!:strength +1
+>20	search/1000/cb  \<!DOCTYPE\ X3D		X3D (Extensible 3D) model xml text
+!:mime model/x3d
+
 #---------------------------------------------------------------------------
 # HVQM4: compressed movie format designed by Hudson for Nintendo GameCube
 # From Mark Sheppard <msheppard@climax.co.uk>, 2002-10-03

+ 4 - 4
magic/Magdir/archive

@@ -577,8 +577,10 @@
 !:mime	application/zip
 
 # OpenOffice.org / KOffice / StarOffice documents
+# Listed here because they ARE zip files
+#
 # From: Abel Cheung <abel@oaka.org>
-# Listed here because they are basically zip files
+>4	byte		0x14
 >>30	string		mimetype
 
 # KOffice (1.2 or above) formats
@@ -608,6 +610,7 @@
 >>>>>69	byte	!0x2e			presentation
 >>>>>69	string	.template		template
 >>>>62	string	math			Math document
+>>>>62	string	base			Database file
 
 # OpenDocument formats (for OpenOffice 2.x / StarOffice >= 8)
 # http://lists.oasis-open.org/archives/office/200505/msg00006.html
@@ -776,9 +779,6 @@
 0	lelong	0x10201A7A	Symbian installation file (Symbian OS 9.x)
 !:mime	x-epoc/x-sisx-app
 
-# Pack200 Java archives, http://jcp.org/en/jsr/detail?id=200
-0	belong	0xcafed00d	Pack200 Java archive
-
 # From "Nelson A. de Oliveira" <naoliv@gmail.com>
 0	string	MPQ\032		MoPaQ (MPQ) archive
 

+ 1 - 1
magic/Magdir/audio

@@ -273,7 +273,7 @@
 >22	belong&0x00ffffff	x		%d Hz,
 >18	beshort		=0			no loop,
 >18	beshort		=-1			loop,
->21	ubyte		<=127			note %d,
+>21	ubyte		<128			note %d,
 >22	byte		=0			replay 5.485 KHz
 >22	byte		=1			replay 8.084 KHz
 >22	byte		=2			replay 10.971 Khz

+ 3 - 1
magic/Magdir/cafebabe

@@ -21,5 +21,7 @@
 >>4	belong		1		Mach-O fat file with 1 architecture
 >>4	belong		>1
 >>>4	belong		<20		Mach-O fat file with %ld architectures
->2	beshort		0xd00d		JAR compressed with pack200
+>2	beshort		0xd00d		JAR compressed with pack200,
+>>5	byte		x		version %d.
+>>4	byte		x		\b%d
 !:mime	application/x-java-pack200

+ 26 - 21
magic/Magdir/commands

@@ -4,48 +4,48 @@
 #
 #0	string		:			shell archive or script for antique kernel text
 0	string/b	#!\ /bin/sh		POSIX shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /bin/csh		C shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 # korn shell magic, sent by George Wu, gwu@clyde.att.com
 0	string/b	#!\ /bin/ksh		Korn shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b 	#!\ /bin/tcsh		Tenex C shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b 	#!\ /usr/local/tcsh	Tenex C shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /usr/local/bin/tcsh	Tenex C shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 
 #
 # zsh/ash/ae/nawk/gawk magic from cameron@cs.unsw.oz.au (Cameron Simpson)
 0	string/b	#!\ /bin/zsh		Paul Falstad's zsh script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /usr/bin/zsh	Paul Falstad's zsh script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /usr/local/bin/zsh	Paul Falstad's zsh script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /usr/local/bin/ash	Neil Brown's ash script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /usr/local/bin/ae	Neil Brown's ae script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /bin/nawk		new awk script text executable
-!:mime	application/x-nawk
+!:mime	text/x-nawk
 0	string/b	#!\ /usr/bin/nawk	new awk script text executable
-!:mime	application/x-nawk
+!:mime	text/x-nawk
 0	string/b	#!\ /usr/local/bin/nawk	new awk script text executable
-!:mime	application/x-nawk
+!:mime	text/x-nawk
 0	string/b	#!\ /bin/gawk		GNU awk script text executable
-!:mime	application/x-gawk
+!:mime	text/x-gawk
 0	string/b	#!\ /usr/bin/gawk	GNU awk script text executable
-!:mime	application/x-gawk
+!:mime	text/x-gawk
 0	string/b	#!\ /usr/local/bin/gawk	GNU awk script text executable
-!:mime	application/x-gawk
+!:mime	text/x-gawk
 #
 0	string/b	#!\ /bin/awk		awk script text executable
-!:mime	application/x-awk
+!:mime	text/x-awk
 0	string/b	#!\ /usr/bin/awk	awk script text executable
-!:mime	application/x-awk
+!:mime	text/x-awk
 # update to distinguish from *.vcf files
 # this is broken because postscript has /EBEGIN{ for example.
 #0	search/Bb	BEGIN {			awk script text
@@ -55,9 +55,9 @@
 
 # bash shell magic, from Peter Tobias (tobias@server.et-inf.fho-emden.de)
 0	string/b	#!\ /bin/bash	Bourne-Again shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 0	string/b	#!\ /usr/local/bin/bash	Bourne-Again shell script text executable
-!:mime	application/x-shellscript
+!:mime	text/x-shellscript
 
 # using env
 0	string		#!/usr/bin/env		a
@@ -68,10 +68,15 @@
 # PHP scripts
 # Ulf Harnhammar <ulfh@update.uu.se>
 0	search/1/c	=<?php			PHP script text
+!:mime	text/x-php
 0	search/1	=<?\n			PHP script text
+!:mime	text/x-php
 0	search/1	=<?\r			PHP script text
+!:mime	text/x-php
 0	search/1/b	#!\ /usr/local/bin/php	PHP script text executable
+!:mime	text/x-php
 0	search/1/b	#!\ /usr/bin/php	PHP script text executable
+!:mime	text/x-php
 
 0	string		Zend\x00		PHP script Zend Optimizer data
 

+ 2 - 2
magic/Magdir/compress

@@ -9,8 +9,8 @@
 # because it tries to uncompress it to figure out what's inside.
 
 # standard unix compress
-#0	string		\037\235	compress'd data
-#!:mime	application/x-compress
+0	string		\037\235	compress'd data
+!:mime	application/x-compress
 >2	byte&0x80	>0		block compressed
 >2	byte&0x1f	x		%d bits
 

+ 6 - 6
magic/Magdir/console

@@ -117,6 +117,12 @@
 #
 0 belong 0x37804012    V64 Nintendo 64 ROM dump
 
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+# Nintendo .nds
+192	string	\044\377\256Qi\232	Nintendo DS Game ROM Image
+# Nintendo .gba
+0	string	\056\000\000\352$\377\256Qi	Nintendo Game Boy Advance ROM Image
+
 #------------------------------------------------------------------------------
 # msx: file(1) magic for MSX game cartridge dumps
 # Too simple - MPi
@@ -246,9 +252,3 @@
 >>>(0x18.l-26)	lelong		x	CRC32 0x%08x
 >>>(0x18.l-23)	string		x	"%s"
 
-# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
-# .w3g
-0	string Warcraft\ III\ recorded\ game	%s
-# .w3m
-0	string HM3W				Warcraft III map file
-

+ 1 - 1
magic/Magdir/database

@@ -234,7 +234,7 @@
 0	string		PGDMP		PostgreSQL custom database dump
 >5	byte		x		- v%d
 >6	byte		x		\b.%d
->5	beshort		<=0x100		\b-0
+>5	beshort		<0x101		\b-0
 >5	beshort		>0x100
 >>7	byte		x		\b-%d
 

+ 5 - 0
magic/Magdir/diff

@@ -2,8 +2,13 @@
 # diff:  file(1) magic for diff(1) output
 #
 0	search/1	diff\ 		diff output text
+!:mime	text/x-diff
 0	search/1	***\ 		diff output text
+!:mime	text/x-diff
 0	search/1	Only\ in\ 	diff output text
+!:mime	text/x-diff
 0	search/1	Common\ subdirectories:\ 	diff output text
+!:mime	text/x-diff
 
 0	search/1	Index:		RCS/CVS diff output text
+!:mime	text/x-diff

+ 18 - 9
magic/Magdir/elf

@@ -7,7 +7,12 @@
 #
 # What're the correct byte orders for the nCUBE and the Fujitsu VPP500?
 #
-# updated by Daniel Quinlan (quinlan@yggdrasil.com)
+# Created by: unknown
+# Modified by (1): Daniel Quinlan <quinlan@yggdrasil.com>
+# Modified by (2): Peter Tobias <tobias@server.et-inf.fho-emden.de> (core support)
+# Modified by (3): Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de> (fix of core support)
+# Modified by (4): <gerardo.cacciari@gmail.com> (VMS Itanium)
+# Modified by (5): Matthias Urlichs <smurf@debian.org> (Listing of many architectures)
 0	string		\177ELF		ELF
 >4	byte		0		invalid class
 >4	byte		1		32-bit
@@ -15,6 +20,7 @@
 >5	byte		0		invalid byte order
 >5	byte		1		LSB
 >>16	leshort		0		no file type,
+!:strength *2
 !:mime	application/octet-stream
 >>16	leshort		1		relocatable,
 !:mime	application/x-object
@@ -22,8 +28,6 @@
 !:mime	application/x-executable
 >>16	leshort		3		shared object,
 !:mime	application/x-sharedlib
-# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>
-# corrections by Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
 >>16	leshort		4		core file
 !:mime	application/x-coredump
 # Core file detection is not reliable.
@@ -79,7 +83,7 @@
 >>>48	leshort		&0x0008		(LP64),
 >>18	leshort		16		nCUBE,
 >>18	leshort		17		Fujitsu VPP500,
->>18	leshort		18		SPARC32PLUS,
+>>18	leshort		18		SPARC32PLUS - invalid byte order,
 >>18	leshort		20		PowerPC,
 >>18	leshort		22		IBM S/390,
 >>18	leshort		36		NEC V800,
@@ -210,10 +214,10 @@
 >>18	beshort		16		nCUBE,
 >>18	beshort		17		Fujitsu VPP500,
 >>18	beshort		18		SPARC32PLUS,
->>>36	belong&0xffff00	&0x000100	V8+ Required,
->>>36	belong&0xffff00	&0x000200	Sun UltraSPARC1 Extensions Required,
->>>36	belong&0xffff00	&0x000400	HaL R1 Extensions Required,
->>>36	belong&0xffff00	&0x000800	Sun UltraSPARC3 Extensions Required,
+>>>36	belong&0xffff00	0x000100	V8+ Required,
+>>>36	belong&0xffff00	0x000200	Sun UltraSPARC1 Extensions Required,
+>>>36	belong&0xffff00	0x000400	HaL R1 Extensions Required,
+>>>36	belong&0xffff00	0x000800	Sun UltraSPARC3 Extensions Required,
 >>18	beshort		20		PowerPC or cisco 4500,
 >>18	beshort		21		64-bit PowerPC or cisco 7500,
 >>18	beshort		22		IBM S/390,
@@ -228,6 +232,12 @@
 >>18	beshort		41		Alpha,
 >>18	beshort		42		Renesas SH,
 >>18	beshort		43		SPARC V9,
+>>>48	belong&0xffff00	0x000200	Sun UltraSPARC1 Extensions Required,
+>>>48	belong&0xffff00	0x000400	HaL R1 Extensions Required,
+>>>48	belong&0xffff00	0x000800	Sun UltraSPARC3 Extensions Required,
+>>>48	belong&0x3	0		total store ordering,
+>>>48	belong&0x3	1		partial store ordering,
+>>>48	belong&0x3	2		relaxed memory ordering,
 >>18	beshort		44		Siemens Tricore Embedded Processor,
 >>18	beshort		45		Argonaut RISC Core, Argonaut Technologies Inc.,
 >>18	beshort		46		Renesas H8/300,
@@ -270,7 +280,6 @@
 >>7	byte		10		(Tru64)
 >>7	byte		11		(Novell Modesto)
 >>7	byte		12		(OpenBSD)
-# VMS Itanium added by gerardo.cacciari@gmail.com
 >8      string          \2
 >>7     byte            13              (OpenVMS)
 >>7	byte		97		(ARM)

+ 38 - 0
magic/Magdir/filesystems

@@ -1266,6 +1266,34 @@
 >>>2         short   2048       AXP generated)
 >>>2         short   4096       I64 generated)
 
+# Summary: Oracle Clustered Filesystem
+# Created by: Aaron Botsis <redhat@digitalmafia.org>
+8	string		OracleCFS	Oracle Clustered Filesystem,
+>4	long		x		rev %d
+>0	long		x		\b.%d,
+>560	string		x		label: %.64s,
+>136	string		x		mountpoint: %.128s
+
+# Summary: Oracle ASM tagged volume
+# Created by: Aaron Botsis <redhat@digitalmafia.org>
+32	string		ORCLDISK	Oracle ASM Volume,
+>40	string		x		Disk Name: %0.12s
+32	string		ORCLCLRD	Oracle ASM Volume (cleared),
+>40	string		x		Disk Name: %0.12s
+
+# Oracle Clustered Filesystem - Aaron Botsis <redhat@digitalmafia.org>
+8	string		OracleCFS	Oracle Clustered Filesystem,
+>4	long		x		rev %d
+>0	long		x		\b.%d,
+>560	string		x		label: %.64s,
+>136	string		x		mountpoint: %.128s
+
+# Oracle ASM tagged volume - Aaron Botsis <redhat@digitalmafia.org>
+32	string		ORCLDISK	Oracle ASM Volume,
+>40	string		x		Disk Name: %0.12s
+32	string		ORCLCLRD	Oracle ASM Volume (cleared),
+>40	string		x		Disk Name: %0.12s
+
 # Compaq/HP RILOE floppy image
 # From: Dirk Jagdmann <doj@cubic.org>
 0	string	CPQRFBLO	Compaq/HP RILOE floppy image
@@ -1289,3 +1317,13 @@
 # really le32 operation,destination,payloadsize (but quite predictable)
 # 01 00 00 00 00 00 00 c0 00 02 00 00
 0	string		\1\0\0\0\0\0\0\300\0\2\0\0	Marvell Libertas firmware
+
+# From Eric Sandeen
+# GFS2
+0x10000         belong          0x01161970      GFS2 Filesystem
+>0x10024        belong          x               (blocksize %d,
+>0x10060        string          >\0             lockproto %s)
+
+# dvdisaster's .ecc
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+0	string	*dvdisaster*	dvdisaster error correction file

+ 2 - 2
magic/Magdir/freebsd

@@ -128,10 +128,10 @@
 # What are you laughing about?
 0	lelong			011421044151	ld.so hints file (Little Endian
 >4	lelong			>0		\b, version %d)
->4	belong			<=0		\b)
+>4	belong			<1		\b)
 0	belong			011421044151	ld.so hints file (Big Endian
 >4	belong			>0		\b, version %d)
->4	belong			<=0		\b)
+>4	belong			<1		\b)
 
 #
 # Files generated by FreeBSD scrshot(1)/vidcontrol(1) utilities

+ 0 - 2
magic/Magdir/fsav

@@ -54,8 +54,6 @@
 >>>>>>>>37	string		x 	\b%-.1s
 >>>>>>>>>38	string		!:	
 >>>>>>>>>>38	string		x 	\b%-.1s
->>>>512	string		\037\213	\b, gzipped
->>>>769	string		ustar\0		\b, tarred
 >512	string		\037\213	\b, gzipped
 >769	string		ustar\0		\b, tarred
 

+ 92 - 0
magic/Magdir/games

@@ -151,3 +151,95 @@
 >4	lelong	x		containing %d lumps
 0	string	=PWAD		doom patch PWAD data
 >4	lelong	x		containing %d lumps
+
+
+# Summary: Warcraft 3 save
+# Extension: .w3g
+# Created by: "Nelson A. de Oliveira" <naoliv@gmail.com>
+0	string		Warcraft\ III\ recorded\ game	%s
+
+
+# Summary: Warcraft 3 map
+# Extension: .w3m
+# Created by: "Nelson A. de Oliveira" <naoliv@gmail.com>
+0	string		HM3W		Warcraft III map file
+
+
+# Summary: SGF Smart Game Format
+# Extension: .sgf
+# Reference: http://www.red-bean.com/sgf/
+# Created by: Eduardo Sabbatella <eduardo_sabbatella@yahoo.com.ar>
+# Modified by (1): Abel Cheung (regex, more game format)
+# FIXME: Some games don't have GM (game type)
+0	regex		\\(;.*GM\\[[0-9]{1,2}\\]	Smart Game Format
+>2	search/0x200	GM[
+>>&0	string		1]	(Go)
+>>&0	string		2]	(Othello)
+>>&0	string		3]	(chess)
+>>&0	string		4]	(Gomoku+Renju)
+>>&0	string		5]	(Nine Men's Morris)
+>>&0	string		6]	(Backgammon)
+>>&0	string		7]	(Chinese chess)
+>>&0	string		8]	(Shogi)
+>>&0	string		9]	(Lines of Action)
+>>&0	string		10]	(Ataxx)
+>>&0	string		11]	(Hex)
+>>&0	string		12]	(Jungle)
+>>&0	string		13]	(Neutron)
+>>&0	string		14]	(Philosopher's Football)
+>>&0	string		15]	(Quadrature)
+>>&0	string		16]	(Trax)
+>>&0	string		17]	(Tantrix)
+>>&0	string		18]	(Amazons)
+>>&0	string		19]	(Octi)
+>>&0	string		20]	(Gess)
+>>&0	string		21]	(Twixt)
+>>&0	string		22]	(Zertz)
+>>&0	string		23]	(Plateau)
+>>&0	string		24]	(Yinsh)
+>>&0	string		25]	(Punct)
+>>&0	string		26]	(Gobblet)
+>>&0	string		27]	(hive)
+>>&0	string		28]	(Exxit)
+>>&0	string		29]	(Hnefatal)
+>>&0	string		30]	(Kuba)
+>>&0	string		31]	(Tripples)
+>>&0	string		32]	(Chase)
+>>&0	string		33]	(Tumbling Down)
+>>&0	string		34]	(Sahara)
+>>&0	string		35]	(Byte)
+>>&0	string		36]	(Focus)
+>>&0	string		37]	(Dvonn)
+>>&0	string		38]	(Tamsk)
+>>&0	string		39]	(Gipf)
+>>&0	string		40]	(Kropki)
+
+
+# Summary: Civilization 4 video
+# Extension: .bik
+# Created by: Abel Cheung <abelcheung@gmail.com>
+0	string	BIKi	Civilization 4 Video
+
+
+##############################################
+# NetImmerse/Gamebryo game engine entries
+
+# Summary: Gamebryo game engine file
+# Extension: .nif, .kf
+# Created by: Abel Cheung <abelcheung@gmail.com>
+0		string		Gamebryo\ File\ Format,\ Version\ 	Gamebryo game engine file
+>&0		regex		[0-9a-z.]+				\b, version %s
+
+# Summary: Gamebryo game engine file
+# Extension: .kfm
+# Created by: Abel Cheung <abelcheung@gmail.com>
+0		string		;Gamebryo\ KFM\ File\ Version\ 		Gamebryo game engine animation File
+>&0		regex		[0-9a-z.]+				\b, version %s
+
+# Summary: NetImmerse game engine file
+# Extension .nif
+# Created by: Abel Cheung <abelcheung@gmail.com>
+0		string		NetImmerse\ File\ Format,\ Versio		
+>&0		string		n\ 					NetImmerse game engine file
+>>&0		regex		[0-9a-z.]+				\b, version %s
+

+ 4 - 0
magic/Magdir/gimp

@@ -34,3 +34,7 @@
 #       ('Bucky' LaDieu, nega@vt.edu)
 
 20      string          GIMP            GIMP brush data
+
+# GIMP Curves File
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+0	string	#\040GIMP\040Curves\040File	GIMP curve file

+ 4 - 0
magic/Magdir/gnu

@@ -36,3 +36,7 @@
 0	string	\0LOCATE	GNU findutils locate database data
 >7	string	>\0		\b, format %s
 >7	string	02		\b (frcode)
+
+# Files produced by GNU gettext
+0	long	0xDE120495		GNU-format message catalog data
+0	long	0x950412DE		GNU-format message catalog data

+ 33 - 10
magic/Magdir/hp

@@ -201,10 +201,13 @@
 0	string		msgcat01	HP NLS message catalog,
 >8	long		>0		%d messages
 
-# addendum to /etc/magic with HP-48sx file-types by phk@data.fls.dk 1jan92
-0	string		HPHP4		HP
->5	string		8		48 binary
->5	string		9		49 binary
+# Summary: HP-48/49 calculator
+# Created by: phk@data.fls.dk
+# Modified by (1): AMAKAWA Shuhei <sa264@cam.ac.uk>
+# Modified by (2): Samuel Thibault <samuel.thibault@ens-lyon.org> (HP49 support)
+0	string		HPHP		HP
+>4	string		48		48 binary
+>4	string		49		49 binary
 >7	byte		>64		- Rev %c
 >8	leshort		0x2911		(ADR)
 >8	leshort		0x2933		(REAL)
@@ -231,7 +234,7 @@
 >8	leshort		0x2e6d		(LNAME)
 >8	leshort		0x2e92		(XLIB)
 
-0	search/1	%%HP:		HP text
+0	string		%%HP:		HP text
 >6	string		T(0)		- T(0)
 >6	string		T(1)		- T(1)
 >6	string		T(2)		- T(2)
@@ -242,9 +245,31 @@
 >14	string		F(.)		F(.);
 >14	string		F(,)		F(,);
 
-0	string		HP3		HP
->3	string		8		38
->3	string		9		39
+
+# Summary: HP-38/39 calculator
+# Created by: Samuel Thibault <samuel.thibault@ens-lyon.org>
+0	string		HP3
+>3	string		8		HP 38
+>3	string		9		HP 39
+>4	string		Bin		binary
+>4	string		Asc		ASCII
+>7	string		A		(Directory List)
+>7	string		B		(Zaplet)
+>7	string		C		(Note)
+>7	string		D		(Program)
+>7	string		E		(Variable)
+>7	string		F		(List)
+>7	string		G		(Matrix)
+>7	string		H		(Library)
+>7	string		I		(Target List)
+>7	string		J		(ASCII Vector specification)
+>7	string		K		(wildcard)
+
+# Summary: HP-38/39 calculator
+# Created by: Samuel Thibault <samuel.thibault@ens-lyon.org>
+0	string		HP3
+>3	string		8		HP 38
+>3	string		9		HP 39
 >4	string		Bin		binary
 >4	string		Asc		ASCII
 >7	string		A		(Directory List)
@@ -409,6 +434,4 @@
 >>>>>>>>>0xC4	belong	33		- received SIGXCPU
 >>>>>>>>>0xC4	belong	34		- received SIGXFSZ
 
-# From: AMAKAWA Shuhei <sa264@cam.ac.uk>
-#0	string	HPHP49-			HP49 binary
 

+ 28 - 16
magic/Magdir/images

@@ -75,11 +75,9 @@
 #
 # 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
 #
-0	string		\x89PNG		PNG image data,
+0	string		\x89PNG\x0d\x0a\x1a\x0a		PNG image
 !:mime	image/png
->4	belong		!0x0d0a1a0a	CORRUPTED,
->4	belong		0x0d0a1a0a
->>16	belong		x		%ld x
+>>16	belong		x		\b, %ld x
 >>20	belong		x		%ld,
 >>24	byte		x		%d-bit
 >>25	byte		0		grayscale,
@@ -90,7 +88,6 @@
 #>>26	byte		0		deflate/32K,
 >>28	byte		0		non-interlaced
 >>28	byte		1		interlaced
-1	string		PNG		PNG image data, CORRUPTED
 
 # possible GIF replacements; none yet released!
 # (Greg Roelofs, newt@uchicago.edu)
@@ -160,9 +157,6 @@
 
 # CGM image files
 0	string		BEGMF		clear text Computer Graphics Metafile
-# XXX - questionable magic
-#0	beshort&0xffe0	0x0020		binary Computer Graphics Metafile
-#0	beshort		0x3020		character Computer Graphics Metafile
 
 # MGR bitmaps  (Michael Haardt, u31b3hs@pool.informatik.rwth-aachen.de)
 0	string	yz	MGR bitmap, modern format, 8-bit aligned
@@ -184,15 +178,22 @@
 
 
 # PC bitmaps (OS/2, Windows BMP files)  (Greg Roelofs, newt@uchicago.edu)
-0	string		BM		PC bitmap data
+0	string		BM
+>14	leshort		12		PC bitmap, OS/2 1.x format
 !:mime	image/x-ms-bmp
->14	leshort		12		\b, OS/2 1.x format
 >>18	leshort		x		\b, %d x
 >>20	leshort		x		%d
->14	leshort		64		\b, OS/2 2.x format
+>14	leshort		64		PC bitmap, OS/2 2.x format
+!:mime	image/x-ms-bmp
 >>18	leshort		x		\b, %d x
 >>20	leshort		x		%d
->14	leshort		40		\b, Windows 3.x format
+>14	leshort		40		PC bitmap, Windows 3.x format
+!:mime	image/x-ms-bmp
+>>18	lelong		x		\b, %d x
+>>22	lelong		x		%d x
+>>28	leshort		x		%d
+>14	leshort		128		PC bitmap, Windows NT/2000 format
+!:mime	image/x-ms-bmp
 >>18	lelong		x		\b, %d x
 >>22	lelong		x		%d x
 >>28	leshort		x		%d
@@ -292,7 +293,6 @@
 
 # other images
 0	string	This\ is\ a\ BitMap\ file	Lisp Machine bit-array-file
-#0	string		=!!		Bennet Yee's "face" format
 
 # From SunOS 5.5.1 "/etc/magic" - appeared right before Sun raster image
 # stuff.
@@ -539,10 +539,18 @@
 # http://www.dalibor.cz/minolta/raw_file_format.htm
 0	string	\000MRM			Minolta Dimage camera raw image data
 
-# From: stephane.loeuillet@tiscali.f
-# http://www.djvuzone.org/
-0	string	AT&TFORM		DjVu Image file
+# Summary: DjVu image / document
+# Extension: .djvu
+# Reference: http://djvu.org/docs/DjVu3Spec.djvu
+# Submitted by: Stephane Loeuillet <stephane.loeuillet@tiscali.fr>
+# Modified by (1): Abel Cheung <abelcheung@gmail.com>
+0	string	AT&TFORM
 !:mime	image/vnd.djvu
+>12	string	DJVM		DjVu multiple page document
+>12	string	DJVU		DjVu image or single page document
+>12	string	DJVI		DjVu shared document
+>12	string	THUM		DjVu page thumbnails
+
 
 # From Marc Espie
 0	lelong	20000630		OpenEXR image data
@@ -588,3 +596,7 @@
 0	string	\xed\xfe\xda\xbe	Cytovision FLEX file
 0	string	\xed\xab\xed\xfe	Cytovision FLEX file
 0	string	\xad\xfd\xea\xad	Cytovision RATS file
+
+# Wavelet Scalar Quantization format used in gray-scale fingerprint images
+# From Tano M Fotang <mfotang@quanteq.com>
+0	string	\xff\xa0\xff\xa8\x00	Wavelet Scalar Quantization image data

+ 16 - 1
magic/Magdir/linux

@@ -83,7 +83,7 @@
 # Linux kernel boot images (i386 arch) (Wolfram Kleff)
 514	string		HdrS		Linux kernel
 >510	leshort		0xAA55		x86 boot executable
->>518	leshort		>=0x200
+>>518	leshort		>0x1ff
 >>529	byte		0		zImage,
 >>>529	byte		1		bzImage,
 >>>(526.s+0x200) string	>\0		version %s,
@@ -231,6 +231,14 @@
 0x618		 string	LVM2\ 001	LVM2 (Linux Logical Volume Manager)
 >(0x614.l+0x600) string	>\0		, UUID: %s
 
+# LVM snapshot
+# from Jason Farrel
+0	string	SnAp	LVM Snapshot (CopyOnWrite store)
+>4	lelong	!0	- valid,
+>4	lelong	0	- invalid,
+>8	lelong	x	version %d,
+>12	lelong	x	chunk_size %d
+
 # SE Linux policy database
 0	lelong	0xf97cff8c		SE Linux policy
 >16	lelong	x			v%d
@@ -247,3 +255,10 @@
 >72	string	x		%s]
 >168	string	x		UUID: %s
 
+
+# Summary: Xen saved domain file
+# Created by: Radek Vokal <rvokal@redhat.com>
+0	string		LinuxGuestRecord	Xen saved domain
+>20	search/256	(name			
+>>&1	string		x			(name %s)
+

+ 10 - 5
magic/Magdir/lisp

@@ -12,12 +12,19 @@
 #>2	search/2048	\r		Windows INF file
 
 0	search/256	(if\ 			Lisp/Scheme program text
+!:mime	text/x-lisp
 0	search/256	(setq\ 			Lisp/Scheme program text
+!:mime	text/x-lisp
 0	search/256	(defvar\ 		Lisp/Scheme program text
+!:mime	text/x-lisp
 0	search/256	(defparam\ 		Lisp/Scheme program text
+!:mime	text/x-lisp
 0	search/256	(defun\  		Lisp/Scheme program text
+!:mime	text/x-lisp
 0	search/256	(autoload\ 		Lisp/Scheme program text
+!:mime	text/x-lisp
 0	search/256	(custom-set-variables\ 	Lisp/Scheme program text
+!:mime	text/x-lisp
 
 # Emacs 18 - this is always correct, but not very magical.
 0	string	\012(			Emacs v18 byte-compiled Lisp data
@@ -31,14 +38,12 @@
 !:mime	application/x-elc		
 
 # Files produced by CLISP Common Lisp From: Bruno Haible <haible@ilog.fr>
-0	string	(SYSTEM::VERSION\040'	CLISP byte-compiled Lisp program
+0	string	(SYSTEM::VERSION\040'	CLISP byte-compiled Lisp program (pre 2004-03-27)
+0	string	(|SYSTEM|::|VERSION|\040'	CLISP byte-compiled Lisp program text
+
 0	long	0x70768BD2		CLISP memory image data
 0	long	0xD28B7670		CLISP memory image data, other endian
 
-# Files produced by GNU gettext
-0	long	0xDE120495		GNU-format message catalog data
-0	long	0x950412DE		GNU-format message catalog data
-
 #.com and .bin for MIT scheme 
 0	string	\372\372\372\372	MIT scheme (library?)
 

+ 8 - 1
magic/Magdir/misctools

@@ -10,5 +10,12 @@
 4	string	gtktalog		GNOME Catalogue (gtktalog)
 >13	string	>\0			version %s
 
-# From: Tomasz Trojanowski <tomek@uninet.com.pl>
+# Summary: Libtool library file
+# Extension: .la
+# Submitted by: Tomasz Trojanowski <tomek@uninet.com.pl>
 0	search/80	.la\ -\ a\ libtool\ library\ file	libtool library file
+
+# Summary: Libtool object file
+# Extension: .lo
+# Submitted by: Abel Cheung <abelcheung@gmail.com>
+0	search/80	.lo\ -\ a\ libtool\ object\ file	libtool object file

+ 119 - 146
magic/Magdir/msdos

@@ -7,9 +7,13 @@
 # updated by Joerg Jenderek
 0	string	@			
 >1	string/cB	\ echo\ off	MS-DOS batch file text
+!:mime	text/x-msdos-batch
 >1	string/cB	echo\ off	MS-DOS batch file text
+!:mime	text/x-msdos-batch
 >1	string/cB	rem\ 		MS-DOS batch file text
+!:mime	text/x-msdos-batch
 >1	string/cB	set\ 		MS-DOS batch file text
+!:mime	text/x-msdos-batch
 
 
 # OS/2 batch files are REXX. the second regex is a bit generic, oh well
@@ -39,14 +43,15 @@
 #
 # Required OS version and subsystem version were 4.0 on some NT 3.51
 # executables built with Visual C++ 4.0, so it's not clear that
-# they're interesting.  The user version was 0.0, but there's
+# they're interesting.	The user version was 0.0, but there's
 # probably some linker directive to set it.  The linker version was
 # 3.0, except for one ".exe" which had it as 4.20 (same damn linker!).
 #
 # many of the compressed formats were extraced from IDARC 1.23 source code
 #
-0	string	MZ		MS-DOS executable
+0	string	MZ
 !:mime	application/x-dosexec
+>0x18  leshort <0x40 MS-DOS executable
 >0 string MZ\0\0\0\0\0\0\0\0\0\0PE\0\0 \b, PE for MS Windows
 >>&18	leshort&0x2000	>0	(DLL)
 >>&88	leshort		0	(unknown subsystem)
@@ -72,27 +77,35 @@
 !:mime	application/zip
 
 >0x18  leshort >0x3f
->>(0x3c.l) string PE\0\0 PE 
+>>(0x3c.l) string PE\0\0 PE
+>>>(0x3c.l+25) byte		1 \b32 executable
+>>>(0x3c.l+25) byte		2 \b32+ executable
 # hooray, there's a DOS extender using the PE format, with a valid PE
 # executable inside (which just prints a message and exits if run in win)
->>>(8.s*16) string 32STUB for MS-DOS, 32rtm DOS extender
->>>(8.s*16) string !32STUB for MS Windows
->>>>(0x3c.l+22)	leshort&0x2000	>0	(DLL)
->>>>(0x3c.l+92)	leshort		0	(unknown subsystem)
->>>>(0x3c.l+92)	leshort		1	(native)
->>>>(0x3c.l+92)	leshort		2	(GUI)
->>>>(0x3c.l+92)	leshort		3	(console)
->>>>(0x3c.l+92)	leshort		7	(POSIX)
->>>>(0x3c.l+4)	leshort		0x0	unknown processor
->>>>(0x3c.l+4)	leshort		0x14c	Intel 80386
->>>>(0x3c.l+4)	leshort		0x166	MIPS R4000
->>>>(0x3c.l+4)	leshort		0x184	Alpha
->>>>(0x3c.l+4)	leshort		0x268	Motorola 68000
->>>>(0x3c.l+4)	leshort		0x1f0	PowerPC
->>>>(0x3c.l+4)	leshort		0x290	PA-RISC
->>>>(0x3c.l+22)	leshort&0x0100	>0	32-bit
->>>>(0x3c.l+22)	leshort&0x1000	>0	system file
->>>>(0x3c.l+232)	lelong	>0	Mono/.Net assembly
+>>>(0x3c.l+92)	leshort		<10
+>>>>(8.s*16) string 32STUB for MS-DOS, 32rtm DOS extender
+>>>>(8.s*16) string !32STUB for MS Windows
+>>>>>(0x3c.l+22)	leshort&0x2000	>0	(DLL)
+>>>>>(0x3c.l+92)	leshort		0	(unknown subsystem)
+>>>>>(0x3c.l+92)	leshort		1	(native)
+>>>>>(0x3c.l+92)	leshort		2	(GUI)
+>>>>>(0x3c.l+92)	leshort		3	(console)
+>>>>>(0x3c.l+92)	leshort		7	(POSIX)
+>>>(0x3c.l+92)	leshort		10	(EFI application)
+>>>(0x3c.l+92)	leshort		11	(EFI boot service driver)
+>>>(0x3c.l+92)	leshort		12	(EFI runtime driver)
+>>>(0x3c.l+92)	leshort		13	(XBOX)
+>>>(0x3c.l+4)	leshort		0x0	unknown processor
+>>>(0x3c.l+4)	leshort		0x14c	Intel 80386
+>>>(0x3c.l+4)	leshort		0x166	MIPS R4000
+>>>(0x3c.l+4)	leshort		0x184	Alpha
+>>>(0x3c.l+4)	leshort		0x268	Motorola 68000
+>>>(0x3c.l+4)	leshort		0x1f0	PowerPC
+>>>(0x3c.l+4)	leshort		0x290	PA-RISC
+>>>(0x3c.l+4)	leshort		0x200	Intel Itanium
+>>>(0x3c.l+22)	leshort&0x0100	>0	32-bit
+>>>(0x3c.l+22)	leshort&0x1000	>0	system file
+>>>(0x3c.l+232) lelong	>0	Mono/.Net assembly
 
 >>>>(0x3c.l+0xf8)	string		UPX0 \b, UPX compressed
 >>>>(0x3c.l+0xf8)	search/0x140	PEC2 \b, PECompact2 compressed
@@ -121,6 +134,8 @@
 >>>>&(0x3c.l+0xf8)	search/0x100	SharedD \b, Microsoft Installer self-extracting archive
 >>>>0x30		string		Inno \b, InnoSetup self-extracting archive
 
+>>(0x3c.l) string !PE\0\0 MS-DOS executable
+
 >>(0x3c.l)		string		NE \b, NE
 >>>(0x3c.l+0x36)	byte		0 (unknown OS)
 >>>(0x3c.l+0x36)	byte		1 for OS/2 1.x
@@ -182,7 +197,7 @@
 >>>(4.s*512)	leshort !0x014c \b, MZ for MS-DOS
 # header data too small for extended executable
 >2		long	!0
->>0x18		leshort	<0x40
+>>0x18		leshort <0x40
 >>>(4.s*512)	leshort !0x014c
 
 >>>>&(2.s-514)	string	!LE
@@ -212,31 +227,31 @@
 
 # .EXE formats (Greg Roelofs, newt@uchicago.edu)
 #
->0x35   string  \x8e\xc0\xb9\x08\x00\xf3\xa5\x4a\x75\xeb\x8e\xc3\x8e\xd8\x33\xff\xbe\x30\x00\x05 \b, aPack compressed
+>0x35	string	\x8e\xc0\xb9\x08\x00\xf3\xa5\x4a\x75\xeb\x8e\xc3\x8e\xd8\x33\xff\xbe\x30\x00\x05 \b, aPack compressed
 >0xe7	string	LH/2\ Self-Extract \b, %s
 >0x1c	string	diet \b, diet compressed
 >0x1c	string	LZ09 \b, LZEXE v0.90 compressed
 >0x1c	string	LZ91 \b, LZEXE v0.91 compressed
->0x1c   string  tz \b, TinyProg compressed
+>0x1c	string	tz \b, TinyProg compressed
 >0x1e	string	PKLITE \b, %s compressed
->0x64   string  W\ Collis\0\0 \b, Compack compressed
+>0x64	string	W\ Collis\0\0 \b, Compack compressed
 >0x24	string	LHa's\ SFX \b, LHa self-extracting archive
 !:mime	application/x-lha
 >0x24	string	LHA's\ SFX \b, LHa self-extracting archive
 !:mime	application/x-lha
->0x24   string  \ $ARX \b, ARX self-extracting archive
->0x24   string  \ $LHarc \b, LHarc self-extracting archive
->0x20   string  SFX\ by\ LARC \b, LARC self-extracting archive
+>0x24	string	\ $ARX \b, ARX self-extracting archive
+>0x24	string	\ $LHarc \b, LHarc self-extracting archive
+>0x20	string	SFX\ by\ LARC \b, LARC self-extracting archive
 >1638	string	-lh5- \b, LHa self-extracting archive v2.13S
->0x17888 string	Rar! \b, RAR self-extracting archive
->0x40   string aPKG \b, aPackage self-extracting archive
+>0x17888 string Rar! \b, RAR self-extracting archive
+>0x40	string aPKG \b, aPackage self-extracting archive
 
->32      string AIN
->>35     string 2              \b, AIN 2.x compressed
->>35     string <2             \b, AIN 1.x compressed
->>35     string >2             \b, AIN 1.x compressed
->28      string UC2X           \b, UCEXE compressed
->28      string WWP\           \b, WWPACK compressed
+>32	 string AIN
+>>35	 string 2		\b, AIN 2.x compressed
+>>35	 string <2		\b, AIN 1.x compressed
+>>35	 string >2		\b, AIN 1.x compressed
+>28	 string UC2X		\b, UCEXE compressed
+>28	 string WWP\  		\b, WWPACK compressed
 
 # skip to the end of the exe
 >(4.s*512)	long	x 
@@ -263,15 +278,15 @@
 
 # TELVOX Teleinformatica CODEC self-extractor for OS/2:
 >49801	string	\x79\xff\x80\xff\x76\xff	\b, CODEC archive v3.21
->>49824	leshort		=1			\b, 1 file
->>49824	leshort		>1			\b, %u files
+>>49824 leshort		=1			\b, 1 file
+>>49824 leshort		>1			\b, %u files
 
 # .COM formats (Daniel Quinlan, quinlan@yggdrasil.com)
 # Uncommenting only the first two lines will cover about 2/3 of COM files,
 # but it isn't feasible to match all COM files since there must be at least
 # two dozen different one-byte "magics".
 #0	byte		0xe9		DOS executable (COM)
-#>0x1FE	leshort		0xAA55		\b, boot code
+#>0x1FE leshort		0xAA55		\b, boot code
 >6	string		SFX\ of\ LHarc	(%s)
 0	belong	0xffffffff		DOS executable (device driver)
 #CMD640X2.SYS
@@ -297,22 +312,22 @@
 #0	byte		0x8c		DOS executable (COM)
 # 0xeb conflicts with "sequent" magic
 #0	byte		0xeb		DOS executable (COM)
-#>0x1FE	leshort		0xAA55		\b, boot code
+#>0x1FE leshort		0xAA55		\b, boot code
 #>85	string		UPX		\b, UPX compressed
 #>4	string		\ $ARX		\b, ARX self-extracting archive
 #>4	string		\ $LHarc	\b, LHarc self-extracting archive
-#>0x20e	string		SFX\ by\ LARC	\b, LARC self-extracting archive
+#>0x20e string		SFX\ by\ LARC	\b, LARC self-extracting archive
 #0	byte		0xb8		COM executable
 # modified by Joerg Jenderek
->1	lelong          !0x21cd4cff	for DOS
+>1	lelong		!0x21cd4cff	for DOS
 # http://syslinux.zytor.com/comboot.php
 # (32-bit COMBOOT) programs *.C32 contain 32-bit code and run in flat-memory 32-bit protected mode
 # start with assembler instructions mov eax,21cd4cffh
->1	lelong          0x21cd4cff	(32-bit COMBOOT)
+>1	lelong		0x21cd4cff	(32-bit COMBOOT)
 0	string	\x81\xfc		
 >4	string	\x77\x02\xcd\x20\xb9	
->>36	string	UPX! 			FREE-DOS executable (COM), UPX compressed
-252	string Must\ have\ DOS\ version	DR-DOS executable (COM)
+>>36	string	UPX!			FREE-DOS executable (COM), UPX compressed
+252	string Must\ have\ DOS\ version DR-DOS executable (COM)
 # GRR search is not working
 #2	search/28	\xcd\x21	COM executable for MS-DOS
 #WHICHFAT.cOM
@@ -349,14 +364,6 @@
 #0	byte		0xf0		MS-DOS program library data
 #
 
-#
-# Windows Registry files.
-# updated by Joerg Jenderek
-0	string		regf		Windows NT/XP registry file
-0	string		CREG		Windows 95/98/ME registry file
-0	string		SHCC3		Windows 3.1 registry file
-
-
 # AAF files:
 # <stuartc@rd.bbc.co.uk> Stuart Cunningham
 0	string	\320\317\021\340\241\261\032\341AAFB\015\000OM\006\016\053\064\001\001\001\377			AAF legacy file using MS Structured Storage
@@ -378,7 +385,7 @@
 0	belong	0x31be0000			Microsoft Word Document
 !:mime	application/msword
 #
-0       string  PO^Q`				Microsoft Word 6.0 Document
+0	string	PO^Q`				Microsoft Word 6.0 Document
 !:mime	application/msword
 #
 0	string	\376\067\0\043			Microsoft Office Document
@@ -410,7 +417,7 @@
 >4	belong	0x07800100	fm3 or fmb document data
 >4	belong	0x07800000	fm3 or fmb document data
 #
-0	belong	0x00000200 	Lotus 1-2-3
+0	belong	0x00000200	Lotus 1-2-3
 !:mime	application/x-123
 >4	belong	0x06040600	wk1 document data
 >4	belong	0x06800200	fmt document data
@@ -420,24 +427,21 @@
 !:mime	application/vnd.lotus-wordpro
 
 
-# Help files
-0	string	?_\3\0		MS Windows Help Data
-
-#  DeIsL1.isu what this is I don't know
-0	string	\161\250\000\000\001\002	DeIsL1.isu whatever that is
+# Summary: Script used by InstallScield to uninstall applications
+# Extension: .isu
+# Submitted by: unknown
+# Modified by (1): Abel Cheung <abelcheung@gmail.com> (replace useless entry)
+0		string		\x71\xa8\x00\x00\x01\x02
+>12		string		Stirling\ Technologies,		InstallShield Uninstall Script
 
 # Winamp .avs
-#0	string	Nullsoft\ AVS\ Preset\ \060\056\061\032	A plug in for Winamp ms-windows Freeware media player
+#0	string	Nullsoft\ AVS\ Preset\ \060\056\061\032 A plug in for Winamp ms-windows Freeware media player
 0	string	Nullsoft\ AVS\ Preset\ 	Winamp plug in
 
-# Hyper terminal:
-0	string	HyperTerminal\ 	hyperterm
->15	string	1.0\ --\ HyperTerminal\ data\ file	MS-windows Hyperterminal
-
 # Windows Metafont .WMF
-0       string  \327\315\306\232        ms-windows metafont .wmf
-0       string  \002\000\011\000        ms-windows metafont .wmf
-0       string  \001\000\011\000        ms-windows metafont .wmf
+0	string	\327\315\306\232	ms-windows metafont .wmf
+0	string	\002\000\011\000	ms-windows metafont .wmf
+0	string	\001\000\011\000	ms-windows metafont .wmf
 
 #tz3 files whatever that is (MS Works files)
 0	string	\003\001\001\004\070\001\000\000	tz3 ms-works file
@@ -457,16 +461,6 @@
 0	string	MDIF\032\000\010\000\000\000\372\046\100\175\001\000\001\036\001\000 MS Windows special zipped file
 
 
-# Windows help file FTG FTS
-0	string	\164\146\115\122\012\000\000\000\001\000\000\000	MS Windows help cache
-
-# grp old windows 3.1 group files
-0 string  \120\115\103\103	MS Windows 3.1 group files
-
-
-# lnk files windows symlinks
-0	string	\114\000\000\000\001\024\002\000\000\000\000\000\300\000\000\000\000\000\000\106	MS Windows shortcut
-
 #ico files
 0	string	\102\101\050\000\000\000\056\000\000\000\000\000\000\000	Icon for MS Windows
 
@@ -493,18 +487,27 @@
 # then there is a copyright notice
 
 
-# recycled/info the windows trash bin index
-9	string	\000\000\000\030\001\000\000\000 MS Windows recycled bin info
+# Windows Recycle Bin record file (named INFO2)
+# By Abel Cheung (abelcheung AT gmail dot com)
+# Version 4 always has 280 bytes (0x118) per record, version 5 has 800 bytes
+# Since Vista uses another structure, INFO2 structure probably won't change
+# anymore. Detailed analysis in:
+# http://www.cybersecurityinstitute.biz/downloads/INFO2.pdf
+0	lelong		0x00000004
+>12	lelong		0x00000118	Windows Recycle Bin INFO2 file (Win98 or below)
+
+0	lelong		0x00000005
+>12	lelong		0x00000320	Windows Recycle Bin INFO2 file (Win2k - WinXP)
 
 
 ##### put in Either Magic/font or Magic/news
-# Acroread or something  files wrongly identified as G3  .pfm
+# Acroread or something	 files wrongly identified as G3	 .pfm
 # these have the form \000 \001 any? \002 \000 \000
 # or \000 \001 any? \022 \000 \000
-#0	string  \000\001 pfm?
-#>3	string  \022\000\000Copyright\  yes
-#>3	string  \002\000\000Copyright\  yes
-#>3	string  >\0     oops, not a font file. Cancel that.
+#0	string	\000\001 pfm?
+#>3	string	\022\000\000Copyright\	yes
+#>3	string	\002\000\000Copyright\	yes
+#>3	string	>\0	oops, not a font file. Cancel that.
 #it clashes with ttf files so put it lower down.
 
 # From Doug Lee via a FreeBSD pr
@@ -552,7 +555,7 @@
 !:mime	application/vnd.ms-tnef
 
 # HtmlHelp files (.chm)
-0	string  ITSF\003\000\000\000\x60\000\000\000\001\000\000\000	MS Windows HtmlHelp Data
+0	string	ITSF\003\000\000\000\x60\000\000\000\001\000\000\000	MS Windows HtmlHelp Data
 
 # GFA-BASIC (Wolfram Kleff)
 2	string		GFA-BASIC3	GFA-BASIC 3 data
@@ -567,8 +570,8 @@
 
 # InstallShield Cabinet files
 0	string		ISc(		InstallShield Cabinet archive data
->5	byte&0xf0	=0x60 		version 6,
->5	byte&0xf0	!0x60 		version 4/5,
+>5	byte&0xf0	=0x60		version 6,
+>5	byte&0xf0	!0x60		version 4/5,
 >(12.l+40)	lelong	x		%u files
 
 # Windows CE package files
@@ -582,57 +585,27 @@
 >20	lelong		10004		\b, Hitachi SH3E
 >20	lelong		10005		\b, Hitachi SH4
 >20	lelong		70001		\b, ARM 7TDMI
->52	leshort		1 		\b, 1 file
->52	leshort		>1 		\b, %u files
->56	leshort		1 		\b, 1 registry entry
->56	leshort		>1 		\b, %u registry entries
-
-# Outlook Personal Folders
-0	lelong	0x4E444221	Microsoft Outlook binary email folder
->10	leshort 0x0e		(Outlook <=2002)
->10	leshort 0x17		(Outlook >=2003)
-
-
-# From: Dirk Jagdmann <doj@cubic.org>
-0	lelong	0x00035f3f	Windows 3.x help file
-
-# Christophe Monniez
-0	string	Client\ UrlCache\ MMF 	Microsoft Internet Explorer Cache File
->20	string	>\0			Version %s
-0	string	\xCF\xAD\x12\xFE	Microsoft Outlook Express DBX File
->4	byte	=0xC5			Message database
->4	byte	=0xC6			Folder database
->4	byte	=0xC7			Accounts informations
->4	byte	=0x30			Offline database
+>52	leshort		1		\b, 1 file
+>52	leshort		>1		\b, %u files
+>56	leshort		1		\b, 1 registry entry
+>56	leshort		>1		\b, %u registry entries
 
 
 # Windows Enhanced Metafile (EMF)
 # See msdn.microsoft.com/archive/en-us/dnargdi/html/msdn_enhmeta.asp 
-# for further information. Note that "0 lelong 1" should be true i.e.
-# the first double word in the file should be 1. With the extended
-# syntax available by some file commands you could write:
-# 0 lelong 1
-# &40 ulelong 0x464D4520 Windows Enhanced Metafile (EMF) image data
-#40	ulelong 0x464D4520	Windows Enhanced Metafile (EMF) image data
-#>44	ulelong x		version 0x%x.
-# If the description has a length greater than zero, it exists and is 
-# found at offset (*64).
-#>64	ulelong >0		Description available at offset 0x%x
-#>>60	ulelong	>0		(length 0x%x)
-# Note it would be better to print out the description, which is found 
-# as below. Unfortunately the following only prints out the first couple
-# of characters instead of all the "description length"
-# number of characters -- indicated by the ulelong at offset 60.
-#>>(64.l)  lestring16 >0 Description: %15.15s
+# for further information.
+0	ulelong 1
+>40	string	\ EMF		Windows Enhanced Metafile (EMF) image data
+>>44	ulelong x		version 0x%x
 
 # From: Alex Beregszaszi <alex@fsn.hu>
 0	string	COWD		VMWare3
->4	byte	3	 	disk image
+>4	byte	3		disk image
 >>32	lelong	x		(%d/
 >>36	lelong	x		\b%d/
 >>40	lelong	x		\b%d)
->4	byte	2	 	undoable disk image
->>32	string  >\0		(%s)
+>4	byte	2		undoable disk image
+>>32	string	>\0		(%s)
 
 0	string	VMDK		 VMware4 disk image
 0	string	KDMV		 VMware4 disk image
@@ -642,39 +615,39 @@
 # Lines written by Friedrich Schwittay (f.schwittay@yousable.de)
 # Made by reading sources and doing trial and error on existing
 # qcow files
-0       string  QFI     Qemu Image, Format: Qcow
+0	string	QFI	Qemu Image, Format: Qcow
 
 # Uncomment the following line to display Magic (only used for debugging
 # this magic number)
-#>0     string  x       , Magic: %s
+#>0	string	x	, Magic: %s
 
 # There are currently 2 Versions: "1" and "2"
 # I do not use Version 2 and therefor branch here
 # but can assure: it works (tested on both versions)
 # Also my Qemu 0.9.0 which uses this Version 2 refuses
 # to start in its bios
->0x04   belong  2       , Version: 2
->0x04   belong  1       , Version: 1
+>0x04	belong	2	, Version: 2
+>0x04	belong	1	, Version: 1
 
 # Using the existence of the Backing File Offset to Branch or not
 # to read Backing File Information
->>0xc    belong  >0      , Backing File( Offset: %lu
->>>(0xc.L)       string >\0     , Path: %s
+>>0xc	 belong	 >0	 , Backing File( Offset: %lu
+>>>(0xc.L)	 string >\0	, Path: %s
 
 # Didn't get the trick here how qemu stores the "Size" at this Position
 # There is actually something stored but nothing makes sense
 # The header in the sources talks about it
-#>>>16   lelong  x       , Size: %lu
+#>>>16	 lelong	 x	 , Size: %lu
 
 # Modification time of the Backing File
 # Really useful if you want to know if your backing
 # file is still usable together with this image
->>>20    bedate x       , Mtime: %s )
+>>>20	 bedate x	, Mtime: %s )
 
 # Don't know how to calculate in Magicfiles
 # Also: this Information is not reliably
-#       stored in image-files
->>24     lelong  x       , Disk Size could be: %d * 256 bytes
+#	stored in image-files
+>>24	 lelong	 x	 , Disk Size could be: %d * 256 bytes
 
 0	string	QEVM		QEMU's suspend to disk image
 
@@ -688,14 +661,14 @@
 # False positive with PPT (also currently this string is too long)
 #0	string	\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF\x09\x00\x06	Microsoft Installer
 0	string	\320\317\021\340\241\261\032\341	Microsoft Office Document
-#>48	byte	0x1B	                                Excel Document
-#!:mime	application/vnd.ms-excel
+#>48	byte	0x1B					Excel Document
+#!:mime application/vnd.ms-excel
 >546	string	bjbj			Microsoft Word Document
 !:mime	application/msword
 >546	string	jbjb			Microsoft Word Document
 !:mime	application/msword
 
-0       string	\224\246\056		Microsoft Word Document
+0	string	\224\246\056		Microsoft Word Document
 !:mime	application/msword
 
 512	string	R\0o\0o\0t\0\ \0E\0n\0t\0r\0y	Microsoft Word Document
@@ -709,19 +682,19 @@
 >48	string x			version %.3s
 
 # Type: Microsoft DirectDraw Surface
-# URL:  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/DDSFileReference/ddsfileformat.asp
+# URL:	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/DDSFileReference/ddsfileformat.asp
 # From: Morten Hustveit <morten@debian.org>
-0	string	DDS\040\174\000\000\000	Microsoft DirectDraw Surface (DDS),
+0	string	DDS\040\174\000\000\000 Microsoft DirectDraw Surface (DDS),
 >16	lelong	>0			%hd x
 >12	lelong	>0			%hd,
 >84	string	x			%.4s
 
 # Type: Microsoft Document Imaging Format (.mdi)
-# URL:  http://en.wikipedia.org/wiki/Microsoft_Document_Imaging_Format
+# URL:	http://en.wikipedia.org/wiki/Microsoft_Document_Imaging_Format
 # From: Daniele Sempione <scrows@oziosi.org>
 0	short	0x5045			Microsoft Document Imaging Format
 
 # MS eBook format (.lit)
-0	string  ITOLITLS		Microsoft Reader eBook Data
+0	string	ITOLITLS		Microsoft Reader eBook Data
 >8	lelong	x			\b, version %u
 !:mime					application/x-ms-reader

+ 7 - 7
magic/Magdir/perl

@@ -5,19 +5,19 @@
 # Keith Waclena <keith@cerberus.uchicago.edu>
 # Send additions to <perl5-porters@perl.org>
 0	search/1/b	#!\ /bin/perl			Perl script text executable
-!:mime	application/x-perl
+!:mime	text/x-perl
 0	search/1	eval\ "exec\ /bin/perl		Perl script text
-!:mime	application/x-perl
+!:mime	text/x-perl
 0	search/1/b	#!\ /usr/bin/perl		Perl script text executable
-!:mime	application/x-perl
+!:mime	text/x-perl
 0	search/1	eval\ "exec\ /usr/bin/perl	Perl script text
-!:mime	application/x-perl
+!:mime	text/x-perl
 0	search/1/b	#!\ /usr/local/bin/perl		Perl script text executable
-!:mime	application/x-perl
+!:mime	text/x-perl
 0	search/1	eval\ "exec\ /usr/local/bin/perl	Perl script text
-!:mime	application/x-perl
+!:mime	text/x-perl
 0	search/1	eval\ '(exit\ $?0)'\ &&\ eval\ 'exec	Perl script text
-!:mime	application/x-perl
+!:mime	text/x-perl
 
 
 # by Dmitry V. Levin and Alexey Tourbin

+ 6 - 4
magic/Magdir/printer

@@ -35,11 +35,13 @@
 >>>20   long            >0              TIFF starts at byte %d
 >>>>24  long            >0              length %d
 
-# Adobe's PostScript Printer Description (PPD) files
-#       Yves Arrouye <arrouye@marin.fdn.fr>
+# Summary: Adobe's PostScript Printer Description File
+# Extension: .ppd
+# Reference: http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf, Section 3.8
+# Submitted by: Yves Arrouye <arrouye@marin.fdn.fr>
 #
-0      string          *PPD-Adobe:    PPD file
->13    string          x              \b, ve
+0	string		*PPD-Adobe:\x20	PPD file
+>&0	string		x		\b, version %s
 
 # HP Printer Job Language
 0	string		\033%-12345X@PJL	HP Printer Job Language data

+ 1 - 1
magic/Magdir/psion

@@ -1,4 +1,3 @@
-
 #------------------------------------------------------------------------------
 # psion:  file(1) magic for Psion handhelds data
 # from: Peter Breitenlohner <peb@mppmu.mpg.de>
@@ -11,6 +10,7 @@
 >4	lelong		0x1000006A	application information file
 >4	lelong		0x1000006D
 >>8	lelong		0x1000007D	sketch image
+!:mime image/x-psion-sketch
 >>8	lelong		0x1000007E	voice note
 >>8	lelong		0x1000007F	word file
 >>8	lelong		0x10000085	OPL program

+ 1 - 1
magic/Magdir/riff

@@ -135,7 +135,7 @@
 >>>>>>>(104.l+132)      string/c        xvid    XviD
 >>>>>>>(104.l+132)	string/c	h264	H.264
 >>>>>>>(104.l+132)      string/c        wmv3    Windows Media Video 9
->>>>>>>(104.l+132)      string/c        h264    X.264
+>>>>>>>(104.l+132)      string/c        h264    X.264 or H.264
 >>>>>>>(104.l+132)      lelong  0
 ##>>>>>>>(104.l+132)      string  x       (%.4s)
 # skip past first (video) LIST

+ 10 - 0
magic/Magdir/ruby

@@ -0,0 +1,10 @@
+#------------------------------------------------------------------------------
+# ruby:  file(1) magic for Lua scripting language
+# URL:  http://www.ruby-lang.org/
+# From: Reuben Thomas <rrt@sc3d.org>
+
+# Ruby scripts
+0	search/1/b	#!\ /usr/bin/ruby	Ruby script text executable
+0	search/1/b	#!\ /usr/local/bin/ruby	Ruby script text executable
+0	search/1	#!/usr/bin/env\ ruby	Ruby script text executable
+0	search/1	#!\ /usr/bin/env\ ruby	Ruby script text executable

+ 6 - 0
magic/Magdir/sgml

@@ -25,14 +25,20 @@
 # Extensible markup language (XML), a subset of SGML
 # from Marc Prud'hommeaux (marc@apocalypse.org)
 0	search/1/cb	\<?xml			XML document text
+!:mime	application/xml
 0	string		\<?xml\ version\ "	XML
+!:mime	application/xml
 0	string		\<?xml\ version="	XML
+!:mime	application/xml
 0	string		\<?xml\ version='	XML
+!:mime	application/xml
 >15	search/1	>\0			%.3s document text
 >>23	search/1	\<xsl:stylesheet	(XSL stylesheet)
 >>24	search/1	\<xsl:stylesheet	(XSL stylesheet)
 0	search/1/b	\<?xml			XML document text
+!:mime	application/xml
 0	search/1/b	\<?XML			broken XML document text
+!:mime	application/xml
 
 
 # SGML, mostly from rph@sq

+ 3 - 1
magic/Magdir/vorbis

@@ -17,9 +17,11 @@
 # to be made relative to the search). In any case, if the file has ID3
 # tags, the ID3 information will be printed, not the Ogg information,
 # so until that's fixed, this doesn't matter.
+# FIXME[2]: Disable the above for now, since search assumes text mode.
 #
 # --- Ogg Framing ---
-0		search/1000	OggS		Ogg data
+#0		search/1000	OggS		Ogg data
+0		string	OggS		Ogg data
 !:mime		application/ogg
 >4		byte		!0		UNKNOWN REVISION %u
 ##>4		byte		0		revision 0

+ 15 - 0
magic/Magdir/weak

@@ -0,0 +1,15 @@
+#------------------------------------------------------------------------------
+# weak:  file(1) magic for very weak magic entries, disabled by default
+#
+# These entries are so weak that they might interfere identification of
+# other formats. Example include:
+# - Only identify for 1 or 2 bytes
+# - Match against very wide range of values
+# - Match against generic word in some spoken languages (e.g. English)
+
+# Summary: Computer Graphics Metafile
+# Extension: .cgm
+#0	beshort&0xffe0	0x0020		binary Computer Graphics Metafile
+#0	beshort		0x3020		character Computer Graphics Metafile
+
+#0	string		=!!		Bennet Yee's "face" format

+ 115 - 0
magic/Magdir/windows

@@ -0,0 +1,115 @@
+
+#------------------------------------------------------------------------------
+# windows:  file(1) magic for Microsoft Windows
+#
+# This file is mainly reserved for files where programs
+# using them are run almost always on MS Windows 3.x or
+# above, or files only used exclusively in Windows OS,
+# where there is no better category to allocate for.
+# For example, even though WinZIP almost run on Windows
+# only, it is better to treat them as "archive" instead.
+# For format usable in DOS, such as generic executable
+# format, please specify under "msdos" file.
+#
+
+
+# Summary: Outlook Express DBX file
+# Extension: .dbx
+# Created by: Christophe Monniez
+0	string	\xCF\xAD\x12\xFE	MS Outlook Express DBX file
+>4	byte	=0xC5			\b, message database
+>4	byte	=0xC6			\b, folder database
+>4	byte	=0xC7			\b, account information
+>4	byte	=0x30			\b, offline database
+
+
+# Summary: Windows crash dump
+# Extension: .dmp
+# Created by: Andreas Schuster (http://computer.forensikblog.de/)
+# Reference (1): http://computer.forensikblog.de/en/2008/02/64bit_magic.html
+# Modified by (1): Abel Cheung (Avoid match with first 4 bytes only)
+0	string		PAGE		
+>4	string		DUMP		MS Windows 32bit crash dump
+>>0x05c	byte            0		\b, no PAE
+>>0x05c	byte            1		\b, PAE
+>>0xf88	lelong		1		\b, full dump
+>>0xf88	lelong		2		\b, kernel dump
+>>0xf88	lelong		3		\b, small dump
+>>0x068	lelong		x		\b, %ld pages
+>4	string		DU64		MS Windows 64bit crash dump
+>>0xf98	lelong		1		\b, full dump
+>>0xf98	lelong		2		\b, kernel dump
+>>0xf98	lelong		3		\b, small dump
+>>0x090	lequad		x		\b, %lld pages
+
+
+# Summary: Vista Event Log
+# Extension: .evtx
+# Created by: Andreas Schuster (http://computer.forensikblog.de/)
+# Reference (1): http://computer.forensikblog.de/en/2007/05/some_magic.html
+0	string		ElfFile\0	MS Windows Vista Event Log
+>0x2a	leshort		x		\b, %d chunks
+>>0x10	lelong		x		\b (no. %d in use)
+>0x18	lelong		>1		\b, next record no. %d
+>0x18	lelong		=1		\b, empty
+>0x78	lelong		&1		\b, DIRTY
+>0x78	lelong		&2		\b, FULL
+
+
+# Summary: Windows 3.1 group files
+# Extension: .grp
+# Created by: unknown
+0	string		\120\115\103\103	MS Windows 3.1 group files
+
+
+# Summary: Old format help files
+# Extension: .hlp
+# Created by: Dirk Jagdmann <doj@cubic.org>
+0	lelong		0x00035f3f		MS Windows 3.x help file
+
+
+# Summary: Hyper terminal
+# Extension: .ht
+# Created by: unknown
+0	string		HyperTerminal\ 
+>15	string		1.0\ --\ HyperTerminal\ data\ file	MS Windows HyperTerminal profile
+
+
+# Summary: Windows shortcut
+# Extension: .lnk
+# Created by: unknown
+0	string		\114\0\0\0\001\024\002\0\0\0\0\0\300\0\0\0\0\0\0\106	MS Windows shortcut
+
+
+# Summary: Outlook Personal Folders
+# Created by: unknown
+0	lelong		0x4E444221	Microsoft Outlook email folder
+>10	leshort		0x0e		(<=2002)
+>10	leshort		0x17		(>=2003)
+
+
+# Summary: Windows help cache
+# Created by: unknown
+0	string		\164\146\115\122\012\000\000\000\001\000\000\000	MS Windows help cache
+
+
+# Summary: IE cache file
+# Created by: Christophe Monniez
+0	string	Client\ UrlCache\ MMF 	Internet Explorer cache file
+>20	string	>\0			version %s
+
+
+# Summary: Registry files
+# Created by: unknown
+# Modified by (1): Joerg Jenderek
+0	string		regf		MS Windows registry file, NT/2000 or above
+0	string		CREG		MS Windows 95/98/ME registry file
+0	string		SHCC3		MS Windows 3.1 registry file
+
+
+# Summary: Windows Registry text
+# Extension: .reg
+# Submitted by: Abel Cheung <abelcheung@gmail.com>
+0	string		REGEDIT4\r\n\r\n	Windows Registry text (Win95 or above)
+0	string		Windows\ Registry\ Editor\ 
+>&0	string		Version\ 5.00\r\n\r\n	Windows Registry text (Win2K or above)

+ 9 - 1
magic/Makefile.am

@@ -1,3 +1,6 @@
+#
+# $File: Makefile.am,v 1.41 2008/06/17 17:49:11 christos Exp $
+#
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_FRAGMENT_DIR = $(top_srcdir)/magic/$(MAGIC_FRAGMENT_BASE)
 
@@ -160,6 +163,7 @@ $(MAGIC_FRAGMENT_DIR)/revision \
 $(MAGIC_FRAGMENT_DIR)/riff \
 $(MAGIC_FRAGMENT_DIR)/rpm \
 $(MAGIC_FRAGMENT_DIR)/rtf \
+$(MAGIC_FRAGMENT_DIR)/ruby \
 $(MAGIC_FRAGMENT_DIR)/sc \
 $(MAGIC_FRAGMENT_DIR)/sccs \
 $(MAGIC_FRAGMENT_DIR)/scientific \
@@ -201,6 +205,8 @@ $(MAGIC_FRAGMENT_DIR)/vms \
 $(MAGIC_FRAGMENT_DIR)/vmware \
 $(MAGIC_FRAGMENT_DIR)/vorbis \
 $(MAGIC_FRAGMENT_DIR)/vxl \
+$(MAGIC_FRAGMENT_DIR)/weak \
+$(MAGIC_FRAGMENT_DIR)/windows \
 $(MAGIC_FRAGMENT_DIR)/wordprocessors \
 $(MAGIC_FRAGMENT_DIR)/xdelta \
 $(MAGIC_FRAGMENT_DIR)/xenix \
@@ -217,10 +223,12 @@ CLEANFILES = ${MAGIC}
 # the target's magic file
 if IS_CROSS_COMPILE
 FILE_COMPILE = file
+FILE_COMPILE_DEP =
 else
 FILE_COMPILE = $(top_builddir)/src/file
+FILE_COMPILE_DEP = $(FILE_COMPILE)
 endif
 
-${MAGIC}: $(EXTRA_DIST) $(FILE_COMPILE)
+${MAGIC}: $(EXTRA_DIST) $(FILE_COMPILE_DEP)
 	$(FILE_COMPILE) -C -m $(MAGIC_FRAGMENT_DIR)
 	@mv $(MAGIC_FRAGMENT_BASE).mgc $@

+ 10 - 1
magic/Makefile.in

@@ -160,6 +160,10 @@ sysconfdir = @sysconfdir@
 target_alias = @target_alias@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+
+#
+# $File: Makefile.am,v 1.41 2008/06/17 17:49:11 christos Exp $
+#
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_FRAGMENT_DIR = $(top_srcdir)/magic/$(MAGIC_FRAGMENT_BASE)
 pkgdata_DATA = magic.mgc
@@ -320,6 +324,7 @@ $(MAGIC_FRAGMENT_DIR)/revision \
 $(MAGIC_FRAGMENT_DIR)/riff \
 $(MAGIC_FRAGMENT_DIR)/rpm \
 $(MAGIC_FRAGMENT_DIR)/rtf \
+$(MAGIC_FRAGMENT_DIR)/ruby \
 $(MAGIC_FRAGMENT_DIR)/sc \
 $(MAGIC_FRAGMENT_DIR)/sccs \
 $(MAGIC_FRAGMENT_DIR)/scientific \
@@ -361,6 +366,8 @@ $(MAGIC_FRAGMENT_DIR)/vms \
 $(MAGIC_FRAGMENT_DIR)/vmware \
 $(MAGIC_FRAGMENT_DIR)/vorbis \
 $(MAGIC_FRAGMENT_DIR)/vxl \
+$(MAGIC_FRAGMENT_DIR)/weak \
+$(MAGIC_FRAGMENT_DIR)/windows \
 $(MAGIC_FRAGMENT_DIR)/wordprocessors \
 $(MAGIC_FRAGMENT_DIR)/xdelta \
 $(MAGIC_FRAGMENT_DIR)/xenix \
@@ -377,6 +384,8 @@ CLEANFILES = ${MAGIC}
 # FIXME: Build file natively as well so that it can be used to compile
 # the target's magic file
 @IS_CROSS_COMPILE_TRUE@FILE_COMPILE = file
+@IS_CROSS_COMPILE_FALSE@FILE_COMPILE_DEP = $(FILE_COMPILE)
+@IS_CROSS_COMPILE_TRUE@FILE_COMPILE_DEP = 
 all: all-am
 
 .SUFFIXES:
@@ -566,7 +575,7 @@ uninstall-am: uninstall-pkgdataDATA
 	uninstall uninstall-am uninstall-pkgdataDATA
 
 
-${MAGIC}: $(EXTRA_DIST) $(FILE_COMPILE)
+${MAGIC}: $(EXTRA_DIST) $(FILE_COMPILE_DEP)
 	$(FILE_COMPILE) -C -m $(MAGIC_FRAGMENT_DIR)
 	@mv $(MAGIC_FRAGMENT_BASE).mgc $@
 # Tell versions [3.59,3.63) of GNU make to not export all variables.

+ 5 - 1
src/Makefile.am

@@ -1,17 +1,21 @@
 MAGIC = $(pkgdatadir)/magic
 lib_LTLIBRARIES = libmagic.la
 include_HEADERS = magic.h
-EXTRA_DIST = getopt_long.c
 
 bin_PROGRAMS = file
 
 AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
+AM_CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
+    -Wmissing-declarations -Wredundant-decls -Wnested-externs \
+    -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
+    -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter
 
 libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
 	compress.c is_tar.c readelf.c print.c fsmagic.c \
 	funcs.c file.h names.h patchlevel.h readelf.h tar.h apptype.c \
 	file_opts.h elfclass.h
 libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
+libmagic_la_LIBADD = $(LTLIBOBJS)
 
 file_SOURCES = file.c
 file_LDADD = libmagic.la

+ 13 - 5
src/Makefile.in

@@ -37,7 +37,7 @@ host_triplet = @host@
 bin_PROGRAMS = file$(EXEEXT)
 subdir = src
 DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
-	$(srcdir)/Makefile.in
+	$(srcdir)/Makefile.in asprintf.c getopt_long.c vasprintf.c
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
 	$(top_srcdir)/configure.ac
@@ -56,7 +56,7 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
 	"$(DESTDIR)$(includedir)"
 libLTLIBRARIES_INSTALL = $(INSTALL)
 LTLIBRARIES = $(lib_LTLIBRARIES)
-libmagic_la_LIBADD =
+libmagic_la_DEPENDENCIES = $(LTLIBOBJS)
 am_libmagic_la_OBJECTS = magic.lo apprentice.lo softmagic.lo \
 	ascmagic.lo compress.lo is_tar.lo readelf.lo print.lo \
 	fsmagic.lo funcs.lo apptype.lo
@@ -197,14 +197,19 @@ top_srcdir = @top_srcdir@
 MAGIC = $(pkgdatadir)/magic
 lib_LTLIBRARIES = libmagic.la
 include_HEADERS = magic.h
-EXTRA_DIST = getopt_long.c
 AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
+AM_CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
+    -Wmissing-declarations -Wredundant-decls -Wnested-externs \
+    -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
+    -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter
+
 libmagic_la_SOURCES = magic.c apprentice.c softmagic.c ascmagic.c \
 	compress.c is_tar.c readelf.c print.c fsmagic.c \
 	funcs.c file.h names.h patchlevel.h readelf.h tar.h apptype.c \
 	file_opts.h elfclass.h
 
 libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
+libmagic_la_LIBADD = $(LTLIBOBJS)
 file_SOURCES = file.c
 file_LDADD = libmagic.la
 all: all-am
@@ -307,6 +312,9 @@ mostlyclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/asprintf.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt_long.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/vasprintf.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apprentice.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apptype.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ascmagic.Plo@am__quote@
@@ -477,7 +485,7 @@ clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
 	clean-libtool mostlyclean-am
 
 distclean: distclean-am
-	-rm -rf ./$(DEPDIR)
+	-rm -rf $(DEPDIR) ./$(DEPDIR)
 	-rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \
 	distclean-tags
@@ -511,7 +519,7 @@ install-ps: install-ps-am
 installcheck-am:
 
 maintainer-clean: maintainer-clean-am
-	-rm -rf ./$(DEPDIR)
+	-rm -rf $(DEPDIR) ./$(DEPDIR)
 	-rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic
 

+ 170 - 52
src/apprentice.c

@@ -49,7 +49,7 @@
 #include <dirent.h>
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.132 2008/03/28 18:19:30 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.137 2008/07/02 15:22:47 christos Exp $")
 #endif	/* lint */
 
 #define	EATAB {while (isascii((unsigned char) *l) && \
@@ -95,8 +95,6 @@ private const char *getstr(struct magic_set *, const char *, char *, int,
     int *, int);
 private int parse(struct magic_set *, struct magic_entry **, uint32_t *,
     const char *, size_t, int);
-private int parse_mime(struct magic_set *, struct magic_entry **, uint32_t *,
-    const char *);
 private void eatsize(const char **);
 private int apprentice_1(struct magic_set *, const char *, int, struct mlist *);
 private size_t apprentice_magic_strength(const struct magic *);
@@ -116,13 +114,27 @@ private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *,
 private int check_format_type(const char *, int);
 private int check_format(struct magic_set *, struct magic *);
 private int get_op(char);
+private int parse_mime(struct magic_set *, struct magic_entry *, const char *);
+private int parse_strength(struct magic_set *, struct magic_entry *,
+    const char *);
+
 
 private size_t maxmagic = 0;
 private size_t magicsize = sizeof(struct magic);
 
 private const char usg_hdr[] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
-private const char mime_marker[] = "!:mime";
-private const size_t mime_marker_len = sizeof(mime_marker) - 1;
+
+private struct {
+	const char *name;
+	size_t len;
+	int (*fun)(struct magic_set *, struct magic_entry *, const char *);
+} bang[] = {
+#define	DECLARE_FIELD(name) { # name, sizeof(# name) - 1, parse_ ## name }
+	DECLARE_FIELD(mime),
+	DECLARE_FIELD(strength),
+#undef	DECLARE_FIELD
+	{ NULL, 0, NULL }
+};
 
 #ifdef COMPILE_ONLY
 
@@ -387,6 +399,8 @@ apprentice_magic_strength(const struct magic *m)
 
 	switch (m->type) {
 	case FILE_DEFAULT:	/* make sure this sorts last */
+		if (m->factor_op != FILE_FACTOR_OP_NONE)
+			abort();
 		return 0;
 
 	case FILE_BYTE:
@@ -484,6 +498,24 @@ apprentice_magic_strength(const struct magic *m)
 	if (val == 0)	/* ensure we only return 0 for FILE_DEFAULT */
 		val = 1;
 
+	switch (m->factor_op) {
+	case FILE_FACTOR_OP_NONE:
+		break;
+	case FILE_FACTOR_OP_PLUS:
+		val += m->factor;
+		break;
+	case FILE_FACTOR_OP_MINUS:
+		val -= m->factor;
+		break;
+	case FILE_FACTOR_OP_TIMES:
+		val *= m->factor;
+		break;
+	case FILE_FACTOR_OP_DIV:
+		val /= m->factor;
+		break;
+	default:
+		abort();
+	}
 	return val;
 }
 
@@ -505,7 +537,7 @@ apprentice_sort(const void *a, const void *b)
 		return 1;
 }
 
-private int
+private void
 set_test_type(struct magic *mstart, struct magic *m)
 {
 	switch (m->type) {
@@ -550,7 +582,7 @@ set_test_type(struct magic *mstart, struct magic *m)
 	case FILE_REGEX:
 	case FILE_SEARCH:
 		/* binary test if pattern is not text */
-		if (file_looks_utf8(m->value.s, m->vallen, NULL, NULL) == 0)
+		if (file_looks_utf8(m->value.us, m->vallen, NULL, NULL) <= 0)
 			mstart->flag |= BINTEST;
 		break;
 	case FILE_DEFAULT:
@@ -594,15 +626,38 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
 				continue;
 			if (line[0] == '#')	/* comment, do not parse */
 				continue;
-			if (len > mime_marker_len &&
-			    memcmp(line, mime_marker, mime_marker_len) == 0) {
-				/* MIME type */
-				if (parse_mime(ms, marray, marraycount,
-					       line + mime_marker_len) != 0)
+			if (line[0] == '!' && line[1] == ':') {
+				size_t i;
+
+				for (i = 0; bang[i].name != NULL; i++) {
+					if (len - 2 > bang[i].len &&
+					    memcmp(bang[i].name, line + 2,
+					    bang[i].len) == 0)
+						break;
+				}
+				if (bang[i].name == NULL) {
+					file_error(ms, 0,
+					    "Unknown !: entry `%s'", line);
 					(*errs)++;
+					continue;
+				}
+				if (*marraycount == 0) {
+					file_error(ms, 0,
+					    "No current entry for :!%s type",
+						bang[i].name);
+					(*errs)++;
+					continue;
+				}
+				if ((*bang[i].fun)(ms, 
+				    &(*marray)[*marraycount - 1],
+				    line + bang[i].len + 2) != 0) {
+					(*errs)++;
+					continue;
+				}
 				continue;
 			}
-			if (parse(ms, marray, marraycount, line, lineno, action) != 0)
+			if (parse(ms, marray, marraycount, line, lineno,
+			    action) != 0)
 				(*errs)++;
 		}
 
@@ -643,10 +698,11 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	if (stat(fn, &st) == 0 && S_ISDIR(st.st_mode)) {
 		dir = opendir(fn);
 		if (dir) {
-			while (d = readdir(dir)) {
+			while ((d = readdir(dir)) != NULL) {
 				snprintf(subfn, sizeof(subfn), "%s/%s",
 				    fn, d->d_name);
-				if (stat(subfn, &st) == 0 && S_ISREG(st.st_mode)) {
+				if (stat(subfn, &st) == 0 &&
+				    S_ISREG(st.st_mode)) {
 					load_1(ms, action, subfn, &errs,
 					    &marray, &marraycount);
 				}
@@ -668,26 +724,27 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 
 		starttest = i;
 		do {
+			static const char text[] = "text";
+			static const char binary[] = "binary";
+			static const size_t len = sizeof(text);
 			set_test_type(marray[starttest].mp, marray[i].mp);
-			if (ms->flags & MAGIC_DEBUG) {
-				(void)fprintf(stderr, "%s%s%s: %s\n",
-					marray[i].mp->mimetype,
-					marray[i].mp->mimetype[0] == '\0' ? "" : "; ",
-					marray[i].mp->desc[0] ? marray[i].mp->desc : "(no description)",
-					marray[i].mp->flag & BINTEST ? "binary" : "text");
-				if (marray[i].mp->flag & BINTEST) {
-#define SYMBOL "text"
-#define SYMLEN sizeof(SYMBOL)
-					char *p = strstr(marray[i].mp->desc, "text");
-					if (p && (p == marray[i].mp->desc || isspace(p[-1])) &&
-					    (p + SYMLEN - marray[i].mp->desc == MAXstring ||
-					     (p[SYMLEN] == '\0' || isspace(p[SYMLEN])))) {
-						(void)fprintf(stderr,
-							      "*** Possible binary test for text type\n");
-					}
-#undef SYMBOL
-#undef SYMLEN
-				}
+			if ((ms->flags & MAGIC_DEBUG) == 0)
+				continue;
+			(void)fprintf(stderr, "%s%s%s: %s\n",
+			    marray[i].mp->mimetype,
+			    marray[i].mp->mimetype[0] == '\0' ? "" : "; ",
+			    marray[i].mp->desc[0] ? marray[i].mp->desc :
+			    "(no description)",
+			    marray[i].mp->flag & BINTEST ? binary : text);
+			if (marray[i].mp->flag & BINTEST) {
+				char *p = strstr(marray[i].mp->desc, text);
+				if (p && (p == marray[i].mp->desc ||
+				    isspace((unsigned char)p[-1])) &&
+				    (p + len - marray[i].mp->desc == 
+				    MAXstring || (p[len] == '\0' ||
+				    isspace((unsigned char)p[len]))))
+					(void)fprintf(stderr, "*** Possible "
+					    "binary test for text type\n");
 			}
 		} while (++i < marraycount && marray[i].mp->cont_level != 0);
 	}
@@ -1039,6 +1096,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 		} else
 			m = me->mp;
 		(void)memset(m, 0, sizeof(*m));
+		m->factor_op = FILE_FACTOR_OP_NONE;
 		m->cont_level = 0;
 		me->cont_count = 1;
 	}
@@ -1261,6 +1319,17 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 	switch (*l) {
 	case '>':
 	case '<':
+  		m->reln = *l;
+  		++l;
+		if (*l == '=') {
+			if (ms->flags & MAGIC_CHECK) {
+				file_magwarn(ms, "%c= not supported",
+				    m->reln);
+				return -1;
+			}
+		   ++l;
+		}
+		break;
 	/* Old-style anding: "0 byte &0x80 dynamically linked" */
 	case '&':
 	case '^':
@@ -1337,29 +1406,73 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 }
 
 /*
- * parse a MIME annotation line from magic file, put into magic[index - 1]
+ * parse a STRENGTH annotation line from magic file, put into magic[index - 1]
  * if valid
  */
 private int
-parse_mime(struct magic_set *ms, struct magic_entry **mentryp,
-    uint32_t *nmentryp, const char *line)
+parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line)
 {
-	size_t i;
 	const char *l = line;
-	struct magic *m;
-	struct magic_entry *me;
-
-	if (*nmentryp == 0) {
-		file_error(ms, 0, "No current entry for MIME type");
+	char *el;
+	unsigned long factor;
+	struct magic *m = &me->mp[0];
+
+	if (m->factor_op != FILE_FACTOR_OP_NONE) {
+		file_magwarn(ms,
+		    "Current entry already has a strength type: %c %d",
+		    m->factor_op, m->factor);
+		return -1;
+	}
+	EATAB;
+	switch (*l) {
+	case FILE_FACTOR_OP_NONE:
+	case FILE_FACTOR_OP_PLUS:
+	case FILE_FACTOR_OP_MINUS:
+	case FILE_FACTOR_OP_TIMES:
+	case FILE_FACTOR_OP_DIV:
+		m->factor_op = *l++;
+		break;
+	default:
+		file_magwarn(ms, "Unknown factor op `%c'", *l);
 		return -1;
 	}
+	EATAB;
+	factor = strtoul(l, &el, 0);
+	if (factor > 255) {
+		file_magwarn(ms, "Too large factor `%lu'", factor);
+		goto out;
+	}
+	if (*el && !isspace((unsigned char)*el)) {
+		file_magwarn(ms, "Bad factor `%s'", l);
+		goto out;
+	}
+	m->factor = (uint8_t)factor;
+	if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) {
+		file_magwarn(ms, "Cannot have factor op `%c' and factor %u",
+		    m->factor_op, m->factor);
+		goto out;
+	}
+	return 0;
+out:
+	m->factor_op = FILE_FACTOR_OP_NONE;
+	m->factor = 0;
+	return -1;
+}
 
-	me = &(*mentryp)[*nmentryp - 1];
-	m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1];
+/*
+ * parse a MIME annotation line from magic file, put into magic[index - 1]
+ * if valid
+ */
+private int
+parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line)
+{
+	size_t i;
+	const char *l = line;
+	struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1];
 
 	if (m->mimetype[0] != '\0') {
-		file_error(ms, 0, "Current entry already has a MIME type: %s\n"
-		    "Description: %s\nNew type: %s", m->mimetype, m->desc, l);
+		file_magwarn(ms, "Current entry already has a MIME type `%s',"
+		    " new type `%s'", m->mimetype, l);
 		return -1;
 	}	
 
@@ -1544,7 +1657,8 @@ check_format(struct magic_set *ms, struct magic *m)
 		 * string is not one character long
 		 */
 		file_magwarn(ms, "Printf format `%c' is not valid for type "
-		    "`%s' in description `%s'", *ptr,
+		    "`%s' in description `%s'",
+		    ptr && *ptr ? *ptr : '?',
 		    file_names[m->type], m->desc);
 		return -1;
 	}
@@ -1927,7 +2041,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	ptr = (uint32_t *)(void *)*magicp;
 	if (*ptr != MAGICNO) {
 		if (swap4(*ptr) != MAGICNO) {
-			file_error(ms, 0, "bad magic in `%s'");
+			file_error(ms, 0, "bad magic in `%s'", dbname);
 			goto error1;
 		}
 		needsbyteswap = 1;
@@ -2025,14 +2139,18 @@ private const char ext[] = ".mgc";
 private void
 mkdbname(const char *fn, char **buf, int strip)
 {
+	const char *p;
 	if (strip) {
-		const char *p;
 		if ((p = strrchr(fn, '/')) != NULL)
 			fn = ++p;
 	}
 
-	(void)asprintf(buf, "%s%s", fn, ext);
-	if (*buf && strlen(*buf) > MAXPATHLEN) {
+	if ((p = strstr(fn, ext)) != NULL && p[sizeof(ext) - 1] == '\0')
+		*buf = strdup(fn);
+	else
+		(void)asprintf(buf, "%s%s", fn, ext);
+
+	if (buf && *buf && strlen(*buf) > MAXPATHLEN) {
 		free(*buf);
 		*buf = NULL;
 	}

+ 1 - 2
src/ascmagic.c

@@ -49,7 +49,7 @@
 #include "names.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.62 2008/03/01 22:21:48 rrt Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.63 2008/05/09 14:20:28 christos Exp $")
 #endif	/* lint */
 
 #define MAXLINELEN 300	/* longest sane line length */
@@ -59,7 +59,6 @@ FILE_RCSID("@(#)$File: ascmagic.c,v 1.62 2008/03/01 22:21:48 rrt Exp $")
 private int looks_ascii(const unsigned char *, size_t, unichar *, size_t *);
 private int looks_utf8_with_BOM(const unsigned char *, size_t, unichar *,
     size_t *);
-protected int file_looks_utf8(const unsigned char *, size_t, unichar *, size_t *);
 private int looks_ucs16(const unsigned char *, size_t, unichar *, size_t *);
 private int looks_latin1(const unsigned char *, size_t, unichar *, size_t *);
 private int looks_extended(const unsigned char *, size_t, unichar *, size_t *);

+ 43 - 0
src/asprintf.c

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) Ian F. Darwin 1986-1995.
+ * Software written by Ian F. Darwin and others;
+ * maintained 1995-present by Christos Zoulas and others.
+ * 
+ * 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.
+ */
+
+#include <stdarg.h>
+
+int vasprintf(char **ptr, const char *format_string, va_list vargs);
+
+int asprintf(char **ptr, const char *fmt, ...)
+{
+  va_list vargs;
+  int retval;
+
+  va_start(vargs, fmt);
+  retval = vasprintf(ptr, fmt, vargs);
+  va_end(vargs);
+
+  return retval;
+}

+ 4 - 2
src/elfclass.h

@@ -49,7 +49,8 @@
 		    (off_t)elf_getu(swap, elfhdr.e_phoff),
 		    elf_getu16(swap, elfhdr.e_phnum), 
 		    (size_t)elf_getu16(swap, elfhdr.e_phentsize),
-		    fsize, &flags) == -1)
+		    fsize, &flags, elf_getu16(swap, elfhdr.e_shnum))
+		    == -1)
 			return -1;
 		/*FALLTHROUGH*/
 	case ET_REL:
@@ -57,7 +58,8 @@
 		    (off_t)elf_getu(swap, elfhdr.e_shoff),
 		    elf_getu16(swap, elfhdr.e_shnum),
 		    (size_t)elf_getu16(swap, elfhdr.e_shentsize),
-		    &flags) == -1)
+		    &flags,
+		    elf_getu16(swap, elfhdr.e_machine)) == -1)
 			return -1;
 		break;
 

+ 2 - 2
src/file.c

@@ -70,7 +70,7 @@ int getopt_long(int argc, char * const *argv, const char *optstring, const struc
 #include "patchlevel.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: file.c,v 1.119 2008/02/07 00:58:52 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.120 2008/05/18 23:21:17 christos Exp $")
 #endif	/* lint */
 
 
@@ -375,7 +375,7 @@ unwrap(char *fn)
 			exit(1);
 		}
 
-		while (fgets(buf, MAXPATHLEN, f) != NULL) {
+		while (fgets(buf, sizeof(buf), f) != NULL) {
 			buf[strcspn(buf, "\n")] = '\0';
 			cwid = file_mbswidth(buf);
 			if (cwid > wid)

+ 21 - 11
src/file.h

@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.103 2008/03/01 22:21:49 rrt Exp $
+ * @(#)$File: file.h,v 1.106 2008/07/02 15:22:47 christos Exp $
  */
 
 #ifndef __file_h__
@@ -97,7 +97,7 @@
 #define MAXstring 32		/* max leng of "string" types */
 
 #define MAGICNO		0xF11E041C
-#define VERSIONNO	5
+#define VERSIONNO	6
 #define FILE_MAGICSIZE	(32 * 6)
 
 #define	FILE_LOAD	0
@@ -117,7 +117,7 @@ struct magic {
                                    for top-level tests) */
 #define TEXTTEST	0	/* for passing to file_softmagic */
 
-	uint8_t dummy1;
+	uint8_t factor;
 
 	/* Word 2 */
 	uint8_t reln;		/* relation (0=eq, '>'=gt, etc) */
@@ -186,11 +186,15 @@ struct magic {
 	uint8_t mask_op;	/* operator for mask */
 #ifdef ENABLE_CONDITIONALS
 	uint8_t cond;		/* conditional type */
-	uint8_t dummy2;	
 #else
-	uint8_t dummy2;	
-	uint8_t dummy3;	
+	uint8_t dummy;
 #endif
+	uint8_t factor_op;	
+#define		FILE_FACTOR_OP_PLUS	'+'
+#define		FILE_FACTOR_OP_MINUS	'-'
+#define		FILE_FACTOR_OP_TIMES	'*'
+#define		FILE_FACTOR_OP_DIV	'/'
+#define		FILE_FACTOR_OP_NONE	'\0'
 
 #define				FILE_OPS	"&|^+-*/%"
 #define				FILE_OPAND	0
@@ -243,6 +247,7 @@ struct magic {
 		uint8_t hl[4];	/* 4 bytes of a fixed-endian "long" */
 		uint8_t hq[8];	/* 8 bytes of a fixed-endian "quad" */
 		char s[MAXstring];	/* the search string or regex pattern */
+		unsigned char us[MAXstring];
 		float f;
 		double d;
 	} value;		/* either number or string */
@@ -323,7 +328,9 @@ protected int file_buffer(struct magic_set *, int, const char *, const void *,
     size_t);
 protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
 protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
-protected int file_printf(struct magic_set *, const char *, ...);
+protected int file_vprintf(struct magic_set *, const char *, va_list);
+protected int file_printf(struct magic_set *, const char *, ...)
+    __attribute__((__format__(__printf__, 2, 3)));
 protected int file_reset(struct magic_set *);
 protected int file_tryelf(struct magic_set *, int, const unsigned char *,
     size_t);
@@ -339,9 +346,12 @@ 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);
-protected void file_error(struct magic_set *, int, const char *, ...);
-protected void file_magerror(struct magic_set *, const char *, ...);
-protected void file_magwarn(struct magic_set *, const char *, ...);
+protected void file_error(struct magic_set *, int, const char *, ...)
+    __attribute__((__format__(__printf__, 3, 4)));
+protected void file_magerror(struct magic_set *, const char *, ...)
+    __attribute__((__format__(__printf__, 2, 3)));
+protected void file_magwarn(struct magic_set *, const char *, ...)
+    __attribute__((__format__(__printf__, 2, 3)));
 protected void file_mdump(struct magic *);
 protected void file_showstr(FILE *, const char *, size_t);
 protected size_t file_mbswidth(const char *);
@@ -367,7 +377,7 @@ extern char *sys_errlist[];
 #endif
 
 #ifndef HAVE_VASPRINTF
-int vasprintf(char **ptr, const char *format_string, va_list vargs);
+int vasprintf(char **, const char *, va_list);
 #endif
 #ifndef HAVE_ASPRINTF
 int asprintf(char **ptr, const char *format_string, ...);

+ 2 - 2
src/fsmagic.c

@@ -57,13 +57,13 @@
 #undef HAVE_MAJOR
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.50 2008/02/12 17:22:54 rrt Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.51 2008/05/09 14:20:28 christos Exp $")
 #endif	/* lint */
 
 private int
 bad_link(struct magic_set *ms, int err, char *buf)
 {
-	char *errfmt;
+	const char *errfmt;
 	if (err == ELOOP)
 		errfmt = "symbolic link in a loop";
 	else

+ 15 - 7
src/funcs.c

@@ -38,25 +38,21 @@
 #endif
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.39 2008/03/01 22:21:49 rrt Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.41 2008/05/16 14:25:01 christos Exp $")
 #endif	/* lint */
 
 /*
  * Like printf, only we append to a buffer.
  */
 protected int
-file_printf(struct magic_set *ms, const char *fmt, ...)
+file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
 {
-	va_list ap;
-	size_t size;
 	int len;
 	char *buf, *newstr;
 
-	va_start(ap, fmt);
 	len = vasprintf(&buf, fmt, ap);
 	if (len < 0)
 		goto out;
-	va_end(ap);
 
 	if (ms->o.buf != NULL) {
 		len = asprintf(&newstr, "%s%s", ms->o.buf, buf);
@@ -73,6 +69,18 @@ out:
 	return -1;
 }
 
+protected int
+file_printf(struct magic_set *ms, const char *fmt, ...)
+{
+	int rv;
+	va_list ap;
+
+	va_start(ap, fmt);
+	rv = file_vprintf(ms, fmt, ap);
+	va_end(ap);
+	return rv;
+}
+
 /*
  * error - print best error message possible
  */
@@ -89,7 +97,7 @@ file_error_core(struct magic_set *ms, int error, const char *f, va_list va,
 		ms->o.buf = NULL;
 		file_printf(ms, "line %u: ", lineno);
 	}
-        file_printf(ms, f, va);
+        file_vprintf(ms, f, va);
 	if (error > 0)
 		file_printf(ms, " (%s)", strerror(error));
 	ms->haderr++;

+ 1 - 2
src/magic.c

@@ -63,7 +63,7 @@
 #include "patchlevel.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: magic.c,v 1.50 2008/02/19 00:58:59 rrt Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.51 2008/05/16 14:25:01 christos Exp $")
 #endif	/* lint */
 
 #ifndef PIPE_BUF 
@@ -302,7 +302,6 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
 			(void)strcat(strcpy(tmp, inname), ".exe");
 			if ((fd = open(tmp, flags)) < 0) {
 #endif
-				fprintf(stderr, "couldn't open file\n");
 				if (info_from_stat(ms, sb.st_mode) == -1)
 					goto done;
 				rv = 0;

+ 5 - 2
src/patchlevel.h

@@ -1,11 +1,14 @@
 #define	FILE_VERSION_MAJOR	4
-#define	patchlevel		24
+#define	patchlevel		25
 
 /*
  * Patchlevel file for Ian Darwin's MAGIC command.
- * $File: patchlevel.h,v 1.68 2008/03/22 21:39:43 christos Exp $
+ * $File: patchlevel.h,v 1.69 2008/07/02 15:27:05 christos Exp $
  *
  * $Log: patchlevel.h,v $
+ * Revision 1.69  2008/07/02 15:27:05  christos
+ * welcome to 4.25
+ *
  * Revision 1.68  2008/03/22 21:39:43  christos
  * file 4.24
  *

+ 177 - 5
src/readelf.c

@@ -38,7 +38,7 @@
 #include "magic.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.73 2008/03/27 22:00:28 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.75 2008/06/05 12:59:15 christos Exp $")
 #endif
 
 #ifdef	ELFCORE
@@ -46,8 +46,9 @@ private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
     off_t, int *);
 #endif
 private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
-    off_t, int *);
-private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, int *);
+    off_t, int *, int);
+private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, int *,
+    int);
 private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int,
     int, size_t, int *);
 
@@ -190,6 +191,18 @@ getu64(int swap, uint64_t value)
 #define prpsoffsets(i)	(class == ELFCLASS32			\
 			 ? prpsoffsets32[i]			\
 			 : prpsoffsets64[i])
+#define xcap_addr	(class == ELFCLASS32			\
+			 ? (void *) &cap32			\
+			 : (void *) &cap64)
+#define xcap_sizeof	(class == ELFCLASS32			\
+			 ? sizeof cap32				\
+			 : sizeof cap64)
+#define xcap_tag	(class == ELFCLASS32			\
+			 ? elf_getu32(swap, cap32.c_tag)	\
+			 : elf_getu64(swap, cap64.c_tag))
+#define xcap_val	(class == ELFCLASS32			\
+			 ? elf_getu32(swap, cap32.c_un.c_val)	\
+			 : elf_getu64(swap, cap64.c_un.c_val))
 
 #ifdef ELFCORE
 /*
@@ -750,15 +763,67 @@ core:
 	return offset;
 }
 
+/* SunOS 5.x hardware capability descriptions */
+typedef struct cap_desc {
+	uint64_t cd_mask;
+	const char *cd_name;
+} cap_desc_t;
+
+static const cap_desc_t cap_desc_sparc[] = {
+	{ AV_SPARC_MUL32,		"MUL32" },
+	{ AV_SPARC_DIV32,		"DIV32" },
+	{ AV_SPARC_FSMULD,		"FSMULD" },
+	{ AV_SPARC_V8PLUS,		"V8PLUS" },
+	{ AV_SPARC_POPC,		"POPC" },
+	{ AV_SPARC_VIS,			"VIS" },
+	{ AV_SPARC_VIS2,		"VIS2" },
+	{ AV_SPARC_ASI_BLK_INIT,	"ASI_BLK_INIT" },
+	{ AV_SPARC_FMAF,		"FMAF" },
+	{ AV_SPARC_FJFMAU,		"FJFMAU" },
+	{ AV_SPARC_IMA,			"IMA" },
+	{ 0, NULL }
+};
+
+static const cap_desc_t cap_desc_386[] = {
+	{ AV_386_FPU,			"FPU" },
+	{ AV_386_TSC,			"TSC" },
+	{ AV_386_CX8,			"CX8" },
+	{ AV_386_SEP,			"SEP" },
+	{ AV_386_AMD_SYSC,		"AMD_SYSC" },
+	{ AV_386_CMOV,			"CMOV" },
+	{ AV_386_MMX,			"MMX" },
+	{ AV_386_AMD_MMX,		"AMD_MMX" },
+	{ AV_386_AMD_3DNow,		"AMD_3DNow" },
+	{ AV_386_AMD_3DNowx,		"AMD_3DNowx" },
+	{ AV_386_FXSR,			"FXSR" },
+	{ AV_386_SSE,			"SSE" },
+	{ AV_386_SSE2,			"SSE2" },
+	{ AV_386_PAUSE,			"PAUSE" },
+	{ AV_386_SSE3,			"SSE3" },
+	{ AV_386_MON,			"MON" },
+	{ AV_386_CX16,			"CX16" },
+	{ AV_386_AHF,			"AHF" },
+	{ AV_386_TSCP,			"TSCP" },
+	{ AV_386_AMD_SSE4A,		"AMD_SSE4A" },
+	{ AV_386_POPCNT,		"POPCNT" },
+	{ AV_386_AMD_LZCNT,		"AMD_LZCNT" },
+	{ AV_386_SSSE3,			"SSSE3" },
+	{ AV_386_SSE4_1,		"SSE4.1" },
+	{ AV_386_SSE4_2,		"SSE4.2" },
+	{ 0, NULL }
+};
+
 private int
 doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
-    size_t size, int *flags)
+    size_t size, int *flags, int mach)
 {
 	Elf32_Shdr sh32;
 	Elf64_Shdr sh64;
 	int stripped = 1;
 	void *nbuf;
 	off_t noff;
+	uint64_t cap_hw1 = 0;	/* SunOS 5.x hardware capabilites */
+	uint64_t cap_sf1 = 0;	/* SunOS 5.x software capabilites */
 
 	if (size != xsh_sizeof) {
 		if (file_printf(ms, ", corrupted section header size") == -1)
@@ -824,10 +889,115 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
 			}
 			free(nbuf);
 			break;
+		case SHT_SUNW_cap:
+		    {
+			off_t coff;
+			if ((off = lseek(fd, (off_t)0, SEEK_CUR)) ==
+			    (off_t)-1) {
+				file_badread(ms);
+				return -1;
+			}
+			if (lseek(fd, (off_t)xsh_offset, SEEK_SET) ==
+			    (off_t)-1) {
+				file_badread(ms);
+				return -1;
+			}
+			coff = 0;
+			for (;;) {
+				Elf32_Cap cap32;
+				Elf64_Cap cap64;
+				char cbuf[MAX(sizeof cap32, sizeof cap64)];
+				if ((coff += xcap_sizeof) >= (size_t)xsh_size)
+					break;
+				if (read(fd, cbuf, (size_t)xcap_sizeof) !=
+				    (ssize_t)xcap_sizeof) {
+					file_badread(ms);
+					return -1;
+				}
+				(void)memcpy(xcap_addr, cbuf, xcap_sizeof);
+				switch (xcap_tag) {
+				case CA_SUNW_NULL:
+					break;
+				case CA_SUNW_HW_1:
+					cap_hw1 |= xcap_val;
+					break;
+				case CA_SUNW_SF_1:
+					cap_sf1 |= xcap_val;
+					break;
+				default:
+					if (file_printf(ms,
+					    ", with unknown capability "
+					    "0x%llx = 0x%llx",
+					    xcap_tag, xcap_val) == -1)
+						return -1;
+					break;
+				}
+			}
+			if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+				file_badread(ms);
+				return -1;
+			}
+			break;
+		    }
 		}
 	}
 	if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
 		return -1;
+	if (cap_hw1) {
+		const cap_desc_t *cdp;
+		switch (mach) {
+		case EM_SPARC:
+		case EM_SPARC32PLUS:
+		case EM_SPARCV9:
+			cdp = cap_desc_sparc;
+			break;
+		case EM_386:
+		case EM_IA_64:
+		case EM_AMD64:
+			cdp = cap_desc_386;
+			break;
+		default:
+			cdp = NULL;
+			break;
+		}
+		if (file_printf(ms, ", uses") == -1)
+			return -1;
+		if (cdp) {
+			while (cdp->cd_name) {
+				if (cap_hw1 & cdp->cd_mask) {
+					if (file_printf(ms,
+					    " %s", cdp->cd_name) == -1)
+						return -1;
+					cap_hw1 &= ~cdp->cd_mask;
+				}
+				++cdp;
+			}
+			if (cap_hw1)
+				if (file_printf(ms,
+				    " unknown hardware capability 0x%llx",
+				    cap_hw1) == -1)
+					return -1;
+		} else {
+			if (file_printf(ms,
+			    " hardware capability 0x%llx", cap_hw1) == -1)
+				return -1;
+		}
+	}
+	if (cap_sf1) {
+		if (cap_sf1 & SF1_SUNW_FPUSED) {
+			if (file_printf(ms,
+			    (cap_sf1 & SF1_SUNW_FPKNWN)
+			    ? ", uses frame pointer"
+			    : ", not known to use frame pointer") == -1)
+				return -1;
+		}
+		cap_sf1 &= ~SF1_SUNW_MASK;
+		if (cap_sf1)
+			if (file_printf(ms,
+			    ", with unknown software capability 0x%llx",
+			    cap_sf1) == -1)
+				return -1;
+	}
 	return 0;
 }
 
@@ -838,7 +1008,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
  */
 private int
 dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
-    int num, size_t size, off_t fsize, int *flags)
+    int num, size_t size, off_t fsize, int *flags, int sh_num)
 {
 	Elf32_Phdr ph32;
 	Elf64_Phdr ph64;
@@ -907,6 +1077,8 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
 					return -1;
 				align = 4;
 			}
+			if (sh_num)
+				break;
 			/*
 			 * This is a PT_NOTE section; loop through all the notes
 			 * in the section.

+ 76 - 0
src/readelf.h

@@ -101,10 +101,19 @@ typedef struct {
 #define ET_DYN		3
 #define ET_CORE		4
 
+/* e_machine (used only for SunOS 5.x hardware capabilities) */
+#define	EM_SPARC	2
+#define	EM_386		3
+#define	EM_SPARC32PLUS	18
+#define	EM_SPARCV9	43
+#define	EM_IA_64	50
+#define	EM_AMD64	62
+
 /* sh_type */
 #define SHT_SYMTAB	2
 #define SHT_NOTE	7
 #define SHT_DYNSYM	11
+#define SHT_SUNW_cap	0x6ffffff5	/* SunOS 5.x hw/sw capabilites */
 
 /* elf type */
 #define ELFDATANONE	0		/* e_ident[EI_DATA] */
@@ -233,4 +242,71 @@ typedef struct {
 #define GNU_OS_KFREEBSD	3
 #define GNU_OS_KNETBSD	4
 
+/* SunOS 5.x hardware/software capabilities */
+typedef struct {
+	Elf32_Word	c_tag;
+	union {
+		Elf32_Word	c_val;
+		Elf32_Addr	c_ptr;
+	} c_un;
+} Elf32_Cap;
+
+typedef struct {
+	Elf64_Xword	c_tag;
+	union {
+		Elf64_Xword	c_val;
+		Elf64_Addr	c_ptr;
+	} c_un;
+} Elf64_Cap;
+
+/* SunOS 5.x hardware/software capability tags */
+#define	CA_SUNW_NULL	0
+#define	CA_SUNW_HW_1	1
+#define	CA_SUNW_SF_1	2
+
+/* SunOS 5.x software capabilities */
+#define	SF1_SUNW_FPKNWN	0x01
+#define	SF1_SUNW_FPUSED	0x02
+#define	SF1_SUNW_MASK	0x03
+
+/* SunOS 5.x hardware capabilities: sparc */
+#define	AV_SPARC_MUL32		0x0001
+#define	AV_SPARC_DIV32		0x0002
+#define	AV_SPARC_FSMULD		0x0004
+#define	AV_SPARC_V8PLUS		0x0008
+#define	AV_SPARC_POPC		0x0010
+#define	AV_SPARC_VIS		0x0020
+#define	AV_SPARC_VIS2		0x0040
+#define	AV_SPARC_ASI_BLK_INIT	0x0080
+#define	AV_SPARC_FMAF		0x0100
+#define	AV_SPARC_FJFMAU		0x4000
+#define	AV_SPARC_IMA		0x8000
+
+/* SunOS 5.x hardware capabilities: 386 */
+#define	AV_386_FPU		0x00000001
+#define	AV_386_TSC		0x00000002
+#define	AV_386_CX8		0x00000004
+#define	AV_386_SEP		0x00000008
+#define	AV_386_AMD_SYSC		0x00000010
+#define	AV_386_CMOV		0x00000020
+#define	AV_386_MMX		0x00000040
+#define	AV_386_AMD_MMX		0x00000080
+#define	AV_386_AMD_3DNow	0x00000100
+#define	AV_386_AMD_3DNowx	0x00000200
+#define	AV_386_FXSR		0x00000400
+#define	AV_386_SSE		0x00000800
+#define	AV_386_SSE2		0x00001000
+#define	AV_386_PAUSE		0x00002000
+#define	AV_386_SSE3		0x00004000
+#define	AV_386_MON		0x00008000
+#define	AV_386_CX16		0x00010000
+#define	AV_386_AHF		0x00020000
+#define	AV_386_TSCP		0x00040000
+#define	AV_386_AMD_SSE4A	0x00080000
+#define	AV_386_POPCNT		0x00100000
+#define	AV_386_AMD_LZCNT	0x00200000
+#define	AV_386_SSSE3		0x00400000
+#define	AV_386_SSE4_1		0x00800000
+#define	AV_386_SSE4_2		0x01000000
+
 #endif

+ 638 - 0
src/vasprintf.c

@@ -0,0 +1,638 @@
+/*
+ * Copyright (c) Ian F. Darwin 1986-1995.
+ * Software written by Ian F. Darwin and others;
+ * maintained 1995-present by Christos Zoulas and others.
+ * 
+ * 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.
+ */
+/*###########################################################################
+  #                                                                           #
+  #                                vasprintf                                  #
+  #                                                                           #
+  #               Copyright (c) 2002-2005 David TAILLANDIER                   #
+  #                                                                           #
+  ###########################################################################*/
+
+/*
+
+This software is distributed under the "modified BSD licence".
+
+This software is also released with GNU license (GPL) in another file (same
+source-code, only license differ).
+
+
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer. 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. The name of the author may not be used to
+endorse or promote products derived from this software without specific
+prior written permission. 
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+====================
+
+Hacked from xnprintf version of 26th February 2005 to provide only
+vasprintf by Reuben Thomas <rrt@sc3d.org>.
+
+====================
+
+
+'printf' function family use the following format string:
+
+%[flag][width][.prec][modifier]type
+
+%% is the escape sequence to print a '%'
+%  followed by an unknown format will print the characters without
+trying to do any interpretation
+
+flag:   none   +     -     #     (blank)
+width:  n    0n    *
+prec:   none   .0    .n     .*
+modifier:    F N L h l ll    ('F' and 'N' are ms-dos/16-bit specific)
+type:  d i o u x X f e g E G c s p n
+
+
+The function needs to allocate memory to store the full text before to
+actually writting it.  i.e if you want to fnprintf() 1000 characters, the
+functions will allocate 1000 bytes.
+This behaviour can be modified: you have to customise the code to flush the
+internal buffer (writing to screen or file) when it reach a given size. Then
+the buffer can have a shorter length. But what? If you really need to write
+HUGE string, don't use printf!
+During the process, some other memory is allocated (1024 bytes minimum)
+to handle the output of partial sprintf() calls. If you have only 10000 bytes
+free in memory, you *may* not be able to nprintf() a 8000 bytes-long text.
+
+note: if a buffer overflow occurs, exit() is called. This situation should
+never appear ... but if you want to be *really* sure, you have to modify the
+code to handle those situations (only one place to modify).
+A buffer overflow can only occur if your sprintf() do strange things or when
+you use strange formats.
+
+*/
+
+#include "config.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <limits.h>
+
+#define ALLOC_CHUNK 2048
+#define ALLOC_SECURITY_MARGIN 1024   /* big value because some platforms have very big 'G' exponent */
+#if ALLOC_CHUNK < ALLOC_SECURITY_MARGIN
+#    error  !!! ALLOC_CHUNK < ALLOC_SECURITY_MARGIN !!!
+#endif
+/* note: to have some interest, ALLOC_CHUNK should be much greater than ALLOC_SECURITY_MARGIN */
+
+/*
+ *  To save a lot of push/pop, every variable are stored into this
+ *  structure, which is passed among nearly every sub-functions.
+ */
+typedef struct {
+  const char * src_string;        /* current position into intput string */
+  char *       buffer_base;       /* output buffer */
+  char *       dest_string;       /* current position into output string */
+  size_t       buffer_len;        /* length of output buffer */
+  size_t       real_len;          /* real current length of output text */
+  size_t       pseudo_len;        /* total length of output text if it were not limited in size */
+  size_t       maxlen;
+  va_list      vargs;             /* pointer to current position into vargs */
+  char *       sprintf_string;
+  FILE *       fprintf_file;
+} xprintf_struct;
+
+/*
+ *  Realloc buffer if needed
+ *  Return value:  0 = ok
+ *               EOF = not enought memory
+ */
+static int realloc_buff(xprintf_struct *s, size_t len)
+{
+  char * ptr;
+
+  if (len + ALLOC_SECURITY_MARGIN + s->real_len > s->buffer_len) {
+    len += s->real_len + ALLOC_CHUNK;
+    ptr = (char *)realloc((void *)(s->buffer_base), len);
+    if (ptr == NULL) {
+      s->buffer_base = NULL;
+      return EOF;
+    }
+
+    s->dest_string = ptr + (size_t)(s->dest_string - s->buffer_base);
+    s->buffer_base = ptr;
+    s->buffer_len = len;
+
+    (s->buffer_base)[s->buffer_len - 1] = 1; /* overflow marker */
+  }
+
+  return 0;
+}
+
+/*
+ *  Prints 'usual' characters    up to next '%'
+ *                            or up to end of text
+ */
+static int usual_char(xprintf_struct * s)
+{
+  size_t len;
+
+  len = strcspn(s->src_string, "%");     /* reachs the next '%' or end of input string */
+  /* note: 'len' is never 0 because the presence of '%' */
+  /* or end-of-line is checked in the calling function  */
+
+  if (realloc_buff(s,len) == EOF)
+    return EOF;
+
+  memcpy(s->dest_string, s->src_string, len);
+  s->src_string += len;
+  s->dest_string += len;
+  s->real_len += len;
+  s->pseudo_len += len;
+
+  return 0;
+}
+
+/*
+ *  Return value: 0 = ok
+ *                EOF = error
+ */
+static int print_it(xprintf_struct *s, size_t approx_len,
+                    const char *format_string, ...)
+{
+  va_list varg;
+  int vsprintf_len;
+  size_t len;
+
+  if (realloc_buff(s,approx_len) == EOF)
+    return EOF;
+
+  va_start(varg, format_string);
+  vsprintf_len = vsprintf(s->dest_string, format_string, varg);
+  va_end(varg);
+
+  /* Check for overflow */
+  assert((s->buffer_base)[s->buffer_len - 1] == 1);
+
+  if (vsprintf_len == EOF) /* must be done *after* overflow-check */
+    return EOF;
+
+  s->pseudo_len += vsprintf_len;
+  len = strlen(s->dest_string);
+  s->real_len += len;
+  s->dest_string += len;
+
+  return 0;
+}
+
+/*
+ *  Prints a string (%s)
+ *  We need special handling because:
+ *     a: the length of the string is unknown
+ *     b: when .prec is used, we must not access any extra byte of the
+ *        string (of course, if the original sprintf() does... what the
+ *        hell, not my problem)
+ *
+ *  Return value: 0 = ok
+ *                EOF = error
+ */
+static int type_s(xprintf_struct *s, int width, int prec,
+                  const char *format_string, const char *arg_string)
+{
+  size_t string_len;
+
+  if (arg_string == NULL)
+    return print_it(s, (size_t)6, "(null)", 0);
+
+  /* hand-made strlen() whitch stops when 'prec' is reached. */
+  /* if 'prec' is -1 then it is never reached. */
+  string_len = 0;
+  while (arg_string[string_len] != 0 && (size_t)prec != string_len)
+    string_len++;
+
+  if (width != -1 && string_len < (size_t)width)
+    string_len = (size_t)width;
+
+  return print_it(s, string_len, format_string, arg_string);
+}
+
+/*
+ *  Read a serie of digits. Stop when non-digit is found.
+ *  Return value: the value read (between 0 and 32767).
+ *  Note: no checks are made against overflow. If the string contain a big
+ *  number, then the return value won't be what we want (but, in this case,
+ *  the programmer don't know whatr he wants, then no problem).
+ */
+static int getint(const char **string)
+{
+  int i = 0;
+
+  while (isdigit((unsigned char)**string) != 0) {
+    i = i * 10 + (**string - '0');
+    (*string)++;
+  }
+
+  if (i < 0 || i > 32767)
+    i = 32767; /* if we have i==-10 this is not because the number is */
+  /* negative; this is because the number is big */
+  return i;
+}
+
+/*
+ *  Read a part of the format string. A part is 'usual characters' (ie "blabla")
+ *  or '%%' escape sequence (to print a single '%') or any combination of
+ *  format specifier (ie "%i" or "%10.2d").
+ *  After the current part is managed, the function returns to caller with
+ *  everything ready to manage the following part.
+ *  The caller must ensure than the string is not empty, i.e. the first byte
+ *  is not zero.
+ *
+ *  Return value:  0 = ok
+ *                 EOF = error
+ */
+static int dispatch(xprintf_struct *s)
+{
+  const char *initial_ptr;
+  char format_string[24]; /* max length may be something like  "% +-#032768.32768Ld" */
+  char *format_ptr;
+  int flag_plus, flag_minus, flag_space, flag_sharp, flag_zero;
+  int width, prec, modifier, approx_width;
+  char type;
+  /* most of those variables are here to rewrite the format string */
+
+#define SRCTXT  (s->src_string)
+#define DESTTXT (s->dest_string)
+
+  /* incoherent format string. Characters after the '%' will be printed with the next call */
+#define INCOHERENT()         do {SRCTXT=initial_ptr; return 0;} while (0)     /* do/while to avoid */
+#define INCOHERENT_TEST()    do {if(*SRCTXT==0)   INCOHERENT();} while (0)    /* a null statement  */
+
+  /* 'normal' text */
+  if (*SRCTXT != '%')
+    return usual_char(s);
+
+  /* we then have a '%' */
+  SRCTXT++;
+  /* don't check for end-of-string ; this is done later */
+
+  /* '%%' escape sequence */
+  if (*SRCTXT == '%') {
+    if (realloc_buff(s, (size_t)1) == EOF) /* because we can have "%%%%%%%%..." */
+      return EOF;
+    *DESTTXT = '%';
+    DESTTXT++;
+    SRCTXT++;
+    (s->real_len)++;
+    (s->pseudo_len)++;
+    return 0;
+  }
+
+  /* '%' managing */
+  initial_ptr = SRCTXT;   /* save current pointer in case of incorrect */
+  /* 'decoding'. Points just after the '%' so the '%' */
+  /* won't be printed in any case, as required. */
+
+  /* flag */
+  flag_plus = flag_minus = flag_space = flag_sharp = flag_zero = 0;
+
+  for (;; SRCTXT++) {
+    if (*SRCTXT == ' ')
+      flag_space = 1;
+    else if (*SRCTXT == '+')
+      flag_plus = 1;
+    else if (*SRCTXT == '-')
+      flag_minus = 1;
+    else if (*SRCTXT == '#')
+      flag_sharp = 1;
+    else if (*SRCTXT == '0')
+      flag_zero = 1;
+    else
+      break;
+  }
+
+  INCOHERENT_TEST();    /* here is the first test for end of string */
+
+  /* width */
+  if (*SRCTXT == '*') {         /* width given by next argument */
+    SRCTXT++;
+    width = va_arg(s->vargs, int);
+    if ((size_t)width > 0x3fffU) /* 'size_t' to check against negative values too */
+      width = 0x3fff;
+  } else if (isdigit((unsigned char)*SRCTXT)) /* width given as ASCII number */
+    width = getint(&SRCTXT);
+  else
+    width = -1;                 /* no width specified */
+
+  INCOHERENT_TEST();
+
+  /* .prec */
+  if (*SRCTXT == '.') {
+    SRCTXT++;
+    if (*SRCTXT == '*') {       /* .prec given by next argument */
+      SRCTXT++;
+      prec = va_arg(s->vargs, int);
+      if ((size_t)prec >= 0x3fffU) /* 'size_t' to check against negative values too */
+        prec = 0x3fff;
+    } else {                    /* .prec given as ASCII number */
+      if (isdigit((unsigned char)*SRCTXT) == 0)
+        INCOHERENT();
+      prec = getint(&SRCTXT);
+    }
+    INCOHERENT_TEST();
+  } else
+    prec = -1;                  /* no .prec specified */
+
+  /* modifier */
+  if (*SRCTXT == 'L' || *SRCTXT == 'h' || *SRCTXT == 'l') {
+    modifier = *SRCTXT;
+    SRCTXT++;
+    if (modifier=='l' && *SRCTXT=='l') {
+      SRCTXT++;
+      modifier = 'L';  /* 'll' == 'L'      long long == long double */
+    } /* only for compatibility ; not portable */
+    INCOHERENT_TEST();
+  } else
+    modifier = -1;              /* no modifier specified */
+
+  /* type */
+  type = *SRCTXT;
+  if (strchr("diouxXfegEGcspn",type) == NULL)
+    INCOHERENT();               /* unknown type */
+  SRCTXT++;
+
+  /* rewrite format-string */
+  format_string[0] = '%';
+  format_ptr = &(format_string[1]);
+
+  if (flag_plus) {
+    *format_ptr = '+';
+    format_ptr++;
+  }
+  if (flag_minus) {
+    *format_ptr = '-';
+    format_ptr++;
+  }
+  if (flag_space) {
+    *format_ptr = ' ';
+    format_ptr++;
+  }
+  if (flag_sharp) {
+    *format_ptr = '#';
+    format_ptr++;
+  }
+  if (flag_zero) {
+    *format_ptr = '0';
+    format_ptr++;
+  } /* '0' *must* be the last one */
+
+  if (width != -1) {
+    sprintf(format_ptr, "%i", width);
+    format_ptr += strlen(format_ptr);
+  }
+
+  if (prec != -1) {
+    *format_ptr = '.';
+    format_ptr++;
+    sprintf(format_ptr, "%i", prec);
+    format_ptr += strlen(format_ptr);
+  }
+
+  if (modifier != -1) {
+    if (modifier == 'L' && strchr("diouxX",type) != NULL) {
+      *format_ptr = 'l';
+      format_ptr++;
+      *format_ptr = 'l';
+      format_ptr++;
+    } else {
+      *format_ptr = modifier;
+      format_ptr++;
+    }
+  }
+
+  *format_ptr = type;
+  format_ptr++;
+  *format_ptr = 0;
+
+  /* vague approximation of minimal length if width or prec are specified */
+  approx_width = width + prec;
+  if (approx_width < 0) /* because width == -1 and/or prec == -1 */
+    approx_width = 0;
+
+  switch (type) {
+    /* int */
+  case 'd':
+  case 'i':
+  case 'o':
+  case 'u':
+  case 'x':
+  case 'X':
+    switch (modifier) {
+    case -1 :
+      return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, int));
+    case 'L':
+      return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, long long int));
+    case 'l':
+      return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, long int));
+    case 'h':
+      return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, int));
+      /* 'int' instead of 'short int' because default promotion is 'int' */
+    default:
+      INCOHERENT();
+    }
+
+    /* char */
+  case 'c':
+    if (modifier != -1)
+      INCOHERENT();
+    return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, int));
+    /* 'int' instead of 'char' because default promotion is 'int' */
+
+    /* math */
+  case 'e':
+  case 'f':
+  case 'g':
+  case 'E':
+  case 'G':
+    switch (modifier) {
+    case -1 : /* because of default promotion, no modifier means 'l' */
+    case 'l':
+      return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, double));
+    case 'L':
+      return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, long double));
+    default:
+      INCOHERENT();
+    }
+
+    /* string */
+  case 's':
+    return type_s(s, width, prec, format_string, va_arg(s->vargs, const char*));
+
+    /* pointer */
+  case 'p':
+    if (modifier == -1)
+      return print_it(s, (size_t)approx_width, format_string, va_arg(s->vargs, void *));
+    INCOHERENT();
+
+    /* store */
+  case 'n':
+    if (modifier == -1) {
+      int * p;
+      p = va_arg(s->vargs, int *);
+      if (p != NULL) {
+        *p = s->pseudo_len;
+        return 0;
+      }
+      return EOF;
+    }
+    INCOHERENT();
+
+  } /* switch */
+
+  INCOHERENT();                 /* unknown type */
+
+#undef INCOHERENT
+#undef INCOHERENT_TEST
+#undef SRCTXT
+#undef DESTTXT
+}
+
+/*
+ *  Return value: number of *virtually* written characters
+ *                EOF = error
+ */
+static int core(xprintf_struct *s)
+{
+  size_t len, save_len;
+  char *dummy_base;
+
+  /* basic checks */
+  if ((int)(s->maxlen) <= 0) /* 'int' to check against some conversion */
+    return EOF;           /* error for example if value is (int)-10 */
+  s->maxlen--;      /* because initial maxlen counts final 0 */
+  /* note: now 'maxlen' _can_ be zero */
+
+  if (s->src_string == NULL)
+    s->src_string = "(null)";
+
+  /* struct init and memory allocation */
+  s->buffer_base = NULL;
+  s->buffer_len = 0;
+  s->real_len = 0;
+  s->pseudo_len = 0;
+  if (realloc_buff(s, (size_t)0) == EOF)
+    return EOF;
+  s->dest_string = s->buffer_base;
+
+  /* process source string */
+  for (;;) {
+    /* up to end of source string */
+    if (*(s->src_string) == 0) {
+      *(s->dest_string) = 0;    /* final 0 */
+      len = s->real_len + 1;
+      break;
+    }
+
+    if (dispatch(s) == EOF)
+      goto free_EOF;
+
+    /* up to end of dest string */
+    if (s->real_len >= s->maxlen) {
+      (s->buffer_base)[s->maxlen] = 0; /* final 0 */
+      len = s->maxlen + 1;
+      break;
+    }
+  }
+
+  /* for (v)asnprintf */
+  dummy_base = s->buffer_base;
+  save_len = 0;                 /* just to avoid a compiler warning */
+
+  dummy_base = s->buffer_base + s->real_len;
+  save_len = s->real_len;
+
+  /* process the remaining of source string to compute 'pseudo_len'. We
+   * overwrite again and again, starting at 'dummy_base' because we don't
+   * need the text, only char count. */
+  while(*(s->src_string) != 0) { /* up to end of source string */
+    s->real_len = 0;
+    s->dest_string = dummy_base;
+    if (dispatch(s) == EOF)
+      goto free_EOF;
+  }
+
+  s->buffer_base = (char *)realloc((void *)(s->buffer_base), save_len + 1);
+  if (s->buffer_base == NULL)
+    return EOF; /* should rarely happen because we shrink the buffer */
+  return s->pseudo_len;
+
+ free_EOF:
+  if (s->buffer_base != NULL)
+    free(s->buffer_base);
+  return EOF;
+}
+
+int vasprintf(char **ptr, const char *format_string, va_list vargs)
+{
+  xprintf_struct s;
+  int retval;
+
+  s.src_string = format_string;
+#ifdef va_copy
+  va_copy (s.vargs, vargs);
+#else
+#ifdef __va_copy
+  __va_copy (s.vargs, vargs);
+#else
+  memcpy (&s.vargs, vargs, sizeof (va_list));
+#endif /* __va_copy */
+#endif /* va_copy */
+  s.maxlen = (size_t)INT_MAX;
+
+  retval = core(&s);
+  va_end(s.vargs);
+  if (retval == EOF) {
+    *ptr = NULL;
+    return EOF;
+  }
+
+  *ptr = s.buffer_base;
+  return retval;
+}

+ 1 - 0
tests/Makefile.am

@@ -1,5 +1,6 @@
 check_PROGRAMS = test
 test_LDADD = $(top_builddir)/src/libmagic.la
+test_CPPFLAGS = -I$(top_builddir)/src
 
 EXTRA_DIST = \
 	gedcom.magic gedcom.testfile gedcom.result

+ 17 - 2
tests/Makefile.in

@@ -43,7 +43,7 @@ mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 test_SOURCES = test.c
-test_OBJECTS = test.$(OBJEXT)
+test_OBJECTS = test-test.$(OBJEXT)
 test_DEPENDENCIES = $(top_builddir)/src/libmagic.la
 DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
 depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -169,6 +169,7 @@ target_alias = @target_alias@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 test_LDADD = $(top_builddir)/src/libmagic.la
+test_CPPFLAGS = -I$(top_builddir)/src
 EXTRA_DIST = \
 	gedcom.magic gedcom.testfile gedcom.result
 
@@ -223,7 +224,7 @@ mostlyclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-test.Po@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -246,6 +247,20 @@ distclean-compile:
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
 
+test-test.o: test.c
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test-test.o -MD -MP -MF $(DEPDIR)/test-test.Tpo -c -o test-test.o `test -f 'test.c' || echo '$(srcdir)/'`test.c
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/test-test.Tpo $(DEPDIR)/test-test.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='test.c' object='test-test.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test-test.o `test -f 'test.c' || echo '$(srcdir)/'`test.c
+
+test-test.obj: test.c
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test-test.obj -MD -MP -MF $(DEPDIR)/test-test.Tpo -c -o test-test.obj `if test -f 'test.c'; then $(CYGPATH_W) 'test.c'; else $(CYGPATH_W) '$(srcdir)/test.c'; fi`
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/test-test.Tpo $(DEPDIR)/test-test.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='test.c' object='test-test.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test-test.obj `if test -f 'test.c'; then $(CYGPATH_W) 'test.c'; else $(CYGPATH_W) '$(srcdir)/test.c'; fi`
+
 mostlyclean-libtool:
 	-rm -f *.lo