From: Christos Zoulas Date: Thu, 8 Jun 2006 20:53:51 +0000 (+0000) Subject: finish quad support. X-Git-Tag: FILE5_05~736 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0ba2c96938741e45f39747141a9fd91b492c3ed;p=file finish quad support. --- diff --git a/src/apprentice.c b/src/apprentice.c index 67f56681..5e495c41 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -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); } diff --git a/src/file.h b/src/file.h index 8ef2fbaa..1f17c8ab 100644 --- a/src/file.h +++ b/src/file.h @@ -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 #endif +#include /* Do this here and now, because struct stat gets re-defined on solaris */ #include @@ -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; diff --git a/src/print.c b/src/print.c index e7c8098d..9230895b 100644 --- a/src/print.c +++ b/src/print.c @@ -41,7 +41,7 @@ #include #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: