Browse Source

Import upstream version 5.43

Christos Zoulas 1 year ago
parent
commit
589d555c46
100 changed files with 12215 additions and 6062 deletions
  1. 66 0
      ChangeLog
  2. 2 1
      Makefile.am
  3. 34 25
      Makefile.in
  4. 155 0
      README.md
  5. 2 1
      acinclude.m4
  6. 47 32
      aclocal.m4
  7. 3 3
      compile
  8. 833 591
      config.guess
  9. 94 23
      config.h.in
  10. 379 290
      config.sub
  11. 3934 3107
      configure
  12. 5 5
      configure.ac
  13. 1 1
      depcomp
  14. 6 4
      doc/Makefile.in
  15. 6 2
      doc/magic.man
  16. 4 3
      magic/Magdir/animation
  17. 303 43
      magic/Magdir/archive
  18. 38 0
      magic/Magdir/aria
  19. 2 2
      magic/Magdir/asf
  20. 157 19
      magic/Magdir/audio
  21. 7 0
      magic/Magdir/burp
  22. 2 2
      magic/Magdir/bytecode
  23. 139 2
      magic/Magdir/c64
  24. 3 1
      magic/Magdir/cad
  25. 7 1
      magic/Magdir/cafebabe
  26. 14 0
      magic/Magdir/ccf
  27. 29 3
      magic/Magdir/commands
  28. 2 1
      magic/Magdir/compress
  29. 71 32
      magic/Magdir/console
  30. 1 1
      magic/Magdir/ctf
  31. 16 6
      magic/Magdir/database
  32. 14 14
      magic/Magdir/dataone
  33. 7 7
      magic/Magdir/der
  34. 25 0
      magic/Magdir/dsf
  35. 187 4
      magic/Magdir/filesystems
  36. 61 7
      magic/Magdir/fonts
  37. 21 1
      magic/Magdir/freebsd
  38. 13 21
      magic/Magdir/games
  39. 80 0
      magic/Magdir/gentoo
  40. 5 5
      magic/Magdir/geo
  41. 2 1
      magic/Magdir/iff
  42. 1975 1099
      magic/Magdir/images
  43. 194 10
      magic/Magdir/intel
  44. 106 7
      magic/Magdir/javascript
  45. 114 5
      magic/Magdir/jpeg
  46. 24 13
      magic/Magdir/linux
  47. 115 2
      magic/Magdir/luks
  48. 48 2
      magic/Magdir/mail.news
  49. 7 22
      magic/Magdir/make
  50. 24 9
      magic/Magdir/mathematica
  51. 15 1
      magic/Magdir/mcrypt
  52. 222 37
      magic/Magdir/msdos
  53. 10 2
      magic/Magdir/msooxml
  54. 157 4
      magic/Magdir/msvc
  55. 202 0
      magic/Magdir/nifty
  56. 109 4
      magic/Magdir/ole2compounddocs
  57. 16 0
      magic/Magdir/oric
  58. 3 1
      magic/Magdir/os2
  59. 2 1
      magic/Magdir/palm
  60. 26 1
      magic/Magdir/pascal
  61. 116 0
      magic/Magdir/pci_ids
  62. 44 31
      magic/Magdir/python
  63. 86 1
      magic/Magdir/riff
  64. 45 0
      magic/Magdir/ringdove
  65. 24 1
      magic/Magdir/rpi
  66. 27 22
      magic/Magdir/sgml
  67. 54 2
      magic/Magdir/sniffer
  68. 7 1
      magic/Magdir/sql
  69. 2 2
      magic/Magdir/statistics
  70. 38 0
      magic/Magdir/subtitle
  71. 128 19
      magic/Magdir/sysex
  72. 10 8
      magic/Magdir/uuencode
  73. 7 7
      magic/Magdir/virtual
  74. 3 1
      magic/Magdir/webassembly
  75. 323 33
      magic/Magdir/windows
  76. 235 1
      magic/Magdir/wordprocessors
  77. 8 1
      magic/Magdir/xo65
  78. 3 3
      magic/Magdir/xwindows
  79. 22 8
      magic/Magdir/zip
  80. 11 1
      magic/Makefile.am
  81. 17 5
      magic/Makefile.in
  82. 1 1
      missing
  83. 7 5
      python/Makefile.in
  84. 29 7
      python/magic.py
  85. 4 4
      python/tests.py
  86. 9 8
      src/Makefile.in
  87. 306 157
      src/apprentice.c
  88. 3 3
      src/ascmagic.c
  89. 17 1
      src/cdf.c
  90. 6 1
      src/cdf_time.c
  91. 95 33
      src/compress.c
  92. 19 7
      src/der.c
  93. 42 18
      src/encoding.c
  94. 144 61
      src/file.c
  95. 90 81
      src/file.h
  96. 1 1
      src/file_opts.h
  97. 3 0
      src/fmtcheck.c
  98. 2 2
      src/fsmagic.c
  99. 81 44
      src/funcs.c
  100. 0 0
      src/is_csv.c

+ 66 - 0
ChangeLog

@@ -1,3 +1,69 @@
+2022-09-13  14:55  Christos Zoulas <christos@zoulas.com>
+
+	* release 5.43
+
+2022-09-10   9:17  Christos Zoulas <christos@zoulas.com>
+
+	* Add octal indirect magic (Michal Gorny)
+
+2022-08-17  11:43  Christos Zoulas <christos@zoulas.com>
+
+	* PR/374: avoid infinite loop in non-wide code (piru)
+	* PR/373: Obey MAGIC_CONTINUE with multiple magic files (vismarli)
+
+2022-07-26  11:10  Christos Zoulas <christos@zoulas.com>
+
+	* Fix bug with large flist (Florian Weimer)
+
+2022-07-07  13:21  Christos Zoulas <christos@zoulas.com>
+
+        * PR/364: Detect non-nul-terminated core filenames from QEMU
+	  (mam-ableton)
+
+2022-07-04  15:45  Christos Zoulas <christos@zoulas.com>
+
+	* PR/359: Add support for http://ndjson.org/ (darose)
+	* PR/362: Fix wide printing (ro-ee)
+	* PR/358: Fix width for -f - (jpalus)
+	* PR/356: Fix JSON constant parsing (davewhite)
+
+2022-06-10   9:40  Christos Zoulas <christos@zoulas.com>
+
+	* release 5.42
+
+2022-05-31  14:50   Christos Zoulas <christos@zoulas.com>
+
+	* PR/348: add missing cases to prevent file from aborting on
+	  random magic files.
+
+2022-05-27  21:05   Christos Zoulas <christos@zoulas.com>
+
+	* PR/351: octalify filenames when not raw before printing.
+
+2022-04-18  17:51   Christos Zoulas <christos@zoulas.com>
+
+	* fix regex cacheing bug (Dirk Mueller)
+	* merge file_regcomp and file_regerror() to simplify the code
+	  and reduce memory requirements for storing regexes (Dirk Mueller)
+
+2022-03-19  12:56   Christos Zoulas <christos@zoulas.com>
+
+	* cache regex (Dirk Mueller)
+	* detect filesystem full by flushing output (Dirk Mueller)
+
+2021-11-19  12:36   Christos Zoulas <christos@zoulas.com>
+
+	* implement running decompressor programs using
+	  posix_spawnp(2) instead of vfork(2)
+
+2021-10-24  11:51   Christos Zoulas <christos@zoulas.com>
+
+	* Add support for msdos dates and times
+
+2021-10-20   9:55   Christos Zoulas <christos@zoulas.com>
+
+	* use the system byte swapping functions if available (Werner Fink)
+
 2021-10-18  11:57  Christos Zoulas <christos@zoulas.com>
 
 	* release 5.41

+ 2 - 1
Makefile.am

@@ -1,6 +1,7 @@
 ACLOCAL_AMFLAGS = -I m4
 
-EXTRA_DIST = MAINT RELEASE-PROCEDURE README.DEVELOPER m4/visibility.m4
+EXTRA_DIST = MAINT RELEASE-PROCEDURE README.DEVELOPER README.md \
+	m4/visibility.m4
 
 SUBDIRS = src magic tests doc python
 

+ 34 - 25
Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.5 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2021 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -168,8 +168,8 @@ am__recursive_targets = \
   $(am__extra_recursive_targets)
 AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
 	cscope distdir distdir-am dist dist-all distcheck
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
-	$(LISP)config.h.in
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
+	config.h.in
 # Read a list of newline-separated strings from the standard input,
 # and print each of them once, without duplicates.  Input order is
 # *not* preserved.
@@ -186,13 +186,10 @@ am__define_uniq_tagged_files = \
   unique=`for i in $$list; do \
     if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
   done | $(am__uniquify_input)`
-ETAGS = etags
-CTAGS = ctags
-CSCOPE = cscope
 DIST_SUBDIRS = $(SUBDIRS)
 am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \
 	$(srcdir)/libmagic.pc.in AUTHORS COPYING ChangeLog INSTALL \
-	NEWS TODO compile config.guess config.sub depcomp install-sh \
+	NEWS README.md TODO compile config.guess config.sub install-sh \
 	ltmain.sh missing
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
@@ -232,6 +229,8 @@ am__relativize = \
 DIST_ARCHIVES = $(distdir).tar.gz
 GZIP_ENV = --best
 DIST_TARGETS = dist-gzip
+# Exists only to be overridden by the user if desired.
+AM_DISTCHECK_DVI_TARGET = dvi
 distuninstallcheck_listfiles = find . -type f -print
 am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
   | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
@@ -249,8 +248,9 @@ CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CFLAG_VISIBILITY = @CFLAG_VISIBILITY@
-CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CSCOPE = @CSCOPE@
+CTAGS = @CTAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
@@ -261,6 +261,7 @@ ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
 EGREP = @EGREP@
+ETAGS = @ETAGS@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
 GREP = @GREP@
@@ -349,6 +350,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -358,7 +360,9 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 ACLOCAL_AMFLAGS = -I m4
-EXTRA_DIST = MAINT RELEASE-PROCEDURE README.DEVELOPER m4/visibility.m4
+EXTRA_DIST = MAINT RELEASE-PROCEDURE README.DEVELOPER README.md \
+	m4/visibility.m4
+
 SUBDIRS = src magic tests doc python
 
 # This variable must have 'exec' in its name, in order to be installed
@@ -555,7 +559,6 @@ cscopelist-am: $(am__tagged_files)
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 	-rm -f cscope.out cscope.in.out cscope.po.out cscope.files
-
 distdir: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) distdir-am
 
@@ -639,6 +642,10 @@ dist-xz: distdir
 	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
 	$(am__post_remove_distdir)
 
+dist-zstd: distdir
+	tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst
+	$(am__post_remove_distdir)
+
 dist-tarZ: distdir
 	@echo WARNING: "Support for distribution archives compressed with" \
 		       "legacy program 'compress' is deprecated." >&2
@@ -681,6 +688,8 @@ distcheck: dist
 	  eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\
 	*.zip*) \
 	  unzip $(distdir).zip ;;\
+	*.tar.zst*) \
+	  zstd -dc $(distdir).tar.zst | $(am__untar) ;;\
 	esac
 	chmod -R a-w $(distdir)
 	chmod u+w $(distdir)
@@ -696,7 +705,7 @@ distcheck: dist
 	    $(DISTCHECK_CONFIGURE_FLAGS) \
 	    --srcdir=../.. --prefix="$$dc_install_base" \
 	  && $(MAKE) $(AM_MAKEFLAGS) \
-	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
+	  && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \
 	  && $(MAKE) $(AM_MAKEFLAGS) check \
 	  && $(MAKE) $(AM_MAKEFLAGS) install \
 	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
@@ -861,19 +870,19 @@ uninstall-am: uninstall-pkgconfigexecDATA
 	am--refresh check check-am clean clean-cscope clean-generic \
 	clean-libtool cscope cscopelist-am ctags ctags-am dist \
 	dist-all dist-bzip2 dist-gzip dist-lzip dist-shar dist-tarZ \
-	dist-xz dist-zip distcheck distclean distclean-generic \
-	distclean-hdr distclean-libtool distclean-tags distcleancheck \
-	distdir distuninstallcheck dvi dvi-am html html-am info \
-	info-am install install-am install-data install-data-am \
-	install-dvi install-dvi-am install-exec install-exec-am \
-	install-html install-html-am install-info install-info-am \
-	install-man install-pdf install-pdf-am \
-	install-pkgconfigexecDATA install-ps install-ps-am \
-	install-strip installcheck installcheck-am installdirs \
-	installdirs-am maintainer-clean maintainer-clean-generic \
-	mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
-	ps ps-am tags tags-am uninstall uninstall-am \
-	uninstall-pkgconfigexecDATA
+	dist-xz dist-zip dist-zstd distcheck distclean \
+	distclean-generic distclean-hdr distclean-libtool \
+	distclean-tags distcleancheck distdir distuninstallcheck dvi \
+	dvi-am html html-am info info-am install install-am \
+	install-data install-data-am install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-man install-pdf \
+	install-pdf-am install-pkgconfigexecDATA install-ps \
+	install-ps-am install-strip installcheck installcheck-am \
+	installdirs installdirs-am maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
+	uninstall-am uninstall-pkgconfigexecDATA
 
 .PRECIOUS: Makefile
 

+ 155 - 0
README.md

@@ -0,0 +1,155 @@
+## README for file(1) Command and the libmagic(3) library ##
+
+    @(#) $File: README.md,v 1.4 2021/10/21 01:51:31 christos Exp $
+
+- Bug Tracker: <https://bugs.astron.com/>
+- Build Status: <https://travis-ci.org/file/file>
+- Download link: <ftp://ftp.astron.com/pub/file/>
+- E-mail: <christos@astron.com>
+- Fuzzing link: <https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:file>
+- Home page: https://www.darwinsys.com/file/
+- Mailing List archives: <https://mailman.astron.com/pipermail/file/>
+- Mailing List: <file@astron.com>
+- Public repo: <https://github.com/file/file>
+- Test framework: <https://github.com/file/file-tests>
+
+Phone: Do not even think of telephoning me about this program. Send
+cash first!
+
+This is Release 5.x of Ian Darwin's (copyright but distributable)
+file(1) command, an implementation of the Unix File(1) command.
+It knows the 'magic number' of several thousands of file types.
+This version is the standard "file" command for Linux, *BSD, and
+other systems. (See "patchlevel.h" for the exact release number).
+
+The major changes for 5.x are CDF file parsing, indirect magic,
+name/use (recursion) and overhaul in mime and ascii encoding
+handling.
+
+The major feature of 4.x is the refactoring of the code into a
+library, and the re-write of the file command in terms of that
+library. The library itself, libmagic can be used by 3rd party
+programs that wish to identify file types without having to fork()
+and exec() file. The prime contributor for 4.0 was Mans Rullgard.
+
+UNIX is a trademark of UNIX System Laboratories.
+
+The prime contributor to Release 3.8 was Guy Harris, who put in
+megachanges including byte-order independence.
+
+The prime contributor to Release 3.0 was Christos Zoulas, who put
+in hundreds of lines of source code changes, including his own
+ANSIfication of the code (I liked my own ANSIfication better, but
+his (__P()) is the "Berkeley standard" way of doing it, and I wanted
+UCB to include the code...), his HP-like "indirection" (a feature
+of the HP file command, I think), and his mods that finally got
+the uncompress (-z) mode finished and working.
+
+This release has compiled in numerous environments; see PORTING
+for a list and problems.
+
+This fine freeware file(1) follows the USG (System V) model of the
+file command, rather than the Research (V7) version or the V7-derived
+4.[23] Berkeley one. That is, the file /etc/magic contains much of
+the ritual information that is the source of this program's power.
+My version knows a little more magic (including tar archives) than
+System V; the /etc/magic parsing seems to be compatible with the
+(poorly documented) System V /etc/magic format (with one exception;
+see the man page).
+
+In addition, the /etc/magic file is built from a subdirectory
+for easier(?) maintenance.  I will act as a clearinghouse for
+magic numbers assigned to all sorts of data files that
+are in reasonable circulation. Send your magic numbers,
+in magic(5) format please, to the maintainer, Christos Zoulas.
+
+COPYING - read this first.
+* `README` - read this second (you are currently reading this file).
+* `INSTALL` - read on how to install
+* `src/apprentice.c` - parses /etc/magic to learn magic
+* `src/apptype.c` - used for OS/2 specific application type magic
+* `src/ascmagic.c` - third & last set of tests, based on hardwired assumptions.
+* `src/asctime_r.c` - replacement for OS's that don't have it.
+* `src/asprintf.c` - replacement for OS's that don't have it.
+* `src/buffer.c` - buffer handling functions.
+* `src/cdf.[ch]` - parser for Microsoft Compound Document Files
+* `src/cdf_time.c` - time converter for CDF.
+* `src/compress.c` - handles decompressing files to look inside.
+* `src/ctime_r.c` - replacement for OS's that don't have it.
+* `src/der.[ch]` - parser for Distinguished Encoding Rules
+* `src/dprintf.c` - replacement for OS's that don't have it.
+* `src/elfclass.h` - common code for elf 32/64.
+* `src/encoding.c` - handles unicode encodings
+* `src/file.c` - the main program
+* `src/file.h` - header file
+* `src/file_opts.h` - list of options
+* `src/fmtcheck.c` - replacement for OS's that don't have it.
+* `src/fsmagic.c` - first set of tests the program runs, based on filesystem info
+* `src/funcs.c` - utilility functions
+* `src/getline.c` - replacement for OS's that don't have it.
+* `src/getopt_long.c` - replacement for OS's that don't have it.
+* `src/gmtime_r.c` - replacement for OS's that don't have it.
+* `src/is_csv.c` - knows about Comma Separated Value file format (RFC 4180).
+* `src/is_json.c` - knows about JavaScript Object Notation format (RFC 8259).
+* `src/is_tar.c, tar.h` - knows about Tape ARchive format (courtesy John Gilmore).
+* `src/localtime_r.c` - replacement for OS's that don't have it.
+* `src/magic.h.in` - source file for magic.h
+* `src/mygetopt.h` - replacement for OS's that don't have it.
+* `src/magic.c` - the libmagic api
+* `src/names.h` - header file for ascmagic.c
+* `src/pread.c` - replacement for OS's that don't have it.
+* `src/print.c` - print results, errors, warnings.
+* `src/readcdf.c` - CDF wrapper.
+* `src/readelf.[ch]` - Stand-alone elf parsing code.
+* `src/softmagic.c` - 2nd set of tests, based on /etc/magic
+* `src/mygetopt.h` - replacement for OS's that don't have it.
+* `src/strcasestr.c` - replacement for OS's that don't have it.
+* `src/strlcat.c` - replacement for OS's that don't have it.
+* `src/strlcpy.c` - replacement for OS's that don't have it.
+* `src/strndup.c` - replacement for OS's that don't have it.
+* `src/tar.h` - tar file definitions
+* `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.
+
+Magdir - directory of /etc/magic pieces
+------------------------------------------------------------------------------
+
+If you submit a new magic entry please make sure you read the following
+guidelines:
+
+- Initial match is preferably at least 32 bits long, and is a _unique_ match
+- If this is not feasible, use additional check
+- Match of <= 16 bits are not accepted
+- Delay printing string as much as possible, don't print output too early
+- Avoid printf arbitrary byte as string, which can be a source of
+  crash and buffer overflow
+
+- Provide complete information with entry:
+  * One line short summary
+  * Optional long description
+  * File extension, if applicable
+  * Full name and contact method (for discussion when entry has problem)
+  * Further reference, such as documentation of format
+
+gpg for dummies:
+------------------------------------------------------------------------------
+
+```
+$ gpg --verify file-X.YY.tar.gz.asc file-X.YY.tar.gz
+gpg: assuming signed data in `file-X.YY.tar.gz'
+gpg: Signature made WWW MMM DD HH:MM:SS YYYY ZZZ using DSA key ID KKKKKKKK
+```
+
+To download the key:
+
+```
+$ gpg --keyserver hkp://keys.gnupg.net --recv-keys KKKKKKKK
+```
+------------------------------------------------------------------------------
+
+
+Parts of this software were developed at SoftQuad Inc., developers
+of SGML/HTML/XML publishing software, in Toronto, Canada.
+SoftQuad was swallowed up by Corel in 2002 and does not exist any longer.

+ 2 - 1
acinclude.m4

@@ -35,7 +35,8 @@ if test "$ac_cv_struct_tm_isdst" = yes; then
 fi
 
 
-AC_CHECK_DECLS([daylight], , , [#include <time.h>])
+AC_CHECK_DECLS([daylight], , , [#include <time.h>
+#include <stdlib.h>])
 AC_CACHE_CHECK(for daylight, ac_cv_var_daylight,
 [AC_LINK_IFELSE(
 [AC_LANG_PROGRAM([#include <time.h>],

+ 47 - 32
aclocal.m4

@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.16.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.16.5 -*- Autoconf -*-
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2021 Free Software Foundation, Inc.
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -14,13 +14,13 @@
 m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
-[m4_warning([this file was generated for autoconf 2.69.
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.71],,
+[m4_warning([this file was generated for autoconf 2.71.
 You have another version of autoconf.  It may work, but is not guaranteed to.
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
 
-# Copyright (C) 2002-2018 Free Software Foundation, Inc.
+# Copyright (C) 2002-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -35,7 +35,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION],
 [am__api_version='1.16'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.16.1], [],
+m4_if([$1], [1.16.5], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 
@@ -51,14 +51,14 @@ m4_define([_AM_AUTOCONF_VERSION], [])
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.16.1])dnl
+[AM_AUTOMAKE_VERSION([1.16.5])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -110,7 +110,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd`
 
 # AM_CONDITIONAL                                            -*- Autoconf -*-
 
-# Copyright (C) 1997-2018 Free Software Foundation, Inc.
+# Copyright (C) 1997-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -141,7 +141,7 @@ AC_CONFIG_COMMANDS_PRE(
 Usually this means the macro was only invoked conditionally.]])
 fi])])
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -332,7 +332,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
 
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -371,7 +371,9 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
   done
   if test $am_rc -ne 0; then
     AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments
-    for automatic dependency tracking.  Try re-running configure with the
+    for automatic dependency tracking.  If GNU make was not used, consider
+    re-running the configure script with MAKE="gmake" (or whatever is
+    necessary).  You can also try re-running configure with the
     '--disable-dependency-tracking' option to at least be able to build
     the package (albeit without support for automatic dependency tracking).])
   fi
@@ -398,7 +400,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
 
 # Do all the work for Automake.                             -*- Autoconf -*-
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -426,6 +428,10 @@ m4_defn([AC_PROG_CC])
 # release and drop the old call support.
 AC_DEFUN([AM_INIT_AUTOMAKE],
 [AC_PREREQ([2.65])dnl
+m4_ifdef([_$0_ALREADY_INIT],
+  [m4_fatal([$0 expanded multiple times
+]m4_defn([_$0_ALREADY_INIT]))],
+  [m4_define([_$0_ALREADY_INIT], m4_expansion_stack)])dnl
 dnl Autoconf wants to disallow AM_ names.  We explicitly allow
 dnl the ones we care about.
 m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
@@ -462,7 +468,7 @@ m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
 [_AM_SET_OPTIONS([$1])dnl
 dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
 m4_if(
-  m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]),
+  m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([AC_PACKAGE_VERSION], [ok]),
   [ok:ok],,
   [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
  AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
@@ -514,6 +520,20 @@ AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
 		  [m4_define([AC_PROG_OBJCXX],
 			     m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl
 ])
+# Variables for tags utilities; see am/tags.am
+if test -z "$CTAGS"; then
+  CTAGS=ctags
+fi
+AC_SUBST([CTAGS])
+if test -z "$ETAGS"; then
+  ETAGS=etags
+fi
+AC_SUBST([ETAGS])
+if test -z "$CSCOPE"; then
+  CSCOPE=cscope
+fi
+AC_SUBST([CSCOPE])
+
 AC_REQUIRE([AM_SILENT_RULES])dnl
 dnl The testsuite driver may need to know about EXEEXT, so add the
 dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This
@@ -595,7 +615,7 @@ for _am_header in $config_headers :; do
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -616,7 +636,7 @@ if test x"${install_sh+set}" != xset; then
 fi
 AC_SUBST([install_sh])])
 
-# Copyright (C) 2003-2018 Free Software Foundation, Inc.
+# Copyright (C) 2003-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -637,7 +657,7 @@ AC_SUBST([am__leading_dot])])
 
 # Check to see how 'make' treats includes.	            -*- Autoconf -*-
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -680,7 +700,7 @@ AC_SUBST([am__quote])])
 
 # Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
 
-# Copyright (C) 1997-2018 Free Software Foundation, Inc.
+# Copyright (C) 1997-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -701,12 +721,7 @@ AC_DEFUN([AM_MISSING_HAS_RUN],
 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 AC_REQUIRE_AUX_FILE([missing])dnl
 if test x"${MISSING+set}" != xset; then
-  case $am_aux_dir in
-  *\ * | *\	*)
-    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
-  *)
-    MISSING="\${SHELL} $am_aux_dir/missing" ;;
-  esac
+  MISSING="\${SHELL} '$am_aux_dir/missing'"
 fi
 # Use eval to expand $SHELL
 if eval "$MISSING --is-lightweight"; then
@@ -719,7 +734,7 @@ fi
 
 # Helper functions for option handling.                     -*- Autoconf -*-
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -748,7 +763,7 @@ AC_DEFUN([_AM_SET_OPTIONS],
 AC_DEFUN([_AM_IF_OPTION],
 [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -795,7 +810,7 @@ AC_LANG_POP([C])])
 # For backward compatibility.
 AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -814,7 +829,7 @@ AC_DEFUN([AM_RUN_LOG],
 
 # Check to make sure that the build environment is sane.    -*- Autoconf -*-
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -895,7 +910,7 @@ AC_CONFIG_COMMANDS_PRE(
 rm -f conftest.file
 ])
 
-# Copyright (C) 2009-2018 Free Software Foundation, Inc.
+# Copyright (C) 2009-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -955,7 +970,7 @@ AC_SUBST([AM_BACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
 ])
 
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -983,7 +998,7 @@ fi
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 
-# Copyright (C) 2006-2018 Free Software Foundation, Inc.
+# Copyright (C) 2006-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -1002,7 +1017,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 
 # Check how to create a tarball.                            -*- Autoconf -*-
 
-# Copyright (C) 2004-2018 Free Software Foundation, Inc.
+# Copyright (C) 2004-2021 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,

+ 3 - 3
compile

@@ -3,7 +3,7 @@
 
 scriptversion=2018-03-07.03; # UTC
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2021 Free Software Foundation, Inc.
 # Written by Tom Tromey <tromey@cygnus.com>.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -53,7 +53,7 @@ func_file_conv ()
 	  MINGW*)
 	    file_conv=mingw
 	    ;;
-	  CYGWIN*)
+	  CYGWIN* | MSYS*)
 	    file_conv=cygwin
 	    ;;
 	  *)
@@ -67,7 +67,7 @@ func_file_conv ()
 	mingw/*)
 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
 	  ;;
-	cygwin/*)
+	cygwin/* | msys/*)
 	  file=`cygpath -m "$file" || echo "$file"`
 	  ;;
 	wine/*)

File diff suppressed because it is too large
+ 833 - 591
config.guess


+ 94 - 23
config.h.in

@@ -18,6 +18,9 @@
 /* Define to 1 if you have the `asprintf' function. */
 #undef HAVE_ASPRINTF
 
+/* Define to 1 if you have the <byteswap.h> header file. */
+#undef HAVE_BYTESWAP_H
+
 /* Define to 1 if you have the <bzlib.h> header file. */
 #undef HAVE_BZLIB_H
 
@@ -110,8 +113,8 @@
 /* Define to 1 if you have the `memmem' function. */
 #undef HAVE_MEMMEM
 
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
+/* Define to 1 if you have the <minix/config.h> header file. */
+#undef HAVE_MINIX_CONFIG_H
 
 /* Define to 1 if you have the `mkostemp' function. */
 #undef HAVE_MKOSTEMP
@@ -128,15 +131,24 @@
 /* Define to 1 if you have the `pipe2' function. */
 #undef HAVE_PIPE2
 
+/* Define to 1 if you have the `posix_spawnp' function. */
+#undef HAVE_POSIX_SPAWNP
+
 /* Define to 1 if you have the `pread' function. */
 #undef HAVE_PREAD
 
 /* Have sig_t type */
 #undef HAVE_SIG_T
 
+/* Define to 1 if you have the <spawn.h> header file. */
+#undef HAVE_SPAWN_H
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
+/* Define to 1 if you have the <stdio.h> header file. */
+#undef HAVE_STDIO_H
+
 /* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
 
@@ -173,6 +185,12 @@
 /* Define to 1 if `tm_zone' is a member of `struct tm'. */
 #undef HAVE_STRUCT_TM_TM_ZONE
 
+/* Define to 1 if you have the <sys/bswap.h> header file. */
+#undef HAVE_SYS_BSWAP_H
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#undef HAVE_SYS_IOCTL_H
+
 /* Define to 1 if you have the <sys/mman.h> header file. */
 #undef HAVE_SYS_MMAN_H
 
@@ -290,7 +308,9 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
-/* Define to 1 if you have the ANSI C header files. */
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
 #undef STDC_HEADERS
 
 /* Define to 1 if your <sys/time.h> declares `struct tm'. */
@@ -300,21 +320,87 @@
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
 #endif
+/* Enable general extensions on macOS.  */
+#ifndef _DARWIN_C_SOURCE
+# undef _DARWIN_C_SOURCE
+#endif
+/* Enable general extensions on Solaris.  */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
 /* Enable GNU extensions on systems that have them.  */
 #ifndef _GNU_SOURCE
 # undef _GNU_SOURCE
 #endif
-/* Enable threading extensions on Solaris.  */
+/* Enable X/Open compliant socket functions that do not require linking
+   with -lxnet on HP-UX 11.11.  */
+#ifndef _HPUX_ALT_XOPEN_SOCKET_API
+# undef _HPUX_ALT_XOPEN_SOCKET_API
+#endif
+/* Identify the host operating system as Minix.
+   This macro does not affect the system headers' behavior.
+   A future release of Autoconf may stop defining this macro.  */
+#ifndef _MINIX
+# undef _MINIX
+#endif
+/* Enable general extensions on NetBSD.
+   Enable NetBSD compatibility extensions on Minix.  */
+#ifndef _NETBSD_SOURCE
+# undef _NETBSD_SOURCE
+#endif
+/* Enable OpenBSD compatibility extensions on NetBSD.
+   Oddly enough, this does nothing on OpenBSD.  */
+#ifndef _OPENBSD_SOURCE
+# undef _OPENBSD_SOURCE
+#endif
+/* Define to 1 if needed for POSIX-compatible behavior.  */
+#ifndef _POSIX_SOURCE
+# undef _POSIX_SOURCE
+#endif
+/* Define to 2 if needed for POSIX-compatible behavior.  */
+#ifndef _POSIX_1_SOURCE
+# undef _POSIX_1_SOURCE
+#endif
+/* Enable POSIX-compatible threading on Solaris.  */
 #ifndef _POSIX_PTHREAD_SEMANTICS
 # undef _POSIX_PTHREAD_SEMANTICS
 #endif
+/* Enable extensions specified by ISO/IEC TS 18661-5:2014.  */
+#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
+# undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-1:2014.  */
+#ifndef __STDC_WANT_IEC_60559_BFP_EXT__
+# undef __STDC_WANT_IEC_60559_BFP_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-2:2015.  */
+#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
+# undef __STDC_WANT_IEC_60559_DFP_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-4:2015.  */
+#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
+# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-3:2015.  */
+#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
+# undef __STDC_WANT_IEC_60559_TYPES_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TR 24731-2:2010.  */
+#ifndef __STDC_WANT_LIB_EXT2__
+# undef __STDC_WANT_LIB_EXT2__
+#endif
+/* Enable extensions specified by ISO/IEC 24747:2009.  */
+#ifndef __STDC_WANT_MATH_SPEC_FUNCS__
+# undef __STDC_WANT_MATH_SPEC_FUNCS__
+#endif
 /* Enable extensions on HP NonStop.  */
 #ifndef _TANDEM_SOURCE
 # undef _TANDEM_SOURCE
 #endif
-/* Enable general extensions on Solaris.  */
-#ifndef __EXTENSIONS__
-# undef __EXTENSIONS__
+/* Enable X/Open extensions.  Define to 500 only if necessary
+   to make mbstate_t available.  */
+#ifndef _XOPEN_SOURCE
+# undef _XOPEN_SOURCE
 #endif
 
 
@@ -339,11 +425,6 @@
 /* Enable zlib compression support */
 #undef ZLIBSUPPORT
 
-/* Enable large inode numbers on Mac OS X 10.5.  */
-#ifndef _DARWIN_USE_64_BIT_INODE
-# define _DARWIN_USE_64_BIT_INODE 1
-#endif
-
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS
 
@@ -353,16 +434,6 @@
 /* Define for large files, on AIX-style hosts. */
 #undef _LARGE_FILES
 
-/* Define to 1 if on MINIX. */
-#undef _MINIX
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
-   this defined. */
-#undef _POSIX_1_SOURCE
-
-/* Define to 1 if you need to in order for `stat' and other things to work. */
-#undef _POSIX_SOURCE
-
 /* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
    <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
    #define below would cause a syntax error. */
@@ -396,7 +467,7 @@
 /* Define to `long int' if <sys/types.h> does not define. */
 #undef off_t
 
-/* Define to `int' if <sys/types.h> does not define. */
+/* Define as a signed integer type capable of holding a process identifier. */
 #undef pid_t
 
 /* Define to `unsigned int' if <sys/types.h> does not define. */

File diff suppressed because it is too large
+ 379 - 290
config.sub


File diff suppressed because it is too large
+ 3934 - 3107
configure


+ 5 - 5
configure.ac

@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT([file],[5.41],[christos@astron.com])
+AC_INIT([file],[5.43],[christos@astron.com])
 AM_INIT_AUTOMAKE([subdir-objects foreign])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
@@ -99,10 +99,10 @@ gl_VISIBILITY
 dnl Checks for headers
 AC_HEADER_MAJOR
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS(stdint.h fcntl.h inttypes.h unistd.h)
-AC_CHECK_HEADERS(utime.h wchar.h wctype.h)
+AC_CHECK_HEADERS(stdint.h fcntl.h inttypes.h unistd.h byteswap.h)
+AC_CHECK_HEADERS(spawn.h utime.h wchar.h wctype.h)
 AC_CHECK_HEADERS(getopt.h err.h xlocale.h)
-AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h sys/sysmacros.h)
+AC_CHECK_HEADERS(sys/bswap.h sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h sys/sysmacros.h sys/ioctl.h)
 if test "$enable_zlib" != "no"; then
   AC_CHECK_HEADERS(zlib.h)
 fi
@@ -165,7 +165,7 @@ else
 fi])
 
 dnl Checks for functions
-AC_CHECK_FUNCS(strndup mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale memmem pipe2)
+AC_CHECK_FUNCS(strndup mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale memmem pipe2 posix_spawnp)
 
 dnl Provide implementation of some required functions if necessary
 AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r localtime_r gmtime_r pread strcasestr fmtcheck dprintf)

+ 1 - 1
depcomp

@@ -3,7 +3,7 @@
 
 scriptversion=2018-03-07.03; # UTC
 
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2021 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 6 - 4
doc/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.5 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2021 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -170,8 +170,9 @@ CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CFLAG_VISIBILITY = @CFLAG_VISIBILITY@
-CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CSCOPE = @CSCOPE@
+CTAGS = @CTAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
@@ -182,6 +183,7 @@ ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
 EGREP = @EGREP@
+ETAGS = @ETAGS@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
 GREP = @GREP@
@@ -270,6 +272,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -500,7 +503,6 @@ ctags CTAGS:
 
 cscope cscopelist:
 
-
 distdir: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) distdir-am
 

+ 6 - 2
doc/magic.man

@@ -1,5 +1,5 @@
-.\" $File: magic.man,v 1.99 2021/05/09 22:37:23 christos Exp $
-.Dd May 9, 2021
+.\" $File: magic.man,v 1.100 2022/09/10 13:19:26 christos Exp $
+.Dd September 10, 2022
 .Dt MAGIC __FSECTION__
 .Os
 .\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
@@ -359,6 +359,9 @@ For example the magic entries:
 -0	offset	<=100	must be more than 100 \e
     bytes and is only %lld
 .Ed
+.It Dv octal
+A string representing an octal number.
+.El
 .El
 .Pp
 For compatibility with the Single
@@ -645,6 +648,7 @@ The following types are recognized:
 .It i	ID3	Little	4
 .It I	ID3	Big	4
 .It m	Middle	Middle	4
+.It o	Octal	Textual	Variable
 .It q	Quad	Little	8
 .It Q	Quad	Big	8
 .El

+ 4 - 3
magic/Magdir/animation

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: animation,v 1.87 2021/08/24 09:25:11 christos Exp $
+# $File: animation,v 1.90 2022/08/16 11:16:39 christos Exp $
 # animation:  file(1) magic for animation/movie formats
 #
 # animation formats
@@ -30,8 +30,6 @@
 #!:mime	image/x-quicktime
 4       string          pckg            Apple QuickTime compressed archive
 !:mime	application/x-quicktime-player
-4	string/W	jP		JPEG 2000 image
-!:mime	image/jp2
 
 #### MP4 ####
 # https://www.ftyps.com/ with local additions
@@ -168,6 +166,7 @@
 #	?/enc-isoff-generic
 >8	string		iso		\b, MP4 Base Media
 !:mime	video/mp4
+!:ext	mp4
 >>11	string		m 		v1 [ISO 14496-12:2003]
 >>11	string		2		v2 [ISO 14496-12:2005]
 >>11	string		4		v4
@@ -937,9 +936,11 @@
 0	belong&0xFF5FFF10	0x47400010
 >188	byte			0x47		MPEG transport stream data
 !:mime  video/MP2T
+!:ext	ts
 
 # DIF digital video file format <mpruett@sgi.com>
 0	belong&0xffffff00	0x1f070000      DIF
+!:mime  video/x-dv
 >4	byte			&0x01		(DVCPRO) movie file
 >4	byte			^0x01		(DV) movie file
 >3	byte			&0x80		(PAL)

+ 303 - 43
magic/Magdir/archive

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: archive,v 1.151 2021/08/16 10:19:56 christos Exp $
+# $File: archive,v 1.169 2022/09/12 13:13:28 christos Exp $
 # archive:  file(1) magic for archive formats (see also "msdos" for self-
 #           extracting compressed archives)
 #
@@ -25,7 +25,16 @@
 >>>>>>155 ubyte&0xDF	=0	
 # space or ascii digit 0 at start of check sum
 >>>>>>>148	ubyte&0xEF	=0x20	
->>>>>>>>0	use	tar-file
+# FOR DEBUGGING: 
+#>>>>>>>>0	regex		\^[0-9]{2,4}[.](png|jpg|jpeg|tif|tiff|gif|bmp)	NAME "%s"
+# check for 1st image main name with digits used for sorting
+# and for name extension case insensitive like: PNG JPG JPEG TIF TIFF GIF BMP
+>>>>>>>>0	regex		\^[0-9]{2,4}[.](png|jpg|jpeg|tif|tiff|gif|bmp)
+#foo
+>>>>>>>>>0	use	tar-cbt
+# if 1st member name without digits and without used image suffix then it is a TAR archive
+>>>>>>>>0	default		x
+>>>>>>>>>0	use	tar-file
 #	minimal check and then display tar archive information which can also be
 #	embedded inside others like Android Backup, Clam AntiVirus database
 0	name		tar-file
@@ -146,11 +155,24 @@
 >>508	default		x		
 # padding[255] in old tar sometimes comment field
 >>>257	string		>\0		\b, comment: %-.40s
+# Summary:	Comic Book Archive *.CBT with TAR format
+# URL:		https://en.wikipedia.org/wiki/Comic_book_archive
+#		http://fileformats.archiveteam.org/wiki/Comic_Book_Archive
+# Note:		there exist also RAR, ZIP, ACE and 7Z packed variants
+0	name		tar-cbt
+>0	string		x		Comic Book archive, tar archive
+#!:mime	application/x-tar
+!:mime	application/vnd.comicbook
+#!:mime	application/vnd.comicbook+tar
+!:ext	cbt
+# name[100] probably like: 19.jpg 0001.png 0002.png
+# or maybe like ComicInfo.xml
+>0	string		>\0		\b, 1st image %-.60s
 
 # Incremental snapshot gnu-tar format from:
 # https://www.gnu.org/software/tar/manual/html_node/Snapshot-Files.html
 0	string		GNU\ tar-	GNU tar incremental snapshot data
->&0	regex		[0-9]\.[0-9]+-[0-9]+	version %s
+>&0	regex		[0-9]\\.[0-9]+-[0-9]+	version %s
 
 # cpio archives
 #
@@ -518,46 +540,65 @@
 #>-3	ubyte		x	\b, last 3 bytes 0x%2.2x
 #>-2	ubeshort	x	\b%4.4x
 # From:		Joerg Jenderek
-# URL:		https://wiki.68kmla.org/DiskCopy_4.2_format_specification
+# URL:		https://en.wikipedia.org/wiki/Disk_Copy
 # reference:	http://nulib.com/library/FTN.e00005.htm
 0x52	ubeshort	0x0100
 # test for disk image size equal or above 400k
 >0x40	ubelong		>409599
 # test also for disk image size equal or below 1440k to skip
 # windows7en.mbr UNICODE.DAT
->>0x40	ubelong		<1474561
-# To skip Flags$StringJoiner.class with size 00106A61h test also for only 4 disk image sizes
-# 00064000 for  400k GCR disks
-# 000c8000 for  800k GCR disks
-# 000b4000 for  720k MFM disks
-# 00168000 for 1440k MFM disks
->>>0x40	ubelong&0xffE03fFF	0
->>>>0	use	dc42-floppy
+#>>0x40	ubelong		<1474561
+# test now for "low" disk image size equal or below 64 MiB to skip
+# windows7en.mbr (B441BBAAh) UNICODE.DAT (0400AF05h)
+>>0x40	ubelong		<0x04000001
+# To skip Flags$StringJoiner.class with size 00106A61h test also for valid disk image sizes
+# 00064000 for  400k GCR disks	dc42-400k-gcr.trid.xml
+# 000c8000 for  800k GCR disks	dc42-800k-gcr.trid.xml
+# 000b4000 for  720k MFM disks	dc42-720k-mfm.trid.xml
+# 00168000 for 1440k MFM disks	dc42-1440k-mfm.trid.xml
+#	https://lisaem.sunder.net/LisaProjectDocs.txt
+# 00500000	05M	available
+# 00A00000	10M	available
+# 01800000	24M	possible
+# 02000000	32M	uncertain
+# 04000000	64M	uncertain
+>>>0x40	ubelong&0xf8003fFF	0
+# skip samples with invalid disk name length like:
+# 181 (biosmd80.rom) 202 (Flags$StringJoiner.class) 90 (UNICODE.DAT)
+>>>>0x0	ubyte			<64
+>>>>>0	use			dc42-floppy
 #	display information of Apple DiskCopy 4.2 floppy image
 0	name		dc42-floppy
-# image pascal name padded with NULs like Microsoft Mail
+# disk name length; maximal 63
+#>0	ubyte	    	x	DISK NAME LENGTH %u
+# ASCII image pascal (maximal 63 bytes) name padded with NULs like:
+# "Microsoft Mail" "Disquette 2" "IIe Installer Disk"
+# "-lisaem.sunder.net hd-" (dc42-lisaem.trid.xml) "-not a Macintosh disk" (dc42-nonmac.trid.xml)
 >00	pstring/B	x	Apple DiskCopy 4.2 image %s
 #!:mime	application/octet-stream
 !:mime	application/x-dc42-floppy-image
 !:apple	dCpydImg
-!:ext	image/dc42
-# data size in bytes like 409600
+# probably also img like: "Utilitaires 2.img" "Installation 7.img"
+!:ext	image/dc42/img
+# data size in bytes like: 409600 737280 819200 1474560
 >0x40	ubelong		x	\b, %u bytes
 # for debugging purpose size in hexadecimal
 #>0x40	ubelong		x	(%#8.8x)
-# tag size in bytes
+# tag size in bytes like: 0 (often) 2580h (PUID fmt/625) 4B00h (Microsoft Mail.image)
 >0x44	ubelong		>0	\b, %#x tag size
 # data checksum
 #>0x48	ubelong		x	\b, %#x checksum
 # tag checksum
 #>0x4c	ubelong		x	\b, %#x tag checksum
-# disk encoding
+# disk encoding like: 0 1 2 3 (PUID: fmt/625)
 >0x50	ubyte		0	\b, GCR CLV ssdd (400k)
 >0x50	ubyte		1	\b, GCR CLV dsdd (800k)
 >0x50	ubyte		2	\b, MFM CAV dsdd (720k)
 >0x50	ubyte		3	\b, MFM CAV dshd (1440k)
 >0x50	ubyte		>3	\b, %#x encoding
-# format byte
+# format byte like: 12h (Lisa 400K) 24h (400K Macintosh) 96h (800K Apple II disk)
+# 2 (Mac 400k "Disquette Installation 13.image")
+# 22h (double-sided MFM or Mac 800k "Disco 12.image" "IIe Installer Disk.image")
 >0x51	ubyte		x	\b, %#x format
 #>0x54	ubequad		x	\b, data %#16.16llx
 # ESP, could this conflict with Easy Software Products' (e.g.ESP ghostscript) documentation?
@@ -670,7 +711,15 @@
 # 2 bytes: length of data + mentioned bytes
 #
 #		SZDD variant Haruhiko Okumura's LZSS or 7z type MsLZ
+# URL:		http://fileformats.archiveteam.org/wiki/MS-DOS_installation_compression
+# Reference:	http://www.cabextract.org.uk/libmspack/doc/szdd_kwaj_format.html
+#		http://mark0.net/download/triddefs_xml.7z/defs/s/szdd.trid.xml
+# Note:		called "Microsoft SZDD compressed (Haruhiko Okumura's LZSS)" by TrID
+#		verfied by 7-Zip `7z l -tMsLZ -slt *.??_` as MsLZ
+#		`deark -l -m lzss_oku -d2 setup-1-41.bin` as "LZSS.C by Haruhiko Okumura"
 >0	string	SZDD		MS Compress archive data, SZDD variant
+# 2nd part of signature
+#>>4	ubelong	0x88F02733	\b, SIGNATURE OK
 !:mime	application/x-ms-compress-szdd
 !:ext	??_
 # The character missing from the end of the filename (0=unknown)
@@ -679,6 +728,24 @@
 # Compression mode: "A" (0x41) found but sometimes "B" in Windows 3.1 builds 026 and 034e
 >>8	string	!A		\b, %-.1s method
 >>10	ulelong	>0		\b, original size: %u bytes
+# Summary:	InstallShield archive with SZDD compressed
+# URL:		https://community.flexera.com/t5/InstallShield-Knowledge-Base/InstallShield-Redistributable-Files/ta-p/5647
+# From:		Joerg Jenderek
+1	search/48/bs	SZDD\x88\xF0\x27\x33	InstallShield archive
+#!:mime	application/octet-stream
+!:mime	application/x-installshield-compress-szdd
+!:ext	ibt
+# name of compressed archive member like: setup.dl_ _setup7int.dl_ _setup2k.dl_ _igdi.dl_ cabinet.dl_
+>0	string	x		%s
+# name of uncompressed archive member like: setup.dll _Setup.dll IGdi.dll CABINET.DLL
+>>&1	string	x		(%s)
+# probably version like: 9.0.0.333 9.1.0.429 11.50.0.42618
+>>>&1	string	x		\b, version %s
+# SZDD member length like: 168048 169333 181842
+>>>>&1	string	x		\b, %s bytes
+# MS Compress archive data
+#>&0	string		SZDD	\b, SIGNATURE FOUND
+>&0	indirect	x
 #		QBasic SZDD variant
 3	string	\x88\xf0\x27
 >0	string	SZ\x20		MS Compress archive data, QBasic variant
@@ -686,6 +753,17 @@
 !:ext	??$
 >>8	ulelong	>0		\b, original size: %u bytes
 
+# Summary:	CAZIP compressed file
+# From:		Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/CAZIP
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/c/caz.trid.xml
+# Note:		Format is distinct from CAZIPXP compressed
+0	string	\x0D\x0A\x1ACAZIP	CAZIP compressed file
+#!:mime	application/octet-stream
+!:mime	application/x-compress-cazip
+# like: BLINKER.WR_ CLIPDEFS._ CAOSETUP.EX_ CLIPPER.EX_ FILEIO.C_
+!:ext	??_/?_/_
+
 # Summary:	FTCOMP compressed archive
 # From:		Joerg Jenderek
 # URL:		http://fileformats.archiveteam.org/wiki/FTCOMP
@@ -772,13 +850,43 @@
 0	string	NSK NaShrink archive data
 # SAPCAR
 0	string	#\ CAR\ archive\ header SAPCAR archive data
-0	string	CAR\ 2.00RG SAPCAR archive data
+0	string	CAR\ 2.00 SAPCAR archive data
+0	string	CAR\ 2.01 SAPCAR archive data
+#!:mime	application/octet-stream
+!:mime	application/vnd.sar
+!:ext	sar
 # Disintegrator
 0	string	DST Disintegrator archive data
 # ASD
 0	string	ASD ASD archive data
 # InstallShield CAB
-0	string	ISc( InstallShield CAB
+# Update:	Joerg Jenderek at Nov 2021
+# URL:		https://en.wikipedia.org/wiki/InstallShield
+# Reference:	https://github.com/twogood/unshield/blob/master/lib/cabfile.h
+# Note:		Not compatible with Microsoft CAB files
+# http://mark0.net/download/triddefs_xml.7z/defs/a/ark-cab-ishield.trid.xml
+# CAB_SIGNATURE 0x28635349
+0	string	ISc( InstallShield
+#!:mime		application/octet-stream
+!:mime		application/x-installshield
+# http://mark0.net/download/triddefs_xml.7z/defs/a/ark-cab-ishield-hdr.trid.xml
+>16	ulelong	!0	setup header
+# like: _SYS1.HDR _USER1.HDR data1.hdr
+!:ext	hdr
+>16	ulelong	=0	CAB
+# like: _SYS1.CAB _USER1.CAB DATA1.CAB  data2.cab
+!:ext	cab
+# https://github.com/twogood/unshield/blob/master/lib/helper.c
+# version like:	0x1005201 0x100600c 0x1007000 0x1009500
+#		0x2000578 0x20005dc 0x2000640 0x40007d0 0x4000834
+>4	ulelong	x	\b, version %#x
+# volume_info like: 0
+>8	ulelong	!0	\b, volume_info %#x
+# cab_descriptor_offset like: 0x200
+>12	ulelong	!0x200	\b, offset %#x
+#>0x200	ubequad	x	\b, at 0x200 %#16.16llx
+# cab_descriptor_size like: 0 (*.cab) BD5 C8B DA5 E2A E36 116C 251D 4DA9 56F0 5CC2 6E4B 777D 779E 1F7C2
+>16	ulelong	!0	\b, descriptor size %#x
 # TOP4
 0	string	T4\x1a TOP4 archive data
 # BatComp left out: sig looks like COM executable
@@ -925,30 +1033,143 @@
 >3	byte&0xf0	0x30
 >>3	byte	x (v%c)
 # JAR archiver (.j), this is the successor to ARJ, not Java's JAR (which is essentially ZIP)
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/JAR_(ARJ_Software)
+# reference:	http://mark0.net/download/triddefs_xml.7z/defs/a/ark-jar.trid.xml
+#		https://www.sac.sk/download/pack/jar102x.exe/TECHNOTE.DOC
+# Note:		called "JAR compressed archive" by TrID
 0xe	string	\x1aJar\x1b JAR (ARJ Software, Inc.) archive data
+#!:mime	application/octet-stream
+!:mime	application/x-compress-j
+>0	ulelong	x		\b, CRC32 %#x
+# standard suffix is ".j"; for multi volumes following order j01 j02 ... j99 100 ... 990
+!:ext	j/j01/j02
+# URL:		http://fileformats.archiveteam.org/wiki/JARCS
+# reference:	http://mark0.net/download/triddefs_xml.7z/defs/a/ark-jarcs.trid.xml
+# Note:		called "JARCS compressed archive" by TrID
 0	string	JARCS JAR (ARJ Software, Inc.) archive data
+#!:mime	application/octet-stream
+!:mime	application/x-compress-jar
+!:ext	jar
 
 # ARJ archiver (jason@jarthur.Claremont.EDU)
-0	leshort		0xea60		ARJ archive data
+# URL:		http://fileformats.archiveteam.org/wiki/ARJ
+# reference:	http://mark0.net/download/triddefs_xml.7z/defs/a/ark-arj.trid.xml
+#		https://github.com/FarGroup/FarManager/
+#		blob/master/plugins/multiarc/arc.doc/arj.txt
+# Note:		called "ARJ compressed archive" by TrID and
+#		"ARJ File Format" by DROID via PUID fmt/610
+#		verified by `7z l -tarj PHRACK1.ARJ` and
+#		`arj.exe l TEST-hk9.ARJ`
+0	leshort		0xea60
+# skip DROID fmt-610-signature-id-946.arj by check for valid file type of main header
+>0xA	ubyte		2
+>>0	use		arj-archive
+0	name		arj-archive
+>0	leshort		x		ARJ archive
 !:mime	application/x-arj
->5	byte		x		\b, v%d,
->8	byte		&0x04		multi-volume,
->8	byte		&0x10		slash-switched,
->8	byte		&0x20		backup,
->34	string		x		original name: %s,
->7	byte		0		os: MS-DOS
->7	byte		1		os: PRIMOS
->7	byte		2		os: Unix
->7	byte		3		os: Amiga
->7	byte		4		os: Macintosh
->7	byte		5		os: OS/2
->7	byte		6		os: Apple ][ GS
->7	byte		7		os: Atari ST
->7	byte		8		os: NeXT
->7	byte		9		os: VAX/VMS
->3	byte		>0		%d]
+# look for terminating 0-character of filename
+>0x26	search/1024	\0
+# file name extension is normally .arj but not for parts of multi volume
+#>>&-5	string		x		extension %.4s
+>>&-5	string/c	.arj		data
+!:ext	arj
+>>&-5	default		x
+# for multi volume first name is archive.arj then following parts archive.a01 archive.a02 ...
+>>>8	byte		&0x04		data
+!:ext	a01/a02
+# for SFX first name is archive.exe then following parts archive.e01 archive.e02 ...
+>>>8	byte		^0x04		data, SFX multi-volume
+!:ext	e01/e02
+# basic header size like: 0x002b 0x002c 0x04e0 0x04e3 0x04e7
+#>2	uleshort	x		basic header size %#4.4x
+# next fragment content like: 0x0a200a003a8fc713 0x524a000010bb3471 0x524a0000c73c70f9
+#>(2.s)	ubequad		x		NEXT FRAGMENT CONTENT %#16.16llx
+# first_hdr_size; seems to be same as basic header size
+#>2	uleshort	x		1st header size %#x
+# archiver version number like: 3 4 6 11 102
+>5	byte		x		\b, v%d
+# minimum archiver version to extract like: 1
+>6	ubyte		!1		\b, minimum %u to extract
+# FOR DEBUGGING
+#>8	byte		x		\b, FLAGS %#x
+# GARBLED_FLAG1; garble with password; g switch
+>8	byte		&0x01		\b, password-protected
+# encryption version: 0~old  1~old 2~new 3~reserved 4~40 bit key GOST
+>>0x20	ubyte		x		(v%u)
+#>8	byte		&0x02		\b, secured
+# ANSIPAGE_FLAG; indicates ANSI codepage used by ARJ32; hy switch
+>8	byte		&0x02		\b, ANSI codepage
+# VOLUME_FLAG indicates presence of succeeding volume; but apparently not for SFX
+>8	byte		&0x04		\b, multi-volume
+#>8	byte		&0x08		\b, file-offset
+# ARJPROT_FLAG; build with data protection record; hk switch
+>8	byte		&0x08		\b, recoverable
+# arj protection factor; maximal 10; switch hky -> factor=y+1
+>>0x22	byte		x		(factor %u)
+>8	byte		&0x10		\b, slash-switched
+# BACKUP_FLAG; obsolete
+>8	byte		&0x20		\b, backup
+# SECURED_FLAG;
+>8	byte		&0x40		\b, secured,
+# ALTNAME_FLAG; indicates dual-name archive
+>8	byte		&0x80		\b, dual-name
+# security version; 0~old 2~current
+>9	ubyte		!0
+>>9	ubyte		!2		\b, security version %u
+# file type; 2 in main header; 0~binary 1~7-bitText 2~comment 3~directory 4~VolumeLabel 5=ChapterLabel
+>0xA	ubyte		!2		\b, file type %u
+# date+time when original archive was created in MS-DOS format via ./msdos
+>0xC	ulelong		x		\b, created
+>0xC	use		dos-date
+# or date and time by new internal function
+#>0xE	lemsdosdate	x		%s
+#>0xC	lemsdostime	x		%s
+# FOR DEBUGGING
+#>0x12	uleshort	x		RAW DATE %#4.4x
+#>0x10	uleshort	x		RAW TIME %#4.4x
+# date+time when archive was last modified; sometimes nil or
+# maybe wrong like in HP4DRVR.ARJ
+#>0x10	ulelong		>0		\b, modified
+#>>0x10	use		dos-date
+# or date and time by new internal function
+#>>0x12	lemsdosdate	x		%s
+#>>0x10	lemsdostime	x		%s
+# archive size (currently used only for secured archives); MAYBE?
+#>0x14	ulelong		!0		\b, file size %u
+# security envelope file position; MAYBE?
+#>0x18	ulelong		!0		\b, at %#x security envelope
+# filespec position in filename; WHAT IS THAT?
+#>0x1C	uleshort	>0		\b, filespec position %#x
+# length in bytes of security envelope data like: 2CAh 301h 364h 471h
+>0x1E	uleshort	!0		\b, security envelope length %#x
+# last chapter like: 0 1
+>0x21	ubyte		!0		\b, last chapter %u
+# filename (null-terminated string); sometimes at 0x26 when 4 bytes for extra data
+>34	byte		x		\b, original name:
+# with extras data
+>34	byte		<0x0B
+>>38	string		x		%s
+# without extras data
+>34	byte		>0x0A
+>>34	string		x		%s
+# host OS: 0~MSDOS ... 11~WIN32
+>7	byte		0		\b, os: MS-DOS
+>7	byte		1		\b, os: PRIMOS
+>7	byte		2		\b, os: Unix
+>7	byte		3		\b, os: Amiga
+>7	byte		4		\b, os: Macintosh
+>7	byte		5		\b, os: OS/2
+>7	byte		6		\b, os: Apple ][ GS
+>7	byte		7		\b, os: Atari ST
+>7	byte		8		\b, os: NeXT
+>7	byte		9		\b, os: VAX/VMS
+>7	byte		10		\b, os: WIN95
+>7	byte		11		\b, os: WIN32
 # [JW] idarc says this is also possible
 2	leshort		0xea60		ARJ archive data
+#2	leshort		0xea60
+#>2	use		arj-archive
 
 # HA archiver (Greg Roelofs, newt@uchicago.edu)
 # This is a really bad format. A file containing HAWAII will match this...
@@ -1276,6 +1497,18 @@
 !:mime	application/vnd.sun.xml.base
 !:ext	sdb
 
+# URL:	https://wiki.openoffice.org/wiki/Documentation/DevGuide/Extensions/File_Format
+# From:	Joerg Jenderek
+# Note:	only few OXT samples are detected here by mimetype member
+#	is used by OpenOffice and LibreOffice and probably also NeoOffice
+#	verified by `unzip -Zv *.oxt` or `7z l -slt *.oxt`
+>>50	string	vnd.openofficeorg.		OpenOffice
+>>>68	string	extension			\b/LibreOffice Extension
+# http://extension.nirsoft.net/oxt
+!:mime	application/vnd.openofficeorg.extension
+# like: Gallery-Puzzle.2.1.0.1.oxt
+!:ext	oxt
+
 #   OpenDocument formats (for OpenOffice 2.x / StarOffice >= 8)
 #   URL: http://fileformats.archiveteam.org/wiki/OpenDocument
 #    https://lists.oasis-open.org/archives/office/200505/msg00006.html
@@ -1513,21 +1746,43 @@
 # Felix von Leitner <felix-file@fefe.de>
 0	string	d8:announce	BitTorrent file
 !:mime	application/x-bittorrent
+!:ext	torrent
 # Durval Menezes, <jmgthbfile at durval dot com>
 0	string	d13:announce-list	BitTorrent file
 !:mime	application/x-bittorrent
+!:ext	torrent
 0	string	d7:comment	BitTorrent file
 !:mime	application/x-bittorrent
+!:ext	torrent
 0	string	d4:info		BitTorrent file
 !:mime	application/x-bittorrent
+!:ext	torrent
 
 # Atari MSA archive - Teemu Hukkanen <tjhukkan@iki.fi>
-0	beshort 0x0e0f		Atari MSA archive data
->2	beshort x		\b, %d sectors per track
->4	beshort 0		\b, 1 sided
->4	beshort 1		\b, 2 sided
->6	beshort x		\b, starting track: %d
->8	beshort x		\b, ending track: %d
+# URL:		http://fileformats.archiveteam.org/wiki/MSA_(Magic_Shadow_Archiver)
+# Reference:	http://info-coach.fr/atari/documents/_mydoc/FD_Image_File_Format.pdf
+#		http://mark0.net/download/triddefs_xml.7z/defs/m/msa.trid.xml
+# Update:	Joerg Jenderek
+# Note:		called by TrID "Atari MSA Disk Image" and verified by
+#		command like `deark -l -m msa -d2 PDATS578.msa` as " Atari ST floppy disk image"
+# GRR: line below is too general as it matches setup.skin
+0	beshort 0x0e0f
+# skip foo setup.skin with unrealistic high number 52255 of sides by check for valid "low" value
+>4	ubeshort <2		Atari MSA archive data
+#!:mime	application/octet-stream
+!:mime	application/x-atari-msa
+!:ext	msa
+# sectors per track like: 9 10
+>>2	beshort x		\b, %d sectors per track
+# sides (0 or 1; add 1 to this to get correct number of sides)
+>>4	beshort 0		\b, 1 sided
+>>4	beshort 1		\b, 2 sided
+# starting track like: 0
+>>6	beshort x		\b, starting track: %d
+# ending track like: 39 79 80 81
+>>8	beshort x		\b, ending track: %d
+# tracks content
+#>>10	ubequad x		\b, track content %#16.16llx
 
 # Alternate ZIP string (amc@arwen.cs.berkeley.edu)
 0	string	PK00PK\003\004	Zip archive data
@@ -1537,6 +1792,8 @@
 # ACE archive (from http://www.wotsit.org/download.asp?f=ace)
 # by Stefan `Sec` Zehl <sec@42.org>
 7	string		**ACE**		ACE archive data
+!:mime	application/x-ace-compressed
+!:ext	ace
 >15	byte	>0		version %d
 >16	byte	=0x00		\b, from MS-DOS
 >16	byte	=0x01		\b, from OS/2
@@ -1850,3 +2107,6 @@
 # URL: http://mattmahoney.net/dc/#paq9a
 # Note: Line 1186 of paq9a.cpp gives the magic bytes
 0	string	pQ9\001		PAQ9A archive
+
+# From wof (wof@stachelkaktus.net)
+0	string	Unison\ archive\ format	Unison archive format

+ 38 - 0
magic/Magdir/aria

@@ -0,0 +1,38 @@
+
+#------------------------------------------------------------------------------
+# URL: 		https://de.wikipedia.org/wiki/Aria_(Software)
+# Reference:	https://github.com/aria2/aria2/blob/master/doc/manual-src/en/technical-notes.rst
+# From:		Joerg Jenderek
+# Note:		only version 1 suited
+# check for valid version one
+0		beshort		0x0001
+# skip most uncompressed DEGAS med-res bitmap *.PI2 and GEM bitmap (v1) *.IMG
+# by test for valid infoHashCheck extension
+>2		ubelong&0xffFFffFE	0x00000000
+# skip DEGAS med-res bitmap DIAGRAM1.PI2 by test for valid length of download
+>>(6.L+14)	ubequad			>0
+>>>0	use     aria
+0	name	aria
+# version; (0x0000) or (0x0001); for 0 all multi-byte are in host byte order. For 1 big endian
+>0	beshort		x	aria2 control file, version %u
+#!:mime	application/octet-stream
+!:mime	application/x-aria
+!:ext	aria2
+# EXTension; if EXT[3]&1 == 1 checks whether saved InfoHash and current downloading the same; infoHashCheck extension
+>2		ubelong		!0	\b, infoHashCheck %#x
+# info hash length like: 0 14h
+>6		ubelong		!0	\b, %#x bytes info hash
+# info hash; BitTorrent InfoHash
+>>10		ubequad		x	%#16.16llx...
+# piece length; the length of the piece like: 400h 100000h
+>(6.L+10)	ubelong		x	\b, piece length 0x%x
+# total length; the total length of the download
+>(6.L+14)	ubequad		x	\b, total length %llu
+#>(6.L+14)	ubequad		x	\b, total length %#llx
+# upload length; the uploaded length of download like: 0 400h
+>(6.L+22)	ubequad		!0	\b, upload length %#llx
+# bitfield length; the length of bitfield like: 4 6 Ah 10h 13h 167h
+>(6.L+30)	ubelong		x	\b, %#x bytes bitfield
+# bitfield; bitfield which represents current download progress
+>(6.L+34)	ubequad		!0	%#llx...
+

+ 2 - 2
magic/Magdir/asf

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: asf,v 1.2 2021/04/26 15:56:00 christos Exp $
+# $File: asf,v 1.3 2022/04/25 17:33:13 christos Exp $
 # asf:  file(1) magic for Microsoft Advanced Systems Format (ASF) files
 # http://www.staroceans.org/e-book/ASF_Specification.pdf
 
@@ -88,7 +88,7 @@
 >0	guid	26F18B5D-4584-47EC-9F5F-0E651F0452C9 ASF_Compatibility_Object
 >0	guid	43058533-6981-49E6-9B74-AD12CB86D58C ASF_Advanced_Content_Encryption_Object
 >0	guid	59DACFC0-59E6-11D0-A3AC-00A0C90348F6 ASF_Command_Media
->0	guid	B61BE100-5B4E-11CF-A8FD-00805F5C44 ASF_JFIF_Media
+>0	guid	B61BE100-5B4E-11CF-A8FD-00805F5C442B ASF_JFIF_Media
 >0	guid	35907DE0-E415-11CF-A917-00805F5C442B ASF_Degradable_JPEG_Media
 >0	guid	91BD222C-F21C-497A-8B6D-5AA86BFC0185 ASF_File_Transfer_Media
 >0	guid	3AFB65E2-47EF-40F2-AC2C-70A90D71D343 ASF_Binary_Media

+ 157 - 19
magic/Magdir/audio

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: audio,v 1.121 2021/04/26 15:56:00 christos Exp $
+# $File: audio,v 1.124 2022/08/28 08:58:20 christos Exp $
 # audio:  file(1) magic for sound formats (see also "iff")
 #
 # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com),
@@ -403,10 +403,26 @@
 0	string		THX		AHX version
 >3	byte		=0		1 module data
 >3	byte		=1		2 module data
->10	byte		x		TRL: %u
->11	byte		x		TRK: %u
->12	byte		x		SMP: %u
->13	byte		x		SS: %u
+>11	ubyte		x		TRK: %u
+>10	ubyte		x		TRL: %u
+>12	ubyte		x		SMP: %u
+>13	ubyte		x		SS: %u
+>(4.H)		string		x		Title: "%.128s"
+
+# header is mostly AHX format
+0		string		HVL
+>3		byte		<2	Hively Tracker Song
+>3		byte		=0		v1 module data
+>3		byte		=1		v2 module data
+>11		ubyte		x		TRK: %u
+>10		ubyte		x		TRL: %u
+>12		ubyte		x		SMP: %u
+>13		ubyte		x		SS: %u
+>8		ubyte/4		=0		CHN: 4
+>8		ubyte/4		>0		CHN: 4+%u
+#>-0		offset		<0xffff
+>(4.H)		string		x		Title: "%.128s"
+
 #
 0	string		OKTASONG	Oktalyzer module data
 #
@@ -548,15 +564,13 @@
 # From: Alex Myczko <alex@aiei.ch>
 
 # https://github.com/rerrahkr/BambooTracker
-0	string		BambooTrackerMod	BambooTracker module
->22	byte	x	\b, version %u
->21	byte	x	\b.%u
->20	byte	x	\b.%u
-
-0	string		BambooTrackerIst	BambooTracker instrument
->22	byte	x	\b, version %u
->21	byte	x	\b.%u
->20	byte	x	\b.%u
+0	string	BambooTracker	BambooTracker
+>13	string	Mod		Module
+>13	string	Ist		Instrument
+>13	string	Bnk		Bank
+>22	byte	x		\b, version %u
+>21	byte	x		\b.%u
+>20	byte	x		\b.%u
 
 0	string		CC2x		CheeseCutter 2 song
 
@@ -894,11 +908,6 @@
 >0x3		byte&0x0F	x	\b%02d
 >>0x4		string		>\0	title: "%s"
 
-0		string		HVL
->3		byte		<2	Hively Tracker Song
->3		byte		0	1 module data
->3		byte		1	2 module data
-
 0		string		MO3
 >3		ubyte		<6	MOdule with MP3
 >>3		byte		0	Version	0	(With MP3 and lossless)
@@ -1136,3 +1145,132 @@
 >>0	use		nintendo-3ds-bcwav-fields
 >4	beshort		0xFEFF
 >>0	use		\^nintendo-3ds-bcwav-fields
+
+# Philips DSDIFF audio format (Direct Stream Digital Interchange File Format)
+# Used for DSD audio recordings and Super Audio CD (SACD) mastering annotations
+# https://dsd-guide.com/sites/default/files/white-papers/DSDIFF_1.5_Spec.pdf
+# From: Toni Ruottu <toni.ruottu@iki.fi>
+0		string		FRM8
+12		string		DSD\x20		DSDIFF audio bitstream data
+!:mime		audio/x-dff
+!:ext		dff
+
+# format version chunk
+>&0		string		FVER
+# version 1
+>>&8		byte		1
+
+# v1 / sampling resolution ( 1 bit PDM only )
+>>>&0		string		x		\b, 1 bit
+
+# v1 / sound property chunk
+>>>&0		search/0xff	PROP
+>>>>&8		string		SND
+
+# v1 / sound property chunk / channel configuration chunk
+>>>>>&0		search/0xff	CHNL
+>>>>>>&8	ubeshort	1							\b, mono
+>>>>>>&8	ubeshort	2
+>>>>>>>&0	string		SLFTSRGT						\b, stereo
+>>>>>>>&0	default		x							\b, 2 channels
+>>>>>>&8	ubeshort	3
+>>>>>>>&0	string		SLFTSRGTLFE\x20						\b, 2.1 stereo
+>>>>>>>&0	string		SLFTSRGTC\x20\x20\x20					\b, 3.0 stereo
+>>>>>>>&0	default		x							\b, 3 channels
+>>>>>>&8	ubeshort	4
+>>>>>>>&0	string		MLFTMRGTLS\x20\x20RS\x20\x20				\b, 4.0 surround
+>>>>>>>&0	string		SLFTSRGTC\x20\x20\x20LFE\x20				\b, 3.1 stereo
+>>>>>>>&0	default		x							\b, 4 channels
+>>>>>>&8	ubeshort	5
+>>>>>>>&0	string		MLFTMRGTC\x20\x20\x20LS\x20\x20RS\x20\x20		\b, 5.0 surround
+>>>>>>>&0	string		MLFTMRGTLFE\x20LS\x20\x20RS\x20\x20			\b, 4.1 surround
+>>>>>>>&0	default		x							\b, 5 channels
+>>>>>>&8	ubeshort	6
+>>>>>>>&0	string		MLFTMRGTC\x20\x20\x20LFE\x20LS\x20\x20RS\x20\x20	\b, 5.1 surround
+>>>>>>>&0	default		x							\b, 6 channels
+>>>>>>&8	ubeshort	>6							\b, %u channels
+
+# v1 / sound property chunk / sample rate chunk
+>>>>>&0		search/0xff	FS\x20\x20
+>>>>>>&0	string		x		\b,
+>>>>>>&8	ubelong%44100	0
+>>>>>>>&-4	ubelong/44100	x		"DSD %u"
+>>>>>>>&-4	ubelong		x		%u Hz
+
+# v1 / sound property chunk / compression type chunk
+>>>>>&0		search/0xff	CMPR
+>>>>>>&8	string		DSD\x20		\b, no compression
+>>>>>>&8	string		DST\x20		\b, DST compression
+>>>>>>&8	default		x		\b, unknown compression
+
+# v1 / quest for metadata
+>>>&0		string		x
+
+# v1 / quest for metadata / edited master information chunk
+>>>>&0		search		DIIN
+>>>>>&0		ubequad		>0		\b, "edited master" metadata
+
+# v1 / quest for metadata / ID3 chunk ( defacto standard )
+>>>>&0		search		ID3\x20
+>>>>>&8		string		ID3		\b, ID3 version 2
+>>>>>&0		byte		x		\b.%u
+>>>>>&1		byte		x		\b.%u
+
+# v1 / quest for metadata / failure ( possibly due to -P bytes=... being too low )
+>>>>&0		default		x		\b, ID3 missing (or unreachable)
+
+# version > 1 or 0
+>>&0		default		x		\b, unknown version
+
+# Sony DSF audio format (Direct Stream Digital Stream File)
+# Used for lossless digital storage of songs produced as DSD audio
+# Portable analog of a track stored on a Super Audio CD (SACD)
+# https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf
+# From: Toni Ruottu <toni.ruottu@iki.fi>
+0		string		DSD\x20		DSF audio bitstream data
+!:mime		audio/x-dsf
+!:ext		dsf
+
+# format chunk
+>28		string		fmt\x20
+# version 1
+>>&8		ulelong		1
+
+# v1 / sampling resolution ( 1 bit PDM only )
+# NOTE: the spec incorrectly uses "bits per sample" instead of "bits per byte"
+>>>&0		string		x		\b, 1 bit
+
+# v1 / channel configuration
+>>>>&4		ulelong		1		\b, mono
+>>>>&4		ulelong		2		\b, stereo
+>>>>&4		ulelong		3		\b, 3.0 stereo
+>>>>&4		ulelong		4		\b, 4.0 surround
+>>>>&4		ulelong		5		\b, 3.1 stereo
+>>>>&4		ulelong		6		\b, 5.0 surround
+>>>>&4		ulelong		7		\b, 5.1 surround
+>>>>&0		default		x
+>>>>>&4		ulelong		x		\b, %u channels
+
+# v1 / sample rate chunk
+>>>>&0		string		x		\b,
+>>>>&12		ulelong%44100	0
+>>>>>&-4	ulelong/44100	x		"DSD %u"
+>>>>&12		ulelong		x		%u Hz
+
+# v1 / compression
+>>>>&0		string		x
+>>>>>&0		ulelong		0		\b, no compression
+>>>>>&0		default		x		\b, unknown compression
+
+# v1 / embedded ID3v2 metadata
+>>>0		string		x 		\b, ID3
+>>>>20		ulequad		!0
+>>>>>(20.q)	string		ID3		version 2
+>>>>>>&0	byte		x		\b.%u
+>>>>>>&1	byte		x		\b.%u
+# unable to verify ID3 ( possibly due to -P bytes=... being too low )
+>>>>>&0		default		x		unreachable
+>>>>&0		default		x		missing
+
+# version > 1 or 0
+>>&0		default		x		\b, unknown version

+ 7 - 0
magic/Magdir/burp

@@ -0,0 +1,7 @@
+
+#------------------------------------------------------------
+# $File: burp,v 1.1 2022/07/04 17:15:09 christos Exp $
+# Burp file, I don't know the version
+#------------------------------------------------------------
+# From wof (wof@stachelkaktus.net)
+0	bequad	0x6685828000000001	Burp project save file

+ 2 - 2
magic/Magdir/bytecode

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------
-# $File: bytecode,v 1.2 2021/06/30 11:57:32 christos Exp $
+# $File: bytecode,v 1.3 2022/03/24 15:48:58 christos Exp $
 # magic for various bytecodes
 
 # From: Mikhail Gusarov <dottedmag@dottedmag.net>
@@ -27,4 +27,4 @@
 >8	string	BE		\b, big endian
 >11	string	4		\b, 32bit
 >11	string	8		\b, 64bit
->13	regex	.\..		\b, bytecode v%s
+>13	regex	.\\..		\b, bytecode v%s

+ 139 - 2
magic/Magdir/c64

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: c64,v 1.9 2021/04/26 15:56:00 christos Exp $
+# $File: c64,v 1.12 2022/05/14 20:03:39 christos Exp $
 # c64:  file(1) magic for various commodore 64 related files
 #
 # From: Dirk Jagdmann <doj@cubic.org>
@@ -8,9 +8,146 @@
 0x16500	belong		0x12014100	D64 Image
 0x16500	belong		0x12014180	D71 Image
 0x61800 belong		0x28034400	D81 Image
-0	string		C64\40CARTRIDGE	CCS C64 Emultar Cartridge Image
 0	belong		0x43154164	X64 Image
 
+# C64 (and other CBM) cartridges
+# Extended by David Korth <gerbilsoft@gerbilsoft.com>
+# Reference: https://vice-emu.sourceforge.io/vice_17.html#SEC391
+
+0	string		C64\40CARTRIDGE	Commodore 64 cartridge
+>0x20	ubyte	0	\b,
+>0x20	ubyte	!0
+>>0x20	string/T	x	\b: "%.32s",
+>0x16	beshort	0
+>>0x18	beshort	0x0000	16 KB game
+>>0x18	beshort	0x0001	8 KB game
+>>0x18	beshort	0x0100	UltiMax mode
+>>0x18	beshort	0x0101	RAM/disabled
+>0x16	beshort	1	Action Replay
+>0x16	beshort	2	KCS Power Cartridge
+>0x16	beshort	3	Final Cartridge III
+>0x16	beshort	4	Simons' BASIC
+>0x16	beshort	5	Ocean type 1
+>0x16	beshort	6	Expert Cartridge
+>0x16	beshort	7	Fun Play, Power Play
+>0x16	beshort	8	Super Games
+>0x16	beshort	9	Atomic Power
+>0x16	beshort	10	Epyx Fastload
+>0x16	beshort	11	Westermann Learning
+>0x16	beshort	12	Rex Utility
+>0x16	beshort	13	Final Cartridge I
+>0x16	beshort	14	Magic Formel
+>0x16	beshort	15	C64 Game System, System 3
+>0x16	beshort	16	Warp Speed
+>0x16	beshort	17	Dinamic
+>0x16	beshort	18	Zaxxon / Super Zaxxon (Sega)
+>0x16	beshort	19	Magic Desk, Domark, HES Australia
+>0x16	beshort	20	Super Snapshot V5
+>0x16	beshort	21	Comal-80
+>0x16	beshort	22	Structured BASIC
+>0x16	beshort	23	Ross
+>0x16	beshort	24	Dela EP64
+>0x16	beshort	25	Dela EP7x8
+>0x16	beshort	26	Dela EP256
+>0x16	beshort	27	Rex EP256
+>0x16	beshort	28	Mikro Assembler
+>0x16	beshort	29	Final Cartridge Plus
+>0x16	beshort	30	Action Replay 4
+>0x16	beshort	31	Stardos
+>0x16	beshort	32	EasyFlash
+>0x16	beshort	33	EasyFlash Xbank
+>0x16	beshort	34	Capture
+>0x16	beshort	35	Action Replay 3
+>0x16	beshort	36
+>>0x1A	ubyte	1	Nordic Replay
+>>0x1A	ubyte	!1	Retro Replay
+>0x16	beshort	37	MMC64
+>0x16	beshort	38	MMC Replay
+>0x16	beshort	39	IDE64
+>0x16	beshort	40	Super Snapshot V4
+>0x16	beshort	41	IEEE-488
+>0x16	beshort	42	Game Killer
+>0x16	beshort	43	Prophet64
+>0x16	beshort	44	EXOS
+>0x16	beshort	45	Freeze Frame
+>0x16	beshort	46	Freeze Machine
+>0x16	beshort	47	Snapshot64
+>0x16	beshort	48	Super Explode V5.0
+>0x16	beshort	49	Magic Voice
+>0x16	beshort	50	Action Replay 2
+>0x16	beshort	51	MACH 5
+>0x16	beshort	52	Diashow-Maker
+>0x16	beshort	53	Pagefox
+>0x16	beshort	54	Kingsoft
+>0x16	beshort	55	Silverrock 128K Cartridge
+>0x16	beshort	56	Formel 64
+>0x16	beshort	57
+>>0x1A	ubyte	1	Hucky
+>>0x1A	ubyte	!1	RGCD
+>0x16	beshort	58	RR-Net MK3
+>0x16	beshort	59	EasyCalc
+>0x16	beshort	60	GMod2
+>0x16	beshort	61	MAX Basic
+>0x16	beshort	62	GMod3
+>0x16	beshort	63	ZIPP-CODE 48
+>0x16	beshort	64	Blackbox V8
+>0x16	beshort	65	Blackbox V3
+>0x16	beshort	66	Blackbox V4
+>0x16	beshort	67	REX RAM-Floppy
+>0x16	beshort	68	BIS-Plus
+>0x16	beshort	69	SD-BOX
+>0x16	beshort	70	MultiMAX
+>0x16	beshort	71	Blackbox V9
+>0x16	beshort	72	Lt. Kernal Host Adaptor
+>0x16	beshort	73	RAMLink
+>0x16	beshort	74	H.E.R.O.
+>0x16	beshort	75	IEEE Flash! 64
+>0x16	beshort	76	Turtle Graphics II
+>0x16	beshort	77	Freeze Frame MK2
+
+0	string		C128\40CARTRIDGE	Commodore 128 cartridge
+>0x20	ubyte	0	\b,
+>0x20	ubyte	!0
+>>0x20	string/T	x	\b: "%.32s",
+>0x16	beshort	0	generic cartridge
+>0x16	beshort	1	Warpspeed128
+>>0x1A	ubyte	1	\b, REU support
+>>0x1A	ubyte	2	\b, REU support, with I/O and ROM banking
+
+0	string		CBM2\40CARTRIDGE	Commodore CBM-II cartridge
+>0x20	ubyte	!0
+>>0x20	string/T	x	\b: "%.32s"
+
+0	string		VIC20\40CARTRIDGE	Commodore VIC-20 cartridge
+>0x20	ubyte	0	\b,
+>0x20	ubyte	!0
+>>0x20	string/T	x	\b: "%.32s",
+>0x16	beshort	0	generic cartridge
+>0x16	beshort	1	Mega-Cart
+>0x16	beshort	2	Behr Bonz
+>0x16	beshort	3	Vic Flash Plugin
+>0x16	beshort	4	UltiMem
+>0x16	beshort	5	Final Expansion
+
+0	string		PLUS4\40CARTRIDGE	Commodore 16/Plus4 cartridge
+>0x20	ubyte	!0
+>>0x20	string/T	x	\b: "%.32s"
+
+
+# DreamLoad archives see:
+# https://www.lemon64.com/forum/viewtopic.php?t=37415\
+# &sid=494dc2ca91289e05dadf80a7f8a968fe (at the bottom).
+# https://www.c64-wiki.com/wiki/DreamLoad.
+# Example HVSC Commodore 64 music collection:
+# https://kohina.duckdns.org/HVSC/C64Music/10_Years_HVSC.dfi
+
+0	byte	0
+>1	string	DREAMLOAD\40FILE\40ARCHIVE
+>>0x17	byte	0	DFI Image
+>>>0x1a	leshort	x	version: %d.
+>>>0x18	leshort	x	\b%d
+>>>0x1c	lelong	x	tracks: %d
+
 0	string		GCR-1541	GCR Image
 >8	byte		x		version: %i
 >9	byte		x		tracks: %i

+ 3 - 1
magic/Magdir/cad

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: cad,v 1.28 2021/04/26 15:56:00 christos Exp $
+# $File: cad,v 1.29 2021/12/06 19:33:27 christos Exp $
 # autocad:  file(1) magic for cad files
 #
 
@@ -287,6 +287,8 @@
 >6	leshort		0x2
 >>8	lelong		0xa
 >>>16	leshort		0x3d3d	3D Studio model
+# Beat sgi MMV
+!:strength +20
 !:mime	image/x-3ds
 !:ext 3ds
 

+ 7 - 1
magic/Magdir/cafebabe

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: cafebabe,v 1.27 2021/04/26 15:56:00 christos Exp $
+# $File: cafebabe,v 1.28 2022/07/01 23:24:47 christos Exp $
 # Cafe Babes unite!
 #
 # Since Java bytecode and Mach-O universal binaries have the same magic number,
@@ -44,6 +44,12 @@
 >>4	belong		0x0038		(Java SE 12)
 >>4	belong		0x0039		(Java SE 13)
 >>4	belong		0x003A		(Java SE 14)
+>>4	belong		0x003B		(Java SE 15)
+>>4	belong		0x003C		(Java SE 16)
+>>4	belong		0x003D		(Java SE 17)
+>>4	belong		0x003E		(Java SE 18)
+>>4	belong		0x003F		(Java SE 19)
+>>4	belong		0x0040		(Java SE 20)
 # pool count unequal zero
 #>>8	beshort		x	        \b, pool count %#x
 # pool table

+ 14 - 0
magic/Magdir/ccf

@@ -0,0 +1,14 @@
+
+#------------------------------------------------------------------------------
+# $File: ccf,v 1.1 2022/02/15 12:57:45 christos Exp $
+# file(1) magic(5) data for Phillips remote controls
+
+# Exchange format for Philips Pronto universal infrared remote controls
+# A CCF file describes a learned/customized remote control,
+# i.e. it contains button UI and infrared pulse code definitions
+# (Georg Sauthoff)
+# http://files.remotecentral.com/download/45/pan-air-csakr.zip.html
+# https://github.com/gsauthof/pronto-ccf/blob/
+
+8	string	@\xa5Z@_CCF
+>32	string	CCF\x00		Philips Pronto IR remote control CCF

+ 29 - 3
magic/Magdir/commands

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: commands,v 1.66 2021/07/03 13:50:29 christos Exp $
+# $File: commands,v 1.69 2022/04/20 21:14:23 christos Exp $
 # commands:  file(1) magic for various shells and interpreters
 #
 #0	string/w	:			shell archive or script for antique kernel text
@@ -35,7 +35,7 @@
 !:mime	text/x-shellscript
 0	string/fwt	#!\ /usr/local/bin/zsh	Paul Falstad's zsh script text executable
 !:mime	text/x-shellscript
-0	search/1	#!/usr/bin/env\ zsh	Paul Falstad's zsh script text executable
+0	string/fwt	#!\ /usr/bin/env\ zsh	Paul Falstad's zsh script text executable
 !:mime	text/x-shellscript
 
 0	string/fwt	#!\ /bin/ash		Neil Brown's ash script text executable
@@ -98,7 +98,7 @@
 !:mime	text/x-shellscript
 
 0	string/wt	#!\ 	a
->&-1	string		x	%s script text executable
+>&-1	string/T	x	%s script text executable
 
 0	search/1/fwt	#!\ /usr/bin/tclsh	Tcl/Tk script text executable
 !:mime  text/x-tcl
@@ -153,6 +153,32 @@
 
 0	string		Zend\x00		PHP script Zend Optimizer data
 
+# From: Anatol Belski <ab@php.net>
+0	string		OPCACHE
+>7	ubyte		0			PHP opcache filecache data
+
+0	search/64	--TEST--
+>16	search/64	--FILE--
+>24	search/8192	--EXPECT		PHP core test
+!:ext	phpt
+
+# https://www.php.net/manual/en/phar.fileformat.signature.php
+-4	string		GBMB			PHP phar archive
+>-8	ubyte		0x1			with MD5 signature
+!:ext	phar
+>-8	ubyte		0x2			with SHA1 signature
+!:ext	phar
+>-8	ubyte		0x3			with SHA256 signature
+!:ext	phar
+>-8	ubyte		0x4			with SHA512 signature
+!:ext	phar
+>-8	ubyte		0x10			with OpenSSL signature
+!:ext	phar
+>-8	ubyte		0x11			with OpenSSL SHA256 signature
+!:ext	phar
+>-8	ubyte		0x12			with OpenSSL SHA512 signature
+!:ext	phar
+
 0	string/t	$!			DCL command file
 
 # Type: Pdmenu

+ 2 - 1
magic/Magdir/compress

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: compress,v 1.82 2021/06/30 08:11:29 christos Exp $
+# $File: compress,v 1.83 2022/08/16 11:16:39 christos Exp $
 # compress:  file(1) magic for pure-compression formats (no archives)
 #
 # compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc.
@@ -147,6 +147,7 @@
 # bzip2
 0	string		BZh		bzip2 compressed data
 !:mime	application/x-bzip2
+!:ext	bz2
 >3	byte		>47		\b, block size = %c00k
 
 # bzip	a block-sorting file compressor

+ 71 - 32
magic/Magdir/console

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: console,v 1.63 2021/04/26 15:56:00 christos Exp $
+# $File: console,v 1.68 2022/05/14 20:04:43 christos Exp $
 # Console game magic
 # Toby Deshane <hac@shoelace.digivill.net>
 
@@ -78,8 +78,8 @@
 >23	byte	!1		FMC-
 >23	byte	1		FSC-
 >16	string	x		\b%.3s
->15	byte	x		\b, mfr %02X
->20	byte	x		(Rev.%02u)
+>15	ubyte	x		\b, mfr %02X
+>20	ubyte	x		(Rev.%02u)
 
 # Headered version.
 0	string	FDS\x1A
@@ -228,21 +228,56 @@
 >0x10	use	sega-mega-drive-header
 >0	byte	x			\b, 2352-byte sectors
 
-# Sega Mega Drive, 32X, Pico, and Mega CD Boot ROM images.
+# Sega Mega Drive: Identify the system ID.
 0x100		string	SEGA
->0x3C0		bequad	0x4D41525320434845	Sega 32X ROM image
+>0x3C0		string	MARS\ CHECK\ MODE	Sega 32X ROM image
 !:mime		application/x-genesis-32x-rom
 >>0		use	sega-mega-drive-header
->0x3C0		bequad	!0x4D41525320434845
->>0x105		belong	0x5049434F	Sega Pico ROM image
+>0x104		string	\ PICO			Sega Pico ROM image
 !:mime		application/x-sega-pico-rom
->>>0		use	sega-mega-drive-header
->>0x105		belong	!0x5049434F
->>>0x180	beshort	0x4252		Sega Mega CD Boot ROM image
+>>0		use	sega-mega-drive-header
+>0x104		string	TOYS\ PICO		Sega Pico ROM image
+!:mime		application/x-sega-pico-rom
+>>0		use	sega-mega-drive-header
+>0x104		string	\ TOYS\ PICO		Sega Pico ROM image
+!:mime		application/x-sega-pico-rom
+>>0		use	sega-mega-drive-header
+>0x104		string	\ IAC			Sega Pico ROM image
+!:mime		application/x-sega-pico-rom
+>>0		use	sega-mega-drive-header
+>0x104		string	\ TERA68K		Sega Teradrive (68K) ROM image
+!:mime		application/x-sega-teradrive-rom
+>>0		use	sega-mega-drive-header
+>0x104		string	\ TERA286		Sega Teradrive (286) ROM image
+!:mime		application/x-sega-teradrive-rom
+>>0		use	sega-mega-drive-header
+>0x180		string	BR			Sega Mega CD Boot ROM image
 !:mime		application/x-genesis-rom
->>>0x180	beshort	!0x4252		Sega Mega Drive / Genesis ROM image
+>>0		use	sega-mega-drive-header
+>0x104		default	x			Sega Mega Drive / Genesis ROM image
 !:mime		application/x-genesis-rom
->>>0		use	sega-mega-drive-header
+>>0		use	sega-mega-drive-header
+
+# Sega Mega Drive: Some ROMs have "SEGA" at 0x101, not 0x100.
+0x100		string	\ SEGA			Sega Mega Drive / Genesis ROM image
+>0		use	sega-mega-drive-header
+
+# Sega Pico ROMs that don't start with "SEGA".
+0x100		string	SAMSUNG\ PICO		Samsung Pico ROM image
+!:mime		application/x-sega-pico-rom
+>0		use	sega-mega-drive-header
+0x100		string	IMA\ IKUNOUJYUKU	Samsung Pico ROM image
+!:mime		application/x-sega-pico-rom
+>0		use	sega-mega-drive-header
+0x100		string	IMA IKUNOJYUKU		Samsung Pico ROM image
+!:mime		application/x-sega-pico-rom
+>0		use	sega-mega-drive-header
+
+# Sega Picture Magic (modified 32X)
+0x100		string	Picture\ Magic
+>0x3C0		string	PICTURE MAGIC-01	Sega 32X ROM image
+!:mime		application/x-genesis-32x-rom
+>>0		use	sega-mega-drive-header
 
 #------------------------------------------------------------------------------
 # genesis: file(1) magic for the Super MegaDrive ROM dump format
@@ -474,12 +509,13 @@
 # - https://neogpc.googlecode.com/svn-history/r10/trunk/src/core/neogpc.cpp
 # - https://www.devrs.com/ngp/files/ngpctech.txt
 #
-0x0A	string	BY\ SNK\ CORPORATION	Neo Geo Pocket
+0x0A	string		BY\ SNK\ CORPORATION	Neo Geo Pocket
 !:mime	application/x-neo-geo-pocket-rom
->0x23	byte	0x10			Color
->0	byte	x			ROM image
->0x24	string	>\0			\b: "%.12s"
->0x1F	byte	0xFF			(debug mode enabled)
+>0x23	byte		0x10			Color
+>0	byte		x			ROM image
+>0x24	string		>\0			\b: "%.12s"
+>0x21	uleshort	x			\b, NEOP%04X
+>0x1F	ubyte		0xFF			(debug mode enabled)
 
 #------------------------------------------------------------------------------
 # msx: file(1) magic for MSX game cartridge dumps
@@ -639,17 +675,21 @@
 >>0	use	xbox-360-package
 
 # Atari Lynx cartridge dump (EXE/BLL header)
-# From: "Stefan A. Haubenthal" <polluks@web.de>
-
+# From: "Stefan A. Haubenthal" <polluks@sdf.lonestar.org>
+# Reference:
+# https://raw.githubusercontent.com/cc65/cc65/master/libsrc/lynx/exehdr.s
 # Double-check that the image type matches too, 0x8008 conflicts with
 # 8 character OMF-86 object file headers.
 0	beshort		0x8008
 >6	string		BS93		Lynx homebrew cartridge
 !:mime	application/x-atari-lynx-rom
 >>2	beshort		x		\b, RAM start $%04x
->6	string		LYNX		Lynx cartridge
+0	string		LYNX		Lynx cartridge
 !:mime	application/x-atari-lynx-rom
->>2	beshort		x		\b, RAM start $%04x
+>4	leshort/4	>0		\b, bank 0 %dk
+>6	leshort/4	>0		\b, bank 1 %dk
+>10	string		>\0		\b, "%.32s"
+>42	string		>\0		\b, "%.16s"
 
 # Opera file system that is used on the 3DO console
 # From: Serge van den Boom <svdb@stack.nl>
@@ -898,6 +938,16 @@
 !:mime	application/x-gamecube-rom
 >>>>0x8000	use	nintendo-gcn-disc-common
 
+# Type: Nintendo GameCube/Wii disc image (RVZ format)
+0	string		RVZ\001	Nintendo
+>0x48	belong		1	GameCube
+!:mime	application/x-gamecube-rom
+>0x48	belong		2	Wii
+!:mime	application/x-wii-rom
+>0x48	default		x	GameCube/Wii
+>0x48	belong		x	disc image (RVZ format):
+>>0x58	use		nintendo-gcn-disc-common
+
 #------------------------------------------------------------------------------
 # Nintendo 3DS file formats.
 #
@@ -1126,14 +1176,3 @@
 >>0x34	ubyte		1	[FastROM]
 >>0x35	ubyte		1	[SRAM]
 >>0x35	ubyte		3	[Special]
-
-# Type: Nintendo GameCube/Wii disc image (RVZ format)
-0	string		RVZ\001	Nintendo
->0x48	belong		1	GameCube
-!:mime	application/x-gamecube-rom
->0x48	belong		2	Wii
-!:mime	application/x-wii-rom
->0x48	default		x	GameCube/Wii
->0x48	belong		x	disc image (RVZ format):
->>0x58	use		nintendo-gcn-disc-common
-

+ 1 - 1
magic/Magdir/ctf

@@ -20,4 +20,4 @@
 # CTF metadata (plain text)
 0	string	/*\x20CTF\x20   Common Trace Format (CTF) plain text metadata
 !:strength + 5			# this is to make sure we beat C
->&0	regex	[0-9]+\.[0-9]+	\b, v%s
+>&0	regex	[0-9]+\\.[0-9]+	\b, v%s

+ 16 - 6
magic/Magdir/database

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: database,v 1.63 2021/10/04 00:44:30 christos Exp $
+# $File: database,v 1.67 2022/07/12 18:57:42 christos Exp $
 # database:  file(1) magic for various databases
 #
 # extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk)
@@ -151,6 +151,7 @@
 # https://www.clicketyclick.dk/databases/xbase/format/dbf.html
 # inspect VVYYMMDD , where 1<= MM <= 12 and 1<= DD <= 31
 0	ubelong&0x0000FFFF		<0x00000C20
+!:strength +10
 # skip Infocom game Z-machine
 >2		ubyte			>0
 # skip Androids *.xml
@@ -399,14 +400,18 @@
 >>>>>>>>>>4	ushort		0
 # check for valid FoxPro field type
 >>>>>>>>>>>512	ubelong		<3
->>>>>>>>>>>>0	use		foxpro-memo-print
+# skip LXMDCLN4.OUT LXMDCLN6.OUT LXMDALG6.OUT with invalid blocksize 170=AAh
+>>>>>>>>>>>>6	ubeshort&0x002f	0
+>>>>>>>>>>>>>0	use		foxpro-memo-print
 # dBASE III DBT , garbage
 # skip WORD1XW.DOC with improbably high free block index
 >>>>>>>>>0	ulelong		<0x400000
 # skip WinStore.App.exe by looking for printable 2nd character of 1st memo item
 >>>>>>>>>>513	ubyte		>037
+# skip DOS executables CPQ0TD.DRV E30ODI.COM IBM0MONO.DRV by looking for printable 1st character of 1st memo item
+>>>>>>>>>>>512	ubyte		>037
 # unusual dBASE III DBT like adressen.dbt
->>>>>>>>>>>0	use		dbase3-memo-print
+>>>>>>>>>>>>0	use		dbase3-memo-print
 # dBASE III DBT like angest.dbt, or garbage PCX DBF
 >>>>>>>>8	ubelong		!0
 # skip PCX and some DBF by test for for reserved NULL bytes
@@ -415,9 +420,11 @@
 >>>>>>>>>>0	ulelong		<0x400000
 # skip AI070GEP.EPS by printable 1st character of 1st memo item
 >>>>>>>>>>>512	ubyte		>037
+# skip some Microsoft Visual C, OMF library like: BZ2.LIB WATTCPWL.LIB ZLIB.LIB
+>>>>>>>>>>>>512	ubyte		<0200
 # skip gluon-ffhat-1.0-tp-link-tl-wr1043n-nd-v2-sysupgrade.bin by printable 2nd character
->>>>>>>>>>>>513	ubyte		>037
->>>>>>>>>>>>>0	use		dbase3-memo-print
+>>>>>>>>>>>>>513 ubyte		>037
+>>>>>>>>>>>>>>0	use		dbase3-memo-print
 # dBASE IV DBT with positive block size
 >>>>>>>20	uleshort	>0
 # dBASE IV DBT with valid block length like 512, 1024
@@ -440,7 +447,10 @@
 #>20	uleshort		=0		\b, block length %u
 >20	uleshort		!0		\b, block length %u
 # dBase III memo field terminated by \032\032
+# like: "WHAT IS XBASE" test.dbt "Borges, Malte" biblio.dbt "First memo\032\032" T2.DBT
 >512	string			>\0		\b, 1st item "%s"
+# For DEBUGGING
+#>512	ubelong			x		\b, 1ST item %#8.8x
 # https://www.clicketyclick.dk/databases/xbase/format/dbt.html
 #		Print the information of dBase IV DBT memo file
 0	name				dbase4-memo-print
@@ -486,7 +496,7 @@
 >0		belong		x		FoxPro FPT
 !:mime	application/x-fpt
 !:ext	fpt
-# Size of blocks for FoxPro ( 64,256 )
+# Size of blocks for FoxPro ( 64,256 ); probably a multiple of two
 >6		ubeshort	x		\b, blocks size %u
 # next available block
 #>0		belong		=0		\b, next free block index %u

+ 14 - 14
magic/Magdir/dataone

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: dataone,v 1.2 2019/04/19 00:42:27 christos Exp $
+# $File: dataone,v 1.3 2022/04/18 21:38:10 christos Exp $
 #
 # DataONE- files from Dave Vieglais <dave.vieglais@gmail.com> &
 #                     Pratik Shrivastava <pratikshrivastava23@gmail.com>
@@ -9,39 +9,39 @@
 #------------------------------------------------------------------------------
 
 # EML (Ecological Metadata Language Format)
-0	string	<?xml
->&0	regex	(eml)-[0-9].[0-9].[0-9]+	eml://ecoinformatics.org/%s
+0	string	\<?xml\ version=
+>&0	regex/1024	eml-[0-9]\\.[0-9]\\.[0-9]+	eml://ecoinformatics.org/%s
 
 # onedcx (DataONE Dublin Core Extended v1.0)
->&0	regex	(onedcx/v)[0-9].[0-9]+		https://ns.dataone.org/metadata/schema/onedcx/v1.0
+>&0	regex/1024	onedcx/v[0-9]\\.[0-9]+		https://ns.dataone.org/metadata/schema/onedcx/v1.0
 
 # FGDC-STD-001-1998 (Content Standard for Digital Geospatial Metadata,
 # version 001-1998)
->&0	regex	fgdc				FGDC-STD-001-1998
+>&0	search/1024	fgdc				FGDC-STD-001-1998
 
 # Mercury (Oak Ridge National Lab Mercury Metadata version 1.0)
->&0	regex	(mercury/terms/v)[0-9].[0-9]	https://purl.org/ornl/schema/mercury/terms/v1.0
+>&0	regex/1024	mercury/terms/v[0-9]\\.[0-9]	https://purl.org/ornl/schema/mercury/terms/v1.0
 
 # ISOTC211 (Geographic MetaData (GMD) Extensible Markup Language)
->&0	regex	isotc211
->>&0	regex	eng;USA				https://www.isotc211.org/2005/gmd
+>&0	search/1024	isotc211
+>>&0	search/1024	eng;USA				https://www.isotc211.org/2005/gmd
 
 # ISOTC211 (NOAA Variant Geographic MetaData (GMD) Extensible Markup Language)
->>&0	regex	gov.noaa.nodc:[0-9]+		https://www.isotc211.org/2005/gmd-noaa
+>>&0	regex/1024	gov\\.noaa\\.nodc:[0-9]+		https://www.isotc211.org/2005/gmd-noaa
 
 # ISOTC211 PANGAEA Variant Geographic MetaData (GMD) Extensible Markup Language
->>&0	regex	pangaea.dataset[0-9][0-9][0-9][0-9][0-9][0-9]+	https://www.isotc211.org/2005/gmd-pangaea
+>>&0	regex/1024	pangaea\\.dataset[0-9][0-9][0-9][0-9][0-9][0-9]+	https://www.isotc211.org/2005/gmd-pangaea
 !:mime	text/xml
 
 
 # Object Reuse and Exchange Vocabulary
-0	string	<?xml
->&0	regex	rdf
->>&0	regex	openarchives	https://www.openarchives.org/ore/terms
+0	string	\<?xml\ version=
+>&0	search/1024	rdf
+>>&0	search/1024	openarchives	https://www.openarchives.org/ore/terms
 !:mime application/rdf+xml
 
 
 # Dryad Metadata Application Profile Version 3.1
 0	string	<DryadData
->&0	regex	(dryad-bibo/v)[0-9].[0-9]	https://datadryad.org/profile/v3.1
+>&0	regex/1024	dryad-bibo/v[0-9]\\.[0-9]	https://datadryad.org/profile/v3.1
 !:mime	text/xml

+ 7 - 7
magic/Magdir/der

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: der,v 1.4 2021/03/14 17:12:04 christos Exp $
+# $File: der,v 1.5 2022/07/30 18:07:34 christos Exp $
 # der: file(1) magic for DER encoded files
 #
 
@@ -110,9 +110,9 @@
 >>>>&0	der	seq
 >>>>>&0	der	obj_id9=2a864886f70d010901
 >>>>>&0	der	ia5_str=x	\b, emailAddress=%s
->>&0	der	seq
->>>&0	der	utc_time=x	\b, utcTime=%s
->>>&0	der	utc_time=x	\b, utcTime=%s
+#>>&0	der	seq
+#>>>&0	der	utc_time=x	\b, utcTime=%s
+#>>>&0	der	utc_time=x	\b, utcTime=%s
 >>&0	use	certinfo
 
 0	der	seq
@@ -129,9 +129,9 @@
 >>>>&0	der	seq	
 >>>>>&0	der     obj_id3=550403
 >>>>>&0	der     utf8_str=x      \b, Issuer=%s
->>&0	der	seq
->>>&0	der	utc_time=x	\b, not-valid-before=%s
->>>&0	der	utc_time=x	\b, not-valid-after=%s
+#>>&0	der	seq
+#>>>&0	der	utc_time=x	\b, not-valid-before=%s
+#>>>&0	der	utc_time=x	\b, not-valid-after=%s
 >>&0	der	seq
 >>>&0	der	set
 >>>>&0	der	seq

+ 25 - 0
magic/Magdir/dsf

@@ -0,0 +1,25 @@
+
+#------------------------------------------------------------
+# $File: dsf,v 1.1 2022/01/08 16:29:18 christos Exp $
+# dsf:  file(1) magic for DSD Stream File
+# URL:          https://en.wikipedia.org/wiki/Direct_Stream_Digital
+# Reference:    https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf
+0	string	DSD\x20		DSD Stream File,
+>0x30	leshort	1		mono,
+>0x30	leshort	2		stereo,
+>0x30	leshort	3		three-channel,
+>0x30	leshort	4		quad-channel,
+>0x30	leshort	5		3.1 4-channel,
+>0x30	leshort	6		five-channel,
+>0x30	leshort	7		5.1 surround,
+>0x30	default	x	
+>>0x30	leshort	x		unknown channel format (%d),
+>0x38	lelong	2822400		simple-rate,
+>0x38	lelong	5644800		double-rate,
+>0x38	default	x	
+>>0x38	lelong	x		%d Hz,
+>0x3c	leshort	1		1 bit,
+>0x3c	leshort	8		8 bit,
+>0x3c	default	x
+>>0x3c	leshort	x		%d bit,
+>0x40	lelong	x		%d samples

+ 187 - 4
magic/Magdir/filesystems

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: filesystems,v 1.145 2021/09/07 18:57:50 christos Exp $
+# $File: filesystems,v 1.150 2022/07/04 16:40:33 christos Exp $
 # filesystems:  file(1) magic for different filesystems
 #
 0	name	partid
@@ -2317,6 +2317,8 @@
 >0x10070	lequad		x		\b%lld bytes used,
 >0x10088	lequad		x		%lld devices
 
+0		string		btrfs-stream	BTRFS stream file
+
 # dvdisaster's .ecc
 # From: "Nelson A. de Oliveira" <naoliv@gmail.com>
 0	string	*dvdisaster*	dvdisaster error correction file
@@ -2399,12 +2401,167 @@
 
 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)
+# URL:		http://fileformats.archiveteam.org/wiki/LoadDskF/SaveDskF
+# Update:	Joerg Jenderek
+# Note:		called "IBM SKF disk image" by TrID
+#		verfied by 7-Zip `7z l -tFAT -slt *.dsk` and
+#		`deark -l -m loaddskf  06200D19.DSK`
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/d/dsk-skf-old.trid.xml 
+0	beshort	0xAA58
+>0	use		SaveDskF
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/d/dsk-skf.trid.xml
+0	beshort	0xAA59
+>0	use		SaveDskF
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/d/dsk-skf-comp.trid.xml
+0	beshort	0xAA5A
+# skip foo by additional check for unused upper byte of media type in SaveDskF header
+#>3	ubyte		=0
+# skip bar by additional check for valid "low" number of heads in SaveDskF header
+#>>26	uleshort	<3
+# skip foo by additional check for unused double word field in SaveDskF header
+#>>>30	long		=0
+#>>>>0	use		SaveDskF
+>0	use		SaveDskF
+# display information about IBM SaveDskF floppy disk images
+0	name			SaveDskF
+# SaveDskF magic
+>0	beshort	x		floppy image data (IBM SaveDskF
+#!:mime	application/octet-stream
+!:mime	application/x-ibm-dsk
+!:ext	dsk
+# also suffix with digit (1dk .2dk ...); NO example FOUND!
+#!:ext	dsk/1dk/2dk
+>1	ubyte		=0x58	\b, old)
+>1	ubyte		=0x59	\b)
+>1	ubyte		=0x5A	\b, compressed)
+# media type; the first byte of the FAT like: 0xF0 (usual floppy) 0xF9 0xFE
+# https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system
+>2	ubyte		!0xF0	\b, Media descriptor %#x
+# upper byte of media type is not used; so this seems to be nil
+>3	ubyte		!0	\b, upper byte of media type %#x
+# sector size in bytes as in the BIOS parameter block like: 512 ; SAVEDSKF.EXE with other sizes produce garbage images
+>4	uleshort	!512	\b, Bytes/sector %u
+# cluster mask; number of sectors per cluster, minus 1
+>6	uleshort+1	>1	\b, sectors/cluster %u
+#>6	uleshort+1	x	\b, sectors/cluster %u
+# cluster shift; log2(cluster size / sector size) like: 0~1=ClusterSize/SectorSize
+>7	ubyte		>0	\b, cluster shift %u
+#>7	ubyte		x	\b, cluster shift %u
+# reserved sectors; as in the BIOS parameter block like: 1 256 (2M256R-K.DSK)
+>8	uleshort	>1	\b, reserved sectors %u
+#>8	uleshort	x	\b, reserved sectors %u
+# FAT copies; as in the BIOS parameter block like: 2 (usual) 1 (2-NK.DSK)
+>10	ubyte		!2	\b, FAT
+# plural s
+>>10	ubyte		>1	\bs
+>>10	ubyte		x	%u
+# root directory entries; as in the BIOS parameter block like: 224 (usual) 64 (H1-NK.DSK) 4096 (2-NK.DSK)
+>11	uleshort	!224	\b, root entries %u
+# sector number of first cluster (count sectors used by boot sector, FATs and root directory) like: 7 10 29 33 288
+>13	uleshort	!33	\b, 1st cluster at sector %u
+# number of clusters in image; empty clusters at the end are not saved and counted like: 2372 2848
+>15	uleshort	x	\b, %u clusters
+# sectors/FAT; as in the BIOS parameter block like: 1 (H1-NK.DSK) 7 9
+>17	ubyte		!9	\b, sectors/FAT %u
+# sector number of root directory (ie, count of sectors used by boot sector and FATs) like: 3 (H1-NK.DSK) 9 10 15 19 274 (2M256R-K.DSK)
+>18	uleshort	!19	\b, root directory at sector %u
+# checksum; sum of all bytes in the file
+>20	ulelong		x	\b, checksum %#8.8x
+# cylinders; number of cylinders like: 40 80
+>24 	uleshort	!80	\b, %u cylinders
+#>24 	uleshort	x	\b, %u cylinders
+# heads; number of heads as in the BIOS parameter block like: 1 (H1-NK.DSK) 2
+>26	uleshort	!2	\b, heads %u
+#>26	uleshort	x	\b, heads %u
+# sectors/track; number of sectors per track as in the BIOS parameter block like: 8 15 18 36
+>28	uleshort	!18	\b, sectors/track %u
+#>28	uleshort	x	\b, sectors/track %u
+# unused double word field seems to be always like: 0
+>30	ulelong		!0	\b, at 0x1E %#x
+# number of sectors in images like: 1017 2786 2880
+>34 	uleshort	x	\b, sectors %u
+# if string is "printable" it can be a real comment
+>(36.s)	ubyte		!0x00
+# if 1st sector is far enough away (> 0x29) then there is space for comment part
+>>38	uleshort	>41
+# offset to comment string like: 28h=40
+>>>36	uleshort	x	\b, at %#x
+# comment string terminated with \r\n\0
+>>>(36.s)	string	x	"%s"
+# offset to the first sector like: 0 (If this is 0, assume it is 0x200) 29h=41 (DISPLAY3.DSK) 31h 43h 45h 46h 48h 50h 200h=512
+>38	uleshort	!0	\b, 1st sector at %#x
+# FOR DEBUGGING!
+#>(38.s)	ubelong		x	SECTOR CONTENT %x
+# not compressed floppy image implies readable DOS boot sector inside image
+>>1		ubyte	!0x5A
+# when not compressed it is readable as DOS boot sector via ./filesystems
+#>>>(38.s)	indirect x	\b; contains
+>38	uleshort	=0	\b, 1st sector at 0x200 (0)
+# maybe standard DOS boot sector; NO example FOUND HERE!
+#>>0x200	indirect	x	\b; contains
 
 0	string	\074CPM_Disk\076	disk image data (YAZE)
 
+# From: 	Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/Central_Point_Software#cite_note-6
+# Reference:	https://www.robcraig.com/download/transcopy-5-x-file-format
+#		https://www.robcraig.com/download/transcopy-file-format-by-gene-thompson
+#		http://mark0.net/download/triddefs_xml.7z/defs/t/tc-transcopy.trid.xml
+# TransCopy signature
+0		beshort		0x5AA5
+# skip Intel serial flash ROM with invalid 0 disk sides handled by ./intel
+>0x103		ubyte		!0
+# skip Intel serial flash ROM with unlikely "high" start cylinder 100 handled by ./intel
+#>>0x101		ubyte		<100		VALID_START_CYLINDER
+# skip Intel serial flash ROM with unlikely description handled by ./intel
+#>>>2		beshort		!0xF00f		VALID_DESCRIPTION
+# skip Intel serial flash ROM with invalid disk types 89h 88h handled by ./intel
+#>>>>0x100	byte		!0x89		VALID_DISK_TYPE
+>>0	use	tc-floppy
+#	display information of Central Point Software (CPS) Option Board TransCopy floppy image
+0	name		tc-floppy
+>0		beshort		x		TransCopy disk image
+#!:mime	application/octet-stream
+!:mime	application/x-floppy-image-tc
+# like: disk04.tc VOCALC2.TC WIZ5_A.tc WIZ2_720.IMG
+!:ext	tc/img
+# 1st description (optional 0-terminated maximal 32) like:
+# "Project Workbench 2.20" "Visi On Calc" "Wizardry V Disk 1 of 3"
+>2		string		>\0		%.32s
+# 2nd desc. (optional 0-terminated maximal 32) like:
+# "(1988)." "Advanced - Utility" 'Program Disk 2"
+>0x22		string		>\0		"%.32s"
+# Looks like ascii (like MESSAGES) formatted with attribute bytes (190)? 
+# not needed for disk copy
+#>>0x42		string		x		'%.190s'
+#>>0x88		lestring16	x		"%.8s"
+# disktype: 2~MFM High Density 3~MFM Double Density 4~Apple II GCR 5~FM Single Density
+# 6~Commodore GCR 7~MFM Double Density 8~Commodore Amiga Ch~Atari FM FFh~Unknown
+>0x100		ubyte		!0xFF		\b, disk type %u
+# StartingCylinder like: 0
+>0x101		ubyte		x		\b, cylinder
+>0x101		ubyte		!0		start=%u
+# EndingCylinder like: 40 (often) 41 79
+>0x102		ubyte		x		end=%u
+# NumberOfSides like: 2
+>0x103		ubyte		!2		\b, %u sides
+# TrackIncrement like: 1
+>0x104		ubyte		!1		\b, track increment %u
+# TrackPosTbl Track skew
+#>0x105		ubequad		x		\b, Track skew %#16.16llx
+# TrackOffsTbl
+#>0x305		ubequad		x		\b, TrackOffsTbl %#16.16llx
+# TrackLngthTbl
+#>0x505		ubequad		x		\b, TrackLngthTbl %#16.16llx
+# TrackTypeTable
+#>0x705		ubequad		x		\b, TrackTypeTable %#16.16llx
+# Address mark timing
+#>0x905		ubequad		x		\b, Address mark timing %#16.16llx
+# Track fragment
+#>0x2905 ubequad			!0		\b, Track fragment %#16.16llx
+# Track data
+#>0x4000		ubequad		!0		\b, Track data %#16.16llx
+
 # ReFS
 # Richard W.M. Jones <rjones@redhat.com>
 0	string	\0\0\0ReFS\0	ReFS filesystem image
@@ -2504,3 +2661,29 @@
 >>>&(0x107a.b*56)	use	bcachefs-uuid
 >>0x107b	byte		x	\b, %d devices
 >>0x1090	byte		^0x02	\b (unclean)
+
+# EROFS
+# https://kernel.googlesource.com/pub/scm/linux/kernel/git/xiang/erofs-utils/\
+# +/refs/heads/experimental/include/erofs_fs.h#12
+1024		lelong		0xE0F5E1E2	EROFS filesystem
+#>1028		lelong		x		\b, checksum=%#x
+>1032		lelong		>0		\b, compat:
+>>1032		lelong		&1		SB_CHKSUM
+>>1032		lelong		&2		MTIME
+>1036		byte		x		\b, blocksize=%u
+>1037		byte		x		\b, exslots=%u
+#>1038		leshort		x		\b, root_nid=%d
+#>1040		lequad		x		\b, inodes=%ld
+#>1048		leldate		x		\b, build_time=%s
+#>1056		lelong		x		\b.%d
+#>1060		lelong		x		\b, blocks=%d
+#>1064		lelong		x		\b, metadata@%#x
+#>1068		lelong		x		\b, xattr@%#x
+>1072		guid		x		\b, uuid=%s
+>1088		string		>0		\b, name=%s
+>1104		lelong		>0		\b, incompat:
+>>1104		lelong		&1		LZ4_0PADDING
+>>1104		lelong		&2		BIG_PCLUSTER
+>>1104		lelong		&4		CHUNKED_FILE
+>>1104		lelong		&8		DEVICE_TABLE
+>>1104		lelong		&16		ZTAILPACKING

+ 61 - 7
magic/Magdir/fonts

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: fonts,v 1.46 2021/04/26 15:56:00 christos Exp $
+# $File: fonts,v 1.51 2022/08/16 11:16:39 christos Exp $
 # fonts:  file(1) magic for font data
 #
 0	search/1	FONT		ASCII vfont text
@@ -8,13 +8,56 @@
 0	short		017001		byte-swapped Berkeley vfont data
 
 # PostScript fonts (must precede "printer" entries), quinlan@yggdrasil.com
+# Modified by:	Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/PostScript_fonts
+#		http://fileformats.archiveteam.org/wiki/Adobe_Type_1
+# Reference:	http://mark0.net/download/triddefs_xml.7z
+#		defs/p/pfb.trid.xml
+# Note:		PFB stands for Printer Font Binary
 0	string		%!PS-AdobeFont-1.	PostScript Type 1 font text
+#!:mime	font/x-postscript-pfb
+#!:ext	pfb
 >20	string		>\0			(%s)
-6	string		%!PS-AdobeFont-1.	PostScript Type 1 font program data
->26	string		>\0			(%s)
+# http://www.nationalarchives.gov.uk/pronom/fmt/525
+6	string		%!PS-AdobeFont-1.
+# skip DROID fmt-525-signature-id-816.pfb by checking for content after header
+>24	ubyte		x			PostScript Type 1 font program data
+#!:mime	application/octet-stream
+!:mime	font/x-postscript-pfb
+!:ext	pfb
+# often followed by colon (3Ah) and space (20h) and font name like: DarkGardenMK LetterGothic
+>>24	ubyte		=0x3A
+>>>26	string		>\0			(%s)
+# some times instead of colon %%CreationDate: and "font name" later
+>>24	ubyte		!0x3A
+# font name directive followed by def like: c0633bt_.pfb
+>>>25	search/1247	/FontName\040/
+# show font name in parentheses like: Frankfurt Lithos CharterBT-BoldItalic Courier10PitchBT-Bold
+>>>>&0	regex		[A-Za-z0-9-]+		(%s)
+# http://cd.textfiles.com/maxfonts/ATM/M/MIRROR__.PFB
+6	string		%PS-AdobeFont-1.	PostScript Type 1 font program data
+!:mime	font/x-postscript-pfb
+!:ext	pfb
+# font name like:  Times-Mirror
+>25	string		>\0			(%s)
 0	string		%!FontType1	PostScript Type 1 font program data
+#!:mime	font/x-postscript-pfb
+#!:ext	pfb
 6	string		%!FontType1	PostScript Type 1 font program data
+#!:mime	application/octet-stream
+!:mime	font/x-postscript-pfb
+!:ext	pfb
+# font name like: CaslonOpenFace FetteFraktur Kaufmann Linotext MesozoicGothic Old-Town
+>23	string		>\0			(%s)
+# http://cd.textfiles.com/maxfonts/ATM/P/PLAYBI.PFB
+230	string		%!FontType1	PostScript Type 1 font program data
+!:mime	font/x-postscript-pfb
+!:ext	pfb
+# font name like: Playbill
+>247	string		>\0			(%s)
 0	string		%!PS-Adobe-3.0\ Resource-Font	PostScript Type 1 font text
+#!:mime	font/x-postscript-pfb
+#!:ext	pfb
 
 # Summary:	PostScript Type 1 Printer Font Metrics
 # URL:		https://en.wikipedia.org/wiki/PostScript_fonts
@@ -67,15 +110,23 @@
 >>>90		ubyte		65		script proportional
 
 # X11 font files in SNF (Server Natural Format) format
-# updated by Joerg Jenderek at Feb 2013
+# updated by Joerg Jenderek at Feb 2013 and Nov 2021
 # http://computer-programming-forum.com/51-perl/8f22fb96d2e34bab.htm
-0	belong		00000004		X11 SNF font data, MSB first
-#>104	belong		00000004		X11 SNF font data, MSB first
+# URL:		http://fileformats.archiveteam.org/wiki/SNF
+# Reference:	https://cgit.freedesktop.org/xorg/lib/libXfont/tree/src/bitmap/snfstr.h
+0	belong		00000004
+# version2 same as version1 in struct _snfFontInfo
+>104	belong		00000004		X11 SNF font data, MSB first
+# GRR: line above is too general as it catches also DEGAS low-res bitmap like:
+# http://cd.textfiles.com/geminiatari/FILES/GRAPHICS/ANIMAT/SPID_PAT/BIGSPID.PI1
 !:mime	application/x-font-sfn
-# GRR: line below too general as it catches also Xbase index file t3-CHAR.NDX
+!:ext	snf
+# GRR: line below is too general as it catches also Xbase index file t3-CHAR.NDX
 0	lelong		00000004
 >104	lelong		00000004		X11 SNF font data, LSB first
 !:mime	application/x-font-sfn
+# Reference:    http://mark0.net/download/triddefs_xml.7z/defs/s/snf-x11-lsb.trid.xml
+!:ext	snf
 
 # X11 Bitmap Distribution Format, from Daniel Quinlan (quinlan@yggdrasil.com)
 0	search/1	STARTFONT\ 		X11 BDF font text
@@ -384,11 +435,14 @@
 
 # https://www.w3.org/TR/WOFF/
 0	string		wOFF	Web Open Font Format
+!:mime font/woff
 >0	use		woff
 >20	beshort		x	\b, version %d
 >22	beshort		x	\b.%d
 # https://www.w3.org/TR/WOFF2/
 0	string		wOF2	Web Open Font Format (Version 2)
+!:mime font/woff2
+!:ext	woff2
 >0	use		woff
 #>20	belong		x	\b, totalCompressedSize %d
 >24	beshort		x	\b, version %d

+ 21 - 1
magic/Magdir/freebsd

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: freebsd,v 1.7 2009/09/19 16:28:09 christos Exp $
+# $File: freebsd,v 1.9 2022/01/19 12:44:13 christos Exp $
 # freebsd:  file(1) magic for FreeBSD objects
 #
 # All new-style FreeBSD magic numbers are in host byte order (i.e.,
@@ -142,3 +142,23 @@
 >9	byte	2		%d bytes in header,
 >>10	byte	x		%d chars wide by
 >>11	byte	x		%d chars high
+
+#
+# FreeBSD kernel minidumps
+#
+0	string	minidump\040FreeBSD/	FreeBSD kernel minidump
+# powerpc uses 32-byte magic, followed by 32-byte mmu kind, then version
+>17	string	powerpc
+>>17	string	>\0			for %s,
+>>>32	string	>\0			%s,
+>>>>64	byte	0			big endian,
+>>>>>64	belong	x			version %d
+>>>>64	default	x			little endian,
+>>>>>64	lelong	x			version %d
+# all other architectures use 24-byte magic, followed by version
+>17	default	x
+>>17	string	>\0			for %s,
+>>>24	byte	0			big endian,
+>>>>24	belong	x			version %d
+>>>24	default	x			little endian,
+>>>>24	lelong	x			version %d

+ 13 - 21
magic/Magdir/games

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: games,v 1.24 2021/04/26 15:56:00 christos Exp $
+# $File: games,v 1.25 2022/05/31 18:40:20 christos Exp $
 # games:  file(1) for games
 
 # Fabio Bonelli <fabiobonelli@libero.it>
@@ -496,25 +496,17 @@
 >4	ulelong	x        	version %d, used in GTA IV,
 >>8	ulelong	x        	%d items
 
-0	uleshort	0x5250	RAGE Package Format (RPF),
->2	uleshort	0x4630	version 0, used in Rockstar Table Tennis,
->>4	ulelong 	x	%d bytes,
->>>8	ulelong 	x	%d entries
->2	uleshort	0x4632	version 2, used in GTA IV,
->>4	ulelong 	x	%d bytes,
->>>8	ulelong 	x	%d entries
->2	uleshort	0x4633	version 3, used in GTA IV Audio & Midnight Club: LA,
->>4	ulelong 	x	%d bytes,
->>>8	ulelong 	x	%d entries
->2	uleshort	0x4634	version 4, used in Max Payne 3,
->>4	ulelong 	x	%d bytes,
->>>8	ulelong 	x	%d entries
->2	uleshort	0x4636	version 6, used in RDR,
->>4	ulelong 	x	%d bytes,
->>>8	ulelong 	x	%d entries
->2	uleshort	0x4637	version 7, used in GTA V,
->>4	ulelong 	x	%d bytes,
->>>8	ulelong 	x	%d entries
->2	uleshort	0x4638	version 8, used in RDR 2,
+# RPF[0-8]
+0	ulelong&0xfffffff0 =0x52504630
+>0	ulelong&0xf	<9	RAGE Package Format (RPF), version %d, used in
+>>0	ulelong&0xf	=0	Rockstar Table Tennis,
+>>0	ulelong&0xf	=1	*unknown*
+>>0	ulelong&0xf	=2	GTA IV,
+>>0	ulelong&0xf	=3	GTA IV Audio & Midnight Club: LA,
+>>0	ulelong&0xf	=4	Max Payne 3,
+>>0	ulelong&0xf	=5	*unknown*
+>>0	ulelong&0xf	=6	RDR,
+>>0	ulelong&0xf	=7	GTA V,
+>>0	ulelong&0xf	=8	RDR 2,
 >>4	ulelong 	x	%d bytes,
 >>>8	ulelong 	x	%d entries

+ 80 - 0
magic/Magdir/gentoo

@@ -0,0 +1,80 @@
+#------------------------------------------------------------------------------
+# $File: gentoo,v 1.2 2022/09/12 13:13:28 christos Exp $
+# gentoo:  file(1) magic for gentoo specific formats
+#
+# Summary: Gentoo ebuild Manifest files (GLEP 74)
+# Reference: https://www.gentoo.org/glep/glep-0074.html
+# Submitted by: Michal Gorny <mgorny@gentoo.org>
+# Start by doing a fast check for the most common tags.
+0	string	AUX
+>0	use	gentoo-manifest
+0	string	DATA
+>0	use	gentoo-manifest
+0	string	DIST
+>0	use	gentoo-manifest
+0	string	EBUILD
+>0	use	gentoo-manifest
+0	string	MANIFEST
+>0	use	gentoo-manifest
+
+# Manifest can be PGP-signed.
+0	string	-----BEGIN\040PGP\040SIGNED\040MESSAGE-----
+>34	search/32	\n\n
+>>&0	string	AUX
+>>>&0	use	gentoo-manifest
+>>&0	string	DATA
+>>>&0	use	gentoo-manifest
+>>&0	string	DIST
+>>>&0	use	gentoo-manifest
+>>&0	string	EBUILD
+>>>&0	use	gentoo-manifest
+>>&0	string	MANIFEST
+>>>&0	use	gentoo-manifest
+
+# Use a more detailed regex to verify that we were correct.
+# <tag> <filename> <size> <hash-name> <hash-value>...
+# (<tag>'s already been matched prior to calling)
+0	name	gentoo-manifest
+>&0	regex	[[:space:]]+[[:print:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:alnum:]]+[[:space:]]+[[:xdigit:]]{32}	Gentoo Manifest (GLEP 74)
+
+# Summary: Gentoo ebuild and eclass files
+# Reference: https://projects.gentoo.org/pms/8/pms.html
+# Submitted by: Michal Gorny <mgorny@gentoo.org>
+0	search/512	EAPI=
+>0	regex		.*\n[\040\t]*EAPI=["']?	Gentoo ebuild
+>>&0	regex		[[:alnum:]+_.-]+	\b, EAPI %s
+
+0	search/512	@ECLASS:\040		Gentoo eclass
+>&0	string		x			%s
+
+# Summary: Gentoo supplementary package and category metadata files
+# Reference: https://www.gentoo.org/glep/glep-0068.html
+# Submitted by: Michal Gorny <mgorny@gentoo.org>
+0	string		\<?xml
+>0	search/512	\<catmetadata		Gentoo category metadata file
+>0	search/512	\<pkgmetadata		Gentoo package metadata file
+
+# Summary: Gentoo GLEP 78 binary package
+# Reference: https://www.gentoo.org/glep/glep-0078.html
+# Note: assumes the strict format
+# Submitted by: Michal Gorny <mgorny@gentoo.org>
+
+# GPKG uses ustar (or ustar-compatible GNU format) that starts with
+# a <directory>/gpkg-1 file
+257	string		ustar
+>0	search/100	/gpkg-1\0
+>>0	regex		[^/]+		Gentoo GLEP 78 (GPKG) binary package for "%s"
+!:mime	application/x-tar
+!:ext	tar
+# the logic below requires the gpkg-1 file to be empty
+>>>124	string	00000000000\0
+# determine the compression used by looking at the second member name
+>>>>512	search/100	.tar.
+>>>>>&0	string		gz\0		using gzip compression
+>>>>>&0	string		bz2\0		using bzip2 compression
+>>>>>&0	string		lz\0		using lzip compression
+>>>>>&0	string		lz4\0		using lz4 compression
+>>>>>&0	string		lzo\0		using lzo compression
+>>>>>&0	string		xz\0		using xz compression
+>>>>>&0	string		zst\0		using zstd compression
+>>>>(636.o+1024)	search/611	.sig\0	\b, signed

+ 5 - 5
magic/Magdir/geo

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: geo,v 1.7 2019/04/19 00:42:27 christos Exp $
+# $File: geo,v 1.8 2022/03/24 15:48:58 christos Exp $
 # Geo- files from Kurt Schwehr <schwehr@ccom.unh.edu>
 
 ######################################################################
@@ -28,8 +28,8 @@
 # Knudsen subbottom chirp profiler - Binary File Format: B9
 # KEB D409-03167 V1.75 Huffman
 0	string	KEB\ 	Knudsen seismic KEL binary (KEB) -
->4	regex	[-A-Z0-9]*	Software: %s
->>&1	regex	V[0-9]*\.[0-9]*	version %s
+>4	regex	[-A-Z0-9]+	Software: %s
+>>&1	regex	V[0-9]+\\.[0-9]+	version %s
 
 ######################################################################
 #
@@ -40,7 +40,7 @@
 
 # Caris LIDAR format for LADS comes as two parts... ascii location file and binary waveform data
 0	string	HCA	LADS Caris Ascii Format (CAF) bathymetric lidar
->4	regex [0-9]*\.[0-9]*	version %s
+>4	regex [0-9]+\\.[0-9]+	version %s
 
 0	string	HCB	LADS Caris Binary Format (CBF) bathymetric lidar waveform data
 >3      byte    x	version %d .
@@ -69,7 +69,7 @@
 
 # mb121 https://www.saic.com/maritime/gsf/
 8	string	GSF-v	SAIC generic sensor format (GSF) sonar data,
->&0	regex [0-9]*\.[0-9]*	version %s
+>&0	regex [0-9]+\\.[0-9]+	version %s
 
 # MGD77 - https://www.ngdc.noaa.gov/mgg/dat/geodas/docs/mgd77.htm
 # mb161

+ 2 - 1
magic/Magdir/iff

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: iff,v 1.17 2021/02/23 01:07:32 christos Exp $
+# $File: iff,v 1.18 2022/03/21 19:57:18 christos Exp $
 # iff:	file(1) magic for Interchange File Format (see also "audio" & "images")
 #
 # Daniel Quinlan (quinlan@yggdrasil.com) -- IFF was designed by Electronic
@@ -45,6 +45,7 @@
 >8	string		ACBM		\b, ACBM continuous image
 >8	string		FAXX		\b, FAXX fax image
 >8	string		STFX		\b, ST-Fax image
+>8	string		IMAGIHDR	\b, CD-i image
 # other formats
 >8	string		FTXT		\b, FTXT formatted text
 >8	string		CTLG		\b, CTLG message catalog

File diff suppressed because it is too large
+ 1975 - 1099
magic/Magdir/images


+ 194 - 10
magic/Magdir/intel

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: intel,v 1.20 2021/04/26 15:56:00 christos Exp $
+# $File: intel,v 1.22 2022/04/02 14:47:42 christos Exp $
 # intel:  file(1) magic for x86 Unix
 #
 # Various flavors of x86 UNIX executable/object (other than Xenix, which
@@ -43,7 +43,16 @@
 # no hint found, that at offset 22 is version
 #>22	leshort		>0		- version %d
 0	leshort		0x0200
->0	use				display-coff
+# no F_EXEC flag bit implies Intel ia64 COFF object file without optional header
+>18	leshort		^0x0002
+# skip some DEGAS high-res uncompressed bitmap *.pi3 handled by ./images like
+# GEMINI03.PI3 MODEM2.PI3 POWERFIX.PI3 sigirl1.pi3 vanna5.pi3
+# by test for valid starting character (often point 0x2E) of 1st section name
+>>20	ubyte		>0x1F
+>>>0	use				display-coff
+# F_EXEC flag bit implies Intel ia64 COFF executable
+>18	leshort		&0x0002
+>>0	use				display-coff
 0	leshort		0x8664
 >0	use				display-coff
 
@@ -52,16 +61,191 @@
 # From: Alex Myczko <alex@aiei.ch>
 # updated by Joerg Jenderek
 # https://en.wikipedia.org/wiki/Option_ROM
-0        beshort         0x55AA       BIOS (ia32) ROM Ext.
-!:mime	application/octet-stream
+# URL:		http://fileformats.archiveteam.org/wiki/BIOS
+# Reference:	http://www.lejabeach.com/sisubb/BIOS_Disassembly_Ninjutsu_Uncovered.pdf
+0	beshort		0x55AA
+# skip misidentified raspberry pi pieeprom-*.bin by check for
+# unlikely high ROM size (0xF0*512=240*512) and not observed start instruction 0x0F 
+>2	ubeshort	!0xF00F
+# skip 2 byte sized eof.bin with start magic 
+>>0	use		rom-x86
+0	name		rom-x86
+>0	beshort		x		BIOS (ia32) ROM Ext.
+#!:mime	application/octet-stream
+!:mime	application/x-ibm-rom
 !:ext	rom/bin
->5       string          USB          USB
->7       string          LDR          UNDI image
+################################################################################
+# not Plug aNd Play ($PnP) like 00000000 (ide_xtp.bin kvmvapic.bin V7VGA.ROM) 000000fc (MCT-VGA.bin)
+# 55aaf00f (pieeprom-*.bin) 55aa40e9 (Trm3x5.bin) 24506f4f (sgabios-bin.rom)
+# 55aa4be9 (vgabios-stdvga.rom vgabios-cirrus-bin.rom vgabios-vmware-bin.rom)
+>(26.s)	ubelong		!0x24506e50
+#>(26.s)	ubelong		!0x24506e50	NOT PNP=%8.8x
+# also not PCI (PCIR) implies "old" ISA cards or foo like: 8a168404 (MCT-VGA.bin)
+# 55aaf00f (pieeprom*.bin)
+>>(24.s)	ubelong	!0x50434952
+#>>(24.s)	ubelong	!0x50434952	ISA CARD=%8.8x
+# "old" identification strings used in file version 5.41 and earlier
+# probably an USB controller
+>>>5	string		USB		USB
+# probably	https://en.wikipedia.org/wiki/Preboot_Execution_Environment
+>>>7	string		LDR		UNDI image
+# probably another Adaptec SCSI controller
+>>>26	string		Adaptec		Adaptec
+# http://minuszerodegrees.net/rom/bin/adaptec_aha1542cp_bios_908501-00.bin
+# already done by PNP variant
+#>>>28	string		Adaptec		Adaptec
+# probably Promise SCSI controller
+>>>42	string		PROMISE		Promise
+# old test for IBM compatible Video cards; INTERNAL FACTS WHY IS THIS WORKING?
 >30      string          IBM          IBM comp. Video
->26      string          Adaptec      Adaptec
->28      string          Adaptec      Adaptec
->42      string          PROMISE      Promise
->2       byte            x            (%d*512)
+# display exact text for IBM compatible Video cards with longer text
+>>33	ubyte		!0
+>>>30	string		x		"%s"
+# http://minuszerodegrees.net/rom/bin/unknown/MCT-VGA-16%20-%20TDVGA%203588%20BIOS%20Version%20V1.04A.zip
+# "IBM COMPATIBLETDVGA 3588 BIOS Version V1.04A2+"	"MCT-VGA-16 - TDVGA 3588 BIOS Version V1.04A.bin" 
+# "IBM VGA Compatible\001"				NVidia44.bin
+# "IBM EGA ROM Video Seven BIOS Code, Version 1.04"	V7VGA.ROM
+# "IBM"							vgabios-stdvga.rom
+# "IBM"							vgabios-vmware-bin.rom:
+# "IBM"							vgabios-cirrus-bin.rom
+# "IBM"							vgabios-virtio-bin.rom
+################################################################################
+# ROM size in 512B blocks must be interpreted as unsigned for ROM of network cards
+# like: efi-eepro100.rom efi-rtl8139.rom pxe-e1000.rom
+>2       ubyte            x            (%u*512)
+# file name		file size	calculated size	remark
+# eof.bin		2		-		with start magic nothing is shown here
+# orchid.bin		188		0	=0*512	on window 95 CD in Drivers\audio\orchid3d
+# multiboot.bin		1024		1024	=2*512	QEMU emulator
+# loader1.bin		512		2048	=4*512
+# ide_xtp.bin		8192		8192	=16*512
+# kvmvapic.bin		9216		9216	=18*512
+# V7VGA.ROM		18832		16384	=32*512
+# adaptec1542.bin	32768		16384	=32*512
+# MCT-VGA.bin		32768		24576	=48*512
+# 2975BIOS.BIN		32768		32256	=63*512
+# efi-e1000.rom		196608		64000	=125*512
+# efi-rtl8139.rom	176640		66048	=129*512
+# pieeprom*.bin		524288		122880	=240*512
+################################################################################
+# initialization vector with executable code; often near JuMP instruction E9 yy zz
+>3	ubyte			=0xE9	jmp
+# jmp offset like: 008fh 0093h 009fh 00afh 0143h 3ad7h 5417h 54ech 594dh 895fh 
+>>4	uleshort		x	%#4.4x
+# for initialization vector samples without 3 byte jump instruction
+>3	ubyte			!0xE9	instruction
+#	eb4b3734h	NVidia44.bin
+#	00003234h	V7VGA.ROM
+#	060e0731h	kvmvapic.bin
+#	cb000000h	linuxboot-bin.rom
+#	e80d0fcbh	PXE-Intel.rom
+#	b8004875h	orchid.bin
+>>3	ubelong			x	%#8.8x
+# For misidetified raspberry pi pieeprom-*.bin like: 0xf00f
+#>2	ubeshort		x	\b, AT 2 %#4.4x
+################################################################################
+#		new sections for BIOS (ia32) ROM Extension
+# 4 bytes ASCII Signature "$PnP" for Plug aNd Play expansion header
+>(26.s)	string		=$PnP		\b;
+#>(26.s)	string		=$PnP		FOUND $PnP
+# at 1Ah possible offset to expansion header structure; new for Plug aNd Play
+>>26		uleshort	x	at %#x PNP
+# Plug and Play vendor+device ID like: 0 0x000f1000 (2975BIOS.BIN) 0x31121095 (4243.bin) 0x04904215 (adaptec1542.bin)
+#>>(26.s+0x0A)	ulelong		!0	NOT-nullID=%8.8x
+>>(26.s+0x0A)	uleshort	!0
+# show PnP Vendor identification in human readable text form instead of numeric
+# For adaptec_ava1515_bios_585201-00.bin reverted endian! BUT IS THIS ALWAYS TRUE?
+>>>(26.s+0x0C)	use		\^PCI-vendor
+>>>(26.s+0x0A)	ubeshort	x	device=%#4.4x
+# 3 byte Device type code; probably the same meaning as in PCI section?
+# OK for	storage controller SCSI		(2975BIOS.BIN adaptec1542.bin)
+# and		network controller ethernet	(efi-e1000.rom efi-rtl8139.rom)
+>>(26.s+0x12)	use		PCI-class
+# structure revision like: 01h
+>>(26.s+4)	ubyte		!1	\b, revision %u
+# PnP Header structure length in multiple of 16 bytes like: 2
+>>(26.s+5)	uleshort	!2	\b, length %u*16
+# offset to next header; 0 if none
+>>(26.s+7)	uleshort	!0	\b, at %#x next header
+# reserved byte; seems to be zero
+>>(26.s+8)	ubyte		!0	\b, reserved %#x
+# 8-bit checksum for this header; calculated and patched by patch2pnprom
+>>(26.s+9)	ubyte		!0	\b, CRC %#x
+# pointer to optional manufacturer string; like: 0 (4243.bin) 59h 5ch 60h c7h 14eh 27ch 296h 324h 3662h
+>>(26.s+0x0E)	uleshort	>0	\b, at %#x
+>>>(26.s+0x0C)	uleshort	x
+# manufacturer ASCII-Z string like "http://ipxe.org" "Plop - Elmar Hanlhofer www.plop.at" "QEMU"
+>>>>(&0.s)	string		x	"%s"
+# pointer to optional product string; like: 0 (2975BIOS.BIN) 6ch 70h 7ch d9h 160h 281h 29bh 329h
+>>(26.s+0x10)	uleshort	>0	\b, at %#x
+>>>(26.s+0x0E)	uleshort	x
+# often human readable product ASCII-Z string like "iPXE" "Plop Boot Manager" 
+# "multiboot loader" "Intel UNDI, PXE-2.0 (build 082)"
+>>>>(&0.s)	string		x	"%s"
+# PnP Device indicators; contains bits that identify the device as being capable of bootable
+#>>(26.s+0x15)	ubyte		x	\b, INDICATORS %#x
+# device is a display device
+>>(26.s+0x15)	ubyte		&0x01	\b, display
+# device is an input device
+>>(26.s+0x15)	ubyte		&0x02	\b, input
+# device is an IPL device
+>>(26.s+0x15)	ubyte		&0x04	\b, IPL
+#>>(26.s+0x15)	ubyte		&0x08	reserved
+# ROM is only required if this device is selected as a boot device
+>>(26.s+0x15)	ubyte		&0x10	\b, bootable
+# indicates ROM is read cacheable
+>>(26.s+0x15)	ubyte		&0x20	\b, cacheable
+# ROM may be shadowed in RAM
+>>(26.s+0x15)	ubyte		&0x40	\b, shadowable
+# ROM supports the device driver initialization model
+>>(26.s+0x15)	ubyte		&0x80	\b, InitialModel
+# boot connection vector; an offset to a routine that hook into INT 9h, INT 10h, or INT 13h
+# 0 means disabled 0x0429 (4650_sr5.bin) 0x0072 (adaptec1542.bin)
+>>(26.s+0x16)	uleshort	!0	\b, boot vector offset %#x
+# disconnect vector; offset to routine that do cleanup from an unsuccessful boot attempt
+>>(26.s+0x18)	uleshort	!0	\b, disconnect offset %#x
+# bootstrap entry point/vector (BEV); offset to a routine (like RPL) that hook into INT 19h
+# 0 means disabled 0x3c (multiboot.bin) 0x358 (efi-rtl8139.rom) 0xae7 (PXE-Intel.rom)
+>>(26.s+0x1A)	uleshort	!0	\b, bootstrap offset %#x
+# 2nd reserved area; seems to be zero
+>>(26.s+0x1C)	uleshort	!0	\b, 2nd reserved %#x
+# static resource information vector; 0 means disabled
+>>(26.s+0x1E)	uleshort	!0	\b, static offset %#4.4x
+################################################################################
+# 4 bytes ASCII Signature "PCIR" for PCI Data Structure
+#>(24.s)	string			=PCIR	FOUND PCIR
+>(24.s)	string			=PCIR	\b;
+# pointer to PCI data structure like: 1Ch 38h 104h 8E44h 
+>>24	uleshort		x	at %#x PCI
+# Vendor identification (ID)		https://pci-ids.ucw.cz/v2.2/pci.ids
+#>>(24.s+4)	uleshort	x	ID=%4.4x
+# show Vendor identification in human readable text form instead of numeric
+>>(24.s+4)	use		PCI-vendor
+# device identification (ID)
+>>(24.s+6)	uleshort	x	device=%#4.4x
+# Base+sub class code			https://wiki.osdev.org/PCI
+>>(24.s+0x0D)	use		PCI-class
+# pointer to vital product data (VPD); 0 indicates no VPD; WHAT EXACTLY iS VPD?
+>>(24.s+8)	uleshort	!0	\b, at %#x VPD
+# PCI data structure length like: 24h 28h
+>>(24.s+0xA)	uleshort	>0x28	\b, length %u
+# PCI data structure revision like: 0 3
+>>(24.s+0xC)	ubyte		>0	\b, revison %u
+# image length (hexadecimal) in multiple of 512 bytes like: 54 56 68 6a 76 78 7c 7d 7e 7f 80 81 83
+# Apparently this gives the same information as given by byte at offset 2 but as 16-bit
+#>>(24.s+0x10)	uleshort	x	\b, length %u*512
+# revision level of code/data like: 0 1 201h 502h
+>>(24.s+0xC)	ubyte		>1	\b, code revison %#x
+# code type: 0~Intel x86/PC-AT compatible 1~Open firmware standard for PCI42 FF~Reserved
+>>(24.s+0x14)	ubyte		>0	\b, code type %#x
+# last image indicator; bit 7 indicates "last image"; bits 0-6 are reserved
+>>(24.s+0x15)	ubyte		>0
+>>>(24.s+0x15)	ubyte		=0x80	\b, last ROM
+# THIS SHOULD NOT HAPPEN!
+>>>(24.s+0x15)	ubyte		!0x80	\b, indicator %x
+# 3rd reserved area; seems to be zero in most cases but not for
+# efi-e1000.rom efi-rtl8139.rom
+>>(24.s+0x16)	ubeshort	!0	\b, 3rd reserved %#x
 
 # Flash descriptors for Intel SPI flash roms.
 # From Dr. Jesus <j@hug.gs>

+ 106 - 7
magic/Magdir/javascript

@@ -1,22 +1,121 @@
 
 #------------------------------------------------------------------------------
-# $File: javascript,v 1.2 2019/08/05 10:34:26 christos Exp $
+# $File: javascript,v 1.4 2022/09/02 08:08:17 christos Exp $
 # javascript:  magic for javascript and node.js scripts.
 #
-0	search/1/w	#!/bin/node		Node.js script text executable
+0	string/w	#!/bin/node		Node.js script text executable
 !:mime application/javascript
-0	search/1/w	#!/usr/bin/node		Node.js script text executable
+0	string/w	#!/usr/bin/node		Node.js script text executable
 !:mime application/javascript
-0	search/1/w	#!/bin/nodejs		Node.js script text executable
+0	string/w	#!/bin/nodejs		Node.js script text executable
 !:mime application/javascript
-0	search/1/w	#!/usr/bin/nodejs	Node.js script text executable
+0	string/w	#!/usr/bin/nodejs	Node.js script text executable
 !:mime application/javascript
-0	search/1	#!/usr/bin/env\ node	Node.js script text executable
+0	string		#!/usr/bin/env\ node	Node.js script text executable
 !:mime application/javascript
-0	search/1	#!/usr/bin/env\ nodejs	Node.js script text executable
+0	string		#!/usr/bin/env\ nodejs	Node.js script text executable
 !:mime application/javascript
 # Hermes by Facebook https://hermesengine.dev/
 # https://github.com/facebook/hermes/blob/master/include/hermes/\
 # BCGen/HBC/BytecodeFileFormat.h#L24
 0	lequad		0x1F1903C103BC1FC6	Hermes JavaScript bytecode
 >8	lelong		x			\b, version %d
+
+# v8 JavaScript engine bytecode
+# From: Alexandre Iooss <erdnaxe@crans.org>
+# URL:	https://v8.dev/docs/ignition
+# Note: used in bytenode and NW.js protected source code
+# V8 bytecode extraction was added in NodeJS v5.7.0 (V8 4.6.85.31).
+# Version information is provided for some v8 versions found in NodeJS releases.
+2	uleshort		=0xC0DE
+>0	ulelong^0xC0DE0000	>0
+# Reservation table starts at 40
+>>40	ulelong&0xFFFFFF00	=0x80000000
+# Stub keys present
+>>>24	ulelong			>0
+>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
+>>>>4	ulelong			=0xEE4BF478	version 5.1.281.111,
+>>>>4	ulelong			=0xC4A0100C	version 5.5.372.43,
+>>>>8	ulelong			x		source size: %u bytes,
+>>>>12	ulelong			x		cpu features: %#08X,
+>>>>16	ulelong			x		flag hash: %#08X,
+>>>>20	ulelong			x		%u reservations,
+>>>>28	ulelong			x		payload size: %u bytes,
+>>>>32	ulelong			x		checksum1: %#08X,
+>>>>36	ulelong			x		checksum2: %#08X
+# No stub keys
+>>>24	ulelong			=0
+>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
+>>>>4	ulelong			=0x54F0AD81	version 6.2.414.46,
+>>>>4	ulelong			=0X7D1BF182	version 6.2.414.54,
+>>>>4	ulelong			=0x35BA122E	version 6.2.414.77,
+>>>>4	ulelong			=0X9319F9C2	version 6.2.414.78,
+>>>>4	ulelong			=0xB1240060	version 6.6.346.32,
+>>>>4	ulelong			=0x2B757060	version 6.7.288.46,
+>>>>4	ulelong			=0x09D147AA	version 6.7.288.49,
+>>>>4	ulelong			=0xF4D4F48A	version 6.8.275.32,
+>>>>4	ulelong			=0xD3961326	version 7.0.276.38,
+>>>>8	ulelong			x		source size: %u bytes,
+>>>>12	ulelong			x		cpu features: %#08X,
+>>>>16	ulelong			x		flag hash: %#08X,
+>>>>20	ulelong			x		%u reservations,
+>>>>28	ulelong			x		payload size: %u bytes,
+>>>>32	ulelong			x		checksum1: %#08X,
+>>>>36	ulelong			x		checksum2: %#08X
+# Reservation table starts at 32
+>>32	ulelong&0xFFFFFF00	=0x80000000
+# Second checksum present
+>>>28	ulelong			>0
+>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
+>>>>4	ulelong			=0x21DDF627	version 7.4.288.21,
+>>>>4	ulelong			=0x1FC9FE84	version 7.4.288.27,
+>>>>4	ulelong			=0x60A99E8B	version 7.5.288.22,
+>>>>4	ulelong			=0x4F665E90	version 7.6.303.29,
+>>>>4	ulelong			=0xC7ACFCDE	version 7.7.299.11,
+>>>>4	ulelong			=0x7F641D8F	version 7.7.299.13,
+>>>>4	ulelong			=0xFD9A4F2E	version 7.8.279.17,
+>>>>4	ulelong			=0x3A845324	version 7.8.279.23,
+>>>>4	ulelong			=0xFF52FEAF	version 7.9.317.25,
+>>>>8	ulelong			x		source size: %u bytes,
+>>>>12	ulelong			x		flag hash: %#08X,
+>>>>16	ulelong			x		%u reservations,
+>>>>20	ulelong			x		payload size: %u bytes,
+>>>>24	ulelong			x		checksum1: %#08X,
+>>>>28	ulelong			x		checksum2: %#08X
+# No second checksum
+>>>28	ulelong			=0
+>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
+>>>>4	ulelong			=0x8725E0F8	version 8.1.307.30,
+>>>>4	ulelong			=0x09ED1289	version 8.1.307.31,
+>>>>4	ulelong			=0xA5728C87	version 8.3.110.9,
+>>>>4	ulelong			=0xB45C5D30	version 8.4.371.23,
+>>>>4	ulelong			=0xED9C278B	version 8.4.371.19,
+>>>>4	ulelong			=0xD27BFF42	version 8.6.395.16,
+>>>>8	ulelong			x		source size: %u bytes,
+>>>>12	ulelong			x		flag hash: %#08X,
+>>>>16	ulelong			x		%u reservations,
+>>>>20	ulelong			x		payload size: %u bytes,
+>>>>24	ulelong			x		payload checksum: %#08X
+# No reservation table and code starts at 24
+>>32	ulelong		=0
+>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
+>>>4	ulelong			=0x9A6F0B0F	version 9.0.257.17,
+>>>4	ulelong			=0x271D5D1E	version 9.0.257.24,
+>>>4	ulelong			=0x4EEA75DF	version 9.0.257.25,
+>>>4	ulelong			=0x80809479	version 9.1.269.36,
+>>>4	ulelong			=0x55C46F65	version 9.1.269.38,
+>>>4	ulelong			=0x8A9C758A	version 9.2.230.21,
+>>>4	ulelong			=0x9712F0E1	version 9.3.345.16,
+>>>4	ulelong			=0x29593715	version 9.4.146.19,
+>>>4	ulelong			=0xCD991825	version 9.4.146.24,
+>>>4	ulelong			=0xACDD64EE	version 9.4.146.26,
+>>>4	ulelong			=0xC96B4CD5	version 9.5.172.21,
+>>>4	ulelong			=0xBCCE4578	version 9.5.172.25,
+>>>4	ulelong			=0xA2EEA077	version 9.6.180.15,
+>>>4	ulelong			=0xFD350011	version 10.1.124.8,
+>>>4	ulelong			=0xBEF4028F	version 10.2.154.13,
+>>>4	ulelong			=0xAF632352	version 10.2.154.4,
+>>>8	ulelong			x		source size: %u bytes,
+>>>12	ulelong			x		flag hash: %#08X,
+>>>16	ulelong			x		payload size: %u bytes,
+>>>20	ulelong			x		payload checksum: %#08X

+ 114 - 5
magic/Magdir/jpeg

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: jpeg,v 1.36 2021/08/28 12:30:52 christos Exp $
+# $File: jpeg,v 1.37 2022/06/17 18:03:35 christos Exp $
 # JPEG images
 # SunOS 5.5.1 had
 #
@@ -103,43 +103,152 @@
 #>>(2.S+2)	use			jpeg_segment
 
 # HSI is Handmade Software's proprietary JPEG encoding scheme
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/HSI_JPEG
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-hsi1.trid.xml
+# Note:         called by TrID "HSI JPEG bitmap"
 0	string		hsi1		JPEG image data, HSI proprietary
+#!:mime	application/octet-stream
+!:mime	image/x-hsi
+!:ext	hsi/jpg
 
 # From: David Santinoli <david@santinoli.com>
 0	string		\x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A	JPEG 2000
+# delete from ./animation (version 1.87) with jP (=6A50h) magic at offset 4
 # From: Johan van der Knijff <johan.vanderknijff@kb.nl>
 # Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes
 # https://github.com/bitsgalore/jp2kMagic
 #
 # Now read value of 'Brand' field, which yields a few possibilities:
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/JP2
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpeg2k.trid.xml
+# Note:         called by TrID "JPEG 2000 bitmap"
 >20	string		\x6a\x70\x32\x20	Part 1 (JP2)
+# aliases	image/jpeg2000, image/jpeg2000-image, image/x-jpeg2000-image
 !:mime	image/jp2
+!:ext	jp2
+# URL:		http://fileformats.archiveteam.org/wiki/JPX
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpx.trid.xml
+# Note:         called by TrID "JPEG 2000 eXtended bitmap"
 >20	string		\x6a\x70\x78\x20	Part 2 (JPX)
 !:mime	image/jpx
+!:ext	jpf/jpx
+# URL:		http://fileformats.archiveteam.org/wiki/JPM
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpm.trid.xml
+# Note:         called by TrID "JPEG 2000 eXtended bitmap"
 >20	string		\x6a\x70\x6d\x20	Part 6 (JPM)
 !:mime	image/jpm
+!:ext	jpm
+# URL:		http://fileformats.archiveteam.org/wiki/MJ2
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/v/video-mj2.trid.xml
+# Note:         called by TrID "Motion JPEG 2000 video"
 >20	string		\x6d\x6a\x70\x32	Part 3 (MJ2)
 !:mime	video/mj2
+!:ext	mj2/mjp2
 
 # Type: JPEG 2000 codesream
 # From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/JPEG_2000_codestream
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpc.trid.xml
+# Note:         called by TrID "JPEG-2000 Code Stream bitmap"
 0	belong		0xff4fff51						JPEG 2000 codestream
-45	beshort		0xff52
+# value like: 0701h FF50h
+#>45	ubeshort	x	\b, at 45 %#4.4x
+#!:mime	application/octet-stream
+# https://reposcope.com/mimetype/image/x-jp2-codestream
+!:mime	image/x-jp2-codestream
+!:ext	jpc/j2c/j2k
+# MAYBE also JHC like in byte_causal.jhc ?
+# WHAT IS THAT? DEAD ENTRY?
+#45	beshort		0xff52
 
 # JPEG extended range
+# URL:		http://fileformats.archiveteam.org/wiki/JPEG_XR
+# Reference:	https://www.itu.int/rec/T-REC-T.832
+#		http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-wmp.trid.xml
+# Note:         called by TrID "JPEG XR bitmap"
 0	string		\x49\x49\xbc
+# FILE_VERSION_ID; shall be equal to 1; other values are reserved for future use
 >3	byte		1
+# FIRST_IFD_OFFSET; shall be an integer multiple of 2; so skip DROID fmt-590-signature-id-931.wdp
 >>4	lelong%2	0	JPEG-XR
+#!:mime	image/vnd.ms-photo
 !:mime	image/jxr
-!:ext	jxr
+# NO example for HDP !
+!:ext	jxr/wdp/hdp
+# MAYBE also WMP ?
+#!:ext	jxr/wdp/hdp/wmp
+# moved from ./images (version 1.205 ), merged and
+# partly verified by XnView `nconvert -info abydos.jxr FLOWER.wdp`
+# example: https://web.archive.org/web/20160403012904/
+# http://shikino.co.jp/solution/upfile/FLOWER.wdp.zip
+>90	bequad		0x574D50484F544F00
+>>98	byte&0x08	=0x08			\b, hard tiling
+>>99	byte&0x80	=0x80			\b, tiling present
+>>99	byte&0x40	=0x40			\b, codestream present
+>>99	byte&0x38	x			\b, spatial xform=
+>>99	byte&0x38	0x00			\bTL
+>>99	byte&0x38	0x08			\bBL
+>>99	byte&0x38	0x10			\bTR
+>>99	byte&0x38	0x18			\bBR
+>>99	byte&0x38	0x20			\bBT
+>>99	byte&0x38	0x28			\bRB
+>>99	byte&0x38	0x30			\bLT
+>>99	byte&0x38	0x38			\bLB
+>>100	byte&0x80	=0x80			\b, short header
+>>>102	beshort+1	x			\b, %d
+>>>104	beshort+1	x			\bx%d
+>>100	byte&0x80	=0x00			\b, long header
+>>>102	belong+1	x			\b, %x
+>>>106	belong+1	x			\bx%x
+>>101	beshort&0xf	x			\b, bitdepth=
+>>>101	beshort&0xf	0x0			\b1-WHITE=1
+>>>101	beshort&0xf	0x1			\b8
+>>>101	beshort&0xf	0x2			\b16
+>>>101	beshort&0xf	0x3			\b16-SIGNED
+>>>101	beshort&0xf	0x4			\b16-FLOAT
+>>>101	beshort&0xf	0x5			\b(reserved 5)
+>>>101	beshort&0xf	0x6			\b32-SIGNED
+>>>101	beshort&0xf	0x7			\b32-FLOAT
+>>>101	beshort&0xf	0x8			\b5
+>>>101	beshort&0xf	0x9			\b10
+>>>101	beshort&0xf	0xa			\b5-6-5
+>>>101	beshort&0xf	0xb			\b(reserved %d)
+>>>101	beshort&0xf	0xc			\b(reserved %d)
+>>>101	beshort&0xf	0xd			\b(reserved %d)
+>>>101	beshort&0xf	0xe			\b(reserved %d)
+>>>101	beshort&0xf	0xf			\b1-BLACK=1
+>>101	beshort&0xf0	x			\b, colorfmt=
+>>>101	beshort&0xf0	0x00			\bYONLY
+>>>101	beshort&0xf0	0x10			\bYUV240
+>>>101	beshort&0xf0	0x20			\bYWV422
+>>>101	beshort&0xf0	0x30			\bYWV444
+>>>101	beshort&0xf0	0x40			\bCMYK
+>>>101	beshort&0xf0	0x50			\bCMYKDIRECT
+>>>101	beshort&0xf0	0x60			\bNCOMPONENT
+>>>101	beshort&0xf0	0x70			\bRGB
+>>>101	beshort&0xf0	0x80			\bRGBE
+>>>101	beshort&0xf0	>0x80			\b(reserved %#x)
 
 # JPEG XL
 # From: Ian Tester
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/JPEG_XL
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl.trid.xml
+# Note:         called by TrID "JPEG XL bitmap"
 0	string	\xff\x0a				JPEG XL codestream
-!:mime  image/jxl
+#!:mime  image/jxl
+!:mime	image/x-jxl
 !:ext jxl
 
 # JPEG XL (transcoded JPEG file)
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/JPEG_XL
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl-iso.trid.xml 
+# Note:         called by TrID "JPEG XL bitmap (ISOBMFF)"
 0	string	\x00\x00\x00\x0cJXL\x20\x0d\x0a\x87\x0a	JPEG XL container
-!:mime  image/jxl
+#!:mime  image/jxl
+!:mime	image/x-jxl
 !:ext jxl

+ 24 - 13
magic/Magdir/linux

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: linux,v 1.79 2021/04/26 15:56:00 christos Exp $
+# $File: linux,v 1.82 2022/09/07 11:23:44 christos Exp $
 # linux:  file(1) magic for Linux files
 #
 # Values for Linux/i386 binaries, from Daniel Quinlan <quinlan@yggdrasil.com>
@@ -364,16 +364,6 @@
 >24	lelong	x			%d symbols
 >28	lelong	x			%d ocons
 
-# LUKS: Linux Unified Key Setup, On-Disk Format, http://luks.endorphin.org/spec
-# Anthon van der Neut (anthon@mnt.org)
-0	string	LUKS\xba\xbe	LUKS encrypted file,
->6	beshort x		ver %d
->8	string	x		[%s,
->40	string	x		%s,
->72	string	x		%s]
->168	string	x		UUID: %s
-
-
 # Summary: Xen saved domain file
 # Created by: Radek Vokal <rvokal@redhat.com>
 0	string		LinuxGuestRecord	Xen saved domain
@@ -532,6 +522,27 @@
 
 # ansible vault (does not really belong here)
 0		string		$ANSIBLE_VAULT;	Ansible Vault
->&0		regex		[0-9]*\.[0-9]*	\b, version %s
+>&0		regex		[0-9]+\\.[0-9]+	\b, version %s
 >>&0		string		;
->>>&0		regex		[A-Z0-9]*	\b, encryption %s
+>>>&0		regex		[A-Z0-9]+	\b, encryption %s
+
+# From:		Joerg Jenderek
+# URL:		https://www.gnu.org/software/grub
+# Reference:	https://ftp.gnu.org/gnu/grub/grub-2.06.tar.gz
+#		grub-2.06/include/grub/keyboard_layouts.h 
+#		grub-2.06/grub-core/commands/keylayouts.c
+# GRUB_KEYBOARD_LAYOUTS_FILEMAGIC
+0	string		GRUBLAYO		GRUB Keyboard
+!:mime			application/x-grub-keyboard
+!:ext			gkb
+# GRUB_KEYBOARD_LAYOUTS_VERSION like: 10
+>8	ulelong		!10			\b, version %u
+# 4 grub_uint32_t grub_keyboard_layout[160]
+# for normal french keyboard this is letter a
+>92	ubyte		!0x71
+>>92	ubyte		>0x40			\b, english q is %c
+#>732	ubyte		x			\b, english Q is %c
+# for normal german keyboard this is letter z
+>124	ubyte		!0x79
+>>124	ubyte		>0x40			\b, english y is %c
+#>764	ubyte		x			\b, english Y is %c

+ 115 - 2
magic/Magdir/luks

@@ -1,13 +1,126 @@
 
 #------------------------------------------------------------------------------
-# $File: luks,v 1.4 2009/09/19 16:28:10 christos Exp $
+# $File: luks,v 1.5 2022/09/07 11:23:44 christos Exp $
 # luks:  file(1) magic for Linux Unified Key Setup
-# URL:	http://luks.endorphin.org/spec
+# URL:		https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup
+#		http://fileformats.archiveteam.org/wiki/LUKS
 # From:	Anthon van der Neut <anthon@mnt.org>
+# Update:	Joerg Jenderek
+# Note:		verfied by command like `cryptsetup luksDump /dev/sda3`
 
 0	string		LUKS\xba\xbe	LUKS encrypted file,
+# https://reposcope.com/mimetype/application/x-raw-disk-image
+!:mime	application/x-raw-disk-image
+#!:mime	application/x-luks-volume
+# img is the generic extension; no suffix for partitions; luksVolumeHeaderBackUp via zuluCrypt
+!:ext	/luks/img/luksVolumeHeaderBackUp
+# version like: 1 2
 >6	beshort		x		ver %d
+# test for version 1 variant
+>6	beshort		1
+>>0			use		luks-v1
+# test for version 2 variant
+>6	beshort		>1
+>>0			use		luks-v2
+# Reference:	https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/LUKS_docs/on-disk-format.pdf
+#		http://mark0.net/download/triddefs_xml.7z/defs/l/luks.trid.xml
+# display information about LUKS version 1
+0	name		luks-v1
+# cipher-name like: aes twofish
 >8	string		x		[%s,
+# cipher-mode like: xts-plain64 cbc-essiv
 >40	string		x		%s,
+# hash specification like: sha256 sha1 ripemd160
 >72	string		x		%s]
 >168	string		x		UUID: %s
+# NEW PART!
+# payload-offset; start offset of the bulk data
+>104	 ubelong	x		\b, at %#x data
+# key-bytes; number of key bytes; key-bytes*8=MK-bits
+>108	 ubelong	x		\b, %u key bytes
+# mk-digest[20]; master key checksum from PBKDF2
+>112	ubequad		x		\b, MK digest %#16.16llx
+>>120	ubequad		x		\b%16.16llx
+>>128	ubelong		x		\b%8.8x
+# mk-digest-salt[32]; salt parameter for master key PBKDF2
+>132	ubequad		x		\b, MK salt %#16.16llx
+>>140	ubequad		x		\b%16.16llx
+>>148	ubequad		x		\b%16.16llx
+>>156	ubequad		x		\b%16.16llx
+# mk-digest-iter; iterations parameter for master key PBKDF2
+>164	ubelong		x		\b, %u MK iterations
+# key slot 1
+>208	ubelong		=0x00AC71F3	\b; slot #0
+>>208			use		luks-slot
+# key slot 2
+>256	ubelong		=0x00AC71F3	\b; slot #1
+>>256			use		luks-slot
+# key slot 3
+>304	ubelong		=0x00AC71F3	\b; slot #2
+>>304			use		luks-slot
+# key slot 4
+>352	ubelong		=0x00AC71F3	\b; slot #3
+>>352			use		luks-slot
+# key slot 5
+>400	ubelong		=0x00AC71F3	\b; slot #4
+>>400			use		luks-slot
+# key slot 6
+>448	ubelong		=0x00AC71F3	\b; slot #5
+>>448			use		luks-slot
+# key slot 7
+>496	ubelong		=0x00AC71F3	\b; slot #6
+>>496			use		luks-slot
+# key slot 8
+>544	ubelong		=0x00AC71F3	\b; slot #7
+>>544			use		luks-slot
+# Reference:	https://gitlab.com/cryptsetup/LUKS2-docs/-/raw/master/luks2_doc_wip.pdf
+#		http://mark0.net/download/triddefs_xml.7z/defs/l/luks2.trid.xml
+# display information about LUKS version 2
+0	name		luks-v2
+# hdr_size; size including JSON area called Metadata area by cryptsetup with value like: 16384
+>8	ubequad		x		\b, header size %llu
+# possible check for MAGIC_2ND after header 
+#>(8.Q) 	 string		SKUL\xba\xbe	\b, 2nd_HEADER_OK
+# seqid; sequence ID, increased on update; called Epoch by cryptsetup with value like: 3 4 8 10
+>16	ubequad		x		\b, ID %llu
+# label[48]; optional ASCII label or empty; called Label by cryptsetup with value like: "LUKS2_EXT4_ROOT"
+>24	string		>\0		\b, label %s
+# csum_alg[32]; checksum algorithm like: sha256 sha1 sha512 wirlpool ripemd160
+>72	string		x		\b, algo %s
+# salt[64]; salt , unique for every header
+>104	ubequad		x		\b, salt %#llx...
+# uuid[40]; UID of device as string like: 242256c6-396e-4a35-af5f-5b70cb7af9a7
+>168	string		x		\b, UUID: %-.40s
+# subsystem[48]; optional owner subsystem label or empty
+>208	string		>\0		\b, sub label %-.48s
+# hdr_offset; offset from device start [ bytes ] like: 0
+>256	ubequad		!0		\b, offset %llx
+# char _padding [184]; must be zeroed
+#>264	ubequad		x		\b, padding %#16.16llx
+#>440	ubequad		x		\b...%16.16llx
+# csum[64]; header checksum
+>448	ubequad		x		\b, crc %#llx...
+# char _padding4096 [7*512];  Padding , must be zeroed
+#>512	ubequad		x		\b, more padding %#16.16llx
+#>4088	ubequad		x		\b...%16.16llx
+# JSON text data terminated by the zero character; unused remainder empty and filled with zeroes like:
+# {"keyslots":{"0":{"type":"luks2","key_size":64,"af":{"type":"luks1","stripes":4000,"hash":"sha256"},"area":{"type":"raw","offse"
+>0x1000	string		x		\b, at 0x1000 %s
+#>0x1000	indirect	x
+# display information (like active) about LUKS1 slot
+0	name		luks-slot
+# state of keyslot; 0x00AC71F3~active 0x0000DEAD~inactive
+#>0	ubelong		x		\b, status %#8.8x
+>0	ubelong		=0x00AC71F3	active
+>0	ubelong		=0x0000DEAD	inactive
+# iteration parameter for PBKDF2
+#>4	ubelong		x		\b, %u iterations
+# salt parameter for PBKDF2
+#>8	ubequad		x		\b, salt %#16.16llx
+#>>16	ubequad		x		\b%16.16llx
+#>>24	ubequad		x		\b%16.16llx
+#>>32	ubequad		x		\b%16.16llx
+# start sector of key material like: 8 0x200 0x3f8 0x5f0 0xdd0
+>40	ubelong		x		\b, %#x material offset
+# number of anti-forensic stripes like: 4000
+>44	ubelong		!4000		\b, %u stripes

+ 48 - 2
magic/Magdir/mail.news

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: mail.news,v 1.28 2021/09/11 19:20:15 christos Exp $
+# $File: mail.news,v 1.29 2022/06/17 18:02:19 christos Exp $
 # mail.news:  file(1) magic for mail and news
 #
 # Unfortunately, saved netnews also has From line added in some news software.
@@ -44,8 +44,54 @@
 #0	string/t		Content-	MIME entity text
 
 # TNEF files...
-0	lelong		0x223E9F78	Transport Neutral Encapsulation Format
+# URL:		http://fileformats.archiveteam.org/wiki/Transport_Neutral_Encapsulation_Format
+#		https://en.wikipedia.org/wiki/Transport_Neutral_Encapsulation_Format
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/t/tnef.trid.xml
+#		https://interoperability.blob.core.windows.net/files/MS-OXTNEF/%5bMS-OXTNEF%5d-210817.pdf
+# Update:	Joerg Jenderek
+# Note:		moved and merged from ./msdos (version 1.154) there just called "TNEF"
+#		partly verified by `tnef --list -v -f voice.tnef` and `ytnef -v  triples.tnef`
+# TNEF magic From "Joomy" <joomy@se-ed.net>
+# TNEF_SIGNATURE 
+0	lelong		0x223E9F78	Transport Neutral Encapsulation Format (TNEF)
 !:mime	application/vnd.ms-tnef
+# winmail.dat or win.dat by Microsoft Outlook
+!:ext	tnef/dat
+# https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxtnef/7fdb64ee-7f63-4d95-9af1-c672e7475c3a
+# LegacyKey
+#>4	uleshort	x		\b, key %#4.4x
+# attrLevelMessage; Level where attribute applies like: 1~attrLevelMessage 2~attrLevelAttachment
+>6	ubyte		!1		\b, 1st level %#2.2x
+# other ID (like 02900000h) or TnefVersion ID (idTnefVersion=06900800h)
+>7	ubelong		!0x06900800	\b, 1st id %#8.8x
+>7	ubelong		=0x06900800
+# TnefVersion lenght like: 4
+>>11	ulelong		!4		\b, TnefVersion length %x
+# TNEFVersionData; TnefVersion data like: 00010000h
+>>15	ulelong		!0x00010000h	\b, version %#8.8x
+# Checksum like: 1
+>>19	uleshort	!1		\b, checksum %#4.4x
+# attrLevelMessage; level of attOemCodepage like: 1
+>>21	ubyte		!1		\b, level %#2.2x
+# idOEMCodePage; OEMCodePage ID like: 07900600h
+>>22	ubelong		=0x07900600	\b, OEM codepage
+# OEMCodePage length like: 8
+>>>26	ulelong		=8		
+# OEMCodePageData; PrimaryCodePage like: 1251 1252
+>>>>30	ulelong		x		%u
+# OEMCodePageData; SecondaryCodePage; unused and SHOULD contain zero
+>>>>34	ulelong		!0		and %u
+# OEMCodePageData Checksum like: E7h E8h
+>>>>38	uleshort	x		(checksum %#x)
+# attrLevelMessage of attMessageClass like: 1
+>>40	ubyte		!1		\b, level %u
+# idMessageClass; ID of attMessageClass like: 08800700h
+>>41	ubelong		=0x08800700	\b, MessageAttribute
+# attMessageClass length like: 16 24 25
+#>>>45	ulelong		x		(length %u)
+# attMessageClass data like: "IPM.Microsoft Mail.Note" "IPM.Note.Portada Newseum"
+# "IPM.Appointment" "IPM.Note.Microsoft.Voicemail.UM.CA"
+>>>45	pstring/l	x		"%s"
 
 # From: Kevin Sullivan <ksulliva@psc.edu>
 0	string		*mbx*		MBX mail folder

+ 7 - 22
magic/Magdir/make

@@ -1,36 +1,21 @@
 #------------------------------------------------------------------------------
-# $File: make,v 1.4 2018/05/29 17:26:02 christos Exp $
+# $File: make,v 1.5 2022/03/12 15:09:47 christos Exp $
 # make:  file(1) magic for makefiles
 #
 # URL: https://en.wikipedia.org/wiki/Make_(software)
-0	regex/100l	\^CFLAGS	makefile script text
-!:mime	text/x-makefile
-0	regex/100l	\^VPATH		makefile script text
-!:mime	text/x-makefile
-0	regex/100l	\^LDFLAGS	makefile script text
-!:mime	text/x-makefile
-0	regex/100l	\^all:		makefile script text
-!:mime	text/x-makefile
-0	regex/100l	\^\\.PRECIOUS	makefile script text
+0	regex/100l	\^(CFLAGS|VPATH|LDFLAGS|all:|\\.PRECIOUS)	makefile script text
 !:mime	text/x-makefile
+!:strength -15
 # Update: Joerg Jenderek
 # Reference: https://www.freebsd.org/cgi/man.cgi?make(1)
 # exclude grub-core\lib\libgcrypt\mpi\Makefile.am with "#BEGIN_ASM_LIST"
 # by additional escaping point character
-0	regex/100l	\^\\.BEGIN	BSD makefile script text
-!:mime	text/x-makefile
-!:ext	/mk
-!:strength +10
 # exclude MS Windows help file CoNtenT with ":include FOOBAR.CNT"
 # and NSIS script with "!include" by additional escaping point character
-0	regex/100l	\^\\.include	BSD makefile script text
-!:mime	text/x-makefile
-!:ext	/mk
-!:strength +10
-0	regex/100l	\^\\.endif	BSD makefile script text
+0	regex/100l	\^\\.(BEGIN|endif|include)	BSD makefile script text
 !:mime	text/x-makefile
 !:ext	/mk
-!:strength +10
-0	regex/100l	\^SUBDIRS	automake makefile script text
+!:strength -10
+0	regex/100l	\^SUBDIRS[[:space:]]+=	automake makefile script text
 !:mime	text/x-makefile
-!:strength +10
+!:strength -15

+ 24 - 9
magic/Magdir/mathematica

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: mathematica,v 1.13 2021/07/14 09:06:24 christos Exp $
+# $File: mathematica,v 1.14 2021/11/07 16:27:36 christos Exp $
 # mathematica:  file(1) magic for mathematica files
 # "H. Nanosecond" <aldomel@ix.netcom.com>
 # Mathematica a multi-purpose math program
@@ -117,16 +117,29 @@
 13	ushort	0
 # check for valid ASCII matrix name
 >20	ubyte	>0x1F
+# skip PreviousEntries.dat with "invalid high" name \304P\344@\001
+>>20	ubyte	<0304
+# skip some Netwfw*.dat and $I3KREPH.dat by checking for non zero number of rows
+>>>4	ulong		!0
 # skip some CD-ROM filesystem like test-hfs.iso by looking for valid big endian type flag
->>0	ubelong&0xFFffFF00	0x00000300
->>>0	use	matlab4
+>>>>0	ubelong&0xFFffFF00	0x00000300
+>>>>>0	use	matlab4
 # no example for 8-bit and 16-bit integers matrix
->>0	ubelong&0xFFffFF00	0x00000400
->>>0	use	matlab4
->>0	ulelong		x
+>>>>0	ubelong&0xFFffFF00	0x00000400
+>>>>>0	use	matlab4
+#	branch for Little-Endian variant of Matlab MATrix version 4
 # skip big endian variant by looking for valid low lttle endian type flag
->>0	ulelong		<53
->>>0	use	\^matlab4
+>>>>0	ulelong		<53
+# skip tokens.dat and some Netwfw*.dat by check for valid imaginary flag value of MAT version 4
+>>>>>12	ulelong		<2
+# no misidentfied little endian MATrix example with "short" matrix name
+>>>>>>16	ulelong		<3
+>>>>>>>0	use	\^matlab4
+# little endian MATrix with "long" matrix name or some misidentified samples
+>>>>>>16	ulelong		>2
+# skip TileCacheLogo-*.dat with invalid 2nd character \001 of matrix name with length 96
+>>>>>>>21 ubyte	>0x1F
+>>>>>>>>0 use	\^matlab4
 #	display information of Matlab v4 mat-file
 0	name	matlab4		Matlab v4 mat-file
 #!:mime	application/octet-stream
@@ -145,8 +158,10 @@
 >0	ubelong/1000	4	(Cray)
 # namlen; the length of the matrix name
 #>16	ubelong		x	\b, name length %u
+#>(16.L+19)	ubyte	x	\b, TERMINATING NAME CHARACTER=%#x
 # nul terminated matrix name like: fit_params testmatrix testsparsecomplex teststringarray
 #>20	string		x	\b, MATRIX NAME="%s"
+#>21		ubyte	x	\b, MAYBE 2ND CHAR=%c
 >16	pstring/L	x	%s
 # T indicates the matrix type: 0~numeric 1~text 2~sparse
 #>0	ubelong%10	x	\b, T=%u
@@ -158,5 +173,5 @@
 # ncols; number of columns in the matrix like: 1 3 4 5 9 43
 >8	ubelong		x	\b, columns %u
 # imagf; imaginary flag; 1~matrix has an imaginary part 0~only real data
->12	ubelong		!0	\b, imaginary
+>12	ubelong		!0	\b, imaginary (%u)
 # real; Real part of the matrix consists of mrows * ncols numbers

+ 15 - 1
magic/Magdir/mcrypt

@@ -1,14 +1,28 @@
 
 #------------------------------------------------------------------------------
-# $File: mcrypt,v 1.5 2009/09/19 16:28:10 christos Exp $
+# $File: mcrypt,v 1.6 2022/02/08 18:51:45 christos Exp $
 # Mavroyanopoulos Nikos <nmav@hellug.gr>
 # mcrypt:   file(1) magic for mcrypt 2.2.x;
+# URL: 		https://en.wikipedia.org/wiki/Mcrypt
+#		http://fileformats.archiveteam.org/wiki/MCrypt
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/n/nc-mcrypt.trid.xml
+# Update:	Joerg Jenderek
+# Note:		called by TrID "mcrypt encrypted (v2.5)"
 0	string		\0m\3		mcrypt 2.5 encrypted data,
+#!:mime	application/octet-stream
+!:mime	application/x-crypt-nc
+!:ext	nc
 >4	string		>\0		algorithm: %s,
 >>&1	leshort		>0		keysize: %d bytes,
 >>>&0	string		>\0		mode: %s,
 
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/n/nc-mcrypt-22.trid.xml
+# Note:		called by TrID "mcrypt encrypted (v2.2)"
 0	string		\0m\2		mcrypt 2.2 encrypted data,
+#!:mime	application/octet-stream
+!:mime	application/x-crypt-nc
+# no example
+!:ext	nc
 >3	byte		0		algorithm: blowfish-448,
 >3	byte		1		algorithm: DES,
 >3	byte		2		algorithm: 3DES,

+ 222 - 37
magic/Magdir/msdos

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: msdos,v 1.152 2021/10/12 18:26:10 christos Exp $
+# $File: msdos,v 1.158 2022/09/07 11:17:31 christos Exp $
 # msdos:  file(1) magic for MS-DOS files
 #
 
@@ -587,7 +587,8 @@
 # skip "GPG symmetrically encrypted data" ./gnu
 # skip "PGP symmetric key encrypted data" ./pgp
 # openpgpdefs.h: fourth byte < 14 indicate cipher algorithm type
->>>4	ubyte			>13	DOS executable (COM, 0x8C-variant)
+>>>4	ubyte			>13
+>>>>0		use	msdos-com
 # the remaining files should be DOS *.COM executables
 # dosshell.COM	8cc0 2ea35f07 e85211 e88a11 b80058 cd
 # hmload.COM	8cc8 8ec0 bbc02b 89dc 83c30f c1eb04 b4
@@ -597,48 +598,164 @@
 # SHARE.COM	8cca 2e8916 d602 b430 cd21 8b 2e0200 8b
 # validchr.COM	8cca 2e8916 9603 b430 cd21 8b 2e028b1e
 # devload.COM	8cca 8916ad01 b430 cd21 8b2e0200 892e
-!:mime	application/x-dosexec
-!:ext com
-
-# updated by Joerg Jenderek at Oct 2008
-0	ulelong		0xffff10eb	DR-DOS executable (COM)
-# byte 0xeb conflicts with "sequent" magic leshort 0xn2eb
-0	ubeshort&0xeb8d	>0xeb00
-# DR-DOS STACKER.COM SCREATE.SYS missed
 
 0       name    msdos-com
->0  byte        x               DOS executable (COM)
-!:mime	application/x-dosexec
-!:ext	com
+# URL:		http://fileformats.archiveteam.org/wiki/DOS_executable_(.com)
+>0  byte        x               DOS executable (
+# DOS execuable with JuMP 16-bit instruction
+>0	byte			=0xE9
+# check for probably nil padding til offset 64 of Lotus driver name
+>>56		quad		=0
+# check for "long" alpabetical Lotus driver name like:
+# Diablo "COMPAQ Text Display" "IBM Monochrome Display" "Plantronics ColorPlus"
+>>>24			regex	=^[A-Z][A-Za-z\040]{5,21}	\bLotus driver) %s
+!:mime				application/x-dosexec
+# like: CPQ0TD.DRV IBM0MONO.DRV (Lotus 123 10a) SDIAB4.DRV SPL0CPLS.DRV (Lotus Symphony 2)
+!:ext				drv
+# COM with nils like MODE.COM IBMDOS.COM (pcdos 3.31 ru Compaq) RSSTUB.COM (PC-DOS 2000 de) ACCESS.COM (Lotus Symphony 1)
+>>>24			default	x				\bCOM)
+!:mime				application/x-dosexec
+!:ext				com
+# DOS excutable with JuMP 16-bit and without nil padding
+>>56		quad		!0
+# https://wiki.syslinux.org/wiki/index.php?title=Doc/comboot
+# TODO: HOWTO distinguish COMboot from pure DOS executables?
+# look for unreliable Syslinux specific api call INTerrupt 22h for 16-bit COMBOOT program
+>>>1			search/0xc088	\xcd\x22		\bCOM or COMBOOT 16-bit)
+!:mime				application/x-dosexec
+# like: sbm.cbt command.com (Windows XP) UNI2ASCI.COM (FreeDOS 1.2)
+!:ext				com/cbt
+>>>1			default		x			\bCOM)
+!:mime				application/x-dosexec
+!:ext				com
+# DOS executable without JuMP 16-bit instruction
+>0	byte			!0xE9
+# SCREATE.SYS	https://en.wikipedia.org/wiki/Stac_Electronics
+>>10		string		=?STACVOL			\bSCREATE.SYS)
+!:mime			application/x-dosexec
+!:ext			sys
+# COM executable without JuMP 16-bit instruction and not SCREATE.SYS
+>>10		string		!?STACVOL			\bCOM)
+!:mime			application/x-dosexec
+!:ext			com
 >6	string		SFX\ of\ LHarc	\b, %s
 >0x1FE leshort	0xAA55		    \b, boot code
 >85	string		UPX		        \b, UPX compressed
 >4	string		\ $ARX		    \b, ARX self-extracting archive
 >4	string		\ $LHarc	    \b, LHarc self-extracting archive
 >0x20e string	SFX\ by\ LARC	\b, LARC self-extracting archive
+# like: E30ODI.COM MADGEODI.COM UNI2ASCI.COM RECOVER.COM (DOS 2) COMMAND.COM (DOS 2)
+>1	search/0xc088	\xcd\x22	\b, maybe with interrupt 22h
+>0	ubelong		x		\b, start instruction %#8.8x
+# show more instructions but not in samples like: rem.com (DJGPP)
+>4	ubelong		x		%8.8x
 
 # JMP 8bit
 0	        byte	0xeb
+# byte 0xeb conflicts with magic leshort 0xn2eb of "SYMMETRY i386" handled by ./sequent
 # allow forward jumps only
 >1          byte    >-1
 # that offset must be accessible
+# with hexadecimal values like: 0e 2e 50 8c 8d ba bc bd be e8 fb fc
 >>(1.b+2)   byte    x
->>>0        use msdos-com
-
+# if look like COM executable with x86 boot signature then this
+# implies FAT volume with x86 real mode code already handled by ./filesystems
+#
+# No x86 boot signature implies often DOS executable
+# check for unrealistic high number of FATs. Then it is an unusual disk image or often a DOS executable
+# like: FIXBIOS.COM (50 bytes)
+>>>16		ubyte		>3
+# https://www.drivedroid.io/
+# skip MBR disk image drivedroid.img version 12 July 2013 by start message
+>>>>2		string		!DriveDroid
+# ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/
+# skip unusual floppy image disk1.img of MS-DOS 1.25 (Corona Data Systems OEM)
+# by check for characteristic message text near the beginning
+>>>>>15		string		!Non\040System\040disk
+# "ftp://old-dos.ru/OSCollect/OS/BeOS/BeOS 4.0.rar"
+# skip BeOS 4 bootfloppy.img done as "Linux kernel x86 boot executable" by ./linux
+# by check for characteristic message text near the beginning
+>>>>>>6		string		!read\040error\015
+# https://github.com/ventoy/Ventoy/releases/download/v1.0.78/ventoy-1.0.78-windows.zip
+# skip ventoy 1.0.78 boot_hybrid.img
+>>>>>>>24	string		!\220\220\353I$\022\017
+# "ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/PC-DOS 1.0 (5.25).rar"
+# skip unusual floppy image PCDOS100.IMG of DOS 1.0
+# by check for characteristic message text near the beginning
+>>>>>>>>9	string		!7-May-81
+# "ftp://old-dos.ru/OSCollect/OS/BeOS/BeOS 5.0 Personal (BA).rar"
+# skip BeOS 5 floppy_1.44.00.ima done as "DOS/MBR boot sector" by ./filesystems
+# by check for characteristic message near the beginning
+>>>>>>>>>3	string		!\370sdfS\270
+# like: FIXBIOS.COM (50 bytes)
+>>>>>>>>>>0		use		msdos-com
+# check for unrealistic low number of FATs. Then it is an unusual FAT disk image or often a DOS executable
+# like: DEVICE.COM INSTALL.COM (GAG 4.10) WORD.COM (Word 1.15)
+>>>16		ubyte		=0
+# if low FATs with x86 boot signature it can be unusual disk image like: boot.img (Ventoy 1.0.27) geodspms.img (Syslinux)
+>>>>0x1FE	leshort		=0xAA55
+>>>>0x1FE	default		x
+# https://thestarman.pcministry.com/tool/hxd/dimtut.htm
+# skip unusual floppy image TK-DOS11.img IBMDOS11.img of IBM DOS 1.10
+# by check for characteristic bootloader names near end of boot sector
+>>>>>395	string		!ibmbio\040\040com
+>>>>>>0			use		msdos-com
+# 8-bit jump with valid number of FAT implies FAT volume already handled by ./filesystems
+# like: balder.img
+>>>16		default		x
+# skip disk images with boot signature at end of 1st sector
+# like: TDSK-64b.img
+>>>>(11.s-2)	uleshort	!0xAA55
+# skip unusual floppy image without boot signature like 360k-256.img (mtools 4.0.18)
+# by check for characteristic file system type text for FAT (12 bit or 16 bit)
+>>>>>54		string		!FAT
+# "ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/Microsoft MS-DOS 3.31 (Compaq OEM) (3.5).rar" 
+# skip unusual floppy image Disk4.img without boot signature and file system type text
+# by check for characteristic OEM-ID text
+>>>>>>3		string		!COMPAQ\040\040
+# no such DOS COM executables found
+>>>>>>>0		use		msdos-com
 # JMP 16bit
 0           byte    0xe9
+# 16-bit offset; for DEBUGGING!; can be negative like: USBDRIVE.COM
+#>1		leshort		x	\b, OFFSET %d
 # forward jumps
->1          short   >-1
+>1		leshort	>-1
 # that offset must be accessible
+# with hexadecimal values like: 06 1e 0e 2e 60 8c 8d b4 ba be e8 fc
 >>(1.s+3)   byte    x
->>>0        use msdos-com
+# check for unrealistic high number of FATs. Then it is not a disk image and it is a DOS executable
+# like: CALLVER.COM CPUCACHE.COM K437_EUR.COM SHSUCDX.COM UMBFILL.COM (183 bytes)
+>>>16		ubyte		>3
+>>>>0			use		msdos-com
+# check for unrealistic low number of FATs. Then it is not a disk image and it is a DOS executable
+# like: GAG.COM DRMOUSE.COM NDN.COM CPQ0TD.DRV
+>>>16		ubyte		=0
+>>>>0			use		msdos-com
+# maybe disc image with valid number of FATs or DOS executable
+# like: IPXODI.COM PERUSE.COM TASKID.COM
+>>>16		default	x
+# invalid low media descriptor. Then it is not a disk image and it is a DOS executable
+>>>>21		ubyte		<0xE5
+>>>>>0			use		msdos-com
+# valid media descriptor. Then it is maybe disk image or DOS executable
+>>>>21		ubyte		>0xE4
+# invalid sectorsize not a power of 2 from 32-32768. Then it is not a disk image and it must be DOS executable
+# like: LEARN.COM (Word 1.15)
+>>>>>11		uleshort&0x001f	!0
+>>>>>>0			use		msdos-com
 # negative offset, must not lead into PSP
->1          short   <-259
+# like: BASICA.COM (PC dos 3.20) FORMAT.COM SMC8100.COM WORD.COM (word4)
+# HIDSUPT1.COM USBDRIVE.COM USBSUPT1.COM USBUHCI.COM (FreeDOS USBDOS)
+>1		leshort	<-259
 # that offset must be accessible
+# add 10000h to jump at end of 64 KiB segment, add 1 for jump instruction and 2 for 16-bit offset
 >>(1,s+65539)   byte    x
+# after jump next instruction for DEBUGGING!
+#>>>&-1		ubelong	x	\b, NEXT instruction %#8.8x
 >>>0        use msdos-com
 
-# updated by Joerg Jenderek at Oct 2008,2015
+# updated by Joerg Jenderek at Oct 2008,2015,2022
 # following line is too general
 0	ubyte		0xb8
 # skip 2 linux kernels like memtest.bin with "\xb8\xc0\x07\x8e" in ./linux
@@ -661,19 +778,49 @@
 # syslinux version (4.x)
 # "COM executable (COM32R)" or "Syslinux COM32 module" by TrID
 >>>1	lelong		0x21CD4CFe	\b, relocatable)
-# Hajin Jang <hajin_jang@worksmobile.com>:
-# Disable simplest COM signature to prevent false positive on some EUC-KR text files.
-## remaining are DOS COM executables starting with assembler instruction MOV
-## like FreeDOS BANNER*.COM FINDDISK.COM GIF2RAW.COM WINCHK.COM
-## MS-DOS SYS.COM RESTART.COM
-## SYSLINUX.COM (version 1.40 - 2.13)
-## GFXBOOT.COM (version 3.75)
-## COPYBS.COM POWEROFF.COM INT18.COM
->>1	default	x			COM executable for DOS
-!:mime	application/x-dosexec
-##!:mime	application/x-ms-dos-executable
-##!:mime	application/x-msdos-program
-!:ext com
+>>1	default	x
+# look for interrupt instruction like in rem.com (DJGPP) LOADER.COM (DR-DOS 7.x)
+>>>3	search/118	\xCD
+# FOR DEBUGGING; possible hexadecimal interupt number like: 10~BANNER.COM 13~bcdw_cl.com 15~poweroff.com (Syslinux)
+# 1A~BERNDPCI.COM 20~SETENHKB.COM 21~mostly 22~gfxboot.com (Syslinux) 2F~SHUTDOWN.COM (GEMSYS)
+#>>>>&0	ubyte	x			\b, INTERUPT %#x
+# few examples with interrupt 0x13 instruction
+>>>>&0	ubyte	=0x13
+# FOR DEBUGGING!
+#>>>>>3	ubequad	x			\b, 2nd INSTRUCTION %#16.16llx
+# skip Gpt.com Mbr.com (edk2-UDK2018 bootsector) described as "DOS/MBR boot sector" by ./filesystems
+# by check for assembler instructions: mov  es,ax ; mov  ax,07c0h ; mov ds,ax 
+>>>>>3	ubequad	!0x8ec0b8c0078ed88d
+# few COM exectables with interrupt 0x13 instruction like: Bootable CD Wizard executables bcdw_cl.com fdemuoff.com
+# http://bootcd.narod.ru/bcdw150z_en.zip
+>>>>>>0		use		msdos-com
+# few examples with interrupt 0x16 instruction like flashimg.img
+>>>>&0	ubyte	=0x16
+# skip Syslinux 3.71 flashimg.img done as "DOS/MBR boot sector" by ./filesystems
+# by check for assembler instructions: cmp ax 0xE4E4 (magic); jnz
+>>>>>8	ubelong	!0x3DE4E475
+# no DOS executable with interrupt 0x16 found
+>>>>>>0		use		msdos-com
+# most examples with interrupt instruction unequal 0x13 and 0x16
+>>>>&0	default	x
+#>>>>>&-1 ubyte	x			\b, INTERUPT %#x
+# like: LOADER.COM SETENHKB.COM banner.com copybs.com gif2raw.com poweroff.com rem.com
+>>>>>0		use		msdos-com
+# few COM executables without interupt instruction like RESTART.COM (DOS 7.10) REBOOT.COM
+# or some EUC-KR text files or one Ulead Imaginfo thumbnail
+>>>3	default	x
+# FOR DEBUGGING; 2nd instruction like 0x50 (RESTART.COM) 0x8e (REBOOT.COM)
+# or random like: 0x0 (IMAGINFO.PE3 sky_snow) 0xb1 (euckr_.txt)
+#>>>>3	ubyte	x			\b, 2nd INSTRUCTION %#x
+# skip 1 Ulead Imaginfo thumbnail (IMAGINFO.PE3 sky_snow) 
+# inside SAMPLES/TEXTURES/SKY_SNOW
+# from https://archive.org/download/PI3CANON/PI3CANON.iso
+>>>>3	ubyte	!0x0
+# skip some EUC-KR text files like: euckr_falsepositive.txt
+# https://bugs.astron.com/view.php?id=186
+>>>>>3	ubyte	!0xb1
+# like: RESTART.COM (DOS 7.10) REBOOT.COM
+>>>>>>0	use		msdos-com
 
 # URL:		https://en.wikipedia.org/wiki/UPX
 # Reference:	https://github.com/upx/upx/archive/v3.96.zip/upx-3.96/
@@ -1275,11 +1422,6 @@
 >>>20	long		>0		TIFF starts at byte %d
 >>>>24	long		>0		length %d
 
-# TNEF magic From "Joomy" <joomy@se-ed.net>
-# Microsoft Outlook's Transport Neutral Encapsulation Format (TNEF)
-0	lelong		0x223e9f78	TNEF
-!:mime	application/vnd.ms-tnef
-
 # Norton Guide (.NG , .HLP) files added by Joerg Jenderek from source NG2HTML.C
 # of http://www.davep.org/norton-guides/ng2h-105.tgz
 # https://en.wikipedia.org/wiki/Norton_Guides
@@ -1367,6 +1509,8 @@
 
 # HtmlHelp files (.chm)
 0	string/b	ITSF\003\000\000\000\x60\000\000\000	MS Windows HtmlHelp Data
+!:mime	application/vnd.ms-htmlhelp
+!:ext	chm
 
 # GFA-BASIC (Wolfram Kleff)
 2	string/b	GFA-BASIC3	GFA-BASIC 3 data
@@ -1475,6 +1619,13 @@
 >>>>>>(16.l+16)	string	!Panoram	7 or 8
 !:ext	themepack/deskthemepack
 >>>>>>(16.l+16)	ubyte	x		Theme Pack
+# URL:		https://en.wikipedia.org/wiki/Microsoft_OneNote#File_format
+#		http://fileformats.archiveteam.org/wiki/OneNote
+# Reference:	https://mark0.net/download/triddefs_xml.7z/defs/o/onepkg.trid.xml
+# 1st member name like: "Class Notes.one" "test-onenote.one" "Open Notebook.onetoc2" "Editor Öffnen.onetoc2"
+>>>>>&0	string/c	one		\b, OneNote Package
+!:mime	application/msonenote
+!:ext	onepkg
 >>>>>&0	default		x
 # look for null terminator of 1st member name
 >>>>>>&0	search/255 	\0
@@ -1765,3 +1916,37 @@
 
 # NB: The BACKUP.nnn files consist of the files backed up,
 # concatenated.
+
+# From:		Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/MS-DOS_date/time
+# Reference:	https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-dosdatetimetofiletime
+# Note:		DOS date+time format is different from formats such as Unix epoch
+#		bit encoded; uses year values relative to 1980 and 2 second precision
+0	name		dos-date
+# HHHHHMMMMMMSSSSS bit encoded Hour (0-23) Minute (0-59) SecondPart (*2)
+#>0	uleshort	x	RAW TIME [%#4.4x]
+# hour part
+#>0	uleshort/2048	x	hour [%u]
+# YYYYYMMMMDDDDD bit encoded YearPart (+1980) Month (1-12) Day (1-31)
+#>2	uleshort	x	RAW DATE [%#4.4x]
+# day part
+>2	uleshort&0x001F	x	%u
+#>2	uleshort/16	x	MONTH PART [%#x]
+# GRR: not working
+#>2	uleshort/16	&0x000F	MONTH [%u]
+#>2	uleshort&0x01E0	x	MONTH PART [%#4.4x]
+>2	uleshort&0x01E0	=0x0020	jan
+>2	uleshort&0x01E0	=0x0040	feb
+>2	uleshort&0x01E0	=0x0060	mar
+>2	uleshort&0x01E0	=0x0080	apr
+>2	uleshort&0x01E0	=0x00A0	may
+>2	uleshort&0x01E0	=0x00C0	jun
+>2	uleshort&0x01E0	=0x00E0	jul
+>2	uleshort&0x01E0	=0x0100	aug
+>2	uleshort&0x01E0	=0x0120	sep
+>2	uleshort&0x01E0	=0x0140	oct
+>2	uleshort&0x01E0	=0x0160	nov
+>2	uleshort&0x01E0	=0x0180	dec
+# year part
+>2	uleshort/512	x	1980+%u
+#

+ 10 - 2
magic/Magdir/msooxml

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: msooxml,v 1.16 2021/08/16 10:06:55 christos Exp $
+# $File: msooxml,v 1.18 2022/08/16 11:16:39 christos Exp $
 # msooxml:  file(1) magic for Microsoft Office XML
 # From: Ralf Brown <ralf.brown@gmail.com>
 
@@ -15,10 +15,13 @@
 0		name		msooxml
 >0		string		word/		Microsoft Word 2007+
 !:mime application/vnd.openxmlformats-officedocument.wordprocessingml.document
+!:ext	docx
 >0		string		ppt/		Microsoft PowerPoint 2007+
 !:mime application/vnd.openxmlformats-officedocument.presentationml.presentation
+!:ext	pptx
 >0		string		xl/		Microsoft Excel 2007+
 !:mime application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
+!:ext	xlsx
 >0		string		visio/		Microsoft Visio 2013+
 !:mime application/vnd.ms-visio.drawing.main+xml
 >0		string		AppManifest.xaml	Microsoft Silverlight Application
@@ -30,7 +33,7 @@
 # make sure the first file is correct
 >0x1E		use		msooxml
 >0x1E		default		x
->>0x1E		regex		\\[Content_Types\\]\\.xml|_rels/\\.rels|docProps
+>>0x1E		regex		\\[Content_Types\\]\\.xml|_rels/\\.rels|docProps|customXml
 # skip to the second local file header
 # since some documents include a 520-byte extra field following the file
 # header, we need to scan for the next header
@@ -46,5 +49,10 @@
 # OpenOffice/Libreoffice orders ZIP entry differently, so check the 4th file
 >>>>>>&26	search/6000	PK\003\004
 >>>>>>>&26	use		msooxml	
+# Some OOXML generators add an extra customXml directory. Check another file.
+>>>>>>>&26	default		x
+>>>>>>>>&26	search/6000	PK\003\004
+>>>>>>>>>&26	use		msooxml	
+>>>>>>>>>&26	default		x		Microsoft OOXML
 >>>>>>>&26	default		x		Microsoft OOXML
 >>>>>&26	default		x		Microsoft OOXML

+ 157 - 4
magic/Magdir/msvc

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: msvc,v 1.10 2018/10/01 19:14:03 christos Exp $
+# $File: msvc,v 1.11 2022/01/17 17:17:30 christos Exp $
 # msvc:  file(1) magic for msvc
 # "H. Nanosecond" <aldomel@ix.netcom.com>
 # Microsoft visual C
@@ -20,9 +20,162 @@
 0	string	\377\003\000\377\001\000\060\020\350	MSVC .res
 
 #.lib
-0	string	\360\015\000\000	Microsoft Visual C library
-0	string	\360\075\000\000	Microsoft Visual C library
-0	string	\360\175\000\000	Microsoft Visual C library
+# URL: 		https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B
+#		http://fileformats.archiveteam.org/wiki/Microsoft_Library
+#		http://fileformats.archiveteam.org/wiki/OMF
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/l/lib-msvc.trid.xml
+#		https://pierrelib.pagesperso-orange.fr/exec_formats/OMF_v1.1.pdf
+# Update:	Joerg Jenderek
+#0	string	\360\015\000\000	Microsoft Visual C library
+#0	string	\360\075\000\000	Microsoft Visual C library
+#0	string	\360\175\000\000	Microsoft Visual C library
+# test for RecordType~LibraryHeaderRecord=0xF0 + RecordLength=???Dh + dictionary offset is multiple of 0x200
+0	ubelong&0xFF0f80ff	=0xF00d0000
+# Microsoft Visual C library (strength=70) before MIDI SysEx messages (strength=50) handled by ./sysex
+#!:strength +0
+# test for valid 2nd RecordType~Translator Header Record=THEADR=80h or LHEADR=82h
+>(1.s+3)	ubyte&0xFD	=0x80
+>>0		use		omf-lib
+#	display information about Microsoft Visual C/OMF library
+0	name			omf-lib
+# RecordType~LibraryHeaderRecord=0xF0
+#>0	byte			0xF0		Microsoft Visual C library
+# the above description was used in file version 5.41
+>0	byte			0xF0		Microsoft Visual C/OMF library
+#>0	byte			0xF0		relocatable Object Module Format (OMF) libray
+#!:mime	application/octet-stream
+!:mime	application/x-omf-lib
+!:ext	lib
+# 1st record data length like 13=0Dh 29=1Dh 61=3Dh 125=7Dh 509=01FDh ... 32765=7FFDh
+#>1	uleshort		x		\b, 1st record data length %u
+#>1	uleshort		x		\b, 1st record data length %#x
+# 2**4=16 <= RecordLength+3 = PageSize = 2**n {16 32 512 no examples 64 128 256 1024 2048 ...32768} <= 2**15=32768
+>1	uleshort+3		x		\b, page size %u
+# dictionary offset like: 400h 600h a00h c00h 1200h 1800h 2400h 5600h 12800h 19200h 28a00h
+>3		ulelong		x		\b, at %#x dictionary
+# dictionary block a 512 bytes; the first 37 bytes correspond to the 37 buckets
+#>(3.l)	ubequad			x		(%#16.16llx...)
+# dictionary size; length in 512-byte blocks; a prime number? like:
+# 1 2 3 4 5 6 7 9 11 13 15 16 18 21 22 23 24 25 31 50 53 89 101 117 277
+>7		uleshort	x		with %u block
+# plurals s
+>7		uleshort	>1		\bs
+# If dictionary byte 38 (FFLAG) has the value 255, there is no space left
+>(3.l+37)	ubyte		<0xFF		(FFLAG=%#x)
+>(3.l+37)	ubyte		=0xFF		(FFLAG=full)
+# dictionary entry; length byte of following symbol, the following text bytes of symbol, two bytes specifies the page number
+# like: dbfntx1! DBFNTX.LIB zlibCompileFlags_ ZLIB.LIB atoi! mwlibc.lib
+>(3.l+38)	pstring		x		1st entry %s
+# like: 1 33 41 47 458 8783
+>>&0		uleshort	x		in page %u
+# library flags; 0 or 1, but WHAT IS 0x4d in MOUSE.LIB ?
+>9	ubyte			>1		\b, flags %#x
+>9	ubyte			=1		case sensitive
+# In the library after header comes first object module with a Library Module Header Record (LHEADR=82h)
+# but in examples Translator Header Record (THEADR=80h) which is handled identically
+>(1.s+3)	ubyte		x		\b, 2nd record
+>(1.s+3)	ubyte		!0x80		(type %#x)
+#>(1.s+4)	uleshort	x		\b, 2nd record data length %u
+# Module name often source name like "dos\crt0.asm" in mlibce.lib or "QB4UTIL.ASM" in QB4UTIL.LIB
+# or "C:\Documents and Settings\Allan Campbell\My Documents\FDOSBoot\zlib\zutil.c" in ZLIB.LIB
+# or title like "87INIT" in FP87.LIB or "ACOSASIN" in MATHC.LIB or "Copyright" in calc-bcc.lib
+>(1.s+6)	pstring		x		"%s"
+# 2nd record checksum
+#>>&0		ubyte		x		checksum %#x
+# 3rd RecordType: 96h~LNAMES 88h~COMENT
+>>&1		ubyte		x		\b, 3rd record
+>>&1		ubyte		!0x88
+>>>&-1		ubyte		!0x96
+# 3rd unusual record type
+>>>>&-1		ubyte		x		(type %#x)
+# 3rd record is a List of Names Record (LNAMES=96h)
+>>&1		ubyte		=0x96		LNAMES
+# LNAMES record length like: 2 15 19
+#>>>&0			uleshort	x	\b, LNAMES record length %u
+>>>&0			uleshort	>2
+# 1st LNAME string length; null is valid; maximal 255
+#>>>>&0			ubyte		x	1st LNAME length %u
+>>>>&0			ubyte		=0
+# 2nd LNAME length like: 4 7 8 17 31
+#>>>>>&0			ubyte		x	2nd LNAME length %u
+# name used for segment, class, group, overlay, etc like:
+# CODE (mwlibc.lib) _TEXT32 (JMPPM32.LIB) _OVLCODE (WOVL.LIB)
+>>>>>&0			pstring		x	%s
+# 3rd LNAME length like: 4 5
+#>>>>>>&0		ubyte		x	3rd LNAME length %u
+# like: DATA (mwlibc.lib) CODE (JMPPM32.LIB) _TEXT (EMU87.LIB)
+>>>>>>&0		pstring		x	%s
+# maybe 4th LNAME length like: 4 6
+>>>>>>>&0		ubyte		<44
+# like: DATA (DEBUG.LIB) DGROUP (mwlibc.lib MOUSE.LIB)
+>>>>>>>>&-1		pstring		x	%s
+# 3rd record is a COMMENT (Including all comment class extensions)
+>>&1		ubyte		=0x88		COMMENT
+# comment record length like: 3 FLIB7M.LIB 1Bh 1Eh 23h 27h 2Bh 30h freetype-bcc.lib
+#>>>&0		uleshort	x		\b, record length %#x
+# real comment length = record length - 1 (comment type) - 1 (comment Class) - 1 (checksum) -1 (char count)
+# like: 2 LIBFL.LIB 4 "UUID" 5 "dscap" 6 "int386" 7 "qb4util" 8 "AMSGEXIT" 16 REXX.LIB 20 27 35 44 freetype-bcc.lib
+#>>>>&-2		uleshort-4	>0		\b, comment length %u
+# check that record contain at least comment type (1 byte), comment class (1 byte), checksum (1 byte)
+# probably always true
+>>>&0		uleshort	>2
+# comment type: 80h~NP~no purge bit 40h~NL~no list bit
+#>>>>&0		ubyte		!0		Type %#x
+>>>>&0		ubyte		&0x80		Preserved
+# no example
+>>>>&0		ubyte		&0x40		NoList
+# comment class like: 0~Translator A0~OMF extensions A3~LIBMOD A1~New OMF extensions AA~UNKNOWN
+>>>>&1		ubyte		x		class=%#x
+# check that comment record contains at least real content
+>>>>&-2		uleshort	>3
+# Translator comment record (0); it may name the source language or translator
+>>>>>&1		ubyte		=0		Translator
+#>>>>>>&0		ubyte	x		Translator length %u
+# like: "TC86 Borland Turbo C 2.01 " (GEMS.LIB) "TC86 Borland Turbo C++ 3.00" (CATDB.LIB)
+>>>>>>&0		pstring	x		"%s"
+# OMF extensions comment record (A0); first byte of commentary string identifies subtype
+>>>>>&1		ubyte		=0xA0		OMF extensions
+# A0 subtype like: 1~IMPDEF
+>>>>>>&0		ubyte	!1		subtype %#x
+# Import Definition Record (Comment Class A0, Subtype 01~IMPDEF)
+>>>>>>&0		ubyte	1		IMPDEF
+# ordinal flag; determines form of Entry Ident field. If nonzero (seems to be 1) Entry is ordinal
+>>>>>>>&0		ubyte	!0		ordinal
+# like: IMPORT.LIB DOSCALLS.LIB mlibw.lib mwinlibc.lib REXX.LIB
+>>>>>>>>&-1		ubyte	>1		%u
+# Internal Name in count, char string format; module name for the imported symbol
+# like: 7 "REXXSAA" 9 11 13 14 15 16 20 21 26 "_Z10_clip_linePdS_S_S_dddd"
+#>>>>>>>&1		ubyte	x		internal name length %u
+# internal module name like: _DllGetVersion DllGetVersion BezierTerminationTest Copyright
+>>>>>>>&1		pstring	x		%s
+# module name in count, char string format; DLL name that supplies a matching export symbol
+# like: jpeg62.dll (jpeg-bcc.lib) unrar3.dll (unrar-bcc.lib) REXX (REXX.LIB)
+>>>>>>>>&0		pstring	x		exported by %s
+# Entry Ident; 16-bit if ordinal flag != 0 or imported name in count, char string format if ordinal flag = 0 
+# like: \0 (calc-bcc.lib) DllGetVersion (libtiff-bcc.lib) UTF8ToHtml (libxml2-bcc.lib) xslAddCall (libxslt-bcc.lib)
+#>>>>>>>>>&0		pstring	>\0		entry ident %s
+# "New OMF" extensions comment (A1); indicate version of symbolic debug information
+# like: LIBFL.LIB
+>>>>>&1		ubyte		=0xA1		New OMF extensions
+# symbolic debug information version n
+>>>>>>&0		ubyte	x		n=%u
+# symbolic debug information style like: HL~IBM PM Debugger style (LIBFL.LIB) DX~AIX style CV~Microsoft symbol and type style
+>>>>>>>&0		string	HL		IBM style
+>>>>>>>&0		string	DX		AIX style
+>>>>>>>&0		string	CV		Microsoft style
+# LIBMOD comment record (A3) used only by the librarian
+# Microsoft extension added for LIB version 3.07 in macro assembler (MASM 5.0)
+>>>>>&1		ubyte		=0xA3		LIBMOD
+# The A3 LIBMOD record contains only the ASCII string of the module name in count char format
+#>>>>>>&0		ubyte	x		LIBMOD length %u
+# LIBMOD comment record module name without path and extension like:
+# qb4util (QB4UTIL.LIB) affaldiv (libh.lib) crt0 (slibc.lib) clipper (DDDRAWS.LIB) dinpdev (DINPUTS.LIB) UUID (UUID.LIB)
+>>>>>>&0		pstring	x		%s
+# GRR: WHAT iS THAT? AA foo comment record
+#>>>>>&1		ubyte		=0xAA		AA-comment
+# like: OS220
+#>>>>>>&0		string	x		what=%-5.5s
+#
 
 #.pch
 0	string	DTJPCH0\000\022\103\006\200	Microsoft Visual C .pch

+ 202 - 0
magic/Magdir/nifty

@@ -0,0 +1,202 @@
+
+#------------------------------------------------------------------------------
+# $File: nifty,v 1.1 2022/02/14 16:51:15 christos Exp $
+# file(1) magic for the NIfTI file format
+
+# Type: NIfTI, Neuroimaging file format
+# URL:  https://nifti.nimh.nih.gov/
+# From: Yann Leprince <yann.leprince@cea.fr>, 2022
+
+344	string		n+1\0		NIfTI-1 neuroimaging data,
+!:mime	image/x.nifti
+!:ext	nii
+>0	use		nifti1
+344	string		ni1\0		NIfTI-1 neuroimaging data header,
+!:mime	image/x.nifti
+!:ext	hdr
+>0	use		nifti1
+
+4	string		n+2\0\r\n\032\n	NIfTI-2 neuroimaging data,
+!:mime	image/x.nifti
+!:ext	nii
+>0	use		nifti2
+4	string		ni2\0\r\n\032\n	NIfTI-2 neuroimaging data header,
+!:mime	image/x.nifti
+!:ext	hdr
+>0	use		nifti2
+
+# Main subroutine for NIfTI-1
+0	name		nifti1
+>0	clear		x
+>0	lelong		=348		little endian
+>>70	use		nifti-datatype-le
+>>112	lefloat	!0		with scaling
+>>0	use		nifti1-dim-le
+>>252	leshort	>0		\b, with qform
+>>>252	use		xform-code-nifti1-le
+>>254	leshort	>0		\b, with sform
+>>>254	use		xform-code-nifti1-le
+>>136	string		>\0		\b, description: %s
+>0	belong		=348		big endian
+>>70	use		\^nifti-datatype-le
+>>112	befloat	!0		with scaling
+>>0	use		\^nifti1-dim-le
+>>252	beshort	>0		\b, with qform
+>>>252	use		\^xform-code-nifti1-le
+>>254	beshort	>0		\b, with sform
+>>>254	use		\^xform-code-nifti1-le
+>>136	string		>\0		\b, description: %s
+>0	default	x
+>>0	long		x		invalid sizeof_hdr=%d
+
+# Main subroutine for NIfTI-2
+0	name		nifti2
+>0	clear		x
+>0	lelong		=540		little endian
+>>12	use		nifti-datatype-le
+>>176	lefloat	!0		with scaling
+>>0	use		nifti2-dim-le
+>>344	lelong		>0		\b, with qform
+>>>344	use		xform-code-nifti2-le
+>>348	lelong		>0		\b, with sform
+>>>348	use		xform-code-nifti2-le
+>>240	string		>\0		\b, description: %s
+>0	belong		=540		big endian
+>>12	use		\^nifti-datatype-le
+>>176	befloat	!0		with scaling
+>>0	use		\^nifti2-dim-le
+>>344	lelong		>0		\b, with qform
+>>>344	use		\^xform-code-nifti2-le
+>>348	lelong		>0		\b, with sform
+>>>348	use		\^xform-code-nifti2-le
+>>240	string		>\0		\b, description: %s
+>0	default	x
+>>0	long		x		invalid sizeof_hdr=%d
+
+
+# Other subroutines for details of NIfTI files
+
+0	name		nifti-datatype-le
+>0	clear		x
+>0	leshort	=1		\b, binary datatype
+>0	leshort	=2		\b, uint8 datatype
+>0	leshort	=4		\b, int16 datatype
+>0	leshort	=8		\b, int32 datatype
+>0	leshort	=16		\b, float32 datatype
+>0	leshort	=32		\b, complex64 datatype
+>0	leshort	=64		\b, float64 datatype
+>0	leshort	=128		\b, RGB24 datatype
+>0	leshort	=256		\b, int8 datatype
+>0	leshort	=512		\b, uint16 datatype
+>0	leshort	=768		\b, uint32 datatype
+>0	leshort	=1024		\b, int64 datatype
+>0	leshort	=1280		\b, uint64 datatype
+>0	leshort	=1536		\b, float128 datatype
+>0	leshort	=1792		\b, complex128 datatype
+>0	leshort	=2048		\b, complex256 datatype
+>0	leshort	=2304		\b, RGBA32 datatype
+>0	default	x
+>>0	leshort	x		\b, unknown datatype 0x%x
+>>2	leshort	x		(%d bits/pixel)
+
+0	name		nifti1-dim-le
+>0	clear		x
+>40	leshort	<0		\b, INVALID dim[0]=%d
+>40	leshort	>7		\b, INVALID dim[0]=%d
+>0	default	x
+>>40	leshort	x		\b, %d-dimensional (size
+>>42	leshort	x		%d
+>>40	leshort	>1
+>>>44	leshort	x		\bx%d
+>>40	leshort	>2
+>>>46	leshort	x		\bx%d
+>>40	leshort	>3
+>>>48	leshort	x		\bx%d
+>>40	leshort	>4
+>>>50	leshort	x		\bx%d
+>>40	leshort	>5
+>>>52	leshort	x		\bx%d
+>>40	leshort	>6
+>>>54	leshort	x		\bx%d
+>>80	lefloat	x		\b, voxel size %f
+>>40	leshort	>1
+>>>84	lefloat	x		x %f
+>>40	leshort	>2
+>>>88	lefloat	x		x %f
+>>123	use		nifti1-xyz-unit
+>>40	leshort	>3
+>>>92	lefloat	x		x %f
+>>>123	use		nifti1-t-unit
+>>40	leshort	x		\b)
+
+0	name		nifti2-dim-le
+>0	clear		x
+>16	lequad		<0		\b, INVALID dim[0]=%lld
+>16	lequad		>7		\b, INVALID dim[0]=%lld
+>0	default	x
+>>16	lequad		x		\b, %lld-dimensional (size
+>>24	lequad		x		%lld
+>>16	lequad		>1
+>>>32	lequad		x		\bx%lld
+>>16	lequad		>2
+>>>40	lequad		x		\bx%lld
+>>16	lequad		>3
+>>>48	lequad		x		\bx%lld
+>>16	lequad		>4
+>>>56	lequad		x		\bx%lld
+>>16	lequad		>5
+>>>64	lequad		x		\bx%lld
+>>16	lequad		>6
+>>>72	lequad		x		\bx%lld,
+>>112	ledouble	x		\b, voxel size %f
+>>16	lequad		>1
+>>>120	ledouble	x		x %f
+>>16	lequad		>2
+>>>128	ledouble	x		x %f
+>>500	use		nifti2-xyz-unit
+>>16	lequad		>3
+>>>136	ledouble	x		x %f
+>>>500	use		nifti2-t-unit
+>>16	lequad		x		\b)
+
+0	name		xform-code-nifti1-le
+>0	leshort	=1		to scanner-based coordinates
+>0	leshort	=2		to aligned coordinates
+>0	leshort	=3		to Talairach coordinates
+>0	leshort	=4		to MNI152 coordinates
+>0	leshort	=5		to template coordinates
+
+0	name		xform-code-nifti2-le
+>0	lelong		=1		to scanner-based coordinates
+>0	lelong		=2		to aligned coordinates
+>0	lelong		=3		to Talairach coordinates
+>0	lelong		=4		to MNI152 coordinates
+>0	lelong		=5		to template coordinates
+
+0	name		nifti1-xyz-unit
+>0	byte		&0x01
+>>0	byte		^0x02		m
+>>0	byte		&0x02		micron
+>0	byte		^0x01
+>>0	byte		&0x02		mm
+
+0	name		nifti1-t-unit
+>0	byte		&0x08
+>>0	byte		^0x10		s
+>>0	byte		&0x10		ms
+>0	byte		^0x08
+>>0	byte		&0x10		microsecond
+
+0	name		nifti2-xyz-unit
+>0	lelong		&0x01
+>>0	lelong		^0x02		m
+>>0	lelong		&0x02		micron
+>0	lelong		^0x01
+>>0	lelong		&0x02		mm
+
+0	name		nifti2-t-unit
+>0	lelong		&0x08
+>>0	lelong		^0x10		s
+>>0	lelong		&0x10		ms
+>0	lelong		^0x08
+>>0	lelong		&0x10		microsecond

+ 109 - 4
magic/Magdir/ole2compounddocs

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: ole2compounddocs,v 1.12 2021/09/04 16:00:38 christos Exp $
+# $File: ole2compounddocs,v 1.19 2022/09/11 20:52:40 christos Exp $
 # Microsoft OLE 2 Compound Documents : file(1) magic for Microsoft Structured
 # storage (https://en.wikipedia.org/wiki/Compound_File_Binary_Format)
 # Additional tests for OLE 2 Compound Documents should be under this recipe.
@@ -200,6 +200,22 @@
 !:mime	application/x-ms-info
 !:ext	nfo
 #
+# From:		Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/Microsoft_Access
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/m/mdz.trid.xml
+#		http://fileformats.archiveteam.org/wiki/Microsoft_Compound_File
+# Note:		only version foo tested and called "Microsoft Access Wizard template" by TrID
+# Fourth directory entry name TemplateID
+>>>>384 	lestring16	TemplateID		: Microsoft Access wizard template
+# Second directory entry name like \005SummaryInformation and 3rd name like \005DocumentSummaryInformation
+#!:mime	application/x-ole-storage
+#!:mime	application/vnd.ms-office
+#!:mime	application/vnd.ms-access
+#!:mime	application/msaccess
+!:mime	application/x-ms-mdz
+# http://extension.nirsoft.net/mdz
+!:ext	mdz
+#
 # URL:	http://fileformats.archiveteam.org/wiki/Corel_Print_House
 # Second directory entry name Thumbnail
 >>>>128 	lestring16	Thumbnail		: Corel PrintHouse image
@@ -220,6 +236,18 @@
 !:mime	application/x-corel-gal
 !:ext	gal
 #
+# From:		Joerg Jenderek
+# URL:		https://archive.org/details/iPhoto-Plus-4
+#		https://filext.com/file-extension/TPL
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/t/tpl-ulead.trid.xml
+# Note:		found in Template sub directory in program directory of software iPhoto Plus version 4
+# second, third and fourth directory entry name like TplHeader TplMainImage TplPreview
+>>>>128 	lestring16	TplHeader		: Ulead iPhoto Template
+#!:mime	application/x-ole-storage
+!:mime	image/x-ulead-tpl
+# https://www.file-extensions.org/tpl-file-extension-ulead-photo-express-template
+!:ext	tpl
+#
 # URL:	https://en.wikipedia.org/wiki/Hangul_(word_processor)
 # Note:	"HWP Document File" signature found in FileHeader
 # Second directory entry name FileHeader hint for Thinkfree Office document
@@ -258,6 +286,24 @@
 !:ext	prd/prv
 # 2nd directory entry name Pictures
 >>>>>>128 	lestring16	Pictures		with pictures
+#
+# URL:		http://fileformats.archiveteam.org/wiki/PageMaker
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p
+#		pagemaker-generic.trid.xml
+#		pagemaker-pm6.trid.xml
+#		pagemaker-pm65.trid.xml
+#		pmd-pm7.trid.xml
+# From:		Joerg Jenderek
+# Note:		since version 6 embedd as stream with PageMaker name the "old" format handled by ./wordprocessors
+#		verified by Michal Mutl Structured Storage Viewer `SSView.exe brochus.pt6`
+# Second directory entry name PageMaker
+>>>>128 	lestring16	PageMaker		:
+# look for magic of "old" PageMaker like in 02TEMPLT.T65
+>>>>>0	search/0xa900/s	\0\0\0\0\0\0\xff\x99
+# GRR: jump to PageMaker stream and inspect it by sub routine PageMaker of ./wordprocessors failed with wrong version!
+#>>>>>>&0	use		PageMaker
+# THIS WORKS PARTLY!
+>>>>>>&0	indirect	x
 #	remaining null clsid
 >>>>128 	default		x			: UNKNOWN
 # second directory entry name like VisioDocument Control000
@@ -267,6 +313,9 @@
 # forth
 >>>>>384	lestring16	x %.20s
 !:mime	application/x-ole-storage
+# according to file version 5.41 with -e soft option
+#!:mime	application/CDFV2
+#!:ext	???
 #	look for known clsid GUID
 # - Visio documents
 # URL:	http://fileformats.archiveteam.org/wiki/Visio
@@ -417,6 +466,28 @@
 !:apple	????PPT3
 # /autostart/template
 !:ext	ppt/pps/pot
+# From:		Joerg Jenderek
+# URL:		https://www.file-extensions.org/ppa-file-extension
+#		https://en.wikipedia.org/wiki/Microsoft_PowerPoint#cite_note-231
+# Reference:	http://fileformats.archiveteam.org/wiki/Microsoft_Compound_File
+>>88 	ubequad		0x871800aa0060263b	: Microsoft
+# only version 8 (97) tested; PowerPoint 4.0 to 11.0 (2004) (Wikipedia); 97 to 2003 (file-extensions.org)
+>>>80 	ubequad		0xf04672810a72cf11	PowerPoint Addin or Wizard
+# second, third and fourth directory entry name like VBA PROJECT PROJECTwm
+# http://extension.nirsoft.net/pwz
+!:mime	application/vnd.ms-powerpoint
+# like: BSHPPT97.PPA "AutoContent Wizard.pwz"
+!:ext	ppa/pwz
+#
+# From:		Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/AWD_(At_Work_Document)
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/a/awd-fax.trid.xml
+# Note:		called "Microsoft At Work Fax document" by TrID
+>>88 	ubequad		0xb29400dd010f2bf9	: Microsoft
+>>>80 	ubequad		0x801cb0023de01a10	At Work fax Document
+#!:mime	application/x-ole-storage
+!:mime	image/x-ms-awd
+!:ext	awd
 #
 # URL:	https://en.wikipedia.org/wiki/Microsoft_Project
 #??
@@ -424,6 +495,20 @@
 >>>80 	ubequad		0x3a8fb774c8c8d111	Project
 !:mime	application/vnd.ms-project
 !:ext	mpp
+# From:		Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/Microsoft_Office_shared_tools#Binder
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/o/obd.trid.xml
+#		http://fileformats.archiveteam.org/wiki/Microsoft_Compound_File
+# Note:		only version 8 tested and called "Office Binder Document" by TrID and
+#		"Microsoft Office Binder File for Windows" version 97-2000 by DROID fmt/240
+>>88 	ubequad		0xb21c00aa004ba90b	: Microsoft
+>>>80 	ubequad		0x0004855964661b10	Office Binder Document, Template or wizard
+# second directory entry name like Binder
+# https://www.file-extensions.org/obd-file-extension
+#!:mime	application/vnd.ms-binder
+!:mime	application/x-msbinder
+# obt for template; obz for Microsoft Office Binder wizard
+!:ext	obd/obt/obz
 #
 # URL:		http://fileformats.archiveteam.org/wiki/WordPerfect
 # Reference:	http://fileformats.archiveteam.org/wiki/Microsoft_Compound_File
@@ -560,9 +645,29 @@
 !:mime	application/vnd.softmaker.planmaker
 # pmv for template	https://www.file-extensions.org/pmv-file-extension
 !:ext	pmd/pmv
+# URL:		http://fileformats.archiveteam.org/wiki/MAX_(3ds_Max)
+#		https://en.wikipedia.org/wiki/Autodesk_3ds_Max
+# Reference:	http://fileformats.archiveteam.org/wiki/Microsoft_Compound_File
+# Note:		called "3D Studio Max Scene" by TrID and "3DS Max" by DROID and
+#		"3DSMax thumbnail" by XnView and verfied by `nconvert -info A380.max`
+#		applies only to "newer" versions (about 2008-2020)
+>>88 	ubequad		0x9fed04143144cc1e	: Autodesk
+>>>80 	ubequad		0x7b8cdd1cc081a045	3ds Max
+#!:mime	application/x-ole-storage
+!:mime	model/x-autodesk-max
+# like: https://static.free3d.com/models/dropbox/dropbox/sq/A380.7z/A380.max 
+!:ext	max
+# also chr for character file according to DROID https://www.nationalarchives.gov.uk/PRONOM/fmt/978
+#!:ext	max/chr
 # remaining non null clsid
->>88 	default		x			: UNKNOWN
+>>88 	default		x
+# GRR: check again for non null clsid because wrong when called by indirect directive
+>>>88 	ubequad		!0			: UNKNOWN
+# https://reposcope.com/mimetype/application/x-ole-storage
 !:mime	application/x-ole-storage
->>>80 	ubequad		!0			\b, clsid %#16.16llx
->>>88 	ubequad		x			\b%16.16llx
+# according to file version 5.41 with -e soft option
+#!:mime	application/CDFV2
+#!:ext	???
+>>>>80 	ubequad		!0			\b, clsid %#16.16llx
+>>>>88 	ubequad		x			\b%16.16llx
 

+ 16 - 0
magic/Magdir/oric

@@ -0,0 +1,16 @@
+
+#------------------------------------------------------------------------------
+# $File: oric,v 1.2 2022/04/25 17:28:20 christos Exp $
+# Oric tape files
+# From: Stefan A. Haubenthal <polluks@sdf.lonestar.org>
+# References:
+# http://fileformats.archiveteam.org/wiki/TAP_(Oric)
+# http://fileformats.archiveteam.org/wiki/DSK_(Oric)
+0	string		\x16\x16\x16\x24	Oric tape,
+>6	byte		=0x00			BASIC,
+>6	byte		=0x80			memory block,
+>7	byte		>0x00			autorun,
+>13	string		x			"%.15s"
+
+0	string		ORICDISK		Oric Image
+0	string		MFM_DISK		Oric Image

+ 3 - 1
magic/Magdir/os2

@@ -1,12 +1,14 @@
 
 #------------------------------------------------------------------------------
-# $File: os2,v 1.13 2021/04/26 15:56:00 christos Exp $
+# $File: os2,v 1.14 2022/03/21 21:25:50 christos Exp $
 # os2:  file(1) magic for OS/2 files
 #
 
 # Provided 1998/08/22 by
 # David Mediavilla <davidme.news@REMOVEIFNOTSPAMusa.net>
 1	search/100	InternetShortcut	MS Windows 95 Internet shortcut text
+!:mime	application/x-mswinurl
+!:ext	url
 >17	search/100	URL= 			(URL=<
 >>&0	string		x			\b%s>)
 

+ 2 - 1
magic/Magdir/palm

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: palm,v 1.14 2019/04/19 00:42:27 christos Exp $
+# $File: palm,v 1.15 2021/12/16 21:50:06 christos Exp $
 # palm:	 file(1) magic for PalmOS {.prc,.pdb}: applications, docfiles, and hacks
 #
 # Brian Lalor <blalor@hcirisc.cs.binghamton.edu>
@@ -55,6 +55,7 @@
 # Mobipocket (www.mobipocket.com), donated by Carl Witty
 # expanded by Ralf Brown
 60		string	 	BOOKMOBI	Mobipocket E-book
+!:mime	application/x-mobipocket-ebook
 # MobiPocket stores a full title, pointed at by the belong at offset
 # 0x54 in its header at (78.L), with length given by the belong at
 # offset 0x58.

+ 26 - 1
magic/Magdir/pascal

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: pascal,v 1.3 2020/06/07 18:10:26 christos Exp $
+# $File: pascal,v 1.4 2022/07/30 16:53:06 christos Exp $
 # pascal:  file(1) magic for Pascal source
 #
 0	search/8192	(input,		Pascal source text
@@ -12,3 +12,28 @@
 # Free Pascal
 0	string	PPU	Pascal unit
 >3	string	x	\b, version %s
+
+# From:		Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/Dan_Bricklin
+0	string/b	Type
+# URL:		https://dl.winworldpc.com/Dan%20Bricklins%20Demo%20II%20Version%202%20Manual.7z
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/d/dbd-v2.trid.xml
+>4	string		D2		Dan Bricklin's Demo 2 demo
+#!:mime	application/octet-stream
+!:ext	dbd
+# URL:		https://muhaz.org/turbo-pascal-download-details.html
+# From:		Joerg Jenderek
+# Note:		used by Turbo Pascal 5.5 TOUR.EXE
+>4	string		T2		Turbo Pascal TOUR data
+#!:mime	application/octet-stream
+!:mime	application/x-borland-cbt
+!:ext	cbt
+# WHAT iS THAT?
+#>4	string		\040P		Dan Bricklin's Demo 2 foo
+#!:mime	application/octet-stream
+# _PPRINT.SG2 _PASCII.SG2
+#!:ext	sg2
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/d/dbd-gen.trid.xml
+>4	default		x		Dan Bricklin's Demo demo (generic)
+#!:mime	application/octet-stream
+!:ext	dbd

+ 116 - 0
magic/Magdir/pci_ids

@@ -0,0 +1,116 @@
+
+#------------------------------------------------------------------------------
+# $File: pci_ids,v 1.1 2022/04/02 14:47:42 christos Exp $
+# pci.ids:  file(1) magic for PCI specific informations
+#
+
+# Vendor identification (ID)		https://pci-ids.ucw.cz/v2.2/pci.ids
+# show hexadecimal PCI vendor identification in human readable text form
+0	name	PCI-vendor
+#			ID	vendor name
+#>0	uleshort	=0x0f00	fOO
+>0	uleshort	=0x1000	Broadcom
+>0	uleshort	=0x1002	AMD/ATI
+>0	uleshort	=0x1013	Cirrus Logic
+>0	uleshort	=0x1014	IBM
+>0	uleshort	=0x1022	AMD
+>0	uleshort	=0x1050	Winbond
+>0	uleshort	=0x105a	Promise
+>0	uleshort	=0x1095	Silicon
+>0	uleshort	=0x10EC	Realtek
+>0	uleshort	=0x10de	NVIDIA
+>0	uleshort	=0x1106	VIA
+# Woodward McCoach, Inc. 
+>0	uleshort	=0x1231	Woodward
+#
+>0	uleshort	=0x1234	Bochs
+>0	uleshort	=0x15ad	VMware
+>0	uleshort	=0x1af4	Virtio
+>0	uleshort	=0x1b36	QEMU
+>0	uleshort	=0x1de1	Tekram
+# maybe also Promise?
+#>0	uleshort	=0x4289	Promise
+#>0	uleshort	=0x66a1	FOO
+>0	uleshort	=0x8086	Intel
+>0	uleshort	=0x9004	Adaptec
+# also Adaptec; but no example
+>0	uleshort	=0x9005	Adaptec
+# for unknown/missing manufactors
+>0	default		x	UNKNOWN
+>>0	uleshort		x	(%#4.4x)
+
+# https://blog.ladsai.com/pci-configuration-space-class-code.html
+# Base class code			https://wiki.osdev.org/PCI
+# show hexadecimal PCI class+sub+ProgIF identification in human readable text form
+0	name		PCI-class
+#>0	ubyte		x	CLASS=%x
+>0	ubyte		x
+# Device was built prior definition of the class code field
+>>0	ubyte		0x00	PRIOR
+# Any device except for VGA-Compatible devices like: 2975BIOS.BIN Trm3x5.bin
+# BUT also NVidia44.bin vgabios-stdvga-bin.rom
+#>>>0	ubyte		0x00		NOT VGA
+# VGA-Compatible Device; NO EXAMPLE found here!!
+#>>>0	ubyte		0x01		VGA
+# like 4243.bin
+#>>>0	ubyte		0x04		SUB_CLASS_4
+>>0	ubyte		0x01	storage controller
+# device sub-type and its definition is dependent upon the base-type code
+>>>1	ubyte		0x00		SCSI
+>>>1	ubyte		0x01		IDE
+>>>1	ubyte		0x02		Floppy
+>>>1	ubyte		0x03		IPI
+>>>0	ubyte		0x04		RAID
+>>>1	ubyte		0x05		ATA
+>>>1	ubyte		0x06		SATA
+>>>1	ubyte		0x07		SAS
+>>>1	ubyte		0x08		NVM
+# 4650_sr5.bin "PROMISE" "FT TX4650 Ary X"
+>>>1	ubyte		0x80		OTHER
+>>0	ubyte		0x02	network controller
+>>>1	ubyte		0x00		ethernet
+>>>1	ubyte		0x01		token ring
+>>>1	ubyte		0x02		FDDI
+>>>1	ubyte		0x03		ATM
+>>>1	ubyte		0x04		ISDN
+>>>1	ubyte		0x05		WorldFip
+# PICMG 2.14 Multi Computing
+>>>1	ubyte		0x06		PICMG
+>>>1	ubyte		0x80		OTHER
+>>0	ubyte		0x03	display controller
+>>0	ubyte		0x04	multimedia controller
+>>0	ubyte		0x05	memory controller
+>>0	ubyte		0x06	bridge device
+# Simple Communication Controllers
+>>0	ubyte		0x07	communication controller
+# Base System Peripherals
+>>0	ubyte		0x08	base peripheral
+# Input Devices
+>>0	ubyte		0x09	input device
+# Docking Stations
+>>0	ubyte		0x0A	docking station
+>>0	ubyte		0x0B	processor
+>>0	ubyte		0x0C	serial bus controller
+>>0	ubyte		0x0D	wireless controller
+# Intelligent I/O Controllers
+>>0	ubyte		0x0E	I/O controller
+# Satellite Communication Controllers
+>>0	ubyte		0x0F	satellite controller
+# Encryption/Decryption Controllers
+>>0	ubyte		0x10	encryption controller
+# Data Acquisition and Signal Processing Controllers
+>>0	ubyte		0x11	signal controller
+# Processing Accelerator 
+>>0	ubyte		0x12	processing accelerator
+# Non-Essential Instrumentation
+>>0	ubyte		0x13	non-essential
+# reserved or unassigned
+>>0	default		x
+# device does not fit any defined class; Unassigned Class (Vendor specific) 
+>>>0		ubyte	0xFF		UNASSIGNED
+# THIS SHOULD NOT HAPPEN! BUT CLASS=8f for Promise 4650_sr5.bin 8660_sr5.bin
+>>>0		default	x		RESERVED
+>>>>0 	ubyte	x		(%#x)
+# Prog IF of PCI class code?
+# defines the specific device programming interface
+>2	ubyte		>0	\b, ProgIF=%u

+ 44 - 31
magic/Magdir/python

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: python,v 1.43 2021/05/25 15:12:03 christos Exp $
+# $File: python,v 1.45 2022/07/24 23:59:37 christos Exp $
 # python:  file(1) magic for python
 #
 # Outlook puts """ too for urgent messages
@@ -8,6 +8,7 @@
 # often the module starts with a multiline string
 0	string/t	"""	Python script text executable
 # MAGIC as specified in Python/import.c (1.0 to 3.7)
+# and in Lib/importlib/_bootstrap_external.py (3.5+)
 # two bytes of magic followed by "\r\n" in little endian order
 0	belong		0x02099900	python 1.0 byte-compiled
 !:mime application/x-bytecode.python
@@ -85,6 +86,8 @@
 !:mime application/x-bytecode.python
 0	belong		0x04f30d0a	python 2.7 byte-compiled
 !:mime application/x-bytecode.python
+0	belong		0x0af30d0a	PyPy2.7 byte-compiled
+!:mime application/x-bytecode.python
 0	belong		0xb80b0d0a	python 3.0 byte-compiled
 !:mime application/x-bytecode.python
 0	belong		0xc20b0d0a	python 3.0 byte-compiled
@@ -185,36 +188,46 @@
 !:mime application/x-bytecode.python
 0	belong		0x3f0d0d0a	python 3.7 byte-compiled
 !:mime application/x-bytecode.python
-0	belong		0x400d0d0a	python 3.7 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x410d0d0a	python 3.7 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x420d0d0a	python 3.7 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x480d0d0a	python 3.8 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x490d0d0a	python 3.8 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x520d0d0a	python 3.8 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x530d0d0a	python 3.8 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x540d0d0a	python 3.8 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x550d0d0a	python 3.8 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x5c0d0d0a	python 3.9 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x5d0d0d0a	python 3.9 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x5e0d0d0a	python 3.9 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x5f0d0d0a	python 3.9 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x600d0d0a	python 3.9 byte-compiled
-!:mime application/x-bytecode.python
-0	belong		0x610d0d0a	python 3.9 byte-compiled
-!:mime application/x-bytecode.python
+
+# magic 3392+ implements PEP 552: Deterministic pycs
+0	name		pyc-pep552
+# the flag field determines how .pyc validity is checked
+>4	ulelong&1	0		timestamp-based,
+>>8	uledate		x		.py timestamp: %s UTC,
+>>12	ulelong		x		.py size: %d bytes
+>4	ulelong&1	!0		hash-based, check-source flag
+>>4	ulelong&2	0		unset,
+>>4	ulelong&2	!0		set,
+>>8	ulequad		x		hash: 0x%llx
+
+# uleshort magic followed by \x0d\0xa
+2		string		\x0d\x0a
+# extra check: only two bits of flag field are currently used
+>4		ulelong		<0x4
+# \x0d as part of magic should suffice till Python 3.14 (magic 3600)
+>>1		ubyte		0x0d		Byte-compiled Python module for
+!:mime application/x-bytecode.python
+# now look at the magic number to determine the version
+>>>0		uleshort	<3400		CPython 3.7,
+>>>0		default		x
+>>>>0		uleshort	<3420		CPython 3.8,
+>>>>0		default		x
+>>>>>0		uleshort	<3430		CPython 3.9,
+>>>>>0		default		x
+>>>>>>0		uleshort	<3450		CPython 3.10,
+>>>>>>0		default		x
+>>>>>>>0	uleshort	<3500		CPython 3.11,
+>>>>>>>0	default		x		CPython 3.12 or newer,
+>>>0		use		pyc-pep552
+>>0		uleshort	240		Byte-compiled Python module for PyPy3.7,
+!:mime application/x-bytecode.python
+>>>0		use		pyc-pep552
+>>0		uleshort	256		Byte-compiled Python module for PyPy3.8,
+!:mime application/x-bytecode.python
+>>>0		use		pyc-pep552
+>>0		uleshort	336		Byte-compiled Python module for PyPy3.9,
+!:mime application/x-bytecode.python
+>>>0		use		pyc-pep552
 
 0	search/1/w	#!\040/usr/bin/python	Python script text executable
 !:strength + 15

+ 86 - 1
magic/Magdir/riff

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: riff,v 1.43 2021/04/26 15:56:00 christos Exp $
+# $File: riff,v 1.45 2022/07/24 23:47:49 christos Exp $
 # riff:  file(1) magic for RIFF format
 # See
 #
@@ -161,6 +161,64 @@
 #>0  string  x		we got %s
 #>>&(4.l+4)  use riff-walk
 
+# RecorderGear TR500 call recorder digits (BCD)
+0	name	tr500-call-recorder-digits
+>0	byte&0xF0	0x00	\b0
+>0	byte&0xF0	0x10	\b1
+>0	byte&0xF0	0x20	\b2
+>0	byte&0xF0	0x30	\b3
+>0	byte&0xF0	0x40	\b4
+>0	byte&0xF0	0x50	\b5
+>0	byte&0xF0	0x60	\b6
+>0	byte&0xF0	0x70	\b7
+>0	byte&0xF0	0x80	\b8
+>0	byte&0xF0	0x90	\b9
+>0	byte&0xF0	0xb0	\b*
+>0	byte&0xF0	0xc0	\b#
+>0	byte&0x0F	0	\b0
+>0	byte&0x0F	1	\b1
+>0	byte&0x0F	2	\b2
+>0	byte&0x0F	3	\b3
+>0	byte&0x0F	4	\b4
+>0	byte&0x0F	5	\b5
+>0	byte&0x0F	6	\b6
+>0	byte&0x0F	7	\b7
+>0	byte&0x0F	8	\b8
+>0	byte&0x0F	9	\b9
+>0	byte&0x0F	0xb	\b*
+>0	byte&0x0F	0xc	\b#
+
+# TR500 call recorder extended header
+# From: David Korth <gerbilsoft@gerbilsoft.com>
+# Contains dialed/incoming phone number and timestamp.
+# TODO: Verify byte 15.
+0	name	tr500-call-recorder-header
+>15	byte	2	(outgoing call: 
+>15	byte	4	(incoming call: 
+>1	byte	0xFF	\bno number
+>1	byte	!0xFF
+>>1	use	tr500-call-recorder-digits
+>>2	byte	!0xFF
+>>>2	use	tr500-call-recorder-digits
+>>3	byte	!0xFF
+>>>3	use	tr500-call-recorder-digits
+>>4	byte	!0xFF
+>>>4	use	tr500-call-recorder-digits
+>>5	byte	!0xFF
+>>>5	use	tr500-call-recorder-digits
+>>6	byte	!0xFF
+>>>6	use	tr500-call-recorder-digits
+>>7	byte	!0xFF
+>>>7	use	tr500-call-recorder-digits
+>>8	byte	!0xFF
+>>>8	use	tr500-call-recorder-digits
+>9	byte	x	\b, 20%02x
+>10	byte	x	\b/%02x
+>11	byte	x	\b/%02x
+>12	byte	x	%02x
+>13	byte	x	\b:%02x
+>14	byte	x	\b:%02x)
+
 # AVI section extended by Patrik Radman <patrik+file-magic@iki.fi>
 #
 0	string		RIFF		RIFF (little-endian) data
@@ -231,6 +289,11 @@
 !:ext	wav/wave
 >>12    string  >\0
 >>>12   use     riff-walk
+# TR500 call recorder extended header
+>>16	ulelong		0x1E4
+>>>20	leshort		0x11
+>>>>256	byte		4
+>>>>>256 use		tr500-call-recorder-header
 # Update:	Joerg Jenderek
 # lower case for Corel Draw version 8 Bidi
 >8	string/c	cdr
@@ -270,6 +333,27 @@
 #>>>0	use		corel-des
 #>>>0	use		corel-draw
 >8	string		NUNDROOT	\b, Steinberg CuBase
+# From:		Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/MIDI_Instrument_Definition_File
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/i/idf.trid.xml
+#		ftp://curscott.servebeer.com/Download/Apps/_Microsoft/
+#  		Visual%20Studio%206.0%20Professional%20MSDN/
+#		SAMPLES/VC98/SDK/GRAPHICS/AUDIO/IDFEDIT/GLOBALS.H 
+# Note:		called "MIDI Instrument Definition File" by TrID
+>8	string		IDF\ LIST	\b, MIDI Instrument Definition File
+!:mime	audio/x-idf
+!:ext	idf
+# 3rd chunk size like: 254 284 286 670
+#>>0x10	ulelong		x		\b, 3th SIZE %u
+# for debugging purpose display next chunk like: MMAPhdr
+#>>0x14	string		x		\b, 4th "%-8.8s"
+#>>0x1C	ulelong		x		\b, 4th SIZE 0x%x
+# probably MIDI instrument name like: "Universal-MIDI-Instrument" "instrument name" "General MIDI"
+>>0x30	string		x		"%s"
+# look for inst TAG
+>>0x31	search/256	inst		by
+# probably manufacture name like: "Unspecified Company" "NVidia Corporation"
+>>>&0x24	string	x		"%s"
 # AVI == Audio Video Interleave
 # Reference:	http://fileformats.archiveteam.org/wiki/AVI
 >8	string		AVI\040		\b, AVI
@@ -676,6 +760,7 @@
 # for debugging purpose display 5th chunk like: LIST osfp
 #>>(26.l+30)	string	x		\b, 5th "%-4.4s"
 >4	ulelong+8	x		\b, %u bytes
+
 #
 # XXX - some of the below may only appear in little-endian form.
 #

+ 45 - 0
magic/Magdir/ringdove

@@ -0,0 +1,45 @@
+#------------------------------------------------------------------------------
+# $File: ringdove,v 1.1 2022/08/16 12:04:30 christos Exp $
+# ringdove:  file(1) magic for RingdoveEDA data files
+
+# librnd and global
+0	regex/128l	ha:rnd-menu-v[0-9]+[\ \t\r\n]*[{]	librnd menu system (lihata)
+0	regex/128l	ha:rnd-menu-patch-v[0-9]+[\ \t\r\n]*[{]	librnd menu patch (lihata)
+0	regex/128l	ha:coraleda-project-v[0-9]+[\ \t\r\n]*[{]	CoralEDA/Ringdove project file (lihata)
+0	regex/128l	ha:ringdove-project-v[0-9]+[\ \t\r\n]*[{]	Ringdove project file (lihata)
+
+# pcb-rnd
+0	regex/128l	ha:pcb-rnd-board-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd board file (lihata)
+0	regex/128l	li:pcb-rnd-subcircuit-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd subcircuit/footprint file (lihata)
+0	regex/128l	ha:pcb-rnd-buffer-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd paste buffer content (lihata)
+0	regex/128l	li:pcb-rnd-conf-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd configuration (lihata)
+0	regex/128l	ha:pcb-rnd-drc-query-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd drc query string (lihata)
+0	regex/128l	li:pcb-rnd-font-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd vector font (lihata)
+0	regex/128l	ha:pcb-rnd-log-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd message log dump (lihata)
+0	regex/128l	ha:pcb-rnd-padstack-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd padstack (lihata)
+0	regex/128l	li:pcb-rnd-view-list-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd view list (lihata)
+0	regex/128l	li:view-list-v[0-9]+[\ \t\r\n]*[{]	pcb-rnd view list (lihata)
+0	search	Netlist(Freeze)	pcb-rnd or gEDA/PCB netlist forward annotation action script
+
+# sch-rnd (cschem data model)
+0	regex/128l	li:cschem-buffer-v[0-9]+[\ \t\r\n]*[{]	sch-rnd/cschem buffer content (lihata)
+0	regex/128l	li:sch-rnd-conf-v[0-9]+[\ \t\r\n]*[{]	sch-rnd configuration (lihata)
+0	regex/128l	ha:std_devmap.v[0-9]+[\ \t\r\n]*[{]	sch-rnd devmap (device mapping; lihata)
+0	regex/128l	li:cschem-group-v[0-9]+[\ \t\r\n]*[{]	sch-rnd/cschem group or symbol (lihata)
+0	regex/128l	ha:cschem-sheet-v[0-9]+[\ \t\r\n]*[{]	sch-rnd/cschem schematic sheet (lihata)
+
+# tEDAx (modular format)
+0	regex/1l	tEDAx[\ \t\r\n]v	tEDAx (Trivial EDA eXchange)
+>0	regex	begin\ symbol\ v	with schematic symbol
+>0	regex	begin\ board\ v	with Printed Circuit Board
+>0	regex	begin\ route_req\ v	with PCB routing request
+>0	regex	begin\ route_res\ v	with PCB routing result
+>0	regex	begin\ camv_layer\ v	with camv-rnd exported layer
+>0	regex	begin\ netlist\ v	with netlist
+>0	regex	begin\ backann\ v	with Ringdove EDA back annotation
+>0	regex	begin\ footprint\ v	with PCB footprint
+>0	regex	begin\ drc\ v	with PCB DRC script
+>0	regex	begin\ drc_query_rule\ v	with pcb-rnd drc_query rules
+>0	regex	begin\ drc_query_def\ v	with pcb-rnd drc_query value/config definitions
+>0	regex	begin\ etest\ v	with PCB electric test
+

+ 24 - 1
magic/Magdir/rpi

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: rpi,v 1.2 2019/10/02 02:07:30 christos Exp $
+# $File: rpi,v 1.3 2022/04/02 14:39:34 christos Exp $
 # rpi:  file(1) magic for Raspberry Pi images
 -44		lelong	0
 >4		lelong	0
@@ -27,3 +27,26 @@
 >>>>>>>>>40	string	DDTK8
 >>>>>>>>>>48	lelong	4
 >>>>>>>>>>>52	string	RPTL		Raspberry PI kernel image
+
+# From: 	Joerg Jenderek
+# URL:		https://www.raspberrypi.com/documentation/computers/raspberry-pi.html
+#		#raspberry-pi-4-boot-eeprom
+# Reference:	https://github.com/raspberrypi/rpi-eeprom/blob/master/rpi-eeprom-config
+# Note:		start with same magic as for BIOS (ia32) ROM Extension handled by ./intel
+# masked with MAGIC_MASK and then compared with MAGIC
+0	belong&0xFFffF00F	0x55aaF00F	Raspberry PI EEPROM
+#!:mime	application/octet-stream
+!:mime	application/x-raspberry-eeprom
+# like: pieeprom-2020-09-03.bin
+!:ext	bin
+# a 32 bit offset to the next section like: 000184d4 000184c8 00018534 ... 0000bb84 0000bbd4 0000bbd4
+>4	ubelong			x		\b, offset %8.8x
+#>(4.L)	ubelong			x		NEXT=%8.8x
+# self.length
+>8	ubelong			!0		\b, length %x
+# self.filename
+>12	string			>0		\b, "%s"
+# length is zero
+>8	ubelong			=0
+# if length is zero then 2nd section magic here can be zero; this means sections parsing done
+>>8	ubelong			!0		\b, 2nd MAGIC=%8.8x

+ 27 - 22
magic/Magdir/sgml

@@ -1,16 +1,18 @@
 
 #------------------------------------------------------------------------------
-# $File: sgml,v 1.42 2020/12/12 20:01:47 christos Exp $
+# $File: sgml,v 1.46 2022/08/16 11:16:39 christos Exp $
 # Type:	SVG Vectorial Graphics
 # From:	Noel Torres <tecnico@ejerciciosresueltos.com>
 0	string		\<?xml\ version=
 >14	regex		['"\ \t]*[0-9.]+['"\ \t]*
 >>19	search/4096	\<svg			SVG Scalable Vector Graphics image
 !:mime	image/svg+xml
+!:ext   svg
 >>19	search/4096	\<gnc-v2		GnuCash file
 !:mime	application/x-gnucash
 0	string		\<svg			SVG Scalable Vector Graphics image
 !:mime	image/svg+xml
+!:ext   svg
 
 # Sitemap file
 0	string/t		\<?xml\ version=
@@ -52,66 +54,66 @@
 # https://www.w3.org/TR/SVG/single-page.html
 0	search/4096/cWbt	\<!doctype\ svg	SVG XML document
 !:mime  image/svg+xml
-!:strength + 5
+!:strength + 15
 
 0	search/4096/cwt	\<head\>		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cWt	\<head\ 		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cwt	\<title\>		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cWt	\<title\ 		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cwt	\<html\>		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cWt	\<html\ 		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cwt	\<script\> 		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cWt	\<script\ 		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cwt	\<style\> 		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cWt	\<style\  		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cwt	\<table\>		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 0	search/4096/cWt	\<table\ 		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 
 0	search/4096/cwt	\<a\ href=		HTML document text
 !:mime	text/html
-!:strength + 5
+!:strength + 15
 
 # Extensible markup language (XML), a subset of SGML
 # from Marc Prud'hommeaux (marc@apocalypse.org)
 0	search/1/cwt	\<?xml			XML document text
 !:mime	text/xml
-!:strength + 5
+!:strength + 15
 0	string/t		\<?xml\ version\ "	XML
 !:mime	text/xml
-!:strength + 5
+!:strength + 15
 0	string/t		\<?xml\ version="	XML
 !:mime	text/xml
-!:strength + 5
+!:strength + 15
 >15	string/t	>\0			%.3s document text
 >>23	search/1	\<xsl:stylesheet	(XSL stylesheet)
 >>24	search/1	\<xsl:stylesheet	(XSL stylesheet)
 0	string/t	\<?xml\ version='	XML
 !:mime	text/xml
-!:strength + 5
+!:strength + 15
 >15	string/t	>\0			%.3s document text
 >>23	search/1	\<xsl:stylesheet	(XSL stylesheet)
 >>24	search/1	\<xsl:stylesheet	(XSL stylesheet)
@@ -139,7 +141,10 @@
 # http://files.pef-format.org/specifications/pef-2008-1/pef-specification.html
 #
 # Simon Aittamaa <simon.aittamaa@gmail.com>
-0   string      \<?xml\ version=
->14 regex       ['"\ \t]*[0-9.]+['"\ \t]*
->>19    search/4096 \<pef           Portable Embosser Format
+0	string		\<?xml\ version=
+>14	regex		['"\ \t]*[0-9.]+['"\ \t]*
+>>19    search/4096	\<pef           Portable Embosser Format
 !:mime  application/x-pef+xml
+
+# https://www.qgis.org/en/site/
+0	string		\<!DOCTYPE\040qgis	QGIS XML document

+ 54 - 2
magic/Magdir/sniffer

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: sniffer,v 1.30 2021/07/03 13:51:56 christos Exp $
+# $File: sniffer,v 1.32 2022/07/30 16:46:56 christos Exp $
 # sniffer:  file(1) magic for packet capture files
 #
 # From: guy@alum.mit.edu (Guy Harris)
@@ -270,6 +270,11 @@
 >20	belong&0x03FFFFFF		288		(USB 2.0
 >20	belong&0x03FFFFFF		289		(ATSC ALP
 >20	belong&0x03FFFFFF		290		(Event Tracing for Windows
+>20	belong&0x03FFFFFF		291		(Hilscher netANALYZER NG pseudo-footer
+>20	belong&0x03FFFFFF		292		(ZBOSS NCP protocol with pseudo-header
+>20	belong&0x03FFFFFF		293		(Low-Speed USB 2.0/1.1/1.0
+>20	belong&0x03FFFFFF		294		(Full-Speed USB 2.0/1.1/1.0
+>20	belong&0x03FFFFFF		295		(High-Speed USB 2.0
 # print default match
 >20	default		x
 >>20	belong		x		(linktype#%u
@@ -362,4 +367,51 @@
 #
 # Files from Accellent Group's 5View products.
 #
-0	string		\xaa\xaa\xaa\xaa	5View capture file
+# URL:		http://www.infovista.com
+# Reference:	http://mark0.net/download/triddefs_xml.7z
+#		defs/0/5vw.trid.xml
+#		https://2.na.dl.wireshark.org/src/wireshark-3.6.2.tar.xz
+#		wireshark-3.6.2/wiretap/5views.c 
+# Update:	Joerg Jenderek
+# Note:		called "5View capture" by TrID and
+#		"Wireshark capture file" on Windows or
+#		"Packet Capture (Accellent/InfoVista 5view)" by shared MIME-info database
+#		verified/falsified by `wireshark *.5vw`
+0	string		\xaa\xaa\xaa\xaa
+# skip misidentified boot/x86_64/loader/kroete.dat on Suse LEAP DVD
+# by check for valid record version
+>8	ulelong		=0x00010000
+>>0	use	5view-le
+0	name	5view-le
+# t_5VW_Info_Header.Signature = CST_5VW_INFO_HEADER_KEY = 0xAAAAAAAAU
+>0	ulelong		x			5View capture file
+# https://reposcope.com/mimetype/application/x-5view
+!:mime	application/x-5view
+!:ext	5vw
+# size of header in bytes (included signature and reserved fields); probably always 20h
+>4	ulelong		!0x00000020		\b, header size %#x
+# version of header record; apparently always CST_5VW_INFO_RECORD_VERSION=0x00010000U
+>8	ulelong		!0x00010000		\b, record version %#x
+# DataSize; total size of data without header like: 18h
+>12	ulelong		x			\b, record size %#x
+# filetype; type of the capture file like: 18001000h
+>16	ulelong		x			\b, file type %#8.8x
+# Reserved[3]; reserved for future use; apparently zero
+>20	quad		!0			\b, Reserved %#llx
+# look for record header key CST_5VW_RECORDS_HEADER_KEY of structure t_5VW_TimeStamped_Header
+>0x20	search/0xB8/b	\xEE\xEE\x33\x33	\b; record
+# HeaderSize; actual size of this header in bytes like: 32 24h
+>>&0	uleshort	x			size %#x
+# HeaderType; exact type of this header; probably always 0x4000
+>>&2	uleshort	!0x4000			\b, header type %#x
+# RecType; type of record like: 80000000h
+>>&4	ulelong		x			\b, record type %#x
+# RecSubType; subtype of record like: 0
+>>&8	ulelong		!0			\b, subtype %#x
+# RecSize; Size of one record like: 5Ch
+>>&12	ulelong		x			\b, RecSize %#x
+# RecNb; Number of records like: 1
+>>&16	ulelong		>1			\b, %#x records
+# Timestamp Utc
+#>>&20	ulelong		x			\b, RAW TIME %#8.8x
+>>&20	date		x			\b, Time-stamp %s

+ 7 - 1
magic/Magdir/sql

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: sql,v 1.23 2021/07/30 14:53:38 christos Exp $
+# $File: sql,v 1.24 2022/07/17 15:32:48 christos Exp $
 # sql:  file(1) magic for SQL files
 #
 # From: "Marty Leisner" <mleisner@eng.mc.xerox.com>
@@ -217,3 +217,9 @@
 
 # H2 Database from https://www.h2database.com/
 0	string		--\ H2\ 0.5/B\ --\ \n	H2 Database file
+
+# DuckDB database file from https://duckdb.org
+8	string	DUCK    DuckDB database file
+>12	lequad	x	\b, version %lld
+#>20	lequad	x	\b, flags %#llx
+#>28	lequad	x	\b, flags %#llx

+ 2 - 2
magic/Magdir/statistics

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: statistics,v 1.2 2020/10/08 17:51:53 christos Exp $
+# $File: statistics,v 1.3 2022/03/24 15:48:58 christos Exp $
 # statistics:  file(1) magic for statistics related software
 #
 
@@ -42,4 +42,4 @@
 # Example of those files can be found on Zenodo:
 # https://zenodo.org/search?page=1&size=20&q=&file_type=dta
 0	string	\<stata_dta\>\<header\>\<release\>	Stata Data File
->&0	regex	[0-9]*					(Release %s)
+>&0	regex	[0-9]+					(Release %s)

+ 38 - 0
magic/Magdir/subtitle

@@ -0,0 +1,38 @@
+
+#------------------------------------------------------------------------------
+# $File: subtitle,v 1.2 2022/09/07 11:29:09 christos Exp $
+# subtitle:  file(1) magic for subtitles files
+
+# EBU-STL
+# https://tech.ebu.ch/docs/tech/tech3264.pdf
+3	string	STL		EBU-STL subtitles
+>6	regex	=^[0-9][0-9]	\b, rate %s
+>>8	string	.01		\b, v1
+!:mime	application/x-ebu-stl
+>>>16	regex	=^[^\ ]{0,32}	\b, title "%s"
+>>>>224 regex	=^[0-9]{2}	\b, created %-.2s
+>>>>>&0 regex	=^[0-9]{2}	\b-%-.2s
+>>>>>>&0 regex	=^[0-9]{2}	\b-%-.2s
+!:ext	stl
+
+# SubRip (srt) subtitles
+0	regex/20	=^1[\r\n]+0[01]:[0-9]{2}:[0-9]{2},[0-9]{3}\040-->	 SubRip
+!:mime	application/x-subrip
+!:ext	srt
+
+# WebVTT subtitles
+# https://www.w3.org/TR/webvtt1/
+0	string/t	WEBVTT
+>&0	regex/255	=[0-9]{2}:[0-9]{2}\\.[0-9]{3}\040-->	WebVTT subtitles
+!:mime	text/vtt
+!:ext	vtt
+
+# XML TTML subtitles
+# https://www.w3.org/TR/ttml2/
+0	string/t	\<?xml
+>20	search/400	\020xmlns=
+>>&0 regex ['"]http://www.w3.org/ns/ttml    TTML subtitles
+!:mime	application/ttml+xml
+# Augment strength to beat plain XML
+!:strength * 3
+!:ext	ttml

+ 128 - 19
magic/Magdir/sysex

@@ -1,20 +1,42 @@
 
 #------------------------------------------------------------------------
-# $File: sysex,v 1.10 2019/04/19 00:42:27 christos Exp $
+# $File: sysex,v 1.11 2022/01/17 17:16:51 christos Exp $
 # sysex: file(1) magic for MIDI sysex files
 #
 # GRR: original 1 byte test at offset was too general as it catches also many FATs of DOS filesystems
 # where real SYStem EXclusive messages at offset 1 are limited to seven bits
 # https://en.wikipedia.org/wiki/MIDI
-0	ubeshort&0xFF80		0xF000		SysEx File -
-
+# test for StartSysEx byte and upper unsed bit of vendor ID
+0	ubeshort&0xFF80		0xF000
+# MIDI System Exclusive (SysEx) messages (strength=50) after Microsoft Visual C library (strength=70)
+#!:strength +0
+# skip Microsoft Visual C library with page size 16 misidentifed as ADA and
+# page size 32 misidentifed as Inventronics by looking for terminating End Of eXclusive byte (EOX)
+>2		search/12	\xF7
+>>0	use	midi-sysex
+#	display information about MIDI System Exclusive (SysEx) messages
+0	name		midi-sysex
+# https://fileinfo.com/extension/syx	
+>1	ubyte			x		MIDI audio System Exclusive (SysEx) message -
+# Note: file (version 5.41) labeled the above entry as "SysEx File"
+#!:mime	application/octet-stream
+!:mime	audio/x-syx
+# https://onsongapp.com/docs/features/formats/sysex
+!:ext	syx/sysex
+# https://www.midi.org/specifications-old/item/manufacturer-id-numbers
+# https://raw.githubusercontent.com/insolace/MIDI-Sysex-MFG-IDs/master/Sysex%20ID%20Tables/MIDI%20Sysex%20MFG%20IDs.csv
+# SysEx manufacturer ID; originally one byte, but now 0 is used as an escapement to reach the next two
 # North American Group
->1	byte			0x01		Sequential
+#>1	byte			0x01		Sequential
+>1	byte			0x01		Sequential Circuits
 >1	byte			0x02		IDP
->1	byte			0x03		OctavePlateau
+#>1	byte			0x03		OctavePlateau
+>1	byte			0x03		Voyetra Turtle Beach
 >1	byte			0x04		Moog
->1	byte			0x05		Passport
->1	byte			0x06		Lexicon
+#>1	byte			0x05		Passport
+>1	byte			0x05		Passport Designs
+#>1	byte			0x06		Lexicon
+>1	byte			0x06		Lexicon Inc.
 >1	byte			0x07		Kurzweil/Future Retro
 >>3	byte			0x77		777
 >>4	byte			0x00		Bank
@@ -38,12 +60,17 @@
 >>5	byte			0x10		(ALL)
 >>2	byte			x			\b, Channel %d
 >1	byte			0x08		Fender
->1	byte			0x09		Gulbransen
->1	byte			0x0a		AKG
+#>1	byte			0x09		Gulbransen
+>1	byte			0x09		MIDI9
+#>1	byte			0x0a		AKG
+>1	byte			0x0a		AKG Acoustics
 >1	byte			0x0b		Voyce
 >1	byte			0x0c		Waveframe
->1	byte			0x0d		ADA
->1	byte			0x0e		Garfield
+# not ADA programming language
+#>1	byte			0x0d		ADA
+>1	byte			0x0d		ADA Signal Processors Inc.
+#>1	byte			0x0e		Garfield
+>1	byte			0x0e		Garfield Electronics
 >1	byte			0x0f		Ensoniq
 >1	byte			0x10		Oberheim
 >>2	byte			0x06		Matrix 6 series
@@ -59,7 +86,8 @@
 >1	byte			0x16		Lowrey
 >1	byte			0x17		AdamsSmith
 >1	byte			0x18		E-mu
->1	byte			0x19		Harmony
+#>1	byte			0x19		Harmony
+>1	byte			0x19		Harmony Systems
 >1	byte			0x1a		ART
 >1	byte			0x1b		Baldwin
 >1	byte			0x1c		Eventide
@@ -67,23 +95,28 @@
 >1	byte			0x1f		Clarity
 
 # European Group
->1	byte			0x21		SIEL
+#>1	byte			0x21		SIEL
+>1	byte			0x21		Proel Labs (SIEL)
 >1	byte			0x22		Synthaxe
 >1	byte			0x24		Hohner
 >1	byte			0x25		Twister
->1	byte			0x26		Solton
+#>1	byte			0x26		Solton
+>1	byte			0x26		Ketron s.r.l.
 >1	byte			0x27		Jellinghaus
 >1	byte			0x28		Southworth
 >1	byte			0x29		PPG
 >1	byte			0x2a		JEN
->1	byte			0x2b		SSL
->1	byte			0x2c		AudioVertrieb
+#>1	byte			0x2b		SSL
+>1	byte			0x2b		Solid State Logic Organ Systems
+#>1	byte			0x2c		AudioVertrieb
+>1	byte			0x2c		Audio Veritrieb-P. Struven
 
 >1	byte			0x2f		ELKA
 >>3	byte			0x09		EK-44
 
 >1	byte			0x30		Dynacord
->1	byte			0x31		Jomox
+#>1	byte			0x31		Jomox
+>1	byte			0x31		Viscount International Spa
 >1	byte			0x33		Clavia
 >1	byte			0x39		Soundcraft
 # Some Waldorf info from http://Stromeko.Synth.net/Downloads#WaldorfDocs
@@ -202,14 +235,16 @@
 >1	byte			0x44		Casio
 >1	byte			0x46		Kamiya
 >1	byte			0x47		Akai
->1	byte			0x48		Victor
+#>1	byte			0x48		Victor
+>1	byte			0x48		Victor Company of Japan. Ltd.
 >1	byte			0x49		Mesosha
 >1	byte			0x4b		Fujitsu
 >1	byte			0x4c		Sony
 >1	byte			0x4e		Teac
 >1	byte			0x50		Matsushita
 >1	byte			0x51		Fostex
->1	byte			0x52		Zoom
+#>1	byte			0x52		Zoom
+>1	byte			0x52		Zoom Corporation
 >1	byte			0x54		Matsushita
 >1	byte			0x57		Acoustic tech. lab.
 # https://www.midi.org/techspecs/manid.php
@@ -317,4 +352,78 @@
 >1	belong&0xffffff00	0x00204700	Klavis Tech.
 >1	belong&0xffffff00	0x00204800	Noteheads AB
 
+# Update:	Joerg Jenderek; January 2022
+>1	byte			0x00		ID EXTENSIONS
+>1	byte			0x13		Digidesign Inc.
+>1	byte			0x1e		Key Concepts
+>1	byte			0x20		Passac
+>1	byte			0x23		Stepp
+>1	byte			0x2d		Neve
+>1	byte			0x2e		Soundtracs Ltd.
+>1	byte			0x32		Drawmer
+>1	byte			0x34		Audio Architecture
+>1	byte			0x35		Generalmusic Corp SpA
+>1	byte			0x36		Cheetah Marketing
+>1	byte			0x37		C.T.M.
+>1	byte			0x38		Simmons UK
+>1	byte			0x3a		Steinberg
+>1	byte			0x3b		Wersi GmbH
+>1	byte			0x3c		AVAB Niethammer AB
+>1	byte			0x3d		Digigram
+>1	byte			0x3f		Quasimidi
+#
+>1	byte			0x40		Kawai Musical Instruments MFG. CO. Ltd
+#>1	byte			0x45		foo
+#>1	byte			0x4a		foo
+#>1	byte			0x4d		foo
+#>1	byte			0x4f		foo
+#>1	byte			0x53		foo
+>1	byte			0x55		Suzuki Musical Instruments MFG. Co. Ltd.
+>1	byte			0x56		Fuji Sound Corporation Ltd.
+#>1	byte			0x58		foo
+>1	byte			0x59		Faith. Inc.
+>1	byte			0x5a		Internet Corporation
+#>1	byte			0x5b		foo
+>1	byte			0x5c		Seekers Co. Ltd.
+#>1	byte			0x5d		foo
+#>1	byte			0x5e		foo
+>1	byte			0x5f		SD Card Association
+# Reserved for other uses for 60H to 7FH
+# URL:		https://www.philscomputerlab.com/roland-midi-emulator-project-20.html
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/s/syx--midiemu.trid.xml
+# Note:         called by TrID "MIDI Emulator Project SysEx preset command"
+>1	byte			0x66		MIDI Emulator
+# https://electronicmusic.fandom.com/wiki/List_of_MIDI_Manufacturer_IDs
+# Educational, prototyping, test, private use and experimentation
+>1	byte			0x7D		PROTOTYPING
+# universal non-real-time (sample dump, tuning table, etc.)
+>1	byte			0x7E		UNIVERSAL
+# universal real time (MIDI time code, MIDI Machine control, etc.)
+>1	byte			0x7F		universal real time 
+# display information about End Of eXclusive byte (EOX=F7)
+#>2	ubyte			0xF7		\b, at 2 EOX
+#>3	ubyte			0xF7		\b, at 3 EOX
+# https://tttapa.github.io/Control-Surface-doc/new-input/Doxygen/d2/d93/SysEx-Send-Receive_8ino-example.html
+>4	ubyte			0xF7		\b, at 4 EOX
+# http://www.1manband.nl/tutorials2/sysex.htm
+>5	ubyte			0xF7		\b, at 5 EOX
+# http://www.somascape.org/midi/tech/mfile.html#sysex
+>6	ubyte			0xF7		\b, at 6 EOX
+#
+>7	ubyte			0xF7		\b, at 7 EOX
+# https://webmidijs.org/forum/discussion/34/how-to-send-or-receive-system-exclusive-messages
+>8	ubyte			0xF7		\b, at 8 EOX
+#
+>9	ubyte			0xF7		\b, at 9 EOX
+# https://www.chd-el.cz/wp-content/uploads/845010_syxcom.pdf
+>10	ubyte			0xF7		\b, at 10 EOX
+# https://stackoverflow.com/questions/52906076/handling-midi-the-input-of-multiple-system-exclusive-messages-in-vb
+>11	ubyte			0xF7		\b, at 11 EOX
+# https://www.2writers.com/eddie/TutSysEx.htm
+>12	ubyte			0xF7		\b, at 12 EOX
+>13	ubyte			0xF7		\b, at 13 EOX
+# http://www.chromakinetics.com/handsonic/rolSysEx.htm
+>14	ubyte			0xF7		\b, at 14 EOX
+#>15	ubyte			0xF7		\b, at 15 EOX
+
 0	string			T707		Roland TR-707 Data

+ 10 - 8
magic/Magdir/uuencode

@@ -1,16 +1,18 @@
 
 #------------------------------------------------------------------------------
-# $File: uuencode,v 1.8 2019/12/14 20:40:26 christos Exp $
+# $File: uuencode,v 1.9 2021/11/13 17:48:10 christos Exp $
 # uuencode:  file(1) magic for ASCII-encoded files
 #
 
-# GRR:  the first line of xxencoded files is identical to that in uuencoded
-# files, but the first character in most subsequent lines is 'h' instead of
-# 'M'.  (xxencoding uses lowercase letters in place of most of uuencode's
-# punctuation and survives BITNET gateways better.)  If regular expressions
-# were supported, this entry could possibly be split into two with
-# "begin\040\.\*\012M" or "begin\040\.\*\012h" (where \. and \* are REs).
-0	search/1	begin\ 		uuencoded or xxencoded text
+# The first line of xxencoded files is identical to that in uuencoded files,
+# but the first character in most subsequent lines is 'h' instead of 'M'.
+# (xxencoding uses lowercase letters in place of most of uuencode's
+# punctuation and survives BITNET gateways better.)
+0		regex/1024	\^begin\040[0-7]{3}\040
+>&0		regex/256	[\012\015]+M[\040-\140]{60}[\012\015]+				uuencoded text
+>&0		regex/256	[\012\015]+h[0-9A-Za-z\053\055]{60}[\012\015]+		xxencoded text
+>&0		default		x													uuencoded or xxencoded text
+>&0		string		>\0													\b, file name "%s"
 
 # btoa(1) is an alternative to uuencode that requires less space.
 0	search/1	xbtoa\ Begin	btoa'd text

+ 7 - 7
magic/Magdir/virtual

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: virtual,v 1.14 2021/04/26 15:56:00 christos Exp $
+# $File: virtual,v 1.17 2022/08/23 08:00:54 christos Exp $
 # From: James Nobis <quel@quelrod.net>
 # Microsoft hard disk images for:
 # Virtual Server
@@ -9,10 +9,10 @@
 # URL: http://fileformats.archiveteam.org/wiki/VHD_(Virtual_Hard_Disk)
 # Reference: https://download.microsoft.com/download/f/f/e/ffef50a5-07dd-4cf8-aaa3-442c0673a029/
 # Virtual%20Hard%20Disk%20Format%20Spec_10_18_06.doc
-0	string	connectix	Microsoft Disk Image, Virtual Server or Virtual PC
+0	string	conectix	Microsoft Disk Image, Virtual Server or Virtual PC
 # alternative shorter names
-#0	string	connectix	Microsoft Virtual Hard Disk image
-#0	string	connectix	Microsoft Virtual HD image
+#0	string	conectix	Microsoft Virtual Hard Disk image
+#0	string	conectix	Microsoft Virtual HD image
 !:mime	application/x-virtualbox-vhd
 !:ext   vhd
 # Features is a bit field used to indicate specific feature support
@@ -219,7 +219,8 @@
 # Updated by Adam Buchbinder (adam.buchbinder@gmail.com)
 # Made by reading sources, reading documentation, and doing trial and error
 # on existing QCOW files
-0	string/b	QFI\xFB
+0	string/b	QFI\xFB	QEMU QCOW Image
+!:mime	application/x-qemu-disk
 
 # Uncomment the following line to display Magic (only used for debugging
 # this magic number)
@@ -227,8 +228,7 @@
 
 # There are currently 2 Versions: "1" and "2".
 # https://www.gnome.org/~markmc/qcow-image-format-version-1.html
->4	belong		!1	QEMU QCOW2 Image
->4	belong		1	QEMU QCOW Image (v1)
+>4	belong		x	(v%d)
 
 # Using the existence of the Backing File Offset to determine whether
 # to read Backing File Information

+ 3 - 1
magic/Magdir/webassembly

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: webassembly,v 1.3 2019/04/19 00:42:27 christos Exp $
+# $File: webassembly,v 1.4 2022/08/16 11:16:39 christos Exp $
 # webassembly:  file(1) magic for WebAssembly modules
 #
 # WebAssembly is a virtual architecture developed by a W3C Community
@@ -12,4 +12,6 @@
 
 0	string	\0asm	WebAssembly (wasm) binary module
 >4	lelong	=1	version %#x (MVP)
+!:mime  application/wasm
+!:ext   wasm
 >4	lelong	>1	version %#x

+ 323 - 33
magic/Magdir/windows

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: windows,v 1.37 2021/04/26 15:56:00 christos Exp $
+# $File: windows,v 1.46 2022/07/02 17:46:09 christos Exp $
 # windows:  file(1) magic for Microsoft Windows
 #
 # This file is mainly reserved for files where programs
@@ -15,14 +15,84 @@
 
 
 # Summary: Outlook Express DBX file
-# Extension: .dbx
 # Created by: Christophe Monniez
-0	string	\xCF\xAD\x12\xFE	MS Outlook Express DBX file
->4	byte	=0xC5			\b, message database
->4	byte	=0xC6			\b, folder database
->4	byte	=0xC7			\b, account information
->4	byte	=0x30			\b, offline database
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/Outlook_Express_Database
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/d/dbx.trid.xml
+#		https://sourceforge.net/projects/ol2mbox/files/LibDBX/
+#		v1.0.4/libdbx_1.0.4.tar.gz/FILE-FORMAT 
+# Note:		called "Outlook Express Database" by TrID and DROID via PUID fmt/838 fmt/839
+#		and partly verified by `undbx --verbosity 4 Posteingang.dbx`
+0	string	\xCF\xAD\x12\xFE
+# skip DROID fmt-838-signature-id-1193.dbx fmt-839-signature-id-1194.dbx by check for valid file size
+>0x7C	ulelong	>0			MS Outlook Express DBX file
+#!:mime		application/octet-stream
+#!:mime		application/vnd.ms-outlook
+!:mime		application/x-ms-dbx
+!:ext	dbx
+>>4	byte	=0xC5			\b, message database
+>>4	byte	=0xC6			\b, folder database
+>>4	byte	=0xC7			\b, account information
+>>4	byte	=0x30			\b, offline database
+# version like: 5.2 5.5 (typical)
+>>20	ulequad	!0x0000000500000005	\b, version
+# major version
+>>>24	ulelong	x			%u
+# minor version
+>>>20	ulelong	x			\b.%u
+# CLSID: 6F74FDC5-E366-11d1-9A4E-00C04FA309D4~Message 6F74FDC6-E366-11D1-9A4E-00C04FA309D4~Folder
+# 26FE9D30-1A8F-11D2-AABF-006097D474C4~offline
+#>>4	guid	x			\b, CLSID %s
+# file size; total size of file; sometimes real size a little bit higher
+>>0x7C	ulelong	x			\b, ~ %u bytes
+# highest Email ID; the next email will have a number one higher than this
+>>0x5c	ulelong	x			\b, highest ID %#x
+# item count; number of items stored in this DBX file
+>>0xC4	ulelong	x			\b, %u item
+# plural s
+>>0xC4	ulelong	!1			\bs
+# index pointer; file offset pointing to a page of Data Indexes
+>>0xE4	ulelong	>0			\b, index pointer %#x
 
+# From:		Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/Nickfile
+#		https://www.nirsoft.net/utils/outlook_nk2_edit.html
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/n/nk2.trid.xml
+#		https://github.com/libyal/libnk2/blob/main/documentation
+#		Nickfile%20(NK2)%20format.asciidoc
+# Note:		called "Outlook Nickfile" by TrID & TestDisk and
+#		"Outlook Nickname File" by Microsoft Outlook and
+#		"Outlook AutoComplete File" by Nirsoft NK2Edit
+#		partly verfied by NK2Edit Raw Text Edit Mode
+0	ubelong		0x0DF0ADBA	MS Outlook Nickfile
+#!:mime		application/octet-stream
+#!:mime		application/vnd.ms-outlook
+!:mime		application/x-ms-nickfile
+!:ext	nk2/dat/bak
+# nick is used by "older" Outlook; dat is used by "newer" Outlook (probably 2010 - 2016); bak is used for backup
+#!:ext	nick/nk2/dat/bak
+# Unknown; probably a version indicator like: 0000000Ah 0000000Ch 
+>4	ulelong		x		\b, probably version %u
+# Unknown2; probably a version indicator like: 1 0
+>8	ulelong		x		\b.%u
+# number of rows (nickname or alias items) in file
+>12	ulelong		x		\b, %u items
+# number of item entries/columns/properties value like: 17h
+>16	ulelong		x		\b, %u entries
+# value type/property tag: 001Fh~4 bytes for data size of UTF-16 LE string
+>20	uleshort	x		\b, value type %#4.4x
+# entry type/property identifier: 6001h~PR_DOTSTUFF_STATE/PR_NICK_NAME_W
+>22	uleshort	x		\b, entry type %#4.4x
+# Reserved like: 0013FD90h
+#>24	ulelong		x		\b, reserved %#8.8x
+# value data array/Irrelevant Union like: 0000000004E31A80h
+#>28	ulequad		x		\b, data %#16.16llx
+# UTF-16
+>20	uleshort	=0x001F
+# unicode string bytes like: 2Ch
+>>36	ulelong		x		\b, %u bytes
+# unicode string value PT_UNICODE like: janesmith@contoso.org
+>>40	lestring16	x		"%s"
 
 # Summary: Windows crash dump
 # Extension: .dmp
@@ -358,7 +428,7 @@
 # skip space at beginning
 >0     string		\040
 # name without extension and greater character or name with hlp extension
->>1	regex/c		\^([^\xd>]*|.*\.hlp)	MS Windows help file Content, based "%s"
+>>1	regex/c		\^([^\xd>]*|.*\\.hlp)	MS Windows help file Content, based "%s"
 !:mime	text/plain
 !:apple	????TEXT
 !:ext	cnt
@@ -382,6 +452,8 @@
 # Created by: unknown
 # 'L' + GUUID
 0	string		\114\0\0\0\001\024\002\0\0\0\0\0\300\0\0\0\0\0\0\106	MS Windows shortcut
+!:mime	application/x-ms-shortcut
+!:ext	lnk
 >20	lelong&1	1	\b, Item id list present
 >20	lelong&2	2	\b, Points to a file or directory
 >20	lelong&4	4	\b, Has Description string
@@ -427,9 +499,95 @@
 
 # Summary: Outlook Personal Folders
 # Created by: unknown
-0	lelong		0x4E444221	Microsoft Outlook email folder
->10	leshort		0x0e		(<=2002)
->10	leshort		0x17		(>=2003)
+# Update:	Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/Personal_Folder_File
+#		https://en.wikipedia.org/wiki/Personal_Storage_Table
+# Reference:	https://interoperability.blob.core.windows.net/files/MS-PST/%5bMS-PST%5d.pdf
+#		http://mark0.net/download/triddefs_xml.7z/defs/p/pab.trid.xml
+# dwMagic !BDN
+0	lelong		0x4E444221
+# skip DROID x-fmt-75-signature-id-472.pab x-fmt-248-signature-id-260.pst x-fmt-249-signature-id-261.pst
+# by check for existance of bPlatformCreate value
+>14	ubyte	x		Microsoft Outlook
+#!:mime		application/octet-stream
+# NOT official registered !
+!:mime		application/vnd.ms-outlook
+# dwCRCPartial; 32-bit cyclic redundancy check (CRC) value of followin 471 bytes; zero for 64-bit
+#>>4	ulelong		!0			\b, CRC %#x
+# wMagicClient; AB (4142h) is used for PAB files; SM (534Dh) is used for PST files; SO (534Fh) is used for OST files
+#>>8	leshort		x			\b, wMagicClient=%#x
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p/pab.trid.xml
+# Note:		called "Microsoft Personal Address Book" by TrID and
+#		"Microsoft Outlook Personal Address Book" by DROID via x-fmt/75
+>>8	leshort		0x4142			Personal Address Book
+#!:mime	application/x-ms-pab
+!:ext	pab
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p/pst.trid.xml
+#		http://mark0.net/download/triddefs_xml.7z/defs/p/pst-unicode.trid.xml
+# Note:		called "Microsoft OutLook Personal Folder" by TrID and
+#		by DROID via x-fmt/248 for ANSI and via x-fmt/249 for Unicode
+#>>8	leshort		0x4D53			\b, PST~
+# called "Microsoft Outlook email folder" in ./windows version 1.37 and older
+>>8	leshort		0x4D53			Personal Storage
+#!:mime	application/x-ms-pst
+!:ext	pst
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/o/ost.trid.xml
+# Note:		called "Outlook Exchange Offline Storage" by TrID
+>>8	leshort		0x4F53			Offline Storage
+#!:mime	application/x-ms-ost
+!:ext	ost
+# wVer; file format version. 14 or 15 if the file is ANSI; > 21 or 23(=17h) if Unicode; 37 for written by Outlook with WIP
+>>10	uleshort	x			(
+# probably NO intermediate versions exist
+>>10	leshort		<0x10			\b<=2002, ANSI,
+>>10	leshort		>0x14			\b>=2003, Unicode,
+>>10	uleshort	x			version %u)
+# wVerClient; client file format version like: 19 22
+#>>12	uleshort	x			\b, wVerClient=%u
+# bPlatformCreate; This value MUST be set to 1 but also found 2
+>>14	ubyte		>1			\b, bPlatformCreate=%u
+# bPlatformAccess; This value MUST be set to 1 but also found 2
+>>15	ubyte		>1			\b, bPlatformAccess=%u
+# dwReserved1; SHOULD ignore and NOT modify this value; SHOULD initialize to zero
+>>16	ulelong		!0			\b, dwReserved1=%#x
+# dwReserved2; SHOULD ignore and NOT modify this value; SHOULD initialize to zero
+>>20	ulelong		!0			\b, dwReserved2=%#x
+# ANSI 32-bit variant Outlook 1997-2002
+>>10	uleshort	<16
+# bidNextB; next BlockID (ANSI 4 bytes)
+#>>>24		ulelong	!0			\b, bidNextB=%#x
+# bidNextP; Next available back BlockID pointer
+#>>>28		ulelong	!0			\b, bidNextP=%#x
+# dwUnique; value monotonically increased when modifying PST; so CRC is changing
+>>>32		ulelong	!0			\b, dwUnique=%#x
+# rgnid[128]; A fixed array of 32 NodeIDs, each corresponding to one of the 32 possible NID_TYPEs
+#>>>36		ubequad	x			\b, rgnid=%#llx...
+# dwReserved; Implementations SHOULD ignore this value and SHOULD NOT modify it; Initialized zero
+>>>164		ulelong	!0			\b, dwReserved=%#x
+# ibFileEof; the size of the PST file, in bytes (ANSI 4 bytes)
+>>>168		ulelong	x			\b, %u bytes
+# ibAMapLast; offset to the last AMap page
+#>>>172		ulelong	x			\b, ibAMapLast=%#x
+# bSentinel; MUST be set to 0x80
+>>>460		ubyte	!0x80			\b, bSentinel=%#x
+# bCryptMethod: 0~No encryption 1~encryption with permutation 2~encryption with cyclic 16~encryption with Windows Information Protection (WIP)
+>>>461		ubyte	>0			\b, bCryptMethod=%u
+# UNICODE 64-bit variant Outlook 2003-2007
+>>10	uleshort >20
+# bidUnused; Unused 8 bytes padding (Unicode only); sometimes like: 0x0000000100000004
+>>>24		ulequad	!0x0000000100000004	\b, bidUnused=%#16.16llx
+# dwUnique; value monotonically increased when modifying PST; so CRC is changing
+>>>40		ulelong	!0			\b, dwUnique=%#x
+# rgnid[] (128 bytes): A fixed array of 32 NIDs, each corresponding to one of the 32 possible
+#>>>44		ubequad	x			\b, rgnid=%#llx...
+# ibFileEof; the size of the PST file, in bytes (Unicode 8 bytes)
+>>>184		ulequad	x			\b, %llu bytes
+# bSentinel; MUST be set to 0x80
+>>>512		ubyte	!0x80			\b, bSentinel=%#x
+# bCryptMethod; Encryption type like: 0 1 2 16
+>>>513		ubyte	>0			\b, bCryptMethod=%u
+# dwCRC; 32-bit CRC of the of the previous 516 bytes
+>>>524		ulelong		x		\b, CRC32 %#x
 
 
 # Summary: Windows help cache
@@ -495,10 +653,16 @@
 # empty line CRLF
 0	ubeshort	0x0D0A
 >0	use		ini-file
-# comment line
+# comment line starting with semicolon
 0	string		;
->0	use		ini-file
-# section line
+# look for phrase of Windows policy ADMinistrative template (with starting remark)
+# like: WINDOW_95_CD/TOOLS/RESKIT/netadmin/poledit/conf.adm
+>1	search/3548	END\040CATEGORY
+# ADM with remark (by adm-rem.trid.xml) already done by generic ASCII variant
+# if no Windows policy ADMinistrative template then Windows INItialization
+>1	default		x
+>>0	use		ini-file
+# section line starting with left bracket
 0	string		[
 >0	use		ini-file
 # check and then display Windows INItialization configuration
@@ -510,7 +674,7 @@
 # space after right bracket
 # or AutoRun.Amd64 for 64 bit systems
 # or only NL separator
->>&0	regex/c		\^(autorun)
+>>&0	regex/c		\^autorun
 # but sometimes total commander directory tree file "treeinfo.wc" with lines like
 # [AUTORUN]
 # [boot]
@@ -535,11 +699,11 @@
 # http://www.winfaq.de/faq_html/Content/tip2500/onlinefaq.php?h=tip2653.htm
 # https://msdn.microsoft.com/en-us/library/windows/desktop/cc144102.aspx
 # .ShellClassInfo DeleteOnCopy LocalizedFileNames ASCII coded case-independent
->>&0	regex/c	\^(\.ShellClassInfo|DeleteOnCopy|LocalizedFileNames)]	Windows desktop.ini
+>>&0	regex/1024c	\^(\\.ShellClassInfo|DeleteOnCopy|LocalizedFileNames)]	Windows desktop.ini
 !:mime application/x-wine-extension-ini
 #!:mime text/plain
 # https://support.microsoft.com/kb/84709/
->>&0	regex/c		\^(don't\ load)]				Windows CONTROL.INI
+>>&0	regex/c		\^don't\ load]					Windows CONTROL.INI
 !:mime application/x-wine-extension-ini
 !:ext	ini
 >>&0	regex/c		\^(ndishlp\\$|protman\\$|NETBEUI\\$)]		Windows PROTOCOL.INI
@@ -555,34 +719,57 @@
 !:mime application/x-wine-extension-ini
 !:ext	ini
 # http://www.mdgx.com/newtip6.htm
->>&0	regex/c		\^(SafeList)]					Windows IOS.INI
+>>&0	regex/c		\^SafeList]					Windows IOS.INI
 !:mime application/x-wine-extension-ini
 !:ext	ini
 # https://en.wikipedia.org/wiki/NTLDR	Windows Boot Loader information
->>&0	regex/c		\^(boot\x20loader)]				Windows boot.ini
+>>&0	regex/c		\^boot\x20loader]				Windows boot.ini
 !:mime application/x-wine-extension-ini
 !:ext	ini
 # https://en.wikipedia.org/wiki/CONFIG.SYS
->>&0	regex/c		\^(menu)]					MS-DOS CONFIG.SYS
+>>&0	regex/c		\^menu]						MS-DOS CONFIG.SYS
 # @CONFIG.UI configuration file of previous DOS version saved by Caldera OPENDOS INSTALL.EXE
 # CONFIG.PSS saved version of file CONFIG.SYS created by %WINDIR%\SYSTEM\MSCONFIG.EXE
 # CONFIG.TSH renamed file CONFIG.SYS.BAT by %WINDIR%\SYSTEM\MSCONFIG.EXE
 # dos and w40 used in dual booting scene
 !:ext	sys/dos/w40
 # https://support.microsoft.com/kb/118579/
->>&0	regex/c		\^(Paths)]\r\n					MS-DOS MSDOS.SYS
+>>&0	regex/c		\^Paths]\r\n					MS-DOS MSDOS.SYS
 !:ext	sys/dos
 # http://chmspec.nongnu.org/latest/INI.html#HHP
->>&0	regex/c		\^(options)]\r\n				Microsoft HTML Help Project
+>>&0	regex/c		\^options]\r\n					Microsoft HTML Help Project
 !:mime text/plain
 !:ext	hhp
 # From:		Joerg Jenderek
-# URL:		https://documentation.basis.com/BASISHelp/WebHelp/b3odbc/obdcdriv_character_translation.htm
+# URL:		https://documentation.basis.com/BASISHelp/WebHelp/b3odbc/ODBC_Driver/obdcdriv_character_translation.htm
 # Reference:	https://www.garykessler.net/library/file_sigs.html
+#		http://mark0.net/download/triddefs_xml.7z/defs/c/cpx.trid.xml
 # Note:		stored in directory %WINDIR%\SysWOW64 or %WINDIR%\system
->>&0	regex/c		\^(Windows\ Latin)				Windows codepage translator
-!:mime	text/plain
+#		second word often Latin but sometimes Cyrillic like in 12510866.CPX
+>>&0	regex/c		\^Windows\ (Latin|Cyrillic)			Windows codepage translator
+#!:mime	text/plain
+!:mime	text/x-ms-cpx
+# like: 12510866.CPX 
 !:ext	cpx
+# From:		Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/InstallShield
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/l/lid-is.trid.xml
+# Note:		contain also 3 keywords like: count Default key0
+>>&0	regex/c		\^Languages]					InstallShield Language Identifier
+#!:mime	text/plain
+!:mime	text/x-installshield-lid
+# like: SETUP.LID
+!:ext	lid
+# From:		Joerg Jenderek
+# URL:		https://www.file-extensions.org/tag-file-extension
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/t/taginfo.trid.xml
+# Note:		contain also keywords like: Application Category Company Misc Version
+>>&0	regex/c		\^TagInfo]					TagInfo
+#!:mime	text/plain
+#!:mime	text/prs.lines.tag
+!:mime	text/x-ms-tag
+# like: DATA.TAG
+!:ext	tag
 # unknown keyword after opening bracket
 >>&0	default				x
 #>>>&0	string/c			x	UNKNOWN [%s
@@ -603,28 +790,73 @@
 !:mime	application/x-wine-extension-ini
 #!:mime	text/plain
 !:ext	ini/inf
+# UTF-16 BOM
+0	ubeshort		=0xFFFE
+# look for phrase of Windows policy ADMinistrative template (UTF-16 by adm-uni.trid.xml)
+# like: wuau.adm
+>2	search/0x384A	E\0N\0D\0\040\0C\0A\0T\0E\0G\0O\0R\0Y\0
+>>0	use		windows-adm
+# if no Windows policy ADMinistrative template then Windows INFormation
+>2	default		x
 # UTF-16 BOM followed by CR~0D00 , comment~semicolon~3B00 , section~bracket~5B00
-0	ubelong&0xFFff89FF	=0xFFFE0900
+>>0	ubelong&0xFFff89FF	=0xFFFE0900
 # look for left bracket in section line
->2	search/8192		[
+>>>2	search/8192		[
 # keyword without 1st letter which is maybe up-/down-case
->>&3	lestring16		ersion]			Windows setup INFormation
+>>>>&3	lestring16		ersion]			Windows setup INFormation
 !:mime	application/x-setupscript
+# like: hdaudio.inf iscsi.inf spaceport.inf tpm.inf usbhub3.inf UVncVirtualDisplay.inf
 !:ext	inf
->>&3	lestring16		trings]			Windows setup INFormation
+>>>>&3	lestring16		trings]			Windows setup INFormation
 !:mime	application/x-setupscript
+# like: arduino_gemma.inf iis.inf MSM8960.inf
 !:ext	inf
->>&3	lestring16		ourceDisksNames]	Windows setup INFormation
+>>>>&3	lestring16		ourceDisksNames]	Windows setup INFormation
 !:mime	application/x-setupscript
+# like: atiixpag.inf mdmnokia.inf netefe32.inf rdpbus.inf
 !:ext	inf
 # netnwcli.inf start with ;---[ NetNWCli.INX ]
->>&3	default			x
+>>>>&3	default			x
 # look for NL followed by left bracket
->>>&0	search/8192		\x0A\x00\x5b
->>>>&3	lestring16		ersion]			Windows setup INFormation
+>>>>>&0	search/8192		\x0A\x00\x5b
+# like: defltwk.inf netvwifibus.inf WSDPrint.inf
+>>>>>>&3 lestring16		ersion]			Windows setup INFormation
 !:mime	application/x-setupscript
 !:ext	inf
 
+# Summary:	Windows Policy ADMinistrative template
+# From:		Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/Administrative_Template
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/a/adm.trid.xml
+# Note:		typically stored in directory like: %WINDIR%\system32\GroupPolicy\ADM
+# worst case ASCII variant starting with remark line like: inetset.adm
+0	search/0x4E	CLASS\040
+>&0	string		MACHINE
+>>0	use		windows-adm
+>&0	string		USER
+>>0	use		windows-adm
+# display information about Windows policy ADMinistrative template
+0	name		windows-adm	Windows Policy Administrative Template
+!:mime	text/x-ms-adm
+!:ext	adm
+# UTF-16 BOM implies UTF-16 encoded ADM (by adm-uni.trid.xml)
+>0	ubeshort		=0xFFFE
+>>2	lestring16		x		\b, 1st line "%s"
+# look for UTF-16 encoded CarriageReturn LineFeed
+>>>2	search/0x3A		\r\0\n\0
+>>>>&0	lestring16		x		\b, 2nd line "%s"
+# no UTF-16 BOM implies "ASCII" encoded ADM (by adm.trid.xml)
+>0	ubeshort		!0xFFFE
+>>0		string		x		\b, 1st line "%s"
+#>>>&0		ubequad		x		\b, 2ND %16.16llx
+# 2nd line empty
+>>>&2		beshort		=0x0D0A
+>>>>&0		beshort		!0x0D0A		\b, 3th line
+>>>>>&-2	string		x		"%s"
+# 2nd line with content
+>>>&2		beshort		!0x0D0A		\b, 2nd line
+>>>>&-2		string		x		"%s"
+
 # Windows Precompiled INF files *.PNF added by Joerg Jenderek at Mar 2013 of _PNF_HEADER inf.h
 # http://read.pudn.com/downloads3/sourcecode/windows/248345/win2k/private/windows/setup/setupapi/inf.h__.htm
 # URL:		http://fileformats.archiveteam.org/wiki/INF_(Windows)
@@ -1080,3 +1312,61 @@
 0	string	ID;P	Microsoft SYLK program
 >4	string	>0	\b, created by %s
 !:ext	slk/sylk
+
+# Summary:	Windows Performance Monitor Alert
+# From:		Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/Performance_Monitor
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p/pma.trid.xml
+# Note:		called "Windows Performance Monitor Alert" by TrID
+0	ubelong			=0xDC058340
+>4	ubyte			=0		Windows Performance Monitor Alert
+#!:mime		application/octet-stream
+# https://www.thoughtco.com/mime-types-by-content-type-3469108
+# https://filext.com/file-extension/PAM
+!:mime		application/x-perfmon 
+#!:mime		application/x-ms-pma
+!:ext		pma
+# metric type like: "BrowserMetrics" "CrashpadMetrics" "SetupMetrics"
+>>80	string			x		\b, "%s"
+
+# From:		Joerg Jenderek
+# URL:		https://en.wikipedia.org/wiki/InstallShield
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/i/ins.trid.xml
+# Note:		contain also keywords like: BATCH_INSTALL ISVERSION LOGHANDLE SRCDIR SRCDISK WINDIR WINSYSDISK 
+0	ubelong	0xB8C90C00	InstallShield Script
+#!:mime	application/octet-stream
+!:mime	application/x-installshield-ins
+# like test.ins Setup.ins
+!:ext	ins
+# UNKNOWN like: 160034121de07e00 1600341260befe00 16003412e0783700
+# 5000010021083f00 50000100b0335600 50000100cbfdf800 50000100dfbc4700
+#>4	ubequad		x		\b, at 4 %#16.16llx
+# copyright text like:	"Stirling Technologies, Inc.  (c) 1990-1994"
+#			"InstallSHIELD Software Coporation  (c) 1990-1997"
+>13	pstring/h	x		"%s"
+# look for specific ASCII variable names
+>1	search/0x121/s	SRCDIR	\b, variable names:
+# 1st like: SRCDIR
+>>&-4		leshort		x	#%u
+>>&-2		pstring/h	x	%s
+# 2nd like: SRCDISK
+>>>&0		leshort		x	#%u
+>>>&2		pstring/h	x	%s
+# 3rd like: TARGETDISK
+>>>>&0		leshort		x	#%u
+>>>>&2		pstring/h	x	%s
+# 4th like: TARGETDIR
+#>>>>>&0		leshort		x	#%u
+#>>>>>&2		pstring/h	x	%s
+# 5th like: WINDIR
+#>>>>>>&0	leshort		x	#%u
+#>>>>>>&2	pstring/h	x	%s
+# 6th like: WINDISK
+#>>>>>>>&0	leshort		x	#%u
+#>>>>>>>&2	pstring/h	x	%s
+# 7th like: WINSYSDIR
+#>>>>>>>>&0	leshort		x	#%u
+#>>>>>>>>&2	pstring/h	x	%s
+# ... LOGHANDLE
+>0		ubelong		x	...
+#

+ 235 - 1
magic/Magdir/wordprocessors

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: wordprocessors,v 1.26 2021/08/21 12:45:34 christos Exp $
+# $File: wordprocessors,v 1.31 2022/08/31 08:00:53 christos Exp $
 # wordprocessors:  file(1) magic fo word processors.
 #
 ####### PWP file format used on Smith Corona Personal Word Processors:
@@ -28,35 +28,170 @@
 !:ext	wps
 
 # Corel/WordPerfect
+# URL:		https://en.wikipedia.org/wiki/WordPerfect
+# Reference:	https://github.com/OneWingedShark/WordPerfect/blob/master/doc/SDK_Help/FileFormats/WPFF_DocumentStructure.htm
+#		http://mark0.net/download/triddefs_xml.7z/defs/w/wp-generic.trid.xml
 0	string	\xffWPC
 # WordPerfect
 >8	byte	1
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/w/wpm-macro.trid.xml
+# Note:		there exist other macro variants
 >>9	byte	1	WordPerfect macro
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-wpm
+# like: ALTD.WPM ENDFOOT.WPM FOOTEND.WPM LABELS.WPM REVEALTX.WPM
+!:ext		wpm
+# Note:		used in WordPerfect 5.1; there exist other FIL variants
 >>9	byte	2	WordPerfect help file
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-help
+# like: WPHELP.FIL
+!:ext		fil
+# pointer to document area like: 10h
+>>>4		ulelong	!0x10	\b, at %#x document area
 >>9	byte	3	WordPerfect keyboard file
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-keyboard
+!:ext		wpk
+# no document area, so point to end of file; so this is file size like: 23381 2978 32835 3355 3775 919
+>>>4		ulelong	x	\b, %u bytes
+>>9	byte	4	WordPerfect VAX keyboard definition
+#!:mime	application/octet-stream
+!:mime	application/x-wordperfect-keyboard
+#!:ext	foo
+# URL:		http://fileformats.archiveteam.org/wiki/WordPerfect
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/w/wpd-doc-gen.trid.xml
 >>9	byte	10	WordPerfect document
+# https://www.iana.org/assignments/media-types/application/vnd.wordperfect
+!:mime		application/vnd.wordperfect
+#!:apple		????WPC2
+# TODO: distinguish different suffix
+!:ext		wpd/wpt/wkb/icr/tut/sty/tst/crs
 >>9	byte	11	WordPerfect dictionary
 >>9	byte	12	WordPerfect thesaurus
 >>9	byte	13	WordPerfect block
 >>9	byte	14	WordPerfect rectangular block
 >>9	byte	15	WordPerfect column block
 >>9	byte	16	WordPerfect printer data
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-prs
+# like: STANDARD.PRS WORKBOOK.PRS
+!:ext		prs
+# like: "Standard Printer" "Workbook Printer"
+>>>0x64		pstring/B	>A	"%s"
+#>>9	byte	18	WordPerfect Prefix information file
+# printer resource .ALL
 >>9	byte	19	WordPerfect printer data
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-all
+!:ext		all
+# display Resource
 >>9	byte	20	WordPerfect driver resource data
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-drs
+# like: WPSMALL.DRS
+!:ext		drs
+# pointer to index area with string "smalldrs" like: 46h
+>>>4		uleshort	!0x46	\b, at %#x index area
+>>9	byte	21	WordPerfect Overlay file
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-fil
+# like: WP.FIL
+!:ext		fil
+# URL:		http://fileformats.archiveteam.org/wiki/WordPerfect_Graphics
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-wpg.trid.xml
+# Note:		called "WordPerfect Graphics bitmap" by TrID and
+#		"WordPerfect Graphics Metafile" by DROID via x-fmt/395 fmt/1042
+#		"WPG (Word Perfect Graphics)" by ImageMagick `identify -verbose BUTTRFLY.WPG`
 >>9	byte	22	WordPerfect graphic image
+# TODO: skip DROID x-fmt-395-signature-id-132.wpg by check for existing document area
+#>>>4		ulelong	>15	WordPerfect_graphic_OK
+#!:mime		application/octet-stream
+# http://extension.nirsoft.net/wpg
+!:mime		image/x-wordperfect-graphics
+# https://reposcope.com/mimetype/application/x-wpg
+#!:mime		application/x-wpg
+# like: BUTTRFLY.WPG STAR-5.WPG input.wpg WORDPFCT.WPG
+!:ext		wpg
+# pointer to document area like: 10h 1Ah
+>>>4		ulelong		!0x1A	\b, at %#x document area
 >>9	byte	23	WordPerfect hyphenation code
 >>9	byte	24	WordPerfect hyphenation data
 >>9	byte	25	WordPerfect macro resource data
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-mrs
+# like: WP.MRS
+!:ext		mrs
 >>9	byte	27	WordPerfect hyphenation lex
 >>9	byte	29	WordPerfect wordlist
 >>9	byte	30	WordPerfect equation resource data
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-qrs
+# like: WQ.QRS wpDE.qrs wpen.qrs
+!:ext		qrs
+# jump to document area with some marker and equation
+>>>(4.l)	ubyte	x
+# equation like: "Fraction:  x OVER y"
+>>>>&1		string	>A	(...%-.19s...)
+# pointer to document area like: 17C4h
+>>>4		ulelong	x	\b, at %#x document area
+#>>9	byte	31	reserved
+#>>9	byte	32	WordPerfect VAX .SET
 >>9	byte	33	WordPerfect spell rules
 >>9	byte	34	WordPerfect dictionary rules
+#>>9	byte	35	reserved
+# video resource device driver
+# Note:		 filetype 26 for VRS and filetype 36 for WPD apparently is wrong
+>>9	byte	36	WordPerfect Video Resource
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-vrs
+# like: STANDARD.VRS
+!:ext		vrs
+# like: "IBM CGA (& compatibles)"
+>>>0x20		string	>A	"%.23s"
 >>9	byte	39	WordPerfect spell rules (Microlytics)
+#>>9	byte	40	reserved
+>>9	byte	41	WordPerfect Install options
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-ins
+# like: WP51.INS
+!:ext		ins
+# probably default directory name like: "C:\WP51\"
+>>>0x12		string	>A	"%.8s"
+# maybe mouse driver for WP5.1
+>>9	byte	42	WordPerfect Resource
+#!:mime		application/octet-stream
+!:mime		application/x-wordperfect-irs
+# like: STANDARD.IRS
+!:ext		irs
+# like: "Mouse Driver (MOUSE.COM)"
+>>>0x28		string	>A	"%.24s"
 >>9	byte	43	WordPerfect settings file
+# maybe Macintosh WP2.0 document
 >>9	byte	44	WordPerfect 3.5 document
+!:mime		application/vnd.wordperfect
+!:apple		????WPD3
+# like: WP3.wpd
+!:ext		wpd
 >>9	byte	45	WordPerfect 4.2 document
+# External spell code module (WP5.1)
+#>>9	byte	46	WordPerfect external spell 
+# external spell dictionary .LEX
+#>>9	byte	47	WordPerfect external spell dictionary
+# Macintosh SOFT graphics file (SOFT (Sequential Object Format)
+#>>9	byte	48	WordPerfect SOFT graphics
+#>>9	byte	49	reserved
+#>>9	byte	50	reserved
+# WPWin 5.1 Application Resource Library added for WPWin 5.1
+#>>9	byte	51	WordPerfect application resource library
 >>9	byte	69	WordPerfect dialog file
+# From:		Joerg Jenderek
+# Note:		found in sub directory WritingTools inside WordPerfect 2021 program directory
+>>9	byte	70	WordPerfect Writing Tools
+#!:mime	application/octet-stream
+!:mime	application/x-wordperfect-cbt
+# like: Wt13cbede.cbt Wt13cbeit.cbt Wt13cbefr.cbt WT21cbede.cbt Wt13cbeEN.CBD WT21cbeEN.CBD
+!:ext	cbd/cbt
 >>9	byte	76	WordPerfect button bar
 >>9	default x
 >>>9	byte	x	Corel WordPerfect: Unknown filetype %d
@@ -196,11 +331,48 @@
 >>9	byte	24	GroupWise admin ADS deferment data file
 >>9	default	x
 >>>9	byte	x	GroupWise: Unknown filetype %d
+# Corel Writing Tools WT*.*
+# From:		Joerg Jenderek
+# URL:		https://support.corel.com/hc/en-us/articles/215876258-Writing-Tools-Spell-Check-Dictionary-does-not-work-in-WordPerfect-X5
+#		http://wordperfect.helpmax.net/en/editing-and-formatting-documents/using-the-writing-tools/working-with-user-word-lists/
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/u/uwl-wp.trid.xml
+>8	byte	32
+>>9	byte	10	Corel Writing Tools User Word List
+#!:mime	application/octet-stream
+!:mime	application/x-wordperfect-wordlist
+# personal user word list UWL under user directory like: WTDE.UWL WTUS.UWL WT21DE.UWL WT21US.UWL WT13DE.UWL ...
+# and "template" SAV/HWL variant under program directory like: wt13en.hwl Wt13de.sav Wt13it.sav wt13ru.sav WT21us.sav Wtcz.sav ...
+!:ext	uwl/hwl/sav
+# jump to document area with some marker and word list
+>>>(4.l)	ubyte	x
+# look for beginning of word list starting mostly with letter a as UTF-16 like: Wt13es.sav
+# but not found in russian wt13ru.sav
+>>>>&0	search/91/sb	a\0
+# word list starting like: "acsesory\022accessory.\001\026acomodate\026accommodate4\001"
+>>>>>&0		lestring16	x	(...%-.33s...)
+# pointer to document area like: 200h
+>>>4	ulelong	!0x200	\b, at %#x document area
+# file size, not including pad characters at EOF
+>>>0x14	uleshort x	\b, %u bytes
 # IntelliTAG
 >8	byte	33
 >>9	byte	10	IntelliTAG (SGML) compiled DTD
 >>9	default	x
 >>>9	byte	x	IntelliTAG: Unknown filetype %d
+# Summary:	Corel WordPerfect WritingTools advise part
+# From:		Joerg Jenderek
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/a/adv-wp.trid.xml
+>8	byte	34
+>>9	byte	11	Corel WordPerfect dictionary advise
+#!:mime	application/octet-stream
+!:mime	application/x-wordperfect-adv
+#!:mime	application/vnd.wordperfect.adv
+# like: WT21de.adv Wt13de.adv Wt13es.adv Wt13fr.adv wt13us.adv
+!:ext	adv
+# advise text part often start with tag like: 580A
+#>>>(16.s)	ubequad	x	ADVISE PART %#llx
+# part of advise text like: "This is too informal for most writing."
+>>>(16.s+16)	string	x	(...%-.33s...)
 # everything else
 >8	default x
 >>8	byte	x	Unknown Corel/Wordperfect product %d,
@@ -229,6 +401,68 @@
 !:mime	application/x-quark-xpress-3
 2	string	MMXPRa			Motorola Quark Express Document (Korean)
 
+# From:		Joerg Jenderek
+# URL:		http://fileformats.archiveteam.org/wiki/PageMaker
+#		https://en.wikipedia.org/wiki/Adobe_PageMaker
+# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p
+#		pm4-pagemaker.trid.xml
+#		pm5-pagemaker.trid.xml
+# Note:		since version 6 in 1995 called Adobe PageMaker and
+#		embedded in Compound Document handled by ./ole2compounddocs
+#		mainly tested little endian variant
+4	ubelong		=0x0000FF99
+>0	use		PageMaker
+# big endian variant
+4	ubelong		=0x000099FF
+>0	use		\^PageMaker
+#	display information of Aldus/Adobe PageMaker document/publication
+0	name		PageMaker
+>110	uleshort	<0x0600			Aldus
+>110	uleshort	>0x05FF			Adobe
+>110	uleshort	x			PageMaker
+# "MP" marker for newer version 4 and above according to TrID
+#>108	string		x			\b, MARKER "%.2s"
+# http://www.nationalarchives.gov.uk/pronom/fmt/876
+!:mime		application/vnd.pagemaker	
+#!:mime		application/x-pagemaker
+# different file name extensions are used depending on version
+# older version like 3
+>110	uleshort/256	=0			document
+# https://www.macdisk.com/macsigen.php
+!:apple	ALB3ALD3
+# PT3 for template and no example for PageMaker document/publiction with PM3 extension
+!:ext	pm3/pt3
+>110	uleshort/256	=4			document
+!:apple	ALD4ALB4
+# no example for PT4 template
+!:ext	pm4/pt4
+>110	uleshort/256	=5			document
+!:apple	ALD5ALB5
+# no example for PT5 template
+!:ext	pm5/pt5
+>110	uleshort	=0x0600			document
+!:apple	ALD6ALB6
+# PT6 for template
+!:ext	pm6/pt6
+# HOWTO to distinguish version 7 from 6.5 ?
+>110	uleshort	=0x0632			document
+!:apple	AD65AB65
+# no example for T65 template
+!:ext	p65/t65/pmd/pmt
+# version 7 with PMT extension for template
+#!:ext	pmd/pmt
+#!:apple	????PUBF
+# endian marker FF 99 for little endian
+>6	ubyte	=0xFF			\b, little-endian
+>6	ubyte	=0x99			\b, big-endian
+# newer numeric version like: 4 5 6 6.50
+#>110	uleshort	x			\b, VERSION=%#x
+>110	uleshort	>0x03FF
+>>110	uleshort/256	x			\b, version %u
+>>110	uleshort%256	>0			\b.%u
+# older version like 3
+>110	uleshort	<0x0400			\b, maybe version 3
+
 # adobe indesign (document, whatever...) from querkan
 0	belong	0x0606edf5		Adobe InDesign
 >16	string	DOCUMENT		Document

+ 8 - 1
magic/Magdir/xo65

@@ -1,6 +1,7 @@
 
 #------------------------------------------------------------------------------
-# $File: xo65,v 1.4 2009/09/19 16:28:13 christos Exp $
+# $File: xo65,v 1.5 2022/07/17 15:36:20 christos Exp $
+# https://cc65.github.io/doc/sim65.html
 # xo65 object files
 # From: "Ullrich von Bassewitz" <uz@cc65.org>
 #
@@ -28,3 +29,9 @@
 >6	leshort&0x0003	=0x0001			alignment 2
 >6	leshort&0x0003	=0x0002			alignment 4
 >6	leshort&0x0003	=0x0003			alignment 256
+
+# sim65 executable files
+0	string		\x73\x69\x6d\x36\x35	sim65 executable,
+>5	byte		x			version %d,
+>6	leshort&0x0000	=0x0000			6502
+>6	leshort&0x0001	=0x0001			65C02

+ 3 - 3
magic/Magdir/xwindows

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: xwindows,v 1.12 2021/08/24 08:31:10 christos Exp $
+# $File: xwindows,v 1.13 2022/03/24 15:48:58 christos Exp $
 # xwindows:  file(1) magic for various X/Window system file formats.
 
 # Compiled X Keymap
@@ -37,7 +37,7 @@
 # X bitmap https://en.wikipedia.org/wiki/X_BitMap
 0	search/2048	#define\040
 >&0	regex		[a-zA-Z0-9]+_width\040	xbm image
->>&0	regex		[0-9]*			(%sx
+>>&0	regex		[0-9]+			(%sx
 >>>&0	string		\n#define\040
 >>>>&0	regex		[a-zA-Z0-9]+_height\040
->>>>>&0	regex		[0-9]*			\b%s)
+>>>>>&0	regex		[0-9]+			\b%s)

+ 22 - 8
magic/Magdir/zip

@@ -1,20 +1,28 @@
 #------------------------------------------------------------------------------
-# $File: zip,v 1.7 2021/04/26 15:56:00 christos Exp $
+# $File: zip,v 1.8 2021/10/24 15:53:56 christos Exp $
 # zip:  file(1) magic for zip files; this is not use
 # Note the version of magic in archive is currently stronger, this is
 # just an example until negative offsets are supported better
+# Note:	All fields unless otherwise noted are unsigned!
 
 # Zip Central Directory record
 0	name		zipcd
 >0	string		PK\001\002	Zip archive data
 !:mime	application/zip
+# no "made by" in local file header with PK\3\4 magic
 >>4	leshort		x		\b, made by
 >>4	use		zipversion
 >>4	use		ziphost
+# inside ./archive 1.151 called "at least" zipversion "to extract"
 >>6	leshort		x		\b, extract using at least
 >>6	use		zipversion
->>12	ledate		x		\b, last modified %s
->>24	lelong		>0		\b, uncompressed size %d
+# This is DOS date like: ledate 21:00:48 19 Dec 2001 != DOS 00:00 1 Jan 2010 ~ 0000213C
+>>12	ulelong		x		\b, last modified
+>>14	lemsdosdate	x		\b, last modified %s
+>>12	lemsdostime	x		%s
+# uncompressed size of 1st entry; FFffFFff means real value stored in ZIP64 record
+>>24	ulelong		!0xFFffFFff	\b, uncompressed size %u
+# inside ./archive 1.151 called "compression method="zipcompression
 >>10	leshort		x		\b, method=
 >>10	use		zipcompression
 
@@ -102,11 +110,17 @@
 #>1	ubyte		>19		unused %#x
 
 # Zip End Of Central Directory record
+# GRR: wrong for ZIP with comment archive
 -22	string		PK\005\006
-#>4	leshort		>1		\b, %d disks
-#>6	leshort		>1		\b, central directory disk %d
-#>8	leshort		>1		\b, %d central directories on this disk
-#>10	leshort		>1		\b, %d central directories
-#>12	lelong		x		\b, %d central directory bytes
+#>4	uleshort	!0xFFff		\b, %u disks
+#>6	uleshort	!0xFFff		\b, central directory disk %u
+#>8	uleshort	!0xFFff		\b, %u central directories on this disk
+#>10	uleshort	!0xFFff		\b, %u central directories
+#>12	ulelong		!0xFFffFFff	\b, %u central directory bytes
+# offset of central directory
+#>16	ulelong		x		\b, central directory offset %#x
 >(16.l)	use		zipcd
+# archive comment length n
+#>>20	uleshort	>0		\b, comment length %u
+# archive comment
 >>20	pstring/l	>0		\b, %s

+ 11 - 1
magic/Makefile.am

@@ -1,5 +1,5 @@
 #
-# $File: Makefile.am,v 1.172 2021/10/07 15:41:22 christos Exp $
+# $File: Makefile.am,v 1.182 2022/09/11 21:04:30 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_DIR = $(top_srcdir)/magic
@@ -29,6 +29,7 @@ $(MAGIC_FRAGMENT_DIR)/application \
 $(MAGIC_FRAGMENT_DIR)/applix \
 $(MAGIC_FRAGMENT_DIR)/apt \
 $(MAGIC_FRAGMENT_DIR)/archive \
+$(MAGIC_FRAGMENT_DIR)/aria \
 $(MAGIC_FRAGMENT_DIR)/arm \
 $(MAGIC_FRAGMENT_DIR)/asf \
 $(MAGIC_FRAGMENT_DIR)/assembler \
@@ -52,12 +53,14 @@ $(MAGIC_FRAGMENT_DIR)/bout \
 $(MAGIC_FRAGMENT_DIR)/bsdi \
 $(MAGIC_FRAGMENT_DIR)/bsi \
 $(MAGIC_FRAGMENT_DIR)/btsnoop \
+$(MAGIC_FRAGMENT_DIR)/burp \
 $(MAGIC_FRAGMENT_DIR)/bytecode \
 $(MAGIC_FRAGMENT_DIR)/c-lang \
 $(MAGIC_FRAGMENT_DIR)/c64 \
 $(MAGIC_FRAGMENT_DIR)/cad \
 $(MAGIC_FRAGMENT_DIR)/cafebabe \
 $(MAGIC_FRAGMENT_DIR)/cbor \
+$(MAGIC_FRAGMENT_DIR)/ccf \
 $(MAGIC_FRAGMENT_DIR)/cddb \
 $(MAGIC_FRAGMENT_DIR)/chord \
 $(MAGIC_FRAGMENT_DIR)/cisco \
@@ -89,6 +92,7 @@ $(MAGIC_FRAGMENT_DIR)/dif \
 $(MAGIC_FRAGMENT_DIR)/diff \
 $(MAGIC_FRAGMENT_DIR)/digital \
 $(MAGIC_FRAGMENT_DIR)/dolby \
+$(MAGIC_FRAGMENT_DIR)/dsf \
 $(MAGIC_FRAGMENT_DIR)/dump \
 $(MAGIC_FRAGMENT_DIR)/dyadic \
 $(MAGIC_FRAGMENT_DIR)/ebml \
@@ -116,6 +120,7 @@ $(MAGIC_FRAGMENT_DIR)/fusecompress \
 $(MAGIC_FRAGMENT_DIR)/games \
 $(MAGIC_FRAGMENT_DIR)/gcc \
 $(MAGIC_FRAGMENT_DIR)/gconv \
+$(MAGIC_FRAGMENT_DIR)/gentoo \
 $(MAGIC_FRAGMENT_DIR)/geo \
 $(MAGIC_FRAGMENT_DIR)/geos \
 $(MAGIC_FRAGMENT_DIR)/gimp \
@@ -206,6 +211,7 @@ $(MAGIC_FRAGMENT_DIR)/netbsd \
 $(MAGIC_FRAGMENT_DIR)/netscape \
 $(MAGIC_FRAGMENT_DIR)/netware \
 $(MAGIC_FRAGMENT_DIR)/news \
+$(MAGIC_FRAGMENT_DIR)/nifty \
 $(MAGIC_FRAGMENT_DIR)/nim-lang \
 $(MAGIC_FRAGMENT_DIR)/nitpicker \
 $(MAGIC_FRAGMENT_DIR)/numpy \
@@ -216,6 +222,7 @@ $(MAGIC_FRAGMENT_DIR)/ole2compounddocs \
 $(MAGIC_FRAGMENT_DIR)/olf \
 $(MAGIC_FRAGMENT_DIR)/openfst \
 $(MAGIC_FRAGMENT_DIR)/opentimestamps \
+$(MAGIC_FRAGMENT_DIR)/oric \
 $(MAGIC_FRAGMENT_DIR)/os2 \
 $(MAGIC_FRAGMENT_DIR)/os400 \
 $(MAGIC_FRAGMENT_DIR)/os9 \
@@ -228,6 +235,7 @@ $(MAGIC_FRAGMENT_DIR)/pbf \
 $(MAGIC_FRAGMENT_DIR)/pbm \
 $(MAGIC_FRAGMENT_DIR)/pc88 \
 $(MAGIC_FRAGMENT_DIR)/pc98 \
+$(MAGIC_FRAGMENT_DIR)/pci_ids \
 $(MAGIC_FRAGMENT_DIR)/pcjr \
 $(MAGIC_FRAGMENT_DIR)/pdf \
 $(MAGIC_FRAGMENT_DIR)/pdp \
@@ -251,6 +259,7 @@ $(MAGIC_FRAGMENT_DIR)/pyramid \
 $(MAGIC_FRAGMENT_DIR)/python \
 $(MAGIC_FRAGMENT_DIR)/qt \
 $(MAGIC_FRAGMENT_DIR)/revision \
+$(MAGIC_FRAGMENT_DIR)/ringdove \
 $(MAGIC_FRAGMENT_DIR)/riff \
 $(MAGIC_FRAGMENT_DIR)/rpi \
 $(MAGIC_FRAGMENT_DIR)/rpm \
@@ -283,6 +292,7 @@ $(MAGIC_FRAGMENT_DIR)/sql \
 $(MAGIC_FRAGMENT_DIR)/ssh \
 $(MAGIC_FRAGMENT_DIR)/ssl \
 $(MAGIC_FRAGMENT_DIR)/statistics \
+$(MAGIC_FRAGMENT_DIR)/subtitle \
 $(MAGIC_FRAGMENT_DIR)/sun \
 $(MAGIC_FRAGMENT_DIR)/sylk \
 $(MAGIC_FRAGMENT_DIR)/symbos \

+ 17 - 5
magic/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.5 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2021 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -165,8 +165,9 @@ CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CFLAG_VISIBILITY = @CFLAG_VISIBILITY@
-CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CSCOPE = @CSCOPE@
+CTAGS = @CTAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
@@ -177,6 +178,7 @@ ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
 EGREP = @EGREP@
+ETAGS = @ETAGS@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
 GREP = @GREP@
@@ -265,6 +267,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -275,7 +278,7 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 
 #
-# $File: Makefile.am,v 1.172 2021/10/07 15:41:22 christos Exp $
+# $File: Makefile.am,v 1.182 2022/09/11 21:04:30 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_DIR = $(top_srcdir)/magic
@@ -303,6 +306,7 @@ $(MAGIC_FRAGMENT_DIR)/application \
 $(MAGIC_FRAGMENT_DIR)/applix \
 $(MAGIC_FRAGMENT_DIR)/apt \
 $(MAGIC_FRAGMENT_DIR)/archive \
+$(MAGIC_FRAGMENT_DIR)/aria \
 $(MAGIC_FRAGMENT_DIR)/arm \
 $(MAGIC_FRAGMENT_DIR)/asf \
 $(MAGIC_FRAGMENT_DIR)/assembler \
@@ -326,12 +330,14 @@ $(MAGIC_FRAGMENT_DIR)/bout \
 $(MAGIC_FRAGMENT_DIR)/bsdi \
 $(MAGIC_FRAGMENT_DIR)/bsi \
 $(MAGIC_FRAGMENT_DIR)/btsnoop \
+$(MAGIC_FRAGMENT_DIR)/burp \
 $(MAGIC_FRAGMENT_DIR)/bytecode \
 $(MAGIC_FRAGMENT_DIR)/c-lang \
 $(MAGIC_FRAGMENT_DIR)/c64 \
 $(MAGIC_FRAGMENT_DIR)/cad \
 $(MAGIC_FRAGMENT_DIR)/cafebabe \
 $(MAGIC_FRAGMENT_DIR)/cbor \
+$(MAGIC_FRAGMENT_DIR)/ccf \
 $(MAGIC_FRAGMENT_DIR)/cddb \
 $(MAGIC_FRAGMENT_DIR)/chord \
 $(MAGIC_FRAGMENT_DIR)/cisco \
@@ -363,6 +369,7 @@ $(MAGIC_FRAGMENT_DIR)/dif \
 $(MAGIC_FRAGMENT_DIR)/diff \
 $(MAGIC_FRAGMENT_DIR)/digital \
 $(MAGIC_FRAGMENT_DIR)/dolby \
+$(MAGIC_FRAGMENT_DIR)/dsf \
 $(MAGIC_FRAGMENT_DIR)/dump \
 $(MAGIC_FRAGMENT_DIR)/dyadic \
 $(MAGIC_FRAGMENT_DIR)/ebml \
@@ -390,6 +397,7 @@ $(MAGIC_FRAGMENT_DIR)/fusecompress \
 $(MAGIC_FRAGMENT_DIR)/games \
 $(MAGIC_FRAGMENT_DIR)/gcc \
 $(MAGIC_FRAGMENT_DIR)/gconv \
+$(MAGIC_FRAGMENT_DIR)/gentoo \
 $(MAGIC_FRAGMENT_DIR)/geo \
 $(MAGIC_FRAGMENT_DIR)/geos \
 $(MAGIC_FRAGMENT_DIR)/gimp \
@@ -480,6 +488,7 @@ $(MAGIC_FRAGMENT_DIR)/netbsd \
 $(MAGIC_FRAGMENT_DIR)/netscape \
 $(MAGIC_FRAGMENT_DIR)/netware \
 $(MAGIC_FRAGMENT_DIR)/news \
+$(MAGIC_FRAGMENT_DIR)/nifty \
 $(MAGIC_FRAGMENT_DIR)/nim-lang \
 $(MAGIC_FRAGMENT_DIR)/nitpicker \
 $(MAGIC_FRAGMENT_DIR)/numpy \
@@ -490,6 +499,7 @@ $(MAGIC_FRAGMENT_DIR)/ole2compounddocs \
 $(MAGIC_FRAGMENT_DIR)/olf \
 $(MAGIC_FRAGMENT_DIR)/openfst \
 $(MAGIC_FRAGMENT_DIR)/opentimestamps \
+$(MAGIC_FRAGMENT_DIR)/oric \
 $(MAGIC_FRAGMENT_DIR)/os2 \
 $(MAGIC_FRAGMENT_DIR)/os400 \
 $(MAGIC_FRAGMENT_DIR)/os9 \
@@ -502,6 +512,7 @@ $(MAGIC_FRAGMENT_DIR)/pbf \
 $(MAGIC_FRAGMENT_DIR)/pbm \
 $(MAGIC_FRAGMENT_DIR)/pc88 \
 $(MAGIC_FRAGMENT_DIR)/pc98 \
+$(MAGIC_FRAGMENT_DIR)/pci_ids \
 $(MAGIC_FRAGMENT_DIR)/pcjr \
 $(MAGIC_FRAGMENT_DIR)/pdf \
 $(MAGIC_FRAGMENT_DIR)/pdp \
@@ -525,6 +536,7 @@ $(MAGIC_FRAGMENT_DIR)/pyramid \
 $(MAGIC_FRAGMENT_DIR)/python \
 $(MAGIC_FRAGMENT_DIR)/qt \
 $(MAGIC_FRAGMENT_DIR)/revision \
+$(MAGIC_FRAGMENT_DIR)/ringdove \
 $(MAGIC_FRAGMENT_DIR)/riff \
 $(MAGIC_FRAGMENT_DIR)/rpi \
 $(MAGIC_FRAGMENT_DIR)/rpm \
@@ -557,6 +569,7 @@ $(MAGIC_FRAGMENT_DIR)/sql \
 $(MAGIC_FRAGMENT_DIR)/ssh \
 $(MAGIC_FRAGMENT_DIR)/ssl \
 $(MAGIC_FRAGMENT_DIR)/statistics \
+$(MAGIC_FRAGMENT_DIR)/subtitle \
 $(MAGIC_FRAGMENT_DIR)/sun \
 $(MAGIC_FRAGMENT_DIR)/sylk \
 $(MAGIC_FRAGMENT_DIR)/symbos \
@@ -689,7 +702,6 @@ ctags CTAGS:
 
 cscope cscopelist:
 
-
 distdir: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) distdir-am
 

+ 1 - 1
missing

@@ -3,7 +3,7 @@
 
 scriptversion=2018-03-07.03; # UTC
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2021 Free Software Foundation, Inc.
 # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 
 # This program is free software; you can redistribute it and/or modify

+ 7 - 5
python/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.5 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2021 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -120,7 +120,7 @@ am__can_run_installinfo = \
     *) (install-info --version) >/dev/null 2>&1;; \
   esac
 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
-am__DIST_COMMON = $(srcdir)/Makefile.in
+am__DIST_COMMON = $(srcdir)/Makefile.in README.md
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 pkgdatadir = @pkgdatadir@
 ACLOCAL = @ACLOCAL@
@@ -135,8 +135,9 @@ CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CFLAG_VISIBILITY = @CFLAG_VISIBILITY@
-CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CSCOPE = @CSCOPE@
+CTAGS = @CTAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
@@ -147,6 +148,7 @@ ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
 EGREP = @EGREP@
+ETAGS = @ETAGS@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
 GREP = @GREP@
@@ -235,6 +237,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -290,7 +293,6 @@ ctags CTAGS:
 
 cscope cscopelist:
 
-
 distdir: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) distdir-am
 

+ 29 - 7
python/magic.py

@@ -272,20 +272,42 @@ def open(flags):
     Returns a magic object on success and None on failure.
     Flags argument as for setflags.
     """
-    return Magic(_open(flags))
+    magic_t = _open(flags)
+    if magic_t is None:
+        return None
+    return Magic(magic_t)
 
 
 # Objects used by `detect_from_` functions
+class error(Exception):
+    pass
+
 class MagicDetect(object):
     def __init__(self):
-        self.mime_magic = Magic(_open(MAGIC_MIME))
-        self.mime_magic.load()
-        self.none_magic = Magic(_open(MAGIC_NONE))
-        self.none_magic.load()
+        self.mime_magic = open(MAGIC_MIME)
+        if self.mime_magic is None:
+            raise error
+        if self.mime_magic.load() == -1:
+            self.mime_magic.close()
+            self.mime_magic = None
+            raise error
+        self.none_magic = open(MAGIC_NONE)
+        if self.none_magic is None:
+            self.mime_magic.close()
+            self.mime_magic = None
+            raise error
+        if self.none_magic.load() == -1:
+            self.none_magic.close()
+            self.none_magic = None
+            self.mime_magic.close()
+            self.mime_magic = None
+            raise error
 
     def __del__(self):
-        self.mime_magic.close()
-        self.none_magic.close()
+        if self.mime_magic is not None:
+            self.mime_magic.close()
+        if self.none_magic is not None:
+            self.none_magic.close()
 
 threadlocal = threading.local()
 

+ 4 - 4
python/tests.py

@@ -8,7 +8,7 @@ import magic
 class MagicTestCase(unittest.TestCase):
 
     filename = 'magic.py'
-    expected_mime_type = 'text/x-python'
+    expected_mime_type = 'text/x-script.python'
     expected_encoding = 'us-ascii'
     expected_name = 'Python script, ASCII text executable'
 
@@ -22,11 +22,11 @@ class MagicTestCase(unittest.TestCase):
         self.assert_result(result)
 
     def test_detect_from_fobj(self):
-        with open(self.filename) as fobj:
+        with open(self.filename, "rb") as fobj:
             result = magic.detect_from_fobj(fobj)
         self.assert_result(result)
 
     def test_detect_from_content(self):
-        with open(self.filename) as fobj:
-            result = magic.detect_from_content(fobj.read(4096))
+        with open(self.filename, "rb") as fobj:
+            result = magic.detect_from_content(fobj.read(8192))
         self.assert_result(result)

+ 9 - 8
src/Makefile.in

@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.5 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2021 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -229,8 +229,6 @@ am__define_uniq_tagged_files = \
   unique=`for i in $$list; do \
     if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
   done | $(am__uniquify_input)`
-ETAGS = etags
-CTAGS = ctags
 am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \
 	asctime_r.c asprintf.c ctime_r.c dprintf.c fmtcheck.c \
 	getline.c getopt_long.c gmtime_r.c localtime_r.c pread.c \
@@ -249,8 +247,9 @@ CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CFLAG_VISIBILITY = @CFLAG_VISIBILITY@
-CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CSCOPE = @CSCOPE@
+CTAGS = @CTAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
@@ -261,6 +260,7 @@ ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
 EGREP = @EGREP@
+ETAGS = @ETAGS@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
 GREP = @GREP@
@@ -349,6 +349,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -653,7 +654,6 @@ cscopelist-am: $(am__tagged_files)
 
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-
 distdir: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) distdir-am
 
@@ -699,7 +699,8 @@ installdirs:
 	done
 install: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) install-am
-install-exec: install-exec-am
+install-exec: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-exec-am
 install-data: install-data-am
 uninstall: uninstall-am
 
@@ -870,7 +871,7 @@ ps-am:
 uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES \
 	uninstall-nodist_includeHEADERS
 
-.MAKE: all check install install-am install-strip
+.MAKE: all check install install-am install-exec install-strip
 
 .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
 	clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \

+ 306 - 157
src/apprentice.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.309 2021/09/24 13:59:19 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.326 2022/09/13 18:46:07 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -50,6 +50,12 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.309 2021/09/24 13:59:19 christos Exp $")
 #endif
 #include <dirent.h>
 #include <limits.h>
+#ifdef HAVE_BYTESWAP_H
+#include <byteswap.h>
+#endif
+#ifdef HAVE_SYS_BSWAP_H
+#include <sys/bswap.h>
+#endif
 
 
 #define	EATAB {while (isascii(CAST(unsigned char, *l)) && \
@@ -114,7 +120,8 @@ private int parse(struct magic_set *, struct magic_entry *, const char *,
     size_t, int);
 private void eatsize(const char **);
 private int apprentice_1(struct magic_set *, const char *, int);
-private size_t apprentice_magic_strength(const struct magic *);
+private ssize_t apprentice_magic_strength_1(const struct magic *);
+private size_t apprentice_magic_strength(const struct magic *, size_t);
 private int apprentice_sort(const void *, const void *);
 private void apprentice_list(struct mlist *, int );
 private struct magic_map *apprentice_load(struct magic_set *,
@@ -124,9 +131,21 @@ private void mlist_free_all(struct magic_set *);
 private void mlist_free(struct mlist *);
 private void byteswap(struct magic *, uint32_t);
 private void bs1(struct magic *);
+
+#if defined(HAVE_BYTESWAP_H)
+#define swap2(x)	bswap_16(x)
+#define swap4(x)	bswap_32(x)
+#define swap8(x)	bswap_64(x)
+#elif defined(HAVE_SYS_BSWAP_H)
+#define swap2(x)	bswap16(x)
+#define swap4(x)	bswap32(x)
+#define swap8(x)	bswap64(x)
+#else
 private uint16_t swap2(uint16_t);
 private uint32_t swap4(uint32_t);
 private uint64_t swap8(uint64_t);
+#endif
+
 private char *mkdbname(struct magic_set *, const char *, int);
 private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
     size_t);
@@ -270,6 +289,13 @@ static const struct type_tbl_s type_tbl[] = {
 	{ XX("offset"),		FILE_OFFSET,		FILE_FMT_QUAD },
 	{ XX("bevarint"),	FILE_BEVARINT,		FILE_FMT_STR },
 	{ XX("levarint"),	FILE_LEVARINT,		FILE_FMT_STR },
+	{ XX("msdosdate"),	FILE_MSDOSDATE,		FILE_FMT_STR },
+	{ XX("lemsdosdate"),	FILE_LEMSDOSDATE,	FILE_FMT_STR },
+	{ XX("bemsdosdate"),	FILE_BEMSDOSDATE,	FILE_FMT_STR },
+	{ XX("msdostime"),	FILE_MSDOSTIME,		FILE_FMT_STR },
+	{ XX("lemsdostime"),	FILE_LEMSDOSTIME,	FILE_FMT_STR },
+	{ XX("bemsdostime"),	FILE_BEMSDOSTIME,	FILE_FMT_STR },
+	{ XX("octal"),		FILE_OCTAL,		FILE_FMT_STR },
 	{ XX_NULL,		FILE_INVALID,		FILE_FMT_NONE },
 };
 
@@ -281,6 +307,7 @@ static const struct type_tbl_s special_tbl[] = {
 	{ XX("der"),		FILE_DER,		FILE_FMT_STR },
 	{ XX("name"),		FILE_NAME,		FILE_FMT_STR },
 	{ XX("use"),		FILE_USE,		FILE_FMT_STR },
+	{ XX("octal"),		FILE_OCTAL,		FILE_FMT_STR },
 	{ XX_NULL,		FILE_INVALID,		FILE_FMT_NONE },
 };
 # undef XX
@@ -425,7 +452,15 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
 	ml->map = idx == 0 ? map : NULL;
 	ml->magic = map->magic[idx];
 	ml->nmagic = map->nmagic[idx];
-
+	if (ml->nmagic) {
+		ml->magic_rxcomp = CAST(file_regex_t **,
+		    calloc(ml->nmagic, sizeof(*ml->magic_rxcomp)));
+		if (ml->magic_rxcomp == NULL) {
+			free(ml);
+			return -1;
+		}
+	} else
+		ml->magic_rxcomp = NULL;
 	mlp->prev->next = ml;
 	ml->prev = mlp->prev;
 	ml->next = mlp;
@@ -507,6 +542,9 @@ file_ms_free(struct magic_set *ms)
 	free(ms->o.pbuf);
 	free(ms->o.buf);
 	free(ms->c.li);
+#ifdef USE_C_LOCALE
+	freelocale(ms->c_lc_ctype);
+#endif
 	free(ms);
 }
 
@@ -546,6 +584,10 @@ file_ms_alloc(int flags)
 	ms->regex_max = FILE_REGEX_MAX;
 	ms->bytes_max = FILE_BYTES_MAX;
 	ms->encoding_max = FILE_ENCODING_MAX;
+#ifdef USE_C_LOCALE
+	ms->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
+	assert(ms->c_lc_ctype != NULL);
+#endif
 	return ms;
 free:
 	free(ms);
@@ -580,6 +622,7 @@ apprentice_unmap(struct magic_map *map)
 		break;
 #endif
 	default:
+		fprintf(stderr, "Bad map type %d", map->type);
 		abort();
 	}
 	free(map);
@@ -610,8 +653,20 @@ mlist_free_all(struct magic_set *ms)
 private void
 mlist_free_one(struct mlist *ml)
 {
+	size_t i;
+
 	if (ml->map)
 		apprentice_unmap(CAST(struct magic_map *, ml->map));
+
+	for (i = 0; i < ml->nmagic; ++i) {
+		if (ml->magic_rxcomp[i]) {
+			file_regfree(ml->magic_rxcomp[i]);
+			free(ml->magic_rxcomp[i]);
+			ml->magic_rxcomp[i] = NULL;
+		}
+	}
+	free(ml->magic_rxcomp);
+	ml->magic_rxcomp = NULL;
 	free(ml);
 }
 
@@ -711,7 +766,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
 	fn = mfn;
 
 	while (fn) {
-		p = strchr(fn, PATHSEP);
+		p = CCAST(char *, strchr(fn, PATHSEP));
 		if (p)
 			*p++ = '\0';
 		if (*fn == '\0')
@@ -817,6 +872,12 @@ typesize(int type)
 	case FILE_SHORT:
 	case FILE_LESHORT:
 	case FILE_BESHORT:
+	case FILE_MSDOSDATE:
+	case FILE_BEMSDOSDATE:
+	case FILE_LEMSDOSDATE:
+	case FILE_MSDOSTIME:
+	case FILE_BEMSDOSTIME:
+	case FILE_LEMSDOSTIME:
 		return 2;
 
 	case FILE_LONG:
@@ -836,6 +897,8 @@ typesize(int type)
 	case FILE_FLOAT:
 	case FILE_BEFLOAT:
 	case FILE_LEFLOAT:
+	case FILE_BEID3:
+	case FILE_LEID3:
 		return 4;
 
 	case FILE_QUAD:
@@ -869,8 +932,8 @@ typesize(int type)
 /*
  * Get weight of this magic entry, for sorting purposes.
  */
-private size_t
-apprentice_magic_strength(const struct magic *m)
+private ssize_t
+apprentice_magic_strength_1(const struct magic *m)
 {
 #define MULT 10U
 	size_t ts, v;
@@ -878,8 +941,10 @@ apprentice_magic_strength(const struct magic *m)
 
 	switch (m->type) {
 	case FILE_DEFAULT:	/* make sure this sorts last */
-		if (m->factor_op != FILE_FACTOR_OP_NONE)
+		if (m->factor_op != FILE_FACTOR_OP_NONE) {
+			fprintf(stderr, "Bad factor_op %d", m->factor_op);
 			abort();
+		}
 		return 0;
 
 	case FILE_BYTE:
@@ -919,15 +984,27 @@ apprentice_magic_strength(const struct magic *m)
 	case FILE_BEVARINT:
 	case FILE_LEVARINT:
 	case FILE_GUID:
+	case FILE_BEID3:
+	case FILE_LEID3:
 	case FILE_OFFSET:
+	case FILE_MSDOSDATE:
+	case FILE_BEMSDOSDATE:
+	case FILE_LEMSDOSDATE:
+	case FILE_MSDOSTIME:
+	case FILE_BEMSDOSTIME:
+	case FILE_LEMSDOSTIME:
 		ts = typesize(m->type);
-		if (ts == FILE_BADSIZE)
+		if (ts == FILE_BADSIZE) {
+			(void)fprintf(stderr, "Bad size for type %d\n",
+			    m->type);
 			abort();
+		}
 		val += ts * MULT;
 		break;
 
 	case FILE_PSTRING:
 	case FILE_STRING:
+	case FILE_OCTAL:
 		val += m->vallen * MULT;
 		break;
 
@@ -950,6 +1027,7 @@ apprentice_magic_strength(const struct magic *m)
 	case FILE_INDIRECT:
 	case FILE_NAME:
 	case FILE_USE:
+	case FILE_CLEAR:
 		break;
 
 	case FILE_DER:
@@ -986,6 +1064,34 @@ apprentice_magic_strength(const struct magic *m)
 		abort();
 	}
 
+	return val;
+}
+
+
+/*ARGSUSED*/
+private size_t
+apprentice_magic_strength(const struct magic *m,
+    size_t nmagic __attribute__((__unused__)))
+{
+	ssize_t val = apprentice_magic_strength_1(m);
+
+#ifdef notyet
+	if (m->desc[0] == '\0') {
+		size_t i;
+		/*
+		 * Magic entries with no description get their continuations
+		 * added
+		 */
+		for (i = 1; m[i].cont_level != 0 && i < MIN(nmagic, 3); i++) {
+			ssize_t v = apprentice_magic_strength_1(&m[i]) >>
+			    (i + 1);
+			val += v;
+			if (m[i].desc[0] != '\0')
+				break;
+		}
+	}
+#endif
+
 	switch (m->factor_op) {
 	case FILE_FACTOR_OP_NONE:
 		break;
@@ -1002,18 +1108,22 @@ apprentice_magic_strength(const struct magic *m)
 		val /= m->factor;
 		break;
 	default:
+		(void)fprintf(stderr, "Bad factor_op %u\n", m->factor_op);
 		abort();
 	}
 
 	if (val <= 0)	/* ensure we only return 0 for FILE_DEFAULT */
 		val = 1;
 
+#ifndef notyet
 	/*
 	 * Magic entries with no description get a bonus because they depend
 	 * on subsequent magic entries to print something.
 	 */
 	if (m->desc[0] == '\0')
 		val++;
+#endif
+
 	return val;
 }
 
@@ -1025,8 +1135,8 @@ apprentice_sort(const void *a, const void *b)
 {
 	const struct magic_entry *ma = CAST(const struct magic_entry *, a);
 	const struct magic_entry *mb = CAST(const struct magic_entry *, b);
-	size_t sa = apprentice_magic_strength(ma->mp);
-	size_t sb = apprentice_magic_strength(mb->mp);
+	size_t sa = apprentice_magic_strength(ma->mp, ma->cont_count);
+	size_t sb = apprentice_magic_strength(mb->mp, mb->cont_count);
 	if (sa == sb)
 		return 0;
 	else if (sa > sb)
@@ -1041,7 +1151,7 @@ apprentice_sort(const void *a, const void *b)
 private void
 apprentice_list(struct mlist *mlist, int mode)
 {
-	uint32_t magindex = 0;
+	uint32_t magindex, descindex, mimeindex, lineindex;
 	struct mlist *ml;
 	for (ml = mlist->next; ml != mlist; ml = ml->next) {
 		for (magindex = 0; magindex < ml->nmagic; magindex++) {
@@ -1058,17 +1168,22 @@ apprentice_list(struct mlist *mlist, int mode)
 			 * Try to iterate over the tree until we find item with
 			 * description/mimetype.
 			 */
-			while (magindex + 1 < ml->nmagic &&
-			       ml->magic[magindex + 1].cont_level != 0 &&
-			       *ml->magic[magindex].desc == '\0' &&
-			       *ml->magic[magindex].mimetype == '\0')
-				magindex++;
+			lineindex = descindex = mimeindex = magindex;
+			for (magindex++; magindex < ml->nmagic &&
+			   ml->magic[magindex].cont_level != 0; magindex++) {
+				if (*ml->magic[descindex].desc == '\0'
+				    && *ml->magic[magindex].desc)
+					descindex = magindex;
+				if (*ml->magic[mimeindex].mimetype == '\0'
+				    && *ml->magic[magindex].mimetype)
+					mimeindex = magindex;
+			}
 
 			printf("Strength = %3" SIZE_T_FORMAT "u@%u: %s [%s]\n",
-			    apprentice_magic_strength(m),
-			    ml->magic[magindex].lineno,
-			    ml->magic[magindex].desc,
-			    ml->magic[magindex].mimetype);
+			    apprentice_magic_strength(m, ml->nmagic - magindex),
+			    ml->magic[lineindex].lineno,
+			    ml->magic[descindex].desc,
+			    ml->magic[mimeindex].mimetype);
 		}
 	}
 }
@@ -1116,6 +1231,13 @@ set_test_type(struct magic *mstart, struct magic *m)
 	case FILE_DER:
 	case FILE_GUID:
 	case FILE_OFFSET:
+	case FILE_MSDOSDATE:
+	case FILE_BEMSDOSDATE:
+	case FILE_LEMSDOSDATE:
+	case FILE_MSDOSTIME:
+	case FILE_BEMSDOSTIME:
+	case FILE_LEMSDOSTIME:
+	case FILE_OCTAL:
 		mstart->flag |= BINTEST;
 		break;
 	case FILE_STRING:
@@ -1162,19 +1284,21 @@ addentry(struct magic_set *ms, struct magic_entry *me,
    struct magic_entry_set *mset)
 {
 	size_t i = me->mp->type == FILE_NAME ? 1 : 0;
-	if (mset[i].count == mset[i].max) {
+	if (mset[i].me == NULL || mset[i].count == mset[i].max) {
 		struct magic_entry *mp;
 
-		mset[i].max += ALLOC_INCR;
+		size_t incr = mset[i].max + ALLOC_INCR;
 		if ((mp = CAST(struct magic_entry *,
-		    realloc(mset[i].me, sizeof(*mp) * mset[i].max))) ==
+		    realloc(mset[i].me, sizeof(*mp) * incr))) ==
 		    NULL) {
-			file_oomem(ms, sizeof(*mp) * mset[i].max);
+			file_oomem(ms, sizeof(*mp) * incr);
 			return -1;
 		}
 		(void)memset(&mp[mset[i].count], 0, sizeof(*mp) *
 		    ALLOC_INCR);
 		mset[i].me = mp;
+		mset[i].max = CAST(uint32_t, incr);
+		assert(mset[i].max == incr);
 	}
 	mset[i].me[mset[i].count++] = *me;
 	memset(me, 0, sizeof(*me));
@@ -1535,6 +1659,12 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
 		case FILE_FLOAT:
 		case FILE_BEFLOAT:
 		case FILE_LEFLOAT:
+		case FILE_MSDOSDATE:
+		case FILE_BEMSDOSDATE:
+		case FILE_LEMSDOSDATE:
+		case FILE_MSDOSTIME:
+		case FILE_BEMSDOSTIME:
+		case FILE_LEMSDOSTIME:
 			v = CAST(int32_t, v);
 			break;
 		case FILE_QUAD:
@@ -1570,6 +1700,7 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
 		case FILE_CLEAR:
 		case FILE_DER:
 		case FILE_GUID:
+		case FILE_OCTAL:
 			break;
 		default:
 			if (ms->flags & MAGIC_CHECK)
@@ -2044,6 +2175,9 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
 			case 'I':
 				m->in_type = FILE_BEID3;
 				break;
+			case 'o':
+				m->in_type = FILE_OCTAL;
+				break;
 			case 'q':
 				m->in_type = FILE_LEQUAD;
 				break;
@@ -2294,6 +2428,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
  * parse a STRENGTH annotation line from magic file, put into magic[index - 1]
  * if valid
  */
+/*ARGSUSED*/
 private int
 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line,
     size_t len __attribute__((__unused__)))
@@ -2413,11 +2548,9 @@ private int
 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line,
     size_t len)
 {
-	struct magic *m = &me->mp[0];
-
 	return parse_extra(ms, me, line, len,
 	    CAST(off_t, offsetof(struct magic, apple)),
-	    sizeof(m->apple), "APPLE", "!+-./?", 0);
+	    sizeof(me->mp[0].apple), "APPLE", "!+-./?", 0);
 }
 
 /*
@@ -2427,11 +2560,9 @@ private int
 parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line,
     size_t len)
 {
-	struct magic *m = &me->mp[0];
-
 	return parse_extra(ms, me, line, len,
 	    CAST(off_t, offsetof(struct magic, ext)),
-	    sizeof(m->ext), "EXTENSION", ",!+-/@?_$&", 0); /* & for b&w */
+	    sizeof(me->mp[0].ext), "EXTENSION", ",!+-/@?_$&", 0); /* & for b&w */
 }
 
 /*
@@ -2442,11 +2573,9 @@ private int
 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line,
     size_t len)
 {
-	struct magic *m = &me->mp[0];
-
 	return parse_extra(ms, me, line, len,
 	    CAST(off_t, offsetof(struct magic, mimetype)),
-	    sizeof(m->mimetype), "MIME", "+-/.$?:{}", 1);
+	    sizeof(me->mp[0].mimetype), "MIME", "+-/.$?:{}", 1);
 }
 
 private int
@@ -2485,6 +2614,7 @@ check_format_type(const char *ptr, int type, const char **estr)
 				h = 0;
 				break;
 			default:
+				fprintf(stderr, "Bad number format %d", type);
 				abort();
 			}
 		} else
@@ -2627,6 +2757,7 @@ check_format_type(const char *ptr, int type, const char **estr)
 
 	default:
 		/* internal error */
+		fprintf(stderr, "Bad file format %d", type);
 		abort();
 	}
 invalid:
@@ -2712,6 +2843,7 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
 	case FILE_NAME:
 	case FILE_USE:
 	case FILE_DER:
+	case FILE_OCTAL:
 		*p = getstr(ms, m, *p, action == FILE_COMPILE);
 		if (*p == NULL) {
 			if (ms->flags & MAGIC_CHECK)
@@ -2721,12 +2853,11 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
 		}
 		if (m->type == FILE_REGEX) {
 			file_regex_t rx;
-			int rc = file_regcomp(&rx, m->value.s, REG_EXTENDED);
-			if (rc) {
-				if (ms->flags & MAGIC_CHECK)
-					file_regerror(&rx, rc, ms);
+			int rc = file_regcomp(ms, &rx, m->value.s,
+			    REG_EXTENDED);
+			if (rc == 0) {
+				file_regfree(&rx);
 			}
-			file_regfree(&rx);
 			return rc ? -1 : 0;
 		}
 		return 0;
@@ -2796,6 +2927,7 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
 				x = 0;
 				break;
 			default:
+				fprintf(stderr, "Bad width %zu", ts);
 				abort();
 			}
 			if (x) {
@@ -2828,6 +2960,7 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
 	char	*pmax = p + plen - 1;
 	int	c;
 	int	val;
+	size_t	bracket_nesting = 0;
 
 	while ((c = *s++) != '\0') {
 		if (isspace(CAST(unsigned char, c)))
@@ -2836,135 +2969,149 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
 			file_error(ms, 0, "string too long: `%s'", origs);
 			return NULL;
 		}
-		if (c == '\\') {
-			switch(c = *s++) {
-
-			case '\0':
-				if (warn)
-					file_magwarn(ms, "incomplete escape");
-				s--;
-				goto out;
-
-			case '\t':
-				if (warn) {
-					file_magwarn(ms,
-					    "escaped tab found, use \\t instead");
-					warn = 0;	/* already did */
-				}
-				/*FALLTHROUGH*/
-			default:
-				if (warn) {
-					if (isprint(CAST(unsigned char, c))) {
-						/* Allow escaping of
-						 * ``relations'' */
-						if (strchr("<>&^=!", c) == NULL
-						    && (m->type != FILE_REGEX ||
-						    strchr("[]().*?^$|{}", c)
-						    == NULL)) {
-							file_magwarn(ms, "no "
-							    "need to escape "
-							    "`%c'", c);
-						}
-					} else {
-						file_magwarn(ms,
-						    "unknown escape sequence: "
-						    "\\%03o", c);
+		if (c != '\\') {
+		    if (c == '[') {
+			    bracket_nesting++;
+		    }
+		    if (c == ']' && bracket_nesting > 0) {
+			    bracket_nesting--;
+		    }
+		    *p++ = CAST(char, c);
+		    continue;
+		}
+		switch(c = *s++) {
+
+		case '\0':
+			if (warn)
+				file_magwarn(ms, "incomplete escape");
+			s--;
+			goto out;
+		case '.':
+			if (m->type == FILE_REGEX &&
+			    bracket_nesting == 0 && warn) {
+				file_magwarn(ms, "escaped dot ('.') found, "
+				    "use \\\\. instead");
+			}
+			warn = 0; /* already did */
+			/*FALLTHROUGH*/
+		case '\t':
+			if (warn) {
+				file_magwarn(ms,
+				    "escaped tab found, use \\\\t instead");
+				warn = 0;	/* already did */
+			}
+			/*FALLTHROUGH*/
+		default:
+			if (warn) {
+				if (isprint(CAST(unsigned char, c))) {
+					/* Allow escaping of
+					 * ``relations'' */
+					if (strchr("<>&^=!", c) == NULL
+					    && (m->type != FILE_REGEX ||
+					    strchr("[]().*?^$|{}", c)
+					    == NULL)) {
+						file_magwarn(ms, "no "
+						    "need to escape "
+						    "`%c'", c);
 					}
+				} else {
+					file_magwarn(ms,
+					    "unknown escape sequence: "
+					    "\\%03o", c);
 				}
-				/*FALLTHROUGH*/
-			/* space, perhaps force people to use \040? */
-			case ' ':
+			}
+			/*FALLTHROUGH*/
+		/* space, perhaps force people to use \040? */
+		case ' ':
 #if 0
-			/*
-			 * Other things people escape, but shouldn't need to,
-			 * so we disallow them
-			 */
-			case '\'':
-			case '"':
-			case '?':
+		/*
+		 * Other things people escape, but shouldn't need to,
+		 * so we disallow them
+		 */
+		case '\'':
+		case '"':
+		case '?':
 #endif
-			/* Relations */
-			case '>':
-			case '<':
-			case '&':
-			case '^':
-			case '=':
-			case '!':
-			/* and baskslash itself */
-			case '\\':
-				*p++ = CAST(char, c);
-				break;
+		/* Relations */
+		case '>':
+		case '<':
+		case '&':
+		case '^':
+		case '=':
+		case '!':
+		/* and backslash itself */
+		case '\\':
+			*p++ = CAST(char, c);
+			break;
 
-			case 'a':
-				*p++ = '\a';
-				break;
+		case 'a':
+			*p++ = '\a';
+			break;
 
-			case 'b':
-				*p++ = '\b';
-				break;
+		case 'b':
+			*p++ = '\b';
+			break;
 
-			case 'f':
-				*p++ = '\f';
-				break;
+		case 'f':
+			*p++ = '\f';
+			break;
 
-			case 'n':
-				*p++ = '\n';
-				break;
+		case 'n':
+			*p++ = '\n';
+			break;
 
-			case 'r':
-				*p++ = '\r';
-				break;
+		case 'r':
+			*p++ = '\r';
+			break;
 
-			case 't':
-				*p++ = '\t';
-				break;
+		case 't':
+			*p++ = '\t';
+			break;
 
-			case 'v':
-				*p++ = '\v';
-				break;
+		case 'v':
+			*p++ = '\v';
+			break;
 
-			/* \ and up to 3 octal digits */
-			case '0':
-			case '1':
-			case '2':
-			case '3':
-			case '4':
-			case '5':
-			case '6':
-			case '7':
-				val = c - '0';
-				c = *s++;  /* try for 2 */
-				if (c >= '0' && c <= '7') {
-					val = (val << 3) | (c - '0');
-					c = *s++;  /* try for 3 */
-					if (c >= '0' && c <= '7')
-						val = (val << 3) | (c-'0');
-					else
-						--s;
-				}
+		/* \ and up to 3 octal digits */
+		case '0':
+		case '1':
+		case '2':
+		case '3':
+		case '4':
+		case '5':
+		case '6':
+		case '7':
+			val = c - '0';
+			c = *s++;  /* try for 2 */
+			if (c >= '0' && c <= '7') {
+				val = (val << 3) | (c - '0');
+				c = *s++;  /* try for 3 */
+				if (c >= '0' && c <= '7')
+					val = (val << 3) | (c-'0');
 				else
 					--s;
-				*p++ = CAST(char, val);
-				break;
+			}
+			else
+				--s;
+			*p++ = CAST(char, val);
+			break;
 
-			/* \x and up to 2 hex digits */
-			case 'x':
-				val = 'x';	/* Default if no digits */
-				c = hextoint(*s++);	/* Get next char */
-				if (c >= 0) {
-					val = c;
-					c = hextoint(*s++);
-					if (c >= 0)
-						val = (val << 4) + c;
-					else
-						--s;
-				} else
+		/* \x and up to 2 hex digits */
+		case 'x':
+			val = 'x';	/* Default if no digits */
+			c = hextoint(*s++);	/* Get next char */
+			if (c >= 0) {
+				val = c;
+				c = hextoint(*s++);
+				if (c >= 0)
+					val = (val << 4) + c;
+				else
 					--s;
-				*p++ = CAST(char, val);
-				break;
-			}
-		} else
-			*p++ = CAST(char, c);
+			} else
+				--s;
+			*p++ = CAST(char, val);
+			break;
+		}
 	}
 	--s;
 out:
@@ -3355,6 +3502,7 @@ byteswap(struct magic *magic, uint32_t nmagic)
 		bs1(&magic[i]);
 }
 
+#if !defined(HAVE_BYTESWAP_H) && !defined(HAVE_SYS_BSWAP_H)
 /*
  * swap a short
  */
@@ -3394,7 +3542,7 @@ swap8(uint64_t sv)
 	uint64_t rv;
 	uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
 	uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
-#if 0
+# if 0
 	d[0] = s[3];
 	d[1] = s[2];
 	d[2] = s[1];
@@ -3403,7 +3551,7 @@ swap8(uint64_t sv)
 	d[5] = s[6];
 	d[6] = s[5];
 	d[7] = s[4];
-#else
+# else
 	d[0] = s[7];
 	d[1] = s[6];
 	d[2] = s[5];
@@ -3412,9 +3560,10 @@ swap8(uint64_t sv)
 	d[5] = s[2];
 	d[6] = s[1];
 	d[7] = s[0];
-#endif
+# endif
 	return rv;
 }
+#endif
 
 protected uintmax_t 
 file_varint2uintmax_t(const unsigned char *us, int t, size_t *l)
@@ -3548,13 +3697,13 @@ file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
 
 	for (ml = mlist->next; ml != mlist; ml = ml->next) {
 		struct magic *ma = ml->magic;
-		uint32_t nma = ml->nmagic;
-		for (i = 0; i < nma; i++) {
+		for (i = 0; i < ml->nmagic; i++) {
 			if (ma[i].type != FILE_NAME)
 				continue;
 			if (strcmp(ma[i].value.s, name) == 0) {
 				v->magic = &ma[i];
-				for (j = i + 1; j < nma; j++)
+				v->magic_rxcomp = &(ml->magic_rxcomp[i]);
+				for (j = i + 1; j < ml->nmagic; j++)
 				    if (ma[j].cont_level == 0)
 					    break;
 				v->nmagic = j - i;

+ 3 - 3
src/ascmagic.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.109 2021/02/05 23:01:40 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.110 2021/12/06 15:33:00 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -273,8 +273,8 @@ file_ascmagic_with_encoding(struct magic_set *ms, const struct buffer *b,
 				goto done;
 
 		if (has_long_lines)
-			if (file_printf(ms, ", with very long lines (%zu)",
-			    has_long_lines) == -1)
+			if (file_printf(ms, ", with very long lines (%"
+			    SIZE_T_FORMAT "u)", has_long_lines) == -1)
 				goto done;
 
 		/*

+ 17 - 1
src/cdf.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.120 2021/09/24 13:59:19 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.121 2021/10/20 13:56:15 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -48,6 +48,12 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.120 2021/09/24 13:59:19 christos Exp $")
 #include <time.h>
 #include <ctype.h>
 #include <limits.h>
+#ifdef HAVE_BYTESWAP_H
+#include <byteswap.h>
+#endif
+#ifdef HAVE_SYS_BSWAP_H
+#include <sys/bswap.h>
+#endif
 
 #ifndef EFTYPE
 #define EFTYPE EINVAL
@@ -124,6 +130,15 @@ cdf_calloc(const char *file __attribute__((__unused__)),
 	return calloc(n, u);
 }
 
+#if defined(HAVE_BYTESWAP_H)
+# define _cdf_tole2(x)	bswap_16(x)
+# define _cdf_tole4(x)	bswap_32(x)
+# define _cdf_tole8(x)	bswap_64(x)
+#elif defined(HAVE_SYS_BSWAP_H)
+# define _cdf_tole2(x)	bswap16(x)
+# define _cdf_tole4(x)	bswap32(x)
+# define _cdf_tole8(x)	bswap64(x)
+#else
 /*
  * swap a short
  */
@@ -173,6 +188,7 @@ _cdf_tole8(uint64_t sv)
 	d[7] = s[0];
 	return rv;
 }
+#endif
 
 /*
  * grab a uint32_t from a possibly unaligned address, and return it in

+ 6 - 1
src/cdf_time.c

@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf_time.c,v 1.19 2019/03/12 20:43:05 christos Exp $")
+FILE_RCSID("@(#)$File: cdf_time.c,v 1.20 2021/12/06 15:33:00 christos Exp $")
 #endif
 
 #include <time.h>
@@ -171,8 +171,13 @@ cdf_ctime(const time_t *sec, char *buf)
 	char *ptr = ctime_r(sec, buf);
 	if (ptr != NULL)
 		return buf;
+#ifdef WIN32
+	(void)snprintf(buf, 26, "*Bad* 0x%16.16I64x\n",
+	    CAST(long long, *sec));
+#else
 	(void)snprintf(buf, 26, "*Bad* %#16.16" INT64_T_FORMAT "x\n",
 	    CAST(long long, *sec));
+#endif
 	return buf;
 }
 

+ 95 - 33
src/compress.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.129 2020/12/08 21:26:00 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.136 2022/09/13 16:08:34 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -43,6 +43,9 @@ FILE_RCSID("@(#)$File: compress.c,v 1.129 2020/12/08 21:26:00 christos Exp $")
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_SPAWN_H
+#include <spawn.h>
+#endif
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
@@ -51,7 +54,7 @@ FILE_RCSID("@(#)$File: compress.c,v 1.129 2020/12/08 21:26:00 christos Exp $")
 #ifndef HAVE_SIG_T
 typedef void (*sig_t)(int);
 #endif /* HAVE_SIG_T */
-#if !defined(__MINGW32__) && !defined(WIN32) && !defined(__MINGW64__)
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
 #ifdef HAVE_SYS_WAIT_H
@@ -449,7 +452,21 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
 	ssize_t r;
 	int tfd;
 
-	(void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof buf);
+#ifdef WIN32
+	const char *t;
+	buf[0] = '\0';
+	if ((t = getenv("TEMP")) != NULL)
+		(void)strlcpy(buf, t, sizeof(buf));
+	else if ((t = getenv("TMP")) != NULL)
+		(void)strlcpy(buf, t, sizeof(buf));
+	else if ((t = getenv("TMPDIR")) != NULL)
+		(void)strlcpy(buf, t, sizeof(buf));
+	if (buf[0] != '\0')
+		(void)strlcat(buf, "/", sizeof(buf));
+	(void)strlcat(buf, "file.XXXXXX", sizeof(buf));
+#else
+	(void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof(buf));
+#endif
 #ifndef HAVE_MKSTEMP
 	{
 		char *ptr = mktemp(buf);
@@ -718,16 +735,61 @@ closep(int *fd)
 		closefd(fd, i);
 }
 
-static int
-copydesc(int i, int fd)
+static void
+movedesc(void *v, int i, int fd)
 {
 	if (fd == i)
-		return 0; /* "no dup was necessary" */
+		return; /* "no dup was necessary" */
+#ifdef HAVE_POSIX_SPAWNP
+	posix_spawn_file_actions_t *fa = RCAST(posix_spawn_file_actions_t *, v);
+	posix_spawn_file_actions_adddup2(fa, fd, i);
+	posix_spawn_file_actions_addclose(fa, fd);
+#else
 	if (dup2(fd, i) == -1) {
 		DPRINTF("dup(%d, %d) failed (%s)\n", fd, i, strerror(errno));
 		exit(1);
 	}
-	return 1;
+	close(v ? fd : fd);
+#endif
+}
+
+static void
+closedesc(void *v, int fd)
+{
+#ifdef HAVE_POSIX_SPAWNP
+	posix_spawn_file_actions_t *fa = RCAST(posix_spawn_file_actions_t *, v);
+	posix_spawn_file_actions_addclose(fa, fd);
+#else
+	close(v ? fd : fd);
+#endif
+}
+
+static void
+handledesc(void *v, int fd, int fdp[3][2])
+{
+	if (fd != -1) {
+		(void) lseek(fd, CAST(off_t, 0), SEEK_SET);
+		movedesc(v, STDIN_FILENO, fd);
+	} else {
+		movedesc(v, STDIN_FILENO, fdp[STDIN_FILENO][0]);
+		if (fdp[STDIN_FILENO][1] > 2)
+		    closedesc(v, fdp[STDIN_FILENO][1]);
+	}
+
+	file_clear_closexec(STDIN_FILENO);
+
+///FIXME: if one of the fdp[i][j] is 0 or 1, this can bomb spectacularly
+	movedesc(v, STDOUT_FILENO, fdp[STDOUT_FILENO][1]);
+	if (fdp[STDOUT_FILENO][0] > 2)
+		closedesc(v, fdp[STDOUT_FILENO][0]);
+
+	file_clear_closexec(STDOUT_FILENO);
+
+	movedesc(v, STDERR_FILENO, fdp[STDERR_FILENO][1]);
+	if (fdp[STDERR_FILENO][0] > 2)
+		closedesc(v, fdp[STDERR_FILENO][0]);
+
+	file_clear_closexec(STDERR_FILENO);
 }
 
 static pid_t
@@ -817,6 +879,10 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
 	pid_t writepid = -1;
 	size_t i;
 	ssize_t r;
+	char *const *args;
+#ifdef HAVE_POSIX_SPAWNP
+	posix_spawn_file_actions_t fa;
+#endif
 
 	switch (method) {
 #ifdef BUILTIN_DECOMPRESS
@@ -867,6 +933,22 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
 		    strerror(errno));
 	}
 
+	args = RCAST(char *const *, RCAST(intptr_t, compr[method].argv));
+#ifdef HAVE_POSIX_SPAWNP
+	posix_spawn_file_actions_init(&fa);
+
+	handledesc(&fa, fd, fdp);
+
+	status = posix_spawnp(&pid, compr[method].argv[0], &fa, NULL,
+	    args, NULL);
+
+	posix_spawn_file_actions_destroy(&fa);
+
+	if (status == -1) {
+		return makeerror(newch, n, "Cannot posix_spawn `%s', %s",
+		    compr[method].argv[0], strerror(errno));
+	}
+#else
 	/* For processes with large mapped virtual sizes, vfork
 	 * may be _much_ faster (10-100 times) than fork.
 	 */
@@ -881,37 +963,14 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
 		 * in a way which confuses parent. In particular,
 		 * do not modify fdp[i][j].
 		 */
-		if (fd != -1) {
-			(void) lseek(fd, CAST(off_t, 0), SEEK_SET);
-			if (copydesc(STDIN_FILENO, fd))
-				(void) close(fd);
-		} else {
-			if (copydesc(STDIN_FILENO, fdp[STDIN_FILENO][0]))
-				(void) close(fdp[STDIN_FILENO][0]);
-			if (fdp[STDIN_FILENO][1] > 2)
-				(void) close(fdp[STDIN_FILENO][1]);
-		}
-		file_clear_closexec(STDIN_FILENO);
+		handledesc(NULL, fd, fdp);
 
-///FIXME: if one of the fdp[i][j] is 0 or 1, this can bomb spectacularly
-		if (copydesc(STDOUT_FILENO, fdp[STDOUT_FILENO][1]))
-			(void) close(fdp[STDOUT_FILENO][1]);
-		if (fdp[STDOUT_FILENO][0] > 2)
-			(void) close(fdp[STDOUT_FILENO][0]);
-		file_clear_closexec(STDOUT_FILENO);
-
-		if (copydesc(STDERR_FILENO, fdp[STDERR_FILENO][1]))
-			(void) close(fdp[STDERR_FILENO][1]);
-		if (fdp[STDERR_FILENO][0] > 2)
-			(void) close(fdp[STDERR_FILENO][0]);
-		file_clear_closexec(STDERR_FILENO);
-
-		(void)execvp(compr[method].argv[0],
-		    RCAST(char *const *, RCAST(intptr_t, compr[method].argv)));
+		(void)execvp(compr[method].argv[0], args);
 		dprintf(STDERR_FILENO, "exec `%s' failed, %s",
 		    compr[method].argv[0], strerror(errno));
 		_exit(1); /* _exit(), not exit(), because of vfork */
 	}
+#endif
 	/* parent */
 	/* Close write sides of child stdout/err pipes */
 	for (i = 1; i < __arraycount(fdp); i++)
@@ -930,7 +989,10 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
 		goto err;
 	}
 	rv = OKDATA;
+	errno = 0;
 	r = sread(fdp[STDOUT_FILENO][0], *newch, bytes_max, 0);
+	if (r == 0 && errno == 0)
+		goto ok;
 	if (r <= 0) {
 		DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0],
 		    r != -1 ? strerror(errno) : "no data");

+ 19 - 7
src/der.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: der.c,v 1.21 2020/06/15 00:58:10 christos Exp $")
+FILE_RCSID("@(#)$File: der.c,v 1.24 2022/07/30 18:08:36 christos Exp $")
 #endif
 #else
 #define SIZE_T_FORMAT "z"
@@ -235,6 +235,7 @@ der_tag(char *buf, size_t len, uint32_t tag)
 static int
 der_data(char *buf, size_t blen, uint32_t tag, const void *q, uint32_t len)
 {
+	uint32_t i;
 	const uint8_t *d = CAST(const uint8_t *, q);
 	switch (tag) {
 	case DER_TAG_PRINTABLE_STRING:
@@ -251,7 +252,7 @@ der_data(char *buf, size_t blen, uint32_t tag, const void *q, uint32_t len)
 		break;
 	}
 
-	for (uint32_t i = 0; i < len; i++) {
+	for (i = 0; i < len; i++) {
 		uint32_t z = i << 1;
 		if (z < blen - 2)
 			snprintf(buf + z, blen - z, "%.2x", d[i]);
@@ -283,7 +284,8 @@ der_offs(struct magic_set *ms, struct magic *m, size_t nbytes)
 	offs += ms->offset + m->offset;
 	DPRINTF(("cont_level = %d\n", m->cont_level));
 #ifdef DEBUG_DER
-	for (size_t i = 0; i < m->cont_level; i++)
+	size_t i;
+	for (i = 0; i < m->cont_level; i++)
 		printf("cont_level[%" SIZE_T_FORMAT "u] = %u\n", i,
 		    ms->c.li[i].off);
 #endif
@@ -329,21 +331,26 @@ der_cmp(struct magic_set *ms, struct magic *m)
 		    buf, s);
 	size_t slen = strlen(buf);
 
-	if (strncmp(buf, s, slen) != 0)
+	if (strncmp(buf, s, slen) != 0) {
+		DPRINTF(("%s: no string match %s != %s\n", __func__, buf, s));
 		return 0;
+	}
 
 	s += slen;
 
 again:
 	switch (*s) {
 	case '\0':
+		DPRINTF(("%s: EOF match\n", __func__));
 		return 1;
 	case '=':
 		s++;
 		goto val;
 	default:
-		if (!isdigit(CAST(unsigned char, *s)))
+		if (!isdigit(CAST(unsigned char, *s))) {
+			DPRINTF(("%s: no digit %c\n", __func__, *s));
 			return 0;
+		}
 
 		slen = 0;
 		do
@@ -352,8 +359,10 @@ again:
 		if ((ms->flags & MAGIC_DEBUG) != 0)
 			fprintf(stderr, "%s: len %" SIZE_T_FORMAT "u %u\n",
 			    __func__, slen, tlen);
-		if (tlen != slen)
+		if (tlen != slen) {
+			DPRINTF(("%s: len %u != %zu\n", __func__, tlen, slen));
 			return 0;
+		}
 		goto again;
 	}
 val:
@@ -362,9 +371,12 @@ val:
 	der_data(buf, sizeof(buf), tag, b + offs, tlen);
 	if ((ms->flags & MAGIC_DEBUG) != 0)
 		fprintf(stderr, "%s: data %s %s\n", __func__, buf, s);
-	if (strcmp(buf, s) != 0 && strcmp("x", s) != 0)
+	if (strcmp(buf, s) != 0 && strcmp("x", s) != 0) {
+		DPRINTF(("%s: no string match %s != %s\n", __func__, buf, s));
 		return 0;
+	}
 	strlcpy(ms->ms_value.s, buf, sizeof(ms->ms_value.s));
+	DPRINTF(("%s: complete match\n", __func__));
 	return 1;
 }
 #endif

+ 42 - 18
src/encoding.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: encoding.c,v 1.32 2021/04/27 19:37:14 christos Exp $")
+FILE_RCSID("@(#)$File: encoding.c,v 1.39 2022/09/13 18:46:07 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -80,7 +80,6 @@ file_encoding(struct magic_set *ms, const struct buffer *b,
 	size_t nbytes = b->flen;
 	size_t mlen;
 	int rv = 1, ucs_type;
-	unsigned char *nbuf = NULL;
 	file_unichar_t *udefbuf;
 	size_t udeflen;
 
@@ -103,13 +102,6 @@ file_encoding(struct magic_set *ms, const struct buffer *b,
 		file_oomem(ms, mlen);
 		goto done;
 	}
-	mlen = (nbytes + 1) * sizeof(nbuf[0]);
-	if ((nbuf = CAST(unsigned char *,
-	    calloc(CAST(size_t, 1), mlen))) == NULL) {
-		file_oomem(ms, mlen);
-		goto done;
-	}
-
 	if (looks_ascii(buf, nbytes, *ubuf, ulen)) {
 		if (looks_utf7(buf, nbytes, *ubuf, ulen) > 0) {
 			DPRINTF(("utf-7 %" SIZE_T_FORMAT "u\n", *ulen));
@@ -155,6 +147,13 @@ file_encoding(struct magic_set *ms, const struct buffer *b,
 		*code = "Non-ISO extended-ASCII";
 		*code_mime = "unknown-8bit";
 	} else {
+		unsigned char *nbuf;
+
+		mlen = (nbytes + 1) * sizeof(nbuf[0]);
+		if ((nbuf = CAST(unsigned char *, malloc(mlen))) == NULL) {
+			file_oomem(ms, mlen);
+			goto done;
+		}
 		from_ebcdic(buf, nbytes, nbuf);
 
 		if (looks_ascii(nbuf, nbytes, *ubuf, ulen)) {
@@ -171,10 +170,10 @@ file_encoding(struct magic_set *ms, const struct buffer *b,
 			rv = 0;
 			*type = "binary";
 		}
+		free(nbuf);
 	}
 
  done:
-	free(nbuf);
 	if (ubuf == &udefbuf)
 		free(udefbuf);
 
@@ -458,11 +457,16 @@ looks_utf7(const unsigned char *buf, size_t nbytes, file_unichar_t *ubuf,
 		return -1;
 }
 
+#define UCS16_NOCHAR(c) ((c) >= 0xfdd0 && (c) <= 0xfdef)
+#define UCS16_HISURR(c) ((c) >= 0xd800 && (c) <= 0xdbff)
+#define UCS16_LOSURR(c) ((c) >= 0xdc00 && (c) <= 0xdfff)
+
 private int
 looks_ucs16(const unsigned char *bf, size_t nbytes, file_unichar_t *ubf,
     size_t *ulen)
 {
 	int bigend;
+	uint32_t hi;
 	size_t i;
 
 	if (nbytes < 2)
@@ -476,21 +480,41 @@ looks_ucs16(const unsigned char *bf, size_t nbytes, file_unichar_t *ubf,
 		return 0;
 
 	*ulen = 0;
+	hi = 0;
 
 	for (i = 2; i + 1 < nbytes; i += 2) {
-		/* XXX fix to properly handle chars > 65536 */
+		uint32_t uc;
 
 		if (bigend)
-			ubf[(*ulen)++] = bf[i + 1]
-			    | (CAST(file_unichar_t, bf[i]) << 8);
+			uc = CAST(uint32_t,
+			    bf[i + 1] | (CAST(file_unichar_t, bf[i]) << 8));
 		else
-			ubf[(*ulen)++] = bf[i]
-			    | (CAST(file_unichar_t, bf[i + 1]) << 8);
+			uc = CAST(uint32_t,
+			    bf[i] | (CAST(file_unichar_t, bf[i + 1]) << 8));
 
-		if (ubf[*ulen - 1] == 0xfffe)
+		uc &= 0xffff;
+
+		switch (uc) {
+		case 0xfffe:
+		case 0xffff:
 			return 0;
-		if (ubf[*ulen - 1] < 128 &&
-		    text_chars[CAST(size_t, ubf[*ulen - 1])] != T)
+		default:
+			if (UCS16_NOCHAR(uc))
+				return 0;
+			break;
+		}
+		if (hi) {
+			if (!UCS16_LOSURR(uc))
+				return 0;
+			uc = 0x10000 + 0x400 * (hi - 1) + (uc - 0xdc00);
+			hi = 0;
+		}
+		if (uc < 128 && text_chars[CAST(size_t, uc)] != T)
+			return 0;
+		ubf[(*ulen)++] = uc;
+		if (UCS16_HISURR(uc))
+			hi = uc - 0xd800 + 1;
+		if (UCS16_LOSURR(uc))
 			return 0;
 	}
 

+ 144 - 61
src/file.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: file.c,v 1.190 2021/09/24 14:14:26 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.204 2022/09/13 18:46:07 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -57,6 +57,15 @@ FILE_RCSID("@(#)$File: file.c,v 1.190 2021/09/24 14:14:26 christos Exp $")
 #ifdef HAVE_WCHAR_H
 #include <wchar.h>
 #endif
+#ifdef HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
+#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) && \
+   defined(HAVE_WCTYPE_H)
+#define FILE_WIDE_SUPPORT
+#else
+#include <ctype.h>
+#endif
 
 #if defined(HAVE_GETOPT_H) && defined(HAVE_STRUCT_OPTION)
 # include <getopt.h>
@@ -182,7 +191,7 @@ int
 main(int argc, char *argv[])
 {
 	int c;
-	size_t i;
+	size_t i, j, wid, nw;
 	int action = 0, didsomefiles = 0, errflg = 0;
 	int flags = 0, e = 0;
 #ifdef HAVE_LIBSECCOMP
@@ -408,27 +417,30 @@ main(int argc, char *argv[])
 	if (optind == argc) {
 		if (!didsomefiles)
 			usage();
+		goto out;
 	}
-	else {
-		size_t j, wid, nw;
-		for (wid = 0, j = CAST(size_t, optind); j < CAST(size_t, argc);
-		    j++) {
-			nw = file_mbswidth(argv[j]);
-			if (nw > wid)
-				wid = nw;
-		}
-		/*
-		 * If bflag is only set twice, set it depending on
-		 * number of files [this is undocumented, and subject to change]
-		 */
-		if (bflag == 2) {
-			bflag = optind >= argc - 1;
-		}
-		for (; optind < argc; optind++)
-			e |= process(magic, argv[optind], wid);
+
+	for (wid = 0, j = CAST(size_t, optind); j < CAST(size_t, argc);
+	    j++) {
+		nw = file_mbswidth(magic, argv[j]);
+		if (nw > wid)
+			wid = nw;
 	}
 
+	/*
+	 * If bflag is only set twice, set it depending on
+	 * number of files [this is undocumented, and subject to change]
+	 */
+	if (bflag == 2) {
+		bflag = optind >= argc - 1;
+	}
+	for (; optind < argc; optind++)
+		e |= process(magic, argv[optind], wid);
+
 out:
+	if (!nobuffer)
+		e |= fflush(stdout) != 0;
+
 	if (magic)
 		magic_close(magic);
 	return e;
@@ -453,7 +465,7 @@ setparam(const char *p)
 	size_t i;
 	char *s;
 
-	if ((s = strchr(p, '=')) == NULL)
+	if ((s = CCAST(char *, strchr(p, '='))) == NULL)
 		goto badparm;
 
 	for (i = 0; i < __arraycount(pm); i++) {
@@ -500,38 +512,104 @@ unwrap(struct magic_set *ms, const char *fn)
 	size_t llen = 0;
 	int wid = 0, cwid;
 	int e = 0;
+	size_t fi = 0, fimax = 100;
+	char **flist = CAST(char **, malloc(sizeof(*flist) * fimax));
 
-	if (strcmp("-", fn) == 0) {
+	if (flist == NULL)
+out:		file_err(EXIT_FAILURE, "Cannot allocate memory for file list");
+
+	if (strcmp("-", fn) == 0)
 		f = stdin;
-		wid = 1;
-	} else {
+	else {
 		if ((f = fopen(fn, "r")) == NULL) {
 			file_warn("Cannot open `%s'", fn);
 			return 1;
 		}
-
-		while ((len = getline(&line, &llen, f)) > 0) {
-			if (line[len - 1] == '\n')
-				line[len - 1] = '\0';
-			cwid = file_mbswidth(line);
-			if (cwid > wid)
-				wid = cwid;
-		}
-
-		rewind(f);
 	}
 
 	while ((len = getline(&line, &llen, f)) > 0) {
 		if (line[len - 1] == '\n')
 			line[len - 1] = '\0';
-		e |= process(ms, line, wid);
+		if (fi >= fimax) {
+			fimax += 100;
+			char **nf = CAST(char **,
+			    realloc(flist, fimax * sizeof(*flist)));
+			if (nf == NULL)
+				goto out;
+			flist = nf;
+		}
+		flist[fi++] = line;
+		cwid = file_mbswidth(ms, line);
+		if (cwid > wid)
+			wid = cwid;
+		line = NULL;
+		llen = 0;
 	}
 
-	free(line);
-	(void)fclose(f);
+	fimax = fi;
+	for (fi = 0; fi < fimax; fi++) {
+		e |= process(ms, flist[fi], wid);
+		free(flist[fi]);
+	}
+	free(flist);
+
+	if (f != stdin)
+		(void)fclose(f);
 	return e;
 }
 
+private void
+file_octal(unsigned char c)
+{
+	putc('\\', stdout);
+	putc(((c >> 6) & 7) + '0', stdout);
+	putc(((c >> 3) & 7) + '0', stdout);
+	putc(((c >> 0) & 7) + '0', stdout);
+}
+
+private void
+fname_print(const char *inname)
+{
+	size_t n = strlen(inname);
+#ifdef FILE_WIDE_SUPPORT
+	mbstate_t state;
+	wchar_t nextchar;
+	size_t bytesconsumed;
+
+
+	(void)memset(&state, 0, sizeof(state));
+	while (n > 0) {
+		bytesconsumed = mbrtowc(&nextchar, inname, n, &state);
+		if (bytesconsumed == CAST(size_t, -1) ||
+		    bytesconsumed == CAST(size_t, -2))  {
+			nextchar = *inname++;
+			n--;
+			(void)memset(&state, 0, sizeof(state));
+			file_octal(CAST(unsigned char, nextchar));
+			continue;
+		}
+		inname += bytesconsumed;
+		n -= bytesconsumed;
+		if (iswprint(nextchar)) {
+			printf("%lc", nextchar);
+			continue;
+		}
+		/* XXX: What if it is > 255? */
+		file_octal(CAST(unsigned char, nextchar));
+	}
+#else
+	size_t i;
+	for (i = 0; i < n; i++) {
+		unsigned char c = CAST(unsigned char, inname[i]);
+		if (isprint(c)) {
+			putc(c);
+			continue;
+		}
+		file_octal(c);
+	}
+#endif
+}
+
 /*
  * Called for each input file on the command line (or in a list of files)
  */
@@ -540,65 +618,70 @@ process(struct magic_set *ms, const char *inname, int wid)
 {
 	const char *type, c = nulsep > 1 ? '\0' : '\n';
 	int std_in = strcmp(inname, "-") == 0;
+	int haderror = 0;
 
 	if (wid > 0 && !bflag) {
-		(void)printf("%s", std_in ? "/dev/stdin" : inname);
+		const char *pname = std_in ? "/dev/stdin" : inname;
+		if ((ms->flags & MAGIC_RAW) == 0)
+			fname_print(pname);
+		else
+			(void)printf("%s", pname);
 		if (nulsep)
 			(void)putc('\0', stdout);
 		if (nulsep < 2) {
 			(void)printf("%s", separator);
 			(void)printf("%*s ", CAST(int, nopad ? 0
-			    : (wid - file_mbswidth(inname))), "");
+			    : (wid - file_mbswidth(ms, inname))), "");
 		}
 	}
 
 	type = magic_file(ms, std_in ? NULL : inname);
 
 	if (type == NULL) {
-		(void)printf("ERROR: %s%c", magic_error(ms), c);
+		haderror |= printf("ERROR: %s%c", magic_error(ms), c);
 	} else {
-		(void)printf("%s%c", type, c);
+		haderror |= printf("%s%c", type, c) < 0;
 	}
 	if (nobuffer)
-		(void)fflush(stdout);
-	return type == NULL;
+		haderror |= fflush(stdout) != 0;
+	return haderror || type == NULL;
 }
 
 protected size_t
-file_mbswidth(const char *s)
+file_mbswidth(struct magic_set *ms, const char *s)
 {
-#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
-	size_t bytesconsumed, old_n, n, width = 0;
+	size_t width = 0;
+#ifdef FILE_WIDE_SUPPORT
+	size_t bytesconsumed, n;
 	mbstate_t state;
 	wchar_t nextchar;
-	(void)memset(&state, 0, sizeof(mbstate_t));
-	old_n = n = strlen(s);
+
+	(void)memset(&state, 0, sizeof(state));
+	n = strlen(s);
 
 	while (n > 0) {
 		bytesconsumed = mbrtowc(&nextchar, s, n, &state);
 		if (bytesconsumed == CAST(size_t, -1) ||
 		    bytesconsumed == CAST(size_t, -2)) {
-			/* Something went wrong, return something reasonable */
-			return old_n;
-		}
-		if (s[0] == '\n') {
-			/*
-			 * do what strlen() would do, so that caller
-			 * is always right
-			 */
-			width++;
+			nextchar = *s;
+			bytesconsumed = 1;
+			(void)memset(&state, 0, sizeof(state));
+			width += 4;
 		} else {
 			int w = wcwidth(nextchar);
-			if (w > 0)
-				width += w;
+			width += ((ms->flags & MAGIC_RAW) != 0
+			    || iswprint(nextchar)) ? (w > 0 ? w : 1) : 4;
 		}
 
 		s += bytesconsumed, n -= bytesconsumed;
 	}
-	return width;
 #else
-	return strlen(s);
+	for (; *s; s++) {
+		width += (ms->flags & MAGIC_RAW) != 0
+		    || isprint(CAST(unsigned char, *s)) ? 1 : 4;
+	}
 #endif
+	return width;
 }
 
 private void
@@ -626,7 +709,7 @@ docprint(const char *opts, int def)
 	int comma, pad;
 	char *sp, *p;
 
-	p = strchr(opts, '%');
+	p = CCAST(char *, strchr(opts, '%'));
 	if (p == NULL) {
 		fprintf(stdout, "%s", opts);
 		defprint(def);

+ 90 - 81
src/file.h

@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.227 2021/06/30 10:08:48 christos Exp $
+ * @(#)$File: file.h,v 1.237 2022/09/10 13:21:42 christos Exp $
  */
 
 #ifndef __file_h__
@@ -88,6 +88,10 @@
 /* Do this here and now, because struct stat gets re-defined on solaris */
 #include <sys/stat.h>
 #include <stdarg.h>
+#include <locale.h>
+#if defined(HAVE_XLOCALE_H)
+#include <xlocale.h>
+#endif
 
 #define ENABLE_CONDITIONALS
 
@@ -157,7 +161,7 @@
 #define MAXstring 128		/* max len of "string" types */
 
 #define MAGICNO		0xF11E041C
-#define VERSIONNO	16
+#define VERSIONNO	18
 #define FILE_MAGICSIZE	376
 
 #define FILE_GUID_SIZE	sizeof("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
@@ -167,6 +171,8 @@
 #define FILE_COMPILE	2
 #define FILE_LIST	3
 
+typedef regex_t file_regex_t;
+
 struct buffer {
 	int fd;
 	struct stat st;
@@ -213,60 +219,67 @@ struct magic {
 	uint8_t vallen;		/* length of string value, if any */
 	uint8_t type;		/* comparison type (FILE_*) */
 	uint8_t in_type;	/* type of indirection */
-#define 			FILE_INVALID	0
-#define 			FILE_BYTE	1
-#define				FILE_SHORT	2
-#define				FILE_DEFAULT	3
-#define				FILE_LONG	4
-#define				FILE_STRING	5
-#define				FILE_DATE	6
-#define				FILE_BESHORT	7
-#define				FILE_BELONG	8
-#define				FILE_BEDATE	9
-#define				FILE_LESHORT	10
-#define				FILE_LELONG	11
-#define				FILE_LEDATE	12
-#define				FILE_PSTRING	13
-#define				FILE_LDATE	14
-#define				FILE_BELDATE	15
-#define				FILE_LELDATE	16
-#define				FILE_REGEX	17
-#define				FILE_BESTRING16	18
-#define				FILE_LESTRING16	19
-#define				FILE_SEARCH	20
-#define				FILE_MEDATE	21
-#define				FILE_MELDATE	22
-#define				FILE_MELONG	23
-#define				FILE_QUAD	24
-#define				FILE_LEQUAD	25
-#define				FILE_BEQUAD	26
-#define				FILE_QDATE	27
-#define				FILE_LEQDATE	28
-#define				FILE_BEQDATE	29
-#define				FILE_QLDATE	30
-#define				FILE_LEQLDATE	31
-#define				FILE_BEQLDATE	32
-#define				FILE_FLOAT	33
-#define				FILE_BEFLOAT	34
-#define				FILE_LEFLOAT	35
-#define				FILE_DOUBLE	36
-#define				FILE_BEDOUBLE	37
-#define				FILE_LEDOUBLE	38
-#define				FILE_BEID3	39
-#define				FILE_LEID3	40
-#define				FILE_INDIRECT	41
-#define				FILE_QWDATE	42
-#define				FILE_LEQWDATE	43
-#define				FILE_BEQWDATE	44
-#define				FILE_NAME	45
-#define				FILE_USE	46
-#define				FILE_CLEAR	47
-#define				FILE_DER	48
-#define				FILE_GUID	49
-#define				FILE_OFFSET	50
-#define				FILE_BEVARINT	51
-#define				FILE_LEVARINT	52
-#define				FILE_NAMES_SIZE	53 /* size of array to contain all names */
+#define 			FILE_INVALID		0
+#define 			FILE_BYTE		1
+#define				FILE_SHORT		2
+#define				FILE_DEFAULT		3
+#define				FILE_LONG		4
+#define				FILE_STRING		5
+#define				FILE_DATE		6
+#define				FILE_BESHORT		7
+#define				FILE_BELONG		8
+#define				FILE_BEDATE		9
+#define				FILE_LESHORT		10
+#define				FILE_LELONG		11
+#define				FILE_LEDATE		12
+#define				FILE_PSTRING		13
+#define				FILE_LDATE		14
+#define				FILE_BELDATE		15
+#define				FILE_LELDATE		16
+#define				FILE_REGEX		17
+#define				FILE_BESTRING16		18
+#define				FILE_LESTRING16		19
+#define				FILE_SEARCH		20
+#define				FILE_MEDATE		21
+#define				FILE_MELDATE		22
+#define				FILE_MELONG		23
+#define				FILE_QUAD		24
+#define				FILE_LEQUAD		25
+#define				FILE_BEQUAD		26
+#define				FILE_QDATE		27
+#define				FILE_LEQDATE		28
+#define				FILE_BEQDATE		29
+#define				FILE_QLDATE		30
+#define				FILE_LEQLDATE		31
+#define				FILE_BEQLDATE		32
+#define				FILE_FLOAT		33
+#define				FILE_BEFLOAT		34
+#define				FILE_LEFLOAT		35
+#define				FILE_DOUBLE		36
+#define				FILE_BEDOUBLE		37
+#define				FILE_LEDOUBLE		38
+#define				FILE_BEID3		39
+#define				FILE_LEID3		40
+#define				FILE_INDIRECT		41
+#define				FILE_QWDATE		42
+#define				FILE_LEQWDATE		43
+#define				FILE_BEQWDATE		44
+#define				FILE_NAME		45
+#define				FILE_USE		46
+#define				FILE_CLEAR		47
+#define				FILE_DER		48
+#define				FILE_GUID		49
+#define				FILE_OFFSET		50
+#define				FILE_BEVARINT		51
+#define				FILE_LEVARINT		52
+#define				FILE_MSDOSDATE		53
+#define				FILE_LEMSDOSDATE	54
+#define				FILE_BEMSDOSDATE	55
+#define				FILE_MSDOSTIME		56
+#define				FILE_LEMSDOSTIME	57
+#define				FILE_BEMSDOSTIME	58
+#define				FILE_OCTAL		59
+#define				FILE_NAMES_SIZE		60 /* size of array to contain all names */
 
 #define IS_STRING(t) \
 	((t) == FILE_STRING || \
@@ -277,7 +290,8 @@ struct magic {
 	 (t) == FILE_SEARCH || \
 	 (t) == FILE_INDIRECT || \
 	 (t) == FILE_NAME || \
-	 (t) == FILE_USE)
+	 (t) == FILE_USE || \
+	 (t) == FILE_OCTAL)
 
 #define FILE_FMT_NONE 0
 #define FILE_FMT_NUM  1 /* "cduxXi" */
@@ -398,7 +412,8 @@ struct magic {
 /* list of magic entries */
 struct mlist {
 	struct magic *magic;		/* array of magic entries */
-	uint32_t nmagic;		/* number of entries in array */
+	file_regex_t **magic_rxcomp;	/* array of compiled regexps */
+	size_t nmagic;			/* number of entries in array */
 	void *map;			/* internal resources used by entry */
 	struct mlist *next, *prev;
 };
@@ -477,6 +492,13 @@ struct magic_set {
 #define	FILE_NAME_MAX			50
 #define	FILE_REGEX_MAX			8192
 #define	FILE_ENCODING_MAX		(64 * 1024)
+#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
+#define USE_C_LOCALE
+	locale_t c_lc_ctype;
+#define file_locale_used
+#else
+#define file_locale_used __attribute__((__unused__))
+#endif
 };
 
 /* Type for Unicode characters */
@@ -485,9 +507,12 @@ typedef unsigned long file_unichar_t;
 struct stat;
 #define FILE_T_LOCAL	1
 #define FILE_T_WINDOWS	2
-protected const char *file_fmttime(char *, size_t, uint64_t, int);
-protected const char *file_fmtvarint(const unsigned char *, int, char *,
-    size_t);
+protected const char *file_fmtdatetime(char *, size_t, uint64_t, int);
+protected const char *file_fmtdate(char *, size_t, uint16_t);
+protected const char *file_fmttime(char *, size_t, uint16_t);
+protected const char *file_fmtvarint(char *, size_t, const unsigned char *,
+    int);
+protected const char *file_fmtnum(char *, size_t, const char *, int);
 protected struct magic_set *file_ms_alloc(int);
 protected void file_ms_free(struct magic_set *);
 protected int file_default(struct magic_set *, size_t);
@@ -543,7 +568,7 @@ protected void file_magwarn(struct magic_set *, const char *, ...)
     __attribute__((__format__(__printf__, 2, 3)));
 protected void file_mdump(struct magic *);
 protected void file_showstr(FILE *, const char *, size_t);
-protected size_t file_mbswidth(const char *);
+protected size_t file_mbswidth(struct magic_set *, const char *);
 protected const char *file_getbuffer(struct magic_set *);
 protected ssize_t sread(int, void *, size_t, int);
 protected int file_check_mem(struct magic_set *, unsigned int);
@@ -568,29 +593,13 @@ protected void buffer_init(struct buffer *, int, const struct stat *,
 protected void buffer_fini(struct buffer *);
 protected int buffer_fill(const struct buffer *);
 
-#include <locale.h>
-#if defined(HAVE_XLOCALE_H)
-#include <xlocale.h>
-#endif
 
-typedef struct {
-	const char *pat;
-#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
-#define USE_C_LOCALE
-	locale_t old_lc_ctype;
-	locale_t c_lc_ctype;
-#else
-	char *old_lc_ctype;
-#endif
-	int rc;
-	regex_t rx;
-} file_regex_t;
 
-protected int file_regcomp(file_regex_t *, const char *, int);
-protected int file_regexec(file_regex_t *, const char *, size_t, regmatch_t *,
+protected int file_regcomp(struct magic_set *, file_regex_t *, const char *,
     int);
+protected int file_regexec(struct magic_set *, file_regex_t *, const char *,
+    size_t, regmatch_t *, int);
 protected void file_regfree(file_regex_t *);
-protected void file_regerror(file_regex_t *, int, struct magic_set *);
 
 typedef struct {
 	char *buf;

+ 1 - 1
src/file_opts.h

@@ -4,7 +4,7 @@
  * The first column specifies the short name, if any, or 0 if none.
  * The second column specifies the long name.
  * The third column specifies whether it takes a parameter.
- * The fourth columns specifies whether is is marked as "default"
+ * The fourth column specifies whether is marked as "default"
  *      if POSIXLY_CORRECT is defined: 1,
  *      if POSIXLY_CORRECT is not defined: 2.
  * The fifth column is the documentation.

+ 3 - 0
src/fmtcheck.c

@@ -29,6 +29,9 @@
  */
 
 #include "file.h"
+#ifndef lint
+FILE_RCSID("@(#)$File: fmtcheck.c,v 1.4 2022/09/13 18:46:07 christos Exp $")
+#endif /* lint */
 
 #include <stdio.h>
 #include <string.h>

+ 2 - 2
src/fsmagic.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.81 2019/07/16 13:30:32 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.82 2022/04/11 18:14:41 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -327,7 +327,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
 			char *tmp;
 			char buf2[BUFSIZ+BUFSIZ+4];
 
-			if ((tmp = strrchr(fn,  '/')) == NULL) {
+			if ((tmp = CCAST(char *, strrchr(fn,  '/'))) == NULL) {
 				tmp = buf; /* in current directory anyway */
 			} else {
 				if (tmp - fn + 1 > BUFSIZ) {

+ 81 - 44
src/funcs.c

@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.122 2021/06/30 10:08:48 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.131 2022/09/13 18:46:07 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -54,9 +54,12 @@ FILE_RCSID("@(#)$File: funcs.c,v 1.122 2021/06/30 10:08:48 christos Exp $")
 protected char *
 file_copystr(char *buf, size_t blen, size_t width, const char *str)
 {
-	if (++width > blen)
-		width = blen;
-	strlcpy(buf, str, width);
+	if (blen == 0)
+		return buf;
+	if (width >= blen)
+		width = blen - 1;
+	memcpy(buf, str, width);
+	buf[width] = '\0';
 	return buf;
 }
 
@@ -90,7 +93,8 @@ file_checkfield(char *msg, size_t mlen, const char *what, const char **pp)
 protected int
 file_checkfmt(char *msg, size_t mlen, const char *fmt)
 {
-	for (const char *p = fmt; *p; p++) {
+	const char *p;
+	for (p = fmt; *p; p++) {
 		if (*p != '%')
 			continue;
 		if (*++p == '%')
@@ -146,8 +150,8 @@ file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
 		size_t blen = ms->o.blen;
 		free(buf);
 		file_clearbuf(ms);
-		file_error(ms, 0, "Output buffer space exceeded %d+%zu", len,
-		    blen);
+		file_error(ms, 0, "Output buffer space exceeded %d+%"
+		    SIZE_T_FORMAT "u", len, blen);
 		return -1;
 	}
 
@@ -634,13 +638,11 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
 	file_regex_t rx;
 	int rc, rv = -1;
 
-	rc = file_regcomp(&rx, pat, REG_EXTENDED);
-	if (rc) {
-		file_regerror(&rx, rc, ms);
-	} else {
+	rc = file_regcomp(ms, &rx, pat, REG_EXTENDED);
+	if (rc == 0) {
 		regmatch_t rm;
 		int nm = 0;
-		while (file_regexec(&rx, ms->o.buf, 1, &rm, 0) == 0) {
+		while (file_regexec(ms, &rx, ms->o.buf, 1, &rm, 0) == 0) {
 			ms->o.buf[rm.rm_so] = '\0';
 			if (file_printf(ms, "%s%s", rep,
 			    rm.rm_eo != 0 ? ms->o.buf + rm.rm_eo : "") == -1)
@@ -655,58 +657,65 @@ out:
 }
 
 protected int
-file_regcomp(file_regex_t *rx, const char *pat, int flags)
+file_regcomp(struct magic_set *ms file_locale_used, file_regex_t *rx,
+    const char *pat, int flags)
 {
 #ifdef USE_C_LOCALE
-	rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
-	assert(rx->c_lc_ctype != NULL);
-	rx->old_lc_ctype = uselocale(rx->c_lc_ctype);
-	assert(rx->old_lc_ctype != NULL);
+	locale_t old = uselocale(ms->c_lc_ctype);
+	assert(old != NULL);
 #else
-	rx->old_lc_ctype = setlocale(LC_CTYPE, NULL);
-	assert(rx->old_lc_ctype != NULL);
-	rx->old_lc_ctype = strdup(rx->old_lc_ctype);
-	assert(rx->old_lc_ctype != NULL);
+	char old[1024];
+	strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old));
 	(void)setlocale(LC_CTYPE, "C");
 #endif
-	rx->pat = pat;
+	int rc;
+	rc = regcomp(rx, pat, flags);
 
-	return rx->rc = regcomp(&rx->rx, pat, flags);
+#ifdef USE_C_LOCALE
+	uselocale(old);
+#else
+	(void)setlocale(LC_CTYPE, old);
+#endif
+	if (rc > 0 && (ms->flags & MAGIC_CHECK)) {
+		char errmsg[512];
+
+		(void)regerror(rc, rx, errmsg, sizeof(errmsg));
+		file_magerror(ms, "regex error %d for `%s', (%s)", rc, pat,
+		    errmsg);
+	}
+	return rc;
 }
 
+/*ARGSUSED*/
 protected int
-file_regexec(file_regex_t *rx, const char *str, size_t nmatch,
-    regmatch_t* pmatch, int eflags)
+file_regexec(struct magic_set *ms file_locale_used, file_regex_t *rx,
+    const char *str, size_t nmatch, regmatch_t* pmatch, int eflags)
 {
-	assert(rx->rc == 0);
+#ifdef USE_C_LOCALE
+	locale_t old = uselocale(ms->c_lc_ctype);
+	assert(old != NULL);
+#else
+	char old[1024];
+	strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old));
+	(void)setlocale(LC_CTYPE, "C");
+#endif
+	int rc;
 	/* XXX: force initialization because glibc does not always do this */
 	if (nmatch != 0)
 		memset(pmatch, 0, nmatch * sizeof(*pmatch));
-	return regexec(&rx->rx, str, nmatch, pmatch, eflags);
-}
-
-protected void
-file_regfree(file_regex_t *rx)
-{
-	if (rx->rc == 0)
-		regfree(&rx->rx);
+	rc = regexec(rx, str, nmatch, pmatch, eflags);
 #ifdef USE_C_LOCALE
-	(void)uselocale(rx->old_lc_ctype);
-	freelocale(rx->c_lc_ctype);
+	uselocale(old);
 #else
-	(void)setlocale(LC_CTYPE, rx->old_lc_ctype);
-	free(rx->old_lc_ctype);
+	(void)setlocale(LC_CTYPE, old);
 #endif
+	return rc;
 }
 
 protected void
-file_regerror(file_regex_t *rx, int rc, struct magic_set *ms)
+file_regfree(file_regex_t *rx)
 {
-	char errmsg[512];
-
-	(void)regerror(rc, &rx->rx, errmsg, sizeof(errmsg));
-	file_magerror(ms, "regex error %d for `%s', (%s)", rc, rx->pat,
-	    errmsg);
+	regfree(rx);
 }
 
 protected file_pushbuf_t *
@@ -790,11 +799,25 @@ protected int
 file_parse_guid(const char *s, uint64_t *guid)
 {
 	struct guid *g = CAST(struct guid *, CAST(void *, guid));
+#ifndef WIN32
 	return sscanf(s,
 	    "%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
 	    &g->data1, &g->data2, &g->data3, &g->data4[0], &g->data4[1],
 	    &g->data4[2], &g->data4[3], &g->data4[4], &g->data4[5],
 	    &g->data4[6], &g->data4[7]) == 11 ? 0 : -1;
+#else
+	/* MS-Windows runtime doesn't support %hhx, except under
+	   non-default __USE_MINGW_ANSI_STDIO.  */
+	uint16_t data16[8];
+	int rv = sscanf(s, "%8x-%4hx-%4hx-%2hx%2hx-%2hx%2hx%2hx%2hx%2hx%2hx",
+	    &g->data1, &g->data2, &g->data3, &data16[0], &data16[1],
+	    &data16[2], &data16[3], &data16[4], &data16[5],
+	    &data16[6], &data16[7]) == 11 ? 0 : -1;
+	int i;
+	for (i = 0; i < 8; i++)
+	    g->data4[i] = data16[i];
+	return rv;
+#endif
 }
 
 protected int
@@ -803,11 +826,19 @@ file_print_guid(char *str, size_t len, const uint64_t *guid)
 	const struct guid *g = CAST(const struct guid *,
 	    CAST(const void *, guid));
 
+#ifndef WIN32
 	return snprintf(str, len, "%.8X-%.4hX-%.4hX-%.2hhX%.2hhX-"
 	    "%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX%.2hhX",
 	    g->data1, g->data2, g->data3, g->data4[0], g->data4[1],
 	    g->data4[2], g->data4[3], g->data4[4], g->data4[5],
 	    g->data4[6], g->data4[7]);
+#else
+	return snprintf(str, len, "%.8X-%.4hX-%.4hX-%.2hX%.2hX-"
+	    "%.2hX%.2hX%.2hX%.2hX%.2hX%.2hX",
+	    g->data1, g->data2, g->data3, g->data4[0], g->data4[1],
+	    g->data4[2], g->data4[3], g->data4[4], g->data4[5],
+	    g->data4[6], g->data4[7]);
+#endif
 }
 
 protected int
@@ -818,15 +849,21 @@ file_pipe_closexec(int *fds)
 #else
 	if (pipe(fds) == -1)
 		return -1;
+# ifdef F_SETFD
 	(void)fcntl(fds[0], F_SETFD, FD_CLOEXEC);
 	(void)fcntl(fds[1], F_SETFD, FD_CLOEXEC);
+# endif
 	return 0;
 #endif
 }
 
 protected int
 file_clear_closexec(int fd) {
+#ifdef F_SETFD
 	return fcntl(fd, F_SETFD, 0);
+#else
+	return 0;
+#endif
 }
 
 protected char *

+ 0 - 0
src/is_csv.c


Some files were not shown because too many files changed in this diff