Browse Source

Import upstream version 5.13

Christos Zoulas 12 years ago
parent
commit
42450514c2
74 changed files with 2460 additions and 1433 deletions
  1. 34 0
      ChangeLog
  2. 11 8
      README
  3. 6 0
      config.h.in
  4. 248 24
      configure
  5. 3 2
      configure.ac
  6. 15 10
      doc/file.man
  7. 20 3
      doc/libmagic.man
  8. 97 14
      doc/magic.man
  9. 251 480
      install-sh
  10. 2 2
      magic/Magdir/animation
  11. 46 0
      magic/Magdir/aout
  12. 82 78
      magic/Magdir/archive
  13. 8 8
      magic/Magdir/assembler
  14. 2 2
      magic/Magdir/audio
  15. 3 13
      magic/Magdir/bsdi
  16. 12 12
      magic/Magdir/cafebabe
  17. 2 2
      magic/Magdir/commands
  18. 3 3
      magic/Magdir/console
  19. 2 10
      magic/Magdir/database
  20. 15 15
      magic/Magdir/digital
  21. 198 41
      magic/Magdir/filesystems
  22. 2 2
      magic/Magdir/fonts
  23. 35 2
      magic/Magdir/gnome-keyring
  24. 241 0
      magic/Magdir/gpt
  25. 4 1
      magic/Magdir/hitachi-sh
  26. 2 1
      magic/Magdir/ibm6000
  27. 51 0
      magic/Magdir/icc
  28. 2 2
      magic/Magdir/images
  29. 2 2
      magic/Magdir/intel
  30. 11 1
      magic/Magdir/java
  31. 2 2
      magic/Magdir/jpeg
  32. 5 4
      magic/Magdir/linux
  33. 11 3
      magic/Magdir/llvm
  34. 2 1
      magic/Magdir/lua
  35. 182 107
      magic/Magdir/mach
  36. 3 3
      magic/Magdir/mail.news
  37. 2 2
      magic/Magdir/maple
  38. 2 2
      magic/Magdir/matroska
  39. 3 65
      magic/Magdir/mips
  40. 1 11
      magic/Magdir/misctools
  41. 2 2
      magic/Magdir/msdos
  42. 6 4
      magic/Magdir/msooxml
  43. 2 2
      magic/Magdir/natinst
  44. 4 6
      magic/Magdir/netbsd
  45. 2 2
      magic/Magdir/revision
  46. 3 3
      magic/Magdir/riff
  47. 10 17
      magic/Magdir/rpm
  48. 69 2
      magic/Magdir/sgi
  49. 60 104
      magic/Magdir/sniffer
  50. 9 2
      magic/Magdir/sql
  51. 37 30
      magic/Magdir/sun
  52. 23 24
      magic/Magdir/unknown
  53. 5 13
      magic/Magdir/vax
  54. 2 2
      magic/Magdir/wordprocessors
  55. 2 2
      magic/Magdir/wsdl
  56. 4 1
      magic/Magdir/xilinx
  57. 2 2
      magic/Magdir/xwindows
  58. 5 2
      magic/Makefile.am
  59. 5 2
      magic/Makefile.in
  60. 7 0
      src/Makefile.am
  61. 19 5
      src/Makefile.in
  62. 282 136
      src/apprentice.c
  63. 2 3
      src/cdf.c
  64. 2 1
      src/elfclass.h
  65. 6 1
      src/file.c
  66. 14 13
      src/file.h
  67. 40 32
      src/fsmagic.c
  68. 1 1
      src/getline.c
  69. 7 1
      src/magic.c
  70. 3 0
      src/magic.h
  71. 107 0
      src/magic.h.in
  72. 14 0
      src/pread.c
  73. 52 60
      src/readelf.c
  74. 29 20
      src/softmagic.c

+ 34 - 0
ChangeLog

@@ -1,3 +1,37 @@
+2013-02-18  10:39  Christos Zoulas <christos@zoulas.com>
+
+	* add elf reading of debug info to determine if file is stripped
+	  (Jan Kaluza)
+	* use pread()
+
+2013-01-25  18:05  Christos Zoulas <christos@zoulas.com>
+
+	* change mime description size from 64 to 80 to accommodate OOXML.
+
+2013-01-11  14:50  Christos Zoulas <christos@zoulas.com>
+
+	* Warn about inconsistent continuation levels.
+	* Change fsmagic to add a space after it prints.
+
+2013-01-10  21:00  Christos Zoulas <christos@zoulas.com>
+
+	* Make getline public so that file can link against it.
+	  Perhaps it is better to rename it, or hide it differently.
+	  Fixes builds on platforms that do not provide it.
+	  
+2013-01-07  16:30  Christos Zoulas <christos@zoulas.com>
+
+	* Add SuS d{,1,2,4,8}, u{,1,2,4,8} and document
+	  what long, int, short, etc is (Guy Harris)
+
+2013-01-06  11:20  Christos Zoulas <christos@zoulas.com>
+
+	* add magic_version function and constant
+	* Redo memory allocation and de-allocation.
+	  (prevents double frees on non mmap platforms)
+	* Fix bug with name/use having to do with passing
+	  found state from the parent to the child and back.
+
 2012-12-19   8:47  Christos Zoulas <christos@zoulas.com>
 2012-12-19   8:47  Christos Zoulas <christos@zoulas.com>
 
 
 	* Only print elf capabilities for archs we know (Jan Kaluza)
 	* Only print elf capabilities for archs we know (Jan Kaluza)

+ 11 - 8
README

@@ -1,5 +1,5 @@
 ** README for file(1) Command **
 ** README for file(1) Command **
-@(#) $File: README,v 1.44 2011/03/24 13:03:39 rrt Exp $
+@(#) $File: README,v 1.45 2013/01/11 16:51:01 christos Exp $
 
 
 Mailing List: file@mx.gw.com
 Mailing List: file@mx.gw.com
 Bug tracker: http://bugs.gw.com/
 Bug tracker: http://bugs.gw.com/
@@ -68,15 +68,19 @@ src/apprentice.c - parses /etc/magic to learn magic
 src/apptype.c - used for OS/2 specific application type magic
 src/apptype.c - used for OS/2 specific application type magic
 src/asprintf.c - replacement for OS's that don't have it.
 src/asprintf.c - replacement for OS's that don't have it.
 src/ascmagic.c - third & last set of tests, based on hardwired assumptions.
 src/ascmagic.c - third & last set of tests, based on hardwired assumptions.
+src/asctime_r.c - for systems that don't have it.
+src/asprintf.c - for systems that don't have it.
 src/cdf.c - parser for Microsoft Compound Document Files
 src/cdf.c - parser for Microsoft Compound Document Files
 src/cdf_time.c - time converter for CDF.
 src/cdf_time.c - time converter for CDF.
 src/compress.c - handles decompressing files to look inside.
 src/compress.c - handles decompressing files to look inside.
+src/ctime_r.c - for systems that don't have it.
 src/encoding.c - handles unicode encodings
 src/encoding.c - handles unicode encodings
 src/file.c - the main program
 src/file.c - the main program
 src/file.h - header file
 src/file.h - header file
 src/fsmagic.c - first set of tests the program runs, based on filesystem info
 src/fsmagic.c - first set of tests the program runs, based on filesystem info
 src/funcs.c - utilility functions
 src/funcs.c - utilility functions
-src/getopt_long.c - used for OS/2 specific application type magic
+src/getopt_long.c - for systems that don't have it.
+src/getline.c - for systems that don't have it.
 src/is_tar.c, tar.h - knows about tarchives (courtesy John Gilmore).
 src/is_tar.c, tar.h - knows about tarchives (courtesy John Gilmore).
 src/names.h - header file for ascmagic.c
 src/names.h - header file for ascmagic.c
 src/magic.c - the libmagic api
 src/magic.c - the libmagic api
@@ -84,14 +88,13 @@ src/print.c - print results, errors, warnings.
 src/readcdf.c - CDF wrapper.
 src/readcdf.c - CDF wrapper.
 src/readelf.[ch] - Stand-alone elf parsing code.
 src/readelf.[ch] - Stand-alone elf parsing code.
 src/softmagic.c - 2nd set of tests, based on /etc/magic
 src/softmagic.c - 2nd set of tests, based on /etc/magic
-src/strlcat.c - used for OS/2 specific application type magic
-src/strlcpy.c - used for OS/2 specific application type magic
-src/vasprintf.c - used for OS/2 specific application type magic
-doc/file.1 - man page for the command
-doc/magic.4 - man page for the magic file, courtesy Guy Harris.
+src/strlcat.c - for systems that don't have it.
+src/strlcpy.c - for systems that don't have it.
+src/vasprintf.c - for systems that don't have it.
+doc/file.man - man page for the command
+doc/magic.man - man page for the magic file, courtesy Guy Harris.
 	Install as magic.4 on USG and magic.5 on V7 or Berkeley; cf Makefile.
 	Install as magic.4 on USG and magic.5 on V7 or Berkeley; cf Makefile.
 Magdir - directory of /etc/magic pieces
 Magdir - directory of /etc/magic pieces
-
 ------------------------------------------------------------------------------
 ------------------------------------------------------------------------------
 
 
 If you submit a new magic entry please make sure you read the following
 If you submit a new magic entry please make sure you read the following

+ 6 - 0
config.h.in

@@ -89,6 +89,9 @@
 /* Define to 1 if you have a working `mmap' system call. */
 /* Define to 1 if you have a working `mmap' system call. */
 #undef HAVE_MMAP
 #undef HAVE_MMAP
 
 
+/* Define to 1 if you have the `pread' function. */
+#undef HAVE_PREAD
+
 /* Define to 1 if you have the <stddef.h> header file. */
 /* Define to 1 if you have the <stddef.h> header file. */
 #undef HAVE_STDDEF_H
 #undef HAVE_STDDEF_H
 
 
@@ -243,6 +246,9 @@
 /* Define to the version of this package. */
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 #undef PACKAGE_VERSION
 
 
+/* The size of `long long', as computed by sizeof. */
+#undef SIZEOF_LONG_LONG
+
 /* Define to 1 if you have the ANSI C header files. */
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 #undef STDC_HEADERS
 
 

+ 248 - 24
configure

@@ -1,6 +1,6 @@
 #! /bin/sh
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for file 5.12.
+# Generated by GNU Autoconf 2.68 for file 5.13.
 #
 #
 # Report bugs to <christos@astron.com>.
 # Report bugs to <christos@astron.com>.
 #
 #
@@ -709,8 +709,8 @@ MAKEFLAGS=
 # Identity of this package.
 # Identity of this package.
 PACKAGE_NAME='file'
 PACKAGE_NAME='file'
 PACKAGE_TARNAME='file'
 PACKAGE_TARNAME='file'
-PACKAGE_VERSION='5.12'
-PACKAGE_STRING='file 5.12'
+PACKAGE_VERSION='5.13'
+PACKAGE_STRING='file 5.13'
 PACKAGE_BUGREPORT='christos@astron.com'
 PACKAGE_BUGREPORT='christos@astron.com'
 PACKAGE_URL=''
 PACKAGE_URL=''
 
 
@@ -1442,7 +1442,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # 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.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
   cat <<_ACEOF
-\`configure' configures file 5.12 to adapt to many kinds of systems.
+\`configure' configures file 5.13 to adapt to many kinds of systems.
 
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
 
@@ -1512,7 +1512,7 @@ fi
 
 
 if test -n "$ac_init_help"; then
 if test -n "$ac_init_help"; then
   case $ac_init_help in
   case $ac_init_help in
-     short | recursive ) echo "Configuration of file 5.12:";;
+     short | recursive ) echo "Configuration of file 5.13:";;
    esac
    esac
   cat <<\_ACEOF
   cat <<\_ACEOF
 
 
@@ -1618,7 +1618,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
 if $ac_init_version; then
   cat <<\_ACEOF
   cat <<\_ACEOF
-file configure 5.12
+file configure 5.13
 generated by GNU Autoconf 2.68
 generated by GNU Autoconf 2.68
 
 
 Copyright (C) 2010 Free Software Foundation, Inc.
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -2267,11 +2267,189 @@ $as_echo "$ac_res" >&6; }
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 
 } # ac_fn_c_find_intX_t
 } # ac_fn_c_find_intX_t
+
+# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
+# --------------------------------------------
+# Tries to find the compile-time value of EXPR in a program that includes
+# INCLUDES, setting VAR accordingly. Returns whether the value could be
+# computed
+ac_fn_c_compute_int ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if test "$cross_compiling" = yes; then
+    # Depending upon the size, compute the lo and hi bounds.
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=0 ac_mid=0
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid; break
+else
+  as_fn_arith $ac_mid + 1 && ac_lo=$as_val
+			if test $ac_lo -le $ac_mid; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) < 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=-1 ac_mid=-1
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=$ac_mid; break
+else
+  as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val
+			if test $ac_mid -le $ac_hi; then
+			  ac_lo= ac_hi=
+			  break
+			fi
+			as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  ac_lo= ac_hi=
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+  as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid
+else
+  as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in #((
+?*) eval "$3=\$ac_lo"; ac_retval=0 ;;
+'') ac_retval=1 ;;
+esac
+  else
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+static long int longval () { return $2; }
+static unsigned long int ulongval () { return $2; }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+  FILE *f = fopen ("conftest.val", "w");
+  if (! f)
+    return 1;
+  if (($2) < 0)
+    {
+      long int i = longval ();
+      if (i != ($2))
+	return 1;
+      fprintf (f, "%ld", i);
+    }
+  else
+    {
+      unsigned long int i = ulongval ();
+      if (i != ($2))
+	return 1;
+      fprintf (f, "%lu", i);
+    }
+  /* Do not output a trailing newline, as this causes \r\n confusion
+     on some platforms.  */
+  return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  echo >>conftest.val; read $3 <conftest.val; ac_retval=0
+else
+  ac_retval=1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+rm -f conftest.val
+
+  fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_compute_int
 cat >config.log <<_ACEOF
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 running configure, to aid debugging if configure makes a mistake.
 
 
-It was created by file $as_me 5.12, which was
+It was created by file $as_me 5.13, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
 
   $ $0 $@
   $ $0 $@
@@ -3089,7 +3267,7 @@ fi
 
 
 # Define the identity of the package.
 # Define the identity of the package.
  PACKAGE='file'
  PACKAGE='file'
- VERSION='5.12'
+ VERSION='5.13'
 
 
 
 
 cat >>confdefs.h <<_ACEOF
 cat >>confdefs.h <<_ACEOF
@@ -5896,13 +6074,13 @@ if ${lt_cv_nm_interface+:} false; then :
 else
 else
   lt_cv_nm_interface="BSD nm"
   lt_cv_nm_interface="BSD nm"
   echo "int some_variable = 0;" > conftest.$ac_ext
   echo "int some_variable = 0;" > conftest.$ac_ext
-  (eval echo "\"\$as_me:5899: $ac_compile\"" >&5)
+  (eval echo "\"\$as_me:6077: $ac_compile\"" >&5)
   (eval "$ac_compile" 2>conftest.err)
   (eval "$ac_compile" 2>conftest.err)
   cat conftest.err >&5
   cat conftest.err >&5
-  (eval echo "\"\$as_me:5902: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+  (eval echo "\"\$as_me:6080: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
   (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
   (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
   cat conftest.err >&5
   cat conftest.err >&5
-  (eval echo "\"\$as_me:5905: output\"" >&5)
+  (eval echo "\"\$as_me:6083: output\"" >&5)
   cat conftest.out >&5
   cat conftest.out >&5
   if $GREP 'External.*some_variable' conftest.out > /dev/null; then
   if $GREP 'External.*some_variable' conftest.out > /dev/null; then
     lt_cv_nm_interface="MS dumpbin"
     lt_cv_nm_interface="MS dumpbin"
@@ -7096,7 +7274,7 @@ ia64-*-hpux*)
   ;;
   ;;
 *-*-irix6*)
 *-*-irix6*)
   # Find out which ABI we are using.
   # Find out which ABI we are using.
-  echo '#line 7099 "configure"' > conftest.$ac_ext
+  echo '#line 7277 "configure"' > conftest.$ac_ext
   if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
   if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
   (eval $ac_compile) 2>&5
   (eval $ac_compile) 2>&5
   ac_status=$?
   ac_status=$?
@@ -8356,11 +8534,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8359: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:8537: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    ac_status=$?
    cat conftest.err >&5
    cat conftest.err >&5
-   echo "$as_me:8363: \$? = $ac_status" >&5
+   echo "$as_me:8541: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
      # So say no if there are warnings other than the usual output.
@@ -8695,11 +8873,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8698: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:8876: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    ac_status=$?
    cat conftest.err >&5
    cat conftest.err >&5
-   echo "$as_me:8702: \$? = $ac_status" >&5
+   echo "$as_me:8880: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
      # So say no if there are warnings other than the usual output.
@@ -8800,11 +8978,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8803: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:8981: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    ac_status=$?
    cat out/conftest.err >&5
    cat out/conftest.err >&5
-   echo "$as_me:8807: \$? = $ac_status" >&5
+   echo "$as_me:8985: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
    then
      # The compiler can only warn and ignore the option if not recognized
      # The compiler can only warn and ignore the option if not recognized
@@ -8855,11 +9033,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8858: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:9036: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    ac_status=$?
    cat out/conftest.err >&5
    cat out/conftest.err >&5
-   echo "$as_me:8862: \$? = $ac_status" >&5
+   echo "$as_me:9040: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
    then
      # The compiler can only warn and ignore the option if not recognized
      # The compiler can only warn and ignore the option if not recognized
@@ -11222,7 +11400,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11225 "configure"
+#line 11403 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 
 
 #if HAVE_DLFCN_H
 #if HAVE_DLFCN_H
@@ -11318,7 +11496,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11321 "configure"
+#line 11499 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 
 
 #if HAVE_DLFCN_H
 #if HAVE_DLFCN_H
@@ -12705,6 +12883,39 @@ _ACEOF
 ;;
 ;;
 esac
 esac
 
 
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of long long" >&5
+$as_echo_n "checking size of long long... " >&6; }
+if ${ac_cv_sizeof_long_long+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (long long))" "ac_cv_sizeof_long_long"        "$ac_includes_default"; then :
+
+else
+  if test "$ac_cv_type_long_long" = yes; then
+     { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "cannot compute sizeof (long long)
+See \`config.log' for more details" "$LINENO" 5; }
+   else
+     ac_cv_sizeof_long_long=0
+   fi
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_long_long" >&5
+$as_echo "$ac_cv_sizeof_long_long" >&6; }
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long
+_ACEOF
+
+
 
 
 
 
 
 
@@ -13307,6 +13518,19 @@ esac
 
 
 fi
 fi
 
 
+ac_fn_c_check_func "$LINENO" "pread" "ac_cv_func_pread"
+if test "x$ac_cv_func_pread" = xyes; then :
+  $as_echo "#define HAVE_PREAD 1" >>confdefs.h
+
+else
+  case " $LIBOBJS " in
+  *" pread.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS pread.$ac_objext"
+ ;;
+esac
+
+fi
+
 
 
 
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gzopen in -lz" >&5
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gzopen in -lz" >&5
@@ -13962,7 +14186,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 # values after options handling.
 ac_log="
 ac_log="
-This file was extended by file $as_me 5.12, which was
+This file was extended by file $as_me 5.13, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_FILES    = $CONFIG_FILES
@@ -14028,7 +14252,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 ac_cs_version="\\
-file config.status 5.12
+file config.status 5.13
 configured by $0, generated by GNU Autoconf 2.68,
 configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
   with options \\"\$ac_cs_config\\"
 
 

+ 3 - 2
configure.ac

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

+ 15 - 10
doc/file.man

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

+ 20 - 3
doc/libmagic.man

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

+ 97 - 14
doc/magic.man

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

+ 251 - 480
install-sh

@@ -1,38 +1,23 @@
 #!/bin/sh
 #!/bin/sh
-# install - install a program, script, or datafile
-
-scriptversion=2009-04-28.21; # UTC
-
-# This originates from X11R5 (mit/util/scripts/install.sh), which was
-# later released in X11R6 (xc/config/util/install.sh) with the
-# following copyright and license.
-#
-# Copyright (C) 1994 X Consortium
 #
 #
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to
-# deal in the Software without restriction, including without limitation the
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-# sell copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
+# $NetBSD: install-sh.in,v 1.5 2010/10/08 19:57:05 tez Exp $
+# This script now also installs multiple files, but might choke on installing
+# multiple files with spaces in the file names.
 #
 #
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
-# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-# Except as contained in this notice, the name of the X Consortium shall not
-# be used in advertising or otherwise to promote the sale, use or other deal-
-# ings in this Software without prior written authorization from the X Consor-
-# tium.
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
 #
 #
+# Copyright 1991 by the Massachusetts Institute of Technology
 #
 #
-# FSF changes to this file are in the public domain.
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission.  M.I.T. makes no representations about the
+# suitability of this software for any purpose.  It is provided "as is"
+# without express or implied warranty.
 #
 #
 # Calling this script install-sh is preferred over install.sh, to prevent
 # Calling this script install-sh is preferred over install.sh, to prevent
 # `make' implicit rules from creating a file called install from it
 # `make' implicit rules from creating a file called install from it
@@ -41,480 +26,266 @@ scriptversion=2009-04-28.21; # UTC
 # This script is compatible with the BSD install script, but was written
 # This script is compatible with the BSD install script, but was written
 # from scratch.
 # from scratch.
 
 
-nl='
-'
-IFS=" ""	$nl"
-
 # set DOITPROG to echo to test this script
 # set DOITPROG to echo to test this script
 
 
 # Don't use :- since 4.3BSD and earlier shells don't like it.
 # Don't use :- since 4.3BSD and earlier shells don't like it.
-doit=${DOITPROG-}
-if test -z "$doit"; then
-  doit_exec=exec
-else
-  doit_exec=$doit
-fi
-
-# Put in absolute file names if you don't have them in your path;
-# or use environment vars.
-
-chgrpprog=${CHGRPPROG-chgrp}
-chmodprog=${CHMODPROG-chmod}
-chownprog=${CHOWNPROG-chown}
-cmpprog=${CMPPROG-cmp}
-cpprog=${CPPROG-cp}
-mkdirprog=${MKDIRPROG-mkdir}
-mvprog=${MVPROG-mv}
-rmprog=${RMPROG-rm}
-stripprog=${STRIPPROG-strip}
-
-posix_glob='?'
-initialize_posix_glob='
-  test "$posix_glob" != "?" || {
-    if (set -f) 2>/dev/null; then
-      posix_glob=
-    else
-      posix_glob=:
-    fi
-  }
-'
-
-posix_mkdir=
-
-# Desired mode of installed file.
-mode=0755
-
-chgrpcmd=
-chmodcmd=$chmodprog
-chowncmd=
-mvcmd=$mvprog
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+awkprog="${AWKPROG-awk}"
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+instcmd="$cpprog"
+pathcompchmodcmd="$chmodprog 755"
+chmodcmd="$chmodprog 755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+stripflags=""
 rmcmd="$rmprog -f"
 rmcmd="$rmprog -f"
-stripcmd=
-
-src=
-dst=
-dir_arg=
-dst_arg=
-
-copy_on_change=false
-no_target_directory=
-
-usage="\
-Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
-   or: $0 [OPTION]... SRCFILES... DIRECTORY
-   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
-   or: $0 [OPTION]... -d DIRECTORIES...
-
-In the 1st form, copy SRCFILE to DSTFILE.
-In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
-In the 4th, create DIRECTORIES.
-
-Options:
-     --help     display this help and exit.
-     --version  display version info and exit.
-
-  -c            (ignored)
-  -C            install only if different (preserve the last data modification time)
-  -d            create directories instead of installing files.
-  -g GROUP      $chgrpprog installed files to GROUP.
-  -m MODE       $chmodprog installed files to MODE.
-  -o USER       $chownprog installed files to USER.
-  -s            $stripprog installed files.
-  -t DIRECTORY  install into DIRECTORY.
-  -T            report an error if DSTFILE is a directory.
+mvcmd="$mvprog"
+src=""
+msrc=""
+dst=""
+dir_arg=""
+suffix=""
+suffixfmt=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+	-b) suffix=".old"
+	    shift
+	    continue;;
+
+	-B) suffixfmt="$2"
+	    shift
+	    shift
+	    continue;;
+
+	-c) instcmd="$cpprog"
+	    shift
+	    continue;;
+
+	-d) dir_arg=true
+	    shift
+	    continue;;
+
+	-m) chmodcmd="$chmodprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-o) chowncmd="$chownprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-g) chgrpcmd="$chgrpprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-s) stripcmd="$stripprog"
+	    shift
+	    continue;;
+
+	-S) stripcmd="$stripprog"
+	    stripflags="-S $2 $stripflags"
+	    shift
+	    shift
+	    continue;;
+
+	*)  if [ x"$msrc" = x ]
+	    then
+		msrc="$dst"
+	    else
+		msrc="$msrc $dst"
+	    fi
+	    src="$dst"
+	    dst="$1"
+	    shift
+	    continue;;
+    esac
+done
 
 
-Environment variables override the default commands:
-  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
-  RMPROG STRIPPROG
-"
+if [ x"$dir_arg" = x ]
+then
+	dstisfile=""
+	if [ ! -d "$dst" ]
+	then
+		if [ x"$msrc" = x"$src" ]
+		then
+			dstisfile=true
+		else
+			echo "install: destination is not a directory"
+			exit 1
+		fi
+	fi
+else
+	msrc="$msrc $dst"
+fi
 
 
-while test $# -ne 0; do
-  case $1 in
-    -c) ;;
+if [ x"$msrc" = x ]
+then
+	echo "install: no destination specified"
+	exit 1
+fi      
 
 
-    -C) copy_on_change=true;;
+for srcarg in $msrc; do
 
 
-    -d) dir_arg=true;;
+if [ x"$dir_arg" != x ]; then
 
 
-    -g) chgrpcmd="$chgrpprog $2"
-	shift;;
+	dstarg="$srcarg"
+else
+	dstarg="$dst"
+
+# Waiting for this to be detected by the "$instcmd $srcarg $dsttmp" command
+# might cause directories to be created, which would be especially bad 
+# if $src (and thus $dsttmp) contains '*'.
+
+	if [ -f "$srcarg" ]
+	then
+		doinst="$instcmd"
+	elif [ -d "$srcarg" ]
+	then
+		echo "install: $srcarg: not a regular file"
+		exit 1
+	elif [ "$srcarg" = "/dev/null" ]
+	then
+		doinst="$cpprog"
+	else
+		echo "install:  $srcarg does not exist"
+		exit 1
+	fi
+	
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
 
 
-    --help) echo "$usage"; exit $?;;
+	if [ -d "$dstarg" ]
+	then
+		dstarg="$dstarg"/`basename "$srcarg"`
+	fi
+fi
 
 
-    -m) mode=$2
-	case $mode in
-	  *' '* | *'	'* | *'
-'*	  | *'*'* | *'?'* | *'['*)
-	    echo "$0: invalid mode: $mode" >&2
-	    exit 1;;
-	esac
-	shift;;
+## this sed command emulates the dirname command
+dstdir=`echo "$dstarg" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
 
 
-    -o) chowncmd="$chownprog $2"
-	shift;;
+# Make sure that the destination directory exists.
+#  this part is taken from Noah Friedman's mkinstalldirs script
 
 
-    -s) stripcmd=$stripprog;;
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='	
+'
+IFS="${IFS-${defaultIFS}}"
 
 
-    -t) dst_arg=$2
-	shift;;
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
 
 
-    -T) no_target_directory=true;;
+pathcomp=''
 
 
-    --version) echo "$0 $scriptversion"; exit $?;;
+while [ $# -ne 0 ] ; do
+	pathcomp="${pathcomp}${1}"
+	shift
 
 
-    --)	shift
-	break;;
+	if [ ! -d "${pathcomp}" ] ;
+        then
+		$doit $mkdirprog "${pathcomp}"
+        	if [ x"$chowncmd" != x ]; then $doit $chowncmd "${pathcomp}"; else true ; fi &&
+        	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "${pathcomp}"; else true ; fi &&
+        	if [ x"$pathcompchmodcmd" != x ]; then $doit $pathcompchmodcmd "${pathcomp}"; else true ; fi
 
 
-    -*)	echo "$0: invalid option: $1" >&2
-	exit 1;;
+	else
+		true
+	fi
 
 
-    *)  break;;
-  esac
-  shift
+	pathcomp="${pathcomp}/"
 done
 done
-
-if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
-  # When -d is used, all remaining arguments are directories to create.
-  # When -t is used, the destination is already specified.
-  # Otherwise, the last argument is the destination.  Remove it from $@.
-  for arg
-  do
-    if test -n "$dst_arg"; then
-      # $@ is not empty: it contains at least $arg.
-      set fnord "$@" "$dst_arg"
-      shift # fnord
-    fi
-    shift # arg
-    dst_arg=$arg
-  done
-fi
-
-if test $# -eq 0; then
-  if test -z "$dir_arg"; then
-    echo "$0: no input file specified." >&2
-    exit 1
-  fi
-  # It's OK to call `install-sh -d' without argument.
-  # This can happen when creating conditional directories.
-  exit 0
 fi
 fi
 
 
-if test -z "$dir_arg"; then
-  trap '(exit $?); exit' 1 2 13 15
-
-  # Set umask so as not to create temps with too-generous modes.
-  # However, 'strip' requires both read and write access to temps.
-  case $mode in
-    # Optimize common cases.
-    *644) cp_umask=133;;
-    *755) cp_umask=22;;
-
-    *[0-7])
-      if test -z "$stripcmd"; then
-	u_plus_rw=
-      else
-	u_plus_rw='% 200'
-      fi
-      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
-    *)
-      if test -z "$stripcmd"; then
-	u_plus_rw=
-      else
-	u_plus_rw=,u+rw
-      fi
-      cp_umask=$mode$u_plus_rw;;
-  esac
-fi
-
-for src
-do
-  # Protect names starting with `-'.
-  case $src in
-    -*) src=./$src;;
-  esac
-
-  if test -n "$dir_arg"; then
-    dst=$src
-    dstdir=$dst
-    test -d "$dstdir"
-    dstdir_status=$?
-  else
-
-    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
-    # might cause directories to be created, which would be especially bad
-    # if $src (and thus $dsttmp) contains '*'.
-    if test ! -f "$src" && test ! -d "$src"; then
-      echo "$0: $src does not exist." >&2
-      exit 1
-    fi
-
-    if test -z "$dst_arg"; then
-      echo "$0: no destination specified." >&2
-      exit 1
-    fi
-
-    dst=$dst_arg
-    # Protect names starting with `-'.
-    case $dst in
-      -*) dst=./$dst;;
-    esac
-
-    # If destination is a directory, append the input filename; won't work
-    # if double slashes aren't ignored.
-    if test -d "$dst"; then
-      if test -n "$no_target_directory"; then
-	echo "$0: $dst_arg: Is a directory" >&2
-	exit 1
-      fi
-      dstdir=$dst
-      dst=$dstdir/`basename "$src"`
-      dstdir_status=0
-    else
-      # Prefer dirname, but fall back on a substitute if dirname fails.
-      dstdir=`
-	(dirname "$dst") 2>/dev/null ||
-	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	     X"$dst" : 'X\(//\)[^/]' \| \
-	     X"$dst" : 'X\(//\)$' \| \
-	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
-	echo X"$dst" |
-	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-		   s//\1/
-		   q
-		 }
-		 /^X\(\/\/\)[^/].*/{
-		   s//\1/
-		   q
-		 }
-		 /^X\(\/\/\)$/{
-		   s//\1/
-		   q
-		 }
-		 /^X\(\/\).*/{
-		   s//\1/
-		   q
-		 }
-		 s/.*/./; q'
-      `
-
-      test -d "$dstdir"
-      dstdir_status=$?
-    fi
-  fi
-
-  obsolete_mkdir_used=false
-
-  if test $dstdir_status != 0; then
-    case $posix_mkdir in
-      '')
-	# Create intermediate dirs using mode 755 as modified by the umask.
-	# This is like FreeBSD 'install' as of 1997-10-28.
-	umask=`umask`
-	case $stripcmd.$umask in
-	  # Optimize common cases.
-	  *[2367][2367]) mkdir_umask=$umask;;
-	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
-
-	  *[0-7])
-	    mkdir_umask=`expr $umask + 22 \
-	      - $umask % 100 % 40 + $umask % 20 \
-	      - $umask % 10 % 4 + $umask % 2
-	    `;;
-	  *) mkdir_umask=$umask,go-w;;
-	esac
-
-	# With -d, create the new directory with the user-specified mode.
-	# Otherwise, rely on $mkdir_umask.
-	if test -n "$dir_arg"; then
-	  mkdir_mode=-m$mode
+	if [ x"$dir_arg" != x ]
+	then
+		if [ -d "$dstarg" ]; then
+			true
+		else
+			$doit $mkdirprog "$dstarg" &&
+
+			if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dstarg"; else true ; fi &&
+			if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dstarg"; else true ; fi &&
+			if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dstarg"; else true ; fi
+		fi
 	else
 	else
