Rizin
unix-like reverse engineering framework and cli tools
rz_name.h File Reference
#include <rz_types.h>

Go to the source code of this file.

Functions

RZ_API bool rz_name_check (const char *name, bool strict)
 
RZ_API bool rz_name_filter (char *name, int len, bool strict)
 
RZ_API char * rz_name_filter2 (const char *name, bool strict)
 
RZ_API bool rz_name_validate_char (const char ch, bool strict)
 

Function Documentation

◆ rz_name_check()

RZ_API bool rz_name_check ( const char *  name,
bool  strict 
)

Definition at line 24 of file name.c.

24  {
25  /* Cannot start by number */
26  if (!name || !*name || IS_DIGIT(*name)) {
27  return false;
28  }
29  /* Cannot contain non-alphanumeric chars + [:._] */
30  for (; *name != '\0'; name++) {
31  if (!rz_name_validate_char(*name, strict)) {
32  return false;
33  }
34  }
35  return true;
36 }
RZ_API bool rz_name_validate_char(const char ch, bool strict)
Definition: name.c:6
#define IS_DIGIT(x)
Definition: rz_str_util.h:11
Definition: z80asm.h:102

References IS_DIGIT, and rz_name_validate_char().

Referenced by rz_name_filter().

◆ rz_name_filter()

RZ_API bool rz_name_filter ( char *  name,
int  len,
bool  strict 
)

Definition at line 43 of file name.c.

43  {
44  size_t i, len;
45  if (!name) {
46  return false;
47  }
48  if (maxlen < 0) {
49  maxlen = strlen(name);
50  }
52  char *oname = name;
53  for (i = 0; *name; name++, i++) {
54  if (maxlen && i > maxlen) {
55  *name = '\0';
56  break;
57  }
58  if (!rz_name_validate_char(*name, strict) && *name != '\\') {
59  *name = '_';
60  }
61  }
62  while (i > 0) {
63  if (*(name - 1) == '\\' && is_special_char(name)) {
64  *name = '_';
65  *(name - 1) = '_';
66  }
67  if (*name == '\\') {
68  *name = '_';
69  }
70  name--;
71  i--;
72  }
73  if (*name == '\\') {
74  *name = '_';
75  }
76  // trimming trailing and leading underscores
77  len = strlen(name);
78  for (; len > 0 && *(name + len - 1) == '_'; len--) {
79  ;
80  }
81  if (!len) { // name consists only of underscores
82  return rz_name_check(oname, strict);
83  }
84  for (i = 0; *(name + i) == '_'; i++, len--) {
85  ;
86  }
87  memmove(name, name + i, len);
88  *(name + len) = '\0';
89  return rz_name_check(oname, strict);
90 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
static bool is_special_char(char *name)
Definition: name.c:38
RZ_API bool rz_name_check(const char *name, bool strict)
Definition: name.c:24
const char * name
Definition: op.c:541
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
ut64 maxlen
Definition: core.c:76

References i, is_special_char(), len, maxlen, name, rz_name_check(), rz_name_validate_char(), and rz_str_trim().

Referenced by add_string_ref(), apply_maps_as_flags(), cb_binprefix(), cmd_debug_current_modules(), cmd_debug_modules(), construct_symbol_flagname(), core_recover_golang_functions_go_1_16(), core_recover_golang_functions_go_1_18(), core_recover_golang_functions_go_1_2(), filter_item_name(), is_filtered_flag(), module_match_buffer(), print_debug_map_line(), recover_string_at(), reloc_set_flag(), rz_core_bin_apply_classes(), rz_core_bin_apply_sections(), rz_core_bin_apply_strings(), rz_core_bin_apply_symbols(), rz_core_bin_class_build_flag_name(), rz_core_bin_field_build_flag_name(), rz_core_bin_load(), rz_core_bin_method_build_flag_name(), rz_core_bin_super_build_flag_name(), rz_core_meta_print(), rz_core_sym_name_init(), rz_core_visual_define(), and set_new_xref().

◆ rz_name_filter2()

RZ_API char* rz_name_filter2 ( const char *  name,
bool  strict 
)

Definition at line 92 of file name.c.

92  {
93  size_t i;
94  while (!rz_name_validate_char(*name, strict)) {
95  name++;
96  }
97  char *res = strdup(name);
98  for (i = 0; res[i]; i++) {
99  if (!rz_name_validate_char(res[i], strict)) {
100  res[i] = '_';
101  }
102  }
103  for (i--; i != 0 && res[i] == '_'; i--) {
104  res[i] = '\0';
105  }
106  return res;
107 }
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")

References i, rz_name_validate_char(), and strdup().

Referenced by pdb_set_symbols().

◆ rz_name_validate_char()

RZ_API bool rz_name_validate_char ( const char  ch,
bool  strict 
)

Definition at line 6 of file name.c.

6  {
7  if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (IS_DIGIT(ch))) {
8  return true;
9  }
10  switch (ch) {
11  case ':':
12  case '.':
13  case '_':
14  return true;
15  case '-':
16  case '[':
17  case ']':
18  return !strict;
19  default:
20  return false;
21  }
22 }

References IS_DIGIT.

Referenced by findBreakChar(), rz_name_check(), rz_name_filter(), and rz_name_filter2().