]> granicus.if.org Git - file/commitdiff
finish quad support.
authorChristos Zoulas <christos@zoulas.com>
Thu, 8 Jun 2006 20:53:51 +0000 (20:53 +0000)
committerChristos Zoulas <christos@zoulas.com>
Thu, 8 Jun 2006 20:53:51 +0000 (20:53 +0000)
src/apprentice.c
src/file.h
src/print.c

index 67f56681be5de8946aae33625dd7773b80d65f18..5e495c4155072a6abf8474ffbbf27548172b5ea6 100644 (file)
@@ -45,7 +45,7 @@
 #endif
 
 #ifndef        lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.92 2006/06/01 21:37:07 ian Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.93 2006/06/08 20:53:51 christos Exp $")
 #endif /* lint */
 
 #define        EATAB {while (isascii((unsigned char) *l) && \
@@ -102,6 +102,7 @@ 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 int apprentice_map(struct magic_set *, struct magic **, uint32_t *,
     const char *);
@@ -458,8 +459,8 @@ out:
 /*
  * extend the sign bit if the comparison is to be signed
  */
-protected uint32_t
-file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
+protected uint64_t
+file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
 {
        if (!(m->flag & UNSIGNED))
                switch(m->type) {
@@ -490,6 +491,11 @@ file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
                case FILE_MELONG:
                        v = (int32_t) v;
                        break;
+               case FILE_QUAD:
+               case FILE_BEQUAD:
+               case FILE_LEQUAD:
+                       v = (int64_t) v;
+                       break;
                case FILE_STRING:
                case FILE_PSTRING:
                case FILE_BESTRING16:
@@ -519,7 +525,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
        const char *l = line;
        char *t;
        private const char *fops = FILE_OPS;
-       uint32_t val;
+       uint64_t val;
        uint32_t cont_level;
 
        cont_level = 0;
@@ -816,7 +822,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
                if (op != FILE_OPDIVIDE || !IS_PLAINSTRING(m->type)) {
                        ++l;
                        m->mask_op |= op;
-                       val = (uint32_t)strtoul(l, &t, 0);
+                       val = (uint64_t)strtoull(l, &t, 0);
                        l = t;
                        m->mask = file_signextend(ms, m, val);
                        eatsize(&l);
@@ -1000,8 +1006,8 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p)
        default:
                if (m->reln != 'x') {
                        char *ep;
-                       m->value.l = file_signextend(ms, m,
-                           (uint32_t)strtoul(*p, &ep, 0));
+                       m->value.q = file_signextend(ms, m,
+                           (uint64_t)strtoull(*p, &ep, 0));
                        *p = ep;
                        eatsize(p);
                }
@@ -1406,6 +1412,26 @@ swap4(uint32_t sv)
        return rv;
 }
 
+/*
+ * swap a quad
+ */
+private uint64_t
+swap8(uint64_t sv)
+{
+       uint32_t rv;
+       uint8_t *s = (uint8_t *)(void *)&sv; 
+       uint8_t *d = (uint8_t *)(void *)&rv; 
+       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];
+       return rv;
+}
+
 /*
  * byteswap a single magic entry
  */
@@ -1416,6 +1442,6 @@ bs1(struct magic *m)
        m->offset = swap4((uint32_t)m->offset);
        m->in_offset = swap4((uint32_t)m->in_offset);
        if (!IS_STRING(m->type))
-               m->value.l = swap4(m->value.l);
-       m->mask = swap4(m->mask);
+               m->value.q = swap8(m->value.q);
+       m->mask = swap8(m->mask);
 }
