Rizin
unix-like reverse engineering framework and cli tools
pager_private.h File Reference

Go to the source code of this file.

Functions

RZ_IPI void pager_color_line (const char *line, RzStrpool *p, RzList *ml)
 
RZ_IPI void pager_printpage (const char *line, int *index, RzList **mla, int from, int to, int w)
 
RZ_IPI int pager_next_match (int from, RzList **mla, int lcount)
 
RZ_IPI int pager_prev_match (int from, RzList **mla)
 
RZ_IPI bool pager_all_matches (const char *s, RzRegex *rx, RzList **mla, int *lines, int lcount)
 
RZ_IPI intpager_splitlines (char *s, int *lines_count)
 

Function Documentation

◆ pager_all_matches()

RZ_IPI bool pager_all_matches ( const char *  s,
RzRegex rx,
RzList **  mla,
int lines,
int  lcount 
)

Definition at line 101 of file pager.c.

101  {
102  bool res = false;
103  RzRegexMatch m = { 0 };
104  int l, slen;
105  for (l = 0; l < lcount; l++) {
106  m.rm_so = 0;
107  const char *loff = s + lines[l]; /* current line offset */
108  char *clean = strdup(loff);
109  if (!clean) {
110  return false;
111  }
112  int *cpos = NULL;
113  int ncpos = rz_str_ansi_filter(clean, NULL, &cpos, -1);
114  m.rm_eo = slen = strlen(clean);
115  rz_list_purge(mla[l]);
116  while (!rz_regex_exec(rx, clean, 1, &m, RZ_REGEX_STARTEND)) {
117  if (!cpos || m.rm_so >= ncpos) {
118  break;
119  }
121  if (ms && cpos) {
122  ms->rm_so = cpos[m.rm_so];
123  ms->rm_eo = cpos[m.rm_eo];
124  rz_list_append(mla[l], ms);
125  }
126  m.rm_so = m.rm_eo;
127  m.rm_eo = slen;
128  res = true;
129  }
130  free(cpos);
131  free(clean);
132  }
133  return res;
134 }
static RzILOpEffect * mla(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:1217
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static RzSocket * s
Definition: rtr.c:28
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch __pmatch[], int eflags)
Definition: regexec.c:149
#define RZ_REGEX_STARTEND
Definition: rz_regex.h:56
RZ_API int rz_str_ansi_filter(char *str, char **out, int **cposs, int len)
Definition: str.c:2124
#define RZ_NEW0(x)
Definition: rz_types.h:284
st64 rm_so
Definition: rz_regex.h:17
st64 rm_eo
Definition: rz_regex.h:18

References free(), lines(), regress::m, mla(), NULL, rz_regmatch_t::rm_eo, rz_regmatch_t::rm_so, rz_list_append(), rz_list_purge(), RZ_NEW0, rz_regex_exec(), RZ_REGEX_STARTEND, rz_str_ansi_filter(), s, and strdup().

Referenced by rz_cons_less_str().

◆ pager_color_line()

RZ_IPI void pager_color_line ( const char *  line,
RzStrpool p,
RzList ml 
)

Definition at line 9 of file pager.c.

9  {
10  int m_len, offset = 0;
11  char *m_addr;
12  RzListIter *it;
13  RzRegexMatch *m;
14  char *inv[2] = {
15  RZ_CONS_INVERT(true, true),
16  RZ_CONS_INVERT(false, true)
17  };
18  int linv[2] = {
19  strlen(inv[0]),
20  strlen(inv[1])
21  };
23  rz_list_foreach (ml, it, m) {
24  /* highlight a match */
25  rz_strpool_memcat(p, line + offset, m->rm_so - offset);
26  rz_strpool_memcat(p, inv[0], linv[0]);
27  m_len = m->rm_eo - m->rm_so;
28  if (m_len < 0) {
29  m_len = 0;
30  }
31  m_addr = rz_str_ndup(line + m->rm_so, m_len);
32  if (m_addr) {
33  /* in case there's a CSI in the middle of this match*/
34  m_len = rz_str_ansi_filter(m_addr, NULL, NULL, m_len);
35  if (m_len < 0) {
36  m_len = 0;
37  }
38  rz_strpool_memcat(p, m_addr, m_len);
39  rz_strpool_memcat(p, inv[1], linv[1]);
40  offset = m->rm_eo;
41  free(m_addr);
42  }
43  }
44  /* append final part of string w/o matches */
46 }
voidpf uLong offset
Definition: ioapi.h:144
void * p
Definition: libc.cpp:67
line
Definition: setup.py:34
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
RZ_API int rz_strpool_append(RzStrpool *p, const char *s)
Definition: strpool.c:70
RZ_API char * rz_strpool_empty(RzStrpool *p)
Definition: strpool.c:27
RZ_API int rz_strpool_memcat(RzStrpool *p, const char *s, int len)
Definition: strpool.c:61

