Lines Matching refs:m

230 		struct magic *m = &magic[magindex];  in match()  local
232 if (m->type != FILE_NAME) in match()
233 if ((IS_LIBMAGIC_STRING(m->type) && in match()
235 ((text && (m->str_flags & FLT) == STRING_BINTEST) || in match()
236 (!text && (m->str_flags & FLT) == STRING_TEXTTEST))) || in match()
237 (m->flag & mode) != mode) { in match()
247 if (msetoffset(ms, m, &bb, b, offset, cont_level) == -1) in match()
249 ms->line = m->lineno; in match()
252 switch (mget(ms, m, b, CAST(const unsigned char *, bb.fbuf), in match()
260 flush = m->reln != '!'; in match()
263 if (m->type == FILE_INDIRECT) { in match()
268 switch (magiccheck(ms, m)) { in match()
288 if (*m->desc) in match()
291 if ((e = handle_annotation(ms, m, firstline)) != 0) in match()
303 if (print && *m->desc) { in match()
309 if (mprint(ms, m) == -1) in match()
313 switch (moffset(ms, m, &bb, &ms->c.li[cont_level].off)) { in match()
327 m = &magic[++magindex]; in match()
328 ms->line = m->lineno; /* for messages */ in match()
330 if (cont_level < m->cont_level) in match()
332 if (cont_level > m->cont_level) { in match()
337 cont_level = m->cont_level; in match()
339 if (msetoffset(ms, m, &bb, b, offset, cont_level) == -1) in match()
341 if (m->flag & OFFADD) { in match()
354 if (m->cond == COND_ELSE || in match()
355 m->cond == COND_ELIF) { in match()
360 switch (mget(ms, m, b, CAST(const unsigned char *, in match()
368 if (m->reln != '!') in match()
373 if (m->type == FILE_INDIRECT) { in match()
381 switch (flush ? 1 : magiccheck(ms, m)) { in match()
393 if (m->type == FILE_CLEAR) in match()
396 if (m->type == FILE_DEFAULT) in match()
401 if (*m->desc) in match()
404 if ((e = handle_annotation(ms, m, firstline)) in match()
411 if (print && *m->desc) { in match()
431 && (m->flag & NOSPACE) == 0) { in match()
437 if (mprint(ms, m) == -1) in match()
442 switch (moffset(ms, m, &bb, in match()
581 mprint(struct magic_set *ms, struct magic *m) in mprint() argument
591 if (varexpand(ms, ebuf, sizeof(ebuf), m->desc) == -1) in mprint()
592 desc = m->desc; in mprint()
597 v = file_signextend(ms, m, CAST(uint64_t, value)); \ in mprint()
602 if (m->flag & UNSIGNED) { \ in mprint()
613 if (m->flag & UNSIGNED) { \ in mprint()
627 switch (m->type) { in mprint()
654 if (m->reln == '=' || m->reln == '!') { in mprint()
656 file_printable(sbuf, sizeof(sbuf), m->value.s, in mprint()
657 sizeof(m->value.s))) == -1) in mprint()
659 t = ms->offset + m->vallen; in mprint()
667 if (*m->value.s == '\0') in mprint()
670 if (m->str_flags & STRING_TRIM) in mprint()
678 if (m->type == FILE_PSTRING) { in mprint()
679 size_t l = file_pstring_length_size(ms, m); in mprint()
786 scp = (m->str_flags & STRING_TRIM) ? file_strtrim(cp) : cp; in mprint()
795 if ((m->str_flags & REGEX_OFFSET_START)) in mprint()
804 if (file_printf(ms, "%s", m->desc) == -1) in mprint()
828 file_magerror(ms, "invalid m->type (%d) in mprint()", m->type); in mprint()
835 moffset(struct magic_set *ms, struct magic *m, const struct buffer *b, in moffset() argument
841 switch (m->type) { in moffset()
869 if (m->reln == '=' || m->reln == '!') { in moffset()
870 o = ms->offset + m->vallen; in moffset()
874 if (*m->value.s == '\0') in moffset()
877 if (m->type == FILE_PSTRING) { in moffset()
878 size_t l = file_pstring_length_size(ms, m); in moffset()
925 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
933 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
936 o = CAST(int32_t, (ms->search.offset + m->vallen)); in moffset()
948 o = der_offs(ms, m, nbytes); in moffset()
1043 if (m->num_mask) \
1044 switch (m->mask_op & FILE_OPS_MASK) { \
1046 p->fld &= CAST(type, m->num_mask); \
1049 p->fld |= CAST(type, m->num_mask); \
1052 p->fld ^= CAST(type, m->num_mask); \
1055 p->fld += CAST(type, m->num_mask); \
1058 p->fld -= CAST(type, m->num_mask); \
1061 p->fld *= CAST(type, m->num_mask); \
1064 if (CAST(type, m->num_mask) == 0) \
1066 p->fld /= CAST(type, m->num_mask); \
1069 if (CAST(type, m->num_mask) == 0) \
1071 p->fld %= CAST(type, m->num_mask); \
1074 if (m->mask_op & FILE_OPINVERSE) \
1078 cvt_8(union VALUETYPE *p, const struct magic *m) in cvt_8() argument
1085 cvt_16(union VALUETYPE *p, const struct magic *m) in cvt_16() argument
1092 cvt_32(union VALUETYPE *p, const struct magic *m) in cvt_32() argument
1099 cvt_64(union VALUETYPE *p, const struct magic *m) in cvt_64() argument
1106 if (m->num_mask) \
1107 switch (m->mask_op & FILE_OPS_MASK) { \
1109 p->fld += CAST(type, m->num_mask); \
1112 p->fld -= CAST(type, m->num_mask); \
1115 p->fld *= CAST(type, m->num_mask); \
1118 if (CAST(type, m->num_mask) == 0) \
1120 p->fld /= CAST(type, m->num_mask); \
1125 cvt_float(union VALUETYPE *p, const struct magic *m) in cvt_float() argument
1132 cvt_double(union VALUETYPE *p, const struct magic *m) in cvt_double() argument
1144 mconvert(struct magic_set *ms, struct magic *m, int flip) in mconvert() argument
1148 switch (cvt_flip(m->type, flip)) { in mconvert()
1150 if (cvt_8(p, m) == -1) in mconvert()
1154 if (cvt_16(p, m) == -1) in mconvert()
1160 if (cvt_32(p, m) == -1) in mconvert()
1168 if (cvt_64(p, m) == -1) in mconvert()
1180 size_t len, sz = file_pstring_length_size(ms, m); in mconvert()
1185 len = file_pstring_get_length(ms, m, ptr1); in mconvert()
1207 if (cvt_16(p, m) == -1) in mconvert()
1214 if (cvt_32(p, m) == -1) in mconvert()
1222 if (cvt_64(p, m) == -1) in mconvert()
1227 if (cvt_16(p, m) == -1) in mconvert()
1234 if (cvt_32(p, m) == -1) in mconvert()
1242 if (cvt_64(p, m) == -1) in mconvert()
1249 if (cvt_32(p, m) == -1) in mconvert()
1253 if (cvt_float(p, m) == -1) in mconvert()
1258 if (cvt_float(p, m) == -1) in mconvert()
1263 if (cvt_float(p, m) == -1) in mconvert()
1267 if (cvt_double(p, m) == -1) in mconvert()
1272 if (cvt_double(p, m) == -1) in mconvert()
1277 if (cvt_double(p, m) == -1) in mconvert()
1290 file_magerror(ms, "invalid type %d in mconvert()", m->type); in mconvert()
1310 const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m) in mcopy() argument
1341 if (m->str_flags & REGEX_LINE_COUNT) { in mcopy()
1342 linecnt = m->str_range; in mcopy()
1346 bytecnt = m->str_range; in mcopy()
1442 do_ops(struct magic *m, intmax_t lhs, intmax_t off) in do_ops() argument
1446 switch (m->in_op & FILE_OPS_MASK) { in do_ops()
1474 if (m->in_op & FILE_OPINVERSE) in do_ops()
1481 msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb, in msetoffset() argument
1485 if (m->flag & OFFNEGATIVE) { in msetoffset()
1486 offset = -m->offset; in msetoffset()
1488 if (m->flag & (OFFADD|INDIROFFADD)) in msetoffset()
1492 "level %u", m->offset, cont_level); in msetoffset()
1504 if (CAST(size_t, m->offset) > b->elen) in msetoffset()
1507 ms->eoffset = ms->offset = CAST(int32_t, b->elen - m->offset); in msetoffset()
1509 offset = m->offset; in msetoffset()
1549 mget(struct magic_set *ms, struct magic *m, const struct buffer *b, in mget() argument
1579 if (mcopy(ms, p, m->type, m->flag & INDIR, s, in mget()
1580 CAST(uint32_t, offset + o), CAST(uint32_t, nbytes), m) == -1) in mget()
1587 m->type, m->flag, offset, o, nbytes, in mget()
1592 file_mdump(m); in mget()
1596 if (m->flag & INDIR) { in mget()
1597 intmax_t off = m->in_offset; in mget()
1598 const int sgn = m->in_op & FILE_OPSIGNED; in mget()
1599 if (m->in_op & FILE_OPINDIRECT) { in mget()
1603 switch (op = cvt_flip(m->in_type, flip)) { in mget()
1664 switch (in_type = cvt_flip(m->in_type, flip)) { in mget()
1668 offset = do_ops(m, SEXT(sgn,8,p->b), off); in mget()
1673 offset = do_ops(m, SEXT(sgn,16,BE16(p)), off); in mget()
1678 offset = do_ops(m, SEXT(sgn,16,LE16(p)), off); in mget()
1683 offset = do_ops(m, SEXT(sgn,16,p->h), off); in mget()
1692 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1701 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1706 offset = do_ops(m, SEXT(sgn,32,ME32(p)), off); in mget()
1711 offset = do_ops(m, SEXT(sgn,32,p->l), off); in mget()
1716 offset = do_ops(m, SEXT(sgn,64,LE64(p)), off); in mget()
1721 offset = do_ops(m, SEXT(sgn,64,BE64(p)), off); in mget()
1729 if (m->flag & INDIROFFADD) { in mget()
1746 if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1) in mget()
1754 file_mdump(m); in mget()
1760 switch (m->type) { in mget()
1807 if (OFFSET_OOB(nbytes, offset, m->vallen)) in mget()
1817 if (m->str_flags & INDIRECT_RELATIVE) in mget()
1844 file_printf(ms, F(ms, m->desc, "%u"), offset) == -1) in mget()
1860 rbuf = m->value.s; in mget()
1875 if (m->flag & NOSPACE) in mget()
1900 if (file_printf(ms, "%s", m->desc) == -1) in mget()
1909 if (!mconvert(ms, m, flip)) in mget()
2056 magiccheck(struct magic_set *ms, struct magic *m) in magiccheck() argument
2058 uint64_t l = m->value.q; in magiccheck()
2065 switch (m->type) { in magiccheck()
2110 fl = m->value.f; in magiccheck()
2112 switch (m->reln) { in magiccheck()
2135 m->reln); in magiccheck()
2143 dl = m->value.d; in magiccheck()
2145 switch (m->reln) { in magiccheck()
2167 file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln); in magiccheck()
2181 v = file_strncmp(m->value.s, p->s, CAST(size_t, m->vallen), in magiccheck()
2182 sizeof(p->s), m->str_flags); in magiccheck()
2188 v = file_strncmp16(m->value.s, p->s, CAST(size_t, m->vallen), in magiccheck()
2189 sizeof(p->s), m->str_flags); in magiccheck()
2199 slen = MIN(m->vallen, sizeof(m->value.s)); in magiccheck()
2202 if (slen > 0 && m->str_flags == 0) { in magiccheck()
2204 idx = m->str_range + slen; in magiccheck()
2205 if (m->str_range == 0 || ms->search.s_len < idx) in magiccheck()
2208 m->value.s, slen, ms->search.s + idx)); in magiccheck()
2217 for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) { in magiccheck()
2221 v = file_strncmp(m->value.s, ms->search.s + idx, slen, in magiccheck()
2222 ms->search.s_len - idx, m->str_flags); in magiccheck()
2238 if (m->str_flags & STRING_IGNORE_CASE) { in magiccheck()
2242 pattern = convert_libmagic_pattern((char *)m->value.s, m->vallen, options); in magiccheck()
2311 matched = der_cmp(ms, m); in magiccheck()
2322 v = memcmp(m->value.guid, p->guid, sizeof(p->guid)); in magiccheck()
2325 file_magerror(ms, "invalid type %d in magiccheck()", m->type); in magiccheck()
2329 v = file_signextend(ms, m, v); in magiccheck()
2331 switch (m->reln) { in magiccheck()
2358 if (m->flag & UNSIGNED) { in magiccheck()
2377 if (m->flag & UNSIGNED) { in magiccheck()
2418 m->reln); in magiccheck()
2426 handle_annotation(struct magic_set *ms, struct magic *m, int firstline) in handle_annotation() argument
2428 if ((ms->flags & MAGIC_APPLE) && m->apple[0]) { in handle_annotation()
2431 if (file_printf(ms, "%.8s", m->apple) == -1) in handle_annotation()
2435 if ((ms->flags & MAGIC_EXTENSION) && m->ext[0]) { in handle_annotation()
2438 if (file_printf(ms, "%s", m->ext) == -1) in handle_annotation()
2442 if ((ms->flags & MAGIC_MIME_TYPE) && m->mimetype[0]) { in handle_annotation()
2447 if (varexpand(ms, buf, sizeof(buf), m->mimetype) == -1) in handle_annotation()
2448 p = m->mimetype; in handle_annotation()