summaryrefslogtreecommitdiff
path: root/usr.bin/file
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2009-04-24 18:54:35 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2009-04-24 18:54:35 +0000
commit8dcb5d1d2940d843dabdcef31bc8cb2dba817119 (patch)
tree7458bf3b9120705a836b9e56b7925dce2cf42159 /usr.bin/file
parenta75d7de4707e3d43e0e869059021172cadecca54 (diff)
file update to 4.24
The '-i' switch is now enabled so file(1) can output mime type strings. ok ian@ builk ports build test on amd64 by jasper@ ok ray@ gilles@ on a almost identical diff builk ports build test on sparc64 on this almost identical diff by ajacoutot@ also tested by landry@
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/MAINT5
-rw-r--r--usr.bin/file/README15
-rw-r--r--usr.bin/file/apprentice.c543
-rw-r--r--usr.bin/file/ascmagic.c225
-rw-r--r--usr.bin/file/compress.c36
-rw-r--r--usr.bin/file/config.h5
-rw-r--r--usr.bin/file/elfclass.h67
-rw-r--r--usr.bin/file/file.c214
-rw-r--r--usr.bin/file/file.h86
-rw-r--r--usr.bin/file/file_opts.h48
-rw-r--r--usr.bin/file/fsmagic.c70
-rw-r--r--usr.bin/file/funcs.c228
-rw-r--r--usr.bin/file/is_tar.c44
-rw-r--r--usr.bin/file/magdir/acorn37
-rw-r--r--usr.bin/file/magdir/adventure12
-rw-r--r--usr.bin/file/magdir/animation348
-rw-r--r--usr.bin/file/magdir/apple73
-rw-r--r--usr.bin/file/magdir/archive81
-rw-r--r--usr.bin/file/magdir/audio96
-rw-r--r--usr.bin/file/magdir/blender50
-rw-r--r--usr.bin/file/magdir/c-lang14
-rw-r--r--usr.bin/file/magdir/cafebabe18
-rw-r--r--usr.bin/file/magdir/cddb4
-rw-r--r--usr.bin/file/magdir/clarion26
-rw-r--r--usr.bin/file/magdir/commands38
-rw-r--r--usr.bin/file/magdir/compress41
-rw-r--r--usr.bin/file/magdir/console63
-rw-r--r--usr.bin/file/magdir/cracklib4
-rw-r--r--usr.bin/file/magdir/ctags4
-rw-r--r--usr.bin/file/magdir/database36
-rw-r--r--usr.bin/file/magdir/diff12
-rw-r--r--usr.bin/file/magdir/dump40
-rw-r--r--usr.bin/file/magdir/efi14
-rw-r--r--usr.bin/file/magdir/elf85
-rw-r--r--usr.bin/file/magdir/erlang18
-rw-r--r--usr.bin/file/magdir/filesystems319
-rw-r--r--usr.bin/file/magdir/flash5
-rw-r--r--usr.bin/file/magdir/fonts10
-rw-r--r--usr.bin/file/magdir/fortran3
-rw-r--r--usr.bin/file/magdir/frame15
-rw-r--r--usr.bin/file/magdir/fsav12
-rw-r--r--usr.bin/file/magdir/games20
-rw-r--r--usr.bin/file/magdir/gnome-keyring23
-rw-r--r--usr.bin/file/magdir/gnu6
-rw-r--r--usr.bin/file/magdir/gnumeric7
-rw-r--r--usr.bin/file/magdir/hp78
-rw-r--r--usr.bin/file/magdir/iff5
-rw-r--r--usr.bin/file/magdir/images96
-rw-r--r--usr.bin/file/magdir/inform8
-rw-r--r--usr.bin/file/magdir/java17
-rw-r--r--usr.bin/file/magdir/jpeg8
-rw-r--r--usr.bin/file/magdir/kde10
-rw-r--r--usr.bin/file/magdir/lex10
-rw-r--r--usr.bin/file/magdir/linux20
-rw-r--r--usr.bin/file/magdir/lisp24
-rw-r--r--usr.bin/file/magdir/llvm10
-rw-r--r--usr.bin/file/magdir/lua15
-rw-r--r--usr.bin/file/magdir/luks12
-rw-r--r--usr.bin/file/magdir/macintosh136
-rw-r--r--usr.bin/file/magdir/mail.news15
-rw-r--r--usr.bin/file/magdir/mathcad7
-rw-r--r--usr.bin/file/magdir/mathematica5
-rw-r--r--usr.bin/file/magdir/mercurial12
-rw-r--r--usr.bin/file/magdir/misctools7
-rw-r--r--usr.bin/file/magdir/mozilla8
-rw-r--r--usr.bin/file/magdir/msdos153
-rw-r--r--usr.bin/file/magdir/mup4
-rw-r--r--usr.bin/file/magdir/netware6
-rw-r--r--usr.bin/file/magdir/ole2compounddocs13
-rw-r--r--usr.bin/file/magdir/os26
-rw-r--r--usr.bin/file/magdir/palm4
-rw-r--r--usr.bin/file/magdir/pdf9
-rw-r--r--usr.bin/file/magdir/perl49
-rw-r--r--usr.bin/file/magdir/pgp25
-rw-r--r--usr.bin/file/magdir/pkgadd3
-rw-r--r--usr.bin/file/magdir/printer25
-rw-r--r--usr.bin/file/magdir/revision12
-rw-r--r--usr.bin/file/magdir/riff6
-rw-r--r--usr.bin/file/magdir/rpm5
-rw-r--r--usr.bin/file/magdir/rtf15
-rw-r--r--usr.bin/file/magdir/sc3
-rw-r--r--usr.bin/file/magdir/scientific14
-rw-r--r--usr.bin/file/magdir/securitycerts3
-rw-r--r--usr.bin/file/magdir/sgi27
-rw-r--r--usr.bin/file/magdir/sgml48
-rw-r--r--usr.bin/file/magdir/sharc10
-rw-r--r--usr.bin/file/magdir/sketch4
-rw-r--r--usr.bin/file/magdir/softquad11
-rw-r--r--usr.bin/file/magdir/spectrum13
-rw-r--r--usr.bin/file/magdir/tex61
-rw-r--r--usr.bin/file/magdir/troff39
-rw-r--r--usr.bin/file/magdir/unicode8
-rw-r--r--usr.bin/file/magdir/uuencode16
-rw-r--r--usr.bin/file/magdir/varied.script8
-rw-r--r--usr.bin/file/magdir/vorbis28
-rw-r--r--usr.bin/file/magdir/wordprocessors31
-rw-r--r--usr.bin/file/magdir/xilinx34
-rw-r--r--usr.bin/file/magic.c87
-rw-r--r--usr.bin/file/magic.h30
-rw-r--r--usr.bin/file/names.h57
-rw-r--r--usr.bin/file/patchlevel.h28
-rw-r--r--usr.bin/file/print.c26
-rw-r--r--usr.bin/file/readelf.c328
-rw-r--r--usr.bin/file/readelf.h16
-rw-r--r--usr.bin/file/softmagic.c367
-rw-r--r--usr.bin/file/tar.h66
106 files changed, 3586 insertions, 1735 deletions
diff --git a/usr.bin/file/MAINT b/usr.bin/file/MAINT
index 5749949e828..a7079c4b41f 100644
--- a/usr.bin/file/MAINT
+++ b/usr.bin/file/MAINT
@@ -1,4 +1,4 @@
-$OpenBSD: MAINT,v 1.4 2008/05/08 01:40:56 chl Exp $
+$OpenBSD: MAINT,v 1.5 2009/04/24 18:54:34 chl Exp $
Maintenance notes:
@@ -41,5 +41,4 @@ ascmagic.c file_ascmagic()
readelf.c file_tryelf()
"unknown"
-Christos Zoulas
-christos@astron.com
+Christos Zoulas (see README for email address)
diff --git a/usr.bin/file/README b/usr.bin/file/README
index e26ac69101f..0fada4f9f4f 100644
--- a/usr.bin/file/README
+++ b/usr.bin/file/README
@@ -1,5 +1,10 @@
-@(#) $OpenBSD: README,v 1.4 2008/05/08 01:40:56 chl Exp $
** README for file(1) Command **
+@(#) $OpenBSD: README,v 1.5 2009/04/24 18:54:34 chl Exp $
+
+E-mail: christos@astron.com
+Mailing List: file@mx.gw.com
+
+Phone: Do not even think of telephoning me about this program. Send cash first!
This is Release 4.x of Ian Darwin's (copyright but distributable)
file(1) command. This version is the standard "file" command for Linux,
@@ -71,6 +76,10 @@ readelf.[ch] - Stand-alone elf parsing code.
compress.c - on-the-fly decompression.
print.c - print results, errors, warnings.
+You can download the latest version of file from:
+
+ ftp://ftp.astron.com/pub/file/
+
If your gzip sometimes fails to decompress things complaining about a short
file, apply this patch [which is going to be in the next version of gzip]:
*** - Tue Oct 29 02:06:35 1996
@@ -85,10 +94,6 @@ file, apply this patch [which is going to be in the next version of gzip]:
}
bytes_in += (ulg)insize;
-E-mail: christos@astron.com
-
-Phone: Do not even think of telephoning me about this program. Send cash first!
-
Parts of this software were developed at SoftQuad Inc., developers
of SGML/HTML/XML publishing software, in Toronto, Canada.
SoftQuad was swallowed up by Corel in 2002
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c
index fb5ff000544..46cb5f81ec4 100644
--- a/usr.bin/file/apprentice.c
+++ b/usr.bin/file/apprentice.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apprentice.c,v 1.25 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: apprentice.c,v 1.26 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -32,6 +32,7 @@
#include "file.h"
#include "magic.h"
+#include "patchlevel.h"
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -45,9 +46,11 @@
#ifdef QUICK
#include <sys/mman.h>
#endif
+#include <sys/types.h>
+#include <dirent.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.25 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.26 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
@@ -93,28 +96,34 @@ private const char *getstr(struct magic_set *, const char *, char *, int,
int *, int);
private int parse(struct magic_set *, struct magic_entry **, uint32_t *,
const char *, size_t, int);
+private int parse_mime(struct magic_set *, struct magic_entry **, uint32_t *,
+ const char *);
private void eatsize(const char **);
private int apprentice_1(struct magic_set *, const char *, int, struct mlist *);
private size_t apprentice_magic_strength(const struct magic *);
private int apprentice_sort(const void *, const void *);
-private int apprentice_file(struct magic_set *, struct magic **, uint32_t *,
+private int apprentice_load(struct magic_set *, struct magic **, uint32_t *,
const char *, int);
private void byteswap(struct magic *, uint32_t);
private void bs1(struct magic *);
private uint16_t swap2(uint16_t);
private uint32_t swap4(uint32_t);
private uint64_t swap8(uint64_t);
-private char *mkdbname(const char *, char *, size_t, int);
+private void mkdbname(const char *, char **, int);
private int apprentice_map(struct magic_set *, struct magic **, uint32_t *,
const char *);
private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *,
const char *);
private int check_format_type(const char *, int);
private int check_format(struct magic_set *, struct magic *);
+private int get_op(char);
private size_t maxmagic = 0;
private size_t magicsize = sizeof(struct magic);
+private const char usg_hdr[] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
+private const char mime_marker[] = "!:mime";
+private const size_t mime_marker_len = sizeof(mime_marker) - 1;
#ifdef COMPILE_ONLY
@@ -150,13 +159,13 @@ main(int argc, char *argv[])
#endif /* COMPILE_ONLY */
static const struct type_tbl_s {
- const char *name;
+ const char name[16];
const size_t len;
const int type;
const int format;
} type_tbl[] = {
# define XX(s) s, (sizeof(s) - 1)
-# define XX_NULL NULL, 0
+# define XX_NULL "", 0
{ XX("byte"), FILE_BYTE, FILE_FMT_NUM },
{ XX("short"), FILE_SHORT, FILE_FMT_NUM },
{ XX("default"), FILE_DEFAULT, FILE_FMT_STR },
@@ -189,6 +198,12 @@ static const struct type_tbl_s {
{ XX("qldate"), FILE_QLDATE, FILE_FMT_STR },
{ XX("leqldate"), FILE_LEQLDATE, FILE_FMT_STR },
{ XX("beqldate"), FILE_BEQLDATE, FILE_FMT_STR },
+ { XX("float"), FILE_FLOAT, FILE_FMT_FLOAT },
+ { XX("befloat"), FILE_BEFLOAT, FILE_FMT_FLOAT },
+ { XX("lefloat"), FILE_LEFLOAT, FILE_FMT_FLOAT },
+ { XX("double"), FILE_DOUBLE, FILE_FMT_DOUBLE },
+ { XX("bedouble"), FILE_BEDOUBLE, FILE_FMT_DOUBLE },
+ { XX("ledouble"), FILE_LEDOUBLE, FILE_FMT_DOUBLE },
{ XX_NULL, FILE_INVALID, FILE_FMT_NONE },
# undef XX
# undef XX_NULL
@@ -199,7 +214,7 @@ get_type(const char *l, const char **t)
{
const struct type_tbl_s *p;
- for (p = type_tbl; p->name; p++) {
+ for (p = type_tbl; p->len; p++) {
if (strncmp(l, p->name, p->len) == 0) {
if (t)
*t = l + p->len;
@@ -219,7 +234,7 @@ init_file_tables(void)
return;
done++;
- for (p = type_tbl; p->name; p++) {
+ for (p = type_tbl; p->len; p++) {
assert(p->type < FILE_NAMES_SIZE);
file_names[p->type] = p->name;
file_formats[p->type] = p->format;
@@ -227,7 +242,7 @@ init_file_tables(void)
}
/*
- * Handle one file.
+ * Handle one file or directory.
*/
private int
apprentice_1(struct magic_set *ms, const char *fn, int action,
@@ -247,7 +262,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
}
if (action == FILE_COMPILE) {
- rv = apprentice_file(ms, &magic, &nmagic, fn, action);
+ rv = apprentice_load(ms, &magic, &nmagic, fn, action);
if (rv != 0)
return -1;
rv = apprentice_compile(ms, &magic, &nmagic, fn);
@@ -259,14 +274,14 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
if ((rv = apprentice_map(ms, &magic, &nmagic, fn)) == -1) {
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms, "using regular magic file `%s'", fn);
- rv = apprentice_file(ms, &magic, &nmagic, fn, action);
+ rv = apprentice_load(ms, &magic, &nmagic, fn, action);
if (rv != 0)
return -1;
}
mapped = rv;
- if (magic == NULL || nmagic == 0) {
+ if (magic == NULL) {
file_delmagic(magic, mapped, nmagic);
return -1;
}
@@ -313,14 +328,13 @@ file_delmagic(struct magic *p, int type, size_t entries)
}
}
-/* const char *fn: list of magic files */
+/* const char *fn: list of magic files and directories */
protected struct mlist *
file_apprentice(struct magic_set *ms, const char *fn, int action)
{
- char *p, *mfn, *afn = NULL;
+ char *p, *mfn;
int file_err, errs = -1;
struct mlist *mlist;
- static const char mime[] = ".mime";
init_file_tables();
@@ -348,25 +362,8 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
*p++ = '\0';
if (*fn == '\0')
break;
- if (ms->flags & MAGIC_MIME) {
- size_t len = strlen(fn) + sizeof(mime);
- if ((afn = malloc(len)) == NULL) {
- free(mfn);
- free(mlist);
- file_oomem(ms, len);
- return NULL;
- }
- (void)strlcpy(afn, fn, len);
- (void)strlcat(afn, ".mime", len);
- fn = afn;
- }
file_err = apprentice_1(ms, fn, action, mlist);
- if (file_err > errs)
- errs = file_err;
- if (afn) {
- free(afn);
- afn = NULL;
- }
+ errs = MAX(errs, file_err);
fn = p;
}
if (errs == -1) {
@@ -422,7 +419,7 @@ apprentice_magic_strength(const struct magic *m)
case FILE_SEARCH:
case FILE_REGEX:
- val += m->vallen;
+ val += m->vallen * MAX(MULT / m->vallen, 1);
break;
case FILE_DATE:
@@ -433,6 +430,9 @@ apprentice_magic_strength(const struct magic *m)
case FILE_LELDATE:
case FILE_BELDATE:
case FILE_MELDATE:
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
val += 4 * MULT;
break;
@@ -445,6 +445,9 @@ apprentice_magic_strength(const struct magic *m)
case FILE_QLDATE:
case FILE_LEQLDATE:
case FILE_BEQLDATE:
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
val += 8 * MULT;
break;
@@ -456,10 +459,10 @@ apprentice_magic_strength(const struct magic *m)
switch (m->reln) {
case 'x': /* matches anything penalize */
+ case '!': /* matches almost anything penalize */
val = 0;
break;
- case '!':
case '=': /* Exact match, prefer */
val += MULT;
break;
@@ -503,36 +506,131 @@ apprentice_sort(const void *a, const void *b)
return 1;
}
+private void
+set_test_type(struct magic *mstart, struct magic *m)
+{
+ switch (m->type) {
+ case FILE_BYTE:
+ case FILE_SHORT:
+ case FILE_LONG:
+ case FILE_DATE:
+ case FILE_BESHORT:
+ case FILE_BELONG:
+ case FILE_BEDATE:
+ case FILE_LESHORT:
+ case FILE_LELONG:
+ case FILE_LEDATE:
+ case FILE_LDATE:
+ case FILE_BELDATE:
+ case FILE_LELDATE:
+ case FILE_MEDATE:
+ case FILE_MELDATE:
+ case FILE_MELONG:
+ case FILE_QUAD:
+ case FILE_LEQUAD:
+ case FILE_BEQUAD:
+ case FILE_QDATE:
+ case FILE_LEQDATE:
+ case FILE_BEQDATE:
+ case FILE_QLDATE:
+ case FILE_LEQLDATE:
+ case FILE_BEQLDATE:
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
+ case FILE_STRING:
+ case FILE_PSTRING:
+ case FILE_BESTRING16:
+ case FILE_LESTRING16:
+ /* binary test, set flag */
+ mstart->flag |= BINTEST;
+ break;
+ case FILE_REGEX:
+ case FILE_SEARCH:
+ /* binary test if pattern is not text */
+ if (file_looks_utf8(m->value.s, m->vallen, NULL, NULL) == 0)
+ mstart->flag |= BINTEST;
+ break;
+ case FILE_DEFAULT:
+ /* can't deduce anything; we shouldn't see this at the
+ top level anyway */
+ break;
+ case FILE_INVALID:
+ default:
+ /* invalid search type, but no need to complain here */
+ break;
+ }
+}
+
/*
- * parse from a file
- * const char *fn: name of magic file
+ * Load and parse one file.
*/
-private int
-apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
- const char *fn, int action)
+private void
+load_1(struct magic_set *ms, int action, const char *fn, int *errs,
+ struct magic_entry **marray, uint32_t *marraycount)
{
- private const char hdr[] =
- "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
- FILE *f;
char line[BUFSIZ];
- int errs = 0;
- struct magic_entry *marray;
- uint32_t marraycount, i, mentrycount = 0;
size_t lineno = 0;
-
- ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */
-
- f = fopen(ms->file = fn, "r");
+ FILE *f = fopen(ms->file = fn, "r");
if (f == NULL) {
if (errno != ENOENT)
file_error(ms, errno, "cannot read magic file `%s'",
- fn);
- return -1;
+ fn);
+ (*errs)++;
+ } else {
+ /* read and parse this file */
+ for (ms->line = 1; fgets(line, sizeof(line), f) != NULL; ms->line++) {
+ size_t len;
+ len = strlen(line);
+ if (len == 0) /* null line, garbage, etc */
+ continue;
+ if (line[len - 1] == '\n') {
+ lineno++;
+ line[len - 1] = '\0'; /* delete newline */
+ }
+ if (line[0] == '\0') /* empty, do not parse */
+ continue;
+ if (line[0] == '#') /* comment, do not parse */
+ continue;
+ if (len > mime_marker_len &&
+ memcmp(line, mime_marker, mime_marker_len) == 0) {
+ /* MIME type */
+ if (parse_mime(ms, marray, marraycount,
+ line + mime_marker_len) != 0)
+ (*errs)++;
+ continue;
+ }
+ if (parse(ms, marray, marraycount, line, lineno, action) != 0)
+ (*errs)++;
+ }
+
+ (void)fclose(f);
}
+}
+
+/*
+ * parse a file or directory of files
+ * const char *fn: name of magic file or directory
+ */
+private int
+apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
+ const char *fn, int action)
+{
+ int errs = 0;
+ struct magic_entry *marray;
+ uint32_t marraycount, i, mentrycount = 0, starttest;
+ char subfn[MAXPATHLEN];
+ struct stat st;
+ DIR *dir;
+ struct dirent *d;
+
+ ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */
maxmagic = MAXMAGIS;
if ((marray = calloc(maxmagic, sizeof(*marray))) == NULL) {
- (void)fclose(f);
file_oomem(ms, maxmagic * sizeof(*marray));
return -1;
}
@@ -540,32 +638,63 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
/* print silly verbose header for USG compat. */
if (action == FILE_CHECK)
- (void)fprintf(stderr, "%s\n", hdr);
+ (void)fprintf(stderr, "%s\n", usg_hdr);
+
+ /* load directory or file */
+ if (stat(fn, &st) == 0 && S_ISDIR(st.st_mode)) {
+ dir = opendir(fn);
+ if (dir) {
+ while (d = readdir(dir)) {
+ snprintf(subfn, sizeof(subfn), "%s/%s",
+ fn, d->d_name);
+ if (stat(subfn, &st) == 0 && S_ISREG(st.st_mode)) {
+ load_1(ms, action, subfn, &errs,
+ &marray, &marraycount);
+ }
+ }
+ closedir(dir);
+ } else
+ errs++;
+ } else
+ load_1(ms, action, fn, &errs, &marray, &marraycount);
+ if (errs)
+ goto out;
- /* read and parse this file */
- for (ms->line = 1; fgets(line, sizeof(line), f) != NULL; ms->line++) {
- size_t len;
- len = strlen(line);
- if (len == 0) /* null line, garbage, etc */
+ /* Set types of tests */
+ for (i = 0; i < marraycount; ) {
+ if (marray[i].mp->cont_level != 0) {
+ i++;
continue;
- if (line[len - 1] == '\n') {
- lineno++;
- line[len - 1] = '\0'; /* delete newline */
}
- if (line[0] == '\0') /* empty, do not parse */
- continue;
- if (line[0] == '#') /* comment, do not parse */
- continue;
- if (parse(ms, &marray, &marraycount, line, lineno, action) != 0)
- errs++;
- }
- (void)fclose(f);
- if (errs)
- goto out;
+ starttest = i;
+ do {
+ set_test_type(marray[starttest].mp, marray[i].mp);
+ if (ms->flags & MAGIC_DEBUG) {
+ (void)fprintf(stderr, "%s%s%s: %s\n",
+ marray[i].mp->mimetype,
+ marray[i].mp->mimetype[0] == '\0' ? "" : "; ",
+ marray[i].mp->desc[0] ? marray[i].mp->desc : "(no description)",
+ marray[i].mp->flag & BINTEST ? "binary" : "text");
+ if (marray[i].mp->flag & BINTEST) {
+#define SYMBOL "text"
+#define SYMLEN sizeof(SYMBOL)
+ char *p = strstr(marray[i].mp->desc, "text");
+ if (p && (p == marray[i].mp->desc || isspace(p[-1])) &&
+ (p + SYMLEN - marray[i].mp->desc == MAXstring ||
+ (p[SYMLEN] == '\0' || isspace(p[SYMLEN])))) {
+ (void)fprintf(stderr,
+ "*** Possible binary test for text type\n");
+ }
+#undef SYMBOL
+#undef SYMLEN
+ }
+ }
+ } while (++i < marraycount && marray[i].mp->cont_level != 0);
+ }
-#ifndef NOORDER
qsort(marray, marraycount, sizeof(*marray), apprentice_sort);
+
/*
* Make sure that any level 0 "default" line is last (if one exists).
*/
@@ -583,7 +712,6 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
break;
}
}
-#endif
for (i = 0; i < marraycount; i++)
mentrycount += marray[i].cont_count;
@@ -648,6 +776,9 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
case FILE_BELONG:
case FILE_LELONG:
case FILE_MELONG:
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
v = (int32_t) v;
break;
case FILE_QUAD:
@@ -659,6 +790,9 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
case FILE_BEQLDATE:
case FILE_LEQDATE:
case FILE_LEQLDATE:
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
v = (int64_t) v;
break;
case FILE_STRING:
@@ -680,7 +814,7 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
}
private int
-string_modifier_check(struct magic_set *ms, struct magic const *m)
+string_modifier_check(struct magic_set *ms, struct magic *m)
{
if ((ms->flags & MAGIC_CHECK) == 0)
return 0;
@@ -689,19 +823,28 @@ string_modifier_check(struct magic_set *ms, struct magic const *m)
case FILE_BESTRING16:
case FILE_LESTRING16:
if (m->str_flags != 0) {
- file_magwarn(ms, "no modifiers allowed for 16-bit strings\n");
+ file_magwarn(ms,
+ "no modifiers allowed for 16-bit strings\n");
return -1;
}
break;
case FILE_STRING:
case FILE_PSTRING:
if ((m->str_flags & REGEX_OFFSET_START) != 0) {
- file_magwarn(ms, "'/%c' only allowed on regex and search\n",
+ file_magwarn(ms,
+ "'/%c' only allowed on regex and search\n",
CHAR_REGEX_OFFSET_START);
return -1;
}
break;
case FILE_SEARCH:
+ if (m->str_range == 0) {
+ file_magwarn(ms,
+ "missing range; defaulting to %d\n",
+ STRING_DEFAULT_RANGE);
+ m->str_range = STRING_DEFAULT_RANGE;
+ return -1;
+ }
break;
case FILE_REGEX:
if ((m->str_flags & STRING_COMPACT_BLANK) != 0) {
@@ -752,19 +895,19 @@ get_op(char c)
private int
get_cond(const char *l, const char **t)
{
- static struct cond_tbl_s {
- const char *name;
- const size_t len;
- const int cond;
+ static const struct cond_tbl_s {
+ char name[8];
+ size_t len;
+ int cond;
} cond_tbl[] = {
{ "if", 2, COND_IF },
{ "elif", 4, COND_ELIF },
{ "else", 4, COND_ELSE },
- { NULL, 0, COND_NONE },
+ { "", 0, COND_NONE },
};
- struct cond_tbl_s *p;
+ const struct cond_tbl_s *p;
- for (p = cond_tbl; p->name; p++) {
+ for (p = cond_tbl; p->len; p++) {
if (strncmp(l, p->name, p->len) == 0 &&
isspace((unsigned char)l[p->len])) {
if (t)
@@ -961,6 +1104,16 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
case 'B':
m->in_type = FILE_BYTE;
break;
+ case 'e':
+ case 'f':
+ case 'g':
+ m->in_type = FILE_LEDOUBLE;
+ break;
+ case 'E':
+ case 'F':
+ case 'G':
+ m->in_type = FILE_BEDOUBLE;
+ break;
default:
if (ms->flags & MAGIC_CHECK)
file_magwarn(ms,
@@ -1031,7 +1184,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
file_magwarn(ms, "'~' invalid for string types");
++l;
}
- m->str_count = 0;
+ m->str_range = 0;
m->str_flags = 0;
m->num_mask = 0;
if ((op = get_op(*l)) != -1) {
@@ -1045,22 +1198,24 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
eatsize(&l);
}
else if (op == FILE_OPDIVIDE) {
- int have_count = 0;
+ int have_range = 0;
while (!isspace((unsigned char)*++l)) {
switch (*l) {
- /* for portability avoid "case '0' ... '9':" */
case '0': case '1': case '2':
case '3': case '4': case '5':
case '6': case '7': case '8':
- case '9': {
- if (have_count && ms->flags & MAGIC_CHECK)
+ case '9':
+ if (have_range &&
+ (ms->flags & MAGIC_CHECK))
file_magwarn(ms,
- "multiple counts");
- have_count = 1;
- m->str_count = strtoul(l, &t, 0);
+ "multiple ranges");
+ have_range = 1;
+ m->str_range = strtoul(l, &t, 0);
+ if (m->str_range == 0)
+ file_magwarn(ms,
+ "zero range");
l = t - 1;
break;
- }
case CHAR_COMPACT_BLANK:
m->str_flags |= STRING_COMPACT_BLANK;
break;
@@ -1085,7 +1240,8 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
return -1;
}
/* allow multiple '/' for readability */
- if (l[1] == '/' && !isspace((unsigned char)l[2]))
+ if (l[1] == '/' &&
+ !isspace((unsigned char)l[2]))
l++;
}
if (string_modifier_check(ms, m) == -1)
@@ -1148,13 +1304,12 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
EATAB;
if (l[0] == '\b') {
++l;
- m->nospflag = 1;
+ m->flag |= NOSPACE;
} else if ((l[0] == '\\') && (l[1] == 'b')) {
++l;
++l;
- m->nospflag = 1;
- } else
- m->nospflag = 0;
+ m->flag |= NOSPACE;
+ }
for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); )
continue;
if (i == sizeof(m->desc)) {
@@ -1176,11 +1331,59 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
file_mdump(m);
}
#endif
+ m->mimetype[0] = '\0'; /* initialise MIME type to none */
if (m->cont_level == 0)
++(*nmentryp); /* make room for next */
return 0;
}
+/*
+ * parse a MIME annotation line from magic file, put into magic[index - 1]
+ * if valid
+ */
+private int
+parse_mime(struct magic_set *ms, struct magic_entry **mentryp,
+ uint32_t *nmentryp, const char *line)
+{
+ size_t i;
+ const char *l = line;
+ struct magic *m;
+ struct magic_entry *me;
+
+ if (*nmentryp == 0) {
+ file_error(ms, 0, "No current entry for MIME type");
+ return -1;
+ }
+
+ me = &(*mentryp)[*nmentryp - 1];
+ m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1];
+
+ if (m->mimetype[0] != '\0') {
+ file_error(ms, 0, "Current entry already has a MIME type: %s\n"
+ "Description: %s\nNew type: %s", m->mimetype, m->desc, l);
+ return -1;
+ }
+
+ EATAB;
+ for (i = 0;
+ *l && ((isascii((unsigned char)*l) && isalnum((unsigned char)*l))
+ || strchr("-+/.", *l)) && i < sizeof(m->mimetype);
+ m->mimetype[i++] = *l++)
+ continue;
+ if (i == sizeof(m->mimetype)) {
+ m->desc[sizeof(m->mimetype) - 1] = '\0';
+ if (ms->flags & MAGIC_CHECK)
+ file_magwarn(ms, "MIME type `%s' truncated %zu",
+ m->mimetype, i);
+ } else
+ m->mimetype[i] = '\0';
+
+ if (i > 0)
+ return 0;
+ else
+ return -1;
+}
+
private int
check_format_type(const char *ptr, int type)
{
@@ -1254,6 +1457,31 @@ check_format_type(const char *ptr, int type)
return -1;
}
+ case FILE_FMT_FLOAT:
+ case FILE_FMT_DOUBLE:
+ if (*ptr == '-')
+ ptr++;
+ if (*ptr == '.')
+ ptr++;
+ while (isdigit((unsigned char)*ptr)) ptr++;
+ if (*ptr == '.')
+ ptr++;
+ while (isdigit((unsigned char)*ptr)) ptr++;
+
+ switch (*ptr++) {
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'F':
+ case 'g':
+ case 'G':
+ return 0;
+
+ default:
+ return -1;
+ }
+
+
case FILE_FMT_STR:
if (*ptr == '-')
ptr++;
@@ -1300,12 +1528,12 @@ check_format(struct magic_set *ms, struct magic *m)
assert(file_nformats == file_nnames);
if (m->type >= file_nformats) {
- file_error(ms, 0, "Internal error inconsistency between "
+ file_magwarn(ms, "Internal error inconsistency between "
"m->type and format strings");
return -1;
}
if (file_formats[m->type] == FILE_FMT_NONE) {
- file_error(ms, 0, "No format string for `%s' with description "
+ file_magwarn(ms, "No format string for `%s' with description "
"`%s'", m->desc, file_names[m->type]);
return -1;
}
@@ -1316,8 +1544,8 @@ check_format(struct magic_set *ms, struct magic *m)
* TODO: this error message is unhelpful if the format
* string is not one character long
*/
- file_error(ms, 0, "Printf format `%c' is not valid for type "
- " `%s' in description `%s'",
+ file_magwarn(ms, "Printf format `%c' is not valid for type "
+ "`%s' in description `%s'",
ptr && *ptr ? *ptr : '?',
file_names[m->type], m->desc);
return -1;
@@ -1325,7 +1553,7 @@ check_format(struct magic_set *ms, struct magic *m)
for (; *ptr; ptr++) {
if (*ptr == '%') {
- file_error(ms, 0,
+ file_magwarn(ms,
"Too many format strings (should have at most one) "
"for `%s' with description `%s'",
file_names[m->type], m->desc);
@@ -1360,6 +1588,30 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
return -1;
}
m->vallen = slen;
+ if (m->type == FILE_PSTRING)
+ m->vallen++;
+ return 0;
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
+ if (m->reln != 'x') {
+ char *ep;
+#ifdef HAVE_STRTOF
+ m->value.f = strtof(*p, &ep);
+#else
+ m->value.f = (float)strtod(*p, &ep);
+#endif
+ *p = ep;
+ }
+ return 0;
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
+ if (m->reln != 'x') {
+ char *ep;
+ m->value.d = strtod(*p, &ep);
+ *p = ep;
+ }
return 0;
default:
if (m->reln != 'x') {
@@ -1634,40 +1886,40 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
uint32_t *ptr;
uint32_t version;
int needsbyteswap;
- char buf[MAXPATHLEN];
- char *dbname = mkdbname(fn, buf, sizeof(buf), 0);
+ char *dbname = NULL;
void *mm = NULL;
+ mkdbname(fn, &dbname, 0);
if (dbname == NULL)
- return -1;
+ goto error2;
if ((fd = open(dbname, O_RDONLY|O_BINARY)) == -1)
- return -1;
+ goto error2;
if (fstat(fd, &st) == -1) {
file_error(ms, errno, "cannot stat `%s'", dbname);
- goto error;
+ goto error1;
}
- if (st.st_size < 16) {
+ if (st.st_size < 8) {
file_error(ms, 0, "file `%s' is too small", dbname);
- goto error;
+ goto error1;
}
#ifdef QUICK
if ((mm = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
file_error(ms, errno, "cannot map `%s'", dbname);
- goto error;
+ goto error1;
}
#define RET 2
#else
if ((mm = malloc((size_t)st.st_size)) == NULL) {
file_oomem(ms, (size_t)st.st_size);
- goto error;
+ goto error1;
}
if (read(fd, mm, (size_t)st.st_size) != (size_t)st.st_size) {
file_badread(ms);
- goto error;
+ goto error1;
}
#define RET 1
#endif
@@ -1678,7 +1930,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
file_error(ms, 0, "bad magic in `%s'");
- goto error;
+ goto error1;
}
needsbyteswap = 1;
} else
@@ -1688,17 +1940,21 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
else
version = ptr[1];
if (version != VERSIONNO) {
- file_error(ms, 0, "version mismatch (%d != %d) in `%s'",
- version, VERSIONNO, dbname);
- goto error;
- }
- *nmagicp = (uint32_t)(st.st_size / sizeof(struct magic)) - 1;
+ file_error(ms, 0, "File %d.%d supports only %d version magic "
+ "files. `%s' is version %d", FILE_VERSION_MAJOR, patchlevel,
+ VERSIONNO, dbname, version);
+ goto error1;
+ }
+ *nmagicp = (uint32_t)(st.st_size / sizeof(struct magic));
+ if (*nmagicp > 0)
+ (*nmagicp)--;
(*magicp)++;
if (needsbyteswap)
byteswap(*magicp, *nmagicp);
+ free(dbname);
return RET;
-error:
+error1:
if (fd != -1)
(void)close(fd);
if (mm) {
@@ -1711,6 +1967,8 @@ error:
*magicp = NULL;
*nmagicp = 0;
}
+error2:
+ free(dbname);
return -1;
}
@@ -1725,44 +1983,49 @@ apprentice_compile(struct magic_set *ms, struct magic **magicp,
uint32_t *nmagicp, const char *fn)
{
int fd;
- char buf[MAXPATHLEN];
- char *dbname = mkdbname(fn, buf, sizeof(buf), 1);
+ char *dbname;
+ int rv = -1;
+
+ mkdbname(fn, &dbname, 1);
if (dbname == NULL)
- return -1;
+ goto out;
if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644)) == -1) {
file_error(ms, errno, "cannot open `%s'", dbname);
- return -1;
+ goto out;
}
if (write(fd, ar, sizeof(ar)) != (ssize_t)sizeof(ar)) {
file_error(ms, errno, "error writing `%s'", dbname);
- return -1;
+ goto out;
}
if (lseek(fd, (off_t)sizeof(struct magic), SEEK_SET)
!= sizeof(struct magic)) {
file_error(ms, errno, "error seeking `%s'", dbname);
- return -1;
+ goto out;
}
if (write(fd, *magicp, (sizeof(struct magic) * *nmagicp))
!= (ssize_t)(sizeof(struct magic) * *nmagicp)) {
file_error(ms, errno, "error writing `%s'", dbname);
- return -1;
+ goto out;
}
(void)close(fd);
- return 0;
+ rv = 0;
+out:
+ free(dbname);
+ return rv;
}
private const char ext[] = ".mgc";
/*
* make a dbname
*/
-private char *
-mkdbname(const char *fn, char *buf, size_t bufsiz, int strip)
+private void
+mkdbname(const char *fn, char **buf, int strip)
{
if (strip) {
const char *p;
@@ -1770,8 +2033,11 @@ mkdbname(const char *fn, char *buf, size_t bufsiz, int strip)
fn = ++p;
}
- (void)snprintf(buf, bufsiz, "%s%s", fn, ext);
- return buf;
+ (void)asprintf(buf, "%s%s", fn, ext);
+ if (*buf && strlen(*buf) > MAXPATHLEN) {
+ free(*buf);
+ *buf = NULL;
+ }
}
/*
@@ -1824,6 +2090,7 @@ swap8(uint64_t sv)
uint32_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
uint8_t *d = (uint8_t *)(void *)&rv;
+#if 0
d[0] = s[3];
d[1] = s[2];
d[2] = s[1];
@@ -1832,6 +2099,16 @@ swap8(uint64_t sv)
d[5] = s[6];
d[6] = s[5];
d[7] = s[4];
+#else
+ d[0] = s[7];
+ d[1] = s[6];
+ d[2] = s[5];
+ d[3] = s[4];
+ d[4] = s[3];
+ d[5] = s[2];
+ d[6] = s[1];
+ d[7] = s[0];
+#endif
return rv;
}
@@ -1846,7 +2123,7 @@ bs1(struct magic *m)
m->in_offset = swap4((uint32_t)m->in_offset);
m->lineno = swap4((uint32_t)m->lineno);
if (IS_STRING(m->type)) {
- m->str_count = swap4(m->str_count);
+ m->str_range = swap4(m->str_range);
m->str_flags = swap4(m->str_flags);
}
else {
diff --git a/usr.bin/file/ascmagic.c b/usr.bin/file/ascmagic.c
index b5cc8b991d6..7dcf0d3d99a 100644
--- a/usr.bin/file/ascmagic.c
+++ b/usr.bin/file/ascmagic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ascmagic.c,v 1.9 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: ascmagic.c,v 1.10 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -50,33 +50,35 @@
#include "names.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: ascmagic.c,v 1.9 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: ascmagic.c,v 1.10 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
-typedef unsigned long unichar;
-
#define MAXLINELEN 300 /* longest sane line length */
#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
|| (x) == 0x85 || (x) == '\f')
private int looks_ascii(const unsigned char *, size_t, unichar *, size_t *);
-private int looks_utf8(const unsigned char *, size_t, unichar *, size_t *);
-private int looks_unicode(const unsigned char *, size_t, unichar *, size_t *);
+private int looks_utf8_with_BOM(const unsigned char *, size_t, unichar *,
+ size_t *);
+protected int file_looks_utf8(const unsigned char *, size_t, unichar *, size_t *);
+private int looks_ucs16(const unsigned char *, size_t, unichar *, size_t *);
private int looks_latin1(const unsigned char *, size_t, unichar *, size_t *);
private int looks_extended(const unsigned char *, size_t, unichar *, size_t *);
private void from_ebcdic(const unsigned char *, size_t, unsigned char *);
private int ascmatch(const unsigned char *, const unichar *, size_t);
+private unsigned char *encode_utf8(unsigned char *, size_t, unichar *, size_t);
protected int
file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
{
size_t i;
- unsigned char *nbuf = NULL;
+ unsigned char *nbuf = NULL, *utf8_buf = NULL, *utf8_end;
unichar *ubuf = NULL;
- size_t ulen;
- struct names *p;
+ size_t ulen, mlen;
+ const struct names *p;
int rv = -1;
+ int mime = ms->flags & MAGIC_MIME;
const char *code = NULL;
const char *code_mime = NULL;
@@ -118,11 +120,15 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
code = "ASCII";
code_mime = "us-ascii";
type = "text";
- } else if (looks_utf8(buf, nbytes, ubuf, &ulen)) {
+ } else if (looks_utf8_with_BOM(buf, nbytes, ubuf, &ulen) > 0) {
+ code = "UTF-8 Unicode (with BOM)";
+ code_mime = "utf-8";
+ type = "text";
+ } else if (file_looks_utf8(buf, nbytes, ubuf, &ulen) > 1) {
code = "UTF-8 Unicode";
code_mime = "utf-8";
type = "text";
- } else if ((i = looks_unicode(buf, nbytes, ubuf, &ulen)) != 0) {
+ } else if ((i = looks_ucs16(buf, nbytes, ubuf, &ulen)) != 0) {
if (i == 1)
code = "Little-endian UTF-16 Unicode";
else
@@ -160,40 +166,25 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
goto done;
}
- /*
- * for troff, look for . + letter + letter or .\";
- * this must be done to disambiguate tar archives' ./file
- * and other trash from real troff input.
- *
- * I believe Plan 9 troff allows non-ASCII characters in the names
- * of macros, so this test might possibly fail on such a file.
- */
- if ((ms->flags & MAGIC_NO_CHECK_TROFF) == 0 && *ubuf == '.') {
- unichar *tp = ubuf + 1;
-
- while (ISSPC(*tp))
- ++tp; /* skip leading whitespace */
- if ((tp[0] == '\\' && tp[1] == '\"') ||
- (isascii((unsigned char)tp[0]) &&
- isalnum((unsigned char)tp[0]) &&
- isascii((unsigned char)tp[1]) &&
- isalnum((unsigned char)tp[1]) &&
- ISSPC(tp[2]))) {
- subtype_mime = "text/troff";
- subtype = "troff or preprocessor input";
- goto subtype_identified;
- }
+ /* Convert ubuf to UTF-8 and try text soft magic */
+ /* If original was ASCII or UTF-8, could use nbuf instead of
+ re-converting. */
+ /* malloc size is a conservative overestimate; could be
+ re-converting improved, or at least realloced after
+ re-converting conversion. */
+ mlen = ulen * 6;
+ if ((utf8_buf = malloc(mlen)) == NULL) {
+ file_oomem(ms, mlen);
+ goto done;
}
-
- if ((ms->flags & MAGIC_NO_CHECK_FORTRAN) == 0 &&
- (*buf == 'c' || *buf == 'C') && ISSPC(buf[1])) {
- subtype_mime = "text/fortran";
- subtype = "fortran program";
- goto subtype_identified;
+ if ((utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)) == NULL)
+ goto done;
+ if (file_softmagic(ms, utf8_buf, utf8_end - utf8_buf, TEXTTEST) != 0) {
+ rv = 1;
+ goto done;
}
/* look for tokens from names.h - this is expensive! */
-
if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
goto subtype_identified;
@@ -201,24 +192,18 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
while (i < ulen) {
size_t end;
- /*
- * skip past any leading space
- */
+ /* skip past any leading space */
while (i < ulen && ISSPC(ubuf[i]))
i++;
if (i >= ulen)
break;
- /*
- * find the next whitespace
- */
+ /* find the next whitespace */
for (end = i + 1; end < nbytes; end++)
if (ISSPC(ubuf[end]))
break;
- /*
- * compare the word thus isolated against the token list
- */
+ /* compare the word thus isolated against the token list */
for (p = names; p < names + NNAMES; p++) {
if (ascmatch((const unsigned char *)p->name, ubuf + i,
end - i)) {
@@ -233,9 +218,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
subtype_identified:
- /*
- * Now try to discover other details about the file.
- */
+ /* Now try to discover other details about the file. */
for (i = 0; i < ulen; i++) {
if (ubuf[i] == '\n') {
if (seen_cr)
@@ -272,21 +255,27 @@ subtype_identified:
if (seen_cr && nbytes < HOWMANY)
n_cr++;
- if ((ms->flags & MAGIC_MIME)) {
- if (subtype_mime) {
- if (file_printf(ms, subtype_mime) == -1)
- goto done;
- } else {
- if (file_printf(ms, "text/plain") == -1)
- goto done;
+ if (mime) {
+ if (mime & MAGIC_MIME_TYPE) {
+ if (subtype_mime) {
+ if (file_printf(ms, subtype_mime) == -1)
+ goto done;
+ } else {
+ if (file_printf(ms, "text/plain") == -1)
+ goto done;
+ }
}
- if (code_mime) {
- if (file_printf(ms, "; charset=") == -1)
+ if ((mime == 0 || mime == MAGIC_MIME) && code_mime) {
+ if ((mime & MAGIC_MIME_TYPE) &&
+ file_printf(ms, " charset=") == -1)
goto done;
if (file_printf(ms, code_mime) == -1)
goto done;
}
+
+ if (mime == MAGIC_MIME_ENCODING)
+ file_printf(ms, "binary");
} else {
if (file_printf(ms, code) == -1)
goto done;
@@ -363,6 +352,8 @@ done:
free(nbuf);
if (ubuf)
free(ubuf);
+ if (utf8_buf)
+ free(utf8_buf);
return rv;
}
@@ -521,15 +512,84 @@ looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
return 1;
}
-private int
-looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
+/*
+ * Encode Unicode string as UTF-8, returning pointer to character
+ * after end of string, or NULL if an invalid character is found.
+ */
+private unsigned char *
+encode_utf8(unsigned char *buf, size_t len, unichar *ubuf, size_t ulen)
+{
+ size_t i;
+ unsigned char *end = buf + len;
+
+ for (i = 0; i < ulen; i++) {
+ if (ubuf[i] <= 0x7f) {
+ if (end - buf < 1)
+ return NULL;
+ *buf++ = (unsigned char)ubuf[i];
+ } else if (ubuf[i] <= 0x7ff) {
+ if (end - buf < 2)
+ return NULL;
+ *buf++ = (unsigned char)((ubuf[i] >> 6) + 0xc0);
+ *buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
+ } else if (ubuf[i] <= 0xffff) {
+ if (end - buf < 3)
+ return NULL;
+ *buf++ = (unsigned char)((ubuf[i] >> 12) + 0xe0);
+ *buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
+ } else if (ubuf[i] <= 0x1fffff) {
+ if (end - buf < 4)
+ return NULL;
+ *buf++ = (unsigned char)((ubuf[i] >> 18) + 0xf0);
+ *buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
+ } else if (ubuf[i] <= 0x3ffffff) {
+ if (end - buf < 5)
+ return NULL;
+ *buf++ = (unsigned char)((ubuf[i] >> 24) + 0xf8);
+ *buf++ = (unsigned char)(((ubuf[i] >> 18) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
+ } else if (ubuf[i] <= 0x7fffffff) {
+ if (end - buf < 6)
+ return NULL;
+ *buf++ = (unsigned char)((ubuf[i] >> 30) + 0xfc);
+ *buf++ = (unsigned char)(((ubuf[i] >> 24) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)(((ubuf[i] >> 18) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
+ *buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
+ } else /* Invalid character */
+ return NULL;
+ }
+
+ return buf;
+}
+
+/*
+ * Decide whether some text looks like UTF-8. Returns:
+ *
+ * -1: invalid UTF-8
+ * 0: uses odd control characters, so doesn't look like text
+ * 1: 7-bit text
+ * 2: definitely UTF-8 text (valid high-bit set bytes)
+ *
+ * If ubuf is non-NULL on entry, text is decoded into ubuf, *ulen;
+ * ubuf must be big enough!
+ */
+protected int
+file_looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
{
size_t i;
int n;
unichar c;
- int gotone = 0;
+ int gotone = 0, ctrl = 0;
- *ulen = 0;
+ if (ubuf)
+ *ulen = 0;
for (i = 0; i < nbytes; i++) {
if ((buf[i] & 0x80) == 0) { /* 0xxxxxxx is plain ASCII */
@@ -539,11 +599,12 @@ looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
*/
if (text_chars[buf[i]] != T)
- return 0;
+ ctrl = 1;
- ubuf[(*ulen)++] = buf[i];
+ if (ubuf)
+ ubuf[(*ulen)++] = buf[i];
} else if ((buf[i] & 0x40) == 0) { /* 10xxxxxx never 1st byte */
- return 0;
+ return -1;
} else { /* 11xxxxxx begins UTF-8 */
int following;
@@ -563,7 +624,7 @@ looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
c = buf[i] & 0x01;
following = 5;
} else
- return 0;
+ return -1;
for (n = 0; n < following; n++) {
i++;
@@ -571,21 +632,37 @@ looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
goto done;
if ((buf[i] & 0x80) == 0 || (buf[i] & 0x40))
- return 0;
+ return -1;
c = (c << 6) + (buf[i] & 0x3f);
}
- ubuf[(*ulen)++] = c;
+ if (ubuf)
+ ubuf[(*ulen)++] = c;
gotone = 1;
}
}
done:
- return gotone; /* don't claim it's UTF-8 if it's all 7-bit */
+ return ctrl ? 0 : (gotone ? 2 : 1);
+}
+
+/*
+ * Decide whether some text looks like UTF-8 with BOM. If there is no
+ * BOM, return -1; otherwise return the result of looks_utf8 on the
+ * rest of the text.
+ */
+private int
+looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unichar *ubuf,
+ size_t *ulen)
+{
+ if (nbytes > 3 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
+ return file_looks_utf8(buf + 3, nbytes - 3, ubuf, ulen);
+ else
+ return -1;
}
private int
-looks_unicode(const unsigned char *buf, size_t nbytes, unichar *ubuf,
+looks_ucs16(const unsigned char *buf, size_t nbytes, unichar *ubuf,
size_t *ulen)
{
int bigend;
diff --git a/usr.bin/file/compress.c b/usr.bin/file/compress.c
index a17a1d32861..6da92b83202 100644
--- a/usr.bin/file/compress.c
+++ b/usr.bin/file/compress.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compress.c,v 1.12 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: compress.c,v 1.13 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -50,19 +50,20 @@
#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif
-#ifdef HAVE_LIBZ
+#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
+#define BUILTIN_DECOMPRESS
#include <zlib.h>
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: compress.c,v 1.12 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: compress.c,v 1.13 2009/04/24 18:54:34 chl Exp $")
#endif
-private struct {
- const char *magic;
+private const struct {
+ const char magic[8];
size_t maglen;
- const char *const argv[3];
+ const char *argv[3];
int silent;
} compr[] = {
{ "\037\235", 2, { "gzip", "-cdq", NULL }, 1 }, /* compressed */
@@ -87,7 +88,7 @@ private size_t ncompr = sizeof(compr) / sizeof(compr[0]);
private ssize_t swrite(int, const void *, size_t);
private size_t uncompressbuf(struct magic_set *, int, size_t,
const unsigned char *, unsigned char **, size_t);
-#ifdef HAVE_LIBZ
+#ifdef BUILTIN_DECOMPRESS
private size_t uncompressgzipped(struct magic_set *, const unsigned char *,
unsigned char **, size_t);
#endif
@@ -99,6 +100,7 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
unsigned char *newbuf = NULL;
size_t i, nsz;
int rv = 0;
+ int mime = ms->flags & MAGIC_MIME;
if ((ms->flags & MAGIC_COMPRESS) == 0)
return 0;
@@ -113,11 +115,18 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
rv = -1;
if (file_buffer(ms, -1, name, newbuf, nsz) == -1)
goto error;
- if (file_printf(ms, " (") == -1)
- goto error;
- if (file_buffer(ms, -1, NULL, buf, nbytes) == -1)
+
+ if (mime == MAGIC_MIME || mime == 0) {
+ if (file_printf(ms, mime ?
+ " compressed-encoding=" : " (") == -1)
+ goto error;
+ }
+
+ if ((mime == 0 || mime & MAGIC_MIME_ENCODING) &&
+ file_buffer(ms, -1, NULL, buf, nbytes) == -1)
goto error;
- if (file_printf(ms, ")") == -1)
+
+ if (!mime && file_printf(ms, ")") == -1)
goto error;
rv = 1;
break;
@@ -286,7 +295,7 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
return fd;
}
-#ifdef HAVE_LIBZ
+#ifdef BUILTIN_DECOMPRESS
#define FHCRC (1 << 1)
#define FEXTRA (1 << 2)
@@ -365,7 +374,8 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
int fdin[2], fdout[2];
int r;
-#ifdef HAVE_LIBZ
+#ifdef BUILTIN_DECOMPRESS
+ /* FIXME: This doesn't cope with bzip2 */
if (method == 2)
return uncompressgzipped(ms, old, newch, n);
#endif
diff --git a/usr.bin/file/config.h b/usr.bin/file/config.h
index 242650c2d31..68a861e5c08 100644
--- a/usr.bin/file/config.h
+++ b/usr.bin/file/config.h
@@ -4,7 +4,7 @@
* but can still carefully import stuff from Christos' version.
*
* This file is in the public domain. Original Author Ian F. Darwin.
- * $OpenBSD: config.h,v 1.3 2008/05/08 01:40:56 chl Exp $
+ * $OpenBSD: config.h,v 1.4 2009/04/24 18:54:34 chl Exp $
*/
/* header file issues. */
@@ -16,7 +16,8 @@
#define HAVE_INTTYPES_H 1
#define HAVE_GETOPT_H 1
#define HAVE_LIMITS_H 1
-/* #define HAVE_LIBZ 1 DO NOT ENABLE YET -- ian */
+/* #define HAVE_ZLIB_H 1 DO NOT ENABLE YET -- chl */
+/* #define HAVE_LIBZ 1 DO NOT ENABLE YET -- ian */
#define HAVE_STRTOUL
#define HAVE_STRERROR
diff --git a/usr.bin/file/elfclass.h b/usr.bin/file/elfclass.h
new file mode 100644
index 00000000000..7f6d8adce6d
--- /dev/null
+++ b/usr.bin/file/elfclass.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) Christos Zoulas 2008.
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice immediately at the beginning of the file, without modification,
+ * this list of conditions, and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+ if (nbytes <= sizeof(elfhdr))
+ return 0;
+
+ u.l = 1;
+ (void)memcpy(&elfhdr, buf, sizeof elfhdr);
+ swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
+
+ type = elf_getu16(swap, elfhdr.e_type);
+ switch (type) {
+#ifdef ELFCORE
+ case ET_CORE:
+ if (dophn_core(ms, class, swap, fd,
+ (off_t)elf_getu(swap, elfhdr.e_phoff),
+ elf_getu16(swap, elfhdr.e_phnum),
+ (size_t)elf_getu16(swap, elfhdr.e_phentsize),
+ fsize, &flags) == -1)
+ return -1;
+ break;
+#endif
+ case ET_EXEC:
+ case ET_DYN:
+ if (dophn_exec(ms, class, swap, fd,
+ (off_t)elf_getu(swap, elfhdr.e_phoff),
+ elf_getu16(swap, elfhdr.e_phnum),
+ (size_t)elf_getu16(swap, elfhdr.e_phentsize),
+ fsize, &flags) == -1)
+ return -1;
+ /*FALLTHROUGH*/
+ case ET_REL:
+ if (doshn(ms, class, swap, fd,
+ (off_t)elf_getu(swap, elfhdr.e_shoff),
+ elf_getu16(swap, elfhdr.e_shnum),
+ (size_t)elf_getu16(swap, elfhdr.e_shentsize),
+ &flags) == -1)
+ return -1;
+ break;
+
+ default:
+ break;
+ }
+ return 1;
diff --git a/usr.bin/file/file.c b/usr.bin/file/file.c
index 8c06ffa732f..b4d05763cbf 100644
--- a/usr.bin/file/file.c
+++ b/usr.bin/file/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.18 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: file.c,v 1.19 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -61,10 +61,9 @@
#include <wchar.h>
#endif
-#ifdef HAVE_GETOPT_H
-#include <getopt.h> /* for long options (is this portable?)*/
-#else
-#undef HAVE_GETOPT_LONG
+#include <getopt.h>
+#ifndef HAVE_GETOPT_LONG
+int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex);
#endif
#include <netinet/in.h> /* for byte swapping */
@@ -72,7 +71,7 @@
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: file.c,v 1.18 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.19 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
@@ -82,7 +81,7 @@ FILE_RCSID("@(#)$Id: file.c,v 1.18 2008/05/08 01:40:56 chl Exp $")
#define SYMLINKFLAG ""
#endif
-# define USAGE "Usage: %s [-bck" SYMLINKFLAG "nNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...\n" \
+# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...\n" \
" %s [-m magicfiles] -C\n"
#ifndef MAXPATHLEN
@@ -99,18 +98,13 @@ private const char *magicfile = 0; /* where the magic is */
private const char *default_magicfile = MAGIC;
private const char *separator = ":"; /* Default field separator */
+extern char *__progname; /* used throughout */
+
private struct magic_set *magic;
-extern char *__progname;
private void unwrap(char *);
private void usage(void);
-#ifdef HAVE_GETOPT_LONG
private void help(void);
-#endif
-#if 0
-private int byteconv4(int, int, int);
-private short byteconv2(int, int, int);
-#endif
int main(int, char *[]);
private void process(const char *, int);
@@ -123,44 +117,26 @@ private void load(const char *, int);
int
main(int argc, char *argv[])
{
- int c, i;
+ int c;
+ size_t i;
int action = 0, didsomefiles = 0, errflg = 0;
int flags = 0;
char *home, *usermagic;
struct stat sb;
static const char hmagic[] = "/.magic";
-#define OPTSTRING "bcCde:f:F:hkLm:nNprsvz0"
-#ifdef HAVE_GETOPT_LONG
+#define OPTSTRING "bcCde:f:F:hikLm:nNprsvz0"
int longindex;
static const struct option long_options[] =
{
- {"version", 0, 0, 'v'},
- {"help", 0, 0, 0},
- {"brief", 0, 0, 'b'},
- {"checking-printout", 0, 0, 'c'},
- {"debug", 0, 0, 'd'},
- {"exclude", 1, 0, 'e' },
- {"files-from", 1, 0, 'f'},
- {"separator", 1, 0, 'F'},
- {"keep-going", 0, 0, 'k'},
-#ifdef S_IFLNK
- {"dereference", 0, 0, 'L'},
- {"no-dereference", 0, 0, 'h'},
-#endif
- {"magic-file", 1, 0, 'm'},
-#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
- {"preserve-date", 0, 0, 'p'},
-#endif
- {"uncompress", 0, 0, 'z'},
- {"raw", 0, 0, 'r'},
- {"no-buffer", 0, 0, 'n'},
- {"no-pad", 0, 0, 'N'},
- {"special-files", 0, 0, 's'},
- {"compile", 0, 0, 'C'},
- {"print0", 0, 0, '0'},
- {0, 0, 0, 0},
- };
-#endif
+#define OPT(shortname, longname, opt, doc) \
+ {longname, opt, NULL, shortname},
+#define OPT_LONGONLY(longname, opt, doc) \
+ {longname, opt, NULL, 0},
+#include "file_opts.h"
+#undef OPT
+#undef OPT_LONGONLY
+ {0, 0, NULL, 0}
+};
static const struct {
const char *name;
@@ -170,17 +146,13 @@ main(int argc, char *argv[])
{ "ascii", MAGIC_NO_CHECK_ASCII },
{ "compress", MAGIC_NO_CHECK_COMPRESS },
{ "elf", MAGIC_NO_CHECK_ELF },
- { "fortran", MAGIC_NO_CHECK_FORTRAN },
{ "soft", MAGIC_NO_CHECK_SOFT },
{ "tar", MAGIC_NO_CHECK_TAR },
{ "tokens", MAGIC_NO_CHECK_TOKENS },
- { "troff", MAGIC_NO_CHECK_TROFF },
};
-#ifdef LC_CTYPE
/* makes islower etc work for other langs */
(void)setlocale(LC_CTYPE, "");
-#endif
#ifdef __EMX__
/* sh-like wildcard expansion! Shouldn't hurt at least ... */
@@ -206,24 +178,27 @@ main(int argc, char *argv[])
#ifdef S_IFLNK
flags |= getenv("POSIXLY_CORRECT") ? MAGIC_SYMLINK : 0;
#endif
-#ifndef HAVE_GETOPT_LONG
- while ((c = getopt(argc, argv, OPTSTRING)) != -1)
-#else
while ((c = getopt_long(argc, argv, OPTSTRING, long_options,
&longindex)) != -1)
-#endif
switch (c) {
-#ifdef HAVE_GETOPT_LONG
case 0 :
- if (longindex == 1)
+ switch (longindex) {
+ case 0:
help();
+ break;
+ case 10:
+ flags |= MAGIC_MIME_TYPE;
+ break;
+ case 11:
+ flags |= MAGIC_MIME_ENCODING;
+ break;
+ }
break;
-#endif
case '0':
nulsep = 1;
break;
case 'b':
- ++bflag;
+ bflag++;
break;
case 'c':
action = FILE_CHECK;
@@ -255,6 +230,9 @@ main(int argc, char *argv[])
case 'F':
separator = optarg;
break;
+ case 'i':
+ flags |= MAGIC_MIME;
+ break;
case 'k':
flags |= MAGIC_CONTINUE;
break;
@@ -279,9 +257,9 @@ main(int argc, char *argv[])
flags |= MAGIC_DEVICES;
break;
case 'v':
- (void)fprintf(stdout, "%s-%d.%.2d\n", __progname,
+ (void)fprintf(stderr, "%s-%d.%.2d\n", __progname,
FILE_VERSION_MAJOR, patchlevel);
- (void)fprintf(stdout, "magic file from %s\n",
+ (void)fprintf(stderr, "magic file from %s\n",
magicfile);
return 1;
case 'z':
@@ -333,18 +311,26 @@ main(int argc, char *argv[])
}
}
else {
- int i, wid, nw;
- for (wid = 0, i = optind; i < argc; i++) {
- nw = file_mbswidth(argv[i]);
+ size_t j, wid, nw;
+ for (wid = 0, j = (size_t)optind; j < (size_t)argc; j++) {
+ nw = file_mbswidth(argv[j]);
if (nw > wid)
wid = nw;
}
+ /*
+ * If bflag is only set twice, set it depending on
+ * number of files [this is undocumented, and subject to change]
+ */
+ if (bflag == 2) {
+ bflag = optind >= argc - 1;
+ }
for (; optind < argc; optind++)
process(argv[optind], wid);
}
+ c = magic->haderr ? 1 : 0;
magic_close(magic);
- return 0;
+ return c;
}
@@ -432,64 +418,6 @@ process(const char *inname, int wid)
(void)printf("%s\n", type);
}
-
-#if 0
-/*
- * byteconv4
- * Input:
- * from 4 byte quantity to convert
- * same whether to perform byte swapping
- * big_endian whether we are a big endian host
- */
-private int
-byteconv4(int from, int same, int big_endian)
-{
- if (same)
- return from;
- else if (big_endian) { /* lsb -> msb conversion on msb */
- union {
- int i;
- char c[4];
- } retval, tmpval;
-
- tmpval.i = from;
- retval.c[0] = tmpval.c[3];
- retval.c[1] = tmpval.c[2];
- retval.c[2] = tmpval.c[1];
- retval.c[3] = tmpval.c[0];
-
- return retval.i;
- }
- else
- return ntohl(from); /* msb -> lsb conversion on lsb */
-}
-
-/*
- * byteconv2
- * Same as byteconv4, but for shorts
- */
-private short
-byteconv2(int from, int same, int big_endian)
-{
- if (same)
- return from;
- else if (big_endian) { /* lsb -> msb conversion on msb */
- union {
- short s;
- char c[2];
- } retval, tmpval;
-
- tmpval.s = (short) from;
- retval.c[0] = tmpval.c[1];
- retval.c[1] = tmpval.c[0];
-
- return retval.s;
- }
- else
- return ntohs(from); /* msb -> lsb conversion on lsb */
-}
-#endif
-
size_t
file_mbswidth(const char *s)
{
@@ -528,47 +456,23 @@ private void
usage(void)
{
(void)fprintf(stderr, USAGE, __progname, __progname);
-#ifdef HAVE_GETOPT_LONG
(void)fputs("Try `file --help' for more information.\n", stderr);
-#endif
exit(1);
}
-#ifdef HAVE_GETOPT_LONG
private void
help(void)
{
- (void)puts(
-"Usage: file [OPTION]... [FILE]...\n"
-"Determine file type of FILEs.\n"
-"\n"
-" -m, --magic-file LIST use LIST as a colon-separated list of magic\n"
-" number files\n"
-" -z, --uncompress try to look inside compressed files\n"
-" -b, --brief do not prepend filenames to output lines\n"
-" -c, --checking-printout print the parsed form of the magic file, use in\n"
-" conjunction with -m to debug a new magic file\n"
-" before installing it\n"
-" -e, --exclude exclude test from the list of test to be\n"
-" performed for file. Valid tests are:\n"
-" ascii, apptype, elf, compress, soft, tar\n"
-" -f, --files-from FILE read the filenames to be examined from FILE\n"
-" -F, --separator string use string as separator instead of `:'\n"
-" -k, --keep-going don't stop at the first match\n"
-" -L, --dereference causes symlinks to be followed\n"
-" -n, --no-buffer do not buffer output\n"
-" -N, --no-pad do not pad output\n"
-" -p, --preserve-date preserve access times on files\n"
-" -r, --raw don't translate unprintable chars to \\ooo\n"
-" -s, --special-files treat special (block/char devices) files as\n"
-" ordinary ones\n"
-"or\n"
-" --help display this help and exit\n"
-"or\n"
-" --version output version information and exit\n"
-"or\n"
-" -C, --compile compile file specified by -m\n"
-);
+ (void)fputs(
+"Usage: file [OPTION...] [FILE...]\n"
+"Determine type of FILEs.\n"
+"\n", stderr);
+#define OPT(shortname, longname, opt, doc) \
+ fprintf(stderr, " -%c, --" longname doc, shortname);
+#define OPT_LONGONLY(longname, opt, doc) \
+ fprintf(stderr, " --" longname doc);
+#include "file_opts.h"
+#undef OPT
+#undef OPT_LONGONLY
exit(0);
}
-#endif
diff --git a/usr.bin/file/file.h b/usr.bin/file/file.h
index d6022fc5887..13d7ece44dc 100644
--- a/usr.bin/file/file.h
+++ b/usr.bin/file/file.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.h,v 1.19 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: file.h,v 1.20 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -28,7 +28,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.19 2008/05/08 01:40:56 chl Exp $
+ * @(#)$Id: file.h,v 1.20 2009/04/24 18:54:34 chl Exp $
*/
#ifndef __file_h__
@@ -51,6 +51,7 @@
#include <sys/types.h>
/* Do this here and now, because struct stat gets re-defined on solaris */
#include <sys/stat.h>
+#include <stdarg.h>
#define ENABLE_CONDITIONALS
@@ -84,16 +85,21 @@
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
+#ifndef MAX
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
#ifndef HOWMANY
# define HOWMANY (256 * 1024) /* how much of the file to look at */
#endif
-#define MAXMAGIS 8192 /* max entries in /etc/magic */
-#define MAXDESC 64 /* max leng of text description */
+#define MAXMAGIS 8192 /* max entries in any one magic file
+ or directory */
+#define MAXDESC 64 /* max leng of text description/MIME type */
#define MAXstring 32 /* max leng of "string" types */
#define MAGICNO 0xF11E041C
-#define VERSIONNO 4
-#define FILE_MAGICSIZE (32 * 4)
+#define VERSIONNO 5
+#define FILE_MAGICSIZE (32 * 6)
#define FILE_LOAD 0
#define FILE_CHECK 1
@@ -102,18 +108,23 @@
struct magic {
/* Word 1 */
uint16_t cont_level; /* level of ">" */
- uint8_t nospflag; /* suppress space character */
uint8_t flag;
-#define INDIR 1 /* if '(...)' appears */
-#define OFFADD 2 /* if '>&' or '>...(&' appears */
-#define INDIROFFADD 4 /* if '>&(' appears */
-#define UNSIGNED 8 /* comparison is unsigned */
+#define INDIR 0x01 /* if '(...)' appears */
+#define OFFADD 0x02 /* if '>&' or '>...(&' appears */
+#define INDIROFFADD 0x04 /* if '>&(' appears */
+#define UNSIGNED 0x08 /* comparison is unsigned */
+#define NOSPACE 0x10 /* suppress space character before output */
+#define BINTEST 0x20 /* test is for a binary type (set only
+ for top-level tests) */
+#define TEXTTEST 0 /* for passing to file_softmagic */
+
+ uint8_t dummy1;
/* Word 2 */
uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
uint8_t vallen; /* length of string value, if any */
- uint8_t type; /* int, short, long or string. */
- uint8_t in_type; /* type of indirrection */
+ uint8_t type; /* comparison type (FILE_*) */
+ uint8_t in_type; /* type of indirection */
#define FILE_INVALID 0
#define FILE_BYTE 1
#define FILE_SHORT 2
@@ -147,7 +158,13 @@ struct magic {
#define FILE_QLDATE 30
#define FILE_LEQLDATE 31
#define FILE_BEQLDATE 32
-#define FILE_NAMES_SIZE 33/* size of array to contain all names */
+#define FILE_FLOAT 33
+#define FILE_BEFLOAT 34
+#define FILE_LEFLOAT 35
+#define FILE_DOUBLE 36
+#define FILE_BEDOUBLE 37
+#define FILE_LEDOUBLE 38
+#define FILE_NAMES_SIZE 39/* size of array to contain all names */
#define IS_STRING(t) \
((t) == FILE_STRING || \
@@ -162,16 +179,18 @@ struct magic {
#define FILE_FMT_NUM 1 /* "cduxXi" */
#define FILE_FMT_STR 2 /* "s" */
#define FILE_FMT_QUAD 3 /* "ll" */
+#define FILE_FMT_FLOAT 4 /* "eEfFgG" */
+#define FILE_FMT_DOUBLE 5 /* "eEfFgG" */
/* Word 3 */
uint8_t in_op; /* operator for indirection */
uint8_t mask_op; /* operator for mask */
#ifdef ENABLE_CONDITIONALS
uint8_t cond; /* conditional type */
- uint8_t dummy1;
+ uint8_t dummy2;
#else
- uint8_t dummy1;
uint8_t dummy2;
+ uint8_t dummy3;
#endif
#define FILE_OPS "&|^+-*/%"
@@ -212,7 +231,7 @@ struct magic {
} _s; /* for use with string types */
} _u;
#define num_mask _u._mask
-#define str_count _u._s._count
+#define str_range _u._s._count
#define str_flags _u._s._flags
/* Words 9-16 */
@@ -225,9 +244,13 @@ struct magic {
uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */
char s[MAXstring]; /* the search string or regex pattern */
+ float f;
+ double d;
} value; /* either number or string */
/* Words 17..31 */
char desc[MAXDESC]; /* description */
+ /* Words 32..47 */
+ char mimetype[MAXDESC]; /* MIME type */
};
#define BIT(A) (1 << (A))
@@ -242,6 +265,7 @@ struct magic {
#define CHAR_IGNORE_UPPERCASE 'C'
#define CHAR_REGEX_OFFSET_START 's'
#define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
+#define STRING_DEFAULT_RANGE 100
/* list of magic entries */
@@ -268,14 +292,8 @@ struct magic_set {
} *li;
} c;
struct out {
- /* Accumulation buffer */
- char *buf;
- char *ptr;
- size_t left;
- size_t size;
- /* Printable buffer */
- char *pbuf;
- size_t psize;
+ char *buf; /* Accumulation buffer */
+ char *pbuf; /* Printable buffer */
} o;
uint32_t offset;
int error;
@@ -292,9 +310,14 @@ struct magic_set {
size_t rm_len; /* match length */
} search;
+ /* 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 */
};
+/* Type for Unicode characters */
+typedef unsigned long unichar;
+
struct stat;
protected const char *file_fmttime(uint32_t, int);
protected int file_buffer(struct magic_set *, int, const char *, const void *,
@@ -309,7 +332,7 @@ protected int file_zmagic(struct magic_set *, int, const char *,
const unsigned char *, size_t);
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
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);
+protected int file_softmagic(struct magic_set *, const unsigned char *, size_t, int);
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
protected uint64_t file_signextend(struct magic_set *, struct magic *,
uint64_t);
@@ -326,6 +349,7 @@ protected size_t file_mbswidth(const char *);
protected const char *file_getbuffer(struct magic_set *);
protected ssize_t sread(int, void *, size_t, int);
protected int file_check_mem(struct magic_set *, unsigned int);
+protected int file_looks_utf8(const unsigned char *, size_t, unichar *, size_t *);
#ifndef COMPILE_ONLY
extern const char *file_names[];
@@ -343,8 +367,11 @@ extern char *sys_errlist[];
#define strtoul(a, b, c) strtol(a, b, c)
#endif
-#ifndef HAVE_SNPRINTF
-int snprintf(char *, size_t, const char *, ...);
+#ifndef HAVE_VASPRINTF
+int vasprintf(char **ptr, const char *format_string, va_list vargs);
+#endif
+#ifndef HAVE_ASPRINTF
+int asprintf(char **ptr, const char *format_string, ...);
#endif
#if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
@@ -355,6 +382,9 @@ int snprintf(char *, size_t, const char *, ...);
#define O_BINARY 0
#endif
+#ifdef __GNUC__
+static const char *rcsid(const char *) __attribute__((__used__));
+#endif
#define FILE_RCSID(id) \
static const char *rcsid(const char *p) { \
return rcsid(p = id); \
diff --git a/usr.bin/file/file_opts.h b/usr.bin/file/file_opts.h
new file mode 100644
index 00000000000..46bc08ae4b4
--- /dev/null
+++ b/usr.bin/file/file_opts.h
@@ -0,0 +1,48 @@
+/*
+ * Table of command-line options
+ *
+ * The first column specifies the short name, if any, or 0 if none.
+ * The second column specifies the long name.
+ * The third column specifies whether it takes a parameter.
+ * The fourth column is the documentation.
+ *
+ * N.B. The long options' order must correspond to the code in file.c,
+ * and OPTSTRING must be kept up-to-date with the short options.
+ * Pay particular attention to the numbers of long-only options in the
+ * switch statement!
+ */
+
+OPT_LONGONLY("help", 0, " display this help and exit\n")
+OPT('v', "version", 0, " output version information and exit\n")
+OPT('m', "magic-file", 1, " LIST use LIST as a colon-separated list of magic\n"
+ " number files\n")
+OPT('z', "uncompress", 0, " try to look inside compressed files\n")
+OPT('b', "brief", 0, " do not prepend filenames to output lines\n")
+OPT('c', "checking-printout", 0, " print the parsed form of the magic file, use in\n"
+ " conjunction with -m to debug a new magic file\n"
+ " before installing it\n")
+OPT('e', "exclude", 1, " TEST exclude TEST from the list of test to be\n"
+ " performed for file. Valid tests are:\n"
+ " ascii, apptype, compress, elf, soft, tar, tokens, troff\n")
+OPT('f', "files-from", 1, " FILE read the filenames to be examined from FILE\n")
+OPT('F', "separator", 1, " STRING use string as separator instead of `:'\n")
+OPT('i', "mime", 0, " output MIME type strings (--mime-type and\n"
+ " --mime-encoding)\n")
+OPT_LONGONLY("mime-type", 0, " output the MIME type\n")
+OPT_LONGONLY("mime-encoding", 0, " output the MIME encoding\n")
+OPT('k', "keep-going", 0, " don't stop at the first match\n")
+#ifdef S_IFLNK
+OPT('L', "dereference", 0, " follow symlinks (default)\n")
+OPT('h', "no-dereference", 0, " don't follow symlinks\n")
+#endif
+OPT('n', "no-buffer", 0, " do not buffer output\n")
+OPT('N', "no-pad", 0, " do not pad output\n")
+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('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")
+OPT('C', "compile", 0, " compile file specified by -m\n")
+OPT('d', "debug", 0, " print debugging messages\n")
diff --git a/usr.bin/file/fsmagic.c b/usr.bin/file/fsmagic.c
index c62428b6b6a..74f1349d331 100644
--- a/usr.bin/file/fsmagic.c
+++ b/usr.bin/file/fsmagic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fsmagic.c,v 1.12 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: fsmagic.c,v 1.13 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -58,13 +58,31 @@
#undef HAVE_MAJOR
#ifndef lint
-FILE_RCSID("@(#)$Id: fsmagic.c,v 1.12 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: fsmagic.c,v 1.13 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
+private int
+bad_link(struct magic_set *ms, int err, char *buf)
+{
+ char *errfmt;
+ if (err == ELOOP)
+ errfmt = "symbolic link in a loop";
+ else
+ errfmt = "broken symbolic link to `%s'";
+ if (ms->flags & MAGIC_ERROR) {
+ file_error(ms, err, errfmt, buf);
+ return -1;
+ }
+ if (file_printf(ms, errfmt, buf) == -1)
+ return -1;
+ return 1;
+}
+
protected int
file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
{
int ret = 0;
+ int mime = ms->flags & MAGIC_MIME;
#ifdef S_IFLNK
char buf[BUFSIZ+4];
int nch;
@@ -96,11 +114,12 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return 1;
}
- if ((ms->flags & MAGIC_MIME) != 0) {
+ if (mime) {
if ((sb->st_mode & S_IFMT) != S_IFREG) {
- if (file_printf(ms, "application/x-not-regular-file")
+ if ((mime & MAGIC_MIME_TYPE) &&
+ file_printf(ms, "application/x-not-regular-file")
== -1)
- return -1;
+ return -1;
return 1;
}
}
@@ -136,7 +155,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
*/
if ((ms->flags & MAGIC_DEVICES) != 0)
break;
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STAT_ST_RDEV
# ifdef dv_unit
if (file_printf(ms, "character special (%d/%d/%d)",
major(sb->st_rdev), dv_unit(sb->st_rdev),
@@ -162,7 +181,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
*/
if ((ms->flags & MAGIC_DEVICES) != 0)
break;
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STAT_ST_RDEV
# ifdef dv_unit
if (file_printf(ms, "block special (%d/%d/%d)",
major(sb->st_rdev), dv_unit(sb->st_rdev),
@@ -208,23 +227,13 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
return -1;
return 1;
}
- buf[nch] = '\0'; /* readlink(2) forgets this */
+ buf[nch] = '\0'; /* readlink(2) does not do this */
/* If broken symlink, say so and quit early. */
if (*buf == '/') {
- if (stat(buf, &tstatbuf) < 0) {
- if (ms->flags & MAGIC_ERROR) {
- file_error(ms, errno,
- "broken symbolic link to `%s'", buf);
- return -1;
- }
- if (file_printf(ms, "broken symbolic link to `%s'",
- buf) == -1)
- return -1;
- return 1;
- }
- }
- else {
+ if (stat(buf, &tstatbuf) < 0)
+ return bad_link(ms, errno, buf);
+ } else {
char *tmp;
char buf2[BUFSIZ+BUFSIZ+4];
@@ -247,18 +256,8 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
(void)strlcat(buf2, buf, sizeof buf2); /* plus (rel) link */
tmp = buf2;
}
- if (stat(tmp, &tstatbuf) < 0) {
- if (ms->flags & MAGIC_ERROR) {
- file_error(ms, errno,
- "broken symbolic link to `%s'",
- buf);
- return -1;
- }
- if (file_printf(ms,
- "broken symbolic link to `%s'", buf) == -1)
- return -1;
- return 1;
- }
+ if (stat(tmp, &tstatbuf) < 0)
+ return bad_link(ms, errno, buf);
}
/* Otherwise, handle it. */
@@ -304,8 +303,9 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
* when we read the file.)
*/
if ((ms->flags & MAGIC_DEVICES) == 0 && sb->st_size == 0) {
- if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
- "application/x-empty" : "empty") == -1)
+ if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
+ file_printf(ms, mime ? "application/x-empty" :
+ "empty") == -1)
return -1;
return 1;
}
diff --git a/usr.bin/file/funcs.c b/usr.bin/file/funcs.c
index 7b8fdb182fa..2b4f34be86c 100644
--- a/usr.bin/file/funcs.c
+++ b/usr.bin/file/funcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: funcs.c,v 1.5 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: funcs.c,v 1.6 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
@@ -37,67 +37,40 @@
#if defined(HAVE_WCTYPE_H)
#include <wctype.h>
#endif
-#if defined(HAVE_LIMITS_H)
-#include <limits.h>
-#endif
-#ifndef SIZE_T_MAX
-#ifdef __LP64__
-#define SIZE_T_MAX (size_t)0xfffffffffffffffffU
-#else
-#define SIZE_T_MAX (size_t)0xffffffffU
-#endif
-#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: funcs.c,v 1.5 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: funcs.c,v 1.6 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
-#ifndef HAVE_VSNPRINTF
-int vsnprintf(char *, size_t, const char *, va_list);
-#endif
-
/*
- * Like printf, only we print to a buffer and advance it.
+ * Like printf, only we append to a buffer.
*/
protected int
file_printf(struct magic_set *ms, const char *fmt, ...)
{
va_list ap;
- size_t len, size;
- char *buf;
+ int len;
+ char *buf, *newstr;
va_start(ap, fmt);
+ len = vasprintf(&buf, fmt, ap);
+ if (len < 0)
+ goto out;
+ va_end(ap);
- len = vsnprintf(ms->o.ptr, ms->o.left, fmt, ap);
- if (len == -1) {
- file_error(ms, errno, "vsnprintf failed");
- return -1;
- } else if (len >= ms->o.left) {
- long diff; /* XXX: really ptrdiff_t */
-
- va_end(ap);
- size = (ms->o.size - ms->o.left) + len + 1024;
- if ((buf = realloc(ms->o.buf, size)) == NULL) {
- file_oomem(ms, size);
- return -1;
- }
- diff = ms->o.ptr - ms->o.buf;
- ms->o.ptr = buf + diff;
- ms->o.buf = buf;
- ms->o.left = size - diff;
- ms->o.size = size;
-
- va_start(ap, fmt);
- len = vsnprintf(ms->o.ptr, ms->o.left, fmt, ap);
- if (len == -1) {
- file_error(ms, errno, "vsnprintf failed");
- return -1;
- }
+ if (ms->o.buf != NULL) {
+ len = asprintf(&newstr, "%s%s", ms->o.buf, buf);
+ free(buf);
+ if (len < 0)
+ goto out;
+ free(ms->o.buf);
+ buf = newstr;
}
- va_end(ap);
- ms->o.ptr += len;
- ms->o.left -= len;
+ ms->o.buf = buf;
return 0;
+out:
+ file_error(ms, errno, "vasprintf failed");
+ return -1;
}
/*
@@ -108,21 +81,17 @@ private void
file_error_core(struct magic_set *ms, int error, const char *f, va_list va,
uint32_t lineno)
{
- size_t len;
/* Only the first error is ok */
if (ms->haderr)
return;
- len = 0;
if (lineno != 0) {
- (void)snprintf(ms->o.buf, ms->o.size, "line %u: ", lineno);
- len = strlen(ms->o.buf);
- }
- (void)vsnprintf(ms->o.buf + len, ms->o.size - len, f, va);
- if (error > 0) {
- len = strlen(ms->o.buf);
- (void)snprintf(ms->o.buf + len, ms->o.size - len, " (%s)",
- strerror(error));
+ free(ms->o.buf);
+ ms->o.buf = NULL;
+ file_printf(ms, "line %u: ", lineno);
}
+ file_printf(ms, f, va);
+ if (error > 0)
+ file_printf(ms, " (%s)", strerror(error));
ms->haderr++;
ms->error = error;
}
@@ -173,59 +142,73 @@ protected int
file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf,
size_t nb)
{
- int m;
+ int m;
+ int mime = ms->flags & MAGIC_MIME;
+
+ if (nb == 0) {
+ if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
+ file_printf(ms, mime ? "application/x-empty" :
+ "empty") == -1)
+ return -1;
+ return 1;
+ } else if (nb == 1) {
+ if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
+ file_printf(ms, mime ? "application/octet-stream" :
+ "very short file (no magic)") == -1)
+ return -1;
+ return 1;
+ }
#ifdef __EMX__
- if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) {
- switch (file_os2_apptype(ms, inname, buf, nb)) {
- case -1:
- return -1;
- case 0:
- break;
- default:
- return 1;
+ if ((ms->flags & MAGIC_NO_CHECK_APPTYPE) == 0 && inname) {
+ switch (file_os2_apptype(ms, inname, buf, nb)) {
+ case -1:
+ return -1;
+ case 0:
+ break;
+ default:
+ return 1;
+ }
}
- }
#endif
- /* try compression stuff */
- if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) != 0 ||
- (m = file_zmagic(ms, fd, inname, buf, nb)) == 0) {
- /* Check if we have a tar file */
- if ((ms->flags & MAGIC_NO_CHECK_TAR) != 0 ||
- (m = file_is_tar(ms, buf, nb)) == 0) {
- /* try tests in /etc/magic (or surrogate magic file) */
- if ((ms->flags & MAGIC_NO_CHECK_SOFT) != 0 ||
- (m = file_softmagic(ms, buf, nb)) == 0) {
- /* try known keywords, check whether it is ASCII */
- if ((ms->flags & MAGIC_NO_CHECK_ASCII) != 0 ||
- (m = file_ascmagic(ms, buf, nb)) == 0) {
- /* abandon hope, all ye who remain here */
- if (file_printf(ms, ms->flags & MAGIC_MIME ?
- (nb ? "application/octet-stream" :
- "application/empty") :
- (nb ? "data" :
- "empty")) == -1)
- return -1;
- m = 1;
+ /* try compression stuff */
+ if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) != 0 ||
+ (m = file_zmagic(ms, fd, inname, buf, nb)) == 0) {
+ /* Check if we have a tar file */
+ if ((ms->flags & MAGIC_NO_CHECK_TAR) != 0 ||
+ (m = file_is_tar(ms, buf, nb)) == 0) {
+ /* try tests in /etc/magic (or surrogate magic file) */
+ if ((ms->flags & MAGIC_NO_CHECK_SOFT) != 0 ||
+ (m = file_softmagic(ms, buf, nb, BINTEST)) == 0) {
+ /* try known keywords, check whether it is ASCII */
+ if ((ms->flags & MAGIC_NO_CHECK_ASCII) != 0 ||
+ (m = file_ascmagic(ms, buf, nb)) == 0) {
+ /* abandon hope, all ye who remain here */
+ if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
+ file_printf(ms, mime ? "application/octet-stream" :
+ "data") == -1)
+ return -1;
+ m = 1;
+ }
}
}
}
- }
#ifdef BUILTIN_ELF
- if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 && nb > 5 && fd != -1) {
- /*
- * We matched something in the file, so this *might*
- * be an ELF file, and the file is at least 5 bytes
- * long, so if it's an ELF file it has at least one
- * byte past the ELF magic number - try extracting
- * information from the ELF headers that cannot easily
- * be extracted with rules in the magic file.
- */
- (void)file_tryelf(ms, fd, buf, nb);
- }
+ if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 &&
+ nb > 5 && fd != -1) {
+ /*
+ * We matched something in the file, so this *might*
+ * be an ELF file, and the file is at least 5 bytes
+ * long, so if it's an ELF file it has at least one
+ * byte past the ELF magic number - try extracting
+ * information from the ELF headers that cannot easily
+ * be extracted with rules in the magic file.
+ */
+ (void)file_tryelf(ms, fd, buf, nb);
+ }
#endif
- return m;
+ return m;
}
#endif
@@ -236,8 +219,7 @@ file_reset(struct magic_set *ms)
file_error(ms, 0, "no magic files loaded");
return -1;
}
- ms->o.ptr = ms->o.buf;
- ms->o.left = ms->o.size;
+ ms->o.buf = NULL;
ms->haderr = 0;
ms->error = -1;
return 0;
@@ -263,21 +245,18 @@ file_getbuffer(struct magic_set *ms)
if (ms->flags & MAGIC_RAW)
return ms->o.buf;
- len = ms->o.size - ms->o.left;
/* * 4 is for octal representation, + 1 is for NUL */
- if (len > (SIZE_T_MAX - 1) / 4) {
+ len = strlen(ms->o.buf);
+ if (len > (SIZE_MAX - 1) / 4) {
file_oomem(ms, len);
return NULL;
}
psize = len * 4 + 1;
- if (ms->o.psize < psize) {
- if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
- file_oomem(ms, psize);
- return NULL;
- }
- ms->o.psize = psize;
- ms->o.pbuf = pbuf;
+ if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
+ file_oomem(ms, psize);
+ return NULL;
}
+ ms->o.pbuf = pbuf;
#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
{
@@ -290,7 +269,7 @@ file_getbuffer(struct magic_set *ms)
np = ms->o.pbuf;
op = ms->o.buf;
- eop = op + strlen(ms->o.buf);
+ eop = op + len;
while (op < eop) {
bytesconsumed = mbrtowc(&nextchar, op,
@@ -350,28 +329,3 @@ file_check_mem(struct magic_set *ms, unsigned int level)
#endif /* ENABLE_CONDITIONALS */
return 0;
}
-/*
- * Yes these wrappers suffer from buffer overflows, but if your OS does not
- * have the real functions, maybe you should consider replacing your OS?
- */
-#ifndef HAVE_VSNPRINTF
-int
-vsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
-{
- return vsprintf(buf, fmt, ap);
-}
-#endif
-
-#ifndef HAVE_SNPRINTF
-/*ARGSUSED*/
-int
-snprintf(char *buf, size_t len, const char *fmt, ...)
-{
- int rv;
- va_list ap;
- va_start(ap, fmt);
- rv = vsprintf(buf, fmt, ap);
- va_end(ap);
- return rv;
-}
-#endif
diff --git a/usr.bin/file/is_tar.c b/usr.bin/file/is_tar.c
index cff746c55a4..8e0dc6d37c9 100644
--- a/usr.bin/file/is_tar.c
+++ b/usr.bin/file/is_tar.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: is_tar.c,v 1.8 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: is_tar.c,v 1.9 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -46,7 +46,7 @@
#include "tar.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: is_tar.c,v 1.8 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: is_tar.c,v 1.9 2009/04/24 18:54:34 chl Exp $")
#endif
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
@@ -54,6 +54,12 @@ FILE_RCSID("@(#)$Id: is_tar.c,v 1.8 2008/05/08 01:40:56 chl Exp $")
private int is_tar(const unsigned char *, size_t);
private int from_oct(int, const char *); /* Decode octal number */
+static const char tartype[][32] = {
+ "tar archive",
+ "POSIX tar archive",
+ "POSIX tar archive (GNU)",
+};
+
protected int
file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
{
@@ -61,33 +67,27 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
* Do the tar test first, because if the first file in the tar
* archive starts with a dot, we can confuse it with an nroff file.
*/
- switch (is_tar(buf, nbytes)) {
- case 1:
- if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
- "application/x-tar" : "tar archive") == -1)
- return -1;
- return 1;
- case 2:
- if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
- "application/x-tar, POSIX" : "POSIX tar archive") == -1)
- return -1;
- return 1;
- case 3:
- if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
- "application/x-tar, POSIX (GNU)" :
- "POSIX tar archive (GNU)") == -1)
- return -1;
- return 1;
- default:
+ int tar = is_tar(buf, nbytes);
+ int mime = ms->flags & MAGIC_MIME;
+
+ if (tar < 1 || tar > 3)
return 0;
- }
+
+ if (mime == MAGIC_MIME_ENCODING)
+ return 0;
+
+ if (file_printf(ms, mime ? "application/x-tar" :
+ tartype[tar - 1]) == -1)
+ return -1;
+ return 1;
}
/*
* Return
* 0 if the checksum is bad (i.e., probably not a tar archive),
* 1 for old UNIX tar file,
- * 2 for Unix Std (POSIX) tar file.
+ * 2 for Unix Std (POSIX) tar file,
+ * 3 for GNU tar file.
*/
private int
is_tar(const unsigned char *buf, size_t nbytes)
diff --git a/usr.bin/file/magdir/acorn b/usr.bin/file/magdir/acorn
index 8245a96b777..156b0235521 100644
--- a/usr.bin/file/magdir/acorn
+++ b/usr.bin/file/magdir/acorn
@@ -1,4 +1,4 @@
-# $OpenBSD: acorn,v 1.1 2004/06/03 03:14:19 tedu Exp $
+# $OpenBSD: acorn,v 1.2 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# acorn: file(1) magic for files found on Acorn systems
@@ -32,3 +32,38 @@
0 string Maestro\r RISC OS music file
>8 byte x version %d
+>8 byte x type %d
+
+# Digital Symphony data files
+# From: Bernard Jungen (bern8817@euphonynet.be)
+0 string \x02\x01\x13\x13\x13\x01\x0d\x10 Digital Symphony sound sample (RISC OS),
+>8 byte x version %d,
+>9 pstring x named "%s",
+>(9.b+19) byte =0 8-bit logarithmic
+>(9.b+19) byte =1 LZW-compressed linear
+>(9.b+19) byte =2 8-bit linear signed
+>(9.b+19) byte =3 16-bit linear signed
+>(9.b+19) byte =4 SigmaDelta-compressed linear
+>(9.b+19) byte =5 SigmaDelta-compressed logarithmic
+>(9.b+19) byte >5 unknown format
+
+0 string \x02\x01\x13\x13\x14\x12\x01\x0b Digital Symphony song (RISC OS),
+>8 byte x version %d,
+>9 byte =1 1 voice,
+>9 byte !1 %d voices,
+>10 leshort =1 1 track,
+>10 leshort !1 %d tracks,
+>12 leshort =1 1 pattern
+>12 leshort !1 %d patterns
+
+0 string \x02\x01\x13\x13\x10\x14\x12\x0e
+>9 byte =0 Digital Symphony sequence (RISC OS),
+>>8 byte x version %d,
+>>10 byte =1 1 line,
+>>10 byte !1 %d lines,
+>>11 leshort =1 1 position
+>>11 leshort !1 %d positions
+>9 byte =1 Digital Symphony pattern data (RISC OS),
+>>8 byte x version %d,
+>>10 leshort =1 1 pattern
+>>10 leshort !1 %d patterns
diff --git a/usr.bin/file/magdir/adventure b/usr.bin/file/magdir/adventure
index 9d8c985df6e..04ff0ceb8ae 100644
--- a/usr.bin/file/magdir/adventure
+++ b/usr.bin/file/magdir/adventure
@@ -1,4 +1,4 @@
-# $OpenBSD: adventure,v 1.1 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: adventure,v 1.2 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# adventure: file(1) magic for Adventure game files
@@ -74,3 +74,13 @@
>10 belong 0x0A0D1A00
>>14 string >\0 %s saved game data
+# Danny Milosavljevic <danny.milo@gmx.net>
+# this are adrift (adventure game standard) game files, extension .taf
+# depending on version magic continues with 0x93453E6139FA (V 4.0)
+# 0x9445376139FA (V 3.90)
+# 0x9445366139FA (V 3.80)
+# this is from source (http://www.adrift.org.uk/) and I have some taf
+# files, and checked them.
+#0 belong 0x3C423FC9
+#>4 belong 0x6A87C2CF Adrift game file
+#!:mime application/x-adrift
diff --git a/usr.bin/file/magdir/animation b/usr.bin/file/magdir/animation
index e525bd137c3..d498d37c106 100644
--- a/usr.bin/file/magdir/animation
+++ b/usr.bin/file/magdir/animation
@@ -1,4 +1,4 @@
-# $OpenBSD: animation,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: animation,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# animation: file(1) magic for animation/movie formats
@@ -9,37 +9,58 @@
# SGI and Apple formats
0 string MOVI Silicon Graphics movie file
+!:mime video/x-sgi-movie
4 string moov Apple QuickTime
+!:mime video/quicktime
>12 string mvhd \b movie (fast start)
>12 string mdra \b URL
>12 string cmov \b movie (fast start, compressed header)
>12 string rmra \b multiple URLs
4 string mdat Apple QuickTime movie (unoptimized)
-4 string wide Apple QuickTime movie (unoptimized)
-4 string skip Apple QuickTime movie (modified)
-4 string free Apple QuickTime movie (modified)
+!:mime video/quicktime
+#4 string wide Apple QuickTime movie (unoptimized)
+#!:mime video/quicktime
+#4 string skip Apple QuickTime movie (modified)
+#!:mime video/quicktime
+#4 string free Apple QuickTime movie (modified)
+#!:mime video/quicktime
4 string idsc Apple QuickTime image (fast start)
-4 string idat Apple QuickTime image (unoptimized)
+!:mime image/x-quicktime
+#4 string idat Apple QuickTime image (unoptimized)
+#!:mime image/x-quicktime
4 string pckg Apple QuickTime compressed archive
+!:mime application/x-quicktime-player
4 string/B jP JPEG 2000 image
+!:mime image/jp2
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/B jp2 \b, JPEG 2000
+!:mime image/jp2
>8 string 3gp \b, MPEG v4 system, 3GPP
+!:mime video/3gpp
>>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 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/B M4A \b, MPEG v4 system, iTunes AAC-LC
+!:mime audio/mp4
+>8 string/B M4V \b, MPEG v4 system, iTunes AVC-LC
+!:mime video/mp4
>8 string/B M4P \b, MPEG v4 system, iTunes AES encrypted
>8 string/B M4B \b, MPEG v4 system, iTunes bookmarked
>8 string/B qt \b, Apple QuickTime movie
+!:mime video/quicktime
# MPEG sequences
# Scans for all common MPEG header start codes
@@ -49,7 +70,7 @@
>>5 byte 77 \b, main
>>5 byte 88 \b, extended
>>7 byte x \b @ L %u
-0 belong&0xFFFFFF00 0x00000100 MPEG sequence
+0 string \000\000\001 MPEG sequence
>3 byte 0xBA
>>4 byte &0x40 \b, v2, program multiplex
>>4 byte ^0x40 \b, v1, system multiplex
@@ -253,22 +274,39 @@
# modified to fully support MPEG ADTS
# MP3, M1A
-0 beshort&0xFFFE 0xFFFA MPEG ADTS, layer III, v1
+# modified by Joerg Jenderek
+# GRR the original test are too common for many DOS files
+# so don't accept as MP3 until we've tested the rate
+0 beshort&0xFFFE
# rates
->2 byte&0xF0 0x10 \b, 32 kBits
->2 byte&0xF0 0x20 \b, 40 kBits
->2 byte&0xF0 0x30 \b, 48 kBits
->2 byte&0xF0 0x40 \b, 56 kBits
->2 byte&0xF0 0x50 \b, 64 kBits
->2 byte&0xF0 0x60 \b, 80 kBits
->2 byte&0xF0 0x70 \b, 96 kBits
->2 byte&0xF0 0x80 \b, 112 kBits
->2 byte&0xF0 0x90 \b, 128 kBits
->2 byte&0xF0 0xA0 \b, 160 kBits
->2 byte&0xF0 0xB0 \b, 192 kBits
->2 byte&0xF0 0xC0 \b, 224 kBits
->2 byte&0xF0 0xD0 \b, 256 kBits
->2 byte&0xF0 0xE0 \b, 320 kBits
+>2 byte&0xF0 0x10 MPEG ADTS, layer III, v1, 32 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x20 MPEG ADTS, layer III, v1, 40 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x30 MPEG ADTS, layer III, v1, 48 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x40 MPEG ADTS, layer III, v1, 56 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x50 MPEG ADTS, layer III, v1, 64 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x60 MPEG ADTS, layer III, v1, 80 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x70 MPEG ADTS, layer III, v1, 96 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x80 MPEG ADTS, layer III, v1, 112 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0x90 MPEG ADTS, layer III, v1, 128 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0xA0 MPEG ADTS, layer III, v1, 160 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0xB0 MPEG ADTS, layer III, v1, 192 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0xC0 MPEG ADTS, layer III, v1, 224 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0xD0 MPEG ADTS, layer III, v1, 256 kbps
+!:mime audio/mpeg
+>2 byte&0xF0 0xE0 MPEG ADTS, layer III, v1, 320 kbps
+!:mime audio/mpeg
# timing
>2 byte&0x0C 0x00 \b, 44.1 kHz
>2 byte&0x0C 0x04 \b, 48 kHz
@@ -289,20 +327,20 @@
# MP2, M1A
0 beshort&0xFFFE 0xFFFC MPEG ADTS, layer II, v1
# rates
->2 byte&0xF0 0x10 \b, 32 kBits
->2 byte&0xF0 0x20 \b, 48 kBits
->2 byte&0xF0 0x30 \b, 56 kBits
->2 byte&0xF0 0x40 \b, 64 kBits
->2 byte&0xF0 0x50 \b, 80 kBits
->2 byte&0xF0 0x60 \b, 96 kBits
->2 byte&0xF0 0x70 \b, 112 kBits
->2 byte&0xF0 0x80 \b, 128 kBits
->2 byte&0xF0 0x90 \b, 160 kBits
->2 byte&0xF0 0xA0 \b, 192 kBits
->2 byte&0xF0 0xB0 \b, 224 kBits
->2 byte&0xF0 0xC0 \b, 256 kBits
->2 byte&0xF0 0xD0 \b, 320 kBits
->2 byte&0xF0 0xE0 \b, 384 kBits
+>2 byte&0xF0 0x10 \b, 32 kbps
+>2 byte&0xF0 0x20 \b, 48 kbps
+>2 byte&0xF0 0x30 \b, 56 kbps
+>2 byte&0xF0 0x40 \b, 64 kbps
+>2 byte&0xF0 0x50 \b, 80 kbps
+>2 byte&0xF0 0x60 \b, 96 kbps
+>2 byte&0xF0 0x70 \b, 112 kbps
+>2 byte&0xF0 0x80 \b, 128 kbps
+>2 byte&0xF0 0x90 \b, 160 kbps
+>2 byte&0xF0 0xA0 \b, 192 kbps
+>2 byte&0xF0 0xB0 \b, 224 kbps
+>2 byte&0xF0 0xC0 \b, 256 kbps
+>2 byte&0xF0 0xD0 \b, 320 kbps
+>2 byte&0xF0 0xE0 \b, 384 kbps
# timing
>2 byte&0x0C 0x00 \b, 44.1 kHz
>2 byte&0x0C 0x04 \b, 48 kHz
@@ -323,58 +361,59 @@
# MPA, M1A
# updated by Joerg Jenderek
# GRR the original test are too common for many DOS files, so test 32 <= kbits <= 448
-0 beshort&0xFFFE 0xFFFE
->2 ubyte&0xF0 >0x0F
->>2 ubyte&0xF0 <0xE1 MPEG ADTS, layer I, v1
-# rate
->>>2 byte&0xF0 0x10 \b, 32 kBits
->>>2 byte&0xF0 0x20 \b, 64 kBits
->>>2 byte&0xF0 0x30 \b, 96 kBits
->>>2 byte&0xF0 0x40 \b, 128 kBits
->>>2 byte&0xF0 0x50 \b, 160 kBits
->>>2 byte&0xF0 0x60 \b, 192 kBits
->>>2 byte&0xF0 0x70 \b, 224 kBits
->>>2 byte&0xF0 0x80 \b, 256 kBits
->>>2 byte&0xF0 0x90 \b, 288 kBits
->>>2 byte&0xF0 0xA0 \b, 320 kBits
->>>2 byte&0xF0 0xB0 \b, 352 kBits
->>>2 byte&0xF0 0xC0 \b, 384 kBits
->>>2 byte&0xF0 0xD0 \b, 416 kBits
->>>2 byte&0xF0 0xE0 \b, 448 kBits
-# timing
->>>2 byte&0x0C 0x00 \b, 44.1 kHz
->>>2 byte&0x0C 0x04 \b, 48 kHz
->>>2 byte&0x0C 0x08 \b, 32 kHz
-# channels/options
->>>3 byte&0xC0 0x00 \b, Stereo
->>>3 byte&0xC0 0x40 \b, JntStereo
->>>3 byte&0xC0 0x80 \b, 2x Monaural
->>>3 byte&0xC0 0xC0 \b, Monaural
-#>1 byte ^0x01 \b, Data Verify
-#>2 byte &0x02 \b, Packet Pad
-#>2 byte &0x01 \b, Custom Flag
-#>3 byte &0x08 \b, Copyrighted
-#>3 byte &0x04 \b, Original Source
-#>3 byte&0x03 1 \b, NR: 50/15 ms
-#>3 byte&0x03 3 \b, NR: CCIT J.17
+# GRR this test is still too general as it catches a BOM of UTF-16 files (0xFFFE)
+#0 beshort&0xFFFE 0xFFFE
+#>2 ubyte&0xF0 >0x0F
+#>>2 ubyte&0xF0 <0xE1 MPEG ADTS, layer I, v1
+## rate
+#>>>2 byte&0xF0 0x10 \b, 32 kbps
+#>>>2 byte&0xF0 0x20 \b, 64 kbps
+#>>>2 byte&0xF0 0x30 \b, 96 kbps
+#>>>2 byte&0xF0 0x40 \b, 128 kbps
+#>>>2 byte&0xF0 0x50 \b, 160 kbps
+#>>>2 byte&0xF0 0x60 \b, 192 kbps
+#>>>2 byte&0xF0 0x70 \b, 224 kbps
+#>>>2 byte&0xF0 0x80 \b, 256 kbps
+#>>>2 byte&0xF0 0x90 \b, 288 kbps
+#>>>2 byte&0xF0 0xA0 \b, 320 kbps
+#>>>2 byte&0xF0 0xB0 \b, 352 kbps
+#>>>2 byte&0xF0 0xC0 \b, 384 kbps
+#>>>2 byte&0xF0 0xD0 \b, 416 kbps
+#>>>2 byte&0xF0 0xE0 \b, 448 kbps
+## timing
+#>>>2 byte&0x0C 0x00 \b, 44.1 kHz
+#>>>2 byte&0x0C 0x04 \b, 48 kHz
+#>>>2 byte&0x0C 0x08 \b, 32 kHz
+## channels/options
+#>>>3 byte&0xC0 0x00 \b, Stereo
+#>>>3 byte&0xC0 0x40 \b, JntStereo
+#>>>3 byte&0xC0 0x80 \b, 2x Monaural
+#>>>3 byte&0xC0 0xC0 \b, Monaural
+##>1 byte ^0x01 \b, Data Verify
+##>2 byte &0x02 \b, Packet Pad
+##>2 byte &0x01 \b, Custom Flag
+##>3 byte &0x08 \b, Copyrighted
+##>3 byte &0x04 \b, Original Source
+##>3 byte&0x03 1 \b, NR: 50/15 ms
+##>3 byte&0x03 3 \b, NR: CCIT J.17
# MP3, M2A
0 beshort&0xFFFE 0xFFF2 MPEG ADTS, layer III, v2
# rate
->2 byte&0xF0 0x10 \b, 8 kBits
->2 byte&0xF0 0x20 \b, 16 kBits
->2 byte&0xF0 0x30 \b, 24 kBits
->2 byte&0xF0 0x40 \b, 32 kBits
->2 byte&0xF0 0x50 \b, 40 kBits
->2 byte&0xF0 0x60 \b, 48 kBits
->2 byte&0xF0 0x70 \b, 56 kBits
->2 byte&0xF0 0x80 \b, 64 kBits
->2 byte&0xF0 0x90 \b, 80 kBits
->2 byte&0xF0 0xA0 \b, 96 kBits
->2 byte&0xF0 0xB0 \b, 112 kBits
->2 byte&0xF0 0xC0 \b, 128 kBits
->2 byte&0xF0 0xD0 \b, 144 kBits
->2 byte&0xF0 0xE0 \b, 160 kBits
+>2 byte&0xF0 0x10 \b, 8 kbps
+>2 byte&0xF0 0x20 \b, 16 kbps
+>2 byte&0xF0 0x30 \b, 24 kbps
+>2 byte&0xF0 0x40 \b, 32 kbps
+>2 byte&0xF0 0x50 \b, 40 kbps
+>2 byte&0xF0 0x60 \b, 48 kbps
+>2 byte&0xF0 0x70 \b, 56 kbps
+>2 byte&0xF0 0x80 \b, 64 kbps
+>2 byte&0xF0 0x90 \b, 80 kbps
+>2 byte&0xF0 0xA0 \b, 96 kbps
+>2 byte&0xF0 0xB0 \b, 112 kbps
+>2 byte&0xF0 0xC0 \b, 128 kbps
+>2 byte&0xF0 0xD0 \b, 144 kbps
+>2 byte&0xF0 0xE0 \b, 160 kbps
# timing
>2 byte&0x0C 0x00 \b, 22.05 kHz
>2 byte&0x0C 0x04 \b, 24 kHz
@@ -395,20 +434,20 @@
# MP2, M2A
0 beshort&0xFFFE 0xFFF4 MPEG ADTS, layer II, v2
# rate
->2 byte&0xF0 0x10 \b, 8 kBits
->2 byte&0xF0 0x20 \b, 16 kBits
->2 byte&0xF0 0x30 \b, 24 kBits
->2 byte&0xF0 0x40 \b, 32 kBits
->2 byte&0xF0 0x50 \b, 40 kBits
->2 byte&0xF0 0x60 \b, 48 kBits
->2 byte&0xF0 0x70 \b, 56 kBits
->2 byte&0xF0 0x80 \b, 64 kBits
->2 byte&0xF0 0x90 \b, 80 kBits
->2 byte&0xF0 0xA0 \b, 96 kBits
->2 byte&0xF0 0xB0 \b, 112 kBits
->2 byte&0xF0 0xC0 \b, 128 kBits
->2 byte&0xF0 0xD0 \b, 144 kBits
->2 byte&0xF0 0xE0 \b, 160 kBits
+>2 byte&0xF0 0x10 \b, 8 kbps
+>2 byte&0xF0 0x20 \b, 16 kbps
+>2 byte&0xF0 0x30 \b, 24 kbps
+>2 byte&0xF0 0x40 \b, 32 kbps
+>2 byte&0xF0 0x50 \b, 40 kbps
+>2 byte&0xF0 0x60 \b, 48 kbps
+>2 byte&0xF0 0x70 \b, 56 kbps
+>2 byte&0xF0 0x80 \b, 64 kbps
+>2 byte&0xF0 0x90 \b, 80 kbps
+>2 byte&0xF0 0xA0 \b, 96 kbps
+>2 byte&0xF0 0xB0 \b, 112 kbps
+>2 byte&0xF0 0xC0 \b, 128 kbps
+>2 byte&0xF0 0xD0 \b, 144 kbps
+>2 byte&0xF0 0xE0 \b, 160 kbps
# timing
>2 byte&0x0C 0x00 \b, 22.05 kHz
>2 byte&0x0C 0x04 \b, 24 kHz
@@ -429,20 +468,20 @@
# MPA, M2A
0 beshort&0xFFFE 0xFFF6 MPEG ADTS, layer I, v2
# rate
->2 byte&0xF0 0x10 \b, 32 kBits
->2 byte&0xF0 0x20 \b, 48 kBits
->2 byte&0xF0 0x30 \b, 56 kBits
->2 byte&0xF0 0x40 \b, 64 kBits
->2 byte&0xF0 0x50 \b, 80 kBits
->2 byte&0xF0 0x60 \b, 96 kBits
->2 byte&0xF0 0x70 \b, 112 kBits
->2 byte&0xF0 0x80 \b, 128 kBits
->2 byte&0xF0 0x90 \b, 144 kBits
->2 byte&0xF0 0xA0 \b, 160 kBits
->2 byte&0xF0 0xB0 \b, 176 kBits
->2 byte&0xF0 0xC0 \b, 192 kBits
->2 byte&0xF0 0xD0 \b, 224 kBits
->2 byte&0xF0 0xE0 \b, 256 kBits
+>2 byte&0xF0 0x10 \b, 32 kbps
+>2 byte&0xF0 0x20 \b, 48 kbps
+>2 byte&0xF0 0x30 \b, 56 kbps
+>2 byte&0xF0 0x40 \b, 64 kbps
+>2 byte&0xF0 0x50 \b, 80 kbps
+>2 byte&0xF0 0x60 \b, 96 kbps
+>2 byte&0xF0 0x70 \b, 112 kbps
+>2 byte&0xF0 0x80 \b, 128 kbps
+>2 byte&0xF0 0x90 \b, 144 kbps
+>2 byte&0xF0 0xA0 \b, 160 kbps
+>2 byte&0xF0 0xB0 \b, 176 kbps
+>2 byte&0xF0 0xC0 \b, 192 kbps
+>2 byte&0xF0 0xD0 \b, 224 kbps
+>2 byte&0xF0 0xE0 \b, 256 kbps
# timing
>2 byte&0x0C 0x00 \b, 22.05 kHz
>2 byte&0x0C 0x04 \b, 24 kHz
@@ -463,20 +502,20 @@
# MP3, M25A
0 beshort&0xFFFE 0xFFE2 MPEG ADTS, layer III, v2.5
# rate
->2 byte&0xF0 0x10 \b, 8 kBits
->2 byte&0xF0 0x20 \b, 16 kBits
->2 byte&0xF0 0x30 \b, 24 kBits
->2 byte&0xF0 0x40 \b, 32 kBits
->2 byte&0xF0 0x50 \b, 40 kBits
->2 byte&0xF0 0x60 \b, 48 kBits
->2 byte&0xF0 0x70 \b, 56 kBits
->2 byte&0xF0 0x80 \b, 64 kBits
->2 byte&0xF0 0x90 \b, 80 kBits
->2 byte&0xF0 0xA0 \b, 96 kBits
->2 byte&0xF0 0xB0 \b, 112 kBits
->2 byte&0xF0 0xC0 \b, 128 kBits
->2 byte&0xF0 0xD0 \b, 144 kBits
->2 byte&0xF0 0xE0 \b, 160 kBits
+>2 byte&0xF0 0x10 \b, 8 kbps
+>2 byte&0xF0 0x20 \b, 16 kbps
+>2 byte&0xF0 0x30 \b, 24 kbps
+>2 byte&0xF0 0x40 \b, 32 kbps
+>2 byte&0xF0 0x50 \b, 40 kbps
+>2 byte&0xF0 0x60 \b, 48 kbps
+>2 byte&0xF0 0x70 \b, 56 kbps
+>2 byte&0xF0 0x80 \b, 64 kbps
+>2 byte&0xF0 0x90 \b, 80 kbps
+>2 byte&0xF0 0xA0 \b, 96 kbps
+>2 byte&0xF0 0xB0 \b, 112 kbps
+>2 byte&0xF0 0xC0 \b, 128 kbps
+>2 byte&0xF0 0xD0 \b, 144 kbps
+>2 byte&0xF0 0xE0 \b, 160 kbps
# timing
>2 byte&0x0C 0x00 \b, 11.025 kHz
>2 byte&0x0C 0x04 \b, 12 kHz
@@ -498,6 +537,7 @@
# Stored AAC streams (instead of the MP4 format)
0 string ADIF MPEG ADIF, AAC
+!:mime audio/x-hx-aac-adif
>4 byte &0x80
>>13 byte &0x10 \b, VBR
>>13 byte ^0x10 \b, CBR
@@ -522,6 +562,7 @@
# Live or stored single AAC stream (used with MPEG-2 systems)
0 beshort&0xFFF6 0xFFF0 MPEG ADTS, AAC
+!:mime audio/x-hx-aac-adts
>1 byte &0x08 \b, v2
>1 byte ^0x08 \b, v4
# profile
@@ -558,6 +599,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
>3 byte&0xE0 0x40
>>4 byte&0x3C 0x04 \b, single stream
@@ -571,10 +613,13 @@
>>4 byte&0x78 0x18 \b, 3 streams
>>4 byte &0x20 \b, 4 or more streams
>>4 byte &0x40 \b, 8 or more streams
-0 beshort 0x4DE1 MPEG-4 LO-EP audio stream
+# This magic isn't strong enough (matches plausible ISO-8859-1 text)
+#0 beshort 0x4DE1 MPEG-4 LO-EP audio stream
+#!:mime audio/x-mp4a-latm
# FLI animation format
4 leshort 0xAF11 FLI file
+!:mime video/x-fli
>6 leshort x - %d frames,
>8 leshort x width=%d pixels,
>10 leshort x height=%d pixels,
@@ -582,6 +627,7 @@
>16 leshort x ticks/frame=%d
# FLC animation format
4 leshort 0xAF12 FLC file
+!:mime video/x-flc
>6 leshort x - %d frames
>8 leshort x width=%d pixels,
>10 leshort x height=%d pixels,
@@ -600,9 +646,11 @@
# 255 (hex FF)! The DL format is really bad.
#
#0 byte 1 DL version 1, medium format (160x100, 4 images/screen)
+#!:mime video/x-unknown
#>42 byte x - %d screens,
#>43 byte x %d commands
#0 byte 2 DL version 2
+#!:mime video/x-unknown
#>1 byte 1 - large format (320x200,1 image/screen),
#>1 byte 2 - medium format (160x100,4 images/screen),
#>1 byte >2 - unknown format,
@@ -642,6 +690,7 @@
# MNG Video Format, <URL:http://www.libpng.org/pub/mng/spec/>
0 string \x8aMNG MNG video data,
+!:mime video/x-mng
>4 belong !0x0d0a1a0a CORRUPTED,
>4 belong 0x0d0a1a0a
>>16 belong x %ld x
@@ -649,6 +698,7 @@
# JNG Video Format, <URL:http://www.libpng.org/pub/mng/spec/>
0 string \x8bJNG JNG video data,
+!:mime video/x-jng
>4 belong !0x0d0a1a0a CORRUPTED,
>4 belong 0x0d0a1a0a
>>16 belong x %ld x
@@ -659,7 +709,9 @@
# VRML (Virtual Reality Modelling Language)
0 string/b #VRML\ V1.0\ ascii VRML 1 file
+!:mime model/vrml
0 string/b #VRML\ V2.0\ utf8 ISO/IEC 14772 VRML 97 file
+!:mime model/vrml
#---------------------------------------------------------------------------
# HVQM4: compressed movie format designed by Hudson for Nintendo GameCube
@@ -679,3 +731,47 @@
>0x21 byte x v%x
0 string DVDVIDEO-VMG Video manager,
>0x21 byte x v%x
+
+# From: Behan Webster <behanw@websterwood.com>
+# NuppelVideo used by Mythtv (*.nuv)
+# Note: there are two identical stanzas here differing only in the
+# initial string matched. It used to be done with a regex, but we're
+# trying to get rid of those.
+0 string NuppelVideo MythTV NuppelVideo
+>12 string x v%s
+>20 lelong x (%d
+>24 lelong x \bx%d),
+>36 string P \bprogressive,
+>36 string I \binterlaced,
+>40 ledouble x \baspect:%.2f,
+>48 ledouble x \bfps:%.2f
+0 string MythTV MythTV NuppelVideo
+>12 string x v%s
+>20 lelong x (%d
+>24 lelong x \bx%d),
+>36 string P \bprogressive,
+>36 string I \binterlaced,
+>40 ledouble x \baspect:%.2f,
+>48 ledouble x \bfps:%.2f
+
+# MPEG file
+# MPEG sequences
+# FIXME: This section is from the old magic.mime file and needs integrating with the rest
+0 belong 0x000001BA
+>4 byte &0x40
+!:mime video/mp2p
+>4 byte ^0x40
+!:mime video/mpeg
+0 belong 0x000001BB
+!:mime video/mpeg
+0 belong 0x000001B0
+!:mime video/mp4v-es
+0 belong 0x000001B5
+!:mime video/mp4v-es
+0 belong 0x000001B3
+!:mime video/mpv
+0 belong&0xFF5FFF1F 0x47400010
+!:mime video/mp2t
+0 belong 0x00000001
+>4 byte&0x1F 0x07
+!:mime video/h264
diff --git a/usr.bin/file/magdir/apple b/usr.bin/file/magdir/apple
index 381a59657f8..b68eb49d481 100644
--- a/usr.bin/file/magdir/apple
+++ b/usr.bin/file/magdir/apple
@@ -1,9 +1,9 @@
-# $OpenBSD: apple,v 1.5 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: apple,v 1.6 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# apple: file(1) magic for Apple file formats
#
-0 string FiLeStArTfIlEsTaRt binscii (apple ][) text
+0 search/1 FiLeStArTfIlEsTaRt binscii (apple ][) text
0 string \x0aGL Binary II (apple ][) data
0 string \x76\xff Squeezed (apple ][) data
0 string NuFile NuFile archive (apple ][) data
@@ -11,6 +11,23 @@
0 belong 0x00051600 AppleSingle encoded Macintosh file
0 belong 0x00051607 AppleDouble encoded Macintosh file
+# Type: Apple Emulator 2IMG format
+# From: Radek Vokal <rvokal@redhat.com>
+0 string 2IMG Apple ][ 2IMG Disk Image
+>4 string XGS! \b, XGS
+>4 string CTKG \b, Catakig
+>4 string ShIm \b, Sheppy's ImageMaker
+>4 string WOOF \b, Sweet 16
+>4 string B2TR \b, Bernie ][ the Rescue
+>4 string !nfc \b, ASIMOV2
+>4 string x \b, Unknown Format
+>0xc byte 00 \b, DOS 3.3 sector order
+>>0x10 byte 00 \b, Volume 254
+>>0x10 byte&0x7f x \b, Volume %u
+>0xc byte 01 \b, ProDOS sector order
+>>0x14 short x \b, %u Blocks
+>0xc byte 02 \b, NIB data
+
# magic for Newton PDA package formats
# from Ruda Moura <ruda@helllabs.org>
0 string package0 Newton package, NOS 1.x,
@@ -119,11 +136,12 @@
# Nevertheless this will manage to catch a lot of images that happen
# to have a solid-colored line at the bottom of the screen.
-8144 string \x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F Apple II image with white background
-8144 string \x55\x2A\x55\x2A\x55\x2A\x55\x2A Apple II image with purple background
-8144 string \x2A\x55\x2A\x55\x2A\x55\x2A\x55 Apple II image with green background
-8144 string \xD5\xAA\xD5\xAA\xD5\xAA\xD5\xAA Apple II image with blue background
-8144 string \xAA\xD5\xAA\xD5\xAA\xD5\xAA\xD5 Apple II image with orange background
+# GRR: Magic too weak
+#8144 string \x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F Apple II image with white background
+#8144 string \x55\x2A\x55\x2A\x55\x2A\x55\x2A Apple II image with purple background
+#8144 string \x2A\x55\x2A\x55\x2A\x55\x2A\x55 Apple II image with green background
+#8144 string \xD5\xAA\xD5\xAA\xD5\xAA\xD5\xAA Apple II image with blue background
+#8144 string \xAA\xD5\xAA\xD5\xAA\xD5\xAA\xD5 Apple II image with orange background
# Beagle Bros. Apple Mechanic fonts
@@ -190,3 +208,44 @@
>0 byte <5 \b
>>13 byte 0x81 \b
>>>14 uleshort x \b, system %hd
+
+#------------------------------------------------------------------------------
+# CAF: Apple CoreAudio File Format
+#
+# Container format for high-end audio purposes.
+# From: David Remahl <dremahl@apple.com>
+#
+0 string caff CoreAudio Format audio file
+>4 beshort <10 version %d
+>6 beshort x
+
+
+#------------------------------------------------------------------------------
+# Keychain database files
+0 string kych Mac OS X Keychain File
+
+#------------------------------------------------------------------------------
+# Code Signing related file types
+0 belong 0xfade0c00 Mac OS X Code Requirement
+>8 belong 1 (opExpr)
+>4 belong x - %d bytes
+
+0 belong 0xfade0c01 Mac OS X Code Requirement Set
+>8 belong >1 containing %d items
+>4 belong x - %d bytes
+
+0 belong 0xfade0c02 Mac OS X Code Directory
+>8 belong x version %x
+>12 belong >0 flags 0x%x
+>4 belong x - %d bytes
+
+0 belong 0xfade0cc0 Mac OS X Detached Code Signature (non-executable)
+>4 belong x - %d bytes
+
+0 belong 0xfade0cc1 Mac OS X Detached Code Signature
+>8 belong >1 (%d elements)
+>4 belong x - %d bytes
+
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+# .vdi
+4 string innotek\ VirtualBox\ Disk\ Image %s
diff --git a/usr.bin/file/magdir/archive b/usr.bin/file/magdir/archive
index 6c9351b516f..4fd090e4aac 100644
--- a/usr.bin/file/magdir/archive
+++ b/usr.bin/file/magdir/archive
@@ -1,4 +1,4 @@
-# $OpenBSD: archive,v 1.5 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: archive,v 1.6 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# archive: file(1) magic for archive formats (see also "msdos" for self-
@@ -9,7 +9,9 @@
# POSIX tar archives
257 string ustar\0 POSIX tar archive
+!:mime application/x-tar # encoding: posix
257 string ustar\040\040\0 GNU tar archive
+!:mime application/x-tar # encoding: gnu
# cpio archives
#
@@ -23,7 +25,9 @@
# are defined as "short"s; I think all the new formats are
# character-header formats and thus are strings, not numbers.
0 short 070707 cpio archive
+!:mime application/x-cpio
0 short 0143561 byte-swapped cpio archive
+!:mime application/x-cpio # encoding: swapped
0 string 070707 ASCII cpio archive (pre-SVR4 or odc)
0 string 070701 ASCII cpio archive (SVR4 with no CRC)
0 string 070702 ASCII cpio archive (SVR4 with CRC)
@@ -31,8 +35,10 @@
# Debian package (needs to go before regular portable archives)
#
0 string =!<arch>\ndebian
+!:mime application/x-debian-package
>8 string debian-split part of multipart Debian package
>8 string debian-binary Debian binary package
+>8 string !debian
>68 string >\0 (format %s)
# These next two lines do not work, because a bzip2 Debian archive
# still uses gzip for the control.tar (first in the archive). Only
@@ -50,6 +56,7 @@
0 short 0177545 old PDP-11 archive
0 long 0100554 apl workspace
0 string =<ar> archive
+!:mime application/x-archive
# MIPS archive (needs to go before regular portable archives)
#
@@ -61,7 +68,7 @@
>19 string B and an EB hash table
>22 string X -- out of date
-0 string -h- Software Tools format archive text
+0 search/1 -h- Software Tools format archive text
#
# XXX - why are there multiple <ar> thingies? Note that 0x213c6172 is
@@ -80,6 +87,7 @@
# "ar" archives?
#
0 string =!<arch> current ar archive
+!:mime application/x-archive
>8 string __.SYMDEF random library
>0 belong =65538 - pre SR9.5
>0 belong =65539 - post SR9.5
@@ -122,15 +130,24 @@
# we only test some types on basis of frequency: 0x08 (83%), 0x09 (5%),
# 0x02 (5%), 0x03 (3%), 0x04 (2%), 0x06 (2%). 0x01 collides with terminfo.
0 lelong&0x8080ffff 0x0000081a ARC archive data, dynamic LZW
+!:mime application/x-arc
0 lelong&0x8080ffff 0x0000091a ARC archive data, squashed
+!:mime application/x-arc
0 lelong&0x8080ffff 0x0000021a ARC archive data, uncompressed
+!:mime application/x-arc
0 lelong&0x8080ffff 0x0000031a ARC archive data, packed
+!:mime application/x-arc
0 lelong&0x8080ffff 0x0000041a ARC archive data, squeezed
+!:mime application/x-arc
0 lelong&0x8080ffff 0x0000061a ARC archive data, crunched
+!:mime application/x-arc
# [JW] stuff taken from idarc, obviously ARC successors:
0 lelong&0x8080ffff 0x00000a1a PAK archive data
+!:mime application/x-arc
0 lelong&0x8080ffff 0x0000141a ARC+ archive data
+!:mime application/x-arc
0 lelong&0x8080ffff 0x0000481a HYP archive data
+!:mime application/x-arc
# Acorn archive formats (Disaster prone simpleton, m91dps@ecs.ox.ac.uk)
# I can't create either SPARK or ArcFS archives so I have not tested this stuff
@@ -436,6 +453,7 @@
# ARJ archiver (jason@jarthur.Claremont.EDU)
0 leshort 0xea60 ARJ archive data
+!:mime application/x-arj
>5 byte x \b, v%d,
>8 byte &0x04 multi-volume,
>8 byte &0x10 slash-switched,
@@ -488,19 +506,32 @@
# LHARC/LHA archiver (Greg Roelofs, newt@uchicago.edu)
2 string -lh0- LHarc 1.x/ARX archive data [lh0]
+!:mime application/x-lharc
2 string -lh1- LHarc 1.x/ARX archive data [lh1]
+!:mime application/x-lharc
2 string -lz4- LHarc 1.x archive data [lz4]
+!:mime application/x-lharc
2 string -lz5- LHarc 1.x archive data [lz5]
+!:mime application/x-lharc
# [never seen any but the last; -lh4- reported in comp.compression:]
2 string -lzs- LHa/LZS archive data [lzs]
+!:mime application/x-lha
2 string -lh\40- LHa 2.x? archive data [lh ]
+!:mime application/x-lha
2 string -lhd- LHa 2.x? archive data [lhd]
+!:mime application/x-lha
2 string -lh2- LHa 2.x? archive data [lh2]
+!:mime application/x-lha
2 string -lh3- LHa 2.x? archive data [lh3]
+!:mime application/x-lha
2 string -lh4- LHa (2.x) archive data [lh4]
+!:mime application/x-lha
2 string -lh5- LHa (2.x) archive data [lh5]
+!:mime application/x-lha
2 string -lh6- LHa (2.x) archive data [lh6]
+!:mime application/x-lha
2 string -lh7- LHa (2.x)/LHark archive data [lh7]
+!:mime application/x-lha
>20 byte x - header level %d
# taken from idarc [JW]
2 string -lZ PUT archive data
@@ -509,6 +540,7 @@
# RAR archiver (Greg Roelofs, newt@uchicago.edu)
0 string Rar! RAR archive data,
+!:mime application/x-rar
>44 byte x v%0x,
>10 byte >0 flags:
>>10 byte &0x01 Archive volume,
@@ -532,13 +564,19 @@
# ZIP archives (Greg Roelofs, c/o zip-bugs@wkuvx1.wku.edu)
0 string PK\003\004
+>4 byte 0x00 Zip archive data
+!:mime application/zip
>4 byte 0x09 Zip archive data, at least v0.9 to extract
+!:mime application/zip
>4 byte 0x0a Zip archive data, at least v1.0 to extract
+!:mime application/zip
>4 byte 0x0b Zip archive data, at least v1.1 to extract
+!:mime application/zip
+>0x161 string WINZIP Zip archive data, WinZIP self-extracting
+!:mime application/zip
>4 byte 0x14
>>30 ubelong !0x6d696d65 Zip archive data, at least v2.0 to extract
->0x161 string WINZIP Zip archive data, WinZIP self-extracting
-
+!:mime application/zip
# OpenOffice.org / KOffice / StarOffice documents
# From: Abel Cheung <abel@oaka.org>
@@ -578,6 +616,7 @@
>>>50 string vnd.oasis.opendocument. OpenDocument
>>>>73 string text
>>>>>77 byte !0x2d Text
+!:mime application/vnd.oasis.opendocument.text
>>>>>77 string -template Text Template
>>>>>77 string -web HTML Document Template
>>>>>77 string -master Master Document
@@ -596,6 +635,7 @@
# Zoo archiver
20 lelong 0xfdc4a7dc Zoo archive data
+!:mime application/x-zoo
>4 byte >48 \b, v%c.
>>6 byte >47 \b%c
>>>7 byte >47 \b%c
@@ -607,6 +647,7 @@
# Shell archives
10 string #\ This\ is\ a\ shell\ archive shell archive text
+!:mime application/octet-stream
#
# LBR. NB: May conflict with the questionable
@@ -652,6 +693,7 @@
# Felix von Leitner <felix-file@fefe.de>
0 string d8:announce BitTorrent file
+!:mime application/x-bittorrent
# Atari MSA archive - Teemu Hukkanen <tjhukkan@iki.fi>
0 beshort 0x0e0f Atari MSA archive data
@@ -709,6 +751,7 @@
# EET archive
# From: Tilman Sauerbeck <tilman@code-monkey.de>
0 belong 0x1ee7ff00 EET archive
+!:mime application/x-eet
# rzip archives
0 string RZIP rzip compressed data
@@ -729,6 +772,36 @@
# http://www.thouky.co.uk/software/psifs/sis.html
# http://developer.symbian.com/main/downloads/papers/SymbianOSv91/softwareinstallsis.pdf
8 lelong 0x10000419 Symbian installation file
+!:mime application/vnd.symbian.install
>4 lelong 0x1000006D (EPOC release 3/4/5)
>4 lelong 0x10003A12 (EPOC release 6)
0 lelong 0x10201A7A Symbian installation file (Symbian OS 9.x)
+!:mime x-epoc/x-sisx-app
+
+# Pack200 Java archives, http://jcp.org/en/jsr/detail?id=200
+0 belong 0xcafed00d Pack200 Java archive
+
+# From "Nelson A. de Oliveira" <naoliv@gmail.com>
+0 string MPQ\032 MoPaQ (MPQ) archive
+
+# From: Dirk Jagdmann <doj@cubic.org>
+# xar archive format: http://code.google.com/p/xar/
+0 string xar! xar archive
+>6 beshort x - version %ld
+
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+# .kgb
+0 string KGB_arch KGB Archiver file
+>10 string x with compression level %.1s
+
+# xar (eXtensible ARchiver) archive
+# From: "David Remahl" <dremahl@apple.com>
+0 string xar! xar archive
+#>4 beshort x header size %d
+>6 beshort x version %d,
+#>8 quad x compressed TOC: %d,
+#>16 quad x uncompressed TOC: %d,
+>24 belong 0 no checksum
+>24 belong 1 SHA-1 checksum
+>24 belong 2 MD5 checksum
+
diff --git a/usr.bin/file/magdir/audio b/usr.bin/file/magdir/audio
index d668d13329e..7b38422a476 100644
--- a/usr.bin/file/magdir/audio
+++ b/usr.bin/file/magdir/audio
@@ -1,4 +1,4 @@
-# $OpenBSD: audio,v 1.10 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: audio,v 1.11 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# audio: file(1) magic for sound formats (see also "iff")
@@ -10,12 +10,19 @@
# Sun/NeXT audio data
0 string .snd Sun/NeXT audio data:
>12 belong 1 8-bit ISDN mu-law,
+!:mime audio/basic
>12 belong 2 8-bit linear PCM [REF-PCM],
+!:mime audio/basic
>12 belong 3 16-bit linear PCM,
+!:mime audio/basic
>12 belong 4 24-bit linear PCM,
+!:mime audio/basic
>12 belong 5 32-bit linear PCM,
+!:mime audio/basic
>12 belong 6 32-bit IEEE floating point,
+!:mime audio/basic
>12 belong 7 64-bit IEEE floating point,
+!:mime audio/basic
>12 belong 8 Fragmented sample data,
>12 belong 10 DSP program,
>12 belong 11 8-bit fixed point,
@@ -27,6 +34,7 @@
>12 belong 20 16-bit linear with emphasis and compression,
>12 belong 21 Music kit DSP commands,
>12 belong 23 8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice enc.),
+!:mime audio/x-adpcm
>12 belong 24 compressed (8-bit CCITT G.722 ADPCM)
>12 belong 25 compressed (3-bit CCITT G.723.3 ADPCM),
>12 belong 26 compressed (5-bit CCITT G.723.5 ADPCM),
@@ -40,12 +48,19 @@
# that uses little-endian encoding and has a different magic number
0 lelong 0x0064732E DEC audio data:
>12 lelong 1 8-bit ISDN mu-law,
+!:mime audio/x-dec-basic
>12 lelong 2 8-bit linear PCM [REF-PCM],
+!:mime audio/x-dec-basic
>12 lelong 3 16-bit linear PCM,
+!:mime audio/x-dec-basic
>12 lelong 4 24-bit linear PCM,
+!:mime audio/x-dec-basic
>12 lelong 5 32-bit linear PCM,
+!:mime audio/x-dec-basic
>12 lelong 6 32-bit IEEE floating point,
+!:mime audio/x-dec-basic
>12 lelong 7 64-bit IEEE floating point,
+!:mime audio/x-dec-basic
>12 belong 8 Fragmented sample data,
>12 belong 10 DSP program,
>12 belong 11 8-bit fixed point,
@@ -57,6 +72,7 @@
>12 belong 20 16-bit linear with emphasis and compression,
>12 belong 21 Music kit DSP commands,
>12 lelong 23 8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice enc.),
+!:mime audio/x-dec-basic
>12 belong 24 compressed (8-bit CCITT G.722 ADPCM)
>12 belong 25 compressed (3-bit CCITT G.723.3 ADPCM),
>12 belong 26 compressed (5-bit CCITT G.723.5 ADPCM),
@@ -68,6 +84,7 @@
# Creative Labs AUDIO stuff
0 string MThd Standard MIDI data
+!:mime audio/midi
>8 beshort x (format %d)
>10 beshort x using %d track
>10 beshort >1 \bs
@@ -75,8 +92,11 @@
>12 beshort&0x8000 >0 SMPTE
0 string CTMF Creative Music (CMF) data
+!:mime audio/x-unknown
0 string SBI SoundBlaster instrument data
+!:mime audio/x-unknown
0 string Creative\ Voice\ File Creative Labs voice data
+!:mime audio/x-unknown
# is this next line right? it came this way...
>19 byte 0x1A
>23 byte >0 - version %d
@@ -97,7 +117,13 @@
# Real Audio (Magic .ra\0375)
0 belong 0x2e7261fd RealAudio sound file
+!:mime audio/x-pn-realaudio
0 string .RMF RealMedia file
+!:mime application/vnd.rn-realmedia
+#video/x-pn-realvideo
+#video/vnd.rn-realvideo
+#application/vnd.rn-realmedia
+# sigh, there are many mimes for that but the above are the most common.
# MTM/669/FAR/S3M/ULT/XM format checking [Aaron Eppert, aeppert@dialin.ind.net]
# Oct 31, 1995
@@ -120,44 +146,84 @@
0 string GF1PATCH110\0ID#000002\0 GUS patch
0 string GF1PATCH100\0ID#000002\0 Old GUS patch
+# mime types according to http://www.geocities.com/nevilo/mod.htm:
+# audio/it .it
+# audio/x-zipped-it .itz
+# audio/xm fasttracker modules
+# audio/x-s3m screamtracker modules
+# audio/s3m screamtracker modules
+# audio/x-zipped-mod mdz
+# audio/mod mod
+# audio/x-mod All modules (mod, s3m, 669, mtm, med, xm, it, mdz, stm, itz, xmz, s3z)
+
#
# Taken from loader code from mikmod version 2.14
# by Steve McIntyre (stevem@chiark.greenend.org.uk)
# <doj@cubic.org> added title printing on 2003-06-24
0 string MAS_UTrack_V00
>14 string >/0 ultratracker V1.%.1s module sound data
+!:mime audio/x-mod
+#audio/x-tracker-module
0 string UN05 MikMod UNI format module sound data
0 string Extended\ Module: Fasttracker II module sound data
+!:mime audio/x-mod
+#audio/x-tracker-module
>17 string >\0 Title: "%s"
21 string/c =!SCREAM! Screamtracker 2 module sound data
+!:mime audio/x-mod
+#audio/x-screamtracker-module
21 string BMOD2STM Screamtracker 2 module sound data
+!:mime audio/x-mod
+#audio/x-screamtracker-module
1080 string M.K. 4-channel Protracker module sound data
+!:mime audio/x-mod
+#audio/x-protracker-module
>0 string >\0 Title: "%s"
1080 string M!K! 4-channel Protracker module sound data
+!:mime audio/x-mod
+#audio/x-protracker-module
>0 string >\0 Title: "%s"
1080 string FLT4 4-channel Startracker module sound data
+!:mime audio/x-mod
+#audio/x-startracker-module
>0 string >\0 Title: "%s"
1080 string FLT8 8-channel Startracker module sound data
+!:mime audio/x-mod
+#audio/x-startracker-module
>0 string >\0 Title: "%s"
1080 string 4CHN 4-channel Fasttracker module sound data
+!:mime audio/x-mod
+#audio/x-fasttracker-module
>0 string >\0 Title: "%s"
1080 string 6CHN 6-channel Fasttracker module sound data
+!:mime audio/x-mod
+#audio/x-fasttracker-module
>0 string >\0 Title: "%s"
1080 string 8CHN 8-channel Fasttracker module sound data
+!:mime audio/x-mod
+#audio/x-fasttracker-module
>0 string >\0 Title: "%s"
1080 string CD81 8-channel Octalyser module sound data
+!:mime audio/x-mod
+#audio/x-octalysertracker-module
>0 string >\0 Title: "%s"
-1080 string OKTA 8-channel Oktalyzer module sound data
+1080 string OKTA 8-channel Octalyzer module sound data
+!:mime audio/x-mod
+#audio/x-octalysertracker-module
>0 string >\0 Title: "%s"
# Not good enough.
#1082 string CH
#>1080 string >/0 %.2s-channel Fasttracker "oktalyzer" module sound data
1080 string 16CN 16-channel Taketracker module sound data
+!:mime audio/x-mod
+#audio/x-taketracker-module
>0 string >\0 Title: "%s"
1080 string 32CN 32-channel Taketracker module sound data
+!:mime audio/x-mod
+#audio/x-taketracker-module
>0 string >\0 Title: "%s"
# TOC sound files -Trevor Johnson <trevor@jpj.net>
@@ -222,9 +288,11 @@
# SGI SoundTrack <mpruett@sgi.com>
0 string _SGI_SoundTrack SGI SoundTrack project file
# ID3 version 2 tags <waschk@informatik.uni-rostock.de>
-0 string ID3 Audio file with ID3 version 2
->3 ubyte <0xff \b%d.
->4 ubyte <0xff \b%d tag
+0 string ID3 Audio file with ID3 version 2.
+# ??? Normally such a file is an MP3 file, but this will give false positives
+!:mime audio/mpeg
+>3 ubyte <0xff \b%d
+#>4 ubyte <0xff \b%d tag
>2584 string fLaC \b, FLAC encoding
>>2588 byte&0x7f >0 \b, unknown version
>>2588 byte&0x7f 0 \b
@@ -271,6 +339,7 @@
# Impulse tracker module (audio/x-it)
0 string IMPM Impulse Tracker module sound data -
+!:mime audio/x-mod
>4 string >\0 "%s"
>40 leshort !0 compatible w/ITv%x
>42 leshort !0 created w/ITv%x
@@ -381,6 +450,7 @@
# Free lossless audio codec <http://flac.sourceforge.net>
# From: Przemyslaw Augustyniak <silvathraec@rpg.pl>
0 string fLaC FLAC audio bitstream data
+!:mime audio/x-flac
>4 byte&0x7f >0 \b, unknown version
>4 byte&0x7f 0 \b
# some common bits/sample values
@@ -503,9 +573,9 @@
# .preset
0 string [Equalizer\ preset] XMMS equalizer preset
# .m3u
-0 string #EXTM3U M3U playlist
+0 search/1 #EXTM3U M3U playlist text
# .pls
-0 string [playlist] PLS playlist
+0 search/1 [playlist] PLS playlist text
# licq.conf
1 string [licq] LICQ configuration file
@@ -554,6 +624,14 @@
# http://www.wx800.com/msg/download/irda/iMelody.pdf
0 string BEGIN:IMELODY iMelody Ringtone Format
-# From: Matthew Flaschen <matthew.flaschen@gatech.edu>
-0 string #EXTM3U M3U playlist text
+# From: "Mateus Caruccio" <mateus@caruccio.com>
+# guitar pro v3,4,5 from http://filext.com/file-extension/gp3
+0 string \030FICHIER\ GUITAR\ PRO\ v3. Guitar Pro Ver. 3 Tablature
+
+# From: "Leslie P. Polzer" <leslie.polzer@gmx.net>
+60 string SONG SoundFX Module sound file
+# Type: Adaptive Multi-Rate Codec
+# URL: http://filext.com/detaillist.php?extdetail=AMR
+# From: Russell Coker <russell@coker.com.au>
+0 string #!AMR Adaptive Multi-Rate Codec (GSM telephony)
diff --git a/usr.bin/file/magdir/blender b/usr.bin/file/magdir/blender
index 5dc3a3da9be..a78af50bb3d 100644
--- a/usr.bin/file/magdir/blender
+++ b/usr.bin/file/magdir/blender
@@ -1,19 +1,39 @@
-# $OpenBSD: blender,v 1.1 2004/06/03 03:14:19 tedu Exp $
+# $OpenBSD: blender,v 1.2 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
-# blender: file(1) magic for Blender 3D data files
+# blender: file(1) magic for Blender 3D related files
#
-# Coded by Guillermo S. Romero <gsromero@alumnos.euitt.upm.es> using the
-# data from Ton Roosendaal <ton@blender.nl>. Ton or his company do not
-# support the rule, so mail GSR if problems with it. Rule version: 1.1.
-# You can get latest version with comments and details about the format
-# at http://acd.asoc.euitt.upm.es/~gsromero/3d/blender/magic.blender
+# Native format rule v1.2. For questions use the developers list
+# http://lists.blender.org/mailman/listinfo/bf-committers
+# GLOB chunk was moved near start and provides subversion info since 2.42
-0 string =BLENDER Blender3D,
->7 string =_ saved as 32-bits
->7 string =- saved as 64-bits
->8 string =v little endian
->8 string =V big endian
->9 byte x with version %c.
->10 byte x \b%c
->11 byte x \b%c
+0 string =BLENDER Blender3D,
+>7 string =_ saved as 32-bits
+>>8 string =v little endian
+>>>9 byte x with version %c.
+>>>10 byte x \b%c
+>>>11 byte x \b%c
+>>>0x40 string =GLOB \b.
+>>>>0x58 leshort x \b%.4d
+>>8 string =V big endian
+>>>9 byte x with version %c.
+>>>10 byte x \b%c
+>>>11 byte x \b%c
+>>>0x40 string =GLOB \b.
+>>>>0x58 beshort x \b%.4d
+>7 string =- saved as 64-bits
+>>8 string =v little endian
+>>9 byte x with version %c.
+>>10 byte x \b%c
+>>11 byte x \b%c
+>>0x44 string =GLOB \b.
+>>>0x60 leshort x \b%.4d
+>>8 string =V big endian
+>>>9 byte x with version %c.
+>>>10 byte x \b%c
+>>>11 byte x \b%c
+>>>0x44 string =GLOB \b.
+>>>>0x60 beshort x \b%.4d
+
+# Scripts that run in the embeded Python interpreter
+0 string #!BPY Blender3D BPython script
diff --git a/usr.bin/file/magdir/c-lang b/usr.bin/file/magdir/c-lang
index c3c1a2188f1..7211af3e073 100644
--- a/usr.bin/file/magdir/c-lang
+++ b/usr.bin/file/magdir/c-lang
@@ -1,4 +1,4 @@
-# $OpenBSD: c-lang,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: c-lang,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# c-lang: file(1) magic for C programs (or REXX)
@@ -7,11 +7,15 @@
# XPM icons (Greg Roelofs, newt@uchicago.edu)
# if you uncomment "/*" for C/REXX below, also uncomment this entry
#0 string /*\ XPM\ */ X pixmap image data
+#!:mime image/x-xpmi
+
+# 3DS (3d Studio files) Conflicts with diff output 0x3d '='
+#16 beshort 0x3d3d image/x-3ds
# this first will upset you if you're a PL/1 shop...
# in which case rm it; ascmagic will catch real C programs
-#0 string /* C or REXX program text
-#0 string // C++ program text
+#0 search/1 /* C or REXX program text
+#0 search/1 // C++ program text
# From: Mikhail Teterin <mi@aldan.algebra.com>
0 string cscope cscope reference data
@@ -21,5 +25,5 @@
# The inverted index functionality was added some time betwen
# versions 11 and 15, so look for -q if version is above 14:
>7 string >14
->>10 regex .+\ -q\ with inverted index
->10 regex .+\ -c\ text (non-compressed)
+>>10 search/100 \ -q\ with inverted index
+>10 search/100 \ -c\ text (non-compressed)
diff --git a/usr.bin/file/magdir/cafebabe b/usr.bin/file/magdir/cafebabe
index 8adeb304369..b48652316c0 100644
--- a/usr.bin/file/magdir/cafebabe
+++ b/usr.bin/file/magdir/cafebabe
@@ -1,4 +1,4 @@
-# $OpenBSD: cafebabe,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: cafebabe,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# Cafe Babes unite!
@@ -14,10 +14,14 @@
# (and use as a hack). Let's not use 18, because the Mach-O people
# might add another one or two as time goes by...
#
-0 belong 0xcafebabe
+0 beshort 0xcafe
+>2 beshort 0xbabe
+!:mime application/x-java-applet
>4 belong >30 compiled Java class data,
->>6 beshort x version %d.
->>4 beshort x \b%d
->4 belong 1 Mach-O fat file with 1 architecture
->4 belong >1
->>4 belong <20 Mach-O fat file with %ld architectures
+>>6 beshort x version %d.
+>>4 beshort x \b%d
+>>4 belong 1 Mach-O fat file with 1 architecture
+>>4 belong >1
+>>>4 belong <20 Mach-O fat file with %ld architectures
+>2 beshort 0xd00d JAR compressed with pack200
+!:mime application/x-java-pack200
diff --git a/usr.bin/file/magdir/cddb b/usr.bin/file/magdir/cddb
index e0f555f0cde..17084c7a861 100644
--- a/usr.bin/file/magdir/cddb
+++ b/usr.bin/file/magdir/cddb
@@ -1,4 +1,4 @@
-# $OpenBSD: cddb,v 1.1 2004/06/03 03:14:19 tedu Exp $
+# $OpenBSD: cddb,v 1.2 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# CDDB: file(1) magic for CDDB(tm) format CD text data files
@@ -9,4 +9,4 @@
# CDDB-enabled CD player applications.
#
-0 string/b #\040xmcd CDDB(tm) format CD text data
+0 search/1/b #\040xmcd CDDB(tm) format CD text data
diff --git a/usr.bin/file/magdir/clarion b/usr.bin/file/magdir/clarion
new file mode 100644
index 00000000000..5f5f6e75613
--- /dev/null
+++ b/usr.bin/file/magdir/clarion
@@ -0,0 +1,26 @@
+
+#------------------------------------------------------------------------------
+# clarion: file(1) magic for # Clarion Personal/Professional Developer
+# (v2 and above)
+# From: Julien Blache <jb@jblache.org>
+
+# Database files
+# signature
+0 leshort 0x3343 Clarion Developer (v2 and above) data file
+# attributes
+>2 leshort &0x0001 \b, locked
+>2 leshort &0x0004 \b, encrypted
+>2 leshort &0x0008 \b, memo file exists
+>2 leshort &0x0010 \b, compressed
+>2 leshort &0x0040 \b, read only
+# number of records
+>5 lelong x \b, %ld records
+
+# Memo files
+0 leshort 0x334d Clarion Developer (v2 and above) memo data
+
+# Key/Index files
+# No magic? :(
+
+# Help files
+0 leshort 0x49e0 Clarion Developer (v2 and above) help data
diff --git a/usr.bin/file/magdir/commands b/usr.bin/file/magdir/commands
index e03324b7f00..7748ce30413 100644
--- a/usr.bin/file/magdir/commands
+++ b/usr.bin/file/magdir/commands
@@ -1,42 +1,64 @@
-# $OpenBSD: commands,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: commands,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# commands: file(1) magic for various shells and interpreters
#
-0 string : shell archive or script for antique kernel text
+#0 string : shell archive or script for antique kernel text
0 string/b #!\ /bin/sh Bourne shell script text executable
+!:mime application/x-shellscript
0 string/b #!\ /bin/csh C shell script text executable
+!:mime application/x-shellscript
# korn shell magic, sent by George Wu, gwu@clyde.att.com
0 string/b #!\ /bin/ksh Korn shell script text executable
+!:mime application/x-shellscript
0 string/b #!\ /bin/tcsh Tenex C shell script text executable
+!:mime application/x-shellscript
0 string/b #!\ /usr/local/tcsh Tenex C shell script text executable
+!:mime application/x-shellscript
0 string/b #!\ /usr/local/bin/tcsh Tenex C shell script text executable
+!:mime application/x-shellscript
#
# zsh/ash/ae/nawk/gawk magic from cameron@cs.unsw.oz.au (Cameron Simpson)
0 string/b #!\ /bin/zsh Paul Falstad's zsh script text executable
+!:mime application/x-shellscript
0 string/b #!\ /usr/bin/zsh Paul Falstad's zsh script text executable
+!:mime application/x-shellscript
0 string/b #!\ /usr/local/bin/zsh Paul Falstad's zsh script text executable
+!:mime application/x-shellscript
0 string/b #!\ /usr/local/bin/ash Neil Brown's ash script text executable
+!:mime application/x-shellscript
0 string/b #!\ /usr/local/bin/ae Neil Brown's ae script text executable
+!:mime application/x-shellscript
0 string/b #!\ /bin/nawk new awk script text executable
+!:mime application/x-nawk
0 string/b #!\ /usr/bin/nawk new awk script text executable
+!:mime application/x-nawk
0 string/b #!\ /usr/local/bin/nawk new awk script text executable
+!:mime application/x-nawk
0 string/b #!\ /bin/gawk GNU awk script text executable
+!:mime application/x-gawk
0 string/b #!\ /usr/bin/gawk GNU awk script text executable
+!:mime application/x-gawk
0 string/b #!\ /usr/local/bin/gawk GNU awk script text executable
+!:mime application/x-gawk
#
0 string/b #!\ /bin/awk awk script text executable
+!:mime application/x-awk
0 string/b #!\ /usr/bin/awk awk script text executable
+!:mime application/x-awk
# update to distinguish from *.vcf files
-0 regex BEGIN[[:space:]]*[{] awk script text
+# this is broken because postscript has /EBEGIN{ for example.
+#0 search/Bb BEGIN { awk script text
# AT&T Bell Labs' Plan 9 shell
0 string/b #!\ /bin/rc Plan 9 rc shell script text executable
# bash shell magic, from Peter Tobias (tobias@server.et-inf.fho-emden.de)
0 string/b #!\ /bin/bash Bourne-Again shell script text executable
+!:mime application/x-shellscript
0 string/b #!\ /usr/local/bin/bash Bourne-Again shell script text executable
+!:mime application/x-shellscript
# using env
0 string #!/usr/bin/env a
@@ -46,11 +68,11 @@
# PHP scripts
# Ulf Harnhammar <ulfh@update.uu.se>
-0 string/c =<?php PHP script text
-0 string =<?\n PHP script text
-0 string =<?\r PHP script text
-0 string/b #!\ /usr/local/bin/php PHP script text executable
-0 string/b #!\ /usr/bin/php PHP script text executable
+0 search/1/c =<?php PHP script text
+0 search/1 =<?\n PHP script text
+0 search/1 =<?\r PHP script text
+0 search/1/b #!\ /usr/local/bin/php PHP script text executable
+0 search/1/b #!\ /usr/bin/php PHP script text executable
0 string Zend\x00 PHP script Zend Optimizer data
diff --git a/usr.bin/file/magdir/compress b/usr.bin/file/magdir/compress
index 2a6809409ec..01e70249487 100644
--- a/usr.bin/file/magdir/compress
+++ b/usr.bin/file/magdir/compress
@@ -1,4 +1,4 @@
-# $OpenBSD: compress,v 1.5 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: compress,v 1.6 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# compress: file(1) magic for pure-compression formats (no archives)
@@ -10,7 +10,8 @@
# because it tries to uncompress it to figure out what's inside.
# standard unix compress
-0 string \037\235 compress'd data
+#0 string \037\235 compress'd data
+#!:mime application/x-compress
>2 byte&0x80 >0 block compressed
>2 byte&0x1f x %d bits
@@ -20,6 +21,7 @@
# * Produce shorter output - notably, only report compression methods
# other than 8 ("deflate", the only method defined in RFC 1952).
0 string \037\213 gzip compressed data
+!:mime application/x-gzip
>2 byte <8 \b, reserved method
>2 byte >8 \b, unknown method
>3 byte &0x01 \b, ASCII
@@ -50,23 +52,29 @@
# packed data, Huffman (minimum redundancy) codes on a byte-by-byte basis
0 string \037\036 packed data
+!:mime application/octet-stream
>2 belong >1 \b, %d characters originally
>2 belong =1 \b, %d character originally
#
# This magic number is byte-order-independent.
0 short 0x1f1f old packed data
+!:mime application/octet-stream
# XXX - why *two* entries for "compacted data", one of which is
# byte-order independent, and one of which is byte-order dependent?
#
0 short 0x1fff compacted data
+!:mime application/octet-stream
# This string is valid for SunOS (BE) and a matching "short" is listed
# in the Ultrix (LE) magic file.
0 string \377\037 compacted data
+!:mime application/octet-stream
0 short 0145405 huf output
+!:mime application/octet-stream
# bzip2
0 string BZh bzip2 compressed data
+!:mime application/x-bzip2
>3 byte >47 \b, block size = %c00k
# squeeze and crunch
@@ -103,17 +111,17 @@
# bzip a block-sorting file compressor
# by Julian Seward <sewardj@cs.man.ac.uk> and others
#
-0 string BZ bzip compressed data
->2 byte x \b, version: %c
->3 string =1 \b, compression block size 100k
->3 string =2 \b, compression block size 200k
->3 string =3 \b, compression block size 300k
->3 string =4 \b, compression block size 400k
->3 string =5 \b, compression block size 500k
->3 string =6 \b, compression block size 600k
->3 string =7 \b, compression block size 700k
->3 string =8 \b, compression block size 800k
->3 string =9 \b, compression block size 900k
+#0 string BZ bzip compressed data
+#>2 byte x \b, version: %c
+#>3 string =1 \b, compression block size 100k
+#>3 string =2 \b, compression block size 200k
+#>3 string =3 \b, compression block size 300k
+#>3 string =4 \b, compression block size 400k
+#>3 string =5 \b, compression block size 500k
+#>3 string =6 \b, compression block size 600k
+#>3 string =7 \b, compression block size 700k
+#>3 string =8 \b, compression block size 800k
+#>3 string =9 \b, compression block size 900k
# lzop from <markus.oberhumer@jk.uni-linz.ac.at>
0 string \x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a lzop compressed data
@@ -175,6 +183,13 @@
>6 byte x version %d
>7 byte x \b.%d
+# Type: LZMA
+# URL: http://www.7-zip.org/sdk.html
+# From: Robert Millan <rmh@aybabtu.com> and Reuben Thomas <rrt@sc3d.org>
+# Commented out because apparently not reliable (according to Debian
+# bug #364260)
+#0 string ]\000\000\200\000 LZMA compressed data
+
# AFX compressed files (Wolfram Kleff)
2 string -afx- AFX compressed file data
diff --git a/usr.bin/file/magdir/console b/usr.bin/file/magdir/console
index c413d64dcce..e61d1820ba5 100644
--- a/usr.bin/file/magdir/console
+++ b/usr.bin/file/magdir/console
@@ -1,4 +1,4 @@
-# $OpenBSD: console,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: console,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# Console game magic
@@ -193,3 +193,64 @@
0 string PPF10 Playstation Patch File version 1.0
>5 byte 0 \b, Simple Encoding
>6 string x \b, description: %s
+
+# From: Daniel Dawson <ddawson@icehouse.net>
+# SNES9x .smv "movie" file format.
+0 string SMV\x1A SNES9x input recording
+>0x4 lelong x \b, version %d
+# version 4 is latest so far
+>0x4 lelong <5
+>>0x8 ledate x \b, recorded at %s
+>>0xc lelong >0 \b, rerecorded %d times
+>>0x10 lelong x \b, %d frames long
+>>0x14 byte >0 \b, data for controller(s):
+>>>0x14 byte &0x1 #1
+>>>0x14 byte &0x2 #2
+>>>0x14 byte &0x4 #3
+>>>0x14 byte &0x8 #4
+>>>0x14 byte &0x10 #5
+>>0x15 byte ^0x1 \b, begins from snapshot
+>>0x15 byte &0x1 \b, begins from reset
+>>0x15 byte ^0x2 \b, NTSC standard
+>>0x15 byte &0x2 \b, PAL standard
+>>0x17 byte &0x1 \b, settings:
+# WIP1Timing not used as of version 4
+>>>0x4 lelong <4
+>>>>0x17 byte &0x2 WIP1Timing
+>>>0x17 byte &0x4 Left+Right
+>>>0x17 byte &0x8 VolumeEnvX
+>>>0x17 byte &0x10 FakeMute
+>>>0x17 byte &0x20 SyncSound
+# New flag as of version 4
+>>>0x4 lelong >3
+>>>>0x17 byte &0x80 NoCPUShutdown
+>>0x4 lelong <4
+>>>0x18 lelong >0x23
+>>>>0x20 leshort !0
+>>>>>0x20 lestring16 x \b, metadata: "%s"
+>>0x4 lelong >3
+>>>0x24 byte >0 \b, port 1:
+>>>>0x24 byte 1 joypad
+>>>>0x24 byte 2 mouse
+>>>>0x24 byte 3 SuperScope
+>>>>0x24 byte 4 Justifier
+>>>>0x24 byte 5 multitap
+>>>0x24 byte >0 \b, port 2:
+>>>>0x25 byte 1 joypad
+>>>>0x25 byte 2 mouse
+>>>>0x25 byte 3 SuperScope
+>>>>0x25 byte 4 Justifier
+>>>>0x25 byte 5 multitap
+>>>0x18 lelong >0x43
+>>>>0x40 leshort !0
+>>>>>0x40 lestring16 x \b, metadata: "%s"
+>>0x17 byte &0x40 \b, ROM:
+>>>(0x18.l-26) lelong x CRC32 0x%08x
+>>>(0x18.l-23) string x "%s"
+
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+# .w3g
+0 string Warcraft\ III\ recorded\ game %s
+# .w3m
+0 string HM3W Warcraft III map file
+
diff --git a/usr.bin/file/magdir/cracklib b/usr.bin/file/magdir/cracklib
index 973dfc3e7cc..75e27491fd0 100644
--- a/usr.bin/file/magdir/cracklib
+++ b/usr.bin/file/magdir/cracklib
@@ -1,4 +1,4 @@
-# $OpenBSD: cracklib,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: cracklib,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# cracklib: file (1) magic for cracklib v2.7
@@ -10,5 +10,5 @@
0 belong 0x70775631 Cracklib password index, big endian
>4 belong >-1 (%i words)
# really bellong 0x0000000070775631
-4 belong 0x70775631 Cracklib password index, big endian ("64-bit")
+0 search/1 \0\0\0\0pwV1 Cracklib password index, big endian ("64-bit")
>12 belong >0 (%i words)
diff --git a/usr.bin/file/magdir/ctags b/usr.bin/file/magdir/ctags
index 3b64f023ef3..0f777a70cd9 100644
--- a/usr.bin/file/magdir/ctags
+++ b/usr.bin/file/magdir/ctags
@@ -1,6 +1,6 @@
-# $OpenBSD: ctags,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: ctags,v 1.3 2009/04/24 18:54:34 chl Exp $
# ----------------------------------------------------------------------------
# ctags: file (1) magic for Exuberant Ctags files
# From: Alexander Mai <mai@migdal.ikp.physik.tu-darmstadt.de>
-0 string =!_TAG Exuberant Ctags tag file text
+0 search/1 =!_TAG Exuberant Ctags tag file text
diff --git a/usr.bin/file/magdir/database b/usr.bin/file/magdir/database
index 2faf6badb33..ea2407a560b 100644
--- a/usr.bin/file/magdir/database
+++ b/usr.bin/file/magdir/database
@@ -1,4 +1,4 @@
-# $OpenBSD: database,v 1.5 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: database,v 1.6 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# database: file(1) magic for various databases
@@ -10,8 +10,11 @@
# Will be maintained as part of the GDBM distribution in the future.
# <downsj@teeny.org>
0 belong 0x13579ace GNU dbm 1.x or ndbm database, big endian
+!:mime application/x-gdbm
0 lelong 0x13579ace GNU dbm 1.x or ndbm database, little endian
+!:mime application/x-gdbm
0 string GDBM GNU dbm 2.x database
+!:mime application/x-gdbm
#
# Berkeley DB
#
@@ -22,6 +25,7 @@
# Hash and Btree 2.X and later databases store the metadata in host byte order.
0 long 0x00061561 Berkeley DB
+!:mime application/x-dbm
>8 belong 4321
>>4 belong >2 1.86
>>4 belong <3 1.85
@@ -108,74 +112,87 @@
#>>0x04 byte 6 non-incrementing secondary index .XGn file
#>>0x04 byte 7 secondary index .YGn file
#>>>0x04 byte 8 incrementing secondary index .XGn file
+
## XBase database files
#0 byte 0x02
#>8 leshort >0
#>>12 leshort 0 FoxBase
+#!:mime application/x-dbf
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x03
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 FoxBase+, FoxPro, dBaseIII+, dBaseIV, no memo
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x04
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 dBASE IV no memo file
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x05
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 dBASE V no memo file
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x30
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 Visual FoxPro
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x43
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 FlagShip with memo var size
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x7b
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 dBASEIV with memo
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x83
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 FoxBase+, dBaseIII+ with memo
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x8b
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 dBaseIV with memo
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0x8e
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 dBaseIV with SQL Table
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0xb3
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 FlagShip with .dbt memo
#>>>0x04 lelong 0 (no records)
#>>>0x04 lelong >0 (%ld records)
#
#0 byte 0xf5
+#!:mime application/x-dbf
#>8 leshort >0
#>>12 leshort 0 FoxPro with memo
#>>>0x04 lelong 0 (no records)
@@ -184,7 +201,8 @@
#0 leshort 0x0006 DBase 3 index file
# MS Access database
-4 string Standard\ Jet\ DB Microsoft Access Database
+4 string Standard\ Jet\ DB Microsoft Access Database
+!:mime application/x-msaccess
# TDB database from Samba et al - Martin Pool <mbp@samba.org>
0 string TDB\ file TDB database
@@ -211,3 +229,17 @@
16 string MIT-MAGIC-COOKIE-1 X11 Xauthority data
17 string MIT-MAGIC-COOKIE-1 X11 Xauthority data
18 string MIT-MAGIC-COOKIE-1 X11 Xauthority data
+
+# From: Maxime Henrion <mux@FreeBSD.org>
+# PostgreSQL's custom dump format, Maxime Henrion <mux@FreeBSD.org>
+0 string PGDMP PostgreSQL custom database dump
+>5 byte x - v%d
+>6 byte x \b.%d
+>5 beshort <=0x100 \b-0
+>5 beshort >0x100
+>>7 byte x \b-%d
+
+# Type: Advanced Data Format (ADF) database
+# URL: http://www.grc.nasa.gov/WWW/cgns/adf/
+# From: Nicolas Chauvat <nicolas.chauvat@logilab.fr>
+0 string @(#)ADF\ Database CGNS Advanced Data Format
diff --git a/usr.bin/file/magdir/diff b/usr.bin/file/magdir/diff
index 7e951a1b2a3..8d5f889bc89 100644
--- a/usr.bin/file/magdir/diff
+++ b/usr.bin/file/magdir/diff
@@ -1,11 +1,11 @@
-# $OpenBSD: diff,v 1.3 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: diff,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# diff: file(1) magic for diff(1) output
#
-0 string diff\ 'diff' output text
-0 string ***\ 'diff' output text
-0 string Only\ in\ 'diff' output text
-0 string Common\ subdirectories:\ 'diff' output text
+0 search/1 diff\ diff output text
+0 search/1 ***\ diff output text
+0 search/1 Only\ in\ diff output text
+0 search/1 Common\ subdirectories:\ diff output text
-0 string Index: RCS/CVS diff output text
+0 search/1 Index: RCS/CVS diff output text
diff --git a/usr.bin/file/magdir/dump b/usr.bin/file/magdir/dump
index 57af29eb764..ae5ed1673a3 100644
--- a/usr.bin/file/magdir/dump
+++ b/usr.bin/file/magdir/dump
@@ -1,4 +1,4 @@
-# $OpenBSD: dump,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: dump,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# dump: file(1) magic for dump file format--for new and old dump filesystems
@@ -92,3 +92,41 @@
>0 leshort 5 end of volume.
>0 leshort 6 map of inodes deleted.
>0 leshort 7 end of medium (for floppy).
+
+24 belong 0x19540119 new-fs dump file (ufs2, big endian),
+>896 beqdate x Previous dump %s,
+>904 beqdate x This dump %s,
+>12 belong >0 Volume %ld,
+>692 belong 0 Level zero, type:
+>692 belong >0 Level %d, type:
+>0 belong 1 tape header,
+>0 belong 2 beginning of file record,
+>0 belong 3 map of inodes on tape,
+>0 belong 4 continuation of file record,
+>0 belong 5 end of volume,
+>0 belong 6 map of inodes deleted,
+>0 belong 7 end of medium (for floppy),
+>676 string >\0 Label %s,
+>696 string >\0 Filesystem %s,
+>760 string >\0 Device %s,
+>824 string >\0 Host %s,
+>888 belong >0 Flags %x
+
+24 lelong 0x19540119 new-fs dump file (ufs2, little endian),
+>896 leqdate x This dump %s,
+>904 leqdate x Previous dump %s,
+>12 lelong >0 Volume %ld,
+>692 lelong 0 Level zero, type:
+>692 lelong >0 Level %d, type:
+>0 lelong 1 tape header,
+>0 lelong 2 beginning of file record,
+>0 lelong 3 map of inodes on tape,
+>0 lelong 4 continuation of file record,
+>0 lelong 5 end of volume,
+>0 lelong 6 map of inodes deleted,
+>0 lelong 7 end of medium (for floppy),
+>676 string >\0 Label %s,
+>696 string >\0 Filesystem %s,
+>760 string >\0 Device %s,
+>824 string >\0 Host %s,
+>888 lelong >0 Flags %x
diff --git a/usr.bin/file/magdir/efi b/usr.bin/file/magdir/efi
new file mode 100644
index 00000000000..4eec2eb9377
--- /dev/null
+++ b/usr.bin/file/magdir/efi
@@ -0,0 +1,14 @@
+
+#------------------------------------------------------------------------------
+# efi: file(1) magic for Universal EFI binaries
+
+0 lelong 0x0ef1fab9
+>4 lelong 1 Universal EFI binary with 1 architecture
+>>&0 lelong 7 \b, i386
+>>&0 lelong 0x01000007 \b, x86_64
+>4 lelong 2 Universal EFI binary with 2 architectures
+>>&0 lelong 7 \b, i386
+>>&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
diff --git a/usr.bin/file/magdir/elf b/usr.bin/file/magdir/elf
index 304d27a85ac..1058ab4c225 100644
--- a/usr.bin/file/magdir/elf
+++ b/usr.bin/file/magdir/elf
@@ -1,4 +1,4 @@
-# $OpenBSD: elf,v 1.16 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: elf,v 1.17 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# elf: file(1) magic for ELF executables
@@ -16,12 +16,17 @@
>5 byte 0 invalid byte order
>5 byte 1 LSB
>>16 leshort 0 no file type,
+!:mime application/octet-stream
>>16 leshort 1 relocatable,
+!:mime application/x-object
>>16 leshort 2 executable,
+!:mime application/x-executable
>>16 leshort 3 shared object,
+!:mime application/x-sharedlib
# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>
# corrections by Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
>>16 leshort 4 core file
+!:mime application/x-coredump
# Core file detection is not reliable.
#>>>(0x38+0xcc) string >\0 of '%s'
#>>>(0x38+0x10) lelong >0 (signal %d),
@@ -52,10 +57,10 @@
>>>>36 lelong&0xf0000000 0x20000000 MIPS-III
>>>>36 lelong&0xf0000000 0x30000000 MIPS-IV
>>>>36 lelong&0xf0000000 0x40000000 MIPS-V
->>>>36 lelong&0xf0000000 0x60000000 MIPS32
->>>>36 lelong&0xf0000000 0x70000000 MIPS64
->>>>36 lelong&0xf0000000 0x80000000 MIPS32 rel2
->>>>36 lelong&0xf0000000 0x90000000 MIPS64 rel2
+>>>>36 lelong&0xf0000000 0x50000000 MIPS32
+>>>>36 lelong&0xf0000000 0x60000000 MIPS64
+>>>>36 lelong&0xf0000000 0x70000000 MIPS32 rel2
+>>>>36 lelong&0xf0000000 0x80000000 MIPS64 rel2
# only for 64-bit
>>>4 byte 2
>>>>48 lelong&0xf0000000 0x00000000 MIPS-I
@@ -63,10 +68,10 @@
>>>>48 lelong&0xf0000000 0x20000000 MIPS-III
>>>>48 lelong&0xf0000000 0x30000000 MIPS-IV
>>>>48 lelong&0xf0000000 0x40000000 MIPS-V
->>>>48 lelong&0xf0000000 0x60000000 MIPS32
->>>>48 lelong&0xf0000000 0x70000000 MIPS64
->>>>48 lelong&0xf0000000 0x80000000 MIPS32 rel2
->>>>48 lelong&0xf0000000 0x90000000 MIPS64 rel2
+>>>>48 lelong&0xf0000000 0x50000000 MIPS32
+>>>>48 lelong&0xf0000000 0x60000000 MIPS64
+>>>>48 lelong&0xf0000000 0x70000000 MIPS32 rel2
+>>>>48 lelong&0xf0000000 0x80000000 MIPS64 rel2
>>18 leshort 9 Amdahl - invalid byte order,
>>18 leshort 10 MIPS (deprecated),
>>18 leshort 11 RS6000 - invalid byte order,
@@ -97,9 +102,46 @@
>>18 leshort 51 Stanford MIPS-X,
>>18 leshort 52 Motorola Coldfire,
>>18 leshort 53 Motorola M68HC12,
+>>18 leshort 54 Fujitsu MMA,
+>>18 leshort 55 Siemens PCP,
+>>18 leshort 56 Sony nCPU,
+>>18 leshort 57 Denso NDR1,
+>>18 leshort 58 Start*Core,
+>>18 leshort 59 Toyota ME16,
+>>18 leshort 60 ST100,
+>>18 leshort 61 Tinyj emb.,
>>18 leshort 62 x86-64,
+>>18 leshort 63 Sony DSP,
+>>18 leshort 66 FX66,
+>>18 leshort 67 ST9+ 8/16 bit,
+>>18 leshort 68 ST7 8 bit,
+>>18 leshort 69 MC68HC16,
+>>18 leshort 70 MC68HC11,
+>>18 leshort 71 MC68HC08,
+>>18 leshort 72 MC68HC05,
+>>18 leshort 73 SGI SVx,
+>>18 leshort 74 ST19 8 bit,
>>18 leshort 75 Digital VAX,
+>>18 leshort 76 Axis cris,
+>>18 leshort 77 Infineon 32-bit embedded,
+>>18 leshort 78 Element 14 64-bit DSP,
+>>18 leshort 79 LSI Logic 16-bit DSP,
+>>18 leshort 80 MMIX,
+>>18 leshort 81 Harvard machine-independent,
+>>18 leshort 82 SiTera Prism,
+>>18 leshort 83 Atmel AVR 8-bit,
+>>18 leshort 84 Fujitsu FR30,
+>>18 leshort 85 Mitsubishi D10V,
+>>18 leshort 86 Mitsubishi D30V,
+>>18 leshort 87 NEC v850,
>>18 leshort 88 Renesas M32R,
+>>18 leshort 89 Matsushita MN10300,
+>>18 leshort 90 Matsushita MN10200,
+>>18 leshort 91 picoJava,
+>>18 leshort 92 OpenRISC,
+>>18 leshort 93 ARC Cores Tangent-A5,
+>>18 leshort 0x3426 OpenRISC (obsolete),
+>>18 leshort 0x8472 OpenRISC (obsolete),
>>18 leshort 94 Tensilica Xtensa,
>>18 leshort 97 NatSemi 32k,
>>18 leshort 106 Analog Devices Blackfin,
@@ -109,10 +151,15 @@
>>36 lelong 1 MathCoPro/FPU/MAU Required
>5 byte 2 MSB
>>16 beshort 0 no file type,
+!:mime application/octet-stream
>>16 beshort 1 relocatable,
+!:mime application/x-object
>>16 beshort 2 executable,
+!:mime application/x-executable
>>16 beshort 3 shared object,
+!:mime application/x-sharedlib
>>16 beshort 4 core file,
+!:mime application/x-coredump
#>>>(0x38+0xcc) string >\0 of '%s'
#>>>(0x38+0x10) belong >0 (signal %d),
>>16 beshort &0xff00 processor-specific,
@@ -140,10 +187,10 @@
>>>>36 belong&0xf0000000 0x20000000 MIPS-III
>>>>36 belong&0xf0000000 0x30000000 MIPS-IV
>>>>36 belong&0xf0000000 0x40000000 MIPS-V
->>>>36 belong&0xf0000000 0x60000000 MIPS32
->>>>36 belong&0xf0000000 0x70000000 MIPS64
->>>>36 belong&0xf0000000 0x80000000 MIPS32 rel2
->>>>36 belong&0xf0000000 0x90000000 MIPS64 rel2
+>>>>36 belong&0xf0000000 0x50000000 MIPS32
+>>>>36 belong&0xf0000000 0x60000000 MIPS64
+>>>>36 belong&0xf0000000 0x70000000 MIPS32 rel2
+>>>>36 belong&0xf0000000 0x80000000 MIPS64 rel2
# only for 64-bit
>>>4 byte 2
>>>>48 belong&0xf0000000 0x00000000 MIPS-I
@@ -151,10 +198,10 @@
>>>>48 belong&0xf0000000 0x20000000 MIPS-III
>>>>48 belong&0xf0000000 0x30000000 MIPS-IV
>>>>48 belong&0xf0000000 0x40000000 MIPS-V
->>>>48 belong&0xf0000000 0x60000000 MIPS32
->>>>48 belong&0xf0000000 0x70000000 MIPS64
->>>>48 belong&0xf0000000 0x80000000 MIPS32 rel2
->>>>48 belong&0xf0000000 0x90000000 MIPS64 rel2
+>>>>48 belong&0xf0000000 0x50000000 MIPS32
+>>>>48 belong&0xf0000000 0x60000000 MIPS64
+>>>>48 belong&0xf0000000 0x70000000 MIPS32 rel2
+>>>>48 belong&0xf0000000 0x80000000 MIPS64 rel2
>>18 beshort 9 Amdahl,
>>18 beshort 10 MIPS (deprecated),
>>18 beshort 11 RS6000,
@@ -195,8 +242,12 @@
>>18 beshort 73 Cray NV1,
>>18 beshort 75 Digital VAX,
>>18 beshort 88 Renesas M32R,
+>>18 leshort 92 OpenRISC,
+>>18 leshort 0x3426 OpenRISC (obsolete),
+>>18 leshort 0x8472 OpenRISC (obsolete),
>>18 beshort 94 Tensilica Xtensa,
>>18 beshort 97 NatSemi 32k,
+>>18 beshort 0x18ad AVR32 (unofficial),
>>18 beshort 0x9026 Alpha (unofficial),
>>18 beshort 0xa390 IBM S/390 (obsolete),
>>20 belong 0 invalid version
diff --git a/usr.bin/file/magdir/erlang b/usr.bin/file/magdir/erlang
new file mode 100644
index 00000000000..59f55ecb31b
--- /dev/null
+++ b/usr.bin/file/magdir/erlang
@@ -0,0 +1,18 @@
+
+#------------------------------------------------------------------------------
+# erlang: file(1) magic for Erlang JAM and BEAM files
+# URL: http://www.erlang.org/faq/x779.html#AEN812
+
+# OTP R3-R4
+0 string \0177BEAM! Old Erlang BEAM file
+>6 short >0 - version %d
+
+# OTP R5 and onwards
+0 string FOR1
+>8 string BEAM Erlang BEAM file
+
+# 4.2 version may have a copyright notice!
+4 string Tue Jan 22 14:32:44 MET 1991 Erlang JAM file - version 4.2
+79 string Tue Jan 22 14:32:44 MET 1991 Erlang JAM file - version 4.2
+
+4 string 1.0 Fri Feb 3 09:55:56 MET 1995 Erlang JAM file - version 4.3
diff --git a/usr.bin/file/magdir/filesystems b/usr.bin/file/magdir/filesystems
index 59318f5b92e..e4858017cbf 100644
--- a/usr.bin/file/magdir/filesystems
+++ b/usr.bin/file/magdir/filesystems
@@ -1,4 +1,4 @@
-# $OpenBSD: filesystems,v 1.3 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: filesystems,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# filesystems: file(1) magic for different filesystems
@@ -53,7 +53,13 @@
>>>>11 ulelong >0 \b, %d sectors/track
>>>>15 ulelong >0 \b, %d cylinders
+# updated by Joerg Jenderek at Sep 2007
+# only for sector sizes with 512 or more Bytes
0x1FE leshort 0xAA55 x86 boot sector
+# to do also for sectors < than 512 Bytes and some other files, GRR
+#30 search/481 \x55\xAA x86 boot sector
+# not for BeOS floppy 1440k, MBRs
+#(11.s-2) uleshort 0xAA55 x86 boot sector
>2 string OSBS \b, OS/BS MBR
# J\xf6rg Jenderek <joerg dot jenderek at web dot de>
>0x8C string Invalid\ partition\ table \b, MS-DOS MBR
@@ -174,56 +180,59 @@
>>498 string BCDL\ \ \ \ BIN \b, Bootable CD Loader (1.50Z)
# mbr partion table entries
# OEM-ID not Microsoft,SYSLINUX,or MTOOLs
->3 string !MS
+>3 string !MS
>>3 string !SYSLINUX
>>>3 string !MTOOL
# not FAT (32 bit)
>>>>82 string !FAT32
#not IO.SYS
>>>>>472 string !IO\ \ \ \ \ \ SYS
+>>>>>>480 string !IO\ \ \ \ \ \ SYS
#not Linux kernel
->>>>>>514 string !HdrS
+>>>>>>>514 string !HdrS
+#not BeOS
+>>>>>>>>422 string !Be\ Boot\ Loader
# active flag 0 or 0x80 and type > 0
->>>>>>>446 ubyte <0x81
->>>>>>>>446 ubyte&0x7F 0
+>>>>>>>>>446 ubyte <0x81
+>>>>>>>>>>446 ubyte&0x7F 0
>>>>>>>>>>>450 ubyte >0 \b; partition 1: ID=0x%x
->>>>>>>>>>446 ubyte 0x80 \b, active
->>>>>>>>>>447 ubyte x \b, starthead %u
-#>>>>>>>>>>448 ubyte x \b, start C_S: 0x%x
-#>>>>>>>>>>448 ubeshort&1023 x \b, startcylinder? %d
->>>>>>>>>>454 ulelong x \b, startsector %u
->>>>>>>>>>458 ulelong x \b, %u sectors
+>>>>>>>>>>>>446 ubyte 0x80 \b, active
+>>>>>>>>>>>>447 ubyte x \b, starthead %u
+#>>>>>>>>>>>>448 ubyte x \b, start C_S: 0x%x
+#>>>>>>>>>>>>448 ubeshort&1023 x \b, startcylinder? %d
+>>>>>>>>>>>>454 ulelong x \b, startsector %u
+>>>>>>>>>>>>458 ulelong x \b, %u sectors
#
->>>>>>>462 ubyte <0x81
->>>>>>>>462 ubyte&0x7F 0
->>>>>>>>>466 ubyte >0 \b; partition 2: ID=0x%x
->>>>>>>>>>462 ubyte 0x80 \b, active
->>>>>>>>>>463 ubyte x \b, starthead %u
-#>>>>>>>>>>464 ubyte x \b, start C_S: 0x%x
-#>>>>>>>>>>464 ubeshort&1023 x \b, startcylinder? %d
->>>>>>>>>>470 ulelong x \b, startsector %u
->>>>>>>>>>474 ulelong x \b, %u sectors
+>>>>>>>>>462 ubyte <0x81
+>>>>>>>>>>462 ubyte&0x7F 0
+>>>>>>>>>>>466 ubyte >0 \b; partition 2: ID=0x%x
+>>>>>>>>>>>>462 ubyte 0x80 \b, active
+>>>>>>>>>>>>463 ubyte x \b, starthead %u
+#>>>>>>>>>>>>464 ubyte x \b, start C_S: 0x%x
+#>>>>>>>>>>>>464 ubeshort&1023 x \b, startcylinder? %d
+>>>>>>>>>>>>470 ulelong x \b, startsector %u
+>>>>>>>>>>>>474 ulelong x \b, %u sectors
#
->>>>>>>478 ubyte <0x81
->>>>>>>>478 ubyte&0x7F 0
->>>>>>>>>482 ubyte >0 \b; partition 3: ID=0x%x
->>>>>>>>>>478 ubyte 0x80 \b, active
->>>>>>>>>>479 ubyte x \b, starthead %u
-#>>>>>>>>>>480 ubyte x \b, start C_S: 0x%x
-#>>>>>>>>>>481 ubyte x \b, start C2S: 0x%x
-#>>>>>>>>>>480 ubeshort&1023 x \b, startcylinder? %d
->>>>>>>>>>486 ulelong x \b, startsector %u
->>>>>>>>>>490 ulelong x \b, %u sectors
+>>>>>>>>>478 ubyte <0x81
+>>>>>>>>>>478 ubyte&0x7F 0
+>>>>>>>>>>>482 ubyte >0 \b; partition 3: ID=0x%x
+>>>>>>>>>>>>478 ubyte 0x80 \b, active
+>>>>>>>>>>>>479 ubyte x \b, starthead %u
+#>>>>>>>>>>>>480 ubyte x \b, start C_S: 0x%x
+#>>>>>>>>>>>>481 ubyte x \b, start C2S: 0x%x
+#>>>>>>>>>>>>480 ubeshort&1023 x \b, startcylinder? %d
+>>>>>>>>>>>>486 ulelong x \b, startsector %u
+>>>>>>>>>>>>490 ulelong x \b, %u sectors
#
->>>>>>>494 ubyte <0x81
->>>>>>>>494 ubyte&0x7F 0
->>>>>>>>>498 ubyte >0 \b; partition 4: ID=0x%x
->>>>>>>>>>494 ubyte 0x80 \b, active
->>>>>>>>>>495 ubyte x \b, starthead %u
-#>>>>>>>>>>496 ubyte x \b, start C_S: 0x%x
-#>>>>>>>>>>496 ubeshort&1023 x \b, startcylinder? %d
->>>>>>>>>>502 ulelong x \b, startsector %u
->>>>>>>>>>506 ulelong x \b, %u sectors
+>>>>>>>>>494 ubyte <0x81
+>>>>>>>>>>494 ubyte&0x7F 0
+>>>>>>>>>>>498 ubyte >0 \b; partition 4: ID=0x%x
+>>>>>>>>>>>>494 ubyte 0x80 \b, active
+>>>>>>>>>>>>495 ubyte x \b, starthead %u
+#>>>>>>>>>>>>496 ubyte x \b, start C_S: 0x%x
+#>>>>>>>>>>>>496 ubeshort&1023 x \b, startcylinder? %d
+>>>>>>>>>>>>502 ulelong x \b, startsector %u
+>>>>>>>>>>>>506 ulelong x \b, %u sectors
# mbr partion table entries end
# http://www.acronis.de/
#FAT label=ACRONIS\ SZ
@@ -508,34 +517,52 @@
>>>>>>>498 ubyte&0xDF >0
>>>>>>>>498 string x \b.%-.3s
#
->486 ubyte&0xDF >0
->>416 string Non-System\ disk\ or\
->>>435 string disk\ error\r
->>>>447 string Replace\ and\ press\ any\ key\
->>>>>473 string when\ ready\r \b, Microsoft DOS Bootloader
->480 ubyte&0xDF >0
->>393 string Non-System\ disk\ or\
->>>412 string disk\ error\r
->>>>424 string Replace\ and\ press\ any\ key\
->>>>>450 string when\ ready\r \b, Microsoft DOS bootloader
-#IO.SYS
->>>>>480 string x \b %-.2s
->>>>>>482 ubyte&0xDF >0
->>>>>>>48 string x \b%-.6s
->>>>>488 ubyte&0xDF >0
->>>>>>488 string x \b.%-.3s
-#MSDOS.SYS
->>>>>>491 ubyte&0xDF >0 \b+
->>>>>>>491 string x \b%-.5s
->>>>>>>>496 ubyte&0xDF >0
->>>>>>>>>496 string x \b%-.3s
->>>>>>>499 ubyte&0xDF >0
->>>>>>>>499 string x \b.%-.3s
+>376 search/41 Non-System\ disk\ or\
+>>395 search/41 disk\ error\r
+>>>407 search/41 Replace\ and\
+>>>>419 search/41 press\ \b,
+>>>>419 search/41 strike\ \b, old
+>>>>426 search/41 any\ key\ when\ ready\r MS or PC-DOS bootloader
+#449 Disk\ Boot\ failure\r MS 3.21
+#466 Boot\ Failure\r MS 3.30
+>>>>>468 search/18 \0
+#IO.SYS,IBMBIO.COM
+>>>>>>&0 string x \b %-.2s
+>>>>>>>&-20 ubyte&0xDF >0
+>>>>>>>>&-1 string x \b%-.4s
+>>>>>>>>>&-16 ubyte&0xDF >0
+>>>>>>>>>>&-1 string x \b%-.2s
+>>>>>>&8 ubyte&0xDF >0 \b.
+>>>>>>>&-1 string x \b%-.3s
+#MSDOS.SYS,IBMDOS.COM
+>>>>>>&11 ubyte&0xDF >0 \b+
+>>>>>>>&-1 string x \b%-.5s
+>>>>>>>>&-6 ubyte&0xDF >0
+>>>>>>>>>&-1 string x \b%-.1s
+>>>>>>>>>>&-5 ubyte&0xDF >0
+>>>>>>>>>>>&-1 string x \b%-.2s
+>>>>>>>&7 ubyte&0xDF >0 \b.
+>>>>>>>>&-1 string x \b%-.3s
+>441 string Cannot\ load\ from\ harddisk.\n\r
+>>469 string Insert\ Systemdisk\
+>>>487 string and\ press\ any\ key.\n\r \b, MS (2.11) DOS bootloader
#>43 string \224R-LOADER\ \ SYS =label
>54 string SYS
>>324 string VASKK
>>>495 string NEWLDR\0 \b, DR-DOS Bootloader (LOADER.SYS)
#
+>98 string Press\ a\ key\ to\ retry\0\r
+>>120 string Cannot\ find\ file\ \0\r
+>>>139 string Disk\ read\ error\0\r
+>>>>156 string Loading\ ...\0 \b, DR-DOS (3.41) Bootloader
+#DRBIOS.SYS
+>>>>>44 ubyte&0xDF >0
+>>>>>>44 string x \b %-.6s
+>>>>>>>50 ubyte&0xDF >0
+>>>>>>>>50 string x \b%-.2s
+>>>>>>52 ubyte&0xDF >0
+>>>>>>>52 string x \b.%-.3s
+#
>70 string IBMBIO\ \ COM
>>472 string Cannot\ load\ DOS!\
>>>489 string Any\ key\ to\ retry \b, DR-DOS Bootloader
@@ -680,26 +707,43 @@
#it also hangs with another message ("NF").
>>>>>492 string RENF \b, FAT (12 bit)
>>>>>495 string RENF \b, FAT (16 bit)
+# added by Joerg Jenderek
+# http://syslinux.zytor.com/iso.php
+0 ulelong 0x7c40eafa isolinux Loader
+# http://syslinux.zytor.com/pxe.php
+0 ulelong 0x007c05ea pxelinux Loader
+0 ulelong 0x60669c66 pxelinux Loader
# loader end
-# Joerg Jenderek
->446 ubyte 0
->>450 ubyte >0
->>>482 ubyte 0
->>>>498 ubyte 0
->>>>466 ubyte 0x05 \b, extended partition table
->>>>466 ubyte 0x0F \b, extended partition table (LBA)
->>>>466 ubyte 0x0 \b, extended partition table (last)
+# 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)
# JuMP short bootcodeoffset NOP assembler instructions will usually be EB xx 90
-# older drives may use E9 xx xx
+# http://mirror.href.com/thestarman/asm/2bytejumps.htmm#FWD
+# older drives may use Near JuMP instruction E9 xx xx
>0 lelong&0x009000EB 0x009000EB
>0 lelong&0x000000E9 0x000000E9
->>1 ubyte >37 \b, code offset 0x%x
+# maximal short forward jump is 07fx
+>1 ubyte <0xff \b, code offset 0x%x
# mtools-3.9.8/msdos.h
# usual values are marked with comments to get only informations of strange FAT systems
-# valid sectorsize are from 32 to 2048
->>>11 uleshort <2049
->>>>11 uleshort >31
+# valid sectorsize must be a power of 2 from 32 to 32768
+>>11 uleshort&0x000f x
+>>>11 uleshort <32769
+>>>>11 uleshort >31
>>>>>3 string >\0 \b, OEM-ID "%8.8s"
+#http://mirror.href.com/thestarman/asm/debug/debug2.htm#IHC
+>>>>>>8 string IHC \b cached by Windows 9M
>>>>>11 uleshort >512 \b, Bytes/sector %u
#>>>>>11 uleshort =512 \b, Bytes/sector %u=512 (usual)
>>>>>11 uleshort <512 \b, Bytes/sector %u
@@ -726,17 +770,18 @@
>>>>>26 ubyte >2 \b, heads %u
#>>>>>26 ubyte =2 \b, heads %u (usual floppy)
>>>>>26 ubyte =1 \b, heads %u
->>>>>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)
+#skip for Digital Research DOS (version 3.41) 1440 kB Bootdisk
+>>>>>38 ubyte !0x70
+>>>>>>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 specific
-# NOT le FAT3=NOT 3TAF=0xCCABBEB9
->>>>>82 ulelong&0xCCABBEB9 >0
->>>>>>36 ubyte >0x80 \b, physical drive 0x%x
-#>>>>>>36 ubyte =0x80 \b, physical drive 0x%x=0x80 (usual harddisk)
->>>>>>36 ubyte&0x7F >0 \b, physical drive 0x%x
-#>>>>>>36 ubyte =0 \b, physical drive 0x%x=0 (usual floppy)
+>>>>>82 string !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
>>>>>>37 ubyte >0 \b, reserved 0x%x
#>>>>>>37 ubyte =0 \b, reserved 0x%x
>>>>>>38 ubyte >0x29 \b, dos < 4.0 BootSector (0x%x)
@@ -789,7 +834,7 @@
# Minix filesystems - Juan Cespedes <cespedes@debian.org>
0x410 leshort 0x137f Minix filesystem
-0x410 beshort 0x137f Minix filesystem (big endian),
+0x410 beshort 0x137f Minix filesystem (big endian)
>0x402 beshort !0 \b, %d zones
>0x1e string minix \b, bootable
0x410 leshort 0x138f Minix filesystem, 30 char names
@@ -981,19 +1026,42 @@
>&-1248 belong 0 TIME optimization
>&-1248 belong 1 SPACE optimization
-# ext2/ext3 filesystems - Andreas Dilger <adilger@turbolabs.com>
-0x438 leshort 0xEF53 Linux
->0x44c lelong x rev %d
->0x43e leshort x \b.%d
->0x45c lelong ^0x0000004 ext2 filesystem data
->>0x43a leshort ^0x0000001 (mounted or unclean)
->0x45c lelong &0x0000004 ext3 filesystem data
->>0x460 lelong &0x0000004 (needs journal recovery)
->0x43a leshort &0x0000002 (errors)
->0x460 lelong &0x0000001 (compressed)
-#>0x460 lelong &0x0000002 (filetype)
-#>0x464 lelong &0x0000001 (sparse_super)
->0x464 lelong &0x0000002 (large files)
+# ext2/ext3 filesystems - Andreas Dilger <adilger@dilger.ca>
+# ext4 filesystem - Eric Sandeen <sandeen@sandeen.net>
+0x438 leshort 0xEF53 Linux
+>0x44c lelong x rev %d
+>0x43e leshort x \b.%d
+# No journal? ext2
+>0x45c lelong ^0x0000004 ext2 filesystem data
+>>0x43a leshort ^0x0000001 (mounted or unclean)
+# Has a journal? ext3 or ext4
+>0x45c lelong &0x0000004
+# and small INCOMPAT?
+>>0x460 lelong <0x0000040
+# and small RO_COMPAT?
+>>>0x464 lelong <0x0000008 ext3 filesystem data
+# else large RO_COMPAT?
+>>>0x464 lelong >0x0000007 ext4 filesystem data
+# else large INCOMPAT?
+>>0x460 lelong >0x000003f ext4 filesystem data
+# General flags for any ext* fs
+>0x460 lelong &0x0000004 (needs journal recovery)
+>0x43a leshort &0x0000002 (errors)
+# INCOMPAT flags
+>0x460 lelong &0x0000001 (compressed)
+#>0x460 lelong &0x0000002 (filetype)
+#>0x460 lelong &0x0000010 (meta bg)
+>0x460 lelong &0x0000040 (extents)
+>0x460 lelong &0x0000080 (64bit)
+#>0x460 lelong &0x0000100 (mmp)
+#>0x460 lelong &0x0000200 (flex bg)
+# RO_INCOMPAT flags
+#>0x464 lelong &0x0000001 (sparse super)
+>0x464 lelong &0x0000002 (large files)
+>0x464 lelong &0x0000008 (huge files)
+#>0x464 lelong &0x0000010 (gdt checksum)
+#>0x464 lelong &0x0000020 (many subdirs)
+#>0x463 lelong &0x0000040 (extra isize)
# SGI disk labels - Nathan Scott <nathans@debian.org>
0 belong 0x0BE5A941 SGI disk label (volume header)
@@ -1071,41 +1139,42 @@
# CDROM Filesystems
# Modified for UDF by gerardo.cacciari@gmail.com
-32769 string CD001
->38913 string !NSR0 ISO 9660 CD-ROM filesystem data
->38913 string NSR01 UDF filesystem data (version 1.0)
->38913 string NSR02 UDF filesystem data (version 1.5)
->38913 string NSR03 UDF filesystem data (version 2.0)
->38913 string >NSR03 UDF filesystem data (unknown version,
->>38917 byte x id 'NSR0%c')
->38913 string <NSR01 UDF filesystem data (unknown version,
->>38917 byte x id 'NSR0%c')
+32769 string CD001
+!:mime application/x-iso9660-image
+>38913 string !NSR0 ISO 9660 CD-ROM filesystem data
+>38913 string NSR0 UDF filesystem data
+>>38917 string 1 (version 1.0)
+>>38917 string 2 (version 1.5)
+>>38917 string 3 (version 2.0)
+>>38917 byte >0x33 (unknown version, ID 0x%X)
+>>38917 byte <0x31 (unknown version, ID 0x%X)
# "application id" which appears to be used as a volume label
->32808 string >\0 '%s'
->34816 string \000CD001\001EL\ TORITO\ SPECIFICATION (bootable)
-37633 string CD001 ISO 9660 CD-ROM filesystem data (raw 2352 byte sectors)
-32776 string CDROM High Sierra CD-ROM filesystem data
+>32808 string >\0 '%s'
+>34816 string \000CD001\001EL\ TORITO\ SPECIFICATION (bootable)
+37633 string CD001 ISO 9660 CD-ROM filesystem data (raw 2352 byte sectors)
+!:mime application/x-iso9660-image
+32776 string CDROM High Sierra CD-ROM filesystem data
# cramfs filesystem - russell@coker.com.au
0 lelong 0x28cd3d45 Linux Compressed ROM File System data, little endian
->4 lelong x size %d
+>4 lelong x size %lu
>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 %d,
->40 lelong x %d blocks,
->44 lelong x %d files
+>36 lelong x edition %lu,
+>40 lelong x %lu blocks,
+>44 lelong x %lu files
0 belong 0x28cd3d45 Linux Compressed ROM File System data, big endian
->4 belong x size %d
+>4 belong x size %lu
>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 %d,
->40 belong x %d blocks,
->44 belong x %d files
+>36 belong x edition %lu,
+>40 belong x %lu blocks,
+>44 belong x %lu files
# reiserfs - russell@coker.com.au
0x10034 string ReIsErFs ReiserFS V3.5
@@ -1211,3 +1280,13 @@
>525 byte x Level %d
>525 byte x (ODS-%d OpenVMS file system),
>984 string x volume label is '%-12.12s'
+
+# From: Thomas Klausner <wiz@NetBSD.org>
+# http://filext.com/file-extension/DAA
+# describes the daa file format. The magic would be:
+0 string DAA\x0\x0\x0\x0\x0 PowerISO Direct-Access-Archive
+
+# From Albert Cahalan <acahalan@gmail.com>
+# really le32 operation,destination,payloadsize (but quite predictable)
+# 01 00 00 00 00 00 00 c0 00 02 00 00
+0 string \1\0\0\0\0\0\0\300\0\2\0\0 Marvell Libertas firmware
diff --git a/usr.bin/file/magdir/flash b/usr.bin/file/magdir/flash
index 7d3d86aa10b..ea3e6fb20e9 100644
--- a/usr.bin/file/magdir/flash
+++ b/usr.bin/file/magdir/flash
@@ -1,4 +1,4 @@
-# $OpenBSD: flash,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: flash,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# flash: file(1) magic for Macromedia Flash file format
@@ -9,10 +9,13 @@
#
0 string FWS Macromedia Flash data,
>3 byte x version %d
+!:mime application/x-shockwave-flash
0 string CWS Macromedia Flash data (compressed),
+!:mime application/x-shockwave-flash
>3 byte x version %d
# From: Cal Peake <cp@absolutedigital.net>
0 string FLV Macromedia Flash Video
+!:mime video/x-flv
#
# From Dave Wilson
diff --git a/usr.bin/file/magdir/fonts b/usr.bin/file/magdir/fonts
index c3d32ab56b6..c2cf2d90394 100644
--- a/usr.bin/file/magdir/fonts
+++ b/usr.bin/file/magdir/fonts
@@ -1,15 +1,15 @@
-# $OpenBSD: fonts,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: fonts,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# fonts: file(1) magic for font data
#
-0 string FONT ASCII vfont text
+0 search/1 FONT ASCII vfont text
0 short 0436 Berkeley vfont data
0 short 017001 byte-swapped Berkeley vfont data
# PostScript fonts (must precede "printer" entries), quinlan@yggdrasil.com
-0 string %!PS-AdobeFont-1. PostScript Type 1 font text
->20 string >\0 (%s)
+0 search/1 %!PS-AdobeFont-1. PostScript Type 1 font text
+>20 search/1 >\0 (%s)
6 string %!PS-AdobeFont-1. PostScript Type 1 font program data
# X11 font files in SNF (Server Natural Format) format
@@ -17,7 +17,7 @@
0 lelong 00000004 X11 SNF font data, LSB first
# X11 Bitmap Distribution Format, from Daniel Quinlan (quinlan@yggdrasil.com)
-0 string STARTFONT\040 X11 BDF font text
+0 search/1 STARTFONT\ X11 BDF font text
# X11 fonts, from Daniel Quinlan (quinlan@yggdrasil.com)
# PCF must come before SGI additions ("MIPSEL MIPS-II COFF" collides)
diff --git a/usr.bin/file/magdir/fortran b/usr.bin/file/magdir/fortran
new file mode 100644
index 00000000000..3e490333e18
--- /dev/null
+++ b/usr.bin/file/magdir/fortran
@@ -0,0 +1,3 @@
+# FORTRAN source
+0 string/c c\ FORTRAN program
+!:mime text/x-fortran
diff --git a/usr.bin/file/magdir/frame b/usr.bin/file/magdir/frame
index 4b3405a3657..08f87e7c4b5 100644
--- a/usr.bin/file/magdir/frame
+++ b/usr.bin/file/magdir/frame
@@ -1,4 +1,4 @@
-# $OpenBSD: frame,v 1.3 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: frame,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# frame: file(1) magic for FrameMaker files
@@ -6,7 +6,11 @@
# This stuff came on a FrameMaker demo tape, most of which is
# copyright, but this file is "published" as witness the following:
#
+# Note that this is the Framemaker Maker Interchange Format, not the
+# Normal format which would be application/vnd.framemaker.
+#
0 string \<MakerFile FrameMaker document
+!:mime application/x-mif
>11 string 5.5 (5.5
>11 string 5.0 (5.0
>11 string 4.0 (4.0
@@ -15,25 +19,32 @@
>11 string 1.0 (1.0
>14 byte x %c)
0 string \<MIFFile FrameMaker MIF (ASCII) file
+!:mime application/x-mif
>9 string 4.0 (4.0)
>9 string 3.0 (3.0)
>9 string 2.0 (2.0)
>9 string 1.0 (1.x)
-0 string \<MakerDictionary FrameMaker Dictionary text
+0 search/1 \<MakerDictionary FrameMaker Dictionary text
+!:mime application/x-mif
>17 string 3.0 (3.0)
>17 string 2.0 (2.0)
>17 string 1.0 (1.x)
0 string \<MakerScreenFont FrameMaker Font file
+!:mime application/x-mif
>17 string 1.01 (%s)
0 string \<MML FrameMaker MML file
+!:mime application/x-mif
0 string \<BookFile FrameMaker Book file
+!:mime application/x-mif
>10 string 3.0 (3.0
>10 string 2.0 (2.0
>10 string 1.0 (1.0
>13 byte x %c)
# XXX - this book entry should be verified, if you find one, uncomment this
#0 string \<Book\ FrameMaker Book (ASCII) file
+#!:mime application/x-mif
#>6 string 3.0 (3.0)
#>6 string 2.0 (2.0)
#>6 string 1.0 (1.0)
0 string \<Maker Intermediate Print File FrameMaker IPL file
+!:mime application/x-mif
diff --git a/usr.bin/file/magdir/fsav b/usr.bin/file/magdir/fsav
index 799e19872d7..18395502fe6 100644
--- a/usr.bin/file/magdir/fsav
+++ b/usr.bin/file/magdir/fsav
@@ -1,4 +1,4 @@
-# $OpenBSD: fsav,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: fsav,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# fsav: file(1) magic for datafellows fsav virus definition files
@@ -47,7 +47,7 @@
0 string ClamAV-VDB:
>11 string >\0 Clam AntiVirus database %-.23s
>>34 string :
->>>35 regex [^:]+ \b, version
+>>>35 string !: \b, version
>>>>35 string x \b%-.1s
>>>>>36 string !:
>>>>>>36 string x \b%-.1s
@@ -56,6 +56,10 @@
>>>>>>>>>38 string !:
>>>>>>>>>>38 string x \b%-.1s
>>>>512 string \037\213 \b, gzipped
->>>>769 string ustar\0 \b, tared
+>>>>769 string ustar\0 \b, tarred
>512 string \037\213 \b, gzipped
->769 string ustar\0 \b, tared
+>769 string ustar\0 \b, tarred
+
+# Type: Grisoft AVG AntiVirus
+# From: David Newgas <david@newgas.net>
+0 string AVG7_ANTIVIRUS_VAULT_FILE AVG 7 Antivirus vault file data
diff --git a/usr.bin/file/magdir/games b/usr.bin/file/magdir/games
index aff8cef4c9e..7f0a79a3b61 100644
--- a/usr.bin/file/magdir/games
+++ b/usr.bin/file/magdir/games
@@ -1,14 +1,8 @@
-# $OpenBSD: games,v 1.1 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: games,v 1.2 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# games: file(1) for games
-# Thomas M. Ott (ThMO)
-1 string =WAD DOOM data,
->0 string =I main wad
->0 string =P patch wad
->0 byte x unknown junk
-
# Fabio Bonelli <fabiobonelli@libero.it>
# Quake II - III data files
0 string IDP2 Quake II 3D Model file,
@@ -31,11 +25,6 @@
# Doom and Quake
# submitted by Nicolas Patrois
-# DOOM
-
-0 string IWAD DOOM or DOOM ][ world
-0 string PWAD DOOM or DOOM ][ extension world
-
0 string \xcb\x1dBoom\xe6\xff\x03\x01 Boom or linuxdoom demo
# some doom lmp files don't match, I've got one beginning with \x6d\x02\x01\x01
@@ -157,3 +146,10 @@
0 string MComprHD MAME CHD compressed hard disk image,
>12 belong x version %lu
+
+# doom - submitted by Jon Dowland
+
+0 string =IWAD doom main IWAD data
+>4 lelong x containing %d lumps
+0 string =PWAD doom patch PWAD data
+>4 lelong x containing %d lumps
diff --git a/usr.bin/file/magdir/gnome-keyring b/usr.bin/file/magdir/gnome-keyring
new file mode 100644
index 00000000000..80a4f882c16
--- /dev/null
+++ b/usr.bin/file/magdir/gnome-keyring
@@ -0,0 +1,23 @@
+# GNOME keyring
+# Contributed by Josh Triplett
+# FIXME: Could be simplified if pstring supported two-byte counts
+0 string GnomeKeyring\n\r\0\n GNOME keyring
+>&0 ubyte 0 \b, major version 0
+>>&0 ubyte 0 \b, minor version 0
+>>>&0 ubyte 0 \b, crypto type 0 (AEL)
+>>>&0 ubyte >0 \b, crypto type %hhu (unknown)
+>>>&1 ubyte 0 \b, hash type 0 (MD5)
+>>>&1 ubyte >0 \b, hash type %hhu (unknown)
+>>>&2 ubelong 0xFFFFFFFF \b, name NULL
+>>>&2 ubelong !0xFFFFFFFF
+>>>>&-4 ubelong >255 \b, name too long for file's pstring type
+>>>>&-4 ubelong <256
+>>>>>&-1 pstring x \b, name "%s"
+>>>>>>&0 ubeqdate x \b, last modified %s
+>>>>>>&8 ubeqdate x \b, created %s
+>>>>>>&16 ubelong &1
+>>>>>>>&0 ubelong x \b, locked if idle for %u seconds
+>>>>>>&16 ubelong ^1 \b, not locked if idle
+>>>>>>&24 ubelong x \b, hash iterations %u
+>>>>>>&28 ubequad x \b, salt %llu
+>>>>>>&52 ubelong x \b, %u item(s)
diff --git a/usr.bin/file/magdir/gnu b/usr.bin/file/magdir/gnu
index baa9f4c03ac..4a34282ca04 100644
--- a/usr.bin/file/magdir/gnu
+++ b/usr.bin/file/magdir/gnu
@@ -1,4 +1,4 @@
-# $OpenBSD: gnu,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: gnu,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# gnu: file(1) magic for various GNU tools
@@ -19,10 +19,14 @@
# The format is very similar to pgp
0 string \001gpg GPG key trust database
>4 byte x version %d
+# Note: magic.mime had 0x8501 for the next line instead of 0x8502
0 beshort 0x8502 GPG encrypted data
+!:mime text/PGP # encoding: data
+
# This magic is not particularly good, as the keyrings don't have true
# magic. Nevertheless, it covers many keyrings.
0 beshort 0x9901 GPG key public ring
+!:mime application/x-gnupg-keyring
# Gnumeric spreadsheet
# This entry is only semi-helpful, as Gnumeric compresses its files, so
diff --git a/usr.bin/file/magdir/gnumeric b/usr.bin/file/magdir/gnumeric
new file mode 100644
index 00000000000..76dfa90684e
--- /dev/null
+++ b/usr.bin/file/magdir/gnumeric
@@ -0,0 +1,7 @@
+
+#------------------------------------------------------------------------------
+# gnumeric: file(1) magic for Gnumeric spreadsheet
+# This entry is only semi-helpful, as Gnumeric compresses its files, so
+# they will ordinarily reported as "compressed", but at least -z helps
+39 string =<gmr:Workbook Gnumeric spreadsheet
+!:mime application/x-gnumeric
diff --git a/usr.bin/file/magdir/hp b/usr.bin/file/magdir/hp
index ed131ba3e3f..49c6434cbd2 100644
--- a/usr.bin/file/magdir/hp
+++ b/usr.bin/file/magdir/hp
@@ -1,4 +1,4 @@
-# $OpenBSD: hp,v 1.6 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: hp,v 1.7 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# hp: file(1) magic for Hewlett Packard machines (see also "printer")
@@ -204,33 +204,36 @@
>8 long >0 %d messages
# addendum to /etc/magic with HP-48sx file-types by phk@data.fls.dk 1jan92
-0 string HPHP48- HP48 binary
->7 byte >0 - Rev %c
->8 beshort 0x1129 (ADR)
->8 beshort 0x3329 (REAL)
->8 beshort 0x5529 (LREAL)
->8 beshort 0x7729 (COMPLX)
->8 beshort 0x9d29 (LCOMPLX)
->8 beshort 0xbf29 (CHAR)
->8 beshort 0xe829 (ARRAY)
->8 beshort 0x0a2a (LNKARRAY)
->8 beshort 0x2c2a (STRING)
->8 beshort 0x4e2a (HXS)
->8 beshort 0x742a (LIST)
->8 beshort 0x962a (DIR)
->8 beshort 0xb82a (ALG)
->8 beshort 0xda2a (UNIT)
->8 beshort 0xfc2a (TAGGED)
->8 beshort 0x1e2b (GROB)
->8 beshort 0x402b (LIB)
->8 beshort 0x622b (BACKUP)
->8 beshort 0x882b (LIBDATA)
->8 beshort 0x9d2d (PROG)
->8 beshort 0xcc2d (CODE)
->8 beshort 0x482e (GNAME)
->8 beshort 0x6d2e (LNAME)
->8 beshort 0x922e (XLIB)
-0 string %%HP: HP48 text
+0 string HPHP4 HP
+>5 string 8 48 binary
+>5 string 9 49 binary
+>7 byte >64 - Rev %c
+>8 leshort 0x2911 (ADR)
+>8 leshort 0x2933 (REAL)
+>8 leshort 0x2955 (LREAL)
+>8 leshort 0x2977 (COMPLX)
+>8 leshort 0x299d (LCOMPLX)
+>8 leshort 0x29bf (CHAR)
+>8 leshort 0x29e8 (ARRAY)
+>8 leshort 0x2a0a (LNKARRAY)
+>8 leshort 0x2a2c (STRING)
+>8 leshort 0x2a4e (HXS)
+>8 leshort 0x2a74 (LIST)
+>8 leshort 0x2a96 (DIR)
+>8 leshort 0x2ab8 (ALG)
+>8 leshort 0x2ada (UNIT)
+>8 leshort 0x2afc (TAGGED)
+>8 leshort 0x2b1e (GROB)
+>8 leshort 0x2b40 (LIB)
+>8 leshort 0x2b62 (BACKUP)
+>8 leshort 0x2b88 (LIBDATA)
+>8 leshort 0x2d9d (PROG)
+>8 leshort 0x2dcc (CODE)
+>8 leshort 0x2e48 (GNAME)
+>8 leshort 0x2e6d (LNAME)
+>8 leshort 0x2e92 (XLIB)
+
+0 search/1 %%HP: HP text
>6 string T(0) - T(0)
>6 string T(1) - T(1)
>6 string T(2) - T(2)
@@ -241,6 +244,23 @@
>14 string F(.) F(.);
>14 string F(,) F(,);
+0 string HP3 HP
+>3 string 8 38
+>3 string 9 39
+>4 string Bin binary
+>4 string Asc ASCII
+>7 string A (Directory List)
+>7 string B (Zaplet)
+>7 string C (Note)
+>7 string D (Program)
+>7 string E (Variable)
+>7 string F (List)
+>7 string G (Matrix)
+>7 string H (Library)
+>7 string I (Target List)
+>7 string J (ASCII Vector specification)
+>7 string K (wildcard)
+
# hpBSD magic numbers
0 beshort 200 hp200 (68010) BSD
>2 beshort 0407 impure binary
@@ -392,5 +412,5 @@
>>>>>>>>>0xC4 belong 34 - received SIGXFSZ
# From: AMAKAWA Shuhei <sa264@cam.ac.uk>
-0 string HPHP49- HP49 binary
+#0 string HPHP49- HP49 binary
diff --git a/usr.bin/file/magdir/iff b/usr.bin/file/magdir/iff
index ca0b18a55bf..d1388b509d1 100644
--- a/usr.bin/file/magdir/iff
+++ b/usr.bin/file/magdir/iff
@@ -1,4 +1,4 @@
-# $OpenBSD: iff,v 1.3 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: iff,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# iff: file(1) magic for Interchange File Format (see also "audio" & "images")
@@ -14,8 +14,11 @@
#>4 belong x \b, FORM is %d bytes long
# audio formats
>8 string AIFF \b, AIFF audio
+!:mime audio/x-aiff
>8 string AIFC \b, AIFF-C compressed audio
+!:mime audio/x-aiff
>8 string 8SVX \b, 8SVX 8-bit sampled sound voice
+!:mime audio/x-aiff
>8 string 16SV \b, 16SV 16-bit sampled sound voice
>8 string SAMP \b, SAMP sampled audio
>8 string MAUD \b, MAUD MacroSystem audio
diff --git a/usr.bin/file/magdir/images b/usr.bin/file/magdir/images
index 343e1ff23d8..2e47a8eb15a 100644
--- a/usr.bin/file/magdir/images
+++ b/usr.bin/file/magdir/images
@@ -1,7 +1,8 @@
-# $OpenBSD: images,v 1.9 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: images,v 1.10 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
-# images: file(1) magic for image formats (see also "iff")
+# images: file(1) magic for image formats (see also "iff", and "c-lang" for
+# XPM bitmaps)
#
# originally from jef@helios.ee.lbl.gov (Jef Poskanzer),
# additions by janl@ifi.uio.no as well as others. Jan also suggested
@@ -31,13 +32,20 @@
# PBMPLUS images
# The next byte following the magic is always whitespace.
-0 string P1 Netpbm PBM image text
-0 string P2 Netpbm PGM image text
-0 string P3 Netpbm PPM image text
+0 search/1 P1 Netpbm PBM image text
+!:mime image/x-portable-bitmap
+0 search/1 P2 Netpbm PGM image text
+!:mime image/x-portable-greymap
+0 search/1 P3 Netpbm PPM image text
+!:mime image/x-portable-pixmap
0 string P4 Netpbm PBM "rawbits" image data
+!:mime image/x-portable-bitmap
0 string P5 Netpbm PGM "rawbits" image data
+!:mime image/x-portable-greymap
0 string P6 Netpbm PPM "rawbits" image data
+!:mime image/x-portable-pixmap
0 string P7 Netpbm PAM image file
+!:mime image/x-portable-pixmap
# From: bryanh@giraffe-data.com (Bryan Henderson)
0 string \117\072 Solitaire Image Recorder format
@@ -51,13 +59,17 @@
>21 byte 51 version 3
# NIFF (Navy Interchange File Format, a modification of TIFF) images
+# [GRR: this *must* go before TIFF]
0 string IIN1 NIFF image data
+!:mime image/x-niff
# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)
# The second word of TIFF files is the TIFF version number, 42, which has
# never changed. The TIFF specification recommends testing for it.
0 string MM\x00\x2a TIFF image data, big-endian
+!:mime image/tiff
0 string II\x2a\x00 TIFF image data, little-endian
+!:mime image/tiff
# PNG [Portable Network Graphics, or "PNG's Not GIF"] images
# (Greg Roelofs, newt@uchicago.edu)
@@ -66,6 +78,7 @@
# 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
#
0 string \x89PNG PNG image data,
+!:mime image/png
>4 belong !0x0d0a1a0a CORRUPTED,
>4 belong 0x0d0a1a0a
>>16 belong x %ld x
@@ -81,8 +94,27 @@
>>28 byte 1 interlaced
1 string PNG PNG image data, CORRUPTED
+# possible GIF replacements; none yet released!
+# (Greg Roelofs, newt@uchicago.edu)
+#
+# GRR 950115: this was mine ("Zip GIF"):
+0 string GIF94z ZIF image (GIF+deflate alpha)
+!:mime image/x-unknown
+#
+# GRR 950115: this is Jeremy Wohl's Free Graphics Format (better):
+#
+0 string FGF95a FGF image (GIF+deflate beta)
+!:mime image/x-unknown
+#
+# GRR 950115: this is Thomas Boutell's Portable Bitmap Format proposal
+# (best; not yet implemented):
+#
+0 string PBF PBF image (deflate compression)
+!:mime image/x-unknown
+
# GIF
0 string GIF8 GIF image data
+!:mime image/gif
>4 string 7a \b, version 8%s,
>4 string 9a \b, version 8%s,
>6 leshort >0 %hd x
@@ -114,7 +146,7 @@
>4 long 3 \b, rectangular 32-bit (24-bit with matte)
# FIG (Facility for Interactive Generation of figures), an object-based format
-0 string #FIG FIG image text
+0 search/1 #FIG FIG image text
>5 string x \b, version %.3s
# PHIGS
@@ -131,8 +163,8 @@
# CGM image files
0 string BEGMF clear text Computer Graphics Metafile
# XXX - questionable magic
-0 beshort&0xffe0 0x0020 binary Computer Graphics Metafile
-0 beshort 0x3020 character Computer Graphics Metafile
+#0 beshort&0xffe0 0x0020 binary Computer Graphics Metafile
+#0 beshort 0x3020 character Computer Graphics Metafile
# MGR bitmaps (Michael Haardt, u31b3hs@pool.informatik.rwth-aachen.de)
0 string yz MGR bitmap, modern format, 8-bit aligned
@@ -153,8 +185,9 @@
0 string Sfff structured fax file
-# PC bitmaps (OS/2, Windoze BMP files) (Greg Roelofs, newt@uchicago.edu)
+# PC bitmaps (OS/2, Windows BMP files) (Greg Roelofs, newt@uchicago.edu)
0 string BM PC bitmap data
+!:mime image/x-ms-bmp
>14 leshort 12 \b, OS/2 1.x format
>>18 leshort x \b, %d x
>>20 leshort x %d
@@ -175,7 +208,7 @@
# XPM icons (Greg Roelofs, newt@uchicago.edu)
# note possible collision with C/REXX entry in c-lang; currently commented out
-0 string /*\ XPM\ */ X pixmap image text
+0 search/1 /*\ XPM\ */ X pixmap image text
# Utah Raster Toolkit RLE images (janl@ifi.uio.no)
0 leshort 0xcc52 RLE image data,
@@ -261,7 +294,7 @@
# other images
0 string This\ is\ a\ BitMap\ file Lisp Machine bit-array-file
-0 string =!! Bennet Yee's "face" format
+#0 string =!! Bennet Yee's "face" format
# From SunOS 5.5.1 "/etc/magic" - appeared right before Sun raster image
# stuff.
@@ -270,6 +303,7 @@
# DICOM medical imaging data
128 string DICM DICOM medical imaging data
+!:mime application/dicom
# XWD - X Window Dump file.
# As described in /usr/X11R6/include/X11/XWDFile.h
@@ -368,6 +402,7 @@
# Adobe Photoshop
0 string 8BPS Adobe Photoshop Image
+!:mime image/vnd.adobe.photoshop
# XV thumbnail indicator (ThMO)
0 string P7\ 332 XV thumbnail image data
@@ -457,9 +492,9 @@
>12 long x \b, track size %d bytes
>16 byte x \b, device type 33%2.2X
-# Squeak images and - etoffi@softhome.net
-0 string \146\031\0\0 Squeak image data
-0 string 'From\040Squeak Squeak program text
+# Squeak images and programs - etoffi@softhome.net
+0 string \146\031\0\0 Squeak image data
+0 search/1 'From\040Squeak Squeak program text
# partimage: file(1) magic for PartImage files (experimental, incomplete)
# Author: Hans-Joachim Baader <hjb@pro-linux.de>
@@ -509,9 +544,7 @@
# From: stephane.loeuillet@tiscali.f
# http://www.djvuzone.org/
0 string AT&TFORM DjVu Image file
-
-# From: Jason Bacon <bacon@smithers.neuro.mcw.edu>
-0 beshort 0x3020 character Computer Graphics Metafile
+!:mime image/vnd.djvu
# From Marc Espie
0 lelong 20000630 OpenEXR image data
@@ -524,9 +557,36 @@
# Hierarchical Data Format, used to facilitate scientific data exchange
# specifications at http://hdf.ncsa.uiuc.edu/
0 belong 0x0e031301 Hierarchical Data Format (version 4) data
+!:mime application/x-hdf
0 string \211HDF\r\n\032 Hierarchical Data Format (version 5) data
+!:mime application/x-hdf
# From: Tobias Burnus <burnus@net-b.de>
# Xara (for a while: Corel Xara) is a graphic package, see
-# http://www.xara.com/ for Windows and as GPL application for
+# http://www.xara.com/ for Windows and as GPL application for Linux
0 string XARA\243\243 Xara graphics file
+
+# http://www.cartesianinc.com/Tech/
+0 string CPC\262 Cartesian Perceptual Compression image
+!:mime image/x-cpi
+
+# From Albert Cahalan <acahalan@gmail.com>
+# puredigital used it for the CVS disposable camcorder
+#8 lelong 4 ZBM bitmap image data
+#>4 leshort x %u x
+#>6 leshort x %u
+
+# From Albert Cahalan <acahalan@gmail.com>
+# uncompressed 5:6:5 HighColor image for OLPC XO firmware icons
+0 string C565 OLPC firmware icon image data
+>4 leshort x %u x
+>6 leshort x %u
+
+# Applied Images - Image files from Cytovision
+# Gustavo Junior Alves <gjalves@gjalves.com.br>
+0 string \xce\xda\xde\xfa Cytovision Metaphases file
+0 string \xed\xad\xef\xac Cytovision Karyotype file
+0 string \x0b\x00\x03\x00 Cytovision FISH Probe file
+0 string \xed\xfe\xda\xbe Cytovision FLEX file
+0 string \xed\xab\xed\xfe Cytovision FLEX file
+0 string \xad\xfd\xea\xad Cytovision RATS file
diff --git a/usr.bin/file/magdir/inform b/usr.bin/file/magdir/inform
new file mode 100644
index 00000000000..ba35d61e046
--- /dev/null
+++ b/usr.bin/file/magdir/inform
@@ -0,0 +1,8 @@
+
+#------------------------------------------------------------------------------
+# inform: file(1) magic for Inform interactive fiction language
+
+# URL: http://www.inform-fiction.org/
+# From: Reuben Thomas <rrt@sc3d.org>
+
+0 search/cB/100 constant\ story Inform source text
diff --git a/usr.bin/file/magdir/java b/usr.bin/file/magdir/java
index cdde1df7b0c..4951a66533c 100644
--- a/usr.bin/file/magdir/java
+++ b/usr.bin/file/magdir/java
@@ -1,4 +1,4 @@
-# $OpenBSD: java,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: java,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------
# Java ByteCode and Mach-O binaries (e.g., Mac OS X) use the
@@ -9,3 +9,18 @@
# From Martin Pool (m.pool@pharos.com.au)
0 beshort 0xaced Java serialization data
>2 beshort >0x0004 \b, version %d
+
+0 belong 0xfeedfeed Java KeyStore
+!:mime application/x-java-keystore
+0 belong 0xcececece Java JCE KeyStore
+!:mime application/x-java-jce-keystore
+
+# Dalvik .dex format. http://retrodev.com/android/dexformat.html
+# From <mkf@google.com> "Mike Fleming"
+0 string dex\n
+>0 regex dex\n[0-9][0-9][0-9]\0 Dalvik dex file
+>4 string >000 version %s
+0 string dey\n
+>0 regex dey\n[0-9][0-9][0-9]\0 Dalvik dex file (optimized for host)
+>4 string >000 version %s
+
diff --git a/usr.bin/file/magdir/jpeg b/usr.bin/file/magdir/jpeg
index 5f40f0c8140..246ae162e57 100644
--- a/usr.bin/file/magdir/jpeg
+++ b/usr.bin/file/magdir/jpeg
@@ -1,4 +1,4 @@
-# $OpenBSD: jpeg,v 1.3 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: jpeg,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# JPEG images
@@ -10,6 +10,7 @@
# both of which turn into "JPEG image data" here.
#
0 beshort 0xffd8 JPEG image data
+!:mime image/jpeg
>6 string JFIF \b, JFIF standard
# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
# in a vain attempt to add image size reporting for JFIF. Note that these
@@ -154,3 +155,8 @@
# From: David Santinoli <david@santinoli.com>
0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000 image data
+
+# Type: JPEG 2000 codesream
+# From: Mathieu Malaterre <mathieu.malaterre@gmail.com>
+0 belong 0xff4fff51 JPEG 2000 codestream
+45 beshort 0xff52
diff --git a/usr.bin/file/magdir/kde b/usr.bin/file/magdir/kde
new file mode 100644
index 00000000000..d81ee693fd5
--- /dev/null
+++ b/usr.bin/file/magdir/kde
@@ -0,0 +1,10 @@
+
+#------------------------------------------------------------------------------
+# kde: file(1) magic for KDE
+
+0 string [KDE\ Desktop\ Entry] KDE desktop entry
+!:mime application/x-kdelnk
+0 string #\ KDE\ Config\ File KDE config file
+!:mime application/x-kdelnk
+0 string #\ xmcd xmcd database file for kscd
+!:mime text/x-xmcd
diff --git a/usr.bin/file/magdir/lex b/usr.bin/file/magdir/lex
index c881e1e2b71..9059bf05bd4 100644
--- a/usr.bin/file/magdir/lex
+++ b/usr.bin/file/magdir/lex
@@ -1,12 +1,12 @@
-# $OpenBSD: lex,v 1.3 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: lex,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# lex: file(1) magic for lex
#
# derived empirically, your offsets may vary!
-53 string yyprevious C program text (from lex)
->3 string >\0 for %s
+0 search/100 yyprevious C program text (from lex)
+>3 search/1 >\0 for %s
# C program text from GNU flex, from Daniel Quinlan <quinlan@yggdrasil.com>
-21 string generated\ by\ flex C program text (from flex)
+0 search/100 generated\ by\ flex C program text (from flex)
# lex description file, from Daniel Quinlan <quinlan@yggdrasil.com>
-0 string %{ lex description text
+0 search/1 %{ lex description text
diff --git a/usr.bin/file/magdir/linux b/usr.bin/file/magdir/linux
index 6d78266de78..76e45a49efe 100644
--- a/usr.bin/file/magdir/linux
+++ b/usr.bin/file/magdir/linux
@@ -1,4 +1,4 @@
-# $OpenBSD: linux,v 1.5 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: linux,v 1.6 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# linux: file(1) magic for Linux files
@@ -104,16 +104,18 @@
>0x1e9 string Loading from prehistoric times
# System.map files - Nicolás Lichtmaier <nick@debian.org>
-8 string \ A\ _text Linux kernel symbol map text
+8 search/1 \ A\ _text Linux kernel symbol map text
# LSM entries - Nicolás Lichtmaier <nick@debian.org>
-0 string Begin3 Linux Software Map entry text
-0 string Begin4 Linux Software Map entry text (new format)
-
-# From Matt Zimmerman
-0 belong 0x4f4f4f4d User-mode Linux COW file
->4 belong x \b, version %d
->8 string >\0 \b, backing file %s
+0 search/1 Begin3 Linux Software Map entry text
+0 search/1 Begin4 Linux Software Map entry text (new format)
+
+# From Matt Zimmerman, enhanced for v3 by Matthew Palmer
+0 belong 0x4f4f4f4d User-mode Linux COW file
+>4 belong <3 \b, version %d
+>>8 string >\0 \b, backing file %s
+>4 belong >2 \b, version %d
+>>32 string >\0 \b, backing file %s
############################################################################
# Linux kernel versions
diff --git a/usr.bin/file/magdir/lisp b/usr.bin/file/magdir/lisp
index 10f127265f0..b5c3bfa09d2 100644
--- a/usr.bin/file/magdir/lisp
+++ b/usr.bin/file/magdir/lisp
@@ -1,4 +1,4 @@
-# $OpenBSD: lisp,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: lisp,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# lisp: file(1) magic for lisp programs
@@ -6,11 +6,12 @@
# various lisp types, from Daniel Quinlan (quinlan@yggdrasil.com)
# updated by Joerg Jenderek
-0 string ;;
+# GRR: This lot is too weak
+#0 string ;;
# windows INF files often begin with semicolon and use CRLF as line end
# lisp files are mainly created on unix system with LF as line end
->2 search/2048 !\r Lisp/Scheme program text
->2 search/2048 \r Windows INF file
+#>2 search/2048 !\r Lisp/Scheme program text
+#>2 search/2048 \r Windows INF file
0 search/256 (if\ Lisp/Scheme program text
0 search/256 (setq\ Lisp/Scheme program text
@@ -22,15 +23,17 @@
# Emacs 18 - this is always correct, but not very magical.
0 string \012( Emacs v18 byte-compiled Lisp data
+!:mime application/x-elc
# Emacs 19+ - ver. recognition added by Ian Springer
-# Also applies to XEmacs 19+ .elc files; could tell them apart if we had regexp
-# support or similar - Chris Chittleborough <cchittleborough@yahoo.com.au>
-0 string ;ELC
->4 byte >19
+# Also applies to XEmacs 19+ .elc files; could tell them apart with regexs
+# - Chris Chittleborough <cchittleborough@yahoo.com.au>
+0 string ;ELC
+>4 byte >18
>4 byte <32 Emacs/XEmacs v%d byte-compiled Lisp data
+!:mime application/x-elc
# Files produced by CLISP Common Lisp From: Bruno Haible <haible@ilog.fr>
-0 string (SYSTEM::VERSION\040' CLISP byte-compiled Lisp program text
+0 string (SYSTEM::VERSION\040' CLISP byte-compiled Lisp program
0 long 0x70768BD2 CLISP memory image data
0 long 0xD28B7670 CLISP memory image data, other endian
@@ -42,4 +45,5 @@
0 string \372\372\372\372 MIT scheme (library?)
# From: David Allouche <david@allouche.net>
-0 string \<TeXmacs| TeXmacs document text
+0 search/1 \<TeXmacs| TeXmacs document text
+!:mime text/texmacs
diff --git a/usr.bin/file/magdir/llvm b/usr.bin/file/magdir/llvm
new file mode 100644
index 00000000000..8c1610cd10e
--- /dev/null
+++ b/usr.bin/file/magdir/llvm
@@ -0,0 +1,10 @@
+
+#------------------------------------------------------------------------------
+# llvm: file(1) magic for LLVM byte-codes
+# URL: http://llvm.cs.uiuc.edu/docs/BytecodeFormat.html#signature
+# From: Al Stone <ahs3@fc.hp.com>
+
+0 string llvm LLVM byte-codes, uncompressed
+0 string llvc0 LLVM byte-codes, null compression
+0 string llvc1 LLVM byte-codes, gzip compression
+0 string llvc2 LLVM byte-codes, bzip2 compression
diff --git a/usr.bin/file/magdir/lua b/usr.bin/file/magdir/lua
new file mode 100644
index 00000000000..303fd3798e1
--- /dev/null
+++ b/usr.bin/file/magdir/lua
@@ -0,0 +1,15 @@
+#------------------------------------------------------------------------------
+# lua: file(1) magic for Lua scripting language
+# URL: http://www.lua.org/
+# From: Reuben Thomas <rrt@sc3d.org>, Seo Sanghyeon <tinuviel@sparcs.kaist.ac.kr>
+
+# Lua scripts
+0 search/1/b #!\ /usr/bin/lua Lua script text executable
+0 search/1/b #!\ /usr/local/bin/lua Lua script text executable
+0 search/1 #!/usr/bin/env\ lua Lua script text executable
+0 search/1 #!\ /usr/bin/env\ lua Lua script text executable
+
+# Lua bytecode
+0 string \033Lua Lua bytecode,
+>4 byte 0x50 version 5.0
+>4 byte 0x51 version 5.1
diff --git a/usr.bin/file/magdir/luks b/usr.bin/file/magdir/luks
new file mode 100644
index 00000000000..2ab23935ef6
--- /dev/null
+++ b/usr.bin/file/magdir/luks
@@ -0,0 +1,12 @@
+
+#------------------------------------------------------------------------------
+# luks: file(1) magic for Linux Unified Key Setup
+# URL: http://luks.endorphin.org/spec
+# From: Anthon van der Neut <anthon@mnt.org>
+
+0 string LUKS\xba\xbe LUKS encrypted file,
+>6 beshort x ver %d
+>8 string x [%s,
+>40 string x %s,
+>72 string x %s]
+>168 string x UUID: %s
diff --git a/usr.bin/file/magdir/macintosh b/usr.bin/file/magdir/macintosh
index c7dbea573a7..3ad6da5b61a 100644
--- a/usr.bin/file/magdir/macintosh
+++ b/usr.bin/file/magdir/macintosh
@@ -1,4 +1,4 @@
-# $OpenBSD: macintosh,v 1.3 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: macintosh,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# macintosh description
@@ -6,6 +6,7 @@
# BinHex is the Macintosh ASCII-encoded file format (see also "apple")
# Daniel Quinlan, quinlan@yggdrasil.com
11 string must\ be\ converted\ with\ BinHex BinHex binary text
+!:mime application/mac-binhex40
>41 string x \b, version %.3s
# Stuffit archives are the de facto standard of compression for Macintosh
@@ -19,37 +20,41 @@
# Newer StuffIt archives (grant@netbsd.org)
0 string StuffIt StuffIt Archive
+!:mime application/x-stuffit
#>162 string >0 : %s
# Macintosh Applications and Installation binaries (franklsm@tuns.ca)
-0 string APPL Macintosh Application (data)
->2 string x \b: %s
+# GRR: Too weak
+#0 string APPL Macintosh Application (data)
+#>2 string x \b: %s
# Macintosh System files (franklsm@tuns.ca)
-0 string zsys Macintosh System File (data)
-0 string FNDR Macintosh Finder (data)
-0 string libr Macintosh Library (data)
->2 string x : %s
-0 string shlb Macintosh Shared Library (data)
->2 string x : %s
-0 string cdev Macintosh Control Panel (data)
->2 string x : %s
-0 string INIT Macintosh Extension (data)
->2 string x : %s
-0 string FFIL Macintosh Truetype Font (data)
->2 string x : %s
-0 string LWFN Macintosh Postscript Font (data)
->2 string x : %s
+# GRR: Too weak
+#0 string zsys Macintosh System File (data)
+#0 string FNDR Macintosh Finder (data)
+#0 string libr Macintosh Library (data)
+#>2 string x : %s
+#0 string shlb Macintosh Shared Library (data)
+#>2 string x : %s
+#0 string cdev Macintosh Control Panel (data)
+#>2 string x : %s
+#0 string INIT Macintosh Extension (data)
+#>2 string x : %s
+#0 string FFIL Macintosh Truetype Font (data)
+#>2 string x : %s
+#0 string LWFN Macintosh Postscript Font (data)
+#>2 string x : %s
# Additional Macintosh Files (franklsm@tuns.ca)
-0 string PACT Macintosh Compact Pro Archive (data)
->2 string x : %s
-0 string ttro Macintosh TeachText File (data)
->2 string x : %s
-0 string TEXT Macintosh TeachText File (data)
->2 string x : %s
-0 string PDF Macintosh PDF File (data)
->2 string x : %s
+# GRR: Too weak
+#0 string PACT Macintosh Compact Pro Archive (data)
+#>2 string x : %s
+#0 string ttro Macintosh TeachText File (data)
+#>2 string x : %s
+#0 string TEXT Macintosh TeachText File (data)
+#>2 string x : %s
+#0 string PDF Macintosh PDF File (data)
+#>2 string x : %s
# MacBinary format (Eric Fischer, enf@pobox.com)
#
@@ -321,41 +326,50 @@
# 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?
-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,
->>0x800 beshort 0x504D
->>>0x830 string x third type: %s,
->>>0x810 string x name: %s,
->>>0x854 belong x number of blocks: %d,
->>>0xa00 beshort 0x504D
->>>>0xa30 string x fourth type: %s,
->>>>0xa10 string x name: %s,
->>>>0xa54 belong x number of blocks: %d
-# AFAIK, only the signature is different
-0x200 beshort 0x5453 Apple Old 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,
->>0x800 beshort 0x504D
->>>0x830 string x third type: %s,
->>>0x810 string x name: %s,
->>>0x854 belong x number of blocks: %d,
->>>0xa00 beshort 0x504D
->>>>0xa30 string x fourth type: %s,
->>>>0xa10 string x name: %s,
->>>>0xa54 belong x number of blocks: %d
+# 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
+#0x200 beshort 0x5453 Apple Old 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,
+#>>0x800 beshort 0x504D
+#>>>0x830 string x third type: %s,
+#>>>0x810 string x name: %s,
+#>>>0x854 belong x number of blocks: %d,
+#>>>0xa00 beshort 0x504D
+#>>>>0xa30 string x fourth type: %s,
+#>>>>0xa10 string x name: %s,
+#>>>>0xa54 belong x number of blocks: %d
# From: Remi Mommsen <mommsen@slac.stanford.edu>
-0 string BOMStore Mac OS X bill of materials (BOM) fil
+0 string BOMStore Mac OS X bill of materials (BOM) file
diff --git a/usr.bin/file/magdir/mail.news b/usr.bin/file/magdir/mail.news
index 66b35309085..d8902728c71 100644
--- a/usr.bin/file/magdir/mail.news
+++ b/usr.bin/file/magdir/mail.news
@@ -1,4 +1,4 @@
-# $OpenBSD: mail.news,v 1.5 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: mail.news,v 1.6 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# mail.news: file(1) magic for mail and news
@@ -7,17 +7,28 @@
#0 string From mail text
# There are tests to ascmagic.c to cope with mail and news.
0 string Relay-Version: old news text
+!:mime message/rfc822
0 string #!\ rnews batched news text
+!:mime message/rfc822
0 string N#!\ rnews mailed, batched news text
+!:mime message/rfc822
0 string Forward\ to mail forwarding text
+!:mime message/rfc822
0 string Pipe\ to mail piping text
+!:mime message/rfc822
0 string Return-Path: smtp mail text
+!:mime message/rfc822
0 string Path: news text
+!:mime message/news
0 string Xref: news text
+!:mime message/news
0 string From: news or mail text
+!:mime message/rfc822
0 string Article saved news text
+!:mime message/news
0 string BABYL Emacs RMAIL text
0 string Received: RFC 822 mail text
+!:mime message/rfc822
0 string MIME-Version: MIME entity text
#0 string Content- MIME entity text
@@ -40,3 +51,5 @@
# XXX: Weak magic
#256 leshort 0xAFAE4453 Squish message area data file
#>4 leshort >0 (%d messages)
+
+#0 string \<!--\ MHonArc text/html; x-type=mhonarc
diff --git a/usr.bin/file/magdir/mathcad b/usr.bin/file/magdir/mathcad
new file mode 100644
index 00000000000..41801968888
--- /dev/null
+++ b/usr.bin/file/magdir/mathcad
@@ -0,0 +1,7 @@
+
+#------------------------------------------------------------------------------
+# mathcad: file(1) magic for Mathcad documents
+# URL: http://www.mathsoft.com/
+# From: Josh Triplett <josh@freedesktop.org>
+
+0 string .MCAD\t Mathcad document
diff --git a/usr.bin/file/magdir/mathematica b/usr.bin/file/magdir/mathematica
index 0738918d1e4..2884d4eb44e 100644
--- a/usr.bin/file/magdir/mathematica
+++ b/usr.bin/file/magdir/mathematica
@@ -1,4 +1,4 @@
-# $OpenBSD: mathematica,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: mathematica,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# mathematica: file(1) magic for mathematica files
@@ -57,7 +57,8 @@
0 string (*********************** Mathematica 3.0 notebook
# other (* matches it is a comment start in these langs
-0 string (* Mathematica, or Pascal, Modula-2 or 3 code text
+# GRR: Too weak; also matches other languages e.g. ML
+#0 string (* Mathematica, or Pascal, Modula-2 or 3 code text
#########################
# MatLab v5
diff --git a/usr.bin/file/magdir/mercurial b/usr.bin/file/magdir/mercurial
new file mode 100644
index 00000000000..3f1bdfc8f9c
--- /dev/null
+++ b/usr.bin/file/magdir/mercurial
@@ -0,0 +1,12 @@
+
+#------------------------------------------------------------------------------
+# mercurial: file(1) magic for Mercurial changeset bundles
+# http://www.selenic.com/mercurial/wiki/
+#
+# Jesse Glick (jesse.glick@sun.com)
+#
+
+0 string HG10 Mercurial changeset bundle
+>4 string UN (uncompressed)
+>4 string GZ (gzip compressed)
+>4 string BZ (bzip2 compressed)
diff --git a/usr.bin/file/magdir/misctools b/usr.bin/file/magdir/misctools
index 9715119e4cc..cfbe2753c46 100644
--- a/usr.bin/file/magdir/misctools
+++ b/usr.bin/file/magdir/misctools
@@ -1,11 +1,12 @@
-# $OpenBSD: misctools,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: misctools,v 1.3 2009/04/24 18:54:34 chl Exp $
#-----------------------------------------------------------------------------
-# misctools: file(1) magic for miscelanous UNIX tools.
+# misctools: file(1) magic for miscellaneous UNIX tools.
#
-0 string %%!! X-Post-It-Note text
+0 search/1 %%!! X-Post-It-Note text
0 string/c BEGIN:VCALENDAR vCalendar calendar file
0 string/c BEGIN:VCARD vCard visiting card
+!:mime text/x-vcard
# From: Alex Beregszaszi <alex@fsn.hu>
4 string gtktalog GNOME Catalogue (gtktalog)
diff --git a/usr.bin/file/magdir/mozilla b/usr.bin/file/magdir/mozilla
new file mode 100644
index 00000000000..069886064fb
--- /dev/null
+++ b/usr.bin/file/magdir/mozilla
@@ -0,0 +1,8 @@
+
+#------------------------------------------------------------------------------
+# mozilla: file(1) magic for Mozilla XUL fastload files
+# (XUL.mfasl and XPC.mfasl)
+# URL: http://www.mozilla.org/
+# From: Josh Triplett <josh@freedesktop.org>
+
+0 string XPCOM\nMozFASL\r\n\x1A Mozilla XUL fastload data
diff --git a/usr.bin/file/magdir/msdos b/usr.bin/file/magdir/msdos
index fe537ac4b88..2a707af65c8 100644
--- a/usr.bin/file/magdir/msdos
+++ b/usr.bin/file/magdir/msdos
@@ -1,4 +1,4 @@
-# $OpenBSD: msdos,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: msdos,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# msdos: file(1) magic for MS-DOS files
@@ -18,10 +18,6 @@
100 regex/c =^[\ \t]{0,10}call[\ \t]{1,10}rxfunc OS/2 REXX batch file text
100 regex/c =^[\ \t]{0,10}say\ ['"] OS/2 REXX batch file text
-
-100 regex/c =^\\s*call\\s+rxfuncadd.*sysloadfu OS/2 REXX batch file text
-100 regex/c =^\\s*say\ ['"] OS/2 REXX batch file text
-
0 leshort 0x14c MS Windows COFF Intel 80386 object file
#>4 ledate x stamp %s
0 leshort 0x166 MS Windows COFF MIPS R4000 object file
@@ -51,6 +47,7 @@
# many of the compressed formats were extraced from IDARC 1.23 source code
#
0 string MZ MS-DOS executable
+!:mime application/x-dosexec
>0 string MZ\0\0\0\0\0\0\0\0\0\0PE\0\0 \b, PE for MS Windows
>>&18 leshort&0x2000 >0 (DLL)
>>&88 leshort 0 (unknown subsystem)
@@ -69,6 +66,11 @@
>>&18 leshort&0x1000 >0 system file
>>&0xf4 search/0x140 \x0\x40\x1\x0
>>>(&0.l+(4)) string MSCF \b, WinHKI CAB self-extracting archive
+>30 string Copyright\ 1989-1990\ PKWARE\ Inc. Self-extracting PKZIP archive
+!:mime application/zip
+# Is next line correct? One might expect "Corp." not "Copr." If it is right, add a note to that effect.
+>30 string PKLITE\ Copr. Self-extracting PKZIP archive
+!:mime application/zip
>0x18 leshort >0x3f
>>(0x3c.l) string PE\0\0 PE
@@ -220,7 +222,9 @@
>0x1e string PKLITE \b, %s compressed
>0x64 string W\ Collis\0\0 \b, Compack compressed
>0x24 string LHa's\ SFX \b, LHa self-extracting archive
+!:mime application/x-lha
>0x24 string LHA's\ SFX \b, LHa self-extracting archive
+!:mime application/x-lha
>0x24 string \ $ARX \b, ARX self-extracting archive
>0x24 string \ $LHarc \b, LHarc self-extracting archive
>0x20 string SFX\ by\ LARC \b, LARC self-extracting archive
@@ -267,8 +271,8 @@
# Uncommenting only the first two lines will cover about 2/3 of COM files,
# but it isn't feasible to match all COM files since there must be at least
# two dozen different one-byte "magics".
-0 byte 0xe9 DOS executable (COM)
->0x1FE leshort 0xAA55 \b, boot code
+#0 byte 0xe9 DOS executable (COM)
+#>0x1FE leshort 0xAA55 \b, boot code
>6 string SFX\ of\ LHarc (%s)
0 belong 0xffffffff DOS executable (device driver)
#CMD640X2.SYS
@@ -291,15 +295,15 @@
>>77 string >\x40
>>>77 string <\x5B
>>>>77 string x \b, name: %.8s
-0 byte 0x8c DOS executable (COM)
+#0 byte 0x8c DOS executable (COM)
# 0xeb conflicts with "sequent" magic
-0 byte 0xeb DOS executable (COM)
->0x1FE leshort 0xAA55 \b, boot code
->85 string UPX \b, UPX compressed
->4 string \ $ARX \b, ARX self-extracting archive
->4 string \ $LHarc \b, LHarc self-extracting archive
->0x20e string SFX\ by\ LARC \b, LARC self-extracting archive
-0 byte 0xb8 COM executable
+#0 byte 0xeb DOS executable (COM)
+#>0x1FE leshort 0xAA55 \b, boot code
+#>85 string UPX \b, UPX compressed
+#>4 string \ $ARX \b, ARX self-extracting archive
+#>4 string \ $LHarc \b, LHarc self-extracting archive
+#>0x20e string SFX\ by\ LARC \b, LARC self-extracting archive
+#0 byte 0xb8 COM executable
# modified by Joerg Jenderek
>1 lelong !0x21cd4cff for DOS
# http://syslinux.zytor.com/comboot.php
@@ -364,38 +368,58 @@
>30 byte 12 (4kB sectors)
# Popular applications
-# False positive with PPT
-#0 string \xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF Microsoft Installer
2080 string Microsoft\ Word\ 6.0\ Document %s
+!:mime application/msword
2080 string Documento\ Microsoft\ Word\ 6 Spanish Microsoft Word 6 document data
+!:mime application/msword
# Pawel Wiecek <coven@i17linuxb.ists.pwr.wroc.pl> (for polish Word)
2112 string MSWordDoc Microsoft Word document data
+!:mime application/msword
#
0 belong 0x31be0000 Microsoft Word Document
+!:mime application/msword
#
0 string PO^Q` Microsoft Word 6.0 Document
+!:mime application/msword
#
0 string \376\067\0\043 Microsoft Office Document
+!:mime application/msword
0 string \333\245-\0\0\0 Microsoft Office Document
+!:mime application/msword
+512 string \354\245\301 Microsoft Word Document
+!:mime application/msword
#
2080 string Microsoft\ Excel\ 5.0\ Worksheet %s
+!:mime application/vnd.ms-excel
+
2080 string Foglio\ di\ lavoro\ Microsoft\ Exce %s
+!:mime application/vnd.ms-excel
#
# Pawel Wiecek <coven@i17linuxb.ists.pwr.wroc.pl> (for polish Excel)
2114 string Biff5 Microsoft Excel 5.0 Worksheet
+!:mime application/vnd.ms-excel
# Italian MS-Excel
2121 string Biff5 Microsoft Excel 5.0 Worksheet
+!:mime application/vnd.ms-excel
0 string \x09\x04\x06\x00\x00\x00\x10\x00 Microsoft Excel Worksheet
+!:mime application/vnd.ms-excel
#
0 belong 0x00001a00 Lotus 1-2-3
+!:mime application/x-123
>4 belong 0x00100400 wk3 document data
>4 belong 0x02100400 wk4 document data
>4 belong 0x07800100 fm3 or fmb document data
>4 belong 0x07800000 fm3 or fmb document data
#
0 belong 0x00000200 Lotus 1-2-3
+!:mime application/x-123
>4 belong 0x06040600 wk1 document data
>4 belong 0x06800200 fmt document data
+0 string WordPro\0 Lotus WordPro
+!:mime application/vnd.lotus-wordpro
+0 string WordPro\r\373 Lotus WordPro
+!:mime application/vnd.lotus-wordpro
+
# Help files
0 string ?_\3\0 MS Windows Help Data
@@ -449,6 +473,7 @@
# Windows icons (Ian Springer <ips@fpk.hp.com>)
0 string \000\000\001\000 MS Windows icon resource
+!:mime image/x-ico
>4 byte 1 - 1 icon
>4 byte >1 - %d icons
>>6 byte >0 \b, %dx
@@ -523,7 +548,9 @@
>>>>24 long >0 length %d
# TNEF magic From "Joomy" <joomy@se-ed.net>
+# Microsoft Outlook's Transport Neutral Encapsulation Format (TNEF)
0 leshort 0x223e9f78 TNEF
+!:mime application/vnd.ms-tnef
# HtmlHelp files (.chm)
0 string ITSF\003\000\000\000\x60\000\000\000\001\000\000\000 MS Windows HtmlHelp Data
@@ -587,17 +614,17 @@
# syntax available by some file commands you could write:
# 0 lelong 1
# &40 ulelong 0x464D4520 Windows Enhanced Metafile (EMF) image data
-40 ulelong 0x464D4520 Windows Enhanced Metafile (EMF) image data
->44 ulelong x version 0x%x.
+#40 ulelong 0x464D4520 Windows Enhanced Metafile (EMF) image data
+#>44 ulelong x version 0x%x.
# If the description has a length greater than zero, it exists and is
# found at offset (*64).
->64 ulelong >0 Description available at offset 0x%x
->>60 ulelong >0 (length 0x%x)
+#>64 ulelong >0 Description available at offset 0x%x
+#>>60 ulelong >0 (length 0x%x)
# Note it would be better to print out the description, which is found
# as below. Unfortunately the following only prints out the first couple
# of characters instead of all the "description length"
# number of characters -- indicated by the ulelong at offset 60.
->>(64.l) lestring16 >0 Description: %15.15s
+#>>(64.l) lestring16 >0 Description: %15.15s
# From: Alex Beregszaszi <alex@fsn.hu>
0 string COWD VMWare3
@@ -611,10 +638,44 @@
0 string VMDK VMware4 disk image
0 string KDMV VMware4 disk image
-0 belong 0x514649fb QEMU Copy-On-Write disk image
->4 belong x version %d,
->24 belong x size %d +
->28 belong x %d
+#--------------------------------------------------------------------
+# Qemu Emulator Images
+# Lines written by Friedrich Schwittay (f.schwittay@yousable.de)
+# Made by reading sources and doing trial and error on existing
+# qcow files
+0 string QFI Qemu Image, Format: Qcow
+
+# Uncomment the following line to display Magic (only used for debugging
+# this magic number)
+#>0 string x , Magic: %s
+
+# There are currently 2 Versions: "1" and "2"
+# I do not use Version 2 and therefor branch here
+# but can assure: it works (tested on both versions)
+# Also my Qemu 0.9.0 which uses this Version 2 refuses
+# to start in its bios
+>0x04 belong 2 , Version: 2
+>0x04 belong 1 , Version: 1
+
+# Using the existence of the Backing File Offset to Branch or not
+# to read Backing File Information
+>>0xc belong >0 , Backing File( Offset: %lu
+>>>(0xc.L) string >\0 , Path: %s
+
+# Didn't get the trick here how qemu stores the "Size" at this Position
+# There is actually something stored but nothing makes sense
+# The header in the sources talks about it
+#>>>16 lelong x , Size: %lu
+
+# Modification time of the Backing File
+# Really useful if you want to know if your backing
+# file is still usable together with this image
+>>>20 bedate x , Mtime: %s )
+
+# Don't know how to calculate in Magicfiles
+# Also: this Information is not reliably
+# stored in image-files
+>>24 lelong x , Disk Size could be: %d * 256 bytes
0 string QEVM QEMU's suspend to disk image
@@ -625,5 +686,43 @@
0 lelong 0x02468ace Bochs Sparse disk image
# from http://filext.com by Derek M Jones <derek@knosof.co.uk>
-0 string \xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF Microsoft Installer
+# False positive with PPT (also currently this string is too long)
+#0 string \xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF\x09\x00\x06 Microsoft Installer
0 string \320\317\021\340\241\261\032\341 Microsoft Office Document
+#>48 byte 0x1B Excel Document
+#!:mime application/vnd.ms-excel
+>546 string bjbj Microsoft Word Document
+!:mime application/msword
+>546 string jbjb Microsoft Word Document
+!:mime application/msword
+
+0 string \224\246\056 Microsoft Word Document
+!:mime application/msword
+
+512 string R\0o\0o\0t\0\ \0E\0n\0t\0r\0y Microsoft Word Document
+!:mime application/msword
+
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+# Magic type for Dell's BIOS .hdr files
+# Dell's .hdr
+0 string $RBU
+>23 string Dell %s system BIOS
+>48 string x version %.3s
+
+# Type: Microsoft DirectDraw Surface
+# URL: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/DDSFileReference/ddsfileformat.asp
+# From: Morten Hustveit <morten@debian.org>
+0 string DDS\040\174\000\000\000 Microsoft DirectDraw Surface (DDS),
+>16 lelong >0 %hd x
+>12 lelong >0 %hd,
+>84 string x %.4s
+
+# Type: Microsoft Document Imaging Format (.mdi)
+# URL: http://en.wikipedia.org/wiki/Microsoft_Document_Imaging_Format
+# From: Daniele Sempione <scrows@oziosi.org>
+0 short 0x5045 Microsoft Document Imaging Format
+
+# MS eBook format (.lit)
+0 string ITOLITLS Microsoft Reader eBook Data
+>8 lelong x \b, version %u
+!:mime application/x-ms-reader
diff --git a/usr.bin/file/magdir/mup b/usr.bin/file/magdir/mup
index d78242017f9..c7a1f0e0dd1 100644
--- a/usr.bin/file/magdir/mup
+++ b/usr.bin/file/magdir/mup
@@ -1,4 +1,4 @@
-# $OpenBSD: mup,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: mup,v 1.3 2009/04/24 18:54:34 chl Exp $
# ------------------------------------------------------------------------
# mup: file(1) magic for Mup (Music Publisher) input file.
@@ -10,7 +10,7 @@
# compatibility. Noteedit also use mup format, but is not forcing
# user to use any header as well.
#
-0 string //!Mup Mup music publication program input text
+0 search/1 //!Mup Mup music publication program input text
>6 string -Arkkra (Arkkra)
>>13 string -
>>>16 string .
diff --git a/usr.bin/file/magdir/netware b/usr.bin/file/magdir/netware
new file mode 100644
index 00000000000..fbc16054a32
--- /dev/null
+++ b/usr.bin/file/magdir/netware
@@ -0,0 +1,6 @@
+
+#------------------------------------------------------------------------------
+# netware: file(1) magic for NetWare Loadable Modules (NLMs)
+# From: Mads Martin Joergensen <mmj@suse.de>
+
+0 string NetWare\ Loadable\ Module NetWare Loadable Module
diff --git a/usr.bin/file/magdir/ole2compounddocs b/usr.bin/file/magdir/ole2compounddocs
new file mode 100644
index 00000000000..ee07514ec5b
--- /dev/null
+++ b/usr.bin/file/magdir/ole2compounddocs
@@ -0,0 +1,13 @@
+
+#------------------------------------------------------------------------------
+# Microsoft OLE 2 Compound Documents : file(1) magic for Microsoft Structured
+# storage (http://en.wikipedia.org/wiki/Structured_Storage)
+# Additional tests for OLE 2 Compound Documents should be under this recipe.
+
+0 string \320\317\021\340\241\261\032\341 OLE 2 Compound Document
+# - Microstation V8 DGN files (www.bentley.com)
+# Last update on 10/23/2006 by Lester Hightower
+> 0x480 string D\000g\000n\000~\000H : Microstation V8 DGN
+# - Visio documents
+# Last update on 10/23/2006 by Lester Hightower
+> 0x480 string V\000i\000s\000i\000o\000D\000o\000c : Visio Document
diff --git a/usr.bin/file/magdir/os2 b/usr.bin/file/magdir/os2
index 91506ec9394..6622bb79f9a 100644
--- a/usr.bin/file/magdir/os2
+++ b/usr.bin/file/magdir/os2
@@ -1,4 +1,4 @@
-# $OpenBSD: os2,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: os2,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# os2: file(1) magic for OS/2 files
@@ -6,8 +6,8 @@
# Provided 1998/08/22 by
# David Mediavilla <davidme.news@REMOVEIFNOTSPAMusa.net>
-1 string InternetShortcut MS Windows 95 Internet shortcut text
->24 string >\ (URL=<%s>)
+1 search/1 InternetShortcut MS Windows 95 Internet shortcut text
+>24 search/1 >\ (URL=<%s>)
# OS/2 URL objects
# Provided 1998/08/22 by
diff --git a/usr.bin/file/magdir/palm b/usr.bin/file/magdir/palm
index 1c7afb77cde..903649af96d 100644
--- a/usr.bin/file/magdir/palm
+++ b/usr.bin/file/magdir/palm
@@ -1,4 +1,4 @@
-# $OpenBSD: palm,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: palm,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# palm: file(1) magic for PalmOS {.prc,.pdb}: applications, docfiles, and hacks
@@ -46,7 +46,7 @@
>0 string >\0 "%s"
60 string SM01SMem SuperMemo PalmOS document
>0 string >\0 "%s"
-60 string DataTlPt TealDoc PalmOS document
+60 string TEXtTlDc TealDoc PalmOS document
>0 string >\0 "%s"
60 string InfoTlIf TealInfo PalmOS document
>0 string >\0 "%s"
diff --git a/usr.bin/file/magdir/pdf b/usr.bin/file/magdir/pdf
index a044c14f809..38d46e9dfed 100644
--- a/usr.bin/file/magdir/pdf
+++ b/usr.bin/file/magdir/pdf
@@ -1,9 +1,16 @@
-# $OpenBSD: pdf,v 1.3 2001/01/29 01:57:57 niklas Exp $
+# $OpenBSD: pdf,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# pdf: file(1) magic for Portable Document Format
#
0 string %PDF- PDF document
+!:mime application/pdf
>5 byte x \b, version %c
>7 byte x \b.%c
+
+# From: Nick Schmalenberger <nick@schmalenberger.us>
+# Forms Data Format
+0 string %FDF- FDF document
+>5 byte x \b, version %c
+>7 byte x \b.%c
diff --git a/usr.bin/file/magdir/perl b/usr.bin/file/magdir/perl
index 1fe81b042a4..5a9b8526f0b 100644
--- a/usr.bin/file/magdir/perl
+++ b/usr.bin/file/magdir/perl
@@ -1,27 +1,34 @@
-# $OpenBSD: perl,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: perl,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# perl: file(1) magic for Larry Wall's perl language.
#
-# The ``eval'' line recognizes an outrageously clever hack for USG systems.
+# The `eval' lines recognizes an outrageously clever hack.
# Keith Waclena <keith@cerberus.uchicago.edu>
# Send additions to <perl5-porters@perl.org>
-0 string/b #!\ /bin/perl perl script text executable
-0 string eval\ "exec\ /bin/perl perl script text
-0 string/b #!\ /usr/bin/perl perl script text executable
-0 string eval\ "exec\ /usr/bin/perl perl script text
-0 string/b #!\ /usr/local/bin/perl perl script text
-0 string eval\ "exec\ /usr/local/bin/perl perl script text executable
-0 string eval\ '(exit\ $?0)'\ &&\ eval\ 'exec perl script text
+0 search/1/b #!\ /bin/perl Perl script text executable
+!:mime application/x-perl
+0 search/1 eval\ "exec\ /bin/perl Perl script text
+!:mime application/x-perl
+0 search/1/b #!\ /usr/bin/perl Perl script text executable
+!:mime application/x-perl
+0 search/1 eval\ "exec\ /usr/bin/perl Perl script text
+!:mime application/x-perl
+0 search/1/b #!\ /usr/local/bin/perl Perl script text executable
+!:mime application/x-perl
+0 search/1 eval\ "exec\ /usr/local/bin/perl Perl script text
+!:mime application/x-perl
+0 search/1 eval\ '(exit\ $?0)'\ &&\ eval\ 'exec Perl script text
+!:mime application/x-perl
# by Dmitry V. Levin and Alexey Tourbin
# check the first line
-0 string package
->1 regex \^package[\ \t]+[A-Za-z_]
->>1 regex \^package[\ \t]+[0-9A-Za-z_:]*\ *; Perl5 module source text
+0 search/1 package
+0 regex \^package[\ \t]+[A-Za-z_]
+>0 regex \^package[\ \t]+[0-9A-Za-z_:]+\ *; Perl5 module source text
# not 'p', check other lines
-0 byte !0x70
+0 search/1 !p
>0 regex \^package[\ \t]+[0-9A-Za-z_:]+\ *;
>>0 regex \^1\ *;|\^(use|sub|my)\ .*[(;{=] Perl5 module source text
@@ -29,21 +36,21 @@
# Perl POD documents
# From: Tom Hukins <tom@eborcom.com>
-0 string/B \=pod\n Perl POD document
-0 string/B \n\=pod\n Perl POD document
-0 string/B \=head1\ Perl POD document
-0 string/B \n\=head1\ Perl POD document
-0 string/B \=head2\ Perl POD document
-0 string/B \n\=head2\ Perl POD document
+0 search/1/B \=pod\n Perl POD document text
+0 search/1/B \n\=pod\n Perl POD document text
+0 search/1/B \=head1\ Perl POD document text
+0 search/1/B \n\=head1\ Perl POD document text
+0 search/1/B \=head2\ Perl POD document text
+0 search/1/B \n\=head2\ Perl POD document text
# Perl Storable data files.
-0 string perl-store perl Storable(v0.6) data
+0 string perl-store perl Storable (v0.6) data
>4 byte >0 (net-order %d)
>>4 byte &01 (network-ordered)
>>4 byte =3 (major 1)
>>4 byte =2 (major 1)
-0 string pst0 perl Storable(v0.7) data
+0 string pst0 perl Storable (v0.7) data
>4 byte >0
>>4 byte &01 (network-ordered)
>>4 byte =5 (major 2)
diff --git a/usr.bin/file/magdir/pgp b/usr.bin/file/magdir/pgp
index e07fcdb4ced..f79b7848989 100644
--- a/usr.bin/file/magdir/pgp
+++ b/usr.bin/file/magdir/pgp
@@ -1,14 +1,27 @@
-# $OpenBSD: pgp,v 1.4 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: pgp,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# pgp: file(1) magic for Pretty Good Privacy
+# see http://lists.gnupg.org/pipermail/gnupg-devel/1999-September/016052.html
#
0 beshort 0x9900 PGP key public ring
+!:mime application/x-pgp-keyring
0 beshort 0x9501 PGP key security ring
+!:mime application/x-pgp-keyring
0 beshort 0x9500 PGP key security ring
+!:mime application/x-pgp-keyring
0 beshort 0xa600 PGP encrypted data
-0 string -----BEGIN\040PGP PGP armored data
->15 string PUBLIC\040KEY\040BLOCK- public key block
->15 string MESSAGE- message
->15 string SIGNED\040MESSAGE- signed message
->15 string PGP\040SIGNATURE- signature
+#!:mime application/pgp-encrypted
+#0 string -----BEGIN\040PGP text/PGP armored data
+!:mime text/PGP # encoding: armored data
+#>15 string PUBLIC\040KEY\040BLOCK- public key block
+#>15 string MESSAGE- message
+#>15 string SIGNED\040MESSAGE- signed message
+#>15 string PGP\040SIGNATURE- signature
+
+2 string ---BEGIN\ PGP\ PUBLIC\ KEY\ BLOCK- PGP public key block
+!:mime application/pgp-keys
+0 string -----BEGIN\040PGP\40MESSAGE- PGP message
+!:mime application/pgp
+0 string -----BEGIN\040PGP\40SIGNATURE- PGP signature
+!:mime application/pgp-signature
diff --git a/usr.bin/file/magdir/pkgadd b/usr.bin/file/magdir/pkgadd
index cd029422b70..602c5ace9f6 100644
--- a/usr.bin/file/magdir/pkgadd
+++ b/usr.bin/file/magdir/pkgadd
@@ -1,6 +1,7 @@
-# $OpenBSD: pkgadd,v 1.2 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: pkgadd,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# pkgadd: file(1) magic for SysV R4 PKG Datastreams
#
0 string #\ PaCkAgE\ DaTaStReAm pkg Datastream (SVR4)
+!:mime application/x-svr4-package
diff --git a/usr.bin/file/magdir/printer b/usr.bin/file/magdir/printer
index fb1fe62b890..6afbe4849cd 100644
--- a/usr.bin/file/magdir/printer
+++ b/usr.bin/file/magdir/printer
@@ -1,4 +1,4 @@
-# $OpenBSD: printer,v 1.6 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: printer,v 1.7 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# printer: file(1) magic for printer-formatted files
@@ -6,21 +6,26 @@
# PostScript, updated by Daniel Quinlan (quinlan@yggdrasil.com)
0 string %! PostScript document text
+!:mime application/postscript
>2 string PS-Adobe- conforming
->>11 string >\0 at level %.3s
->>>15 string EPS - type %s
->>>15 string Query - type %s
->>>15 string ExitServer - type %s
+>>11 string >\0 DSC level %.3s
+>>>15 string EPS \b, type %s
+>>>15 string Query \b, type %s
+>>>15 string ExitServer \b, type %s
+>>>15 search/1000 %%LanguageLevel:\
+>>>>&0 string >\0 \b, Level %s
# Some PCs have the annoying habit of adding a ^D as a document separator
0 string \004%! PostScript document text
+!:mime application/postscript
>3 string PS-Adobe- conforming
->>12 string >\0 at level %.3s
->>>16 string EPS - type %s
->>>16 string Query - type %s
->>>16 string ExitServer - type %s
+>>12 string >\0 DSC level %.3s
+>>>16 string EPS \b, type %s
+>>>16 string Query \b, type %s
+>>>16 string ExitServer \b, type %s
+>>>16 search/1000 %%LanguageLevel:\
+>>>>&0 string >\0 \b, Level %s
0 string \033%-12345X%!PS PostScript document
-
# DOS EPS Binary File Header
# From: Ed Sznyter <ews@Black.Market.NET>
0 belong 0xC5D0D3C6 DOS EPS Binary File
diff --git a/usr.bin/file/magdir/revision b/usr.bin/file/magdir/revision
index 9ce0073cb41..0134cfc3d8a 100644
--- a/usr.bin/file/magdir/revision
+++ b/usr.bin/file/magdir/revision
@@ -1,4 +1,4 @@
-# $OpenBSD: revision,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: revision,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# file(1) magic for revision control files
@@ -8,3 +8,13 @@
# Conary changesets
# From: Jonathan Smith <smithj@rpath.com>
0 belong 0xea3f81bb Conary changeset data
+
+# Type: Git bundles (git-bundle)
+# From: Josh Triplett <josh@freedesktop.org>
+0 string #\ v2\ git\ bundle\n Git bundle
+
+# Type: Mercurial bundles
+# From: Seo Sanghyeon <tinuviel@sparcs.kaist.ac.kr>
+0 string HG10 Mercurial bundle,
+>4 string UN uncompressed
+>4 string BZ bzip2 compressed
diff --git a/usr.bin/file/magdir/riff b/usr.bin/file/magdir/riff
index 8eca0e3a3e2..2aa2b3f07b7 100644
--- a/usr.bin/file/magdir/riff
+++ b/usr.bin/file/magdir/riff
@@ -1,4 +1,4 @@
-# $OpenBSD: riff,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: riff,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# riff: file(1) magic for RIFF format
@@ -34,6 +34,7 @@
>8 string RMP3 \b, MPEG Layer 3 audio
# Microsoft WAVE format (*.wav)
>8 string WAVE \b, WAVE audio
+!:mime audio/x-wav
>>20 leshort 1 \b, Microsoft PCM
>>>34 leshort >0 \b, %d bit
>>20 leshort 2 \b, Microsoft ADPCM
@@ -51,8 +52,10 @@
>>24 lelong >0 %d Hz
# Corel Draw Picture
>8 string CDRA \b, Corel Draw Picture
+!:mime image/x-coreldraw
# AVI == Audio Video Interleave
>8 string AVI\040 \b, AVI
+!:mime video/x-msvideo
>>12 string LIST
>>>20 string hdrlavih
>>>>&36 lelong x \b, %lu x
@@ -131,6 +134,7 @@
>>>>>>>(104.l+132) string/c divx DivX 4
>>>>>>>(104.l+132) string/c dx50 DivX 5
>>>>>>>(104.l+132) string/c xvid XviD
+>>>>>>>(104.l+132) string/c h264 H.264
>>>>>>>(104.l+132) string/c wmv3 Windows Media Video 9
>>>>>>>(104.l+132) string/c h264 X.264
>>>>>>>(104.l+132) lelong 0
diff --git a/usr.bin/file/magdir/rpm b/usr.bin/file/magdir/rpm
index eb87b23ea48..e8583cf457b 100644
--- a/usr.bin/file/magdir/rpm
+++ b/usr.bin/file/magdir/rpm
@@ -1,4 +1,4 @@
-# $OpenBSD: rpm,v 1.5 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: rpm,v 1.6 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
#
@@ -6,6 +6,7 @@
#
0 beshort 0xedab
>2 beshort 0xeedb RPM
+!:mime application/x-rpm
>>4 byte x v%d
>>6 beshort 0 bin
>>6 beshort 1 src
@@ -15,7 +16,7 @@
>>8 beshort 4 MIPS
>>8 beshort 5 PowerPC
>>8 beshort 6 68000
->>8 beshort 7 SGI
+>>8 beshort 7 SGI
>>8 beshort 8 RS6000
>>8 beshort 9 IA64
>>8 beshort 10 Sparc64
diff --git a/usr.bin/file/magdir/rtf b/usr.bin/file/magdir/rtf
index d4c4014cea3..2c9ed84502f 100644
--- a/usr.bin/file/magdir/rtf
+++ b/usr.bin/file/magdir/rtf
@@ -1,4 +1,4 @@
-# $OpenBSD: rtf,v 1.3 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: rtf,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# rtf: file(1) magic for Rich Text Format (RTF)
@@ -6,8 +6,11 @@
# Duncan P. Simpson, D.P.Simpson@dcs.warwick.ac.uk
#
0 string {\\rtf Rich Text Format data,
->5 byte x version %c,
->6 string \\ansi ANSI
->6 string \\mac Apple Macintosh
->6 string \\pc IBM PC, code page 437
->6 string \\pca IBM PS/2, code page 850
+!:mime text/rtf
+>5 string 1 version 1,
+>>6 string \\ansi ANSI
+>>6 string \\mac Apple Macintosh
+>>6 string \\pc IBM PC, code page 437
+>>6 string \\pca IBM PS/2, code page 850
+>>6 default x unknown character set
+>5 default x unknown version
diff --git a/usr.bin/file/magdir/sc b/usr.bin/file/magdir/sc
index 23b0f710a7c..25c2c44ae3a 100644
--- a/usr.bin/file/magdir/sc
+++ b/usr.bin/file/magdir/sc
@@ -1,6 +1,7 @@
-# $OpenBSD: sc,v 1.2 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: sc,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# sc: file(1) magic for "sc" spreadsheet
#
38 string Spreadsheet sc spreadsheet file
+!:mime application/x-sc
diff --git a/usr.bin/file/magdir/scientific b/usr.bin/file/magdir/scientific
index fdf9f54799c..9571b47ebae 100644
--- a/usr.bin/file/magdir/scientific
+++ b/usr.bin/file/magdir/scientific
@@ -1,4 +1,4 @@
-# $OpenBSD: scientific,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: scientific,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# scientific: file(1) magic for scientific formats
@@ -59,3 +59,15 @@
>1104 ulong >0 %d x
>1108 ulong >0 %d,
>1120 ulong >0 %d bits/pixel
+
+# Type: GEDCOM genealogical (family history) data
+# From: Giuseppe Bilotta
+0 search/1/c 0\ HEAD GEDCOM genealogy text
+>&0 search 1\ GEDC
+>>&0 search 2\ VERS version
+>>>&1 search/1 >\0 %s
+# From: Phil Endecott <phil05@chezphil.org>
+0 string \000\060\000\040\000\110\000\105\000\101\000\104 GEDCOM data
+0 string \060\000\040\000\110\000\105\000\101\000\104\000 GEDCOM data
+0 string \376\377\000\060\000\040\000\110\000\105\000\101\000\104 GEDCOM data
+0 string \377\376\060\000\040\000\110\000\105\000\101\000\104\000 GEDCOM data
diff --git a/usr.bin/file/magdir/securitycerts b/usr.bin/file/magdir/securitycerts
new file mode 100644
index 00000000000..aa55d2188fc
--- /dev/null
+++ b/usr.bin/file/magdir/securitycerts
@@ -0,0 +1,3 @@
+0 search/1 -----BEGIN\ CERTIFICATE------ RFC1421 Security Certificate text
+0 search/1 -----BEGIN\ NEW\ CERTIFICATE RFC1421 Security Certificate Signing Request text
+0 belong 0xedfeedfe Sun 'jks' Java Keystore File data
diff --git a/usr.bin/file/magdir/sgi b/usr.bin/file/magdir/sgi
index dddb9f08fbd..fa6a1edd32c 100644
--- a/usr.bin/file/magdir/sgi
+++ b/usr.bin/file/magdir/sgi
@@ -1,4 +1,4 @@
-# $OpenBSD: sgi,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: sgi,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# sgi: file(1) magic for Silicon Graphics applications
@@ -9,26 +9,37 @@
0 string PmNs PCP compiled namespace (V.0)
0 string PmN PCP compiled namespace
>3 string >\0 (V.%1.1s)
-3 lelong 0x84500526 PCP archive
+#3 lelong 0x84500526 PCP archive
+3 belong 0x84500526 PCP archive
>7 byte x (V.%d)
->20 lelong -2 temporal index
->20 lelong -1 metadata
->20 lelong 0 log volume #0
->20 lelong >0 log volume #%ld
+#>20 lelong -2 temporal index
+#>20 lelong -1 metadata
+#>20 lelong 0 log volume #0
+#>20 lelong >0 log volume #%ld
+>20 belong -2 temporal index
+>20 belong -1 metadata
+>20 belong 0 log volume #0
+>20 belong >0 log volume #%ld
>24 string >\0 host: %s
-0 string PCPFolio PCP
+0 string PCPFolio PCP
>9 string Version: Archive Folio
>18 string >\0 (V.%s)
0 string #pmchart PCP pmchart view
>9 string Version
>17 string >\0 (V%-3.3s)
+0 string #kmchart PCP kmchart view
+>9 string Version
+>17 string >\0 (V.%s)
0 string pmview PCP pmview config
>7 string Version
>15 string >\0 (V%-3.3s)
0 string #pmlogger PCP pmlogger config
>10 string Version
>18 string >\0 (V%1.1s)
-0 string PcPh PCP Help
+0 string #pmdahotproc PCP pmdahotproc config
+>13 string Version
+>21 string >\0 (V%-3.3s)
+0 string PcPh PCP Help
>4 string 1 Index
>4 string 2 Text
>5 string >\0 (V.%1.1s)
diff --git a/usr.bin/file/magdir/sgml b/usr.bin/file/magdir/sgml
index 0a891744bfe..60e9870fd6c 100644
--- a/usr.bin/file/magdir/sgml
+++ b/usr.bin/file/magdir/sgml
@@ -1,36 +1,50 @@
-# $OpenBSD: sgml,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: sgml,v 1.5 2009/04/24 18:54:34 chl Exp $
+
+#------------------------------------------------------------------------------
+# Type: SVG Vectorial Graphics
+# From: Noel Torres <tecnico@ejerciciosresueltos.com>
+0 string \<?xml\ version="
+>15 string >\0
+>>23 search/400 \<svg SVG Scalable Vector Graphics image
+!:mime image/svg+xml
+>>23 search/400 \<gnc-v2 GnuCash file
+!:mime application/x-gnucash
#------------------------------------------------------------------------------
# sgml: file(1) magic for Standard Generalized Markup Language
# HyperText Markup Language (HTML) is an SGML document type,
# from Daniel Quinlan (quinlan@yggdrasil.com)
# adapted to string extenstions by Anthon van der Neut <anthon@mnt.org)
-0 string/cB \<!DOCTYPE\ html HTML document text
-0 string/cb \<head HTML document text
-0 string/cb \<title HTML document text
-0 string/cb \<html HTML document text
+0 search/1/cB \<!DOCTYPE\ html HTML document text
+!:mime text/html
+0 search/1/cb \<head HTML document text
+!:mime text/html
+0 search/1/cb \<title HTML document text
+!:mime text/html
+0 search/1/cb \<html HTML document text
+!:mime text/html
# Extensible markup language (XML), a subset of SGML
# from Marc Prud'hommeaux (marc@apocalypse.org)
-0 string/cb \<?xml XML document text
+0 search/1/cb \<?xml XML document text
0 string \<?xml\ version\ " XML
0 string \<?xml\ version=" XML
0 string \<?xml\ version=' XML
->15 string >\0 %.3s document text
->>23 string \<xsl:stylesheet (XSL stylesheet)
->>24 string \<xsl:stylesheet (XSL stylesheet)
-0 string/b \<?xml XML document text
-0 string/cb \<?xml broken XML document text
+>15 search/1 >\0 %.3s document text
+>>23 search/1 \<xsl:stylesheet (XSL stylesheet)
+>>24 search/1 \<xsl:stylesheet (XSL stylesheet)
+0 search/1/b \<?xml XML document text
+0 search/1/b \<?XML broken XML document text
# SGML, mostly from rph@sq
-0 string/cb \<!doctype exported SGML document text
-0 string/cb \<!subdoc exported SGML subdocument text
-0 string/cb \<!-- exported SGML document text
+0 search/1/cb \<!doctype exported SGML document text
+0 search/1/cb \<!subdoc exported SGML subdocument text
+0 search/1/cb \<!-- exported SGML document text
# Web browser cookie files
# (Mozilla, Galeon, Netscape 4, Konqueror..)
# Ulf Harnhammar <ulfh@update.uu.se>
-0 string #\ HTTP\ Cookie\ File Web browser cookie text
-0 string #\ Netscape\ HTTP\ Cookie\ File Netscape cookie text
-0 string #\ KDE\ Cookie\ File Konqueror cookie text
+0 search/1 #\ HTTP\ Cookie\ File Web browser cookie text
+0 search/1 #\ Netscape\ HTTP\ Cookie\ File Netscape cookie text
+0 search/1 #\ KDE\ Cookie\ File Konqueror cookie text
diff --git a/usr.bin/file/magdir/sharc b/usr.bin/file/magdir/sharc
index 6ac4b61a9d6..efb736d0682 100644
--- a/usr.bin/file/magdir/sharc
+++ b/usr.bin/file/magdir/sharc
@@ -1,4 +1,4 @@
-# $OpenBSD: sharc,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: sharc,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------
# file(1) magic for sharc files
@@ -7,14 +7,14 @@
# FutureGroove Music (dsp@futuregroove.de)
#------------------------------------------------------------------------
-0 string Draw RiscOS Drawfile
-0 string PACK RiscOS PackdDir archive
+#0 string Draw RiscOS Drawfile
+#0 string PACK RiscOS PackdDir archive
#------------------------------------------------------------------------
# SHARC DSP stuff (based on the FGM SHARC DSP SDK)
-0 string =! Assembler source
-0 string Analog ADi asm listing file
+#0 string =! Assembler source
+#0 string Analog ADi asm listing file
0 string .SYSTEM SHARC architecture file
0 string .system SHARC architecture file
diff --git a/usr.bin/file/magdir/sketch b/usr.bin/file/magdir/sketch
index 6addb7fa046..5d08adab003 100644
--- a/usr.bin/file/magdir/sketch
+++ b/usr.bin/file/magdir/sketch
@@ -1,6 +1,6 @@
-# $OpenBSD: sketch,v 1.1 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: sketch,v 1.2 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# Sketch Drawings: http://sketch.sourceforge.net/
# From: Edwin Mons <e@ik.nu>
-0 string ##Sketch Sketch document text
+0 search/1 ##Sketch Sketch document text
diff --git a/usr.bin/file/magdir/softquad b/usr.bin/file/magdir/softquad
index 76e0b31a1e5..75dd69b786b 100644
--- a/usr.bin/file/magdir/softquad
+++ b/usr.bin/file/magdir/softquad
@@ -1,4 +1,4 @@
-# $OpenBSD: softquad,v 1.4 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: softquad,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# softquad: file(1) magic for SoftQuad Publishing Software
@@ -20,7 +20,7 @@
0 short 0125252 SoftQuad DESC or font file binary
>2 short >0 - version %d
# Bitmaps...
-0 string SQ\ BITMAP1 SoftQuad Raster Format text
+0 search/1 SQ\ BITMAP1 SoftQuad Raster Format text
#0 string SQ\ BITMAP2 SoftQuad Raster Format data
# sqtroff intermediate language (replacement for ditroff int. lang.)
0 string X\ SoftQuad troff Context intermediate
@@ -28,3 +28,10 @@
>2 string hp for Hewlett-Packard LaserJet
>2 string impr for IMAGEN imPRESS
>2 string ps for PostScript
+
+# From: Michael Piefel <piefel@debian.org>
+# sqtroff intermediate language (replacement for ditroff int. lang.)
+0 string X\ 495 SoftQuad troff Context intermediate for AT&T 495 laser printer
+0 string X\ hp SoftQuad troff Context intermediate for HP LaserJet
+0 string X\ impr SoftQuad troff Context intermediate for IMAGEN imPRESS
+0 string X\ ps SoftQuad troff Context intermediate for PostScript
diff --git a/usr.bin/file/magdir/spectrum b/usr.bin/file/magdir/spectrum
index 1b27ca24c43..7fcf867ffc4 100644
--- a/usr.bin/file/magdir/spectrum
+++ b/usr.bin/file/magdir/spectrum
@@ -1,4 +1,4 @@
-# $OpenBSD: spectrum,v 1.1 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: spectrum,v 1.2 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# spectrum: file(1) magic for Spectrum emulator files.
@@ -32,14 +32,19 @@
# TZX tape images
0 string ZXTape!\x1a Spectrum .TZX data
>8 byte x version %d
->9 byte x .%d
+>9 byte x \b.%d
# RZX input recording files
0 string RZX! Spectrum .RZX data
>4 byte x version %d
->5 byte x .%d
+>5 byte x \b.%d
-# And three sorts of disk image
+# Floppy disk images
0 string MV\ -\ CPCEMU\ Disk-Fil Amstrad/Spectrum .DSK data
0 string MV\ -\ CPC\ format\ Dis Amstrad/Spectrum DU54 .DSK data
0 string EXTENDED\ CPC\ DSK\ Fil Amstrad/Spectrum Extended .DSK data
+0 string SINCLAIR Spectrum .SCL Betadisk image
+
+# Hard disk images
+0 string RS-IDE\x1a Spectrum .HDF hard disk image
+>7 byte x \b, version 0x%02x
diff --git a/usr.bin/file/magdir/tex b/usr.bin/file/magdir/tex
index 1a0633d48ba..c77deddc6f3 100644
--- a/usr.bin/file/magdir/tex
+++ b/usr.bin/file/magdir/tex
@@ -1,47 +1,63 @@
-# $OpenBSD: tex,v 1.4 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: tex,v 1.5 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# tex: file(1) magic for TeX files
#
+# XXX - needs byte-endian stuff (big-endian and little-endian DVI?)
+#
# From <conklin@talisman.kaleida.com>
# Although we may know the offset of certain text fields in TeX DVI
# and font files, we can't use them reliably because they are not
# zero terminated. [but we do anyway, christos]
0 string \367\002 TeX DVI file
+!:mime application/x-dvi
>16 string >\0 (%s)
0 string \367\203 TeX generic font data
0 string \367\131 TeX packed font data
>3 string >\0 (%s)
0 string \367\312 TeX virtual font data
-0 string This\ is\ TeX, TeX transcript text
-0 string This\ is\ METAFONT, METAFONT transcript text
+0 search/1 This\ is\ TeX, TeX transcript text
+0 search/1 This\ is\ METAFONT, METAFONT transcript text
# There is no way to detect TeX Font Metric (*.tfm) files without
# breaking them apart and reading the data. The following patterns
# match most *.tfm files generated by METAFONT or afm2tfm.
2 string \000\021 TeX font metric data
+!:mime application/x-tex-tfm
>33 string >\0 (%s)
2 string \000\022 TeX font metric data
+!:mime application/x-tex-tfm
>33 string >\0 (%s)
# Texinfo and GNU Info, from Daniel Quinlan (quinlan@yggdrasil.com)
-0 string \\input\ texinfo Texinfo source text
-0 string This\ is\ Info\ file GNU Info text
+0 search/1 \\input\ texinfo Texinfo source text
+!:mime text/x-texinfo
+0 search/1 This\ is\ Info\ file GNU Info text
+!:mime text/x-info
# TeX documents, from Daniel Quinlan (quinlan@yggdrasil.com)
0 search/400 \\input TeX document text
+!:mime text/x-tex
0 search/400 \\section LaTeX document text
+!:mime text/x-tex
0 search/400 \\setlength LaTeX document text
+!:mime text/x-tex
0 search/400 \\documentstyle LaTeX document text
+!:mime text/x-tex
0 search/400 \\chapter LaTeX document text
+!:mime text/x-tex
0 search/400 \\documentclass LaTeX 2e document text
+!:mime text/x-tex
0 search/400 \\relax LaTeX auxiliary file
+!:mime text/x-tex
0 search/400 \\contentsline LaTeX table of contents
+!:mime text/x-tex
0 search/400 %\ -*-latex-*- LaTeX document text
+!:mime text/x-tex
# Tex document, from Hendrik Scholz <hendrik@scholz.net>
-0 string \\ifx TeX document text
+0 search/1 \\ifx TeX document text
# Index and glossary files
0 search/400 \\indexentry LaTeX raw index file
@@ -56,25 +72,24 @@
# file(1) magic for BibTex text files
# From Hendrik Scholz <hendrik@scholz.net>
-0 string/c @article{ BibTeX text file
-0 string/c @book{ BibTeX text file
-0 string/c @inbook{ BibTeX text file
-0 string/c @incollection{ BibTeX text file
-0 string/c @inproceedings{ BibTeX text file
-0 string/c @manual{ BibTeX text file
-0 string/c @misc{ BibTeX text file
-0 string/c @preamble{ BibTeX text file
-0 string/c @phdthesis{ BibTeX text file
-0 string/c @techreport{ BibTeX text file
-0 string/c @unpublished{ BibTeX text file
-
-73 string %%%\ \ BibTeX-file{ BibTex text file (with full header)
+0 search/1/c @article{ BibTeX text file
+0 search/1/c @book{ BibTeX text file
+0 search/1/c @inbook{ BibTeX text file
+0 search/1/c @incollection{ BibTeX text file
+0 search/1/c @inproceedings{ BibTeX text file
+0 search/1/c @manual{ BibTeX text file
+0 search/1/c @misc{ BibTeX text file
+0 search/1/c @preamble{ BibTeX text file
+0 search/1/c @phdthesis{ BibTeX text file
+0 search/1/c @techreport{ BibTeX text file
+0 search/1/c @unpublished{ BibTeX text file
-73 string %%%\ \ @BibTeX-style-file{ BibTeX style text file (with full header)
+73 search/1 %%%\ \ BibTeX-file{ BibTex text file (with full header)
-0 string %\ BibTeX\ standard\ bibliography\ BibTeX standard bibliography style text file
+73 search/1 %%%\ \ @BibTeX-style-file{ BibTeX style text file (with full header)
-0 string %\ BibTeX\ ` BibTeX custom bibliography style text file
+0 search/1 %\ BibTeX\ standard\ bibliography\ BibTeX standard bibliography style text file
-0 string @c\ @mapfile{ TeX font aliases text file
+0 search/1 %\ BibTeX\ ` BibTeX custom bibliography style text file
+0 search/1 @c\ @mapfile{ TeX font aliases text file
diff --git a/usr.bin/file/magdir/troff b/usr.bin/file/magdir/troff
index 9f6a87c874b..9fd3f5a423c 100644
--- a/usr.bin/file/magdir/troff
+++ b/usr.bin/file/magdir/troff
@@ -1,4 +1,4 @@
-# $OpenBSD: troff,v 1.3 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: troff,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# troff: file(1) magic for *roff
@@ -6,24 +6,29 @@
# updated by Daniel Quinlan (quinlan@yggdrasil.com)
# troff input
-0 string .\\" troff or preprocessor input text
-0 string '\\" troff or preprocessor input text
-0 string '.\\" troff or preprocessor input text
-0 string \\" troff or preprocessor input text
-0 string ''' troff or preprocessor input text
+0 search/1 .\\" troff or preprocessor input text
+!:mime text/troff
+0 search/1 '\\" troff or preprocessor input text
+!:mime text/troff
+0 search/1 '.\\" troff or preprocessor input text
+!:mime text/troff
+0 search/1 \\" troff or preprocessor input text
+!:mime text/troff
+0 search/1 ''' troff or preprocessor input text
+!:mime text/troff
# ditroff intermediate output text
-0 string x\ T ditroff output text
->4 string cat for the C/A/T phototypesetter
->4 string ps for PostScript
->4 string dvi for DVI
->4 string ascii for ASCII
->4 string lj4 for LaserJet 4
->4 string latin1 for ISO 8859-1 (Latin 1)
->4 string X75 for xditview at 75dpi
->>7 string -12 (12pt)
->4 string X100 for xditview at 100dpi
->>8 string -12 (12pt)
+0 search/1 x\ T ditroff output text
+>4 search/1 cat for the C/A/T phototypesetter
+>4 search/1 ps for PostScript
+>4 search/1 dvi for DVI
+>4 search/1 ascii for ASCII
+>4 search/1 lj4 for LaserJet 4
+>4 search/1 latin1 for ISO 8859-1 (Latin 1)
+>4 search/1 X75 for xditview at 75dpi
+>>7 search/1 -12 (12pt)
+>4 search/1 X100 for xditview at 100dpi
+>>8 search/1 -12 (12pt)
# output data formats
0 string \100\357 very old (C/A/T) troff output data
diff --git a/usr.bin/file/magdir/unicode b/usr.bin/file/magdir/unicode
index 184fa7fe5a8..a00ebcdce08 100644
--- a/usr.bin/file/magdir/unicode
+++ b/usr.bin/file/magdir/unicode
@@ -1,16 +1,16 @@
-# $OpenBSD: unicode,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: unicode,v 1.3 2009/04/24 18:54:34 chl Exp $
#---------------------------------------------------------------------------
# Unicode: BOM prefixed text files - Adrian Havill <havill@turbolinux.co.jp>
+# GRR: These types should be recognised in file_ascmagic so these
+# encodings can be treated by text patterns.
+# Missing types are already dealt with internally.
#
0 string +/v8 Unicode text, UTF-7
0 string +/v9 Unicode text, UTF-7
0 string +/v+ Unicode text, UTF-7
0 string +/v/ Unicode text, UTF-7
-0 string \357\273\277 Unicode text, UTF-8
0 string \335\163\146\163 Unicode text, UTF-8-EBCDIC
0 string \376\377\000\000 Unicode text, UTF-32, big-endian
0 string \377\376\000\000 Unicode text, UTF-32, little-endian
-0 string \376\377 Unicode text, UTF-16, big-endian
-0 string \377\376 Unicode text, UTF-16, little-endian
0 string \016\376\377 Unicode text, SCSU (Standard Compression Scheme for Unicode)
diff --git a/usr.bin/file/magdir/uuencode b/usr.bin/file/magdir/uuencode
index aab736b5ce7..a1aa0f4d5cf 100644
--- a/usr.bin/file/magdir/uuencode
+++ b/usr.bin/file/magdir/uuencode
@@ -1,4 +1,4 @@
-# $OpenBSD: uuencode,v 1.3 2004/06/03 03:14:20 tedu Exp $
+# $OpenBSD: uuencode,v 1.4 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# uuencode: file(1) magic for ASCII-encoded files
@@ -10,22 +10,22 @@
# punctuation and survives BITNET gateways better.) If regular expressions
# were supported, this entry could possibly be split into two with
# "begin\040\.\*\012M" or "begin\040\.\*\012h" (where \. and \* are REs).
-0 string begin\040 uuencoded or xxencoded text
+0 search/1 begin\ uuencoded or xxencoded text
# btoa(1) is an alternative to uuencode that requires less space.
-0 string xbtoa\ Begin btoa'd text
+0 search/1 xbtoa\ Begin btoa'd text
# ship(1) is another, much cooler alternative to uuencode.
# Greg Roelofs, newt@uchicago.edu
-0 string $\012ship ship'd binary text
+0 search/1 $\012ship ship'd binary text
# bencode(8) is used to encode compressed news batches (Bnews/Cnews only?)
# Greg Roelofs, newt@uchicago.edu
-0 string Decode\ the\ following\ with\ bdeco bencoded News text
+0 search/1 Decode\ the\ following\ with\ bdeco bencoded News text
# BinHex is the Macintosh ASCII-encoded file format (see also "apple")
# Daniel Quinlan, quinlan@yggdrasil.com
-11 string must\ be\ converted\ with\ BinHex BinHex binary text
->41 string x \b, version %.3s
+11 search/1 must\ be\ converted\ with\ BinHex BinHex binary text
+>41 search/1 x \b, version %.3s
-# GRR: is MIME BASE64 encoding handled somewhere?
+# GRR: handle BASE64
diff --git a/usr.bin/file/magdir/varied.script b/usr.bin/file/magdir/varied.script
index 3e2ada75e1c..c00f72b70e6 100644
--- a/usr.bin/file/magdir/varied.script
+++ b/usr.bin/file/magdir/varied.script
@@ -1,4 +1,4 @@
-# $OpenBSD: varied.script,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: varied.script,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# varied.script: file(1) magic for various interpreter scripts
@@ -12,3 +12,9 @@
0 string #!\ script text executable
>3 string >\0 for %s
+# From: arno <arenevier@fdn.fr>
+# mozilla xpconnect typelib
+# see http://www.mozilla.org/scriptable/typelib_file.html
+0 string XPCOM\nTypeLib\r\n\032 XPConnect Typelib
+>0x10 byte x version %d
+>>0x11 byte x \b.%d
diff --git a/usr.bin/file/magdir/vorbis b/usr.bin/file/magdir/vorbis
index b7b6d47ceac..b2537643919 100644
--- a/usr.bin/file/magdir/vorbis
+++ b/usr.bin/file/magdir/vorbis
@@ -1,4 +1,4 @@
-# $OpenBSD: vorbis,v 1.2 2008/05/08 01:40:57 chl Exp $
+# $OpenBSD: vorbis,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# vorbis: file(1) magic for Ogg/Vorbis files
@@ -12,16 +12,38 @@
# probable things advanced users would want to uncomment are probably
# the number of comments and the encoder version.
#
+# FIXME: The first match has been made a search, so that it can skip
+# over prepended ID3 tags. This will work for MIME type detection, but
+# won't work for detecting other properties of the file (they all need
+# to be made relative to the search). In any case, if the file has ID3
+# tags, the ID3 information will be printed, not the Ogg information,
+# so until that's fixed, this doesn't matter.
+#
# --- Ogg Framing ---
-0 string OggS Ogg data
+0 search/1000 OggS Ogg data
+!:mime application/ogg
>4 byte !0 UNKNOWN REVISION %u
##>4 byte 0 revision 0
>4 byte 0
##>>14 lelong x (Serial %lX)
# non-Vorbis content: FLAC (Free Lossless Audio Codec, http://flac.sourceforge.net)
->>28 string fLaC \b, FLAC audio
+>>28 string \x7fFLAC \b, FLAC audio
# non-Vorbis content: Theora
>>28 string \x80theora \b, Theora video
+# non-Vorbis content: Kate
+>>28 string \x80kate\0\0\0\0 \b, Kate
+>>>37 ubyte x v%u
+>>>38 ubyte x \b.%u,
+>>>40 byte 0 utf8 encoding,
+>>>40 byte !0 unknown character encoding,
+>>>60 string >\0 language %s,
+>>>60 string \0 no language set,
+>>>76 string >\0 category %s
+>>>76 string \0 no category set
+# non-Vorbis content: Skeleton
+>>28 string fishead\0 \b, Skeleton
+>>>36 short x v%u
+>>>40 short x \b.%u
# non-Vorbis content: Speex
>>28 string Speex\ \ \ \b, Speex audio
# non-Vorbis content: OGM
diff --git a/usr.bin/file/magdir/wordprocessors b/usr.bin/file/magdir/wordprocessors
index e25af223a5c..f0afe538da7 100644
--- a/usr.bin/file/magdir/wordprocessors
+++ b/usr.bin/file/magdir/wordprocessors
@@ -1,4 +1,4 @@
-# $OpenBSD: wordprocessors,v 1.2 2008/05/14 20:45:35 chl Exp $
+# $OpenBSD: wordprocessors,v 1.3 2009/04/24 18:54:34 chl Exp $
#------------------------------------------------------------------------------
# wordprocessors: file(1) magic fo word processors.
@@ -13,7 +13,7 @@
>26 byte 0x46 \b, A4
#WordPerfect type files Version 1.6 - PLEASE DO NOT REMOVE THIS LINE
-0 string \377WPC\020\000\000\000\022\012\001\001\000\000\000\000 (WP) loadable text
+0 string \377WPC\020\000\000\000\022\012\001\001\000\000\000\000 (WP) loadable file
>15 byte 0 Optimized for Intel
>15 byte 1 Optimized for Non-Intel
1 string WPC (Corel/WP)
@@ -108,6 +108,7 @@
0 string HWP\ Document\ File Hangul (Korean) Word Processor File 3.0
# From: Won-Kyu Park <wkpark@kldp.org>
512 string R\0o\0o\0t\0 Hangul (Korean) Word Processor File 2000
+!:mime application/x-hwp
# CosmicBook, from Benoît Rouits
0 string CSBK Ted Neslson's CosmicBook hypertext file
@@ -123,15 +124,29 @@
2 string IIXPR3 Intel Quark Express Document (English)
2 string IIXPRa Intel Quark Express Document (Korean)
2 string MMXPR3 Motorola Quark Express Document (English)
+!:mime application/x-quark-xpress-3
2 string MMXPRa Motorola Quark Express Document (Korean)
# adobe indesign (document, whatever...) from querkan
0 belong 0x0606edf5 Adobe InDesign
>16 string DOCUMENT Document
-# From: Michael Piefel <piefel@debian.org>
-# sqtroff intermediate language (replacement for ditroff int. lang.)
-0 string X\ 495 SoftQuad troff Context intermediate for AT&T 495 laser printer
-0 string X\ hp SoftQuad troff Context intermediate for HP LaserJet
-0 string X\ impr SoftQuad troff Context intermediate for IMAGEN imPRESS
-0 string X\ ps SoftQuad troff Context intermediate for PostScript
+#------------------------------------------------------------------------------
+# ichitaro456: file(1) magic for Just System Word Processor Ichitaro
+#
+# Contributor kenzo-:
+# Reversed-engineered JS Ichitaro magic numbers
+#
+
+0 string DOC
+>43 byte 0x14 Just System Word Processor Ichitaro v4
+!:mime application/x-ichitaro4
+>144 string JDASH application/x-ichitaro4
+
+0 string DOC
+>43 byte 0x15 Just System Word Processor Ichitaro v5
+!:mime application/x-ichitaro5
+
+0 string DOC
+>43 byte 0x16 Just System Word Processor Ichitaro v6
+!:mime application/x-ichitaro6
diff --git a/usr.bin/file/magdir/xilinx b/usr.bin/file/magdir/xilinx
new file mode 100644
index 00000000000..8f411ce21dd
--- /dev/null
+++ b/usr.bin/file/magdir/xilinx
@@ -0,0 +1,34 @@
+
+#------------------------------------------------------------------------------
+# This is Aaron's attempt at a MAGIC file for Xilinx .bit files.
+# Xilinx-Magic@RevRagnarok.com
+# Got the info from FPGA-FAQ 0026
+#
+# First there is the sync header and its length
+0 beshort 0x0009
+>2 belong =0x0ff00ff0
+>>&0 belong =0x0ff00ff0
+>>>&0 beshort =0x0000
+>>>>&0 pstring a Xilinx BIT data
+# Next is a Pascal-style string with the NCD name. We want to capture that.
+>>>>0x0F pstring x - from %s
+# It is followed by a NUL
+>>>>>&1 byte 0x00
+# And then 'b'
+>>>>>&2 string b
+# With the part number:
+#>>>>>&5 string 4v (Virtex4)
+#>>>>>&5 string 2v (Virtex II
+#>>>>>>&0 string !p \b)
+#>>>>>>&0 string p Pro)
+>>>>>&4 pstring x - for %s
+# And then NUL / 'c' / Build Data / NUL / 'd' / Date / NUL / 'e' / Data Length
+>>>>>>&1 byte 0x00
+>>>>>>&2 string c
+>>>>>>&4 pstring x - built %s
+>>>>>>>&1 byte 0x00
+>>>>>>>&2 string d
+>>>>>>>&4 pstring x \b(%s)
+>>>>>>>>&1 byte 0x00
+>>>>>>>>&2 string e
+>>>>>>>>&4 belong x - data length 0x%lx
diff --git a/usr.bin/file/magic.c b/usr.bin/file/magic.c
index a09b987a182..e28186a9639 100644
--- a/usr.bin/file/magic.c
+++ b/usr.bin/file/magic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: magic.c,v 1.5 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: magic.c,v 1.6 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
@@ -64,9 +64,18 @@
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: magic.c,v 1.5 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: magic.c,v 1.6 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
+#ifndef PIPE_BUF
+/* Get the PIPE_BUF from pathconf */
+#ifdef _PC_PIPE_BUF
+#define PIPE_BUF pathconf(".", _PC_PIPE_BUF)
+#else
+#define PIPE_BUF 512
+#endif
+#endif
+
#ifdef __EMX__
private char *apptypeName = NULL;
protected int file_os2_apptype(struct magic_set *ms, const char *fn,
@@ -77,6 +86,9 @@ private void free_mlist(struct mlist *);
private void close_and_restore(const struct magic_set *, const char *, int,
const struct stat *);
private int info_from_stat(struct magic_set *, mode_t);
+#ifndef COMPILE_ONLY
+private const char *file_or_fd(struct magic_set *, const char *, int);
+#endif
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
@@ -92,20 +104,14 @@ magic_open(int flags)
if (magic_setflags(ms, flags) == -1) {
errno = EINVAL;
- goto free1;
+ goto free;
}
- ms->o.ptr = ms->o.buf = malloc(ms->o.left = ms->o.size = 1024);
- if (ms->o.buf == NULL)
- goto free1;
-
- ms->o.pbuf = malloc(ms->o.psize = 1024);
- if (ms->o.pbuf == NULL)
- goto free2;
+ ms->o.buf = ms->o.pbuf = NULL;
ms->c.li = malloc((ms->c.len = 10) * sizeof(*ms->c.li));
if (ms->c.li == NULL)
- goto free3;
+ goto free;
ms->haderr = 0;
ms->error = -1;
@@ -113,11 +119,7 @@ magic_open(int flags)
ms->file = "unknown";
ms->line = 0;
return ms;
-free3:
- free(ms->o.pbuf);
-free2:
- free(ms->o.buf);
-free1:
+free:
free(ms);
return NULL;
}
@@ -216,6 +218,7 @@ close_and_restore(const struct magic_set *ms, const char *name, int fd,
*/
#ifdef HAVE_UTIMES
struct timeval utsbuf[2];
+ (void)memset(utsbuf, 0, sizeof(utsbuf));
utsbuf[0].tv_sec = sb->st_atime;
utsbuf[1].tv_sec = sb->st_mtime;
@@ -223,6 +226,7 @@ close_and_restore(const struct magic_set *ms, const char *name, int fd,
#elif defined(HAVE_UTIME_H) || defined(HAVE_SYS_UTIME_H)
struct utimbuf utbuf;
+ (void)memset(utbuf, 0, sizeof(utbuf));
utbuf.actime = sb->st_atime;
utbuf.modtime = sb->st_mtime;
(void) utime(name, &utbuf); /* don't care if loses */
@@ -231,13 +235,28 @@ close_and_restore(const struct magic_set *ms, const char *name, int fd,
}
#ifndef COMPILE_ONLY
+
+/*
+ * find type of descriptor
+ */
+public const char *
+magic_descriptor(struct magic_set *ms, int fd)
+{
+ return file_or_fd(ms, NULL, fd);
+}
+
/*
* find type of named file
*/
public const char *
magic_file(struct magic_set *ms, const char *inname)
{
- int fd = 0;
+ return file_or_fd(ms, inname, STDIN_FILENO);
+}
+
+private const char *
+file_or_fd(struct magic_set *ms, const char *inname, int fd)
+{
int rv = -1;
unsigned char *buf;
struct stat sb;
@@ -266,7 +285,6 @@ magic_file(struct magic_set *ms, const char *inname)
}
if (inname == NULL) {
- fd = STDIN_FILENO;
if (fstat(fd, &sb) == 0 && S_ISFIFO(sb.st_mode))
ispipe = 1;
} else {
@@ -280,16 +298,18 @@ magic_file(struct magic_set *ms, const char *inname)
errno = 0;
if ((fd = open(inname, flags)) < 0) {
#ifdef __CYGWIN__
- char *tmp = alloca(strlen(inname) + 5);
- (void)strcat(strcpy(tmp, inname), ".exe");
- if ((fd = open(tmp, flags)) < 0) {
+ /* FIXME: Do this with EXEEXT from autotools */
+ char *tmp = alloca(strlen(inname) + 5);
+ (void)strcat(strcpy(tmp, inname), ".exe");
+ if ((fd = open(tmp, flags)) < 0) {
#endif
- if (info_from_stat(ms, sb.st_mode) == -1)
- goto done;
- rv = 0;
- goto done;
+ fprintf(stderr, "couldn't open file\n");
+ if (info_from_stat(ms, sb.st_mode) == -1)
+ goto done;
+ rv = 0;
+ goto done;
#ifdef __CYGWIN__
- }
+ }
#endif
}
#ifdef O_NONBLOCK
@@ -327,18 +347,9 @@ magic_file(struct magic_set *ms, const char *inname)
}
}
- if (nbytes == 0) {
- if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
- "application/x-empty" : "empty") == -1)
- goto done;
- } else if (nbytes == 1) {
- if (file_printf(ms, "very short file (no magic)") == -1)
- goto done;
- } else {
- (void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */
- if (file_buffer(ms, fd, inname, buf, (size_t)nbytes) == -1)
- goto done;
- }
+ (void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */
+ if (file_buffer(ms, fd, inname, buf, (size_t)nbytes) == -1)
+ goto done;
rv = 0;
done:
free(buf);
diff --git a/usr.bin/file/magic.h b/usr.bin/file/magic.h
index 1731bffbcb6..03d0b1b0d6c 100644
--- a/usr.bin/file/magic.h
+++ b/usr.bin/file/magic.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: magic.h,v 1.3 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: magic.h,v 1.4 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
@@ -35,21 +35,26 @@
#define MAGIC_SYMLINK 0x000002 /* Follow symlinks */
#define MAGIC_COMPRESS 0x000004 /* Check inside compressed files */
#define MAGIC_DEVICES 0x000008 /* Look at the contents of devices */
-#define MAGIC_MIME 0x000010 /* Return a mime string */
+#define MAGIC_MIME_TYPE 0x000010 /* Return only the MIME type */
#define MAGIC_CONTINUE 0x000020 /* Return all matches */
#define MAGIC_CHECK 0x000040 /* Print warnings to stderr */
#define MAGIC_PRESERVE_ATIME 0x000080 /* Restore access time on exit */
-#define MAGIC_RAW 0x000100 /* Don't translate unprintable chars */
+#define MAGIC_RAW 0x000100 /* Don't translate unprint chars */
#define MAGIC_ERROR 0x000200 /* Handle ENOENT etc as real errors */
-#define MAGIC_NO_CHECK_COMPRESS 0x001000 /* Don't check for compressed files */
-#define MAGIC_NO_CHECK_TAR 0x002000 /* Don't check for tar files */
-#define MAGIC_NO_CHECK_SOFT 0x004000 /* Don't check magic entries */
-#define MAGIC_NO_CHECK_APPTYPE 0x008000 /* Don't check application type */
-#define MAGIC_NO_CHECK_ELF 0x010000 /* Don't check for elf details */
-#define MAGIC_NO_CHECK_ASCII 0x020000 /* Don't check for ascii files */
-#define MAGIC_NO_CHECK_TROFF 0x040000 /* Don't check ascii/troff */
-#define MAGIC_NO_CHECK_FORTRAN 0x080000 /* Don't check ascii/fortran */
-#define MAGIC_NO_CHECK_TOKENS 0x100000 /* Don't check ascii/tokens */
+#define MAGIC_MIME_ENCODING 0x000400 /* Return only the MIME encoding */
+#define MAGIC_MIME (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
+#define MAGIC_NO_CHECK_COMPRESS 0x001000 /* Don't check for compressed files */
+#define MAGIC_NO_CHECK_TAR 0x002000 /* Don't check for tar files */
+#define MAGIC_NO_CHECK_SOFT 0x004000 /* Don't check magic entries */
+#define MAGIC_NO_CHECK_APPTYPE 0x008000 /* Don't check application type */
+#define MAGIC_NO_CHECK_ELF 0x010000 /* Don't check for elf details */
+#define MAGIC_NO_CHECK_ASCII 0x020000 /* Don't check for ascii files */
+#define MAGIC_NO_CHECK_TOKENS 0x100000 /* Don't check ascii/tokens */
+
+/* Defined for backwards compatibility; do nothing */
+#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */
+#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */
+
#ifdef __cplusplus
extern "C" {
@@ -60,6 +65,7 @@ magic_t magic_open(int);
void magic_close(magic_t);
const char *magic_file(magic_t, const char *);
+const char *magic_descriptor(magic_t, int);
const char *magic_buffer(magic_t, const void *, size_t);
const char *magic_error(magic_t);
diff --git a/usr.bin/file/names.h b/usr.bin/file/names.h
index afc018d0c41..ef5fdf86d98 100644
--- a/usr.bin/file/names.h
+++ b/usr.bin/file/names.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: names.h,v 1.7 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: names.h,v 1.8 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -33,7 +33,7 @@
* appear at fixed offsets into the file. Don't make HOWMANY
* too high unless you have a very fast CPU.
*
- * $Id: names.h,v 1.7 2008/05/08 01:40:56 chl Exp $
+ * $Id: names.h,v 1.8 2009/04/24 18:54:34 chl Exp $
*/
/*
@@ -44,27 +44,25 @@
/* these types are used to index the table 'types': keep em in sync! */
#define L_C 0 /* first and foremost on UNIX */
#define L_CC 1 /* Bjarne's postincrement */
-#define L_FORT 2 /* the oldest one */
-#define L_MAKE 3 /* Makefiles */
-#define L_PLI 4 /* PL/1 */
-#define L_MACH 5 /* some kinda assembler */
-#define L_ENG 6 /* English */
-#define L_PAS 7 /* Pascal */
-#define L_MAIL 8 /* Electronic mail */
-#define L_NEWS 9 /* Usenet Netnews */
-#define L_JAVA 10 /* Java code */
-#define L_HTML 11 /* HTML */
-#define L_BCPL 12 /* BCPL */
-#define L_M4 13 /* M4 */
-#define L_PO 14 /* PO */
+#define L_MAKE 2 /* Makefiles */
+#define L_PLI 3 /* PL/1 */
+#define L_MACH 4 /* some kinda assembler */
+#define L_ENG 5 /* English */
+#define L_PAS 6 /* Pascal */
+#define L_MAIL 7 /* Electronic mail */
+#define L_NEWS 8 /* Usenet Netnews */
+#define L_JAVA 9 /* Java code */
+#define L_HTML 10 /* HTML */
+#define L_BCPL 11 /* BCPL */
+#define L_M4 12 /* M4 */
+#define L_PO 13 /* PO */
static const struct {
- const char *human;
- const char *mime;
+ char human[48];
+ char mime[16];
} types[] = {
{ "C program", "text/x-c", },
{ "C++ program", "text/x-c++" },
- { "FORTRAN program", "text/x-fortran" },
{ "make commands", "text/x-makefile" },
{ "PL/1 program", "text/x-pl1" },
{ "assembler program", "text/x-asm" },
@@ -77,8 +75,7 @@ static const struct {
{ "BCPL program", "text/x-bcpl" },
{ "M4 macro language pre-processor", "text/x-m4" },
{ "PO (gettext message catalogue)", "text/x-po" },
- { "cannot happen error on names.h/types", "error/x-error" },
- { 0, 0}
+ { "cannot happen error on names.h/types", "error/x-error" }
};
/*
@@ -117,8 +114,8 @@ static const struct {
* as Java, as it comes after "the" and "The". Perhaps we need a fancier
* heuristic to identify Java?
*/
-static struct names {
- const char *name;
+static const struct names {
+ char name[14];
short type;
} names[] = {
/* These must be sorted by eye for optimal hit rate */
@@ -148,18 +145,6 @@ static struct names {
{"LDFLAGS", L_MAKE},
{"all:", L_MAKE},
{".PRECIOUS", L_MAKE},
-/* Too many files of text have these words in them. Find another way
- * to recognize Fortrash.
- */
-#ifdef NOTDEF
- {"subroutine", L_FORT},
- {"function", L_FORT},
- {"block", L_FORT},
- {"common", L_FORT},
- {"dimension", L_FORT},
- {"integer", L_FORT},
- {"data", L_FORT},
-#endif /*NOTDEF*/
{".ascii", L_MACH},
{".asciiz", L_MACH},
{".byte", L_MACH},
@@ -184,6 +169,6 @@ static struct names {
{"<BODY", L_HTML},
{"<html", L_HTML},
{"<HTML", L_HTML},
- {NULL, 0}
+ {"<!--", L_HTML},
};
-#define NNAMES ((sizeof(names)/sizeof(struct names)) - 1)
+#define NNAMES (sizeof(names)/sizeof(struct names))
diff --git a/usr.bin/file/patchlevel.h b/usr.bin/file/patchlevel.h
index 103cde05235..4e540831195 100644
--- a/usr.bin/file/patchlevel.h
+++ b/usr.bin/file/patchlevel.h
@@ -1,19 +1,33 @@
-/* $OpenBSD: patchlevel.h,v 1.8 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: patchlevel.h,v 1.9 2009/04/24 18:54:34 chl Exp $ */
#define FILE_VERSION_MAJOR 4
-#define patchlevel 21
+#define patchlevel 24
/*
* Patchlevel file for Ian Darwin's MAGIC command.
- * $File: patchlevel.h,v 1.65 2007/05/24 17:22:27 christos Exp $
+ * $File: patchlevel.h,v 1.68 2008/03/22 21:39:43 christos Exp $
*
* $Log: patchlevel.h,v $
- * Revision 1.8 2008/05/08 01:40:56 chl
- * Update file to 4.21.
+ * Revision 1.9 2009/04/24 18:54:34 chl
+ * file update to 4.24
*
- * tested by ian@ sthen@
+ * The '-i' switch is now enabled so file(1) can output mime type strings.
*
- * OK ian@, "move ahead with it" deraadt@
+ * ok ian@
+ * builk ports build test on amd64 by jasper@
+ *
+ * ok ray@ gilles@ on a almost identical diff
+ * builk ports build test on sparc64 on this almost identical diff by ajacoutot@
+ * also tested by landry@
+ *
+ * Revision 1.68 2008/03/22 21:39:43 christos
+ * file 4.24
+ *
+ * Revision 1.67 2007/12/28 20:08:40 christos
+ * welcome to 4.23.
+ *
+ * Revision 1.66 2007/12/27 16:38:24 christos
+ * welcome to 4.22
*
* Revision 1.65 2007/05/24 17:22:27 christos
* Welcome to 4.21
diff --git a/usr.bin/file/print.c b/usr.bin/file/print.c
index 438aaa00712..32dee304645 100644
--- a/usr.bin/file/print.c
+++ b/usr.bin/file/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.14 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: print.c,v 1.15 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -42,7 +42,7 @@
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.14 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.15 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -90,8 +90,8 @@ file_mdump(struct magic *m)
if (m->str_flags & REGEX_OFFSET_START)
(void) fputc(CHAR_REGEX_OFFSET_START, stderr);
}
- if (m->str_count)
- (void) fprintf(stderr, "/%u", m->str_count);
+ if (m->str_range)
+ (void) fprintf(stderr, "/%u", m->str_range);
}
else {
if ((m->mask_op & FILE_OPS_MASK) < SZOF(optyp))
@@ -158,6 +158,16 @@ file_mdump(struct magic *m)
(void)fprintf(stderr, "%s,",
file_fmttime((uint32_t)m->value.q, 0));
break;
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
+ (void) fprintf(stderr, "%G", m->value.f);
+ break;
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
+ (void) fprintf(stderr, "%G", m->value.d);
+ break;
case FILE_DEFAULT:
/* XXX - do anything here? */
break;
@@ -175,13 +185,15 @@ protected void
file_magwarn(struct magic_set *ms, const char *f, ...)
{
va_list va;
- va_start(va, f);
/* cuz we use stdout for most, stderr here */
(void) fflush(stdout);
- (void) fprintf(stderr, "%s, %lu: Warning ", ms->file,
- (unsigned long)ms->line);
+ if (ms->file)
+ (void) fprintf(stderr, "%s, %lu: ", ms->file,
+ (unsigned long)ms->line);
+ (void) fprintf(stderr, "Warning: ");
+ va_start(va, f);
(void) vfprintf(stderr, f, va);
va_end(va);
(void) fputc('\n', stderr);
diff --git a/usr.bin/file/readelf.c b/usr.bin/file/readelf.c
index da2d53ad4b5..e41f217ec51 100644
--- a/usr.bin/file/readelf.c
+++ b/usr.bin/file/readelf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readelf.c,v 1.9 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: readelf.c,v 1.10 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
@@ -36,9 +36,10 @@
#endif
#include "readelf.h"
+#include "magic.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: readelf.c,v 1.9 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: readelf.c,v 1.10 2009/04/24 18:54:34 chl Exp $")
#endif
#ifdef ELFCORE
@@ -124,84 +125,106 @@ getu64(int swap, uint64_t value)
return value;
}
+#define elf_getu16(swap, value) getu16(swap, value)
+#define elf_getu32(swap, value) getu32(swap, value)
#ifdef USE_ARRAY_FOR_64BIT_TYPES
# define elf_getu64(swap, array) \
- ((swap ? ((uint64_t)getu32(swap, array[0])) << 32 : getu32(swap, array[0])) + \
- (swap ? getu32(swap, array[1]) : ((uint64_t)getu32(swap, array[1]) << 32)))
+ ((swap ? ((uint64_t)elf_getu32(swap, array[0])) << 32 : elf_getu32(swap, array[0])) + \
+ (swap ? elf_getu32(swap, array[1]) : ((uint64_t)elf_getu32(swap, array[1]) << 32)))
#else
# define elf_getu64(swap, value) getu64(swap, value)
#endif
-#define xsh_addr (class == ELFCLASS32 \
- ? (void *) &sh32 \
+#define xsh_addr (class == ELFCLASS32 \
+ ? (void *) &sh32 \
: (void *) &sh64)
-#define xsh_sizeof (class == ELFCLASS32 \
- ? sizeof sh32 \
+#define xsh_sizeof (class == ELFCLASS32 \
+ ? sizeof sh32 \
: sizeof sh64)
-#define xsh_size (class == ELFCLASS32 \
- ? getu32(swap, sh32.sh_size) \
- : getu64(swap, sh64.sh_size))
-#define xsh_offset (class == ELFCLASS32 \
- ? getu32(swap, sh32.sh_offset) \
- : getu64(swap, sh64.sh_offset))
-#define xsh_type (class == ELFCLASS32 \
- ? getu32(swap, sh32.sh_type) \
- : getu32(swap, sh64.sh_type))
-#define xph_addr (class == ELFCLASS32 \
- ? (void *) &ph32 \
+#define xsh_size (class == ELFCLASS32 \
+ ? elf_getu32(swap, sh32.sh_size) \
+ : elf_getu64(swap, sh64.sh_size))
+#define xsh_offset (class == ELFCLASS32 \
+ ? elf_getu32(swap, sh32.sh_offset) \
+ : elf_getu64(swap, sh64.sh_offset))
+#define xsh_type (class == ELFCLASS32 \
+ ? elf_getu32(swap, sh32.sh_type) \
+ : elf_getu32(swap, sh64.sh_type))
+#define xph_addr (class == ELFCLASS32 \
+ ? (void *) &ph32 \
: (void *) &ph64)
-#define xph_sizeof (class == ELFCLASS32 \
- ? sizeof ph32 \
+#define xph_sizeof (class == ELFCLASS32 \
+ ? sizeof ph32 \
: sizeof ph64)
-#define xph_type (class == ELFCLASS32 \
- ? getu32(swap, ph32.p_type) \
- : getu32(swap, ph64.p_type))
-#define xph_offset (off_t)(class == ELFCLASS32 \
- ? getu32(swap, ph32.p_offset) \
- : getu64(swap, ph64.p_offset))
-#define xph_align (size_t)((class == ELFCLASS32 \
- ? (off_t) (ph32.p_align ? \
- getu32(swap, ph32.p_align) : 4) \
- : (off_t) (ph64.p_align ? \
- getu64(swap, ph64.p_align) : 4)))
-#define xph_filesz (size_t)((class == ELFCLASS32 \
- ? getu32(swap, ph32.p_filesz) \
- : getu64(swap, ph64.p_filesz)))
-#define xnh_addr (class == ELFCLASS32 \
- ? (void *) &nh32 \
+#define xph_type (class == ELFCLASS32 \
+ ? elf_getu32(swap, ph32.p_type) \
+ : elf_getu32(swap, ph64.p_type))
+#define xph_offset (off_t)(class == ELFCLASS32 \
+ ? elf_getu32(swap, ph32.p_offset) \
+ : elf_getu64(swap, ph64.p_offset))
+#define xph_align (size_t)((class == ELFCLASS32 \
+ ? (off_t) (ph32.p_align ? \
+ elf_getu32(swap, ph32.p_align) : 4) \
+ : (off_t) (ph64.p_align ? \
+ elf_getu64(swap, ph64.p_align) : 4)))
+#define xph_filesz (size_t)((class == ELFCLASS32 \
+ ? elf_getu32(swap, ph32.p_filesz) \
+ : elf_getu64(swap, ph64.p_filesz)))
+#define xnh_addr (class == ELFCLASS32 \
+ ? (void *) &nh32 \
: (void *) &nh64)
-#define xph_memsz (size_t)((class == ELFCLASS32 \
- ? getu32(swap, ph32.p_memsz) \
- : getu64(swap, ph64.p_memsz)))
-#define xnh_sizeof (class == ELFCLASS32 \
- ? sizeof nh32 \
+#define xph_memsz (size_t)((class == ELFCLASS32 \
+ ? elf_getu32(swap, ph32.p_memsz) \
+ : elf_getu64(swap, ph64.p_memsz)))
+#define xnh_sizeof (class == ELFCLASS32 \
+ ? sizeof nh32 \
: sizeof nh64)
-#define xnh_type (class == ELFCLASS32 \
- ? getu32(swap, nh32.n_type) \
- : getu32(swap, nh64.n_type))
-#define xnh_namesz (class == ELFCLASS32 \
- ? getu32(swap, nh32.n_namesz) \
- : getu32(swap, nh64.n_namesz))
-#define xnh_descsz (class == ELFCLASS32 \
- ? getu32(swap, nh32.n_descsz) \
- : getu32(swap, nh64.n_descsz))
-#define prpsoffsets(i) (class == ELFCLASS32 \
- ? prpsoffsets32[i] \
+#define xnh_type (class == ELFCLASS32 \
+ ? elf_getu32(swap, nh32.n_type) \
+ : elf_getu32(swap, nh64.n_type))
+#define xnh_namesz (class == ELFCLASS32 \
+ ? elf_getu32(swap, nh32.n_namesz) \
+ : elf_getu32(swap, nh64.n_namesz))
+#define xnh_descsz (class == ELFCLASS32 \
+ ? elf_getu32(swap, nh32.n_descsz) \
+ : elf_getu32(swap, nh64.n_descsz))
+#define prpsoffsets(i) (class == ELFCLASS32 \
+ ? prpsoffsets32[i] \
: prpsoffsets64[i])
#ifdef ELFCORE
-size_t prpsoffsets32[] = {
- 8, /* FreeBSD */
+/*
+ * Try larger offsets first to avoid false matches
+ * from earlier data that happen to look like strings.
+ */
+static const size_t prpsoffsets32[] = {
+#ifdef USE_NT_PSINFO
+ 104, /* SunOS 5.x (command line) */
+ 88, /* SunOS 5.x (short name) */
+#endif /* USE_NT_PSINFO */
+
+ 100, /* SunOS 5.x (command line) */
+ 84, /* SunOS 5.x (short name) */
+
+ 44, /* Linux (command line) */
28, /* Linux 2.0.36 (short name) */
- 44, /* Linux (path name) */
- 84, /* SunOS 5.x */
+
+ 8, /* FreeBSD */
};
-size_t prpsoffsets64[] = {
- 16, /* FreeBSD, 64-bit */
+static const size_t prpsoffsets64[] = {
+#ifdef USE_NT_PSINFO
+ 152, /* SunOS 5.x (command line) */
+ 136, /* SunOS 5.x (short name) */
+#endif /* USE_NT_PSINFO */
+
+ 136, /* SunOS 5.x, 64-bit (command line) */
+ 120, /* SunOS 5.x, 64-bit (short name) */
+
+ 56, /* Linux (command line) */
40, /* Linux (tested on core from 2.4.x, short name) */
- 56, /* Linux (path name) */
- 120, /* SunOS 5.x, 64-bit */
+
+ 16, /* FreeBSD, 64-bit */
};
#define NOFFSETS32 (sizeof prpsoffsets32 / sizeof prpsoffsets32[0])
@@ -221,6 +244,14 @@ size_t prpsoffsets64[] = {
* SVR4-flavored systems, and Linux) containing the start of the
* command line for that program.
*
+ * SunOS 5.x core files contain two PT_NOTE sections, with the types
+ * NT_PRPSINFO (old) and NT_PSINFO (new). These structs contain the
+ * same info about the command name and command line, so it probably
+ * isn't worthwhile to look for NT_PSINFO, but the offsets are provided
+ * above (see USE_NT_PSINFO), in case we ever decide to do so. The
+ * NT_PRPSINFO and NT_PSINFO sections are always in order and adjacent;
+ * the SunOS 5.x file command relies on this (and prefers the latter).
+ *
* The signal number probably appears in a section of type NT_PRSTATUS,
* but that's also rather OS-dependent, in ways that are harder to
* dissect with heuristics, so I'm not bothering with the signal number.
@@ -234,7 +265,7 @@ size_t prpsoffsets64[] = {
#define OS_STYLE_FREEBSD 1
#define OS_STYLE_NETBSD 2
-private const char *os_style_names[] = {
+private const char os_style_names[][8] = {
"SVR4",
"FreeBSD",
"NetBSD",
@@ -242,6 +273,7 @@ private const char *os_style_names[] = {
#define FLAGS_DID_CORE 1
#define FLAGS_DID_NOTE 2
+#define FLAGS_DID_CORE_STYLE 4
private int
dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
@@ -384,7 +416,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
if (file_printf(ms, ", for GNU/") == -1)
return size;
- switch (getu32(swap, desc[0])) {
+ switch (elf_getu32(swap, desc[0])) {
case GNU_OS_LINUX:
if (file_printf(ms, "Linux") == -1)
return size;
@@ -397,12 +429,20 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
if (file_printf(ms, "Solaris") == -1)
return size;
break;
+ case GNU_OS_KFREEBSD:
+ if (file_printf(ms, "kFreeBSD") == -1)
+ return size;
+ break;
+ case GNU_OS_KNETBSD:
+ if (file_printf(ms, "kNetBSD") == -1)
+ return size;
+ break;
default:
if (file_printf(ms, "<unknown>") == -1)
return size;
}
- if (file_printf(ms, " %d.%d.%d", getu32(swap, desc[1]),
- getu32(swap, desc[2]), getu32(swap, desc[3])) == -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;
@@ -412,7 +452,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
xnh_type == NT_NETBSD_VERSION && descsz == 4) {
uint32_t desc;
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
- desc = getu32(swap, desc);
+ desc = elf_getu32(swap, desc);
if (file_printf(ms, ", for NetBSD") == -1)
return size;
@@ -458,7 +498,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
xnh_type == NT_FREEBSD_VERSION && descsz == 4) {
uint32_t desc;
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
- desc = getu32(swap, desc);
+ desc = elf_getu32(swap, desc);
if (file_printf(ms, ", for FreeBSD") == -1)
return size;
@@ -547,7 +587,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
if (file_printf(ms, ", for DragonFly") == -1)
return size;
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
- desc = getu32(swap, desc);
+ desc = elf_getu32(swap, desc);
if (file_printf(ms, " %d.%d.%d", desc / 100000,
desc / 10000 % 10, desc % 10000) == -1)
return size;
@@ -588,10 +628,11 @@ core:
if ((*flags & FLAGS_DID_CORE) != 0)
return size;
- if (os_style != -1) {
+ if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) {
if (file_printf(ms, ", %s-style", os_style_names[os_style])
== -1)
return size;
+ *flags |= FLAGS_DID_CORE_STYLE;
}
switch (os_style) {
@@ -614,8 +655,9 @@ core:
(void)memcpy(&signo, &nbuf[doff + 0x08],
sizeof(signo));
if (file_printf(ms, " (signal %u)",
- getu32(swap, signo)) == -1)
+ elf_getu32(swap, signo)) == -1)
return size;
+ *flags |= FLAGS_DID_CORE;
return size;
}
break;
@@ -635,6 +677,7 @@ core:
* reject it.
*/
for (i = 0; i < NOFFSETS; i++) {
+ unsigned char *cname, *cp;
size_t reloffset = prpsoffsets(i);
size_t noffset = doff + reloffset;
for (j = 0; j < 16; j++, noffset++,
@@ -682,9 +725,20 @@ core:
/*
* Well, that worked.
*/
- if (file_printf(ms, ", from '%.16s'",
- &nbuf[doff + prpsoffsets(i)]) == -1)
+ cname = (unsigned char *)
+ &nbuf[doff + prpsoffsets(i)];
+ for (cp = cname; *cp && isprint(*cp); cp++)
+ continue;
+ /*
+ * Linux apparently appends a space at the end
+ * of the command line: remove it.
+ */
+ while (cp > cname && isspace(cp[-1]))
+ cp--;
+ if (file_printf(ms, ", from '%.*s'",
+ (int)(cp - cname), cname) == -1)
return size;
+ *flags |= FLAGS_DID_CORE;
return size;
tryanother:
@@ -694,7 +748,6 @@ core:
break;
}
#endif
- *flags |= FLAGS_DID_CORE;
return offset;
}
@@ -805,7 +858,7 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
if (size != xph_sizeof) {
if (file_printf(ms, ", corrupted program header size") == -1)
- return -1;
+ return -1;
return 0;
}
@@ -885,6 +938,8 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
return -1;
}
break;
+ default:
+ break;
}
}
if (file_printf(ms, ", %s linked%s", linking_style, shared_libraries)
@@ -907,112 +962,55 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
struct stat st;
off_t fsize;
int flags = 0;
+ Elf32_Ehdr elf32hdr;
+ Elf64_Ehdr elf64hdr;
+ uint16_t type;
- /*
- * If we cannot seek, it must be a pipe, socket or fifo.
- */
- if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
- fd = file_pipe2file(ms, fd, buf, nbytes);
-
- if (fstat(fd, &st) == -1) {
- file_badread(ms);
- return -1;
- }
- fsize = st.st_size;
-
+ if (ms->flags & MAGIC_MIME)
+ return 0;
/*
* ELF executables have multiple section headers in arbitrary
* file locations and thus file(1) cannot determine it from easily.
* Instead we traverse thru all section headers until a symbol table
* one is found or else the binary is stripped.
+ * Return immediately if it's not ELF (so we avoid pipe2file unless needed).
*/
if (buf[EI_MAG0] != ELFMAG0
|| (buf[EI_MAG1] != ELFMAG1 && buf[EI_MAG1] != OLFMAG1)
|| buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
- return 0;
-
-
- class = buf[EI_CLASS];
-
- if (class == ELFCLASS32) {
- Elf32_Ehdr elfhdr;
- if (nbytes <= sizeof (Elf32_Ehdr))
- return 0;
-
+ return 0;
- u.l = 1;
- (void) memcpy(&elfhdr, buf, sizeof elfhdr);
- swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
+ /*
+ * If we cannot seek, it must be a pipe, socket or fifo.
+ */
+ if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
+ fd = file_pipe2file(ms, fd, buf, nbytes);
- if (getu16(swap, elfhdr.e_type) == ET_CORE) {
-#ifdef ELFCORE
- if (dophn_core(ms, class, swap, fd,
- (off_t)getu32(swap, elfhdr.e_phoff),
- getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize),
- fsize, &flags) == -1)
- return -1;
-#else
- ;
-#endif
- } else {
- if (getu16(swap, elfhdr.e_type) == ET_EXEC) {
- if (dophn_exec(ms, class, swap,
- fd, (off_t)getu32(swap, elfhdr.e_phoff),
- getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize),
- fsize, &flags)
- == -1)
- return -1;
- }
- if (doshn(ms, class, swap, fd,
- (off_t)getu32(swap, elfhdr.e_shoff),
- getu16(swap, elfhdr.e_shnum),
- (size_t)getu16(swap, elfhdr.e_shentsize),
- &flags) == -1)
- return -1;
- }
- return 1;
+ if (fstat(fd, &st) == -1) {
+ file_badread(ms);
+ return -1;
}
+ fsize = st.st_size;
- if (class == ELFCLASS64) {
- Elf64_Ehdr elfhdr;
- if (nbytes <= sizeof (Elf64_Ehdr))
- return 0;
-
-
- u.l = 1;
- (void) memcpy(&elfhdr, buf, sizeof elfhdr);
- swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
+ class = buf[EI_CLASS];
- if (getu16(swap, elfhdr.e_type) == ET_CORE) {
-#ifdef ELFCORE
- if (dophn_core(ms, class, swap, fd,
- (off_t)elf_getu64(swap, elfhdr.e_phoff),
- getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize),
- fsize, &flags) == -1)
- return -1;
-#else
- ;
-#endif
- } else {
- if (getu16(swap, elfhdr.e_type) == ET_EXEC) {
- if (dophn_exec(ms, class, swap, fd,
- (off_t)elf_getu64(swap, elfhdr.e_phoff),
- getu16(swap, elfhdr.e_phnum),
- (size_t)getu16(swap, elfhdr.e_phentsize),
- fsize, &flags) == -1)
- return -1;
- }
- if (doshn(ms, class, swap, fd,
- (off_t)elf_getu64(swap, elfhdr.e_shoff),
- getu16(swap, elfhdr.e_shnum),
- (size_t)getu16(swap, elfhdr.e_shentsize), &flags)
- == -1)
- return -1;
- }
- return 1;
+ switch (class) {
+ case ELFCLASS32:
+#undef elf_getu
+#define elf_getu(a, b) elf_getu32(a, b)
+#undef elfhdr
+#define elfhdr elf32hdr
+#include "elfclass.h"
+ case ELFCLASS64:
+#undef elf_getu
+#define elf_getu(a, b) elf_getu64(a, b)
+#undef elfhdr
+#define elfhdr elf64hdr
+#include "elfclass.h"
+ default:
+ if (file_printf(ms, ", unknown class %d", class) == -1)
+ return -1;
+ break;
}
return 0;
}
diff --git a/usr.bin/file/readelf.h b/usr.bin/file/readelf.h
index 1ffab5a97a7..6d5bc30158f 100644
--- a/usr.bin/file/readelf.h
+++ b/usr.bin/file/readelf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: readelf.h,v 1.6 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: readelf.h,v 1.7 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
@@ -45,7 +45,7 @@ typedef uint16_t Elf32_Half;
typedef uint32_t Elf32_Word;
typedef uint8_t Elf32_Char;
-#if SIZEOF_UINT64_T != 8
+#if SIZEOF_LONG_LONG != 8
#define USE_ARRAY_FOR_64BIT_TYPES
typedef uint32_t Elf64_Addr[2];
typedef uint32_t Elf64_Off[2];
@@ -97,7 +97,9 @@ typedef struct {
} Elf64_Ehdr;
/* e_type */
+#define ET_REL 1
#define ET_EXEC 2
+#define ET_DYN 3
#define ET_CORE 4
/* sh_type */
@@ -191,12 +193,6 @@ typedef struct {
Elf64_Off sh_entsize;
} Elf64_Shdr;
-/* Notes used in ET_CORE */
-#define NT_PRSTATUS 1
-#define NT_PRFPREG 2
-#define NT_PRPSINFO 3
-#define NT_TASKSTRUCT 4
-
#define NT_NETBSD_CORE_PROCINFO 1
/* Note header in a PT_NOTE section */
@@ -212,10 +208,12 @@ typedef struct {
Elf64_Word n_type;
} Elf64_Nhdr;
+/* Notes used in ET_CORE */
#define NT_PRSTATUS 1
#define NT_PRFPREG 2
#define NT_PRPSINFO 3
#define NT_PRXREG 4
+#define NT_TASKSTRUCT 4
#define NT_PLATFORM 5
#define NT_AUXV 6
@@ -233,5 +231,7 @@ typedef struct {
#define GNU_OS_LINUX 0
#define GNU_OS_HURD 1
#define GNU_OS_SOLARIS 2
+#define GNU_OS_KFREEBSD 3
+#define GNU_OS_KNETBSD 4
#endif
diff --git a/usr.bin/file/softmagic.c b/usr.bin/file/softmagic.c
index 701ebe41646..5290b613334 100644
--- a/usr.bin/file/softmagic.c
+++ b/usr.bin/file/softmagic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softmagic.c,v 1.13 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: softmagic.c,v 1.14 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -39,11 +39,11 @@
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.13 2008/05/08 01:40:56 chl Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.14 2009/04/24 18:54:34 chl Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
- const unsigned char *, size_t);
+ const unsigned char *, size_t, int);
private int mget(struct magic_set *, const unsigned char *,
struct magic *, size_t, unsigned int);
private int magiccheck(struct magic_set *, struct magic *);
@@ -59,17 +59,23 @@ private void cvt_32(union VALUETYPE *, const struct magic *);
private void cvt_64(union VALUETYPE *, const struct magic *);
/*
+ * Macro to give description string according to whether we want plain
+ * text or MIME type
+ */
+#define MAGIC_DESC ((ms->flags & MAGIC_MIME) ? m->mimetype : m->desc)
+
+/*
* softmagic - lookup one file in parsed, in-memory copy of database
* Passed the name and FILE * of one file to be typed.
*/
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
protected int
-file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
+file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes, int mode)
{
struct mlist *ml;
int rv;
for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
- if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes)) != 0)
+ if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, mode)) != 0)
return rv;
return 0;
@@ -104,7 +110,7 @@ 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)
+ const unsigned char *s, size_t nbytes, int mode)
{
uint32_t magindex = 0;
unsigned int cont_level = 0;
@@ -118,17 +124,26 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
for (magindex = 0; magindex < nmagic; magindex++) {
int flush;
+ struct magic *m = &magic[magindex];
+
+ if ((m->flag & BINTEST) != mode) {
+ /* Skip sub-tests */
+ while (magic[magindex + 1].cont_level != 0 &&
+ ++magindex < nmagic)
+ continue;
+ continue; /* Skip to next top-level test*/
+ }
- ms->offset = magic[magindex].offset;
- ms->line = magic[magindex].lineno;
+ ms->offset = m->offset;
+ ms->line = m->lineno;
/* if main entry matches, print it... */
- flush = !mget(ms, s, &magic[magindex], nbytes, cont_level);
+ flush = !mget(ms, s, m, nbytes, cont_level);
if (flush) {
- if (magic[magindex].reln == '!')
+ if (m->reln == '!')
flush = 0;
} else {
- switch (magiccheck(ms, &magic[magindex])) {
+ switch (magiccheck(ms, m)) {
case -1:
return -1;
case 0:
@@ -153,15 +168,14 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* If we are going to print something, we'll need to print
* a blank before we print something else.
*/
- if (magic[magindex].desc[0]) {
+ if (*MAGIC_DESC) {
need_separator = 1;
printed_something = 1;
if (print_sep(ms, firstline) == -1)
return -1;
}
- if ((ms->c.li[cont_level].off = mprint(ms, &magic[magindex]))
- == -1)
+ if ((ms->c.li[cont_level].off = mprint(ms, m)) == -1)
return -1;
/* and any continuations that match */
@@ -170,36 +184,36 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
while (magic[magindex+1].cont_level != 0 &&
++magindex < nmagic) {
- ms->line = magic[magindex].lineno; /* for messages */
+ m = &magic[magindex];
+ ms->line = m->lineno; /* for messages */
- if (cont_level < magic[magindex].cont_level)
+ if (cont_level < m->cont_level)
continue;
- if (cont_level > magic[magindex].cont_level) {
+ if (cont_level > m->cont_level) {
/*
* We're at the end of the level
* "cont_level" continuations.
*/
- cont_level = magic[magindex].cont_level;
+ cont_level = m->cont_level;
}
- ms->offset = magic[magindex].offset;
- if (magic[magindex].flag & OFFADD) {
+ ms->offset = m->offset;
+ if (m->flag & OFFADD) {
ms->offset +=
ms->c.li[cont_level - 1].off;
}
#ifdef ENABLE_CONDITIONALS
- if (magic[magindex].cond == COND_ELSE ||
- magic[magindex].cond == COND_ELIF) {
+ if (m->cond == COND_ELSE ||
+ m->cond == COND_ELIF) {
if (ms->c.li[cont_level].last_match == 1)
continue;
}
#endif
- flush = !mget(ms, s, &magic[magindex], nbytes,
- cont_level);
- if (flush && magic[magindex].reln != '!')
+ flush = !mget(ms, s, m, nbytes, cont_level);
+ if (flush && m->reln != '!')
continue;
- switch (flush ? 1 : magiccheck(ms, &magic[magindex])) {
+ switch (flush ? 1 : magiccheck(ms, m)) {
case -1:
return -1;
case 0:
@@ -211,7 +225,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
#ifdef ENABLE_CONDITIONALS
ms->c.li[cont_level].last_match = 1;
#endif
- if (magic[magindex].type != FILE_DEFAULT)
+ if (m->type != FILE_DEFAULT)
ms->c.li[cont_level].got_match = 1;
else if (ms->c.li[cont_level].got_match) {
ms->c.li[cont_level].got_match = 0;
@@ -221,7 +235,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* If we are going to print something,
* make sure that we have a separator first.
*/
- if (magic[magindex].desc[0]) {
+ if (*MAGIC_DESC) {
printed_something = 1;
if (print_sep(ms, firstline) == -1)
return -1;
@@ -234,15 +248,15 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
*/
/* space if previous printed */
if (need_separator
- && (magic[magindex].nospflag == 0)
- && (magic[magindex].desc[0] != '\0')) {
+ && ((m->flag & NOSPACE) == 0)
+ && *MAGIC_DESC) {
if (file_printf(ms, " ") == -1)
return -1;
need_separator = 0;
}
- if ((ms->c.li[cont_level].off = mprint(ms, &magic[magindex])) == -1)
+ if ((ms->c.li[cont_level].off = mprint(ms, m)) == -1)
return -1;
- if (magic[magindex].desc[0])
+ if (*MAGIC_DESC)
need_separator = 1;
/*
@@ -255,9 +269,10 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
break;
}
}
- firstline = 0;
- if (printed_something)
+ if (printed_something) {
+ firstline = 0;
returnval = 1;
+ }
if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
return 1; /* don't keep searching */
}
@@ -271,7 +286,7 @@ check_fmt(struct magic_set *ms, struct magic *m)
regex_t rx;
int rc;
- if (strchr(m->desc, '%') == NULL)
+ if (strchr(MAGIC_DESC, '%') == NULL)
return 0;
rc = regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
@@ -281,7 +296,7 @@ check_fmt(struct magic_set *ms, struct magic *m)
file_magerror(ms, "regex error %d, (%s)", rc, errmsg);
return -1;
} else {
- rc = regexec(&rx, m->desc, 0, 0, 0);
+ rc = regexec(&rx, MAGIC_DESC, 0, 0, 0);
regfree(&rx);
return !rc;
}
@@ -311,8 +326,10 @@ private int32_t
mprint(struct magic_set *ms, struct magic *m)
{
uint64_t v;
+ float vf;
+ double vd;
int64_t t = 0;
- char buf[512];
+ char *buf;
union VALUETYPE *p = &ms->ms_value;
switch (m->type) {
@@ -322,14 +339,13 @@ mprint(struct magic_set *ms, struct magic *m)
case -1:
return -1;
case 1:
- if (snprintf(buf, sizeof(buf), "%c",
- (unsigned char)v) < 0)
+ if (asprintf(&buf, "%c", (unsigned char)v) < 0)
return -1;
- if (file_printf(ms, m->desc, buf) == -1)
+ if (file_printf(ms, MAGIC_DESC, buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, m->desc, (unsigned char) v) == -1)
+ if (file_printf(ms, MAGIC_DESC, (unsigned char) v) == -1)
return -1;
break;
}
@@ -344,14 +360,13 @@ mprint(struct magic_set *ms, struct magic *m)
case -1:
return -1;
case 1:
- if (snprintf(buf, sizeof(buf), "%hu",
- (unsigned short)v) < 0)
+ if (asprintf(&buf, "%hu", (unsigned short)v) < 0)
return -1;
- if (file_printf(ms, m->desc, buf) == -1)
+ if (file_printf(ms, MAGIC_DESC, buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, m->desc, (unsigned short) v) == -1)
+ if (file_printf(ms, MAGIC_DESC, (unsigned short) v) == -1)
return -1;
break;
}
@@ -367,13 +382,13 @@ mprint(struct magic_set *ms, struct magic *m)
case -1:
return -1;
case 1:
- if (snprintf(buf, sizeof(buf), "%u", (uint32_t)v) < 0)
+ if (asprintf(&buf, "%u", (uint32_t)v) < 0)
return -1;
- if (file_printf(ms, m->desc, buf) == -1)
+ if (file_printf(ms, MAGIC_DESC, buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, m->desc, (uint32_t) v) == -1)
+ if (file_printf(ms, MAGIC_DESC, (uint32_t) v) == -1)
return -1;
break;
}
@@ -384,7 +399,7 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BEQUAD:
case FILE_LEQUAD:
v = file_signextend(ms, m, p->q);
- if (file_printf(ms, m->desc, (uint64_t) v) == -1)
+ if (file_printf(ms, MAGIC_DESC, (uint64_t) v) == -1)
return -1;
t = ms->offset + sizeof(int64_t);
break;
@@ -394,16 +409,18 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BESTRING16:
case FILE_LESTRING16:
if (m->reln == '=' || m->reln == '!') {
- if (file_printf(ms, m->desc, m->value.s) == -1)
+ if (file_printf(ms, MAGIC_DESC, m->value.s) == -1)
return -1;
t = ms->offset + m->vallen;
}
else {
if (*m->value.s == '\0')
p->s[strcspn(p->s, "\n")] = '\0';
- if (file_printf(ms, m->desc, p->s) == -1)
+ if (file_printf(ms, MAGIC_DESC, p->s) == -1)
return -1;
t = ms->offset + strlen(p->s);
+ if (m->type == FILE_PSTRING)
+ t++;
}
break;
@@ -411,7 +428,7 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BEDATE:
case FILE_LEDATE:
case FILE_MEDATE:
- if (file_printf(ms, m->desc, file_fmttime(p->l, 1)) == -1)
+ if (file_printf(ms, MAGIC_DESC, file_fmttime(p->l, 1)) == -1)
return -1;
t = ms->offset + sizeof(time_t);
break;
@@ -420,7 +437,7 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BELDATE:
case FILE_LELDATE:
case FILE_MELDATE:
- if (file_printf(ms, m->desc, file_fmttime(p->l, 0)) == -1)
+ if (file_printf(ms, MAGIC_DESC, file_fmttime(p->l, 0)) == -1)
return -1;
t = ms->offset + sizeof(time_t);
break;
@@ -428,7 +445,7 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_QDATE:
case FILE_BEQDATE:
case FILE_LEQDATE:
- if (file_printf(ms, m->desc, file_fmttime((uint32_t)p->q, 1))
+ if (file_printf(ms, MAGIC_DESC, file_fmttime((uint32_t)p->q, 1))
== -1)
return -1;
t = ms->offset + sizeof(uint64_t);
@@ -437,12 +454,54 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_QLDATE:
case FILE_BEQLDATE:
case FILE_LEQLDATE:
- if (file_printf(ms, m->desc, file_fmttime((uint32_t)p->q, 0))
+ if (file_printf(ms, MAGIC_DESC, file_fmttime((uint32_t)p->q, 0))
== -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
+ vf = p->f;
+ switch (check_fmt(ms, m)) {
+ case -1:
+ return -1;
+ case 1:
+ if (asprintf(&buf, "%g", vf) < 0)
+ return -1;
+ if (file_printf(ms, MAGIC_DESC, buf) == -1)
+ return -1;
+ break;
+ default:
+ if (file_printf(ms, MAGIC_DESC, vf) == -1)
+ return -1;
+ break;
+ }
+ t = ms->offset + sizeof(float);
+ break;
+
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
+ vd = p->d;
+ switch (check_fmt(ms, m)) {
+ case -1:
+ return -1;
+ case 1:
+ if (asprintf(&buf, "%g", vd) < 0)
+ return -1;
+ if (file_printf(ms, MAGIC_DESC, buf) == -1)
+ return -1;
+ break;
+ default:
+ if (file_printf(ms, MAGIC_DESC, vd) == -1)
+ return -1;
+ break;
+ }
+ t = ms->offset + sizeof(double);
+ break;
+
case FILE_REGEX: {
char *cp;
int rval;
@@ -452,7 +511,7 @@ mprint(struct magic_set *ms, struct magic *m)
file_oomem(ms, ms->search.rm_len);
return -1;
}
- rval = file_printf(ms, m->desc, cp);
+ rval = file_printf(ms, MAGIC_DESC, cp);
free(cp);
if (rval == -1)
@@ -466,7 +525,7 @@ mprint(struct magic_set *ms, struct magic *m)
}
case FILE_SEARCH:
- if (file_printf(ms, m->desc, m->value.s) == -1)
+ if (file_printf(ms, MAGIC_DESC, m->value.s) == -1)
return -1;
if ((m->str_flags & REGEX_OFFSET_START))
t = ms->search.offset;
@@ -475,7 +534,7 @@ mprint(struct magic_set *ms, struct magic *m)
break;
case FILE_DEFAULT:
- if (file_printf(ms, m->desc, m->value.s) == -1)
+ if (file_printf(ms, MAGIC_DESC, m->value.s) == -1)
return -1;
t = ms->offset;
break;
@@ -543,6 +602,35 @@ cvt_64(union VALUETYPE *p, const struct magic *m)
DO_CVT(q, (uint64_t));
}
+#define DO_CVT2(fld, cast) \
+ if (m->num_mask) \
+ switch (m->mask_op & FILE_OPS_MASK) { \
+ case FILE_OPADD: \
+ p->fld += cast m->num_mask; \
+ break; \
+ case FILE_OPMINUS: \
+ p->fld -= cast m->num_mask; \
+ break; \
+ case FILE_OPMULTIPLY: \
+ p->fld *= cast m->num_mask; \
+ break; \
+ case FILE_OPDIVIDE: \
+ p->fld /= cast m->num_mask; \
+ break; \
+ } \
+
+private void
+cvt_float(union VALUETYPE *p, const struct magic *m)
+{
+ DO_CVT2(f, (float));
+}
+
+private void
+cvt_double(union VALUETYPE *p, const struct magic *m)
+{
+ DO_CVT2(d, (double));
+}
+
/*
* Convert the byte order of the data we are looking at
* While we're here, let's apply the mask operation
@@ -609,10 +697,11 @@ mconvert(struct magic_set *ms, struct magic *m)
case FILE_BEQUAD:
case FILE_BEQDATE:
case FILE_BEQLDATE:
- p->q = (int64_t)
- (((int64_t)p->hq[0]<<56)|((int64_t)p->hq[1]<<48)|
- ((int64_t)p->hq[2]<<40)|((int64_t)p->hq[3]<<32)|
- (p->hq[4]<<24)|(p->hq[5]<<16)|(p->hq[6]<<8)|(p->hq[7]));
+ p->q = (uint64_t)
+ (((uint64_t)p->hq[0]<<56)|((uint64_t)p->hq[1]<<48)|
+ ((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);
return 1;
case FILE_LESHORT:
@@ -629,10 +718,11 @@ mconvert(struct magic_set *ms, struct magic *m)
case FILE_LEQUAD:
case FILE_LEQDATE:
case FILE_LEQLDATE:
- p->q = (int64_t)
- (((int64_t)p->hq[7]<<56)|((int64_t)p->hq[6]<<48)|
- ((int64_t)p->hq[5]<<40)|((int64_t)p->hq[4]<<32)|
- (p->hq[3]<<24)|(p->hq[2]<<16)|(p->hq[1]<<8)|(p->hq[0]));
+ p->q = (uint64_t)
+ (((uint64_t)p->hq[7]<<56)|((uint64_t)p->hq[6]<<48)|
+ ((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);
return 1;
case FILE_MELONG:
@@ -642,6 +732,36 @@ mconvert(struct magic_set *ms, struct magic *m)
((p->hl[1]<<24)|(p->hl[0]<<16)|(p->hl[3]<<8)|(p->hl[2]));
cvt_32(p, m);
return 1;
+ case FILE_FLOAT:
+ cvt_float(p, m);
+ return 1;
+ case FILE_BEFLOAT:
+ p->l = ((uint32_t)p->hl[0]<<24)|((uint32_t)p->hl[1]<<16)|
+ ((uint32_t)p->hl[2]<<8) |((uint32_t)p->hl[3]);
+ cvt_float(p, m);
+ return 1;
+ case FILE_LEFLOAT:
+ p->l = ((uint32_t)p->hl[3]<<24)|((uint32_t)p->hl[2]<<16)|
+ ((uint32_t)p->hl[1]<<8) |((uint32_t)p->hl[0]);
+ cvt_float(p, m);
+ return 1;
+ case FILE_DOUBLE:
+ cvt_double(p, m);
+ return 1;
+ case FILE_BEDOUBLE:
+ p->q = ((uint64_t)p->hq[0]<<56)|((uint64_t)p->hq[1]<<48)|
+ ((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_double(p, m);
+ return 1;
+ case FILE_LEDOUBLE:
+ p->q = ((uint64_t)p->hq[7]<<56)|((uint64_t)p->hq[6]<<48)|
+ ((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_double(p, m);
+ return 1;
case FILE_REGEX:
case FILE_SEARCH:
case FILE_DEFAULT:
@@ -675,13 +795,10 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
case FILE_SEARCH:
ms->search.s = (const char *)s + offset;
ms->search.s_len = nbytes - offset;
+ ms->search.offset = offset;
return 0;
case FILE_REGEX: {
- /*
- * offset is interpreted as last line to search,
- * (starting at 1), not as bytes-from start-of-file
- */
const char *b;
const char *c;
const char *last; /* end of search region */
@@ -728,13 +845,17 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
offset);
return -1;
}
- for (/*EMPTY*/; src < esrc; src++, dst++) {
+ for (/*EMPTY*/; src < esrc; src += 2, dst++) {
if (dst < edst)
- *dst = *src++;
+ *dst = *src;
else
break;
- if (*dst == '\0')
- *dst = ' ';
+ if (*dst == '\0') {
+ if (type == FILE_BESTRING16 ?
+ *(src - 1) != '\0' :
+ *(src + 1) != '\0')
+ *dst = ' ';
+ }
}
*edst = '\0';
return 0;
@@ -772,7 +893,7 @@ mget(struct magic_set *ms, const unsigned char *s,
struct magic *m, size_t nbytes, unsigned int cont_level)
{
uint32_t offset = ms->offset;
- uint32_t count = m->str_count;
+ uint32_t count = m->str_range;
union VALUETYPE *p = &ms->ms_value;
if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1)
@@ -1233,13 +1354,6 @@ mget(struct magic_set *ms, const unsigned char *s,
case FILE_OPMODULO:
offset = p->l % off;
break;
- /* case TOOMANYSWITCHBLOCKS:
- * ugh = p->eye % m->strain;
- * rub;
- * case BEER:
- * off = p->tab & m->in_gest;
- * sleep;
- */
}
} else
offset = p->l;
@@ -1287,10 +1401,20 @@ mget(struct magic_set *ms, const unsigned char *s,
case FILE_BELDATE:
case FILE_LELDATE:
case FILE_MELDATE:
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
if (nbytes < (offset + 4))
return 0;
break;
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
+ if (nbytes < (offset + 8))
+ return 0;
+ break;
+
case FILE_STRING:
case FILE_PSTRING:
case FILE_SEARCH:
@@ -1326,10 +1450,8 @@ file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags)
uint64_t v;
/*
- * What we want here is:
- * v = strncmp(m->value.s, p->s, m->vallen);
- * but ignoring any nulls. bcmp doesn't give -/+/0
- * and isn't universally available anyway.
+ * What we want here is v = strncmp(s1, s2, len),
+ * but ignoring any nulls.
*/
v = 0;
if (0L == flags) { /* normal string: do it fast */
@@ -1393,6 +1515,8 @@ magiccheck(struct magic_set *ms, struct magic *m)
{
uint64_t l = m->value.q;
uint64_t v;
+ float fl, fv;
+ double dl, dv;
int matched;
union VALUETYPE *p = &ms->ms_value;
@@ -1434,6 +1558,72 @@ magiccheck(struct magic_set *ms, struct magic *m)
v = p->q;
break;
+ case FILE_FLOAT:
+ case FILE_BEFLOAT:
+ case FILE_LEFLOAT:
+ fl = m->value.f;
+ fv = p->f;
+ switch (m->reln) {
+ case 'x':
+ matched = 1;
+ break;
+
+ case '!':
+ matched = fv != fl;
+ break;
+
+ case '=':
+ matched = fv == fl;
+ break;
+
+ case '>':
+ matched = fv > fl;
+ break;
+
+ case '<':
+ matched = fv < fl;
+ break;
+
+ default:
+ matched = 0;
+ file_magerror(ms, "cannot happen with float: invalid relation `%c'", m->reln);
+ return -1;
+ }
+ return matched;
+
+ case FILE_DOUBLE:
+ case FILE_BEDOUBLE:
+ case FILE_LEDOUBLE:
+ dl = m->value.d;
+ dv = p->d;
+ switch (m->reln) {
+ case 'x':
+ matched = 1;
+ break;
+
+ case '!':
+ matched = dv != dl;
+ break;
+
+ case '=':
+ matched = dv == dl;
+ break;
+
+ case '>':
+ matched = dv > dl;
+ break;
+
+ case '<':
+ matched = dv < dl;
+ break;
+
+ default:
+ matched = 0;
+ file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln);
+ return -1;
+ }
+ return matched;
+
case FILE_DEFAULT:
l = 0;
v = 0;
@@ -1461,15 +1651,14 @@ magiccheck(struct magic_set *ms, struct magic *m)
slen = MIN(m->vallen, sizeof(m->value.s));
l = 0;
v = 0;
- ms->search.offset = m->offset;
- for (idx = 0; m->str_count == 0 || idx < m->str_count; idx++) {
+ for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) {
if (slen + idx > ms->search.s_len)
break;
v = file_strncmp(m->value.s, ms->search.s + idx, slen, m->str_flags);
if (v == 0) { /* found match */
- ms->search.offset = m->offset + idx;
+ ms->search.offset += idx;
break;
}
}
diff --git a/usr.bin/file/tar.h b/usr.bin/file/tar.h
index 0a10238695b..9e6f3a84f3b 100644
--- a/usr.bin/file/tar.h
+++ b/usr.bin/file/tar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tar.h,v 1.6 2008/05/08 01:40:56 chl Exp $ */
+/* $OpenBSD: tar.h,v 1.7 2009/04/24 18:54:34 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -33,20 +33,10 @@
*
* Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
*
- * $Id: tar.h,v 1.6 2008/05/08 01:40:56 chl Exp $ # checkin only
+ * $Id: tar.h,v 1.7 2009/04/24 18:54:34 chl Exp $ # checkin only
*/
/*
- * Kludge for handling systems that cannot cope with multiple
- * external definitions of a variable. In ONE routine (tar.c),
- * we #define TAR_EXTERN to null; here, we set it to "extern" if
- * it is not already set.
- */
-#ifndef TAR_EXTERN
-#define TAR_EXTERN extern
-#endif
-
-/*
* Header block on tape.
*
* I'm going to use traditional DP naming conventions here.
@@ -79,58 +69,6 @@ union record {
} header;
};
-/* The checksum field is filled with this while the checksum is computed. */
-#define CHKBLANKS " " /* 8 blanks, no null */
-
/* The magic field is filled with this if uname and gname are valid. */
#define TMAGIC "ustar" /* 5 chars and a null */
#define GNUTMAGIC "ustar " /* 7 chars and a null */
-
-/* The linkflag defines the type of file */
-#define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */
-#define LF_NORMAL '0' /* Normal disk file */
-#define LF_LINK '1' /* Link to previously dumped file */
-#define LF_SYMLINK '2' /* Symbolic link */
-#define LF_CHR '3' /* Character special file */
-#define LF_BLK '4' /* Block special file */
-#define LF_DIR '5' /* Directory */
-#define LF_FIFO '6' /* FIFO special file */
-#define LF_CONTIG '7' /* Contiguous file */
-/* Further link types may be defined later. */
-
-/*
- * Exit codes from the "tar" program
- */
-#define EX_SUCCESS 0 /* success! */
-#define EX_ARGSBAD 1 /* invalid args */
-#define EX_BADFILE 2 /* invalid filename */
-#define EX_BADARCH 3 /* bad archive */
-#define EX_SYSTEM 4 /* system gave unexpected error */
-
-/*
- * Structure for keeping track of filenames and lists thereof.
- */
-struct name {
- struct name *next;
- short length;
- char found;
- char name[NAMSIZ+1];
-};
-
-/*
- *
- * Due to the next struct declaration, each routine that includes
- * "tar.h" must also include <sys/types.h>. I tried to make it automatic,
- * but System V has no defines in <sys/types.h>, so there is no way of
- * knowing when it has been included. In addition, it cannot be included
- * twice, but must be included exactly once. Argghh!
- *
- * Thanks, typedef. Thanks, USG.
- */
-struct link {
- struct link *next;
- dev_t dev;
- ino_t ino;
- short linkcount;
- char name[NAMSIZ+1];
-};