#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) && \
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 *);
/*
* 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) {
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:
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;
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);
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);
}
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
*/
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);
}
*/
/*
* 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__
#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>
#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", \
/* 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"
/* 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 */
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 */
uint8_t b;
uint16_t h;
uint32_t l;
+ uint64_t q;
char s[MAXstring];
struct {
char *buf;
} 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 */
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 *);
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;
#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]))
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: