]> granicus.if.org Git - file/commitdiff
add apple creator/type
authorChristos Zoulas <christos@zoulas.com>
Sat, 18 Oct 2008 20:47:47 +0000 (20:47 +0000)
committerChristos Zoulas <christos@zoulas.com>
Sat, 18 Oct 2008 20:47:47 +0000 (20:47 +0000)
19 files changed:
ChangeLog
doc/file.man
doc/magic.man
magic/Magdir/compress
magic/Magdir/images
magic/Magdir/jpeg
magic/Magdir/macintosh
magic/Magdir/printer
src/apprentice.c
src/ascmagic.c
src/file.c
src/file.h
src/file_opts.h
src/fsmagic.c
src/is_tar.c
src/magic.h
src/readcdf.c
src/readelf.c
src/softmagic.c

index 1cd8d3389daab5ea7ec8aed4e117ed23a5591f91..42a5c13281ab5efbfbbba147d14f382f48e33135 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-10-18 16:45  Christos Zoulas <christos@astron.com>
+       
+       * Added APPLE file creator/type
+
 2008-10-12 10:20  Christos Zoulas <christos@astron.com>
 
        * Added CDF parsing
index 4b0468684b10a28fc0551b9aa2c3dd6b617fe74d..f033770ba0ddbbb4f086456b70ca4b8c835afdfa 100644 (file)
@@ -1,4 +1,4 @@
-.\" $File: file.man,v 1.75 2008/10/09 17:25:01 christos Exp $
+.\" $File: file.man,v 1.76 2008/10/18 20:47:47 christos Exp $
 .Dd October 9, 2008
 .Dt FILE __CSECTION__
 .Os
@@ -182,6 +182,8 @@ Check for
 application type (only on EMX).
 .It ascii
 Check for various types of ascii files.
+.It cdf
+Don't look for Compound Document Files.
 .It compress
 Don't look for, or inside compressed files.
 .It elf
index 314a01476af35216d0d18ab7ef1883ac68a0e688..893199a4ec6c1de59346c1890674e7d6e4b051d9 100644 (file)
@@ -1,4 +1,4 @@
-.\" $File: magic.man,v 1.57 2008/08/30 09:50:20 christos Exp $
+.\" $File: magic.man,v 1.58 2008/10/18 20:47:47 christos Exp $
 .Dd August 30, 2008
 .Dt MAGIC __FSECTION__
 .Os
@@ -290,6 +290,11 @@ added before it: multiple matches are normally separated by a single
 space.
 .El
 .Pp
+An APPLE 4+4 character APPLE creator and type can be specified as:
+.Bd -literal -offset indent 
+!:apple        CREATYPE
+.Ed
+.Pp
 A MIME type is given on a separate line, which must be the next
 non-blank or comment line after the magic line that identifies the
 file type, and has the following format:
index e2e4e03261cb3a9f8b10d9f727b0792544534769..016d09320ea544bd20b9a398296047af4b77ae51 100644 (file)
@@ -11,6 +11,7 @@
 # standard unix compress
 0      string          \037\235        compress'd data
 !:mime application/x-compress
+!:apple        LZIVZIVU
 >2     byte&0x80       >0              block compressed
 >2     byte&0x1f       x               %d bits
 
index cccc70be503567712bc0534995ad23d7bb5e081b..22474538a05e004c9b8a068090eabde409527171 100644 (file)
 # GIF
 0      string          GIF8            GIF image data
 !:mime image/gif
+!:apple        8BIMGIFf
 >4     string          7a              \b, version 8%s,
 >4     string          9a              \b, version 8%s,
 >6     leshort         >0              %hd x
index d728de6e6f7f5a44eb6ff2a41e1571c90e3a2fc8..4470be4adf9a5533cc66265455cec6b68fef7046 100644 (file)
@@ -10,6 +10,7 @@
 #
 0      beshort         0xffd8          JPEG image data
 !:mime image/jpeg
+!:apple        8BIMJPEG
 !:strength +1
 >6     string          JFIF            \b, JFIF standard
 # The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06
index 77187a398d67e3c04633eb72cc7d393b8d08dee4..ca665ded8cb875b8fcd2dd2b8a22b4cbb6c0ccb3 100644 (file)
@@ -11,6 +11,8 @@
 # Stuffit archives are the de facto standard of compression for Macintosh
 # files obtained from most archives. (franklsm@tuns.ca)
 0      string          SIT!                    StuffIt Archive (data)
