+2008-07-02 11:15 Christos Zoulas <christos@astron.com>
+
+ * add !:strength op to adjust magic strength (experimental)
+
2008-06-16 21:41 Reuben Thomas <rrt@sc3d.org>
* Fix automake error in configure.ac.
# X3D (Extensible 3D) [http://www.web3d.org/specifications/x3d-3.0.dtd]
# From Michel Briand <michelbriand@free.fr>
0 string \<?xml\ version="
->20 search/1000/cb \<!DOCTYPE\ X3D X3D (Extensible 3D) model
+!:strength +1
+>20 search/1000/cb \<!DOCTYPE\ X3D X3D (Extensible 3D) model xml text
!:mime model/x3d
#---------------------------------------------------------------------------
#
0 belong 0x37804012 V64 Nintendo 64 ROM dump
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+# Nintendo .nds
+192 string \044\377\256Qi\232 Nintendo DS Game ROM Image
+# Nintendo .gba
+0 string \056\000\000\352$\377\256Qi Nintendo Game Boy Advance ROM Image
+
#------------------------------------------------------------------------------
# msx: file(1) magic for MSX game cartridge dumps
# Too simple - MPi
>5 byte 0 invalid byte order
>5 byte 1 LSB
>>16 leshort 0 no file type,
+!:strength *2
!:mime application/octet-stream
>>16 leshort 1 relocatable,
!:mime application/x-object
0x10000 belong 0x01161970 GFS2 Filesystem
>0x10024 belong x (blocksize %d,
>0x10060 string >\0 lockproto %s)
+
+# dvdisaster's .ecc
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+0 string *dvdisaster* dvdisaster error correction file
# ('Bucky' LaDieu, nega@vt.edu)
20 string GIMP GIMP brush data
+
+# GIMP Curves File
+# From: "Nelson A. de Oliveira" <naoliv@gmail.com>
+0 string #\040GIMP\040Curves\040File GIMP curve file
#
# 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,
+0 string \x89PNG\x0d\x0a\x1a\x0a PNG image
!:mime image/png
->4 belong !0x0d0a1a0a CORRUPTED,
->4 belong 0x0d0a1a0a
->>16 belong x %ld x
+>>16 belong x \b, %ld x
>>20 belong x %ld,
>>24 byte x %d-bit
>>25 byte 0 grayscale,
#>>26 byte 0 deflate/32K,
>>28 byte 0 non-interlaced
>>28 byte 1 interlaced
-1 string PNG PNG image data, CORRUPTED
# possible GIF replacements; none yet released!
# (Greg Roelofs, newt@uchicago.edu)
# PC bitmaps (OS/2, Windows BMP files) (Greg Roelofs, newt@uchicago.edu)
-0 string BM PC bitmap data
+0 string BM
+>14 leshort 12 PC bitmap, OS/2 1.x format
!:mime image/x-ms-bmp
->14 leshort 12 \b, OS/2 1.x format
>>18 leshort x \b, %d x
>>20 leshort x %d
->14 leshort 64 \b, OS/2 2.x format
+>14 leshort 64 PC bitmap, OS/2 2.x format
+!:mime image/x-ms-bmp
>>18 leshort x \b, %d x
>>20 leshort x %d
->14 leshort 40 \b, Windows 3.x format
+>14 leshort 40 PC bitmap, Windows 3.x format
+!:mime image/x-ms-bmp
+>>18 lelong x \b, %d x
+>>22 lelong x %d x
+>>28 leshort x %d
+>14 leshort 128 PC bitmap, Windows NT/2000 format
+!:mime image/x-ms-bmp
>>18 lelong x \b, %d x
>>22 lelong x %d x
>>28 leshort x %d
# http://www.dalibor.cz/minolta/raw_file_format.htm
0 string \000MRM Minolta Dimage camera raw image data
-# From: stephane.loeuillet@tiscali.f
-# http://www.djvuzone.org/
-0 string AT&TFORM DjVu Image file
+# Summary: DjVu image / document
+# Extension: .djvu
+# Reference: http://djvu.org/docs/DjVu3Spec.djvu
+# Submitted by: Stephane Loeuillet <stephane.loeuillet@tiscali.fr>
+# Modified by (1): Abel Cheung <abelcheung@gmail.com>
+0 string AT&TFORM
!:mime image/vnd.djvu
+>12 string DJVM DjVu multiple page document
+>12 string DJVU DjVu image or single page document
+>12 string DJVI DjVu shared document
+>12 string THUM DjVu page thumbnails
+
# From Marc Espie
0 lelong 20000630 OpenEXR image data
# Files produced by CLISP Common Lisp From: Bruno Haible <haible@ilog.fr>
0 string (SYSTEM::VERSION\040' CLISP byte-compiled Lisp program (pre 2004-03-27)
-0 string (|SYSTEM|::|VERSION|\040' CLISP byte-compiled Lisp program
- text
+0 string (|SYSTEM|::|VERSION|\040' CLISP byte-compiled Lisp program text
0 long 0x70768BD2 CLISP memory image data
0 long 0xD28B7670 CLISP memory image data, other endian
4 string gtktalog GNOME Catalogue (gtktalog)
>13 string >\0 version %s
-# From: Tomasz Trojanowski <tomek@uninet.com.pl>
+# Summary: Libtool library file
+# Extension: .la
+# Submitted by: Tomasz Trojanowski <tomek@uninet.com.pl>
0 search/80 .la\ -\ a\ libtool\ library\ file libtool library file
+
+# Summary: Libtool object file
+# Extension: .lo
+# Submitted by: Abel Cheung <abelcheung@gmail.com>
+0 search/80 .lo\ -\ a\ libtool\ object\ file libtool object file
!:mime text/x-msdos-batch
>1 string/cB echo\ off MS-DOS batch file text
!:mime text/x-msdos-batch
->1 string/cB rem\ MS-DOS batch file text
+>1 string/cB rem\ MS-DOS batch file text
!:mime text/x-msdos-batch
->1 string/cB set\ MS-DOS batch file text
+>1 string/cB set\ MS-DOS batch file text
!:mime text/x-msdos-batch
>0x40 string aPKG \b, aPackage self-extracting archive
>32 string AIN
->>35 string 2 \b, AIN 2.x compressed
->>35 string <2 \b, AIN 1.x compressed
->>35 string >2 \b, AIN 1.x compressed
->28 string UC2X \b, UCEXE compressed
->28 string WWP\ \b, WWPACK compressed
+>>35 string 2 \b, AIN 2.x compressed
+>>35 string <2 \b, AIN 1.x compressed
+>>35 string >2 \b, AIN 1.x compressed
+>28 string UC2X \b, UCEXE compressed
+>28 string WWP\ \b, WWPACK compressed
# skip to the end of the exe
>(4.s*512) long x
!:mime application/vnd.lotus-wordpro
-# DeIsL1.isu what this is I don't know
-0 string \161\250\000\000\001\002 DeIsL1.isu whatever that is
+# Summary: Script used by InstallScield to uninstall applications
+# Extension: .isu
+# Submitted by: unknown
+# Modified by (1): Abel Cheung <abelcheung@gmail.com> (replace useless entry)
+0 string \x71\xa8\x00\x00\x01\x02
+>12 string Stirling\ Technologies, InstallShield Uninstall Script
# Winamp .avs
#0 string Nullsoft\ AVS\ Preset\ \060\056\061\032 A plug in for Winamp ms-windows Freeware media player
-0 string Nullsoft\ AVS\ Preset\ Winamp plug in
+0 string Nullsoft\ AVS\ Preset\ Winamp plug in
# Windows Metafont .WMF
0 string \327\315\306\232 ms-windows metafont .wmf
>>>20 long >0 TIFF starts at byte %d
>>>>24 long >0 length %d
-# Adobe's PostScript Printer Description (PPD) files
-# Yves Arrouye <arrouye@marin.fdn.fr>
+# Summary: Adobe's PostScript Printer Description File
+# Extension: .ppd
+# Reference: http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf, Section 3.8
+# Submitted by: Yves Arrouye <arrouye@marin.fdn.fr>
#
-0 string *PPD-Adobe: PPD file
->13 string x \b, ve
+0 string *PPD-Adobe:\x20 PPD file
+>&0 string x \b, version %s
# HP Printer Job Language
0 string \033%-12345X@PJL HP Printer Job Language data
0 string SHCC3 MS Windows 3.1 registry file
+# Summary: Windows Registry text
+# Extension: .reg
+# Submitted by: Abel Cheung <abelcheung@gmail.com>
+0 string REGEDIT4\r\n\r\n Windows Registry text (Win95 or above)
+0 string Windows\ Registry\ Editor\
+>&0 string Version\ 5.00\r\n\r\n Windows Registry text (Win2K or above)
#include <dirent.h>
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.135 2008/05/09 14:20:28 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.136 2008/05/18 23:20:40 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
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 check_format_type(const char *, int);
private int check_format(struct magic_set *, struct magic *);
private int get_op(char);
+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 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;
+
+private struct {
+ const char *name;
+ size_t len;
+ int (*fun)(struct magic_set *, struct magic_entry *, const char *);
+} bang[] = {
+#define DECLARE_FIELD(name) { # name, sizeof(# name) - 1, parse_ ## name }
+ DECLARE_FIELD(mime),
+ DECLARE_FIELD(strength),
+#undef DECLARE_FIELD
+ { NULL, 0, NULL }
+};
#ifdef COMPILE_ONLY
switch (m->type) {
case FILE_DEFAULT: /* make sure this sorts last */
+ if (m->factor_op != FILE_FACTOR_OP_NONE)
+ abort();
return 0;
case FILE_BYTE:
if (val == 0) /* ensure we only return 0 for FILE_DEFAULT */
val = 1;
+ switch (m->factor_op) {
+ case FILE_FACTOR_OP_NONE:
+ break;
+ case FILE_FACTOR_OP_PLUS:
+ val += m->factor;
+ break;
+ case FILE_FACTOR_OP_MINUS:
+ val -= m->factor;
+ break;
+ case FILE_FACTOR_OP_TIMES:
+ val *= m->factor;
+ break;
+ case FILE_FACTOR_OP_DIV:
+ val /= m->factor;
+ break;
+ default:
+ abort();
+ }
return val;
}
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)
+ if (line[0] == '!' && line[1] == ':') {
+ size_t i;
+
+ for (i = 0; bang[i].name != NULL; i++) {
+ if (len - 2 > bang[i].len &&
+ memcmp(bang[i].name, line + 2,
+ bang[i].len) == 0)
+ break;
+ }
+ if (bang[i].name == NULL) {
+ file_error(ms, 0,
+ "Unknown !: entry `%s'", line);
+ (*errs)++;
+ continue;
+ }
+ if (*marraycount == 0) {
+ file_error(ms, 0,
+ "No current entry for :!%s type",
+ bang[i].name);
(*errs)++;
+ continue;
+ }
+ if ((*bang[i].fun)(ms,
+ &(*marray)[*marraycount - 1],
+ line + bang[i].len + 2) != 0) {
+ (*errs)++;
+ continue;
+ }
continue;
}
- if (parse(ms, marray, marraycount, line, lineno, action) != 0)
+ if (parse(ms, marray, marraycount, line, lineno,
+ action) != 0)
(*errs)++;
}
} else
m = me->mp;
(void)memset(m, 0, sizeof(*m));
+ m->factor_op = FILE_FACTOR_OP_NONE;
m->cont_level = 0;
me->cont_count = 1;
}
}
/*
- * parse a MIME annotation line from magic file, put into magic[index - 1]
+ * parse a STRENGTH 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)
+parse_strength(struct magic_set *ms, struct magic_entry *me, 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");
+ char *el;
+ unsigned long factor;
+ struct magic *m = &me->mp[0];
+
+ if (m->factor_op != FILE_FACTOR_OP_NONE) {
+ file_magwarn(ms,
+ "Current entry already has a strength type: %c %d",
+ m->factor_op, m->factor);
return -1;
}
+ EATAB;
+ switch (*l) {
+ case FILE_FACTOR_OP_NONE:
+ case FILE_FACTOR_OP_PLUS:
+ case FILE_FACTOR_OP_MINUS:
+ case FILE_FACTOR_OP_TIMES:
+ case FILE_FACTOR_OP_DIV:
+ m->factor_op = *l++;
+ break;
+ default:
+ file_magwarn(ms, "Unknown factor op `%c'", *l);
+ return -1;
+ }
+ EATAB;
+ factor = strtoul(l, &el, 0);
+ if (factor > 255) {
+ file_magwarn(ms, "Too large factor `%lu'", factor);
+ goto out;
+ }
+ if (*el && !isspace((unsigned char)*el)) {
+ file_magwarn(ms, "Bad factor `%s'", l);
+ goto out;
+ }
+ m->factor = (uint8_t)factor;
+ if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) {
+ file_magwarn(ms, "Cannot have factor op `%c' and factor %u",
+ m->factor_op, m->factor);
+ goto out;
+ }
+ return 0;
+out:
+ m->factor_op = FILE_FACTOR_OP_NONE;
+ m->factor = 0;
+ return -1;
+}
- me = &(*mentryp)[*nmentryp - 1];
- m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1];
+/*
+ * 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 *me, const char *line)
+{
+ size_t i;
+ const char *l = line;
+ struct magic *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);
+ file_magwarn(ms, "Current entry already has a MIME type `%s',"
+ " new type `%s'", m->mimetype, l);
return -1;
}
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.104 2008/05/09 14:20:28 christos Exp $
+ * @(#)$File: file.h,v 1.105 2008/05/28 21:02:29 christos Exp $
*/
#ifndef __file_h__
#define MAXstring 32 /* max leng of "string" types */
#define MAGICNO 0xF11E041C
-#define VERSIONNO 5
+#define VERSIONNO 6
#define FILE_MAGICSIZE (32 * 6)
#define FILE_LOAD 0
for top-level tests) */
#define TEXTTEST 0 /* for passing to file_softmagic */
- uint8_t dummy1;
+ uint8_t factor;
/* Word 2 */
uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
uint8_t mask_op; /* operator for mask */
#ifdef ENABLE_CONDITIONALS
uint8_t cond; /* conditional type */
- uint8_t dummy2;
#else
- uint8_t dummy2;
- uint8_t dummy3;
+ uint8_t dummy;
#endif
+ uint8_t factor_op;
+#define FILE_FACTOR_OP_PLUS '+'
+#define FILE_FACTOR_OP_MINUS '-'
+#define FILE_FACTOR_OP_TIMES '*'
+#define FILE_FACTOR_OP_DIV '/'
+#define FILE_FACTOR_OP_NONE '\0'
#define FILE_OPS "&|^+-*/%"
#define FILE_OPAND 0