Rizin
unix-like reverse engineering framework and cli tools
filter.c File Reference
#include "rz_util/rz_str.h"
#include <rz_regex.h>
#include <stdio.h>
#include <rz_types.h>
#include <rz_parse.h>
#include <config.h>

Go to the source code of this file.

Macros

#define isx86separator(x)
 

Functions

static bool isvalidflag (RzFlagItem *flag)
 
static char * findEnd (const char *s)
 
static void insert (char *dst, const char *src)
 
static int parse_number (const char *str)
 
static void replaceWords (char *s, const char *k, const char *v)
 
static char * findNextNumber (char *op)
 
static void __replaceRegisters (RzReg *reg, char *s, bool x86)
 
static bool is_lea (const char *asm_str)
 Checks if the given asm string is an x86 "lea" instruction. More...
 
static bool filter (RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
 
RZ_API bool rz_parse_filter (RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
 filter the opcode in data into str by following the flags and hints information More...
 
RZ_API char * rz_parse_filter_dup (RzParse *p, ut64 addr, const char *opstr)
 

Macro Definition Documentation

◆ isx86separator

#define isx86separator (   x)
Value:
( \
(x) == ' ' || (x) == '\t' || (x) == '\n' || (x) == '\r' || (x) == ' ' || \
(x) == ',' || (x) == ';' || (x) == '[' || (x) == ']' || \
(x) == '(' || (x) == ')' || (x) == '{' || (x) == '}' || (x) == '\x1b')
int x
Definition: mipsasm.c:20

Definition at line 14 of file filter.c.

Function Documentation

◆ __replaceRegisters()

static void __replaceRegisters ( RzReg reg,
char *  s,
bool  x86 
)
static

Definition at line 147 of file filter.c.

147  {
148  int i;
149  for (i = 0; i < 64; i++) {
150  const char *k = rz_reg_get_name(reg, i);
151  if (!k || i == RZ_REG_NAME_PC) {
152  continue;
153  }
154  const char *v = rz_reg_get_role(i);
155  if (!v) {
156  break;
157  }
158  if (x86 && *k == 'r') {
159  replaceWords(s, k, v);
160  char *reg32 = strdup(k);
161  *reg32 = 'e';
162  replaceWords(s, reg32, v);
163  } else {
164  replaceWords(s, k, v);
165  }
166  }
167 }
lzma_index ** i
Definition: index.h:629
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
#define reg(n)
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 void replaceWords(char *s, const char *k, const char *v)
Definition: filter.c:71
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API const char * rz_reg_get_role(int role)
Definition: reg.c:172
static RzSocket * s
Definition: rtr.c:28
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43

References i, k, reg, replaceWords(), rz_reg_get_name(), rz_reg_get_role(), RZ_REG_NAME_PC, s, strdup(), and v.

Referenced by filter().

◆ filter()

static bool filter ( RzParse p,
ut64  addr,
RzFlag f,
RzAnalysisHint hint,
char *  data,
char *  str,
int  len,
bool  big_endian 
)
static

Definition at line 185 of file filter.c.

185  {
186  char *ptr = data, *ptr2, *ptr_backup;
187  RzAnalysisFunction *fcn;
188  RzFlagItem *flag;
189  ut64 off;
190  bool x86 = false;
191  bool arm = false;
192  if (p && p->cur && p->cur->name) {
193  if (strstr(p->cur->name, "x86")) {
194  x86 = true;
195  }
196  if (strstr(p->cur->name, "m68k")) {
197  x86 = true;
198  }
199  if (strstr(p->cur->name, "arm")) {
200  arm = true;
201  }
202  }
203  if (!data || !p) {
204  return 0;
205  }
206 #if FILTER_DWORD
207  replaceWords(ptr, "dword ", src);
208  replaceWords(ptr, "qword ", src);
209 #endif
210  if (p->subreg) {
211  __replaceRegisters(p->analb.analysis->reg, ptr, false);
212  if (x86) {
213  __replaceRegisters(p->analb.analysis->reg, ptr, true);
214  }
215  }
216  ptr2 = NULL;
217  // remove "dword" 2
218  char *nptr;
219  int count = 0;
220  for (count = 0; (nptr = findNextNumber(ptr)); count++) {
221  ptr = nptr;
222 
223  // Skip floats
224  for (ptr2 = ptr; IS_DIGIT(*ptr2); ptr2++) { // before .
225  ;
226  }
227  if (*ptr2 == '.' && IS_DIGIT(ptr2[1])) { // .
228  while (++ptr2, IS_DIGIT(*ptr2)) { // after .
229  ;
230  }
231  ptr = ptr2;
232  continue;
233  }
234 
235  if (x86) {
236  for (ptr2 = ptr; *ptr2 && !isx86separator(*ptr2); ptr2++) {
237  ;
238  }
239  } else {
240  for (ptr2 = ptr; *ptr2 && (*ptr2 != ']' && (*ptr2 != '\x1b') && !IS_SEPARATOR(*ptr2)); ptr2++) {
241  ;
242  }
243  }
244  off = rz_num_math(NULL, ptr);
245  if (off >= p->minval) {
246  fcn = p->analb.get_fcn_in(p->analb.analysis, off, 0);
247  if (fcn && fcn->addr == off) {
248  *ptr = 0;
249  // hack to realign pointer for colours
250  ptr2--;
251  if (*ptr2 != 0x1b) {
252  ptr2++;
253  }
254  const char *name = fcn->name;
255  // TODO: implement realname with flags, because functions dont hold this yet
256  if (f->realnames) {
257  flag = p->flag_get(f, off);
258  if (flag && flag->realname) {
259  name = flag->realname;
260  }
261  }
262  snprintf(str, len, "%s%s%s", data, name,
263  (ptr != ptr2) ? ptr2 : "");
264  return true;
265  }
266  if (f) {
267  RzFlagItem *flag2;
268  bool lea = x86 && is_lea(data);
269  bool remove_brackets = false;
270  flag = p->flag_get(f, off);
271  if ((!flag || arm) && p->subrel_addr) {
272  remove_brackets = lea || (arm && p->subrel_addr);
273  flag2 = p->flag_get(f, p->subrel_addr);
274  if (!flag || arm) {
275  flag = flag2;
276  }
277  }
278  if (flag && !strncmp(flag->name, "section.", 8)) {
279  flag = rz_flag_get_i(f, off);
280  }
281  const char *label = fcn ? p->label_get(fcn, off) : NULL;
282  if (label || isvalidflag(flag)) {
283  if (p->notin_flagspace) {
284  if (p->flagspace == flag->space) {
285  continue;
286  }
287  } else if (p->flagspace && (p->flagspace != flag->space)) {
288  ptr = ptr2;
289  continue;
290  }
291  // hack to realign pointer for colours
292  ptr2--;
293  if (*ptr2 != 0x1b) {
294  ptr2++;
295  }
296  ptr_backup = ptr;
297  if (remove_brackets && ptr != ptr2 && *ptr) {
298  if (*ptr2 == ']') {
299  ptr2++;
300  for (ptr--; ptr > data && *ptr != '['; ptr--) {
301  ;
302  }
303  if (ptr == data) {
304  ptr = ptr_backup;
305  }
306  }
307  }
308  *ptr = 0;
309  char *flagname;
310  if (label) {
311  flagname = rz_str_newf(".%s", label);
312  } else {
313  flagname = strdup(f->realnames ? flag->realname : flag->name);
314  }
315  int maxflagname = p->maxflagnamelen;
316  if (maxflagname > 0 && strlen(flagname) > maxflagname) {
317  char *doublelower = (char *)rz_str_rstr(flagname, "__");
318  char *doublecolon = (char *)rz_str_rstr(flagname, "::");
319  char *token = NULL;
320  if (doublelower && doublecolon) {
321  token = RZ_MAX(doublelower, doublecolon);
322  } else {
323  token = doublelower ? doublelower : doublecolon;
324  }
325  if (token) {
326  const char *mod = doublecolon ? "(cxx)" : "(...)";
327  char *newstr = rz_str_newf("%s%s", mod, token);
328  free(flagname);
329  flagname = newstr;
330  } else {
331  const char *lower = rz_str_rstr(flagname, "_");
332  char *newstr;
333  if (lower) {
334  newstr = rz_str_newf("..%s", lower + 1);
335  } else {
336  newstr = rz_str_newf("..%s", flagname + (strlen(flagname) - maxflagname));
337  }
338  free(flagname);
339  flagname = newstr;
340  }
341  }
342  snprintf(str, len, "%s%s%s", data, flagname, (ptr != ptr2) ? ptr2 : "");
343  free(flagname);
344  bool banned = false;
345  {
346  const char *p = strchr(str, '[');
347  const char *a = strchr(str, '+');
348  const char *m = strchr(str, '*');
349  if (p && (a || m)) {
350  banned = true;
351  }
352  }
353  if (p->subrel_addr && !banned && lea) { // TODO: use remove_brackets
354  int flag_len = strlen(flag->name);
355  char *ptr_end = str + strlen(data) + flag_len - 1;
356  char *ptr_right = ptr_end + 1, *ptr_left, *ptr_esc;
357  bool ansi_found = false;
358  if (!*ptr_end) {
359  return true;
360  }
361  while (*ptr_right) {
362  if (*ptr_right == 0x1b) {
363  while (*ptr_right && *ptr_right != 'm') {
364  ptr_right++;
365  }
366  if (*ptr_right) {
367  ptr_right++;
368  }
369  ansi_found = true;
370  continue;
371  }
372  if (*ptr_right == ']') {
373  ptr_left = ptr_esc = ptr_end - flag_len;
374  while (ptr_left >= str) {
375  if (*ptr_left == '[' &&
376  (ptr_left == str || *(ptr_left - 1) != 0x1b)) {
377  break;
378  }
379  ptr_left--;
380  }
381  if (ptr_left < str) {
382  break;
383  }
384  for (; ptr_esc >= str && *ptr_esc != 0x1b; ptr_esc--) {
385  ;
386  }
387  if (ptr_esc < str) {
388  ptr_esc = ptr_end - flag_len + 1;
389  }
390  int copied_len = ptr_end - ptr_esc + 1;
391  if (copied_len < 1) {
392  break;
393  }
394  memmove(ptr_left, ptr_esc, copied_len);
395  char *dptr_left = strcpy(ptr_left + copied_len,
396  (ansi_found && ptr_right - ptr_end + 1 >= 4) ? Color_RESET : "");
397  int dlen = strlen(dptr_left);
398  dptr_left += dlen;
399  char *dptr_end = ptr_right + 1;
400  while (*dptr_end) {
401  dptr_end++;
402  }
403  int llen = dptr_end - (ptr_right + 1);
404  memmove(dptr_left, ptr_right + 1, llen);
405  dptr_left[llen] = 0;
406  }
407  break;
408  }
409  }
410  return true;
411  }
412  if (p->subtail) { // && off > UT32_MAX && addr > UT32_MAX)
413  if (off != UT64_MAX) {
414  if (off == addr) {
415  insert(ptr, "$$");
416  } else {
417  ut64 tail = rz_num_tail_base(NULL, addr, off);
418  if (tail != UT64_MAX) {
419  char str[128];
420  snprintf(str, sizeof(str), "..%" PFMT64x, tail);
421  insert(ptr, str);
422  }
423  }
424  }
425  }
426  }
427  }
428  if (hint) {
429  const int nw = hint->nword;
430  if (count != nw) {
431  ptr = ptr2;
432  continue;
433  }
434  int pnumleft, immbase = hint->immbase;
435  char num[256] = { 0 }, *pnum, *tmp;
436  int tmp_count;
437  if (hint->offset) {
438  *ptr = 0;
439  snprintf(str, len, "%s%s%s", data, hint->offset, (ptr != ptr2) ? ptr2 : "");
440  return true;
441  }
442  strncpy(num, ptr, sizeof(num) - 2);
443  pnum = num + parse_number(num);
444  *pnum = 0;
445  switch (immbase) {
446  case 0:
447  // do nothing
448  break;
449  case 1: // hack for ascii
450  tmp_count = 0;
451  for (tmp = data; tmp < ptr; tmp++) {
452  if (*tmp == 0x1b) {
453  while (tmp < ptr - 1 && *tmp != 'm') {
454  tmp++;
455  }
456  continue;
457  } else if (*tmp == '[') {
458  tmp_count++;
459  } else if (*tmp == ']') {
460  tmp_count--;
461  }
462  }
463  if (tmp_count > 0) {
464  ptr = ptr2;
465  continue;
466  }
467  memset(num, 0, sizeof(num));
468  pnum = num;
469  *pnum++ = '\'';
470  pnumleft = sizeof(num) - 2;
471  // Convert *off* to ascii string, byte by byte.
472  // Since *num* is 256 bytes long, we can omit
473  // overflow checks.
474  while (off) {
475  ut8 ch;
476  if (big_endian) {
477  ch = off & 0xff;
478  off >>= 8;
479  } else {
480  ch = off >> (8 * (sizeof(off) - 1));
481  off <<= 8;
482  }
483 
484  // Skip first '\x00' bytes
485  if (num[1] == '\0' && ch == '\0') {
486  continue;
487  }
488  if (IS_PRINTABLE(ch)) {
489  *pnum++ = ch;
490  pnumleft--;
491  } else {
492  int sz = snprintf(pnum, pnumleft, "\\x%2.2x", ch);
493  if (sz < 0) {
494  break;
495  }
496  pnum += sz;
497  pnumleft -= sz;
498  }
499  }
500  *pnum++ = '\'';
501  *pnum = '\0';
502  break;
503  case 2:
505  strcat(num, "b");
506  break;
507  case 3: {
508  ut64 swap = 0;
509  if (big_endian) {
510  swap = off & 0xffff;
511  } else {
512  if (off >> 32) {
513  rz_mem_swapendian((ut8 *)&swap, (const ut8 *)&off, sizeof(off));
514  } else if (off >> 16) {
515  ut32 port = 0;
516  rz_mem_swapendian((ut8 *)&port, (const ut8 *)&off, sizeof(port));
517  swap = port;
518  } else {
519  ut16 port = 0;
520  rz_mem_swapendian((ut8 *)&port, (const ut8 *)&off, sizeof(port));
521  swap = port;
522  }
523  }
524  snprintf(num, sizeof(num), "htons (%d)", (int)(swap & 0xFFFF));
525  } break;
526  case 8:
527  snprintf(num, sizeof(num), "0%o", (int)off);
528  break;
529  case 10: {
530  const RzList *regs = rz_reg_get_list(p->analb.analysis->reg, RZ_REG_TYPE_GPR);
531  RzRegItem *reg;
532  RzListIter *iter;
533  bool imm32 = false;
534  rz_list_foreach (regs, iter, reg) {
535  if (reg->size == 32 && rz_str_casestr(data, reg->name)) {
536  imm32 = true;
537  break;
538  }
539  }
540  if (imm32) {
541  snprintf(num, sizeof(num), "%" PFMT32d, (st32)off);
542  break;
543  }
544  snprintf(num, sizeof(num), "%" PFMT64d, (st64)off);
545  } break;
546  case 11:
547  snprintf(num, sizeof(num), "%" PFMT64u, off);
548  break;
549  case 32: {
550  ut32 ip32 = off;
551  ut8 *ip = (ut8 *)&ip32;
552  snprintf(num, sizeof(num), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
553  } break;
554  case 80:
555  if (p && p->analb.analysis && p->analb.analysis->syscall) {
556  RzSyscallItem *si;
557  si = rz_syscall_get(p->analb.analysis->syscall, off, -1);
558  if (si) {
559  snprintf(num, sizeof(num), "%s()", si->name);
561  } else {
562  snprintf(num, sizeof(num), "unknown()");
563  }
564  }
565  break;
566  case 16:
567  /* do nothing */
568  default:
569  snprintf(num, sizeof(num), "0x%" PFMT64x, (ut64)off);
570  break;
571  }
572  *ptr = 0;
573  snprintf(str, len, "%s%s%s", data, num, (ptr != ptr2) ? ptr2 : "");
574  return true;
575  }
576  ptr = ptr2;
577  }
578  if (data != str) {
579  strncpy(str, data, len);
580  } else {
581  eprintf("Invalid str/data inputs\n");
582  }
583  return false;
584 }
size_t len
Definition: 6502dis.c:15
si
static char * regs[]
Definition: analysis_sh.c:203
lzma_index * src
Definition: index.h:567
static RASN1String * newstr(const char *string)
Definition: astr.c:23
#define NULL
Definition: cris-opc.c:27
int mod(int a, int b)
Definition: crypto_rot.c:8
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
uint16_t ut16
uint32_t ut32
RZ_API RzFlagItem * rz_flag_get_i(RzFlag *f, ut64 off)
Definition: flag.c:317
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
snprintf
Definition: kernel.h:364
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
void * p
Definition: libc.cpp:67
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
#define ip
int off
Definition: pal.c:13
static void insert(char *dst, const char *src)
Definition: filter.c:39
static void __replaceRegisters(RzReg *reg, char *s, bool x86)
Definition: filter.c:147
static int parse_number(const char *str)
Definition: filter.c:46
static bool is_lea(const char *asm_str)
Checks if the given asm string is an x86 "lea" instruction.
Definition: filter.c:176
static bool isvalidflag(RzFlagItem *flag)
Definition: filter.c:19
#define isx86separator(x)
Definition: filter.c:14
static char * findNextNumber(char *op)
Definition: filter.c:84
#define swap(a, b)
Definition: qsort.h:111
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
Definition: reg.c:389
#define eprintf(x, y...)
Definition: rlcc.c:7
#define Color_RESET
Definition: rz_cons.h:617
RZ_API void rz_mem_swapendian(ut8 *dest, const ut8 *orig, int size)
Definition: mem.c:202
RZ_API ut64 rz_num_tail_base(RzNum *num, ut64 addr, ut64 off)
Definition: unum.c:753
RZ_API int rz_num_to_bits(char *out, ut64 num)
Definition: unum.c:542
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_rstr(const char *base, const char *p)
Definition: str.c:814
RZ_API const char * rz_str_casestr(const char *a, const char *b)
Definition: str.c:2757
#define IS_SEPARATOR(x)
Definition: rz_str_util.h:6
#define IS_DIGIT(x)
Definition: rz_str_util.h:11
#define IS_PRINTABLE(x)
Definition: rz_str_util.h:10
#define PFMT64d
Definition: rz_types.h:394
#define PFMT64u
Definition: rz_types.h:395
#define PFMT64x
Definition: rz_types.h:393
#define PFMT32d
Definition: rz_types.h:408
#define st64
Definition: rz_types_base.h:10
#define RZ_MAX(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
#define st32
Definition: rz_types_base.h:12
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
Definition: dis.h:35
Definition: z80asm.h:102
RzSpace * space
Definition: rz_flag.h:40
char * realname
Definition: rz_flag.h:36
char * name
Definition: rz_flag.h:35
RZ_API void rz_syscall_item_free(RzSyscallItem *si)
Definition: syscall.c:325
RZ_API RzSyscallItem * rz_syscall_get(RzSyscall *s, int num, int swi)
Definition: syscall.c:345
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References __replaceRegisters(), a, addr, rz_analysis_function_t::addr, Color_RESET, count, eprintf, f, findNextNumber(), free(), rz_analysis_hint_t::immbase, insert(), ip, IS_DIGIT, is_lea(), IS_PRINTABLE, IS_SEPARATOR, isvalidflag(), isx86separator, len, regress::m, memset(), mod(), rz_analysis_function_t::name, rz_flag_item_t::name, newstr(), NULL, num, rz_analysis_hint_t::nword, off, rz_analysis_hint_t::offset, p, parse_number(), PFMT32d, PFMT64d, PFMT64u, PFMT64x, rz_flag_item_t::realname, reg, regs, replaceWords(), rz_flag_get_i(), RZ_MAX, rz_mem_swapendian(), rz_num_math(), rz_num_tail_base(), rz_num_to_bits(), rz_reg_get_list(), RZ_REG_TYPE_GPR, rz_str_casestr(), rz_str_newf(), rz_str_rstr(), rz_syscall_get(), rz_syscall_item_free(), si, snprintf, rz_flag_item_t::space, src, st32, st64, cmd_descs_generate::str, strdup(), swap, autogen_x86imm::tmp, ut64(), and UT64_MAX.

Referenced by __matchString(), __renew_filter(), compute_symbols_from_segment(), get_gnu_debugdata_elf_symbols(), lzma_simple_coder_init(), rz_bin_trycatch_new(), rz_cmd_debug_dmi(), rz_main_rz_bin(), rz_parse_filter(), scandir(), sdb_foreach_list_filter_user(), and uv__io_poll().

◆ findEnd()

static char* findEnd ( const char *  s)
static

Definition at line 31 of file filter.c.

31  {
32  while (*s == 'x' || IS_HEXCHAR(*s)) {
33  s++;
34  // also skip ansi escape codes here :?
35  }
36  return strdup(s);
37 }
#define IS_HEXCHAR(x)
Definition: rz_str_util.h:9

References IS_HEXCHAR, s, and strdup().

Referenced by insert().

◆ findNextNumber()

static char* findNextNumber ( char *  op)
static

Definition at line 84 of file filter.c.

84  {
85  if (!op) {
86  return NULL;
87  }
88  bool ansi_found = false;
89  char *p = op;
90  const char *o = NULL;
91  while (*p) {
92  if (p[0] == 0x1b && p[1] == '[') {
93  ansi_found = true;
94  p += 2;
95  for (; *p && *p != 'J' && *p != 'm' && *p != 'H'; p++) {
96  ;
97  }
98  if (*p) {
99  p++;
100  if (!*p) {
101  break;
102  }
103  }
104  o = p - 1;
105  } else {
106  bool isSpace = ansi_found;
107  ansi_found = false;
108  if (!isSpace) {
109  isSpace = p == op;
110  if (!isSpace && o) {
111  isSpace = (*o == ' ' || *o == ',' || *o == '[');
112  }
113  }
114  if (*p == '[') {
115  p++;
116  if (!*p) {
117  break;
118  }
119  if (!IS_DIGIT(*p)) {
120  char *t = p;
121  for (; *t && *t != ']'; t++) {
122  ;
123  }
124  if (*t == ']') {
125  continue;
126  }
127  p = t;
128  if (!*p) {
129  break;
130  }
131  }
132  }
133  if (isSpace) {
134  if (IS_DIGIT(*p)) {
135  return p;
136  }
137  if ((*p == '-') && IS_DIGIT(p[1])) {
138  return p + 1;
139  }
140  }
141  o = p++;
142  }
143  }
144  return NULL;
145 }
ut8 op
Definition: 6502dis.c:13
Definition: dis.c:32
static int isSpace(char ch)
Definition: visual.c:966

References IS_DIGIT, isSpace(), NULL, op, and p.

Referenced by filter().

◆ insert()

static void insert ( char *  dst,
const char *  src 
)
static

Definition at line 39 of file filter.c.

39  {
40  char *endNum = findEnd(dst);
41  strcpy(dst, src);
42  strcpy(dst + strlen(src), endNum);
43  free(endNum);
44 }
char * dst
Definition: lz4.h:724
static char * findEnd(const char *s)
Definition: filter.c:31

References dst, findEnd(), free(), and src.

Referenced by filter(), and rtr_visual().

◆ is_lea()

static bool is_lea ( const char *  asm_str)
static

Checks if the given asm string is an x86 "lea" instruction.

Parameters
asm_strThe asm string.
Returns
true The asm string represents a "lea" instruction.
false Otherwise.

Definition at line 176 of file filter.c.

176  {
177  rz_return_val_if_fail(asm_str, false);
178  bool colored = asm_str[0] == '\x1b';
179  if (!colored) {
180  return strlen(asm_str) > 4 && rz_str_startswith_icase(asm_str, "lea") && asm_str[3] == ' ';
181  }
182  return rz_regex_match("(^\x1b\\[[[:digit:]]{1,3}mlea\x1b\\[0m.+)", "ei", asm_str) != RZ_REGEX_NOMATCH;
183 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_REGEX_NOMATCH
Definition: rz_regex.h:33
RZ_API int rz_regex_match(const char *pattern, const char *flags, const char *text)
Definition: regcomp.c:142
RZ_API bool rz_str_startswith_icase(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case insensitive)
Definition: str.c:3301

References rz_regex_match(), RZ_REGEX_NOMATCH, rz_return_val_if_fail, and rz_str_startswith_icase().

Referenced by filter().

◆ isvalidflag()

static bool isvalidflag ( RzFlagItem flag)
static

Definition at line 19 of file filter.c.

19  {
20  if (flag) {
21  if (strstr(flag->name, "main") || strstr(flag->name, "entry")) {
22  return true;
23  }
24  if (strchr(flag->name, '.')) {
25  return true;
26  }
27  }
28  return false;
29 }

References rz_flag_item_t::name.

Referenced by filter().

◆ parse_number()

static int parse_number ( const char *  str)
static

Definition at line 46 of file filter.c.

46  {
47  const char *p = str;
48  // Parse as hexadecmial (0x notation)
49  if (!strncmp(p, "0x", 2)) {
50  for (p += 2; *p && IS_HEXCHAR(*p); p++) {
51  }
52  return p - str;
53  }
54  // Parse as hexadecimal (trailing 'h' notation)
55  for (; *p; p++) {
56  if (IS_HEXCHAR(*p)) {
57  continue;
58  }
59  if (*p == 'h' || *p == 'H') {
60  return p - str + 1;
61  }
62  break;
63  }
64  // Parse as decimal
65  for (; *p && IS_DIGIT(*p); p++) {
66  }
67  return p - str;
68 }

References IS_DIGIT, IS_HEXCHAR, p, and cmd_descs_generate::str.

Referenced by filter().

◆ replaceWords()

static void replaceWords ( char *  s,
const char *  k,
const char *  v 
)
static

Definition at line 71 of file filter.c.

71  {
72  for (;;) {
73  char *p = strstr(s, k);
74  if (!p) {
75  break;
76  }
77  char *s = p + strlen(k);
78  char *d = p + strlen(v);
79  memmove(d, s, strlen(s) + 1);
80  memmove(p, v, strlen(v));
81  }
82 }
#define d(i)
Definition: sha256.c:44

References d, k, p, s, and v.

Referenced by __replaceRegisters(), and filter().

◆ rz_parse_filter()

RZ_API bool rz_parse_filter ( RzParse p,
ut64  addr,
RzFlag f,
RzAnalysisHint hint,
char *  data,
char *  str,
int  len,
bool  big_endian 
)

filter the opcode in data into str by following the flags and hints information

Definition at line 592 of file filter.c.

592  {
593  filter(p, addr, f, hint, data, str, len, big_endian);
594  if (p->cur && p->cur->filter) {
595  return p->cur->filter(p, addr, f, data, str, len, big_endian);
596  }
597  return false;
598 }
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
Definition: filter.c:185

References addr, f, filter(), len, p, and cmd_descs_generate::str.

Referenced by do_asm_search(), do_ref_search(), ds_build_op_str(), rz_analysis_xrefs_from_list_handler(), rz_core_analysis_bytes(), rz_core_disasm_instruction(), rz_core_disasm_pdi_with_buf(), rz_core_print_disasm_all(), and rz_parse_filter_dup().

◆ rz_parse_filter_dup()

RZ_API char* rz_parse_filter_dup ( RzParse p,
ut64  addr,
const char *  opstr 
)

Definition at line 601 of file filter.c.

601  {
602  const size_t out_len = 256;
603  char *in = strdup(opstr);
604  char *out = calloc(out_len, 1);
605  if (!rz_parse_filter(p, addr, NULL, NULL, in, out, out_len, false)) {
606  free(out);
607  return NULL;
608  }
609  return out;
610 }
static int opstr(RzAsm *a, ut8 *data, const Opcode *op)
Definition: asm_x86_nz.c:4054
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API bool rz_parse_filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
filter the opcode in data into str by following the flags and hints information
Definition: filter.c:592

References addr, calloc(), free(), in, NULL, opstr(), out, p, rz_parse_filter(), and strdup().