-	  mkdir_mode=
+
+		if [ x"$dstisfile" = x ]
+		then
+			file=$srcarg
+		else
+			file=$dst
+		fi
+
+		dstfile=`basename "$file"`
+		dstfinal="$dstdir/$dstfile"
+
+# Make a temp file name in the proper directory.
+
+		dsttmp=$dstdir/#inst.$$#
+
+# Make a backup file name in the proper directory.
+		case x$suffixfmt in
+		*%*)	suffix=`echo x |
+			$awkprog -v bname="$dstfinal" -v fmt="$suffixfmt" '
+			{ cnt = 0;
+			  do {
+				sfx = sprintf(fmt, cnt++);
+				name = bname sfx;
+			  } while (system("test -f " name) == 0);
+			  print sfx; }' -`;;
+		x)	;;
+		*)	suffix="$suffixfmt";;
+		esac
+		dstbackup="$dstfinal$suffix"
+
+# Move or copy the file name to the temp name
+
+		$doit $doinst $srcarg "$dsttmp" &&
+
+		trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing.  If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+		if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else true;fi &&
+		if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else true;fi &&
+		if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripflags "$dsttmp"; else true;fi &&
+		if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else true;fi &&
+
+# Now rename the file to the real destination.
+
+		if [ x"$suffix" != x ] && [ -f "$dstfinal" ]
+		then
+			$doit $mvcmd "$dstfinal" "$dstbackup"
+		else
+			$doit $rmcmd -f "$dstfinal"
+		fi &&
+		$doit $mvcmd "$dsttmp" "$dstfinal"
 	fi
 	fi
 
 
