Lines Matching refs:m
228 struct magic *m = &magic[magindex]; in match() local
230 if (m->type != FILE_NAME) in match()
231 if ((IS_LIBMAGIC_STRING(m->type) && in match()
233 ((text && (m->str_flags & FLT) == STRING_BINTEST) || in match()
234 (!text && (m->str_flags & FLT) == STRING_TEXTTEST))) || in match()
235 (m->flag & mode) != mode) { in match()
245 if (msetoffset(ms, m, &bb, b, offset, cont_level) == -1) in match()
247 ms->line = m->lineno; in match()
250 switch (mget(ms, m, b, CAST(const unsigned char *, bb.fbuf), in match()
258 flush = m->reln != '!'; in match()
261 if (m->type == FILE_INDIRECT) { in match()
266 switch (magiccheck(ms, m)) { in match()
286 if (*m->desc) in match()
289 if ((e = handle_annotation(ms, m, firstline)) != 0) in match()
301 if (print && *m->desc) { in match()
307 if (mprint(ms, m) == -1) in match()
311 switch (moffset(ms, m, &bb, &ms->c.li[cont_level].off)) { in match()
325 m = &magic[++magindex]; in match()
326 ms->line = m->lineno; /* for messages */ in match()
328 if (cont_level < m->cont_level) in match()
330 if (cont_level > m->cont_level) { in match()
335 cont_level = m->cont_level; in match()
337 if (msetoffset(ms, m, &bb, b, offset, cont_level) == -1) in match()
339 if (m->flag & OFFADD) { in match()
345 if (m->cond == COND_ELSE || in match()
346 m->cond == COND_ELIF) { in match()
351 switch (mget(ms, m, b, CAST(const unsigned char *, in match()
359 if (m->reln != '!') in match()
364 if (m->type == FILE_INDIRECT) { in match()
372 switch (flush ? 1 : magiccheck(ms, m)) { in match()
384 if (m->type == FILE_CLEAR) in match()
387 if (m->type == FILE_DEFAULT) in match()
392 if (*m->desc) in match()
395 if ((e = handle_annotation(ms, m, firstline)) in match()
402 if (print && *m->desc) { in match()
422 && (m->flag & NOSPACE) == 0) { in match()
428 if (mprint(ms, m) == -1) in match()
433 switch (moffset(ms, m, &bb, in match()
550 mprint(struct magic_set *ms, struct magic *m) in mprint() argument
560 if (varexpand(ms, ebuf, sizeof(ebuf), m->desc) == -1) in mprint()
561 desc = m->desc; in mprint()
565 switch (m->type) { in mprint()
567 v = file_signextend(ms, m, CAST(uint64_t, p->b)); in mprint()
589 v = file_signextend(ms, m, CAST(uint64_t, p->h)); in mprint()
612 v = file_signextend(ms, m, CAST(uint64_t, p->l)); in mprint()
634 v = file_signextend(ms, m, p->q); in mprint()
657 if (m->reln == '=' || m->reln == '!') { in mprint()
659 file_printable(sbuf, sizeof(sbuf), m->value.s, in mprint()
660 sizeof(m->value.s))) == -1) in mprint()
662 t = ms->offset + m->vallen; in mprint()
670 if (*m->value.s == '\0') in mprint()
673 if (m->str_flags & STRING_TRIM) { in mprint()
691 if (m->type == FILE_PSTRING) in mprint()
692 t += file_pstring_length_size(m); in mprint()
797 if ((m->str_flags & REGEX_OFFSET_START)) in mprint()
806 if (file_printf(ms, "%s", m->desc) == -1) in mprint()
824 file_magerror(ms, "invalid m->type (%d) in mprint()", m->type); in mprint()
831 moffset(struct magic_set *ms, struct magic *m, const struct buffer *b, in moffset() argument
837 switch (m->type) { in moffset()
865 if (m->reln == '=' || m->reln == '!') { in moffset()
866 o = ms->offset + m->vallen; in moffset()
870 if (*m->value.s == '\0') in moffset()
873 if (m->type == FILE_PSTRING) in moffset()
875 file_pstring_length_size(m)); in moffset()
918 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
926 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
929 o = CAST(int32_t, (ms->search.offset + m->vallen)); in moffset()
940 o = der_offs(ms, m, nbytes); in moffset()
1032 if (m->num_mask) \
1033 switch (m->mask_op & FILE_OPS_MASK) { \
1035 p->fld &= CAST(type, m->num_mask); \
1038 p->fld |= CAST(type, m->num_mask); \
1041 p->fld ^= CAST(type, m->num_mask); \
1044 p->fld += CAST(type, m->num_mask); \
1047 p->fld -= CAST(type, m->num_mask); \
1050 p->fld *= CAST(type, m->num_mask); \
1053 if (CAST(type, m->num_mask) == 0) \
1055 p->fld /= CAST(type, m->num_mask); \
1058 if (CAST(type, m->num_mask) == 0) \
1060 p->fld %= CAST(type, m->num_mask); \
1063 if (m->mask_op & FILE_OPINVERSE) \
1067 cvt_8(union VALUETYPE *p, const struct magic *m) in cvt_8() argument
1074 cvt_16(union VALUETYPE *p, const struct magic *m) in cvt_16() argument
1081 cvt_32(union VALUETYPE *p, const struct magic *m) in cvt_32() argument
1088 cvt_64(union VALUETYPE *p, const struct magic *m) in cvt_64() argument
1095 if (m->num_mask) \
1096 switch (m->mask_op & FILE_OPS_MASK) { \
1098 p->fld += CAST(type, m->num_mask); \
1101 p->fld -= CAST(type, m->num_mask); \
1104 p->fld *= CAST(type, m->num_mask); \
1107 if (CAST(type, m->num_mask) == 0) \
1109 p->fld /= CAST(type, m->num_mask); \
1114 cvt_float(union VALUETYPE *p, const struct magic *m) in cvt_float() argument
1121 cvt_double(union VALUETYPE *p, const struct magic *m) in cvt_double() argument
1133 mconvert(struct magic_set *ms, struct magic *m, int flip) in mconvert() argument
1137 switch (cvt_flip(m->type, flip)) { in mconvert()
1139 if (cvt_8(p, m) == -1) in mconvert()
1143 if (cvt_16(p, m) == -1) in mconvert()
1149 if (cvt_32(p, m) == -1) in mconvert()
1156 if (cvt_64(p, m) == -1) in mconvert()
1167 size_t sz = file_pstring_length_size(m); in mconvert()
1169 size_t len = file_pstring_get_length(m, ptr1); in mconvert()
1189 if (cvt_16(p, m) == -1) in mconvert()
1196 if (cvt_32(p, m) == -1) in mconvert()
1204 if (cvt_64(p, m) == -1) in mconvert()
1209 if (cvt_16(p, m) == -1) in mconvert()
1216 if (cvt_32(p, m) == -1) in mconvert()
1224 if (cvt_64(p, m) == -1) in mconvert()
1231 if (cvt_32(p, m) == -1) in mconvert()
1235 if (cvt_float(p, m) == -1) in mconvert()
1240 if (cvt_float(p, m) == -1) in mconvert()
1245 if (cvt_float(p, m) == -1) in mconvert()
1249 if (cvt_double(p, m) == -1) in mconvert()
1254 if (cvt_double(p, m) == -1) in mconvert()
1259 if (cvt_double(p, m) == -1) in mconvert()
1271 file_magerror(ms, "invalid type %d in mconvert()", m->type); in mconvert()
1291 const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m) in mcopy() argument
1322 if (m->str_flags & REGEX_LINE_COUNT) { in mcopy()
1323 linecnt = m->str_range; in mcopy()
1327 bytecnt = m->str_range; in mcopy()
1417 do_ops(struct magic *m, intmax_t lhs, intmax_t off) in do_ops() argument
1421 switch (m->in_op & FILE_OPS_MASK) { in do_ops()
1449 if (m->in_op & FILE_OPINVERSE) in do_ops()
1456 msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb, in msetoffset() argument
1459 if (m->offset < 0) { in msetoffset()
1461 if (m->flag & (OFFADD|INDIROFFADD)) in msetoffset()
1465 "level %u", m->offset, cont_level); in msetoffset()
1477 if (CAST(size_t, -m->offset) > b->elen) in msetoffset()
1480 ms->eoffset = ms->offset = CAST(int32_t, b->elen + m->offset); in msetoffset()
1486 ms->offset = m->offset; in msetoffset()
1489 ms->offset = ms->eoffset + m->offset; in msetoffset()
1496 m->offset, cont_level); in msetoffset()
1502 mget(struct magic_set *ms, struct magic *m, const struct buffer *b, in mget() argument
1531 if (mcopy(ms, p, m->type, m->flag & INDIR, s, in mget()
1532 CAST(uint32_t, offset + o), CAST(uint32_t, nbytes), m) == -1) in mget()
1539 m->type, m->flag, offset, o, nbytes, in mget()
1545 if (m->flag & INDIR) { in mget()
1546 intmax_t off = m->in_offset; in mget()
1547 const int sgn = m->in_op & FILE_OPSIGNED; in mget()
1548 if (m->in_op & FILE_OPINDIRECT) { in mget()
1551 switch (cvt_flip(m->in_type, flip)) { in mget()
1610 switch (in_type = cvt_flip(m->in_type, flip)) { in mget()
1614 offset = do_ops(m, SEXT(sgn,8,p->b), off); in mget()
1619 offset = do_ops(m, SEXT(sgn,16,BE16(p)), off); in mget()
1624 offset = do_ops(m, SEXT(sgn,16,LE16(p)), off); in mget()
1629 offset = do_ops(m, SEXT(sgn,16,p->h), off); in mget()
1638 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1647 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1652 offset = do_ops(m, SEXT(sgn,32,ME32(p)), off); in mget()
1657 offset = do_ops(m, SEXT(sgn,32,p->l), off); in mget()
1662 offset = do_ops(m, SEXT(sgn,64,LE64(p)), off); in mget()
1667 offset = do_ops(m, SEXT(sgn,64,BE64(p)), off); in mget()
1673 if (m->flag & INDIROFFADD) { in mget()
1684 if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1) in mget()
1695 switch (m->type) { in mget()
1737 if (OFFSET_OOB(nbytes, offset, m->vallen)) in mget()
1747 if (m->str_flags & INDIRECT_RELATIVE) in mget()
1774 file_printf(ms, F(ms, m->desc, "%u"), offset) == -1) { in mget()
1789 rbuf = m->value.s; in mget()
1800 if (m->flag & NOSPACE) in mget()
1813 if (file_printf(ms, "%s", m->desc) == -1) in mget()
1822 if (!mconvert(ms, m, flip)) in mget()
1963 magiccheck(struct magic_set *ms, struct magic *m) in magiccheck() argument
1965 uint64_t l = m->value.q; in magiccheck()
1972 switch (m->type) { in magiccheck()
2016 fl = m->value.f; in magiccheck()
2018 switch (m->reln) { in magiccheck()
2041 m->reln); in magiccheck()
2049 dl = m->value.d; in magiccheck()
2051 switch (m->reln) { in magiccheck()
2073 file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln); in magiccheck()
2087 v = file_strncmp(m->value.s, p->s, CAST(size_t, m->vallen), in magiccheck()
2088 m->str_flags); in magiccheck()
2094 v = file_strncmp16(m->value.s, p->s, CAST(size_t, m->vallen), in magiccheck()
2095 m->str_flags); in magiccheck()
2105 slen = MIN(m->vallen, sizeof(m->value.s)); in magiccheck()
2109 if (slen > 0 && m->str_flags == 0) { in magiccheck()
2111 idx = m->str_range + slen; in magiccheck()
2112 if (m->str_range == 0 || ms->search.s_len < idx) in magiccheck()
2115 m->value.s, slen)); in magiccheck()
2125 for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) { in magiccheck()
2129 v = file_strncmp(m->value.s, ms->search.s + idx, slen, in magiccheck()
2130 m->str_flags); in magiccheck()
2146 if (m->str_flags & STRING_IGNORE_CASE) { in magiccheck()
2150 convert_libmagic_pattern(&pattern, (char *)m->value.s, m->vallen, options); in magiccheck()
2218 matched = der_cmp(ms, m); in magiccheck()
2228 file_magerror(ms, "invalid type %d in magiccheck()", m->type); in magiccheck()
2232 v = file_signextend(ms, m, v); in magiccheck()
2234 switch (m->reln) { in magiccheck()
2261 if (m->flag & UNSIGNED) { in magiccheck()
2280 if (m->flag & UNSIGNED) { in magiccheck()
2321 m->reln); in magiccheck()
2329 handle_annotation(struct magic_set *ms, struct magic *m, int firstline) in handle_annotation() argument
2331 if ((ms->flags & MAGIC_APPLE) && m->apple[0]) { in handle_annotation()
2334 if (file_printf(ms, "%.8s", m->apple) == -1) in handle_annotation()
2338 if ((ms->flags & MAGIC_EXTENSION) && m->ext[0]) { in handle_annotation()
2341 if (file_printf(ms, "%s", m->ext) == -1) in handle_annotation()
2345 if ((ms->flags & MAGIC_MIME_TYPE) && m->mimetype[0]) { in handle_annotation()
2350 if (varexpand(ms, buf, sizeof(buf), m->mimetype) == -1) in handle_annotation()
2351 p = m->mimetype; in handle_annotation()