version 1.13, 2007/09/14 14:29:20 |
version 1.14, 2008/05/08 01:40:56 |
|
|
protected void |
protected void |
file_mdump(struct magic *m) |
file_mdump(struct magic *m) |
{ |
{ |
private const char *typ[] = { "invalid", "byte", "short", "invalid", |
private const char optyp[] = { FILE_OPS }; |
"long", "string", "date", "beshort", |
|
"belong", "bedate", "leshort", "lelong", |
(void) fprintf(stderr, "[%u", m->lineno); |
"ledate", "pstring", "ldate", "beldate", |
(void) fprintf(stderr, ">>>>>>>> %u" + 8 - (m->cont_level & 7), |
"leldate", "regex" }; |
|
private const char optyp[] = { '@', '&', '|', '^', '+', '-', |
|
'*', '/', '%' }; |
|
(void) fputc('[', stderr); |
|
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7), |
|
m->offset); |
m->offset); |
|
|
if (m->flag & INDIR) { |
if (m->flag & INDIR) { |
(void) fprintf(stderr, "(%s,", |
(void) fprintf(stderr, "(%s,", |
/* Note: type is unsigned */ |
/* Note: type is unsigned */ |
(m->in_type < SZOF(typ)) ? |
(m->in_type < file_nnames) ? |
typ[m->in_type] : "*bad*"); |
file_names[m->in_type] : "*bad*"); |
if (m->in_op & FILE_OPINVERSE) |
if (m->in_op & FILE_OPINVERSE) |
(void) fputc('~', stderr); |
(void) fputc('~', stderr); |
(void) fprintf(stderr, "%c%d),", |
(void) fprintf(stderr, "%c%u),", |
((m->in_op&0x7F) < SZOF(optyp)) ? |
((m->in_op & FILE_OPS_MASK) < SZOF(optyp)) ? |
optyp[m->in_op&0x7F] : '?', |
optyp[m->in_op & FILE_OPS_MASK] : '?', |
m->in_offset); |
m->in_offset); |
} |
} |
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "", |
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "", |
/* Note: type is unsigned */ |
/* Note: type is unsigned */ |
(m->type < SZOF(typ)) ? typ[m->type] : "*bad*"); |
(m->type < file_nnames) ? file_names[m->type] : "*bad*"); |
if (m->mask_op & FILE_OPINVERSE) |
if (m->mask_op & FILE_OPINVERSE) |
(void) fputc('~', stderr); |
(void) fputc('~', stderr); |
if (m->mask) { |
|
if ((m->mask_op & 0x7F) < SZOF(optyp)) |
if (IS_STRING(m->type)) { |
fputc(optyp[m->mask_op&0x7F], stderr); |
if (m->str_flags) { |
else |
(void) fputc('/', stderr); |
fputc('?', stderr); |
if (m->str_flags & STRING_COMPACT_BLANK) |
if(FILE_STRING != m->type || FILE_PSTRING != m->type) |
|
(void) fprintf(stderr, "%.8x", m->mask); |
|
else { |
|
if (m->mask & STRING_IGNORE_LOWERCASE) |
|
(void) fputc(CHAR_IGNORE_LOWERCASE, stderr); |
|
if (m->mask & STRING_COMPACT_BLANK) |
|
(void) fputc(CHAR_COMPACT_BLANK, stderr); |
(void) fputc(CHAR_COMPACT_BLANK, stderr); |
if (m->mask & STRING_COMPACT_OPTIONAL_BLANK) |
if (m->str_flags & STRING_COMPACT_OPTIONAL_BLANK) |
(void) fputc(CHAR_COMPACT_OPTIONAL_BLANK, |
(void) fputc(CHAR_COMPACT_OPTIONAL_BLANK, |
stderr); |
stderr); |
|
if (m->str_flags & STRING_IGNORE_LOWERCASE) |
|
(void) fputc(CHAR_IGNORE_LOWERCASE, stderr); |
|
if (m->str_flags & STRING_IGNORE_UPPERCASE) |
|
(void) fputc(CHAR_IGNORE_UPPERCASE, stderr); |
|
if (m->str_flags & REGEX_OFFSET_START) |
|
(void) fputc(CHAR_REGEX_OFFSET_START, stderr); |
} |
} |
|
if (m->str_count) |
|
(void) fprintf(stderr, "/%u", m->str_count); |
} |
} |
|
else { |
|
if ((m->mask_op & FILE_OPS_MASK) < SZOF(optyp)) |
|
(void) fputc(optyp[m->mask_op & FILE_OPS_MASK], stderr); |
|
else |
|
(void) fputc('?', stderr); |
|
|
|
if (m->num_mask) { |
|
(void) fprintf(stderr, "%.8llx", |
|
(unsigned long long)m->num_mask); |
|
} |
|
} |
(void) fprintf(stderr, ",%c", m->reln); |
(void) fprintf(stderr, ",%c", m->reln); |
|
|
if (m->reln != 'x') { |
if (m->reln != 'x') { |
|
|
case FILE_LONG: |
case FILE_LONG: |
case FILE_LESHORT: |
case FILE_LESHORT: |
case FILE_LELONG: |
case FILE_LELONG: |
|
case FILE_MELONG: |
case FILE_BESHORT: |
case FILE_BESHORT: |
case FILE_BELONG: |
case FILE_BELONG: |
(void) fprintf(stderr, "%d", m->value.l); |
(void) fprintf(stderr, "%d", m->value.l); |
break; |
break; |
case FILE_STRING: |
case FILE_BEQUAD: |
|
case FILE_LEQUAD: |
|
case FILE_QUAD: |
|
(void) fprintf(stderr, "%lld", |
|
(unsigned long long)m->value.q); |
|
break; |
case FILE_PSTRING: |
case FILE_PSTRING: |
|
case FILE_STRING: |
case FILE_REGEX: |
case FILE_REGEX: |
file_showstr(stderr, m->value.s, ~0U); |
case FILE_BESTRING16: |
|
case FILE_LESTRING16: |
|
case FILE_SEARCH: |
|
file_showstr(stderr, m->value.s, (size_t)m->vallen); |
break; |
break; |
case FILE_DATE: |
case FILE_DATE: |
case FILE_LEDATE: |
case FILE_LEDATE: |
case FILE_BEDATE: |
case FILE_BEDATE: |
|
case FILE_MEDATE: |
(void)fprintf(stderr, "%s,", |
(void)fprintf(stderr, "%s,", |
file_fmttime(m->value.l, 1)); |
file_fmttime(m->value.l, 1)); |
break; |
break; |
case FILE_LDATE: |
case FILE_LDATE: |
case FILE_LELDATE: |
case FILE_LELDATE: |
case FILE_BELDATE: |
case FILE_BELDATE: |
|
case FILE_MELDATE: |
(void)fprintf(stderr, "%s,", |
(void)fprintf(stderr, "%s,", |
file_fmttime(m->value.l, 0)); |
file_fmttime(m->value.l, 0)); |
break; |
break; |
|
case FILE_QDATE: |
|
case FILE_LEQDATE: |
|
case FILE_BEQDATE: |
|
(void)fprintf(stderr, "%s,", |
|
file_fmttime((uint32_t)m->value.q, 1)); |
|
break; |
|
case FILE_QLDATE: |
|
case FILE_LEQLDATE: |
|
case FILE_BEQLDATE: |
|
(void)fprintf(stderr, "%s,", |
|
file_fmttime((uint32_t)m->value.q, 0)); |
|
break; |
|
case FILE_DEFAULT: |
|
/* XXX - do anything here? */ |
|
break; |
default: |
default: |
(void) fputs("*bad*", stderr); |
(void) fputs("*bad*", stderr); |
break; |
break; |
|
|
|
|
/*VARARGS*/ |
/*VARARGS*/ |
protected void |
protected void |
file_magwarn(const char *f, ...) |
file_magwarn(struct magic_set *ms, const char *f, ...) |
{ |
{ |
va_list va; |
va_list va; |
va_start(va, f); |
va_start(va, f); |
|
|
/* cuz we use stdout for most, stderr here */ |
/* cuz we use stdout for most, stderr here */ |
(void) fflush(stdout); |
(void) fflush(stdout); |
|
|
(void) fprintf(stderr, "WARNING: "); |
(void) fprintf(stderr, "%s, %lu: Warning ", ms->file, |
|
(unsigned long)ms->line); |
(void) vfprintf(stderr, f, va); |
(void) vfprintf(stderr, f, va); |
va_end(va); |
va_end(va); |
fputc('\n', stderr); |
(void) fputc('\n', stderr); |
} |
} |
|
|
protected char * |
protected const char * |
file_fmttime(uint32_t v, int local) |
file_fmttime(uint32_t v, int local) |
{ |
{ |
char *pp; |
char *pp; |
|
|
struct tm *tm1; |
struct tm *tm1; |
(void)time(&now); |
(void)time(&now); |
tm1 = localtime(&now); |
tm1 = localtime(&now); |
|
if (tm1 == NULL) |
|
return "*Invalid time*"; |
daylight = tm1->tm_isdst; |
daylight = tm1->tm_isdst; |
} |
} |
#endif /* HAVE_TM_ISDST */ |
#endif /* HAVE_TM_ISDST */ |
|
|
if (daylight) |
if (daylight) |
t += 3600; |
t += 3600; |
tm = gmtime(&t); |
tm = gmtime(&t); |
|
if (tm == NULL) |
|
return "*Invalid time*"; |
pp = asctime(tm); |
pp = asctime(tm); |
} |
} |
|
|