-	posix_mkdir=false
-	case $umask in
-	  *[123567][0-7][0-7])
-	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
-	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
-	    ;;
-	  *)
-	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
-	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
-
-	    if (umask $mkdir_umask &&
-		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
-	    then
-	      if test -z "$dir_arg" || {
-		   # Check for POSIX incompatibilities with -m.
-		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
-		   # other-writeable bit of parent directory when it shouldn't.
-		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
-		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
-		   case $ls_ld_tmpdir in
-		     d????-?r-*) different_mode=700;;
-		     d????-?--*) different_mode=755;;
-		     *) false;;
-		   esac &&
-		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
-		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
-		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
-		   }
-		 }
-	      then posix_mkdir=:
-	      fi
-	      rmdir "$tmpdir/d" "$tmpdir"
-	    else
-	      # Remove any dirs left behind by ancient mkdir implementations.
-	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
-	    fi
-	    trap '' 0;;
-	esac;;
-    esac
+done &&
 
 
-    if
-      $posix_mkdir && (
-	umask $mkdir_umask &&
-	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
-      )
-    then :
-    else
-
-      # The umask is ridiculous, or mkdir does not conform to POSIX,
-      # or it failed possibly due to a race condition.  Create the
-      # directory the slow way, step by step, checking for races as we go.
-
-      case $dstdir in
-	/*) prefix='/';;
-	-*) prefix='./';;
-	*)  prefix='';;
-      esac
-
-      eval "$initialize_posix_glob"
-
-      oIFS=$IFS
-      IFS=/
-      $posix_glob set -f
-      set fnord $dstdir
-      shift
-      $posix_glob set +f
-      IFS=$oIFS
-
-      prefixes=
-
-      for d
-      do
-	test -z "$d" && continue
-
-	prefix=$prefix$d
-	if test -d "$prefix"; then
-	  prefixes=
-	else
-	  if $posix_mkdir; then
-	    (umask=$mkdir_umask &&
-	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
-	    # Don't fail if two instances are running concurrently.
-	    test -d "$prefix" || exit 1
-	  else
-	    case $prefix in
-	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
-	      *) qprefix=$prefix;;
-	    esac
-	    prefixes="$prefixes '$qprefix'"
-	  fi
-	fi
-	prefix=$prefix/
-      done
-
-      if test -n "$prefixes"; then
-	# Don't fail if two instances are running concurrently.
-	(umask $mkdir_umask &&
-	 eval "\$doit_exec \$mkdirprog $prefixes") ||
-	  test -d "$dstdir" || exit 1
-	obsolete_mkdir_used=true
-      fi
-    fi
-  fi
-
-  if test -n "$dir_arg"; then
-    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
-    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
-    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
-      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
-  else
-
-    # Make a couple of temp file names in the proper directory.
-    dsttmp=$dstdir/_inst.$$_
-    rmtmp=$dstdir/_rm.$$_
-
-    # Trap to clean up those temp files at exit.
-    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
-
-    # Copy the file name to the temp name.
-    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
-
-    # and set any options; do chmod last to preserve setuid bits.
-    #
-    # If any of these fail, we abort the whole thing.  If we want to
-    # ignore errors from any of these, just make sure not to ignore
-    # errors from the above "$doit $cpprog $src $dsttmp" command.
-    #
-    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
-    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
-    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
-    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
-
-    # If -C, don't bother to copy if it wouldn't change the file.
-    if $copy_on_change &&
-       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
-       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
-
-       eval "$initialize_posix_glob" &&
-       $posix_glob set -f &&
-       set X $old && old=:$2:$4:$5:$6 &&
-       set X $new && new=:$2:$4:$5:$6 &&
-       $posix_glob set +f &&
-
-       test "$old" = "$new" &&
-       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
-    then
-      rm -f "$dsttmp"
-    else
-      # Rename the file to the real destination.
-      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
-
-      # The rename failed, perhaps because mv can't rename something else
-      # to itself, or perhaps because mv is so ancient that it does not
-      # support -f.
-      {
-	# Now remove or move aside any old file at destination location.
-	# We try this two ways since rm can't unlink itself on some
-	# systems and the destination file might be busy for other
-	# reasons.  In this case, the final cleanup might fail but the new
-	# file should still install successfully.
-	{
-	  test ! -f "$dst" ||
-	  $doit $rmcmd -f "$dst" 2>/dev/null ||
-	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
-	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
-	  } ||
-	  { echo "$0: cannot unlink or rename $dst" >&2
-	    (exit 1); exit 1
-	  }
-	} &&
-
-	# Now rename the file to the real destination.
-	$doit $mvcmd "$dsttmp" "$dst"
-      }
-    fi || exit 1
-
-    trap '' 0
-  fi
-done
 
 
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End:
+exit 0

+ 2 - 2
magic/Magdir/animation

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: animation,v 1.46 2012/08/26 10:43:05 christos Exp $
+# $File: animation,v 1.47 2013/02/06 14:18:52 christos Exp $
 # animation:  file(1) magic for animation/movie formats
 # animation:  file(1) magic for animation/movie formats
 #
 #
 # animation formats
 # animation formats
@@ -751,7 +751,7 @@
 >0	byte		x		GameCube movie,
 >0	byte		x		GameCube movie,
 >0x34	ubeshort	x		%d x
 >0x34	ubeshort	x		%d x
 >0x36	ubeshort	x		%d,
 >0x36	ubeshort	x		%d,
->0x26	ubeshort	x		%dµs,
+>0x26	ubeshort	x		%dus,
 >0x42	ubeshort	0		no audio
 >0x42	ubeshort	0		no audio
 >0x42	ubeshort	>0		%dHz audio
 >0x42	ubeshort	>0		%dHz audio
 
 

+ 46 - 0
magic/Magdir/aout

@@ -0,0 +1,46 @@
+
+#------------------------------------------------------------------------------
+# $File: aout,v 1.1 2013/01/09 22:37:23 christos Exp $
+# aout:  file(1) magic for a.out executable/object/etc entries that
+# handle executables on multiple platforms.
+#
+
+#
+# Little-endian 32-bit-int a.out, merged from bsdi (for BSD/OS, from
+# BSDI), netbsd, and vax (for UNIX/32V and BSD)
+#
+# XXX - is there anything we can look at to distinguish BSD/OS 386 from
+# NetBSD 386 from various VAX binaries?  The BSD/OS shared library flag
+# works only for binaries using shared libraries.  Grabbing the entry
+# point from the a.out header, using it to find the first code executed
+# in the program, and looking at that might help.
+#
+0	lelong		0407		a.out little-endian 32-bit executable
+>16	lelong		>0		not stripped
+>32	byte		0x6a		(uses BSD/OS shared libs)
+
+0	lelong		0410		a.out little-endian 32-bit pure executable
+>16	lelong		>0		not stripped
+>32	byte		0x6a		(uses BSD/OS shared libs)
+
+0	lelong		0413		a.out little-endian 32-bit demand paged pure executable
+>16	lelong		>0		not stripped
+>32	byte		0x6a		(uses BSD/OS shared libs)
+
+#
+# Big-endian 32-bit-int a.out, merged from sun (for old 68010 SunOS a.out),
+# mips (for old 68020(!) SGI a.out), and netbsd (for old big-endian a.out).
+#
+# XXX - is there anything we can look at to distinguish old SunOS 68010
+# from old 68020 IRIX from old NetBSD?  Again, I guess we could look at
+# the first instruction or instructions in the program.
+#
+0	belong		0407		a.out big-endian 32-bit executable
+>16	belong		>0		not stripped
+
+0	belong		0410		a.out big-endian 32-bit pure executable
+>16	belong		>0		not stripped
+
+0	belong		0413		a.out big-endian 32-bit demand paged executable
+>16	belong		>0		not stripped
+

+ 82 - 78
magic/Magdir/archive

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

+ 8 - 8
magic/Magdir/assembler

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

+ 2 - 2
magic/Magdir/audio

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: audio,v 1.65 2012/10/31 13:38:40 christos Exp $
+# $File: audio,v 1.66 2013/02/06 14:18:52 christos Exp $
 # audio:  file(1) magic for sound formats (see also "iff")
 # audio:  file(1) magic for sound formats (see also "iff")
 #
 #
 # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com),
 # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com),
@@ -512,7 +512,7 @@
 >>12		ulelong		x		\b, sample rate %d
 >>12		ulelong		x		\b, sample rate %d
 
 
 # adlib sound files
 # adlib sound files
-# From Gürkan Sengün <gurkan@linuks.mine.nu>, http://www.linuks.mine.nu
+# From Gurkan Sengun <gurkan@linuks.mine.nu>, http://www.linuks.mine.nu
 0    	string		RAWADATA	RdosPlay RAW
 0    	string		RAWADATA	RdosPlay RAW
 
 
 1068	string		RoR		AMUSIC Adlib Tracker
 1068	string		RoR		AMUSIC Adlib Tracker

+ 3 - 13
magic/Magdir/bsdi

@@ -1,25 +1,15 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: bsdi,v 1.5 2009/09/19 16:28:08 christos Exp $
+# $File: bsdi,v 1.6 2013/01/09 22:37:24 christos Exp $
 # bsdi:  file(1) magic for BSD/OS (from BSDI) objects
 # bsdi:  file(1) magic for BSD/OS (from BSDI) objects
+# Some object/executable formats use the same magic numbers as are used
+# in other OSes; those are handled by entries in aout.
 #
 #
 
 
 0	lelong		0314		386 compact demand paged pure executable
 0	lelong		0314		386 compact demand paged pure executable
 >16	lelong		>0		not stripped
 >16	lelong		>0		not stripped
 >32	byte		0x6a		(uses shared libs)
 >32	byte		0x6a		(uses shared libs)
 
 
-0	lelong		0407		386 executable
->16	lelong		>0		not stripped
->32	byte		0x6a		(uses shared libs)
-
-0	lelong		0410		386 pure executable
->16	lelong		>0		not stripped
->32	byte		0x6a		(uses shared libs)
-
-0	lelong		0413		386 demand paged pure executable
->16	lelong		>0		not stripped
->32	byte		0x6a		(uses shared libs)
-
 # same as in SunOS 4.x, except for static shared libraries
 # same as in SunOS 4.x, except for static shared libraries
 0	belong&077777777	0600413		sparc demand paged
 0	belong&077777777	0600413		sparc demand paged
 >0	byte		&0x80
 >0	byte		&0x80

+ 12 - 12
magic/Magdir/cafebabe

@@ -1,13 +1,13 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: cafebabe,v 1.10 2012/10/31 16:32:01 christos Exp $
+# $File: cafebabe,v 1.12 2013/01/11 16:45:23 christos Exp $
 # Cafe Babes unite!
 # Cafe Babes unite!
 #
 #
-# Since Java bytecode and Mach-O fat-files have the same magic number, the test
-# must be performed in the same "magic" sequence to get both right.  The long
-# at offset 4 in a mach-O fat file tells the number of architectures; the short at
-# offset 4 in a Java bytecode file is the JVM minor version and the
-# short at offset 6 is the JVM major version.  Since there are only 
+# Since Java bytecode and Mach-O universal binaries have the same magic number,
+# the test must be performed in the same "magic" sequence to get both right.
+# The long at offset 4 in a Mach-O universal binary tells the number of
+# architectures; the short at offset 4 in a Java bytecode file is the JVM minor
+# version and the short at offset 6 is the JVM major version.  Since there are only 
 # only 18 labeled Mach-O architectures at current, and the first released 
 # only 18 labeled Mach-O architectures at current, and the first released 
 # Java class format was version 43.0, we can safely choose any number
 # Java class format was version 43.0, we can safely choose any number
 # between 18 and 39 to test the number of architectures against
 # between 18 and 39 to test the number of architectures against
@@ -30,14 +30,14 @@
 >>4	belong		0x0032		(Java 1.6)
 >>4	belong		0x0032		(Java 1.6)
 
 
 0	belong		0xcafed00d	JAR compressed with pack200,
 0	belong		0xcafed00d	JAR compressed with pack200,
->>5	byte		x		version %d.
->>4	byte		x		\b%d
+>5	byte		x		version %d.
+>4	byte		x		\b%d
 !:mime	application/x-java-pack200
 !:mime	application/x-java-pack200
 
 
 
 
 0	belong		0xcafed00d	JAR compressed with pack200,
 0	belong		0xcafed00d	JAR compressed with pack200,
->>5	byte		x		version %d.
->>4	byte		x		\b%d
+>5	byte		x		version %d.
+>4	byte		x		\b%d
 !:mime	application/x-java-pack200
 !:mime	application/x-java-pack200
 
 
 ### JAVA END ###
 ### JAVA END ###
@@ -64,10 +64,10 @@
 >0	belong		x		\b]
 >0	belong		x		\b]
 
 
 0	belong		0xcafebabe
 0	belong		0xcafebabe
->4	belong		1		Mach-O fat file with 1 architecture:
+>4	belong		1		Mach-O universal binary with 1 architecture:
 >>8	use		mach-o
 >>8	use		mach-o
 >4	belong		>1
 >4	belong		>1
->>4	belong		<20		Mach-O fat file with %ld architectures:
+>>4	belong		<20		Mach-O universal binary with %ld architectures:
 >>>8	use		mach-o
 >>>8	use		mach-o
 >>>28	use		mach-o
 >>>28	use		mach-o
 >>>4	belong		>2
 >>>4	belong		>2

+ 2 - 2
magic/Magdir/commands

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: commands,v 1.43 2012/06/21 01:08:56 christos Exp $
+# $File: commands,v 1.45 2013/02/06 14:18:52 christos Exp $
 # commands:  file(1) magic for various shells and interpreters
 # commands:  file(1) magic for various shells and interpreters
 #
 #
 #0	string/w	:			shell archive or script for antique kernel text
 #0	string/w	:			shell archive or script for antique kernel text
@@ -80,7 +80,7 @@
 !:strength + 10
 !:strength + 10
 !:mime	text/x-php
 !:mime	text/x-php
 # Smarty compiled template, http://www.smarty.net/
 # Smarty compiled template, http://www.smarty.net/
-# Elan Ruusamäe <glen@delfi.ee>
+# Elan Ruusamae <glen@delfi.ee>
 0	string	=<?php\ /*\ Smarty\ version	Smarty compiled template
 0	string	=<?php\ /*\ Smarty\ version	Smarty compiled template
 >24	regex	[0-9.]+				\b, version %s
 >24	regex	[0-9.]+				\b, version %s
 !:mime	text/x-php
 !:mime	text/x-php

+ 3 - 3
magic/Magdir/console

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: console,v 1.18 2010/09/20 19:19:17 rrt Exp $
+# $File: console,v 1.19 2013/02/06 14:18:52 christos Exp $
 # Console game magic
 # Console game magic
 # Toby Deshane <hac@shoelace.digivill.net>
 # Toby Deshane <hac@shoelace.digivill.net>
 #    ines:  file(1) magic for Marat's iNES Nintendo Entertainment System
 #    ines:  file(1) magic for Marat's iNES Nintendo Entertainment System
@@ -137,7 +137,7 @@
 >113	string	x		(%s)
 >113	string	x		(%s)
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# Microsoft Xbox executables .xbe (Esa Hyytiä <ehyytia@cc.hut.fi>)
+# Microsoft Xbox executables .xbe (Esa Hyytia <ehyytia@cc.hut.fi>)
 0       string          XBEH            XBE, Microsoft Xbox executable
 0       string          XBEH            XBE, Microsoft Xbox executable
 # probabilistic checks whether signed or not
 # probabilistic checks whether signed or not
 >0x0004 ulelong =0x0
 >0x0004 ulelong =0x0
@@ -177,7 +177,7 @@
 # From: Serge van den Boom <svdb@stack.nl>
 # From: Serge van den Boom <svdb@stack.nl>
 0	string		\x01ZZZZZ\x01	3DO "Opera" file system
 0	string		\x01ZZZZZ\x01	3DO "Opera" file system
 
 
-# From Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu
+# From Gurkan Sengun <gurkan@linuks.mine.nu>, www.linuks.mine.nu
 0	string		GBS		Nintendo Gameboy Music/Audio Data
 0	string		GBS		Nintendo Gameboy Music/Audio Data
 12	string		GameBoy\ Music\ Module	Nintendo Gameboy Music Module
 12	string		GameBoy\ Music\ Module	Nintendo Gameboy Music Module
 
 

+ 2 - 10
magic/Magdir/database

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: database,v 1.30 2012/08/26 10:23:30 christos Exp $
+# $File: database,v 1.32 2013/02/06 14:18:52 christos Exp $
 # database:  file(1) magic for various databases
 # database:  file(1) magic for various databases
 #
 #
 # extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk)
 # extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk)
@@ -271,14 +271,6 @@
 >48	lequad		x			\b, rnum=%lld
 >48	lequad		x			\b, rnum=%lld
 >56	lequad		x			\b, fsiz=%lld
 >56	lequad		x			\b, fsiz=%lld
 
 
-# G-IR database made by gobject-introspect toolset,
-# http://live.gnome.org/GObjectIntrospection
-0	string		GOBJ\nMETADATA\r\n\032	G-IR binary database
->16	byte		x			\b, v%d
->17	byte		x			\b.%d
->20	leshort		x			\b, %d entries
->22	leshort		x			\b/%d local
-
 # Type:	QDBM Quick Database Manager
 # Type:	QDBM Quick Database Manager
 # From:	Benoit Sibaud <bsibaud@april.org>
 # From:	Benoit Sibaud <bsibaud@april.org>
 0	string		\\[depot\\]\n\f		Quick Database Manager, little endian
 0	string		\\[depot\\]\n\f		Quick Database Manager, little endian
@@ -290,7 +282,7 @@
 0	string		ToKyO\ CaBiNeT\n	TokyoCabinet database
 0	string		ToKyO\ CaBiNeT\n	TokyoCabinet database
 >14	string		x			(version %s)
 >14	string		x			(version %s)
 
 
-# From:  Stéphane Blondon http://www.yaal.fr
+# From:  Stephane Blondon http://www.yaal.fr
 # Database file for Zope (done by FileStorage)
 # Database file for Zope (done by FileStorage)
 0	string		FS21	Zope Object Database File Storage (data)
 0	string		FS21	Zope Object Database File Storage (data)
 # Cache file for the database of Zope (done by ClientStorage)
 # Cache file for the database of Zope (done by ClientStorage)

+ 15 - 15
magic/Magdir/digital

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: digital,v 1.10 2011/05/03 01:44:17 christos Exp $
+# $File: digital,v 1.11 2013/01/11 16:45:23 christos Exp $
 #  Digital UNIX - Info
 #  Digital UNIX - Info
 #
 #
 0	string	=!<arch>\n________64E	Alpha archive
 0	string	=!<arch>\n________64E	Alpha archive
@@ -8,20 +8,20 @@
 #
 #
 
 
 0	leshort		0603
 0	leshort		0603
->>24	leshort		0410		COFF format alpha pure
->>24	leshort		0413		COFF format alpha demand paged
->>>22	leshort&030000	!020000		executable
->>>22	leshort&020000	!0		dynamically linked
->>>16	lelong		!0		not stripped
->>>16	lelong		0		stripped
->>>27	byte		x		- version %d
->>>26	byte		x		\b.%d
->>>28	byte		x		\b-%d
->>24	leshort		0407		COFF format alpha object
->>>22	leshort&030000	020000		shared library
->>>27	byte		x		- version %d
->>>26	byte		x		\b.%d
->>>28	byte		x		\b-%d
+>24	leshort		0410		COFF format alpha pure
+>24	leshort		0413		COFF format alpha demand paged
+>>22	leshort&030000	!020000		executable
+>>22	leshort&020000	!0		dynamically linked
+>>16	lelong		!0		not stripped
+>>16	lelong		0		stripped
+>>27	byte		x		- version %d
+>>26	byte		x		\b.%d
+>>28	byte		x		\b-%d
+>24	leshort		0407		COFF format alpha object
+>>22	leshort&030000	020000		shared library
+>>27	byte		x		- version %d
+>>26	byte		x		\b.%d
+>>28	byte		x		\b-%d
 
 
 # Basic recognition of Digital UNIX core dumps - Mike Bremford <mike@opac.bl.uk>
 # Basic recognition of Digital UNIX core dumps - Mike Bremford <mike@opac.bl.uk>
 #
 #

+ 198 - 41
magic/Magdir/filesystems

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

+ 2 - 2
magic/Magdir/fonts

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: fonts,v 1.24 2012/08/26 10:32:10 christos Exp $
+# $File: fonts,v 1.25 2013/02/06 14:18:52 christos Exp $
 # fonts:  file(1) magic for font data
 # fonts:  file(1) magic for font data
 #
 #
 0	search/1	FONT		ASCII vfont text
 0	search/1	FONT		ASCII vfont text
@@ -75,7 +75,7 @@
 0	string		OTTO		OpenType font data
 0	string		OTTO		OpenType font data
 !:mime application/vnd.ms-opentype
 !:mime application/vnd.ms-opentype
 
 
-# Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu 
+# Gurkan Sengun <gurkan@linuks.mine.nu>, www.linuks.mine.nu 
 0	string		SplineFontDB:	Spline Font Database 
 0	string		SplineFontDB:	Spline Font Database 
 !:mime application/vnd.font-fontforge-sfd
 !:mime application/vnd.font-fontforge-sfd
 >14	string		x		version %s
 >14	string		x		version %s

+ 35 - 2
magic/Magdir/gnome-keyring

@@ -1,7 +1,8 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: gnome-keyring,v 1.3 2012/06/21 01:19:51 christos Exp $
-# GNOME keyring
+# $File: gnome,v 1.3 2013/02/05 15:20:47 christos Exp $
+# GNOME related files
+
 # Contributed by Josh Triplett
 # Contributed by Josh Triplett
 # FIXME: Could be simplified if pstring supported two-byte counts
 # FIXME: Could be simplified if pstring supported two-byte counts
 0         string   GnomeKeyring\n\r\0\n GNOME keyring
 0         string   GnomeKeyring\n\r\0\n GNOME keyring
@@ -24,3 +25,35 @@
 >>>>>>&24 ubelong  x                    \b, hash iterations %u
 >>>>>>&24 ubelong  x                    \b, hash iterations %u
 >>>>>>&28 ubequad  x                    \b, salt %llu
 >>>>>>&28 ubequad  x                    \b, salt %llu
 >>>>>>&52 ubelong  x                    \b, %u item(s)
 >>>>>>&52 ubelong  x                    \b, %u item(s)
+
+# From: Alex Beregszaszi <alex@fsn.hu>
+4	string	gtktalog		GNOME Catalogue (gtktalog)
+>13	string	>\0			version %s
+
+# Summary: GStreamer binary registry
+# Extension: .bin
+# Submitted by: Josh Triplett <josh@joshtriplett.org>
+0	belong	0xc0def00d		GStreamer binary registry
+>4	string	x			\b, version %s
+
+# GVariant Database file
+# By Elan Ruusamae <glen@delfi.ee>
+# https://github.com/GNOME/gvdb/blob/master/gvdb-format.h
+# It's always "GVariant", it's byte swapped on incompatible archs
+# See https://github.com/GNOME/gvdb/blob/master/gvdb-builder.c
+# file_builder_serialise()
+# http://developer.gnome.org/glib/2.34/glib-GVariant.html#GVariant
+0	string	GVariant	GVariant Database file,
+# version is never filled. probably future extension
+>8	lelong	x		version %d
+# not sure are these usable, so commented out
+#>>16	lelong	x		start %d,
+#>>>20	lelong	x		end %d
+
+# G-IR database made by gobject-introspect toolset,
+# http://live.gnome.org/GObjectIntrospection
+0	string		GOBJ\nMETADATA\r\n\032	G-IR binary database
+>16	byte		x			\b, v%d
+>17	byte		x			\b.%d
+>20	leshort		x			\b, %d entries
+>22	leshort		x			\b/%d local

+ 241 - 0
magic/Magdir/gpt

@@ -0,0 +1,241 @@
+
+#------------------------------------------------------------------------------
+# $File: gpt,v 1.1 2013/02/18 18:31:09 christos Exp $
+#
+# GPT Partition table patterns.
+# Author: Rogier Goossens (goossens.rogier@gmail.com)
+# Note that a GPT-formatted disk must contain an MBR as well.
+#
+
+# The initial segment (up to >>>>>>>>422) was copied from the X86
+# partition table code (aka MBR).
+# This is kept separate, so that MBR partitions are not reported as well.
+# (use -k if you do want them as well)
+
+# First, detect the MBR partiton table
+# If more than one GPT protective MBR partition exists, don't print anything
+# (the other MBR detection code will then just print the MBR partition table)
+0x1FE			leshort		0xAA55
+>3			string		!MS
+>>3			string		!SYSLINUX
+>>>3			string		!MTOOL
+>>>>3			string		!NEWLDR
+>>>>>5			string		!DOS
+# not FAT (32 bit)
+>>>>>>82		string		!FAT32
+#not Linux kernel
+>>>>>>>514		string		!HdrS
+#not BeOS
+>>>>>>>>422		string		!Be\ Boot\ Loader
+# GPT with protective MBR entry in partition 1 (only)
+>>>>>>>>>450		ubyte		0xee
+>>>>>>>>>>466		ubyte		!0xee
+>>>>>>>>>>>482		ubyte		!0xee
+>>>>>>>>>>>>498		ubyte		!0xee
+#>>>>>>>>>>>>>446	use		gpt-mbr-partition
+>>>>>>>>>>>>>(454.l*8192)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>0			use		gpt-mbr-type
+>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>0			ubyte		x		of 8192 bytes		
+>>>>>>>>>>>>>(454.l*8192)	string		!EFI\ PART
+>>>>>>>>>>>>>>(454.l*4096)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>0		ubyte		x		of 4096 bytes
+>>>>>>>>>>>>>>(454.l*4096)	string		!EFI\ PART
+>>>>>>>>>>>>>>>(454.l*2048)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>0		ubyte		x		of 2048 bytes
+>>>>>>>>>>>>>>>(454.l*2048)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>(454.l*1024)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>0		ubyte		x		of 1024 bytes
+>>>>>>>>>>>>>>>>(454.l*1024)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>>(454.l*512)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>>0		ubyte		x		of 512 bytes
+# GPT with protective MBR entry in partition 2 (only)
+>>>>>>>>>450		ubyte		!0xee
+>>>>>>>>>>466		ubyte		0xee
+>>>>>>>>>>>482		ubyte		!0xee
+>>>>>>>>>>>>498		ubyte		!0xee
+#>>>>>>>>>>>>>462	use		gpt-mbr-partition
+>>>>>>>>>>>>>(470.l*8192)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>0			use		gpt-mbr-type
+>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>0			ubyte		x		of 8192 bytes		
+>>>>>>>>>>>>>(470.l*8192)	string		!EFI\ PART
+>>>>>>>>>>>>>>(470.l*4096)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>0		ubyte		x		of 4096 bytes
+>>>>>>>>>>>>>>(470.l*4096)	string		!EFI\ PART
+>>>>>>>>>>>>>>>(470.l*2048)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>0		ubyte		x		of 2048 bytes
+>>>>>>>>>>>>>>>(470.l*2048)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>(470.l*1024)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>0		ubyte		x		of 1024 bytes
+>>>>>>>>>>>>>>>>(470.l*1024)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>>(470.l*512)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>>0		ubyte		x		of 512 bytes
+# GPT with protective MBR entry in partition 3 (only)
+>>>>>>>>>450		ubyte		!0xee
+>>>>>>>>>>466		ubyte		!0xee
+>>>>>>>>>>>482		ubyte		0xee
+>>>>>>>>>>>>498		ubyte		!0xee
+#>>>>>>>>>>>>>478	use		gpt-mbr-partition
+>>>>>>>>>>>>>(486.l*8192)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>0			use		gpt-mbr-type
+>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>0			ubyte		x		of 8192 bytes		
+>>>>>>>>>>>>>(486.l*8192)	string		!EFI\ PART
+>>>>>>>>>>>>>>(486.l*4096)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>0		ubyte		x		of 4096 bytes
+>>>>>>>>>>>>>>(486.l*4096)	string		!EFI\ PART
+>>>>>>>>>>>>>>>(486.l*2048)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>0		ubyte		x		of 2048 bytes
+>>>>>>>>>>>>>>>(486.l*2048)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>(486.l*1024)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>0		ubyte		x		of 1024 bytes
+>>>>>>>>>>>>>>>>(486.l*1024)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>>(486.l*512)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>>0		ubyte		x		of 512 bytes
+# GPT with protective MBR entry in partition 4 (only)
+>>>>>>>>>450		ubyte		!0xee
+>>>>>>>>>>466		ubyte		!0xee
+>>>>>>>>>>>482		ubyte		!0xee
+>>>>>>>>>>>>498		ubyte		0xee
+#>>>>>>>>>>>>>494	use		gpt-mbr-partition
+>>>>>>>>>>>>>(502.l*8192)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>0			use		gpt-mbr-type
+>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>0			ubyte		x		of 8192 bytes		
+>>>>>>>>>>>>>(502.l*8192)	string		!EFI\ PART
+>>>>>>>>>>>>>>(502.l*4096)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>0		ubyte		x		of 4096 bytes
+>>>>>>>>>>>>>>(502.l*4096)	string		!EFI\ PART
+>>>>>>>>>>>>>>>(502.l*2048)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>0		ubyte		x		of 2048 bytes
+>>>>>>>>>>>>>>>(502.l*2048)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>(502.l*1024)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>0		ubyte		x		of 1024 bytes
+>>>>>>>>>>>>>>>>(502.l*1024)	string		!EFI\ PART
+>>>>>>>>>>>>>>>>>(502.l*512)	string		EFI\ PART	GPT partition table
+>>>>>>>>>>>>>>>>>>0		use		gpt-mbr-type
+>>>>>>>>>>>>>>>>>>&-8		use		gpt-table
+>>>>>>>>>>>>>>>>>>0		ubyte		x		of 512 bytes
+
+# The following code does GPT detection and processing, including
+# sector size detection.
+# It has to be duplicated above because the top-level pattern
+# (i.e. not called using 'use') must print *something* for file
+# to count it as a match. Text only printed in named patterns is
+# not counted, and causes file to continue, and try and match
+# other patterns.
+#
+# Unfortunately, when assuming sector sizes >=16k, if the sector size
+# happens to be 512 instead, we may find confusing data after the GPT
+# table...  If the GPT table has less than 128 entries, this may even
+# happen for assumed sector sizes as small as 4k
+# This could be solved by checking for the presence of the backup GPT
+# header as well, but that makes the logic extremely complex
+##0		name		gpt-mbr-partition
+##>(8.l*8192)	string		EFI\ PART
+##>>(8.l*8192)	use		gpt-mbr-type
+##>>&-8		use		gpt-table
+##>>0		ubyte		x		of 8192 bytes		
+##>(8.l*8192)	string		!EFI\ PART
+##>>(8.l*4096)	string		EFI\ PART	GPT partition table
+##>>>0		use		gpt-mbr-type
+##>>>&-8		use		gpt-table
+##>>>0		ubyte		x		of 4096 bytes
+##>>(8.l*4096)	string		!EFI\ PART
+##>>>(8.l*2048)	string		EFI\ PART	GPT partition table
+##>>>>0		use		gpt-mbr-type
+##>>>>&-8		use		gpt-table
+##>>>>0		ubyte		x		of 2048 bytes
+##>>>(8.l*2048)	string		!EFI\ PART
+##>>>>(8.l*1024)	string		EFI\ PART	GPT partition table
+##>>>>>0		use		gpt-mbr-type
+##>>>>>&-8	use		gpt-table
+##>>>>>0		ubyte		x		of 1024 bytes
+##>>>>(8.l*1024)	string		!EFI\ PART
+##>>>>>(8.l*512)	string		EFI\ PART	GPT partition table
+##>>>>>>0		use		gpt-mbr-type
+##>>>>>>&-8	use		gpt-table
+##>>>>>>0		ubyte		x		of 512 bytes
+
+# Print details of MBR type for a GPT-disk
+# Calling code ensures that there is only one 0xee partition.
+0		name		gpt-mbr-type
+# GPT with protective MBR entry in partition 1
+>450		ubyte		0xee
+>>454		ulelong		1
+>>>462		string		!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0	\b (with hybrid MBR)
+>>454		ulelong		!1													\b (nonstandard: not at LBA 1)
+# GPT with protective MBR entry in partition 2
+>466		ubyte		0xee
+>>470		ulelong		1
+>>>478		string		\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
+>>>>446		string		!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0					\b (with hybrid MBR)
+>>>478		string		!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0	\b (with hybrid MBR)
+>>470		ulelong		!1									\b (nonstandard: not at LBA 1)
+# GPT with protective MBR entry in partition 3
+>482		ubyte		0xee
+>>486		ulelong		1
+>>>494		string		\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
+>>>>446		string		!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0	\b (with hybrid MBR)
+>>>494		string		!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0					\b (with hybrid MBR)
+>>486		ulelong		!1									\b (nonstandard: not at LBA 1)
+# GPT with protective MBR entry in partition 4
+>498		ubyte		0xee
+>>502		ulelong		1		
+>>>446		string		!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0	\b (with hybrid MBR)
+>>502		ulelong		!1													\b (nonstandard: not at LBA 1)
+
+# Print the information from a GPT partition table structure
+0		name		gpt-table
+>10		uleshort	x		\b, version %u
+>8		uleshort	x		\b.%u
+# a GUID is just like a UUID, except it's displayed mixed-endian.
+>56		ulelong		x		\b, GUID: %08x
+>60		uleshort	x		\b-%04x
+>62		uleshort	x		\b-%04x
+>64		ubeshort	x		\b-%04x
+>66		ubeshort	x		\b-%04x
+>68		ubelong		x		\b%08x
+#>80		uleshort	x		\b, %d partition entries
+>32		ulequad+1	x		\b, disk size: %lld sectors
+
+# In case a GPT data-structure is at LBA 0, report it as well
+# This covers systems which are not GPT-aware, and which show
+# and allow access to the protective partition. This code will
+# detect the contents of such a partition.
+0		string		EFI\ PART	GPT data structure (nonstandard: at LBA 0)
+>0		use		gpt-table
+>0		ubyte		x		(sector size unknown)
+
+

+ 4 - 1
magic/Magdir/hitachi-sh

@@ -1,11 +1,14 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: hitachi-sh,v 1.5 2009/09/19 16:28:09 christos Exp $
+# $File: hitachi-sh,v 1.6 2013/01/29 19:31:33 christos Exp $
 # hitach-sh: file(1) magic for Hitachi Super-H
 # hitach-sh: file(1) magic for Hitachi Super-H
 #
 #
 # Super-H COFF
 # Super-H COFF
 #
 #
+# below test line conflicts with 2nd NTFS filesystem sector 
 0	beshort		0x0500		Hitachi SH big-endian COFF
 0	beshort		0x0500		Hitachi SH big-endian COFF
+# 2nd NTFS filesystem sector often starts with 0x05004e00 for unicode string 5 NTLDR
+#0	ubelong&0xFFFFNMPQ	0x0500NMPQ     Hitachi SH big-endian COFF
 >18	beshort&0x0002	=0x0000		object
 >18	beshort&0x0002	=0x0000		object
 >18	beshort&0x0002	=0x0002		executable
 >18	beshort&0x0002	=0x0002		executable
 >18	beshort&0x0008	=0x0008		\b, stripped
 >18	beshort&0x0008	=0x0008		\b, stripped

+ 2 - 1
magic/Magdir/ibm6000

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: ibm6000,v 1.10 2012/08/10 15:06:07 christos Exp $
+# $File: ibm6000,v 1.11 2013/01/08 20:13:01 christos Exp $
 # ibm6000:  file(1) magic for RS/6000 and the RT PC.
 # ibm6000:  file(1) magic for RS/6000 and the RT PC.
 #
 #
 0	beshort		0x01df		executable (RISC System/6000 V3.1) or obj module
 0	beshort		0x01df		executable (RISC System/6000 V3.1) or obj module
@@ -21,6 +21,7 @@
 0	beshort		0x01f7		64-bit XCOFF executable or object module
 0	beshort		0x01f7		64-bit XCOFF executable or object module
 >20	belong		0		not stripped
 >20	belong		0		not stripped
 4	belong		&0x0feeddb0	AIX core file
 4	belong		&0x0feeddb0	AIX core file
+>1	byte		&0x01		fulldump
 >7	byte		&0x01		32-bit
 >7	byte		&0x01		32-bit
 >>0x6e0 string		>\0		\b, %s
 >>0x6e0 string		>\0		\b, %s
 >7	byte		&0x02		64-bit
 >7	byte		&0x02		64-bit

+ 51 - 0
magic/Magdir/icc

@@ -0,0 +1,51 @@
+
+#------------------------------------------------------------------------------
+# $File: icc,v 1.1 2013/01/08 01:43:18 christos Exp $
+# icc:  file(1) magic for International Color Consortium file formats
+
+#
+# Color profiles as per the ICC's "Image technology colour management -
+# Architecture, profile format, and data structure" specification.
+# See
+#
+#	http://www.color.org/specification/ICC1v43_2010-12.pdf
+#
+# for Specification ICC.1:2010 (Profile version 4.3.0.0).
+#
+# Bytes 36 to 39 contain a generic profile file signature of "acsp";
+# bytes 40 to 43 "may be used to identify the primary platform/operating
+# system framework for which the profile was created".
+#
+# There are other fields that might be worth dumping as well.
+#
+
+# This appears to be what's used for Apple ColorSync profiles.
+# Instead of adding that, Apple just changed the generic "acsp" entry
+# to be for "ColorSync ICC Color Profile" rather than "Kodak Color
+# Management System, ICC Profile".
+# Yes, it's "APPL", not "AAPL"; see the spec.
+36	string		acspAPPL	ColorSync ICC Profile
+!:mime	application/vnd.iccprofile
+
+# Microsoft ICM color profile
+36	string		acspMSFT	Microsoft ICM Color Profile
+!:mime	application/vnd.iccprofile
+
+# Yes, that's a blank after "SGI".
+36	string		acspSGI\ 	SGI ICC Profile
+!:mime	application/vnd.iccprofile
+
+# XXX - is this what's used for the Sun KCMS or not?  The standard file
+# uses just "acsp" for that, but Apple's file uses it for "ColorSync",
+# and there *is* an identified "primary platform" value of SUNW.
+36	string		acspSUNW	Sun KCMS ICC Profile
+!:mime	application/vnd.iccprofile
+
+# Any other profile.
+# XXX - should we use "acsp\0\0\0\0" for "no primary platform" profiles,
+# and use "acsp" for everything else and dump the "primary platform"
+# string in those cases?
+36	string		acsp		ICC Profile
+!:mime	application/vnd.iccprofile
+
+

+ 2 - 2
magic/Magdir/images

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: images,v 1.79 2012/12/18 17:28:44 christos Exp $
+# $File: images,v 1.80 2013/02/06 14:18:52 christos Exp $
 # images:  file(1) magic for image formats (see also "iff", and "c-lang" for
 # images:  file(1) magic for image formats (see also "iff", and "c-lang" for
 # XPM bitmaps)
 # XPM bitmaps)
 #
 #
@@ -427,7 +427,7 @@
 >5	byte	0x00		(white background)
 >5	byte	0x00		(white background)
 >5	byte	0xFF		(black background)
 >5	byte	0xFF		(black background)
 
 
-# Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu
+# Gurkan Sengun <gurkan@linuks.mine.nu>, www.linuks.mine.nu
 # http://www.atarimax.com/jindroush.atari.org/afmtatr.html
 # http://www.atarimax.com/jindroush.atari.org/afmtatr.html
 0	leshort	0x0296		Atari ATR image
 0	leshort	0x0296		Atari ATR image
 
 

+ 2 - 2
magic/Magdir/intel

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: intel,v 1.10 2011/03/30 19:51:00 christos Exp $
+# $File: intel,v 1.11 2013/02/06 14:18:52 christos Exp $
 # intel:  file(1) magic for x86 Unix
 # intel:  file(1) magic for x86 Unix
 #
 #
 # Various flavors of x86 UNIX executable/object (other than Xenix, which
 # Various flavors of x86 UNIX executable/object (other than Xenix, which
@@ -37,7 +37,7 @@
 
 
 # rom: file(1) magic for BIOS ROM Extensions found in intel machines
 # rom: file(1) magic for BIOS ROM Extensions found in intel machines
 #      mapped into memory between 0xC0000 and 0xFFFFF
 #      mapped into memory between 0xC0000 and 0xFFFFF
-# From Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu
+# From Gurkan Sengun <gurkan@linuks.mine.nu>, www.linuks.mine.nu
 0        beshort         0x55AA       BIOS (ia32) ROM Ext.
 0        beshort         0x55AA       BIOS (ia32) ROM Ext.
 >5       string          USB          USB
 >5       string          USB          USB
 >7       string          LDR          UNDI image
 >7       string          LDR          UNDI image

+ 11 - 1
magic/Magdir/java

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------
 #------------------------------------------------------------
-# $File: java,v 1.13 2011/12/08 12:12:46 rrt Exp $
+# $File: java,v 1.14 2013/02/08 16:54:45 christos Exp $
 # Java ByteCode and Mach-O binaries (e.g., Mac OS X) use the
 # Java ByteCode and Mach-O binaries (e.g., Mac OS X) use the
 # same magic number, 0xcafebabe, so they are both handled
 # same magic number, 0xcafebabe, so they are both handled
 # in the entry called "cafebabe".
 # in the entry called "cafebabe".
@@ -27,3 +27,13 @@
 # Java source
 # Java source
 0	regex	^import.*;$	Java source
 0	regex	^import.*;$	Java source
 !:mime	text/x-java
 !:mime	text/x-java
+
+# http://android.stackexchange.com/questions/23357/\
+# is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file/\
+# 23608#23608
+0	string	ANDROID\040BACKUP\n	Android Backup
+>15	string	1\n			\b, version 1
+>17	string	0\n			\b, uncompressed
+>17	string	1\n			\b, compressed
+>19	string	none\n			\b, unencrypted
+>19	string	AES-256\n		\b, encrypted AES-256

+ 2 - 2
magic/Magdir/jpeg

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: jpeg,v 1.18 2012/08/01 12:12:36 christos Exp $
+# $File: jpeg,v 1.19 2013/02/04 15:50:03 christos Exp $
 # JPEG images
 # JPEG images
 # SunOS 5.5.1 had
 # SunOS 5.5.1 had
 #
 #
@@ -12,7 +12,7 @@
 0	beshort		0xffd8		JPEG image data
 0	beshort		0xffd8		JPEG image data
 !:mime	image/jpeg
 !:mime	image/jpeg
 !:apple	8BIMJPEG
 !:apple	8BIMJPEG
-!:strength +1
+!:strength +2
 >6	string		JFIF		\b, JFIF standard
 >6	string		JFIF		\b, JFIF standard
 # The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
 # The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
 # in a vain attempt to add image size reporting for JFIF.  Note that these
 # in a vain attempt to add image size reporting for JFIF.  Note that these

+ 5 - 4
magic/Magdir/linux

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: linux,v 1.45 2012/10/29 17:36:49 christos Exp $
+# $File: linux,v 1.47 2013/02/06 14:18:52 christos Exp $
 # linux:  file(1) magic for Linux files
 # linux:  file(1) magic for Linux files
 #
 #
 # Values for Linux/i386 binaries, from Daniel Quinlan <quinlan@yggdrasil.com>
 # Values for Linux/i386 binaries, from Daniel Quinlan <quinlan@yggdrasil.com>
@@ -94,10 +94,11 @@
 #
 #
 # Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>
 # Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>
 # and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>
 # and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>
-# and Nicolás Lichtmaier <nick@debian.org>
+# and Nicolas Lichtmaier <nick@debian.org>
 # All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29
 # All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29
 # Linux kernel boot images (i386 arch) (Wolfram Kleff)
 # Linux kernel boot images (i386 arch) (Wolfram Kleff)
 514	string		HdrS		Linux kernel
 514	string		HdrS		Linux kernel
+!:strength + 5
 >510	leshort		0xAA55		x86 boot executable
 >510	leshort		0xAA55		x86 boot executable
 >>518	leshort		>0x1ff
 >>518	leshort		>0x1ff
 >>>529	byte		0		zImage,
 >>>529	byte		0		zImage,
@@ -117,10 +118,10 @@
 >0x1e3		string	Loading		version 1.3.79 or older
 >0x1e3		string	Loading		version 1.3.79 or older
 >0x1e9		string	Loading		from prehistoric times
 >0x1e9		string	Loading		from prehistoric times
 
 
-# System.map files - Nicolás Lichtmaier <nick@debian.org>
+# System.map files - Nicolas Lichtmaier <nick@debian.org>
 8	search/1	\ A\ _text	Linux kernel symbol map text
 8	search/1	\ A\ _text	Linux kernel symbol map text
 
 
-# LSM entries - Nicolás Lichtmaier <nick@debian.org>
+# LSM entries - Nicolas Lichtmaier <nick@debian.org>
 0	search/1	Begin3	Linux Software Map entry text
 0	search/1	Begin3	Linux Software Map entry text
 0	search/1	Begin4	Linux Software Map entry text (new format)
 0	search/1	Begin4	Linux Software Map entry text (new format)
 
 

+ 11 - 3
magic/Magdir/llvm

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: llvm,v 1.5 2010/09/20 18:55:20 rrt Exp $
+# $File: llvm,v 1.8 2013/01/12 03:09:51 christos Exp $
 # llvm:  file(1) magic for LLVM byte-codes
 # llvm:  file(1) magic for LLVM byte-codes
 # URL:  http://llvm.org/docs/BitCodeFormat.html
 # URL:  http://llvm.org/docs/BitCodeFormat.html
 # From: Al Stone <ahs3@fc.hp.com>
 # From: Al Stone <ahs3@fc.hp.com>
@@ -9,5 +9,13 @@
 0	string	llvc0	LLVM byte-codes, null compression
 0	string	llvc0	LLVM byte-codes, null compression
 0	string	llvc1	LLVM byte-codes, gzip compression
 0	string	llvc1	LLVM byte-codes, gzip compression
 0	string	llvc2	LLVM byte-codes, bzip2 compression
 0	string	llvc2	LLVM byte-codes, bzip2 compression
-0	string	\xde\xc0\x17\x0b	LLVM bitcode, wrapper
-0       string	BC\xc0\xde	LLVM bitcode
+
+0	lelong	0x0b17c0de	LLVM bitcode, wrapper
+# Are these Mach-O ABI values?  They appear to be.
+>16	lelong	0x01000007	x86_64
+>16	lelong	0x00000007	i386
+>16	lelong	0x00000012	ppc
+>16	lelong	0x01000012	ppc64
+>16	lelong 	0x0000000c	arm
+
+0	string	BC\xc0\xde	LLVM IR bitcode

+ 2 - 1
magic/Magdir/lua

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: lua,v 1.5 2009/09/19 16:28:10 christos Exp $
+# $File: lua,v 1.6 2013/01/09 16:23:17 christos Exp $
 # lua:  file(1) magic for Lua scripting language
 # lua:  file(1) magic for Lua scripting language
 # URL:  http://www.lua.org/
 # URL:  http://www.lua.org/
 # From: Reuben Thomas <rrt@sc3d.org>, Seo Sanghyeon <tinuviel@sparcs.kaist.ac.kr>
 # From: Reuben Thomas <rrt@sc3d.org>, Seo Sanghyeon <tinuviel@sparcs.kaist.ac.kr>
@@ -19,3 +19,4 @@
 0	string		\033Lua			Lua bytecode,
 0	string		\033Lua			Lua bytecode,
 >4	byte		0x50			version 5.0
 >4	byte		0x50			version 5.0
 >4	byte		0x51			version 5.1
 >4	byte		0x51			version 5.1
+>4	byte		0x52			version 5.2

+ 182 - 107
magic/Magdir/mach

@@ -1,118 +1,191 @@
 
 
 #------------------------------------------------------------
 #------------------------------------------------------------
-# $File: mach,v 1.12 2012/11/01 04:26:40 christos Exp $
+# $File: mach,v 1.14 2013/01/04 23:35:53 christos Exp $
 # Mach has two magic numbers, 0xcafebabe and 0xfeedface.
 # Mach has two magic numbers, 0xcafebabe and 0xfeedface.
 # Unfortunately the first, cafebabe, is shared with
 # Unfortunately the first, cafebabe, is shared with
 # Java ByteCode, so they are both handled in the file "cafebabe".
 # Java ByteCode, so they are both handled in the file "cafebabe".
 # The "feedface" ones are handled herein.
 # The "feedface" ones are handled herein.
 #------------------------------------------------------------
 #------------------------------------------------------------
 
 
-0	name		mach-o-bed
+0	name		mach-o-be
 >0	byte		0xcf		64-bit
 >0	byte		0xcf		64-bit
->4	belong		<0
->>4	belong		x		architecture=%ld
->4	belong		1
->>8	belong		0		vax
->>8	belong		1		vax11/780
->>8	belong		2		vax11/785
->>8	belong		3		vax11/750
->>8	belong		4		vax11/730
->>8	belong		5		uvaxI
->>8	belong		6		uvaxII
->>8	belong		7		vax8200
->>8	belong		8		vax8500
->>8	belong		9		vax8600
->>8	belong		10		vax8650
->>8	belong		11		vax8800
->>8	belong		12		uvaxIII
->4	belong		2		romp
->4	belong		3		architecture=3
->4	belong		4		ns32032
->4	belong		5		ns32332
->4	belong		6		m68k
->4	belong		7
->>8	belong		3		i386
->>8	belong		4		i486
->>8	belong		132		i486sx
->>8	belong		5		i586
->>8	belong		8		pentium_3
->>8	belong		9		pentiumM
->>8	belong		10		pentiumIV
->>8	belong		11		itanium
->>8	belong		12		xeon
->>8	belong		14		pentiumIV_M
->>8	belong		15		itanium2
->>8	belong		21		pentiumpro
->>8	belong		23		pentiumIII
->>8	belong		24		pentium_3_M
->>8	belong		25		pentiumV
->>8	belong		26		xeon_mp
->>8	belong		40		pentium_3_xeon
->>8	belong		113		celeron
->>8	belong		119		celeron_mobile
->4	belong		8		mips
->>8	belong		1		R2300
->>8	belong		2		R2600
->>8	belong		3		R2800
->>8	belong		4		R2000a
->>8	belong		5		R2000
->>8	belong		6		R3000a
->>8	belong		7		R3000
->4	belong		9		ns32532
->4	belong		10		mc98000
->4	belong		11		hppa
->>8	belong		0		7100
->>8	belong		1		7100LC
->4	belong		12
->>8	belong		0		arm
->>8	belong		1		arm_v4t
->>8	belong		2		arm_v6
->>8	belong		3		arm_v5tej
->>8	belong		4		arm_xscale
->>8	belong		5		arm_v7
->>8	belong		6		arm_v7f
->>8	belong		7		arm_v7k
->4	belong		13
->>8	belong		0		mc88000
->>8	belong		1		mc88100
->>8	belong		2		mc88110
->4	belong		14		sparc
->4	belong		15		i860g
->4	belong		16		alpha
->4	belong		17		rs6000
->4	belong		18
->>8	belong		0		ppc
->>8	belong		1		ppc_601
->>8	belong		2		ppc_602
->>8	belong		3		ppc_603
->>8	belong		4		ppc_603e
->>8	belong		5		ppc_603ev
->>8	belong		6		ppc_604
->>8	belong		7		ppc_604e
->>8	belong		8		ppc_620
->>8	belong		9		ppc_650
->>8	belong		10		ppc_7400
->>8	belong		11		ppc_7450
->>8	belong		100		ppc_970
->4	belong		16777223
->>8	belong		3		x86_64
->>8	belong		4		x86_64_arch1
->4	belong		16777234
->>8	belong		0		ppc64
->>8	belong		1		ppc64_601
->>8	belong		2		ppc64_602
->>8	belong		3		ppc64_603
->>8	belong		4		ppc64_603e
->>8	belong		5		ppc64_603ev
->>8	belong		6		ppc64_604
->>8	belong		7		ppc64_604e
->>8	belong		8		ppc64_620
->>8	belong		9		ppc64_650
->>8	belong		10		ppc64_7400
->>8	belong		11		ppc64_7450
->>8	belong		100		ppc64_970
->4	belong		>16777234
->>4	belong		x		architecture=%ld
+# if set, it's for the 64-bit version of the architecture
+# yes, this is separate from the low-order magic number bit
+# it's also separate from the "64-bit libraries" bit in the
+# upper 8 bits of the CPU subtype
+>4	belong&0x01000000	0
+#
+# 32-bit ABIs.
+#
+#				1	vax
+>>4	belong&0x00ffffff	1
+>>>8		belong&0x00ffffff	0	vax
+>>>8		belong&0x00ffffff	1	vax11/780
+>>>8		belong&0x00ffffff	2	vax11/785
+>>>8		belong&0x00ffffff	3	vax11/750
+>>>8		belong&0x00ffffff	4	vax11/730
+>>>8		belong&0x00ffffff	5	uvaxI
+>>>8		belong&0x00ffffff	6	uvaxII
+>>>8		belong&0x00ffffff	7	vax8200
+>>>8		belong&0x00ffffff	8	vax8500
+>>>8		belong&0x00ffffff	9	vax8600
+>>>8		belong&0x00ffffff	10	vax8650
+>>>8		belong&0x00ffffff	11	vax8800
+>>>8		belong&0x00ffffff	12	uvaxIII
+>>>8		belong&0x00ffffff	>12	vax subarchitecture=%ld
+>>4	belong&0x00ffffff	2	romp
+>>4	belong&0x00ffffff	3	architecture=3
+>>4	belong&0x00ffffff	4	ns32032
+>>4	belong&0x00ffffff	5	ns32332
+>>4	belong&0x00ffffff	6	m68k
+#				7	x86
+>>4	belong&0x00ffffff	7
+>>>8	belong&0x0000000f	3		i386
+>>>8	belong&0x0000000f	4		i486
+>>>>8	belong&0x00fffff0	0
+>>>>8	belong&0x00fffff0	0x80		\bsx
+>>>8	belong&0x0000000f	5		i586
+>>>8	belong&0x0000000f	6
+>>>>8	belong&0x00fffff0	0		p6
+>>>>8	belong&0x00fffff0	0x10		pentium_pro
+>>>>8	belong&0x00fffff0	0x20		pentium_2_m0x20
+>>>>8	belong&0x00fffff0	0x30		pentium_2_m3
+>>>>8	belong&0x00fffff0	0x40		pentium_2_m0x40
+>>>>8	belong&0x00fffff0	0x50		pentium_2_m5
+>>>>8	belong&0x00fffff0	>0x50		pentium_2_m0x%lx
+>>>8	belong&0x0000000f	7		celeron
+>>>>8	belong&0x00fffff0	0x00		\b_m0x%lx
+>>>>8	belong&0x00fffff0	0x10		\b_m0x%lx
+>>>>8	belong&0x00fffff0	0x20		\b_m0x%lx
+>>>>8	belong&0x00fffff0	0x30		\b_m0x%lx
+>>>>8	belong&0x00fffff0	0x40		\b_m0x%lx
+>>>>8	belong&0x00fffff0	0x50		\b_m0x%lx
+>>>>8	belong&0x00fffff0	0x60
+>>>>8	belong&0x00fffff0	0x70		\b_mobile
+>>>>8	belong&0x00fffff0	>0x70		\b_m0x%lx
+>>>8	belong&0x0000000f	8		pentium_3
+>>>>8	belong&0x00fffff0	0x00
+>>>>8	belong&0x00fffff0	0x10		\b_m
+>>>>8	belong&0x00fffff0	0x20		\b_xeon
+>>>>8	belong&0x00fffff0	>0x20		\b_m0x%lx
+>>>8	belong&0x0000000f	9		pentiumM
+>>>>8	belong&0x00fffff0	0x00
+>>>>8	belong&0x00fffff0	>0x00		\b_m0x%lx
+>>>8	belong&0x0000000f	10		pentium_4
+>>>>8	belong&0x00fffff0	0x00
+>>>>8	belong&0x00fffff0	0x10		\b_m
+>>>>8	belong&0x00fffff0	>0x10		\b_m0x%lx
+>>>8	belong&0x0000000f	11		itanium
+>>>>8	belong&0x00fffff0	0x00
+>>>>8	belong&0x00fffff0	0x10		\b_2
+>>>>8	belong&0x00fffff0	>0x10		\b_m0x%lx
+>>>8	belong&0x0000000f	12		xeon
+>>>>8	belong&0x00fffff0	0x00
+>>>>8	belong&0x00fffff0	0x10		\b_mp
+>>>>8	belong&0x00fffff0	>0x10		\b_m0x%lx
+>>>8	belong&0x0000000f	>12		ia32 family=%ld
+>>>>8	belong&0x00fffff0	0x00
+>>>>8	belong&0x00fffff0	>0x00		model=%lx
+>>4	belong&0x00ffffff	8	mips
+>>>8		belong&0x00ffffff	1	R2300
+>>>8		belong&0x00ffffff	2	R2600
+>>>8		belong&0x00ffffff	3	R2800
+>>>8		belong&0x00ffffff	4	R2000a
+>>>8		belong&0x00ffffff	5	R2000
+>>>8		belong&0x00ffffff	6	R3000a
+>>>8		belong&0x00ffffff	7	R3000
+>>>8		belong&0x00ffffff	>7	subarchitecture=%ld
+>>4	belong&0x00ffffff	9	ns32532
+>>4	belong&0x00ffffff	10	mc98000
+>>4	belong&0x00ffffff	11	hppa
+>>>8		belong&0x00ffffff	0	7100
+>>>8		belong&0x00ffffff	1	7100LC
+>>>8		belong&0x00ffffff	>1	subarchitecture=%ld
+>>4	belong&0x00ffffff	12	arm
+>>>8		belong&0x00ffffff	0
+>>>8		belong&0x00ffffff	1	subarchitecture=%ld
+>>>8		belong&0x00ffffff	2	subarchitecture=%ld
+>>>8		belong&0x00ffffff	3	subarchitecture=%ld
+>>>8		belong&0x00ffffff	4	subarchitecture=%ld
+>>>8		belong&0x00ffffff	5	\b_v4t
+>>>8		belong&0x00ffffff	6	\b_v6
+>>>8		belong&0x00ffffff	7	\b_v5tej
+>>>8		belong&0x00ffffff	8	\b_xscale
+>>>8		belong&0x00ffffff	9	\b_v7
+>>>8		belong&0x00ffffff	10	\b_v7f
+>>>8		belong&0x00ffffff	11	subarchitecture=%ld
+>>>8		belong&0x00ffffff	12	\b_v7k
+>>>8		belong&0x00ffffff	>12	subarchitecture=%ld
+#				13	m88k
+>>4	belong&0x00ffffff	13
+>>>8		belong&0x00ffffff	0	mc88000
+>>>8		belong&0x00ffffff	1	mc88100
+>>>8		belong&0x00ffffff	2	mc88110
+>>>8		belong&0x00ffffff	>2	mc88000 subarchitecture=%ld
+>>4	belong&0x00ffffff	14	sparc
+>>4	belong&0x00ffffff	15	i860g
+>>4	belong&0x00ffffff	16	alpha
+>>4	belong&0x00ffffff	17	rs6000
+>>4	belong&0x00ffffff	18	ppc
+>>>8		belong&0x00ffffff	0
+>>>8		belong&0x00ffffff	1	\b_601
+>>>8		belong&0x00ffffff	2	\b_602
+>>>8		belong&0x00ffffff	3	\b_603
+>>>8		belong&0x00ffffff	4	\b_603e
+>>>8		belong&0x00ffffff	5	\b_603ev
+>>>8		belong&0x00ffffff	6	\b_604
+>>>8		belong&0x00ffffff	7	\b_604e
+>>>8		belong&0x00ffffff	8	\b_620
+>>>8		belong&0x00ffffff	9	\b_650
+>>>8		belong&0x00ffffff	10	\b_7400
+>>>8		belong&0x00ffffff	11	\b_7450
+>>>8		belong&0x00ffffff	100	\b_970
+>>>8		belong&0x00ffffff	>100	subarchitecture=%ld
+>>4	belong&0x00ffffff	>18	architecture=%ld
+>4	belong&0x01000000	0x01000000
+#
+# 64-bit ABIs.
+#
+>>4	belong&0x00ffffff	0	64-bit architecture=%ld
+>>4	belong&0x00ffffff	1	64-bit architecture=%ld
+>>4	belong&0x00ffffff	2	64-bit architecture=%ld
+>>4	belong&0x00ffffff	3	64-bit architecture=%ld
+>>4	belong&0x00ffffff	4	64-bit architecture=%ld
+>>4	belong&0x00ffffff	5	64-bit architecture=%ld
+>>4	belong&0x00ffffff	6	64-bit architecture=%ld
+>>4	belong&0x00ffffff	7	x86_64
+>>>8		belong&0x00ffffff	0	subarchitecture=%ld
+>>>8		belong&0x00ffffff	1	subarchitecture=%ld
+>>>8		belong&0x00ffffff	2	subarchitecture=%ld
+>>>8		belong&0x00ffffff	3
+>>>8		belong&0x00ffffff	4	\b_arch1
+>>>8		belong&0x00ffffff	>4	subarchitecture=%ld
+>>4	belong&0x00ffffff	8	64-bit architecture=%ld
+>>4	belong&0x00ffffff	9	64-bit architecture=%ld
+>>4	belong&0x00ffffff	10	64-bit architecture=%ld
+>>4	belong&0x00ffffff	11	64-bit architecture=%ld
+>>4	belong&0x00ffffff	12	64-bit architecture=%ld
+>>4	belong&0x00ffffff	13	64-bit architecture=%ld
+>>4	belong&0x00ffffff	14	64-bit architecture=%ld
+>>4	belong&0x00ffffff	15	64-bit architecture=%ld
+>>4	belong&0x00ffffff	16	64-bit architecture=%ld
+>>4	belong&0x00ffffff	17	64-bit architecture=%ld
+>>4	belong&0x00ffffff	18	ppc64
+>>>8		belong&0x00ffffff	0
+>>>8		belong&0x00ffffff	1		\b_601
+>>>8		belong&0x00ffffff	2		\b_602
+>>>8		belong&0x00ffffff	3		\b_603
+>>>8		belong&0x00ffffff	4		\b_603e
+>>>8		belong&0x00ffffff	5		\b_603ev
+>>>8		belong&0x00ffffff	6		\b_604
+>>>8		belong&0x00ffffff	7		\b_604e
+>>>8		belong&0x00ffffff	8		\b_620
+>>>8		belong&0x00ffffff	9		\b_650
+>>>8		belong&0x00ffffff	10		\b_7400
+>>>8		belong&0x00ffffff	11		\b_7450
+>>>8		belong&0x00ffffff	100		\b_970
+>>>8		belong&0x00ffffff	>100		subarchitecture=%ld
+>>4	belong&0x00ffffff	>18	64-bit architecture=%ld
 >12	belong		1		object
 >12	belong		1		object
 >12	belong		2		executable
 >12	belong		2		executable
 >12	belong		3		fixed virtual memory shared library
 >12	belong		3		fixed virtual memory shared library
@@ -122,7 +195,9 @@
 >12	belong		7		dynamic linker
 >12	belong		7		dynamic linker
 >12	belong		8		bundle
 >12	belong		8		bundle
 >12	belong		9		dynamically linked shared library stub
 >12	belong		9		dynamically linked shared library stub
->12	belong		>9
+>12	belong		10		dSYM companion file
+>12	belong		11		kext bundle
+>12	belong		>11
 >>12	belong		x		filetype=%ld
 >>12	belong		x		filetype=%ld
 
 
 #
 #

+ 3 - 3
magic/Magdir/mail.news

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: mail.news,v 1.21 2012/06/21 01:44:52 christos Exp $
+# $File: mail.news,v 1.22 2013/01/04 14:22:07 christos Exp $
 # mail.news:  file(1) magic for mail and news
 # mail.news:  file(1) magic for mail and news
 #
 #
 # Unfortunately, saved netnews also has From line added in some news software.
 # Unfortunately, saved netnews also has From line added in some news software.
@@ -14,9 +14,9 @@
 !:mime	message/rfc822
 !:mime	message/rfc822
 0	string/t		Pipe\ to 	mail piping text
 0	string/t		Pipe\ to 	mail piping text
 !:mime	message/rfc822
 !:mime	message/rfc822
-0	string/t		Delivered-To:	SMTP mail text
+0	string/tc		delivered-to:	SMTP mail text
 !:mime	message/rfc822
 !:mime	message/rfc822
-0	string/t		Return-Path:	SMTP mail text
+0	string/tc		return-path:	SMTP mail text
 !:mime	message/rfc822
 !:mime	message/rfc822
 0	string/t		Path:		news text
 0	string/t		Path:		news text
 !:mime	message/news
 !:mime	message/news

+ 2 - 2
magic/Magdir/maple

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: maple,v 1.6 2009/09/19 16:28:10 christos Exp $
+# $File: maple,v 1.7 2013/01/11 16:45:23 christos Exp $
 # maple:  file(1) magic for maple files
 # maple:  file(1) magic for maple files
 # "H. Nanosecond" <aldomel@ix.netcom.com>
 # "H. Nanosecond" <aldomel@ix.netcom.com>
 # Maple V release 4, a multi-purpose math program
 # Maple V release 4, a multi-purpose math program
@@ -33,7 +33,7 @@
 # that is {VERSION major_version miunor_version computer_type version_string}
 # that is {VERSION major_version miunor_version computer_type version_string}
 0	string	{VERSION\ 	Maple worksheet
 0	string	{VERSION\ 	Maple worksheet
 >9	string	>\0	version %.1s.
 >9	string	>\0	version %.1s.
->>>11	string	>\0	%.1s
+>>11	string	>\0	%.1s
 
 
 # .mps
 # .mps
 0	string	\0\0\001$	Maple something
 0	string	\0\0\001$	Maple something

+ 2 - 2
magic/Magdir/matroska

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: matroska,v 1.7 2012/08/26 10:06:15 christos Exp $
+# $File: matroska,v 1.8 2013/02/08 17:25:16 christos Exp $
 # matroska:  file(1) magic for Matroska files
 # matroska:  file(1) magic for Matroska files
 #
 #
 # See http://www.matroska.org/
 # See http://www.matroska.org/
@@ -9,7 +9,7 @@
 # EBML id:
 # EBML id:
 0		belong		0x1a45dfa3
 0		belong		0x1a45dfa3
 # DocType id:
 # DocType id:
->0		search/4096 	\x42\x82
+>4		search/4096 	\x42\x82
 # DocType contents:
 # DocType contents:
 >>&1		string		webm		WebM
 >>&1		string		webm		WebM
 !:mime  video/webm
 !:mime  video/webm

+ 3 - 65
magic/Magdir/mips

@@ -1,32 +1,8 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: mips,v 1.7 2011/05/03 01:44:17 christos Exp $
-# mips:  file(1) magic for Silicon Graphics (MIPS, IRIS, IRIX, etc.)
-#                         Dec Ultrix (MIPS)
-# all of SGI's *current* machines and OSes run in big-endian mode on the
-# MIPS machines, as far as I know.
-#
-# XXX - what is the blank "-" line?
-#
-# kbd file definitions
-0	string	kbd!map		kbd map file
->8	byte	>0		Ver %d:
->10	short	>0		with %d table(s)
-0	belong	0407		old SGI 68020 executable
-0	belong	0410		old SGI 68020 pure executable
-0	beshort	0x8765		disk quotas file
-0	beshort	0x0506		IRIS Showcase file
->2	byte	0x49		-
->3	byte	x		- version %ld
-0	beshort	0x0226		IRIS Showcase template
->2	byte	0x63		-
->3	byte	x		- version %ld
-0	belong	0x5343464d	IRIS Showcase file
->4	byte	x		- version %ld
-0	belong	0x5443464d	IRIS Showcase template
->4	byte	x		- version %ld
-0	belong	0xdeadbabe	IRIX Parallel Arena
->8	belong	>0		- version %ld
+# $File: mips,v 1.9 2013/01/12 03:09:51 christos Exp $
+# mips:  file(1) magic for MIPS ECOFF and Ucode, as used in SGI IRIX
+# and DEC Ultrix
 #
 #
 0	beshort	0x0160		MIPSEB ECOFF executable
 0	beshort	0x0160		MIPSEB ECOFF executable
 >20	beshort	0407		(impure)
 >20	beshort	0407		(impure)
@@ -142,41 +118,3 @@
 #
 #
 0	beshort	0x180		MIPSEB Ucode
 0	beshort	0x180		MIPSEB Ucode
 0	beshort	0x182		MIPSEL-BE Ucode
 0	beshort	0x182		MIPSEL-BE Ucode
-# 32bit core file
-0	belong	0xdeadadb0	IRIX core dump
->4	belong	1		of
->16	string	>\0		'%s'
-# 64bit core file
-0	belong	0xdeadad40	IRIX 64-bit core dump
->4	belong	1		of
->16	string	>\0		'%s'
-# N32bit core file
-0       belong	0xbabec0bb	IRIX N32 core dump
->4      belong	1               of
->16     string	>\0             '%s'
-# New style crash dump file
-0	string	\x43\x72\x73\x68\x44\x75\x6d\x70	IRIX vmcore dump of
->36	string	>\0					'%s'
-# Trusted IRIX info
-0	string	SGIAUDIT	SGI Audit file
->8	byte	x		- version %d
->9	byte	x		\b.%ld
-#
-0	string	WNGZWZSC	Wingz compiled script
-0	string	WNGZWZSS	Wingz spreadsheet
-0	string	WNGZWZHP	Wingz help file
-#
-0	string	#Inventor V	IRIS Inventor 1.0 file
-0	string	#Inventor V2	Open Inventor 2.0 file
-# GLF is OpenGL stream encoding
-0	string	glfHeadMagic();		GLF_TEXT
-4	belong	0x7d000000		GLF_BINARY_LSB_FIRST
-!:strength -30
-4	belong	0x0000007d		GLF_BINARY_MSB_FIRST
-!:strength -30
-# GLS is OpenGL stream encoding; GLS is the successor of GLF
-0	string	glsBeginGLS(		GLS_TEXT
-4	belong	0x10000000		GLS_BINARY_LSB_FIRST
-!:strength -30
-4	belong	0x00000010		GLS_BINARY_MSB_FIRST
-!:strength -30

+ 1 - 11
magic/Magdir/misctools

@@ -1,6 +1,6 @@
 
 
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
-# $File: misctools,v 1.12 2010/09/29 18:36:49 rrt Exp $
+# $File: misctools,v 1.13 2013/01/16 13:53:10 christos Exp $
 # misctools:  file(1) magic for miscellaneous UNIX tools.
 # misctools:  file(1) magic for miscellaneous UNIX tools.
 #
 #
 0	search/1	%%!!			X-Post-It-Note text
 0	search/1	%%!!			X-Post-It-Note text
@@ -9,16 +9,6 @@
 0	string/c	BEGIN:VCARD		vCard visiting card
 0	string/c	BEGIN:VCARD		vCard visiting card
 !:mime	text/x-vcard
 !:mime	text/x-vcard
 
 
-# From: Alex Beregszaszi <alex@fsn.hu>
-4	string	gtktalog		GNOME Catalogue (gtktalog)
->13	string	>\0			version %s
-
-# Summary: GStreamer binary registry
-# Extension: .bin
-# Submitted by: Josh Triplett <josh@joshtriplett.org>
-0	belong	0xc0def00d		GStreamer binary registry
->4	string	x			\b, version %s
-
 # Summary: Libtool library file
 # Summary: Libtool library file
 # Extension: .la
 # Extension: .la
 # Submitted by: Tomasz Trojanowski <tomek@uninet.com.pl>
 # Submitted by: Tomasz Trojanowski <tomek@uninet.com.pl>

+ 2 - 2
magic/Magdir/msdos

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: msdos,v 1.83 2012/11/13 14:55:44 christos Exp $
+# $File: msdos,v 1.84 2013/02/05 13:55:22 christos Exp $
 # msdos:  file(1) magic for MS-DOS files
 # msdos:  file(1) magic for MS-DOS files
 #
 #
 
 
@@ -313,7 +313,7 @@
 >5	ubyte		>0		
 >5	ubyte		>0		
 >>8	string		x		\b, name=%-.2s
 >>8	string		x		\b, name=%-.2s
 0	string	\xffKEYB\ \ \ \0\0\0\0	
 0	string	\xffKEYB\ \ \ \0\0\0\0	
->12	string	\0\0\0\0`\360		MS-DOS KEYBoard Layout file
+>12	string	\0\0\0\0`\004\360	MS-DOS KEYBoard Layout file
 
 
 # .COM formats (Daniel Quinlan, quinlan@yggdrasil.com)
 # .COM formats (Daniel Quinlan, quinlan@yggdrasil.com)
 # Uncommenting only the first two lines will cover about 2/3 of COM files,
 # Uncommenting only the first two lines will cover about 2/3 of COM files,

+ 6 - 4
magic/Magdir/msooxml

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: msooxml,v 1.1 2011/01/25 18:36:19 christos Exp $
+# $File: msooxml,v 1.2 2013/01/25 23:04:37 christos Exp $
 # msooxml:  file(1) magic for Microsoft Office XML
 # msooxml:  file(1) magic for Microsoft Office XML
 # From: Ralf Brown <ralf.brown@gmail.com>
 # From: Ralf Brown <ralf.brown@gmail.com>
 
 
@@ -23,11 +23,13 @@
 >>>&26          search/1000     PK\003\004
 >>>&26          search/1000     PK\003\004
 # and check the subdirectory name to determine which type of OOXML
 # and check the subdirectory name to determine which type of OOXML
 #   file we have
 #   file we have
+#   Correct the mimetype with the registered ones:
+#     http://technet.microsoft.com/en-us/library/cc179224.aspx
 >>>>&26         string          word/           Microsoft Word 2007+
 >>>>&26         string          word/           Microsoft Word 2007+
-!:mime application/msword
+!:mime application/vnd.openxmlformats-officedocument.wordprocessingml.document
 >>>>&26         string          ppt/            Microsoft PowerPoint 2007+
 >>>>&26         string          ppt/            Microsoft PowerPoint 2007+
-!:mime application/vnd.ms-powerpoint
+!:mime application/vnd.openxmlformats-officedocument.presentationml.presentation
 >>>>&26         string          xl/             Microsoft Excel 2007+
 >>>>&26         string          xl/             Microsoft Excel 2007+
-!:mime application/vnd.ms-excel
+!:mime application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
 >>>>&26         default         x               Microsoft OOXML
 >>>>&26         default         x               Microsoft OOXML
 !:strength +10
 !:strength +10

+ 2 - 2
magic/Magdir/natinst

@@ -1,10 +1,10 @@
 
 
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
-# $File: natinst,v 1.4 2009/09/19 16:28:11 christos Exp $
+# $File: natinst,v 1.5 2013/02/06 14:18:52 christos Exp $
 # natinst:  file(1) magic for National Instruments Code Files
 # natinst:  file(1) magic for National Instruments Code Files
 
 
 #
 #
-# From <egamez@fcfm.buap.mx> Enrique Gámez-Flores
+# From <egamez@fcfm.buap.mx> Enrique Gamez-Flores
 # version 1
 # version 1
 # Many formats still missing, we use, for the moment LabVIEW
 # Many formats still missing, we use, for the moment LabVIEW
 # We guess VXI format file. VISA, LabWindowsCVI, BridgeVIEW, etc, are missing
 # We guess VXI format file. VISA, LabWindowsCVI, BridgeVIEW, etc, are missing

+ 4 - 6
magic/Magdir/netbsd

@@ -1,16 +1,14 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: netbsd,v 1.19 2011/10/31 17:23:34 christos Exp $
+# $File: netbsd,v 1.20 2013/01/09 22:37:24 christos Exp $
 # netbsd:  file(1) magic for NetBSD objects
 # netbsd:  file(1) magic for NetBSD objects
 #
 #
 # All new-style magic numbers are in network byte order.
 # All new-style magic numbers are in network byte order.
+# The old-style magic numbers are indistinguishable from the same magic
+# numbers used in other systems, and are handled, for all those systems,
+# in aout.
 #
 #
 
 
-0	lelong			000000407	a.out NetBSD little-endian object file
->16	lelong			>0		not stripped
-0	belong			000000407	a.out NetBSD big-endian object file
->16	belong			>0		not stripped
-
 0	belong&0377777777	041400413	a.out NetBSD/i386 demand paged
 0	belong&0377777777	041400413	a.out NetBSD/i386 demand paged
 >0	byte			&0x80		
 >0	byte			&0x80		
 >>20	lelong			<4096		shared library
 >>20	lelong			<4096		shared library

+ 2 - 2
magic/Magdir/revision

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: revision,v 1.8 2010/11/25 15:00:12 christos Exp $
+# $File: revision,v 1.9 2013/02/06 14:18:52 christos Exp $
 # file(1) magic for revision control files
 # file(1) magic for revision control files
 # From Hendrik Scholz <hendrik@scholz.net>
 # From Hendrik Scholz <hendrik@scholz.net>
 0	string/t	/1\ :pserver:	cvs password text file
 0	string/t	/1\ :pserver:	cvs password text file
@@ -29,7 +29,7 @@
 >4	belong	=2		\b, version 2
 >4	belong	=2		\b, version 2
 
 
 # Type: Git index file
 # Type: Git index file
-# From: Frédéric Brière <fbriere@fbriere.net>
+# From: Frederic Briare <fbriere@fbriere.net>
 0	string	DIRC		Git index
 0	string	DIRC		Git index
 >4	belong	>0		\b, version %d
 >4	belong	>0		\b, version %d
 >>8	belong	>0		\b, %d entries
 >>8	belong	>0		\b, %d entries

+ 3 - 3
magic/Magdir/riff

@@ -1,12 +1,12 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: riff,v 1.22 2011/09/06 11:00:06 christos Exp $
+# $File: riff,v 1.23 2013/02/06 14:18:52 christos Exp $
 # riff:  file(1) magic for RIFF format
 # riff:  file(1) magic for RIFF format
 # See
 # See
 #
 #
 #	http://www.seanet.com/users/matts/riffmci/riffmci.htm
 #	http://www.seanet.com/users/matts/riffmci/riffmci.htm
 #
 #
-# AVI section extended by Patrik Rådman <patrik+file-magic@iki.fi>
+# AVI section extended by Patrik Radman <patrik+file-magic@iki.fi>
 #
 #
 0	string		RIFF		RIFF (little-endian) data
 0	string		RIFF		RIFF (little-endian) data
 # RIFF Palette format
 # RIFF Palette format
@@ -247,7 +247,7 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
 # MBWF/RF64
 # MBWF/RF64
-# see EBU TECH 3306 http://tech.ebu.ch/docs/tech/tech3306-2009.pdf
+# see EBU TECH 3306 http://tech.ebu.ch/docs/tech/tech3306-2009.pdf
 0	string	RF64\xff\xff\xff\xffWAVEds64		MBWF/RF64 audio
 0	string	RF64\xff\xff\xff\xffWAVEds64		MBWF/RF64 audio
 !:mime	audio/x-wav
 !:mime	audio/x-wav
 >40	search/256	fmt\x20		\b
 >40	search/256	fmt\x20		\b

+ 10 - 17
magic/Magdir/rpm

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: rpm,v 1.11 2011/06/14 12:47:41 christos Exp $
+# $File: rpm,v 1.12 2013/01/11 16:45:23 christos Exp $
 #
 #
 # RPM: file(1) magic for Red Hat Packages   Erik Troan (ewt@redhat.com)
 # RPM: file(1) magic for Red Hat Packages   Erik Troan (ewt@redhat.com)
 #
 #
@@ -31,22 +31,15 @@
 >>8	beshort		255		noarch
 >>8	beshort		255		noarch
 
 
 #delta RPM    Daniel Novotny (dnovotny@redhat.com)
 #delta RPM    Daniel Novotny (dnovotny@redhat.com)
-0	string	drpm	Delta RPM
+0	string		drpm		Delta RPM
 !:mime  application/x-rpm
 !:mime  application/x-rpm
 >12	string 	x	%s
 >12	string 	x	%s
-
->>>8	beshort		11		MIPSel
->>>8	beshort		12		ARM
->>>8	beshort		13		MiNT
->>>8	beshort		14		S/390
->>>8	beshort		15		S/390x
->>>8	beshort		16		PowerPC64
->>>8	beshort		17		SuperH
->>>8	beshort		18		Xtensa
+>>8	beshort		11		MIPSel
+>>8	beshort		12		ARM
+>>8	beshort		13		MiNT
+>>8	beshort		14		S/390
+>>8	beshort		15		S/390x
+>>8	beshort		16		PowerPC64
+>>8	beshort		17		SuperH
+>>8	beshort		18		Xtensa
 >>10	string		x		%s
 >>10	string		x		%s
-
-# Type:	Delta RPM
-# From:	Daniel Novotny (dnovotny@redhat.com)
-0	string		drpm		Delta RPM
-!:mime application/x-rpm
->12	string		x		%s

+ 69 - 2
magic/Magdir/sgi

@@ -1,7 +1,74 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: sgi,v 1.18 2010/11/25 15:00:12 christos Exp $
-# sgi:  file(1) magic for Silicon Graphics applications
+# $File: sgi,v 1.19 2013/01/12 03:09:51 christos Exp $
+# sgi:  file(1) magic for Silicon Graphics operating systems and applications
+#
+# Executable images are handled either in aout (for old-style a.out
+# files for 68K; they are indistinguishable from other big-endian 32-bit
+# a.out files) or in mips (for MIPS ECOFF and Ucode files)
+#
+
+# kbd file definitions
+0	string	kbd!map		kbd map file
+>8	byte	>0		Ver %d:
+>10	short	>0		with %d table(s)
+
+0	beshort	0x8765		disk quotas file
+
+0	beshort	0x0506		IRIS Showcase file
+>2	byte	0x49		-
+>3	byte	x		- version %ld
+0	beshort	0x0226		IRIS Showcase template
+>2	byte	0x63		-
+>3	byte	x		- version %ld
+0	belong	0x5343464d	IRIS Showcase file
+>4	byte	x		- version %ld
+0	belong	0x5443464d	IRIS Showcase template
+>4	byte	x		- version %ld
+0	belong	0xdeadbabe	IRIX Parallel Arena
+>8	belong	>0		- version %ld
+
+# core files
+#
+# 32bit core file
+0	belong	0xdeadadb0	IRIX core dump
+>4	belong	1		of
+>16	string	>\0		'%s'
+# 64bit core file
+0	belong	0xdeadad40	IRIX 64-bit core dump
+>4	belong	1		of
+>16	string	>\0		'%s'
+# N32bit core file
+0       belong	0xbabec0bb	IRIX N32 core dump
+>4      belong	1               of
+>16     string	>\0             '%s'
+# New style crash dump file
+0	string	\x43\x72\x73\x68\x44\x75\x6d\x70	IRIX vmcore dump of
+>36	string	>\0					'%s'
+
+# Trusted IRIX info
+0	string	SGIAUDIT	SGI Audit file
+>8	byte	x		- version %d
+>9	byte	x		\b.%ld
+#
+0	string	WNGZWZSC	Wingz compiled script
+0	string	WNGZWZSS	Wingz spreadsheet
+0	string	WNGZWZHP	Wingz help file
+#
+0	string	#Inventor V	IRIS Inventor 1.0 file
+0	string	#Inventor V2	Open Inventor 2.0 file
+# GLF is OpenGL stream encoding
+0	string	glfHeadMagic();		GLF_TEXT
+4	belong	0x7d000000		GLF_BINARY_LSB_FIRST
+!:strength -30
+4	belong	0x0000007d		GLF_BINARY_MSB_FIRST
+!:strength -30
+# GLS is OpenGL stream encoding; GLS is the successor of GLF
+0	string	glsBeginGLS(		GLS_TEXT
+4	belong	0x10000000		GLS_BINARY_LSB_FIRST
+!:strength -30
+4	belong	0x00000010		GLS_BINARY_MSB_FIRST
+!:strength -30
 
 
 #
 #
 #
 #

+ 60 - 104
magic/Magdir/sniffer

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: sniffer,v 1.18 2011/08/08 08:49:27 christos Exp $
+# $File: sniffer,v 1.19 2013/01/06 01:11:04 christos Exp $
 # sniffer:  file(1) magic for packet capture files
 # sniffer:  file(1) magic for packet capture files
 #
 #
 # From: guy@alum.mit.edu (Guy Harris)
 # From: guy@alum.mit.edu (Guy Harris)
@@ -17,6 +17,7 @@
 >6	leshort		2		(Token Ring)
 >6	leshort		2		(Token Ring)
 >6	leshort		3		(FDDI)
 >6	leshort		3		(FDDI)
 >6	leshort		4		(ATM)
 >6	leshort		4		(ATM)
+>6	leshort		>4		(type %d)
 
 
 #
 #
 # Microsoft Network Monitor 2.x capture files.
 # Microsoft Network Monitor 2.x capture files.
@@ -29,6 +30,12 @@
 >6	leshort		2		(Token Ring)
 >6	leshort		2		(Token Ring)
 >6	leshort		3		(FDDI)
 >6	leshort		3		(FDDI)
 >6	leshort		4		(ATM)
 >6	leshort		4		(ATM)
+>6	leshort		5		(IP-over-IEEE 1394)
+>6	leshort		6		(802.11)
+>6	leshort		7		(Raw IP)
+>6	leshort		8		(Raw IP)
+>6	leshort		9		(Raw IP)
+>6	leshort		>9		(type %d)
 
 
 #
 #
 # Network General Sniffer capture files.
 # Network General Sniffer capture files.
@@ -57,6 +64,7 @@
 # Sorry, make that "Network Associates Sniffer Basic, and Windows
 # Sorry, make that "Network Associates Sniffer Basic, and Windows
 # Sniffer Pro", capture files."
 # Sniffer Pro", capture files."
 # Sorry, make that "Network General Sniffer capture files."
 # Sorry, make that "Network General Sniffer capture files."
+# Sorry, make that "NetScout Sniffer capture files."
 #
 #
 0	string		XCP\0		NetXRay capture file
 0	string		XCP\0		NetXRay capture file
 >4	string		>\0		- version %s
 >4	string		>\0		- version %s
@@ -73,8 +81,7 @@
 # the main program that uses that format, but there are other programs
 # the main program that uses that format, but there are other programs
 # that use "libpcap", or that use the same capture file format.)
 # that use "libpcap", or that use the same capture file format.)
 #
 #
-0	ubelong		0xa1b2c3d4	tcpdump capture file (big-endian)
-!:mime	application/vnd.tcpdump.pcap
+0	name		pcap-be
 >4	beshort		x		- version %d
 >4	beshort		x		- version %d
 >6	beshort		x		\b.%d
 >6	beshort		x		\b.%d
 >20	belong		0		(No link-layer encapsulation
 >20	belong		0		(No link-layer encapsulation
@@ -116,8 +123,10 @@
 >20	belong		127		(802.11 with radiotap header
 >20	belong		127		(802.11 with radiotap header
 >20	belong		129		(Linux ARCNET
 >20	belong		129		(Linux ARCNET
 >20	belong		138		(Apple IP over IEEE 1394
 >20	belong		138		(Apple IP over IEEE 1394
+>20	belong		139		(MTP2 with pseudo-header
 >20	belong		140		(MTP2
 >20	belong		140		(MTP2
 >20	belong		141		(MTP3
 >20	belong		141		(MTP3
+>20	belong		142		(SCCP
 >20	belong		143		(DOCSIS
 >20	belong		143		(DOCSIS
 >20	belong		144		(IrDA
 >20	belong		144		(IrDA
 >20	belong		147		(Private use 0
 >20	belong		147		(Private use 0
@@ -137,72 +146,53 @@
 >20	belong		161		(Private use 14
 >20	belong		161		(Private use 14
 >20	belong		162		(Private use 15
 >20	belong		162		(Private use 15
 >20	belong		163		(802.11 with AVS header
 >20	belong		163		(802.11 with AVS header
+>20	belong		165		(BACnet MS/TP
+>20	belong		166		(PPPD
+>20	belong		169		(GPRS LLC
+>20	belong		177		(Linux LAPD
+>20	belong		187		(Bluetooth HCI H4
+>20	belong		189		(Linux USB
+>20	belong		192		(PPI
+>20	belong		195		(802.15.4
+>20	belong		196		(SITA
+>20	belong		197		(Endace ERF
+>20	belong		201		(Bluetooth HCI H4 with pseudo-header
+>20	belong		202		(AX.25 with KISS header
+>20	belong		203		(LAPD
+>20	belong		204		(PPP with direction pseudo-header
+>20	belong		205		(Cisco HDLC with direction pseudo-header
+>20	belong		206		(Frame Relay with direction pseudo-header
+>20	belong		209		(Linux IPMB
+>20	belong		215		(802.15.4 with non-ASK PHY header
+>20	belong		220		(Memory-mapped Linux USB
+>20	belong		224		(Fibre Channel FC-2
+>20	belong		225		(Fibre Channel FC-2 with frame delimiters
+>20	belong		226		(Solaris IPNET
+>20	belong		227		(SocketCAN
+>20	belong		228		(Raw IPv4
+>20	belong		229		(Raw IPv6
+>20	belong		230		(802.15.4 without FCS
+>20	belong		231		(D-Bus messages
+>20	belong		235		(DVB-CI
+>20	belong		236		(MUX27010
+>20	belong		237		(STANAG 5066 D_PDUs
+>20	belong		239		(Linux netlink NFLOG messages
+>20	belong		240		(Hilscher netAnalyzer
+>20	belong		241		(Hilscher netAnalyzer with delimiters
+>20	belong		242		(IP-over-Infiniband
+>20	belong		243		(MPEG-2 Transport Stream packets
+>20	belong		244		(ng4t ng40
+>20	belong		245		(NFC LLCP
+>20	belong		247		(Infiniband
+>20	belong		248		(SCTP
 >16	belong		x		\b, capture length %d)
 >16	belong		x		\b, capture length %d)
+
+0	ubelong		0xa1b2c3d4	tcpdump capture file (big-endian)
+!:mime	application/vnd.tcpdump.pcap
+>0	use	pcap-be
 0	ulelong		0xa1b2c3d4	tcpdump capture file (little-endian)
 0	ulelong		0xa1b2c3d4	tcpdump capture file (little-endian)
 !:mime	application/vnd.tcpdump.pcap
 !:mime	application/vnd.tcpdump.pcap
->4	leshort		x		- version %d
->6	leshort		x		\b.%d
->20	lelong		0		(No link-layer encapsulation
->20	lelong		1		(Ethernet
->20	lelong		2		(3Mb Ethernet
->20	lelong		3		(AX.25
->20	lelong		4		(ProNET
->20	lelong		5		(CHAOS
->20	lelong		6		(Token Ring
->20	lelong		7		(ARCNET
->20	lelong		8		(SLIP
->20	lelong		9		(PPP
->20	lelong		10		(FDDI
->20	lelong		11		(RFC 1483 ATM
->20	lelong		12		(raw IP
->20	lelong		13		(BSD/OS SLIP
->20	lelong		14		(BSD/OS PPP
->20	lelong		19		(Linux ATM Classical IP
->20	lelong		50		(PPP or Cisco HDLC
->20	lelong		51		(PPP-over-Ethernet
->20	lelong		99		(Symantec Enterprise Firewall
->20	lelong		100		(RFC 1483 ATM
->20	lelong		101		(raw IP
->20	lelong		102		(BSD/OS SLIP
->20	lelong		103		(BSD/OS PPP
->20	lelong		104		(BSD/OS Cisco HDLC
->20	lelong		105		(802.11
->20	lelong		106		(Linux Classical IP over ATM
->20	lelong		107		(Frame Relay
->20	lelong		108		(OpenBSD loopback
->20	lelong		109		(OpenBSD IPsec encrypted
->20	lelong		112		(Cisco HDLC
->20	lelong		113		(Linux "cooked"
->20	lelong		114		(LocalTalk
->20	lelong		117		(OpenBSD PFLOG
->20	lelong		119		(802.11 with Prism header
->20	lelong		122		(RFC 2625 IP over Fibre Channel
->20	lelong		123		(SunATM
->20	lelong		127		(802.11 with radiotap header
->20	lelong		129		(Linux ARCNET
->20	lelong		138		(Apple IP over IEEE 1394
->20	lelong		140		(MTP2
->20	lelong		141		(MTP3
->20	lelong		143		(DOCSIS
->20	lelong		144		(IrDA
->20	lelong		147		(Private use 0
->20	lelong		148		(Private use 1
->20	lelong		149		(Private use 2
->20	lelong		150		(Private use 3
->20	lelong		151		(Private use 4
->20	lelong		152		(Private use 5
->20	lelong		153		(Private use 6
->20	lelong		154		(Private use 7
->20	lelong		155		(Private use 8
->20	lelong		156		(Private use 9
->20	lelong		157		(Private use 10
->20	lelong		158		(Private use 11
->20	lelong		159		(Private use 12
->20	lelong		160		(Private use 13
->20	lelong		161		(Private use 14
->20	lelong		162		(Private use 15
->20	lelong		163		(802.11 with AVS header
->16	lelong		x		\b, capture length %d)
+>0	use	\^pcap-be
 
 
 #
 #
 # "libpcap"-with-Alexey-Kuznetsov's-patches capture files.
 # "libpcap"-with-Alexey-Kuznetsov's-patches capture files.
@@ -211,43 +201,9 @@
 # that use "libpcap", or that use the same capture file format.)
 # that use "libpcap", or that use the same capture file format.)
 #
 #
 0	ubelong		0xa1b2cd34	extended tcpdump capture file (big-endian)
 0	ubelong		0xa1b2cd34	extended tcpdump capture file (big-endian)
->4	beshort		x		- version %d
->6	beshort		x		\b.%d
->20	belong		0		(No link-layer encapsulation
->20	belong		1		(Ethernet
->20	belong		2		(3Mb Ethernet
->20	belong		3		(AX.25
->20	belong		4		(ProNET
->20	belong		5		(CHAOS
->20	belong		6		(Token Ring
->20	belong		7		(ARCNET
->20	belong		8		(SLIP
->20	belong		9		(PPP
->20	belong		10		(FDDI
->20	belong		11		(RFC 1483 ATM
->20	belong		12		(raw IP
->20	belong		13		(BSD/OS SLIP
->20	belong		14		(BSD/OS PPP
->16	belong		x		\b, capture length %d)
+>0	use	pcap-be
 0	ulelong		0xa1b2cd34	extended tcpdump capture file (little-endian)
 0	ulelong		0xa1b2cd34	extended tcpdump capture file (little-endian)
->4	leshort		x		- version %d
->6	leshort		x		\b.%d
->20	lelong		0		(No link-layer encapsulation
->20	lelong		1		(Ethernet
->20	lelong		2		(3Mb Ethernet
->20	lelong		3		(AX.25
->20	lelong		4		(ProNET
->20	lelong		5		(CHAOS
->20	lelong		6		(Token Ring
->20	lelong		7		(ARCNET
->20	lelong		8		(SLIP
->20	lelong		9		(PPP
->20	lelong		10		(FDDI
->20	lelong		11		(RFC 1483 ATM
->20	lelong		12		(raw IP
->20	lelong		13		(BSD/OS SLIP
->20	lelong		14		(BSD/OS PPP
->16	lelong		x		\b, capture length %d)
+>0	use	\^pcap-be
 
 
 #
 #
 # "pcap-ng" capture files.
 # "pcap-ng" capture files.
@@ -295,9 +251,9 @@
 >8	lelong		x		\b, %d stations found
 >8	lelong		x		\b, %d stations found
 
 
 #
 #
-# EtherPeek/AiroPeek "version 9" capture files.
+# *Peek tagged capture files.
 #
 #
-0	string		\177ver		EtherPeek/AiroPeek capture file
+0	string		\177ver		EtherPeek/AiroPeek/OmniPeek capture file
 
 
 #
 #
 # Visual Networks traffic capture files.
 # Visual Networks traffic capture files.

+ 9 - 2
magic/Magdir/sql

@@ -1,11 +1,11 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: sql,v 1.8 2012/12/09 17:11:08 christos Exp $
+# $File: sql,v 1.11 2013/02/21 15:27:01 christos Exp $
 # sql:  file(1) magic for SQL files
 # sql:  file(1) magic for SQL files
 #
 #
 # From: "Marty Leisner" <mleisner@eng.mc.xerox.com>
 # From: "Marty Leisner" <mleisner@eng.mc.xerox.com>
 # Recognize some MySQL files.
 # Recognize some MySQL files.
-# Elan Ruusamäe <glen@delfi.ee>, added MariaDB signatures
+# Elan Ruusamae <glen@delfi.ee>, added MariaDB signatures
 # from https://bazaar.launchpad.net/~maria-captains/maria/5.5/view/head:/support-files/magic
 # from https://bazaar.launchpad.net/~maria-captains/maria/5.5/view/head:/support-files/magic
 #
 #
 0	beshort			0xfe01		MySQL table definition file
 0	beshort			0xfe01		MySQL table definition file
@@ -56,3 +56,10 @@
 >60 string  _MTN               Monotone source repository
 >60 string  _MTN               Monotone source repository
 >60 belong  !0                 SQLite 3.x database, user version %u
 >60 belong  !0                 SQLite 3.x database, user version %u
 >60 belong  0                  SQLite 3.x database
 >60 belong  0                  SQLite 3.x database
+
+# Panasonic channel list database svl.bin or svl.db added by Joerg Jenderek
+# http://www.ullrich.es/job/service-menue/panasonic/panasonic-sendersortierung-sat-am-pc/
+# pceditor_V2003.jar
+0	string		PSDB\0			Panasonic channel list database
+>126	string		SQLite\ format\ 3	
+>>&-15	indirect	x			\b; contains 

+ 37 - 30
magic/Magdir/sun

@@ -1,12 +1,15 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: sun,v 1.22 2011/02/10 01:52:51 christos Exp $
+# $File: sun,v 1.25 2013/01/09 22:37:24 christos Exp $
 # sun:  file(1) magic for Sun machines
 # sun:  file(1) magic for Sun machines
 #
 #
 # Values for big-endian Sun (MC680x0, SPARC) binaries on pre-5.x
 # Values for big-endian Sun (MC680x0, SPARC) binaries on pre-5.x
-# releases.  (5.x uses ELF.)
+# releases.  (5.x uses ELF.)  Entries for executables without an
+# architecture type, used before the 68020-based Sun-3's came out,
+# are in aout, as they're indistinguishable from other big-endian
+# 32-bit a.out files.
 #
 #
-0	belong&077777777	0600413		sparc demand paged
+0	belong&077777777	0600413		a.out SunOS sparc demand paged
 >0	byte		&0x80
 >0	byte		&0x80
 >>20	belong		<4096		shared library
 >>20	belong		<4096		shared library
 >>20	belong		=4096		dynamically linked executable
 >>20	belong		=4096		dynamically linked executable
@@ -14,17 +17,17 @@
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0600410		sparc pure
+0	belong&077777777	0600410		a.out SunOS sparc pure
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0600407		sparc
+0	belong&077777777	0600407		a.out SunOS sparc
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0400413		mc68020 demand paged
+0	belong&077777777	0400413		a.out SunOS mc68020 demand paged
 >0	byte		&0x80
 >0	byte		&0x80
 >>20	belong		<4096		shared library
 >>20	belong		<4096		shared library
 >>20	belong		=4096		dynamically linked executable
 >>20	belong		=4096		dynamically linked executable
@@ -32,17 +35,17 @@
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0400410		mc68020 pure
+0	belong&077777777	0400410		a.out SunOS mc68020 pure
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0400407		mc68020
+0	belong&077777777	0400407		a.out SunOS mc68020
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0200413		mc68010 demand paged
+0	belong&077777777	0200413		a.out SunOS mc68010 demand paged
 >0	byte		&0x80
 >0	byte		&0x80
 >>20	belong		<4096		shared library
 >>20	belong		<4096		shared library
 >>20	belong		=4096		dynamically linked executable
 >>20	belong		=4096		dynamically linked executable
@@ -50,24 +53,16 @@
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0200410		mc68010 pure
+0	belong&077777777	0200410		a.out SunOS mc68010 pure
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-0	belong&077777777	0200407		mc68010
+0	belong&077777777	0200407		a.out SunOS mc68010
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
 
 
-# reworked these to avoid anything beginning with zero becoming "old sun-2"
-0	belong		0407		old sun-2 executable
->16	belong		>0		not stripped
-0	belong		0410		old sun-2 pure executable
->16	belong		>0		not stripped
-0	belong		0413		old sun-2 demand paged executable
->16	belong		>0		not stripped
-
 #
 #
 # Core files.  "SPARC 4.x BCP" means "core file from a SunOS 4.x SPARC
 # Core files.  "SPARC 4.x BCP" means "core file from a SunOS 4.x SPARC
 # binary executed in compatibility mode under SunOS 5.x".
 # binary executed in compatibility mode under SunOS 5.x".
@@ -96,7 +91,10 @@
 # Sun SunPC
 # Sun SunPC
 0	long		0xfa33c08e	SunPC 4.0 Hard Disk
 0	long		0xfa33c08e	SunPC 4.0 Hard Disk
 0	string		#SUNPC_CONFIG	SunPC 4.0 Properties Values
 0	string		#SUNPC_CONFIG	SunPC 4.0 Properties Values
-# Sun snoop (see RFC 1761, which describes the capture file format).
+# Sun snoop (see RFC 1761, which describes the capture file format,
+# RFC 3827, which describes some additional datalink types, and
+# http://www.iana.org/assignments/snoop-datalink-types/snoop-datalink-types.xml,
+# which is the IANA registry of Snoop datalink types)
 #
 #
 0	string		snoop		Snoop capture file
 0	string		snoop		Snoop capture file
 >8	belong		>0		- version %ld
 >8	belong		>0		- version %ld
@@ -109,14 +107,25 @@
 >12	belong		6		(Character synchronous)
 >12	belong		6		(Character synchronous)
 >12	belong		7		(IBM channel-to-channel adapter)
 >12	belong		7		(IBM channel-to-channel adapter)
 >12	belong		8		(FDDI)
 >12	belong		8		(FDDI)
->12	belong		9		(Unknown)
-
-# Microsoft ICM color profile
-36	string		acspMSFT	Microsoft ICM Color Profile
-!:mime	application/vnd.iccprofile
-# Sun KCMS
-36	string		acsp		Kodak Color Management System, ICC Profile
-!:mime	application/vnd.iccprofile
+>12	belong		9		(Other)
+>12	belong		10		(type %ld)
+>12	belong		11		(type %ld)
+>12	belong		12		(type %ld)
+>12	belong		13		(type %ld)
+>12	belong		14		(type %ld)
+>12	belong		15		(type %ld)
+>12	belong		16		(Fibre Channel)
+>12	belong		17		(ATM)
+>12	belong		18		(ATM Classical IP)
+>12	belong		19		(type %ld)
+>12	belong		20		(type %ld)
+>12	belong		21		(type %ld)
+>12	belong		22		(type %ld)
+>12	belong		23		(type %ld)
+>12	belong		24		(type %ld)
+>12	belong		25		(type %ld)
+>12	belong		26		(IP over Infiniband)
+>12	belong		>26		(type %ld)
 
 
 #---------------------------------------------------------------------------
 #---------------------------------------------------------------------------
 # The following entries have been tested by Duncan Laurie <duncan@sun.com> (a
 # The following entries have been tested by Duncan Laurie <duncan@sun.com> (a
@@ -130,5 +139,3 @@
 # New format for Sun/Cobalt boot ROMs is annoying, it stores the version code
 # New format for Sun/Cobalt boot ROMs is annoying, it stores the version code
 # at the very end where file(1) can't get it.
 # at the very end where file(1) can't get it.
 0       string CRfs     COBALT boot rom data (Flat boot rom or file system)
 0       string CRfs     COBALT boot rom data (Flat boot rom or file system)
-
-

+ 23 - 24
magic/Magdir/unknown

@@ -1,35 +1,34 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: unknown,v 1.7 2009/09/19 16:28:13 christos Exp $
+# $File: unknown,v 1.8 2013/01/09 22:37:24 christos Exp $
 # unknown:  file(1) magic for unknown machines
 # unknown:  file(1) magic for unknown machines
 #
 #
-# XXX - this probably should be pruned, as it'll match PDP-11 and
-# VAX image formats.
-#
-# 0x107 is 0407; 0x108 is 0410; both are PDP-11 (executable and pure,
-# respectively).
-#
-# 0x109 is 0411; that's PDP-11 split I&D, but the PDP-11 version doesn't
-# have the "version %ld", which may be a bogus COFFism (I don't think
-# there ever was COFF for the PDP-11).
+# 0x107 is 0407, 0x108 is 0410, and 0x109 is 0411; those are all PDP-11
+# (executable, pure, and split I&D, respectively), but the PDP-11 version
+# doesn't have the "version %ld", which may be a bogus COFFism (I don't
+# think there was ever COFF for the PDP-11).
 #
 #
 # 0x10B is 0413; that's VAX demand-paged, but this is a short, not a
 # 0x10B is 0413; that's VAX demand-paged, but this is a short, not a
-# long, as it would be on a VAX.
+# long, as it would be on a VAX.  In any case, that could collide with
+# VAX demand-paged files, as the magic number is little-endian on those
+# binaries, so the first 16 bits of the file would contain 0x10B.
+#
+# Therefore, those entries are commented out.
 #
 #
-# 0x10C is 0414 and 0x10E is 416; those *are* unknown.
+# 0x10C is 0414 and 0x10E is 0416; those *are* unknown.
 #
 #
-0	short		0x107		unknown machine executable
->8	short		>0		not stripped
->15	byte		>0		- version %ld
-0	short		0x108		unknown pure executable
->8	short		>0		not stripped
->15	byte		>0		- version %ld
-0	short		0x109		PDP-11 separate I&D
->8	short		>0		not stripped
->15	byte		>0		- version %ld
-0	short		0x10b		unknown pure executable
->8	short		>0		not stripped
->15	byte		>0		- version %ld
+#0	short		0x107		unknown machine executable
+#>8	short		>0		not stripped
+#>15	byte		>0		- version %ld
+#0	short		0x108		unknown pure executable
+#>8	short		>0		not stripped
+#>15	byte		>0		- version %ld
+#0	short		0x109		PDP-11 separate I&D
+#>8	short		>0		not stripped
+#>15	byte		>0		- version %ld
+#0	short		0x10b		unknown pure executable
+#>8	short		>0		not stripped
+#>15	byte		>0		- version %ld
 0	long		0x10c		unknown demand paged pure executable
 0	long		0x10c		unknown demand paged pure executable
 >16	long		>0		not stripped
 >16	long		>0		not stripped
 0	long		0x10e		unknown readable demand paged pure executable
 0	long		0x10e		unknown readable demand paged pure executable

+ 5 - 13
magic/Magdir/vax

@@ -1,30 +1,22 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: vax,v 1.7 2009/09/19 16:28:13 christos Exp $
+# $File: vax,v 1.8 2013/01/09 22:37:24 christos Exp $
 # vax:  file(1) magic for VAX executable/object and APL workspace
 # vax:  file(1) magic for VAX executable/object and APL workspace
 #
 #
 0	lelong		0101557		VAX single precision APL workspace
 0	lelong		0101557		VAX single precision APL workspace
 0	lelong		0101556		VAX double precision APL workspace
 0	lelong		0101556		VAX double precision APL workspace
 
 
 #
 #
-# VAX a.out (32V, BSD)
+# VAX a.out (BSD; others collide with 386 and other 32-bit little-endian
+# executables, and are handled in aout)
 #
 #
-0	lelong		0407		VAX executable
->16	lelong		>0		not stripped
-
-0	lelong		0410		VAX pure executable
->16	lelong		>0		not stripped
-
-0	lelong		0413		VAX demand paged pure executable
->16	lelong		>0		not stripped
-
-0	lelong		0420		VAX demand paged (first page unmapped) pure executable
+0	lelong		0420		a.out VAX demand paged (first page unmapped) pure executable
 >16	lelong		>0		not stripped
 >16	lelong		>0		not stripped
 
 
 #
 #
 # VAX COFF
 # VAX COFF
 #
 #
-# The `versions' should be un-commented if they work for you.
+# The `versions' were commented out, but have been un-commented out.
 # (Was the problem just one of endianness?)
 # (Was the problem just one of endianness?)
 #
 #
 0	leshort		0570		VAX COFF executable
 0	leshort		0570		VAX COFF executable

+ 2 - 2
magic/Magdir/wordprocessors

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: wordprocessors,v 1.16 2012/10/29 17:36:49 christos Exp $
+# $File: wordprocessors,v 1.17 2013/02/06 14:18:52 christos Exp $
 # wordprocessors:  file(1) magic fo word processors.
 # wordprocessors:  file(1) magic fo word processors.
 #
 #
 ####### PWP file format used on Smith Corona Personal Word Processors:
 ####### PWP file format used on Smith Corona Personal Word Processors:
@@ -110,7 +110,7 @@
 512	string		R\0o\0o\0t\0	Hangul (Korean) Word Processor File 2000
 512	string		R\0o\0o\0t\0	Hangul (Korean) Word Processor File 2000
 !:mime	application/x-hwp
 !:mime	application/x-hwp
 
 
-# CosmicBook, from Benoît Rouits
+# CosmicBook, from Benoit Rouits
 0       string  CSBK    Ted Neslson's CosmicBook hypertext file
 0       string  CSBK    Ted Neslson's CosmicBook hypertext file
 
 
 2       string  EYWR    AmigaWriter file
 2       string  EYWR    AmigaWriter file

+ 2 - 2
magic/Magdir/wsdl

@@ -1,11 +1,11 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: wsdl,v 1.1 2011/01/19 19:34:50 christos Exp $
+# $File: wsdl,v 1.3 2013/02/06 14:18:52 christos Exp $
 # wsdl: PHP WSDL Cache, http://www.php.net/manual/en/book.soap.php
 # wsdl: PHP WSDL Cache, http://www.php.net/manual/en/book.soap.php
 # Cache format extracted from source:
 # Cache format extracted from source:
 # http://svn.php.net/viewvc/php/php-src/trunk/ext/soap/php_sdl.c?revision=HEAD&view=markup
 # http://svn.php.net/viewvc/php/php-src/trunk/ext/soap/php_sdl.c?revision=HEAD&view=markup
 # Requires file >= 5.05, see http://mx.gw.com/pipermail/file/2010/000683.html
 # Requires file >= 5.05, see http://mx.gw.com/pipermail/file/2010/000683.html
-# By Elan Ruusamäe <glen@delfi.ee>, Patryk Zawadzki <patrys@pld-linux.org>, 2010-2011
+# By Elan Ruusamae <glen@delfi.ee>, Patryk Zawadzki <patrys@pld-linux.org>, 2010-2011
 0		string		wsdl		PHP WSDL cache,
 0		string		wsdl		PHP WSDL cache,
 >4		byte		x		version 0x%02x
 >4		byte		x		version 0x%02x
 >6		ledate		x		\b, created %s
 >6		ledate		x		\b, created %s

+ 4 - 1
magic/Magdir/xilinx

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: xilinx,v 1.4 2009/09/19 16:28:13 christos Exp $
+# $File: xilinx,v 1.5 2013/01/08 03:06:50 christos Exp $
 # This is Aaron's attempt at a MAGIC file for Xilinx .bit files.
 # This is Aaron's attempt at a MAGIC file for Xilinx .bit files.
 # Xilinx-Magic@RevRagnarok.com
 # Xilinx-Magic@RevRagnarok.com
 # Got the info from FPGA-FAQ 0026
 # Got the info from FPGA-FAQ 0026
@@ -33,3 +33,6 @@
 >>>>>>>>&1	byte	0x00
 >>>>>>>>&1	byte	0x00
 >>>>>>>>&2	string	e
 >>>>>>>>&2	string	e
 >>>>>>>>&4	belong	x	- data length 0x%lx
 >>>>>>>>&4	belong	x	- data length 0x%lx
+# Raw bitstream files
+0	long	0xffffffff	
+>&0	belong	0xaa995566	Xilinx RAW bitstream (.BIN)

+ 2 - 2
magic/Magdir/xwindows

@@ -1,6 +1,6 @@
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
-# $File: xwindows,v 1.7 2011/05/03 01:44:17 christos Exp $
+# $File: xwindows,v 1.8 2013/02/08 17:25:57 christos Exp $
 # xwindows:  file(1) magic for various X/Window system file formats.
 # xwindows:  file(1) magic for various X/Window system file formats.
 
 
 # Compiled X Keymap 
 # Compiled X Keymap 
@@ -10,7 +10,7 @@
 >0	byte	=0				obsolete
 >0	byte	=0				obsolete
 0	string	xkm				Compiled XKB Keymap: msb,
 0	string	xkm				Compiled XKB Keymap: msb,
 >3	byte	>0				version %d
 >3	byte	>0				version %d
->0	byte	=0				obsolete
+>3	byte	=0				obsolete
 
 
 # xfsdump archive
 # xfsdump archive
 0	string	xFSdump0			xfsdump archive
 0	string	xFSdump0			xfsdump archive

+ 5 - 2
magic/Makefile.am

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

+ 5 - 2
magic/Makefile.in

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

+ 7 - 0
src/Makefile.am

@@ -21,3 +21,10 @@ libmagic_la_LIBADD = $(LTLIBOBJS) $(MINGWLIBS)
 
 
 file_SOURCES = file.c
 file_SOURCES = file.c
 file_LDADD = libmagic.la
 file_LDADD = libmagic.la
+CLEANFILES = magic.h
+EXTRA_DIST = magic.h.in
+HDR= $(top_srcdir)/src/magic.h.in
+BUILT_SOURCES = magic.h
+
+magic.h:	${HDR}
+	sed -e "s/X.YY/$$(echo @VERSION@ | tr -d .)/" < ${HDR} > $@

+ 19 - 5
src/Makefile.in

@@ -39,7 +39,8 @@ bin_PROGRAMS = file$(EXEEXT)
 subdir = src
 subdir = src
 DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
 DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in asctime_r.c asprintf.c ctime_r.c \
 	$(srcdir)/Makefile.in asctime_r.c asprintf.c ctime_r.c \
-	getline.c getopt_long.c strlcat.c strlcpy.c vasprintf.c
+	getline.c getopt_long.c pread.c strlcat.c strlcpy.c \
+	vasprintf.c
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
 	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
 	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -259,7 +260,12 @@ libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
 libmagic_la_LIBADD = $(LTLIBOBJS) $(MINGWLIBS)
 libmagic_la_LIBADD = $(LTLIBOBJS) $(MINGWLIBS)
 file_SOURCES = file.c
 file_SOURCES = file.c
 file_LDADD = libmagic.la
 file_LDADD = libmagic.la
-all: all-am
+CLEANFILES = magic.h
+EXTRA_DIST = magic.h.in
+HDR = $(top_srcdir)/src/magic.h.in
+BUILT_SOURCES = magic.h
+all: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) all-am
 
 
 .SUFFIXES:
 .SUFFIXES:
 .SUFFIXES: .c .lo .o .obj
 .SUFFIXES: .c .lo .o .obj
@@ -384,6 +390,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/ctime_r.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/ctime_r.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getline.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getline.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt_long.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt_long.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/pread.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcat.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcat.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcpy.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strlcpy.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/vasprintf.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/vasprintf.Plo@am__quote@
@@ -540,7 +547,8 @@ distdir: $(DISTFILES)
 	  fi; \
 	  fi; \
 	done
 	done
 check-am: all-am
 check-am: all-am
-check: check-am
+check: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) check-am
 all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS)
 all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS)
 install-binPROGRAMS: install-libLTLIBRARIES
 install-binPROGRAMS: install-libLTLIBRARIES
 
 
@@ -548,7 +556,8 @@ installdirs:
 	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
 	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
 	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 	done
 	done
-install: install-am
+install: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-am
 install-exec: install-exec-am
 install-exec: install-exec-am
 install-data: install-data-am
 install-data: install-data-am
 uninstall: uninstall-am
 uninstall: uninstall-am
@@ -565,6 +574,7 @@ install-strip:
 mostlyclean-generic:
 mostlyclean-generic:
 
 
 clean-generic:
 clean-generic:
+	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
 
 
 distclean-generic:
 distclean-generic:
 	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
 	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
@@ -573,6 +583,7 @@ distclean-generic:
 maintainer-clean-generic:
 maintainer-clean-generic:
 	@echo "This command is intended for maintainers to use"
 	@echo "This command is intended for maintainers to use"
 	@echo "it deletes files that may require special tools to rebuild."
 	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
 clean: clean-am
 clean: clean-am
 
 
 clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
 clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
@@ -645,7 +656,7 @@ ps-am:
 uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
 uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
 	uninstall-libLTLIBRARIES
 	uninstall-libLTLIBRARIES
 
 
-.MAKE: install-am install-strip
+.MAKE: all check install install-am install-strip
 
 
 .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
 .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
 	clean-generic clean-libLTLIBRARIES clean-libtool ctags \
 	clean-generic clean-libLTLIBRARIES clean-libtool ctags \
@@ -664,6 +675,9 @@ uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
 	uninstall-includeHEADERS uninstall-libLTLIBRARIES
 	uninstall-includeHEADERS uninstall-libLTLIBRARIES
 
 
 
 
+magic.h:	${HDR}
+	sed -e "s/X.YY/$$(echo @VERSION@ | tr -d .)/" < ${HDR} > $@
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
 .NOEXPORT:

+ 282 - 136
src/apprentice.c

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

+ 2 - 3
src/cdf.c

@@ -35,7 +35,7 @@
 #include "file.h"
 #include "file.h"
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.51 2012/03/20 18:28:02 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.52 2013/02/18 15:40:59 christos Exp $")
 #endif
 #endif
 
 
 #include <assert.h>
 #include <assert.h>
@@ -296,10 +296,9 @@ cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len)
 	if (info->i_fd == -1)
 	if (info->i_fd == -1)
 		return -1;
 		return -1;
 
 
-	if (lseek(info->i_fd, off, SEEK_SET) == (off_t)-1)
 		return -1;
 		return -1;
 
 
-	if (read(info->i_fd, buf, len) != (ssize_t)len)
+	if (pread(info->i_fd, buf, len, off) != (ssize_t)len)
 		return -1;
 		return -1;
 
 
 	return (ssize_t)len;
 	return (ssize_t)len;

+ 2 - 1
src/elfclass.h

@@ -59,7 +59,8 @@
 		    (off_t)elf_getu(swap, elfhdr.e_shoff),
 		    (off_t)elf_getu(swap, elfhdr.e_shoff),
 		    elf_getu16(swap, elfhdr.e_shnum),
 		    elf_getu16(swap, elfhdr.e_shnum),
 		    (size_t)elf_getu16(swap, elfhdr.e_shentsize),
 		    (size_t)elf_getu16(swap, elfhdr.e_shentsize),
-		    fsize, &flags, elf_getu16(swap, elfhdr.e_machine)) == -1)
+		    fsize, &flags, elf_getu16(swap, elfhdr.e_machine),
+		    (int)elf_getu16(swap, elfhdr.e_shstrndx)) == -1)
 			return -1;
 			return -1;
 		break;
 		break;
 
 

+ 6 - 1
src/file.c

@@ -32,7 +32,7 @@
 #include "file.h"
 #include "file.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: file.c,v 1.148 2012/11/21 16:27:39 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.149 2013/01/07 18:20:19 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #include "magic.h"
 #include "magic.h"
@@ -276,6 +276,11 @@ main(int argc, char *argv[])
 	if (e)
 	if (e)
 		return e;
 		return e;
 
 
+	if (MAGIC_VERSION != magic_version())
+		(void)fprintf(stderr, "%s: compiled magic version [%d] "
+		    "does not match with shared library magic version [%d]\n",
+		    progname, MAGIC_VERSION, magic_version());
+
 	switch(action) {
 	switch(action) {
 	case FILE_CHECK:
 	case FILE_CHECK:
 	case FILE_COMPILE:
 	case FILE_COMPILE:

+ 14 - 13
src/file.h

@@ -27,7 +27,7 @@
  */
  */
 /*
 /*
  * file.h - definitions for file(1) program
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.140 2012/10/30 23:11:51 christos Exp $
+ * @(#)$File: file.h,v 1.144 2013/02/18 15:40:59 christos Exp $
  */
  */
 
 
 #ifndef __file_h__
 #ifndef __file_h__
