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()
352 if (m->cond == COND_ELSE || in match()
353 m->cond == COND_ELIF) { in match()
358 switch (mget(ms, m, b, CAST(const unsigned char *, in match()
366 if (m->reln != '!') in match()
371 if (m->type == FILE_INDIRECT) { in match()
379 switch (flush ? 1 : magiccheck(ms, m)) { in match()
391 if (m->type == FILE_CLEAR) in match()
394 if (m->type == FILE_DEFAULT) in match()
399 if (*m->desc) in match()
402 if ((e = handle_annotation(ms, m, firstline)) in match()
409 if (print && *m->desc) { in match()
429 && (m->flag & NOSPACE) == 0) { in match()
435 if (mprint(ms, m) == -1) in match()
440 switch (moffset(ms, m, &bb, in match()
557 mprint(struct magic_set *ms, struct magic *m) in mprint() argument
567 if (varexpand(ms, ebuf, sizeof(ebuf), m->desc) == -1) in mprint()
568 desc = m->desc; in mprint()
572 switch (m->type) { in mprint()
574 v = file_signextend(ms, m, CAST(uint64_t, p->b)); in mprint()
596 v = file_signextend(ms, m, CAST(uint64_t, p->h)); in mprint()
619 v = file_signextend(ms, m, CAST(uint64_t, p->l)); in mprint()
642 v = file_signextend(ms, m, p->q); in mprint()
665 if (m->reln == '=' || m->reln == '!') { in mprint()
667 file_printable(sbuf, sizeof(sbuf), m->value.s, in mprint()
668 sizeof(m->value.s))) == -1) in mprint()
670 t = ms->offset + m->vallen; in mprint()
678 if (*m->value.s == '\0') in mprint()
681 if (m->str_flags & STRING_TRIM) { in mprint()
699 if (m->type == FILE_PSTRING) { in mprint()
700 size_t l = file_pstring_length_size(ms, m); in mprint()
810 if ((m->str_flags & REGEX_OFFSET_START)) in mprint()
819 if (file_printf(ms, "%s", m->desc) == -1) in mprint()
843 file_magerror(ms, "invalid m->type (%d) in mprint()", m->type); in mprint()
850 moffset(struct magic_set *ms, struct magic *m, const struct buffer *b, in moffset() argument
856 switch (m->type) { in moffset()
884 if (m->reln == '=' || m->reln == '!') { in moffset()
885 o = ms->offset + m->vallen; in moffset()
889 if (*m->value.s == '\0') in moffset()
892 if (m->type == FILE_PSTRING) { in moffset()
893 size_t l = file_pstring_length_size(ms, m); in moffset()
940 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
948 if ((m->str_flags & REGEX_OFFSET_START) != 0) in moffset()
951 o = CAST(int32_t, (ms->search.offset + m->vallen)); in moffset()
962 o = der_offs(ms, m, nbytes); in moffset()
1057 if (m->num_mask) \
1058 switch (m->mask_op & FILE_OPS_MASK) { \
1060 p->fld &= CAST(type, m->num_mask); \
1063 p->fld |= CAST(type, m->num_mask); \
1066 p->fld ^= CAST(type, m->num_mask); \
1069 p->fld += CAST(type, m->num_mask); \
1072 p->fld -= CAST(type, m->num_mask); \
1075 p->fld *= CAST(type, m->num_mask); \
1078 if (CAST(type, m->num_mask) == 0) \
1080 p->fld /= CAST(type, m->num_mask); \
1083 if (CAST(type, m->num_mask) == 0) \
1085 p->fld %= CAST(type, m->num_mask); \
1088 if (m->mask_op & FILE_OPINVERSE) \
1092 cvt_8(union VALUETYPE *p, const struct magic *m) in cvt_8() argument
1099 cvt_16(union VALUETYPE *p, const struct magic *m) in cvt_16() argument
1106 cvt_32(union VALUETYPE *p, const struct magic *m) in cvt_32() argument
1113 cvt_64(union VALUETYPE *p, const struct magic *m) in cvt_64() argument
1120 if (m->num_mask) \
1121 switch (m->mask_op & FILE_OPS_MASK) { \
1123 p->fld += CAST(type, m->num_mask); \
1126 p->fld -= CAST(type, m->num_mask); \
1129 p->fld *= CAST(type, m->num_mask); \
1132 if (CAST(type, m->num_mask) == 0) \
1134 p->fld /= CAST(type, m->num_mask); \
1139 cvt_float(union VALUETYPE *p, const struct magic *m) in cvt_float() argument
1146 cvt_double(union VALUETYPE *p, const struct magic *m) in cvt_double() argument
1158 mconvert(struct magic_set *ms, struct magic *m, int flip) in mconvert() argument
1162 switch (cvt_flip(m->type, flip)) { in mconvert()
1164 if (cvt_8(p, m) == -1) in mconvert()
1168 if (cvt_16(p, m) == -1) in mconvert()
1174 if (cvt_32(p, m) == -1) in mconvert()
1182 if (cvt_64(p, m) == -1) in mconvert()
1194 size_t len, sz = file_pstring_length_size(ms, m); in mconvert()
1199 len = file_pstring_get_length(ms, m, ptr1); in mconvert()
1221 if (cvt_16(p, m) == -1) in mconvert()
1228 if (cvt_32(p, m) == -1) in mconvert()
1236 if (cvt_64(p, m) == -1) in mconvert()
1241 if (cvt_16(p, m) == -1) in mconvert()
1248 if (cvt_32(p, m) == -1) in mconvert()
1256 if (cvt_64(p, m) == -1) in mconvert()
1263 if (cvt_32(p, m) == -1) in mconvert()
1267 if (cvt_float(p, m) == -1) in mconvert()
1272 if (cvt_float(p, m) == -1) in mconvert()
1277 if (cvt_float(p, m) == -1) in mconvert()
1281 if (cvt_double(p, m) == -1) in mconvert()
1286 if (cvt_double(p, m) == -1) in mconvert()
1291 if (cvt_double(p, m) == -1) in mconvert()
1304 file_magerror(ms, "invalid type %d in mconvert()", m->type); in mconvert()
1324 const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m) in mcopy() argument
1355 if (m->str_flags & REGEX_LINE_COUNT) { in mcopy()
1356 linecnt = m->str_range; in mcopy()
1360 bytecnt = m->str_range; in mcopy()
1456 do_ops(struct magic *m, intmax_t lhs, intmax_t off) in do_ops() argument
1460 switch (m->in_op & FILE_OPS_MASK) { in do_ops()
1488 if (m->in_op & FILE_OPINVERSE) in do_ops()
1495 msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb, in msetoffset() argument
1499 if (m->flag & OFFNEGATIVE) { in msetoffset()
1500 offset = -m->offset; in msetoffset()
1502 if (m->flag & (OFFADD|INDIROFFADD)) in msetoffset()
1506 "level %u", m->offset, cont_level); in msetoffset()
1518 if (CAST(size_t, m->offset) > b->elen) in msetoffset()
1521 ms->eoffset = ms->offset = CAST(int32_t, b->elen - m->offset); in msetoffset()
1523 offset = m->offset; in msetoffset()
1545 mget(struct magic_set *ms, struct magic *m, const struct buffer *b, in mget() argument
1574 if (mcopy(ms, p, m->type, m->flag & INDIR, s, in mget()
1575 CAST(uint32_t, offset + o), CAST(uint32_t, nbytes), m) == -1) in mget()
1582 m->type, m->flag, offset, o, nbytes, in mget()
1587 file_mdump(m); in mget()
1591 if (m->flag & INDIR) { in mget()
1592 intmax_t off = m->in_offset; in mget()
1593 const int sgn = m->in_op & FILE_OPSIGNED; in mget()
1594 if (m->in_op & FILE_OPINDIRECT) { in mget()
1598 switch (op = cvt_flip(m->in_type, flip)) { in mget()
1659 switch (in_type = cvt_flip(m->in_type, flip)) { in mget()
1663 offset = do_ops(m, SEXT(sgn,8,p->b), off); in mget()
1668 offset = do_ops(m, SEXT(sgn,16,BE16(p)), off); in mget()
1673 offset = do_ops(m, SEXT(sgn,16,LE16(p)), off); in mget()
1678 offset = do_ops(m, SEXT(sgn,16,p->h), off); in mget()
1687 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1696 offset = do_ops(m, SEXT(sgn,32,lhs), off); in mget()
1701 offset = do_ops(m, SEXT(sgn,32,ME32(p)), off); in mget()
1706 offset = do_ops(m, SEXT(sgn,32,p->l), off); in mget()
1711 offset = do_ops(m, SEXT(sgn,64,LE64(p)), off); in mget()
1716 offset = do_ops(m, SEXT(sgn,64,BE64(p)), off); in mget()
1724 if (m->flag & INDIROFFADD) { in mget()
1741 if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1) in mget()
1749 file_mdump(m); in mget()
1755 switch (m->type) { in mget()
1802 if (OFFSET_OOB(nbytes, offset, m->vallen)) in mget()
1812 if (m->str_flags & INDIRECT_RELATIVE) in mget()
1839 file_printf(ms, F(ms, m->desc, "%u"), offset) == -1) { in mget()
1854 rbuf = m->value.s; in mget()
1865 if (m->flag & NOSPACE) in mget()
1878 if (file_printf(ms, "%s", m->desc) == -1) in mget()
1887 if (!mconvert(ms, m, flip)) in mget()
2034 magiccheck(struct magic_set *ms, struct magic *m) in magiccheck() argument
2036 uint64_t l = m->value.q; in magiccheck()
2043 switch (m->type) { in magiccheck()
2088 fl = m->value.f; in magiccheck()
2090 switch (m->reln) { in magiccheck()
2113 m->reln); in magiccheck()
2121 dl = m->value.d; in magiccheck()
2123 switch (m->reln) { in magiccheck()
2145 file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln); in magiccheck()
2159 v = file_strncmp(m->value.s, p->s, CAST(size_t, m->vallen), in magiccheck()
2160 sizeof(p->s), m->str_flags); in magiccheck()
2166 v = file_strncmp16(m->value.s, p->s, CAST(size_t, m->vallen), in magiccheck()
2167 sizeof(p->s), m->str_flags); in magiccheck()
2177 slen = MIN(m->vallen, sizeof(m->value.s)); in magiccheck()
2181 if (slen > 0 && m->str_flags == 0) { in magiccheck()
2183 idx = m->str_range + slen; in magiccheck()
2184 if (m->str_range == 0 || ms->search.s_len < idx) in magiccheck()
2187 m->value.s, slen)); in magiccheck()
2197 for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) { in magiccheck()
2201 v = file_strncmp(m->value.s, ms->search.s + idx, slen, in magiccheck()
2202 ms->search.s_len - idx, m->str_flags); in magiccheck()
2218 if (m->str_flags & STRING_IGNORE_CASE) { in magiccheck()
2222 pattern = convert_libmagic_pattern((char *)m->value.s, m->vallen, options); in magiccheck()
2290 matched = der_cmp(ms, m); in magiccheck()
2301 v = memcmp(m->value.guid, p->guid, sizeof(p->guid)); in magiccheck()
2304 file_magerror(ms, "invalid type %d in magiccheck()", m->type); in magiccheck()
2308 v = file_signextend(ms, m, v); in magiccheck()
2310 switch (m->reln) { in magiccheck()
2337 if (m->flag & UNSIGNED) { in magiccheck()
2356 if (m->flag & UNSIGNED) { in magiccheck()
2397 m->reln); in magiccheck()
2405 handle_annotation(struct magic_set *ms, struct magic *m, int firstline) in handle_annotation() argument
2407 if ((ms->flags & MAGIC_APPLE) && m->apple[0]) { in handle_annotation()
2410 if (file_printf(ms, "%.8s", m->apple) == -1) in handle_annotation()
2414 if ((ms->flags & MAGIC_EXTENSION) && m->ext[0]) { in handle_annotation()
2417 if (file_printf(ms, "%s", m->ext) == -1) in handle_annotation()
2421 if ((ms->flags & MAGIC_MIME_TYPE) && m->mimetype[0]) { in handle_annotation()
2426 if (varexpand(ms, buf, sizeof(buf), m->mimetype) == -1) in handle_annotation()
2427 p = m->mimetype; in handle_annotation()