References free(), setup::line, regress::m, NULL, p, rz_str_ansi_filter(), rz_str_ndup(), rz_strpool_append(), rz_strpool_empty(), and rz_strpool_memcat().

Referenced by pager_printpage().

◆ pager_next_match()

RZ_IPI int pager_next_match ( int  from,
RzList **  mla,
int  lcount 
)

Definition at line 74 of file pager.c.

74  {
75  int l;
76  if (from > lcount - 2) {
77  return from;
78  }
79  for (l = from + 1; l < lcount; l++) {
80  /* if there's at least one match on the line */
81  if (rz_list_first(mla[l])) {
82  return l;
83  }
84  }
85  return from;
86 }
RZ_API RZ_BORROW void * rz_list_first(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:77
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123

References from, mla(), and rz_list_first().

Referenced by rz_cons_less_str().

◆ pager_prev_match()

RZ_IPI int pager_prev_match ( int  from,
RzList **  mla 
)

Definition at line 88 of file pager.c.

88  {
89  int l;
90  if (from < 1) {
91  return from;
92  }
93  for (l = from - 1; l > 0; l--) {
94  if (rz_list_first(mla[l])) {
95  return l;
96  }
97  }
98  return from;
99 }

References from, mla(), and rz_list_first().

Referenced by rz_cons_less_str().

◆ pager_printpage()

RZ_IPI void pager_printpage ( const char *  line,
int index,
RzList **  mla,
int  from,
int  to,
int  w 
)

Definition at line 48 of file pager.c.

48  {
49  int i;
50 
52  if (from < 0 || to < 0) {
53  return;
54  }
55 
57  if (!p) {
58  return;
59  }
60  for (i = from; i < to; i++) {
61  pager_color_line(line + index[i], p, mla[i]);
64  if (i + 1 == to) {
65  rz_cons_print(p->str);
66  } else {
67  rz_cons_println(p->str);
68  }
69  }
71  rz_cons_flush();
72 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_cons_clear00(void)
Definition: cons.c:778
RZ_API void rz_cons_reset_colors(void)
Definition: cons.c:783
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
#define w
Definition: crypto_rc6.c:13
RZ_IPI void pager_color_line(const char *line, RzStrpool *p, RzList *ml)
Definition: pager.c:9
RZ_API int rz_strpool_ansi_chop(RzStrpool *p, int n)
Definition: strpool.c:75
RZ_API void rz_strpool_free(RzStrpool *p)
Definition: strpool.c:82
RZ_API RzStrpool * rz_strpool_new(int sz)
Definition: strpool.c:6
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125

References from, i, setup::line, mla(), p, pager_color_line(), rz_cons_clear00(), rz_cons_flush(), rz_cons_println(), rz_cons_reset_colors(), rz_strpool_ansi_chop(), rz_strpool_free(), rz_strpool_new(), to, and w.

Referenced by rz_cons_less_str().

◆ pager_splitlines()

RZ_IPI int* pager_splitlines ( char *  s,
int lines_count 
)

Definition at line 136 of file pager.c.

136  {
137  int lines_size = 128;
138  int *lines = NULL;
139  int i, row = 0;
140  int sidx = 0;
141 
142  if (lines_size * sizeof(int) < lines_size) {
143  return NULL;
144  }
145  lines = malloc(lines_size * sizeof(int));
146  if (lines) {
147  lines[row++] = 0;
148  for (i = 0; s[i]; i++) {
149  if (row >= lines_size) {
150  int *tmp;
151  lines_size += 128;
152  if (lines_size * sizeof(int) < lines_size) {
153  free(lines);
154  return NULL;
155  }
156  tmp = realloc(lines, lines_size * sizeof(int));
157  if (!tmp) {
158  free(lines);
159  return NULL;
160  }
161  lines = tmp;
162  }
163  if (s[i] == '\n') {
164  s[i] = 0;
165  lines[row++] = i + 1;
166  }
167  sidx++;
168  }
169  *lines_count = row;
170  }
171  return lines;
172 }
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
void * malloc(size_t size)
Definition: malloc.c:123

References free(), i, lines(), malloc(), NULL, realloc(), s, and autogen_x86imm::tmp.

Referenced by rz_cons_less_str().