index 8ef2fbaa49bdf5dcdd61456ec6a22292a0d27a33..1f17c8abe466312ab5fe0d21f0ced1dc5b53b4b0 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.73 2005/10/20 14:59:01 christos Exp $
+ * @(#)$Id: file.h,v 1.74 2006/06/08 20:53:51 christos Exp $
  */
 
 #ifndef __file_h__
@@ -46,6 +46,7 @@
 #ifdef HAVE_INTTYPES_H
 #include <inttypes.h>
 #endif
+#include <sys/types.h>
 /* Do this here and now, because struct stat gets re-defined on solaris */
 #include <sys/stat.h>
 
@@ -116,6 +117,9 @@ struct magic {
 #define                                FILE_MEDATE     21
 #define                                FILE_MELDATE    22
 #define                                FILE_MELONG     23
+#define                                FILE_QUAD       24
+#define                                FILE_LEQUAD     25
+#define                                FILE_BEQUAD     26
 
 #define                                FILE_FORMAT_NAME        \
 /* 0 */                        "invalid 0",            \
@@ -141,7 +145,10 @@ struct magic {
 /* 20 */                       "search",               \
 /* 21 */                       "medate",               \
 /* 22 */                       "meldate",              \
-/* 23 */                       "melong",
+/* 23 */                       "melong",               \
+/* 24 */                       "quad",                 \
+/* 25 */                       "lequad",               \
+/* 26 */                       "bequad",
 
 #define        FILE_FMT_NUM    "cduxXi"
 #define FILE_FMT_STR   "s"     
@@ -170,7 +177,10 @@ struct magic {
 /* 20 */                       FILE_FMT_STR,           \
 /* 21 */                       FILE_FMT_STR,           \
 /* 22 */                       FILE_FMT_STR,           \
-/* 23 */                       FILE_FMT_NUM,
+/* 23 */                       FILE_FMT_NUM,           \
+/* 24 */                       FILE_FMT_NUM,           \
+/* 25 */                       FILE_FMT_NUM,           \
+/* 26 */                       FILE_FMT_NUM,
 
        /* Word 3 */
        uint8_t in_op;          /* operator for indirection */
@@ -192,10 +202,8 @@ struct magic {
        uint32_t offset;        /* offset to magic number */
        /* Word 5 */
        int32_t in_offset;      /* offset from indirection */
-       /* Word 6 */
-       uint32_t mask;  /* mask before comparison with value */
-       /* Word 7 */
-       uint32_t dummy3;
+       /* Word 6,7 */
+       uint64_t mask;  /* mask before comparison with value */
        /* Word 8 */
        uint32_t dummp4;
        /* Words 9-16 */
@@ -203,6 +211,7 @@ struct magic {
                uint8_t b;
                uint16_t h;
                uint32_t l;
+               uint64_t q;
                char s[MAXstring];
                struct {
                        char *buf;
@@ -210,6 +219,7 @@ struct magic {
                } search;
                uint8_t hs[2];  /* 2 bytes of a fixed-endian "short" */
                uint8_t hl[4];  /* 4 bytes of a fixed-endian "long" */
+               uint8_t hq[8];  /* 8 bytes of a fixed-endian "quad" */
        } value;                /* either number or string */
        /* Words 17..31 */
        char desc[MAXDESC];     /* description */
@@ -270,7 +280,7 @@ 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 struct mlist *file_apprentice(struct magic_set *, const char *, int);
-protected uint32_t file_signextend(struct magic_set *, struct magic *, uint32_t);
+protected uint64_t file_signextend(struct magic_set *, struct magic *, uint64_t);
 protected void file_delmagic(struct magic *, int type, size_t entries);
 protected void file_badread(struct magic_set *);
 protected void file_badseek(struct magic_set *);
@@ -281,6 +291,7 @@ protected void file_mdump(struct magic *);
 protected void file_showstr(FILE *, const char *, size_t);
 protected size_t file_mbswidth(const char *);
 protected const char *file_getbuffer(struct magic_set *);
+protected ssize_t sread(int, void *, size_t);
 
 #ifndef HAVE_STRERROR
 extern int sys_nerr;
index e7c8098d699e11070081971b2f9dfa70338d3358..9230895b0822808f49f9a3f7508ac3ec325a2674 100644 (file)
@@ -41,7 +41,7 @@
 #include <time.h>
 
 #ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.50 2006/03/02 22:07:53 christos Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.51 2006/06/08 20:53:51 christos Exp $")
 #endif  /* lint */
 
 #define SZOF(a)        (sizeof(a) / sizeof(a[0]))
@@ -106,6 +106,11 @@ file_mdump(struct magic *m)
                case FILE_BELONG:
                        (void) fprintf(stderr, "%d", m->value.l);
                        break;
+               case FILE_BEQUAD:
+               case FILE_LEQUAD:
+               case FILE_QUAD:
+                       (void) fprintf(stderr, "%lld", m->value.q);
+                       break;
                case FILE_PSTRING:
                case FILE_STRING:
                case FILE_REGEX: