Lines Matching defs:ms
90 file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
106 for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
107 if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
120 file_fmtcheck(struct magic_set *ms, const struct magic *m, const char *def,
125 file_magerror(ms,
162 match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
171 int print = (ms->flags & MAGIC_NODESC) == 0;
176 if (file_check_mem(ms, cont_level) == -1)
197 ms->offset = m->offset;
198 ms->line = m->lineno;
201 switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
213 switch (magiccheck(ms, m)) {
233 if ((e = handle_annotation(ms, m)) != 0) {
247 if (print_sep(ms, firstline) == -1)
252 if (print && mprint(ms, m) == -1)
255 switch (moffset(ms, m, nbytes, &ms->c.li[cont_level].off)) {
264 if (file_check_mem(ms, ++cont_level) == -1)
270 ms->line = m->lineno; /* for messages */
281 ms->offset = m->offset;
283 ms->offset +=
284 ms->c.li[cont_level - 1].off;
290 if (ms->c.li[cont_level].last_match == 1)
294 switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
311 switch (flush ? 1 : magiccheck(ms, m)) {
316 ms->c.li[cont_level].last_match = 0;
321 ms->c.li[cont_level].last_match = 1;
324 ms->c.li[cont_level].got_match = 0;
325 else if (ms->c.li[cont_level].got_match) {
329 ms->c.li[cont_level].got_match = 1;
331 if ((e = handle_annotation(ms, m)) != 0) {
344 if (print_sep(ms, firstline)
360 file_printf(ms, " ") == -1)
364 if (print && mprint(ms, m) == -1)
367 switch (moffset(ms, m, nbytes,
368 &ms->c.li[cont_level].off)) {
385 if (file_check_mem(ms, ++cont_level) == -1)
395 if ((ms->flags & MAGIC_CONTINUE) == 0 && *printed_something) {
404 check_fmt(struct magic_set *ms, struct magic *m)
414 file_regerror(&rx, rc, ms);
443 mprint(struct magic_set *ms, struct magic *m)
450 union VALUETYPE *p = &ms->ms_value;
454 v = file_signextend(ms, m, (uint64_t)p->b);
455 switch (check_fmt(ms, m)) {
461 if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
465 if (file_printf(ms, F(ms, m, "%d"),
470 t = ms->offset + sizeof(char);
476 v = file_signextend(ms, m, (uint64_t)p->h);
477 switch (check_fmt(ms, m)) {
483 if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
487 if (file_printf(ms, F(ms, m, "%u"),
492 t = ms->offset + sizeof(short);
499 v = file_signextend(ms, m, (uint64_t)p->l);
500 switch (check_fmt(ms, m)) {
505 if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
509 if (file_printf(ms, F(ms, m, "%u"), (uint32_t) v) == -1)
513 t = ms->offset + sizeof(int32_t);
519 v = file_signextend(ms, m, p->q);
520 switch (check_fmt(ms, m)) {
526 if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
530 if (file_printf(ms, F(ms, m, "%" INT64_T_FORMAT "u"),
535 t = ms->offset + sizeof(int64_t);
543 if (file_printf(ms, F(ms, m, "%s"),
547 t = ms->offset + m->vallen;
553 t = ms->offset + strlen(str);
571 if (file_printf(ms, F(ms, m, "%s"),
584 if (file_printf(ms, F(ms, m, "%s"),
587 t = ms->offset + sizeof(uint32_t);
594 if (file_printf(ms, F(ms, m, "%s"),
597 t = ms->offset + sizeof(uint32_t);
603 if (file_printf(ms, F(ms, m, "%s"),
606 t = ms->offset + sizeof(uint64_t);
612 if (file_printf(ms, F(ms, m, "%s"),
615 t = ms->offset + sizeof(uint64_t);
621 if (file_printf(ms, F(ms, m, "%s"),
624 t = ms->offset + sizeof(uint64_t);
631 switch (check_fmt(ms, m)) {
636 if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
640 if (file_printf(ms, F(ms, m, "%g"), vf) == -1)
644 t = ms->offset + sizeof(float);
651 switch (check_fmt(ms, m)) {
656 if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
660 if (file_printf(ms, F(ms, m, "%g"), vd) == -1)
664 t = ms->offset + sizeof(double);
672 cp = strndup((const char *)ms->search.s, ms->search.rm_len);
674 file_oomem(ms, ms->search.rm_len);
677 rval = file_printf(ms, F(ms, m, "%s"),
685 t = ms->search.offset;
687 t = ms->search.offset + ms->search.rm_len;
693 if (file_printf(ms, "%s", m->desc) == -1)
695 t = ms->offset;
701 t = ms->offset;
704 if (file_printf(ms, F(ms, m, "%s"),
705 file_printable(sbuf, sizeof(sbuf), ms->ms_value.s)) == -1)
707 t = ms->offset;
710 file_magerror(ms, "invalid m->type (%d) in mprint()", m->type);
717 moffset(struct magic_set *ms, struct magic *m, size_t nbytes, int32_t *op)
723 o = CAST(int32_t, (ms->offset + sizeof(char)));
729 o = CAST(int32_t, (ms->offset + sizeof(short)));
736 o = CAST(int32_t, (ms->offset + sizeof(int32_t)));
742 o = CAST(int32_t, (ms->offset + sizeof(int64_t)));
750 o = ms->offset + m->vallen;
752 union VALUETYPE *p = &ms->ms_value;
756 o = CAST(uint32_t, (ms->offset + strlen(p->s)));
766 o = CAST(int32_t, (ms->offset + sizeof(uint32_t)));
773 o = CAST(int32_t, (ms->offset + sizeof(uint32_t)));
779 o = CAST(int32_t, (ms->offset + sizeof(uint64_t)));
785 o = CAST(int32_t, (ms->offset + sizeof(uint64_t)));
791 o = CAST(int32_t, (ms->offset + sizeof(float)));
797 o = CAST(int32_t, (ms->offset + sizeof(double)));
802 o = CAST(int32_t, ms->search.offset);
805 (ms->search.offset + ms->search.rm_len));
810 o = CAST(int32_t, ms->search.offset);
812 o = CAST(int32_t, (ms->search.offset + m->vallen));
818 o = ms->offset;
823 o = der_offs(ms, m, nbytes);
825 if ((ms->flags & MAGIC_DEBUG) != 0) {
843 file_error(ms, 0, "Offset out of range %zu > %zu",
853 cvt_id3(struct magic_set *ms, uint32_t v)
859 if ((ms->flags & MAGIC_DEBUG) != 0)
1016 mconvert(struct magic_set *ms, struct magic *m, int flip)
1018 union VALUETYPE *p = &ms->ms_value;
1155 file_magerror(ms, "invalid type %d in mconvert()", m->type);
1159 file_magerror(ms, "zerodivide in mconvert()");
1174 mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
1187 ms->search.s = RCAST(const char *, s) + offset;
1188 ms->search.s_len = nbytes - offset;
1189 ms->search.offset = offset;
1201 ms->search.s_len = 0;
1202 ms->search.s = NULL;
1216 if (bytecnt > ms->regex_max)
1217 bytecnt = ms->regex_max;
1235 ms->search.s = buf;
1236 ms->search.s_len = last - buf;
1237 ms->search.offset = offset;
1238 ms->search.rm_len = 0;
1298 mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
1303 uint32_t offset = ms->offset;
1308 union VALUETYPE *p = &ms->ms_value;
1311 if (*indir_count >= ms->indir_max) {
1312 file_error(ms, 0, "indirect count (%hu) exceeded",
1317 if (*name_count >= ms->name_max) {
1318 file_error(ms, 0, "name use count (%hu) exceeded",
1323 if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),
1327 if ((ms->flags & MAGIC_DEBUG) != 0) {
1374 if ((ms->flags & MAGIC_DEBUG) != 0)
1527 lhs = cvt_id3(ms, lhs);
1566 lhs = cvt_id3(ms, lhs);
1675 offset += ms->c.li[cont_level-1].off;
1677 if ((ms->flags & MAGIC_DEBUG) != 0)
1682 if ((ms->flags & MAGIC_DEBUG) != 0)
1685 if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1)
1687 ms->offset = offset;
1689 if ((ms->flags & MAGIC_DEBUG) != 0) {
1759 if ((pb = file_push_buffer(ms)) == NULL)
1763 rv = file_softmagic(ms, s + offset, nbytes - offset,
1766 if ((ms->flags & MAGIC_DEBUG) != 0)
1769 rbuf = file_pop_buffer(ms, pb);
1770 if (rbuf == NULL && ms->event_flags & EVENT_HAD_ERR)
1774 if ((ms->flags & MAGIC_NODESC) == 0 &&
1775 file_printf(ms, F(ms, m, "%u"), offset) == -1) {
1779 if (file_printf(ms, "%s", rbuf) == -1) {
1795 if (file_magicfind(ms, rbuf, &ml) == -1) {
1796 file_error(ms, 0, "cannot find entry `%s'", rbuf);
1803 rv = match(ms, ml.magic, ml.nmagic, s, nbytes, offset + o,
1811 if (ms->flags & MAGIC_NODESC)
1813 if (file_printf(ms, "%s", m->desc) == -1)
1822 if (!mconvert(ms, m, flip))
1903 magiccheck(struct magic_set *ms, struct magic *m)
1910 union VALUETYPE *p = &ms->ms_value;
1980 file_magerror(ms, "cannot happen with float: invalid relation `%c'",
2013 file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln);
2036 case FILE_SEARCH: { /* search ms->search.s for the string m->value.s */
2040 if (ms->search.s == NULL)
2048 if (slen + idx > ms->search.s_len)
2051 v = file_strncmp(m->value.s, ms->search.s + idx, slen,
2054 ms->search.offset += idx;
2055 ms->search.rm_len = m->str_range - idx;
2066 if (ms->search.s == NULL)
2074 file_regerror(&rx, rc, ms);
2078 size_t slen = ms->search.s_len;
2084 file_error(ms, errno,
2089 memcpy(copy, ms->search.s, slen);
2093 search = ms->search.s;
2101 ms->search.s += (int)pmatch.rm_so;
2102 ms->search.offset += (size_t)pmatch.rm_so;
2103 ms->search.rm_len =
2113 file_regerror(&rx, rc, ms);
2128 matched = der_cmp(ms, m);
2130 if ((ms->flags & MAGIC_DEBUG) != 0) {
2138 file_magerror(ms, "invalid type %d in magiccheck()", m->type);
2142 v = file_signextend(ms, m, v);
2146 if ((ms->flags & MAGIC_DEBUG) != 0)
2154 if ((ms->flags & MAGIC_DEBUG) != 0)
2162 if ((ms->flags & MAGIC_DEBUG) != 0)
2171 if ((ms->flags & MAGIC_DEBUG) != 0)
2179 if ((ms->flags & MAGIC_DEBUG) != 0)
2189 if ((ms->flags & MAGIC_DEBUG) != 0)
2197 if ((ms->flags & MAGIC_DEBUG) != 0)
2206 if ((ms->flags & MAGIC_DEBUG) != 0)
2216 if ((ms->flags & MAGIC_DEBUG) != 0)
2225 file_magerror(ms, "cannot happen: invalid relation `%c'",
2234 handle_annotation(struct magic_set *ms, struct magic *m)
2236 if ((ms->flags & MAGIC_APPLE) && m->apple[0]) {
2237 if (file_printf(ms, "%.8s", m->apple) == -1)
2241 if ((ms->flags & MAGIC_EXTENSION) && m->ext[0]) {
2242 if (file_printf(ms, "%s", m->ext) == -1)
2246 if ((ms->flags & MAGIC_MIME_TYPE) && m->mimetype[0]) {
2247 if (file_printf(ms, "%s", m->mimetype) == -1)
2255 print_sep(struct magic_set *ms, int firstline)
2257 if (ms->flags & MAGIC_NODESC)
2265 return file_printf(ms, "\n- ");