@@ -128,12 +128,13 @@
 #endif
 #endif
 #define MAXMAGIS 8192		/* max entries in any one magic file
 #define MAXMAGIS 8192		/* max entries in any one magic file
 				   or directory */
 				   or directory */
-#define MAXDESC	64		/* max leng of text description/MIME type */
-#define MAXstring 64		/* max leng of "string" types */
+#define MAXDESC	64		/* max len of text description/MIME type */
+#define MAXMIME	80		/* max len of text MIME type */
+#define MAXstring 64		/* max len of "string" types */
 
 
 #define MAGICNO		0xF11E041C
 #define MAGICNO		0xF11E041C
-#define VERSIONNO	9
-#define FILE_MAGICSIZE	232
+#define VERSIONNO	10
+#define FILE_MAGICSIZE	248
 
 
 #define	FILE_LOAD	0
 #define	FILE_LOAD	0
 #define FILE_CHECK	1
 #define FILE_CHECK	1
@@ -300,9 +301,9 @@ struct magic {
 	union VALUETYPE value;	/* either number or string */
 	union VALUETYPE value;	/* either number or string */
 	/* Words 17-32 */
 	/* Words 17-32 */
 	char desc[MAXDESC];	/* description */
 	char desc[MAXDESC];	/* description */
-	/* Words 33-48 */
-	char mimetype[MAXDESC]; /* MIME type */
-	/* Words 49-50 */
+	/* Words 33-52 */
+	char mimetype[MAXMIME]; /* MIME type */
+	/* Words 53-54 */
 	char apple[8];
 	char apple[8];
 };
 };
 
 
