Lines Matching refs:ms
121 file_softmagic(struct magic_set *ms, const struct buffer *b, in file_softmagic() argument
137 for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next) in file_softmagic()
138 if ((rv = match(ms, ml->magic, ml->nmagic, b, 0, mode, in file_softmagic()
151 file_fmtcheck(struct magic_set *ms, const char *desc, const char *def, in file_fmtcheck() argument
161 file_magerror(ms, in file_fmtcheck()
200 match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, in match() argument
212 int print = (ms->flags & MAGIC_NODESC) == 0; in match()
223 if (file_check_mem(ms, cont_level) == -1) 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()
266 switch (magiccheck(ms, m)) { in match()
289 if ((e = handle_annotation(ms, m, firstline)) != 0) in match()
305 if (print_sep(ms, firstline) == -1) in match()
307 if (mprint(ms, m) == -1) in match()
311 switch (moffset(ms, m, &bb, &ms->c.li[cont_level].off)) { in match()
320 if (file_check_mem(ms, ++cont_level) == -1) in match()
326 ms->line = m->lineno; /* for messages */ in match()
337 if (msetoffset(ms, m, &bb, b, offset, cont_level) == -1) in match()
341 if ((ms->flags & MAGIC_DEBUG) != 0) in match()
347 ms->offset += in match()
348 ms->c.li[cont_level - 1].off; in match()
354 if (ms->c.li[cont_level].last_match == 1) in match()
358 switch (mget(ms, m, b, CAST(const unsigned char *, in match()
379 switch (flush ? 1 : magiccheck(ms, m)) { in match()
384 ms->c.li[cont_level].last_match = 0; in match()
389 ms->c.li[cont_level].last_match = 1; in match()
392 ms->c.li[cont_level].got_match = 0; in match()
393 else if (ms->c.li[cont_level].got_match) { in match()
397 ms->c.li[cont_level].got_match = 1; in match()
402 if ((e = handle_annotation(ms, m, firstline)) in match()
423 if (print_sep(ms, firstline) in match()
430 if (file_printf(ms, " ") == -1) in match()
435 if (mprint(ms, m) == -1) in match()
440 switch (moffset(ms, m, &bb, in match()
441 &ms->c.li[cont_level].off)) { in match()
456 if (file_check_mem(ms, ++cont_level) == -1) in match()
465 if ((ms->flags & MAGIC_CONTINUE) == 0) in match()
477 check_fmt(struct magic_set *ms, const char *fmt) in check_fmt() argument
502 varexpand(struct magic_set *ms, char *buf, size_t len, const char *str) in varexpand() argument
527 if (ms->mode & 0111) { in varexpand()
557 mprint(struct magic_set *ms, struct magic *m) in mprint() argument
565 union VALUETYPE *p = &ms->ms_value; in mprint()
567 if (varexpand(ms, ebuf, sizeof(ebuf), m->desc) == -1) in mprint()
574 v = file_signextend(ms, m, CAST(uint64_t, p->b)); in mprint()
575 switch (check_fmt(ms, desc)) { in mprint()
581 if (file_printf(ms, F(ms, desc, "%s"), buf) == -1) in mprint()
585 if (file_printf(ms, F(ms, desc, "%d"), in mprint()
590 t = ms->offset + sizeof(char); in mprint()
596 v = file_signextend(ms, m, CAST(uint64_t, p->h)); in mprint()
597 switch (check_fmt(ms, desc)) { in mprint()
603 if (file_printf(ms, F(ms, desc, "%s"), buf) == -1) in mprint()
607 if (file_printf(ms, F(ms, desc, "%u"), in mprint()
612 t = ms->offset + sizeof(short); in mprint()
619 v = file_signextend(ms, m, CAST(uint64_t, p->l)); in mprint()
620 switch (check_fmt(ms, desc)) { in mprint()
626 if (file_printf(ms, F(ms, desc, "%s"), buf) == -1) in mprint()
630 if (file_printf(ms, F(ms, desc, "%u"), in mprint()
635 t = ms->offset + sizeof(int32_t); in mprint()
642 v = file_signextend(ms, m, p->q); in mprint()
643 switch (check_fmt(ms, desc)) { in mprint()
649 if (file_printf(ms, F(ms, desc, "%s"), buf) == -1) in mprint()
653 if (file_printf(ms, F(ms, desc, "%" INT64_T_FORMAT "u"), in mprint()
658 t = ms->offset + sizeof(int64_t); in mprint()
666 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
670 t = ms->offset + m->vallen; in mprint()
676 t = ms->offset + strlen(str); in mprint()
694 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
700 size_t l = file_pstring_length_size(ms, m); in mprint()
712 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
715 t = ms->offset + sizeof(uint32_t); in mprint()
722 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
725 t = ms->offset + sizeof(uint32_t); in mprint()
731 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
734 t = ms->offset + sizeof(uint64_t); in mprint()
740 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
743 t = ms->offset + sizeof(uint64_t); in mprint()
749 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
753 t = ms->offset + sizeof(uint64_t); in mprint()
760 switch (check_fmt(ms, desc)) { in mprint()
765 if (file_printf(ms, F(ms, desc, "%s"), buf) == -1) in mprint()
769 if (file_printf(ms, F(ms, desc, "%g"), vf) == -1) in mprint()
773 t = ms->offset + sizeof(float); in mprint()
780 switch (check_fmt(ms, desc)) { in mprint()
785 if (file_printf(ms, F(ms, desc, "%s"), buf) == -1) in mprint()
789 if (file_printf(ms, F(ms, desc, "%g"), vd) == -1) in mprint()
793 t = ms->offset + sizeof(double); in mprint()
801 cp = estrndup(RCAST(const char *, ms->search.s), in mprint()
802 ms->search.rm_len); in mprint()
803 rval = file_printf(ms, F(ms, desc, "%s"), in mprint()
804 file_printable(sbuf, sizeof(sbuf), cp, ms->search.rm_len)); in mprint()
811 t = ms->search.offset; in mprint()
813 t = ms->search.offset + ms->search.rm_len; in mprint()
819 if (file_printf(ms, "%s", m->desc) == -1) in mprint()
821 t = ms->offset; in mprint()
827 t = ms->offset; in mprint()
830 if (file_printf(ms, F(ms, desc, "%s"), in mprint()
831 file_printable(sbuf, sizeof(sbuf), ms->ms_value.s, in mprint()
832 sizeof(ms->ms_value.s))) == -1) in mprint()
834 t = ms->offset; in mprint()
837 (void) file_print_guid(buf, sizeof(buf), ms->ms_value.guid); in mprint()
838 if (file_printf(ms, F(ms, desc, "%s"), buf) == -1) in mprint()
840 t = ms->offset; 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
858 o = CAST(int32_t, (ms->offset + sizeof(char))); in moffset()
864 o = CAST(int32_t, (ms->offset + sizeof(short))); in moffset()
871 o = CAST(int32_t, (ms->offset + sizeof(int32_t))); in moffset()
877 o = CAST(int32_t, (ms->offset + sizeof(int64_t))); in moffset()
885 o = ms->offset + m->vallen; in moffset()
887 union VALUETYPE *p = &ms->ms_value; in moffset()
891 o = CAST(uint32_t, (ms->offset + strlen(p->s))); in moffset()
893 size_t l = file_pstring_length_size(ms, m); in moffset()
905 o = CAST(int32_t, (ms->offset + sizeof(uint32_t))); in moffset()
912 o = CAST(int32_t, (ms->offset + sizeof(uint32_t))); in moffset()
918 o = CAST(int32_t, (ms->offset + sizeof(uint64_t))); in moffset()
924 o = CAST(int32_t, (ms->offset + sizeof(uint64_t))); in moffset()
930 o = CAST(int32_t, (ms->offset + sizeof(float))); in moffset()
936 o = CAST(int32_t, (ms->offset + sizeof(double))); in moffset()
941 o = CAST(int32_t, ms->search.offset); in moffset()
944 (ms->search.offset + ms->search.rm_len)); in moffset()
949 o = CAST(int32_t, ms->search.offset); in moffset()
951 o = CAST(int32_t, (ms->search.offset + m->vallen)); in moffset()
958 o = ms->offset; in moffset()
962 o = der_offs(ms, m, nbytes); in moffset()
964 if ((ms->flags & MAGIC_DEBUG) != 0) { in moffset()
975 o = CAST(int32_t, (ms->offset + 2 * sizeof(uint64_t))); in moffset()
985 file_error(ms, 0, "Offset out of range %" SIZE_T_FORMAT in moffset()
995 cvt_id3(struct magic_set *ms, uint32_t v) in cvt_id3() argument
1001 if ((ms->flags & MAGIC_DEBUG) != 0) in cvt_id3()
1158 mconvert(struct magic_set *ms, struct magic *m, int flip) in mconvert() argument
1160 union VALUETYPE *p = &ms->ms_value; 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()
1304 file_magerror(ms, "invalid type %d in mconvert()", m->type); in mconvert()
1308 file_magerror(ms, "zerodivide in mconvert()"); in mconvert()
1323 mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, in mcopy() argument
1336 ms->search.s = RCAST(const char *, s) + offset; in mcopy()
1337 ms->search.s_len = nbytes - offset; in mcopy()
1338 ms->search.offset = offset; in mcopy()
1350 ms->search.s_len = 0; in mcopy()
1351 ms->search.s = NULL; in mcopy()
1365 if (bytecnt > ms->regex_max) in mcopy()
1366 bytecnt = ms->regex_max; in mcopy()
1386 ms->search.s = buf; in mcopy()
1387 ms->search.s_len = last - buf; in mcopy()
1388 ms->search.offset = offset; in mcopy()
1389 ms->search.rm_len = 0; in mcopy()
1495 msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb, in msetoffset() argument
1505 file_error(ms, 0, "negative offset %d at continuation" in msetoffset()
1514 file_magerror(ms, "non zero offset %" SIZE_T_FORMAT in msetoffset()
1521 ms->eoffset = ms->offset = CAST(int32_t, b->elen - m->offset); in msetoffset()
1528 ms->offset = offset; in msetoffset()
1529 ms->eoffset = 0; in msetoffset()
1531 ms->offset = ms->eoffset + offset; in msetoffset()
1534 if ((ms->flags & MAGIC_DEBUG) != 0) { in msetoffset()
1538 bb->fbuf, bb->flen, bb->elen, ms->offset, b->fbuf, in msetoffset()
1545 mget(struct magic_set *ms, struct magic *m, const struct buffer *b, in mget() argument
1551 uint32_t offset = ms->offset; in mget()
1557 union VALUETYPE *p = &ms->ms_value; in mget()
1560 if (*indir_count >= ms->indir_max) { in mget()
1561 file_error(ms, 0, "indirect count (%hu) exceeded", in mget()
1566 if (*name_count >= ms->name_max) { in mget()
1567 file_error(ms, 0, "name use count (%hu) exceeded", in mget()
1574 if (mcopy(ms, p, m->type, m->flag & INDIR, s, in mget()
1578 if ((ms->flags & MAGIC_DEBUG) != 0) { in mget()
1652 if ((ms->flags & MAGIC_DEBUG) != 0) in mget()
1656 if ((ms->flags & MAGIC_DEBUG) != 0) in mget()
1686 lhs = cvt_id3(ms, CAST(uint32_t, lhs)); in mget()
1695 lhs = cvt_id3(ms, CAST(uint32_t, lhs)); in mget()
1719 if ((ms->flags & MAGIC_DEBUG) != 0) in mget()
1726 if ((ms->flags & MAGIC_DEBUG) != 0) in mget()
1731 offset += ms->c.li[cont_level - 1].off; in mget()
1733 if ((ms->flags & MAGIC_DEBUG) != 0) in mget()
1738 if ((ms->flags & MAGIC_DEBUG) != 0) in mget()
1741 if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1) in mget()
1743 ms->offset = offset; in mget()
1745 if ((ms->flags & MAGIC_DEBUG) != 0) { in mget()
1820 if ((pb = file_push_buffer(ms)) == NULL) in mget()
1827 rv = file_softmagic(ms, &bb, in mget()
1830 if ((ms->flags & MAGIC_DEBUG) != 0) in mget()
1833 rbuf = file_pop_buffer(ms, pb); in mget()
1834 if (rbuf == NULL && ms->event_flags & EVENT_HAD_ERR) in mget()
1838 if ((ms->flags & MAGIC_NODESC) == 0 && in mget()
1839 file_printf(ms, F(ms, m->desc, "%u"), offset) == -1) { in mget()
1843 if (file_printf(ms, "%s", rbuf) == -1) { in mget()
1859 if (file_magicfind(ms, rbuf, &ml) == -1) { in mget()
1860 file_error(ms, 0, "cannot find entry `%s'", rbuf); in mget()
1867 rv = match(ms, ml.magic, ml.nmagic, b, offset + o, in mget()
1876 if (ms->flags & MAGIC_NODESC) 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
2041 union VALUETYPE *p = &ms->ms_value; in magiccheck()
2112 file_magerror(ms, "cannot happen with float: invalid relation `%c'", in magiccheck()
2145 file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln); in magiccheck()
2174 if (ms->search.s == NULL) in magiccheck()
2184 if (m->str_range == 0 || ms->search.s_len < idx) in magiccheck()
2185 idx = ms->search.s_len; in magiccheck()
2186 found = CAST(const char *, memmem(ms->search.s, idx, in magiccheck()
2190 idx = found - ms->search.s; in magiccheck()
2191 ms->search.offset += idx; in magiccheck()
2192 ms->search.rm_len = ms->search.s_len - idx; in magiccheck()
2198 if (slen + idx > ms->search.s_len) 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()
2204 ms->search.offset += idx; in magiccheck()
2205 ms->search.rm_len = ms->search.s_len - idx; in magiccheck()
2238 haystack = zend_string_init(ms->search.s, ms->search.s_len, 0); in magiccheck()
2264 ms->search.s += Z_LVAL_P(offset); /* this is where the match starts */ in magiccheck()
2265 ms->search.offset += Z_LVAL_P(offset); /* this is where the match starts as size_t */ in magiccheck()
2266 ms->search.rm_len = Z_STRLEN_P(match) /* This is the length of the matched pattern */; in magiccheck()
2290 matched = der_cmp(ms, m); in magiccheck()
2292 if ((ms->flags & MAGIC_DEBUG) != 0) { in magiccheck()
2304 file_magerror(ms, "invalid type %d in magiccheck()", m->type); in magiccheck()
2308 v = file_signextend(ms, m, v); in magiccheck()
2312 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2320 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2329 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2339 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2347 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2358 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2366 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2376 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2387 if ((ms->flags & MAGIC_DEBUG) != 0) in magiccheck()
2396 file_magerror(ms, "cannot happen: invalid relation `%c'", 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()
2408 if (print_sep(ms, firstline) == -1) 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()
2415 if (print_sep(ms, firstline) == -1) 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()
2424 if (print_sep(ms, firstline) == -1) in handle_annotation()
2426 if (varexpand(ms, buf, sizeof(buf), m->mimetype) == -1) in handle_annotation()
2430 if (file_printf(ms, "%s", p) == -1) in handle_annotation()
2438 print_sep(struct magic_set *ms, int firstline) in print_sep() argument
2446 return file_separator(ms); in print_sep()