+!:mime application/x-stuffit
+!:apple        SIT!SIT!
 >2     string          x                       : %s
 0      string          SITD                    StuffIt Deluxe (data)
 >2     string          x                       : %s
@@ -20,6 +22,7 @@
 # Newer StuffIt archives (grant@netbsd.org)
 0      string          StuffIt                 StuffIt Archive
 !:mime application/x-stuffit
+!:apple        SIT!SIT!
 #>162  string          >0                      : %s
 
 # Macintosh Applications and Installation binaries (franklsm@tuns.ca)
index 15a175821308fe0e37dce36d919d6191b8afac76..e25d03e977f5cc79ee454c4fd49a1ff924f2806d 100644 (file)
@@ -6,6 +6,7 @@
 # PostScript, updated by Daniel Quinlan (quinlan@yggdrasil.com)
 0      string          %!              PostScript document text
 !:mime application/postscript
+!:apple        ASPSTEXT
 >2     string          PS-Adobe-       conforming
 >>11   string          >\0             DSC level %.3s
 >>>15  string          EPS             \b, type %s
@@ -16,6 +17,7 @@
 # Some PCs have the annoying habit of adding a ^D as a document separator
 0      string          \004%!          PostScript document text
 !:mime application/postscript
+!:apple        ASPSTEXT
 >3     string          PS-Adobe-       conforming
 >>12   string          >\0             DSC level %.3s
 >>>16  string          EPS             \b, type %s
index 244906aaa610f392a11c98709934ea399d6691f9..7ecfd8bd94c827822da274b2c34bf267c49954b3 100644 (file)
@@ -49,7 +49,7 @@
 #include <dirent.h>
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.141 2008/08/31 07:58:00 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.142 2008/10/18 20:47:48 christos Exp $")
 #endif /* lint */
 
 #define        EATAB {while (isascii((unsigned char) *l) && \
@@ -115,8 +115,8 @@ 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 int parse_strength(struct magic_set *, struct magic_entry *, const char *);
+private int parse_apple(struct magic_set *, struct magic_entry *, const char *);
 
 
 private size_t maxmagic = 0;
@@ -131,6 +131,7 @@ private struct {
 } bang[] = {
 #define        DECLARE_FIELD(name) { # name, sizeof(# name) - 1, parse_ ## name }
        DECLARE_FIELD(mime),
+       DECLARE_FIELD(apple),
        DECLARE_FIELD(strength),
 #undef DECLARE_FIELD
        { NULL, 0, NULL }
@@ -1473,6 +1474,38 @@ out:
        return -1;
 }
 
+/*
+ * Parse an Apple CREATOR/TYPE annotation from magic file and put it into magic[index - 1]
+ */
+private int
+parse_apple(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->apple[0] != '\0') {
+               file_magwarn(ms, "Current entry already has a APPLE type `%.8s',"
+                   " new type `%s'", m->mimetype, l);
+               return -1;
+       }       
+
+       EATAB;
+       for (i = 0; *l && ((isascii((unsigned char)*l) && isalnum((unsigned char)*l))
+            || strchr("-+/.", *l)) && i < sizeof(m->apple); m->apple[i++] = *l++)
+               continue;
+       if (i == sizeof(m->apple) && *l) {
+               if (ms->flags & MAGIC_CHECK)
+                       file_magwarn(ms, "APPLE type `%s' truncated %zu",
+                           line, i);
+       }
+
+       if (i > 0)
+               return 0;
+       else
+               return -1;
+}
+
 /*
  * parse a MIME annotation line from magic file, put into magic[index - 1]
  * if valid
@@ -1491,10 +1524,8 @@ parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line)
        }       
 
        EATAB;
-       for (i = 0;
-            *l && ((isascii((unsigned char)*l) && isalnum((unsigned char)*l))
-            || strchr("-+/.", *l)) && i < sizeof(m->mimetype);
-            m->mimetype[i++] = *l++)
+       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';
index 841dea000caa3560fcdd02aa49a3445f59d41b93..c40942f975070da139ecc2df2485c51a9f5e2dba 100644 (file)
@@ -49,7 +49,7 @@
 #include "names.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.66 2008/10/16 16:31:16 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.67 2008/10/18 20:47:48 christos Exp $")
 #endif /* lint */
 
 #define MAXLINELEN 300 /* longest sane line length */
@@ -97,6 +97,9 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
        size_t last_line_end = (size_t)-1;
        int has_long_lines = 0;
 
