+2015-04-09 15:59 Christos Zoulas <christos@zoulas.com>
+
+ * Add --extension to list the known extensions for this file type
+ Idea by Andrew J Roazen
+
2015-02-14 12:23 Christos Zoulas <christos@zoulas.com>
* Bump file search buffer size to 1M.
BSD-licensed, has a magic reimplementation in Python.
Read the kerberos magic entry for more ideas.
+
+Write a string merger to make magic entry sizes dynamic.
+Strings will be converted to offsets from the string table.
-.\" $File: file.man,v 1.112 2015/02/14 17:24:30 christos Exp $
-.Dd February 14, 2015
+.\" $File: file.man,v 1.113 2015/04/09 20:01:40 christos Exp $
+.Dd April 9, 2015
.Dt FILE __CSECTION__
.Os
.Sh NAME
.Bk -words
.Op Fl bcEhiklLNnprsvz0
.Op Fl Fl apple
+.Op Fl Fl extension
.Op Fl Fl mime-encoding
.Op Fl Fl mime-type
.Op Fl e Ar testname
.It tar
Examines tar files.
.El
+.It Fl Fl extension
+Print a comma-separated list of valid extensions for the file type found.
.It Fl F , Fl Fl separator Ar separator
Use the specified string as the separator between the filename and the
file result returned.
-.\" $File: libmagic.man,v 1.34 2014/12/16 23:18:40 christos Exp $
+.\" $File: libmagic.man,v 1.35 2015/04/09 20:01:40 christos Exp $
.\"
.\" Copyright (c) Christos Zoulas 2003.
.\" All Rights Reserved.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 16, 2014
+.Dd April 9, 2015
.Dt LIBMAGIC 3
.Os
.Sh NAME
as real errors, instead of printing them in the magic buffer.
.It Dv MAGIC_APPLE
Return the Apple creator and type.
+.It Dv MAGIC_EXTENSION
+Return a comma-separated list of extensions for this file type.
.It Dv MAGIC_NO_CHECK_APPTYPE
Don't check for
.Dv EMX
#------------------------------------------------------------------------------
-# $File: jpeg,v 1.27 2015/02/06 17:08:31 christos Exp $
+# $File: jpeg,v 1.28 2015/04/09 20:01:40 christos Exp $
# JPEG images
# SunOS 5.5.1 had
#
!:mime image/jpeg
!:apple 8BIMJPEG
!:strength *3
+!:ext jpeg,jpg,jpe,jfif
>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
#------------------------------------------------------------------------------
-# $File: mathematica,v 1.7 2009/09/19 16:28:10 christos Exp $
+# $File: mathematica,v 1.8 2015/04/09 20:01:40 christos Exp $
# mathematica: file(1) magic for mathematica files
# "H. Nanosecond" <aldomel@ix.netcom.com>
# Mathematica a multi-purpose math program
#mathematica .mb
0 string \064\024\012\000\035\000\000\000 Mathematica version 2 notebook
+!:ext mb
0 string \064\024\011\000\035\000\000\000 Mathematica version 2 notebook
+!:ext mb
# .ma
# multiple possibilites:
0 string (*^\n\n::[\011frontEndVersion\ =\ Mathematica notebook
#>41 string >\0 %s
+!:ext mb
#0 string (*^\n\n::[\011palette Mathematica notebook version 2.x
# generic:
0 string (*^\r\r::[\011 Mathematica notebook version 2.x
+!:ext mb
0 string (*^\r\n\r\n::[\011 Mathematica notebook version 2.x
+!:ext mb
0 string (*^\015 Mathematica notebook version 2.x
+!:ext mb
0 string (*^\n\r\n\r::[\011 Mathematica notebook version 2.x
+!:ext mb
0 string (*^\r::[\011 Mathematica notebook version 2.x
+!:ext mb
0 string (*^\r\n::[\011 Mathematica notebook version 2.x
+!:ext mb
0 string (*^\n\n::[\011 Mathematica notebook version 2.x
+!:ext mb
0 string (*^\n::[\011 Mathematica notebook version 2.x
+!:ext mb
# Mathematica .mx files
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.231 2015/02/06 17:08:58 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.232 2015/04/09 20:01:40 christos Exp $")
#endif /* lint */
#include "magic.h"
private int parse_mime(struct magic_set *, struct magic_entry *, const char *);
private int parse_strength(struct magic_set *, struct magic_entry *, const char *);
private int parse_apple(struct magic_set *, struct magic_entry *, const char *);
+private int parse_ext(struct magic_set *, struct magic_entry *, const char *);
private size_t magicsize = sizeof(struct magic);
#define DECLARE_FIELD(name) { # name, sizeof(# name) - 1, parse_ ## name }
DECLARE_FIELD(mime),
DECLARE_FIELD(apple),
+ DECLARE_FIELD(ext),
DECLARE_FIELD(strength),
#undef DECLARE_FIELD
{ NULL, 0, NULL }
sizeof(m->apple), "APPLE", "!+-./", 0);
}
+/*
+ * Parse a comma-separated list of extensions
+ */
+private int
+parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line)
+{
+ struct magic *m = &me->mp[0];
+
+ return parse_extra(ms, me, line,
+ CAST(off_t, offsetof(struct magic, ext)),
+ sizeof(m->ext), "EXTENSION", ",!+-/", 0);
+}
+
/*
* parse a MIME annotation line from magic file, put into magic[index - 1]
* if valid
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.91 2014/11/28 02:46:39 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.92 2015/04/09 20:01:41 christos Exp $")
#endif /* lint */
#include "magic.h"
const char *code_mime = NULL;
const char *type = NULL;
- if (ms->flags & MAGIC_APPLE)
+ if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
return 0;
nbytes = trim_nuls(buf, nbytes);
size_t last_line_end = (size_t)-1;
int has_long_lines = 0;
- if (ms->flags & MAGIC_APPLE)
+ if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
return 0;
nbytes = trim_nuls(buf, nbytes);
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.162 2015/02/09 20:15:50 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.163 2015/04/09 20:01:41 christos Exp $")
#endif /* lint */
#include "magic.h"
# define USAGE \
"Usage: %s [" FILE_FLAGS \
- "] [--apple] [--mime-encoding] [--mime-type]\n" \
+ "] [--apple] [--extension] [--mime-encoding] [--mime-type]\n" \
" [-e testname] [-F separator] [-f namefile] [-m magicfiles] " \
"file ...\n" \
" %s -C [-m magicfiles]\n" \
flags |= MAGIC_APPLE;
break;
case 11:
- flags |= MAGIC_MIME_TYPE;
+ flags |= MAGIC_EXTENSION;
break;
case 12:
+ flags |= MAGIC_MIME_TYPE;
+ break;
+ case 13:
flags |= MAGIC_MIME_ENCODING;
break;
}
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.167 2015/02/14 17:19:29 christos Exp $
+ * @(#)$File: file.h,v 1.168 2015/04/09 20:01:41 christos Exp $
*/
#ifndef __file_h__
#define MAXstring 64 /* max len of "string" types */
#define MAGICNO 0xF11E041C
-#define VERSIONNO 12
-#define FILE_MAGICSIZE 248
+#define VERSIONNO 13
+#define FILE_MAGICSIZE 312
#define FILE_LOAD 0
#define FILE_CHECK 1
/* Words 33-52 */
char mimetype[MAXMIME]; /* MIME type */
/* Words 53-54 */
- char apple[8];
+ char apple[8]; /* APPLE CREATOR/TYPE */
+ /* Words 55-63 */
+ char ext[64]; /* Popular extensions */
};
#define BIT(A) (1 << (A))
OPT('i', "mime", 0, " output MIME type strings (--mime-type and\n"
" --mime-encoding)\n")
OPT_LONGONLY("apple", 0, " output the Apple CREATOR/TYPE\n")
+OPT_LONGONLY("extension", 0, " output a comma-separated list of extnsions\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")
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.75 2014/12/04 15:56:46 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.76 2015/04/09 20:01:41 christos Exp $")
#endif /* lint */
#include "magic.h"
struct stat tstatbuf;
#endif
- if (ms->flags & MAGIC_APPLE)
+ if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
return 0;
if (fn == NULL)
return 0;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.37 2010/11/30 14:58:53 rrt Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.38 2015/04/09 20:01:41 christos Exp $")
#endif
#include "magic.h"
int tar;
int mime = ms->flags & MAGIC_MIME;
- if ((ms->flags & MAGIC_APPLE) != 0)
+ if ((ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION)) != 0)
return 0;
tar = is_tar(buf, nbytes);
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.52 2015/02/27 21:16:38 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.53 2015/04/09 20:01:41 christos Exp $")
#endif
#include <assert.h>
info.i_fd = fd;
info.i_buf = buf;
info.i_len = nbytes;
- if (ms->flags & MAGIC_APPLE)
+ if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
return 0;
if (cdf_read_header(&info, &h) == -1)
return 0;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.118 2015/01/02 21:29:39 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.119 2015/04/09 20:01:41 christos Exp $")
#endif
#ifdef BUILTIN_ELF
Elf64_Ehdr elf64hdr;
uint16_t type, phnum, shnum, notecount;
- if (ms->flags & (MAGIC_MIME|MAGIC_APPLE))
+ if (ms->flags & (MAGIC_MIME|MAGIC_APPLE|MAGIC_EXTENSION))
return 0;
/*
* ELF executables have multiple section headers in arbitrary
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.213 2015/02/14 18:43:12 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.214 2015/04/09 20:01:41 christos Exp $")
#endif /* lint */
#include "magic.h"
unsigned int cont_level = 0;
int returnvalv = 0, e; /* if a match is found it is set to 1*/
int firstline = 1; /* a flag to print X\n X\n- X */
- int print = (ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0;
+ int print = (ms->flags & (MAGIC_MIME|MAGIC_APPLE|MAGIC_EXTENSION)) == 0;
if (returnval == NULL)
returnval = &returnvalv;
return -1;
if (rv == 1) {
- if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
+ if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE|MAGIC_EXTENSION)) == 0 &&
file_printf(ms, F(ms, m, "%u"), offset) == -1) {
free(rbuf);
return -1;
return -1;
return 1;
}
+ if (ms->flags & MAGIC_EXTENSION) {
+ if (file_printf(ms, "%s", m->ext) == -1)
+ return -1;
+ return 1;
+ }
if ((ms->flags & MAGIC_MIME_TYPE) && m->mimetype[0]) {
if (file_printf(ms, "%s", m->mimetype) == -1)
return -1;