@@ -346,10 +347,8 @@ struct magic {
 /* list of magic entries */
 /* list of magic entries */
 struct mlist {
 struct mlist {
 	struct magic *magic;		/* array of magic entries */
 	struct magic *magic;		/* array of magic entries */
-	uint32_t nmagic;			/* number of entries in array */
-	int mapped;  /* allocation type: 0 => apprentice_file
-		      *                  1 => apprentice_map + malloc
-		      *                  2 => apprentice_map + mmap */
+	uint32_t nmagic;		/* number of entries in array */
+	void *map;			/* internal resources used by entry */
 	struct mlist *next, *prev;
 	struct mlist *next, *prev;
 };
 };
 
 
@@ -444,7 +443,6 @@ protected int file_apprentice(struct magic_set *, const char *, int);
 protected int file_magicfind(struct magic_set *, const char *, struct mlist *);
 protected int file_magicfind(struct magic_set *, const char *, struct mlist *);
 protected uint64_t file_signextend(struct magic_set *, struct magic *,
 protected uint64_t file_signextend(struct magic_set *, struct magic *,
     uint64_t);
     uint64_t);
-protected void file_delmagic(struct magic *, int type, size_t entries);
 protected void file_badread(struct magic_set *);
 protected void file_badread(struct magic_set *);
 protected void file_badseek(struct magic_set *);
 protected void file_badseek(struct magic_set *);
 protected void file_oomem(struct magic_set *, size_t);
 protected void file_oomem(struct magic_set *, size_t);
@@ -486,6 +484,9 @@ extern char *sys_errlist[];
 #define strtoul(a, b, c)	strtol(a, b, c)
 #define strtoul(a, b, c)	strtol(a, b, c)
 #endif
 #endif
 
 
+#ifndef HAVE_PREAD
+ssize_t pread(int, void *, size_t, off_t);
+#endif
 #ifndef HAVE_VASPRINTF
 #ifndef HAVE_VASPRINTF
 int vasprintf(char **, const char *, va_list);
 int vasprintf(char **, const char *, va_list);
 #endif
 #endif

+ 40 - 32
src/fsmagic.c

@@ -32,7 +32,7 @@
 #include "file.h"
 #include "file.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.65 2012/08/26 09:56:26 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.66 2013/01/11 19:46:55 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #include "magic.h"
 #include "magic.h"
@@ -98,7 +98,7 @@ handle_mime(struct magic_set *ms, int mime, const char *str)
 protected int
 protected int
 file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 {
 {
-	int ret = 0, did = 0;
+	int ret, did = 0;
 	int mime = ms->flags & MAGIC_MIME;
 	int mime = ms->flags & MAGIC_MIME;
 #ifdef	S_IFLNK
 #ifdef	S_IFLNK
 	char buf[BUFSIZ+4];
 	char buf[BUFSIZ+4];
@@ -135,6 +135,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 		return -1;
 		return -1;
 	}
 	}
 
 
+	ret = 1;
 	if (!mime) {
 	if (!mime) {
 #ifdef S_ISUID
 #ifdef S_ISUID
 		if (sb->st_mode & S_ISUID)
 		if (sb->st_mode & S_ISUID)
@@ -160,7 +161,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 				return -1;
 				return -1;
 		} else if (file_printf(ms, "%sdirectory", COMMA) == -1)
 		} else if (file_printf(ms, "%sdirectory", COMMA) == -1)
 			return -1;
 			return -1;
-		return 1;
+		break;
 #ifdef S_IFCHR
 #ifdef S_IFCHR
 	case S_IFCHR:
 	case S_IFCHR:
 		/* 
 		/* 
@@ -191,7 +192,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 				return -1;
 				return -1;
 #endif
 #endif
 		}
 		}
-		return 1;
+		break;
 #endif
 #endif
 #ifdef S_IFBLK
 #ifdef S_IFBLK
 	case S_IFBLK:
 	case S_IFBLK:
@@ -223,7 +224,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 				return -1;
 				return -1;
 #endif
 #endif
 		}
 		}
-		return 1;
+		break;
 #endif
 #endif
 	/* TODO add code to handle V7 MUX and Blit MUX files */
 	/* TODO add code to handle V7 MUX and Blit MUX files */
 #ifdef	S_IFIFO
 #ifdef	S_IFIFO
@@ -235,7 +236,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 				return -1;
 				return -1;
 		} else if (file_printf(ms, "%sfifo (named pipe)", COMMA) == -1)
 		} else if (file_printf(ms, "%sfifo (named pipe)", COMMA) == -1)
 			return -1;
 			return -1;