+       if (ms->flags & MAGIC_APPLE)
+               return 0;
+
        /*
         * Undo the NUL-termination kindly provided by process()
         * but leave at least one byte to look at
index effa06a07839940184502d98ed186ad5680b84be..ab3e6c593bdc0679f7f41c3f12570b12d6022cdb 100644 (file)
@@ -74,7 +74,7 @@ int getopt_long(int argc, char * const *argv, const char *optstring, const struc
 #include "patchlevel.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: file.c,v 1.125 2008/10/12 15:38:51 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.126 2008/10/18 20:47:48 christos Exp $")
 #endif /* lint */
 
 
@@ -193,9 +193,12 @@ main(int argc, char *argv[])
                                help();
                                break;
                        case 10:
-                               flags |= MAGIC_MIME_TYPE;
+                               flags |= MAGIC_APPLE;
                                break;
                        case 11:
+                               flags |= MAGIC_MIME_TYPE;
+                               break;
+                       case 12:
                                flags |= MAGIC_MIME_ENCODING;
                                break;
                        }
index 668bfb25bad49e7700a51e70f08aa11ca8ce4897..230888213e361df9f6eb6f41f8caec9e36e9f78b 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.110 2008/10/12 15:38:52 christos Exp $
+ * @(#)$File: file.h,v 1.111 2008/10/18 20:47:48 christos Exp $
  */
 
 #ifndef __file_h__
 #define MAXstring 32           /* max leng of "string" types */
 
 #define MAGICNO                0xF11E041C
-#define VERSIONNO      6
-#define FILE_MAGICSIZE (32 * 6)
+#define VERSIONNO      7
+#define FILE_MAGICSIZE 200
 
 #define        FILE_LOAD       0
 #define FILE_CHECK     1
@@ -258,10 +258,12 @@ struct magic {
 #define str_flags _u._s._flags
        /* Words 9-16 */
        union VALUETYPE value;          /* either number or string */
-       /* Words 17..31 */
+       /* Words 17-25 */
        char desc[MAXDESC];     /* description */
-       /* Words 32..47 */
+       /* Words 26-34 */
        char mimetype[MAXDESC]; /* MIME type */
+       /* Words 35-43 */
+       char apple[8];
 };
 
 #define BIT(A)   (1 << (A))
index 46bc08ae4b4e40429acc6647f2c2096247b9d66d..f38354adb13eed0cd7699cbebb2a04d880780a4e 100644 (file)
@@ -28,6 +28,7 @@ OPT('f', "files-from", 1, " FILE      read the filenames to be examined from FIL
 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("apple", 0, "            output the APPLE CREATOR/TYPE\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")
index 0d05549332030478de1149286de1a8120d463755..d643f1f19897563a88912430f087690129ad011f 100644 (file)
@@ -57,7 +57,7 @@
 #undef HAVE_MAJOR
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.53 2008/10/16 16:31:16 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.54 2008/10/18 20:47:48 christos Exp $")
 #endif /* lint */
 
 private int
@@ -106,6 +106,8 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
        struct stat tstatbuf;
 #endif
 
+       if (ms->flags & MAGIC_APPLE)
+               return 0;
        if (fn == NULL)
                return 0;
 
index a9311117ed24095c953269b05c0eed179af9a78b..98ff73718f21eea7d9ab36a7eccb9037b1b82ab8 100644 (file)
@@ -45,7 +45,7 @@
 #include "tar.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.31 2008/02/04 20:51:17 christos Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.32 2008/10/18 20:47:48 christos Exp $")
 #endif
 
 #define        isodigit(c)     ( ((c) >= '0') && ((c) <= '7') )
@@ -66,13 +66,14 @@ 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.
         */
-       int tar = is_tar(buf, nbytes);
+       int tar;
        int mime = ms->flags & MAGIC_MIME;
 
-       if (tar < 1 || tar > 3)
+       if ((ms->flags & MAGIC_APPLE) != 0 || mime == MAGIC_MIME_ENCODING)
                return 0;
 
-       if (mime == MAGIC_MIME_ENCODING)
+       tar = is_tar(buf, nbytes);
+       if (tar < 1 || tar > 3)
                return 0;
 
        if (file_printf(ms, mime ? "application/x-tar" :
index 2c085701afa0a1620022865c0d096e74065ba7b6..5ff78a29b1e60b781321de53bf3fa98b1a13b577 100644 (file)
@@ -42,6 +42,7 @@
 #define        MAGIC_ERROR             0x000200 /* Handle ENOENT etc as real errors */
 #define        MAGIC_MIME_ENCODING     0x000400 /* Return only the MIME encoding */
 #define MAGIC_MIME             (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
+#define        MAGIC_APPLE             0x000800 /* Return APPLE CREATOR/TYPE */
 #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 */
index d4de5d2f21fb6810856b42c0ccf5d30aeb78b5cf..5908473fd11c9bd2da2454c7fbb8f84d1950d2f1 100644 (file)
@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.6 2008/10/14 10:38:22 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.7 2008/10/18 20:47:48 christos Exp $")
 #endif
 
 #include <stdio.h>
@@ -191,6 +191,8 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
        (void)&nbytes;
        (void)&buf;
 
+       if (ms->flags & MAGIC_APPLE)
+               return 0;
        if (cdf_read_header(fd, &h) == -1)
                return 0;
 #ifdef CDF_DEBUG
index 57aa200d3367517005c4465f081df315bdd7d520..31b363113760e05ac911354e6314ab6dcebc3fbe 100644 (file)
@@ -38,7 +38,7 @@
 #include "magic.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.79 2008/10/12 19:06:36 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.80 2008/10/18 20:47:48 christos Exp $")
 #endif
 
 #ifdef ELFCORE
@@ -1141,7 +1141,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
        Elf64_Ehdr elf64hdr;
        uint16_t type;
 
-       if (ms->flags & MAGIC_MIME)
+       if (ms->flags & (MAGIC_MIME|MAGIC_APPLE))
                return 0;
        /*
         * ELF executables have multiple section headers in arbitrary
index ac2b8befc9405708a52dd063f9e02c5b8bcab96c..5eab3f6857fbd36041538f76a65ade0e51138a20 100644 (file)
@@ -38,7 +38,7 @@
 
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.123 2008/10/16 16:31:16 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.124 2008/10/18 20:47:48 christos Exp $")
 #endif /* lint */
 
 private int match(struct magic_set *, struct magic *, uint32_t,
@@ -52,7 +52,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
     const unsigned char *, uint32_t, size_t, size_t);
 private int mconvert(struct magic_set *, struct magic *);
 private int print_sep(struct magic_set *, int);
-private int handle_mime(struct magic_set *, struct magic *);
+private int handle_annotation(struct magic_set *, struct magic *);
 private void cvt_8(union VALUETYPE *, const struct magic *);
 private void cvt_16(union VALUETYPE *, const struct magic *);
 private void cvt_32(union VALUETYPE *, const struct magic *);
@@ -168,7 +168,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
                if (*m->desc) {
                        need_separator = 1;
                        printed_something = 1;
-                       if ((e = handle_mime(ms, m)) != 0)
+                       if ((e = handle_annotation(ms, m)) != 0)
                                return e;
                        if (print_sep(ms, firstline) == -1)
                                return -1;
@@ -236,7 +236,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
                                 */
                                if (*m->desc) {
                                        printed_something = 1;
-                                       if ((e = handle_mime(ms, m)) != 0)
+                                       if ((e = handle_annotation(ms, m)) != 0)
                                                return e;
                                        if (print_sep(ms, firstline) == -1)
                                                return -1;
@@ -1592,7 +1592,8 @@ magiccheck(struct magic_set *ms, struct magic *m)
        
                default:
                        matched = 0;
-                       file_magerror(ms, "cannot happen with float: invalid relation `%c'", m->reln);
+                       file_magerror(ms, "cannot happen with float: invalid relation `%c'",
+                           m->reln);
                        return -1;
                }
                return matched;
@@ -1820,10 +1821,17 @@ magiccheck(struct magic_set *ms, struct magic *m)
 }
 
 private int
-handle_mime(struct magic_set *ms, struct magic *m)
+handle_annotation(struct magic_set *ms, struct magic *m)
 {
-       if (ms->flags & MAGIC_MIME_TYPE)
-               return file_printf(ms, "%s", m->mimetype);
+       if (ms->flags & MAGIC_APPLE) {
+               if (file_printf(ms, "%.8s", m->apple) == -1)
+                       return -1;
+               return 1;
+       }
+       if (ms->flags & MAGIC_MIME_TYPE) {
+               if (file_printf(ms, "%.8s", m->mimetype) == -1)
+               return 1;
+       }
        return 0;
 }