#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"
{
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)
(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:
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;
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: