From: Christos Zoulas Date: Wed, 2 Jul 2008 15:22:46 +0000 (+0000) Subject: - strength addition X-Git-Tag: FILE4_25~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad23877fa9a2569844706dc5c371204c01cb920c;p=file - strength addition - magic patches --- diff --git a/ChangeLog b/ChangeLog index 7dfef26f..a6db7587 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-07-02 11:15 Christos Zoulas + + * add !:strength op to adjust magic strength (experimental) + 2008-06-16 21:41 Reuben Thomas * Fix automake error in configure.ac. diff --git a/magic/Magdir/animation b/magic/Magdir/animation index e983549d..443338a6 100644 --- a/magic/Magdir/animation +++ b/magic/Magdir/animation @@ -724,7 +724,8 @@ # X3D (Extensible 3D) [http://www.web3d.org/specifications/x3d-3.0.dtd] # From Michel Briand 0 string \20 search/1000/cb \20 search/1000/cb \ +# 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 diff --git a/magic/Magdir/elf b/magic/Magdir/elf index 2e3db981..891e2ad4 100644 --- a/magic/Magdir/elf +++ b/magic/Magdir/elf @@ -20,6 +20,7 @@ >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 diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems index 0e0db4ac..36c2f72d 100644 --- a/magic/Magdir/filesystems +++ b/magic/Magdir/filesystems @@ -1323,3 +1323,7 @@ 0x10000 belong 0x01161970 GFS2 Filesystem >0x10024 belong x (blocksize %d, >0x10060 string >\0 lockproto %s) + +# dvdisaster's .ecc +# From: "Nelson A. de Oliveira" +0 string *dvdisaster* dvdisaster error correction file diff --git a/magic/Magdir/gimp b/magic/Magdir/gimp index 9a9d61e2..674bbfba 100644 --- a/magic/Magdir/gimp +++ b/magic/Magdir/gimp @@ -34,3 +34,7 @@ # ('Bucky' LaDieu, nega@vt.edu) 20 string GIMP GIMP brush data + +# GIMP Curves File +# From: "Nelson A. de Oliveira" +0 string #\040GIMP\040Curves\040File GIMP curve file diff --git a/magic/Magdir/images b/magic/Magdir/images index aa3ea30e..09fc2a67 100644 --- a/magic/Magdir/images +++ b/magic/Magdir/images @@ -75,11 +75,9 @@ # # 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, @@ -90,7 +88,6 @@ #>>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) @@ -181,15 +178,22 @@ # 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 @@ -535,10 +539,18 @@ # 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 +# Modified by (1): Abel Cheung +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 diff --git a/magic/Magdir/lisp b/magic/Magdir/lisp index 98e097e7..60b740a8 100644 --- a/magic/Magdir/lisp +++ b/magic/Magdir/lisp @@ -39,8 +39,7 @@ # Files produced by CLISP Common Lisp From: Bruno Haible 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 diff --git a/magic/Magdir/misctools b/magic/Magdir/misctools index a8f1f27b..9a43e7b4 100644 --- a/magic/Magdir/misctools +++ b/magic/Magdir/misctools @@ -10,5 +10,12 @@ 4 string gtktalog GNOME Catalogue (gtktalog) >13 string >\0 version %s -# From: Tomasz Trojanowski +# Summary: Libtool library file +# Extension: .la +# Submitted by: Tomasz Trojanowski 0 search/80 .la\ -\ a\ libtool\ library\ file libtool library file + +# Summary: Libtool object file +# Extension: .lo +# Submitted by: Abel Cheung +0 search/80 .lo\ -\ a\ libtool\ object\ file libtool object file diff --git a/magic/Magdir/msdos b/magic/Magdir/msdos index d2e2e226..cdd7c931 100644 --- a/magic/Magdir/msdos +++ b/magic/Magdir/msdos @@ -10,9 +10,9 @@ !: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 @@ -247,11 +247,11 @@ >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 @@ -427,12 +427,16 @@ !: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 (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 diff --git a/magic/Magdir/printer b/magic/Magdir/printer index 17280ab9..15a17582 100644 --- a/magic/Magdir/printer +++ b/magic/Magdir/printer @@ -35,11 +35,13 @@ >>>20 long >0 TIFF starts at byte %d >>>>24 long >0 length %d -# Adobe's PostScript Printer Description (PPD) files -# Yves Arrouye +# 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 # -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 diff --git a/magic/Magdir/windows b/magic/Magdir/windows index 7abb8006..5cde739f 100644 --- a/magic/Magdir/windows +++ b/magic/Magdir/windows @@ -107,3 +107,9 @@ 0 string SHCC3 MS Windows 3.1 registry file +# Summary: Windows Registry text +# Extension: .reg +# Submitted by: Abel Cheung +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) diff --git a/src/apprentice.c b/src/apprentice.c index 6457c882..0f9a01a5 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -49,7 +49,7 @@ #include #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) && \ @@ -95,8 +95,6 @@ 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 *); @@ -116,13 +114,27 @@ private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *, 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 @@ -387,6 +399,8 @@ apprentice_magic_strength(const struct magic *m) switch (m->type) { case FILE_DEFAULT: /* make sure this sorts last */ + if (m->factor_op != FILE_FACTOR_OP_NONE) + abort(); return 0; case FILE_BYTE: @@ -484,6 +498,24 @@ apprentice_magic_strength(const struct magic *m) 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; } @@ -594,15 +626,38 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs, 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)++; } @@ -1041,6 +1096,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, } 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; } @@ -1350,29 +1406,73 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, } /* - * 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; } diff --git a/src/file.h b/src/file.h index ea8e59c7..5bd08e2a 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * 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__ @@ -97,7 +97,7 @@ #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 @@ -117,7 +117,7 @@ struct magic { 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) */ @@ -186,11 +186,15 @@ struct magic { 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