Lines Matching refs:m

879 apprentice_magic_strength_1(const struct magic *m)  in apprentice_magic_strength_1()  argument
885 switch (m->type) { in apprentice_magic_strength_1()
887 if (m->factor_op != FILE_FACTOR_OP_NONE) { in apprentice_magic_strength_1()
889 m->factor_op); in apprentice_magic_strength_1()
939 ts = typesize(m->type); in apprentice_magic_strength_1()
942 m->type); in apprentice_magic_strength_1()
951 val += m->vallen * MULT; in apprentice_magic_strength_1()
956 val += m->vallen * MULT / 2; in apprentice_magic_strength_1()
960 if (m->vallen == 0) in apprentice_magic_strength_1()
962 val += m->vallen * MAX(MULT / m->vallen, 1); in apprentice_magic_strength_1()
966 v = nonmagic(m->value.s); in apprentice_magic_strength_1()
981 (void)fprintf(stderr, "Bad type %d\n", m->type); in apprentice_magic_strength_1()
985 switch (m->reln) { in apprentice_magic_strength_1()
1006 (void)fprintf(stderr, "Bad relation %c\n", m->reln); in apprentice_magic_strength_1()
1016 file_magic_strength(const struct magic *m, in file_magic_strength() argument
1019 ssize_t val = apprentice_magic_strength_1(m); in file_magic_strength()
1022 if (m->desc[0] == '\0') { in file_magic_strength()
1028 for (i = 1; m[i].cont_level != 0 && i < MIN(nmagic, 3); i++) { in file_magic_strength()
1029 ssize_t v = apprentice_magic_strength_1(&m[i]) >> in file_magic_strength()
1032 if (m[i].desc[0] != '\0') in file_magic_strength()
1038 switch (m->factor_op) { in file_magic_strength()
1042 val += m->factor; in file_magic_strength()
1045 val -= m->factor; in file_magic_strength()
1048 val *= m->factor; in file_magic_strength()
1051 val /= m->factor; in file_magic_strength()
1054 (void)fprintf(stderr, "Bad factor_op %u\n", m->factor_op); in file_magic_strength()
1066 if (m->desc[0] == '\0') in file_magic_strength()
1101 struct magic *m = &ml->magic[magindex]; in apprentice_list() local
1102 if ((m->flag & mode) != mode) { in apprentice_list()
1128 file_magic_strength(m, ml->nmagic - magindex), in apprentice_list()
1137 set_test_type(struct magic *mstart, struct magic *m) in set_test_type() argument
1139 switch (m->type) { in set_test_type()
1210 if (file_looks_utf8(m->value.us, CAST(size_t, m->vallen), NULL, in set_test_type()
1578 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1580 if (!(m->flag & UNSIGNED)) { in file_signextend()
1581 switch(m->type) { in file_signextend()
1656 m->type); in file_signextend()
1664 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1669 if ((m->type != FILE_REGEX || (m->str_flags & REGEX_LINE_COUNT) == 0) && in string_modifier_check()
1670 (m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0)) { in string_modifier_check()
1675 switch (m->type) { in string_modifier_check()
1678 if (m->str_flags != 0) { in string_modifier_check()
1686 if ((m->str_flags & REGEX_OFFSET_START) != 0) { in string_modifier_check()
1694 if (m->str_range == 0) { in string_modifier_check()
1698 m->str_range = STRING_DEFAULT_RANGE; in string_modifier_check()
1703 if ((m->str_flags & STRING_COMPACT_WHITESPACE) != 0) { in string_modifier_check()
1708 if ((m->str_flags & STRING_COMPACT_OPTIONAL_WHITESPACE) != 0) { in string_modifier_check()
1716 m->type); in string_modifier_check()
1819 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1826 m->str_flags |= INDIRECT_RELATIVE; in parse_indirect_modifier()
1840 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1848 m->mask_op |= op; in parse_op_modifier()
1851 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1857 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1872 m->str_range = CAST(uint32_t, strtoul(l, &t, 0)); in parse_string_modifier()
1873 if (m->str_range == 0) in parse_string_modifier()
1878 m->str_flags |= STRING_COMPACT_WHITESPACE; in parse_string_modifier()
1881 m->str_flags |= STRING_COMPACT_OPTIONAL_WHITESPACE; in parse_string_modifier()
1884 m->str_flags |= STRING_IGNORE_LOWERCASE; in parse_string_modifier()
1887 m->str_flags |= STRING_IGNORE_UPPERCASE; in parse_string_modifier()
1890 m->str_flags |= REGEX_OFFSET_START; in parse_string_modifier()
1893 m->str_flags |= STRING_BINTEST; in parse_string_modifier()
1896 m->str_flags |= STRING_TEXTTEST; in parse_string_modifier()
1899 m->str_flags |= STRING_TRIM; in parse_string_modifier()
1902 m->str_flags |= STRING_FULL_WORD; in parse_string_modifier()
1905 #define SET_LENGTH(a) m->str_flags = (m->str_flags & ~PSTRING_LEN) | (a) in parse_string_modifier()
1906 if (m->type != FILE_PSTRING) in parse_string_modifier()
1911 if (m->type != FILE_PSTRING) in parse_string_modifier()
1916 if (m->type != FILE_PSTRING) in parse_string_modifier()
1921 if (m->type != FILE_PSTRING) in parse_string_modifier()
1926 switch (m->type) { in parse_string_modifier()
1936 if (m->type != FILE_PSTRING) in parse_string_modifier()
1938 m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF; in parse_string_modifier()
1951 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
1971 struct magic *m; in parse() local
2002 m = &me->mp[me->cont_count - 1]; in parse()
2003 diff = CAST(int32_t, cont_level) - CAST(int32_t, m->cont_level); in parse()
2007 m->cont_level); in parse()
2019 m = &me->mp[me->cont_count++]; in parse()
2020 (void)memset(m, 0, sizeof(*m)); in parse()
2021 m->cont_level = cont_level; in parse()
2023 static const size_t len = sizeof(*m) * ALLOC_CHUNK; in parse()
2026 if ((m = CAST(struct magic *, emalloc(len))) == NULL) { in parse()
2030 me->mp = m; in parse()
2032 (void)memset(m, 0, sizeof(*m)); in parse()
2033 m->factor_op = FILE_FACTOR_OP_NONE; in parse()
2034 m->cont_level = 0; in parse()
2037 m->lineno = CAST(uint32_t, lineno); in parse()
2041 m->flag |= OFFADD; in parse()
2045 m->flag |= INDIR; in parse()
2046 if (m->flag & OFFADD) in parse()
2047 m->flag = (m->flag & ~OFFADD) | INDIROFFADD; in parse()
2051 m->flag |= OFFADD; in parse()
2055 if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD))) { in parse()
2064 m->flag |= OFFNEGATIVE; in parse()
2066 m->offset = CAST(int32_t, strtol(l, &t, 0)); in parse()
2075 if (m->flag & INDIR) { in parse()
2076 m->in_type = FILE_LONG; in parse()
2077 m->in_offset = 0; in parse()
2078 m->in_op = 0; in parse()
2084 m->in_op |= FILE_OPSIGNED; in parse()
2088 m->in_type = FILE_LELONG; in parse()
2091 m->in_type = FILE_BELONG; in parse()
2094 m->in_type = FILE_MELONG; in parse()
2098 m->in_type = FILE_LESHORT; in parse()
2102 m->in_type = FILE_BESHORT; in parse()
2108 m->in_type = FILE_BYTE; in parse()
2113 m->in_type = FILE_LEDOUBLE; in parse()
2118 m->in_type = FILE_BEDOUBLE; in parse()
2121 m->in_type = FILE_LEID3; in parse()
2124 m->in_type = FILE_BEID3; in parse()
2127 m->in_type = FILE_OCTAL; in parse()
2130 m->in_type = FILE_LEQUAD; in parse()
2133 m->in_type = FILE_BEQUAD; in parse()
2146 m->in_op |= FILE_OPINVERSE; in parse()
2150 m->in_op |= op; in parse()
2154 m->in_op |= FILE_OPINDIRECT; in parse()
2158 m->in_offset = CAST(int32_t, strtol(l, &t, 0)); in parse()
2168 ((m->in_op & FILE_OPINDIRECT) && *l++ != ')')) { in parse()
2178 m->cond = get_cond(l, &l); in parse()
2179 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
2194 m->type = get_type(type_tbl, l + 1, &l); in parse()
2195 if (m->type == FILE_INVALID) { in parse()
2200 m->type = get_standard_integer_type(l, &l); in parse()
2203 if (m->type != FILE_INVALID) in parse()
2204 m->flag |= UNSIGNED; in parse()
2212 m->type = get_type(type_tbl, l, &l); in parse()
2213 if (m->type == FILE_INVALID) { in parse()
2220 m->type = get_standard_integer_type(l, &l); in parse()
2223 m->type = FILE_STRING; in parse()
2229 if (m->type == FILE_INVALID) { in parse()
2231 m->type = get_type(special_tbl, l, &l); in parse()
2234 if (m->type == FILE_INVALID) { in parse()
2240 if (m->type == FILE_NAME && cont_level != 0) { in parse()
2250 m->mask_op = 0; in parse()
2252 if (!IS_LIBMAGIC_STRING(m->type)) in parse()
2253 m->mask_op |= FILE_OPINVERSE; in parse()
2258 m->str_range = 0; in parse()
2259 m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0; in parse()
2261 if (IS_LIBMAGIC_STRING(m->type)) { in parse()
2272 if (m->type == FILE_INDIRECT) in parse()
2273 r = parse_indirect_modifier(ms, m, &l); in parse()
2275 r = parse_string_modifier(ms, m, &l); in parse()
2279 parse_op_modifier(ms, m, &l, op); in parse()
2291 m->reln = *l; in parse()
2296 m->reln); in parse()
2306 m->reln = *l; in parse()
2314 m->reln = *l; in parse()
2318 m->reln = '='; /* the default relation */ in parse()
2321 m->reln = *l; in parse()
2329 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2344 m->flag |= NOSPACE; in parse()
2348 m->flag |= NOSPACE; in parse()
2350 for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); ) in parse()
2352 if (i == sizeof(m->desc)) { in parse()
2353 m->desc[sizeof(m->desc) - 1] = '\0'; in parse()
2355 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2363 if (check_format(ms, m) == -1) in parse()
2368 file_mdump(m); in parse()
2371 m->mimetype[0] = '\0'; /* initialise MIME type to none */ in parse()
2388 struct magic *m = &me->mp[0]; in parse_strength() local
2390 if (m->factor_op != FILE_FACTOR_OP_NONE) { in parse_strength()
2393 m->factor_op, m->factor); in parse_strength()
2396 if (m->type == FILE_NAME) { in parse_strength()
2399 file_printable(ms, sbuf, sizeof(sbuf), m->value.s, in parse_strength()
2400 sizeof(m->value.s))); in parse_strength()
2411 m->factor_op = *l++; in parse_strength()
2427 m->factor = CAST(uint8_t, factor); in parse_strength()
2428 if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) { in parse_strength()
2430 m->factor_op, m->factor); in parse_strength()
2435 m->factor_op = FILE_FACTOR_OP_NONE; in parse_strength()
2436 m->factor = 0; in parse_strength()
2453 struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1]; in parse_extra() local
2454 char *buf = CAST(char *, CAST(void *, m)) + off; in parse_extra()
2463 if (*m->desc == '\0') { in parse_extra()
2730 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2735 for (ptr = m->desc; *ptr; ptr++) in check_format()
2745 if (m->type >= file_nformats) { in check_format()
2750 if (file_formats[m->type] == FILE_FMT_NONE) { in check_format()
2752 "`%s'", m->desc, file_names[m->type]); in check_format()
2757 if (check_format_type(ptr, m->type, &estr) == -1) { in check_format()
2764 file_names[m->type], m->desc); in check_format()
2773 file_names[m->type], m->desc); in check_format()
2786 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2792 switch (m->type) { in getvalue()
2803 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2807 m->value.s); in getvalue()
2810 if (m->type == FILE_REGEX) { in getvalue()
2815 pattern = convert_libmagic_pattern(m->value.s, strlen(m->value.s), options); in getvalue()
2827 if (m->reln == 'x') in getvalue()
2832 switch (m->type) { in getvalue()
2838 m->value.f = strtof(*p, &ep); in getvalue()
2840 m->value.f = (float)strtod(*p, &ep); in getvalue()
2849 m->value.d = strtod(*p, &ep); in getvalue()
2854 if (file_parse_guid(*p, m->value.guid) == -1) in getvalue()
2861 m->value.q = file_signextend(ms, m, ull); in getvalue()
2866 size_t ts = typesize(m->type); in getvalue()
2873 type_tbl[m->type].name); in getvalue()
2904 type_tbl[m->type].name, ull); in getvalue()
2923 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2926 char *p = m->value.s; in getstr()
2927 size_t plen = sizeof(m->value.s); in getstr()
2959 if (m->type == FILE_REGEX && in getstr()
2979 && (m->type != FILE_REGEX || in getstr()
3088 m->vallen = CAST(unsigned char, (p - origp)); in getstr()
3089 if (m->type == FILE_PSTRING) { in getstr()
3090 size_t l = file_pstring_length_size(ms, m); in getstr()
3093 m->vallen += CAST(unsigned char, l); in getstr()
3355 static const size_t m = sizeof(**map->magic); in apprentice_compile() local
3362 struct magic m; in apprentice_compile() member
3389 len = m * map->nmagic[i]; in apprentice_compile()
3562 bs1(struct magic *m) argument
3564 m->cont_level = swap2(m->cont_level);
3565 m->offset = swap4(CAST(uint32_t, m->offset));
3566 m->in_offset = swap4(CAST(uint32_t, m->in_offset));
3567 m->lineno = swap4(CAST(uint32_t, m->lineno));
3568 if (IS_LIBMAGIC_STRING(m->type)) {
3569 m->str_range = swap4(m->str_range);
3570 m->str_flags = swap4(m->str_flags);
3573 m->value.q = swap8(m->value.q);
3574 m->num_mask = swap8(m->num_mask);
3579 file_pstring_length_size(struct magic_set *ms, const struct magic *m) argument
3581 switch (m->str_flags & PSTRING_LEN) {
3593 m->str_flags & PSTRING_LEN);
3598 file_pstring_get_length(struct magic_set *ms, const struct magic *m, argument
3605 switch (m->str_flags & PSTRING_LEN) {
3636 m->str_flags & PSTRING_LEN);
3640 if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF) {
3641 size_t l = file_pstring_length_size(ms, m);