From 1650748976efa1edc01e2446facffc527ba2f169 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Sat, 24 Jan 2015 11:56:16 +0100 Subject: [PATCH 01/16] drm: Improve linux/pci.h * Add struct pci_device_id * Add PCI_DEVFN, obtained from FreeBSD's OFED subsystem --- sys/dev/drm/include/linux/pci.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/dev/drm/include/linux/pci.h b/sys/dev/drm/include/linux/pci.h index c2ac50de32..2638dac104 100644 --- a/sys/dev/drm/include/linux/pci.h +++ b/sys/dev/drm/include/linux/pci.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 François Tigeot + * Copyright (c) 2014-2015 François Tigeot * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,10 +37,22 @@ #include +struct pci_device_id { + uint32_t class; + uint32_t class_mask; + uint32_t vendor; + uint32_t device; + uint32_t subvendor; + uint32_t subdevice; + unsigned long driver_data; +}; + struct pci_dev { struct device *dev; }; +#define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) + static inline int pci_read_config_byte(struct pci_dev *pdev, int where, u8 *val) { -- 2.41.0 From dd664e5c7980e272aacba4f558b13a65c2645a41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Sat, 24 Jan 2015 12:11:27 +0100 Subject: [PATCH 02/16] drm: Improve linux/jiffies.h --- sys/dev/drm/include/linux/jiffies.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sys/dev/drm/include/linux/jiffies.h b/sys/dev/drm/include/linux/jiffies.h index 5e0241783f..02cc7d00eb 100644 --- a/sys/dev/drm/include/linux/jiffies.h +++ b/sys/dev/drm/include/linux/jiffies.h @@ -35,12 +35,20 @@ #define HZ hz +#define MAX_JIFFY_OFFSET ((LONG_MAX >> 1) - 1) + #define jiffies_to_msecs(x) (((int64_t)(x)) * 1000 / hz) #define msecs_to_jiffies(x) (((int64_t)(x)) * hz / 1000) #define jiffies ticks #define time_after(a,b) ((long)(b) - (long)(a) < 0) #define time_after_eq(a,b) ((long)(b) - (long)(a) <= 0) +#define time_before(a,b) time_after(b,a) +#define time_before_eq(a,b) time_after_eq(b,a) + +#define time_in_range(a,b,c) \ + time_after_eq(a,b) && time_before_eq(a,c) + static inline unsigned long timespec_to_jiffies(const struct timespec *ts) { -- 2.41.0 From ebe97d87650d4f73433ed5437099b688b69aeb6d Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 24 Jan 2015 14:11:54 +0100 Subject: [PATCH 03/16] : Adjust whitespace better (no functional change). --- include/dirent.h | 51 +++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/include/dirent.h b/include/dirent.h index 21b4d89521..67b1b9c264 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -35,7 +35,7 @@ */ #ifndef _DIRENT_H_ -#define _DIRENT_H_ +#define _DIRENT_H_ /* * The kernel defines the format of directory entries returned by @@ -67,11 +67,11 @@ typedef struct _dirdesc { #define dirfd(dirp) ((dirp)->dd_fd) /* flags for opendir2 */ -#define DTF_HIDEW 0x0001 /* hide whiteout entries */ -#define DTF_NODUP 0x0002 /* don't return duplicate names */ -#define DTF_REWIND 0x0004 /* rewind after reading union stack */ -#define __DTF_READALL 0x0008 /* everything has been read */ -#define __DTF_SKIPME 0x0010 /* next entry to read not current entry */ +#define DTF_HIDEW 0x0001 /* hide whiteout entries */ +#define DTF_NODUP 0x0002 /* don't return duplicate names */ +#define DTF_REWIND 0x0004 /* rewind after reading union stack */ +#define __DTF_READALL 0x0008 /* everything has been read */ +#define __DTF_SKIPME 0x0010 /* next entry to read not current entry */ #include @@ -82,27 +82,30 @@ typedef struct _dirdesc { #include __BEGIN_DECLS -DIR *opendir (const char *); -DIR *fdopendir (int); -struct dirent *readdir (DIR *); -void rewinddir (DIR *); -int closedir (DIR *); +DIR *opendir(const char *); +DIR *fdopendir(int); +struct dirent * + readdir(DIR *); +void rewinddir(DIR *); +int closedir(DIR *); #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 || !defined(_POSIX_SOURCE) -int alphasort (const struct dirent **, const struct dirent **); -int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), - int (*)(const struct dirent **, const struct dirent **)); +int alphasort(const struct dirent **, const struct dirent **); +int scandir(const char *, struct dirent ***, + int (*)(const struct dirent *), + int (*)(const struct dirent **, const struct dirent **)); #endif #ifndef _POSIX_SOURCE -DIR *__opendir2 (const char *, int); -DIR *__fdopendir2 (int, int); -long telldir(DIR *); -struct dirent *_readdir_unlocked(DIR *, int); -void seekdir(DIR *, long); -void _reclaim_telldir(DIR *); -void _seekdir (DIR *, long); -int getdents (int, char *, int); -int getdirentries (int, char *, int, long *); -int readdir_r (DIR *, struct dirent *, struct dirent **); +DIR *__opendir2(const char *, int); +DIR *__fdopendir2(int, int); +long telldir(DIR *); +struct dirent * + _readdir_unlocked(DIR *, int); +void seekdir(DIR *, long); +void _reclaim_telldir(DIR *); +void _seekdir(DIR *, long); +int getdents(int, char *, int); +int getdirentries(int, char *, int, long *); +int readdir_r(DIR *, struct dirent *, struct dirent **); #endif /* not POSIX */ __END_DECLS -- 2.41.0 From de45303d1431339260c3a353a1e18d034c807c4a Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 24 Jan 2015 14:15:08 +0100 Subject: [PATCH 04/16] libc: Change dirfd() into a function (needed per POSIX). At the same time, make struct _dirdesc private to libc. If access to dd_fd is needed, dirfd() has to be used. Inside libc, the former dirfd() macro is preserved as _dirfd(). Also, in struct _dirdesc, change the lock from "void *" to "struct pthread_mutex *". This allows us to eliminate some casts in readdir() and friends. Our documentation already describes dirfd() as a function. Based-on: FreeBSD's similar work --- include/dirent.h | 18 ++------ lib/libc/gen/Makefile.inc | 2 +- lib/libc/gen/Symbol.map | 1 + lib/libc/gen/closedir.c | 8 ++-- lib/libc/gen/{rewinddir.c => dirfd.c} | 35 +++++++-------- lib/libc/gen/{seekdir.c => gen_private.h} | 54 +++++++++++------------ lib/libc/gen/opendir.c | 1 + lib/libc/gen/readdir.c | 10 ++--- lib/libc/gen/rewinddir.c | 3 +- lib/libc/gen/scandir.c | 2 + lib/libc/gen/seekdir.c | 5 ++- lib/libc/gen/telldir.c | 6 +-- 12 files changed, 67 insertions(+), 78 deletions(-) copy lib/libc/gen/{rewinddir.c => dirfd.c} (53%) copy lib/libc/gen/{seekdir.c => gen_private.h} (60%) diff --git a/include/dirent.h b/include/dirent.h index 67b1b9c264..fc308f0150 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -50,21 +50,8 @@ typedef void * DIR; /* definitions for library routines operating on directories. */ #define DIRBLKSIZ 1024 -/* structure describing an open directory. */ -typedef struct _dirdesc { - int dd_fd; /* file descriptor associated with directory */ - long dd_loc; /* offset in current buffer */ - long dd_size; /* amount of data returned by getdirentries */ - char *dd_buf; /* data buffer */ - int dd_len; /* size of data buffer */ - long dd_lastseek; /* last seek index */ - long dd_rewind; /* magic cookie for rewinding */ - int dd_flags; /* flags for readdir */ - void *dd_lock; /* hack to avoid include */ - off_t dd_seek; /* new magic cookie returned by getdirentries */ -} DIR; - -#define dirfd(dirp) ((dirp)->dd_fd) +struct _dirdesc; +typedef struct _dirdesc DIR; /* flags for opendir2 */ #define DTF_HIDEW 0x0001 /* hide whiteout entries */ @@ -90,6 +77,7 @@ void rewinddir(DIR *); int closedir(DIR *); #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 || !defined(_POSIX_SOURCE) int alphasort(const struct dirent **, const struct dirent **); +int dirfd(DIR *); int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index b40c13abcd..49a2d0bf2d 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -11,7 +11,7 @@ CMAPS+= ${.CURDIR}/gen/Symbol.map SRCS+= _once_stub.c _pthread_stubs.c _rand48.c _spinlock_stub.c \ _thread_init.c alarm.c arc4random.c assert.c basename.c \ clock.c closedir.c confstr.c \ - ctermid.c daemon.c devname.c dirname.c disklabel.c disktab.c \ + ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c disktab.c \ dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c exec.c \ fdevname.c fmtcheck.c fmtmsg.c fnmatch.c fpclassify.c \ frexp.c fstab.c ftok.c fts.c ftw.c getbootfile.c getbsize.c \ diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index dcd6152753..6f702ec497 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -48,6 +48,7 @@ DF402.0 { daemon; devname; devname_r; + dirfd; dirname; dl_iterate_phdr; dladdr; diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c index 40f862e6d8..abfac3c332 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -31,7 +31,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/closedir.c,v 1.6.2.1 2001/03/05 08:29:56 obrien Exp $ - * $DragonFly: src/lib/libc/gen/closedir.c,v 1.5 2005/04/26 15:04:59 joerg Exp $ * * @(#)closedir.c 8.1 (Berkeley) 6/10/93 */ @@ -44,6 +43,7 @@ #include "un-namespace.h" #include "libc_private.h" +#include "gen_private.h" /* * close a directory. @@ -54,7 +54,7 @@ closedir(DIR *dirp) int fd; if (__isthreaded) - _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_lock(&dirp->dd_lock); _seekdir(dirp, dirp->dd_rewind); /* free seekdir storage */ fd = dirp->dd_fd; dirp->dd_fd = -1; @@ -62,8 +62,8 @@ closedir(DIR *dirp) free(dirp->dd_buf); _reclaim_telldir(dirp); if (__isthreaded) { - _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); - _pthread_mutex_destroy((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_unlock(&dirp->dd_lock); + _pthread_mutex_destroy(&dirp->dd_lock); } free(dirp); return(_close(fd)); diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/dirfd.c similarity index 53% copy from lib/libc/gen/rewinddir.c copy to lib/libc/gen/dirfd.c index 23e017ecc9..2a993acd2c 100644 --- a/lib/libc/gen/rewinddir.c +++ b/lib/libc/gen/dirfd.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2011 Gleb Kurtsou + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,18 +10,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -30,18 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/gen/rewinddir.c,v 1.2.8.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/rewinddir.c,v 1.5 2008/04/22 21:29:42 dillon Exp $ - * - * @(#)rewinddir.c 8.1 (Berkeley) 6/8/93 + * $FreeBSD: head/lib/libc/gen/dirfd.c 235649 2012-05-19 14:30:49Z gleb $ */ +#include "namespace.h" +#include + #include +#include "un-namespace.h" -void -rewinddir(DIR *dirp) +#include "gen_private.h" + +int +dirfd(DIR *dirp) { - _seekdir(dirp, dirp->dd_rewind); - _reclaim_telldir(dirp); - dirp->dd_rewind = telldir(dirp); + + return (_dirfd(dirp)); } diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/gen_private.h similarity index 60% copy from lib/libc/gen/seekdir.c copy to lib/libc/gen/gen_private.h index 7f947dbcc6..933743aad2 100644 --- a/lib/libc/gen/seekdir.c +++ b/lib/libc/gen/gen_private.h @@ -1,5 +1,5 @@ -/* - * Copyright (c) 1983, 1993 +/*- + * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -30,29 +26,33 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/gen/seekdir.c,v 1.2.8.1 2001/03/05 09:52:13 obrien Exp $ - * - * @(#)seekdir.c 8.1 (Berkeley) 6/4/93 + * $FreeBSD: head/lib/libc/gen/gen-private.h 268531 2014-07-11 16:16:26Z jhb $ */ -#include "namespace.h" -#include -#include -#include -#include "un-namespace.h" +#ifndef _GEN_PRIVATE_H_ +#define _GEN_PRIVATE_H_ -#include "libc_private.h" +struct pthread_mutex; /* - * Seek to an entry in a directory. - * _seekdir is in telldir.c so that it can share opaque data structures. + * Structure describing an open directory. + * + * NOTE. Change structure layout with care, at least dd_fd field has to + * remain unchanged to guarantee backward compatibility. */ -void -seekdir(DIR *dirp, long loc) -{ - if (__isthreaded) - _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); - _seekdir(dirp, loc); - if (__isthreaded) - _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); -} +struct _dirdesc { + int dd_fd; /* file descriptor associated with directory */ + long dd_loc; /* offset in current buffer */ + long dd_size; /* amount of data returned by getdirentries */ + char *dd_buf; /* data buffer */ + int dd_len; /* size of data buffer */ + long dd_lastseek; /* last seek index */ + long dd_rewind; /* magic cookie for rewinding */ + int dd_flags; /* flags for readdir */ + struct pthread_mutex *dd_lock; /* lock */ + off_t dd_seek; /* new magic cookie returned by getdirentries */ +}; + +#define _dirfd(dirp) ((dirp)->dd_fd) + +#endif /* !_GEN_PRIVATE_H_ */ diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 888fd5202a..557a7ce90d 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -47,6 +47,7 @@ #include #include "un-namespace.h" +#include "gen_private.h" #define DEFAULT_FLAGS (DTF_HIDEW | DTF_NODUP) diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c index abf5e12968..e4b69c88d4 100644 --- a/lib/libc/gen/readdir.c +++ b/lib/libc/gen/readdir.c @@ -31,7 +31,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/readdir.c,v 1.5.2.4 2002/02/26 22:53:57 alfred Exp $ - * $DragonFly: src/lib/libc/gen/readdir.c,v 1.10 2008/05/03 22:07:37 dillon Exp $ * * @(#)readdir.c 8.3 (Berkeley) 9/29/94 */ @@ -46,6 +45,7 @@ #include "un-namespace.h" #include "libc_private.h" +#include "gen_private.h" /* * get next entry in a directory. @@ -90,10 +90,10 @@ readdir(DIR *dirp) struct dirent *dp; if (__isthreaded) - _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_lock(&dirp->dd_lock); dp = _readdir_unlocked(dirp, 1); if (__isthreaded) - _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_unlock(&dirp->dd_lock); return (dp); } @@ -107,11 +107,11 @@ readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) saved_errno = errno; errno = 0; if (__isthreaded) - _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_lock(&dirp->dd_lock); if ((dp = _readdir_unlocked(dirp, 1)) != NULL) memcpy(entry, dp, _DIRENT_MINSIZ(dp)); if (__isthreaded) - _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_unlock(&dirp->dd_lock); if (errno != 0) { if (dp == NULL) { diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c index 23e017ecc9..53d4d0b89b 100644 --- a/lib/libc/gen/rewinddir.c +++ b/lib/libc/gen/rewinddir.c @@ -31,13 +31,14 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/rewinddir.c,v 1.2.8.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/rewinddir.c,v 1.5 2008/04/22 21:29:42 dillon Exp $ * * @(#)rewinddir.c 8.1 (Berkeley) 6/8/93 */ #include +#include "gen_private.h" + void rewinddir(DIR *dirp) { diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 534d1f3dcb..f8b5e506ae 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -51,6 +51,8 @@ #include #include "un-namespace.h" +#include "gen_private.h" + int scandir(const char *dirname, struct dirent ***namelist, int (*select)(const struct dirent *), diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c index 7f947dbcc6..ffdbc460fc 100644 --- a/lib/libc/gen/seekdir.c +++ b/lib/libc/gen/seekdir.c @@ -42,6 +42,7 @@ #include "un-namespace.h" #include "libc_private.h" +#include "gen_private.h" /* * Seek to an entry in a directory. @@ -51,8 +52,8 @@ void seekdir(DIR *dirp, long loc) { if (__isthreaded) - _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_lock(&dirp->dd_lock); _seekdir(dirp, loc); if (__isthreaded) - _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_unlock(&dirp->dd_lock); } diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c index 5bf8a78506..62835cbc3a 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -31,7 +31,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/telldir.c,v 1.4.12.1 2001/03/05 09:39:59 obrien Exp $ - * $DragonFly: src/lib/libc/gen/telldir.c,v 1.7 2008/05/03 22:07:37 dillon Exp $ * * @(#)telldir.c 8.1 (Berkeley) 6/4/93 */ @@ -45,6 +44,7 @@ #include "un-namespace.h" #include "libc_private.h" +#include "gen_private.h" /* * One of these structures is malloced to describe the current directory @@ -77,7 +77,7 @@ telldir(DIR *dirp) struct ddloc *lp; if (__isthreaded) { - _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_lock(&dirp->dd_lock); _pthread_mutex_lock(&dd_hash_lock); } @@ -109,7 +109,7 @@ telldir(DIR *dirp) done: if (__isthreaded) { _pthread_mutex_unlock(&dd_hash_lock); - _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_unlock(&dirp->dd_lock); } return (index); } -- 2.41.0 From 6bd7e4d0eed8d4ef5a34d3bd954399ef62c47b0b Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 24 Jan 2015 14:19:59 +0100 Subject: [PATCH 05/16] : Don't check _POSIX_SOURCE. Use the __POSIX_VISIBLE, __XSI_VISIBLE and __BSD_VISIBLE macros, per . --- include/dirent.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/include/dirent.h b/include/dirent.h index fc308f0150..2bcca6f12d 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -43,9 +43,7 @@ */ #include -#ifdef _POSIX_SOURCE -typedef void * DIR; -#else +#if __BSD_VISIBLE /* definitions for library routines operating on directories. */ #define DIRBLKSIZ 1024 @@ -62,7 +60,11 @@ typedef struct _dirdesc DIR; #include -#endif /* _POSIX_SOURCE */ +#else /* !__BSD_VISIBLE */ + +typedef void * DIR; + +#endif /* __BSD_VISIBLE */ #ifndef _KERNEL @@ -75,26 +77,30 @@ struct dirent * readdir(DIR *); void rewinddir(DIR *); int closedir(DIR *); -#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 || !defined(_POSIX_SOURCE) +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 +int readdir_r(DIR *, struct dirent *, struct dirent **); +#endif +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 int alphasort(const struct dirent **, const struct dirent **); int dirfd(DIR *); int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); #endif -#ifndef _POSIX_SOURCE +#if __XSI_VISIBLE +void seekdir(DIR *, long); +long telldir(DIR *); +#endif +#if __BSD_VISIBLE DIR *__opendir2(const char *, int); DIR *__fdopendir2(int, int); -long telldir(DIR *); struct dirent * _readdir_unlocked(DIR *, int); -void seekdir(DIR *, long); void _reclaim_telldir(DIR *); void _seekdir(DIR *, long); int getdents(int, char *, int); int getdirentries(int, char *, int, long *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -#endif /* not POSIX */ +#endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_KERNEL */ -- 2.41.0 From 85e1e7369f14535c441e8b364faf7f9688292029 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 24 Jan 2015 14:09:48 +0100 Subject: [PATCH 06/16] liblvm: Request _XOPEN_SOURCE=700 for alphasort() prototype. --- gnu/lib/liblvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnu/lib/liblvm/Makefile b/gnu/lib/liblvm/Makefile index 64807d6b0f..f41ea378db 100644 --- a/gnu/lib/liblvm/Makefile +++ b/gnu/lib/liblvm/Makefile @@ -7,7 +7,7 @@ SHLIB_MAJOR?= 0 LVM2_DISTDIR= ${LVM2_DIR}/dist -CFLAGS+= -D_XOPEN_SOURCE=600 +CFLAGS+= -D_XOPEN_SOURCE=700 CFLAGS+= -I${LVM2_DISTDIR}/include SRCS+= activate.c lvmcache.c toolcontext.c config.c btree.c \ -- 2.41.0 From 3e581a72263dd3b726387b5dc2399a066511099f Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 24 Jan 2015 14:36:29 -0800 Subject: [PATCH 07/16] inttypes.h: Add typedef for wchar_t. --- include/inttypes.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/inttypes.h b/include/inttypes.h index 888c89a08a..5f7845d81c 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -24,7 +24,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/include/inttypes.h,v 1.8 2002/09/22 08:06:45 tjr Exp $ - * $DragonFly: src/include/inttypes.h,v 1.1 2003/11/09 02:22:28 dillon Exp $ */ #ifndef _INTTYPES_H_ @@ -33,6 +32,13 @@ #include #include +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +#define _WCHAR_T_DECLARED +typedef __wchar_t wchar_t; +#endif +#endif + typedef struct { intmax_t quot; /* Quotient. */ intmax_t rem; /* Remainder. */ @@ -45,10 +51,10 @@ imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2; intmax_t strtoimax(const char * __restrict, char ** __restrict, int); uintmax_t strtoumax(const char * __restrict, char ** __restrict, int); #ifndef __cplusplus -intmax_t wcstoimax(const __wchar_t * __restrict, - __wchar_t ** __restrict, int); -uintmax_t wcstoumax(const __wchar_t * __restrict, - __wchar_t ** __restrict, int); +intmax_t wcstoimax(const wchar_t * __restrict, + wchar_t ** __restrict, int); +uintmax_t wcstoumax(const wchar_t * __restrict, + wchar_t ** __restrict, int); #endif __END_DECLS -- 2.41.0 From 89a9c80e537ed7238142c9af2cdc03401742a18a Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 24 Jan 2015 12:48:01 -0800 Subject: [PATCH 08/16] Import file-5.22. --- contrib/file/ChangeLog | 155 ++++- contrib/file/README | 32 +- contrib/file/doc/file.man | 15 +- contrib/file/doc/libmagic.man | 67 +- contrib/file/doc/magic.man | 34 +- contrib/file/magic/Magdir/android | 141 +++-- contrib/file/magic/Magdir/animation | 168 ++++- contrib/file/magic/Magdir/apple | 10 +- contrib/file/magic/Magdir/archive | 45 +- contrib/file/magic/Magdir/att3b | 10 +- contrib/file/magic/Magdir/audio | 6 +- contrib/file/magic/Magdir/bflt | 4 +- contrib/file/magic/Magdir/blender | 4 +- contrib/file/magic/Magdir/bsdi | 8 +- contrib/file/magic/Magdir/c-lang | 4 +- contrib/file/magic/Magdir/cafebabe | 6 +- contrib/file/magic/Magdir/clarion | 4 +- contrib/file/magic/Magdir/claris | 4 +- contrib/file/magic/Magdir/clipper | 6 +- contrib/file/magic/Magdir/commands | 4 +- contrib/file/magic/Magdir/compress | 23 +- contrib/file/magic/Magdir/cups | 8 +- contrib/file/magic/Magdir/database | 189 ++++-- contrib/file/magic/Magdir/dump | 10 +- contrib/file/magic/Magdir/dyadic | 90 +-- contrib/file/magic/Magdir/efi | 4 +- contrib/file/magic/Magdir/elf | 17 +- contrib/file/magic/Magdir/encore | 6 +- contrib/file/magic/Magdir/filesystems | 338 +++++----- contrib/file/magic/Magdir/flash | 26 +- contrib/file/magic/Magdir/fonts | 6 +- contrib/file/magic/Magdir/fortran | 4 +- contrib/file/magic/Magdir/games | 20 +- contrib/file/magic/Magdir/gimp | 6 +- contrib/file/magic/Magdir/gnome | 6 +- contrib/file/magic/Magdir/gpt | 3 +- contrib/file/magic/Magdir/graphviz | 6 +- contrib/file/magic/Magdir/hp | 30 +- contrib/file/magic/Magdir/ibm370 | 10 +- contrib/file/magic/Magdir/images | 251 +++++++- contrib/file/magic/Magdir/intel | 12 +- contrib/file/magic/Magdir/isz | 2 +- contrib/file/magic/Magdir/jpeg | 187 ++---- contrib/file/magic/Magdir/karma | 4 +- contrib/file/magic/Magdir/kerberos | 45 ++ contrib/file/magic/Magdir/linux | 38 +- contrib/file/magic/Magdir/mach | 106 ++-- contrib/file/magic/Magdir/macintosh | 86 +-- contrib/file/magic/Magdir/map | 25 + contrib/file/magic/Magdir/marc21 | 12 +- .../magic/Magdir/{rinex => meteorological} | 7 +- contrib/file/magic/Magdir/mips | 46 +- contrib/file/magic/Magdir/motorola | 30 +- contrib/file/magic/Magdir/msdos | 130 +--- contrib/file/magic/Magdir/msooxml | 4 +- contrib/file/magic/Magdir/msx | 2 +- contrib/file/magic/Magdir/natinst | 4 +- contrib/file/magic/Magdir/ncr | 16 +- contrib/file/magic/Magdir/netbsd | 46 +- contrib/file/magic/Magdir/nitpicker | 2 +- contrib/file/magic/Magdir/oasis | 4 +- contrib/file/magic/Magdir/palm | 10 +- contrib/file/magic/Magdir/pascal | 10 +- contrib/file/magic/Magdir/pdp | 8 +- contrib/file/magic/Magdir/perl | 33 +- contrib/file/magic/Magdir/pgp | 444 ++++++++++++- contrib/file/magic/Magdir/printer | 22 +- contrib/file/magic/Magdir/python | 5 +- contrib/file/magic/Magdir/qt | 19 + contrib/file/magic/Magdir/riff | 29 +- contrib/file/magic/Magdir/scientific | 12 +- contrib/file/magic/Magdir/sequent | 29 +- contrib/file/magic/Magdir/sereal | 25 + contrib/file/magic/Magdir/sgi | 18 +- contrib/file/magic/Magdir/sharc | 4 +- contrib/file/magic/Magdir/sql | 4 +- contrib/file/magic/Magdir/ssh | 2 + contrib/file/magic/Magdir/sun | 38 +- contrib/file/magic/Magdir/symbos | 2 +- contrib/file/magic/Magdir/sysex | 4 +- contrib/file/magic/Magdir/ti-8x | 4 +- contrib/file/magic/Magdir/troff | 6 +- contrib/file/magic/Magdir/uterus | 2 +- contrib/file/magic/Magdir/varied.out | 4 +- contrib/file/magic/Magdir/vax | 6 +- contrib/file/magic/Magdir/virtual | 112 +++- contrib/file/magic/Magdir/vms | 2 +- contrib/file/magic/Magdir/vorbis | 22 +- contrib/file/magic/Magdir/windows | 9 +- contrib/file/magic/Magdir/xilinx | 4 +- contrib/file/magic/Magdir/xwindows | 14 +- contrib/file/magic/Magdir/zfs | 8 +- contrib/file/src/apprentice.c | 596 ++++++++++++------ contrib/file/src/ascmagic.c | 5 +- contrib/file/src/cdf.c | 182 +++++- contrib/file/src/cdf.h | 26 + contrib/file/src/cdf_time.c | 7 +- contrib/file/src/compress.c | 47 +- contrib/file/src/elfclass.h | 34 +- contrib/file/src/encoding.c | 3 +- contrib/file/src/file.c | 66 +- contrib/file/src/file.h | 58 +- contrib/file/src/file_opts.h | 6 + contrib/file/src/fsmagic.c | 47 +- contrib/file/src/funcs.c | 139 +++- contrib/file/src/magic.c | 127 +++- contrib/file/src/magic.h | 13 +- contrib/file/src/readcdf.c | 160 +++-- contrib/file/src/readelf.c | 559 ++++++++++------ contrib/file/src/softmagic.c | 586 ++++++++--------- 110 files changed, 4222 insertions(+), 1938 deletions(-) create mode 100644 contrib/file/magic/Magdir/kerberos create mode 100644 contrib/file/magic/Magdir/map rename contrib/file/magic/Magdir/{rinex => meteorological} (88%) create mode 100644 contrib/file/magic/Magdir/qt create mode 100644 contrib/file/magic/Magdir/sereal diff --git a/contrib/file/ChangeLog b/contrib/file/ChangeLog index dd90401863..98cdcc46b6 100644 --- a/contrib/file/ChangeLog +++ b/contrib/file/ChangeLog @@ -1,10 +1,157 @@ +2015-01-02 15:15 Christos Zoulas + + * release 5.22 + +2015-01-01 12:01 Christos Zoulas + + * add indirect relative for TIFF/Exif + +2014-12-16 18:10 Christos Zoulas + + * restructure elf note printing to avoid repeated messages + * add note limit, suggested by Alexander Cherepanov + +2014-12-16 16:53 Christos Zoulas + + * Bail out on partial pread()'s (Alexander Cherepanov) + * Fix incorrect bounds check in file_printable (Alexander Cherepanov) + +2014-12-11 20:01 Christos Zoulas + + * PR/405: ignore SIGPIPE from uncompress programs + * change printable -> file_printable and use it in + more places for safety + * in ELF, instead of "(uses dynamic libraries)" when PT_INTERP + is present print the interpreter name. + +2014-12-10 20:01 Christos Zoulas + + * release 5.21 + +2014-11-27 18:40 Christos Zoulas + + * Allow setting more parameters from the command line. + * Split name/use and indirect magic recursion limits. + +2014-11-27 11:12 Christos Zoulas + + * Adjust ELF parameters and the default recursion + level. + * Allow setting the recursion level dynamically. + +2014-11-24 8:55 Christos Zoulas + + * The following fixes resulted from Thomas Jarosch's fuzzing + tests that revealed severe performance issues on pathological + input: + - limit number of elf program and sections processing + - abort elf note processing quickly + - reduce the number of recursion levels from 20 to 10 + - preserve error messages in indirect magic handling + + This is tracked as CVE-2014-8116 and CVE-2014-8117 + +2014-11-12 10:30 Christos Zoulas + + * fix bogus free in the user buffer case. + +2014-11-11 12:35 Christos Zoulas + + * fix out of bounds read for pascal strings + * fix memory leak (not freeing the head of each mlist) + +2014-11-07 10:25 Christos Zoulas + + * When printing strings from a file, convert them to printable + on a byte by byte basis, so that we don't get issues with + locale's trying to interpret random byte streams as UTF-8 and + having printf error out with EILSEQ. + +2014-10-17 11:48 Christos Zoulas + + * fix bounds in note reading (Francisco Alonso / Red Hat) + +2014-10-11 15:02 Christos Zoulas + + * fix autoconf glue for setlocale and locale_t; some OS's + have locale_t in xlocale.h + +2014-10-10 15:01 Christos Zoulas + + * release 5.20 + +2014-08-17 10:01 Christos Zoulas + + * recognize encrypted CDF documents + +2014-08-04 9:18 Christos Zoulas + + * add magic_load_buffers from Brooks Davis + +2014-07-24 16:40 Christos Zoulas + + * add thumbs.db support + +2014-06-12 12:28 Christos Zoulas + + * release 5.19 + +2014-06-09 9:04 Christos Zoulas + + * Misc buffer overruns and missing buffer size tests in cdf parsing + (Francisco Alonso, Jan Kaluza) + +2014-06-02 14:50 Christos Zoulas + + * Enforce limit of 8K on regex searches that have no limits + * Allow the l modifier for regex to mean line count. Default + to byte count. If line count is specified, assume a max + of 80 characters per line to limit the byte count. + * Don't allow conversions to be used for dates, allowing + the mask field to be used as an offset. + +2014-05-30 12:51 Christos Zoulas + + * Make the range operator limit the length of the + regex search. + +2014-05-14 19:23 Christos Zoulas + + * PR/347: Windows fixes + * PR/352: Hangul word processor recognition + * PR/354: Encoding irregularities in text files + +2014-05-06 6:12 Christos Zoulas + + * Fix uninitialized title in CDF files (Jan Kaluza) + +2014-05-04 14:55 Christos Zoulas + + * PR/351: Fix compilation of empty files + +2014-04-30 17:39 Christos Zoulas + + * Fix integer formats: We don't specify 'l' or + 'h' and 'hh' specifiers anymore, only 'll' for + quads and nothing for the rest. This is so that + magic writing is simpler. + +2014-04-01 15:25 Christos Zoulas + + * PR/341: Jan Kaluza, fix memory leak + * PR/342: Jan Kaluza, fix out of bounds read + +2014-03-28 15:25 Christos Zoulas + + * Fix issue with long formats not matching fmtcheck + 2014-03-26 11:25 Christos Zoulas * release 5.18 2014-03-15 17:45 Christos Zoulas - * add fmtcheck(3) for those who don't have it + * add fmtcheck(3) for those who don't have it 2014-03-14 15:12 Christos Zoulas @@ -1040,7 +1187,7 @@ * Identify gnu tar vs. posix tar - * When keep going, don't print spurious newlines (Radek Vokál) + * When keep going, don't print spurious newlines (Radek Vokal) 2006-04-01 12:02 Christos Zoulas @@ -1064,7 +1211,7 @@ 2005-10-31 8:54 Christos Zoulas * Fix regression where the core info was not completely processed - (Radek Vokál) + (Radek Vokal) 2005-10-20 11:15 Christos Zoulas @@ -1081,7 +1228,7 @@ 2005-09-20 13:33 Christos Zoulas * Don't print SVR4 Style in core files multiple times - (Radek Vokál) + (Radek Vokal) 2005-08-27 04:09 Christos Zoulas diff --git a/contrib/file/README b/contrib/file/README index cfc530f520..81a52216c4 100644 --- a/contrib/file/README +++ b/contrib/file/README @@ -1,6 +1,6 @@ ## README for file(1) Command ## - @(#) $File: README,v 1.48 2014/03/07 13:55:30 christos Exp $ + @(#) $File: README,v 1.49 2015/01/02 20:23:04 christos Exp $ Mailing List: file@mx.gw.com Mailing List archives: http://mx.gw.com/pipermail/file/ @@ -25,8 +25,8 @@ A public read-only git repository of the same sources is available at: https://github.com/file/file -The major changes for 5.x are CDF file parsing, indirect magic, and -overhaul in mime and ascii encoding handling. +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 @@ -67,33 +67,41 @@ 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/asctime_r.c - replacement for OS's that don't have it. src/apptype.c - used for OS/2 specific application type magic src/asprintf.c - replacement for OS's that don't have it. src/ascmagic.c - third & last set of tests, based on hardwired assumptions. -src/asctime_r.c - for systems that don't have it. -src/asprintf.c - for systems that don't have it. -src/cdf.c - parser for Microsoft Compound Document Files +src/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/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 - for systems that don't have it. +src/ctime_r.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/getopt_long.c - for systems that don't have it. -src/getline.c - for systems that don't have it. +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/is_tar.c, tar.h - knows about tarchives (courtesy John Gilmore). src/names.h - header file for ascmagic.c +src/magic.h.in - source file for magic.h src/magic.c - the libmagic api +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/strlcat.c - for systems that don't have it. -src/strlcpy.c - for systems that don't have it. +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/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. diff --git a/contrib/file/doc/file.man b/contrib/file/doc/file.man index 361188e139..64b8435877 100644 --- a/contrib/file/doc/file.man +++ b/contrib/file/doc/file.man @@ -1,5 +1,5 @@ -.\" $File: file.man,v 1.106 2014/03/07 23:11:51 christos Exp $ -.Dd January 30, 2014 +.\" $File: file.man,v 1.111 2014/12/16 23:18:40 christos Exp $ +.Dd December 16, 2014 .Dt FILE __CSECTION__ .Os .Sh NAME @@ -16,6 +16,7 @@ .Op Fl F Ar separator .Op Fl f Ar namefile .Op Fl m Ar magicfiles +.Op Fl P Ar name=value .Ar .Ek .Nm @@ -303,6 +304,16 @@ or attempt to preserve the access time of files analyzed, to pretend that .Nm never read them. +.It Fl P , Fl Fl parameter Ar name=value +Set various parameter limits. +.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent +.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation" +.It Li indir Ta 15 Ta recursion limit for indirect magic +.It Li name Ta 30 Ta use count limit for name/use magic +.It Li elf_notes Ta 256 Ta max ELF notes processed +.It Li elf_phnum Ta 128 Ta max ELF program sections processed +.It Li elf_shnum Ta 32768 Ta max ELF sections processed +.El .It Fl r , Fl Fl raw Don't translate unprintable characters to \eooo. Normally diff --git a/contrib/file/doc/libmagic.man b/contrib/file/doc/libmagic.man index ee9cdb284e..3c907cad9b 100644 --- a/contrib/file/doc/libmagic.man +++ b/contrib/file/doc/libmagic.man @@ -1,4 +1,4 @@ -.\" $File: libmagic.man,v 1.28 2014/03/02 14:47:16 christos Exp $ +.\" $File: libmagic.man,v 1.34 2014/12/16 23:18:40 christos Exp $ .\" .\" Copyright (c) Christos Zoulas 2003. .\" All Rights Reserved. @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 6, 2012 +.Dd December 16, 2014 .Dt LIBMAGIC 3 .Os .Sh NAME @@ -40,6 +40,9 @@ .Nm magic_compile , .Nm magic_list , .Nm magic_load , +.Nm magic_load_buffers , +.Nm magic_setparam , +.Nm magic_getparam , .Nm magic_version .Nd Magic number recognition library .Sh LIBRARY @@ -71,6 +74,12 @@ .Ft int .Fn magic_load "magic_t cookie" "const char *filename" .Ft int +.Fn magic_load_buffers "magic_t cookie" "void **buffers" "size_t *sizes" "size_t nbuffers" +.Ft int +.Fn magic_getparam "magic_t cookie" "int param" "void *value" +.Ft int +.Fn magic_setparam "magic_t cookie" "int param" "const void *value" +.Ft int .Fn magic_version "void" .Sh DESCRIPTION These functions @@ -253,6 +262,60 @@ adds to the database filename as appropriate. .Pp The +.Fn magic_load_buffers +function takes an array of size +.Fa nbuffers +of +.Fa buffers +with a respective size for each in the array of +.Fa sizes +loaded with the contents of the magic databases from the filesystem. +This function can be used in environment where the magic library does +not have direct access to the filesystem, but can access the magic +database via shared memory or other IPC means. +.Pp +The +.Fn magic_getparam +and +.Fn magic_setparam +allow getting and setting various limits related to the the magic +library. +.Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent +.It Sy "Parameter" Ta Sy "Type" Ta Sy "Default" +.It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15 +.It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30 +.It Li MAGIC_PARAM_ELF_NOTES_MAX Ta size_t Ta 256 +.It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128 +.It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768 +.El +.Pp +The +.Dv MAGIC_PARAM_INDIR_RECURSION +parameter controls how many levels of recursion will be followed for +indirect magic entries. +.Pp +The +.Dv MAGIC_PARAM_NAME_RECURSION +parameter controls how many levels of recursion will be followed for +for name/use calls. +.Pp +The +.Dv MAGIC_PARAM_NAME_MAX +parameter controls the maximum number of calls for name/use. +.Pp +The +.Dv MAGIC_PARAM_NOTES_MAX +parameter controls how many ELF notes will be processed. +.Pp +The +.Dv MAGIC_PARAM_PHNUM_MAX +parameter controls how many ELF program sections will be processed. +.Pp +The +.Dv MAGIC_PARAM_SHNUM_MAX +parameter controls how many ELF sections will be processed. +.Pp +The .Fn magic_version command returns the version number of this library which is compiled into the shared library using the constant diff --git a/contrib/file/doc/magic.man b/contrib/file/doc/magic.man index fab13efb37..b6523f2d9e 100644 --- a/contrib/file/doc/magic.man +++ b/contrib/file/doc/magic.man @@ -1,5 +1,5 @@ -.\" $File: magic.man,v 1.81 2014/03/08 17:28:08 christos Exp $ -.Dd April 22, 2013 +.\" $File: magic.man,v 1.85 2015/01/01 17:07:34 christos Exp $ +.Dd January 1, 2015 .Dt MAGIC __FSECTION__ .Os .\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems. @@ -200,6 +200,11 @@ interpreted as a UNIX-style date, but interpreted as local time rather than UTC. .It Dv indirect Starting at the given offset, consult the magic database again. +The offset of th +.Dv indirect +magic is by default absolute in the file, but one can specify +.Dv /r +to indicate that the offset is relative from the beginning of the entry. .It Dv name Define a .Dq named @@ -228,19 +233,25 @@ Regular expressions can take exponential time to process, and their performance is hard to predict, so their use is discouraged. When used in production environments, their performance should be carefully checked. -The type specification can be optionally followed by -.Dv /[c][s] . +The size of the string to search should also be limited by specifying +.Dv / , +to avoid performance issues scanning long files. +The type specification can also be optionally followed by +.Dv /[c][s][l] . The .Dq c flag makes the match case insensitive, while the .Dq s flag update the offset to the start offset of the match, rather than the end. -The regular expression is tested against line -.Dv N + 1 -onwards, where -.Dv N -is the given offset. -Line endings are assumed to be in the machine's native format. +The +.Dq l +modifier, changes the limit of length to mean number of lines instead of a +byte count. +Lines are delimited by the platforms native line delimiter. +When a line count is specified, an implicit byte count also computed assuming +each line is 80 characters long. +If neither a byte or line count is specified, the search is limited automatically +to 8KiB. .Dv ^ and .Dv $ @@ -409,6 +420,9 @@ is octal, and .Dv 0x13 is hexadecimal. .Pp +Numeric operations are not performed on date types, instead the numeric +value is interpreted as an offset. +.Pp For string values, the string from the file must match the specified string. The operators diff --git a/contrib/file/magic/Magdir/android b/contrib/file/magic/Magdir/android index cae0cb7d76..da98b576e7 100644 --- a/contrib/file/magic/Magdir/android +++ b/contrib/file/magic/Magdir/android @@ -1,6 +1,6 @@ #------------------------------------------------------------ -# $File: android,v 1.3 2013/11/08 01:24:22 christos Exp $ +# $File: android,v 1.7 2014/11/10 05:08:23 christos Exp $ # Various android related magic entries #------------------------------------------------------------ @@ -15,54 +15,11 @@ >0 regex dey\n[0-9]{2}\0 Dalvik dex file (optimized for host) >4 string >000 version %s -# http://android.stackexchange.com/questions/23357/\ -# is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file/\ -# 23608#23608 -0 string ANDROID\040BACKUP\n Android Backup ->15 string 1\n \b, version 1 ->17 string 0\n \b, uncompressed ->17 string 1\n \b, compressed ->19 string none\n \b, unencrypted ->19 string AES-256\n \b, encrypted AES-256 - -# Android bootimg format -# From https://android.googlesource.com/\ -# platform/system/core/+/master/mkbootimg/bootimg.h -0 string ANDROID! Android bootimg ->8 lelong >0 \b, kernel ->>12 lelong >0 \b (0x%x) ->16 lelong >0 \b, ramdisk ->>20 lelong >0 \b (0x%x) ->24 lelong >0 \b, second stage ->>28 lelong >0 \b (0x%x) ->36 lelong >0 \b, page size: %d ->38 string >0 \b, name: %s ->64 string >0 \b, cmdline (%s) -# Dalvik .dex format. http://retrodev.com/android/dexformat.html -# From "Mike Fleming" -# Fixed to avoid regexec 17 errors on some dex files -# From "Tim Strazzere" -0 string dex\n ->0 regex dex\n[0-9]{2}\0 Dalvik dex file ->4 string >000 version %s -0 string dey\n ->0 regex dey\n[0-9]{2}\0 Dalvik dex file (optimized for host) ->4 string >000 version %s - -# http://android.stackexchange.com/questions/23357/\ -# is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file/\ -# 23608#23608 -0 string ANDROID\040BACKUP\n Android Backup ->15 string 1\n \b, version 1 ->17 string 0\n \b, uncompressed ->17 string 1\n \b, compressed ->19 string none\n \b, unencrypted ->19 string AES-256\n \b, encrypted AES-256 - # Android bootimg format # From https://android.googlesource.com/\ # platform/system/core/+/master/mkbootimg/bootimg.h 0 string ANDROID! Android bootimg +>1024 string LOKI\01 \b, LOKI'd >8 lelong >0 \b, kernel >>12 lelong >0 \b (0x%x) >16 lelong >0 \b, ramdisk @@ -89,12 +46,94 @@ >17 string 0\n \b, Not-Compressed >17 string 1\n \b, Compressed # any string as long as it's not the word none (which is matched below) ->>19 regex/1 \^([^n\n]|n[^o]|no[^n]|non[^e]|none.+).* \b, Encrypted (%s) +>>19 regex/1l \^([^n\n]|n[^o]|no[^n]|non[^e]|none.+).* \b, Encrypted (%s) >>19 string none\n \b, Not-Encrypted # Commented out because they don't seem useful to print # (but they are part of the header - the tar file comes after them): -#>>>&1 regex/1 .* \b, Password salt: %s -#>>>>&1 regex/1 .* \b, Master salt: %s -#>>>>>&1 regex/1 .* \b, PBKDF2 rounds: %s -#>>>>>>&1 regex/1 .* \b, IV: %s -#>>>>>>>&1 regex/1 .* \b, Key: %s +#>>>&1 regex/1l .* \b, Password salt: %s +#>>>>&1 regex/1l .* \b, Master salt: %s +#>>>>>&1 regex/1l .* \b, PBKDF2 rounds: %s +#>>>>>>&1 regex/1l .* \b, IV: %s +#>>>>>>>&1 regex/1l .* \b, Key: %s + +# *.pit files by Joerg Jenderek +# http://forum.xda-developers.com/showthread.php?p=9122369 +# http://forum.xda-developers.com/showthread.php?t=816449 +# Partition Information Table for Samsung's smartphone with Android +# used by flash software Odin +0 ulelong 0x12349876 +# 1st pit entry marker +>0x01C ulequad&0xFFFFFFFCFFFFFFFC =0x0000000000000000 +# minimal 13 and maximal 18 PIT entries found +>>4 ulelong <128 Partition Information Table for Samsung smartphone +>>>4 ulelong x \b, %d entries +# 1. pit entry +>>>4 ulelong >0 \b; #1 +>>>0x01C use PIT-entry +>>>4 ulelong >1 \b; #2 +>>>0x0A0 use PIT-entry +>>>4 ulelong >2 \b; #3 +>>>0x124 use PIT-entry +>>>4 ulelong >3 \b; #4 +>>>0x1A8 use PIT-entry +>>>4 ulelong >4 \b; #5 +>>>0x22C use PIT-entry +>>>4 ulelong >5 \b; #6 +>>>0x2B0 use PIT-entry +>>>4 ulelong >6 \b; #7 +>>>0x334 use PIT-entry +>>>4 ulelong >7 \b; #8 +>>>0x3B8 use PIT-entry +>>>4 ulelong >8 \b; #9 +>>>0x43C use PIT-entry +>>>4 ulelong >9 \b; #10 +>>>0x4C0 use PIT-entry +>>>4 ulelong >10 \b; #11 +>>>0x544 use PIT-entry +>>>4 ulelong >11 \b; #12 +>>>0x5C8 use PIT-entry +>>>4 ulelong >12 \b; #13 +>>>>0x64C use PIT-entry +# 14. pit entry +>>>4 ulelong >13 \b; #14 +>>>>0x6D0 use PIT-entry +>>>4 ulelong >14 \b; #15 +>>>0x754 use PIT-entry +>>>4 ulelong >15 \b; #16 +>>>0x7D8 use PIT-entry +>>>4 ulelong >16 \b; #17 +>>>0x85C use PIT-entry +# 18. pit entry +>>>4 ulelong >17 \b; #18 +>>>0x8E0 use PIT-entry + +0 name PIT-entry +# garbage value implies end of pit entries +>0x00 ulequad&0xFFFFFFFCFFFFFFFC =0x0000000000000000 +# skip empty partition name +>>0x24 ubyte !0 +# partition name +>>>0x24 string >\0 %-.32s +# flags +>>>0x0C ulelong&0x00000002 2 \b+RW +# partition ID: +# 0~IPL,MOVINAND,GANG;1~PIT,GPT;2~HIDDEN;3~SBL,HIDDEN;4~SBL2,HIDDEN;5~BOOT;6~KENREl,RECOVER,misc;7~RECOVER +# ;11~MODEM;20~efs;21~PARAM;22~FACTORY,SYSTEM;23~DBDATAFS,USERDATA;24~CACHE;80~BOOTLOADER;81~TZSW +>>>0x08 ulelong x (0x%x) +# filename +>>>0x44 string >\0 "%-.64s" +#>>>0x18 ulelong >0 +# blocksize in 512 byte units ? +#>>>>0x18 ulelong x \b, %db +# partition size in blocks ? +#>>>>0x22 ulelong x \b*%d + +# Android bootimg format +# From https://android.googlesource.com/\ +# platform/system/core/+/master/libsparse/sparse_format.h +0 lelong 0xed26ff3a Android sparse image +>4 leshort x \b, version: %d +>6 leshort x \b.%d +>16 lelong x \b, Total of %d +>12 lelong x \b %d-byte output blocks in +>20 lelong x \b %d input chunks. diff --git a/contrib/file/magic/Magdir/animation b/contrib/file/magic/Magdir/animation index 198b8c5a23..0445adc614 100644 --- a/contrib/file/magic/Magdir/animation +++ b/contrib/file/magic/Magdir/animation @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: animation,v 1.51 2014/03/14 18:47:29 christos Exp $ +# $File: animation,v 1.56 2014/10/23 23:12:51 christos Exp $ # animation: file(1) magic for animation/movie formats # # animation formats @@ -32,43 +32,155 @@ !:mime application/x-quicktime-player 4 string/W jP JPEG 2000 image !:mime image/jp2 +# http://www.ftyps.com/ with local additions 4 string ftyp ISO Media ->8 string isom \b, MPEG v4 system, version 1 -!:mime video/mp4 ->8 string iso2 \b, MPEG v4 system, part 12 revision ->8 string mp41 \b, MPEG v4 system, version 1 -!:mime video/mp4 ->8 string mp42 \b, MPEG v4 system, version 2 -!:mime video/mp4 ->8 string mp7t \b, MPEG v4 system, MPEG v7 XML ->8 string mp7b \b, MPEG v4 system, MPEG v7 binary XML ->8 string/W jp2 \b, JPEG 2000 -!:mime image/jp2 +>8 string 3g2 \b, MPEG v4 system, 3GPP2 +!:mime video/3gpp2 +>>11 byte 4 \b v4 (H.263/AMR GSM 6.10) +>>11 byte 5 \b v5 (H.263/AMR GSM 6.10) +>>11 byte 6 \b v6 (ITU H.264/AMR GSM 6.10) +>>11 byte a \b C.S0050-0 V1.0 +>>11 byte b \b C.S0050-0-A V1.0.0 +>>11 byte c \b C.S0050-0-B V1.0 >8 string 3ge \b, MPEG v4 system, 3GPP !:mime video/3gpp +>>11 byte 6 \b, Release 6 MBMS Extended Presentations +>>11 byte 7 \b, Release 7 MBMS Extended Presentations >8 string 3gg \b, MPEG v4 system, 3GPP +>11 byte 6 \b, Release 6 General Profile !:mime video/3gpp >8 string 3gp \b, MPEG v4 system, 3GPP +>11 byte 1 \b, Release %d (non existent) +>11 byte 2 \b, Release %d (non existent) +>11 byte 3 \b, Release %d (non existent) +>11 byte 4 \b, Release %d +>11 byte 5 \b, Release %d +>11 byte 6 \b, Release %d +>11 byte 7 \b, Release %d Streaming Servers !:mime video/3gpp >8 string 3gs \b, MPEG v4 system, 3GPP +>11 byte 7 \b, Release %d Streaming Servers !:mime video/3gpp ->8 string 3g2 \b, MPEG v4 system, 3GPP2 +>8 string avc1 \b, MPEG v4 system, 3GPP JVT AVC [ISO 14496-12:2005] +!:mime video/mp4 +>8 string/W qt \b, Apple QuickTime movie +!:mime video/quicktime +>8 string CAEP \b, Canon Digital Camera +>8 string caqv \b, Casio Digital Camera +>8 string CDes \b, Convergent Design +>8 string da0a \b, DMB MAF w/ MPEG Layer II aud, MOT slides, DLS, JPG/PNG/MNG +>8 string da0b \b, DMB MAF, ext DA0A, with 3GPP timed text, DID, TVA, REL, IPMP +>8 string da1a \b, DMB MAF audio with ER-BSAC audio, JPG/PNG/MNG images +>8 string da1b \b, DMB MAF, ext da1a, with 3GPP timed text, DID, TVA, REL, IPMP +>8 string da2a \b, DMB MAF aud w/ HE-AAC v2 aud, MOT slides, DLS, JPG/PNG/MNG +>8 string da2b \b, DMB MAF, ext da2a, with 3GPP timed text, DID, TVA, REL, IPMP +>8 string da3a \b, DMB MAF aud with HE-AAC aud, JPG/PNG/MNG images +>8 string da3b \b, DMB MAF, ext da3a w/ BIFS, 3GPP, DID, TVA, REL, IPMP +>8 string dmb1 \b, DMB MAF supporting all the components defined in the spec +>8 string dmpf \b, Digital Media Project +>8 string drc1 \b, Dirac (wavelet compression), encap in ISO base media (MP4) +>8 string dv1a \b, DMB MAF vid w/ AVC vid, ER-BSAC aud, BIFS, JPG/PNG/MNG, TS +>8 string dv1b \b, DMB MAF, ext dv1a, with 3GPP timed text, DID, TVA, REL, IPMP +>8 string dv2a \b, DMB MAF vid w/ AVC vid, HE-AAC v2 aud, BIFS, JPG/PNG/MNG, TS +>8 string dv2b \b, DMB MAF, ext dv2a, with 3GPP timed text, DID, TVA, REL, IPMP +>8 string dv3a \b, DMB MAF vid w/ AVC vid, HE-AAC aud, BIFS, JPG/PNG/MNG, TS +>8 string dv3b \b, DMB MAF, ext dv3a, with 3GPP timed text, DID, TVA, REL, IPMP +>8 string dvr1 \b, DVB (.DVB) over RTP +!:mime video/vnd.dvb.file +>8 string dvt1 \b, DVB (.DVB) over MPEG-2 Transport Stream +!:mime video/vnd.dvb.file +>8 string F4V \b, Video for Adobe Flash Player 9+ (.F4V) +!:mime video/mp4 +>8 string F4P \b, Protected Video for Adobe Flash Player 9+ (.F4P) +!:mime video/mp4 +>8 string F4A \b, Audio for Adobe Flash Player 9+ (.F4A) +!:mime audio/mp4 +>8 string F4B \b, Audio Book for Adobe Flash Player 9+ (.F4B) +!:mime audio/mp4 +>8 string isc2 \b, ISMACryp 2.0 Encrypted File +# ?/enc-isoff-generic +>8 string iso2 \b, MP4 Base Media v2 [ISO 14496-12:2005] +!:mime video/mp4 +>8 string isom \b, MP4 Base Media v1 [IS0 14496-12:2003] +!:mime video/mp4 +>8 string/W jp2 \b, JPEG 2000 +!:mime image/jp2 +>8 string JP2 \b, JPEG 2000 Image (.JP2) [ISO 15444-1 ?] +!:mime image/jp2 +>8 string JP20 \b, Unknown, from GPAC samples (prob non-existent) +>8 string jpm \b, JPEG 2000 Compound Image (.JPM) [ISO 15444-6] +!:mime image/jpm +>8 string jpx \b, JPEG 2000 w/ extensions (.JPX) [ISO 15444-2] +!:mime image/jpx +>8 string KDDI \b, 3GPP2 EZmovie for KDDI 3G cellphones !:mime video/3gpp2 ->>11 byte 4 \b v4 (H.263/AMR GSM 6.10) ->>11 byte 5 \b v5 (H.263/AMR GSM 6.10) ->>11 byte 6 \b v6 (ITU H.264/AMR GSM 6.10) +>8 string M4A \b, Apple iTunes ALAC/AAC-LC (.M4A) Audio +!:mime audio/x-m4a +>8 string M4B \b, Apple iTunes ALAC/AAC-LC (.M4B) Audio Book +!:mime audio/mp4 +>8 string M4P \b, Apple iTunes ALAC/AAC-LC (.M4P) AES Protected Audio +!:mime video/mp4 +>8 string M4V \b, Apple iTunes Video (.M4V) Video +!:mime video/x-m4v +>8 string M4VH \b, Apple TV (.M4V) +!:mime video/x-m4v +>8 string M4VP \b, Apple iPhone (.M4V) +!:mime video/x-m4v +>8 string mj2s \b, Motion JPEG 2000 [ISO 15444-3] Simple Profile +!:mime video/mj2 +>8 string mjp2 \b, Motion JPEG 2000 [ISO 15444-3] General Profile +!:mime video/mj2 +>8 string mmp4 \b, MPEG-4/3GPP Mobile Profile (.MP4 / .3GP) (for NTT) +!:mime video/mp4 +>8 string mobi \b, MPEG-4, MOBI format +!:mime video/mp4 +>8 string mp21 \b, MPEG-21 [ISO/IEC 21000-9] +>8 string mp41 \b, MP4 v1 [ISO 14496-1:ch13] +!:mime video/mp4 +>8 string mp42 \b, MP4 v2 [ISO 14496-14] +!:mime video/mp4 +>8 string mp71 \b, MP4 w/ MPEG-7 Metadata [per ISO 14496-12] +>8 string mp7t \b, MPEG v4 system, MPEG v7 XML +>8 string mp7b \b, MPEG v4 system, MPEG v7 binary XML >8 string mmp4 \b, MPEG v4 system, 3GPP Mobile !:mime video/mp4 ->8 string avc1 \b, MPEG v4 system, 3GPP JVT AVC -!:mime video/3gpp ->8 string/W M4A \b, MPEG v4 system, iTunes AAC-LC +>8 string MPPI \b, Photo Player, MAF [ISO/IEC 23000-3] +>8 string mqt \b, Sony / Mobile QuickTime (.MQV) US Pat 7,477,830 +!:mime video/quicktime +>8 string MSNV \b, MPEG-4 (.MP4) for SonyPSP +!:mime audio/mp4 +>8 string NDAS \b, MP4 v2 [ISO 14496-14] Nero Digital AAC Audio !:mime audio/mp4 ->8 string/W M4V \b, MPEG v4 system, iTunes AVC-LC +>8 string NDSC \b, MPEG-4 (.MP4) Nero Cinema Profile !:mime video/mp4 ->8 string/W M4P \b, MPEG v4 system, iTunes AES encrypted ->8 string/W M4B \b, MPEG v4 system, iTunes bookmarked ->8 string/W qt \b, Apple QuickTime movie +>8 string NDSH \b, MPEG-4 (.MP4) Nero HDTV Profile +!:mime video/mp4 +>8 string NDSM \b, MPEG-4 (.MP4) Nero Mobile Profile +!:mime video/mp4 +>8 string NDSP \b, MPEG-4 (.MP4) Nero Portable Profile +!:mime video/mp4 +>8 string NDSS \b, MPEG-4 (.MP4) Nero Standard Profile +!:mime video/mp4 +>8 string NDXC \b, H.264/MPEG-4 AVC (.MP4) Nero Cinema Profile +!:mime video/mp4 +>8 string NDXH \b, H.264/MPEG-4 AVC (.MP4) Nero HDTV Profile +!:mime video/mp4 +>8 string NDXM \b, H.264/MPEG-4 AVC (.MP4) Nero Mobile Profile +!:mime video/mp4 +>8 string NDXP \b, H.264/MPEG-4 AVC (.MP4) Nero Portable Profile +!:mime video/mp4 +>8 string NDXS \b, H.264/MPEG-4 AVC (.MP4) Nero Standard Profile +!:mime video/mp4 +>8 string odcf \b, OMA DCF DRM Format 2.0 (OMA-TS-DRM-DCF-V2_0-20060303-A) +>8 string opf2 \b, OMA PDCF DRM Format 2.1 (OMA-TS-DRM-DCF-V2_1-20070724-C) +>8 string opx2 \b, OMA PDCF DRM + XBS ext (OMA-TS-DRM_XBS-V1_0-20070529-C) +>8 string pana \b, Panasonic Digital Camera +>8 string qt \b, Apple QuickTime (.MOV/QT) !:mime video/quicktime +>8 string ROSS \b, Ross Video +>8 string sdv \b, SD Memory Card Video +>8 string ssc1 \b, Samsung stereo, single stream (patent pending) +>8 string ssc2 \b, Samsung stereo, dual stream (patent pending) # MPEG sequences # Scans for all common MPEG header start codes @@ -621,7 +733,7 @@ # Live MPEG-4 audio streams (instead of RTP FlexMux) 0 beshort&0xFFE0 0x56E0 MPEG-4 LOAS !:mime audio/x-mp4a-latm -#>1 beshort&0x1FFF x \b, %u byte packet +#>1 beshort&0x1FFF x \b, %hu byte packet >3 byte&0xE0 0x40 >>4 byte&0x3C 0x04 \b, single stream >>4 byte&0x3C 0x08 \b, 2 streams @@ -719,16 +831,16 @@ !:mime video/x-mng >4 belong !0x0d0a1a0a CORRUPTED, >4 belong 0x0d0a1a0a ->>16 belong x %ld x ->>20 belong x %ld +>>16 belong x %d x +>>20 belong x %d # JNG Video Format, 0 string \x8bJNG JNG video data, !:mime video/x-jng >4 belong !0x0d0a1a0a CORRUPTED, >4 belong 0x0d0a1a0a ->>16 belong x %ld x ->>20 belong x %ld +>>16 belong x %d x +>>20 belong x %d # Vivo video (Wolfram Kleff) 3 string \x0D\x0AVersion:Vivo Vivo video data diff --git a/contrib/file/magic/Magdir/apple b/contrib/file/magic/Magdir/apple index 633c01271b..e3dd059f8a 100644 --- a/contrib/file/magic/Magdir/apple +++ b/contrib/file/magic/Magdir/apple @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: apple,v 1.27 2013/03/09 22:36:00 christos Exp $ +# $File: apple,v 1.29 2014/04/30 21:41:02 christos Exp $ # apple: file(1) magic for Apple file formats # 0 search/1/t FiLeStArTfIlEsTaRt binscii (apple ][) text @@ -204,15 +204,15 @@ # purposes in YellowStep/Cocoa, including some nib files. # From: David Remahl 2 string typedstream NeXT/Apple typedstream data, big endian ->0 byte x \b, version %hhd +>0 byte x \b, version %d >0 byte <5 \b >>13 byte 0x81 \b ->>>14 ubeshort x \b, system %hd +>>>14 ubeshort x \b, system %d 2 string streamtyped NeXT/Apple typedstream data, little endian ->0 byte x \b, version %hhd +>0 byte x \b, version %d >0 byte <5 \b >>13 byte 0x81 \b ->>>14 uleshort x \b, system %hd +>>>14 uleshort x \b, system %d #------------------------------------------------------------------------------ # CAF: Apple CoreAudio File Format diff --git a/contrib/file/magic/Magdir/archive b/contrib/file/magic/Magdir/archive index 32f8592f9f..4ef73a7d72 100644 --- a/contrib/file/magic/Magdir/archive +++ b/contrib/file/magic/Magdir/archive @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# $File: archive,v 1.82 2014/03/14 18:47:29 christos Exp $ +# $File: archive,v 1.88 2014/08/16 10:42:17 christos Exp $ # archive: file(1) magic for archive formats (see also "msdos" for self- # extracting compressed archives) # @@ -93,9 +93,9 @@ # 0 string =!\ndebian >8 string debian-split part of multipart Debian package -!:mime application/x-debian-package +!:mime application/vnd.debian.binary-package >8 string debian-binary Debian binary package -!:mime application/x-debian-package +!:mime application/vnd.debian.binary-package >8 string !debian >68 string >\0 (format %s) # These next two lines do not work, because a bzip2 Debian archive @@ -269,7 +269,7 @@ >9 string \0 >>0 string KWAJ >>>7 string \321\003 MS Compress archive data ->>>>14 ulong >0 \b, original size: %ld bytes +>>>>14 ulong >0 \b, original size: %d bytes >>>>18 ubyte >0x65 >>>>>18 string x \b, was %.8s >>>>>(10.b-4) string x \b.%.3s @@ -498,7 +498,7 @@ # This is a really bad format. A file containing HAWAII will match this... #0 string HA HA archive data, #>2 leshort =1 1 file, -#>2 leshort >1 %u files, +#>2 leshort >1 %hu files, #>4 byte&0x0f =0 first is type CPY #>4 byte&0x0f =1 first is type ASC #>4 byte&0x0f =2 first is type HSC @@ -874,7 +874,7 @@ # From: Dirk Jagdmann # xar archive format: http://code.google.com/p/xar/ 0 string xar! xar archive ->6 beshort x - version %ld +>6 beshort x - version %d # From: "Nelson A. de Oliveira" # .kgb @@ -921,3 +921,36 @@ >36 byte 16 \b, back-to-front >42 beshort x \b, (%dx, >44 beshort x %d) + +# Symantec GHOST image by Joerg Jenderek at May 2014 +# http://us.norton.com/ghost/ +# http://www.garykessler.net/library/file_sigs.html +0 ubelong&0xFFFFf7f0 0xFEEF0100 Norton GHost image +# *.GHO +>2 ubyte&0x08 0x00 \b, first file +# *.GHS or *.[0-9] with cns program option +>2 ubyte&0x08 0x08 \b, split file +# part of split index interesting for *.ghs +>>4 ubyte x id=0x%x +# compression tag minus one equals numeric compression command line switch z[1-9] +>3 ubyte 0 \b, no compression +>3 ubyte 2 \b, fast compression (Z1) +>3 ubyte 3 \b, medium compression (Z2) +>3 ubyte >3 +>>3 ubyte <11 \b, compression (Z%d-1) +>2 ubyte&0x08 0x00 +# ~ 30 byte password field only for *.gho +>>12 ubequad !0 \b, password protected +>>44 ubyte !1 +# 1~Image All, sector-by-sector only for *.gho +>>>10 ubyte 1 \b, sector copy +# 1~Image Boot track only for *.gho +>>>43 ubyte 1 \b, boot track +# 1~Image Disc only for *.gho implies Image Boot track and sector copy +>>44 ubyte 1 \b, disc sector copy +# optional image description only *.gho +>>0xff string >\0 "%-.254s" +# look for DOS sector end sequence +>0xE08 search/7776 \x55\xAA +>>&-512 indirect x \b; contains + diff --git a/contrib/file/magic/Magdir/att3b b/contrib/file/magic/Magdir/att3b index 96880111e0..a3ed9c0037 100644 --- a/contrib/file/magic/Magdir/att3b +++ b/contrib/file/magic/Magdir/att3b @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: att3b,v 1.8 2009/09/19 16:28:08 christos Exp $ +# $File: att3b,v 1.9 2014/04/30 21:41:02 christos Exp $ # att3b: file(1) magic for AT&T 3B machines # # The `versions' should be un-commented if they work for you. @@ -11,10 +11,10 @@ # The 3B20 conflicts with SCCS. #0 beshort 0550 3b20 COFF executable #>12 belong >0 not stripped -#>22 beshort >0 - version %ld +#>22 beshort >0 - version %d #0 beshort 0551 3b20 COFF executable (TV) #>12 belong >0 not stripped -#>22 beshort >0 - version %ld +#>22 beshort >0 - version %d # # WE32K # @@ -29,12 +29,12 @@ >20 beshort 0410 (pure) >20 beshort 0413 (demand paged) >20 beshort 0443 (target shared library) ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 0561 WE32000 COFF executable (TV) >12 belong >0 not stripped #>18 beshort &00020000 - 32100 required #>18 beshort &00040000 and MAU hardware required -#>22 beshort >0 - version %ld +#>22 beshort >0 - version %d # # core file for 3b2 0 string \000\004\036\212\200 3b2 core file diff --git a/contrib/file/magic/Magdir/audio b/contrib/file/magic/Magdir/audio index ced932480e..338d8aebda 100644 --- a/contrib/file/magic/Magdir/audio +++ b/contrib/file/magic/Magdir/audio @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: audio,v 1.68 2013/12/02 13:32:26 christos Exp $ +# $File: audio,v 1.71 2014/05/14 23:30:28 christos Exp $ # audio: file(1) magic for sound formats (see also "iff") # # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com), @@ -104,7 +104,7 @@ # first entry is also the string "NTRK" 0 belong 0x4e54524b MultiTrack sound data ->4 belong x - version %ld +>4 belong x - version %d # Extended MOD format (*.emd) (Greg Roelofs, newt@uchicago.edu); NOT TESTED # [based on posting 940824 by "Dirk/Elastik", husberg@lehtori.cc.tut.fi] @@ -638,7 +638,7 @@ # From: Mike Melanson 0 string wvpk WavPack Lossless Audio -# From Fábio R. Schmidlin +# From Fabio R. Schmidlin # VGM music file 0 string Vgm\ >9 ubyte >0 VGM Video Game Music dump v diff --git a/contrib/file/magic/Magdir/bflt b/contrib/file/magic/Magdir/bflt index 03eb59d34a..c46b4dbb4b 100644 --- a/contrib/file/magic/Magdir/bflt +++ b/contrib/file/magic/Magdir/bflt @@ -1,12 +1,12 @@ #------------------------------------------------------------------------------ -# $File: bflt,v 1.4 2009/09/19 16:28:08 christos Exp $ +# $File: bflt,v 1.5 2014/04/30 21:41:02 christos Exp $ # bFLT: file(1) magic for BFLT uclinux binary files # # From Philippe De Muyter # 0 string bFLT BFLT executable ->4 belong x - version %ld +>4 belong x - version %d >4 belong 4 >>36 belong&0x1 0x1 ram >>36 belong&0x2 0x2 gotpic diff --git a/contrib/file/magic/Magdir/blender b/contrib/file/magic/Magdir/blender index 1814738ab4..5b9c8556e5 100644 --- a/contrib/file/magic/Magdir/blender +++ b/contrib/file/magic/Magdir/blender @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: blender,v 1.5 2009/09/19 16:28:08 christos Exp $ +# $File: blender,v 1.6 2014/08/30 08:34:17 christos Exp $ # blender: file(1) magic for Blender 3D related files # # Native format rule v1.2. For questions use the developers list @@ -35,5 +35,5 @@ >>>0x44 string =GLOB \b. >>>>0x60 beshort x \b%.4d -# Scripts that run in the embeded Python interpreter +# Scripts that run in the embedded Python interpreter 0 string #!BPY Blender3D BPython script diff --git a/contrib/file/magic/Magdir/bsdi b/contrib/file/magic/Magdir/bsdi index e8a6c358cf..8499b0c903 100644 --- a/contrib/file/magic/Magdir/bsdi +++ b/contrib/file/magic/Magdir/bsdi @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: bsdi,v 1.6 2013/01/09 22:37:24 christos Exp $ +# $File: bsdi,v 1.7 2014/03/29 15:40:34 christos Exp $ # bsdi: file(1) magic for BSD/OS (from BSDI) objects # Some object/executable formats use the same magic numbers as are used # in other OSes; those are handled by entries in aout. @@ -11,7 +11,7 @@ >32 byte 0x6a (uses shared libs) # same as in SunOS 4.x, except for static shared libraries -0 belong&077777777 0600413 sparc demand paged +0 belong&077777777 0600413 SPARC demand paged >0 byte &0x80 >>20 belong <4096 shared library >>20 belong =4096 dynamically linked executable @@ -20,13 +20,13 @@ >16 belong >0 not stripped >36 belong 0xb4100001 (uses shared libs) -0 belong&077777777 0600410 sparc pure +0 belong&077777777 0600410 SPARC pure >0 byte &0x80 dynamically linked executable >0 byte ^0x80 executable >16 belong >0 not stripped >36 belong 0xb4100001 (uses shared libs) -0 belong&077777777 0600407 sparc +0 belong&077777777 0600407 SPARC >0 byte &0x80 dynamically linked executable >0 byte ^0x80 executable >16 belong >0 not stripped diff --git a/contrib/file/magic/Magdir/c-lang b/contrib/file/magic/Magdir/c-lang index cd17648a0e..39889ec1cf 100644 --- a/contrib/file/magic/Magdir/c-lang +++ b/contrib/file/magic/Magdir/c-lang @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# $File: c-lang,v 1.18 2013/08/14 13:06:43 christos Exp $ +# $File: c-lang,v 1.19 2014/06/03 19:17:27 christos Exp $ # c-lang: file(1) magic for C and related languages programs # @@ -50,7 +50,7 @@ >7 string x version %.2s # We skip the path here, because it is often long (so file will # truncate it) and mostly redundant. -# The inverted index functionality was added some time betwen +# The inverted index functionality was added some time between # versions 11 and 15, so look for -q if version is above 14: >7 string >14 >>10 search/100 \ -q\ with inverted index diff --git a/contrib/file/magic/Magdir/cafebabe b/contrib/file/magic/Magdir/cafebabe index 0afcb8dc55..4c58fc6c93 100644 --- a/contrib/file/magic/Magdir/cafebabe +++ b/contrib/file/magic/Magdir/cafebabe @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: cafebabe,v 1.15 2014/03/14 18:47:29 christos Exp $ +# $File: cafebabe,v 1.17 2015/01/01 17:07:00 christos Exp $ # Cafe Babes unite! # # Since Java bytecode and Mach-O universal binaries have the same magic number, @@ -45,14 +45,14 @@ 0 name mach-o \b [ >0 use mach-o-cpu \b ->&(8.L) indirect \b: +>(8.L) indirect \b: >0 belong x \b] 0 belong 0xcafebabe >4 belong 1 Mach-O universal binary with 1 architecture: >>8 use mach-o \b >4 belong >1 ->>4 belong <20 Mach-O universal binary with %ld architectures: +>>4 belong <20 Mach-O universal binary with %d architectures: >>>8 use mach-o \b >>>28 use mach-o \b >>4 belong >2 diff --git a/contrib/file/magic/Magdir/clarion b/contrib/file/magic/Magdir/clarion index cff7a3bdd0..9fa0049dab 100644 --- a/contrib/file/magic/Magdir/clarion +++ b/contrib/file/magic/Magdir/clarion @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: clarion,v 1.4 2009/09/19 16:28:08 christos Exp $ +# $File: clarion,v 1.5 2014/04/30 21:41:02 christos Exp $ # clarion: file(1) magic for # Clarion Personal/Professional Developer # (v2 and above) # From: Julien Blache @@ -15,7 +15,7 @@ >2 leshort &0x0010 \b, compressed >2 leshort &0x0040 \b, read only # number of records ->5 lelong x \b, %ld records +>5 lelong x \b, %d records # Memo files 0 leshort 0x334d Clarion Developer (v2 and above) memo data diff --git a/contrib/file/magic/Magdir/claris b/contrib/file/magic/Magdir/claris index 3f447bc22b..0f7b591b77 100644 --- a/contrib/file/magic/Magdir/claris +++ b/contrib/file/magic/Magdir/claris @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: claris,v 1.6 2012/06/20 21:19:05 christos Exp $ +# $File: claris,v 1.7 2014/06/03 19:17:27 christos Exp $ # claris: file(1) magic for claris # "H. Nanosecond" # Claris Works a word processor, etc. @@ -20,7 +20,7 @@ # .cwk 0 string \002\000\210\003\102\117\102\117\000\001\206 Claris works document # .plt -0 string \020\341\000\000\010\010 Claris Works pallete files .plt +0 string \020\341\000\000\010\010 Claris Works palette files .plt # .msp a dictionary file I am not sure about this I have only one .msp file 0 string \002\271\262\000\040\002\000\164 Claris works dictionary diff --git a/contrib/file/magic/Magdir/clipper b/contrib/file/magic/Magdir/clipper index 9f47534059..98278ebf06 100644 --- a/contrib/file/magic/Magdir/clipper +++ b/contrib/file/magic/Magdir/clipper @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: clipper,v 1.6 2009/09/19 16:28:08 christos Exp $ +# $File: clipper,v 1.7 2014/04/30 21:41:02 christos Exp $ # clipper: file(1) magic for Intergraph (formerly Fairchild) Clipper. # # XXX - what byte order does the Clipper use? @@ -35,7 +35,7 @@ >20 short 0413 (demand paged) >20 short 0443 (target shared library) >12 long >0 not stripped ->22 short >0 - version %ld +>22 short >0 - version %d 0 short 0577 CLIPPER COFF executable >18 short&074000 000000 C1 R1 >18 short&074000 004000 C2 R1 @@ -47,7 +47,7 @@ >20 short 0413 (paged) >20 short 0443 (target shared library) >12 long >0 not stripped ->22 short >0 - version %ld +>22 short >0 - version %d >48 long&01 01 alignment trap enabled >52 byte 1 -Ctnc >52 byte 2 -Ctsw diff --git a/contrib/file/magic/Magdir/commands b/contrib/file/magic/Magdir/commands index 670bbe29d4..3d9748926e 100644 --- a/contrib/file/magic/Magdir/commands +++ b/contrib/file/magic/Magdir/commands @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: commands,v 1.48 2014/03/04 12:20:42 kim Exp $ +# $File: commands,v 1.51 2014/09/27 00:12:55 christos Exp $ # commands: file(1) magic for various shells and interpreters # #0 string/w : shell archive or script for antique kernel text @@ -56,7 +56,7 @@ !:mime text/x-awk 0 string/wt #!\ /usr/bin/awk awk script text executable !:mime text/x-awk -0 regex =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text +0 regex/4096 =^\\s{0,100}BEGIN\\s{0,100}[{] awk or perl script text # AT&T Bell Labs' Plan 9 shell 0 string/wt #!\ /bin/rc Plan 9 rc shell script text executable diff --git a/contrib/file/magic/Magdir/compress b/contrib/file/magic/Magdir/compress index 15602de2ca..beb8ebe66a 100644 --- a/contrib/file/magic/Magdir/compress +++ b/contrib/file/magic/Magdir/compress @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# $File: compress,v 1.54 2014/03/14 18:47:29 christos Exp $ +# $File: compress,v 1.62 2014/09/13 14:27:12 christos Exp $ # compress: file(1) magic for pure-compression formats (no archives) # # compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc. @@ -210,9 +210,12 @@ !:mime application/x-lrzip # http://fastcompression.blogspot.fi/2013/04/lz4-streaming-format-final.html -0 lelong 0x184d2204 LZ4 compressed data +0 lelong 0x184d2204 LZ4 compressed data (v1.4+) !:mime application/x-lz4 -0 lelong 0x184c2102 LZ4 compressed data, legacy format +# Added by osm0sis@xda-developers.com +0 lelong 0x184c2103 LZ4 compressed data (v1.0-v1.3) +!:mime application/x-lz4 +0 lelong 0x184c2102 LZ4 compressed data (v0.1-v0.9) !:mime application/x-lz4 # AFX compressed files (Wolfram Kleff) @@ -244,3 +247,17 @@ >0x4 lelong x \b, version %u >0x8 lelong x \b, %u entries +# Snappy framing format +# http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt +0 string \377\006\0\0sNaPpY snappy framed data +!:mime application/x-snappy-framed + +# qpress, http://www.quicklz.com/ +0 string qpress10 qpress compressed data +!:mime application/x-qpress + +# Zlib https://www.ietf.org/rfc/rfc6713.txt +0 beshort%31 =0 +>0 byte&0xf =8 +>>0 byte&0x80 =0 zlib compressed data +!:mime application/zlib diff --git a/contrib/file/magic/Magdir/cups b/contrib/file/magic/Magdir/cups index 54167fc04b..005a134586 100644 --- a/contrib/file/magic/Magdir/cups +++ b/contrib/file/magic/Magdir/cups @@ -1,12 +1,12 @@ #------------------------------------------------------------------------------ -# $File: cups,v 1.2 2012/11/02 21:50:29 christos Exp $ +# $File: cups,v 1.3 2014/05/28 19:50:41 christos Exp $ # Cups: file(1) magic for the cups raster file format # From: Laurent Martelli # http://www.cups.org/documentation.php/spec-raster.html # -0 name cups-be +0 name cups-le >280 lelong x \b, %d >284 lelong x \bx%d dpi >376 lelong x \b, %dx @@ -44,7 +44,7 @@ >3 string 2 Cups Raster version 2, Big Endian >3 string 3 Cups Raster version 3, Big Endian !:mime application/vnd.cups-raster ->0 use ^cups-be +>0 use ^cups-le # Cups Raster image format, Little Endian @@ -53,4 +53,4 @@ >0 string 2 Cups Raster version 2, Little Endian >0 string 3 Cups Raster version 3, Little Endian !:mime application/vnd.cups-raster ->0 use \^cups-be +>0 use cups-le diff --git a/contrib/file/magic/Magdir/database b/contrib/file/magic/Magdir/database index 584bbd68ee..b00252bc29 100644 --- a/contrib/file/magic/Magdir/database +++ b/contrib/file/magic/Magdir/database @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: database,v 1.37 2014/03/14 18:47:29 christos Exp $ +# $File: database,v 1.43 2014/10/28 15:47:39 christos Exp $ # database: file(1) magic for various databases # # extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk) @@ -9,9 +9,17 @@ # GDBM magic numbers # Will be maintained as part of the GDBM distribution in the future. # -0 belong 0x13579ace GNU dbm 1.x or ndbm database, big endian +0 belong 0x13579acd GNU dbm 1.x or ndbm database, big endian, 32-bit !:mime application/x-gdbm -0 lelong 0x13579ace GNU dbm 1.x or ndbm database, little endian +0 belong 0x13579ace GNU dbm 1.x or ndbm database, big endian, old +!:mime application/x-gdbm +0 belong 0x13579acf GNU dbm 1.x or ndbm database, big endian, 64-bit +!:mime application/x-gdbm +0 lelong 0x13579acd GNU dbm 1.x or ndbm database, little endian, 32-bit +!:mime application/x-gdbm +0 lelong 0x13579ace GNU dbm 1.x or ndbm database, little endian, old +!:mime application/x-gdbm +0 lelong 0x13579acf GNU dbm 1.x or ndbm database, little endian, 64-bit !:mime application/x-gdbm 0 string GDBM GNU dbm 2.x database !:mime application/x-gdbm @@ -105,7 +113,7 @@ >>8 quad 0 64bit aligned >>>16 bedouble 8.642135e+130 big-endian >>>>24 long 0 64bit long (s390x) ->>>>24 long !0 32bit long (hppa/mips/ppc/s390/sparc) +>>>>24 long !0 32bit long (hppa/mips/ppc/s390/SPARC) >>>16 ledouble 8.642135e+130 little-endian >>>>28 long 0 64bit long (alpha/amd64/ia64) >>>>28 long !0 32bit long (armel/mipsel) @@ -176,7 +184,7 @@ # database file >>>>>>>>>>>>0 ubyte x \b DBF >>>>>>>>>>>>4 lelong 0 \b, no records ->>>>>>>>>>>>4 lelong >0 \b, %ld record +>>>>>>>>>>>>4 lelong >0 \b, %d record # plural s appended >>>>>>>>>>>>>4 lelong >1 \bs # http://www.clicketyclick.dk/databases/xbase/format/dbf_check.html#CHECK_DBF @@ -202,27 +210,27 @@ # for multiple index files (*.MDX) Production flag,tag numbers(<=0x30),tag length(<=0x20), reserverd (NULL) >>>>>>>24 ubelong&0x0133f7ff >0 # test for reserved NULL byte ->>>>>>>>47 ubyte x +>>>>>>>>47 ubyte 0 # test for valid TAG key format (0x10 or 0) >>>>>>>>>559 ubyte&0xeF 0 # test MM <= 12 ->>>>>>>>>45 ubeshort <0x0C20 ->>>>>>>>>>45 ubyte >0 ->>>>>>>>>>>46 ubyte <32 ->>>>>>>>>>>>46 ubyte >0 +>>>>>>>>>>45 ubeshort <0x0C20 +>>>>>>>>>>>45 ubyte >0 +>>>>>>>>>>>>46 ubyte <32 +>>>>>>>>>>>>>46 ubyte >0 #!:mime application/x-mdx ->>>>>>>>>>>>>0 use xbase-type ->>>>>>>>>>>>>0 ubyte x \b MDX ->>>>>>>>>>>>>1 ubyte x \b, creation-date ->>>>>>>>>>>>>1 use xbase-date ->>>>>>>>>>>>>44 ubyte x \b, update-date ->>>>>>>>>>>>>44 use xbase-date +>>>>>>>>>>>>>>0 use xbase-type +>>>>>>>>>>>>>>0 ubyte x \b MDX +>>>>>>>>>>>>>>1 ubyte x \b, creation-date +>>>>>>>>>>>>>>1 use xbase-date +>>>>>>>>>>>>>>44 ubyte x \b, update-date +>>>>>>>>>>>>>>44 use xbase-date # No.of tags in use (1,2,5,12) ->>>>>>>>>>>>>28 uleshort x \b, %d +>>>>>>>>>>>>>>28 uleshort x \b, %d # No. of entries in tag (0x30) ->>>>>>>>>>>>>25 ubyte x \b/%d tags +>>>>>>>>>>>>>>25 ubyte x \b/%d tags # Length of tag ->>>>>>>>>>>>>26 ubyte x * %d +>>>>>>>>>>>>>>26 ubyte x * %d # 1st tag name_ >>>>>>>>>>>>>548 string x \b, 1st tag "%.11s" # 2nd tag name @@ -337,60 +345,103 @@ # dBASE III >>>>>>16 ubyte 3 # dBASE III DBT ->>>>>>>0 use xbase-memo-print -# dBASE IV DBT , FoxPro FPT or many PNG , ZIP , DBF garbage +>>>>>>>0 use dbase3-memo-print +# dBASE III DBT without version, dBASE IV DBT , FoxPro FPT , or many ZIP , DBF garbage >>>>>>16 ubyte 0 -# dBASE IV DBT with DBF name or DBF garbage ->>>>>>>8 ubelong >0x40000000 -# skip DBF and catch dBASE IV DBT with DBF name and with non big index of next free block ->>>>>>>>0 ulelong <0x01010002 ->>>>>>>>>0 use xbase-memo-print ->>>>>>>8 ubelong 0 +# unusual dBASE III DBT like angest.dbt, dBASE IV DBT with block size 0 , FoxPro FPT , or garbage PCX DBF +>>>>>>>20 uleshort 0 +# FoxPro FPT , unusual dBASE III DBT like biblio.dbt or garbage +>>>>>>>>8 ulong =0 +>>>>>>>>>6 ubeshort >0 +# skip emacs.PIF +>>>>>>>>>>4 ushort 0 +>>>>>>>>>>>0 use foxpro-memo-print +# dBASE III DBT , garbage +>>>>>>>>>6 ubeshort 0 # skip MM*DD*.bin by test for for reserved NULL byte ->>>>>>>>508 ubelong 0 -# real memo files should contain text here ->>>>>>>>>520 ubelong >0x20202019 ->>>>>>>>>>520 ubelong <0xFEFEFEFF ->>>>>>>>>>>0 use xbase-memo-print -# garbage PCX , ZIP , JAR , XPI ->>>>>>>8 default x +>>>>>>>>>>510 ubeshort 0 +# skip TK-DOS11.img image by looking for memo text +>>>>>>>>>>>512 ubelong <0xfeffff03 +# skip EFI executables by looking for memo text +>>>>>>>>>>>>512 ubelong >0x1F202020 +>>>>>>>>>>>>>513 ubyte >0 +# unusual dBASE III DBT like adressen.dbt +>>>>>>>>>>>>>>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 +>>>>>>>>>510 ubeshort 0 +# skip some DBF by test of invalid version +>>>>>>>>>>0 ubyte >5 +>>>>>>>>>>>0 ubyte <48 +>>>>>>>>>>>>0 use dbase3-memo-print +# dBASE IV DBT with positive block size +>>>>>>>20 uleshort >0 +>>>>>>>>0 use dbase4-memo-print -# Print the information of dBase DBT or FoxPro FPT memo files -0 name xbase-memo-print ->0 ubyte x -# test version -# memo file ->>16 ubyte 3 dBase III DBT ->>16 ubyte 0 ->>>512 ubelong <0x00000003 FoxPro FPT -# Size of blocks for FoxPro ->>>>6 ubeshort x \b, blocks size %lu -# Number of next available block for appending data for FoxPro ->>>>0 ubelong =0 \b, next free block index %lu ->>>>0 ubelong !0 \b, next free block index %lu ->>>512 default x dBase IV DBT -# DBF file name without extention ->>>>8 string >\0 \b of %-.8s.DBF -# size of blocks ; not reliable 0x2020204C -#>>>>4 ulelong =0 \b, blocks size %lu ->>>>4 ulelong !0 \b, blocks size %lu -# Block length found 0 , 512 -#>>>>20 uleshort =0 \b, block length %u ->>>>20 uleshort !0 \b, block length %u +# Print the information of dBase III DBT memo file +0 name dbase3-memo-print +>0 ubyte x dBase III DBT +# instead 3 as version number 0 for unusual examples like biblio.dbt +>16 ubyte !3 \b, version number %u # Number of next available block for appending data ->>>>0 ulelong =0 \b, next free block index %lu ->>>>0 ulelong !0 \b, next free block index %lu ->>512 ubelong x ->>>512 ubelong =0xFFFF0800 ->>>>520 string >\0 \b, 1st used item "%s" -# FoxPro ->>>512 ubelong <3 -# FoxPro memo ->>>>512 ubelong =1 ->>>>520 string >\0 \b, 1st used item "%s" ->>>512 default x -# may be deleted memo field ->>>>512 string >\0 \b, 1st item "%s" +#>0 lelong =0 \b, next free block index %u +>0 lelong !0 \b, next free block index %u +# no positiv block length +#>20 uleshort =0 \b, block length %u +>20 uleshort !0 \b, block length %u +# dBase III memo field terminated by \032\032 +>512 string >\0 \b, 1st item "%s" +# Print the information of dBase IV DBT memo file +0 name dbase4-memo-print +>0 lelong x dBase IV DBT +# 8 character shorted main name of coresponding dBASE IV DBF file +>8 ubelong >0x20000000 +# skip unusual like for angest.dbt +>>20 uleshort >0 +>>>8 string >\0 \b of %-.8s.DBF +# value 0 implies 512 as size +#>4 ulelong =0 \b, blocks size %u +# size of blocks not reliable like 0x2020204C in angest.dbt +>4 ulelong !0 +>>4 ulelong&0x0000003f 0 \b, blocks size %u +# dBase IV DBT with positive block length (found 512 , 1024) +>20 uleshort >0 \b, block length %u +# next available block +#>0 lelong =0 \b, next free block index %u +>0 lelong !0 \b, next free block index %u +>20 uleshort >0 +>>(20.s) ubelong x +>>>&-4 use dbase4-memofield-print +# unusual dBase IV DBT without block length (implies 512 as length) +>20 uleshort =0 +>>512 ubelong x +>>>&-4 use dbase4-memofield-print +# Print the information of dBase IV memo field +0 name dbase4-memofield-print +# free dBase IV memo field +>0 ubelong !0xFFFF0800 +>>0 lelong x \b, next free block %u +>>4 lelong x \b, next used block %u +# used dBase IV memo field +>0 ubelong =0xFFFF0800 +# length of memo field +>>4 lelong x \b, field length %d +>>>8 string >\0 \b, 1st used item "%s" +# Print the information of FoxPro FPT memo file +0 name foxpro-memo-print +>0 belong x FoxPro FPT +# Size of blocks for FoxPro ( 64,256 ) +>6 ubeshort x \b, blocks size %u +# next available block +#>0 belong =0 \b, next free block index %u +>0 belong !0 \b, next free block index %u +# field type ( 0~picture, 1~memo, 2~object ) +>512 ubelong <3 \b, field type %u +# length of memo field +>512 ubelong 1 +>>516 belong >0 \b, field length %d +>>>520 string >\0 \b, 1st item "%s" # TODO: # DBASE index file *.NDX diff --git a/contrib/file/magic/Magdir/dump b/contrib/file/magic/Magdir/dump index b4a7240e55..1a20ace29c 100644 --- a/contrib/file/magic/Magdir/dump +++ b/contrib/file/magic/Magdir/dump @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: dump,v 1.12 2012/11/01 04:26:40 christos Exp $ +# $File: dump,v 1.13 2014/04/30 21:41:02 christos Exp $ # dump: file(1) magic for dump file format--for new and old dump filesystems # # We specify both byte orders in order to recognize byte-swapped dumps. @@ -8,7 +8,7 @@ 0 name new-dump-be >4 bedate x Previous dump %s, >8 bedate x This dump %s, ->12 belong >0 Volume %ld, +>12 belong >0 Volume %d, >692 belong 0 Level zero, type: >692 belong >0 Level %d, type: >0 belong 1 tape header, @@ -27,7 +27,7 @@ 0 name old-dump-be #>4 bedate x Previous dump %s, #>8 bedate x This dump %s, ->12 belong >0 Volume %ld, +>12 belong >0 Volume %d, >692 belong 0 Level zero, type: >692 belong >0 Level %d, type: >0 belong 1 tape header, @@ -46,7 +46,7 @@ 0 name ufs2-dump-be >896 beqdate x Previous dump %s, >904 beqdate x This dump %s, ->12 belong >0 Volume %ld, +>12 belong >0 Volume %d, >692 belong 0 Level zero, type: >692 belong >0 Level %d, type: >0 belong 1 tape header, @@ -84,7 +84,7 @@ 18 leshort 60011 old-fs dump file (16-bit, assuming PDP-11 endianness), >2 medate x Previous dump %s, >6 medate x This dump %s, ->10 leshort >0 Volume %ld, +>10 leshort >0 Volume %d, >0 leshort 1 tape header. >0 leshort 2 beginning of file record. >0 leshort 3 map of inodes on tape. diff --git a/contrib/file/magic/Magdir/dyadic b/contrib/file/magic/Magdir/dyadic index c1a2c3c53e..18f18bcf17 100644 --- a/contrib/file/magic/Magdir/dyadic +++ b/contrib/file/magic/Magdir/dyadic @@ -1,46 +1,56 @@ #------------------------------------------------------------------------------ -# $File: dyadic,v 1.5 2010/09/20 18:55:20 rrt Exp $ +# $File: dyadic,v 1.6 2014/06/01 19:14:42 christos Exp $ # Dyadic: file(1) magic for Dyalog APL. # -0 byte 0xaa ->1 byte <4 Dyalog APL ->>1 byte 0x00 incomplete workspace ->>1 byte 0x01 component file ->>1 byte 0x02 external variable ->>1 byte 0x03 workspace ->>2 byte x version %d ->>3 byte x .%d - -0 beshort 0xaa03 Dyalog APL ->2 byte x workspace type %d ->3 byte x subtype %d ->7 byte&0x28 0x00 32-bit ->7 byte&0x28 0x20 64-bit ->7 byte&0x0c 0x00 classic ->7 byte&0x0c 0x04 unicode ->7 byte&0x88 0x00 big-endian ->7 byte&0x88 0x80 little-endian - -0 byte 0xaa Dyalog APL ->1 byte 0x00 aplcore ->1 byte 0x01 component file 32-bit non-journaled non-checksummed ->1 byte 0x02 external variable exclusive ->1 byte 0x06 external variable shared ->1 byte 0x07 session ->1 byte 0x08 mapped file 32-bit ->1 byte 0x09 component file 64-bit non-journaled non-checksummed ->1 byte 0x0a mapped file 64-bit ->1 byte 0x0b component file 32-bit level 1 journaled non-checksummed ->1 byte 0x0c component file 64-bit level 1 journaled non-checksummed ->1 byte 0x0d component file 32-bit level 1 journaled checksummed ->1 byte 0x0e component file 64-bit level 1 journaled checksummed ->1 byte 0x0f component file 32-bit level 2 journaled checksummed ->1 byte 0x10 component file 64-bit level 2 journaled checksummed ->1 byte 0x11 component file 32-bit level 3 journaled checksummed ->1 byte 0x12 component file 64-bit level 3 journaled checksummed ->1 byte 0x13 component file 32-bit non-journaled checksummed ->1 byte 0x14 component file 64-bit non-journaled checksummed ->1 byte 0x80 DDB +# updated by Joerg Jenderek at Oct 2013 +# http://en.wikipedia.org/wiki/Dyalog_APL +# http://www.dyalog.com/ +# .DXV Dyalog APL External Variable +# .DIN Dyalog APL Input Table +# .DOT Dyalog APL Output Table +# .DFT Dyalog APL Format File +0 ubeshort&0xFF60 0xaa00 +# skip biblio.dbt +>1 byte !4 +# real Dyalog APL have non zero version numbers like 7.3 or 13.4 +>>2 ubeshort >0x0000 Dyalog APL +>>>1 byte 0x00 aplcore +#>>>1 byte 0x00 incomplete workspace +# *.DCF Dyalog APL Component File +>>>1 byte 0x01 component file 32-bit non-journaled non-checksummed +#>>>1 byte 0x01 component file +>>>1 byte 0x02 external variable exclusive +#>>>1 byte 0x02 external variable +# *.DWS Dyalog APL Workspace +>>>1 byte 0x03 workspace +>>>>7 byte&0x28 0x00 32-bit +>>>>7 byte&0x28 0x20 64-bit +>>>>7 byte&0x0c 0x00 classic +>>>>7 byte&0x0c 0x04 unicode +>>>>7 byte&0x88 0x00 big-endian +>>>>7 byte&0x88 0x80 little-endian +>>>1 byte 0x06 external variable shared +# *.DSE Dyalog APL Session , *.DLF Dyalog APL Session Log File +>>>1 byte 0x07 session +>>>1 byte 0x08 mapped file 32-bit +>>>1 byte 0x09 component file 64-bit non-journaled non-checksummed +>>>1 byte 0x0a mapped file 64-bit +>>>1 byte 0x0b component file 32-bit level 1 journaled non-checksummed +>>>1 byte 0x0c component file 64-bit level 1 journaled non-checksummed +>>>1 byte 0x0d component file 32-bit level 1 journaled checksummed +>>>1 byte 0x0e component file 64-bit level 1 journaled checksummed +>>>1 byte 0x0f component file 32-bit level 2 journaled checksummed +>>>1 byte 0x10 component file 64-bit level 2 journaled checksummed +>>>1 byte 0x11 component file 32-bit level 3 journaled checksummed +>>>1 byte 0x12 component file 64-bit level 3 journaled checksummed +>>>1 byte 0x13 component file 32-bit non-journaled checksummed +>>>1 byte 0x14 component file 64-bit non-journaled checksummed +>>>1 byte 0x80 DDB +>>>2 byte x version %d +>>>3 byte x \b.%d +#>>>2 byte x type %d +#>>>3 byte x subtype %d +# *.DXF Dyalog APL Transfer File 0 short 0x6060 Dyalog APL transfer diff --git a/contrib/file/magic/Magdir/efi b/contrib/file/magic/Magdir/efi index 7335c5cefd..7760100b19 100644 --- a/contrib/file/magic/Magdir/efi +++ b/contrib/file/magic/Magdir/efi @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: efi,v 1.4 2009/09/19 16:28:09 christos Exp $ +# $File: efi,v 1.5 2014/04/30 21:41:02 christos Exp $ # efi: file(1) magic for Universal EFI binaries 0 lelong 0x0ef1fab9 @@ -12,4 +12,4 @@ >>&0 lelong 0x01000007 \b, x86_64 >>&20 lelong 7 \b, i386 >>&20 lelong 0x01000007 \b, x86_64 ->4 lelong >2 Universal EFI binary with %ld architectures +>4 lelong >2 Universal EFI binary with %d architectures diff --git a/contrib/file/magic/Magdir/elf b/contrib/file/magic/Magdir/elf index 6a23e56dab..04ee37ed5c 100644 --- a/contrib/file/magic/Magdir/elf +++ b/contrib/file/magic/Magdir/elf @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: elf,v 1.66 2014/03/06 16:37:39 christos Exp $ +# $File: elf,v 1.68 2014/09/19 19:05:57 christos Exp $ # elf: file(1) magic for ELF executables # # We have to check the byte order flag to see what byte order all the @@ -243,6 +243,21 @@ >18 leshort 191 Tilera TILE-Gx, >18 leshort 197 Renesas RL78 family, >18 leshort 199 Renesas 78K0R, +>18 leshort 200 Freescale 56800EX, +>18 leshort 201 Beyond BA1, +>18 leshort 202 Beyond BA2, +>18 leshort 203 XMOS xCORE, +>18 leshort 204 Microchip 8-bit PIC(r), +>18 leshort 210 KM211 KM32, +>18 leshort 211 KM211 KMX32, +>18 leshort 212 KM211 KMX16, +>18 leshort 213 KM211 KMX8, +>18 leshort 214 KM211 KVARC, +>18 leshort 215 Paneve CDP, +>18 leshort 216 Cognitive Smart Memory, +>18 leshort 217 iCelero CoolEngine, +>18 leshort 218 Nanoradio Optimized RISC, +>18 leshort 243 UCB RISC-V, >18 leshort 0x1057 AVR (unofficial), >18 leshort 0x1059 MSP430 (unofficial), >18 leshort 0x1223 Adapteva Epiphany (unofficial), diff --git a/contrib/file/magic/Magdir/encore b/contrib/file/magic/Magdir/encore index ef82eed64b..287b388dba 100644 --- a/contrib/file/magic/Magdir/encore +++ b/contrib/file/magic/Magdir/encore @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: encore,v 1.6 2009/09/19 16:28:09 christos Exp $ +# $File: encore,v 1.7 2014/04/30 21:41:02 christos Exp $ # encore: file(1) magic for Encore machines # # XXX - needs to have the byte order specified (NS32K was little-endian, @@ -12,11 +12,11 @@ >20 short 0x10b demand-paged executable >20 short 0x10f unsupported executable >12 long >0 not stripped ->22 short >0 - version %ld +>22 short >0 - version %d >22 short 0 - #>4 date x stamp %s 0 short 0x155 Encore unsupported executable >12 long >0 not stripped ->22 short >0 - version %ld +>22 short >0 - version %d >22 short 0 - #>4 date x stamp %s diff --git a/contrib/file/magic/Magdir/filesystems b/contrib/file/magic/Magdir/filesystems index b3796f5651..939a0920c9 100644 --- a/contrib/file/magic/Magdir/filesystems +++ b/contrib/file/magic/Magdir/filesystems @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# $File: filesystems,v 1.87 2014/03/01 03:04:06 christos Exp $ +# $File: filesystems,v 1.108 2015/01/01 17:43:47 christos Exp $ # filesystems: file(1) magic for different filesystems # 0 name partid @@ -204,8 +204,8 @@ >>0752 short >0 %d alt cyls, >>0754 short >0 %d heads/partition, >>0756 short >0 %d sectors/track, ->>0764 long >0 start cyl %ld, ->>0770 long x %ld blocks +>>0764 long >0 start cyl %d, +>>0770 long x %d blocks # Is there a boot block written 1 sector in? >512 belong&077777777 0600407 \b, boot block present @@ -249,24 +249,25 @@ 0 string PNCIUNDO Norton Disk Doctor UnDo file # -# DOS/MBR boot sector updated by Joerg Jenderek at Sep 2007,May 2011 +# DOS/MBR boot sector updated by Joerg Jenderek at Sep 2007,May 2011,2013 # for any allowed sector sizes 30 search/481 \x55\xAA # to display DOS/MBR boot sector (40) before old one (strength=50+21),Syslinux bootloader (71),SYSLINUX MBR (37+36),NetBSD mbr (110),AdvanceMAME mbr (111) # DOS BPB information (70) and after DOS floppy (120) like in previous file version -!:strength +72 +!:strength +65 # for sector sizes < 512 Bytes >11 uleshort <512 >>(11.s-2) uleshort 0xAA55 DOS/MBR boot sector # for sector sizes with 512 or more Bytes >0x1FE leshort 0xAA55 DOS/MBR boot sector + # keep old DOS/MBR boot sector as dummy for mbr and bootloader displaying # only for sector sizes with 512 or more Bytes -0x1FE leshort 0xAA55 DOS/MBR boot sector -!:strength +72 +0x1FE leshort 0xAA55 DOS/MBR boot sector +# # to display information (50) before DOS BPB (strength=70) and after DOS floppy (120) like in old file version -#!:strength +21 ->2 string OSBS \b, OS/BS MBR +!:strength +65 +>2 string OSBS OS/BS MBR # added by Joerg Jenderek at Feb 2013 according to http://thestarman.pcministry.com/asm/mbr/ # and http://en.wikipedia.org/wiki/Master_Boot_Record # test for nearly all MS-DOS Master Boot Record initial program loader (IPL) is now done by @@ -319,8 +320,8 @@ # assembler instructions: rep;movsb;retf;mov si,07be;mov cl,04 >>>24 ubequad 0xf3a4cbbebe07b104 9M # "Invalid partition table" nn=0x10F for english version -# "Ungültige Partitionstabelle" nn=0x10F for german version -# "Table de partition erronée" nn=0x10F for french version +# "Ung\201ltige Partitionstabelle" nn=0x10F for german version +# "Table de partition erron\202e" nn=0x10F for french version # "\216\257\245\340\240\346\250\256\255\255\240\357 \341\250\341\342\245\254\240 \255\245 \255\240\251\244\245\255\240" nn=0x10F for russian version >>>>(0x3C.b+0x0FF) string Invalid\ partition\ table english >>>>(0x3C.b+0x0FF) string Ung\201ltige\ Partitionstabelle german @@ -330,13 +331,13 @@ >>>>(0x3C.b+0x0FF) string >\0 "%s" # "Error loading operating system" nn=0x127 for english version # "Fehler beim Laden des Betriebssystems" nn=0x12b for german version -# "Erreur lors du chargement du système d'exploitation" nn=0x12a for french version +# "Erreur lors du chargement du syst\212me d'exploitation" nn=0x12a for french version # "\216\350\250\241\252\240 \257\340\250 \247\240\243\340\343\247\252\245 \256\257\245\340\240\346\250\256\255\255\256\251 \341\250\341\342\245\254\353" nn=0x12d for russian version >>>>0xBD ubyte x at offset 0x1%x >>>>(0xBD.b+0x100) string >\0 "%s" # "Missing operating system" nn=0x146 for english version # "Betriebssystem fehlt" nn=0x151 for german version -# "Système d'exploitation manquant" nn=0x15e for french version +# "Syst\212me d'exploitation manquant" nn=0x15e for french version # "\216\257\245\340\240\346\250\256\255\255\240\357 \341\250\341\342\245\254\240 \255\245 \255\240\251\244\245\255\240" nn=0x156 for russian version >>>>0xA9 ubyte x at offset 0x1%x >>>>(0xA9.b+0x100) string >\0 "%s" @@ -347,7 +348,7 @@ >>>>0x1B4 ubelong&0x00FFFFFF 0x002c4463 english >>>>0x1B4 ubelong&0x00FFFFFF 0x002c486e german # "Invalid partition table" xx=0x12C for english version -# "Ungültige Partitionstabelle" xx=0x12C for german version +# "Ung\201ltige Partitionstabelle" xx=0x12C for german version >>>>0x1b5 ubyte >0 at offset 0x1%x >>>>(0x1b5.b+0x100) string >\0 "%s" # "Error loading operating system" yy=0x144 for english version @@ -368,7 +369,7 @@ >>>>0x1B4 ubelong&0x00FFFFFF 0x00627a99 english #>>>>0x1B4 ubelong&0x00FFFFFF ? german # "Invalid partition table" xx=0x162 for english version -# "Ungültige Partitionstabelle" xx=0x1?? for german version +# "Ung\201ltige Partitionstabelle" xx=0x1?? for german version >>>>0x1b5 ubyte >0 at offset 0x1%x >>>>(0x1b5.b+0x100) string >\0 "%s" # "Error loading operating system" yy=0x17a for english version @@ -386,7 +387,7 @@ >>>>0x1B4 ubelong&0x00FFFFFF 0x00637b9a english #>>>>0x1B4 ubelong&0x00FFFFFF ? german # "Invalid partition table" xx=0x163 for english version -# "Ungültige Partitionstabelle" xx=0x1?? for german version +# "Ung\201ltige Partitionstabelle" xx=0x1?? for german version >>>>0x1b5 ubyte >0 at offset 0x1%x >>>>(0x1b5.b+0x100) string >\0 "%s" # "Error loading operating system" yy=0x17b for english version @@ -519,7 +520,7 @@ >>>>>379 string GRUB\ \0 \b, GRUB version 0.95 or 0.96 >>>>391 string Geom\0Hard\ Disk\0Read\0\ Error\0 >>>>>385 string GRUB\ \0 \b, GRUB version 0.97 -#unkown version +# unknown version >>>343 string Geom\0Read\0\ Error\0 >>>>321 string Loading\ stage1.5 \b, GRUB version x.y >>>380 string Geom\0Hard\ Disk\0Read\0\ Error\0 @@ -538,6 +539,8 @@ >>>514 string !HdrS # not BeOS >>>>422 string !Be\ Boot\ Loader +>>>>>32769 string CD001 +>>>>>>0 use cdrom # jump over BPB instruction implies DOS bootsector or AdvanceMAME mbr >>>>>0 ubelong&0xFD000000 =0xE9000000 # AdvanceMAME mbr @@ -566,16 +569,11 @@ #OEM-ID=BOOTWIZ0 >442 string Non-system\ disk,\ >>459 string press\ any\ key...\x7\0 \b, Acronis Startup Recovery Loader -# updated by Joerg Jenderek at Nov 2012 +# updated by Joerg Jenderek at Nov 2012, Sep 2013 # DOS names like F11.SYS or BOOTWIZ.SYS are 8 right space padded bytes+3 bytes ->>>477 ubyte&0xDF >0 ->>>>477 string x \b %-.3s ->>>>>480 ubyte&0xDF >0 ->>>>>>480 string x \b%-.4s ->>>>>>>484 ubyte&0xDF >0 ->>>>>>>>484 string x \b%-.1s ->>>>485 ubyte&0xDF >0 ->>>>>485 string x \b.%-.3s +# display 1 space +>>>447 ubyte x \b +>>>477 use DOS-filename # >185 string FDBOOT\ Version\ >>204 string \rNo\ Systemdisk.\ @@ -1015,75 +1013,45 @@ # It just looks for a program file name at the root directory # and loads corresponding file with following execution. # DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes ->>>>499 ubyte&0xDF >0 \b, COM/EXE Bootloader ->>>>>499 string x \b %-.1s ->>>>>>500 ubyte&0xDF >0 ->>>>>>>500 string x \b%-.1s ->>>>>>>>501 ubyte&0xDF >0 ->>>>>>>>>501 string x \b%-.1s ->>>>>>>>>>502 ubyte&0xDF >0 ->>>>>>>>>>>502 string x \b%-.1s ->>>>>>>>>>>>503 ubyte&0xDF >0 ->>>>>>>>>>>>>503 string x \b%-.1s ->>>>>>>>>>>>>>504 ubyte&0xDF >0 ->>>>>>>>>>>>>>>504 string x \b%-.1s ->>>>>>>>>>>>>>>>505 ubyte&0xDF >0 ->>>>>>>>>>>>>>>>>505 string x \b%-.1s ->>>>>>>>>>>>>>>>>>506 ubyte&0xDF >0 ->>>>>>>>>>>>>>>>>>>506 string x \b%-.1s -#name extension ->>>>>507 ubyte&0xDF >0 \b. ->>>>>>507 string x \b%-.1s ->>>>>>>508 ubyte&0xDF >0 ->>>>>>>>508 string x \b%-.1s ->>>>>>>>>509 ubyte&0xDF >0 ->>>>>>>>>>509 string x \b%-.1s +>>>>499 ubyte&0xDF >0 \b, COM/EXE Bootloader +>>>>>499 use DOS-filename #If the boot sector fails to read any other sector, #it prints a very short message ("RE") to the screen and hangs the computer. #If the boot sector fails to find needed program in the root directory, #it also hangs with another message ("NF"). >>>>>492 string RENF \b, FAT (12 bit) >>>>>495 string RENF \b, FAT (16 bit) -# http://alexfru.chat.ru/epm.html#bootprog ->494 ubyte >0x4D ->>495 string >E ->>>495 string >>>3 string BootProg -# It just looks for a program file name at the root directory -# and loads corresponding file with following execution. -# DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes ->>>>499 ubyte&0xDF >0 \b, COM/EXE Bootloader ->>>>>499 string x \b %-.1s ->>>>>>500 ubyte&0xDF >0 ->>>>>>>500 string x \b%-.1s ->>>>>>>>501 ubyte&0xDF >0 ->>>>>>>>>501 string x \b%-.1s ->>>>>>>>>>502 ubyte&0xDF >0 ->>>>>>>>>>>502 string x \b%-.1s ->>>>>>>>>>>>503 ubyte&0xDF >0 ->>>>>>>>>>>>>503 string x \b%-.1s ->>>>>>>>>>>>>>504 ubyte&0xDF >0 ->>>>>>>>>>>>>>>504 string x \b%-.1s ->>>>>>>>>>>>>>>>505 ubyte&0xDF >0 ->>>>>>>>>>>>>>>>>505 string x \b%-.1s ->>>>>>>>>>>>>>>>>>506 ubyte&0xDF >0 ->>>>>>>>>>>>>>>>>>>506 string x \b%-.1s -#name extension ->>>>>507 ubyte&0xDF >0 \b. ->>>>>>507 string x \b%-.1s ->>>>>>>508 ubyte&0xDF >0 ->>>>>>>>508 string x \b%-.1s ->>>>>>>>>509 ubyte&0xDF >0 ->>>>>>>>>>509 string x \b%-.1s #If the boot sector fails to read any other sector, #it prints a very short message ("RE") to the screen and hangs the computer. -#If the boot sector fails to find needed program in the root directory, -#it also hangs with another message ("NF"). ->>>>>492 string RENF \b, FAT (12 bit) ->>>>>495 string RENF \b, FAT (16 bit) # x86 bootloader end +# added by Joerg Jenderek at Feb 2013 according to http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm#FSINFO +# and http://en.wikipedia.org/wiki/File_Allocation_Table#FS_Information_Sector +>0 string RRaA +>>0x1E4 string rrAa \b, FSInfosector +#>>0x1FC uleshort =0 SHOULD BE ZERO +>>>0x1E8 ulelong <0xffffffff \b, %u free clusters +>>>0x1EC ulelong <0xffffffff \b, last allocated cluster %u + +# updated by Joerg Jenderek at Sep 2007 +>3 ubyte 0 +#no active flag +>>446 ubyte 0 +# partition 1 not empty +>>>450 ubyte >0 +# partitions 3,4 empty +>>>>482 ubyte 0 +>>>>>498 ubyte 0 +# partition 2 ID=0,5,15 +>>>>>>466 ubyte <0x10 +>>>>>>>466 ubyte 0x05 \b, extended partition table +>>>>>>>466 ubyte 0x0F \b, extended partition table (LBA) +>>>>>>>466 ubyte 0x0 \b, extended partition table (last) + +# DOS x86 sector separated and moved from "DOS/MBR boot sector" by Joerg Jenderek at May 2011 + +>0x200 lelong 0x82564557 \b, BSD disklabel + # by Joerg Jenderek at Apr 2013 # Print the DOS filenames from directory entry form with 8 right space padded bytes + 3 bytes for extension # like IO.SYS. MSDOS.SYS , KERNEL.SYS , DRBIO.SYS @@ -1121,33 +1089,6 @@ >11 ubyte x \b+ >11 use DOS-filename -# added by Joerg Jenderek at Feb 2013 according to http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm#FSINFO -# and http://en.wikipedia.org/wiki/File_Allocation_Table#FS_Information_Sector ->0 string RRaA ->>0x1E4 string rrAa \b, FSInfosector -#>>0x1FC uleshort =0 SHOULD BE ZERO ->>>0x1E8 ulelong <0xffffffff \b, %u free clusters ->>>0x1EC ulelong <0xffffffff \b, last allocated cluster %u - -# updated by Joerg Jenderek at Sep 2007 ->3 ubyte 0 -#no active flag ->>446 ubyte 0 -# partition 1 not empty ->>>450 ubyte >0 -# partitions 3,4 empty ->>>>482 ubyte 0 ->>>>>498 ubyte 0 -# partition 2 ID=0,5,15 ->>>>>>466 ubyte <0x10 ->>>>>>>466 ubyte 0x05 \b, extended partition table ->>>>>>>466 ubyte 0x0F \b, extended partition table (LBA) ->>>>>>>466 ubyte 0x0 \b, extended partition table (last) - -# DOS x86 sector separated and moved from "DOS/MBR boot sector" by Joerg Jenderek at May 2011 - ->0x200 lelong 0x82564557 \b, BSD disklabel - # http://en.wikipedia.org/wiki/Master_boot_record#PTE # display standard partition table 0 name partition-table @@ -1298,6 +1239,7 @@ >>>>>181 search/166 Error\ \0 # "a: disk" , "Fn: diskn" or "NetBSD MBR boot" >>>>>>&3 string x \b,"%s" +>>>446 use partition-table # Andrea Mazzoleni AdvanceCD mbr loader of http://advancemame.sourceforge.net/boot-readme.html # added by Joerg Jenderek at Nov 2012 for versions 1.3 - 1.4 # assembler instructions: jmp short 0x58;nop;ASCII @@ -1330,7 +1272,7 @@ #>>>(0x1BC.s+11) ubyte x \b,cfg_def 0x%x # for older versions >>>(0x1BC.s+9) ubyte <2 -#>>>>(0x1BC.s+12) ubyte 18 \b,%u/18 seconds +#>>>>(0x1BC.s+12) ubyte 18 \b,%hhu/18 seconds >>>>(0x1BC.s+12) ubyte !18 \b,%u/18 seconds # floppy A: or B: >>>>(0x1BC.s+13) ubyte <2 \b,floppy 0x%x @@ -1373,7 +1315,7 @@ >>>>0x207 ubyte x \b.%u # module_size for 1.94 >>>>0x208 ulelong <0xffffff \b, installed partition %u -#>>>>0x208 ulelong =0xffffff \b, %u (default) +#>>>>0x208 ulelong =0xffffff \b, %lu (default) >>>>0x208 ulelong >0xffffff \b, installed partition %u # GRUB 0.5.95 unofficial >>>>0x20C ulelong&0x2E300000 0x2E300000 @@ -1415,18 +1357,19 @@ # minimal short forward jump found 0x29 for bootloaders or 0x0 # maximal short forward jump is 0x7f # OEM-ID is empty or contain readable bytes -0 ulelong&0x804000E9 0x000000E9 +0 ulelong&0x804000E9 0x000000E9 +!:strength +60 # mtools-3.9.8/msdos.h # usual values are marked with comments to get only informations of strange FAT systems # valid sectorsize must be a power of 2 from 32 to 32768 ->11 uleshort&0xf001f 0 +>11 uleshort&0x001f 0 >>11 uleshort <32769 >>>11 uleshort >31 >>>>21 ubyte&0xf0 0xF0 ->>>>>0 ubyte 0xEB +>>>>>0 ubyte 0xEB DOS/MBR boot sector >>>>>>1 ubyte x \b, code offset 0x%x+2 >>>>>0 ubyte 0xE9 ->>>>>>1 uleshort x \b, code offset 0x%x+2 +>>>>>>1 uleshort x \b, code offset 0x%x+3 >>>>>3 string >\0 \b, OEM-ID "%-.8s" #http://mirror.href.com/thestarman/asm/debug/debug2.htm#IHC >>>>>>8 string IHC \b cached by Windows 9M @@ -1435,10 +1378,11 @@ >>>>>11 uleshort <512 \b, Bytes/sector %u >>>>>13 ubyte >1 \b, sectors/cluster %u #>>>>>13 ubyte =1 \b, sectors/cluster %u (usual on Floppies) ->>>>>82 string FAT32 +# for lazy FAT32 implementation like Transcend digital photo frame PF830 +>>>>>82 string/c fat32 >>>>>>14 uleshort !32 \b, reserved sectors %u #>>>>>>14 uleshort =32 \b, reserved sectors %u (usual Fat32) ->>>>>82 string !FAT32 +>>>>>82 string/c !fat32 >>>>>>14 uleshort >1 \b, reserved sectors %u #>>>>>>14 uleshort =1 \b, reserved sectors %u (usual FAT12,FAT16) #>>>>>>14 uleshort 0 \b, reserved sectors %u (usual NTFS) @@ -1447,38 +1391,43 @@ >>>>>16 ubyte =1 \b, FAT %u >>>>>16 ubyte >0 >>>>>17 uleshort >0 \b, root entries %u -#>>>>>17 uleshort =0 \b, root entries %u=0 (usual Fat32) +#>>>>>17 uleshort =0 \b, root entries %hu=0 (usual Fat32) >>>>>19 uleshort >0 \b, sectors %u (volumes <=32 MB) -#>>>>>19 uleshort =0 \b, sectors %u=0 (usual Fat32) +#>>>>>19 uleshort =0 \b, sectors %hu=0 (usual Fat32) >>>>>21 ubyte >0xF0 \b, Media descriptor 0x%x #>>>>>21 ubyte =0xF0 \b, Media descriptor 0x%x (usual floppy) >>>>>21 ubyte <0xF0 \b, Media descriptor 0x%x >>>>>22 uleshort >0 \b, sectors/FAT %u -#>>>>>22 uleshort =0 \b, sectors/FAT %u=0 (usual Fat32) +#>>>>>22 uleshort =0 \b, sectors/FAT %hu=0 (usual Fat32) >>>>>24 uleshort x \b, sectors/track %u >>>>>26 ubyte >2 \b, heads %u #>>>>>26 ubyte =2 \b, heads %u (usual floppy) >>>>>26 ubyte =1 \b, heads %u # valid only for sector sizes with more then 32 Bytes >>>>>11 uleshort >32 -# skip for Digital Research DOS (version 3.41) 1440 kB Bootdisk ->>>>>>38 ubyte !0x70 +# http://en.wikipedia.org/wiki/Design_of_the_FAT_file_system#Extended_BIOS_Parameter_Block +# skip for values 2,2Ah,70h,73h,DFh +# and continue for extended boot signature values 0,28h,29h,80h +>>>>>>38 ubyte&0x56 =0 >>>>>>>28 ulelong >0 \b, hidden sectors %u #>>>>>>>28 ulelong =0 \b, hidden sectors %u (usual floppy) >>>>>>>32 ulelong >0 \b, sectors %u (volumes > 32 MB) #>>>>>>>32 ulelong =0 \b, sectors %u (volumes > 32 MB) # FAT<32 bit specific ->>>>>>>82 string !FAT32 +>>>>>>>82 string/c !fat32 #>>>>>>>>36 ubyte 0x80 \b, physical drive 0x%x=0x80 (usual harddisk) #>>>>>>>>36 ubyte 0 \b, physical drive 0x%x=0 (usual floppy) >>>>>>>>36 ubyte !0x80 >>>>>>>>>36 ubyte !0 \b, physical drive 0x%x +# VGA-copy CRC or +# in Windows NT bit 0 is a dirty flag to request chkdsk at boot time. bit 1 requests surface scan too >>>>>>>>37 ubyte >0 \b, reserved 0x%x #>>>>>>>>37 ubyte =0 \b, reserved 0x%x -# value is 0x80 for NTFS +# extended boot signatur value is 0x80 for NTFS, 0x28 or 0x29 for others >>>>>>>>38 ubyte !0x29 \b, dos < 4.0 BootSector (0x%x) ->>>>>>>>38 ubyte =0x29 +>>>>>>>>38 ubyte&0xFE =0x28 >>>>>>>>>39 ulelong x \b, serial number 0x%x +>>>>>>>>38 ubyte =0x29 >>>>>>>>>43 string >>>>>>>>43 string >NO\ NAME \b, label: "%11.11s" >>>>>>>>>43 string =NO\ NAME \b, unlabeled @@ -1488,15 +1437,39 @@ # if it is small enough FAT is 12 bit, if it is too big enough FAT is 32 bit, # otherwise FAT is 16 bit. # http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/determining-fat-widths.html ->>>>>>54 string FAT \b, FAT ->>>>>>>54 string FAT12 \b (12 bit) ->>>>>>>54 string FAT16 \b (16 bit) +>>>>>82 string/c !fat32 +>>>>>>54 string FAT12 \b, FAT (12 bit) +>>>>>>54 string FAT16 \b, FAT (16 bit) +>>>>>>54 default x +# determinate FAT bit size by media descriptor +# small floppies implies FAT12 +>>>>>>>21 ubyte <0xF0 \b, FAT (12 bit by descriptor) +# with media descriptor F0h floppy or maybe superfloppy with FAT16 +>>>>>>>21 ubyte =0xF0 +# superfloppy (many sectors) implies FAT16 +>>>>>>>>32 ulelong >0xFFFF \b, FAT (16 bit by descriptor+sectors) +# no superfloppy with media descriptor F0h implies FAT12 +>>>>>>>>32 default x \b, FAT (12 bit by descriptor+sectors) +# with media descriptor F8h floppy or hard disc with FAT12 or FAT16 +>>>>>>>21 ubyte =0xF8 +# 360 KiB with media descriptor F8h, 9 sectors per track ,single sided floppy implies FAT12 +>>>>>>>>19 ubequad 0xd002f80300090001 \b, FAT (12 bit by descriptor+geometry) +# hard disc with FAT12 or FAT16 +>>>>>>>>19 default x \b, FAT (1Y bit by descriptor) +# with media descriptor FAh floppy, RAM disc with FAT12 or FAT16 or Tandy hard disc +>>>>>>>21 ubyte =0xFA +# 320 KiB with media descriptor FAh, 8 sectors per track ,single sided floppy implies FAT12 +>>>>>>>>19 ubequad 0x8002fa0200080001 \b, FAT (12 bit by descriptor+geometry) +# RAM disc with FAT12 or FAT16 or Tandy hard disc +>>>>>>>>19 default x \b, FAT (1Y bit by descriptor) +# others are floppy +>>>>>>>21 default x \b, FAT (12 bit by descriptor) # FAT32 bit specific ->>>>>82 string FAT32 \b, FAT (32 bit) +>>>>>82 string/c fat32 \b, FAT (32 bit) >>>>>>36 ulelong x \b, sectors/FAT %u # http://technet.microsoft.com/en-us/library/cc977221.aspx >>>>>>40 uleshort >0 \b, extension flags 0x%x -#>>>>>>40 uleshort =0 \b, extension flags %u +#>>>>>>40 uleshort =0 \b, extension flags %hu >>>>>>42 uleshort >0 \b, fsVersion %u #>>>>>>42 uleshort =0 \b, fsVersion %u (usual) >>>>>>44 ulelong >2 \b, rootdir cluster %u @@ -1505,9 +1478,12 @@ >>>>>>48 uleshort >1 \b, infoSector %u #>>>>>>48 uleshort =1 \b, infoSector %u (usual) >>>>>>48 uleshort <1 \b, infoSector %u ->>>>>>50 uleshort >6 \b, Backup boot sector %u +# 0 or 0xFFFF instead of usual 6 means no backup sector +>>>>>>50 uleshort =0xFFFF \b, no Backup boot sector +>>>>>>50 uleshort =0 \b, no Backup boot sector #>>>>>>50 uleshort =6 \b, Backup boot sector %u (usual) ->>>>>>50 uleshort <6 \b, Backup boot sector %u +>>>>>>50 default x +>>>>>>>50 uleshort x \b, Backup boot sector %u # corrected by Joerg Jenderek at Feb 2011 according to http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm#FSINFO >>>>>>52 ulelong >0 \b, reserved1 0x%x >>>>>>56 ulelong >0 \b, reserved2 0x%x @@ -1555,13 +1531,13 @@ # Values 128 to 255 represent MFT record sizes of 2^(256-N) bytes. >>>>>>>>>64 lelong <256 >>>>>>>>>>64 lelong <128 \b, clusters/RecordSegment %d ->>>>>>>>>>64 ubyte >127 \b, bytes/RecordSegment 2^(-1*%hhi) +>>>>>>>>>>64 ubyte >127 \b, bytes/RecordSegment 2^(-1*%i) # Values 0 to 127 represent index block sizes of 0 to 127 clusters. # Values 128 to 255 represent index block sizes of 2^(256-N) byte >>>>>>>>>68 ulelong <256 >>>>>>>>>>68 ulelong <128 \b, clusters/index block %d #>>>>>>>>>>68 ulelong >127 \b, bytes/index block 2^(256-%d) ->>>>>>>>>>68 ubyte >127 \b, bytes/index block 2^(-1*%hhi) +>>>>>>>>>>68 ubyte >127 \b, bytes/index block 2^(-1*%i) >>>>>>>>>72 ulequad x \b, serial number 0%llx >>>>>>>>>80 ulelong >0 \b, checksum 0x%x #>>>>>>>>>80 ulelong =0 \b, checksum 0x%x=0 (usual) @@ -1609,7 +1585,7 @@ >&-180 lelong x average file size %d, >&-176 lelong x average number of files in dir %d, >&-272 lequad x pending blocks to free %lld, ->&-264 lelong x pending inodes to free %ld, +>&-264 lelong x pending inodes to free %d, >&-664 lequad x system-wide uuid %0llx, >&-1316 lelong x minimum percentage of free blocks %d, >&-1248 lelong 0 TIME optimization @@ -1629,7 +1605,7 @@ >&-180 lelong x average file size %d, >&-176 lelong x average number of files in dir %d, >&-272 lequad x pending blocks to free %lld, ->&-264 lelong x pending inodes to free %ld, +>&-264 lelong x pending inodes to free %d, >&-664 lequad x system-wide uuid %0llx, >&-1316 lelong x minimum percentage of free blocks %d, >&-1248 lelong 0 TIME optimization @@ -1669,7 +1645,7 @@ >&-180 belong x average file size %d, >&-176 belong x average number of files in dir %d, >&-272 bequad x pending blocks to free %lld, ->&-264 belong x pending inodes to free %ld, +>&-264 belong x pending inodes to free %d, >&-664 bequad x system-wide uuid %0llx, >&-1316 belong x minimum percentage of free blocks %d, >&-1248 belong 0 TIME optimization @@ -1689,7 +1665,7 @@ >&-180 belong x average file size %d, >&-176 belong x average number of files in dir %d, >&-272 bequad x pending blocks to free %lld, ->&-264 belong x pending inodes to free %ld, +>&-264 belong x pending inodes to free %d, >&-664 bequad x system-wide uuid %0llx, >&-1316 belong x minimum percentage of free blocks %d, >&-1248 belong 0 TIME optimization @@ -1942,12 +1918,11 @@ # defect IO.SYS+MSDOS.SYS ? #>>>>>0x162 use 2xDOS-filename -# CDROM Filesystems -# Modified for UDF by gerardo.cacciari@gmail.com -32769 string CD001 # -!:mime application/x-iso9660-image +0 name cdrom >38913 string !NSR0 ISO 9660 CD-ROM filesystem data +!:mime application/x-iso9660-image >38913 string NSR0 UDF filesystem data +!:mime application/x-iso9660-image >>38917 string 1 (version 1.0) >>38917 string 2 (version 1.5) >>38917 string 3 (version 2.0) @@ -1960,29 +1935,41 @@ !:mime application/x-iso9660-image 32777 string CDROM High Sierra CD-ROM filesystem data +# CDROM Filesystems +# https://en.wikipedia.org/wiki/ISO_9660 +# Modified for UDF by gerardo.cacciari@gmail.com +32769 string CD001 +# mime line at that position does not work +# to display CD-ROM (70=81-11) after MBR (113=40+72+1), partition-table (71=50+21) and before Apple Driver Map (51) +!:strength -11 +# to display CD-ROM (114=81+33) before MBR (113=40+72+1), partition-table (71=50+21) and Apple Driver Map (51) +# does not work +#!:strength +33 +>0 use cdrom + # .cso files 0 string CISO Compressed ISO CD image # cramfs filesystem - russell@coker.com.au 0 lelong 0x28cd3d45 Linux Compressed ROM File System data, little endian ->4 lelong x size %lu +>4 lelong x size %u >8 lelong &1 version #2 >8 lelong &2 sorted_dirs >8 lelong &4 hole_support >32 lelong x CRC 0x%x, ->36 lelong x edition %lu, ->40 lelong x %lu blocks, ->44 lelong x %lu files +>36 lelong x edition %u, +>40 lelong x %u blocks, +>44 lelong x %u files 0 belong 0x28cd3d45 Linux Compressed ROM File System data, big endian ->4 belong x size %lu +>4 belong x size %u >8 belong &1 version #2 >8 belong &2 sorted_dirs >8 belong &4 hole_support >32 belong x CRC 0x%x, ->36 belong x edition %lu, ->40 belong x %lu blocks, ->44 belong x %lu files +>36 belong x edition %u, +>40 belong x %u blocks, +>44 belong x %u files # reiserfs - russell@coker.com.au 0x10034 string ReIsErFs ReiserFS V3.5 @@ -2142,6 +2129,7 @@ #---------------------------------------------------------- #delta ISO Daniel Novotny (dnovotny@redhat.com) 0 string DISO Delta ISO data +!:strength +50 >4 belong x version %d # VMS backup savesets - gerardo.cacciari@gmail.com @@ -2193,7 +2181,6 @@ # which is mapped to VBN 2 of [000000]INDEXF.SYS;1 - gerardo.cacciari@gmail.com # 1008 string DECFILE11 Files-11 On-Disk Structure ->525 byte x Level %d >525 byte x (ODS-%d); >1017 string A RSX-11, VAX/VMS or OpenVMS VAX file system; >1017 string B @@ -2247,8 +2234,8 @@ >16 ulequad >0 \b fblock table at %lld, >24 ulequad >0 \b inode table at %lld, >32 ulequad >0 \b root at %lld, ->40 ulelong >0 \b fblock size = %ld, ->44 ulelong >0 \b block size = %ld, +>40 ulelong >0 \b fblock size = %d, +>44 ulelong >0 \b block size = %d, >48 ulequad >0 \b bytes = %lld # Type: xfs metadump image @@ -2328,14 +2315,31 @@ # UBIfs # Linux kernel sources: fs/ubifs/ubifs-media.h -0 belong 0x31181006 ->0x16 short 0 UBIfs image ->0x08 lequad x \b, sequence number %llu ->0x10 leshort x \b, length %u ->0x04 lelong x \b, CRC 0x%08x - -0 belong 0x55424923 ->0x04 short <2 ->0x05 string \0\0\0 ->0x1c string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 ->0x04 short x UBI image, version %u +0 lelong 0x06101831 +>0x16 leshort 0 UBIfs image +>0x08 lequad x \b, sequence number %llu +>0x10 leshort x \b, length %u +>0x04 lelong x \b, CRC 0x%08x + +0 lelong 0x23494255 +>0x04 leshort <2 +>0x05 string \0\0\0 +>0x1c string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 +>0x04 leshort x UBI image, version %u + +# NEC PC-88 2D disk image +# From Fabio R. Schmidlin +0x20 ulelong&0xFFFFFEFF 0x2A0 +>0x10 string \0\0\0\0\0\0\0\0\0\0 +>>0x280 string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 +>>>0x1A ubyte&0xEF 0 +>>>>0x1B ubyte&0x8F 0 +>>>>>0x1B ubyte&70 <0x40 +>>>>>>0x1C ulelong >0x21 +>>>>>>>0 regex [[:print:]]* NEC PC-88 disk image, name=%s +>>>>>>>>0x1B ubyte 0 \b, media=2D +>>>>>>>>0x1B ubyte 0x10 \b, media=2DD +>>>>>>>>0x1B ubyte 0x20 \b, media=2HD +>>>>>>>>0x1B ubyte 0x30 \b, media=1D +>>>>>>>>0x1B ubyte 0x40 \b, media=1DD +>>>>>>>>0x1A ubyte 0x10 \b, write-protected diff --git a/contrib/file/magic/Magdir/flash b/contrib/file/magic/Magdir/flash index fa22562c5d..b06f879efc 100644 --- a/contrib/file/magic/Magdir/flash +++ b/contrib/file/magic/Magdir/flash @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: flash,v 1.10 2014/03/06 16:07:24 christos Exp $ +# $File: flash,v 1.11 2014/05/02 00:26:49 christos Exp $ # flash: file(1) magic for Macromedia Flash file format # # See @@ -9,17 +9,27 @@ # http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/\ # en/devnet/swf/pdf/swf-file-format-spec.pdf page 27 # -0 string FWS Macromedia Flash data, ->3 byte x version %d + +0 name swf-details +>0 string F Macromedia Flash data !:mime application/x-shockwave-flash -0 string CWS Macromedia Flash data (compressed), +>0 string C Macromedia Flash data (compressed) !:mime application/x-shockwave-flash ->3 byte x version %d -0 string ZWS Macromedia Flash data (lzma compressed), +>0 string Z Macromedia Flash data (lzma compressed) !:mime application/x-shockwave-flash ->3 byte x version %d +>3 byte x \b, version %d + +1 string WS +>4 lelong !0 +>>3 byte 255 Suspicious +>>>0 use swf-details + +>>3 ubyte <32 +>>>3 ubyte !0 +>>>>0 use swf-details + # From: Cal Peake -0 string FLV Macromedia Flash Video +0 string FLV\x01 Macromedia Flash Video !:mime video/x-flv # diff --git a/contrib/file/magic/Magdir/fonts b/contrib/file/magic/Magdir/fonts index a702a175a8..4b3173cd2a 100644 --- a/contrib/file/magic/Magdir/fonts +++ b/contrib/file/magic/Magdir/fonts @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: fonts,v 1.26 2013/03/09 22:36:00 christos Exp $ +# $File: fonts,v 1.27 2014/04/30 21:41:02 christos Exp $ # fonts: file(1) magic for font data # 0 search/1 FONT ASCII vfont text @@ -96,5 +96,5 @@ 0 string wOFF Web Open Font Format >4 belong x \b, flavor %d >8 belong x \b, length %d ->20 beshort x \b, version %hd ->22 beshort x \b.%hd +>20 beshort x \b, version %d +>22 beshort x \b.%d diff --git a/contrib/file/magic/Magdir/fortran b/contrib/file/magic/Magdir/fortran index 0604c25930..921beec396 100644 --- a/contrib/file/magic/Magdir/fortran +++ b/contrib/file/magic/Magdir/fortran @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------ -# $File: fortran,v 1.7 2012/06/21 01:55:02 christos Exp $ +# $File: fortran,v 1.8 2014/06/03 19:01:34 christos Exp $ # FORTRAN source -0 regex/100 \^[Cc][\ \t] FORTRAN program +0 regex/100l \^[Cc][\ \t] FORTRAN program !:mime text/x-fortran !:strength - 5 diff --git a/contrib/file/magic/Magdir/games b/contrib/file/magic/Magdir/games index e8116289cb..779bc6cfd6 100644 --- a/contrib/file/magic/Magdir/games +++ b/contrib/file/magic/Magdir/games @@ -1,19 +1,19 @@ #------------------------------------------------------------------------------ -# $File: games,v 1.13 2012/02/13 22:50:50 christos Exp $ +# $File: games,v 1.14 2014/04/30 21:41:02 christos Exp $ # games: file(1) for games # Fabio Bonelli # Quake II - III data files 0 string IDP2 Quake II 3D Model file, ->20 long x %lu skin(s), ->8 long x (%lu x ->12 long x %lu), ->40 long x %lu frame(s), ->16 long x Frame size %lu bytes, ->24 long x %lu vertices/frame, ->28 long x %lu texture coordinates, ->32 long x %lu triangles/frame +>20 long x %u skin(s), +>8 long x (%u x +>12 long x %u), +>40 long x %u frame(s), +>16 long x Frame size %u bytes, +>24 long x %u vertices/frame, +>28 long x %u texture coordinates, +>32 long x %u triangles/frame 0 string IBSP Quake >4 long 0x26 II Map file (BSP) @@ -146,7 +146,7 @@ 0 string MComprHD MAME CHD compressed hard disk image, ->12 belong x version %lu +>12 belong x version %u # doom - submitted by Jon Dowland diff --git a/contrib/file/magic/Magdir/gimp b/contrib/file/magic/Magdir/gimp index ba0727f7b6..516abb25a1 100644 --- a/contrib/file/magic/Magdir/gimp +++ b/contrib/file/magic/Magdir/gimp @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: gimp,v 1.8 2013/12/21 14:29:45 christos Exp $ +# $File: gimp,v 1.9 2014/04/30 21:41:02 christos Exp $ # GIMP Gradient: file(1) magic for the GIMP's gradient data files (.ggr) # by Federico Mena @@ -20,8 +20,8 @@ >9 string file version 0, >9 string v version >>10 string >\0 %s, ->14 belong x %lu x ->18 belong x %lu, +>14 belong x %u x +>18 belong x %u, >22 belong 0 RGB Color >22 belong 1 Greyscale >22 belong 2 Indexed Color diff --git a/contrib/file/magic/Magdir/gnome b/contrib/file/magic/Magdir/gnome index 14d5aeb32d..32c9ae9388 100644 --- a/contrib/file/magic/Magdir/gnome +++ b/contrib/file/magic/Magdir/gnome @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: gnome,v 1.3 2013/02/05 15:20:47 christos Exp $ +# $File: gnome,v 1.5 2014/04/30 21:41:02 christos Exp $ # GNOME related files # Contributed by Josh Triplett @@ -9,9 +9,9 @@ >&0 ubyte 0 \b, major version 0 >>&0 ubyte 0 \b, minor version 0 >>>&0 ubyte 0 \b, crypto type 0 (AES) ->>>&0 ubyte >0 \b, crypto type %hhu (unknown) +>>>&0 ubyte >0 \b, crypto type %u (unknown) >>>&1 ubyte 0 \b, hash type 0 (MD5) ->>>&1 ubyte >0 \b, hash type %hhu (unknown) +>>>&1 ubyte >0 \b, hash type %u (unknown) >>>&2 ubelong 0xFFFFFFFF \b, name NULL >>>&2 ubelong !0xFFFFFFFF >>>>&-4 ubelong >255 \b, name too long for file's pstring type diff --git a/contrib/file/magic/Magdir/gpt b/contrib/file/magic/Magdir/gpt index 74aaaf7bfb..c48a58f7fe 100644 --- a/contrib/file/magic/Magdir/gpt +++ b/contrib/file/magic/Magdir/gpt @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: gpt,v 1.1 2013/02/18 18:31:09 christos Exp $ +# $File: gpt,v 1.3 2014/04/30 21:41:02 christos Exp $ # # GPT Partition table patterns. # Author: Rogier Goossens (goossens.rogier@gmail.com) @@ -220,7 +220,6 @@ 0 name gpt-table >10 uleshort x \b, version %u >8 uleshort x \b.%u -# a GUID is just like a UUID, except it's displayed mixed-endian. >56 ulelong x \b, GUID: %08x >60 uleshort x \b-%04x >62 uleshort x \b-%04x diff --git a/contrib/file/magic/Magdir/graphviz b/contrib/file/magic/Magdir/graphviz index b944d4637c..cddc116400 100644 --- a/contrib/file/magic/Magdir/graphviz +++ b/contrib/file/magic/Magdir/graphviz @@ -1,12 +1,12 @@ #------------------------------------------------------------------------------ -# $File: graphviz,v 1.7 2009/09/19 16:28:09 christos Exp $ +# $File: graphviz,v 1.8 2014/06/03 19:01:34 christos Exp $ # graphviz: file(1) magic for http://www.graphviz.org/ # FIXME: These patterns match too generally. For example, the first # line matches a LaTeX file containing the word "graph" (with a { # following later) and the second line matches this file. -#0 regex/100 [\r\n\t\ ]*graph[\r\n\t\ ]+.*\\{ graphviz graph text +#0 regex/100l [\r\n\t\ ]*graph[\r\n\t\ ]+.*\\{ graphviz graph text #!:mime text/vnd.graphviz -#0 regex/100 [\r\n\t\ ]*digraph[\r\n\t\ ]+.*\\{ graphviz digraph text +#0 regex/100l [\r\n\t\ ]*digraph[\r\n\t\ ]+.*\\{ graphviz digraph text #!:mime text/vnd.graphviz diff --git a/contrib/file/magic/Magdir/hp b/contrib/file/magic/Magdir/hp index 3201c1567c..b01c3a40b0 100644 --- a/contrib/file/magic/Magdir/hp +++ b/contrib/file/magic/Magdir/hp @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: hp,v 1.23 2009/09/19 16:28:09 christos Exp $ +# $File: hp,v 1.24 2014/04/30 21:41:02 christos Exp $ # hp: file(1) magic for Hewlett Packard machines (see also "printer") # # XXX - somebody should figure out whether any byte order needs to be @@ -41,10 +41,10 @@ #### Old Apollo stuff 0 beshort 0627 Apollo m68k COFF executable >18 beshort ^040000 not stripped ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 0624 apollo a88k COFF executable >18 beshort ^040000 not stripped ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 long 01203604016 TML 0123 byte-order format 0 long 01702407010 TML 1032 byte-order format 0 long 01003405017 TML 2301 byte-order format @@ -128,58 +128,58 @@ #### 500 0 long 0x02080106 HP s500 relocatable executable ->16 long >0 - version %ld +>16 long >0 - version %d 0 long 0x02080107 HP s500 executable ->16 long >0 - version %ld +>16 long >0 - version %d 0 long 0x02080108 HP s500 pure executable ->16 long >0 - version %ld +>16 long >0 - version %d #### 200 0 belong 0x020c0108 HP s200 pure executable ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >8 belong &0x80000000 save fp regs >8 belong &0x40000000 dynamically linked >8 belong &0x20000000 debuggable >36 belong >0 not stripped 0 belong 0x020c0107 HP s200 executable ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >8 belong &0x80000000 save fp regs >8 belong &0x40000000 dynamically linked >8 belong &0x20000000 debuggable >36 belong >0 not stripped 0 belong 0x020c010b HP s200 demand-load executable ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >8 belong &0x80000000 save fp regs >8 belong &0x40000000 dynamically linked >8 belong &0x20000000 debuggable >36 belong >0 not stripped 0 belong 0x020c0106 HP s200 relocatable executable ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >6 beshort >0 - highwater %d >8 belong &0x80000000 save fp regs >8 belong &0x20000000 debuggable >8 belong &0x10000000 PIC 0 belong 0x020a0108 HP s200 (2.x release) pure executable ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >36 belong >0 not stripped 0 belong 0x020a0107 HP s200 (2.x release) executable ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >36 belong >0 not stripped 0 belong 0x020c010e HP s200 shared library ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >6 beshort >0 - highwater %d >36 belong >0 not stripped 0 belong 0x020c010d HP s200 dynamic load library ->4 beshort >0 - version %ld +>4 beshort >0 - version %d >6 beshort >0 - highwater %d >36 belong >0 not stripped @@ -192,7 +192,7 @@ 0 long 0x015821a6 HP core file 0 long 0x4da7eee8 HP-WINDOWS font ->8 byte >0 - version %ld +>8 byte >0 - version %d 0 string Bitmapfile HP Bitmapfile 0 string IMGfile CIS compimg HP Bitmapfile diff --git a/contrib/file/magic/Magdir/ibm370 b/contrib/file/magic/Magdir/ibm370 index 37d17bd8a5..7887dc3c5c 100644 --- a/contrib/file/magic/Magdir/ibm370 +++ b/contrib/file/magic/Magdir/ibm370 @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: ibm370,v 1.8 2009/09/19 16:28:09 christos Exp $ +# $File: ibm370,v 1.9 2014/04/30 21:41:02 christos Exp $ # ibm370: file(1) magic for IBM 370 and compatibles. # # "ibm370" said that 0x15d == 0535 was "ibm 370 pure executable". @@ -36,13 +36,13 @@ >12 belong >0 not stripped 0 beshort 0531 SVR2 executable (Amdahl-UTS) >12 belong >0 not stripped ->24 belong >0 - version %ld +>24 belong >0 - version %d 0 beshort 0534 SVR2 pure executable (Amdahl-UTS) >12 belong >0 not stripped ->24 belong >0 - version %ld +>24 belong >0 - version %d 0 beshort 0530 SVR2 pure executable (USS/370) >12 belong >0 not stripped ->24 belong >0 - version %ld +>24 belong >0 - version %d 0 beshort 0535 SVR2 executable (USS/370) >12 belong >0 not stripped ->24 belong >0 - version %ld +>24 belong >0 - version %d diff --git a/contrib/file/magic/Magdir/images b/contrib/file/magic/Magdir/images index 6497e593cf..672dd88ba7 100644 --- a/contrib/file/magic/Magdir/images +++ b/contrib/file/magic/Magdir/images @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: images,v 1.87 2013/12/11 14:14:20 christos Exp $ +# $File: images,v 1.102 2015/01/02 02:36:35 christos Exp $ # images: file(1) magic for image formats (see also "iff", and "c-lang" for # XPM bitmaps) # @@ -18,17 +18,20 @@ # `xv' recognizes only a subset of the following (RGB with pixelsize = 24) # `tgatoppm' recognizes a superset (Index may be anything) 1 belong&0xfff7ffff 0x01010000 Targa image data - Map +!:strength + 2 >2 byte&8 8 - RLE ->12 leshort >0 %hd x ->14 leshort >0 %hd +>12 leshort >0 %d x +>14 leshort >0 %d 1 belong&0xfff7ffff 0x00020000 Targa image data - RGB +!:strength + 2 >2 byte&8 8 - RLE ->12 leshort >0 %hd x ->14 leshort >0 %hd +>12 leshort >0 %d x +>14 leshort >0 %d 1 belong&0xfff7ffff 0x00030000 Targa image data - Mono +!:strength + 2 >2 byte&8 8 - RLE ->12 leshort >0 %hd x ->14 leshort >0 %hd +>12 leshort >0 %d x +>14 leshort >0 %d # PBMPLUS images # The next byte following the magic is always whitespace. @@ -112,8 +115,153 @@ # never changed. The TIFF specification recommends testing for it. 0 string MM\x00\x2a TIFF image data, big-endian !:mime image/tiff +>(4.L) use \^tiff_ifd 0 string II\x2a\x00 TIFF image data, little-endian !:mime image/tiff +>(4.l) use tiff_ifd + +0 name tiff_ifd +>0 leshort x \b, direntries=%d +>2 use tiff_entry + +0 name tiff_entry +# NewSubFileType +>0 leshort 0xfe +>>12 use tiff_entry +>0 leshort 0x100 +>>4 lelong 1 +>>>12 use tiff_entry +>>>8 leshort x \b, width=%d +>0 leshort 0x101 +>>4 lelong 1 +>>>8 leshort x \b, height=%d +>>>12 use tiff_entry +>0 leshort 0x102 +>>8 leshort x \b, bps=%d +>>12 use tiff_entry +>0 leshort 0x103 +>>4 lelong 1 \b, compression= +>>>8 leshort 1 \bnone +>>>8 leshort 2 \bhuffman +>>>8 leshort 3 \bbi-level group 3 +>>>8 leshort 4 \bbi-level group 4 +>>>8 leshort 5 \bLZW +>>>8 leshort 6 \bJPEG (old) +>>>8 leshort 7 \bJPEG +>>>8 leshort 8 \bdeflate +>>>8 leshort 9 \bJBIG, ITU-T T.85 +>>>8 leshort 0xa \bJBIG, ITU-T T.43 +>>>8 leshort 0x7ffe \bNeXT RLE 2-bit +>>>8 leshort 0x8005 \bPackBits (Macintosh RLE) +>>>8 leshort 0x8029 \bThunderscan RLE +>>>8 leshort 0x807f \bRasterPadding (CT or MP) +>>>8 leshort 0x8080 \bRLE (Line Work) +>>>8 leshort 0x8081 \bRLE (High-Res Cont-Tone) +>>>8 leshort 0x8082 \bRLE (Binary Line Work) +>>>8 leshort 0x80b2 \bDeflate (PKZIP) +>>>8 leshort 0x80b3 \bKodak DCS +>>>8 leshort 0x8765 \bJBIG +>>>8 leshort 0x8798 \bJPEG2000 +>>>8 leshort 0x8799 \bNikon NEF Compressed +>>>8 default x +>>>>8 leshort x \b(unknown 0x%x) +>>>12 use tiff_entry +>0 leshort 0x106 \b, PhotometricIntepretation= +>>8 leshort 0 \bWhiteIsZero +>>8 leshort 1 \bBlackIsZero +>>8 leshort 2 \bRGB +>>8 leshort 3 \bRGB Palette +>>8 leshort 4 \bTransparency Mask +>>8 leshort 5 \bCMYK +>>8 leshort 6 \bYCbCr +>>8 leshort 8 \bCIELab +>>>8 leshort x \b(unknown=0x%x) +>>12 use tiff_entry +# FillOrder +>0 leshort 0x10a +>>4 lelong 1 +>>>12 use tiff_entry +# DocumentName +>0 leshort 0x10d +>>(8.l) string x \b, name=%s +>>>12 use tiff_entry +# ImageDescription +>0 leshort 0x10e +>>(8.l) string x \b, description=%s +>>>12 use tiff_entry +# Make +>0 leshort 0x10f +>>(8.l) string x \b, manufacturer=%s +>>>12 use tiff_entry +# Model +>0 leshort 0x110 +>>(8.l) string x \b, model=%s +>>>12 use tiff_entry +# StripOffsets +>0 leshort 0x111 +>>12 use tiff_entry +# Orientation +>0 leshort 0x112 \b, orientation= +>>8 leshort 1 \bupper-left +>>8 leshort 3 \blower-right +>>8 leshort 6 \bupper-right +>>8 leshort 8 \blower-left +>>8 leshort 9 \bundefined +>>8 default x +>>>8 leshort x \b[*%d*] +>>12 use tiff_entry +# XResolution +>0 leshort 0x11a +>>8 lelong x \b, xresolution=%d +>>12 use tiff_entry +# YResolution +>0 leshort 0x11b +>>8 lelong x \b, yresolution=%d +>>12 use tiff_entry +# ResolutionUnit +>0 leshort 0x128 +>>8 leshort x \b, resolutionunit=%d +>>12 use tiff_entry +# Software +>0 leshort 0x131 +>>(8.l) string x \b, software=%s +>>12 use tiff_entry +# Datetime +>0 leshort 0x132 +>>(8.l) string x \b, datetime=%s +>>12 use tiff_entry +# HostComputer +>0 leshort 0x13c +>>(8.l) string x \b, hostcomputer=%s +>>12 use tiff_entry +# WhitePoint +>0 leshort 0x13e +>>12 use tiff_entry +# PrimaryChromaticities +>0 leshort 0x13f +>>12 use tiff_entry +# YCbCrCoefficients +>0 leshort 0x211 +>>12 use tiff_entry +# YCbCrPositioning +>0 leshort 0x213 +>>12 use tiff_entry +# ReferenceBlackWhite +>0 leshort 0x214 +>>12 use tiff_entry +# Copyright +>0 leshort 0x8298 +>>(8.l) string x \b, copyright=%s +>>12 use tiff_entry +# ExifOffset +>0 leshort 0x8769 +>>12 use tiff_entry +# GPS IFD +>0 leshort 0x8825 \b, GPS-Data +>>12 use tiff_entry + +#>0 leshort x \b, unknown=0x%x +#>>12 use tiff_entry 0 string MM\x00\x2b Big TIFF image data, big-endian !:mime image/tiff @@ -128,8 +276,8 @@ # 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data !:mime image/png ->16 belong x \b, %ld x ->20 belong x %ld, +>16 belong x \b, %d x +>20 belong x %d, >24 byte x %d-bit >25 byte 0 grayscale, >25 byte 2 \b/color RGB, @@ -164,8 +312,8 @@ !:apple 8BIMGIFf >4 string 7a \b, version 8%s, >4 string 9a \b, version 8%s, ->6 leshort >0 %hd x ->8 leshort >0 %hd +>6 leshort >0 %d x +>8 leshort >0 %d #>10 byte &0x80 color mapped, #>10 byte&0x07 =0x00 2 colors #>10 byte&0x07 =0x01 4 colors @@ -483,7 +631,7 @@ >>>>1 ubyte 3 ver. 2.8 image data, without palette >>>>1 ubyte 4 for Windows image data >>>>1 ubyte 5 ver. 3.0 image data ->>>>4 uleshort x bounding box [%hd, +>>>>4 uleshort x bounding box [%d, >>>>6 uleshort x %d] - >>>>8 uleshort x [%d, >>>>10 uleshort x %d], @@ -618,7 +766,7 @@ # Author: Hans-Joachim Baader 0 string PaRtImAgE-VoLuMe PartImage >0x0020 string 0.6.1 file version %s ->>0x0060 lelong >-1 volume %ld +>>0x0060 lelong >-1 volume %d #>>0x0064 8 byte identifier #>>0x007c reserved >>0x0200 string >\0 type %s @@ -641,8 +789,8 @@ # Kodak Cineon format for scanned negatives # http://www.kodak.com/US/en/motion/support/dlad/ 0 lelong 0xd75f2a80 Cineon image data ->200 belong >0 \b, %ld x ->204 belong >0 %ld +>200 belong >0 \b, %d x +>204 belong >0 %d # Bio-Rad .PIC is an image format used by microscope control systems @@ -654,10 +802,10 @@ 14 leshort <2 >62 leshort <2 >>54 leshort 12345 Bio-Rad .PIC Image File ->>>0 leshort >0 %hd x ->>>2 leshort >0 %hd, +>>>0 leshort >0 %d x +>>>2 leshort >0 %d, >>>4 leshort =1 1 image in file ->>>4 leshort >1 %hd images in file +>>>4 leshort >1 %d images in file # From Jan "Yenya" Kasprzak # The description of *.mrw format can be found at @@ -823,7 +971,7 @@ 0 string/t [BitmapInfo2] Polar Monitor Bitmap text !:mime image/x-polar-monitor-bitmap -# From: Rick Richardson +# From: Rick Richardson 0 string GARMIN\ BITMAP\ 01 Garmin Bitmap file # Type: Ulead Photo Explorer5 (.pe5) @@ -889,6 +1037,65 @@ 0 string \x46\x4d\x52\x00 ISO/IEC 19794-2 Format Minutiae Record (FMR) # WEBP https://developers.google.com/speed/webp/docs/riff_container -0 string RIFF ->8 string WEBP Web/P image data ->>4 lelong x \b, %d bytes +#0 string RIFF +#>8 string WEBP Web/P image data +#>>4 lelong x \b, %d bytes + +# doc: http://www.shikino.co.jp/eng/products/images/FLOWER.jpg.zip +# example: http://www.shikino.co.jp/eng/products/images/FLOWER.wdp.zip +90 bequad 0x574D50484F544F00 JPEG-XR Image +>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 0x%x) + +# From: Johan van der Knijff +# +# BPG (Better Portable Graphics) format +# http://bellard.org/bpg/ +# http://fileformats.archiveteam.org/wiki/BPG +# +0 string \x42\x50\x47\xFB BPG (Better Portable Graphics) +!:mime image/bpg diff --git a/contrib/file/magic/Magdir/intel b/contrib/file/magic/Magdir/intel index c3657f0533..9fa90f4784 100644 --- a/contrib/file/magic/Magdir/intel +++ b/contrib/file/magic/Magdir/intel @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: intel,v 1.11 2013/02/06 14:18:52 christos Exp $ +# $File: intel,v 1.12 2014/04/30 21:41:02 christos Exp $ # intel: file(1) magic for x86 Unix # # Various flavors of x86 UNIX executable/object (other than Xenix, which @@ -16,24 +16,24 @@ # 0 leshort 0502 basic-16 executable >12 lelong >0 not stripped -#>22 leshort >0 - version %ld +#>22 leshort >0 - version %d 0 leshort 0503 basic-16 executable (TV) >12 lelong >0 not stripped -#>22 leshort >0 - version %ld +#>22 leshort >0 - version %d 0 leshort 0510 x86 executable >12 lelong >0 not stripped 0 leshort 0511 x86 executable (TV) >12 lelong >0 not stripped 0 leshort =0512 iAPX 286 executable small model (COFF) >12 lelong >0 not stripped -#>22 leshort >0 - version %ld +#>22 leshort >0 - version %d 0 leshort =0522 iAPX 286 executable large model (COFF) >12 lelong >0 not stripped -#>22 leshort >0 - version %ld +#>22 leshort >0 - version %d # SGI labeled the next entry as "iAPX 386 executable" --Dan Quinlan 0 leshort =0514 80386 COFF executable >12 lelong >0 not stripped ->22 leshort >0 - version %ld +>22 leshort >0 - version %d # rom: file(1) magic for BIOS ROM Extensions found in intel machines # mapped into memory between 0xC0000 and 0xFFFFF diff --git a/contrib/file/magic/Magdir/isz b/contrib/file/magic/Magdir/isz index 316bbd4acf..3388a82a5b 100644 --- a/contrib/file/magic/Magdir/isz +++ b/contrib/file/magic/Magdir/isz @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: isz,v 1.1 2010/03/27 16:17:09 christos Exp $ +# $File: isz,v 1.3 2014/04/30 21:41:02 christos Exp $ # ISO Zipped file format # http://www.ezbsystems.com/isz/iszspec.txt 0 string IsZ! ISO Zipped file diff --git a/contrib/file/magic/Magdir/jpeg b/contrib/file/magic/Magdir/jpeg index bc8b342664..cfe8973693 100644 --- a/contrib/file/magic/Magdir/jpeg +++ b/contrib/file/magic/Magdir/jpeg @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: jpeg,v 1.19 2013/02/04 15:50:03 christos Exp $ +# $File: jpeg,v 1.25 2015/01/02 16:56:50 christos Exp $ # JPEG images # SunOS 5.5.1 had # @@ -22,132 +22,73 @@ >>11 byte x \b %d. >>12 byte x \b%02d # Next, the resolution or aspect ratio of the image: -#>>13 byte 0 \b, aspect ratio -#>>13 byte 1 \b, resolution (DPI) -#>>13 byte 2 \b, resolution (DPCM) -#>>4 beshort x \b, segment length %d +>>13 byte 0 \b, aspect ratio +>>13 byte 1 \b, resolution (DPI) +>>13 byte 2 \b, resolution (DPCM) +>>14 beshort x \b, density %dx +>>16 beshort x \b%d +>>4 beshort x \b, segment length %d # Next, show thumbnail info, if it exists: >>18 byte !0 \b, thumbnail %dx >>>19 byte x \b%d +>6 string Exif \b, Exif standard: [ +>>12 indirect/r x +>>12 string x \b] -# EXIF moved down here to avoid reporting a bogus version number, -# and EXIF version number printing added. -# - Patrik R=E5dman ->6 string Exif \b, EXIF standard -# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD. -# All possible combinations of entries have to be enumerated, since no looping -# is possible. And both endians are possible... -# The combinations included below are from real-world JPEGs. -# Little-endian ->>12 string II -# IFD 0 Entry #5: ->>>70 leshort 0x8769 -# EXIF IFD Entry #1: ->>>>(78.l+14) leshort 0x9000 ->>>>>(78.l+23) byte x %c ->>>>>(78.l+24) byte x \b.%c ->>>>>(78.l+25) byte !0x30 \b%c -# IFD 0 Entry #9: ->>>118 leshort 0x8769 -# EXIF IFD Entry #3: ->>>>(126.l+38) leshort 0x9000 ->>>>>(126.l+47) byte x %c ->>>>>(126.l+48) byte x \b.%c ->>>>>(126.l+49) byte !0x30 \b%c -# IFD 0 Entry #10 ->>>130 leshort 0x8769 -# EXIF IFD Entry #3: ->>>>(138.l+38) leshort 0x9000 ->>>>>(138.l+47) byte x %c ->>>>>(138.l+48) byte x \b.%c ->>>>>(138.l+49) byte !0x30 \b%c -# EXIF IFD Entry #4: ->>>>(138.l+50) leshort 0x9000 ->>>>>(138.l+59) byte x %c ->>>>>(138.l+60) byte x \b.%c ->>>>>(138.l+61) byte !0x30 \b%c -# EXIF IFD Entry #5: ->>>>(138.l+62) leshort 0x9000 ->>>>>(138.l+71) byte x %c ->>>>>(138.l+72) byte x \b.%c ->>>>>(138.l+73) byte !0x30 \b%c -# IFD 0 Entry #11 ->>>142 leshort 0x8769 -# EXIF IFD Entry #3: ->>>>(150.l+38) leshort 0x9000 ->>>>>(150.l+47) byte x %c ->>>>>(150.l+48) byte x \b.%c ->>>>>(150.l+49) byte !0x30 \b%c -# EXIF IFD Entry #4: ->>>>(150.l+50) leshort 0x9000 ->>>>>(150.l+59) byte x %c ->>>>>(150.l+60) byte x \b.%c ->>>>>(150.l+61) byte !0x30 \b%c -# EXIF IFD Entry #5: ->>>>(150.l+62) leshort 0x9000 ->>>>>(150.l+71) byte x %c ->>>>>(150.l+72) byte x \b.%c ->>>>>(150.l+73) byte !0x30 \b%c -# Big-endian ->>12 string MM -# IFD 0 Entry #9: ->>>118 beshort 0x8769 -# EXIF IFD Entry #1: ->>>>(126.L+14) beshort 0x9000 ->>>>>(126.L+23) byte x %c ->>>>>(126.L+24) byte x \b.%c ->>>>>(126.L+25) byte !0x30 \b%c -# EXIF IFD Entry #3: ->>>>(126.L+38) beshort 0x9000 ->>>>>(126.L+47) byte x %c ->>>>>(126.L+48) byte x \b.%c ->>>>>(126.L+49) byte !0x30 \b%c -# IFD 0 Entry #10 ->>>130 beshort 0x8769 -# EXIF IFD Entry #3: ->>>>(138.L+38) beshort 0x9000 ->>>>>(138.L+47) byte x %c ->>>>>(138.L+48) byte x \b.%c ->>>>>(138.L+49) byte !0x30 \b%c -# EXIF IFD Entry #5: ->>>>(138.L+62) beshort 0x9000 ->>>>>(138.L+71) byte x %c ->>>>>(138.L+72) byte x \b.%c ->>>>>(138.L+73) byte !0x30 \b%c -# IFD 0 Entry #11 ->>>142 beshort 0x8769 -# EXIF IFD Entry #4: ->>>>(150.L+50) beshort 0x9000 ->>>>>(150.L+59) byte x %c ->>>>>(150.L+60) byte x \b.%c ->>>>>(150.L+61) byte !0x30 \b%c -# Here things get sticky. We can do ONE MORE marker segment with -# indirect addressing, and that's all. It would be great if we could -# do pointer arithemetic like in an assembler language. Christos? -# And if there was some sort of looping construct to do searches, plus a few -# named accumulators, it would be even more effective... -# At least we can show a comment if no other segments got inserted before: ->(4.S+5) byte 0xFE \b, comment: ->>(4.S+6) pstring/HJ x "%s" -# Or, we can show the encoding type (I've included only the three most common) -# and image dimensions if we are lucky and the SOFn (image segment) is here: ->(4.S+5) byte 0xC0 \b, baseline ->>(4.S+6) byte x \b, precision %d ->>(4.S+7) beshort x \b, %dx ->>(4.S+9) beshort x \b%d ->(4.S+5) byte 0xC1 \b, extended sequential ->>(4.S+6) byte x \b, precision %d ->>(4.S+7) beshort x \b, %dx ->>(4.S+9) beshort x \b%d ->(4.S+5) byte 0xC2 \b, progressive ->>(4.S+6) byte x \b, precision %d ->>(4.S+7) beshort x \b, %dx ->>(4.S+9) beshort x \b%d -# I've commented-out quantisation table reporting. I doubt anyone cares yet. -#>(4.S+5) byte 0xDB \b, quantisation table -#>>(4.S+6) beshort x \b length=%d -#>14 beshort x \b, %d x -#>16 beshort x \b %d +# Jump to the first segment +>(4.S+4) use jpeg_segment + +# This uses recursion... +0 name jpeg_segment +>0 beshort 0xFFFE +>>(2.S+2) use jpeg_segment +>>2 pstring/HJ x \b, comment: "%s" + +>0 beshort 0xFFC0 +>>(2.S+2) use jpeg_segment +>>4 byte x \b, baseline, precision %d +>>7 beshort x \b, %dx +>>5 beshort x \b%d +>>9 byte x \b, frames %d + +>0 beshort 0xFFC1 +>>(2.S+2) use jpeg_segment +>>4 byte x \b, extended sequential, precision %d +>>7 beshort x \b, %dx +>>5 beshort x \b%d +>>9 byte x \b, frames %d + +>0 beshort 0xFFC2 +>>(2.S+2) use jpeg_segment +>>4 byte x \b, progressive, precision %d +>>7 beshort x \b, %dx +>>5 beshort x \b%d +>>9 byte x \b, frames %d + +# Define Huffman Tables +>0 beshort 0xFFC4 +>>(2.S+2) use jpeg_segment + +>0 beshort 0xFFE1 +#>>(2.S+2) use jpeg_segment +>>4 string Exif \b, Exif Standard: [ +>>>10 indirect/r x +>>>10 string x \b] + +# Application specific markers +>0 beshort&0xFFE0 =0xFFE0 +>>(2.S+2) use jpeg_segment + +# DB: Define Quantization tables +# DD: Define Restart interval [XXX: wrong here, it is 4 bytes] +# D8: Start of image +# D9: End of image +# Dn: Restart +>0 beshort&0xFFD0 =0xFFD0 +>>(2.S+2) use jpeg_segment + +#>0 beshort x unknown 0x%x +#>>(2.S+2) use jpeg_segment # HSI is Handmade Software's proprietary JPEG encoding scheme 0 string hsi1 JPEG image data, HSI proprietary diff --git a/contrib/file/magic/Magdir/karma b/contrib/file/magic/Magdir/karma index 007a4b74b2..47d5d97304 100644 --- a/contrib/file/magic/Magdir/karma +++ b/contrib/file/magic/Magdir/karma @@ -1,9 +1,9 @@ #------------------------------------------------------------------------------ -# $File: karma,v 1.6 2009/09/19 16:28:10 christos Exp $ +# $File: karma,v 1.7 2014/04/30 21:41:02 christos Exp $ # karma: file(1) magic for Karma data files # # From 0 string KarmaRHD Version Karma Data Structure Version ->16 belong x %lu +>16 belong x %u diff --git a/contrib/file/magic/Magdir/kerberos b/contrib/file/magic/Magdir/kerberos new file mode 100644 index 0000000000..cb07fedbe2 --- /dev/null +++ b/contrib/file/magic/Magdir/kerberos @@ -0,0 +1,45 @@ + +#------------------------------------------------------------------------------ +# $File: kerberos,v 1.1 2014/12/10 18:45:43 christos Exp $ +# kerberos: MIT kerberos file binary formats +# + +# This magic entry is for demonstration purposes and could be improved +# if the following features were implemented in file: +# +# Strings inside [[ .. ]] in the descriptions have special meanings and +# are not printed. +# +# - Provide some form of iteration in number of components +# [[${counter}=%d]] in the description +# then append +# [${counter}--] in the offset of the entries +# - Provide a way to round the next offset +# Add [R:4] after the offset? +# - Provide a way to have optional entries +# XXX: Syntax: +# - Provide a way to "save" entries to print them later. +# if the description is [[${name}=%s]], then nothing is +# printed and a subsequent entry in the same magic file +# can refer to ${name} +# - Provide a way to format strings as hex values +# +# http://www.gnu.org/software/shishi/manual/html_node/\ +# The-Keytab-Binary-File-Format.html +# + +0 name keytab_entry +#>0 beshort x \b, size=%d +#>2 beshort x \b, components=%d +>4 pstring/H x \b, realm=%s +>>&0 pstring/H x \b, principal=%s/ +>>>&0 pstring/H x \b%s +>>>>&0 belong x \b, type=%d +>>>>>&0 bedate x \b, date=%s +>>>>>>&0 byte x \b, kvno=%u +#>>>>>>>&0 pstring/H x +#>>>>>>>>&0 belong x +#>>>>>>>>>>&0 use keytab_entry + +0 belong 0x05020000 Kerberos Keytab file +>4 use keytab_entry diff --git a/contrib/file/magic/Magdir/linux b/contrib/file/magic/Magdir/linux index 4360f2dcf4..d3f6a9d6d7 100644 --- a/contrib/file/magic/Magdir/linux +++ b/contrib/file/magic/Magdir/linux @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: linux,v 1.54 2014/03/02 00:01:29 christos Exp $ +# $File: linux,v 1.59 2014/11/03 21:03:36 christos Exp $ # linux: file(1) magic for Linux files # # Values for Linux/i386 binaries, from Daniel Quinlan @@ -396,3 +396,39 @@ >>0x1042 ubelong x \b-%08x >>0x1046 ubeshort x \b%04x +# Linux device tree: +# File format description can be found in the Linux kernel sources at +# Documentation/devicetree/booting-without-of.txt +# From Christoph Biedl +0 belong 0xd00dfeed +# structure and strings must be within blob +>&(8.L) byte x +>>&(12.L) byte x +>>>20 belong >1 Device Tree Blob version %d +>>>>4 belong x \b, size=%d +>>>>20 belong >1 +>>>>>28 belong x \b, boot CPU=%d +>>>>20 belong >2 +>>>>>32 belong x \b, string block size=%d +>>>>20 belong >16 +>>>>>36 belong x \b, DT structure block size=%d + +# glibc locale archive as defined in glibc locale/locarchive.h +0 lelong 0xde020109 locale archive +>24 lelong x %d strings + +# Summary: Database file for mlocate +# Description: A database file as used by mlocate, a fast implementation +# of locate/updatedb. It uses merging to reuse the existing +# database and avoid rereading most of the filesystem. It's +# the default version of locate on Arch Linux (and others). +# File path: /var/lib/mlocate/mlocate.db by default (but configurable) +# Site: https://fedorahosted.org/mlocate/ +# Format docs: http://linux.die.net/man/5/mlocate.db +# Type: mlocate database file +# URL: https://fedorahosted.org/mlocate/ +# From: Wander Nauta +0 string \0mlocate mlocate database +>12 byte x \b, version %d +>13 byte 1 \b, require visibility +>16 string x \b, root %s diff --git a/contrib/file/magic/Magdir/mach b/contrib/file/magic/Magdir/mach index fccb17b7cb..23b9f8a126 100644 --- a/contrib/file/magic/Magdir/mach +++ b/contrib/file/magic/Magdir/mach @@ -1,6 +1,6 @@ #------------------------------------------------------------ -# $File: mach,v 1.17 2013/03/07 02:22:52 christos Exp $ +# $File: mach,v 1.19 2014/04/30 21:41:02 christos Exp $ # Mach has two magic numbers, 0xcafebabe and 0xfeedface. # Unfortunately the first, cafebabe, is shared with # Java ByteCode, so they are both handled in the file "cafebabe". @@ -31,7 +31,7 @@ >>>4 belong&0x00ffffff 10 vax8650 >>>4 belong&0x00ffffff 11 vax8800 >>>4 belong&0x00ffffff 12 uvaxIII ->>>4 belong&0x00ffffff >12 vax subarchitecture=%ld +>>>4 belong&0x00ffffff >12 vax subarchitecture=%d >>0 belong&0x00ffffff 2 romp >>0 belong&0x00ffffff 3 architecture=3 >>0 belong&0x00ffffff 4 ns32032 @@ -51,40 +51,40 @@ >>>>4 belong&0x00fffff0 0x30 pentium_2_m3 >>>>4 belong&0x00fffff0 0x40 pentium_2_m0x40 >>>>4 belong&0x00fffff0 0x50 pentium_2_m5 ->>>>4 belong&0x00fffff0 >0x50 pentium_2_m0x%lx +>>>>4 belong&0x00fffff0 >0x50 pentium_2_m0x%x >>>4 belong&0x0000000f 7 celeron ->>>>4 belong&0x00fffff0 0x00 \b_m0x%lx ->>>>4 belong&0x00fffff0 0x10 \b_m0x%lx ->>>>4 belong&0x00fffff0 0x20 \b_m0x%lx ->>>>4 belong&0x00fffff0 0x30 \b_m0x%lx ->>>>4 belong&0x00fffff0 0x40 \b_m0x%lx ->>>>4 belong&0x00fffff0 0x50 \b_m0x%lx +>>>>4 belong&0x00fffff0 0x00 \b_m0x%x +>>>>4 belong&0x00fffff0 0x10 \b_m0x%x +>>>>4 belong&0x00fffff0 0x20 \b_m0x%x +>>>>4 belong&0x00fffff0 0x30 \b_m0x%x +>>>>4 belong&0x00fffff0 0x40 \b_m0x%x +>>>>4 belong&0x00fffff0 0x50 \b_m0x%x >>>>4 belong&0x00fffff0 0x60 >>>>4 belong&0x00fffff0 0x70 \b_mobile ->>>>4 belong&0x00fffff0 >0x70 \b_m0x%lx +>>>>4 belong&0x00fffff0 >0x70 \b_m0x%x >>>4 belong&0x0000000f 8 pentium_3 >>>>4 belong&0x00fffff0 0x00 >>>>4 belong&0x00fffff0 0x10 \b_m >>>>4 belong&0x00fffff0 0x20 \b_xeon ->>>>4 belong&0x00fffff0 >0x20 \b_m0x%lx +>>>>4 belong&0x00fffff0 >0x20 \b_m0x%x >>>4 belong&0x0000000f 9 pentiumM >>>>4 belong&0x00fffff0 0x00 ->>>>4 belong&0x00fffff0 >0x00 \b_m0x%lx +>>>>4 belong&0x00fffff0 >0x00 \b_m0x%x >>>4 belong&0x0000000f 10 pentium_4 >>>>4 belong&0x00fffff0 0x00 >>>>4 belong&0x00fffff0 0x10 \b_m ->>>>4 belong&0x00fffff0 >0x10 \b_m0x%lx +>>>>4 belong&0x00fffff0 >0x10 \b_m0x%x >>>4 belong&0x0000000f 11 itanium >>>>4 belong&0x00fffff0 0x00 >>>>4 belong&0x00fffff0 0x10 \b_2 ->>>>4 belong&0x00fffff0 >0x10 \b_m0x%lx +>>>>4 belong&0x00fffff0 >0x10 \b_m0x%x >>>4 belong&0x0000000f 12 xeon >>>>4 belong&0x00fffff0 0x00 >>>>4 belong&0x00fffff0 0x10 \b_mp ->>>>4 belong&0x00fffff0 >0x10 \b_m0x%lx ->>>4 belong&0x0000000f >12 ia32 family=%ld +>>>>4 belong&0x00fffff0 >0x10 \b_m0x%x +>>>4 belong&0x0000000f >12 ia32 family=%d >>>>4 belong&0x00fffff0 0x00 ->>>>4 belong&0x00fffff0 >0x00 model=%lx +>>>>4 belong&0x00fffff0 >0x00 model=%x >>0 belong&0x00ffffff 8 mips >>>4 belong&0x00ffffff 1 R2300 >>>4 belong&0x00ffffff 2 R2600 @@ -93,35 +93,35 @@ >>>4 belong&0x00ffffff 5 R2000 >>>4 belong&0x00ffffff 6 R3000a >>>4 belong&0x00ffffff 7 R3000 ->>>4 belong&0x00ffffff >7 subarchitecture=%ld +>>>4 belong&0x00ffffff >7 subarchitecture=%d >>0 belong&0x00ffffff 9 ns32532 >>0 belong&0x00ffffff 10 mc98000 >>0 belong&0x00ffffff 11 hppa >>>4 belong&0x00ffffff 0 7100 >>>4 belong&0x00ffffff 1 7100LC ->>>4 belong&0x00ffffff >1 subarchitecture=%ld +>>>4 belong&0x00ffffff >1 subarchitecture=%d >>0 belong&0x00ffffff 12 arm >>>4 belong&0x00ffffff 0 ->>>4 belong&0x00ffffff 1 subarchitecture=%ld ->>>4 belong&0x00ffffff 2 subarchitecture=%ld ->>>4 belong&0x00ffffff 3 subarchitecture=%ld ->>>4 belong&0x00ffffff 4 subarchitecture=%ld +>>>4 belong&0x00ffffff 1 subarchitecture=%d +>>>4 belong&0x00ffffff 2 subarchitecture=%d +>>>4 belong&0x00ffffff 3 subarchitecture=%d +>>>4 belong&0x00ffffff 4 subarchitecture=%d >>>4 belong&0x00ffffff 5 \b_v4t >>>4 belong&0x00ffffff 6 \b_v6 >>>4 belong&0x00ffffff 7 \b_v5tej >>>4 belong&0x00ffffff 8 \b_xscale >>>4 belong&0x00ffffff 9 \b_v7 >>>4 belong&0x00ffffff 10 \b_v7f ->>>4 belong&0x00ffffff 11 subarchitecture=%ld +>>>4 belong&0x00ffffff 11 subarchitecture=%d >>>4 belong&0x00ffffff 12 \b_v7k ->>>4 belong&0x00ffffff >12 subarchitecture=%ld +>>>4 belong&0x00ffffff >12 subarchitecture=%d # 13 m88k >>0 belong&0x00ffffff 13 >>>4 belong&0x00ffffff 0 mc88000 >>>4 belong&0x00ffffff 1 mc88100 >>>4 belong&0x00ffffff 2 mc88110 ->>>4 belong&0x00ffffff >2 mc88000 subarchitecture=%ld ->>0 belong&0x00ffffff 14 sparc +>>>4 belong&0x00ffffff >2 mc88000 subarchitecture=%d +>>0 belong&0x00ffffff 14 SPARC >>0 belong&0x00ffffff 15 i860g >>0 belong&0x00ffffff 16 alpha >>0 belong&0x00ffffff 17 rs6000 @@ -139,36 +139,36 @@ >>>4 belong&0x00ffffff 10 \b_7400 >>>4 belong&0x00ffffff 11 \b_7450 >>>4 belong&0x00ffffff 100 \b_970 ->>>4 belong&0x00ffffff >100 subarchitecture=%ld ->>0 belong&0x00ffffff >18 architecture=%ld +>>>4 belong&0x00ffffff >100 subarchitecture=%d +>>0 belong&0x00ffffff >18 architecture=%d >0 belong&0x01000000 0x01000000 # # 64-bit ABIs. # ->>0 belong&0x00ffffff 0 64-bit architecture=%ld ->>0 belong&0x00ffffff 1 64-bit architecture=%ld ->>0 belong&0x00ffffff 2 64-bit architecture=%ld ->>0 belong&0x00ffffff 3 64-bit architecture=%ld ->>0 belong&0x00ffffff 4 64-bit architecture=%ld ->>0 belong&0x00ffffff 5 64-bit architecture=%ld ->>0 belong&0x00ffffff 6 64-bit architecture=%ld +>>0 belong&0x00ffffff 0 64-bit architecture=%d +>>0 belong&0x00ffffff 1 64-bit architecture=%d +>>0 belong&0x00ffffff 2 64-bit architecture=%d +>>0 belong&0x00ffffff 3 64-bit architecture=%d +>>0 belong&0x00ffffff 4 64-bit architecture=%d +>>0 belong&0x00ffffff 5 64-bit architecture=%d +>>0 belong&0x00ffffff 6 64-bit architecture=%d >>0 belong&0x00ffffff 7 x86_64 ->>>4 belong&0x00ffffff 0 subarchitecture=%ld ->>>4 belong&0x00ffffff 1 subarchitecture=%ld ->>>4 belong&0x00ffffff 2 subarchitecture=%ld +>>>4 belong&0x00ffffff 0 subarchitecture=%d +>>>4 belong&0x00ffffff 1 subarchitecture=%d +>>>4 belong&0x00ffffff 2 subarchitecture=%d >>>4 belong&0x00ffffff 3 >>>4 belong&0x00ffffff 4 \b_arch1 ->>>4 belong&0x00ffffff >4 subarchitecture=%ld ->>0 belong&0x00ffffff 8 64-bit architecture=%ld ->>0 belong&0x00ffffff 9 64-bit architecture=%ld ->>0 belong&0x00ffffff 10 64-bit architecture=%ld ->>0 belong&0x00ffffff 11 64-bit architecture=%ld ->>0 belong&0x00ffffff 12 64-bit architecture=%ld ->>0 belong&0x00ffffff 13 64-bit architecture=%ld ->>0 belong&0x00ffffff 14 64-bit architecture=%ld ->>0 belong&0x00ffffff 15 64-bit architecture=%ld ->>0 belong&0x00ffffff 16 64-bit architecture=%ld ->>0 belong&0x00ffffff 17 64-bit architecture=%ld +>>>4 belong&0x00ffffff >4 subarchitecture=%d +>>0 belong&0x00ffffff 8 64-bit architecture=%d +>>0 belong&0x00ffffff 9 64-bit architecture=%d +>>0 belong&0x00ffffff 10 64-bit architecture=%d +>>0 belong&0x00ffffff 11 64-bit architecture=%d +>>0 belong&0x00ffffff 12 64-bit architecture=%d +>>0 belong&0x00ffffff 13 64-bit architecture=%d +>>0 belong&0x00ffffff 14 64-bit architecture=%d +>>0 belong&0x00ffffff 15 64-bit architecture=%d +>>0 belong&0x00ffffff 16 64-bit architecture=%d +>>0 belong&0x00ffffff 17 64-bit architecture=%d >>0 belong&0x00ffffff 18 ppc64 >>>4 belong&0x00ffffff 0 >>>4 belong&0x00ffffff 1 \b_601 @@ -183,8 +183,8 @@ >>>4 belong&0x00ffffff 10 \b_7400 >>>4 belong&0x00ffffff 11 \b_7450 >>>4 belong&0x00ffffff 100 \b_970 ->>>4 belong&0x00ffffff >100 subarchitecture=%ld ->>0 belong&0x00ffffff >18 64-bit architecture=%ld +>>>4 belong&0x00ffffff >100 subarchitecture=%d +>>0 belong&0x00ffffff >18 64-bit architecture=%d 0 name mach-o-be @@ -202,7 +202,7 @@ >12 belong 10 dSYM companion file >12 belong 11 kext bundle >12 belong >11 ->>12 belong x filetype=%ld +>>12 belong x filetype=%d # 0 lelong&0xfffffffe 0xfeedface Mach-O diff --git a/contrib/file/magic/Magdir/macintosh b/contrib/file/magic/Magdir/macintosh index d86fd8f4fd..3ca2cab274 100644 --- a/contrib/file/magic/Magdir/macintosh +++ b/contrib/file/magic/Magdir/macintosh @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: macintosh,v 1.23 2013/11/19 18:47:58 christos Exp $ +# $File: macintosh,v 1.25 2014/09/03 13:34:16 christos Exp $ # macintosh description # # BinHex is the Macintosh ASCII-encoded file format (see also "apple") @@ -165,7 +165,7 @@ #>65 string ZSYS (Pre-System 7 system file) #>65 string acf3 (Aldus FreeHand) #>65 string cdev (control panel) -#>65 string dfil (Desk Acessory suitcase) +#>65 string dfil (Desk Accessory suitcase) #>65 string libr (library) #>65 string nX^d (WriteNow word processor) #>65 string nX^w (WriteNow dictionary) @@ -288,20 +288,38 @@ >0x412 beshort x number of blocks: %d, >0x424 pstring x volume name: %s +# *.hfs updated by Joerg Jenderek +# http://en.wikipedia.org/wiki/Hierarchical_File_System # "BD" gives many false positives -#0x400 beshort 0x4244 Macintosh HFS data -#>0 beshort 0x4C4B (bootable) -#>0x40a beshort &0x8000 (locked) -#>0x40a beshort ^0x0100 (mounted) -#>0x40a beshort &0x0200 (spared blocks) -#>0x40a beshort &0x0800 (unclean) -#>0x47C beshort 0x482B (Embedded HFS+ Volume) -#>0x402 beldate-0x7C25B080 x created: %s, -#>0x406 beldate-0x7C25B080 x last modified: %s, -#>0x440 beldate-0x7C25B080 >0 last backup: %s, -#>0x414 belong x block size: %d, -#>0x412 beshort x number of blocks: %d, -#>0x424 pstring x volume name: %s +0x400 beshort 0x4244 +# ftp://ftp.mars.org/pub/hfs/hfsutils-3.2.6.tar.gz/hfsutils-3.2.6/libhfs/apple.h +# first block of volume bit map (always 3) +>0x40e ubeshort 0x0003 +# maximal length of volume name is 27 +>>0x424 ubyte <28 Macintosh HFS data +#!:mime application/octet-stream +# these mime and apple types are not sure +!:mime application/x-apple-diskimage +#!:apple hfsdINIT +#!:apple MACSdisk +>>>0 beshort 0x4C4B (bootable) +#>>>0 beshort 0x0000 (not bootable) +>>>0x40a beshort &0x8000 (locked) +>>>0x40a beshort ^0x0100 (mounted) +>>>0x40a beshort &0x0200 (spared blocks) +>>>0x40a beshort &0x0800 (unclean) +>>>0x47C beshort 0x482B (Embedded HFS+ Volume) +# http://www.epochconverter.com/ +# 0x7C245F00 seconds ~ 2082758400 ~ 01 Jan 2036 00:00:00 ~ 66 years to 1970 +# 0x7C25B080 seconds ~ 2082844800 ~ 02 Jan 2036 00:00:00 +# construct not working +#>>>0x402 beldate-0x7C25B080 x created: %s, +#>>>0x406 beldate-0x7C25B080 x last modified: %s, +#>>>0x440 beldate-0x7C25B080 >0 last backup: %s, +# found block sizes 200h,1200h,2800h +>>>0x414 belong x block size: %d, +>>>0x412 beshort x number of blocks: %d, +>>>0x424 pstring x volume name: %s 0x400 beshort 0x482B Macintosh HFS Extended >&0 beshort x version %d data @@ -322,43 +340,9 @@ >&42 belong x number of blocks: %d, >&46 belong x free blocks: %d -# I don't think this is really necessary since it doesn't do much and -# anything with a valid driver descriptor will also have a valid -# partition map -#0 beshort 0x4552 Apple Device Driver data -#>&24 beshort =1 \b, MacOS - -# Is that the partition type a cstring or a pstring? Well, IM says "strings -# shorter than 32 bytes must be terminated with NULL" so I'll treat it as a -# cstring. Of course, partitions can contain more than four entries, but -# what're you gonna do? -# GRR: This magic is too weak, it is just "PM" -#0x200 beshort 0x504D Apple Partition data -#>0x2 beshort x (block size: %d): -#>0x230 string x first type: %s, -#>0x210 string x name: %s, -#>0x254 belong x number of blocks: %d, -#>0x400 beshort 0x504D -#>>0x430 string x second type: %s, -#>>0x410 string x name: %s, -#>>0x454 belong x number of blocks: %d, -#>>0x600 beshort 0x504D -#>>>0x630 string x third type: %s, -#>>>0x610 string x name: %s, -#>>>0x654 belong x number of blocks: %d, -#>>0x800 beshort 0x504D -#>>>0x830 string x fourth type: %s, -#>>>0x810 string x name: %s, -#>>>0x854 belong x number of blocks: %d, -#>>>0xa00 beshort 0x504D -#>>>>0xa30 string x fifth type: %s, -#>>>>0xa10 string x name: %s, -#>>>>0xa54 belong x number of blocks: %d -#>>>0xc00 beshort 0x504D -#>>>>0xc30 string x sixth type: %s, -#>>>>0xc10 string x name: %s, -#>>>>0xc54 belong x number of blocks: %d ## AFAIK, only the signature is different +# same as Apple Partition Map +# GRR: This magic is too weak, it is just "TS" #0x200 beshort 0x5453 Apple Old Partition data #>0x2 beshort x block size: %d, #>0x230 string x first type: %s, diff --git a/contrib/file/magic/Magdir/map b/contrib/file/magic/Magdir/map new file mode 100644 index 0000000000..d9471fe51b --- /dev/null +++ b/contrib/file/magic/Magdir/map @@ -0,0 +1,25 @@ + + +#------------------------------------------------------------------------------ +# $File: map,v 1.1 2014/06/03 18:22:25 christos Exp $ +# map: file(1) magic for Map data +# + +# Garmin .FIT files http://pub.ks-and-ks.ne.jp/cycling/edge500_fit.shtml +8 string .FIT FIT Map data +>15 byte 0 +>>35 belong x \b, unit id %d +# 20 years after unix epoch +>>39 lelong x \b, serial %u +>>43 ledate/631152000 x \b, %s + +>>47 leshort x \b, manufacturer %d +>>47 leshort 1 \b (garmin) +>>49 leshort x \b, product %d +>>53 byte x \b, type %d +>>53 byte 1 \b (Device) +>>53 byte 2 \b (Settings) +>>53 byte 3 \b (Sports/Cycling) +>>53 byte 4 \b (Activity) +>>53 byte 8 \b (Elevations) +>>53 byte 10 \b (Totals) diff --git a/contrib/file/magic/Magdir/marc21 b/contrib/file/magic/Magdir/marc21 index 83f7959e05..7e859a3893 100644 --- a/contrib/file/magic/Magdir/marc21 +++ b/contrib/file/magic/Magdir/marc21 @@ -12,17 +12,17 @@ 20 string 45 # leader starts with 5 digits, followed by codes specific to MARC format ->0 regex/1 (^[0-9]{5})[acdnp][^bhlnqsu-z] MARC21 Bibliographic +>0 regex/1l (^[0-9]{5})[acdnp][^bhlnqsu-z] MARC21 Bibliographic !:mime application/marc ->0 regex/1 (^[0-9]{5})[acdnosx][z] MARC21 Authority +>0 regex/1l (^[0-9]{5})[acdnosx][z] MARC21 Authority !:mime application/marc ->0 regex/1 (^[0-9]{5})[cdn][uvxy] MARC21 Holdings +>0 regex/1l (^[0-9]{5})[cdn][uvxy] MARC21 Holdings !:mime application/marc -0 regex/1 (^[0-9]{5})[acdn][w] MARC21 Classification +0 regex/1l (^[0-9]{5})[acdn][w] MARC21 Classification !:mime application/marc ->0 regex/1 (^[0-9]{5})[cdn][q] MARC21 Community +>0 regex/1l (^[0-9]{5})[cdn][q] MARC21 Community !:mime application/marc # leader position 22-23, should be "00" but is it? ->0 regex/1 (^.{21})([^0]{2}) (non-conforming) +>0 regex/1l (^.{21})([^0]{2}) (non-conforming) !:mime application/marc diff --git a/contrib/file/magic/Magdir/rinex b/contrib/file/magic/Magdir/meteorological similarity index 88% rename from contrib/file/magic/Magdir/rinex rename to contrib/file/magic/Magdir/meteorological index c5f2bcbd31..541bbbffb8 100644 --- a/contrib/file/magic/Magdir/rinex +++ b/contrib/file/magic/Magdir/meteorological @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: rinex,v 1.4 2011/05/03 01:44:17 christos Exp $ +# $File: meteorological,v 1.1 2014/08/04 06:26:16 christos Exp $ # rinex: file(1) magic for RINEX files # http://igscb.jpl.nasa.gov/igscb/data/format/rinex210.txt # ftp://cddis.gsfc.nasa.gov/pub/reports/formats/rinex300.pdf @@ -42,3 +42,8 @@ >>&32 string x \b, date %15.15s >>5 string x \b, version %6.6s !:mime rinex/observation + +# https://en.wikipedia.org/wiki/GRIB +0 string GRIB +>7 byte =1 Gridded binary (GRIB) version 1 +>7 byte =2 Gridded binary (GRIB) version 2 diff --git a/contrib/file/magic/Magdir/mips b/contrib/file/magic/Magdir/mips index 8ed3567b23..fe83614703 100644 --- a/contrib/file/magic/Magdir/mips +++ b/contrib/file/magic/Magdir/mips @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: mips,v 1.9 2013/01/12 03:09:51 christos Exp $ +# $File: mips,v 1.10 2014/04/30 21:41:02 christos Exp $ # mips: file(1) magic for MIPS ECOFF and Ucode, as used in SGI IRIX # and DEC Ultrix # @@ -10,8 +10,8 @@ >20 beshort 0413 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->22 byte x - version %ld ->23 byte x \b.%ld +>22 byte x - version %d +>23 byte x \b.%d # 0 beshort 0x0162 MIPSEL-BE ECOFF executable >20 beshort 0407 (impure) @@ -20,7 +20,7 @@ >8 belong >0 not stripped >8 belong 0 stripped >23 byte x - version %d ->22 byte x \b.%ld +>22 byte x \b.%d # 0 beshort 0x6001 MIPSEB-LE ECOFF executable >20 beshort 03401 (impure) @@ -29,7 +29,7 @@ >8 belong >0 not stripped >8 belong 0 stripped >23 byte x - version %d ->22 byte x \b.%ld +>22 byte x \b.%d # 0 beshort 0x6201 MIPSEL ECOFF executable >20 beshort 03401 (impure) @@ -37,8 +37,8 @@ >20 beshort 05401 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->23 byte x - version %ld ->22 byte x \b.%ld +>23 byte x - version %d +>22 byte x \b.%d # # MIPS 2 additions # @@ -48,8 +48,8 @@ >20 beshort 0413 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->22 byte x - version %ld ->23 byte x \b.%ld +>22 byte x - version %d +>23 byte x \b.%d # 0 beshort 0x0166 MIPSEL-BE MIPS-II ECOFF executable >20 beshort 0407 (impure) @@ -57,8 +57,8 @@ >20 beshort 0413 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->22 byte x - version %ld ->23 byte x \b.%ld +>22 byte x - version %d +>23 byte x \b.%d # 0 beshort 0x6301 MIPSEB-LE MIPS-II ECOFF executable >20 beshort 03401 (impure) @@ -66,8 +66,8 @@ >20 beshort 05401 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->23 byte x - version %ld ->22 byte x \b.%ld +>23 byte x - version %d +>22 byte x \b.%d # 0 beshort 0x6601 MIPSEL MIPS-II ECOFF executable >20 beshort 03401 (impure) @@ -75,8 +75,8 @@ >20 beshort 05401 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->23 byte x - version %ld ->22 byte x \b.%ld +>23 byte x - version %d +>22 byte x \b.%d # # MIPS 3 additions # @@ -86,8 +86,8 @@ >20 beshort 0413 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->22 byte x - version %ld ->23 byte x \b.%ld +>22 byte x - version %d +>23 byte x \b.%d # 0 beshort 0x0142 MIPSEL-BE MIPS-III ECOFF executable >20 beshort 0407 (impure) @@ -95,8 +95,8 @@ >20 beshort 0413 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->22 byte x - version %ld ->23 byte x \b.%ld +>22 byte x - version %d +>23 byte x \b.%d # 0 beshort 0x4001 MIPSEB-LE MIPS-III ECOFF executable >20 beshort 03401 (impure) @@ -104,8 +104,8 @@ >20 beshort 05401 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->23 byte x - version %ld ->22 byte x \b.%ld +>23 byte x - version %d +>22 byte x \b.%d # 0 beshort 0x4201 MIPSEL MIPS-III ECOFF executable >20 beshort 03401 (impure) @@ -113,8 +113,8 @@ >20 beshort 05401 (paged) >8 belong >0 not stripped >8 belong 0 stripped ->23 byte x - version %ld ->22 byte x \b.%ld +>23 byte x - version %d +>22 byte x \b.%d # 0 beshort 0x180 MIPSEB Ucode 0 beshort 0x182 MIPSEL-BE Ucode diff --git a/contrib/file/magic/Magdir/motorola b/contrib/file/magic/Magdir/motorola index b56e5e483a..e19a907562 100644 --- a/contrib/file/magic/Magdir/motorola +++ b/contrib/file/magic/Magdir/motorola @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: motorola,v 1.10 2009/09/19 16:28:11 christos Exp $ +# $File: motorola,v 1.11 2014/04/30 21:41:02 christos Exp $ # motorola: file(1) magic for Motorola 68K and 88K binaries # # 68K @@ -40,27 +40,27 @@ # not larger than 1 MB (which is a lot on ST). # The additional 0x601b distinction I took from Doug Lee's magic. 0 belong&0xFFFFFFF0 0x601A0000 Atari ST M68K contiguous executable ->2 belong x (txt=%ld, ->6 belong x dat=%ld, ->10 belong x bss=%ld, ->14 belong x sym=%ld) +>2 belong x (txt=%d, +>6 belong x dat=%d, +>10 belong x bss=%d, +>14 belong x sym=%d) 0 belong&0xFFFFFFF0 0x601B0000 Atari ST M68K non-contig executable ->2 belong x (txt=%ld, ->6 belong x dat=%ld, ->10 belong x bss=%ld, ->14 belong x sym=%ld) +>2 belong x (txt=%d, +>6 belong x dat=%d, +>10 belong x bss=%d, +>14 belong x sym=%d) # Atari ST/TT... program format (sent by Wolfram Kleff ) 0 beshort 0x601A Atari 68xxx executable, ->2 belong x text len %lu, ->6 belong x data len %lu, ->10 belong x BSS len %lu, ->14 belong x symboltab len %lu, +>2 belong x text len %u, +>6 belong x data len %u, +>10 belong x BSS len %u, +>14 belong x symboltab len %u, >18 belong 0 >22 belong &0x01 fastload flag, >22 belong &0x02 may be loaded to alternate RAM, >22 belong &0x04 malloc may be from alternate RAM, ->22 belong x flags: 0x%lX, +>22 belong x flags: 0x%X, >26 beshort 0 no relocation tab >26 beshort !0 + relocation tab >30 string SFX [Self-Extracting LZH SFX archive] @@ -68,4 +68,4 @@ >44 string ZIP! [Self-Extracting ZIP SFX archive] 0 beshort 0x0064 Atari 68xxx CPX file ->8 beshort x (version %04lx) +>8 beshort x (version %04x) diff --git a/contrib/file/magic/Magdir/msdos b/contrib/file/magic/Magdir/msdos index 18b29c4d24..64d4862236 100644 --- a/contrib/file/magic/Magdir/msdos +++ b/contrib/file/magic/Magdir/msdos @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: msdos,v 1.92 2014/03/14 18:47:29 christos Exp $ +# $File: msdos,v 1.100 2014/06/03 19:17:27 christos Exp $ # msdos: file(1) magic for MS-DOS files # @@ -56,6 +56,7 @@ # Maybe it's a PE? >>(0x3c.l) string PE\0\0 PE +!:mime application/x-dosexec >>>(0x3c.l+24) leshort 0x010b \b32 executable >>>(0x3c.l+24) leshort 0x020b \b32+ executable >>>(0x3c.l+24) leshort 0x0107 ROM image @@ -134,8 +135,10 @@ # Hmm, not a PE but the relocation table is too high for a traditional DOS exe, # must be one of the unusual subformats. >>(0x3c.l) string !PE\0\0 MS-DOS executable +!:mime application/x-dosexec >>(0x3c.l) string NE \b, NE +!:mime application/x-dosexec >>>(0x3c.l+0x36) byte 1 for OS/2 1.x >>>(0x3c.l+0x36) byte 2 for MS Windows 3.x >>>(0x3c.l+0x36) byte 3 for MS-DOS @@ -150,6 +153,7 @@ >>>(0x3c.l+0x70) search/0x80 WinZip(R)\ Self-Extractor \b, ZIP self-extracting archive (WinZip) >>(0x3c.l) string LX\0\0 \b, LX +!:mime application/x-dosexec >>>(0x3c.l+0x0a) leshort <1 (unknown OS) >>>(0x3c.l+0x0a) leshort 1 for OS/2 >>>(0x3c.l+0x0a) leshort 2 for MS Windows @@ -168,8 +172,10 @@ # MS Windows system file, supposedly a collection of LE executables >>(0x3c.l) string W3 \b, W3 for MS Windows +!:mime application/x-dosexec >>(0x3c.l) string LE\0\0 \b, LE executable +!:mime application/x-dosexec >>>(0x3c.l+0x0a) leshort 1 # some DOS extenders use LE files with OS/2 header >>>>0x240 search/0x100 DOS/4G for MS-DOS, DOS4GW DOS extender @@ -196,6 +202,7 @@ # and definitely not NE/LE/LX/PE >>0x3c lelong >0x20000000 >>>(4.s*512) leshort !0x014c \b, MZ for MS-DOS +!:mime application/x-dosexec # header data too small for extended executable >2 long !0 >>0x18 leshort <0x40 @@ -203,6 +210,7 @@ >>>>&(2.s-514) string !LE >>>>>&-2 string !BW \b, MZ for MS-DOS +!:mime application/x-dosexec >>>>&(2.s-514) string LE \b, LE >>>>>0x240 search/0x100 DOS/4G for MS-DOS, DOS4GW DOS extender # educated guess since indirection is still not capable enough for complex offset @@ -214,6 +222,7 @@ # This sequence skips to the first COFF segment, usually .text >(4.s*512) leshort 0x014c \b, COFF +!:mime application/x-dosexec >>(8.s*16) string go32stub for MS-DOS, DJGPP go32 DOS extender >>(8.s*16) string emx >>>&1 string x for DOS, Win or OS/2, emx %s @@ -373,7 +382,7 @@ # they have their real name at offset 22 >>>>>22 string >\0 \b%-.5s >4 uleshort&0x8000 0x0000 -# 32 bit sector adressing ( > 32 MB) for block devices +# 32 bit sector addressing ( > 32 MB) for block devices >>4 uleshort&0x0002 0x0002 \b,32-bit sector- # support by driver functions 13h, 17h, 18h >4 uleshort&0x0040 0x0040 \b,IOCTL- @@ -590,7 +599,6 @@ >4 ubyte !0 \b, %d colors 0 belong 0x00000100 - >9 byte 0 >>0 byte x MS Windows icon resource !:mime image/x-icon @@ -741,6 +749,19 @@ 0 leshort 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 +# http://en.wikipedia.org/wiki/Norton_Guides +0 string NG\0\001 +# only value 0x100 found at offset 2 +>2 ulelong 0x00000100 Norton Guide +# Title[40] +>>8 string >\0 "%-.40s" +#>>6 uleshort x \b, MenuCount=%u +# szCredits[5][66] +>>48 string >\0 \b, %-.66s +>>114 string >\0 %-.66s + # 4DOS help (.HLP) files added by Joerg Jenderek from source TPHELP.PAS # of http://www.4dos.info/ # pointer,HelpID[8]=4DHnnnmm @@ -795,105 +816,6 @@ >40 string \ EMF Windows Enhanced Metafile (EMF) image data >>44 ulelong x version 0x%x -# From: Alex Beregszaszi -0 string/b COWD VMWare3 ->4 byte 3 disk image ->>32 lelong x (%d/ ->>36 lelong x \b%d/ ->>40 lelong x \b%d) ->4 byte 2 undoable disk image ->>32 string >\0 (%s) - -0 string/b VMDK VMware4 disk image -0 string/b KDMV VMware4 disk image - -#-------------------------------------------------------------------- -# Qemu Emulator Images -# Lines written by Friedrich Schwittay (f.schwittay@yousable.de) -# 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 QEMU QCOW Image - -# Uncomment the following line to display Magic (only used for debugging -# this magic number) -#>0 string/b x , Magic: %s - -# There are currently 2 Versions: "1" and "2". -# http://www.gnome.org/~markmc/qcow-image-format-version-1.html ->4 belong 1 (v1) - -# Using the existence of the Backing File Offset to determine whether -# to read Backing File Information ->>12 belong >0 \b, has backing file ( -# Note that this isn't a null-terminated string; the length is actually -# (16.L). Assuming a null-terminated string happens to work usually, but it -# may spew junk until it reaches a \0 in some cases. ->>>(12.L) string >\0 \bpath %s - -# Modification time of the Backing File -# Really useful if you want to know if your backing -# file is still usable together with this image ->>>>20 bedate >0 \b, mtime %s) ->>>>20 default x \b) - -# Size is stored in bytes in a big-endian u64. ->>24 bequad x \b, %lld bytes - -# 1 for AES encryption, 0 for none. ->>36 belong 1 \b, AES-encrypted - -# http://www.gnome.org/~markmc/qcow-image-format.html ->4 belong 2 (v2) -# Using the existence of the Backing File Offset to determine whether -# to read Backing File Information ->>8 bequad >0 \b, has backing file -# Note that this isn't a null-terminated string; the length is actually -# (16.L). Assuming a null-terminated string happens to work usually, but it -# may spew junk until it reaches a \0 in some cases. Also, since there's no -# .Q modifier, we just use the bottom four bytes as an offset. Note that if -# the file is over 4G, and the backing file path is stored after the first 4G, -# the wrong filename will be printed. (This should be (8.Q), when that syntax -# is introduced.) ->>>(12.L) string >\0 (path %s) ->>24 bequad x \b, %lld bytes ->>32 belong 1 \b, AES-encrypted - ->4 belong 3 (v3) -# Using the existence of the Backing File Offset to determine whether -# to read Backing File Information ->>8 bequad >0 \b, has backing file -# Note that this isn't a null-terminated string; the length is actually -# (16.L). Assuming a null-terminated string happens to work usually, but it -# may spew junk until it reaches a \0 in some cases. Also, since there's no -# .Q modifier, we just use the bottom four bytes as an offset. Note that if -# the file is over 4G, and the backing file path is stored after the first 4G, -# the wrong filename will be printed. (This should be (8.Q), when that syntax -# is introduced.) ->>>(12.L) string >\0 (path %s) ->>24 bequad x \b, %lld bytes ->>32 belong 1 \b, AES-encrypted - ->4 default x (unknown version) - -0 string/b QEVM QEMU suspend to disk image - -# QEMU QED Image -# http://wiki.qemu.org/Features/QED/Specification -0 string/b QED\0 QEMU QED Image - -# VDI Image -64 string/b \x7f\x10\xda\xbe VDI Image ->68 string/b \x01\x00\x01\x00 version 1.1 ->0 string >\0 (%s) ->368 lequad x \b, %lld bytes - -0 string/b Bochs\ Virtual\ HD\ Image Bochs disk image, ->32 string x type %s, ->48 string x subtype %s - -0 lelong 0x02468ace Bochs Sparse disk image - # from http://filext.com by Derek M Jones # False positive with PPT (also currently this string is too long) #0 string/b \xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF\x09\x00\x06 Microsoft Installer @@ -927,8 +849,8 @@ # URL: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/DDSFileReference/ddsfileformat.asp # From: Morten Hustveit 0 string/b DDS\040\174\000\000\000 Microsoft DirectDraw Surface (DDS), ->16 lelong >0 %hd x ->12 lelong >0 %hd, +>16 lelong >0 %d x +>12 lelong >0 %d, >84 string x %.4s # Type: Microsoft Document Imaging Format (.mdi) diff --git a/contrib/file/magic/Magdir/msooxml b/contrib/file/magic/Magdir/msooxml index e5be5b37db..059e729c54 100644 --- a/contrib/file/magic/Magdir/msooxml +++ b/contrib/file/magic/Magdir/msooxml @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: msooxml,v 1.4 2014/01/06 18:16:24 rrt Exp $ +# $File: msooxml,v 1.5 2014/08/05 07:38:45 christos Exp $ # msooxml: file(1) magic for Microsoft Office XML # From: Ralf Brown @@ -16,7 +16,7 @@ 0 string PK\003\004 !:strength +10 # make sure the first file is correct ->0x1E regex \[Content_Types\]\.xml|_rels/\.rels +>0x1E regex \\[Content_Types\\]\\.xml|_rels/\\.rels # 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 diff --git a/contrib/file/magic/Magdir/msx b/contrib/file/magic/Magdir/msx index e0c5ae5cbc..0eacbe5208 100644 --- a/contrib/file/magic/Magdir/msx +++ b/contrib/file/magic/Magdir/msx @@ -2,7 +2,7 @@ #------------------------------------------------------------------------------ # msx: file(1) magic for the MSX Home Computer # v1.1 -# Fábio R. Schmidlin +# Fabio R. Schmidlin ############## MSX Music file formats ############## diff --git a/contrib/file/magic/Magdir/natinst b/contrib/file/magic/Magdir/natinst index 0a936c576e..7a55ddecdf 100644 --- a/contrib/file/magic/Magdir/natinst +++ b/contrib/file/magic/Magdir/natinst @@ -1,6 +1,6 @@ #----------------------------------------------------------------------------- -# $File: natinst,v 1.5 2013/02/06 14:18:52 christos Exp $ +# $File: natinst,v 1.6 2014/06/03 19:17:27 christos Exp $ # natinst: file(1) magic for National Instruments Code Files # @@ -12,7 +12,7 @@ 0 string RSRC National Instruments, # Check if it's a LabVIEW File >8 string LV LabVIEW File, -# Check wich kind of file is +# Check which kind of file it is >>10 string SB Code Resource File, data >>10 string IN Virtual Instrument Program, data >>10 string AR VI Library, data diff --git a/contrib/file/magic/Magdir/ncr b/contrib/file/magic/Magdir/ncr index 4067596f59..21b09aba5c 100644 --- a/contrib/file/magic/Magdir/ncr +++ b/contrib/file/magic/Magdir/ncr @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: ncr,v 1.7 2009/09/19 16:28:11 christos Exp $ +# $File: ncr,v 1.8 2014/04/30 21:41:02 christos Exp $ # ncr: file(1) magic for NCR Tower objects # # contributed by @@ -11,27 +11,27 @@ >12 belong >0 not stripped >20 beshort 0407 executable >20 beshort 0410 pure executable ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 000615 Tower/XP rel 2 object >12 belong >0 not stripped >20 beshort 0407 executable >20 beshort 0410 pure executable ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 000620 Tower/XP rel 3 object >12 belong >0 not stripped >20 beshort 0407 executable >20 beshort 0410 pure executable ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 000625 Tower/XP rel 3 object >12 belong >0 not stripped >20 beshort 0407 executable >20 beshort 0410 pure executable ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 000630 Tower32/600/400 68020 object >12 belong >0 not stripped >20 beshort 0407 executable >20 beshort 0410 pure executable ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 000640 Tower32/800 68020 >18 beshort &020000 w/68881 object >18 beshort &040000 compatible object @@ -39,11 +39,11 @@ >20 beshort 0407 executable >20 beshort 0413 pure executable >12 belong >0 not stripped ->22 beshort >0 - version %ld +>22 beshort >0 - version %d 0 beshort 000645 Tower32/800 68010 >18 beshort &040000 compatible object >18 beshort &060000 object >20 beshort 0407 executable >20 beshort 0413 pure executable >12 belong >0 not stripped ->22 beshort >0 - version %ld +>22 beshort >0 - version %d diff --git a/contrib/file/magic/Magdir/netbsd b/contrib/file/magic/Magdir/netbsd index fd0eed3030..aa933ff939 100644 --- a/contrib/file/magic/Magdir/netbsd +++ b/contrib/file/magic/Magdir/netbsd @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: netbsd,v 1.20 2013/01/09 22:37:24 christos Exp $ +# $File: netbsd,v 1.22 2014/12/08 20:53:52 christos Exp $ # netbsd: file(1) magic for NetBSD objects # # All new-style magic numbers are in network byte order. @@ -100,25 +100,25 @@ 0 belong&0377777777 045200507 a.out NetBSD/powerpc core >12 string >\0 from '%s' -0 belong&0377777777 042400413 a.out NetBSD/sparc demand paged +0 belong&0377777777 042400413 a.out NetBSD/SPARC demand paged >0 byte &0x80 >>20 belong <8192 shared library >>20 belong =8192 dynamically linked executable >>20 belong >8192 dynamically linked executable >0 byte ^0x80 executable >16 belong >0 not stripped -0 belong&0377777777 042400410 a.out NetBSD/sparc pure +0 belong&0377777777 042400410 a.out NetBSD/SPARC pure >0 byte &0x80 dynamically linked executable >0 byte ^0x80 executable >16 belong >0 not stripped -0 belong&0377777777 042400407 a.out NetBSD/sparc +0 belong&0377777777 042400407 a.out NetBSD/SPARC >0 byte &0x80 dynamically linked executable >0 byte ^0x80 >>0 byte &0x40 position independent >>20 belong !0 executable >>20 belong =0 object file >16 belong >0 not stripped -0 belong&0377777777 042400507 a.out NetBSD/sparc core +0 belong&0377777777 042400507 a.out NetBSD/SPARC core >12 string >\0 from '%s' >32 belong !0 (signal %d) @@ -247,14 +247,14 @@ # Kernel core dump format 0 belong&0x0000ffff 0x00008fca NetBSD kernel core file >0 belong&0x03ff0000 0x00000000 \b, Unknown ->0 belong&0x03ff0000 0x00001000 \b, sun 68010/68020 +>0 belong&0x03ff0000 0x00010000 \b, sun 68010/68020 >0 belong&0x03ff0000 0x00020000 \b, sun 68020 >0 belong&0x03ff0000 0x00640000 \b, 386 PC >0 belong&0x03ff0000 0x00860000 \b, i386 BSD >0 belong&0x03ff0000 0x00870000 \b, m68k BSD (8K pages) >0 belong&0x03ff0000 0x00880000 \b, m68k BSD (4K pages) >0 belong&0x03ff0000 0x00890000 \b, ns32532 BSD ->0 belong&0x03ff0000 0x008a0000 \b, sparc/32 BSD +>0 belong&0x03ff0000 0x008a0000 \b, SPARC/32 BSD >0 belong&0x03ff0000 0x008b0000 \b, pmax BSD >0 belong&0x03ff0000 0x008c0000 \b, vax BSD (1K pages) >0 belong&0x03ff0000 0x008d0000 \b, alpha BSD @@ -262,20 +262,24 @@ >0 belong&0x03ff0000 0x008f0000 \b, arm6 BSD >0 belong&0x03ff0000 0x00900000 \b, m68k BSD (2K pages) >0 belong&0x03ff0000 0x00910000 \b, sh3 BSD ->0 belong&0x03ff0000 0x00920000 \b, ppc BSD (Big Endian) ->0 belong&0x03ff0000 0x00930000 \b, vax BSD (4K pages) ->0 belong&0x03ff0000 0x00940000 \b, mips1 BSD ->0 belong&0x03ff0000 0x00950000 \b, mips2 BSD ->0 belong&0x03ff0000 0x00960000 \b, parisc BSD ->0 belong&0x03ff0000 0x00970000 \b, sh5/64 BSD ->0 belong&0x03ff0000 0x00980000 \b, sparc/64 BSD ->0 belong&0x03ff0000 0x00990000 \b, amd64 BSD ->0 belong&0x03ff0000 0x009a0000 \b, hp200 (68010) BSD ->0 belong&0x03ff0000 0x009b0000 \b, hp300 (68020+68881) BSD ->0 belong&0x03ff0000 0x009b0000 \b, hp300 (68020+68881) BSD ->0 belong&0x03ff0000 0x00c80000 \b, hp200 ->0 belong&0x03ff0000 0x020b0000 \b, hp300 (68020+68881) HP-UX ->0 belong&0x03ff0000 0x020c0000 \b, hp300 (68020+68881) HP-UX +>0 belong&0x03ff0000 0x00950000 \b, ppc BSD (Big Endian) +>0 belong&0x03ff0000 0x00960000 \b, vax BSD (4K pages) +>0 belong&0x03ff0000 0x00970000 \b, mips1 BSD +>0 belong&0x03ff0000 0x00980000 \b, mips2 BSD +>0 belong&0x03ff0000 0x00990000 \b, m88k BSD +>0 belong&0x03ff0000 0x00920000 \b, parisc BSD +>0 belong&0x03ff0000 0x009b0000 \b, sh5/64 BSD +>0 belong&0x03ff0000 0x009c0000 \b, SPARC/64 BSD +>0 belong&0x03ff0000 0x009d0000 \b, amd64 BSD +>0 belong&0x03ff0000 0x009e0000 \b, sh5/32 BSD +>0 belong&0x03ff0000 0x009f0000 \b, ia64 BSD +>0 belong&0x03ff0000 0x00b70000 \b, aarch64 BSD +>0 belong&0x03ff0000 0x00b80000 \b, or1k BSD +>0 belong&0x03ff0000 0x00b90000 \b, Risk-V BSD +>0 belong&0x03ff0000 0x00c80000 \b, hp200 BSD +>0 belong&0x03ff0000 0x012c0000 \b, hp300 BSD +>0 belong&0x03ff0000 0x020b0000 \b, hp800 HP-UX +>0 belong&0x03ff0000 0x020c0000 \b, hp200/hp300 HP-UX >0 belong&0xfc000000 0x04000000 \b, CPU >0 belong&0xfc000000 0x08000000 \b, DATA >0 belong&0xfc000000 0x10000000 \b, STACK diff --git a/contrib/file/magic/Magdir/nitpicker b/contrib/file/magic/Magdir/nitpicker index d1a66287fd..2486dee037 100644 --- a/contrib/file/magic/Magdir/nitpicker +++ b/contrib/file/magic/Magdir/nitpicker @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: nitpicker,v 1.4 2009/09/19 16:28:11 christos Exp $ +# $File: nitpicker,v 1.6 2014/04/30 21:41:02 christos Exp $ # nitpicker: file(1) magic for Flowfiles. # From: Christian Jachmann http://www.nitpicker.de 0 string NPFF NItpicker Flow File diff --git a/contrib/file/magic/Magdir/oasis b/contrib/file/magic/Magdir/oasis index e527185fd1..45ad6d137d 100644 --- a/contrib/file/magic/Magdir/oasis +++ b/contrib/file/magic/Magdir/oasis @@ -1,9 +1,9 @@ #------------------------------------------------------------------------------ -# $File: oasis,v 1.1 2011/03/15 02:09:38 christos Exp $ +# $File: oasis,v 1.2 2014/06/03 19:17:27 christos Exp $ # OASIS # Summary: OASIS stream file -# Long descripton: Open Artwork System Interchange Standard +# Long description: Open Artwork System Interchange Standard # File extension: .oas # Full name: Ben Cowley (bcowley@broadcom.com) # Philip Dixon (pdixon@broadcom.com) diff --git a/contrib/file/magic/Magdir/palm b/contrib/file/magic/Magdir/palm index bee4f49fb4..e852cc7181 100644 --- a/contrib/file/magic/Magdir/palm +++ b/contrib/file/magic/Magdir/palm @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: palm,v 1.11 2013/12/31 19:18:02 christos Exp $ +# $File: palm,v 1.13 2014/03/30 21:40:08 christos Exp $ # palm: file(1) magic for PalmOS {.prc,.pdb}: applications, docfiles, and hacks # # Brian Lalor @@ -141,8 +141,12 @@ >>(0x4E.L+1) byte x %02d) # Palm OS .prc file types -60 string libr Palm OS dynamic library data ->0 string >\0 "%s" +60 string libr +# flags, only bit 0 or bit 6 +# http://en.wikipedia.org/wiki/PRC_%28Palm_OS%29 +# http://web.mit.edu/tytso/www/pilot/prc-format.html +>0x20 beshort&0xffbe 0 +>>0 string >\0 Palm OS dynamic library data "%s" 60 string ptch Palm OS operating system patch data >0 string >\0 "%s" diff --git a/contrib/file/magic/Magdir/pascal b/contrib/file/magic/Magdir/pascal index a134a47a22..eebd349e12 100644 --- a/contrib/file/magic/Magdir/pascal +++ b/contrib/file/magic/Magdir/pascal @@ -1,10 +1,10 @@ #------------------------------------------------------------------------------ -# $File: pascal,v 1.1 2011/12/08 12:12:46 rrt Exp $ +# $File: pascal,v 1.2 2014/07/14 14:21:33 rrt Exp $ # pascal: file(1) magic for Pascal source # 0 search/8192 (input, Pascal source text !:mime text/x-pascal -0 regex \^program Pascal source text -!:mime text/x-pascal -0 regex \^record Pascal source text -!:mime text/x-pascal +#0 regex \^program Pascal source text +#!:mime text/x-pascal +#0 regex \^record Pascal source text +#!:mime text/x-pascal diff --git a/contrib/file/magic/Magdir/pdp b/contrib/file/magic/Magdir/pdp index 536dd1b4eb..0afee0c9ba 100644 --- a/contrib/file/magic/Magdir/pdp +++ b/contrib/file/magic/Magdir/pdp @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: pdp,v 1.9 2013/04/19 20:11:43 christos Exp $ +# $File: pdp,v 1.10 2014/04/30 21:41:02 christos Exp $ # pdp: file(1) magic for PDP-11 executable/object and APL workspace # 0 lelong 0101555 PDP-11 single precision APL workspace @@ -10,7 +10,7 @@ # 0 leshort 0407 PDP-11 executable >8 leshort >0 not stripped ->15 byte >0 - version %ld +>15 byte >0 - version %d # updated by Joerg Jenderek at Mar 2013 # GRR: line below too general as it catches also Windows precompiled setup information *.PNF @@ -23,11 +23,11 @@ 0 leshort 0410 PDP-11 pure executable >8 leshort >0 not stripped ->15 byte >0 - version %ld +>15 byte >0 - version %d 0 leshort 0411 PDP-11 separate I&D executable >8 leshort >0 not stripped ->15 byte >0 - version %ld +>15 byte >0 - version %d 0 leshort 0437 PDP-11 kernel overlay diff --git a/contrib/file/magic/Magdir/perl b/contrib/file/magic/Magdir/perl index cb82960ddc..b5b54fbc82 100644 --- a/contrib/file/magic/Magdir/perl +++ b/contrib/file/magic/Magdir/perl @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# $File: perl,v 1.21 2013/12/08 23:33:18 christos Exp $ +# $File: perl,v 1.22 2014/04/28 12:04:35 christos Exp $ # perl: file(1) magic for Larry Wall's perl language. # # The `eval' lines recognizes an outrageously clever hack. @@ -57,3 +57,34 @@ >>4 byte =5 (major 2) >>4 byte =4 (major 2) >>5 byte >0 (minor %d) + +# This is Debian #742949 by Zefram : +# ----------------------------------------------------------- +# The Perl module Hash::SharedMem +# defines a file format +# for a key/value store. Details of the file format are in the "DESIGN" +# file in the module distribution. Magic: +0 bequad =0xa58afd185cbf5af7 Hash::SharedMem master file, big-endian +>8 bequad <0x1000000 +>>15 byte >2 \b, line size 2^%d byte +>>14 byte >2 \b, page size 2^%d byte +>>13 byte &1 +>>>13 byte >1 \b, max fanout %d +0 lequad =0xa58afd185cbf5af7 Hash::SharedMem master file, little-endian +>8 lequad <0x1000000 +>>8 byte >2 \b, line size 2^%d byte +>>9 byte >2 \b, page size 2^%d byte +>>10 byte &1 +>>>10 byte >1 \b, max fanout %d +0 bequad =0xc693dac5ed5e47c2 Hash::SharedMem data file, big-endian +>8 bequad <0x1000000 +>>15 byte >2 \b, line size 2^%d byte +>>14 byte >2 \b, page size 2^%d byte +>>13 byte &1 +>>>13 byte >1 \b, max fanout %d +0 lequad =0xc693dac5ed5e47c2 Hash::SharedMem data file, little-endian +>8 lequad <0x1000000 +>>8 byte >2 \b, line size 2^%d byte +>>9 byte >2 \b, page size 2^%d byte +>>10 byte &1 +>>>10 byte >1 \b, max fanout %d diff --git a/contrib/file/magic/Magdir/pgp b/contrib/file/magic/Magdir/pgp index a8d3c9a133..95a676600d 100644 --- a/contrib/file/magic/Magdir/pgp +++ b/contrib/file/magic/Magdir/pgp @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: pgp,v 1.9 2009/09/19 16:28:11 christos Exp $ +# $File: pgp,v 1.11 2014/11/11 21:32:38 christos Exp $ # pgp: file(1) magic for Pretty Good Privacy # see http://lists.gnupg.org/pipermail/gnupg-devel/1999-September/016052.html # @@ -21,7 +21,449 @@ 2 string ---BEGIN\ PGP\ PUBLIC\ KEY\ BLOCK- PGP public key block !:mime application/pgp-keys +>10 search/100 \n\n +>>&0 use pgp 0 string -----BEGIN\040PGP\40MESSAGE- PGP message !:mime application/pgp +>10 search/100 \n\n +>>&0 use pgp 0 string -----BEGIN\040PGP\40SIGNATURE- PGP signature !:mime application/pgp-signature +>10 search/100 \n\n +>>&0 use pgp + +# Decode the type of the packet based on it's base64 encoding. +# Idea from Mark Martinec +# The specification is in RFC 4880, section 4.2 and 4.3: +# http://tools.ietf.org/html/rfc4880#section-4.2 + +0 name pgp +>0 byte 0x67 Reserved (old) +>0 byte 0x68 Public-Key Encrypted Session Key (old) +>0 byte 0x69 Signature (old) +>0 byte 0x6a Symmetric-Key Encrypted Session Key (old) +>0 byte 0x6b One-Pass Signature (old) +>0 byte 0x6c Secret-Key (old) +>0 byte 0x6d Public-Key (old) +>0 byte 0x6e Secret-Subkey (old) +>0 byte 0x6f Compressed Data (old) +>0 byte 0x70 Symmetrically Encrypted Data (old) +>0 byte 0x71 Marker (old) +>0 byte 0x72 Literal Data (old) +>0 byte 0x73 Trust (old) +>0 byte 0x74 User ID (old) +>0 byte 0x75 Public-Subkey (old) +>0 byte 0x76 Unused (old) +>0 byte 0x77 +>>1 byte&0xc0 0x00 Reserved +>>1 byte&0xc0 0x40 Public-Key Encrypted Session Key +>>1 byte&0xc0 0x80 Signature +>>1 byte&0xc0 0xc0 Symmetric-Key Encrypted Session Key +>0 byte 0x78 +>>1 byte&0xc0 0x00 One-Pass Signature +>>1 byte&0xc0 0x40 Secret-Key +>>1 byte&0xc0 0x80 Public-Key +>>1 byte&0xc0 0xc0 Secret-Subkey +>0 byte 0x79 +>>1 byte&0xc0 0x00 Compressed Data +>>1 byte&0xc0 0x40 Symmetrically Encrypted Data +>>1 byte&0xc0 0x80 Marker +>>1 byte&0xc0 0xc0 Literal Data +>0 byte 0x7a +>>1 byte&0xc0 0x00 Trust +>>1 byte&0xc0 0x40 User ID +>>1 byte&0xc0 0x80 Public-Subkey +>>1 byte&0xc0 0xc0 Unused [z%x] +>0 byte 0x30 +>>1 byte&0xc0 0x00 Unused [0%x] +>>1 byte&0xc0 0x40 User Attribute +>>1 byte&0xc0 0x80 Sym. Encrypted and Integrity Protected Data +>>1 byte&0xc0 0xc0 Modification Detection Code + +# magic signatures to detect PGP crypto material (from stef) +# detects and extracts metadata from: +# - symmetric encrypted packet header +# - RSA (e=65537) secret (sub-)keys + +# 1024b RSA encrypted data + +0 string \x84\x8c\x03 PGP RSA encrypted session key - +>3 lelong x keyid: %X +>7 lelong x %X +>11 byte 0x01 RSA (Encrypt or Sign) 1024b +>11 byte 0x02 RSA Encrypt-Only 1024b +>12 string \x04\x00 +>12 string \x03\xff +>12 string \x03\xfe +>12 string \x03\xfd +>12 string \x03\xfc +>12 string \x03\xfb +>12 string \x03\xfa +>12 string \x03\xf9 +>142 byte 0xd2 . + +# 2048b RSA encrypted data + +0 string \x85\x01\x0c\x03 PGP RSA encrypted session key - +>4 lelong x keyid: %X +>8 lelong x %X +>12 byte 0x01 RSA (Encrypt or Sign) 2048b +>12 byte 0x02 RSA Encrypt-Only 2048b +>13 string \x08\x00 +>13 string \x07\xff +>13 string \x07\xfe +>13 string \x07\xfd +>13 string \x07\xfc +>13 string \x07\xfb +>13 string \x07\xfa +>13 string \x07\xf9 +>271 byte 0xd2 . + +# 3072b RSA encrypted data + +0 string \x85\x01\x8c\x03 PGP RSA encrypted session key - +>4 lelong x keyid: %X +>8 lelong x %X +>12 byte 0x01 RSA (Encrypt or Sign) 3072b +>12 byte 0x02 RSA Encrypt-Only 3072b +>13 string \x0c\x00 +>13 string \x0b\xff +>13 string \x0b\xfe +>13 string \x0b\xfd +>13 string \x0b\xfc +>13 string \x0b\xfb +>13 string \x0b\xfa +>13 string \x0b\xf9 +>399 byte 0xd2 . + +# 3072b RSA encrypted data + +0 string \x85\x02\x0c\x03 PGP RSA encrypted session key - +>4 lelong x keyid: %X +>8 lelong x %X +>12 byte 0x01 RSA (Encrypt or Sign) 4096b +>12 byte 0x02 RSA Encrypt-Only 4096b +>13 string \x10\x00 +>13 string \x0f\xff +>13 string \x0f\xfe +>13 string \x0f\xfd +>13 string \x0f\xfc +>13 string \x0f\xfb +>13 string \x0f\xfa +>13 string \x0f\xf9 +>527 byte 0xd2 . + +# 4096b RSA encrypted data + +0 string \x85\x04\x0c\x03 PGP RSA encrypted session key - +>4 lelong x keyid: %X +>8 lelong x %X +>12 byte 0x01 RSA (Encrypt or Sign) 8129b +>12 byte 0x02 RSA Encrypt-Only 8129b +>13 string \x20\x00 +>13 string \x1f\xff +>13 string \x1f\xfe +>13 string \x1f\xfd +>13 string \x1f\xfc +>13 string \x1f\xfb +>13 string \x1f\xfa +>13 string \x1f\xf9 +>1039 byte 0xd2 . + +# crypto algo mapper + +0 name crypto +>0 byte 0x00 Plaintext or unencrypted data +>0 byte 0x01 IDEA +>0 byte 0x02 TripleDES +>0 byte 0x03 CAST5 (128 bit key) +>0 byte 0x04 Blowfish (128 bit key, 16 rounds) +>0 byte 0x07 AES with 128-bit key +>0 byte 0x08 AES with 192-bit key +>0 byte 0x09 AES with 256-bit key +>0 byte 0x0a Twofish with 256-bit key + +# hash algo mapper + +0 name hash +>0 byte 0x01 MD5 +>0 byte 0x02 SHA-1 +>0 byte 0x03 RIPE-MD/160 +>0 byte 0x08 SHA256 +>0 byte 0x09 SHA384 +>0 byte 0x0a SHA512 +>0 byte 0x0b SHA224 + +# pgp symmetric encrypted data + +0 byte 0x8c PGP symmetric key encrypted data - +>1 byte 0x0d +>1 byte 0x0c +>2 byte 0x04 +>3 use crypto +>4 byte 0x01 salted - +>>5 use hash +>>14 byte 0xd2 . +>>14 byte 0xc9 . +>4 byte 0x03 salted & iterated - +>>5 use hash +>>15 byte 0xd2 . +>>15 byte 0xc9 . + +# encrypted keymaterial needs s2k & can be checksummed/hashed + +0 name chkcrypto +>0 use crypto +>1 byte 0x00 Simple S2K +>1 byte 0x01 Salted S2K +>1 byte 0x03 Salted&Iterated S2K +>2 use hash + +# all PGP keys start with this prolog +# containing version, creation date, and purpose + +0 name keyprolog +>0 byte 0x04 +>1 beldate x created on %s - +>5 byte 0x01 RSA (Encrypt or Sign) +>5 byte 0x02 RSA Encrypt-Only + +# end of secret keys known signature +# contains e=65537 and the prolog to +# the encrypted parameters + +0 name keyend +>0 string \x00\x11\x01\x00\x01 e=65537 +>5 use crypto +>5 byte 0xff checksummed +>>6 use chkcrypto +>5 byte 0xfe hashed +>>6 use chkcrypto + +# PGP secret keys contain also the public parts +# these vary by bitsize of the key + +0 name x1024 +>0 use keyprolog +>6 string \x03\xfe +>6 string \x03\xff +>6 string \x04\x00 +>136 use keyend + +0 name x2048 +>0 use keyprolog +>6 string \x80\x00 +>6 string \x07\xfe +>6 string \x07\xff +>264 use keyend + +0 name x3072 +>0 use keyprolog +>6 string \x0b\xfe +>6 string \x0b\xff +>6 string \x0c\x00 +>392 use keyend + +0 name x4096 +>0 use keyprolog +>6 string \x10\x00 +>6 string \x0f\xfe +>6 string \x0f\xff +>520 use keyend + +# \x00|\x1f[\xfe\xff]).{1024})' +0 name x8192 +>0 use keyprolog +>6 string \x20\x00 +>6 string \x1f\xfe +>6 string \x1f\xff +>1032 use keyend + +# depending on the size of the pkt +# we branch into the proper key size +# signatures defined as x{keysize} + +>0 name pgpkey +>0 string \x01\xd8 1024b +>>2 use x1024 +>0 string \x01\xeb 1024b +>>2 use x1024 +>0 string \x01\xfb 1024b +>>2 use x1024 +>0 string \x01\xfd 1024b +>>2 use x1024 +>0 string \x01\xf3 1024b +>>2 use x1024 +>0 string \x01\xee 1024b +>>2 use x1024 +>0 string \x01\xfe 1024b +>>2 use x1024 +>0 string \x01\xf4 1024b +>>2 use x1024 +>0 string \x02\x0d 1024b +>>2 use x1024 +>0 string \x02\x03 1024b +>>2 use x1024 +>0 string \x02\x05 1024b +>>2 use x1024 +>0 string \x02\x15 1024b +>>2 use x1024 +>0 string \x02\x00 1024b +>>2 use x1024 +>0 string \x02\x10 1024b +>>2 use x1024 +>0 string \x02\x04 1024b +>>2 use x1024 +>0 string \x02\x06 1024b +>>2 use x1024 +>0 string \x02\x16 1024b +>>2 use x1024 +>0 string \x03\x98 2048b +>>2 use x2048 +>0 string \x03\xab 2048b +>>2 use x2048 +>0 string \x03\xbb 2048b +>>2 use x2048 +>0 string \x03\xbd 2048b +>>2 use x2048 +>0 string \x03\xcd 2048b +>>2 use x2048 +>0 string \x03\xb3 2048b +>>2 use x2048 +>0 string \x03\xc3 2048b +>>2 use x2048 +>0 string \x03\xc5 2048b +>>2 use x2048 +>0 string \x03\xd5 2048b +>>2 use x2048 +>0 string \x03\xae 2048b +>>2 use x2048 +>0 string \x03\xbe 2048b +>>2 use x2048 +>0 string \x03\xc0 2048b +>>2 use x2048 +>0 string \x03\xd0 2048b +>>2 use x2048 +>0 string \x03\xb4 2048b +>>2 use x2048 +>0 string \x03\xc4 2048b +>>2 use x2048 +>0 string \x03\xc6 2048b +>>2 use x2048 +>0 string \x03\xd6 2048b +>>2 use x2048 +>0 string \x05X 3072b +>>2 use x3072 +>0 string \x05k 3072b +>>2 use x3072 +>0 string \x05{ 3072b +>>2 use x3072 +>0 string \x05} 3072b +>>2 use x3072 +>0 string \x05\x8d 3072b +>>2 use x3072 +>0 string \x05s 3072b +>>2 use x3072 +>0 string \x05\x83 3072b +>>2 use x3072 +>0 string \x05\x85 3072b +>>2 use x3072 +>0 string \x05\x95 3072b +>>2 use x3072 +>0 string \x05n 3072b +>>2 use x3072 +>0 string \x05\x7e 3072b +>>2 use x3072 +>0 string \x05\x80 3072b +>>2 use x3072 +>0 string \x05\x90 3072b +>>2 use x3072 +>0 string \x05t 3072b +>>2 use x3072 +>0 string \x05\x84 3072b +>>2 use x3072 +>0 string \x05\x86 3072b +>>2 use x3072 +>0 string \x05\x96 3072b +>>2 use x3072 +>0 string \x07[ 4096b +>>2 use x4096 +>0 string \x07\x18 4096b +>>2 use x4096 +>0 string \x07+ 4096b +>>2 use x4096 +>0 string \x07; 4096b +>>2 use x4096 +>0 string \x07= 4096b +>>2 use x4096 +>0 string \x07M 4096b +>>2 use x4096 +>0 string \x073 4096b +>>2 use x4096 +>0 string \x07C 4096b +>>2 use x4096 +>0 string \x07E 4096b +>>2 use x4096 +>0 string \x07U 4096b +>>2 use x4096 +>0 string \x07. 4096b +>>2 use x4096 +>0 string \x07> 4096b +>>2 use x4096 +>0 string \x07@ 4096b +>>2 use x4096 +>0 string \x07P 4096b +>>2 use x4096 +>0 string \x074 4096b +>>2 use x4096 +>0 string \x07D 4096b +>>2 use x4096 +>0 string \x07F 4096b +>>2 use x4096 +>0 string \x07V 4096b +>>2 use x4096 +>0 string \x0e[ 8192b +>>2 use x8192 +>0 string \x0e\x18 8192b +>>2 use x8192 +>0 string \x0e+ 8192b +>>2 use x8192 +>0 string \x0e; 8192b +>>2 use x8192 +>0 string \x0e= 8192b +>>2 use x8192 +>0 string \x0eM 8192b +>>2 use x8192 +>0 string \x0e3 8192b +>>2 use x8192 +>0 string \x0eC 8192b +>>2 use x8192 +>0 string \x0eE 8192b +>>2 use x8192 +>0 string \x0eU 8192b +>>2 use x8192 +>0 string \x0e. 8192b +>>2 use x8192 +>0 string \x0e> 8192b +>>2 use x8192 +>0 string \x0e@ 8192b +>>2 use x8192 +>0 string \x0eP 8192b +>>2 use x8192 +>0 string \x0e4 8192b +>>2 use x8192 +>0 string \x0eD 8192b +>>2 use x8192 +>0 string \x0eF 8192b +>>2 use x8192 +>0 string \x0eV 8192b +>>2 use x8192 + +# PGP RSA (e=65537) secret (sub-)key header + +0 byte 0x95 PGP Secret Key - +>1 use pgpkey +0 byte 0x97 PGP Secret Sub-key - +>1 use pgpkey +0 byte 0x9d PGP Secret Sub-key - +>1 use pgpkey diff --git a/contrib/file/magic/Magdir/printer b/contrib/file/magic/Magdir/printer index d9d39eefc8..10168266c9 100644 --- a/contrib/file/magic/Magdir/printer +++ b/contrib/file/magic/Magdir/printer @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: printer,v 1.25 2011/05/20 23:31:46 christos Exp $ +# $File: printer,v 1.26 2014/04/12 14:51:52 christos Exp $ # printer: file(1) magic for printer-formatted files # @@ -68,6 +68,22 @@ 0 string \033%-12345X@PJL >&0 search/10000 %! PJL encapsulated PostScript document text +# Rick Richardson + +# For Fuji-Xerox Printers - HBPL stands for Host Based Printer Language +# For Oki Data Printers - HIPERC +# For Konica Minolta Printers - LAVAFLOW +# For Samsung Printers - QPDL +# For HP Printers - ZJS stands for Zenographics ZJStream +0 string \033%-12345X@PJL HP Printer Job Language data +>0 search/10000 @PJL\ ENTER\ LANGUAGE=HBPL - HBPL +>0 search/10000 @PJL\ ENTER\ LANGUAGE=HIPERC - Oki Data HIPERC +>0 search/10000 @PJL\ ENTER\ LANGUAGE=LAVAFLOW - Konica Minolta LAVAFLOW +>0 search/10000 @PJL\ ENTER\ LANGUAGE=QPDL - Samsung QPDL +>0 search/10000 @PJL\ ENTER\ LANGUAGE\ =\ QPDL - Samsung QPDL +>0 search/10000 @PJL\ ENTER\ LANGUAGE=ZJS - HP ZJS + + # HP Printer Control Language, Daniel Quinlan (quinlan@yggdrasil.com) 0 string \033E\033 HP PCL printer data >3 string \&l0A - default page size @@ -108,7 +124,7 @@ #------------------------------------------------------------------------------ # zenographics: file(1) magic for Zenographics ZjStream printer data -# Rick Richardson rickr@mn.rr.com +# Rick Richardson 0 string JZJZ >0x12 string ZZ Zenographics ZjStream printer data (big-endian) 0 string ZJZJ @@ -117,7 +133,7 @@ #------------------------------------------------------------------------------ # Oak Technologies printer stream -# Rick Richardson +# Rick Richardson 0 string OAK >0x07 byte 0 >0x0b byte 0 Oak Technologies printer stream diff --git a/contrib/file/magic/Magdir/python b/contrib/file/magic/Magdir/python index 238fe6a464..36cdfd8cb7 100644 --- a/contrib/file/magic/Magdir/python +++ b/contrib/file/magic/Magdir/python @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: python,v 1.24 2014/02/15 01:30:52 christos Exp $ +# $File: python,v 1.26 2014/08/04 05:58:40 christos Exp $ # python: file(1) magic for python # # Outlook puts """ too for urgent messages @@ -23,6 +23,7 @@ 0 belong 0x4f0c0d0a python 3.1 byte-compiled 0 belong 0x6c0c0d0a python 3.2 byte-compiled 0 belong 0x9e0c0d0a python 3.3 byte-compiled +0 belong 0xee0c0d0a python 3.4 byte-compiled 0 search/1/w #!\ /usr/bin/python Python script text executable !:mime text/x-python @@ -63,5 +64,5 @@ # def name(args, args): 0 regex \^(\ |\\t){0,50}def\ {1,50}[a-zA-Z]{1,100} ->&0 regex \ {0,50}\\(([a-zA-Z]|,|\ ){1,500}\\):$ Python script text executable +>&0 regex \ {0,50}\\(([a-zA-Z]|,|\ ){1,255}\\):$ Python script text executable !:mime text/x-python diff --git a/contrib/file/magic/Magdir/qt b/contrib/file/magic/Magdir/qt new file mode 100644 index 0000000000..72e6ff3a0d --- /dev/null +++ b/contrib/file/magic/Magdir/qt @@ -0,0 +1,19 @@ + +#------------------------------------------------------------------------------ +# $File: qt,v 1.2 2014/12/16 19:49:29 christos Exp $ +# qt: file(1) magic for Qt + +# http://doc.qt.io/qt-5/resources.html +0 string \ Qt Resource Collection file + +# https://qt.gitorious.org/qt/qtbase/source/\ +# 5367fa356233da4c0f28172a8f817791525f5457:\ +# src/tools/rcc/rcc.cpp#L840 +0 string qres\0\0 Qt Binary Resource file +0 search/1024 The\040Resource\040Compiler\040for\040Qt Qt C-code resource file + +# https://qt.gitorious.org/qt/qtbase/source/\ +# 5367fa356233da4c0f28172a8f817791525f5457:\ +# src/corelib/kernel/qtranslator.cpp#L62 +0 string \x3c\xb8\x64\x18\xca\xef\x9c\x95 +>8 string \xcd\x21\x1c\xbf\x60\xa1\xbd\xdd Qt Translation file diff --git a/contrib/file/magic/Magdir/riff b/contrib/file/magic/Magdir/riff index 524fbd3c89..e551292b38 100644 --- a/contrib/file/magic/Magdir/riff +++ b/contrib/file/magic/Magdir/riff @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: riff,v 1.26 2014/03/06 18:55:09 christos Exp $ +# $File: riff,v 1.30 2014/09/23 17:02:12 christos Exp $ # riff: file(1) magic for RIFF format # See # @@ -45,6 +45,26 @@ >>&(4.l+4) use riff-walk >0 string fact >>&(4.l+4) use riff-walk +>0 string VP8 +>>11 byte 0x9d +>>>12 byte 0x01 +>>>>13 byte 0x2a \b, VP8 encoding +>>>>>14 leshort&0x3fff x \b, %d +>>>>>16 leshort&0x3fff x \bx%d, Scaling: +>>>>>14 leshort&0xc000 0x0000 \b [none] +>>>>>14 leshort&0xc000 0x1000 \b [5/4] +>>>>>14 leshort&0xc000 0x2000 \b [5/3] +>>>>>14 leshort&0xc000 0x3000 \b [2] +>>>>>14 leshort&0xc000 0x0000 \bx[none] +>>>>>14 leshort&0xc000 0x1000 \bx[5/4] +>>>>>14 leshort&0xc000 0x2000 \bx[5/3] +>>>>>14 leshort&0xc000 0x3000 \bx[2] +>>>>>15 byte&0x80 =0x00 \b, YUV color +>>>>>15 byte&0x80 =0x80 \b, bad color specification +>>>>>15 byte&0x40 =0x40 \b, no clamping required +>>>>>15 byte&0x40 =0x00 \b, decoders should clamp +#>0 string x we got %s +#>>&(4.l+4) use riff-walk # AVI section extended by Patrik Radman # @@ -88,8 +108,8 @@ !:mime video/x-msvideo >>12 string LIST >>>20 string hdrlavih ->>>>&36 lelong x \b, %lu x ->>>>&40 lelong x %lu, +>>>>&36 lelong x \b, %u x +>>>>&40 lelong x %u, >>>>&4 lelong >1000000 <1 fps, >>>>&4 lelong 1000000 1.00 fps, >>>>&4 lelong 500000 2.00 fps, @@ -209,6 +229,8 @@ >8 string 4XMV \b, 4X Movie file # AMV-type AVI file: http://wiki.multimedia.cx/index.php?title=AMV >8 string AMV\040 \b, AMV +>8 string WEBP \b, Web/P image +>>12 use riff-walk # # XXX - some of the below may only appear in little-endian form. @@ -284,4 +306,3 @@ >>&6 leshort =2 \b, stereo >>&6 leshort >2 \b, %d channels >>&8 lelong >0 %d Hz - diff --git a/contrib/file/magic/Magdir/scientific b/contrib/file/magic/Magdir/scientific index 66d3c598ca..f780743ca4 100644 --- a/contrib/file/magic/Magdir/scientific +++ b/contrib/file/magic/Magdir/scientific @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: scientific,v 1.8 2014/01/06 17:46:23 rrt Exp $ +# $File: scientific,v 1.9 2014/06/03 19:01:34 christos Exp $ # scientific: file(1) magic for scientific formats # # From: Joe Krahn @@ -91,12 +91,12 @@ # uppercase letters. However, examples have been seen without the date string, # e.g., the example on the chemime site. 0 string HEADER\ \ \ \ ->&0 regex/1 \^.{40} ->>&0 regex/1 [0-9]{2}-[A-Z]{3}-[0-9]{2}\ {3} ->>>&0 regex/1s [A-Z0-9]{4}.{14}$ ->>>>&0 regex/1 [A-Z0-9]{4} Protein Data Bank data, ID Code %s +>&0 regex/1l \^.{40} +>>&0 regex/1l [0-9]{2}-[A-Z]{3}-[0-9]{2}\ {3} +>>>&0 regex/1ls [A-Z0-9]{4}.{14}$ +>>>>&0 regex/1l [A-Z0-9]{4} Protein Data Bank data, ID Code %s !:mime chemical/x-pdb ->>>>0 regex/1 [0-9]{2}-[A-Z]{3}-[0-9]{2} \b, %s +>>>>0 regex/1l [0-9]{2}-[A-Z]{3}-[0-9]{2} \b, %s # Type: GDSII Stream file 0 belong 0x00060002 GDSII Stream file diff --git a/contrib/file/magic/Magdir/sequent b/contrib/file/magic/Magdir/sequent index 0ce6bf2c79..5137c0ed9a 100644 --- a/contrib/file/magic/Magdir/sequent +++ b/contrib/file/magic/Magdir/sequent @@ -1,35 +1,42 @@ #------------------------------------------------------------------------------ -# $File: sequent,v 1.8 2009/09/19 16:28:12 christos Exp $ +# $File: sequent,v 1.12 2014/08/16 16:07:12 christos Exp $ # sequent: file(1) magic for Sequent machines # # Sequent information updated by Don Dwiggins . # For Sequent's multiprocessor systems (incomplete). 0 lelong 0x00ea BALANCE NS32000 .o >16 lelong >0 not stripped ->124 lelong >0 version %ld +>124 lelong >0 version %d 0 lelong 0x10ea BALANCE NS32000 executable (0 @ 0) >16 lelong >0 not stripped ->124 lelong >0 version %ld +>124 lelong >0 version %d 0 lelong 0x20ea BALANCE NS32000 executable (invalid @ 0) >16 lelong >0 not stripped ->124 lelong >0 version %ld +>124 lelong >0 version %d 0 lelong 0x30ea BALANCE NS32000 standalone executable >16 lelong >0 not stripped ->124 lelong >0 version %ld +>124 lelong >0 version %d # # Symmetry information added by Jason Merrill . # Symmetry magic nums will not be reached if DOS COM comes before them; # byte 0xeb is matched before these get a chance. 0 leshort 0x12eb SYMMETRY i386 .o >16 lelong >0 not stripped ->124 lelong >0 version %ld +>124 lelong >0 version %d 0 leshort 0x22eb SYMMETRY i386 executable (0 @ 0) >16 lelong >0 not stripped ->124 lelong >0 version %ld +>124 lelong >0 version %d 0 leshort 0x32eb SYMMETRY i386 executable (invalid @ 0) >16 lelong >0 not stripped ->124 lelong >0 version %ld -0 leshort 0x42eb SYMMETRY i386 standalone executable ->16 lelong >0 not stripped ->124 lelong >0 version %ld +>124 lelong >0 version %d +# http://en.wikipedia.org/wiki/Sequent_Computer_Systems +# below test line conflicts with MS-DOS 2.11 floppies and Acronis loader +#0 leshort 0x42eb SYMMETRY i386 standalone executable +0 leshort 0x42eb +# skip unlike negative version +>124 lelong >-1 +# assuming version 28867614 is very low probable +>>124 lelong !28867614 SYMMETRY i386 standalone executable +>>>16 lelong >0 not stripped +>>>124 lelong >0 version %d diff --git a/contrib/file/magic/Magdir/sereal b/contrib/file/magic/Magdir/sereal new file mode 100644 index 0000000000..7fa4503f98 --- /dev/null +++ b/contrib/file/magic/Magdir/sereal @@ -0,0 +1,25 @@ + +#------------------------------------------------------------------------------ +# $File: sereal,v 1.2 2014/11/11 20:10:49 christos Exp $ +# sereal: file(1) magic the Sereal binary serialization format +# +# From: Ævar Arnfjörð Bjarmason +# +# See the specification of the format at +# https://github.com/Sereal/Sereal/blob/master/sereal_spec.pod#document-header-format +# +# I'd have liked to do the byte&0xF0 matching against 0, 1, 2 ... by +# doing (byte&0xF0)>>4 here, but unfortunately that's not +# supported. So when we print out a message about an unknown format +# we'll print out e.g. 0x30 instead of the more human-readable +# 0x30>>4. +# +# See https://github.com/Sereal/Sereal/commit/35372ae01d in the +# Sereal.git repository for test Sereal data. +0 string \=srl Sereal data +!:mime application/sereal +>4 byte&0x0F x (version %d, +>4 byte&0xF0 0x00 uncompressed) +>4 byte&0xF0 0x10 compressed with non-incremental Snappy) +>4 byte&0xF0 0x20 compressed with incremental Snappy) +>4 byte&0xF0 >0x20 unknown subformat, flag: %d>>4) diff --git a/contrib/file/magic/Magdir/sgi b/contrib/file/magic/Magdir/sgi index 913e3b8aac..a6223d78d1 100644 --- a/contrib/file/magic/Magdir/sgi +++ b/contrib/file/magic/Magdir/sgi @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: sgi,v 1.20 2014/03/10 00:53:38 christos Exp $ +# $File: sgi,v 1.21 2014/04/30 21:41:02 christos Exp $ # sgi: file(1) magic for Silicon Graphics operating systems and applications # # Executable images are handled either in aout (for old-style a.out @@ -17,16 +17,16 @@ 0 beshort 0x0506 IRIS Showcase file >2 byte 0x49 - ->3 byte x - version %ld +>3 byte x - version %d 0 beshort 0x0226 IRIS Showcase template >2 byte 0x63 - ->3 byte x - version %ld +>3 byte x - version %d 0 belong 0x5343464d IRIS Showcase file ->4 byte x - version %ld +>4 byte x - version %d 0 belong 0x5443464d IRIS Showcase template ->4 byte x - version %ld +>4 byte x - version %d 0 belong 0xdeadbabe IRIX Parallel Arena ->8 belong >0 - version %ld +>8 belong >0 - version %d # core files # @@ -49,7 +49,7 @@ # Trusted IRIX info 0 string SGIAUDIT SGI Audit file >8 byte x - version %d ->9 byte x \b.%ld +>9 byte x \b.%d # 0 string WNGZWZSC Wingz compiled script 0 string WNGZWZSS Wingz spreadsheet @@ -82,11 +82,11 @@ #>20 lelong -2 temporal index #>20 lelong -1 metadata #>20 lelong 0 log volume #0 -#>20 lelong >0 log volume #%ld +#>20 lelong >0 log volume #%d >20 belong -2 temporal index >20 belong -1 metadata >20 belong 0 log volume #0 ->20 belong >0 log volume #%ld +>20 belong >0 log volume #%d >24 string >\0 host: %s 0 string PCPFolio PCP >9 string Version: Archive Folio diff --git a/contrib/file/magic/Magdir/sharc b/contrib/file/magic/Magdir/sharc index d5f360460b..b40e652342 100644 --- a/contrib/file/magic/Magdir/sharc +++ b/contrib/file/magic/Magdir/sharc @@ -1,6 +1,6 @@ #------------------------------------------------------------------------ -# $File: sharc,v 1.6 2009/09/19 16:28:12 christos Exp $ +# $File: sharc,v 1.7 2014/04/30 21:41:02 christos Exp $ # file(1) magic for sharc files # # SHARC DSP, MIDI SysEx and RiscOS filetype definitions added by @@ -19,5 +19,5 @@ 0 string .system SHARC architecture file 0 leshort 0x521C SHARC COFF binary ->2 leshort >1 , %hd sections +>2 leshort >1 , %d sections >>12 lelong >0 , not stripped diff --git a/contrib/file/magic/Magdir/sql b/contrib/file/magic/Magdir/sql index 5b8c3e3acb..c69f44f0bb 100644 --- a/contrib/file/magic/Magdir/sql +++ b/contrib/file/magic/Magdir/sql @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: sql,v 1.13 2013/08/27 04:02:33 christos Exp $ +# $File: sql,v 1.15 2014/04/30 21:41:02 christos Exp $ # sql: file(1) magic for SQL files # # From: "Marty Leisner" @@ -69,7 +69,7 @@ # SQLite Write-Ahead Log from SQLite version >= 3.7.0 # http://www.sqlite.org/fileformat.html#walformat 0 belong&0xfffffffe 0x377f0682 SQLite Write-Ahead Log, ->4 belong x version %ld +>4 belong x version %d # SQLite Rollback Journal # http://www.sqlite.org/fileformat.html#rollbackjournal diff --git a/contrib/file/magic/Magdir/ssh b/contrib/file/magic/Magdir/ssh index d867af0d7a..ca645644a7 100644 --- a/contrib/file/magic/Magdir/ssh +++ b/contrib/file/magic/Magdir/ssh @@ -3,9 +3,11 @@ 0 string SSH\ PRIVATE\ KEY OpenSSH RSA1 private key, >28 string >\0 version %s +0 string -----BEGIN\ OPENSSH\ PRIVATE\ KEY----- OpenSSH private key 0 string ssh-dss\ OpenSSH DSA public key 0 string ssh-rsa\ OpenSSH RSA public key 0 string ecdsa-sha2-nistp256 OpenSSH ECDSA public key 0 string ecdsa-sha2-nistp384 OpenSSH ECDSA public key 0 string ecdsa-sha2-nistp521 OpenSSH ECDSA public key +0 string ssh-ed25519 OpenSSH ED25519 public key diff --git a/contrib/file/magic/Magdir/sun b/contrib/file/magic/Magdir/sun index 86ffad2f15..802a9eb889 100644 --- a/contrib/file/magic/Magdir/sun +++ b/contrib/file/magic/Magdir/sun @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: sun,v 1.25 2013/01/09 22:37:24 christos Exp $ +# $File: sun,v 1.27 2014/04/30 21:41:02 christos Exp $ # sun: file(1) magic for Sun machines # # Values for big-endian Sun (MC680x0, SPARC) binaries on pre-5.x @@ -9,7 +9,7 @@ # are in aout, as they're indistinguishable from other big-endian # 32-bit a.out files. # -0 belong&077777777 0600413 a.out SunOS sparc demand paged +0 belong&077777777 0600413 a.out SunOS SPARC demand paged >0 byte &0x80 >>20 belong <4096 shared library >>20 belong =4096 dynamically linked executable @@ -17,12 +17,12 @@ >0 byte ^0x80 executable >16 belong >0 not stripped -0 belong&077777777 0600410 a.out SunOS sparc pure +0 belong&077777777 0600410 a.out SunOS SPARC pure >0 byte &0x80 dynamically linked executable >0 byte ^0x80 executable >16 belong >0 not stripped -0 belong&077777777 0600407 a.out SunOS sparc +0 belong&077777777 0600407 a.out SunOS SPARC >0 byte &0x80 dynamically linked executable >0 byte ^0x80 executable >16 belong >0 not stripped @@ -97,7 +97,7 @@ # which is the IANA registry of Snoop datalink types) # 0 string snoop Snoop capture file ->8 belong >0 - version %ld +>8 belong >0 - version %d >12 belong 0 (IEEE 802.3) >12 belong 1 (IEEE 802.4) >12 belong 2 (IEEE 802.5) @@ -108,24 +108,24 @@ >12 belong 7 (IBM channel-to-channel adapter) >12 belong 8 (FDDI) >12 belong 9 (Other) ->12 belong 10 (type %ld) ->12 belong 11 (type %ld) ->12 belong 12 (type %ld) ->12 belong 13 (type %ld) ->12 belong 14 (type %ld) ->12 belong 15 (type %ld) +>12 belong 10 (type %d) +>12 belong 11 (type %d) +>12 belong 12 (type %d) +>12 belong 13 (type %d) +>12 belong 14 (type %d) +>12 belong 15 (type %d) >12 belong 16 (Fibre Channel) >12 belong 17 (ATM) >12 belong 18 (ATM Classical IP) ->12 belong 19 (type %ld) ->12 belong 20 (type %ld) ->12 belong 21 (type %ld) ->12 belong 22 (type %ld) ->12 belong 23 (type %ld) ->12 belong 24 (type %ld) ->12 belong 25 (type %ld) +>12 belong 19 (type %d) +>12 belong 20 (type %d) +>12 belong 21 (type %d) +>12 belong 22 (type %d) +>12 belong 23 (type %d) +>12 belong 24 (type %d) +>12 belong 25 (type %d) >12 belong 26 (IP over Infiniband) ->12 belong >26 (type %ld) +>12 belong >26 (type %d) #--------------------------------------------------------------------------- # The following entries have been tested by Duncan Laurie (a diff --git a/contrib/file/magic/Magdir/symbos b/contrib/file/magic/Magdir/symbos index c6a4480e8b..c97a42e0c7 100644 --- a/contrib/file/magic/Magdir/symbos +++ b/contrib/file/magic/Magdir/symbos @@ -2,7 +2,7 @@ #------------------------------------------------------------------------------ # msx: file(1) magic for the SymbOS operating system # http://www.symbos.de -# Fábio R. Schmidlin +# Fabio R. Schmidlin # SymbOS EXE file 0x30 string SymExe SymbOS executable diff --git a/contrib/file/magic/Magdir/sysex b/contrib/file/magic/Magdir/sysex index c6f78cde28..97472e2755 100644 --- a/contrib/file/magic/Magdir/sysex +++ b/contrib/file/magic/Magdir/sysex @@ -1,9 +1,9 @@ #------------------------------------------------------------------------ -# $File: sysex,v 1.7 2013/09/16 15:12:42 christos Exp $ +# $File: sysex,v 1.8 2014/06/03 19:17:27 christos Exp $ # sysex: file(1) magic for MIDI sysex files # -# GRR: orginal 1 byte test at offset was too general as it catches also many FATs of DOS filesystems +# 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 # http://en.wikipedia.org/wiki/MIDI 0 ubeshort&0xFF80 0xF000 SysEx File - diff --git a/contrib/file/magic/Magdir/ti-8x b/contrib/file/magic/Magdir/ti-8x index d7903febcb..205f982d2d 100644 --- a/contrib/file/magic/Magdir/ti-8x +++ b/contrib/file/magic/Magdir/ti-8x @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: ti-8x,v 1.6 2009/09/19 16:28:12 christos Exp $ +# $File: ti-8x,v 1.7 2014/04/30 21:41:02 christos Exp $ # ti-8x: file(1) magic for the TI-8x and TI-9x Graphing Calculators. # # From: Ryan McGuire (rmcguire@freenet.columbus.oh.us). @@ -222,7 +222,7 @@ >49 byte 0x24 type: application, >49 byte 0x25 type: certificate, >49 byte 0x3e type: license, ->74 lelong >0 size: %ld bytes +>74 lelong >0 size: %d bytes # VTi & TiEmu skins (TI Graphing Calculators). # From: Romain Lievin (roms@lpg.ticalc.org). diff --git a/contrib/file/magic/Magdir/troff b/contrib/file/magic/Magdir/troff index b24ea0a498..cb6bc00eb8 100644 --- a/contrib/file/magic/Magdir/troff +++ b/contrib/file/magic/Magdir/troff @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: troff,v 1.10 2009/09/19 16:28:12 christos Exp $ +# $File: troff,v 1.11 2014/06/03 19:01:34 christos Exp $ # troff: file(1) magic for *roff # # updated by Daniel Quinlan (quinlan@yggdrasil.com) @@ -16,9 +16,9 @@ !:mime text/troff 0 search/1 ''' troff or preprocessor input text !:mime text/troff -0 regex/20 \^\\.[A-Za-z0-9][A-Za-z0-9][\ \t] troff or preprocessor input text +0 regex/20l \^\\.[A-Za-z0-9][A-Za-z0-9][\ \t] troff or preprocessor input text !:mime text/troff -0 regex/20 \^\\.[A-Za-z0-9][A-Za-z0-9]$ troff or preprocessor input text +0 regex/20l \^\\.[A-Za-z0-9][A-Za-z0-9]$ troff or preprocessor input text !:mime text/troff # ditroff intermediate output text diff --git a/contrib/file/magic/Magdir/uterus b/contrib/file/magic/Magdir/uterus index c5a139b5fa..a8be8a880d 100644 --- a/contrib/file/magic/Magdir/uterus +++ b/contrib/file/magic/Magdir/uterus @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: uterus,v 1.1 2012/12/18 18:53:32 christos Exp $ +# $File: uterus,v 1.3 2014/04/30 21:41:02 christos Exp $ # file(1) magic for uterus files # http://freecode.com/projects/uterus # diff --git a/contrib/file/magic/Magdir/varied.out b/contrib/file/magic/Magdir/varied.out index 3d8aa9219a..01caf07faf 100644 --- a/contrib/file/magic/Magdir/varied.out +++ b/contrib/file/magic/Magdir/varied.out @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: varied.out,v 1.22 2010/07/02 00:06:27 christos Exp $ +# $File: varied.out,v 1.23 2014/04/30 21:41:02 christos Exp $ # varied.out: file(1) magic for various USG systems # # Herewith many of the object file formats used by USG systems. @@ -26,7 +26,7 @@ >7 string >\0 version '%s' # gnu gmon magic From: Eugen Dedu 0 string gmon GNU prof performance data ->4 long x - version %ld +>4 long x - version %d # From: Dave Pearson # Harbour HRB files. 0 string \xc0HRB Harbour HRB file diff --git a/contrib/file/magic/Magdir/vax b/contrib/file/magic/Magdir/vax index 5a096e8650..11de6cef00 100644 --- a/contrib/file/magic/Magdir/vax +++ b/contrib/file/magic/Magdir/vax @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: vax,v 1.8 2013/01/09 22:37:24 christos Exp $ +# $File: vax,v 1.9 2014/04/30 21:41:02 christos Exp $ # vax: file(1) magic for VAX executable/object and APL workspace # 0 lelong 0101557 VAX single precision APL workspace @@ -21,7 +21,7 @@ # 0 leshort 0570 VAX COFF executable >12 lelong >0 not stripped ->22 leshort >0 - version %ld +>22 leshort >0 - version %d 0 leshort 0575 VAX COFF pure executable >12 lelong >0 not stripped ->22 leshort >0 - version %ld +>22 leshort >0 - version %d diff --git a/contrib/file/magic/Magdir/virtual b/contrib/file/magic/Magdir/virtual index 17ef44d209..26442bf94b 100644 --- a/contrib/file/magic/Magdir/virtual +++ b/contrib/file/magic/Magdir/virtual @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: virtual,v 1.3 2014/03/03 14:19:46 christos Exp $ +# $File: virtual,v 1.6 2014/05/07 21:25:41 christos Exp $ # From: James Nobis # Microsoft hard disk images for: # Virtual Server @@ -9,13 +9,6 @@ # .vhd 0 string conectix Microsoft Disk Image, Virtual Server or Virtual PC -# Sun xVM VirtualBox Disk Image -# From: Richard W.M. Jones -# VirtualBox Disk Image -0x40 ulelong 0xbeda107f VirtualBox Disk Image ->0x44 uleshort >0 \b, major %u ->0x46 uleshort >0 \b, minor %u - # libvirt # From: Philipp Hahn 0 string LibvirtQemudSave Libvirt QEMU Suspend Image @@ -25,3 +18,106 @@ >0x1c lelong 1 \b, compressed 0 string LibvirtQemudPart Libvirt QEMU partial Suspend Image +# From: Alex Beregszaszi +0 string/b COWD VMWare3 +>4 byte 3 disk image +>>32 lelong x (%d/ +>>36 lelong x \b%d/ +>>40 lelong x \b%d) +>4 byte 2 undoable disk image +>>32 string >\0 (%s) + +0 string/b VMDK VMware4 disk image +0 string/b KDMV VMware4 disk image + +#-------------------------------------------------------------------- +# Qemu Emulator Images +# Lines written by Friedrich Schwittay (f.schwittay@yousable.de) +# 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 QEMU QCOW Image + +# Uncomment the following line to display Magic (only used for debugging +# this magic number) +#>0 string/b x , Magic: %s + +# There are currently 2 Versions: "1" and "2". +# http://www.gnome.org/~markmc/qcow-image-format-version-1.html +>4 belong 1 (v1) + +# Using the existence of the Backing File Offset to determine whether +# to read Backing File Information +>>12 belong >0 \b, has backing file ( +# Note that this isn't a null-terminated string; the length is actually +# (16.L). Assuming a null-terminated string happens to work usually, but it +# may spew junk until it reaches a \0 in some cases. +>>>(12.L) string >\0 \bpath %s + +# Modification time of the Backing File +# Really useful if you want to know if your backing +# file is still usable together with this image +>>>>20 bedate >0 \b, mtime %s) +>>>>20 default x \b) + +# Size is stored in bytes in a big-endian u64. +>>24 bequad x \b, %lld bytes + +# 1 for AES encryption, 0 for none. +>>36 belong 1 \b, AES-encrypted + +# http://www.gnome.org/~markmc/qcow-image-format.html +>4 belong 2 (v2) +# Using the existence of the Backing File Offset to determine whether +# to read Backing File Information +>>8 bequad >0 \b, has backing file +# Note that this isn't a null-terminated string; the length is actually +# (16.L). Assuming a null-terminated string happens to work usually, but it +# may spew junk until it reaches a \0 in some cases. Also, since there's no +# .Q modifier, we just use the bottom four bytes as an offset. Note that if +# the file is over 4G, and the backing file path is stored after the first 4G, +# the wrong filename will be printed. (This should be (8.Q), when that syntax +# is introduced.) +>>>(12.L) string >\0 (path %s) +>>24 bequad x \b, %lld bytes +>>32 belong 1 \b, AES-encrypted + +>4 belong 3 (v3) +# Using the existence of the Backing File Offset to determine whether +# to read Backing File Information +>>8 bequad >0 \b, has backing file +# Note that this isn't a null-terminated string; the length is actually +# (16.L). Assuming a null-terminated string happens to work usually, but it +# may spew junk until it reaches a \0 in some cases. Also, since there's no +# .Q modifier, we just use the bottom four bytes as an offset. Note that if +# the file is over 4G, and the backing file path is stored after the first 4G, +# the wrong filename will be printed. (This should be (8.Q), when that syntax +# is introduced.) +>>>(12.L) string >\0 (path %s) +>>24 bequad x \b, %lld bytes +>>32 belong 1 \b, AES-encrypted + +>4 default x (unknown version) + +0 string/b QEVM QEMU suspend to disk image + +# QEMU QED Image +# http://wiki.qemu.org/Features/QED/Specification +0 string/b QED\0 QEMU QED Image + +# VDI Image +# Sun xVM VirtualBox Disk Image +# From: Richard W.M. Jones +# VirtualBox Disk Image +0x40 ulelong 0xbeda107f VirtualBox Disk Image +>0x44 uleshort >0 \b, major %u +>0x46 uleshort >0 \b, minor %u +>0 string >\0 (%s) +>368 lequad x \b, %lld bytes + +0 string/b Bochs\ Virtual\ HD\ Image Bochs disk image, +>32 string x type %s, +>48 string x subtype %s + +0 lelong 0x02468ace Bochs Sparse disk image + diff --git a/contrib/file/magic/Magdir/vms b/contrib/file/magic/Magdir/vms index be716b38e3..4939303948 100644 --- a/contrib/file/magic/Magdir/vms +++ b/contrib/file/magic/Magdir/vms @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: vms,v 1.7 2013/03/09 22:36:00 christos Exp $ +# $File: vms,v 1.9 2014/08/17 13:47:59 christos Exp $ # vms: file(1) magic for VMS executables (experimental) # # VMS .exe formats, both VAX and AXP (Greg Roelofs, newt@uchicago.edu) diff --git a/contrib/file/magic/Magdir/vorbis b/contrib/file/magic/Magdir/vorbis index ed6c040c30..d337398dcb 100644 --- a/contrib/file/magic/Magdir/vorbis +++ b/contrib/file/magic/Magdir/vorbis @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: vorbis,v 1.16 2009/09/19 16:28:13 christos Exp $ +# $File: vorbis,v 1.20 2014/09/23 16:35:08 christos Exp $ # vorbis: file(1) magic for Ogg/Vorbis files # # From Felix von Leitner @@ -23,7 +23,6 @@ # --- Ogg Framing --- #0 search/1000 OggS Ogg data 0 string OggS Ogg data -!:mime application/ogg >4 byte !0 UNKNOWN REVISION %u ##>4 byte 0 revision 0 >4 byte 0 @@ -31,9 +30,12 @@ # non-Vorbis content: FLAC (Free Lossless Audio Codec, http://flac.sourceforge.net) >>28 string \x7fFLAC \b, FLAC audio # non-Vorbis content: Theora +!:mime audio/ogg >>28 string \x80theora \b, Theora video +!:mime video/ogg # non-Vorbis content: Kate ->>28 string \x80kate\0\0\0\0 \b, Kate +>>28 string \x80kate\0\0\0\0 \b, Kate (Karaoke and Text) +!:mime application/ogg >>>37 ubyte x v%u >>>38 ubyte x \b.%u, >>>40 byte 0 utf8 encoding, @@ -44,25 +46,29 @@ >>>76 string \0 no category set # non-Vorbis content: Skeleton >>28 string fishead\0 \b, Skeleton +!:mime video/ogg >>>36 short x v%u >>>40 short x \b.%u # non-Vorbis content: Speex >>28 string Speex\ \ \ \b, Speex audio +!:mime audio/ogg # non-Vorbis content: OGM >>28 string \x01video\0\0\0 \b, OGM video +!:mime video/ogg >>>37 string/c div3 (DivX 3) >>>37 string/c divx (DivX 4) >>>37 string/c dx50 (DivX 5) >>>37 string/c xvid (XviD) # --- First vorbis packet - general header --- >>28 string \x01vorbis \b, Vorbis audio, ->>>35 lelong !0 UNKNOWN VERSION %lu, +!:mime audio/ogg +>>>35 lelong !0 UNKNOWN VERSION %u, ##>>>35 lelong 0 version 0, >>>35 lelong 0 >>>>39 ubyte 1 mono, >>>>39 ubyte 2 stereo, >>>>39 ubyte >2 %u channels, ->>>>40 lelong x %lu Hz +>>>>40 lelong x %u Hz # Minimal, nominal and maximal bitrates specified when encoding >>>>48 string <\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \b, # The above tests if at least one of these is specified: @@ -72,13 +78,13 @@ # Vorbis 1.0 uses 0 instead of -1. >>>>>>52 lelong !0 >>>>>>>52 lelong !-1000 ->>>>>>>>52 lelong x <%lu +>>>>>>>>52 lelong x <%u >>>>>48 lelong !-1 ->>>>>>48 lelong x ~%lu +>>>>>>48 lelong x ~%u >>>>>44 lelong !-1 >>>>>>44 lelong !-1000 >>>>>>>44 lelong !0 ->>>>>>>>44 lelong x >%lu +>>>>>>>>44 lelong x >%u >>>>>48 string <\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff bps # -- Second vorbis header packet - the comments # A kludge to read the vendor string. It's a counted string, not a diff --git a/contrib/file/magic/Magdir/windows b/contrib/file/magic/Magdir/windows index 6c70e02a2f..3f7bded3e1 100644 --- a/contrib/file/magic/Magdir/windows +++ b/contrib/file/magic/Magdir/windows @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: windows,v 1.6 2013/04/19 20:12:29 christos Exp $ +# $File: windows,v 1.10 2014/09/24 19:52:46 christos Exp $ # windows: file(1) magic for Microsoft Windows # # This file is mainly reserved for files where programs @@ -36,7 +36,7 @@ >>0xf88 lelong 1 \b, full dump >>0xf88 lelong 2 \b, kernel dump >>0xf88 lelong 3 \b, small dump ->>0x068 lelong x \b, %ld pages +>>0x068 lelong x \b, %d pages >4 string DU64 MS Windows 64bit crash dump >>0xf98 lelong 1 \b, full dump >>0xf98 lelong 2 \b, kernel dump @@ -159,8 +159,9 @@ >&0 string Version\ 5.00\r\n\r\n Windows Registry text (Win2K or above) # Windows *.INF *.INI files updated by Joerg Jenderek at Apr 2013 -# emtpy ,comment , section , unicode line -0 regex/s \\`(\r\n|;|[[]|\xFF\xFE) +# empty ,comment , section +# PR/383: remove unicode BOM because it is not portable across regex impls +0 regex/s \\`(\\r\\n|;|[[]) # left bracket in section line >&0 search/8192 [ # http://en.wikipedia.org/wiki/Autorun.inf diff --git a/contrib/file/magic/Magdir/xilinx b/contrib/file/magic/Magdir/xilinx index 2c97d11dde..91e84d91d0 100644 --- a/contrib/file/magic/Magdir/xilinx +++ b/contrib/file/magic/Magdir/xilinx @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: xilinx,v 1.6 2013/11/19 23:15:13 christos Exp $ +# $File: xilinx,v 1.7 2014/04/30 21:41:02 christos Exp $ # This is Aaron's attempt at a MAGIC file for Xilinx .bit files. # Xilinx-Magic@RevRagnarok.com # Got the info from FPGA-FAQ 0026 @@ -33,7 +33,7 @@ # Then 'e' >>>>>>>>>>>&1 string e # And length of data ->>>>>>>>>>>>&0 belong x - data length 0x%lx +>>>>>>>>>>>>&0 belong x - data length 0x%x # Raw bitstream files 0 long 0xffffffff diff --git a/contrib/file/magic/Magdir/xwindows b/contrib/file/magic/Magdir/xwindows index 6ebe676238..eb208927f0 100644 --- a/contrib/file/magic/Magdir/xwindows +++ b/contrib/file/magic/Magdir/xwindows @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: xwindows,v 1.8 2013/02/08 17:25:57 christos Exp $ +# $File: xwindows,v 1.9 2014/04/30 21:41:02 christos Exp $ # xwindows: file(1) magic for various X/Window system file formats. # Compiled X Keymap @@ -18,10 +18,10 @@ # Jaleo XFS files 0 long 395726 Jaleo XFS file ->4 long x - version %ld ->8 long x - [%ld - ->20 long x \b%ldx ->24 long x \b%ldx +>4 long x - version %d +>8 long x - [%d - +>20 long x \b%dx +>24 long x \b%dx >28 long 1008 \bYUV422] >28 long 1000 \bRGB24] @@ -31,5 +31,5 @@ # http://cgit.freedesktop.org/xorg/lib/libXcursor/tree/include/X11/Xcursor/Xcursor.h 0 string Xcur Xcursor data !:mime image/x-xcursor ->10 leshort x version %hd ->>8 leshort x \b.%hd +>10 leshort x version %d +>>8 leshort x \b.%d diff --git a/contrib/file/magic/Magdir/zfs b/contrib/file/magic/Magdir/zfs index 1f74409a8c..77675ed719 100644 --- a/contrib/file/magic/Magdir/zfs +++ b/contrib/file/magic/Magdir/zfs @@ -37,14 +37,14 @@ # Big-endian values 8 string \000\000\000\002\365\272\313\254 ZFS shapshot (big-endian machine), ->20 belong x version %lu, +>20 belong x version %u, >32 belong 0 type: NONE, >32 belong 1 type: META, >32 belong 2 type: ZFS, >32 belong 3 type: ZVOL, >32 belong 4 type: OTHER, >32 belong 5 type: ANY, ->32 belong >5 type: UNKNOWN (%lu), +>32 belong >5 type: UNKNOWN (%u), >40 byte x destination GUID: %02X >41 byte x %02X >42 byte x %02X @@ -67,14 +67,14 @@ # Little-endian values 8 string \254\313\272\365\002\000\000\000 ZFS shapshot (little-endian machine), ->16 lelong x version %lu, +>16 lelong x version %u, >32 lelong 0 type: NONE, >32 lelong 1 type: META, >32 lelong 2 type: ZFS, >32 lelong 3 type: ZVOL, >32 lelong 4 type: OTHER, >32 lelong 5 type: ANY, ->32 lelong >5 type: UNKNOWN (%lu), +>32 lelong >5 type: UNKNOWN (%u), >47 byte x destination GUID: %02X >46 byte x %02X >45 byte x %02X diff --git a/contrib/file/src/apprentice.c b/contrib/file/src/apprentice.c index 7400c57185..47b4c870c2 100644 --- a/contrib/file/src/apprentice.c +++ b/contrib/file/src/apprentice.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.202 2014/03/14 18:48:11 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.229 2015/01/01 17:07:34 christos Exp $") #endif /* lint */ #include "magic.h" @@ -86,6 +86,10 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.202 2014/03/14 18:48:11 christos Exp $") #define ALLOC_CHUNK (size_t)10 #define ALLOC_INCR (size_t)200 +#define MAP_TYPE_MMAP 0 +#define MAP_TYPE_MALLOC 1 +#define MAP_TYPE_USER 2 + struct magic_entry { struct magic *mp; uint32_t cont_count; @@ -101,6 +105,7 @@ struct magic_entry_set { struct magic_map { void *p; size_t len; + int type; struct magic *magic[MAGIC_SETS]; uint32_t nmagic[MAGIC_SETS]; }; @@ -131,7 +136,10 @@ private uint16_t swap2(uint16_t); private uint32_t swap4(uint32_t); private uint64_t swap8(uint64_t); private char *mkdbname(struct magic_set *, const char *, int); +private struct magic_map *apprentice_buf(struct magic_set *, struct magic *, + size_t); private struct magic_map *apprentice_map(struct magic_set *, const char *); +private int check_buffer(struct magic_set *, struct magic_map *, const char *); private void apprentice_unmap(struct magic_map *); private int apprentice_compile(struct magic_set *, struct magic_map *, const char *); @@ -396,10 +404,11 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx) { struct mlist *ml; + mlp->map = idx == 0 ? map : NULL; if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL) return -1; - ml->map = idx == 0 ? map : NULL; + ml->map = NULL; ml->magic = map->magic[idx]; ml->nmagic = map->nmagic[idx]; @@ -416,9 +425,11 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx) private int apprentice_1(struct magic_set *ms, const char *fn, int action) { - struct mlist *ml; struct magic_map *map; +#ifndef COMPILE_ONLY + struct mlist *ml; size_t i; +#endif if (magicsize != FILE_MAGICSIZE) { file_error(ms, 0, "magic element size %lu != %lu", @@ -447,20 +458,27 @@ apprentice_1(struct magic_set *ms, const char *fn, int action) for (i = 0; i < MAGIC_SETS; i++) { if (add_mlist(ms->mlist[i], map, i) == -1) { file_oomem(ms, sizeof(*ml)); - apprentice_unmap(map); - return -1; + goto fail; } } if (action == FILE_LIST) { for (i = 0; i < MAGIC_SETS; i++) { - printf("Set %zu:\nBinary patterns:\n", i); + printf("Set %" SIZE_T_FORMAT "u:\nBinary patterns:\n", + i); apprentice_list(ms->mlist[i], BINTEST); printf("Text patterns:\n"); apprentice_list(ms->mlist[i], TEXTTEST); } } - + return 0; +fail: + for (i = 0; i < MAGIC_SETS; i++) { + mlist_free(ms->mlist[i]); + ms->mlist[i] = NULL; + } + return -1; +#else return 0; #endif /* COMPILE_ONLY */ } @@ -506,6 +524,11 @@ file_ms_alloc(int flags) ms->mlist[i] = NULL; ms->file = "unknown"; ms->line = 0; + ms->indir_max = FILE_INDIR_MAX; + ms->name_max = FILE_NAME_MAX; + ms->elf_shnum_max = FILE_ELF_SHNUM_MAX; + ms->elf_phnum_max = FILE_ELF_PHNUM_MAX; + ms->elf_notes_max = FILE_ELF_NOTES_MAX; return ms; free: free(ms); @@ -517,14 +540,22 @@ apprentice_unmap(struct magic_map *map) { if (map == NULL) return; - if (map->p == NULL) - return; + + switch (map->type) { #ifdef QUICK - if (map->len) - (void)munmap(map->p, map->len); - else + case MAP_TYPE_MMAP: + if (map->p) + (void)munmap(map->p, map->len); + break; #endif + case MAP_TYPE_MALLOC: free(map->p); + break; + case MAP_TYPE_USER: + break; + default: + abort(); + } free(map); } @@ -542,20 +573,69 @@ mlist_alloc(void) private void mlist_free(struct mlist *mlist) { - struct mlist *ml; + struct mlist *ml, *next; if (mlist == NULL) return; - for (ml = mlist->next; ml != mlist;) { - struct mlist *next = ml->next; + ml = mlist->next; + for (ml = mlist->next; (next = ml->next) != NULL; ml = next) { if (ml->map) apprentice_unmap(ml->map); free(ml); - ml = next; + if (ml == mlist) + break; + } +} + +#ifndef COMPILE_ONLY +/* void **bufs: an array of compiled magic files */ +protected int +buffer_apprentice(struct magic_set *ms, struct magic **bufs, + size_t *sizes, size_t nbufs) +{ + size_t i, j; + struct mlist *ml; + struct magic_map *map; + + if (nbufs == 0) + return -1; + + if (ms->mlist[0] != NULL) + file_reset(ms); + + init_file_tables(); + + for (i = 0; i < MAGIC_SETS; i++) { + mlist_free(ms->mlist[i]); + if ((ms->mlist[i] = mlist_alloc()) == NULL) { + file_oomem(ms, sizeof(*ms->mlist[i])); + goto fail; + } } - free(ml); + + for (i = 0; i < nbufs; i++) { + map = apprentice_buf(ms, bufs[i], sizes[i]); + if (map == NULL) + goto fail; + + for (j = 0; j < MAGIC_SETS; j++) { + if (add_mlist(ms->mlist[j], map, j) == -1) { + file_oomem(ms, sizeof(*ml)); + goto fail; + } + } + } + + return 0; +fail: + for (i = 0; i < MAGIC_SETS; i++) { + mlist_free(ms->mlist[i]); + ms->mlist[i] = NULL; + } + return -1; } +#endif /* const char *fn: list of magic files and directories */ protected int @@ -582,11 +662,9 @@ file_apprentice(struct magic_set *ms, const char *fn, int action) mlist_free(ms->mlist[i]); if ((ms->mlist[i] = mlist_alloc()) == NULL) { file_oomem(ms, sizeof(*ms->mlist[i])); - if (i != 0) { - --i; - do - mlist_free(ms->mlist[i]); - while (i != 0); + while (i-- > 0) { + mlist_free(ms->mlist[i]); + ms->mlist[i] = NULL; } free(mfn); return -1; @@ -779,7 +857,6 @@ apprentice_magic_strength(const struct magic *m) break; default: - val = 0; (void)fprintf(stderr, "Bad type %d\n", m->type); abort(); } @@ -1290,11 +1367,7 @@ out: magic_entry_free(mset[j].me, mset[j].count); if (errs) { - for (j = 0; j < MAGIC_SETS; j++) { - if (map->magic[j]) - free(map->magic[j]); - } - free(map); + apprentice_unmap(map); return NULL; } return map; @@ -1314,7 +1387,7 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) * the sign extension must have happened. */ case FILE_BYTE: - v = (char) v; + v = (signed char) v; break; case FILE_SHORT: case FILE_BESHORT: @@ -1383,7 +1456,8 @@ string_modifier_check(struct magic_set *ms, struct magic *m) if ((ms->flags & MAGIC_CHECK) == 0) return 0; - if (m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0) { + if ((m->type != FILE_REGEX || (m->str_flags & REGEX_LINE_COUNT) == 0) && + (m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0)) { file_magwarn(ms, "'/BHhLl' modifiers are only allowed for pascal strings\n"); return -1; @@ -1531,6 +1605,145 @@ check_cond(struct magic_set *ms, int cond, uint32_t cont_level) } #endif /* ENABLE_CONDITIONALS */ +private int +parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) +{ + const char *l = *lp; + + while (!isspace((unsigned char)*++l)) + switch (*l) { + case CHAR_INDIRECT_RELATIVE: + m->str_flags |= INDIRECT_RELATIVE; + break; + default: + if (ms->flags & MAGIC_CHECK) + file_magwarn(ms, "indirect modifier `%c' " + "invalid", *l); + *lp = l; + return -1; + } + *lp = l; + return 0; +} + +private void +parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, + int op) +{ + const char *l = *lp; + char *t; + uint64_t val; + + ++l; + m->mask_op |= op; + val = (uint64_t)strtoull(l, &t, 0); + l = t; + m->num_mask = file_signextend(ms, m, val); + eatsize(&l); + *lp = l; +} + +private int +parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) +{ + const char *l = *lp; + char *t; + int have_range = 0; + + while (!isspace((unsigned char)*++l)) { + switch (*l) { + case '0': case '1': case '2': + case '3': case '4': case '5': + case '6': case '7': case '8': + case '9': + if (have_range && (ms->flags & MAGIC_CHECK)) + file_magwarn(ms, "multiple ranges"); + have_range = 1; + m->str_range = CAST(uint32_t, strtoul(l, &t, 0)); + if (m->str_range == 0) + file_magwarn(ms, "zero range"); + l = t - 1; + break; + case CHAR_COMPACT_WHITESPACE: + m->str_flags |= STRING_COMPACT_WHITESPACE; + break; + case CHAR_COMPACT_OPTIONAL_WHITESPACE: + m->str_flags |= STRING_COMPACT_OPTIONAL_WHITESPACE; + break; + case CHAR_IGNORE_LOWERCASE: + m->str_flags |= STRING_IGNORE_LOWERCASE; + break; + case CHAR_IGNORE_UPPERCASE: + m->str_flags |= STRING_IGNORE_UPPERCASE; + break; + case CHAR_REGEX_OFFSET_START: + m->str_flags |= REGEX_OFFSET_START; + break; + case CHAR_BINTEST: + m->str_flags |= STRING_BINTEST; + break; + case CHAR_TEXTTEST: + m->str_flags |= STRING_TEXTTEST; + break; + case CHAR_TRIM: + m->str_flags |= STRING_TRIM; + break; + case CHAR_PSTRING_1_LE: +#define SET_LENGTH(a) m->str_flags = (m->str_flags & ~PSTRING_LEN) | (a) + if (m->type != FILE_PSTRING) + goto bad; + SET_LENGTH(PSTRING_1_LE); + break; + case CHAR_PSTRING_2_BE: + if (m->type != FILE_PSTRING) + goto bad; + SET_LENGTH(PSTRING_2_BE); + break; + case CHAR_PSTRING_2_LE: + if (m->type != FILE_PSTRING) + goto bad; + SET_LENGTH(PSTRING_2_LE); + break; + case CHAR_PSTRING_4_BE: + if (m->type != FILE_PSTRING) + goto bad; + SET_LENGTH(PSTRING_4_BE); + break; + case CHAR_PSTRING_4_LE: + switch (m->type) { + case FILE_PSTRING: + case FILE_REGEX: + break; + default: + goto bad; + } + SET_LENGTH(PSTRING_4_LE); + break; + case CHAR_PSTRING_LENGTH_INCLUDES_ITSELF: + if (m->type != FILE_PSTRING) + goto bad; + m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF; + break; + default: + bad: + if (ms->flags & MAGIC_CHECK) + file_magwarn(ms, "string modifier `%c' " + "invalid", *l); + goto out; + } + /* allow multiple '/' for readability */ + if (l[1] == '/' && !isspace((unsigned char)l[2])) + l++; + } + if (string_modifier_check(ms, m) == -1) + goto out; + *lp = l; + return 0; +out: + *lp = l; + return -1; +} + /* * parse one line from magic file, put into magic[index++] if valid */ @@ -1749,7 +1962,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line, */ m->type = get_standard_integer_type(l, &l); } - // It's unsigned. + /* It's unsigned. */ if (m->type != FILE_INVALID) m->flag |= UNSIGNED; } else { @@ -1800,113 +2013,27 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line, m->str_range = 0; m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0; if ((op = get_op(*l)) != -1) { - if (!IS_STRING(m->type)) { - uint64_t val; - ++l; - m->mask_op |= op; - val = (uint64_t)strtoull(l, &t, 0); - l = t; - m->num_mask = file_signextend(ms, m, val); - eatsize(&l); - } - else if (op == FILE_OPDIVIDE) { - int have_range = 0; - while (!isspace((unsigned char)*++l)) { - switch (*l) { - case '0': case '1': case '2': - case '3': case '4': case '5': - case '6': case '7': case '8': - case '9': - if (have_range && - (ms->flags & MAGIC_CHECK)) - file_magwarn(ms, - "multiple ranges"); - have_range = 1; - m->str_range = CAST(uint32_t, - strtoul(l, &t, 0)); - if (m->str_range == 0) - file_magwarn(ms, - "zero range"); - l = t - 1; - break; - case CHAR_COMPACT_WHITESPACE: - m->str_flags |= - STRING_COMPACT_WHITESPACE; - break; - case CHAR_COMPACT_OPTIONAL_WHITESPACE: - m->str_flags |= - STRING_COMPACT_OPTIONAL_WHITESPACE; - break; - case CHAR_IGNORE_LOWERCASE: - m->str_flags |= STRING_IGNORE_LOWERCASE; - break; - case CHAR_IGNORE_UPPERCASE: - m->str_flags |= STRING_IGNORE_UPPERCASE; - break; - case CHAR_REGEX_OFFSET_START: - m->str_flags |= REGEX_OFFSET_START; - break; - case CHAR_BINTEST: - m->str_flags |= STRING_BINTEST; - break; - case CHAR_TEXTTEST: - m->str_flags |= STRING_TEXTTEST; - break; - case CHAR_TRIM: - m->str_flags |= STRING_TRIM; - break; - case CHAR_PSTRING_1_LE: - if (m->type != FILE_PSTRING) - goto bad; - m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_1_LE; - break; - case CHAR_PSTRING_2_BE: - if (m->type != FILE_PSTRING) - goto bad; - m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_BE; - break; - case CHAR_PSTRING_2_LE: - if (m->type != FILE_PSTRING) - goto bad; - m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_LE; - break; - case CHAR_PSTRING_4_BE: - if (m->type != FILE_PSTRING) - goto bad; - m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_BE; - break; - case CHAR_PSTRING_4_LE: - if (m->type != FILE_PSTRING) - goto bad; - m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_LE; - break; - case CHAR_PSTRING_LENGTH_INCLUDES_ITSELF: - if (m->type != FILE_PSTRING) - goto bad; - m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF; - break; - default: - bad: - if (ms->flags & MAGIC_CHECK) - file_magwarn(ms, - "string extension `%c' " - "invalid", *l); - return -1; - } - /* allow multiple '/' for readability */ - if (l[1] == '/' && - !isspace((unsigned char)l[2])) - l++; + if (IS_STRING(m->type)) { + int r; + + if (op != FILE_OPDIVIDE) { + if (ms->flags & MAGIC_CHECK) + file_magwarn(ms, + "invalid string/indirect op: " + "`%c'", *t); + return -1; } - if (string_modifier_check(ms, m) == -1) + + if (m->type == FILE_INDIRECT) + r = parse_indirect_modifier(ms, m, &l); + else + r = parse_string_modifier(ms, m, &l); + if (r == -1) return -1; - } - else { - if (ms->flags & MAGIC_CHECK) - file_magwarn(ms, "invalid string op: %c", *t); - return -1; - } + } else + parse_op_modifier(ms, m, &l, op); } + /* * We used to set mask to all 1's here, instead let's just not do * anything if mask = 0 (unless you have a better idea) @@ -2059,9 +2186,15 @@ out: return -1; } +private int +goodchar(unsigned char x, const char *extra) +{ + return (isascii(x) && isalnum(x)) || strchr(extra, x); +} + private int parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, - off_t off, size_t len, const char *name, int nt) + off_t off, size_t len, const char *name, const char *extra, int nt) { size_t i; const char *l = line; @@ -2082,9 +2215,7 @@ parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, } EATAB; - for (i = 0; *l && ((isascii((unsigned char)*l) && - isalnum((unsigned char)*l)) || strchr("-+/.", *l)) && - i < len; buf[i++] = *l++) + for (i = 0; *l && i < len && goodchar(*l, extra); buf[i++] = *l++) continue; if (i == len && *l) { @@ -2094,14 +2225,18 @@ parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, file_magwarn(ms, "%s type `%s' truncated %" SIZE_T_FORMAT "u", name, line, i); } else { + if (!isspace((unsigned char)*l) && !goodchar(*l, extra)) + file_magwarn(ms, "%s type `%s' has bad char '%c'", + name, line, *l); if (nt) buf[i] = '\0'; } if (i > 0) return 0; - else - return -1; + + file_magerror(ms, "Bad magic entry '%s'", line); + return -1; } /* @@ -2114,7 +2249,7 @@ parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line) struct magic *m = &me->mp[0]; return parse_extra(ms, me, line, offsetof(struct magic, apple), - sizeof(m->apple), "APPLE", 0); + sizeof(m->apple), "APPLE", "!+-./", 0); } /* @@ -2127,23 +2262,47 @@ parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line) struct magic *m = &me->mp[0]; return parse_extra(ms, me, line, offsetof(struct magic, mimetype), - sizeof(m->mimetype), "MIME", 1); + sizeof(m->mimetype), "MIME", "+-/.", 1); } private int check_format_type(const char *ptr, int type) { - int quad = 0; + int quad = 0, h; if (*ptr == '\0') { /* Missing format string; bad */ return -1; } - switch (type) { + switch (file_formats[type]) { case FILE_FMT_QUAD: quad = 1; /*FALLTHROUGH*/ case FILE_FMT_NUM: + if (quad == 0) { + switch (type) { + case FILE_BYTE: + h = 2; + break; + case FILE_SHORT: + case FILE_BESHORT: + case FILE_LESHORT: + h = 1; + break; + case FILE_LONG: + case FILE_BELONG: + case FILE_LELONG: + case FILE_MELONG: + case FILE_LEID3: + case FILE_BEID3: + case FILE_INDIRECT: + h = 0; + break; + default: + abort(); + } + } else + h = 0; if (*ptr == '-') ptr++; if (*ptr == '.') @@ -2160,6 +2319,8 @@ check_format_type(const char *ptr, int type) } switch (*ptr++) { +#ifdef STRICT_FORMAT /* "long" formats are int formats for us */ + /* so don't accept the 'l' modifier */ case 'l': switch (*ptr++) { case 'i': @@ -2168,14 +2329,22 @@ check_format_type(const char *ptr, int type) case 'o': case 'x': case 'X': - return 0; + return h != 0 ? -1 : 0; default: return -1; } + /* + * Don't accept h and hh modifiers. They make writing + * magic entries more complicated, for very little benefit + */ case 'h': + if (h-- <= 0) + return -1; switch (*ptr++) { case 'h': + if (h-- <= 0) + return -1; switch (*ptr++) { case 'i': case 'd': @@ -2187,21 +2356,30 @@ check_format_type(const char *ptr, int type) default: return -1; } + case 'i': case 'd': - return 0; + case 'u': + case 'o': + case 'x': + case 'X': + return h != 0 ? -1 : 0; default: return -1; } - - case 'i': +#endif case 'c': + return h != 2 ? -1 : 0; + case 'i': case 'd': case 'u': case 'o': case 'x': case 'X': +#ifdef STRICT_FORMAT + return h != 0 ? -1 : 0; +#else return 0; - +#endif default: return -1; } @@ -2288,7 +2466,7 @@ check_format(struct magic_set *ms, struct magic *m) } ptr++; - if (check_format_type(ptr, file_formats[m->type]) == -1) { + if (check_format_type(ptr, m->type) == -1) { /* * TODO: this error message is unhelpful if the format * string is not one character long @@ -2335,6 +2513,16 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) m->value.s); return -1; } + 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); + } + file_regfree(&rx); + return rc ? -1 : 0; + } return 0; case FILE_FLOAT: case FILE_BEFLOAT: @@ -2634,6 +2822,28 @@ eatsize(const char **p) *p = l; } +/* + * handle a buffer containing a compiled file. + */ +private struct magic_map * +apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len) +{ + struct magic_map *map; + + if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) { + file_oomem(ms, sizeof(*map)); + return NULL; + } + map->len = len; + map->p = buf; + map->type = MAP_TYPE_USER; + if (check_buffer(ms, map, "buffer") != 0) { + apprentice_unmap(map); + return NULL; + } + return map; +} + /* * handle a compiled file. */ @@ -2643,12 +2853,8 @@ apprentice_map(struct magic_set *ms, const char *fn) { int fd; struct stat st; - uint32_t *ptr; - uint32_t version, entries, nentries; - int needsbyteswap; char *dbname = NULL; struct magic_map *map; - size_t i; fd = -1; if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) { @@ -2680,6 +2886,7 @@ apprentice_map(struct magic_set *ms, const char *fn) file_error(ms, errno, "cannot map `%s'", dbname); goto error; } + map->type = MAP_TYPE_MMAP; #else if ((map->p = CAST(void *, malloc(map->len))) == NULL) { file_oomem(ms, map->len); @@ -2689,16 +2896,39 @@ apprentice_map(struct magic_set *ms, const char *fn) file_badread(ms); goto error; } - map->len = 0; + map->type = MAP_TYPE_MALLOC; #define RET 1 #endif (void)close(fd); fd = -1; + + if (check_buffer(ms, map, dbname) != 0) + goto error; + + free(dbname); + return map; + +error: + if (fd != -1) + (void)close(fd); + apprentice_unmap(map); + free(dbname); + return NULL; +} + +private int +check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) +{ + uint32_t *ptr; + uint32_t entries, nentries; + uint32_t version; + int i, needsbyteswap; + ptr = CAST(uint32_t *, map->p); if (*ptr != MAGICNO) { if (swap4(*ptr) != MAGICNO) { file_error(ms, 0, "bad magic in `%s'", dbname); - goto error; + return -1; } needsbyteswap = 1; } else @@ -2711,14 +2941,14 @@ apprentice_map(struct magic_set *ms, const char *fn) file_error(ms, 0, "File %s supports only version %d magic " "files. `%s' is version %d", VERSION, VERSIONNO, dbname, version); - goto error; + return -1; } - entries = (uint32_t)(st.st_size / sizeof(struct magic)); - if ((off_t)(entries * sizeof(struct magic)) != st.st_size) { - file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu", - dbname, (unsigned long long)st.st_size, - sizeof(struct magic)); - goto error; + entries = (uint32_t)(map->len / sizeof(struct magic)); + if ((entries * sizeof(struct magic)) != map->len) { + file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not " + "a multiple of %" SIZE_T_FORMAT "u", + dbname, map->len, sizeof(struct magic)); + return -1; } map->magic[0] = CAST(struct magic *, map->p) + 1; nentries = 0; @@ -2734,26 +2964,14 @@ apprentice_map(struct magic_set *ms, const char *fn) if (entries != nentries + 1) { file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", dbname, entries, nentries + 1); - goto error; + return -1; } if (needsbyteswap) for (i = 0; i < MAGIC_SETS; i++) byteswap(map->magic[i], map->nmagic[i]); - free(dbname); - return map; - -error: - if (fd != -1) - (void)close(fd); - apprentice_unmap(map); - free(dbname); - return NULL; + return 0; } -private const uint32_t ar[] = { - MAGICNO, VERSIONNO -}; - /* * handle an mmaped file. */ @@ -2767,6 +2985,10 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) char *dbname; int rv = -1; uint32_t i; + union { + struct magic m; + uint32_t h[2 + MAGIC_SETS]; + } hdr; dbname = mkdbname(ms, fn, 1); @@ -2778,24 +3000,16 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) file_error(ms, errno, "cannot open `%s'", dbname); goto out; } + memset(&hdr, 0, sizeof(hdr)); + hdr.h[0] = MAGICNO; + hdr.h[1] = VERSIONNO; + memcpy(hdr.h + 2, map->nmagic, nm); - if (write(fd, ar, sizeof(ar)) != (ssize_t)sizeof(ar)) { + if (write(fd, &hdr, sizeof(hdr)) != (ssize_t)sizeof(hdr)) { file_error(ms, errno, "error writing `%s'", dbname); goto out; } - if (write(fd, map->nmagic, nm) != (ssize_t)nm) { - file_error(ms, errno, "error writing `%s'", dbname); - goto out; - } - - assert(nm + sizeof(ar) < m); - - if (lseek(fd, (off_t)m, SEEK_SET) != (off_t)m) { - file_error(ms, errno, "error seeking `%s'", dbname); - goto out; - } - for (i = 0; i < MAGIC_SETS; i++) { len = m * map->nmagic[i]; if (write(fd, map->magic[i], len) != (ssize_t)len) { diff --git a/contrib/file/src/ascmagic.c b/contrib/file/src/ascmagic.c index ca26665568..78a6dbb7c8 100644 --- a/contrib/file/src/ascmagic.c +++ b/contrib/file/src/ascmagic.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: ascmagic.c,v 1.88 2014/02/12 23:20:53 christos Exp $") +FILE_RCSID("@(#)$File: ascmagic.c,v 1.91 2014/11/28 02:46:39 christos Exp $") #endif /* lint */ #include "magic.h" @@ -147,7 +147,8 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf, == NULL) goto done; if ((rv = file_softmagic(ms, utf8_buf, - (size_t)(utf8_end - utf8_buf), 0, TEXTTEST, text)) == 0) + (size_t)(utf8_end - utf8_buf), 0, NULL, + TEXTTEST, text)) == 0) rv = -1; } diff --git a/contrib/file/src/cdf.c b/contrib/file/src/cdf.c index a50e84232e..9e3cf9fd2c 100644 --- a/contrib/file/src/cdf.c +++ b/contrib/file/src/cdf.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: cdf.c,v 1.55 2014/02/27 23:26:17 christos Exp $") +FILE_RCSID("@(#)$File: cdf.c,v 1.69 2014/12/04 15:56:46 christos Exp $") #endif #include @@ -73,6 +73,8 @@ static union { #define CDF_TOLE8(x) ((uint64_t)(NEED_SWAP ? _cdf_tole8(x) : (uint64_t)(x))) #define CDF_TOLE4(x) ((uint32_t)(NEED_SWAP ? _cdf_tole4(x) : (uint32_t)(x))) #define CDF_TOLE2(x) ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x))) +#define CDF_TOLE(x) (sizeof(x) == 2 ? CDF_TOLE2(x) : (sizeof(x) == 4 ? \ + CDF_TOLE4(x) : CDF_TOLE8(x))) #define CDF_GETUINT32(x, y) cdf_getuint32(x, y) @@ -267,13 +269,15 @@ cdf_check_stream_offset(const cdf_stream_t *sst, const cdf_header_t *h, { const char *b = (const char *)sst->sst_tab; const char *e = ((const char *)p) + tail; + size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ? + CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h); (void)&line; - if (e >= b && (size_t)(e - b) <= CDF_SEC_SIZE(h) * sst->sst_len) + if (e >= b && (size_t)(e - b) <= ss * sst->sst_len) return 0; DPRINTF(("%d: offset begin %p < end %p || %" SIZE_T_FORMAT "u" " > %" SIZE_T_FORMAT "u [%" SIZE_T_FORMAT "u %" SIZE_T_FORMAT "u]\n", line, b, e, (size_t)(e - b), - CDF_SEC_SIZE(h) * sst->sst_len, CDF_SEC_SIZE(h), sst->sst_len)); + ss * sst->sst_len, ss, sst->sst_len)); errno = EFTYPE; return -1; } @@ -352,10 +356,10 @@ cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs, size_t ss = CDF_SHORT_SEC_SIZE(h); size_t pos = CDF_SHORT_SEC_POS(h, id); assert(ss == len); - if (pos > CDF_SEC_SIZE(h) * sst->sst_len) { + if (pos + len > CDF_SEC_SIZE(h) * sst->sst_len) { DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", - pos, CDF_SEC_SIZE(h) * sst->sst_len)); + pos + len, CDF_SEC_SIZE(h) * sst->sst_len)); return -1; } (void)memcpy(((char *)buf) + offs, @@ -455,9 +459,16 @@ size_t cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size) { size_t i, j; - cdf_secid_t maxsector = (cdf_secid_t)(sat->sat_len * size); + cdf_secid_t maxsector = (cdf_secid_t)((sat->sat_len * size) + / sizeof(maxsector)); DPRINTF(("Chain:")); + if (sid == CDF_SECID_END_OF_CHAIN) { + /* 0-length chain. */ + DPRINTF((" empty\n")); + return 0; + } + for (j = i = 0; sid >= 0; i++, j++) { DPRINTF((" %d", sid)); if (j >= CDF_LOOP_LIMIT) { @@ -465,13 +476,18 @@ cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size) errno = EFTYPE; return (size_t)-1; } - if (sid > maxsector) { - DPRINTF(("Sector %d > %d\n", sid, maxsector)); + if (sid >= maxsector) { + DPRINTF(("Sector %d >= %d\n", sid, maxsector)); errno = EFTYPE; return (size_t)-1; } sid = CDF_TOLE4((uint32_t)sat->sat_tab[sid]); } + if (i == 0) { + DPRINTF((" none, sid: %d\n", sid)); + return (size_t)-1; + + } DPRINTF(("\n")); return i; } @@ -718,19 +734,28 @@ int cdf_read_summary_info(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, cdf_stream_t *scn) +{ + return cdf_read_user_stream(info, h, sat, ssat, sst, dir, + "\05SummaryInformation", scn); +} + +int +cdf_read_user_stream(const cdf_info_t *info, const cdf_header_t *h, + const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, + const cdf_dir_t *dir, const char *name, cdf_stream_t *scn) { size_t i; const cdf_directory_t *d; - static const char name[] = "\05SummaryInformation"; + size_t name_len = strlen(name) + 1; for (i = dir->dir_len; i > 0; i--) if (dir->dir_tab[i - 1].d_type == CDF_DIR_TYPE_USER_STREAM && - cdf_namecmp(name, dir->dir_tab[i - 1].d_name, sizeof(name)) + cdf_namecmp(name, dir->dir_tab[i - 1].d_name, name_len) == 0) break; if (i == 0) { - DPRINTF(("Cannot find summary information section\n")); + DPRINTF(("Cannot find user stream `%s'\n", name)); errno = ESRCH; return -1; } @@ -799,10 +824,19 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h, if (cdf_check_stream_offset(sst, h, e, 0, __LINE__) == -1) goto out; for (i = 0; i < sh.sh_properties; i++) { - size_t ofs = CDF_GETUINT32(p, (i << 1) + 1); + size_t tail = (i << 1) + 1; + size_t ofs; + if (cdf_check_stream_offset(sst, h, p, tail * sizeof(uint32_t), + __LINE__) == -1) + goto out; + ofs = CDF_GETUINT32(p, tail); q = (const uint8_t *)(const void *) ((const char *)(const void *)p + ofs - 2 * sizeof(uint32_t)); + if (q < p) { + DPRINTF(("Wrapped around %p < %p\n", q, p)); + goto out; + } if (q > e) { DPRINTF(("Ran of the end %p > %p\n", q, e)); goto out; @@ -813,6 +847,10 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h, i, inp[i].pi_id, inp[i].pi_type, q - p, offs)); if (inp[i].pi_type & CDF_VECTOR) { nelements = CDF_GETUINT32(q, 1); + if (nelements == 0) { + DPRINTF(("CDF_VECTOR with nelements == 0\n")); + goto out; + } o = 2; } else { nelements = 1; @@ -887,7 +925,9 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h, } DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n", nelements)); - for (j = 0; j < nelements; j++, i++) { + for (j = 0; j < nelements && i < sh.sh_properties; + j++, i++) + { uint32_t l = CDF_GETUINT32(q, o); inp[i].pi_str.s_len = l; inp[i].pi_str.s_buf = (const char *) @@ -932,7 +972,7 @@ int cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h, cdf_summary_info_header_t *ssi, cdf_property_info_t **info, size_t *count) { - size_t i, maxcount; + size_t maxcount; const cdf_summary_info_header_t *si = CAST(const cdf_summary_info_header_t *, sst->sst_tab); const cdf_section_declaration_t *sd = @@ -947,25 +987,65 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h, ssi->si_os = CDF_TOLE2(si->si_os); ssi->si_class = si->si_class; cdf_swap_class(&ssi->si_class); - ssi->si_count = CDF_TOLE2(si->si_count); + ssi->si_count = CDF_TOLE4(si->si_count); *count = 0; maxcount = 0; *info = NULL; - for (i = 0; i < CDF_TOLE4(si->si_count); i++) { - if (i >= CDF_LOOP_LIMIT) { - DPRINTF(("Unpack summary info loop limit")); - errno = EFTYPE; - return -1; - } - if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset), - info, count, &maxcount) == -1) { - return -1; - } - } + if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset), info, + count, &maxcount) == -1) + return -1; return 0; } +#define extract_catalog_field(f, l) \ + memcpy(&ce[i].f, b + (l), sizeof(ce[i].f)); \ + ce[i].f = CDF_TOLE(ce[i].f) + +int +cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst, + cdf_catalog_t **cat) +{ + size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ? + CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h); + const char *b = CAST(const char *, sst->sst_tab); + const char *eb = b + ss * sst->sst_len; + size_t nr, i, k; + cdf_catalog_entry_t *ce; + uint16_t reclen; + const uint16_t *np; + + for (nr = 0; b < eb; nr++) { + memcpy(&reclen, b, sizeof(reclen)); + reclen = CDF_TOLE2(reclen); + if (reclen == 0) + break; + b += reclen; + } + *cat = CAST(cdf_catalog_t *, + malloc(sizeof(cdf_catalog_t) + nr * sizeof(*ce))); + (*cat)->cat_num = nr; + ce = (*cat)->cat_e; + b = CAST(const char *, sst->sst_tab); + for (i = 0; i < nr; i++) { + extract_catalog_field(ce_namlen, 0); + extract_catalog_field(ce_num, 2); + extract_catalog_field(ce_timestamp, 6); + reclen = ce[i].ce_namlen; + ce[i].ce_namlen = + sizeof(ce[i].ce_name) / sizeof(ce[i].ce_name[0]) - 1; + if (ce[i].ce_namlen > reclen - 14) + ce[i].ce_namlen = reclen - 14; + np = CAST(const uint16_t *, (b + 16)); + for (k = 0; k < ce[i].ce_namlen; k++) { + ce[i].ce_name[k] = np[k]; + CDF_TOLE2(ce[i].ce_name[k]); + } + ce[i].ce_name[ce[i].ce_namlen] = 0; + b += reclen; + } + return 0; +} int cdf_print_classid(char *buf, size_t buflen, const cdf_classid_t *id) @@ -1049,6 +1129,15 @@ cdf_print_elapsed_time(char *buf, size_t bufsiz, cdf_timestamp_t ts) return len; } +char * +cdf_u16tos8(char *buf, size_t len, const uint16_t *p) +{ + size_t i; + for (i = 0; i < len && p[i]; i++) + buf[i] = (char)p[i]; + buf[i] = '\0'; + return buf; +} #ifdef CDF_DEBUG void @@ -1074,7 +1163,7 @@ cdf_dump_header(const cdf_header_t *h) for (i = 0; i < __arraycount(h->h_master_sat); i++) { if (h->h_master_sat[i] == CDF_SECID_FREE) break; - (void)fprintf(stderr, "%35.35s[%.3zu] = %d\n", + (void)fprintf(stderr, "%35.35s[%.3" SIZE_T_FORMAT "u] = %d\n", "master_sat", i, h->h_master_sat[i]); } } @@ -1269,7 +1358,7 @@ cdf_dump_summary_info(const cdf_header_t *h, const cdf_stream_t *sst) return; (void)fprintf(stderr, "Endian: %x\n", ssi.si_byte_order); (void)fprintf(stderr, "Os Version %d.%d\n", ssi.si_os_version & 0xff, - ssi.si_os_version >> 8); + ssi.si_os_version >> 8); (void)fprintf(stderr, "Os %d\n", ssi.si_os); cdf_print_classid(buf, sizeof(buf), &ssi.si_class); (void)fprintf(stderr, "Class %s\n", buf); @@ -1278,6 +1367,27 @@ cdf_dump_summary_info(const cdf_header_t *h, const cdf_stream_t *sst) free(info); } + +void +cdf_dump_catalog(const cdf_header_t *h, const cdf_stream_t *sst) +{ + cdf_catalog_t *cat; + cdf_unpack_catalog(h, sst, &cat); + const cdf_catalog_entry_t *ce = cat->cat_e; + struct timespec ts; + char tbuf[64], sbuf[256]; + size_t i; + + printf("Catalog:\n"); + for (i = 0; i < cat->cat_num; i++) { + cdf_timestamp_to_timespec(&ts, ce[i].ce_timestamp); + printf("\t%d %s %s", ce[i].ce_num, + cdf_u16tos8(sbuf, ce[i].ce_namlen, ce[i].ce_name), + cdf_ctime(&ts.tv_sec, tbuf)); + } + free(cat); +} + #endif #ifdef TEST @@ -1290,6 +1400,7 @@ main(int argc, char *argv[]) cdf_stream_t sst, scn; cdf_dir_t dir; cdf_info_t info; + const cdf_directory_t *root; if (argc < 2) { (void)fprintf(stderr, "Usage: %s \n", getprogname()); @@ -1323,7 +1434,8 @@ main(int argc, char *argv[]) if (cdf_read_dir(&info, &h, &sat, &dir) == -1) err(1, "Cannot read dir"); - if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst) == -1) + if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst, &root) + == -1) err(1, "Cannot read short stream"); #ifdef CDF_DEBUG cdf_dump_stream(&h, &sst); @@ -1336,9 +1448,17 @@ main(int argc, char *argv[]) if (cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir, &scn) == -1) - err(1, "Cannot read summary info"); + warn("Cannot read summary info"); +#ifdef CDF_DEBUG + else + cdf_dump_summary_info(&h, &scn); +#endif + if (cdf_read_catalog(&info, &h, &sat, &ssat, &sst, &dir, + &scn) == -1) + warn("Cannot read catalog"); #ifdef CDF_DEBUG - cdf_dump_summary_info(&h, &scn); + else + cdf_dump_catalog(&h, &scn); #endif (void)close(info.i_fd); diff --git a/contrib/file/src/cdf.h b/contrib/file/src/cdf.h index 177868eb55..64e3648ca1 100644 --- a/contrib/file/src/cdf.h +++ b/contrib/file/src/cdf.h @@ -267,6 +267,19 @@ typedef struct { size_t i_len; } cdf_info_t; + +typedef struct { + uint16_t ce_namlen; + uint32_t ce_num; + uint64_t ce_timestamp; + uint16_t ce_name[256]; +} cdf_catalog_entry_t; + +typedef struct { + size_t cat_num; + cdf_catalog_entry_t cat_e[0]; +} cdf_catalog_t; + struct timespec; int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t); int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *); @@ -298,11 +311,22 @@ int cdf_read_short_stream(const cdf_info_t *, const cdf_header_t *, const cdf_directory_t **); int cdf_read_property_info(const cdf_stream_t *, const cdf_header_t *, uint32_t, cdf_property_info_t **, size_t *, size_t *); +int cdf_read_user_stream(const cdf_info_t *, const cdf_header_t *, + const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, + const cdf_dir_t *, const char *, cdf_stream_t *); +#define cdf_read_catalog(info, header, sat, ssat, stream, dir, scn) \ + cdf_read_user_stream(info, header, sat, ssat, stream, dir, "Catalog", \ + scn) +#define cdf_read_encrypted_package(info, header, sat, ssat, stream, dir, scn) \ + cdf_read_user_stream(info, header, sat, ssat, stream, dir, \ + "EncryptedPackage", scn) int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, const cdf_dir_t *, cdf_stream_t *); int cdf_unpack_summary_info(const cdf_stream_t *, const cdf_header_t *, cdf_summary_info_header_t *, cdf_property_info_t **, size_t *); +int cdf_unpack_catalog(const cdf_header_t *, const cdf_stream_t *, + cdf_catalog_t **); int cdf_print_classid(char *, size_t, const cdf_classid_t *); int cdf_print_property_name(char *, size_t, uint32_t); int cdf_print_elapsed_time(char *, size_t, cdf_timestamp_t); @@ -310,6 +334,7 @@ uint16_t cdf_tole2(uint16_t); uint32_t cdf_tole4(uint32_t); uint64_t cdf_tole8(uint64_t); char *cdf_ctime(const time_t *, char *); +char *cdf_u16tos8(char *, size_t, const uint16_t *); #ifdef CDF_DEBUG void cdf_dump_header(const cdf_header_t *); @@ -320,6 +345,7 @@ void cdf_dump_dir(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, const cdf_dir_t *); void cdf_dump_property_info(const cdf_property_info_t *, size_t); void cdf_dump_summary_info(const cdf_header_t *, const cdf_stream_t *); +void cdf_dump_catalog(const cdf_header_t *, const cdf_stream_t *); #endif diff --git a/contrib/file/src/cdf_time.c b/contrib/file/src/cdf_time.c index e18bc9c610..1e572de539 100644 --- a/contrib/file/src/cdf_time.c +++ b/contrib/file/src/cdf_time.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: cdf_time.c,v 1.13 2014/02/25 20:52:02 christos Exp $") +FILE_RCSID("@(#)$File: cdf_time.c,v 1.15 2014/05/14 23:15:42 christos Exp $") #endif #include @@ -117,7 +117,7 @@ cdf_timestamp_to_timespec(struct timespec *ts, cdf_timestamp_t t) tm.tm_hour = (int)(t % 24); t /= 24; - // XXX: Approx + /* XXX: Approx */ tm.tm_year = (int)(CDF_BASE_YEAR + (t / 365)); rdays = cdf_getdays(tm.tm_year); @@ -171,7 +171,8 @@ cdf_ctime(const time_t *sec, char *buf) char *ptr = ctime_r(sec, buf); if (ptr != NULL) return buf; - (void)snprintf(buf, 26, "*Bad* 0x%16.16llx\n", (long long)*sec); + (void)snprintf(buf, 26, "*Bad* 0x%16.16" INT64_T_FORMAT "x\n", + (long long)*sec); return buf; } diff --git a/contrib/file/src/compress.c b/contrib/file/src/compress.c index 45251b1d40..e968bb4528 100644 --- a/contrib/file/src/compress.c +++ b/contrib/file/src/compress.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.77 2014/12/12 16:33:01 christos Exp $") #endif #include "magic.h" @@ -45,7 +45,8 @@ FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $") #endif #include #include -#ifndef __MINGW32__ +#include +#if !defined(__MINGW32__) && !defined(WIN32) #include #endif #ifdef HAVE_SYS_WAIT_H @@ -103,10 +104,12 @@ file_zmagic(struct magic_set *ms, int fd, const char *name, size_t i, nsz; int rv = 0; int mime = ms->flags & MAGIC_MIME; + sig_t osigpipe; if ((ms->flags & MAGIC_COMPRESS) == 0) return 0; + osigpipe = signal(SIGPIPE, SIG_IGN); for (i = 0; i < ncompr; i++) { if (nbytes < compr[i].maglen) continue; @@ -133,6 +136,7 @@ file_zmagic(struct magic_set *ms, int fd, const char *name, } } error: + (void)signal(SIGPIPE, osigpipe); free(newbuf); ms->flags |= MAGIC_COMPRESS; return rv; @@ -377,6 +381,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method, const unsigned char *old, unsigned char **newch, size_t n) { int fdin[2], fdout[2]; + int status; ssize_t r; pid_t pid; @@ -459,7 +464,17 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method, /*NOTREACHED*/ default: /* parent */ - break; + if (wait(&status) == -1) { +#ifdef DEBUG + (void)fprintf(stderr, + "Wait failed (%s)\n", + strerror(errno)); +#endif + exit(1); + } + exit(WIFEXITED(status) ? + WEXITSTATUS(status) : 1); + /*NOTREACHED*/ } (void) close(fdin[1]); fdin[1] = -1; @@ -470,7 +485,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method, (void)fprintf(stderr, "Malloc failed (%s)\n", strerror(errno)); #endif - n = 0; + n = NODATA; goto err; } if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) { @@ -479,7 +494,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method, strerror(errno)); #endif free(*newch); - n = 0; + n = NODATA; *newch = NULL; goto err; } else { @@ -491,12 +506,24 @@ err: if (fdin[1] != -1) (void) close(fdin[1]); (void) close(fdout[0]); -#ifdef WNOHANG - while (waitpid(pid, NULL, WNOHANG) != -1) - continue; -#else - (void)wait(NULL); + if (wait(&status) == -1) { +#ifdef DEBUG + (void)fprintf(stderr, "Wait failed (%s)\n", + strerror(errno)); +#endif + n = NODATA; + } else if (!WIFEXITED(status)) { +#ifdef DEBUG + (void)fprintf(stderr, "Child not exited (0x%x)\n", + status); #endif + } else if (WEXITSTATUS(status) != 0) { +#ifdef DEBUG + (void)fprintf(stderr, "Child exited (0x%d)\n", + WEXITSTATUS(status)); +#endif + } + (void) close(fdin[0]); return n; diff --git a/contrib/file/src/elfclass.h b/contrib/file/src/elfclass.h index 010958a429..5360b0b55a 100644 --- a/contrib/file/src/elfclass.h +++ b/contrib/file/src/elfclass.h @@ -32,39 +32,51 @@ swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA]; type = elf_getu16(swap, elfhdr.e_type); + notecount = ms->elf_notes_max; switch (type) { #ifdef ELFCORE case ET_CORE: + phnum = elf_getu16(swap, elfhdr.e_phnum); + if (phnum > ms->elf_phnum_max) + return toomany(ms, "program headers", phnum); flags |= FLAGS_IS_CORE; if (dophn_core(ms, clazz, swap, fd, - (off_t)elf_getu(swap, elfhdr.e_phoff), - elf_getu16(swap, elfhdr.e_phnum), + (off_t)elf_getu(swap, elfhdr.e_phoff), phnum, (size_t)elf_getu16(swap, elfhdr.e_phentsize), - fsize, &flags) == -1) + fsize, &flags, ¬ecount) == -1) return -1; break; #endif case ET_EXEC: case ET_DYN: + phnum = elf_getu16(swap, elfhdr.e_phnum); + if (phnum > ms->elf_phnum_max) + return toomany(ms, "program", phnum); + shnum = elf_getu16(swap, elfhdr.e_shnum); + if (shnum > ms->elf_shnum_max) + return toomany(ms, "section", shnum); if (dophn_exec(ms, clazz, swap, fd, - (off_t)elf_getu(swap, elfhdr.e_phoff), - elf_getu16(swap, elfhdr.e_phnum), + (off_t)elf_getu(swap, elfhdr.e_phoff), phnum, (size_t)elf_getu16(swap, elfhdr.e_phentsize), - fsize, &flags, elf_getu16(swap, elfhdr.e_shnum)) - == -1) + fsize, shnum, &flags, ¬ecount) == -1) return -1; /*FALLTHROUGH*/ case ET_REL: + shnum = elf_getu16(swap, elfhdr.e_shnum); + if (shnum > ms->elf_shnum_max) + return toomany(ms, "section headers", shnum); if (doshn(ms, clazz, swap, fd, - (off_t)elf_getu(swap, elfhdr.e_shoff), - elf_getu16(swap, elfhdr.e_shnum), + (off_t)elf_getu(swap, elfhdr.e_shoff), shnum, (size_t)elf_getu16(swap, elfhdr.e_shentsize), - fsize, &flags, elf_getu16(swap, elfhdr.e_machine), - (int)elf_getu16(swap, elfhdr.e_shstrndx)) == -1) + fsize, elf_getu16(swap, elfhdr.e_machine), + (int)elf_getu16(swap, elfhdr.e_shstrndx), + &flags, ¬ecount) == -1) return -1; break; default: break; } + if (notecount == 0) + return toomany(ms, "notes", ms->elf_notes_max); return 1; diff --git a/contrib/file/src/encoding.c b/contrib/file/src/encoding.c index b75e0ccb7f..c1b23cc0f3 100644 --- a/contrib/file/src/encoding.c +++ b/contrib/file/src/encoding.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: encoding.c,v 1.9 2013/11/19 20:45:50 christos Exp $") +FILE_RCSID("@(#)$File: encoding.c,v 1.10 2014/09/11 12:08:52 christos Exp $") #endif /* lint */ #include "magic.h" @@ -97,7 +97,6 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni *code_mime = "utf-8"; } else if (file_looks_utf8(buf, nbytes, *ubuf, ulen) > 1) { DPRINTF(("utf8 %" SIZE_T_FORMAT "u\n", *ulen)); - *code = "UTF-8 Unicode (with BOM)"; *code = "UTF-8 Unicode"; *code_mime = "utf-8"; } else if ((ucs_type = looks_ucs16(buf, nbytes, *ubuf, ulen)) != 0) { diff --git a/contrib/file/src/file.c b/contrib/file/src/file.c index 370da91462..546fd8bac6 100644 --- a/contrib/file/src/file.c +++ b/contrib/file/src/file.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: file.c,v 1.153 2014/02/11 15:41:04 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.160 2014/12/16 23:18:40 christos Exp $") #endif /* lint */ #include "magic.h" @@ -54,9 +54,6 @@ FILE_RCSID("@(#)$File: file.c,v 1.153 2014/02/11 15:41:04 christos Exp $") #ifdef HAVE_UNISTD_H #include /* for read() */ #endif -#ifdef HAVE_LOCALE_H -#include -#endif #ifdef HAVE_WCHAR_H #include #endif @@ -101,7 +98,7 @@ private const struct option long_options[] = { #undef OPT_LONGONLY {0, 0, NULL, 0} }; -#define OPTSTRING "bcCde:Ef:F:hiklLm:nNprsvz0" +#define OPTSTRING "bcCde:Ef:F:hiklLm:nNpP:rsvz0" private const struct { const char *name; @@ -119,6 +116,18 @@ private const struct { { "tokens", MAGIC_NO_CHECK_TOKENS }, /* OBSOLETE: ignored for backwards compatibility */ }; +private struct { + const char *name; + int tag; + size_t value; +} pm[] = { + { "indir", MAGIC_PARAM_INDIR_MAX, 0 }, + { "name", MAGIC_PARAM_NAME_MAX, 0 }, + { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0 }, + { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0 }, + { "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0 }, +}; + private char *progname; /* used throughout */ private void usage(void); @@ -128,6 +137,8 @@ private void help(void); private int unwrap(struct magic_set *, const char *); private int process(struct magic_set *ms, const char *, int); private struct magic_set *load(const char *, int); +private void setparam(const char *); +private void applyparam(magic_t); /* @@ -145,7 +156,9 @@ main(int argc, char *argv[]) const char *magicfile = NULL; /* where the magic is */ /* makes islower etc work for other langs */ +#ifdef HAVE_SETLOCALE (void)setlocale(LC_CTYPE, ""); +#endif #ifdef __EMX__ /* sh-like wildcard expansion! Shouldn't hurt at least ... */ @@ -243,9 +256,13 @@ main(int argc, char *argv[]) flags |= MAGIC_PRESERVE_ATIME; break; #endif + case 'P': + setparam(optarg); + break; case 'r': flags |= MAGIC_RAW; break; + break; case 's': flags |= MAGIC_DEVICES; break; @@ -298,6 +315,8 @@ main(int argc, char *argv[]) strerror(errno)); return 1; } + + switch(action) { case FILE_CHECK: c = magic_check(magic, magicfile); @@ -321,7 +340,7 @@ main(int argc, char *argv[]) if (magic == NULL) if ((magic = load(magicfile, flags)) == NULL) return 1; - break; + applyparam(magic); } if (optind == argc) { @@ -351,6 +370,41 @@ main(int argc, char *argv[]) return e; } +private void +applyparam(magic_t magic) +{ + size_t i; + + for (i = 0; i < __arraycount(pm); i++) { + if (pm[i].value == 0) + continue; + if (magic_setparam(magic, pm[i].tag, &pm[i].value) == -1) { + (void)fprintf(stderr, "%s: Can't set %s %s\n", progname, + pm[i].name, strerror(errno)); + exit(1); + } + } +} + +private void +setparam(const char *p) +{ + size_t i; + char *s; + + if ((s = strchr(p, '=')) == NULL) + goto badparm; + + for (i = 0; i < __arraycount(pm); i++) { + if (strncmp(p, pm[i].name, s - p) != 0) + continue; + pm[i].value = atoi(s + 1); + return; + } +badparm: + (void)fprintf(stderr, "%s: Unknown param %s\n", progname, p); + exit(1); +} private struct magic_set * /*ARGSUSED*/ diff --git a/contrib/file/src/file.h b/contrib/file/src/file.h index 5c67ddd78a..01aa37a6b9 100644 --- a/contrib/file/src/file.h +++ b/contrib/file/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.149 2014/03/15 21:47:40 christos Exp $ + * @(#)$File: file.h,v 1.164 2015/01/01 17:07:34 christos Exp $ */ #ifndef __file_h__ @@ -64,7 +64,9 @@ #include #include #include +#ifndef WIN32 #include +#endif /* Do this here and now, because struct stat gets re-defined on solaris */ #include #include @@ -83,7 +85,7 @@ #define private static -#if HAVE_VISIBILITY +#if HAVE_VISIBILITY && !defined(WIN32) #define public __attribute__ ((__visibility__("default"))) #ifndef protected #define protected __attribute__ ((__visibility__("hidden"))) @@ -133,7 +135,7 @@ #define MAXstring 64 /* max len of "string" types */ #define MAGICNO 0xF11E041C -#define VERSIONNO 11 +#define VERSIONNO 12 #define FILE_MAGICSIZE 248 #define FILE_LOAD 0 @@ -232,6 +234,7 @@ struct magic { (t) == FILE_LESTRING16 || \ (t) == FILE_REGEX || \ (t) == FILE_SEARCH || \ + (t) == FILE_INDIRECT || \ (t) == FILE_NAME || \ (t) == FILE_USE) @@ -321,6 +324,7 @@ struct magic { #define PSTRING_2_LE BIT(9) #define PSTRING_4_BE BIT(10) #define PSTRING_4_LE BIT(11) +#define REGEX_LINE_COUNT BIT(11) #define PSTRING_LEN \ (PSTRING_1_BE|PSTRING_2_LE|PSTRING_2_BE|PSTRING_4_LE|PSTRING_4_BE) #define PSTRING_LENGTH_INCLUDES_ITSELF BIT(12) @@ -343,6 +347,8 @@ struct magic { #define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE) #define STRING_DEFAULT_RANGE 100 +#define INDIRECT_RELATIVE BIT(0) +#define CHAR_INDIRECT_RELATIVE 'r' /* list of magic entries */ struct mlist { @@ -400,6 +406,16 @@ struct magic_set { /* FIXME: Make the string dynamically allocated so that e.g. strings matched in files can be longer than MAXstring */ union VALUETYPE ms_value; /* either number or string */ + uint16_t indir_max; + uint16_t name_max; + uint16_t elf_shnum_max; + uint16_t elf_phnum_max; + uint16_t elf_notes_max; +#define FILE_INDIR_MAX 15 +#define FILE_NAME_MAX 30 +#define FILE_ELF_SHNUM_MAX 32768 +#define FILE_ELF_PHNUM_MAX 128 +#define FILE_ELF_NOTES_MAX 256 }; /* Type for Unicode characters */ @@ -439,8 +455,10 @@ protected int file_encoding(struct magic_set *, const unsigned char *, size_t, unichar **, size_t *, const char **, const char **, const char **); protected int file_is_tar(struct magic_set *, const unsigned char *, size_t); protected int file_softmagic(struct magic_set *, const unsigned char *, size_t, - size_t, int, int); + uint16_t, uint16_t *, int, int); protected int file_apprentice(struct magic_set *, const char *, int); +protected int buffer_apprentice(struct magic_set *, struct magic **, + size_t *, size_t); protected int file_magicfind(struct magic_set *, const char *, struct mlist *); protected uint64_t file_signextend(struct magic_set *, struct magic *, uint64_t); @@ -463,11 +481,43 @@ protected int file_looks_utf8(const unsigned char *, size_t, unichar *, size_t *); protected size_t file_pstring_length_size(const struct magic *); protected size_t file_pstring_get_length(const struct magic *, const char *); +protected char * file_printable(char *, size_t, const char *); #ifdef __EMX__ protected int file_os2_apptype(struct magic_set *, const char *, const void *, size_t); #endif /* __EMX__ */ +#if defined(HAVE_LOCALE_H) +#include +#endif +#if defined(HAVE_XLOCALE_H) +#include +#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; +#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 *, + int); +protected void file_regfree(file_regex_t *); +protected void file_regerror(file_regex_t *, int, struct magic_set *); + +typedef struct { + char *buf; + uint32_t offset; +} file_pushbuf_t; + +protected file_pushbuf_t *file_push_buffer(struct magic_set *); +protected char *file_pop_buffer(struct magic_set *, file_pushbuf_t *); #ifndef COMPILE_ONLY extern const char *file_names[]; diff --git a/contrib/file/src/file_opts.h b/contrib/file/src/file_opts.h index db34eb732b..3286ac607e 100644 --- a/contrib/file/src/file_opts.h +++ b/contrib/file/src/file_opts.h @@ -43,6 +43,12 @@ OPT('0', "print0", 0, " terminate filenames with ASCII NUL\n") #if defined(HAVE_UTIME) || defined(HAVE_UTIMES) OPT('p', "preserve-date", 0, " preserve access times on files\n") #endif +OPT('P', "parameter", 0, " set file engine parameter limits\n" + " indir 15 recursion limit for indirection\n" + " name 30 use limit for name/use magic\n" + " elf_notes 256 max ELF notes processed\n" + " elf_phnum 128 max ELF prog sections processed\n" + " elf_shnum 32768 max ELF sections processed\n") OPT('r', "raw", 0, " don't translate unprintable chars to \\ooo\n") OPT('s', "special-files", 0, " treat special (block/char devices) files as\n" " ordinary ones\n") diff --git a/contrib/file/src/fsmagic.c b/contrib/file/src/fsmagic.c index 72d035599a..1e8fd74d2a 100644 --- a/contrib/file/src/fsmagic.c +++ b/contrib/file/src/fsmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: fsmagic.c,v 1.71 2013/12/01 18:01:07 christos Exp $") +FILE_RCSID("@(#)$File: fsmagic.c,v 1.75 2014/12/04 15:56:46 christos Exp $") #endif /* lint */ #include "magic.h" @@ -53,7 +53,11 @@ FILE_RCSID("@(#)$File: fsmagic.c,v 1.71 2013/12/01 18:01:07 christos Exp $") #ifdef major /* Might be defined in sys/types.h. */ # define HAVE_MAJOR #endif - +#ifdef WIN32 +# define WIN32_LEAN_AND_MEAN +# include +#endif + #ifndef HAVE_MAJOR # define major(dev) (((dev) >> 8) & 0xff) # define minor(dev) ((dev) & 0xff) @@ -71,10 +75,10 @@ bad_link(struct magic_set *ms, int err, char *buf) else if (!mime) { if (ms->flags & MAGIC_ERROR) { file_error(ms, err, - "broken symbolic link to `%s'", buf); + "broken symbolic link to %s", buf); return -1; } - if (file_printf(ms, "broken symbolic link to `%s'", buf) == -1) + if (file_printf(ms, "broken symbolic link to %s", buf) == -1) return -1; } return 1; @@ -123,6 +127,35 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) #endif ret = stat(fn, sb); /* don't merge into if; see "ret =" above */ +#ifdef WIN32 + { + HANDLE hFile = CreateFile((LPCSTR)fn, 0, FILE_SHARE_DELETE | + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, + NULL); + if (hFile != INVALID_HANDLE_VALUE) { + /* + * Stat failed, but we can still open it - assume it's + * a block device, if nothing else. + */ + if (ret) { + sb->st_mode = S_IFBLK; + ret = 0; + } + switch (GetFileType(hFile)) { + case FILE_TYPE_CHAR: + sb->st_mode |= S_IFCHR; + sb->st_mode &= ~S_IFREG; + break; + case FILE_TYPE_PIPE: + sb->st_mode |= S_IFIFO; + sb->st_mode &= ~S_IFREG; + break; + } + CloseHandle(hFile); + } + } +#endif + if (ret) { if (ms->flags & MAGIC_ERROR) { file_error(ms, errno, "cannot stat `%s'", fn); @@ -176,7 +209,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) if (handle_mime(ms, mime, "chardevice") == -1) return -1; } else { -#ifdef HAVE_STAT_ST_RDEV +#ifdef HAVE_STRUCT_STAT_ST_RDEV # ifdef dv_unit if (file_printf(ms, "%scharacter special (%d/%d/%d)", COMMA, major(sb->st_rdev), dv_unit(sb->st_rdev), @@ -210,7 +243,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) if (handle_mime(ms, mime, "blockdevice") == -1) return -1; } else { -#ifdef HAVE_STAT_ST_RDEV +#ifdef HAVE_STRUCT_STAT_ST_RDEV # ifdef dv_unit if (file_printf(ms, "%sblock special (%d/%d/%d)", COMMA, major(sb->st_rdev), dv_unit(sb->st_rdev), @@ -319,7 +352,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) if (mime) { if (handle_mime(ms, mime, "symlink") == -1) return -1; - } else if (file_printf(ms, "%ssymbolic link to `%s'", + } else if (file_printf(ms, "%ssymbolic link to %s", COMMA, buf) == -1) return -1; } diff --git a/contrib/file/src/funcs.c b/contrib/file/src/funcs.c index a9624a28b9..a60ccaaf9c 100644 --- a/contrib/file/src/funcs.c +++ b/contrib/file/src/funcs.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: funcs.c,v 1.70 2014/03/14 19:02:37 christos Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.79 2014/12/16 20:52:49 christos Exp $") #endif /* lint */ #include "magic.h" @@ -45,9 +45,6 @@ FILE_RCSID("@(#)$File: funcs.c,v 1.70 2014/03/14 19:02:37 christos Exp $") #if defined(HAVE_LIMITS_H) #include #endif -#if defined(HAVE_LOCALE_H) -#include -#endif #ifndef SIZE_MAX #define SIZE_MAX ((size_t)~0) @@ -230,7 +227,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu /* try soft magic tests */ if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0) - if ((m = file_softmagic(ms, ubuf, nb, 0, BINTEST, + if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST, looks_text)) != 0) { if ((ms->flags & MAGIC_DEBUG) != 0) (void)fprintf(stderr, "softmagic %d\n", m); @@ -280,7 +277,9 @@ simple: if (file_printf(ms, "%s", code_mime) == -1) rv = -1; } +#if HAVE_FORK done_encoding: +#endif free(u8buf); if (rv) return rv; @@ -427,35 +426,133 @@ file_printedlen(const struct magic_set *ms) protected int file_replace(struct magic_set *ms, const char *pat, const char *rep) { - regex_t rx; + file_regex_t rx; int rc, rv = -1; - char *old_lc_ctype; - - old_lc_ctype = setlocale(LC_CTYPE, NULL); - assert(old_lc_ctype != NULL); - old_lc_ctype = strdup(old_lc_ctype); - assert(old_lc_ctype != NULL); - (void)setlocale(LC_CTYPE, "C"); - rc = regcomp(&rx, pat, REG_EXTENDED); + + rc = file_regcomp(&rx, pat, REG_EXTENDED); if (rc) { - char errmsg[512]; - (void)regerror(rc, &rx, errmsg, sizeof(errmsg)); - file_magerror(ms, "regex error %d, (%s)", rc, errmsg); + file_regerror(&rx, rc, ms); } else { regmatch_t rm; int nm = 0; - while (regexec(&rx, ms->o.buf, 1, &rm, 0) == 0) { + while (file_regexec(&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) goto out; nm++; } - regfree(&rx); rv = nm; } out: - (void)setlocale(LC_CTYPE, old_lc_ctype); - free(old_lc_ctype); + file_regfree(&rx); return rv; } + +protected int +file_regcomp(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); +#endif + rx->pat = pat; + + return rx->rc = regcomp(&rx->rx, pat, flags); +} + +protected int +file_regexec(file_regex_t *rx, const char *str, size_t nmatch, + regmatch_t* pmatch, int eflags) +{ + assert(rx->rc == 0); + return regexec(&rx->rx, str, nmatch, pmatch, eflags); +} + +protected void +file_regfree(file_regex_t *rx) +{ + if (rx->rc == 0) + regfree(&rx->rx); +#ifdef USE_C_LOCALE + (void)uselocale(rx->old_lc_ctype); + freelocale(rx->c_lc_ctype); +#endif +} + +protected void +file_regerror(file_regex_t *rx, int rc, struct magic_set *ms) +{ + char errmsg[512]; + + (void)regerror(rc, &rx->rx, errmsg, sizeof(errmsg)); + file_magerror(ms, "regex error %d for `%s', (%s)", rc, rx->pat, + errmsg); +} + +protected file_pushbuf_t * +file_push_buffer(struct magic_set *ms) +{ + file_pushbuf_t *pb; + + if (ms->event_flags & EVENT_HAD_ERR) + return NULL; + + if ((pb = (CAST(file_pushbuf_t *, malloc(sizeof(*pb))))) == NULL) + return NULL; + + pb->buf = ms->o.buf; + pb->offset = ms->offset; + + ms->o.buf = NULL; + ms->offset = 0; + + return pb; +} + +protected char * +file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) +{ + char *rbuf; + + if (ms->event_flags & EVENT_HAD_ERR) { + free(pb->buf); + free(pb); + return NULL; + } + + rbuf = ms->o.buf; + + ms->o.buf = pb->buf; + ms->offset = pb->offset; + + free(pb); + return rbuf; +} + +/* + * convert string to ascii printable format. + */ +protected char * +file_printable(char *buf, size_t bufsiz, const char *str) +{ + char *ptr, *eptr; + const unsigned char *s = (const unsigned char *)str; + + for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) { + if (isprint(*s)) { + *ptr++ = *s; + continue; + } + if (ptr >= eptr - 3) + break; + *ptr++ = '\\'; + *ptr++ = ((*s >> 6) & 7) + '0'; + *ptr++ = ((*s >> 3) & 7) + '0'; + *ptr++ = ((*s >> 0) & 7) + '0'; + } + *ptr = '\0'; + return buf; +} diff --git a/contrib/file/src/magic.c b/contrib/file/src/magic.c index 22174b8f52..d16f8c6ce9 100644 --- a/contrib/file/src/magic.c +++ b/contrib/file/src/magic.c @@ -33,7 +33,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.81 2013/11/29 15:42:51 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.91 2014/12/16 23:18:40 christos Exp $") #endif /* lint */ #include "magic.h" @@ -126,8 +126,10 @@ out: free(hmagicpath); return MAGIC; #else - char *hmagicp = hmagicpath; + char *hmagicp; char *tmppath = NULL; + LPTSTR dllpath; + hmagicpath = NULL; #define APPENDPATH() \ do { \ @@ -172,7 +174,7 @@ out: } /* Third, try to get magic file relative to dll location */ - LPTSTR dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1)); + dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1)); dllpath[MAX_PATH] = 0; /* just in case long path gets truncated and not null terminated */ if (GetModuleFileNameA(NULL, dllpath, MAX_PATH)){ PathRemoveFileSpecA(dllpath); @@ -220,13 +222,15 @@ magic_open(int flags) private int unreadable_info(struct magic_set *ms, mode_t md, const char *file) { - /* We cannot open it, but we were able to stat it. */ - if (access(file, W_OK) == 0) - if (file_printf(ms, "writable, ") == -1) - return -1; - if (access(file, X_OK) == 0) - if (file_printf(ms, "executable, ") == -1) - return -1; + if (file) { + /* We cannot open it, but we were able to stat it. */ + if (access(file, W_OK) == 0) + if (file_printf(ms, "writable, ") == -1) + return -1; + if (access(file, X_OK) == 0) + if (file_printf(ms, "executable, ") == -1) + return -1; + } if (S_ISREG(md)) if (file_printf(ms, "regular file, ") == -1) return -1; @@ -254,6 +258,20 @@ magic_load(struct magic_set *ms, const char *magicfile) return file_apprentice(ms, magicfile, FILE_LOAD); } +#ifndef COMPILE_ONLY +/* + * Install a set of compiled magic buffers. + */ +public int +magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes, + size_t nbufs) +{ + if (ms == NULL) + return -1; + return buffer_apprentice(ms, (struct magic **)bufs, sizes, nbufs); +} +#endif + public int magic_compile(struct magic_set *ms, const char *magicfile) { @@ -345,6 +363,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) int ispipe = 0; off_t pos = (off_t)-1; + if (file_reset(ms) == -1) + goto out; + /* * one extra for terminating '\0', and * some overlapping space for matches near EOF @@ -353,9 +374,6 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) if ((buf = CAST(unsigned char *, malloc(HOWMANY + SLOP))) == NULL) return NULL; - if (file_reset(ms) == -1) - goto done; - switch (file_fsmagic(ms, inname, &sb)) { case -1: /* error */ goto done; @@ -366,6 +384,12 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) goto done; } +#ifdef WIN32 + /* Place stdin in binary mode, so EOF (Ctrl+Z) doesn't stop early. */ + if (fd == STDIN_FILENO) + _setmode(STDIN_FILENO, O_BINARY); +#endif + if (inname == NULL) { if (fstat(fd, &sb) == 0 && S_ISFIFO(sb.st_mode)) ispipe = 1; @@ -384,6 +408,18 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) errno = 0; if ((fd = open(inname, flags)) < 0) { +#ifdef WIN32 + /* + * Can't stat, can't open. It may have been opened in + * fsmagic, so if the user doesn't have read permission, + * allow it to say so; otherwise an error was probably + * displayed in fsmagic. + */ + if (!okstat && errno == EACCES) { + sb.st_mode = S_IFBLK; + okstat = 1; + } +#endif if (okstat && unreadable_info(ms, sb.st_mode, inname) == -1) goto done; @@ -419,8 +455,18 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) } } else { - if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) { - file_error(ms, errno, "cannot read `%s'", inname); + /* Windows refuses to read from a big console buffer. */ + size_t howmany = +#if defined(WIN32) && HOWMANY > 8 * 1024 + _isatty(fd) ? 8 * 1024 : +#endif + HOWMANY; + if ((nbytes = read(fd, (char *)buf, howmany)) == -1) { + if (inname == NULL && fd != STDIN_FILENO) + file_error(ms, errno, "cannot read fd %d", fd); + else + file_error(ms, errno, "cannot read `%s'", + inname == NULL ? "/dev/stdin" : inname); goto done; } } @@ -434,6 +480,7 @@ done: if (pos != (off_t)-1) (void)lseek(fd, pos, SEEK_SET); close_and_restore(ms, inname, fd, &sb); +out: return rv == 0 ? file_getbuffer(ms) : NULL; } @@ -490,3 +537,53 @@ magic_version(void) { return MAGIC_VERSION; } + +public int +magic_setparam(struct magic_set *ms, int param, const void *val) +{ + switch (param) { + case MAGIC_PARAM_INDIR_MAX: + ms->indir_max = *(const size_t *)val; + return 0; + case MAGIC_PARAM_NAME_MAX: + ms->name_max = *(const size_t *)val; + return 0; + case MAGIC_PARAM_ELF_PHNUM_MAX: + ms->elf_phnum_max = *(const size_t *)val; + return 0; + case MAGIC_PARAM_ELF_SHNUM_MAX: + ms->elf_shnum_max = *(const size_t *)val; + return 0; + case MAGIC_PARAM_ELF_NOTES_MAX: + ms->elf_notes_max = *(const size_t *)val; + return 0; + default: + errno = EINVAL; + return -1; + } +} + +public int +magic_getparam(struct magic_set *ms, int param, void *val) +{ + switch (param) { + case MAGIC_PARAM_INDIR_MAX: + *(size_t *)val = ms->indir_max; + return 0; + case MAGIC_PARAM_NAME_MAX: + *(size_t *)val = ms->name_max; + return 0; + case MAGIC_PARAM_ELF_PHNUM_MAX: + *(size_t *)val = ms->elf_phnum_max; + return 0; + case MAGIC_PARAM_ELF_SHNUM_MAX: + *(size_t *)val = ms->elf_shnum_max; + return 0; + case MAGIC_PARAM_ELF_NOTES_MAX: + *(size_t *)val = ms->elf_notes_max; + return 0; + default: + errno = EINVAL; + return -1; + } +} diff --git a/contrib/file/src/magic.h b/contrib/file/src/magic.h index 535a177b88..721712ffea 100644 --- a/contrib/file/src/magic.h +++ b/contrib/file/src/magic.h @@ -75,7 +75,7 @@ #define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */ #define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */ -#define MAGIC_VERSION 517 /* This implementation */ +#define MAGIC_VERSION 521 /* This implementation */ #ifdef __cplusplus @@ -96,11 +96,22 @@ int magic_setflags(magic_t, int); int magic_version(void); int magic_load(magic_t, const char *); +int magic_load_buffers(magic_t, void **, size_t *, size_t); + int magic_compile(magic_t, const char *); int magic_check(magic_t, const char *); int magic_list(magic_t, const char *); int magic_errno(magic_t); +#define MAGIC_PARAM_INDIR_MAX 0 +#define MAGIC_PARAM_NAME_MAX 1 +#define MAGIC_PARAM_ELF_PHNUM_MAX 2 +#define MAGIC_PARAM_ELF_SHNUM_MAX 3 +#define MAGIC_PARAM_ELF_NOTES_MAX 4 + +int magic_setparam(magic_t, int, const void *); +int magic_getparam(magic_t, int, void *); + #ifdef __cplusplus }; #endif diff --git a/contrib/file/src/readcdf.c b/contrib/file/src/readcdf.c index 2367b8a21e..635a926376 100644 --- a/contrib/file/src/readcdf.c +++ b/contrib/file/src/readcdf.c @@ -26,7 +26,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: readcdf.c,v 1.40 2014/03/06 15:23:33 christos Exp $") +FILE_RCSID("@(#)$File: readcdf.c,v 1.49 2014/12/04 15:56:46 christos Exp $") #endif #include @@ -35,9 +35,6 @@ FILE_RCSID("@(#)$File: readcdf.c,v 1.40 2014/03/06 15:23:33 christos Exp $") #include #include #include -#if defined(HAVE_LOCALE_H) -#include -#endif #include "cdf.h" #include "magic.h" @@ -75,14 +72,20 @@ static const struct cv { const char *mime; } clsid2mime[] = { { - { 0x00000000000c1084LLU, 0x46000000000000c0LLU }, + { 0x00000000000c1084ULL, 0x46000000000000c0ULL }, "x-msi", - } + }, + { { 0, 0 }, + NULL, + }, }, clsid2desc[] = { { - { 0x00000000000c1084LLU, 0x46000000000000c0LLU }, + { 0x00000000000c1084ULL, 0x46000000000000c0ULL }, "MSI Installer", }, + { { 0, 0 }, + NULL, + }, }; private const char * @@ -101,26 +104,29 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv) { size_t i; const char *rv = NULL; - char *old_lc_ctype; +#ifdef USE_C_LOCALE + locale_t old_lc_ctype, c_lc_ctype; - old_lc_ctype = setlocale(LC_CTYPE, NULL); + c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0); + assert(c_lc_ctype != NULL); + old_lc_ctype = uselocale(c_lc_ctype); assert(old_lc_ctype != NULL); - old_lc_ctype = strdup(old_lc_ctype); - assert(old_lc_ctype != NULL); - (void)setlocale(LC_CTYPE, "C"); +#endif for (i = 0; nv[i].pattern != NULL; i++) if (strcasestr(vbuf, nv[i].pattern) != NULL) { rv = nv[i].mime; break; } - (void)setlocale(LC_CTYPE, old_lc_ctype); - free(old_lc_ctype); +#ifdef USE_C_LOCALE + (void)uselocale(old_lc_ctype); + freelocale(c_lc_ctype); +#endif return rv; } private int cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, - size_t count, const uint64_t clsid[2]) + size_t count, const cdf_directory_t *root_storage) { size_t i; cdf_timestamp_t tp; @@ -130,8 +136,9 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, const char *s; int len; - if (!NOTMIME(ms)) - str = cdf_clsid_to_mime(clsid, clsid2mime); + if (!NOTMIME(ms) && root_storage) + str = cdf_clsid_to_mime(root_storage->d_storage_uuid, + clsid2mime); for (i = 0; i < count; i++) { cdf_print_property_name(buf, sizeof(buf), info[i].pi_id); @@ -173,12 +180,11 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, if (info[i].pi_type == CDF_LENGTH32_WSTRING) k++; s = info[i].pi_str.s_buf; - for (j = 0; j < sizeof(vbuf) && len--; - j++, s += k) { + for (j = 0; j < sizeof(vbuf) && len--; s += k) { if (*s == '\0') break; if (isprint((unsigned char)*s)) - vbuf[j] = *s; + vbuf[j++] = *s; } if (j == sizeof(vbuf)) --j; @@ -234,9 +240,40 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, return 1; } +private int +cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h, + const cdf_stream_t *sst) +{ + cdf_catalog_t *cat; + size_t i; + char buf[256]; + cdf_catalog_entry_t *ce; + + if (NOTMIME(ms)) { + if (file_printf(ms, "Microsoft Thumbs.db [") == -1) + return -1; + if (cdf_unpack_catalog(h, sst, &cat) == -1) + return -1; + ce = cat->cat_e; + /* skip first entry since it has a , or paren */ + for (i = 1; i < cat->cat_num; i++) + if (file_printf(ms, "%s%s", + cdf_u16tos8(buf, ce[i].ce_namlen, ce[i].ce_name), + i == cat->cat_num - 1 ? "]" : ", ") == -1) { + free(cat); + return -1; + } + free(cat); + } else { + if (file_printf(ms, "application/CDFV2") == -1) + return -1; + } + return 1; +} + private int cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h, - const cdf_stream_t *sst, const uint64_t clsid[2]) + const cdf_stream_t *sst, const cdf_directory_t *root_storage) { cdf_summary_info_header_t si; cdf_property_info_t *info; @@ -276,13 +313,17 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h, return -2; break; } - str = cdf_clsid_to_mime(clsid, clsid2desc); - if (str) - if (file_printf(ms, ", %s", str) == -1) - return -2; - } + if (root_storage) { + str = cdf_clsid_to_mime(root_storage->d_storage_uuid, + clsid2desc); + if (str) { + if (file_printf(ms, ", %s", str) == -1) + return -2; + } + } + } - m = cdf_file_property_info(ms, info, count, clsid); + m = cdf_file_property_info(ms, info, count, root_storage); free(info); return m == -1 ? -2 : m; @@ -293,11 +334,11 @@ private char * format_clsid(char *buf, size_t len, const uint64_t uuid[2]) { snprintf(buf, len, "%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.12" PRIx64, - (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffLLU, - (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffLLU, - (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffLLU, - (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffLLU, - (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffLLU); + (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffULL, + (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffULL, + (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffULL, + (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffULL, + (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffULL); return buf; } #endif @@ -314,6 +355,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf, int i; const char *expn = ""; const char *corrupt = "corrupt: "; + const cdf_directory_t *root_storage; info.i_fd = fd; info.i_buf = buf; @@ -347,7 +389,6 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf, goto out2; } - const cdf_directory_t *root_storage; if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst, &root_storage)) == -1) { expn = "Cannot read short stream"; @@ -368,11 +409,51 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf, } #endif + if ((i = cdf_read_user_stream(&info, &h, &sat, &ssat, &sst, &dir, + "FileHeader", &scn)) != -1) { +#define HWP5_SIGNATURE "HWP Document File" + if (scn.sst_dirlen >= sizeof(HWP5_SIGNATURE) - 1 + && memcmp(scn.sst_tab, HWP5_SIGNATURE, + sizeof(HWP5_SIGNATURE) - 1) == 0) { + if (NOTMIME(ms)) { + if (file_printf(ms, + "Hangul (Korean) Word Processor File 5.x") == -1) + return -1; + } else { + if (file_printf(ms, "application/x-hwp") == -1) + return -1; + } + i = 1; + goto out5; + } else { + free(scn.sst_tab); + scn.sst_tab = NULL; + scn.sst_len = 0; + scn.sst_dirlen = 0; + } + } + if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir, &scn)) == -1) { if (errno == ESRCH) { - corrupt = expn; - expn = "No summary info"; + if ((i = cdf_read_catalog(&info, &h, &sat, &ssat, &sst, + &dir, &scn)) == -1) { + corrupt = expn; + if ((i = cdf_read_encrypted_package(&info, &h, + &sat, &ssat, &sst, &dir, &scn)) == -1) + expn = "No summary info"; + else { + expn = "Encrypted"; + i = -1; + } + goto out4; + } +#ifdef CDF_DEBUG + cdf_dump_catalog(&h, &scn); +#endif + if ((i = cdf_file_catalog(ms, &h, &scn)) + < 0) + expn = "Can't expand catalog"; } else { expn = "Cannot read summary info"; } @@ -381,9 +462,8 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf, #ifdef CDF_DEBUG cdf_dump_summary_info(&h, &scn); #endif - if ((i = cdf_file_summary_info(ms, &h, &scn, - root_storage->d_storage_uuid)) < 0) - expn = "Can't expand summary_info"; + if ((i = cdf_file_summary_info(ms, &h, &scn, root_storage)) < 0) + expn = "Can't expand summary_info"; if (i == 0) { const char *str = NULL; @@ -412,6 +492,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf, i = 1; } } +out5: free(scn.sst_tab); out4: free(sst.sst_tab); @@ -431,7 +512,8 @@ out0: if (file_printf(ms, ", %s%s", corrupt, expn) == -1) return -1; } else { - if (file_printf(ms, "application/CDFV2-corrupt") == -1) + if (file_printf(ms, "application/CDFV2-%s", + *corrupt ? "corrupt" : "encrypted") == -1) return -1; } i = 1; diff --git a/contrib/file/src/readelf.c b/contrib/file/src/readelf.c index cbed12920c..d159620cec 100644 --- a/contrib/file/src/readelf.c +++ b/contrib/file/src/readelf.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: readelf.c,v 1.102 2014/03/11 21:00:13 christos Exp $") +FILE_RCSID("@(#)$File: readelf.c,v 1.117 2014/12/16 23:29:42 christos Exp $") #endif #ifdef BUILTIN_ELF @@ -43,14 +43,14 @@ FILE_RCSID("@(#)$File: readelf.c,v 1.102 2014/03/11 21:00:13 christos Exp $") #ifdef ELFCORE private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t, - off_t, int *); + off_t, int *, uint16_t *); #endif private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t, - off_t, int *, int); + off_t, int, int *, uint16_t *); private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, - off_t, int *, int, int); + off_t, int, int, int *, uint16_t *); private size_t donote(struct magic_set *, void *, size_t, size_t, int, - int, size_t, int *); + int, size_t, int *, uint16_t *); #define ELF_ALIGN(a) ((((a) + align - 1) / align) * align) @@ -60,6 +60,19 @@ private uint16_t getu16(int, uint16_t); private uint32_t getu32(int, uint32_t); private uint64_t getu64(int, uint64_t); +#define MAX_PHNUM 128 +#define MAX_SHNUM 32768 +#define SIZE_UNKNOWN ((off_t)-1) + +private int +toomany(struct magic_set *ms, const char *name, uint16_t num) +{ + if (file_printf(ms, ", too many %s (%u)", name, num + ) == -1) + return -1; + return 0; +} + private uint16_t getu16(int swap, uint16_t value) { @@ -280,15 +293,19 @@ private const char os_style_names[][8] = { "NetBSD", }; -#define FLAGS_DID_CORE 0x01 -#define FLAGS_DID_NOTE 0x02 -#define FLAGS_DID_BUILD_ID 0x04 -#define FLAGS_DID_CORE_STYLE 0x08 -#define FLAGS_IS_CORE 0x10 +#define FLAGS_DID_CORE 0x001 +#define FLAGS_DID_OS_NOTE 0x002 +#define FLAGS_DID_BUILD_ID 0x004 +#define FLAGS_DID_CORE_STYLE 0x008 +#define FLAGS_DID_NETBSD_PAX 0x010 +#define FLAGS_DID_NETBSD_MARCH 0x020 +#define FLAGS_DID_NETBSD_CMODEL 0x040 +#define FLAGS_DID_NETBSD_UNKNOWN 0x080 +#define FLAGS_IS_CORE 0x100 private int dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off, - int num, size_t size, off_t fsize, int *flags) + int num, size_t size, off_t fsize, int *flags, uint16_t *notecount) { Elf32_Phdr ph32; Elf64_Phdr ph64; @@ -306,13 +323,13 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off, * Loop through all the program headers. */ for ( ; num; num--) { - if (pread(fd, xph_addr, xph_sizeof, off) == -1) { + if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) { file_badread(ms); return -1; } off += size; - if (xph_offset > fsize) { + if (fsize != SIZE_UNKNOWN && xph_offset > fsize) { /* Perhaps warn here */ continue; } @@ -334,7 +351,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off, if (offset >= (size_t)bufsize) break; offset = donote(ms, nbuf, offset, (size_t)bufsize, - clazz, swap, 4, flags); + clazz, swap, 4, flags, notecount); if (offset == 0) break; @@ -464,125 +481,127 @@ do_note_freebsd_version(struct magic_set *ms, int swap, void *v) } } -private size_t -donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size, - int clazz, int swap, size_t align, int *flags) +private int +do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, + int swap __attribute__((__unused__)), uint32_t namesz, uint32_t descsz, + size_t noff, size_t doff, int *flags) { - Elf32_Nhdr nh32; - Elf64_Nhdr nh64; - size_t noff, doff; -#ifdef ELFCORE - int os_style = -1; -#endif - uint32_t namesz, descsz; - unsigned char *nbuf = CAST(unsigned char *, vbuf); - - (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof); - offset += xnh_sizeof; - - namesz = xnh_namesz; - descsz = xnh_descsz; - if ((namesz == 0) && (descsz == 0)) { - /* - * We're out of note headers. - */ - return (offset >= size) ? offset : size; - } - - if (namesz & 0x80000000) { - (void)file_printf(ms, ", bad note name size 0x%lx", - (unsigned long)namesz); - return offset; - } - - if (descsz & 0x80000000) { - (void)file_printf(ms, ", bad note description size 0x%lx", - (unsigned long)descsz); - return offset; - } - - - noff = offset; - doff = ELF_ALIGN(offset + namesz); - - if (offset + namesz > size) { - /* - * We're past the end of the buffer. - */ - return doff; - } - - offset = ELF_ALIGN(doff + descsz); - if (doff + descsz > size) { - /* - * We're past the end of the buffer. - */ - return (offset >= size) ? offset : size; + if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 && + type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) { + uint8_t desc[20]; + uint32_t i; + *flags |= FLAGS_DID_BUILD_ID; + if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" : + "sha1") == -1) + return 1; + (void)memcpy(desc, &nbuf[doff], descsz); + for (i = 0; i < descsz; i++) + if (file_printf(ms, "%02x", desc[i]) == -1) + return 1; + return 1; } + return 0; +} - if ((*flags & (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID)) == - (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID)) - goto core; - +private int +do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, + int swap, uint32_t namesz, uint32_t descsz, + size_t noff, size_t doff, int *flags) +{ if (namesz == 5 && strcmp((char *)&nbuf[noff], "SuSE") == 0 && - xnh_type == NT_GNU_VERSION && descsz == 2) { + type == NT_GNU_VERSION && descsz == 2) { + *flags |= FLAGS_DID_OS_NOTE; file_printf(ms, ", for SuSE %d.%d", nbuf[doff], nbuf[doff + 1]); + return 1; } + if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 && - xnh_type == NT_GNU_VERSION && descsz == 16) { + type == NT_GNU_VERSION && descsz == 16) { uint32_t desc[4]; (void)memcpy(desc, &nbuf[doff], sizeof(desc)); + *flags |= FLAGS_DID_OS_NOTE; if (file_printf(ms, ", for GNU/") == -1) - return size; + return 1; switch (elf_getu32(swap, desc[0])) { case GNU_OS_LINUX: if (file_printf(ms, "Linux") == -1) - return size; + return 1; break; case GNU_OS_HURD: if (file_printf(ms, "Hurd") == -1) - return size; + return 1; break; case GNU_OS_SOLARIS: if (file_printf(ms, "Solaris") == -1) - return size; + return 1; break; case GNU_OS_KFREEBSD: if (file_printf(ms, "kFreeBSD") == -1) - return size; + return 1; break; case GNU_OS_KNETBSD: if (file_printf(ms, "kNetBSD") == -1) - return size; + return 1; break; default: if (file_printf(ms, "") == -1) - return size; + return 1; } if (file_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]), elf_getu32(swap, desc[2]), elf_getu32(swap, desc[3])) == -1) - return size; - *flags |= FLAGS_DID_NOTE; - return size; + return 1; + return 1; } - if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 && - xnh_type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) { - uint8_t desc[20]; - uint32_t i; - if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" : - "sha1") == -1) - return size; - (void)memcpy(desc, &nbuf[doff], descsz); - for (i = 0; i < descsz; i++) - if (file_printf(ms, "%02x", desc[i]) == -1) - return size; - *flags |= FLAGS_DID_BUILD_ID; + if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) { + if (type == NT_NETBSD_VERSION && descsz == 4) { + *flags |= FLAGS_DID_OS_NOTE; + do_note_netbsd_version(ms, swap, &nbuf[doff]); + return 1; + } + } + + if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0) { + if (type == NT_FREEBSD_VERSION && descsz == 4) { + *flags |= FLAGS_DID_OS_NOTE; + do_note_freebsd_version(ms, swap, &nbuf[doff]); + return 1; + } } + if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 && + type == NT_OPENBSD_VERSION && descsz == 4) { + *flags |= FLAGS_DID_OS_NOTE; + if (file_printf(ms, ", for OpenBSD") == -1) + return 1; + /* Content of note is always 0 */ + return 1; + } + + if (namesz == 10 && strcmp((char *)&nbuf[noff], "DragonFly") == 0 && + type == NT_DRAGONFLY_VERSION && descsz == 4) { + uint32_t desc; + *flags |= FLAGS_DID_OS_NOTE; + if (file_printf(ms, ", for DragonFly") == -1) + return 1; + (void)memcpy(&desc, &nbuf[doff], sizeof(desc)); + desc = elf_getu32(swap, desc); + if (file_printf(ms, " %d.%d.%d", desc / 100000, + desc / 10000 % 10, desc % 10000) == -1) + return 1; + return 1; + } + return 0; +} + +private int +do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, + int swap, uint32_t namesz, uint32_t descsz, + size_t noff, size_t doff, int *flags) +{ if (namesz == 4 && strcmp((char *)&nbuf[noff], "PaX") == 0 && - xnh_type == NT_NETBSD_PAX && descsz == 4) { + type == NT_NETBSD_PAX && descsz == 4) { static const char *pax[] = { "+mprotect", "-mprotect", @@ -595,80 +614,32 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size, size_t i; int did = 0; + *flags |= FLAGS_DID_NETBSD_PAX; (void)memcpy(&desc, &nbuf[doff], sizeof(desc)); desc = elf_getu32(swap, desc); if (desc && file_printf(ms, ", PaX: ") == -1) - return size; + return 1; for (i = 0; i < __arraycount(pax); i++) { if (((1 << i) & desc) == 0) continue; if (file_printf(ms, "%s%s", did++ ? "," : "", pax[i]) == -1) - return size; - } - } - - if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) { - switch (xnh_type) { - case NT_NETBSD_VERSION: - if (descsz == 4) { - do_note_netbsd_version(ms, swap, &nbuf[doff]); - *flags |= FLAGS_DID_NOTE; - return size; - } - break; - case NT_NETBSD_MARCH: - if (file_printf(ms, ", compiled for: %.*s", (int)descsz, - (const char *)&nbuf[doff]) == -1) - return size; - break; - case NT_NETBSD_CMODEL: - if (file_printf(ms, ", compiler model: %.*s", - (int)descsz, (const char *)&nbuf[doff]) == -1) - return size; - break; - default: - if (file_printf(ms, ", note=%u", xnh_type) == -1) - return size; - break; + return 1; } - return size; - } - - if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0) { - if (xnh_type == NT_FREEBSD_VERSION && descsz == 4) { - do_note_freebsd_version(ms, swap, &nbuf[doff]); - *flags |= FLAGS_DID_NOTE; - return size; - } - } - - if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 && - xnh_type == NT_OPENBSD_VERSION && descsz == 4) { - if (file_printf(ms, ", for OpenBSD") == -1) - return size; - /* Content of note is always 0 */ - *flags |= FLAGS_DID_NOTE; - return size; - } - - if (namesz == 10 && strcmp((char *)&nbuf[noff], "DragonFly") == 0 && - xnh_type == NT_DRAGONFLY_VERSION && descsz == 4) { - uint32_t desc; - if (file_printf(ms, ", for DragonFly") == -1) - return size; - (void)memcpy(&desc, &nbuf[doff], sizeof(desc)); - desc = elf_getu32(swap, desc); - if (file_printf(ms, " %d.%d.%d", desc / 100000, - desc / 10000 % 10, desc % 10000) == -1) - return size; - *flags |= FLAGS_DID_NOTE; - return size; + return 1; } + return 0; +} -core: +private int +do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, + int swap, uint32_t namesz, uint32_t descsz, + size_t noff, size_t doff, int *flags, size_t size, int clazz) +{ +#ifdef ELFCORE + int os_style = -1; /* * Sigh. The 2.0.36 kernel in Debian 2.1, at * least, doesn't correctly implement name @@ -697,20 +668,17 @@ core: os_style = OS_STYLE_NETBSD; } -#ifdef ELFCORE - if ((*flags & FLAGS_DID_CORE) != 0) - return size; - if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) { if (file_printf(ms, ", %s-style", os_style_names[os_style]) == -1) - return size; + return 1; *flags |= FLAGS_DID_CORE_STYLE; } switch (os_style) { case OS_STYLE_NETBSD: - if (xnh_type == NT_NETBSD_CORE_PROCINFO) { + if (type == NT_NETBSD_CORE_PROCINFO) { + char sbuf[512]; uint32_t signo; /* * Extract the program name. It is at @@ -718,8 +686,9 @@ core: * including the terminating NUL. */ if (file_printf(ms, ", from '%.31s'", - &nbuf[doff + 0x7c]) == -1) - return size; + file_printable(sbuf, sizeof(sbuf), + (const char *)&nbuf[doff + 0x7c])) == -1) + return 1; /* * Extract the signal number. It is at @@ -729,14 +698,14 @@ core: sizeof(signo)); if (file_printf(ms, " (signal %u)", elf_getu32(swap, signo)) == -1) - return size; + return 1; *flags |= FLAGS_DID_CORE; - return size; + return 1; } break; default: - if (xnh_type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) { + if (type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) { size_t i, j; unsigned char c; /* @@ -804,7 +773,7 @@ core: * Try next offsets, in case this match is * in the middle of a string. */ - for (k = i + 1 ; k < NOFFSETS ; k++) { + for (k = i + 1 ; k < NOFFSETS; k++) { size_t no; int adjust = 1; if (prpsoffsets(k) >= prpsoffsets(i)) @@ -829,9 +798,9 @@ core: cp--; if (file_printf(ms, ", from '%.*s'", (int)(cp - cname), cname) == -1) - return size; + return 1; *flags |= FLAGS_DID_CORE; - return size; + return 1; tryanother: ; @@ -840,6 +809,129 @@ core: break; } #endif + return 0; +} + +private size_t +donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size, + int clazz, int swap, size_t align, int *flags, uint16_t *notecount) +{ + Elf32_Nhdr nh32; + Elf64_Nhdr nh64; + size_t noff, doff; + uint32_t namesz, descsz; + unsigned char *nbuf = CAST(unsigned char *, vbuf); + + if (*notecount == 0) + return 0; + --*notecount; + + if (xnh_sizeof + offset > size) { + /* + * We're out of note headers. + */ + return xnh_sizeof + offset; + } + + (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof); + offset += xnh_sizeof; + + namesz = xnh_namesz; + descsz = xnh_descsz; + if ((namesz == 0) && (descsz == 0)) { + /* + * We're out of note headers. + */ + return (offset >= size) ? offset : size; + } + + if (namesz & 0x80000000) { + (void)file_printf(ms, ", bad note name size 0x%lx", + (unsigned long)namesz); + return 0; + } + + if (descsz & 0x80000000) { + (void)file_printf(ms, ", bad note description size 0x%lx", + (unsigned long)descsz); + return 0; + } + + noff = offset; + doff = ELF_ALIGN(offset + namesz); + + if (offset + namesz > size) { + /* + * We're past the end of the buffer. + */ + return doff; + } + + offset = ELF_ALIGN(doff + descsz); + if (doff + descsz > size) { + /* + * We're past the end of the buffer. + */ + return (offset >= size) ? offset : size; + } + + if ((*flags & FLAGS_DID_OS_NOTE) == 0) { + if (do_os_note(ms, nbuf, xnh_type, swap, + namesz, descsz, noff, doff, flags)) + return size; + } + + if ((*flags & FLAGS_DID_BUILD_ID) == 0) { + if (do_bid_note(ms, nbuf, xnh_type, swap, + namesz, descsz, noff, doff, flags)) + return size; + } + + if ((*flags & FLAGS_DID_NETBSD_PAX) == 0) { + if (do_pax_note(ms, nbuf, xnh_type, swap, + namesz, descsz, noff, doff, flags)) + return size; + } + + if ((*flags & FLAGS_DID_CORE) == 0) { + if (do_core_note(ms, nbuf, xnh_type, swap, + namesz, descsz, noff, doff, flags, size, clazz)) + return size; + } + + if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) { + if (descsz > 100) + descsz = 100; + switch (xnh_type) { + case NT_NETBSD_VERSION: + return size; + case NT_NETBSD_MARCH: + if (*flags & FLAGS_DID_NETBSD_MARCH) + return size; + *flags |= FLAGS_DID_NETBSD_MARCH; + if (file_printf(ms, ", compiled for: %.*s", + (int)descsz, (const char *)&nbuf[doff]) == -1) + return size; + break; + case NT_NETBSD_CMODEL: + if (*flags & FLAGS_DID_NETBSD_CMODEL) + return size; + *flags |= FLAGS_DID_NETBSD_CMODEL; + if (file_printf(ms, ", compiler model: %.*s", + (int)descsz, (const char *)&nbuf[doff]) == -1) + return size; + break; + default: + if (*flags & FLAGS_DID_NETBSD_UNKNOWN) + return size; + *flags |= FLAGS_DID_NETBSD_UNKNOWN; + if (file_printf(ms, ", note=%u", xnh_type) == -1) + return size; + break; + } + return size; + } + return offset; } @@ -895,16 +987,19 @@ static const cap_desc_t cap_desc_386[] = { private int doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, - size_t size, off_t fsize, int *flags, int mach, int strtab) + size_t size, off_t fsize, int mach, int strtab, int *flags, + uint16_t *notecount) { Elf32_Shdr sh32; Elf64_Shdr sh64; int stripped = 1; + size_t nbadcap = 0; void *nbuf; off_t noff, coff, name_off; uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */ uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */ char name[50]; + ssize_t namesize; if (size != xsh_sizeof) { if (file_printf(ms, ", corrupted section header size") == -1) @@ -913,7 +1008,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, } /* Read offset of name section to be able to read section names later */ - if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) { + if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) < (ssize_t)xsh_sizeof) { file_badread(ms); return -1; } @@ -921,15 +1016,15 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, for ( ; num; num--) { /* Read the name of this section. */ - if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) { + if ((namesize = pread(fd, name, sizeof(name) - 1, name_off + xsh_name)) == -1) { file_badread(ms); return -1; } - name[sizeof(name) - 1] = '\0'; + name[namesize] = '\0'; if (strcmp(name, ".debug_info") == 0) stripped = 0; - if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) { + if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) { file_badread(ms); return -1; } @@ -944,7 +1039,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, stripped = 0; break; default: - if (xsh_offset > fsize) { + if (fsize != SIZE_UNKNOWN && xsh_offset > fsize) { /* Perhaps warn here */ continue; } @@ -959,7 +1054,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, " for note"); return -1; } - if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) { + if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) { file_badread(ms); free(nbuf); return -1; @@ -970,7 +1065,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, if (noff >= (off_t)xsh_size) break; noff = donote(ms, nbuf, (size_t)noff, - xsh_size, clazz, swap, 4, flags); + xsh_size, clazz, swap, 4, flags, notecount); if (noff == 0) break; } @@ -988,6 +1083,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, goto skip; } + if (nbadcap > 5) + break; if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) { file_badseek(ms); return -1; @@ -1005,6 +1102,36 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, file_badread(ms); return -1; } + if (cbuf[0] == 'A') { +#ifdef notyet + char *p = cbuf + 1; + uint32_t len, tag; + memcpy(&len, p, sizeof(len)); + p += 4; + len = getu32(swap, len); + if (memcmp("gnu", p, 3) != 0) { + if (file_printf(ms, + ", unknown capability %.3s", p) + == -1) + return -1; + break; + } + p += strlen(p) + 1; + tag = *p++; + memcpy(&len, p, sizeof(len)); + p += 4; + len = getu32(swap, len); + if (tag != 1) { + if (file_printf(ms, ", unknown gnu" + " capability tag %d", tag) + == -1) + return -1; + break; + } + // gnu attributes +#endif + break; + } (void)memcpy(xcap_addr, cbuf, xcap_sizeof); switch (xcap_tag) { case CA_SUNW_NULL: @@ -1023,6 +1150,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, (unsigned long long)xcap_tag, (unsigned long long)xcap_val) == -1) return -1; + if (nbadcap++ > 2) + coff = xsh_size; break; } } @@ -1103,13 +1232,15 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, */ private int dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, - int num, size_t size, off_t fsize, int *flags, int sh_num) + int num, size_t size, off_t fsize, int sh_num, int *flags, + uint16_t *notecount) { Elf32_Phdr ph32; Elf64_Phdr ph64; const char *linking_style = "statically"; - const char *shared_libraries = ""; + const char *interp = ""; unsigned char nbuf[BUFSIZ]; + char ibuf[BUFSIZ]; ssize_t bufsize; size_t offset, align, len; @@ -1120,23 +1251,43 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, } for ( ; num; num--) { - if (pread(fd, xph_addr, xph_sizeof, off) == -1) { + if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) { file_badread(ms); return -1; } off += size; + bufsize = 0; + align = 4; /* Things we can determine before we seek */ switch (xph_type) { case PT_DYNAMIC: linking_style = "dynamically"; break; + case PT_NOTE: + if (sh_num) /* Did this through section headers */ + continue; + if (((align = xph_align) & 0x80000000UL) != 0 || + align < 4) { + if (file_printf(ms, + ", invalid note alignment 0x%lx", + (unsigned long)align) == -1) + return -1; + align = 4; + } + /*FALLTHROUGH*/ case PT_INTERP: - shared_libraries = " (uses shared libs)"; + len = xph_filesz < sizeof(nbuf) ? xph_filesz + : sizeof(nbuf); + bufsize = pread(fd, nbuf, len, xph_offset); + if (bufsize == -1) { + file_badread(ms); + return -1; + } break; default: - if (xph_offset > fsize) { + if (fsize != SIZE_UNKNOWN && xph_offset > fsize) { /* Maybe warn here? */ continue; } @@ -1145,34 +1296,25 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, /* Things we can determine when we seek */ switch (xph_type) { + case PT_INTERP: + if (bufsize && nbuf[0]) { + nbuf[bufsize - 1] = '\0'; + interp = (const char *)nbuf; + } else + interp = "*empty*"; + break; case PT_NOTE: - if ((align = xph_align) & 0x80000000UL) { - if (file_printf(ms, - ", invalid note alignment 0x%lx", - (unsigned long)align) == -1) - return -1; - align = 4; - } - if (sh_num) - break; /* * This is a PT_NOTE section; loop through all the notes * in the section. */ - len = xph_filesz < sizeof(nbuf) ? xph_filesz - : sizeof(nbuf); - bufsize = pread(fd, nbuf, len, xph_offset); - if (bufsize == -1) { - file_badread(ms); - return -1; - } offset = 0; for (;;) { if (offset >= (size_t)bufsize) break; offset = donote(ms, nbuf, offset, (size_t)bufsize, clazz, swap, align, - flags); + flags, notecount); if (offset == 0) break; } @@ -1181,9 +1323,13 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, break; } } - if (file_printf(ms, ", %s linked%s", linking_style, shared_libraries) + if (file_printf(ms, ", %s linked", linking_style) == -1) - return -1; + return -1; + if (interp[0]) + if (file_printf(ms, ", interpreter %s", + file_printable(ibuf, sizeof(ibuf), interp)) == -1) + return -1; return 0; } @@ -1203,7 +1349,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf, int flags = 0; Elf32_Ehdr elf32hdr; Elf64_Ehdr elf64hdr; - uint16_t type; + uint16_t type, phnum, shnum, notecount; if (ms->flags & (MAGIC_MIME|MAGIC_APPLE)) return 0; @@ -1229,7 +1375,10 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf, file_badread(ms); return -1; } - fsize = st.st_size; + if (S_ISREG(st.st_mode) || st.st_size != 0) + fsize = st.st_size; + else + fsize = SIZE_UNKNOWN; clazz = buf[EI_CLASS]; diff --git a/contrib/file/src/softmagic.c b/contrib/file/src/softmagic.c index eaa0f6b612..5e277e31fd 100644 --- a/contrib/file/src/softmagic.c +++ b/contrib/file/src/softmagic.c @@ -32,33 +32,28 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.180 2014/03/15 21:47:40 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.206 2015/01/01 17:07:34 christos Exp $") #endif /* lint */ #include "magic.h" -#define F(a, b) fmtcheck((a), (b)) #include #include #include #include #include -#if defined(HAVE_LOCALE_H) -#include -#endif - private int match(struct magic_set *, struct magic *, uint32_t, - const unsigned char *, size_t, size_t, int, int, int, int, int *, int *, - int *); + const unsigned char *, size_t, size_t, int, int, int, uint16_t, + uint16_t *, int *, int *, int *); private int mget(struct magic_set *, const unsigned char *, - struct magic *, size_t, size_t, unsigned int, int, int, int, int, int *, - int *, int *); + struct magic *, size_t, size_t, unsigned int, int, int, int, uint16_t, + uint16_t *, int *, int *, int *); private int magiccheck(struct magic_set *, struct magic *); private int32_t mprint(struct magic_set *, struct magic *); private int32_t moffset(struct magic_set *, struct magic *); private void mdebug(uint32_t, const char *, size_t); private int mcopy(struct magic_set *, union VALUETYPE *, int, int, - const unsigned char *, uint32_t, size_t, size_t); + const unsigned char *, uint32_t, size_t, struct magic *); private int mconvert(struct magic_set *, struct magic *, int); private int print_sep(struct magic_set *, int); private int handle_annotation(struct magic_set *, struct magic *); @@ -68,6 +63,7 @@ private void cvt_32(union VALUETYPE *, const struct magic *); private void cvt_64(union VALUETYPE *, const struct magic *); #define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o))) + /* * softmagic - lookup one file in parsed, in-memory copy of database * Passed the name and FILE * of one file to be typed. @@ -75,19 +71,45 @@ private void cvt_64(union VALUETYPE *, const struct magic *); /*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */ protected int file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes, - size_t level, int mode, int text) + uint16_t indir_level, uint16_t *name_count, int mode, int text) { struct mlist *ml; int rv, printed_something = 0, need_separator = 0; + uint16_t nc; + + if (name_count == NULL) { + nc = 0; + name_count = &nc; + } + for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next) if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode, - text, 0, level, &printed_something, &need_separator, - NULL)) != 0) + text, 0, indir_level, name_count, + &printed_something, &need_separator, NULL)) != 0) return rv; return 0; } +#define FILE_FMTDEBUG +#ifdef FILE_FMTDEBUG +#define F(a, b, c) file_fmtcheck((a), (b), (c), __FILE__, __LINE__) + +private const char * __attribute__((__format_arg__(3))) +file_fmtcheck(struct magic_set *ms, const struct magic *m, const char *def, + const char *file, size_t line) +{ + const char *ptr = fmtcheck(m->desc, def); + if (ptr == def) + file_magerror(ms, + "%s, %" SIZE_T_FORMAT "u: format `%s' does not match" + " with `%s'", file, line, m->desc, def); + return ptr; +} +#else +#define F(a, b, c) fmtcheck((b)->desc, (c)) +#endif + /* * Go through the whole list, stopping if you find a match. Process all * the continuations of that match before returning. @@ -118,8 +140,8 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes, private int match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, const unsigned char *s, size_t nbytes, size_t offset, int mode, int text, - int flip, int recursion_level, int *printed_something, int *need_separator, - int *returnval) + int flip, uint16_t indir_level, uint16_t *name_count, + int *printed_something, int *need_separator, int *returnval) { uint32_t magindex = 0; unsigned int cont_level = 0; @@ -156,8 +178,8 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, /* if main entry matches, print it... */ switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text, - flip, recursion_level + 1, printed_something, - need_separator, returnval)) { + flip, indir_level, name_count, + printed_something, need_separator, returnval)) { case -1: return -1; case 0: @@ -217,9 +239,9 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, if (file_check_mem(ms, ++cont_level) == -1) return -1; - while (magic[magindex+1].cont_level != 0 && - ++magindex < nmagic) { - m = &magic[magindex]; + while (magindex + 1 < nmagic && + magic[magindex + 1].cont_level != 0) { + m = &magic[++magindex]; ms->line = m->lineno; /* for messages */ if (cont_level < m->cont_level) @@ -245,8 +267,8 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, } #endif switch (mget(ms, s, m, nbytes, offset, cont_level, mode, - text, flip, recursion_level + 1, printed_something, - need_separator, returnval)) { + text, flip, indir_level, name_count, + printed_something, need_separator, returnval)) { case -1: return -1; case 0: @@ -346,30 +368,20 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, private int check_fmt(struct magic_set *ms, struct magic *m) { - regex_t rx; + file_regex_t rx; int rc, rv = -1; - char *old_lc_ctype; if (strchr(m->desc, '%') == NULL) return 0; - old_lc_ctype = setlocale(LC_CTYPE, NULL); - assert(old_lc_ctype != NULL); - old_lc_ctype = strdup(old_lc_ctype); - assert(old_lc_ctype != NULL); - (void)setlocale(LC_CTYPE, "C"); - rc = regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB); + rc = file_regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB); if (rc) { - char errmsg[512]; - (void)regerror(rc, &rx, errmsg, sizeof(errmsg)); - file_magerror(ms, "regex error %d, (%s)", rc, errmsg); + file_regerror(&rx, rc, ms); } else { - rc = regexec(&rx, m->desc, 0, 0, 0); - regfree(&rx); + rc = file_regexec(&rx, m->desc, 0, 0, 0); rv = !rc; } - (void)setlocale(LC_CTYPE, old_lc_ctype); - free(old_lc_ctype); + file_regfree(&rx); return rv; } @@ -399,7 +411,7 @@ mprint(struct magic_set *ms, struct magic *m) float vf; double vd; int64_t t = 0; - char buf[128], tbuf[26]; + char buf[128], tbuf[26], sbuf[512]; union VALUETYPE *p = &ms->ms_value; switch (m->type) { @@ -409,13 +421,13 @@ mprint(struct magic_set *ms, struct magic *m) case -1: return -1; case 1: - (void)snprintf(buf, sizeof(buf), "%c", + (void)snprintf(buf, sizeof(buf), "%d", (unsigned char)v); - if (file_printf(ms, F(m->desc, "%s"), buf) == -1) + if (file_printf(ms, F(ms, m, "%s"), buf) == -1) return -1; break; default: - if (file_printf(ms, F(m->desc, "%c"), + if (file_printf(ms, F(ms, m, "%d"), (unsigned char) v) == -1) return -1; break; @@ -431,13 +443,13 @@ mprint(struct magic_set *ms, struct magic *m) case -1: return -1; case 1: - (void)snprintf(buf, sizeof(buf), "%hu", + (void)snprintf(buf, sizeof(buf), "%u", (unsigned short)v); - if (file_printf(ms, F(m->desc, "%s"), buf) == -1) + if (file_printf(ms, F(ms, m, "%s"), buf) == -1) return -1; break; default: - if (file_printf(ms, F(m->desc, "%hu"), + if (file_printf(ms, F(ms, m, "%u"), (unsigned short) v) == -1) return -1; break; @@ -454,13 +466,12 @@ mprint(struct magic_set *ms, struct magic *m) case -1: return -1; case 1: - (void)snprintf(buf, sizeof(buf), "%u", (uint32_t)v); - if (file_printf(ms, F(m->desc, "%s"), buf) == -1) + (void)snprintf(buf, sizeof(buf), "%u", (uint32_t) v); + if (file_printf(ms, F(ms, m, "%s"), buf) == -1) return -1; break; default: - if (file_printf(ms, F(m->desc, "%u"), - (uint32_t) v) == -1) + if (file_printf(ms, F(ms, m, "%u"), (uint32_t) v) == -1) return -1; break; } @@ -475,13 +486,13 @@ mprint(struct magic_set *ms, struct magic *m) case -1: return -1; case 1: - (void)snprintf(buf, sizeof(buf), "%llu", + (void)snprintf(buf, sizeof(buf), "%" INT64_T_FORMAT "u", (unsigned long long)v); - if (file_printf(ms, F(m->desc, "%s"), buf) == -1) + if (file_printf(ms, F(ms, m, "%s"), buf) == -1) return -1; break; default: - if (file_printf(ms, F(m->desc, "%llu"), + if (file_printf(ms, F(ms, m, "%" INT64_T_FORMAT "u"), (unsigned long long) v) == -1) return -1; break; @@ -494,7 +505,9 @@ mprint(struct magic_set *ms, struct magic *m) case FILE_BESTRING16: case FILE_LESTRING16: if (m->reln == '=' || m->reln == '!') { - if (file_printf(ms, F(m->desc, "%s"), m->value.s) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_printable(sbuf, sizeof(sbuf), m->value.s)) + == -1) return -1; t = ms->offset + m->vallen; } @@ -520,7 +533,8 @@ mprint(struct magic_set *ms, struct magic *m) *++last = '\0'; } - if (file_printf(ms, F(m->desc, "%s"), str) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_printable(sbuf, sizeof(sbuf), str)) == -1) return -1; if (m->type == FILE_PSTRING) @@ -532,8 +546,8 @@ mprint(struct magic_set *ms, struct magic *m) case FILE_BEDATE: case FILE_LEDATE: case FILE_MEDATE: - if (file_printf(ms, F(m->desc, "%s"), - file_fmttime(p->l, FILE_T_LOCAL, tbuf)) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_fmttime(p->l + m->num_mask, FILE_T_LOCAL, tbuf)) == -1) return -1; t = ms->offset + sizeof(uint32_t); break; @@ -542,8 +556,8 @@ mprint(struct magic_set *ms, struct magic *m) case FILE_BELDATE: case FILE_LELDATE: case FILE_MELDATE: - if (file_printf(ms, F(m->desc, "%s"), - file_fmttime(p->l, 0, tbuf)) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_fmttime(p->l + m->num_mask, 0, tbuf)) == -1) return -1; t = ms->offset + sizeof(uint32_t); break; @@ -551,8 +565,8 @@ mprint(struct magic_set *ms, struct magic *m) case FILE_QDATE: case FILE_BEQDATE: case FILE_LEQDATE: - if (file_printf(ms, F(m->desc, "%s"), - file_fmttime(p->q, FILE_T_LOCAL, tbuf)) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_fmttime(p->q + m->num_mask, FILE_T_LOCAL, tbuf)) == -1) return -1; t = ms->offset + sizeof(uint64_t); break; @@ -560,8 +574,8 @@ mprint(struct magic_set *ms, struct magic *m) case FILE_QLDATE: case FILE_BEQLDATE: case FILE_LEQLDATE: - if (file_printf(ms, F(m->desc, "%s"), - file_fmttime(p->q, 0, tbuf)) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_fmttime(p->q + m->num_mask, 0, tbuf)) == -1) return -1; t = ms->offset + sizeof(uint64_t); break; @@ -569,8 +583,8 @@ mprint(struct magic_set *ms, struct magic *m) case FILE_QWDATE: case FILE_BEQWDATE: case FILE_LEQWDATE: - if (file_printf(ms, F(m->desc, "%s"), - file_fmttime(p->q, FILE_T_WINDOWS, tbuf)) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_fmttime(p->q + m->num_mask, FILE_T_WINDOWS, tbuf)) == -1) return -1; t = ms->offset + sizeof(uint64_t); break; @@ -584,11 +598,11 @@ mprint(struct magic_set *ms, struct magic *m) return -1; case 1: (void)snprintf(buf, sizeof(buf), "%g", vf); - if (file_printf(ms, F(m->desc, "%s"), buf) == -1) + if (file_printf(ms, F(ms, m, "%s"), buf) == -1) return -1; break; default: - if (file_printf(ms, F(m->desc, "%g"), vf) == -1) + if (file_printf(ms, F(ms, m, "%g"), vf) == -1) return -1; break; } @@ -604,11 +618,11 @@ mprint(struct magic_set *ms, struct magic *m) return -1; case 1: (void)snprintf(buf, sizeof(buf), "%g", vd); - if (file_printf(ms, F(m->desc, "%s"), buf) == -1) + if (file_printf(ms, F(ms, m, "%s"), buf) == -1) return -1; break; default: - if (file_printf(ms, F(m->desc, "%g"), vd) == -1) + if (file_printf(ms, F(ms, m, "%g"), vd) == -1) return -1; break; } @@ -624,7 +638,8 @@ mprint(struct magic_set *ms, struct magic *m) file_oomem(ms, ms->search.rm_len); return -1; } - rval = file_printf(ms, F(m->desc, "%s"), cp); + rval = file_printf(ms, F(ms, m, "%s"), + file_printable(sbuf, sizeof(sbuf), cp)); free(cp); if (rval == -1) @@ -638,7 +653,8 @@ mprint(struct magic_set *ms, struct magic *m) } case FILE_SEARCH: - if (file_printf(ms, F(m->desc, "%s"), m->value.s) == -1) + if (file_printf(ms, F(ms, m, "%s"), + file_printable(sbuf, sizeof(sbuf), m->value.s)) == -1) return -1; if ((m->str_flags & REGEX_OFFSET_START)) t = ms->search.offset; @@ -905,8 +921,9 @@ private int mconvert(struct magic_set *ms, struct magic *m, int flip) { union VALUETYPE *p = &ms->ms_value; + uint8_t type; - switch (cvt_flip(m->type, flip)) { + switch (type = cvt_flip(m->type, flip)) { case FILE_BYTE: cvt_8(p, m); return 1; @@ -932,10 +949,21 @@ mconvert(struct magic_set *ms, struct magic *m, int flip) return 1; } case FILE_PSTRING: { - char *ptr1 = p->s, *ptr2 = ptr1 + file_pstring_length_size(m); + size_t sz = file_pstring_length_size(m); + char *ptr1 = p->s, *ptr2 = ptr1 + sz; size_t len = file_pstring_get_length(m, ptr1); - if (len >= sizeof(p->s)) - len = sizeof(p->s) - 1; + sz = sizeof(p->s) - sz; /* maximum length of string */ + if (len >= sz) { + /* + * The size of the pascal string length (sz) + * is 1, 2, or 4. We need at least 1 byte for NUL + * termination, but we've already truncated the + * string by p->s, so we need to deduct sz. + * Because we can use one of the bytes of the length + * after we shifted as NUL termination. + */ + len = sz; + } while (len--) *ptr1++ = *ptr2++; *ptr1 = '\0'; @@ -950,7 +978,8 @@ mconvert(struct magic_set *ms, struct magic *m, int flip) case FILE_BELDATE: p->l = (int32_t) ((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3])); - cvt_32(p, m); + if (type == FILE_BELONG) + cvt_32(p, m); return 1; case FILE_BEQUAD: case FILE_BEQDATE: @@ -961,7 +990,8 @@ mconvert(struct magic_set *ms, struct magic *m, int flip) ((uint64_t)p->hq[2]<<40)|((uint64_t)p->hq[3]<<32)| ((uint64_t)p->hq[4]<<24)|((uint64_t)p->hq[5]<<16)| ((uint64_t)p->hq[6]<<8)|((uint64_t)p->hq[7])); - cvt_64(p, m); + if (type == FILE_BEQUAD) + cvt_64(p, m); return 1; case FILE_LESHORT: p->h = (short)((p->hs[1]<<8)|(p->hs[0])); @@ -972,7 +1002,8 @@ mconvert(struct magic_set *ms, struct magic *m, int flip) case FILE_LELDATE: p->l = (int32_t) ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0])); - cvt_32(p, m); + if (type == FILE_LELONG) + cvt_32(p, m); return 1; case FILE_LEQUAD: case FILE_LEQDATE: @@ -983,14 +1014,16 @@ mconvert(struct magic_set *ms, struct magic *m, int flip) ((uint64_t)p->hq[5]<<40)|((uint64_t)p->hq[4]<<32)| ((uint64_t)p->hq[3]<<24)|((uint64_t)p->hq[2]<<16)| ((uint64_t)p->hq[1]<<8)|((uint64_t)p->hq[0])); - cvt_64(p, m); + if (type == FILE_LEQUAD) + cvt_64(p, m); return 1; case FILE_MELONG: case FILE_MEDATE: case FILE_MELDATE: p->l = (int32_t) ((p->hl[1]<<24)|(p->hl[0]<<16)|(p->hl[3]<<8)|(p->hl[2])); - cvt_32(p, m); + if (type == FILE_MELONG) + cvt_32(p, m); return 1; case FILE_FLOAT: cvt_float(p, m); @@ -1039,7 +1072,7 @@ mconvert(struct magic_set *ms, struct magic *m, int flip) private void mdebug(uint32_t offset, const char *str, size_t len) { - (void) fprintf(stderr, "mget/%zu @%d: ", len, offset); + (void) fprintf(stderr, "mget/%" SIZE_T_FORMAT "u @%d: ", len, offset); file_showstr(stderr, str, len); (void) fputc('\n', stderr); (void) fputc('\n', stderr); @@ -1047,7 +1080,7 @@ mdebug(uint32_t offset, const char *str, size_t len) private int mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, - const unsigned char *s, uint32_t offset, size_t nbytes, size_t linecnt) + const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m) { /* * Note: FILE_SEARCH and FILE_REGEX do not actually copy @@ -1067,15 +1100,29 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, const char *last; /* end of search region */ const char *buf; /* start of search region */ const char *end; - size_t lines; + size_t lines, linecnt, bytecnt; if (s == NULL) { ms->search.s_len = 0; ms->search.s = NULL; return 0; } + + if (m->str_flags & REGEX_LINE_COUNT) { + linecnt = m->str_range; + bytecnt = linecnt * 80; + } else { + linecnt = 0; + bytecnt = m->str_range; + } + + if (bytecnt == 0) + bytecnt = 8192; + if (bytecnt > nbytes) + bytecnt = nbytes; + buf = RCAST(const char *, s) + offset; - end = last = RCAST(const char *, s) + nbytes; + end = last = RCAST(const char *, s) + bytecnt; /* mget() guarantees buf <= last */ for (lines = linecnt, b = buf; lines && b < end && ((b = CAST(const char *, @@ -1088,7 +1135,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, b++; } if (lines) - last = RCAST(const char *, s) + nbytes; + last = RCAST(const char *, s) + bytecnt; ms->search.s = buf; ms->search.s_len = last - buf; @@ -1155,29 +1202,39 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, private int mget(struct magic_set *ms, const unsigned char *s, struct magic *m, size_t nbytes, size_t o, unsigned int cont_level, int mode, int text, - int flip, int recursion_level, int *printed_something, - int *need_separator, int *returnval) + int flip, uint16_t indir_level, uint16_t *name_count, + int *printed_something, int *need_separator, int *returnval) { - uint32_t soffset, offset = ms->offset; - uint32_t count = m->str_range; + uint32_t offset = ms->offset; + uint32_t lhs; + file_pushbuf_t *pb; int rv, oneed_separator, in_type; - char *sbuf, *rbuf; + char *rbuf; union VALUETYPE *p = &ms->ms_value; struct mlist ml; - if (recursion_level >= 20) { - file_error(ms, 0, "recursion nesting exceeded"); + if (indir_level >= ms->indir_max) { + file_error(ms, 0, "indirect recursion nesting (%hu) exceeded", + indir_level); + return -1; + } + + if (*name_count >= ms->name_max) { + file_error(ms, 0, "name use count (%hu) exceeded", + *name_count); return -1; } if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o), - (uint32_t)nbytes, count) == -1) + (uint32_t)nbytes, m) == -1) return -1; if ((ms->flags & MAGIC_DEBUG) != 0) { - fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%zu, " - "nbytes=%zu, count=%u)\n", m->type, m->flag, offset, o, - nbytes, count); + fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%" + SIZE_T_FORMAT "u, " "nbytes=%" SIZE_T_FORMAT + "u, il=%hu, nc=%hu)\n", + m->type, m->flag, offset, o, nbytes, + indir_level, *name_count); mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE)); #ifndef COMPILE_ONLY file_mdump(m); @@ -1262,104 +1319,72 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, case FILE_BESHORT: if (OFFSET_OOB(nbytes, offset, 2)) return 0; + lhs = (p->hs[0] << 8) | p->hs[1]; if (off) { switch (m->in_op & FILE_OPS_MASK) { case FILE_OPAND: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) & - off; + offset = lhs & off; break; case FILE_OPOR: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) | - off; + offset = lhs | off; break; case FILE_OPXOR: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) ^ - off; + offset = lhs ^ off; break; case FILE_OPADD: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) + - off; + offset = lhs + off; break; case FILE_OPMINUS: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) - - off; + offset = lhs - off; break; case FILE_OPMULTIPLY: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) * - off; + offset = lhs * off; break; case FILE_OPDIVIDE: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) / - off; + offset = lhs / off; break; case FILE_OPMODULO: - offset = (short)((p->hs[0]<<8)| - (p->hs[1])) % - off; + offset = lhs % off; break; } } else - offset = (short)((p->hs[0]<<8)| - (p->hs[1])); + offset = lhs; if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; case FILE_LESHORT: if (OFFSET_OOB(nbytes, offset, 2)) return 0; + lhs = (p->hs[1] << 8) | p->hs[0]; if (off) { switch (m->in_op & FILE_OPS_MASK) { case FILE_OPAND: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) & - off; + offset = lhs & off; break; case FILE_OPOR: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) | - off; + offset = lhs | off; break; case FILE_OPXOR: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) ^ - off; + offset = lhs ^ off; break; case FILE_OPADD: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) + - off; + offset = lhs + off; break; case FILE_OPMINUS: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) - - off; + offset = lhs - off; break; case FILE_OPMULTIPLY: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) * - off; + offset = lhs * off; break; case FILE_OPDIVIDE: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) / - off; + offset = lhs / off; break; case FILE_OPMODULO: - offset = (short)((p->hs[1]<<8)| - (p->hs[0])) % - off; + offset = lhs % off; break; } } else - offset = (short)((p->hs[1]<<8)| - (p->hs[0])); + offset = lhs; if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; @@ -1403,70 +1428,37 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, case FILE_BEID3: if (OFFSET_OOB(nbytes, offset, 4)) return 0; + lhs = (p->hl[0] << 24) | (p->hl[1] << 16) | + (p->hl[2] << 8) | p->hl[3]; if (off) { switch (m->in_op & FILE_OPS_MASK) { case FILE_OPAND: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) & - off; + offset = lhs & off; break; case FILE_OPOR: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) | - off; + offset = lhs | off; break; case FILE_OPXOR: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) ^ - off; + offset = lhs ^ off; break; case FILE_OPADD: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) + - off; + offset = lhs + off; break; case FILE_OPMINUS: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) - - off; + offset = lhs - off; break; case FILE_OPMULTIPLY: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) * - off; + offset = lhs * off; break; case FILE_OPDIVIDE: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) / - off; + offset = lhs / off; break; case FILE_OPMODULO: - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])) % - off; + offset = lhs % off; break; } } else - offset = (int32_t)((p->hl[0]<<24)| - (p->hl[1]<<16)| - (p->hl[2]<<8)| - (p->hl[3])); + offset = lhs; if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; @@ -1474,140 +1466,74 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, case FILE_LEID3: if (OFFSET_OOB(nbytes, offset, 4)) return 0; + lhs = (p->hl[3] << 24) | (p->hl[2] << 16) | + (p->hl[1] << 8) | p->hl[0]; if (off) { switch (m->in_op & FILE_OPS_MASK) { case FILE_OPAND: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) & - off; + offset = lhs & off; break; case FILE_OPOR: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) | - off; + offset = lhs | off; break; case FILE_OPXOR: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) ^ - off; + offset = lhs ^ off; break; case FILE_OPADD: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) + - off; + offset = lhs + off; break; case FILE_OPMINUS: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) - - off; + offset = lhs - off; break; case FILE_OPMULTIPLY: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) * - off; + offset = lhs * off; break; case FILE_OPDIVIDE: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) / - off; + offset = lhs / off; break; case FILE_OPMODULO: - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])) % - off; + offset = lhs % off; break; } } else - offset = (int32_t)((p->hl[3]<<24)| - (p->hl[2]<<16)| - (p->hl[1]<<8)| - (p->hl[0])); + offset = lhs; if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; case FILE_MELONG: if (OFFSET_OOB(nbytes, offset, 4)) return 0; + lhs = (p->hl[1] << 24) | (p->hl[0] << 16) | + (p->hl[3] << 8) | p->hl[2]; if (off) { switch (m->in_op & FILE_OPS_MASK) { case FILE_OPAND: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) & - off; + offset = lhs & off; break; case FILE_OPOR: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) | - off; + offset = lhs | off; break; case FILE_OPXOR: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) ^ - off; + offset = lhs ^ off; break; case FILE_OPADD: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) + - off; + offset = lhs + off; break; case FILE_OPMINUS: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) - - off; + offset = lhs - off; break; case FILE_OPMULTIPLY: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) * - off; + offset = lhs * off; break; case FILE_OPDIVIDE: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) / - off; + offset = lhs / off; break; case FILE_OPMODULO: - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])) % - off; + offset = lhs % off; break; } } else - offset = (int32_t)((p->hl[1]<<24)| - (p->hl[0]<<16)| - (p->hl[3]<<8)| - (p->hl[2])); + offset = lhs; if (m->in_op & FILE_OPINVERSE) offset = ~offset; break; @@ -1673,7 +1599,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, if ((ms->flags & MAGIC_DEBUG) != 0) fprintf(stderr, "indirect +offs=%u\n", offset); } - if (mcopy(ms, p, m->type, 0, s, offset, nbytes, count) == -1) + if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1) return -1; ms->offset = offset; @@ -1739,24 +1665,30 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, break; case FILE_INDIRECT: + if (m->str_flags & INDIRECT_RELATIVE) + offset += o; if (offset == 0) return 0; + if (nbytes < offset) return 0; - sbuf = ms->o.buf; - soffset = ms->offset; - ms->o.buf = NULL; - ms->offset = 0; + + if ((pb = file_push_buffer(ms)) == NULL) + return -1; + rv = file_softmagic(ms, s + offset, nbytes - offset, - recursion_level, BINTEST, text); + indir_level + 1, name_count, BINTEST, text); + if ((ms->flags & MAGIC_DEBUG) != 0) fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv); - rbuf = ms->o.buf; - ms->o.buf = sbuf; - ms->offset = soffset; + + rbuf = file_pop_buffer(ms, pb); + if (rbuf == NULL && ms->event_flags & EVENT_HAD_ERR) + return -1; + if (rv == 1) { if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 && - file_printf(ms, F(m->desc, "%u"), offset) == -1) { + file_printf(ms, F(ms, m, "%u"), offset) == -1) { free(rbuf); return -1; } @@ -1771,22 +1703,22 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, case FILE_USE: if (nbytes < offset) return 0; - sbuf = m->value.s; - if (*sbuf == '^') { - sbuf++; + rbuf = m->value.s; + if (*rbuf == '^') { + rbuf++; flip = !flip; } - if (file_magicfind(ms, sbuf, &ml) == -1) { - file_error(ms, 0, "cannot find entry `%s'", sbuf); + if (file_magicfind(ms, rbuf, &ml) == -1) { + file_error(ms, 0, "cannot find entry `%s'", rbuf); return -1; } - + (*name_count)++; oneed_separator = *need_separator; if (m->flag & NOSPACE) *need_separator = 0; rv = match(ms, ml.magic, ml.nmagic, s, nbytes, offset + o, - mode, text, flip, recursion_level, printed_something, - need_separator, returnval); + mode, text, flip, indir_level, name_count, + printed_something, need_separator, returnval); if (rv != 1) *need_separator = oneed_separator; return rv; @@ -1889,7 +1821,6 @@ magiccheck(struct magic_set *ms, struct magic *m) double dl, dv; int matched; union VALUETYPE *p = &ms->ms_value; - char *old_lc_ctype; switch (m->type) { case FILE_BYTE: @@ -1959,7 +1890,6 @@ magiccheck(struct magic_set *ms, struct magic *m) break; default: - matched = 0; file_magerror(ms, "cannot happen with float: invalid relation `%c'", m->reln); return -1; @@ -1993,7 +1923,6 @@ magiccheck(struct magic_set *ms, struct magic *m) break; default: - matched = 0; file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln); return -1; } @@ -2032,7 +1961,8 @@ magiccheck(struct magic_set *ms, struct magic *m) if (slen + idx > ms->search.s_len) break; - v = file_strncmp(m->value.s, ms->search.s + idx, slen, m->str_flags); + v = file_strncmp(m->value.s, ms->search.s + idx, slen, + m->str_flags); if (v == 0) { /* found match */ ms->search.offset += idx; break; @@ -2042,42 +1972,49 @@ magiccheck(struct magic_set *ms, struct magic *m) } case FILE_REGEX: { int rc; - regex_t rx; - char errmsg[512]; + file_regex_t rx; + const char *search; if (ms->search.s == NULL) return 0; - old_lc_ctype = setlocale(LC_CTYPE, NULL); - assert(old_lc_ctype != NULL); - old_lc_ctype = strdup(old_lc_ctype); - assert(old_lc_ctype != NULL); - (void)setlocale(LC_CTYPE, "C"); l = 0; - rc = regcomp(&rx, m->value.s, + rc = file_regcomp(&rx, m->value.s, REG_EXTENDED|REG_NEWLINE| ((m->str_flags & STRING_IGNORE_CASE) ? REG_ICASE : 0)); if (rc) { - (void)regerror(rc, &rx, errmsg, sizeof(errmsg)); - file_magerror(ms, "regex error %d, (%s)", - rc, errmsg); + file_regerror(&rx, rc, ms); v = (uint64_t)-1; - } - else { + } else { regmatch_t pmatch[1]; + size_t slen = ms->search.s_len; #ifndef REG_STARTEND #define REG_STARTEND 0 - size_t l = ms->search.s_len - 1; - char c = ms->search.s[l]; - ((char *)(intptr_t)ms->search.s)[l] = '\0'; + char *copy; + if (slen != 0) { + copy = malloc(slen); + if (copy == NULL) { + file_error(ms, errno, + "can't allocate %" SIZE_T_FORMAT "u bytes", + slen); + return -1; + } + memcpy(copy, ms->search.s, slen); + copy[--slen] = '\0'; + search = copy; + } else { + search = ms->search.s; + copy = NULL; + } #else + search = ms->search.s; pmatch[0].rm_so = 0; - pmatch[0].rm_eo = ms->search.s_len; + pmatch[0].rm_eo = slen; #endif - rc = regexec(&rx, (const char *)ms->search.s, + rc = file_regexec(&rx, (const char *)search, 1, pmatch, REG_STARTEND); #if REG_STARTEND == 0 - ((char *)(intptr_t)ms->search.s)[l] = c; + free(copy); #endif switch (rc) { case 0: @@ -2093,16 +2030,12 @@ magiccheck(struct magic_set *ms, struct magic *m) break; default: - (void)regerror(rc, &rx, errmsg, sizeof(errmsg)); - file_magerror(ms, "regexec error %d, (%s)", - rc, errmsg); + file_regerror(&rx, rc, ms); v = (uint64_t)-1; break; } - regfree(&rx); } - (void)setlocale(LC_CTYPE, old_lc_ctype); - free(old_lc_ctype); + file_regfree(&rx); if (v == (uint64_t)-1) return -1; break; @@ -2199,7 +2132,6 @@ magiccheck(struct magic_set *ms, struct magic *m) break; default: - matched = 0; file_magerror(ms, "cannot happen: invalid relation `%c'", m->reln); return -1; -- 2.41.0 From f01491b5c83693b9c1b8fd41379cfe6daf6ba69f Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 24 Jan 2015 14:56:40 -0800 Subject: [PATCH 09/16] Update files for file-5.22 import. --- lib/libmagic/Makefile | 3 +++ lib/libmagic/config.h | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/libmagic/Makefile b/lib/libmagic/Makefile index 4f6ba3376f..50087563a2 100644 --- a/lib/libmagic/Makefile +++ b/lib/libmagic/Makefile @@ -32,6 +32,9 @@ MLINKS+= libmagic.3 magic_check.3 MLINKS+= libmagic.3 magic_compile.3 MLINKS+= libmagic.3 magic_list.3 MLINKS+= libmagic.3 magic_load.3 +MLINKS+= libmagic.3 magic_load_buffers.3 +MLINKS+= libmagic.3 magic_setparam.3 +MLINKS+= libmagic.3 magic_getparam.3 MLINKS+= libmagic.3 magic_version.3 CLEANFILES+= magic magic.mgc libmagic.3 diff --git a/lib/libmagic/config.h b/lib/libmagic/config.h index 010a572393..0b84672c11 100644 --- a/lib/libmagic/config.h +++ b/lib/libmagic/config.h @@ -45,6 +45,9 @@ /* Define to 1 if you have the `fork' function. */ #define HAVE_FORK 1 +/* Define to 1 if you have the `freelocale' function. */ +#define HAVE_FREELOCALE 1 + /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ #define HAVE_FSEEKO 1 @@ -60,6 +63,9 @@ /* Define to 1 if you have the `getpagesize' function. */ #define HAVE_GETPAGESIZE 1 +/* Define to 1 if the system has the type `intptr_t'. */ +#define HAVE_INTPTR_T 1 + /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 @@ -93,9 +99,15 @@ /* Define to 1 if you have a working `mmap' system call. */ #define HAVE_MMAP 1 +/* Define to 1 if you have the `newlocale' function. */ +#define HAVE_NEWLOCALE 1 + /* Define to 1 if you have the `pread' function. */ #define HAVE_PREAD 1 +/* Define to 1 if you have the `setlocale' function. */ +#define HAVE_SETLOCALE 1 + /* Define to 1 if you have the header file. */ #define HAVE_STDDEF_H 1 @@ -174,9 +186,15 @@ /* HAVE_TZNAME */ #define HAVE_TZNAME 1 +/* Define to 1 if the system has the type `uintptr_t'. */ +#define HAVE_UINTPTR_T 1 + /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 +/* Define to 1 if you have the `uselocale' function. */ +#define HAVE_USELOCALE 1 + /* Define to 1 if you have the `utime' function. */ #define HAVE_UTIME 1 @@ -214,6 +232,9 @@ /* Define to 1 if `vfork' works. */ #define HAVE_WORKING_VFORK 1 +/* Define to 1 if you have the header file. */ +#define HAVE_XLOCALE_H 1 + /* Define to 1 if you have the header file. */ #define HAVE_ZLIB_H 1 @@ -239,7 +260,7 @@ #define PACKAGE_NAME "file" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "file 5.18" +#define PACKAGE_STRING "file 5.22" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "file" @@ -248,7 +269,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "5.18" +#define PACKAGE_VERSION "5.22" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 @@ -279,7 +300,7 @@ /* Version number of package */ -#define VERSION "5.18" +#define VERSION "5.22" /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ @@ -343,6 +364,10 @@ such a type exists and the standard includes do not define it. */ /* #undef int64_t */ +/* Define to the type of a signed integer type wide enough to hold a pointer, + if such a type exists, and if the system does not define it. */ +/* #undef intptr_t */ + /* Define to a type if does not define. */ /* #undef mbstate_t */ @@ -371,5 +396,9 @@ such a type exists and the standard includes do not define it. */ /* #undef uint8_t */ +/* Define to the type of an unsigned integer type wide enough to hold a + pointer, if such a type exists, and if the system does not define it. */ +/* #undef uintptr_t */ + /* Define as `fork' if `vfork' does not work. */ /* #undef vfork */ -- 2.41.0 From 8679cc51cdd04a5e8e3db32820fc0ccd679aa03c Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 24 Jan 2015 15:10:51 -0800 Subject: [PATCH 10/16] rc.d/sshd: Simplify key generation. ssh-keygen(1) already provides the functionality we were previously trying to do here with its -A flag, except now it will reduce the maintenance burden of having to update this file when there are new key types. --- etc/rc.d/sshd | 50 ++------------------------------------------------ 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/etc/rc.d/sshd b/etc/rc.d/sshd index 13f607e5cf..99ab8dfa05 100644 --- a/etc/rc.d/sshd +++ b/etc/rc.d/sshd @@ -19,58 +19,12 @@ extra_commands="keygen reload" sshd_keygen() { - ( - umask 022 - - # Can't do anything if ssh is not installed - [ -x /usr/bin/ssh-keygen ] || { - warn "/usr/bin/ssh-keygen does not exist." - return 1 - } - - if [ -f /etc/ssh/ssh_host_key ]; then - echo "You already have an RSA host key" \ - "in /etc/ssh/ssh_host_key" - echo "Skipping protocol version 1 RSA Key Generation" - else - /usr/bin/ssh-keygen -t rsa1 -b 1024 \ - -f /etc/ssh/ssh_host_key -N '' - fi - - if [ -f /etc/ssh/ssh_host_dsa_key ]; then - echo "You already have a DSA host key" \ - "in /etc/ssh/ssh_host_dsa_key" - echo "Skipping protocol version 2 DSA Key Generation" - else - /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' - fi - - if [ -f /etc/ssh/ssh_host_ecdsa_key ]; then - echo "You already have a ECDSA host key" \ - "in /etc/ssh/ssh_host_ecdsa_key" - echo "Skipping protocol version 2 ECDSA Key Generation" - else - /usr/bin/ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' - fi - - if [ -f /etc/ssh/ssh_host_rsa_key ]; then - echo "You already have a RSA host key" \ - "in /etc/ssh/ssh_host_rsa_key" - echo "Skipping protocol version 2 RSA Key Generation" - else - /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' - fi - ) + /usr/bin/ssh-keygen -A } sshd_precmd() { - if [ ! -f /etc/ssh/ssh_host_key -o \ - ! -f /etc/ssh/ssh_host_dsa_key -o \ - ! -f /etc/ssh/ssh_host_ecdsa_key -o \ - ! -f /etc/ssh/ssh_host_rsa_key ]; then - run_rc_command keygen - fi + run_rc_command keygen } load_rc_config $name -- 2.41.0 From df39a89a5bb4bee1c800692e048b860bb13092a7 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 25 Jan 2015 03:50:33 +0100 Subject: [PATCH 11/16] ssh: Add a missing include for bindresvport_sa(). --- crypto/openssh/sshconnect.c | 1 + 1 file changed, 1 insertion(+) diff --git a/crypto/openssh/sshconnect.c b/crypto/openssh/sshconnect.c index c848c41ce1..7900919f8a 100644 --- a/crypto/openssh/sshconnect.c +++ b/crypto/openssh/sshconnect.c @@ -25,6 +25,7 @@ #include #include +#include #include #include -- 2.41.0 From 68398a5451b1a946e9f72ba8932930051bc4e9e5 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 25 Jan 2015 04:09:47 +0100 Subject: [PATCH 12/16] ssh: Raise WARNS back to 2. --- secure/usr.bin/ssh/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/secure/usr.bin/ssh/Makefile b/secure/usr.bin/ssh/Makefile index 5b872f414b..90d74a4bb2 100644 --- a/secure/usr.bin/ssh/Makefile +++ b/secure/usr.bin/ssh/Makefile @@ -4,7 +4,7 @@ PROG= ssh LINKS= ${BINDIR}/ssh ${BINDIR}/slogin MAN= ssh.1 ssh_config.5 MLINKS= ssh.1 slogin.1 -WARNS?= 0 +WARNS?= 2 SRCS= ssh.c readconf.c clientloop.c sshtty.c \ sshconnect.c sshconnect1.c sshconnect2.c mux.c \ -- 2.41.0 From 158486a6a57db6e82c3f8da282e6d6e37932d133 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Sun, 24 May 2015 08:53:21 +0100 Subject: [PATCH 13/16] drm: Implement and use the Linux version of kfree() --- sys/dev/drm/drm_bufs.c | 2 +- sys/dev/drm/drm_crtc_helper.c | 6 ++--- sys/dev/drm/drm_edid.c | 2 +- sys/dev/drm/drm_fb_helper.c | 2 +- sys/dev/drm/drm_hashtab.c | 2 +- sys/dev/drm/drm_linux_list_sort.c | 2 +- sys/dev/drm/drm_vm.c | 4 +-- sys/dev/drm/i915/i915_dma.c | 8 +++--- sys/dev/drm/i915/i915_gem.c | 6 ++--- sys/dev/drm/i915/i915_gem_context.c | 4 +-- sys/dev/drm/i915/i915_gem_gtt.c | 2 +- sys/dev/drm/i915/intel_crt.c | 4 +-- sys/dev/drm/i915/intel_ddi.c | 6 ++--- sys/dev/drm/i915/intel_display.c | 6 ++--- sys/dev/drm/i915/intel_dp.c | 14 +++++------ sys/dev/drm/i915/intel_fb.c | 4 +-- sys/dev/drm/i915/intel_hdmi.c | 2 +- sys/dev/drm/i915/intel_lvds.c | 12 ++++----- sys/dev/drm/i915/intel_modes.c | 2 +- sys/dev/drm/i915/intel_overlay.c | 10 ++++---- sys/dev/drm/i915/intel_pm.c | 4 +-- sys/dev/drm/i915/intel_ringbuffer.c | 4 +-- sys/dev/drm/i915/intel_sdvo.c | 6 ++--- sys/dev/drm/i915/intel_sprite.c | 6 ++--- sys/dev/drm/i915/intel_tv.c | 4 +-- sys/dev/drm/include/drm/drmP.h | 15 ++--------- sys/dev/drm/include/drm/drm_mem_util.h | 2 +- sys/dev/drm/include/linux/slab.h | 35 ++++++++++++++++++++++++++ sys/dev/drm/include/linux/workqueue.h | 2 +- sys/dev/drm/radeon/radeon_connectors.c | 2 +- sys/dev/drm/radeon/radeon_display.c | 2 +- sys/dev/drm/ttm/ttm_bo.c | 8 +++--- sys/dev/drm/ttm/ttm_bo_manager.c | 4 +-- sys/dev/drm/ttm/ttm_bo_util.c | 2 +- 34 files changed, 110 insertions(+), 86 deletions(-) create mode 100644 sys/dev/drm/include/linux/slab.h diff --git a/sys/dev/drm/drm_bufs.c b/sys/dev/drm/drm_bufs.c index ef4576695d..09e1faba35 100644 --- a/sys/dev/drm/drm_bufs.c +++ b/sys/dev/drm/drm_bufs.c @@ -233,7 +233,7 @@ int drm_addmap(struct drm_device * dev, resource_size_t offset, * need to point to a 64bit variable first. */ dmah = drm_pci_alloc(dev, map->size, map->size); if (!dmah) { - kfree(map, M_DRM); + kfree(map); return -ENOMEM; } map->handle = dmah->vaddr; diff --git a/sys/dev/drm/drm_crtc_helper.c b/sys/dev/drm/drm_crtc_helper.c index 6dd27080d4..03367cac5d 100644 --- a/sys/dev/drm/drm_crtc_helper.c +++ b/sys/dev/drm/drm_crtc_helper.c @@ -787,9 +787,9 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) } } - kfree(save_connectors, M_DRM); - kfree(save_encoders, M_DRM); - kfree(save_crtcs, M_DRM); + kfree(save_connectors); + kfree(save_encoders); + kfree(save_crtcs); return 0; fail: diff --git a/sys/dev/drm/drm_edid.c b/sys/dev/drm/drm_edid.c index 1c0fd56f31..b66e4c122a 100644 --- a/sys/dev/drm/drm_edid.c +++ b/sys/dev/drm/drm_edid.c @@ -1135,7 +1135,7 @@ carp: connector->bad_edid_counter++; out: - kfree(block, M_DRM); + kfree(block); return NULL; } diff --git a/sys/dev/drm/drm_fb_helper.c b/sys/dev/drm/drm_fb_helper.c index cf9879250b..bb8d2d4847 100644 --- a/sys/dev/drm/drm_fb_helper.c +++ b/sys/dev/drm/drm_fb_helper.c @@ -466,7 +466,7 @@ int drm_fb_helper_init(struct drm_device *dev, sizeof(struct drm_fb_helper_connector *), M_DRM, M_WAITOK | M_ZERO); if (!fb_helper->connector_info) { - kfree(fb_helper->crtc_info, M_DRM); + kfree(fb_helper->crtc_info); return -ENOMEM; } fb_helper->connector_count = 0; diff --git a/sys/dev/drm/drm_hashtab.c b/sys/dev/drm/drm_hashtab.c index 55b996e782..bbea5f7008 100644 --- a/sys/dev/drm/drm_hashtab.c +++ b/sys/dev/drm/drm_hashtab.c @@ -198,7 +198,7 @@ EXPORT_SYMBOL(drm_ht_remove_item); void drm_ht_remove(struct drm_open_hash *ht) { if (ht->table) { - kfree(ht->table, M_DRM); + kfree(ht->table); ht->table = NULL; } } diff --git a/sys/dev/drm/drm_linux_list_sort.c b/sys/dev/drm/drm_linux_list_sort.c index 1d24b775f4..1d07cf0a6c 100644 --- a/sys/dev/drm/drm_linux_list_sort.c +++ b/sys/dev/drm/drm_linux_list_sort.c @@ -72,5 +72,5 @@ drm_list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv, INIT_LIST_HEAD(head); for (i = 0; i < count; i++) list_add_tail(ar[i], head); - kfree(ar, M_TEMP); + kfree(ar); } diff --git a/sys/dev/drm/drm_vm.c b/sys/dev/drm/drm_vm.c index 6244370aca..2f01e648a7 100644 --- a/sys/dev/drm/drm_vm.c +++ b/sys/dev/drm/drm_vm.c @@ -201,7 +201,7 @@ vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end, } } mtx_unlock(&vm_phys_fictitious_reg_mtx); - kfree(fp, M_DRM); + kfree(fp); return (EBUSY); } @@ -220,7 +220,7 @@ vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end) fp = seg->first_page; seg->first_page = NULL; mtx_unlock(&vm_phys_fictitious_reg_mtx); - kfree(fp, M_DRM); + kfree(fp); return; } } diff --git a/sys/dev/drm/i915/i915_dma.c b/sys/dev/drm/i915/i915_dma.c index c696eeae10..54c771cca9 100644 --- a/sys/dev/drm/i915/i915_dma.c +++ b/sys/dev/drm/i915/i915_dma.c @@ -657,7 +657,7 @@ static int i915_batchbuffer(struct drm_device *dev, void *data, sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); fail_free: - kfree(cliprects, M_DRM); + kfree(cliprects); return ret; } @@ -1573,7 +1573,7 @@ out_gem_unload: out_mtrrfree: put_bridge: free_priv: - kfree(dev_priv, M_DRM); + kfree(dev_priv); return ret; } @@ -1625,7 +1625,7 @@ int i915_driver_unload(struct drm_device *dev) * config parsed from VBT */ if (dev_priv->child_dev && dev_priv->child_dev_num) { - kfree(dev_priv->child_dev, M_DRM); + kfree(dev_priv->child_dev); dev_priv->child_dev = NULL; dev_priv->child_dev_num = 0; } @@ -1736,7 +1736,7 @@ void i915_driver_postclose(struct drm_device *dev, struct drm_file *file) { struct drm_i915_file_private *file_priv = file->driver_priv; - kfree(file_priv, M_DRM); + kfree(file_priv); } struct drm_ioctl_desc i915_ioctls[] = { diff --git a/sys/dev/drm/i915/i915_gem.c b/sys/dev/drm/i915/i915_gem.c index e02738d81c..edf5db9acf 100644 --- a/sys/dev/drm/i915/i915_gem.c +++ b/sys/dev/drm/i915/i915_gem.c @@ -1646,7 +1646,7 @@ i915_add_request(struct intel_ring_buffer *ring, ret = ring->add_request(ring); if (ret) { - kfree(request, M_DRM); + kfree(request); return ret; } @@ -1809,7 +1809,7 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring) list_del(&request->list); i915_gem_request_remove_from_client(request); - kfree(request, M_DRM); + kfree(request); } /* Move any buffers on the active list that are no longer referenced @@ -3405,7 +3405,7 @@ struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev, return NULL; if (drm_gem_object_init(dev, &obj->base, size) != 0) { - kfree(obj, M_DRM); + kfree(obj); return NULL; } diff --git a/sys/dev/drm/i915/i915_gem_context.c b/sys/dev/drm/i915/i915_gem_context.c index 237af0446a..fed7afd001 100644 --- a/sys/dev/drm/i915/i915_gem_context.c +++ b/sys/dev/drm/i915/i915_gem_context.c @@ -131,7 +131,7 @@ static void do_destroy(struct i915_hw_context *ctx) idr_remove(&ctx->file_priv->context_idr, ctx->id); drm_gem_object_unreference(&ctx->obj->base); - kfree(ctx, M_DRM); + kfree(ctx); } static struct i915_hw_context * @@ -148,7 +148,7 @@ create_hw_context(struct drm_device *dev, ctx->obj = i915_gem_alloc_object(dev, dev_priv->hw_context_size); if (ctx->obj == NULL) { - kfree(ctx, M_DRM); + kfree(ctx); DRM_DEBUG_DRIVER("Context object allocated failed\n"); return ERR_PTR(-ENOMEM); } diff --git a/sys/dev/drm/i915/i915_gem_gtt.c b/sys/dev/drm/i915/i915_gem_gtt.c index 21105f950d..88df8f8a5f 100644 --- a/sys/dev/drm/i915/i915_gem_gtt.c +++ b/sys/dev/drm/i915/i915_gem_gtt.c @@ -234,7 +234,7 @@ static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev) ret = gen6_ppgtt_init(ppgtt); if (ret) - kfree(ppgtt, M_DRM); + kfree(ppgtt); else dev_priv->mm.aliasing_ppgtt = ppgtt; diff --git a/sys/dev/drm/i915/intel_crt.c b/sys/dev/drm/i915/intel_crt.c index 8886d4da29..601e0b6436 100644 --- a/sys/dev/drm/i915/intel_crt.c +++ b/sys/dev/drm/i915/intel_crt.c @@ -410,7 +410,7 @@ static int intel_crt_ddc_get_modes(struct drm_connector *connector, return 0; ret = intel_connector_update_modes(connector, edid); - kfree(edid, M_DRM); + kfree(edid); return ret; } @@ -735,7 +735,7 @@ void intel_crt_init(struct drm_device *dev) intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, M_WAITOK | M_ZERO); if (!intel_connector) { - kfree(crt, M_DRM); + kfree(crt); return; } diff --git a/sys/dev/drm/i915/intel_ddi.c b/sys/dev/drm/i915/intel_ddi.c index f3ea7a20c0..83a3fda0ed 100644 --- a/sys/dev/drm/i915/intel_ddi.c +++ b/sys/dev/drm/i915/intel_ddi.c @@ -1510,7 +1510,7 @@ void intel_ddi_init(struct drm_device *dev, enum port port) dp_connector = kmalloc(sizeof(struct intel_connector), M_DRM, M_WAITOK | M_ZERO); if (!dp_connector) { - kfree(intel_dig_port, M_DRM); + kfree(intel_dig_port); return; } @@ -1518,8 +1518,8 @@ void intel_ddi_init(struct drm_device *dev, enum port port) hdmi_connector = kmalloc(sizeof(struct intel_connector), M_DRM, M_WAITOK | M_ZERO); if (!hdmi_connector) { - kfree(dp_connector, M_DRM); - kfree(intel_dig_port, M_DRM); + kfree(dp_connector); + kfree(intel_dig_port); return; } } diff --git a/sys/dev/drm/i915/intel_display.c b/sys/dev/drm/i915/intel_display.c index 63a3be9a13..729290acb7 100644 --- a/sys/dev/drm/i915/intel_display.c +++ b/sys/dev/drm/i915/intel_display.c @@ -6514,7 +6514,7 @@ intel_framebuffer_create(struct drm_device *dev, ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); if (ret) { drm_gem_object_unreference_unlocked(&obj->base); - kfree(intel_fb, M_DRM); + kfree(intel_fb); return ERR_PTR(ret); } @@ -6959,7 +6959,7 @@ static void intel_crtc_destroy(struct drm_crtc *crtc) if (work) { cancel_work_sync(&work->work); - kfree(work, M_DRM); + kfree(work); } drm_crtc_cleanup(crtc); @@ -7906,7 +7906,7 @@ done: } out: - kfree(saved_mode, M_DRM); + kfree(saved_mode); return ret; } diff --git a/sys/dev/drm/i915/intel_dp.c b/sys/dev/drm/i915/intel_dp.c index caa4e95145..766c0894d6 100644 --- a/sys/dev/drm/i915/intel_dp.c +++ b/sys/dev/drm/i915/intel_dp.c @@ -2395,7 +2395,7 @@ intel_dp_detect(struct drm_connector *connector, bool force) edid = intel_dp_get_edid(connector, intel_dp->adapter); if (edid) { intel_dp->has_audio = drm_detect_monitor_audio(edid); - kfree(edid, M_DRM); + kfree(edid); } } @@ -2441,7 +2441,7 @@ intel_dp_detect_audio(struct drm_connector *connector) edid = intel_dp_get_edid(connector, intel_dp->adapter); if (edid) { has_audio = drm_detect_monitor_audio(edid); - kfree(edid, M_DRM); + kfree(edid); } return has_audio; @@ -2534,7 +2534,7 @@ intel_dp_destroy(struct drm_connector *connector) struct intel_connector *intel_connector = to_intel_connector(connector); if (!IS_ERR_OR_NULL(intel_connector->edid)) - kfree(intel_connector->edid, M_DRM); + kfree(intel_connector->edid); if (is_edp(intel_dp)) intel_panel_fini(&intel_connector->panel); @@ -2543,7 +2543,7 @@ intel_dp_destroy(struct drm_connector *connector) drm_sysfs_connector_remove(connector); #endif drm_connector_cleanup(connector); - kfree(connector, M_DRM); + kfree(connector); } void intel_dp_encoder_destroy(struct drm_encoder *encoder) @@ -2566,7 +2566,7 @@ void intel_dp_encoder_destroy(struct drm_encoder *encoder) ironlake_panel_vdd_off_sync(intel_dp); mutex_unlock(&dev->mode_config.mutex); } - kfree(intel_dig_port, M_DRM); + kfree(intel_dig_port); } static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { @@ -2906,7 +2906,7 @@ intel_dp_init_connector(struct intel_digital_port *intel_dig_port, drm_mode_connector_update_edid_property(connector, edid); drm_edid_to_eld(connector, edid); } else { - kfree(edid, M_DRM); + kfree(edid); edid = ERR_PTR(-EINVAL); } } else { @@ -2965,7 +2965,7 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port) intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, M_WAITOK | M_ZERO); if (!intel_connector) { - kfree(intel_dig_port, M_DRM); + kfree(intel_dig_port); return; } diff --git a/sys/dev/drm/i915/intel_fb.c b/sys/dev/drm/i915/intel_fb.c index 9391ab5bf4..e313151777 100644 --- a/sys/dev/drm/i915/intel_fb.c +++ b/sys/dev/drm/i915/intel_fb.c @@ -237,7 +237,7 @@ int intel_fbdev_init(struct drm_device *dev) dev_priv->num_pipe, INTELFB_CONN_LIMIT); if (ret) { - kfree(ifbdev, M_DRM); + kfree(ifbdev); return ret; } @@ -262,7 +262,7 @@ void intel_fbdev_fini(struct drm_device *dev) return; intel_fbdev_destroy(dev, dev_priv->fbdev); - kfree(dev_priv->fbdev, M_DRM); + kfree(dev_priv->fbdev); dev_priv->fbdev = NULL; } diff --git a/sys/dev/drm/i915/intel_hdmi.c b/sys/dev/drm/i915/intel_hdmi.c index 4ee3c8e807..9a2b581a41 100644 --- a/sys/dev/drm/i915/intel_hdmi.c +++ b/sys/dev/drm/i915/intel_hdmi.c @@ -1067,7 +1067,7 @@ void intel_hdmi_init(struct drm_device *dev, int sdvox_reg, enum port port) intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, M_WAITOK | M_ZERO); if (!intel_connector) { - kfree(intel_dig_port, M_DRM); + kfree(intel_dig_port); return; } diff --git a/sys/dev/drm/i915/intel_lvds.c b/sys/dev/drm/i915/intel_lvds.c index f49644bf58..62eee29fdc 100644 --- a/sys/dev/drm/i915/intel_lvds.c +++ b/sys/dev/drm/i915/intel_lvds.c @@ -618,7 +618,7 @@ static void intel_lvds_destroy(struct drm_connector *connector) #endif if (!IS_ERR_OR_NULL(lvds_connector->base.edid)) - kfree(lvds_connector->base.edid, M_DRM); + kfree(lvds_connector->base.edid); intel_panel_fini(&lvds_connector->base.panel); @@ -626,7 +626,7 @@ static void intel_lvds_destroy(struct drm_connector *connector) drm_sysfs_connector_remove(connector); #endif drm_connector_cleanup(connector); - kfree(connector, M_DRM); + kfree(connector); } static int intel_lvds_set_property(struct drm_connector *connector, @@ -1092,7 +1092,7 @@ bool intel_lvds_init(struct drm_device *dev) lvds_connector = kmalloc(sizeof(struct intel_lvds_connector), M_DRM, M_WAITOK | M_ZERO); if (!lvds_connector) { - kfree(lvds_encoder, M_DRM); + kfree(lvds_encoder); return false; } @@ -1168,7 +1168,7 @@ bool intel_lvds_init(struct drm_device *dev) drm_mode_connector_update_edid_property(connector, edid); } else { - kfree(edid, M_DRM); + kfree(edid); edid = ERR_PTR(-EINVAL); } } else { @@ -1277,7 +1277,7 @@ failed: drm_encoder_cleanup(encoder); if (fixed_mode) drm_mode_destroy(dev, fixed_mode); - kfree(lvds_encoder, M_DRM); - kfree(lvds_connector, M_DRM); + kfree(lvds_encoder); + kfree(lvds_connector); return false; } diff --git a/sys/dev/drm/i915/intel_modes.c b/sys/dev/drm/i915/intel_modes.c index 94af089176..5d2702cbde 100644 --- a/sys/dev/drm/i915/intel_modes.c +++ b/sys/dev/drm/i915/intel_modes.c @@ -64,7 +64,7 @@ int intel_ddc_get_modes(struct drm_connector *connector, return 0; ret = intel_connector_update_modes(connector, edid); - kfree(edid, M_DRM); + kfree(edid); return ret; } diff --git a/sys/dev/drm/i915/intel_overlay.c b/sys/dev/drm/i915/intel_overlay.c index c7bb232488..cc1f3cb20c 100644 --- a/sys/dev/drm/i915/intel_overlay.c +++ b/sys/dev/drm/i915/intel_overlay.c @@ -1160,7 +1160,7 @@ int intel_overlay_put_image(struct drm_device *dev, void *data, mutex_unlock(&dev->struct_mutex); drm_modeset_unlock_all(dev); - kfree(params, M_DRM); + kfree(params); return 0; @@ -1169,7 +1169,7 @@ out_unlock: drm_modeset_unlock_all(dev); drm_gem_object_unreference_unlocked(&new_bo->base); out_free: - kfree(params, M_DRM); + kfree(params); return ret; } @@ -1392,7 +1392,7 @@ out_free_bo: drm_gem_object_unreference(®_bo->base); out_free: mutex_unlock(&dev->struct_mutex); - kfree(overlay, M_DRM); + kfree(overlay); return; } @@ -1409,7 +1409,7 @@ void intel_cleanup_overlay(struct drm_device *dev) BUG_ON(dev_priv->overlay->active); drm_gem_object_unreference_unlocked(&dev_priv->overlay->reg_bo->base); - kfree(dev_priv->overlay, M_DRM); + kfree(dev_priv->overlay); } #ifdef CONFIG_DEBUG_FS @@ -1480,7 +1480,7 @@ intel_overlay_capture_error_state(struct drm_device *dev) return error; err: - kfree(error, M_DRM); + kfree(error); return NULL; } diff --git a/sys/dev/drm/i915/intel_pm.c b/sys/dev/drm/i915/intel_pm.c index b2bc61f77b..f63e51b980 100644 --- a/sys/dev/drm/i915/intel_pm.c +++ b/sys/dev/drm/i915/intel_pm.c @@ -288,7 +288,7 @@ static void intel_fbc_work_fn(struct work_struct *__work) } mutex_unlock(&dev->struct_mutex); - kfree(work, M_DRM); + kfree(work); } static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) @@ -304,7 +304,7 @@ static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) */ if (cancel_delayed_work(&dev_priv->fbc_work->work)) /* tasklet was killed before being run, clean up */ - kfree(dev_priv->fbc_work, M_DRM); + kfree(dev_priv->fbc_work); /* Mark the work as no longer wanted so that if it does * wake-up (because the work was already running and waiting diff --git a/sys/dev/drm/i915/intel_ringbuffer.c b/sys/dev/drm/i915/intel_ringbuffer.c index a2f1f4aee4..39fd071dac 100644 --- a/sys/dev/drm/i915/intel_ringbuffer.c +++ b/sys/dev/drm/i915/intel_ringbuffer.c @@ -483,7 +483,7 @@ err_unpin: err_unref: drm_gem_object_unreference(&obj->base); err: - kfree(pc, M_DRM); + kfree(pc); return ret; } @@ -503,7 +503,7 @@ cleanup_pipe_control(struct intel_ring_buffer *ring) i915_gem_object_unpin(obj); drm_gem_object_unreference(&obj->base); - kfree(pc, M_DRM); + kfree(pc); ring->private = NULL; } diff --git a/sys/dev/drm/i915/intel_sdvo.c b/sys/dev/drm/i915/intel_sdvo.c index e632385a7a..b2d297a30f 100644 --- a/sys/dev/drm/i915/intel_sdvo.c +++ b/sys/dev/drm/i915/intel_sdvo.c @@ -1595,7 +1595,7 @@ intel_sdvo_detect(struct drm_connector *connector, bool force) else ret = connector_status_disconnected; - kfree(edid, M_DRM); + kfree(edid); } else ret = connector_status_connected; } @@ -2824,7 +2824,7 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob) intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, intel_sdvo) >> 1; intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo, sdvo_reg); if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev, sdvo_reg)) { - kfree(intel_sdvo, M_DRM); + kfree(intel_sdvo); return false; } @@ -2925,7 +2925,7 @@ err_output: err: drm_encoder_cleanup(&intel_encoder->base); intel_sdvo_unselect_i2c_bus(intel_sdvo); - kfree(intel_sdvo, M_DRM); + kfree(intel_sdvo); return false; } diff --git a/sys/dev/drm/i915/intel_sprite.c b/sys/dev/drm/i915/intel_sprite.c index 95baf510e8..6347181dd1 100644 --- a/sys/dev/drm/i915/intel_sprite.c +++ b/sys/dev/drm/i915/intel_sprite.c @@ -582,7 +582,7 @@ static void intel_destroy_plane(struct drm_plane *plane) struct intel_plane *intel_plane = to_intel_plane(plane); intel_disable_plane(plane); drm_plane_cleanup(plane); - kfree(intel_plane, M_DRM); + kfree(intel_plane); } int intel_sprite_set_colorkey(struct drm_device *dev, void *data, @@ -722,7 +722,7 @@ intel_plane_init(struct drm_device *dev, enum i915_pipe pipe) break; default: - kfree(intel_plane, M_DRM); + kfree(intel_plane); return -ENODEV; } @@ -733,7 +733,7 @@ intel_plane_init(struct drm_device *dev, enum i915_pipe pipe) plane_formats, num_plane_formats, false); if (ret) - kfree(intel_plane, M_DRM); + kfree(intel_plane); return ret; } diff --git a/sys/dev/drm/i915/intel_tv.c b/sys/dev/drm/i915/intel_tv.c index b7ee87a789..5e19217edb 100644 --- a/sys/dev/drm/i915/intel_tv.c +++ b/sys/dev/drm/i915/intel_tv.c @@ -1430,7 +1430,7 @@ intel_tv_destroy(struct drm_connector *connector) drm_sysfs_connector_remove(connector); #endif drm_connector_cleanup(connector); - kfree(connector, M_DRM); + kfree(connector); } @@ -1598,7 +1598,7 @@ intel_tv_init(struct drm_device *dev) intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, M_WAITOK | M_ZERO); if (!intel_connector) { - kfree(intel_tv, M_DRM); + kfree(intel_tv); return; } diff --git a/sys/dev/drm/include/drm/drmP.h b/sys/dev/drm/include/drm/drmP.h index d0578c39fb..4bb7b6f80c 100644 --- a/sys/dev/drm/include/drm/drmP.h +++ b/sys/dev/drm/include/drm/drmP.h @@ -107,6 +107,7 @@ MALLOC_DECLARE(M_DRM); #include #include #include +#include #include #include #include @@ -1541,22 +1542,10 @@ drm_calloc(size_t nmemb, size_t size, struct malloc_type *area) return kmalloc(size * nmemb, area, M_WAITOK | M_NULLOK | M_ZERO); } -static __inline__ void * -drm_realloc(void *oldpt, size_t oldsize, size_t size, - struct malloc_type *area) -{ - void *res; - res = krealloc(oldpt, size, area, M_WAITOK | M_NULLOK); - if (res == NULL && oldpt != NULL) - kfree(oldpt,area); - return res; -} - static __inline__ void drm_free(void *pt, struct malloc_type *area) { - if (pt != NULL) - kfree(pt, area); + kfree(pt); } /* Inline replacements for DRM_IOREMAP macros */ diff --git a/sys/dev/drm/include/drm/drm_mem_util.h b/sys/dev/drm/include/drm/drm_mem_util.h index 46bca01d3e..3adf183e8a 100644 --- a/sys/dev/drm/include/drm/drm_mem_util.h +++ b/sys/dev/drm/include/drm/drm_mem_util.h @@ -49,7 +49,7 @@ static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size) static __inline void drm_free_large(void *ptr) { - kfree(ptr, M_DRM); + kfree(ptr); } #endif diff --git a/sys/dev/drm/include/linux/slab.h b/sys/dev/drm/include/linux/slab.h new file mode 100644 index 0000000000..4053d4d6e6 --- /dev/null +++ b/sys/dev/drm/include/linux/slab.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 François Tigeot + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LINUX_SLAB_H_ +#define _LINUX_SLAB_H_ + +#define kfree(ptr) do { \ + if (ptr != NULL) \ + kfree(ptr, M_DRM); \ +} while (0) + +#endif /* _LINUX_SLAB_H_ */ diff --git a/sys/dev/drm/include/linux/workqueue.h b/sys/dev/drm/include/linux/workqueue.h index 90e59b5ee9..c5f82fcd85 100644 --- a/sys/dev/drm/include/linux/workqueue.h +++ b/sys/dev/drm/include/linux/workqueue.h @@ -163,7 +163,7 @@ static inline void destroy_workqueue(struct workqueue_struct *wq) { taskqueue_free(wq->taskqueue); - kfree(wq, M_DRM); + kfree(wq); } #define flush_workqueue(wq) flush_taskqueue((wq)->taskqueue) diff --git a/sys/dev/drm/radeon/radeon_connectors.c b/sys/dev/drm/radeon/radeon_connectors.c index 7fc287c6e1..4baddc43c4 100644 --- a/sys/dev/drm/radeon/radeon_connectors.c +++ b/sys/dev/drm/radeon/radeon_connectors.c @@ -1876,7 +1876,7 @@ radeon_add_atom_connector(struct drm_device *dev, failed: drm_connector_cleanup(connector); - kfree(connector, M_DRM); + kfree(connector); } void diff --git a/sys/dev/drm/radeon/radeon_display.c b/sys/dev/drm/radeon/radeon_display.c index a7104e3f80..5cec7e31a9 100644 --- a/sys/dev/drm/radeon/radeon_display.c +++ b/sys/dev/drm/radeon/radeon_display.c @@ -1124,7 +1124,7 @@ radeon_user_framebuffer_create(struct drm_device *dev, ret = radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj); if (ret) { - kfree(radeon_fb, M_DRM); + kfree(radeon_fb); drm_gem_object_unreference_unlocked(obj); return ERR_PTR(ret); } diff --git a/sys/dev/drm/ttm/ttm_bo.c b/sys/dev/drm/ttm/ttm_bo.c index 66adfc078b..6a0336e235 100644 --- a/sys/dev/drm/ttm/ttm_bo.c +++ b/sys/dev/drm/ttm/ttm_bo.c @@ -128,7 +128,7 @@ static void ttm_bo_release_list(struct kref *list_kref) if (bo->destroy) bo->destroy(bo); else { - kfree(bo, M_DRM); + kfree(bo); } ttm_mem_global_free(bdev->glob->mem_glob, acc_size); } @@ -1256,7 +1256,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev, if (destroy) (*destroy)(bo); else - kfree(bo, M_DRM); + kfree(bo); return -ENOMEM; } @@ -1266,7 +1266,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev, if (destroy) (*destroy)(bo); else - kfree(bo, M_DRM); + kfree(bo); ttm_mem_global_free(mem_glob, acc_size); return -EINVAL; } @@ -1565,7 +1565,7 @@ out_no_shrink: vm_page_free(glob->dummy_read_page); */ out_no_drp: - kfree(glob, M_DRM); + kfree(glob); return ret; } EXPORT_SYMBOL(ttm_bo_global_init); diff --git a/sys/dev/drm/ttm/ttm_bo_manager.c b/sys/dev/drm/ttm/ttm_bo_manager.c index c88e715d7f..4cb6e1c58a 100644 --- a/sys/dev/drm/ttm/ttm_bo_manager.c +++ b/sys/dev/drm/ttm/ttm_bo_manager.c @@ -111,7 +111,7 @@ static int ttm_bo_man_init(struct ttm_mem_type_manager *man, ret = drm_mm_init(&rman->mm, 0, p_size); if (ret) { - kfree(rman, M_DRM); + kfree(rman); return ret; } @@ -129,7 +129,7 @@ static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man) if (drm_mm_clean(mm)) { drm_mm_takedown(mm); lockmgr(&rman->lock, LK_RELEASE); - kfree(rman, M_DRM); + kfree(rman); man->priv = NULL; return 0; } diff --git a/sys/dev/drm/ttm/ttm_bo_util.c b/sys/dev/drm/ttm/ttm_bo_util.c index f7cea75f76..51354e5ef4 100644 --- a/sys/dev/drm/ttm/ttm_bo_util.c +++ b/sys/dev/drm/ttm/ttm_bo_util.c @@ -379,7 +379,7 @@ EXPORT_SYMBOL(ttm_bo_move_memcpy); static void ttm_transfered_destroy(struct ttm_buffer_object *bo) { - kfree(bo, M_DRM); + kfree(bo); } /** -- 2.41.0 From 372f6e60d8b5056a2cf692df7645fce9b3b69fc9 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 25 Jan 2015 13:54:27 +0100 Subject: [PATCH 14/16] file(1): Unbreak buildworld. The issue is the missing definition of wchar_t in (required by POSIX too) which file(1) winds up needing because of new code in this version. The commit 3e581a72263dd3b726387b5dc2399a066511099f fixes it correctly but mkmagic.nx is a build-tool and so uses host includes (which don't have that fix yet at this point). I see no other way to fix this easily right now than just including . This has a wchar_t definition, too. Reported-by: Robin Hahling --- contrib/file/src/file.h | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/file/src/file.h b/contrib/file/src/file.h index 01aa37a6b9..c0c7458df0 100644 --- a/contrib/file/src/file.h +++ b/contrib/file/src/file.h @@ -70,6 +70,7 @@ /* Do this here and now, because struct stat gets re-defined on solaris */ #include #include +#include #define ENABLE_CONDITIONALS -- 2.41.0 From 580564c977f204ff746acc026351c0ee70a04b56 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 25 Jan 2015 19:33:15 +0100 Subject: [PATCH 15/16] libssh: Silence some redefinition warnings. Taken-from: FreeBSD Submitted-by: Robin Hahling --- crypto/openssh/umac128.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crypto/openssh/umac128.c b/crypto/openssh/umac128.c index 52f9173d7c..628fcf64d2 100644 --- a/crypto/openssh/umac128.c +++ b/crypto/openssh/umac128.c @@ -1,6 +1,13 @@ +/* $FreeBSD: head/crypto/openssh/umac128.c 255767 2013-09-21 21:36:09Z des $ */ #define UMAC_OUTPUT_LEN 16 +#undef umac_ctx +#define umac_ctx umac128_ctx +#undef umac_new #define umac_new umac128_new +#undef umac_update #define umac_update umac128_update +#undef umac_final #define umac_final umac128_final +#undef umac_delete #define umac_delete umac128_delete #include "umac.c" -- 2.41.0 From 9be608cb62307f2d282421fd95f1c0cb5dacca57 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 25 Jan 2015 20:03:55 +0100 Subject: [PATCH 16/16] libssh: Fix a remaining warning and raise WARNS to 2. --- crypto/openssh/cipher-ctr-mt.c | 2 +- secure/lib/libssh/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/openssh/cipher-ctr-mt.c b/crypto/openssh/cipher-ctr-mt.c index c13ddf0a7f..238b53c132 100644 --- a/crypto/openssh/cipher-ctr-mt.c +++ b/crypto/openssh/cipher-ctr-mt.c @@ -285,7 +285,7 @@ thread_loop(void *x) static int ssh_aes_ctr(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, - u_int len) + LIBCRYPTO_EVP_INL_TYPE len) { struct ssh_aes_ctr_ctx *c; struct kq *q, *oldq; diff --git a/secure/lib/libssh/Makefile b/secure/lib/libssh/Makefile index 57c1a48ae9..6bd31884d6 100644 --- a/secure/lib/libssh/Makefile +++ b/secure/lib/libssh/Makefile @@ -27,7 +27,7 @@ SRCS+= bcrypt_pbkdf.c blowfish.c bsd-misc.c explicit_bzero.c \ MAN= moduli.5 -WARNS?= 0 +WARNS?= 2 .include "../../Makefile.ssh.common" .include -- 2.41.0