-		return 1;
+		break;
 #endif
 #endif
 #ifdef	S_IFDOOR
 #ifdef	S_IFDOOR
 	case S_IFDOOR:
 	case S_IFDOOR:
@@ -244,7 +245,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 				return -1;
 				return -1;
 		} else if (file_printf(ms, "%sdoor", COMMA) == -1)
 		} else if (file_printf(ms, "%sdoor", COMMA) == -1)
 			return -1;
 			return -1;
-		return 1;
+		break;
 #endif
 #endif
 #ifdef	S_IFLNK
 #ifdef	S_IFLNK
 	case S_IFLNK:
 	case S_IFLNK:
@@ -261,7 +262,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 			    "%sunreadable symlink `%s' (%s)", COMMA, fn,
 			    "%sunreadable symlink `%s' (%s)", COMMA, fn,
 			    strerror(errno)) == -1)
 			    strerror(errno)) == -1)
 				return -1;
 				return -1;
-			return 1;
+			break;
 		}
 		}
 		buf[nch] = '\0';	/* readlink(2) does not do this */
 		buf[nch] = '\0';	/* readlink(2) does not do this */
 
 
@@ -290,7 +291,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 					    "%spath too long: `%s'", COMMA,
 					    "%spath too long: `%s'", COMMA,
 					    fn) == -1)
 					    fn) == -1)
 						return -1;
 						return -1;
