Lines Matching refs:m

773 apprentice_magic_strength(const struct magic *m)  in apprentice_magic_strength()  argument
778 switch (m->type) { in apprentice_magic_strength()
780 if (m->factor_op != FILE_FACTOR_OP_NONE) in apprentice_magic_strength()
818 ts = typesize(m->type); in apprentice_magic_strength()
826 val += m->vallen * MULT; in apprentice_magic_strength()
831 val += m->vallen * MULT / 2; in apprentice_magic_strength()
835 val += m->vallen * MAX(MULT / m->vallen, 1); in apprentice_magic_strength()
839 v = nonmagic(m->value.s); in apprentice_magic_strength()
853 (void)fprintf(stderr, "Bad type %d\n", m->type); in apprentice_magic_strength()
857 switch (m->reln) { in apprentice_magic_strength()
878 (void)fprintf(stderr, "Bad relation %c\n", m->reln); in apprentice_magic_strength()
885 switch (m->factor_op) { in apprentice_magic_strength()
889 val += m->factor; in apprentice_magic_strength()
892 val -= m->factor; in apprentice_magic_strength()
895 val *= m->factor; in apprentice_magic_strength()
898 val /= m->factor; in apprentice_magic_strength()
908 if (m->desc[0] == '\0') in apprentice_magic_strength()
941 struct magic *m = &ml->magic[magindex]; in apprentice_list() local
942 if ((m->flag & mode) != mode) { in apprentice_list()
961 apprentice_magic_strength(m), in apprentice_list()
970 set_test_type(struct magic *mstart, struct magic *m) in set_test_type() argument
972 switch (m->type) { in set_test_type()
1032 if (file_looks_utf8(m->value.us, (size_t)m->vallen, NULL, in set_test_type()
1386 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1388 if (!(m->flag & UNSIGNED)) { in file_signextend()
1389 switch(m->type) { in file_signextend()
1453 m->type); in file_signextend()
1461 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1466 if ((m->type != FILE_REGEX || (m->str_flags & REGEX_LINE_COUNT) == 0) && in string_modifier_check()
1467 (m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0)) { in string_modifier_check()
1472 switch (m->type) { in string_modifier_check()
1475 if (m->str_flags != 0) { in string_modifier_check()
1483 if ((m->str_flags & REGEX_OFFSET_START) != 0) { in string_modifier_check()
1491 if (m->str_range == 0) { in string_modifier_check()
1495 m->str_range = STRING_DEFAULT_RANGE; in string_modifier_check()
1500 if ((m->str_flags & STRING_COMPACT_WHITESPACE) != 0) { in string_modifier_check()
1505 if ((m->str_flags & STRING_COMPACT_OPTIONAL_WHITESPACE) != 0) { in string_modifier_check()
1513 m->type); in string_modifier_check()
1616 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1623 m->str_flags |= INDIRECT_RELATIVE; in parse_indirect_modifier()
1637 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1645 m->mask_op |= op; in parse_op_modifier()
1648 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1654 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1669 m->str_range = CAST(uint32_t, strtoul(l, &t, 0)); in parse_string_modifier()
1670 if (m->str_range == 0) in parse_string_modifier()
1675 m->str_flags |= STRING_COMPACT_WHITESPACE; in parse_string_modifier()
1678 m->str_flags |= STRING_COMPACT_OPTIONAL_WHITESPACE; in parse_string_modifier()
1681 m->str_flags |= STRING_IGNORE_LOWERCASE; in parse_string_modifier()
1684 m->str_flags |= STRING_IGNORE_UPPERCASE; in parse_string_modifier()
1687 m->str_flags |= REGEX_OFFSET_START; in parse_string_modifier()
1690 m->str_flags |= STRING_BINTEST; in parse_string_modifier()
1693 m->str_flags |= STRING_TEXTTEST; in parse_string_modifier()
1696 m->str_flags |= STRING_TRIM; in parse_string_modifier()
1699 #define SET_LENGTH(a) m->str_flags = (m->str_flags & ~PSTRING_LEN) | (a) in parse_string_modifier()
1700 if (m->type != FILE_PSTRING) in parse_string_modifier()
1705 if (m->type != FILE_PSTRING) in parse_string_modifier()
1710 if (m->type != FILE_PSTRING) in parse_string_modifier()
1715 if (m->type != FILE_PSTRING) in parse_string_modifier()
1720 switch (m->type) { in parse_string_modifier()
1730 if (m->type != FILE_PSTRING) in parse_string_modifier()
1732 m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF; in parse_string_modifier()
1745 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
1765 struct magic *m; in parse() local
1796 m = &me->mp[me->cont_count - 1]; in parse()
1797 diff = (int32_t)cont_level - (int32_t)m->cont_level; in parse()
1801 m->cont_level); in parse()
1810 me->mp = m = nm; in parse()
1813 m = &me->mp[me->cont_count++]; in parse()
1814 (void)memset(m, 0, sizeof(*m)); in parse()
1815 m->cont_level = cont_level; in parse()
1817 static const size_t len = sizeof(*m) * ALLOC_CHUNK; in parse()
1820 if ((m = CAST(struct magic *, emalloc(len))) == NULL) { in parse()
1824 me->mp = m; in parse()
1826 (void)memset(m, 0, sizeof(*m)); in parse()
1827 m->factor_op = FILE_FACTOR_OP_NONE; in parse()
1828 m->cont_level = 0; in parse()
1831 m->lineno = CAST(uint32_t, lineno); in parse()
1835 m->flag |= OFFADD; in parse()
1839 m->flag |= INDIR; in parse()
1840 if (m->flag & OFFADD) in parse()
1841 m->flag = (m->flag & ~OFFADD) | INDIROFFADD; in parse()
1845 m->flag |= OFFADD; in parse()
1849 if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD))) { in parse()
1856 m->offset = (int32_t)strtol(l, &t, 0); in parse()
1864 if (m->flag & INDIR) { in parse()
1865 m->in_type = FILE_LONG; in parse()
1866 m->in_offset = 0; in parse()
1867 m->in_op = 0; in parse()
1873 m->in_op |= FILE_OPSIGNED; in parse()
1877 m->in_type = FILE_LELONG; in parse()
1880 m->in_type = FILE_BELONG; in parse()
1883 m->in_type = FILE_MELONG; in parse()
1887 m->in_type = FILE_LESHORT; in parse()
1891 m->in_type = FILE_BESHORT; in parse()
1897 m->in_type = FILE_BYTE; in parse()
1902 m->in_type = FILE_LEDOUBLE; in parse()
1907 m->in_type = FILE_BEDOUBLE; in parse()
1910 m->in_type = FILE_LEID3; in parse()
1913 m->in_type = FILE_BEID3; in parse()
1926 m->in_op |= FILE_OPINVERSE; in parse()
1930 m->in_op |= op; in parse()
1934 m->in_op |= FILE_OPINDIRECT; in parse()
1938 m->in_offset = (int32_t)strtol(l, &t, 0); in parse()
1948 ((m->in_op & FILE_OPINDIRECT) && *l++ != ')')) { in parse()
1958 m->cond = get_cond(l, &l); in parse()
1959 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
1974 m->type = get_type(type_tbl, l + 1, &l); in parse()
1975 if (m->type == FILE_INVALID) { in parse()
1980 m->type = get_standard_integer_type(l, &l); in parse()
1983 if (m->type != FILE_INVALID) in parse()
1984 m->flag |= UNSIGNED; in parse()
1992 m->type = get_type(type_tbl, l, &l); in parse()
1993 if (m->type == FILE_INVALID) { in parse()
2000 m->type = get_standard_integer_type(l, &l); in parse()
2002 m->type = FILE_STRING; in parse()
2008 if (m->type == FILE_INVALID) { in parse()
2010 m->type = get_type(special_tbl, l, &l); in parse()
2013 if (m->type == FILE_INVALID) { in parse()
2022 m->mask_op = 0; in parse()
2024 if (!IS_LIBMAGIC_STRING(m->type)) in parse()
2025 m->mask_op |= FILE_OPINVERSE; in parse()
2030 m->str_range = 0; in parse()
2031 m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0; in parse()
2033 if (IS_LIBMAGIC_STRING(m->type)) { in parse()
2044 if (m->type == FILE_INDIRECT) in parse()
2045 r = parse_indirect_modifier(ms, m, &l); in parse()
2047 r = parse_string_modifier(ms, m, &l); in parse()
2051 parse_op_modifier(ms, m, &l, op); in parse()
2063 m->reln = *l; in parse()
2068 m->reln); in parse()
2078 m->reln = *l; in parse()
2086 m->reln = *l; in parse()
2090 m->reln = '='; /* the default relation */ in parse()
2093 m->reln = *l; in parse()
2101 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2116 m->flag |= NOSPACE; in parse()
2120 m->flag |= NOSPACE; in parse()
2122 for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); ) in parse()
2124 if (i == sizeof(m->desc)) { in parse()
2125 m->desc[sizeof(m->desc) - 1] = '\0'; in parse()
2127 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2135 if (check_format(ms, m) == -1) in parse()
2138 m->mimetype[0] = '\0'; /* initialise MIME type to none */ in parse()
2152 struct magic *m = &me->mp[0]; in parse_strength() local
2154 if (m->factor_op != FILE_FACTOR_OP_NONE) { in parse_strength()
2157 m->factor_op, m->factor); in parse_strength()
2160 if (m->type == FILE_NAME) { in parse_strength()
2162 "\"name\" magic entries", m->value.s); in parse_strength()
2172 m->factor_op = *l++; in parse_strength()
2188 m->factor = (uint8_t)factor; in parse_strength()
2189 if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) { in parse_strength()
2191 m->factor_op, m->factor); in parse_strength()
2196 m->factor_op = FILE_FACTOR_OP_NONE; in parse_strength()
2197 m->factor = 0; in parse_strength()
2213 struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1]; in parse_extra() local
2214 char *buf = CAST(char *, CAST(void *, m)) + off; in parse_extra()
2223 if (*m->desc == '\0') { in parse_extra()
2261 struct magic *m = &me->mp[0]; in parse_apple() local
2265 sizeof(m->apple), "APPLE", "!+-./?", 0); in parse_apple()
2274 struct magic *m = &me->mp[0]; in parse_ext() local
2278 sizeof(m->ext), "EXTENSION", ",!+-/@?_$", 0); in parse_ext()
2288 struct magic *m = &me->mp[0]; in parse_mime() local
2292 sizeof(m->mimetype), "MIME", "+-/.$?:{}", 1); in parse_mime()
2491 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2496 for (ptr = m->desc; *ptr; ptr++) in check_format()
2506 if (m->type >= file_nformats) { in check_format()
2511 if (file_formats[m->type] == FILE_FMT_NONE) { in check_format()
2513 "`%s'", m->desc, file_names[m->type]); in check_format()
2518 if (check_format_type(ptr, m->type, &estr) == -1) { in check_format()
2525 file_names[m->type], m->desc); in check_format()
2534 file_names[m->type], m->desc); in check_format()
2547 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2552 switch (m->type) { in getvalue()
2562 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2566 m->value.s); in getvalue()
2569 if (m->type == FILE_REGEX) { in getvalue()
2574 convert_libmagic_pattern(&pattern, m->value.s, strlen(m->value.s), options); in getvalue()
2586 if (m->reln == 'x') in getvalue()
2591 switch (m->type) { in getvalue()
2597 m->value.f = strtof(*p, &ep); in getvalue()
2599 m->value.f = (float)strtod(*p, &ep); in getvalue()
2608 m->value.d = strtod(*p, &ep); in getvalue()
2615 m->value.q = file_signextend(ms, m, ull); in getvalue()
2619 size_t ts = typesize(m->type); in getvalue()
2626 type_tbl[m->type].name); in getvalue()
2651 type_tbl[m->type].name, ull); in getvalue()
2669 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2672 char *p = m->value.s; in getstr()
2673 size_t plen = sizeof(m->value.s); in getstr()
2708 && (m->type != FILE_REGEX || in getstr()
2819 m->vallen = CAST(unsigned char, (p - origp)); in getstr()
2820 if (m->type == FILE_PSTRING) in getstr()
2821 m->vallen += (unsigned char)file_pstring_length_size(m); in getstr()
3161 static const size_t m = sizeof(**map->magic); in apprentice_compile() local
3167 struct magic m; in apprentice_compile() member
3195 len = m * map->nmagic[i]; in apprentice_compile()
3336 bs1(struct magic *m) argument
3338 m->cont_level = swap2(m->cont_level);
3339 m->offset = swap4((int32_t)m->offset);
3340 m->in_offset = swap4((uint32_t)m->in_offset);
3341 m->lineno = swap4((uint32_t)m->lineno);
3342 if (IS_LIBMAGIC_STRING(m->type)) {
3343 m->str_range = swap4(m->str_range);
3344 m->str_flags = swap4(m->str_flags);
3347 m->value.q = swap8(m->value.q);
3348 m->num_mask = swap8(m->num_mask);
3353 file_pstring_length_size(const struct magic *m) argument
3355 switch (m->str_flags & PSTRING_LEN) {
3370 file_pstring_get_length(const struct magic *m, const char *ss) argument
3376 switch (m->str_flags & PSTRING_LEN) {
3408 if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
3409 len -= file_pstring_length_size(m);