From 11297895fb724ae95722b1dd6816dba197a979de Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Fri, 6 Apr 2012 21:15:54 +0000 Subject: [PATCH] - add more debugging for indirect offsets. - only print the description for indirect offsets if a match was found, and add the offset as the number to print. --- src/softmagic.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/softmagic.c b/src/softmagic.c index 3c47374b..e5aeeea4 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.148 2012/04/03 22:25:07 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.149 2012/04/06 21:15:54 christos Exp $") #endif /* lint */ #include "magic.h" @@ -1034,6 +1034,8 @@ mget(struct magic_set *ms, const unsigned char *s, { uint32_t offset = ms->offset; uint32_t count = m->str_range; + int rv; + char *sbuf, *rbuf; union VALUETYPE *p = &ms->ms_value; if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1) @@ -1082,6 +1084,8 @@ mget(struct magic_set *ms, const unsigned char *s, (q->hl[3]<<8)|(q->hl[2])); break; } + if ((ms->flags & MAGIC_DEBUG) != 0) + fprintf(stderr, "indirect offs=%u\n", off); } switch (m->in_type) { case FILE_BYTE: @@ -1522,6 +1526,8 @@ mget(struct magic_set *ms, const unsigned char *s, if (m->flag & INDIROFFADD) { offset += ms->c.li[cont_level-1].off; + if ((ms->flags & MAGIC_DEBUG) != 0) + fprintf(stderr, "indirect +offs=%u\n", offset); } if (mcopy(ms, p, m->type, 0, s, offset, nbytes, count) == -1) return -1; @@ -1589,13 +1595,26 @@ mget(struct magic_set *ms, const unsigned char *s, break; case FILE_INDIRECT: - if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 && - file_printf(ms, "%s", m->desc) == -1) - return -1; if (nbytes < offset) return 0; - return file_softmagic(ms, s + offset, nbytes - offset, + sbuf = ms->o.buf; + ms->o.buf = NULL; + rv = file_softmagic(ms, s + offset, nbytes - offset, BINTEST, text); + if ((ms->flags & MAGIC_DEBUG) != 0) + fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv); + if (rv == 1) { + rbuf = ms->o.buf; + ms->o.buf = sbuf; + if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 && + file_printf(ms, m->desc, offset) == -1) + return -1; + if (file_printf(ms, "%s", rbuf) == -1) + return -1; + free(rbuf); + } else + ms->o.buf = sbuf; + return rv; case FILE_DEFAULT: /* nothing to check */ default: -- 2.50.0