-					return 1;
+					break;
 				}
 				}
 				/* take dir part */
 				/* take dir part */
 				(void)strlcpy(buf2, fn, sizeof buf2);
 				(void)strlcpy(buf2, fn, sizeof buf2);
@@ -309,7 +310,8 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 			ms->flags &= MAGIC_SYMLINK;
 			ms->flags &= MAGIC_SYMLINK;
 			p = magic_file(ms, buf);
 			p = magic_file(ms, buf);
 			ms->flags |= MAGIC_SYMLINK;
 			ms->flags |= MAGIC_SYMLINK;
-			return p != NULL ? 1 : -1;
+			if (p == NULL)
+				return -1;
 		} else { /* just print what it points to */
 		} else { /* just print what it points to */
 			if (mime) {
 			if (mime) {
 				if (handle_mime(ms, mime, "symlink") == -1)
 				if (handle_mime(ms, mime, "symlink") == -1)
@@ -318,7 +320,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 			    COMMA, buf) == -1)
 			    COMMA, buf) == -1)
 				return -1;
 				return -1;
 		}
 		}
-		return 1;
+		break;
 #endif
 #endif
 #ifdef	S_IFSOCK
 #ifdef	S_IFSOCK
 #ifndef __COHERENT__
 #ifndef __COHERENT__
@@ -328,36 +330,42 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 				return -1;
 				return -1;
 		} else if (file_printf(ms, "%ssocket", COMMA) == -1)
 		} else if (file_printf(ms, "%ssocket", COMMA) == -1)
 			return -1;
 			return -1;
-		return 1;
+		break;
 #endif
 #endif
 #endif
 #endif
 	case S_IFREG:
 	case S_IFREG:
+		/*
+		 * regular file, check next possibility
+		 *
+		 * If stat() tells us the file has zero length, report here that
+		 * the file is empty, so we can skip all the work of opening and
+		 * reading the file.
+		 * But if the -s option has been given, we skip this
+		 * optimization, since on some systems, stat() reports zero
+		 * size for raw disk partitions. (If the block special device
+		 * really has zero length, the fact that it is empty will be
+		 * detected and reported correctly when we read the file.)
+		 */
+		if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
+			if (mime) {
+				if (handle_mime(ms, mime, "x-empty") == -1)
+					return -1;
+			} else if (file_printf(ms, "%sempty", COMMA) == -1)
+				return -1;
+			break;
+		}
+		ret = 0;
 		break;
 		break;
+
 	default:
 	default:
 		file_error(ms, 0, "invalid mode 0%o", sb->st_mode);
 		file_error(ms, 0, "invalid mode 0%o", sb->st_mode);
 		return -1;
 		return -1;
 		/*NOTREACHED*/
 		/*NOTREACHED*/
 	}
 	}
 
 
-	/*
-	 * regular file, check next possibility
-	 *
-	 * If stat() tells us the file has zero length, report here that
-	 * the file is empty, so we can skip all the work of opening and 
-	 * reading the file.
-	 * But if the -s option has been given, we skip this optimization,
-	 * since on some systems, stat() reports zero size for raw disk
-	 * partitions.  (If the block special device really has zero length,
-	 * the fact that it is empty will be detected and reported correctly
-	 * when we read the file.)
-	 */
-	if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
-		if (mime) {
-			if (handle_mime(ms, mime, "x-empty") == -1)
-				return -1;
-		} else if (file_printf(ms, "%sempty", COMMA) == -1)
-			return -1;
-		return 1;
+	if (!mime && did) {
+	    if (file_printf(ms, " ") == -1)
+		    return -1;
 	}
 	}
-	return 0;
+	return ret;
 }
 }

+ 1 - 1
src/getline.c

@@ -37,7 +37,7 @@
 #include <errno.h>
 #include <errno.h>
 #include <string.h>
 #include <string.h>
 
 
-ssize_t
+public ssize_t
 getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp)
 getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp)
 {
 {
 	char *ptr, *eptr;
 	char *ptr, *eptr;

+ 7 - 1
src/magic.c

@@ -33,7 +33,7 @@
 #include "file.h"
 #include "file.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: magic.c,v 1.77 2012/10/31 17:20:06 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.78 2013/01/07 18:20:19 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #include "magic.h"
 #include "magic.h"
@@ -477,3 +477,9 @@ magic_setflags(struct magic_set *ms, int flags)
 	ms->flags = flags;
 	ms->flags = flags;
 	return 0;
 	return 0;
 }
 }
+
+public int
+magic_version(void)
+{
+	return MAGIC_VERSION;
+}

+ 3 - 0
src/magic.h

@@ -74,6 +74,8 @@
 #define	MAGIC_NO_CHECK_FORTRAN	0x000000 /* Don't check ascii/fortran */
 #define	MAGIC_NO_CHECK_FORTRAN	0x000000 /* Don't check ascii/fortran */
 #define	MAGIC_NO_CHECK_TROFF	0x000000 /* Don't check ascii/troff */
 #define	MAGIC_NO_CHECK_TROFF	0x000000 /* Don't check ascii/troff */
 
 
+#define MAGIC_VERSION		513	/* This implementation */
+
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
@@ -91,6 +93,7 @@ const char *magic_buffer(magic_t, const void *, size_t);
 const char *magic_error(magic_t);
 const char *magic_error(magic_t);
 int magic_setflags(magic_t, int);
 int magic_setflags(magic_t, int);
 
 
+int magic_version(void);
 int magic_load(magic_t, const char *);
 int magic_load(magic_t, const char *);
 int magic_compile(magic_t, const char *);
 int magic_compile(magic_t, const char *);
 int magic_check(magic_t, const char *);
 int magic_check(magic_t, const char *);

+ 107 - 0
src/magic.h.in

