version 1.7, 2002/02/17 19:42:30 |
version 1.8, 2002/06/05 13:46:44 |
|
|
static int match(unsigned char *, int); |
static int match(unsigned char *, int); |
static int mget(union VALUETYPE *, unsigned char *, struct magic *, int); |
static int mget(union VALUETYPE *, unsigned char *, struct magic *, int); |
static int mcheck(union VALUETYPE *, struct magic *); |
static int mcheck(union VALUETYPE *, struct magic *); |
static int32 mprint(union VALUETYPE *, struct magic *); |
static int32_t mprint(union VALUETYPE *, struct magic *); |
static void mdebug(int32, char *, int); |
static void mdebug(int32_t, char *, int); |
static int mconvert(union VALUETYPE *, struct magic *); |
static int mconvert(union VALUETYPE *, struct magic *); |
|
|
/* |
/* |
|
|
int cont_level = 0; |
int cont_level = 0; |
int need_separator = 0; |
int need_separator = 0; |
union VALUETYPE p; |
union VALUETYPE p; |
static int32 *tmpoff = NULL; |
static int32_t *tmpoff = NULL; |
static size_t tmplen = 0; |
static size_t tmplen = 0; |
int32 oldoff = 0; |
int32_t oldoff = 0; |
|
|
if (tmpoff == NULL) |
if (tmpoff == NULL) |
if ((tmpoff = (int32 *) malloc(tmplen = 20)) == NULL) |
if ((tmpoff = (int32_t *) malloc(tmplen = 20)) == NULL) |
err(1, "malloc"); |
err(1, "malloc"); |
|
|
for (magindex = 0; magindex < nmagic; magindex++) { |
for (magindex = 0; magindex < nmagic; magindex++) { |
|
|
need_separator = 1; |
need_separator = 1; |
/* and any continuations that match */ |
/* and any continuations that match */ |
if (++cont_level >= tmplen) |
if (++cont_level >= tmplen) |
if ((tmpoff = (int32 *) realloc(tmpoff, |
if ((tmpoff = (int32_t *) realloc(tmpoff, |
tmplen += 20)) == NULL) |
tmplen += 20)) == NULL) |
err(1, "malloc"); |
err(1, "malloc"); |
while (magic[magindex+1].cont_level != 0 && |
while (magic[magindex+1].cont_level != 0 && |
|
|
*/ |
*/ |
if (++cont_level >= tmplen) |
if (++cont_level >= tmplen) |
if ((tmpoff = |
if ((tmpoff = |
(int32 *) realloc(tmpoff, |
(int32_t *) realloc(tmpoff, |
tmplen += 20)) == NULL) |
tmplen += 20)) == NULL) |
err(1, "malloc"); |
err(1, "malloc"); |
} |
} |
|
|
return 0; /* no match at all */ |
return 0; /* no match at all */ |
} |
} |
|
|
static int32 |
static int32_t |
mprint(p, m) |
mprint(p, m) |
union VALUETYPE *p; |
union VALUETYPE *p; |
struct magic *m; |
struct magic *m; |
{ |
{ |
char *pp, *rt; |
char *pp, *rt; |
uint32 v; |
uint32_t v; |
int32 t=0 ; |
int32_t t=0 ; |
|
|
|
|
switch (m->type) { |
switch (m->type) { |
|
|
case LELONG: |
case LELONG: |
v = p->l; |
v = p->l; |
v = signextend(m, v) & m->mask; |
v = signextend(m, v) & m->mask; |
(void) printf(m->desc, (uint32) v); |
(void) printf(m->desc, (uint32_t) v); |
t = m->offset + sizeof(int32); |
t = m->offset + sizeof(int32_t); |
break; |
break; |
|
|
case STRING: |
case STRING: |
|
|
return 1; |
return 1; |
case BELONG: |
case BELONG: |
case BEDATE: |
case BEDATE: |
p->l = (int32) |
p->l = (int32_t) |
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3])); |
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3])); |
return 1; |
return 1; |
case LESHORT: |
case LESHORT: |
|
|
return 1; |
return 1; |
case LELONG: |
case LELONG: |
case LEDATE: |
case LEDATE: |
p->l = (int32) |
p->l = (int32_t) |
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0])); |
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0])); |
return 1; |
return 1; |
default: |
default: |
|
|
|
|
static void |
static void |
mdebug(offset, str, len) |
mdebug(offset, str, len) |
int32 offset; |
int32_t offset; |
char *str; |
char *str; |
int len; |
int len; |
{ |
{ |
|
|
struct magic *m; |
struct magic *m; |
int nbytes; |
int nbytes; |
{ |
{ |
int32 offset = m->offset; |
int32_t offset = m->offset; |
|
|
if (offset + sizeof(union VALUETYPE) <= nbytes) |
if (offset + sizeof(union VALUETYPE) <= nbytes) |
memcpy(p, s + offset, sizeof(union VALUETYPE)); |
memcpy(p, s + offset, sizeof(union VALUETYPE)); |
|
|
* the usefulness of padding with zeroes eludes me, it |
* the usefulness of padding with zeroes eludes me, it |
* might even cause problems |
* might even cause problems |
*/ |
*/ |
int32 have = nbytes - offset; |
int32_t have = nbytes - offset; |
memset(p, 0, sizeof(union VALUETYPE)); |
memset(p, 0, sizeof(union VALUETYPE)); |
if (have > 0) |
if (have > 0) |
memcpy(p, s + offset, have); |
memcpy(p, s + offset, have); |
|
|
union VALUETYPE* p; |
union VALUETYPE* p; |
struct magic *m; |
struct magic *m; |
{ |
{ |
uint32 l = m->value.l; |
uint32_t l = m->value.l; |
uint32 v; |
uint32_t v; |
int matched; |
int matched; |
|
|
if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) { |
if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) { |
|
|
v, l, matched); |
v, l, matched); |
} |
} |
else { |
else { |
matched = (int32) v > (int32) l; |
matched = (int32_t) v > (int32_t) l; |
if (debug) |
if (debug) |
(void) fprintf(stderr, "%d > %d = %d\n", |
(void) fprintf(stderr, "%d > %d = %d\n", |
v, l, matched); |
v, l, matched); |
|
|
v, l, matched); |
v, l, matched); |
} |
} |
else { |
else { |
matched = (int32) v < (int32) l; |
matched = (int32_t) v < (int32_t) l; |
if (debug) |
if (debug) |
(void) fprintf(stderr, "%d < %d = %d\n", |
(void) fprintf(stderr, "%d < %d = %d\n", |
v, l, matched); |
v, l, matched); |