Rizin
unix-like reverse engineering framework and cli tools
|
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include "rz_regex.h"
#include "rz_util/rz_str.h"
#include "rz_util/rz_assert.h"
#include "utils.h"
#include "regex2.h"
#include "cclass.h"
#include "cname.h"
Go to the source code of this file.
Classes | |
struct | parse |
Macros | |
#define | NPAREN 10 /* we need to remember () 1-9 for back refs */ |
#define | PEEK() (*p->next) |
#define | PEEK2() (*(p->next + 1)) |
#define | MORE() (p->next < p->end) |
#define | MORE2() (p->next + 1 < p->end) |
#define | SEE(c) (MORE() && PEEK() == (c)) |
#define | SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) |
#define | EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) |
#define | EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) |
#define | NEXT() (p->next++) |
#define | NEXT2() (p->next += 2) |
#define | NEXTn(n) (p->next += (n)) |
#define | GETNEXT() (*p->next++) |
#define | SETERROR(e) seterr(p, (e)) |
#define | REQUIRE(co, e) (void)((co) || SETERROR(e)) |
#define | MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) |
#define | MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) |
#define | MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) |
#define | EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd)) |
#define | INSERT(op, pos) doinsert(p, (sop)(op), HERE() - (pos) + 1, pos) |
#define | AHEAD(pos) dofwd(p, pos, HERE() - (pos)) |
#define | ASTERN(sop, pos) EMIT(sop, HERE() - (pos)) |
#define | HERE() (p->slen) |
#define | THERE() (p->slen - 1) |
#define | THERETHERE() (p->slen - 2) |
#define | DROP(n) (p->slen -= (n)) |
#define | GOODFLAGS(f) ((f) & ~RZ_REGEX_DUMP) |
#define | BACKSL (1 << CHAR_BIT) |
#define | N 2 |
#define | INF 3 |
#define | REP(f, t) ((f)*8 + (t)) |
#define | MAP(n) |
Functions | |
static void | p_ere (struct parse *, int) |
static void | p_ere_exp (struct parse *) |
static void | p_str (struct parse *) |
static void | p_bre (struct parse *, int, int) |
static int | p_simp_re (struct parse *, int) |
static int | p_count (struct parse *) |
static void | p_bracket (struct parse *) |
static void | p_b_term (struct parse *, cset *) |
static void | p_b_cclass (struct parse *, cset *) |
static void | p_b_eclass (struct parse *, cset *) |
static char | p_b_symbol (struct parse *) |
static char | p_b_coll_elem (struct parse *, int) |
static char | othercase (int) |
static void | bothcases (struct parse *, int) |
static void | ordinary (struct parse *, int) |
static void | special (struct parse *, int) |
static void | nonnewline (struct parse *) |
static void | repeat (struct parse *, sopno, int, int) |
static int | seterr (struct parse *, int) |
static cset * | allocset (struct parse *) |
static void | freeset (struct parse *, cset *) |
static int | freezeset (struct parse *, cset *) |
static int | firstch (struct parse *, cset *) |
static int | nch (struct parse *, cset *) |
static void | mcadd (struct parse *, cset *, char *) |
static void | mcinvert (struct parse *, cset *) |
static void | mccase (struct parse *, cset *) |
static int | isinsets (struct re_guts *, int) |
static int | samesets (struct re_guts *, int, int) |
static void | categorize (struct parse *, struct re_guts *) |
static sopno | dupl (struct parse *, sopno, sopno) |
static void | doemit (struct parse *, sop, size_t) |
static void | doinsert (struct parse *, sop, size_t, sopno) |
static void | dofwd (struct parse *, sopno, sop) |
static void | enlarge (struct parse *, sopno) |
static void | stripsnug (struct parse *, struct re_guts *) |
static void | findmust (struct parse *, struct re_guts *) |
static sopno | pluscount (struct parse *, struct re_guts *) |
RZ_API int | rz_regex_match (const char *pattern, const char *flags, const char *text) |
RZ_API RzList * | rz_regex_get_match_list (const char *pattern, const char *flags, const char *text) |
RZ_API RzRegex * | rz_regex_new (const char *pattern, const char *flags) |
RZ_API int | rz_regex_flags (const char *f) |
RZ_API void | rz_regex_fini (RzRegex *preg) |
RZ_API void | rz_regex_free (RzRegex *preg) |
RZ_API int | rz_regex_comp (RzRegex *preg, const char *pattern, int cflags) |
Variables | |
static char | nuls [10] |
#define BACKSL (1 << CHAR_BIT) |
#define GOODFLAGS | ( | f | ) | ((f) & ~RZ_REGEX_DUMP) |
#define INF 3 |
#define MAP | ( | n | ) |
#define N 2 |
#define NPAREN 10 /* we need to remember () 1-9 for back refs */ |
Definition at line 1242 of file regcomp.c.
References CHAR_BIT, test_evm::cs, cset(), i, if(), memset(), nbytes, NULL, p, realloc(), RZ_FREE, RZ_REGEX_ESPACE, and SETERROR.
Referenced by p_bracket().
Definition at line 1038 of file regcomp.c.
References othercase(), p, p_bracket(), and ut8.
Referenced by ordinary().
Definition at line 1475 of file regcomp.c.
References c, c2, cat(), g, isinsets(), NULL, p, and samesets().
Referenced by rz_regex_comp().
Definition at line 1503 of file regcomp.c.
References enlarge(), finish(), HERE, len, memcpy(), p, and start.
Referenced by p_simp_re(), and repeat().
Definition at line 1360 of file regcomp.c.
References CHIN, test_evm::cs, i, and p.
Referenced by p_bracket().
Definition at line 1303 of file regcomp.c.
References CHsub, test_evm::cs, i, and p.
Referenced by freezeset(), and p_bracket().
Definition at line 1326 of file regcomp.c.
References CHIN, test_evm::cs, freeset(), h, cset::hash, i, and p.
Referenced by p_bracket().
Definition at line 1391 of file regcomp.c.
References test_evm::cs, free(), NULL, realloc(), RZ_REGEX_ESPACE, SETERROR, and STRLCPY.
Definition at line 1429 of file regcomp.c.
Referenced by p_bracket().
Definition at line 1417 of file regcomp.c.
Referenced by p_bracket().
Definition at line 1375 of file regcomp.c.
References CHIN, test_evm::cs, i, n, and p.
Referenced by file_fsmagic(), and p_bracket().
|
static |
Definition at line 1133 of file regcomp.c.
References p, and p_bracket().
Referenced by p_ere_exp(), and p_simp_re().
Definition at line 1062 of file regcomp.c.
References bothcases(), EMIT, isalpha, OCHAR, othercase(), p, and RZ_REGEX_ICASE.
Referenced by p_bracket(), p_ere_exp(), p_simp_re(), p_str(), and special().
|
static |
Definition at line 1019 of file regcomp.c.
References isalpha, islower, isupper, tolower, toupper, and ut8.
Referenced by bothcases(), ordinary(), and p_bracket().
Definition at line 923 of file regcomp.c.
References c, cclasses, CHadd, cclass::chars, test_evm::cs, isalpha, len, MCadd, MORE, cclass::multis, cclass::name, NEXT, NULL, p, PEEK, RZ_REGEX_ECTYPE, SETERROR, and sp.
Referenced by p_b_term().
Definition at line 988 of file regcomp.c.
References cnames, cname::code, len, MORE, cname::name, NEXT, NULL, p, RZ_REGEX_EBRACK, RZ_REGEX_ECOLLATE, SEETWO, SETERROR, and sp.
Referenced by p_b_eclass(), and p_b_symbol().
Definition at line 959 of file regcomp.c.
References c, CHadd, test_evm::cs, p, and p_b_coll_elem().
Referenced by p_b_term().
|
static |
Definition at line 970 of file regcomp.c.
References EATTWO, GETNEXT, MORE, p, p_b_coll_elem(), REQUIRE, RZ_REGEX_EBRACK, RZ_REGEX_ECOLLATE, and value.
Referenced by p_b_term().
Definition at line 859 of file regcomp.c.
References c, CHadd, test_evm::cs, EAT, EATTWO, finish(), i, MORE, MORE2, NEXT, NEXT2, p, p_b_cclass(), p_b_eclass(), p_b_symbol(), PEEK, PEEK2, REQUIRE, RZ_REGEX_EBRACK, RZ_REGEX_ECOLLATE, RZ_REGEX_ECTYPE, RZ_REGEX_ERANGE, SEE, SETERROR, and start.
Referenced by p_bracket().
|
static |
Definition at line 768 of file regcomp.c.
References allocset(), CHadd, CHIN, CHsub, test_evm::cs, EAT, EMIT, firstch(), freeset(), freezeset(), i, invert(), isalpha, mccase(), mcinvert(), MORE, MUSTEAT, nch(), NEXTn, NULL, OANYOF, OBOW, OEOW, ordinary(), othercase(), p, p_b_term(), PEEK, RZ_REGEX_EBRACK, RZ_REGEX_ICASE, RZ_REGEX_NEWLINE, and SEETWO.
Referenced by bothcases(), nonnewline(), p_ere_exp(), p_simp_re(), and special().
Definition at line 590 of file regcomp.c.
References DROP, EAT, EMIT, HERE, MORE, OBOL, OEOL, p, p_simp_re(), REQUIRE, RZ_REGEX_EMPTY, SEETWO, start, USEBOL, and USEEOL.
Referenced by p_simp_re(), and rz_regex_comp().
Definition at line 749 of file regcomp.c.
References count, DUPMAX, GETNEXT, isdigit, MORE, PEEK, REQUIRE, and RZ_REGEX_BADBR.
Referenced by p_ere_exp(), and p_simp_re().
|
static |
Definition at line 422 of file regcomp.c.
References AHEAD, ASTERN, c, count, EAT, EMIT, GETNEXT, HERE, INSERT, INTFINITY, isalpha, isdigit, MORE, MORE2, MUSTEAT, NEXT, nonnewline(), NPAREN, O_CH, O_PLUS, O_QUEST, OANY, OBOL, OCH_, OEOL, OLPAREN, OOR1, OOR2, OPLUS_, OQUEST_, ordinary(), ORPAREN, p, p_bracket(), p_count(), p_ere(), PEEK, PEEK2, pos, repeat(), REQUIRE, RZ_REGEX_BADBR, RZ_REGEX_BADRPT, RZ_REGEX_EBRACE, RZ_REGEX_EESCAPE, RZ_REGEX_EMPTY, RZ_REGEX_EPAREN, RZ_REGEX_NEWLINE, SEE, SETERROR, special(), THERE, THERETHERE, USEBOL, and USEEOL.
Referenced by p_ere().
Definition at line 621 of file regcomp.c.
References ASTERN, BACKSL, c, count, dupl(), EAT, EATTWO, EMIT, g, GETNEXT, HERE, i, INSERT, INTFINITY, isdigit, MORE, NEXT, nonnewline(), NPAREN, O_BACK, O_PLUS, O_QUEST, OANY, OBACK_, OLPAREN, OP, OPLUS_, OQUEST_, ordinary(), ORPAREN, p, p_bracket(), p_bre(), p_count(), PEEK, pos, repeat(), REQUIRE, RZ_REGEX_BADBR, RZ_REGEX_BADRPT, RZ_REGEX_EBRACE, RZ_REGEX_EESCAPE, RZ_REGEX_EPAREN, RZ_REGEX_ESUBREG, RZ_REGEX_NEWLINE, SEETWO, and SETERROR.
Referenced by p_bre().
|
static |
Definition at line 573 of file regcomp.c.
References GETNEXT, MORE, ordinary(), p, REQUIRE, and RZ_REGEX_EMPTY.
Referenced by rz_regex_comp().
Definition at line 1155 of file regcomp.c.
References AHEAD, ASTERN, DROP, dupl(), EMIT, finish(), from, HERE, INF, INSERT, MAP, N, O_CH, O_PLUS, OCH_, OOR1, OOR2, OPLUS_, p, REP, RZ_REGEX_ASSERT, SETERROR, start, THERE, THERETHERE, and to.
Referenced by __panels_process(), cmd_print_pv(), LZ4HC_InsertAndGetWiderMatch(), p_ere_exp(), p_simp_re(), run_basic_block_analysis(), rz_analysis_esil_parse(), rz_asm_pseudo_fill(), rz_bin_le_get_relocs(), rz_bp_get_bytes(), rz_core_analysis_callgraph(), rz_core_analysis_esil(), rz_core_esil_step(), rz_core_visual_define(), rz_core_visual_xrefs(), rz_debug_continue_kill(), rz_file_readlink(), rz_il_op_effect_free(), rz_il_op_new_repeat(), rz_meta_data_handler(), rz_meta_data_remove_handler(), sdb_querys(), uv__poll(), uv__poll_wine(), uv_timer_set_repeat(), uv_timer_start(), and visual_help().
Definition at line 258 of file regcomp.c.
References BAD, calloc(), categorize(), EMIT, findmust(), free(), g, GOODFLAGS, i, len, MAGIC1, MAGIC2, maxlen, memset(), NC, NPAREN, NULL, OEND, OUT, p, p_bre(), p_ere(), p_str(), pluscount(), rz_regex_t::re_endp, rz_regex_t::re_flags, rz_regex_t::re_g, rz_regex_t::re_magic, rz_regex_t::re_nsub, RZ_REGEX_ASSERT, RZ_REGEX_ESPACE, RZ_REGEX_EXTENDED, rz_regex_fini(), RZ_REGEX_INVARG, RZ_REGEX_NOSPEC, RZ_REGEX_PEND, SETERROR, stripsnug(), and THERE.
Referenced by _main(), check_fmt(), magiccheck(), rz_regex_get_match_list(), rz_regex_match(), rz_regex_new(), and rz_search_regexp_update().
Definition at line 226 of file regcomp.c.
References free(), g, MAGIC1, MAGIC2, rz_regex_t::re_g, and rz_regex_t::re_magic.
Referenced by check_fmt(), magiccheck(), rz_regex_comp(), rz_regex_free(), rz_regex_get_match_list(), rz_regex_match(), and rz_search_regexp_update().
Definition at line 197 of file regcomp.c.
References f, flags, RZ_REGEX_DUMP, RZ_REGEX_EXTENDED, RZ_REGEX_ICASE, RZ_REGEX_NEWLINE, RZ_REGEX_NOSPEC, RZ_REGEX_NOSUB, and RZ_REGEX_PEND.
Referenced by rz_regex_get_match_list(), rz_regex_match(), and rz_regex_new().
Definition at line 249 of file regcomp.c.
References free(), and rz_regex_fini().
Referenced by _main(), find_e_opts(), main(), rz_asm_token_pattern_free(), rz_cons_less_str(), rz_core_asm_strsearch(), rz_str_split_duplist_n_regex(), rz_str_split_list_regex(), and test_or().
RZ_API RzList* rz_regex_get_match_list | ( | const char * | pattern, |
const char * | flags, | ||
const char * | text | ||
) |
Definition at line 155 of file regcomp.c.
References eprintf, flags, free(), list(), match, NULL, rz_list_append(), rz_list_newf(), RZ_NEWS0, rz_regex_comp(), rz_regex_exec(), rz_regex_fini(), rz_regex_flags(), RZ_REGEX_STARTEND, rz_str_ncpy(), and create_tags_rz::text.
Referenced by print_diff(), and rz_test_cmp_cmd_output().
Definition at line 142 of file regcomp.c.
References eprintf, flags, rz_regex_comp(), rz_regex_exec(), rz_regex_fini(), rz_regex_flags(), and create_tags_rz::text.
Referenced by classdump_objc(), construct_rop_gadget(), is_lea(), step_until_inst(), and test_or().
Definition at line 183 of file regcomp.c.
References flags, memcpy(), NULL, r, RZ_NEW, rz_regex_comp(), rz_regex_flags(), and rz_return_val_if_fail.
Referenced by find_e_opts(), main(), rz_cons_less_str(), rz_core_asm_strsearch(), rz_str_split_duplist_n_regex(), rz_str_split_list_regex(), and test_or().
Definition at line 1456 of file regcomp.c.
References c1, c2, CHAR_BIT, g, i, and ut8.
Referenced by categorize().
Definition at line 1076 of file regcomp.c.
References c, GETNEXT, memcpy(), NULL, num, ordinary(), p, p_bracket(), RZ_REGEX_INVARG, and SETERROR.
Referenced by fmove_fpcr(), p_ere_exp(), and parse_abbrev_raw().
Definition at line 1630 of file regcomp.c.
References g, p, realloc(), RZ_REGEX_ESPACE, and SETERROR.
Referenced by rz_regex_comp().