Lines Matching refs:m
819 apprentice_magic_strength(const struct magic *m) in apprentice_magic_strength() argument
825 switch (m->type) { in apprentice_magic_strength()
827 if (m->factor_op != FILE_FACTOR_OP_NONE) in apprentice_magic_strength()
867 ts = typesize(m->type); in apprentice_magic_strength()
875 val += m->vallen * MULT; in apprentice_magic_strength()
880 val += m->vallen * MULT / 2; in apprentice_magic_strength()
884 if (m->vallen == 0) in apprentice_magic_strength()
886 val += m->vallen * MAX(MULT / m->vallen, 1); in apprentice_magic_strength()
890 v = nonmagic(m->value.s); in apprentice_magic_strength()
904 (void)fprintf(stderr, "Bad type %d\n", m->type); in apprentice_magic_strength()
908 switch (m->reln) { in apprentice_magic_strength()
929 (void)fprintf(stderr, "Bad relation %c\n", m->reln); in apprentice_magic_strength()
933 switch (m->factor_op) { in apprentice_magic_strength()
937 val += m->factor; in apprentice_magic_strength()
940 val -= m->factor; in apprentice_magic_strength()
943 val *= m->factor; in apprentice_magic_strength()
946 val /= m->factor; in apprentice_magic_strength()
959 if (m->desc[0] == '\0') in apprentice_magic_strength()
992 struct magic *m = &ml->magic[magindex]; in apprentice_list() local
993 if ((m->flag & mode) != mode) { in apprentice_list()
1012 apprentice_magic_strength(m), in apprentice_list()
1021 set_test_type(struct magic *mstart, struct magic *m) in set_test_type() argument
1023 switch (m->type) { in set_test_type()
1085 if (file_looks_utf8(m->value.us, CAST(size_t, m->vallen), NULL, in set_test_type()
1445 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1447 if (!(m->flag & UNSIGNED)) { in file_signextend()
1448 switch(m->type) { in file_signextend()
1514 m->type); in file_signextend()
1522 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1527 if ((m->type != FILE_REGEX || (m->str_flags & REGEX_LINE_COUNT) == 0) && in string_modifier_check()
1528 (m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0)) { in string_modifier_check()
1533 switch (m->type) { in string_modifier_check()
1536 if (m->str_flags != 0) { in string_modifier_check()
1544 if ((m->str_flags & REGEX_OFFSET_START) != 0) { in string_modifier_check()
1552 if (m->str_range == 0) { in string_modifier_check()
1556 m->str_range = STRING_DEFAULT_RANGE; in string_modifier_check()
1561 if ((m->str_flags & STRING_COMPACT_WHITESPACE) != 0) { in string_modifier_check()
1566 if ((m->str_flags & STRING_COMPACT_OPTIONAL_WHITESPACE) != 0) { in string_modifier_check()
1574 m->type); in string_modifier_check()
1677 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1684 m->str_flags |= INDIRECT_RELATIVE; in parse_indirect_modifier()
1698 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1706 m->mask_op |= op; in parse_op_modifier()
1709 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1715 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1730 m->str_range = CAST(uint32_t, strtoul(l, &t, 0)); in parse_string_modifier()
1731 if (m->str_range == 0) in parse_string_modifier()
1736 m->str_flags |= STRING_COMPACT_WHITESPACE; in parse_string_modifier()
1739 m->str_flags |= STRING_COMPACT_OPTIONAL_WHITESPACE; in parse_string_modifier()
1742 m->str_flags |= STRING_IGNORE_LOWERCASE; in parse_string_modifier()
1745 m->str_flags |= STRING_IGNORE_UPPERCASE; in parse_string_modifier()
1748 m->str_flags |= REGEX_OFFSET_START; in parse_string_modifier()
1751 m->str_flags |= STRING_BINTEST; in parse_string_modifier()
1754 m->str_flags |= STRING_TEXTTEST; in parse_string_modifier()
1757 m->str_flags |= STRING_TRIM; in parse_string_modifier()
1760 #define SET_LENGTH(a) m->str_flags = (m->str_flags & ~PSTRING_LEN) | (a) in parse_string_modifier()
1761 if (m->type != FILE_PSTRING) in parse_string_modifier()
1766 if (m->type != FILE_PSTRING) in parse_string_modifier()
1771 if (m->type != FILE_PSTRING) in parse_string_modifier()
1776 if (m->type != FILE_PSTRING) in parse_string_modifier()
1781 switch (m->type) { in parse_string_modifier()
1791 if (m->type != FILE_PSTRING) in parse_string_modifier()
1793 m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF; in parse_string_modifier()
1806 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
1826 struct magic *m; in parse() local
1857 m = &me->mp[me->cont_count - 1]; in parse()
1858 diff = CAST(int32_t, cont_level) - CAST(int32_t, m->cont_level); in parse()
1862 m->cont_level); in parse()
1874 m = &me->mp[me->cont_count++]; in parse()
1875 (void)memset(m, 0, sizeof(*m)); in parse()
1876 m->cont_level = cont_level; in parse()
1878 static const size_t len = sizeof(*m) * ALLOC_CHUNK; in parse()
1881 if ((m = CAST(struct magic *, emalloc(len))) == NULL) { in parse()
1885 me->mp = m; in parse()
1887 (void)memset(m, 0, sizeof(*m)); in parse()
1888 m->factor_op = FILE_FACTOR_OP_NONE; in parse()
1889 m->cont_level = 0; in parse()
1892 m->lineno = CAST(uint32_t, lineno); in parse()
1896 m->flag |= OFFADD; in parse()
1900 m->flag |= INDIR; in parse()
1901 if (m->flag & OFFADD) in parse()
1902 m->flag = (m->flag & ~OFFADD) | INDIROFFADD; in parse()
1906 m->flag |= OFFADD; in parse()
1910 if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD))) { in parse()
1919 m->flag |= OFFNEGATIVE; in parse()
1921 m->offset = CAST(int32_t, strtol(l, &t, 0)); in parse()
1930 if (m->flag & INDIR) { in parse()
1931 m->in_type = FILE_LONG; in parse()
1932 m->in_offset = 0; in parse()
1933 m->in_op = 0; in parse()
1939 m->in_op |= FILE_OPSIGNED; in parse()
1943 m->in_type = FILE_LELONG; in parse()
1946 m->in_type = FILE_BELONG; in parse()
1949 m->in_type = FILE_MELONG; in parse()
1953 m->in_type = FILE_LESHORT; in parse()
1957 m->in_type = FILE_BESHORT; in parse()
1963 m->in_type = FILE_BYTE; in parse()
1968 m->in_type = FILE_LEDOUBLE; in parse()
1973 m->in_type = FILE_BEDOUBLE; in parse()
1976 m->in_type = FILE_LEID3; in parse()
1979 m->in_type = FILE_BEID3; in parse()
1982 m->in_type = FILE_LEQUAD; in parse()
1985 m->in_type = FILE_BEQUAD; in parse()
1998 m->in_op |= FILE_OPINVERSE; in parse()
2002 m->in_op |= op; in parse()
2006 m->in_op |= FILE_OPINDIRECT; in parse()
2010 m->in_offset = CAST(int32_t, strtol(l, &t, 0)); in parse()
2020 ((m->in_op & FILE_OPINDIRECT) && *l++ != ')')) { in parse()
2030 m->cond = get_cond(l, &l); in parse()
2031 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
2046 m->type = get_type(type_tbl, l + 1, &l); in parse()
2047 if (m->type == FILE_INVALID) { in parse()
2052 m->type = get_standard_integer_type(l, &l); in parse()
2055 if (m->type != FILE_INVALID) in parse()
2056 m->flag |= UNSIGNED; in parse()
2064 m->type = get_type(type_tbl, l, &l); in parse()
2065 if (m->type == FILE_INVALID) { in parse()
2072 m->type = get_standard_integer_type(l, &l); in parse()
2075 m->type = FILE_STRING; in parse()
2081 if (m->type == FILE_INVALID) { in parse()
2083 m->type = get_type(special_tbl, l, &l); in parse()
2086 if (m->type == FILE_INVALID) { in parse()
2092 if (m->type == FILE_NAME && cont_level != 0) { in parse()
2102 m->mask_op = 0; in parse()
2104 if (!IS_LIBMAGIC_STRING(m->type)) in parse()
2105 m->mask_op |= FILE_OPINVERSE; in parse()
2110 m->str_range = 0; in parse()
2111 m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0; in parse()
2113 if (IS_LIBMAGIC_STRING(m->type)) { in parse()
2124 if (m->type == FILE_INDIRECT) in parse()
2125 r = parse_indirect_modifier(ms, m, &l); in parse()
2127 r = parse_string_modifier(ms, m, &l); in parse()
2131 parse_op_modifier(ms, m, &l, op); in parse()
2143 m->reln = *l; in parse()
2148 m->reln); in parse()
2158 m->reln = *l; in parse()
2166 m->reln = *l; in parse()
2170 m->reln = '='; /* the default relation */ in parse()
2173 m->reln = *l; in parse()
2181 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2196 m->flag |= NOSPACE; in parse()
2200 m->flag |= NOSPACE; in parse()
2202 for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); ) in parse()
2204 if (i == sizeof(m->desc)) { in parse()
2205 m->desc[sizeof(m->desc) - 1] = '\0'; in parse()
2207 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2215 if (check_format(ms, m) == -1) in parse()
2220 file_mdump(m); in parse()
2223 m->mimetype[0] = '\0'; /* initialise MIME type to none */ in parse()
2238 struct magic *m = &me->mp[0]; in parse_strength() local
2240 if (m->factor_op != FILE_FACTOR_OP_NONE) { in parse_strength()
2243 m->factor_op, m->factor); in parse_strength()
2246 if (m->type == FILE_NAME) { in parse_strength()
2248 "\"name\" magic entries", m->value.s); in parse_strength()
2258 m->factor_op = *l++; in parse_strength()
2274 m->factor = CAST(uint8_t, factor); in parse_strength()
2275 if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) { in parse_strength()
2277 m->factor_op, m->factor); in parse_strength()
2282 m->factor_op = FILE_FACTOR_OP_NONE; in parse_strength()
2283 m->factor = 0; in parse_strength()
2299 struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1]; in parse_extra() local
2300 char *buf = CAST(char *, CAST(void *, m)) + off; in parse_extra()
2309 if (*m->desc == '\0') { in parse_extra()
2349 struct magic *m = &me->mp[0]; in parse_apple() local
2353 sizeof(m->apple), "APPLE", "!+-./?", 0); in parse_apple()
2363 struct magic *m = &me->mp[0]; in parse_ext() local
2367 sizeof(m->ext), "EXTENSION", ",!+-/@?_$", 0); in parse_ext()
2378 struct magic *m = &me->mp[0]; in parse_mime() local
2382 sizeof(m->mimetype), "MIME", "+-/.$?:{}", 1); in parse_mime()
2581 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2586 for (ptr = m->desc; *ptr; ptr++) in check_format()
2596 if (m->type >= file_nformats) { in check_format()
2601 if (file_formats[m->type] == FILE_FMT_NONE) { in check_format()
2603 "`%s'", m->desc, file_names[m->type]); in check_format()
2608 if (check_format_type(ptr, m->type, &estr) == -1) { in check_format()
2615 file_names[m->type], m->desc); in check_format()
2624 file_names[m->type], m->desc); in check_format()
2637 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2642 switch (m->type) { in getvalue()
2652 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2656 m->value.s); in getvalue()
2659 if (m->type == FILE_REGEX) { in getvalue()
2664 pattern = convert_libmagic_pattern(m->value.s, strlen(m->value.s), options); in getvalue()
2676 if (m->reln == 'x') in getvalue()
2681 switch (m->type) { in getvalue()
2687 m->value.f = strtof(*p, &ep); in getvalue()
2689 m->value.f = (float)strtod(*p, &ep); in getvalue()
2698 m->value.d = strtod(*p, &ep); in getvalue()
2703 if (file_parse_guid(*p, m->value.guid) == -1) in getvalue()
2710 m->value.q = file_signextend(ms, m, ull); in getvalue()
2714 size_t ts = typesize(m->type); in getvalue()
2721 type_tbl[m->type].name); in getvalue()
2746 type_tbl[m->type].name, ull); in getvalue()
2764 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2767 char *p = m->value.s; in getstr()
2768 size_t plen = sizeof(m->value.s); in getstr()
2803 && (m->type != FILE_REGEX || in getstr()
2914 m->vallen = CAST(unsigned char, (p - origp)); in getstr()
2915 if (m->type == FILE_PSTRING) { in getstr()
2916 size_t l = file_pstring_length_size(ms, m); in getstr()
2919 m->vallen += CAST(unsigned char, l); in getstr()
3181 static const size_t m = sizeof(**map->magic); in apprentice_compile() local
3187 struct magic m; in apprentice_compile() member
3215 len = m * map->nmagic[i]; in apprentice_compile()
3356 bs1(struct magic *m) argument
3358 m->cont_level = swap2(m->cont_level);
3359 m->offset = swap4(CAST(uint32_t, m->offset));
3360 m->in_offset = swap4(CAST(uint32_t, m->in_offset));
3361 m->lineno = swap4(CAST(uint32_t, m->lineno));
3362 if (IS_LIBMAGIC_STRING(m->type)) {
3363 m->str_range = swap4(m->str_range);
3364 m->str_flags = swap4(m->str_flags);
3367 m->value.q = swap8(m->value.q);
3368 m->num_mask = swap8(m->num_mask);
3373 file_pstring_length_size(struct magic_set *ms, const struct magic *m) argument
3375 switch (m->str_flags & PSTRING_LEN) {
3387 m->str_flags & PSTRING_LEN);
3392 file_pstring_get_length(struct magic_set *ms, const struct magic *m, argument
3399 switch (m->str_flags & PSTRING_LEN) {
3430 m->str_flags & PSTRING_LEN);
3434 if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF) {
3435 size_t l = file_pstring_length_size(ms, m);