@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) Christos Zoulas 2003.
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice immediately at the beginning of the file, without modification,
+ *    this list of conditions, and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef _MAGIC_H
+#define _MAGIC_H
+
+#include <sys/types.h>
+
+#define	MAGIC_NONE		0x000000 /* No flags */
+#define	MAGIC_DEBUG		0x000001 /* Turn on debugging */
+#define	MAGIC_SYMLINK		0x000002 /* Follow symlinks */
+#define	MAGIC_COMPRESS		0x000004 /* Check inside compressed files */
+#define	MAGIC_DEVICES		0x000008 /* Look at the contents of devices */
+#define	MAGIC_MIME_TYPE		0x000010 /* Return the MIME type */
+#define	MAGIC_CONTINUE		0x000020 /* Return all matches */
+#define	MAGIC_CHECK		0x000040 /* Print warnings to stderr */
+#define	MAGIC_PRESERVE_ATIME	0x000080 /* Restore access time on exit */
+#define	MAGIC_RAW		0x000100 /* Don't translate unprintable chars */
+#define	MAGIC_ERROR		0x000200 /* Handle ENOENT etc as real errors */
+#define	MAGIC_MIME_ENCODING	0x000400 /* Return the MIME encoding */
+#define MAGIC_MIME		(MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
+#define	MAGIC_APPLE		0x000800 /* Return the Apple creator and type */
+
+#define	MAGIC_NO_CHECK_COMPRESS	0x001000 /* Don't check for compressed files */
+#define	MAGIC_NO_CHECK_TAR	0x002000 /* Don't check for tar files */
+#define	MAGIC_NO_CHECK_SOFT	0x004000 /* Don't check magic entries */
+#define	MAGIC_NO_CHECK_APPTYPE	0x008000 /* Don't check application type */
+#define	MAGIC_NO_CHECK_ELF	0x010000 /* Don't check for elf details */
+#define	MAGIC_NO_CHECK_TEXT	0x020000 /* Don't check for text files */
+#define	MAGIC_NO_CHECK_CDF	0x040000 /* Don't check for cdf files */
+#define	MAGIC_NO_CHECK_TOKENS	0x100000 /* Don't check tokens */
+#define MAGIC_NO_CHECK_ENCODING 0x200000 /* Don't check text encodings */
+
+/* No built-in tests; only consult the magic file */
+#define MAGIC_NO_CHECK_BUILTIN	( \
+	MAGIC_NO_CHECK_COMPRESS	| \
+	MAGIC_NO_CHECK_TAR	| \
+/*	MAGIC_NO_CHECK_SOFT	| */ \
+	MAGIC_NO_CHECK_APPTYPE	| \
+	MAGIC_NO_CHECK_ELF	| \
+	MAGIC_NO_CHECK_TEXT	| \
+	MAGIC_NO_CHECK_CDF	| \
+	MAGIC_NO_CHECK_TOKENS	| \
+	MAGIC_NO_CHECK_ENCODING	| \
+)
+
+/* Defined for backwards compatibility (renamed) */
+#define	MAGIC_NO_CHECK_ASCII	MAGIC_NO_CHECK_TEXT
+
+/* Defined for backwards compatibility; do nothing */
+#define	MAGIC_NO_CHECK_FORTRAN	0x000000 /* Don't check ascii/fortran */
+#define	MAGIC_NO_CHECK_TROFF	0x000000 /* Don't check ascii/troff */
+
+#define MAGIC_VERSION		X.YY	/* This implementation */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct magic_set *magic_t;
+magic_t magic_open(int);
+void magic_close(magic_t);
+
+const char *magic_getpath(const char *, int);
+const char *magic_file(magic_t, const char *);
+const char *magic_descriptor(magic_t, int);
+const char *magic_buffer(magic_t, const void *, size_t);
+
+const char *magic_error(magic_t);
+int magic_setflags(magic_t, int);
+
+int magic_version(void);
+int magic_load(magic_t, const char *);
+int magic_compile(magic_t, const char *);
+int magic_check(magic_t, const char *);
+int magic_list(magic_t, const char *);
+int magic_errno(magic_t);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _MAGIC_H */

+ 14 - 0
src/pread.c

@@ -0,0 +1,14 @@
+#include "file.h"
+#ifndef lint
+FILE_RCSID("@(#)$File: pread.c,v 1.1 2013/02/18 15:40:59 christos Exp $")
+#endif  /* lint */
+#include <fcntl.h>
+#include <unistd.h>
+
+ssize_t
+pread(int fd, void *buf, ssize_t len, off_t off) {
+	if (lseek(fd, off, SEEK_SET) == (off_t)-1)
+		return -1;
+
+	return read(fd, buf, len);
+}

+ 52 - 60
src/readelf.c

@@ -27,7 +27,7 @@
 #include "file.h"
 #include "file.h"
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.94 2012/12/13 13:48:31 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.96 2013/02/22 01:35:49 christos Exp $")
 #endif
 #endif
 
 
 #ifdef BUILTIN_ELF
 #ifdef BUILTIN_ELF
@@ -48,7 +48,7 @@ private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
 private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
 private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
     off_t, int *, int);
     off_t, int *, int);
 private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
 private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
-    off_t, int *, int);
+    off_t, int *, int, int);
 private size_t donote(struct magic_set *, void *, size_t, size_t, int,
 private size_t donote(struct magic_set *, void *, size_t, size_t, int,
     int, size_t, int *);
     int, size_t, int *);
 
 
@@ -133,19 +133,21 @@ getu64(int swap, uint64_t value)
 #define elf_getu32(swap, value) getu32(swap, value)
 #define elf_getu32(swap, value) getu32(swap, value)
 #ifdef USE_ARRAY_FOR_64BIT_TYPES
 #ifdef USE_ARRAY_FOR_64BIT_TYPES
 # define elf_getu64(swap, array) \
 # define elf_getu64(swap, array) \
-	((swap ? ((uint64_t)elf_getu32(swap, array[0])) << 32 : elf_getu32(swap, array[0])) + \
-	 (swap ? elf_getu32(swap, array[1]) : ((uint64_t)elf_getu32(swap, array[1]) << 32)))
+    ((swap ? ((uint64_t)elf_getu32(swap, array[0])) << 32 \
+     : elf_getu32(swap, array[0])) + \
+     (swap ? elf_getu32(swap, array[1]) : \
+     ((uint64_t)elf_getu32(swap, array[1]) << 32)))
 #else
 #else
 # define elf_getu64(swap, value) getu64(swap, value)
 # define elf_getu64(swap, value) getu64(swap, value)
 #endif
 #endif
 
 
 #define xsh_addr	(clazz == ELFCLASS32			\
 #define xsh_addr	(clazz == ELFCLASS32			\
-			 ? (void *) &sh32			\
-			 : (void *) &sh64)
+			 ? (void *)&sh32			\
+			 : (void *)&sh64)
 #define xsh_sizeof	(clazz == ELFCLASS32			\
 #define xsh_sizeof	(clazz == ELFCLASS32			\
-			 ? sizeof sh32				\
-			 : sizeof sh64)
-#define xsh_size	(clazz == ELFCLASS32			\
+			 ? sizeof(sh32)				\
+			 : sizeof(sh64))
+#define xsh_size	(size_t)(clazz == ELFCLASS32		\
 			 ? elf_getu32(swap, sh32.sh_size)	\
 			 ? elf_getu32(swap, sh32.sh_size)	\
 			 : elf_getu64(swap, sh64.sh_size))
 			 : elf_getu64(swap, sh64.sh_size))
 #define xsh_offset	(off_t)(clazz == ELFCLASS32		\
 #define xsh_offset	(off_t)(clazz == ELFCLASS32		\
@@ -154,12 +156,15 @@ getu64(int swap, uint64_t value)
 #define xsh_type	(clazz == ELFCLASS32			\
 #define xsh_type	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, sh32.sh_type)	\
 			 ? elf_getu32(swap, sh32.sh_type)	\
 			 : elf_getu32(swap, sh64.sh_type))
 			 : elf_getu32(swap, sh64.sh_type))
+#define xsh_name    	(clazz == ELFCLASS32			\
+			 ? elf_getu32(swap, sh32.sh_name)	\
+			 : elf_getu32(swap, sh64.sh_name))
 #define xph_addr	(clazz == ELFCLASS32			\
 #define xph_addr	(clazz == ELFCLASS32			\
 			 ? (void *) &ph32			\
 			 ? (void *) &ph32			\
 			 : (void *) &ph64)
 			 : (void *) &ph64)
 #define xph_sizeof	(clazz == ELFCLASS32			\
 #define xph_sizeof	(clazz == ELFCLASS32			\
-			 ? sizeof ph32				\
-			 : sizeof ph64)
+			 ? sizeof(ph32)				\
+			 : sizeof(ph64))
 #define xph_type	(clazz == ELFCLASS32			\
 #define xph_type	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, ph32.p_type)	\
 			 ? elf_getu32(swap, ph32.p_type)	\
 			 : elf_getu32(swap, ph64.p_type))
 			 : elf_getu32(swap, ph64.p_type))
@@ -175,8 +180,8 @@ getu64(int swap, uint64_t value)
 			 ? elf_getu32(swap, ph32.p_filesz)	\
 			 ? elf_getu32(swap, ph32.p_filesz)	\
 			 : elf_getu64(swap, ph64.p_filesz)))
 			 : elf_getu64(swap, ph64.p_filesz)))
 #define xnh_addr	(clazz == ELFCLASS32			\
 #define xnh_addr	(clazz == ELFCLASS32			\
-			 ? (void *) &nh32			\
-			 : (void *) &nh64)
+			 ? (void *)&nh32			\
+			 : (void *)&nh64)
 #define xph_memsz	(size_t)((clazz == ELFCLASS32		\
 #define xph_memsz	(size_t)((clazz == ELFCLASS32		\
 			 ? elf_getu32(swap, ph32.p_memsz)	\
 			 ? elf_getu32(swap, ph32.p_memsz)	\
 			 : elf_getu64(swap, ph64.p_memsz)))
 			 : elf_getu64(swap, ph64.p_memsz)))
@@ -196,8 +201,8 @@ getu64(int swap, uint64_t value)
 			 ? prpsoffsets32[i]			\
 			 ? prpsoffsets32[i]			\
 			 : prpsoffsets64[i])
 			 : prpsoffsets64[i])
 #define xcap_addr	(clazz == ELFCLASS32			\
 #define xcap_addr	(clazz == ELFCLASS32			\
-			 ? (void *) &cap32			\
-			 : (void *) &cap64)
+			 ? (void *)&cap32			\
+			 : (void *)&cap64)
 #define xcap_sizeof	(clazz == ELFCLASS32			\
 #define xcap_sizeof	(clazz == ELFCLASS32			\
 			 ? sizeof cap32				\
 			 ? sizeof cap32				\
 			 : sizeof cap64)
 			 : sizeof cap64)
@@ -299,7 +304,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 {
 {
 	Elf32_Phdr ph32;
 	Elf32_Phdr ph32;
 	Elf64_Phdr ph64;
 	Elf64_Phdr ph64;
-	size_t offset;
+	size_t offset, len;
 	unsigned char nbuf[BUFSIZ];
 	unsigned char nbuf[BUFSIZ];
 	ssize_t bufsize;
 	ssize_t bufsize;
 
 
@@ -313,11 +318,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	 * Loop through all the program headers.
 	 * Loop through all the program headers.
 	 */
 	 */
 	for ( ; num; num--) {
 	for ( ; num; num--) {
-		if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
-			file_badseek(ms);
-			return -1;
-		}
-		if (read(fd, xph_addr, xph_sizeof) == -1) {
+		if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
 			file_badread(ms);
 			file_badread(ms);
 			return -1;
 			return -1;
 		}
 		}
@@ -335,13 +336,8 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 		 * This is a PT_NOTE section; loop through all the notes
 		 * This is a PT_NOTE section; loop through all the notes
 		 * in the section.
 		 * in the section.
 		 */
 		 */
-		if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
-			file_badseek(ms);
-			return -1;
-		}
-		bufsize = read(fd, nbuf,
-		    ((xph_filesz < sizeof(nbuf)) ? xph_filesz : sizeof(nbuf)));
-		if (bufsize == -1) {
+		len = xph_filesz < sizeof(nbuf) ? xph_filesz : sizeof(nbuf);
+		if ((bufsize = pread(fd, nbuf, len, xph_offset)) == -1) {
 			file_badread(ms);
 			file_badread(ms);
 			return -1;
 			return -1;
 		}
 		}
@@ -851,15 +847,16 @@ static const cap_desc_t cap_desc_386[] = {
 
 
 private int
 private int
 doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
-    size_t size, off_t fsize, int *flags, int mach)
+    size_t size, off_t fsize, int *flags, int mach, int strtab)
 {
 {
 	Elf32_Shdr sh32;
 	Elf32_Shdr sh32;
 	Elf64_Shdr sh64;
 	Elf64_Shdr sh64;
 	int stripped = 1;
 	int stripped = 1;
 	void *nbuf;
 	void *nbuf;
-	off_t noff, coff;
+	off_t noff, coff, name_off;
 	uint64_t cap_hw1 = 0;	/* SunOS 5.x hardware capabilites */
 	uint64_t cap_hw1 = 0;	/* SunOS 5.x hardware capabilites */
 	uint64_t cap_sf1 = 0;	/* SunOS 5.x software capabilites */
 	uint64_t cap_sf1 = 0;	/* SunOS 5.x software capabilites */
+	char name[50];
 
 
 	if (size != xsh_sizeof) {
 	if (size != xsh_sizeof) {
 		if (file_printf(ms, ", corrupted section header size") == -1)
 		if (file_printf(ms, ", corrupted section header size") == -1)
@@ -867,12 +864,24 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 		return 0;
 		return 0;
 	}
 	}
 
 
+	/* Read offset of name section to be able to read section names later */
+	if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) {
+		file_badread(ms);
+		return -1;
+	}
+	name_off = xsh_offset;
+
 	for ( ; num; num--) {
 	for ( ; num; num--) {
-		if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
-			file_badseek(ms);
+		/* Read the name of this section. */
+		if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) {
+			file_badread(ms);
 			return -1;
 			return -1;
 		}
 		}
-		if (read(fd, xsh_addr, xsh_sizeof) == -1) {
+		name[sizeof(name) - 1] = '\0';
+		if (strcmp(name, ".debug_info") == 0)
+			stripped = 0;
+
+		if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {
 			file_badread(ms);
 			file_badread(ms);
 			return -1;
 			return -1;
 		}
 		}
@@ -897,31 +906,23 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 		/* Things we can determine when we seek */
 		/* Things we can determine when we seek */
 		switch (xsh_type) {
 		switch (xsh_type) {
 		case SHT_NOTE:
 		case SHT_NOTE:
-			if ((nbuf = malloc((size_t)xsh_size)) == NULL) {
+			if ((nbuf = malloc(xsh_size)) == NULL) {
 				file_error(ms, errno, "Cannot allocate memory"
 				file_error(ms, errno, "Cannot allocate memory"
 				    " for note");
 				    " for note");
 				return -1;
 				return -1;
 			}
 			}
-			if ((noff = lseek(fd, (off_t)xsh_offset, SEEK_SET)) ==
-			    (off_t)-1) {
+			if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {
 				file_badread(ms);
 				file_badread(ms);
 				free(nbuf);
 				free(nbuf);
 				return -1;
 				return -1;
 			}
 			}
-			if (read(fd, nbuf, (size_t)xsh_size) !=
-			    (ssize_t)xsh_size) {
-				free(nbuf);
-				file_badread(ms);
-				return -1;
-			}
 
 
 			noff = 0;
 			noff = 0;
 			for (;;) {
 			for (;;) {
 				if (noff >= (off_t)xsh_size)
 				if (noff >= (off_t)xsh_size)
 					break;
 					break;
 				noff = donote(ms, nbuf, (size_t)noff,
 				noff = donote(ms, nbuf, (size_t)noff,
-				    (size_t)xsh_size, clazz, swap, 4,
-				    flags);
+				    xsh_size, clazz, swap, 4, flags);
 				if (noff == 0)
 				if (noff == 0)
 					break;
 					break;
 			}
 			}
@@ -939,8 +940,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 				goto skip;
 				goto skip;
 			}
 			}
 
 
-			if (lseek(fd, (off_t)xsh_offset, SEEK_SET) ==
-			    (off_t)-1) {
+			if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) {
 				file_badseek(ms);
 				file_badseek(ms);
 				return -1;
 				return -1;
 			}
 			}
@@ -1063,7 +1063,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	const char *shared_libraries = "";
 	const char *shared_libraries = "";
 	unsigned char nbuf[BUFSIZ];
 	unsigned char nbuf[BUFSIZ];
 	ssize_t bufsize;
 	ssize_t bufsize;
-	size_t offset, align;
+	size_t offset, align, len;
 	
 	
 	if (size != xph_sizeof) {
 	if (size != xph_sizeof) {
 		if (file_printf(ms, ", corrupted program header size") == -1)
 		if (file_printf(ms, ", corrupted program header size") == -1)
@@ -1072,13 +1072,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	}
 	}
 
 
   	for ( ; num; num--) {
   	for ( ; num; num--) {
-		if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
-			file_badseek(ms);
-			return -1;
-		}
-
-  		if (read(fd, xph_addr, xph_sizeof) == -1) {
-  			file_badread(ms);
+		if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
+			file_badread(ms);
 			return -1;
 			return -1;
 		}
 		}
 
 
@@ -1116,12 +1111,9 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 			 * This is a PT_NOTE section; loop through all the notes
 			 * This is a PT_NOTE section; loop through all the notes
 			 * in the section.
 			 * in the section.
 			 */
 			 */
-			if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
-				file_badseek(ms);
-				return -1;
-			}
-			bufsize = read(fd, nbuf, ((xph_filesz < sizeof(nbuf)) ?
-			    xph_filesz : sizeof(nbuf)));
+			len = xph_filesz < sizeof(nbuf) ? xph_filesz
+			    : sizeof(nbuf);
+			bufsize = pread(fd, nbuf, len, xph_offset);
 			if (bufsize == -1) {
 			if (bufsize == -1) {
 				file_badread(ms);
 				file_badread(ms);
 				return -1;
 				return -1;

+ 29 - 20
src/softmagic.c

@@ -32,7 +32,7 @@
 #include "file.h"
 #include "file.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.156 2013/01/03 23:11:38 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.159 2013/02/17 22:28:27 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #include "magic.h"
 #include "magic.h"
@@ -43,9 +43,9 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.156 2013/01/03 23:11:38 christos Exp $")
 
 
 
 
 private int match(struct magic_set *, struct magic *, uint32_t,
 private int match(struct magic_set *, struct magic *, uint32_t,
-    const unsigned char *, size_t, size_t, int, int, int);
+    const unsigned char *, size_t, size_t, int, int, int, int *);
 private int mget(struct magic_set *, const unsigned char *,
 private int mget(struct magic_set *, const unsigned char *,
-    struct magic *, size_t, size_t, unsigned int, int, int, int);
+    struct magic *, size_t, size_t, unsigned int, int, int, int, int *);
 private int magiccheck(struct magic_set *, struct magic *);
 private int magiccheck(struct magic_set *, struct magic *);
 private int32_t mprint(struct magic_set *, struct magic *);
 private int32_t mprint(struct magic_set *, struct magic *);
 private int32_t moffset(struct magic_set *, struct magic *);
 private int32_t moffset(struct magic_set *, struct magic *);
@@ -73,7 +73,7 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
 	int rv;
 	int rv;
 	for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
 	for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
 		if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
 		if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
-		    text, 0)) != 0)
+		    text, 0, NULL)) != 0)
 			return rv;
 			return rv;
 
 
 	return 0;
 	return 0;
@@ -109,16 +109,19 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
 private int
 private int
 match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
     const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,
     const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,
-    int flip)
+    int flip, int *returnval)
 {
 {
 	uint32_t magindex = 0;
 	uint32_t magindex = 0;
 	unsigned int cont_level = 0;
 	unsigned int cont_level = 0;
 	int need_separator = 0;
 	int need_separator = 0;
-	int returnval = 0, e; /* if a match is found it is set to 1*/
+	int returnvalv = 0, e; /* if a match is found it is set to 1*/
 	int firstline = 1; /* a flag to print X\n  X\n- X */
 	int firstline = 1; /* a flag to print X\n  X\n- X */
 	int printed_something = 0;
 	int printed_something = 0;
 	int print = (ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0;
 	int print = (ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0;
 
 
+	if (returnval == NULL)
+		returnval = &returnvalv;
+
 	if (file_check_mem(ms, cont_level) == -1)
 	if (file_check_mem(ms, cont_level) == -1)
 		return -1;
 		return -1;
 
 
@@ -144,7 +147,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 
 
 		/* if main entry matches, print it... */
 		/* if main entry matches, print it... */
 		switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
 		switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
-		    flip)) {
+		    flip, returnval)) {
 		case -1:
 		case -1:
 			return -1;
 			return -1;
 		case 0:
 		case 0:
@@ -152,7 +155,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 			break;
 			break;
 		default:
 		default:
 			if (m->type == FILE_INDIRECT)
 			if (m->type == FILE_INDIRECT)
-				returnval = 1;
+				*returnval = 1;
 
 
 			switch (magiccheck(ms, m)) {
 			switch (magiccheck(ms, m)) {
 			case -1:
 			case -1:
@@ -178,6 +181,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 		}
 		}
 
 
 		if ((e = handle_annotation(ms, m)) != 0) {
 		if ((e = handle_annotation(ms, m)) != 0) {
+			*returnval = 1;
 			return e;
 			return e;
 		}
 		}
 		/*
 		/*
@@ -229,7 +233,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 			}
 			}
 #endif
 #endif
 			switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
 			switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
-			    text, flip)) {
+			    text, flip, returnval)) {
 			case -1:
 			case -1:
 				return -1;
 				return -1;
 			case 0:
 			case 0:
@@ -239,7 +243,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 				break;
 				break;
 			default:
 			default:
 				if (m->type == FILE_INDIRECT)
 				if (m->type == FILE_INDIRECT)
-					returnval = 1;
+					*returnval = 1;
 				flush = 0;
 				flush = 0;
 				break;
 				break;
 			}
 			}
@@ -262,8 +266,10 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 					ms->c.li[cont_level].got_match = 0;
 					ms->c.li[cont_level].got_match = 0;
 					break;
 					break;
 				}
 				}
-				if ((e = handle_annotation(ms, m)) != 0)
+				if ((e = handle_annotation(ms, m)) != 0) {
+					*returnval = 1;
 					return e;
 					return e;
+				}
 				/*
 				/*
 				 * If we are going to print something,
 				 * If we are going to print something,
 				 * make sure that we have a separator first.
 				 * make sure that we have a separator first.
@@ -312,13 +318,13 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 		if (printed_something) {
 		if (printed_something) {
 			firstline = 0;
 			firstline = 0;
 			if (print)
 			if (print)
-				returnval = 1;
+				*returnval = 1;
 		}
 		}
 		if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
 		if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
-			return returnval; /* don't keep searching */
+			return *returnval; /* don't keep searching */
 		}
 		}
 	}
 	}
-	return returnval;  /* This is hit if -k is set or there is no match */
+	return *returnval;  /* This is hit if -k is set or there is no match */
 }
 }
 
 
 private int
 private int
@@ -991,7 +997,7 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
 private void
 private void
 mdebug(uint32_t offset, const char *str, size_t len)
 mdebug(uint32_t offset, const char *str, size_t len)
 {
 {
-	(void) fprintf(stderr, "mget @%d: ", offset);
+	(void) fprintf(stderr, "mget/%zu @%d: ", len, offset);
 	file_showstr(stderr, str, len);
 	file_showstr(stderr, str, len);
 	(void) fputc('\n', stderr);
 	(void) fputc('\n', stderr);
 	(void) fputc('\n', stderr);
 	(void) fputc('\n', stderr);
@@ -1058,8 +1064,8 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
 			if (type == FILE_BESTRING16)
 			if (type == FILE_BESTRING16)
 				src++;
 				src++;
 
 
-			/* check for pointer overflow */
-			if (src < s) {
+			/* check that offset is within range */
+			if (offset >= nbytes) {
 				file_magerror(ms, "invalid offset %u in mcopy()",
 				file_magerror(ms, "invalid offset %u in mcopy()",
 				    offset);
 				    offset);
 				return -1;
 				return -1;
@@ -1110,7 +1116,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
 private int
 private int
 mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
 mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
     size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,
     size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,
-    int flip)
+    int flip, int *returnval)
 {
 {
 	uint32_t offset = ms->offset;
 	uint32_t offset = ms->offset;
 	uint32_t count = m->str_range;
 	uint32_t count = m->str_range;
@@ -1120,10 +1126,13 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
 	struct mlist ml;
 	struct mlist ml;
 
 
 	if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),
 	if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),
-	    (uint32_t)(nbytes - o), count) == -1)
+	    (uint32_t)nbytes, count) == -1)
 		return -1;
 		return -1;
 
 
 	if ((ms->flags & MAGIC_DEBUG) != 0) {
 	if ((ms->flags & MAGIC_DEBUG) != 0) {
+		fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%zu, "
+		    "nbytes=%zu, count=%u)\n", m->type, m->flag, offset, o,
+		    nbytes, count);
 		mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
 		mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
 #ifndef COMPILE_ONLY
 #ifndef COMPILE_ONLY
 		file_mdump(m);
 		file_mdump(m);
@@ -1713,7 +1722,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
 			return -1;
 			return -1;
 		}
 		}
 		return match(ms, ml.magic, ml.nmagic, s, nbytes, offset,
 		return match(ms, ml.magic, ml.nmagic, s, nbytes, offset,
-		    mode, text, flip);
+		    mode, text, flip, returnval);
 
 
 	case FILE_NAME:
 	case FILE_NAME:
 		if (file_printf(ms, "%s", m->desc) == -1)
 		if (file_printf(ms, "%s", m->desc) == -1)