Lines Matching refs:m

125 file_fmtcheck(struct magic_set *ms, const struct magic *m, const char *def,  in file_fmtcheck()  argument
128 const char *ptr = fmtcheck(m->desc, def); in file_fmtcheck()
132 " with `%s'", file, line, m->desc, def); in file_fmtcheck()
188 struct magic *m = &magic[magindex]; in match() local
190 if (m->type != FILE_NAME) in match()
191 if ((IS_LIBMAGIC_STRING(m->type) && in match()
193 ((text && (m->str_flags & FLT) == STRING_BINTEST) || in match()
194 (!text && (m->str_flags & FLT) == STRING_TEXTTEST))) || in match()
195 (m->flag & mode) != mode) { in match()
205 ms->offset = m->offset; in match()
206 ms->line = m->lineno; in match()
209 switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text, in match()
215 flush = m->reln != '!'; in match()
218 if (m->type == FILE_INDIRECT) in match()
221 switch (magiccheck(ms, m)) { in match()
241 if ((e = handle_annotation(ms, m, firstline)) != 0) { in match()
252 if (*m->desc) { in match()
260 if (print && mprint(ms, m) == -1) in match()
263 switch (moffset(ms, m, nbytes, &ms->c.li[cont_level].off)) { in match()
277 m = &magic[++magindex]; in match()
278 ms->line = m->lineno; /* for messages */ in match()
280 if (cont_level < m->cont_level) in match()
282 if (cont_level > m->cont_level) { in match()
287 cont_level = m->cont_level; in match()
289 ms->offset = m->offset; in match()
290 if (m->flag & OFFADD) { in match()
296 if (m->cond == COND_ELSE || in match()
297 m->cond == COND_ELIF) { in match()
302 switch (mget(ms, s, m, nbytes, offset, cont_level, mode, in match()
308 if (m->reln != '!') in match()
313 if (m->type == FILE_INDIRECT) in match()
319 switch (flush ? 1 : magiccheck(ms, m)) { in match()
331 if (m->type == FILE_CLEAR) in match()
334 if (m->type == FILE_DEFAULT) in match()
339 if ((e = handle_annotation(ms, m, firstline)) != 0) { in match()
349 if (*m->desc) { in match()
365 && ((m->flag & NOSPACE) == 0) in match()
366 && *m->desc) { in match()
372 if (print && mprint(ms, m) == -1) in match()
375 switch (moffset(ms, m, nbytes, in match()
386 if (*m->desc) in match()
413 check_fmt(struct magic_set *ms, struct magic *m) in check_fmt() argument
420 if (strchr(m->desc, '%') == NULL) in check_fmt()
428 rv = !pcre_exec(pce, re_extra, m->desc, strlen(m->desc), 0, re_options, NULL, 0); in check_fmt()
436 mprint(struct magic_set *ms, struct magic *m) in mprint() argument
445 switch (m->type) { in mprint()
447 v = file_signextend(ms, m, (uint64_t)p->b); in mprint()
448 switch (check_fmt(ms, m)) { in mprint()
454 if (file_printf(ms, F(ms, m, "%s"), buf) == -1) in mprint()
458 if (file_printf(ms, F(ms, m, "%d"), in mprint()
469 v = file_signextend(ms, m, (uint64_t)p->h); in mprint()
470 switch (check_fmt(ms, m)) { in mprint()
476 if (file_printf(ms, F(ms, m, "%s"), buf) == -1) in mprint()
480 if (file_printf(ms, F(ms, m, "%u"), in mprint()
492 v = file_signextend(ms, m, (uint64_t)p->l); in mprint()
493 switch (check_fmt(ms, m)) { in mprint()
498 if (file_printf(ms, F(ms, m, "%s"), buf) == -1) in mprint()
502 if (file_printf(ms, F(ms, m, "%u"), (uint32_t) v) == -1) in mprint()
512 v = file_signextend(ms, m, p->q); in mprint()
513 switch (check_fmt(ms, m)) { in mprint()
519 if (file_printf(ms, F(ms, m, "%s"), buf) == -1) in mprint()
523 if (file_printf(ms, F(ms, m, "%" INT64_T_FORMAT "u"), in mprint()
535 if (m->reln == '=' || m->reln == '!') { in mprint()
536 if (file_printf(ms, F(ms, m, "%s"), in mprint()
537 file_printable(sbuf, sizeof(sbuf), m->value.s)) in mprint()
540 t = ms->offset + m->vallen; in mprint()
548 if (*m->value.s == '\0') in mprint()
551 if (m->str_flags & STRING_TRIM) { in mprint()
564 if (file_printf(ms, F(ms, m, "%s"), in mprint()
568 if (m->type == FILE_PSTRING) in mprint()
569 t += file_pstring_length_size(m); in mprint()
577 if (file_printf(ms, F(ms, m, "%s"), in mprint()
587 if (file_printf(ms, F(ms, m, "%s"), in mprint()
596 if (file_printf(ms, F(ms, m, "%s"), in mprint()
605 if (file_printf(ms, F(ms, m, "%s"), in mprint()
614 if (file_printf(ms, F(ms, m, "%s"), in mprint()
624 switch (check_fmt(ms, m)) { in mprint()
629 if (file_printf(ms, F(ms, m, "%s"), buf) == -1) in mprint()
633 if (file_printf(ms, F(ms, m, "%g"), vf) == -1) in mprint()
644 switch (check_fmt(ms, m)) { in mprint()
649 if (file_printf(ms, F(ms, m, "%s"), buf) == -1) in mprint()
653 if (file_printf(ms, F(ms, m, "%g"), vd) == -1) in mprint()
666 rval = file_printf(ms, F(ms, m, "%s"), in mprint()
673 if ((m->str_flags & REGEX_OFFSET_START)) in mprint()
682 if (file_printf(ms, "%s", m->desc) == -1) in mprint()
693 if (file_printf(ms, F(ms, m, "%s"), in mprint()
699 file_magerror(ms, "invalid m->type (%d) in mprint()", m->type); in mprint()
706 moffset(struct magic_set *ms, struct magic *m, size_t nbytes, int32_t *op) in moffset() argument
710 switch (m->type) { in moffset()
738 if (m->reln == '=' || m->reln == '!') { in moffset()
739 o = ms->offset + m->vallen; in moffset()
743 if (*m->value.s == '\0') in moffset()
746 if (m->type == FILE_PSTRING) in moffset()
747 o += (uint32_t)file_pstring_length_size(m); in moffset()
790 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
798 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
801 o = CAST(int32_t, (ms->search.offset + m->vallen)); in moffset()
812 o = der_offs(ms, m, nbytes); in moffset()
904 if (m->num_mask) \
905 switch (m->mask_op & FILE_OPS_MASK) { \
907 p->fld &= cast m->num_mask; \
910 p->fld |= cast m->num_mask; \
913 p->fld ^= cast m->num_mask; \
916 p->fld += cast m->num_mask; \
919 p->fld -= cast m->num_mask; \
922 p->fld *= cast m->num_mask; \
925 if (cast m->num_mask == 0) \
927 p->fld /= cast m->num_mask; \
930 if (cast m->num_mask == 0) \
932 p->fld %= cast m->num_mask; \
935 if (m->mask_op & FILE_OPINVERSE) \
939 cvt_8(union VALUETYPE *p, const struct magic *m) in cvt_8() argument
946 cvt_16(union VALUETYPE *p, const struct magic *m) in cvt_16() argument
953 cvt_32(union VALUETYPE *p, const struct magic *m) in cvt_32() argument
960 cvt_64(union VALUETYPE *p, const struct magic *m) in cvt_64() argument
967 if (m->num_mask) \
968 switch (m->mask_op & FILE_OPS_MASK) { \
970 p->fld += cast m->num_mask; \
973 p->fld -= cast m->num_mask; \
976 p->fld *= cast m->num_mask; \
979 if (cast m->num_mask == 0) \
981 p->fld /= cast m->num_mask; \
986 cvt_float(union VALUETYPE *p, const struct magic *m) in cvt_float() argument
993 cvt_double(union VALUETYPE *p, const struct magic *m) in cvt_double() argument
1005 mconvert(struct magic_set *ms, struct magic *m, int flip) in mconvert() argument
1009 switch (cvt_flip(m->type, flip)) { in mconvert()
1011 if (cvt_8(p, m) == -1) in mconvert()
1015 if (cvt_16(p, m) == -1) in mconvert()
1021 if (cvt_32(p, m) == -1) in mconvert()
1028 if (cvt_64(p, m) == -1) in mconvert()
1039 size_t sz = file_pstring_length_size(m); in mconvert()
1041 size_t len = file_pstring_get_length(m, ptr1); in mconvert()
1061 if (cvt_16(p, m) == -1) in mconvert()
1068 if (cvt_32(p, m) == -1) in mconvert()
1076 if (cvt_64(p, m) == -1) in mconvert()
1081 if (cvt_16(p, m) == -1) in mconvert()
1088 if (cvt_32(p, m) == -1) in mconvert()
1096 if (cvt_64(p, m) == -1) in mconvert()
1103 if (cvt_32(p, m) == -1) in mconvert()
1107 if (cvt_float(p, m) == -1) in mconvert()
1112 if (cvt_float(p, m) == -1) in mconvert()
1117 if (cvt_float(p, m) == -1) in mconvert()
1121 if (cvt_double(p, m) == -1) in mconvert()
1126 if (cvt_double(p, m) == -1) in mconvert()
1131 if (cvt_double(p, m) == -1) in mconvert()
1143 file_magerror(ms, "invalid type %d in mconvert()", m->type); in mconvert()
1163 const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m) in mcopy() argument
1194 if (m->str_flags & REGEX_LINE_COUNT) { in mcopy()
1195 linecnt = m->str_range; in mcopy()
1199 bytecnt = m->str_range; in mcopy()
1287 do_ops(struct magic *m, intmax_t lhs, intmax_t off) in do_ops() argument
1291 switch (m->in_op & FILE_OPS_MASK) { in do_ops()
1319 if (m->in_op & FILE_OPINVERSE) in do_ops()
1326 mget(struct magic_set *ms, const unsigned char *s, struct magic *m, in mget() argument
1351 if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o), in mget()
1352 (uint32_t)nbytes, m) == -1) in mget()
1359 m->type, m->flag, offset, o, nbytes, in mget()
1364 if (m->flag & INDIR) { in mget()
1365 intmax_t off = m->in_offset; in mget()
1366 const int sgn = m->in_op & FILE_OPSIGNED; in mget()
1367 if (m->in_op & FILE_OPINDIRECT) { in mget()
1372 switch (cvt_flip(m->in_type, flip)) { in mget()
1403 switch (in_type = cvt_flip(m->in_type, flip)) { in mget()
1407 offset = do_ops(m, SEXT(sgn,8,p->b), off); in mget()
1412 offset = do_ops(m, SEXT(sgn,16,BE16(p)), off); in mget()
1417 offset = do_ops(m, SEXT(sgn,16,LE16(p)), off); in mget()
1422 offset = do_ops(m, SEXT(sgn,16,p->h), off); in mget()
1431 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1440 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1445 offset = do_ops(m, SEXT(sgn,32,ME32(p)), off); in mget()
1450 offset = do_ops(m, SEXT(sgn,32,p->l), off); in mget()
1456 if (m->flag & INDIROFFADD) { in mget()
1467 if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1) in mget()
1478 switch (m->type) { in mget()
1520 if (OFFSET_OOB(nbytes, offset, m->vallen)) in mget()
1530 if (m->str_flags & INDIRECT_RELATIVE) in mget()
1554 file_printf(ms, F(ms, m, "%u"), offset) == -1) { in mget()
1569 rbuf = m->value.s; in mget()
1580 if (m->flag & NOSPACE) in mget()
1592 if (file_printf(ms, "%s", m->desc) == -1) in mget()
1601 if (!mconvert(ms, m, flip)) in mget()
1722 magiccheck(struct magic_set *ms, struct magic *m) in magiccheck() argument
1724 uint64_t l = m->value.q; in magiccheck()
1731 switch (m->type) { in magiccheck()
1775 fl = m->value.f; in magiccheck()
1777 switch (m->reln) { in magiccheck()
1800 m->reln); in magiccheck()
1808 dl = m->value.d; in magiccheck()
1810 switch (m->reln) { in magiccheck()
1832 file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln); in magiccheck()
1846 v = file_strncmp(m->value.s, p->s, (size_t)m->vallen, m->str_flags); in magiccheck()
1852 v = file_strncmp16(m->value.s, p->s, (size_t)m->vallen, m->str_flags); in magiccheck()
1862 slen = MIN(m->vallen, sizeof(m->value.s)); in magiccheck()
1866 for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) { in magiccheck()
1870 v = file_strncmp(m->value.s, ms->search.s + idx, slen, in magiccheck()
1871 m->str_flags); in magiccheck()
1887 if (m->str_flags & STRING_IGNORE_CASE) { in magiccheck()
1891 convert_libmagic_pattern(&pattern, (char *)m->value.s, m->vallen, options); in magiccheck()
1959 matched = der_cmp(ms, m); in magiccheck()
1969 file_magerror(ms, "invalid type %d in magiccheck()", m->type); in magiccheck()
1973 v = file_signextend(ms, m, v); in magiccheck()
1975 switch (m->reln) { in magiccheck()
2000 if (m->flag & UNSIGNED) { in magiccheck()
2018 if (m->flag & UNSIGNED) { in magiccheck()
2057 m->reln); in magiccheck()
2065 handle_annotation(struct magic_set *ms, struct magic *m, int firstline) in handle_annotation() argument
2067 if ((ms->flags & MAGIC_APPLE) && m->apple[0]) { in handle_annotation()
2070 if (file_printf(ms, "%.8s", m->apple) == -1) in handle_annotation()
2074 if ((ms->flags & MAGIC_EXTENSION) && m->ext[0]) { in handle_annotation()
2077 if (file_printf(ms, "%s", m->ext) == -1) in handle_annotation()
2081 if ((ms->flags & MAGIC_MIME_TYPE) && m->mimetype[0]) { in handle_annotation()
2084 if (file_printf(ms, "%s", m->mimetype) == -1) in handle_annotation()