Rizin
unix-like reverse engineering framework and cli tools
flag.c File Reference
#include <rz_flag.h>
#include <rz_util.h>
#include <rz_cons.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  unset_off_foreach_t
 
struct  unset_foreach_t
 
struct  flag_relocate_t
 

Macros

#define IS_FI_NOTIN_SPACE(f, i)   (rz_flag_space_cur(f) && (i)->space != rz_flag_space_cur(f))
 
#define IS_FI_IN_SPACE(fi, sp)   (!(sp) || (fi)->space == (sp))
 
#define STRDUP_OR_NULL(s)   (!RZ_STR_ISEMPTY(s) ? strdup(s) : NULL)
 
#define FOREACH_BODY(condition)
 

Functions

 RZ_LIB_VERSION (rz_flag)
 
static const char * str_callback (RzNum *user, ut64 off, int *ok)
 
static void flag_skiplist_free (void *data)
 
static int flag_skiplist_cmp (const void *va, const void *vb)
 
static ut64 num_callback (RzNum *user, const char *name, int *ok)
 
static void free_item_realname (RzFlagItem *item)
 
static void free_item_name (RzFlagItem *item)
 
static RzFlagsAtOffsetrz_flag_get_nearest_list (RzFlag *f, ut64 off, int dir)
 
static void remove_offsetmap (RzFlag *f, RzFlagItem *item)
 
static RzFlagsAtOffsetflags_at_offset (RzFlag *f, ut64 off)
 
static char * filter_item_name (const char *name)
 
static void set_name (RzFlagItem *item, char *name)
 
static bool update_flag_item_offset (RzFlag *f, RzFlagItem *item, ut64 newoff, bool is_new, bool force)
 
static bool update_flag_item_name (RzFlag *f, RzFlagItem *item, const char *newname, bool force)
 
static void ht_free_flag (HtPPKv *kv)
 
static bool count_flags (RzFlagItem *fi, void *user)
 
static bool unset_flags_space (RzFlagItem *fi, void *user)
 
static void count_flags_in_space (RzEvent *ev, int type, void *user, void *data)
 
static void unset_flagspace (RzEvent *ev, int type, void *user, void *data)
 
static void new_spaces (RzFlag *f)
 
RZ_API RzFlagrz_flag_new (void)
 
RZ_API RzFlagItemrz_flag_item_clone (RzFlagItem *item)
 
RZ_API void rz_flag_item_free (RzFlagItem *item)
 
RZ_API RzFlagrz_flag_free (RzFlag *f)
 
static RzFlagItemevalFlag (RzFlag *f, RzFlagItem *item)
 
RZ_API bool rz_flag_exist_at (RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off)
 
RZ_API RzFlagItemrz_flag_get (RzFlag *f, const char *name)
 
RZ_API RzFlagItemrz_flag_get_i (RzFlag *f, ut64 off)
 
RZ_API RzFlagItemrz_flag_get_by_spaces (RzFlag *f, ut64 off,...)
 
static bool isFunctionFlag (const char *n)
 
RZ_API RzFlagItemrz_flag_get_at (RzFlag *f, ut64 off, bool closest)
 
static bool append_to_list (RzFlagItem *fi, void *user)
 
RZ_API RzListrz_flag_all_list (RzFlag *f, bool by_space)
 
RZ_API const RzListrz_flag_get_list (RzFlag *f, ut64 off)
 
RZ_API char * rz_flag_get_liststr (RzFlag *f, ut64 off)
 
RZ_API RzFlagItemrz_flag_set_next (RzFlag *f, const char *name, ut64 off, ut32 size)
 
RZ_API RzFlagItemrz_flag_set (RzFlag *f, const char *name, ut64 off, ut32 size)
 
RZ_API void rz_flag_item_set_alias (RzFlagItem *item, const char *alias)
 
RZ_API void rz_flag_item_set_comment (RzFlagItem *item, const char *comment)
 
RZ_API void rz_flag_item_set_realname (RzFlagItem *item, const char *realname)
 
RZ_API const char * rz_flag_item_set_color (RzFlagItem *item, const char *color)
 
RZ_API int rz_flag_rename (RzFlag *f, RzFlagItem *item, const char *name)
 
RZ_API bool rz_flag_unset (RzFlag *f, RzFlagItem *item)
 
RZ_API bool rz_flag_unset_off (RzFlag *f, ut64 off)
 
static bool unset_off_foreach (void *user, const void *k, const void *v)
 
RZ_API bool rz_flag_unset_all_off (RzFlag *f, ut64 off)
 
static bool unset_foreach (RzFlagItem *fi, void *user)
 
RZ_API int rz_flag_unset_glob (RzFlag *f, const char *glob)
 
RZ_API bool rz_flag_unset_name (RzFlag *f, const char *name)
 
RZ_API void rz_flag_unset_all (RzFlag *f)
 
RZ_API void rz_flag_unset_all_in_space (RzFlag *f, const char *space_name)
 Unset all flag items in the space with the given name. More...
 
static bool flag_relocate_foreach (RzFlagItem *fi, void *user)
 
RZ_API int rz_flag_relocate (RzFlag *f, ut64 off, ut64 off_mask, ut64 to)
 
RZ_API bool rz_flag_move (RzFlag *f, ut64 at, ut64 to)
 
RZ_API void rz_flag_bind (RzFlag *f, RzFlagBind *fb)
 
static bool flag_count_foreach (RzFlagItem *fi, void *user)
 
RZ_API int rz_flag_count (RzFlag *f, const char *glob)
 
RZ_API void rz_flag_foreach (RzFlag *f, RzFlagItemCb cb, void *user)
 
RZ_API void rz_flag_foreach_prefix (RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user)
 
RZ_API void rz_flag_foreach_range (RZ_NONNULL RzFlag *f, ut64 from, ut64 to, RzFlagItemCb cb, void *user)
 
RZ_API void rz_flag_foreach_glob (RzFlag *f, const char *glob, RzFlagItemCb cb, void *user)
 
RZ_API void rz_flag_foreach_space_glob (RzFlag *f, const char *glob, const RzSpace *space, RzFlagItemCb cb, void *user)
 
RZ_API void rz_flag_foreach_space (RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user)
 

Macro Definition Documentation

◆ FOREACH_BODY

#define FOREACH_BODY (   condition)
Value:
RzFlagsAtOffset *flags_at; \
RzListIter *it2, *tmp2; \
RzFlagItem *fi; \
rz_skiplist_foreach_safe(f->by_off, it, tmp, flags_at) { \
if (flags_at) { \
rz_list_foreach_safe (flags_at->flags, it2, tmp2, fi) { \
if (condition) { \
if (!cb(fi, user)) { \
return; \
} \
} \
} \
} \
}
#define f(i)
Definition: sha256.c:46
static const char * cb[]
Definition: z80_tab.h:176

Definition at line 783 of file flag.c.

◆ IS_FI_IN_SPACE

#define IS_FI_IN_SPACE (   fi,
  sp 
)    (!(sp) || (fi)->space == (sp))

Definition at line 13 of file flag.c.

◆ IS_FI_NOTIN_SPACE

#define IS_FI_NOTIN_SPACE (   f,
  i 
)    (rz_flag_space_cur(f) && (i)->space != rz_flag_space_cur(f))

Definition at line 12 of file flag.c.

◆ STRDUP_OR_NULL

#define STRDUP_OR_NULL (   s)    (!RZ_STR_ISEMPTY(s) ? strdup(s) : NULL)

Definition at line 14 of file flag.c.

Function Documentation

◆ append_to_list()

static bool append_to_list ( RzFlagItem fi,
void *  user 
)
static

Definition at line 457 of file flag.c.

457  {
458  RzList *ret = (RzList *)user;
459  rz_list_append(ret, fi);
460  return true;
461 }
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

References rz_list_append().

Referenced by rz_flag_all_list().

◆ count_flags()

static bool count_flags ( RzFlagItem fi,
void *  user 
)
static

Definition at line 189 of file flag.c.

189  {
190  int *count = (int *)user;
191  (*count)++;
192  return true;
193 }
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

References count.

Referenced by count_flags_in_space().

◆ count_flags_in_space()

static void count_flags_in_space ( RzEvent ev,
int  type,
void *  user,
void *  data 
)
static

Definition at line 200 of file flag.c.

200  {
201  RzSpaces *sp = (RzSpaces *)ev->user;
203  RzSpaceEvent *spe = (RzSpaceEvent *)data;
204  rz_flag_foreach_space(f, spe->data.count.space, count_flags, &spe->res);
205 }
static bool count_flags(RzFlagItem *fi, void *user)
Definition: flag.c:189
RZ_API void rz_flag_foreach_space(RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user)
Definition: flag.c:826
const char * spaces(int count)
#define container_of(ptr, type, member)
Definition: rz_types.h:650
void * user
Definition: rz_event.h:15
struct rz_space_event_t::@311::@312 count
union rz_space_event_t::@311 data
static int sp
Definition: z80asm.c:91

References container_of, rz_space_event_t::count, count_flags(), rz_space_event_t::data, f, rz_space_event_t::res, rz_flag_foreach_space(), sp, spaces(), and rz_event_t::user.

Referenced by new_spaces().

◆ evalFlag()

static RzFlagItem* evalFlag ( RzFlag f,
RzFlagItem item 
)
static

Definition at line 283 of file flag.c.

283  {
284  rz_return_val_if_fail(f && item, NULL);
285  if (item->alias) {
286  item->offset = rz_num_math(f->num, item->alias);
287  }
288  return item;
289 }
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
char * alias
Definition: rz_flag.h:43
ut64 offset
Definition: rz_flag.h:38

References rz_flag_item_t::alias, f, NULL, rz_flag_item_t::offset, rz_num_math(), and rz_return_val_if_fail.

Referenced by rz_flag_get(), rz_flag_get_at(), rz_flag_get_by_spaces(), and rz_flag_get_i().

◆ filter_item_name()

static char* filter_item_name ( const char *  name)
static

Definition at line 125 of file flag.c.

125  {
126  char *res = strdup(name);
127  if (!res) {
128  return NULL;
129  }
130 
131  rz_str_trim(res);
132  rz_name_filter(res, 0, true);
133  return res;
134 }
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")
RZ_API bool rz_name_filter(char *name, int len, bool strict)
Definition: name.c:43
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
Definition: z80asm.h:102

References NULL, rz_name_filter(), rz_str_trim(), and strdup().

Referenced by rz_flag_set(), and update_flag_item_name().

◆ flag_count_foreach()

static bool flag_count_foreach ( RzFlagItem fi,
void *  user 
)
static

Definition at line 770 of file flag.c.

770  {
771  int *count = (int *)user;
772  (*count)++;
773  return true;
774 }

References count.

Referenced by rz_flag_count().

◆ flag_relocate_foreach()

static bool flag_relocate_foreach ( RzFlagItem fi,
void *  user 
)
static

Definition at line 713 of file flag.c.

713  {
714  struct flag_relocate_t *u = (struct flag_relocate_t *)user;
715  ut64 fn = fi->offset & u->neg_mask;
716  ut64 on = u->off & u->neg_mask;
717  if (fn == on) {
718  ut64 fm = fi->offset & u->off_mask;
719  ut64 om = u->to & u->off_mask;
720  update_flag_item_offset(u->f, fi, (u->to & u->neg_mask) + fm + om, false, false);
721  u->n++;
722  }
723  return true;
724 }
static bool update_flag_item_offset(RzFlag *f, RzFlagItem *item, ut64 newoff, bool is_new, bool force)
Definition: flag.c:143
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
RzFlag * f
Definition: flag.c:705
ut64 off
Definition: flag.c:706
ut64 off_mask
Definition: flag.c:707
ut64 neg_mask
Definition: flag.c:708
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References flag_relocate_t::f, fn, flag_relocate_t::n, flag_relocate_t::neg_mask, flag_relocate_t::off, flag_relocate_t::off_mask, rz_flag_item_t::offset, flag_relocate_t::to, update_flag_item_offset(), and ut64().

Referenced by rz_flag_relocate().

◆ flag_skiplist_cmp()

static int flag_skiplist_cmp ( const void *  va,
const void *  vb 
)
static

Definition at line 40 of file flag.c.

40  {
41  const RzFlagsAtOffset *a = (RzFlagsAtOffset *)va, *b = (RzFlagsAtOffset *)vb;
42  if (a->off == b->off) {
43  return 0;
44  }
45  return a->off < b->off ? -1 : 1;
46 }
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, b, and patch_major_os_version::vb.

Referenced by rz_flag_new().

◆ flag_skiplist_free()

static void flag_skiplist_free ( void *  data)
static

Definition at line 34 of file flag.c.

34  {
35  RzFlagsAtOffset *item = (RzFlagsAtOffset *)data;
36  rz_list_free(item->flags);
37  free(data);
38 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RzList * flags
Definition: rz_flag.h:31

References rz_flags_at_offset_t::flags, free(), and rz_list_free().

Referenced by rz_flag_new().

◆ flags_at_offset()

static RzFlagsAtOffset* flags_at_offset ( RzFlag f,
ut64  off 
)
static

Definition at line 102 of file flag.c.

102  {
104  if (res) {
105  return res;
106  }
107 
108  // there is no existing flagsAtOffset, we create one now
109  res = RZ_NEW(RzFlagsAtOffset);
110  if (!res) {
111  return NULL;
112  }
113 
114  res->flags = rz_list_new();
115  if (!res->flags) {
116  free(res);
117  return NULL;
118  }
119 
120  res->off = off;
121  rz_skiplist_insert(f->by_off, res);
122  return res;
123 }
static RzFlagsAtOffset * rz_flag_get_nearest_list(RzFlag *f, ut64 off, int dir)
Definition: flag.c:83
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
int off
Definition: pal.c:13
RZ_API RzSkipListNode * rz_skiplist_insert(RzSkipList *list, void *data)
Definition: skiplist.c:156
#define RZ_NEW(x)
Definition: rz_types.h:285

References f, rz_flags_at_offset_t::flags, free(), NULL, off, rz_flags_at_offset_t::off, rz_flag_get_nearest_list(), rz_list_new(), RZ_NEW, and rz_skiplist_insert().

Referenced by update_flag_item_offset().

◆ free_item_name()

static void free_item_name ( RzFlagItem item)
static

Definition at line 73 of file flag.c.

73  {
74  if (item->name != item->realname) {
75  free(item->name);
76  }
77 }
char * realname
Definition: rz_flag.h:36
char * name
Definition: rz_flag.h:35

References free(), rz_flag_item_t::name, and rz_flag_item_t::realname.

Referenced by rz_flag_item_free(), and set_name().

◆ free_item_realname()

static void free_item_realname ( RzFlagItem item)
static

Definition at line 67 of file flag.c.

67  {
68  if (item->name != item->realname) {
69  free(item->realname);
70  }
71 }

References free(), rz_flag_item_t::name, and rz_flag_item_t::realname.

Referenced by rz_flag_item_set_realname(), and set_name().

◆ ht_free_flag()

static void ht_free_flag ( HtPPKv *  kv)
static

Definition at line 184 of file flag.c.

184  {
185  free(kv->key);
186  rz_flag_item_free(kv->value);
187 }
RZ_API void rz_flag_item_free(RzFlagItem *item)
Definition: flag.c:258

References free(), and rz_flag_item_free().

Referenced by rz_flag_new(), and rz_flag_unset_all().

◆ isFunctionFlag()

static bool isFunctionFlag ( const char *  n)
static

Definition at line 398 of file flag.c.

398  {
399  return (!strncmp(n, "sym.func.", 9) || !strncmp(n, "method.", 7) || !strncmp(n, "sym.", 4) || !strncmp(n, "func.", 5) || !strncmp(n, "fcn.0", 5));
400 }
int n
Definition: mipsasm.c:19

References n.

Referenced by rz_flag_get_at().

◆ new_spaces()

static void new_spaces ( RzFlag f)
static

Definition at line 214 of file flag.c.

214  {
215  rz_spaces_init(&f->spaces, "fs");
218 }
static void count_flags_in_space(RzEvent *ev, int type, void *user, void *data)
Definition: flag.c:200
static void unset_flagspace(RzEvent *ev, int type, void *user, void *data)
Definition: flag.c:207
RZ_API RzEventCallbackHandle rz_event_hook(RzEvent *ev, int type, RzEventCallback cb, void *user)
Definition: event.c:58
@ RZ_SPACE_EVENT_COUNT
Definition: rz_spaces.h:34
@ RZ_SPACE_EVENT_UNSET
Definition: rz_spaces.h:36
RZ_API bool rz_spaces_init(RzSpaces *sp, const char *name)
Definition: spaces.c:16

References count_flags_in_space(), f, NULL, rz_event_hook(), RZ_SPACE_EVENT_COUNT, RZ_SPACE_EVENT_UNSET, rz_spaces_init(), and unset_flagspace().

Referenced by rz_flag_new(), and rz_flag_unset_all().

◆ num_callback()

static ut64 num_callback ( RzNum user,
const char *  name,
int ok 
)
static

Definition at line 48 of file flag.c.

48  {
49  RzFlag *f = (RzFlag *)user;
50  if (ok) {
51  *ok = 0;
52  }
53  RzFlagItem *item = ht_pp_find(f->ht_name, name, NULL);
54  if (item) {
55  // NOTE: to avoid warning infinite loop here we avoid recursivity
56  if (item->alias) {
57  return 0LL;
58  }
59  if (ok) {
60  *ok = 1;
61  }
62  return item->offset;
63  }
64  return 0LL;
65 }
@ ok
Definition: lz4.c:1706

References rz_flag_item_t::alias, f, NULL, rz_flag_item_t::offset, and ok.

Referenced by rz_flag_new().

◆ remove_offsetmap()

static void remove_offsetmap ( RzFlag f,
RzFlagItem item 
)
static

Definition at line 91 of file flag.c.

91  {
92  rz_return_if_fail(f && item);
94  if (flags) {
95  rz_list_delete_data(flags->flags, item);
96  if (rz_list_empty(flags->flags)) {
97  rz_skiplist_delete(f->by_off, flags);
98  }
99  }
100 }
RZ_API bool rz_list_delete_data(RZ_NONNULL RzList *list, void *ptr)
Deletes an entry in the list by searching for a pointer.
Definition: list.c:148
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API bool rz_skiplist_delete(RzSkipList *list, void *data)
Definition: skiplist.c:201
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References f, flags, rz_flag_item_t::offset, rz_flag_get_nearest_list(), rz_list_delete_data(), rz_return_if_fail, and rz_skiplist_delete().

Referenced by rz_flag_unset(), and update_flag_item_offset().

◆ rz_flag_all_list()

RZ_API RzList* rz_flag_all_list ( RzFlag f,
bool  by_space 
)

Definition at line 463 of file flag.c.

463  {
464  RzList *ret = rz_list_new();
465  if (!ret) {
466  return NULL;
467  }
468 
469  RzSpace *cur = by_space ? rz_flag_space_cur(f) : NULL;
471  return ret;
472 }
static bool append_to_list(RzFlagItem *fi, void *user)
Definition: flag.c:457

References append_to_list(), f, NULL, rz_flag_foreach_space(), and rz_list_new().

Referenced by autocmplt_cmd_arg_flag(), rz_core_visual_trackflags(), rz_flag_describe_closest_handler(), and rz_flag_unset_all_in_space().

◆ rz_flag_bind()

RZ_API void rz_flag_bind ( RzFlag f,
RzFlagBind fb 
)

Definition at line 752 of file flag.c.

752  {
753  rz_return_if_fail(f && fb);
754  fb->f = f;
756  fb->get = rz_flag_get;
757  fb->get_at = rz_flag_get_at;
760  fb->set = rz_flag_set;
761  fb->unset = rz_flag_unset;
764  fb->set_fs = rz_flag_space_set;
765  fb->push_fs = rz_flag_space_push;
766  fb->pop_fs = rz_flag_space_pop;
767  fb->rename = rz_flag_rename;
768 }
RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name)
Definition: flag.c:587
RZ_API const RzList * rz_flag_get_list(RzFlag *f, ut64 off)
Definition: flag.c:475
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
RZ_API bool rz_flag_exist_at(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off)
Definition: flag.c:293
RZ_API bool rz_flag_unset(RzFlag *f, RzFlagItem *item)
Definition: flag.c:597
RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name)
Definition: flag.c:670
RZ_API RzFlagItem * rz_flag_get_by_spaces(RzFlag *f, ut64 off,...)
Definition: flag.c:326
RZ_API bool rz_flag_unset_off(RzFlag *f, ut64 off)
Definition: flag.c:608
RzFlagExistAt exist_at
Definition: rz_flag.h:79
RzFlagGetAtBySpaces get_at_by_spaces
Definition: rz_flag.h:82
RzFlagSet set
Definition: rz_flag.h:84
RzFlagRename rename
Definition: rz_flag.h:91
RzFlagGet get
Definition: rz_flag.h:80
RzFlagGetAt get_at
Definition: rz_flag.h:81
RzFlagGetList get_list
Definition: rz_flag.h:83
RzFlagSetSpace set_fs
Definition: rz_flag.h:88
RzFlagPopSpace pop_fs
Definition: rz_flag.h:90
RzFlagUnsetName unset_name
Definition: rz_flag.h:86
RzFlagUnsetOff unset_off
Definition: rz_flag.h:87
RzFlag * f
Definition: rz_flag.h:78
RzFlagPushSpace push_fs
Definition: rz_flag.h:89
RzFlagUnset unset
Definition: rz_flag.h:85

References rz_flag_bind_t::exist_at, rz_flag_bind_t::f, f, rz_flag_bind_t::get, rz_flag_bind_t::get_at, rz_flag_bind_t::get_at_by_spaces, rz_flag_bind_t::get_list, rz_flag_bind_t::pop_fs, rz_flag_bind_t::push_fs, rz_flag_bind_t::rename, rz_flag_exist_at(), rz_flag_get(), rz_flag_get_at(), rz_flag_get_by_spaces(), rz_flag_get_list(), rz_flag_rename(), rz_flag_set(), rz_flag_unset(), rz_flag_unset_name(), rz_flag_unset_off(), rz_return_if_fail, rz_flag_bind_t::set, rz_flag_bind_t::set_fs, rz_flag_bind_t::unset, rz_flag_bind_t::unset_name, and rz_flag_bind_t::unset_off.

Referenced by rz_core_init().

◆ rz_flag_count()

RZ_API int rz_flag_count ( RzFlag f,
const char *  glob 
)

Definition at line 776 of file flag.c.

776  {
777  int count = 0;
780  return count;
781 }
static bool flag_count_foreach(RzFlagItem *fi, void *user)
Definition: flag.c:770
RZ_API void rz_flag_foreach_glob(RzFlag *f, const char *glob, RzFlagItemCb cb, void *user)
Definition: flag.c:818

References count, f, flag_count_foreach(), rz_flag_foreach_glob(), and rz_return_val_if_fail.

Referenced by rz_core_analysis_sigdb_apply(), rz_flirt_scan_handler(), and rz_print_analysis_details_handler().

◆ rz_flag_exist_at()

RZ_API bool rz_flag_exist_at ( RzFlag f,
const char *  flag_prefix,
ut16  fp_size,
ut64  off 
)

Definition at line 293 of file flag.c.

293  {
294  rz_return_val_if_fail(f && flag_prefix, false);
295  RzListIter *iter = NULL;
296  RzFlagItem *item = NULL;
297  const RzList *list = rz_flag_get_list(f, off);
298  if (list) {
299  rz_list_foreach (list, iter, item) {
300  if (item->name && !strncmp(item->name, flag_prefix, fp_size)) {
301  return true;
302  }
303  }
304  }
305  return false;
306 }
static void list(RzEgg *egg)
Definition: rz-gg.c:52

References f, list(), rz_flag_item_t::name, NULL, off, rz_flag_get_list(), and rz_return_val_if_fail.

Referenced by propagate_types_among_used_variables(), and rz_flag_bind().

◆ rz_flag_foreach()

RZ_API void rz_flag_foreach ( RzFlag f,
RzFlagItemCb  cb,
void *  user 
)

Definition at line 800 of file flag.c.

800  {
801  FOREACH_BODY(true);
802 }
#define FOREACH_BODY(condition)
Definition: flag.c:783

References FOREACH_BODY.

Referenced by __rebase_everything(), rz_core_seek_next(), rz_core_seek_prev(), rz_core_visual_hudstuff(), rz_flag_relocate(), rz_flag_tags_get(), and rz_serialize_flag_save().

◆ rz_flag_foreach_glob()

RZ_API void rz_flag_foreach_glob ( RzFlag f,
const char *  glob,
RzFlagItemCb  cb,
void *  user 
)

Definition at line 818 of file flag.c.

818  {
819  FOREACH_BODY(!glob || rz_str_glob(fi->name, glob));
820 }
RZ_API bool rz_str_glob(const char *str, const char *glob)
Definition: str.c:2368

References FOREACH_BODY, and rz_str_glob().

Referenced by flag_ordinals(), flag_to_flag(), rz_analyze_symbols_entries_flags_handler(), rz_analyze_symbols_entries_handler(), rz_core_cmd_foreach3(), rz_flag_base_handler(), rz_flag_count(), and rz_flag_unset_glob().

◆ rz_flag_foreach_prefix()

RZ_API void rz_flag_foreach_prefix ( RzFlag f,
const char *  pfx,
int  pfx_len,
RzFlagItemCb  cb,
void *  user 
)

Definition at line 804 of file flag.c.

804  {
805  pfx_len = pfx_len < 0 ? strlen(pfx) : pfx_len;
806  FOREACH_BODY(!strncmp(fi->name, pfx, pfx_len));
807 }

References FOREACH_BODY.

Referenced by autocmplt_cmd_arg_rznum(), autocomplete_flags(), rz_core_autocomplete(), rz_core_seek_next(), and rz_core_seek_prev().

◆ rz_flag_foreach_range()

RZ_API void rz_flag_foreach_range ( RZ_NONNULL RzFlag f,
ut64  from,
ut64  to,
RzFlagItemCb  cb,
void *  user 
)
Parameters
frominclusive
toinclusive

Definition at line 813 of file flag.c.

813  {
815  FOREACH_BODY(fi->offset >= from && fi->offset <= to);
816 }
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
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 f, FOREACH_BODY, from, rz_return_if_fail, and to.

Referenced by rz_core_analysis_get_stats().

◆ rz_flag_foreach_space()

RZ_API void rz_flag_foreach_space ( RzFlag f,
const RzSpace space,
RzFlagItemCb  cb,
void *  user 
)

◆ rz_flag_foreach_space_glob()

RZ_API void rz_flag_foreach_space_glob ( RzFlag f,
const char *  glob,
const RzSpace space,
RzFlagItemCb  cb,
void *  user 
)

Definition at line 822 of file flag.c.

822  {
823  FOREACH_BODY(IS_FI_IN_SPACE(fi, space) && (!glob || rz_str_glob(fi->name, glob)));
824 }

References FOREACH_BODY, IS_FI_IN_SPACE, and rz_str_glob().

Referenced by flagbars().

◆ rz_flag_free()

RZ_API RzFlag* rz_flag_free ( RzFlag f)

Definition at line 271 of file flag.c.

271  {
273  rz_skiplist_free(f->by_off);
274  ht_pp_free(f->ht_name);
275  sdb_free(f->tags);
276  rz_spaces_fini(&f->spaces);
277  rz_num_free(f->num);
278  rz_list_free(f->zones);
279  free(f);
280  return NULL;
281 }
RZ_API void rz_num_free(RzNum *num)
Definition: unum.c:87
RZ_API void rz_skiplist_free(RzSkipList *list)
Definition: skiplist.c:145
RZ_API void rz_spaces_fini(RzSpaces *sp)
Definition: spaces.c:59
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206

References f, free(), NULL, rz_list_free(), rz_num_free(), rz_return_val_if_fail, rz_skiplist_free(), rz_spaces_fini(), and sdb_free().

Referenced by rz_core_fini(), and rz_flag_new().

◆ rz_flag_get()

◆ rz_flag_get_at()

RZ_API RzFlagItem* rz_flag_get_at ( RzFlag f,
ut64  off,
bool  closest 
)

Definition at line 404 of file flag.c.

404  {
406 
407  RzFlagItem *nice = NULL;
408  RzListIter *iter;
409  const RzFlagsAtOffset *flags_at = rz_flag_get_nearest_list(f, off, -1);
410  if (!flags_at) {
411  return NULL;
412  }
413  if (flags_at->off == off) {
414  RzFlagItem *item;
415  rz_list_foreach (flags_at->flags, iter, item) {
416  if (IS_FI_NOTIN_SPACE(f, item)) {
417  continue;
418  }
419  if (nice) {
420  if (isFunctionFlag(nice->name)) {
421  nice = item;
422  }
423  } else {
424  nice = item;
425  }
426  }
427  if (nice) {
428  return evalFlag(f, nice);
429  }
430  }
431 
432  if (!closest) {
433  return NULL;
434  }
435  while (!nice && flags_at) {
436  RzFlagItem *item;
437  rz_list_foreach (flags_at->flags, iter, item) {
438  if (IS_FI_NOTIN_SPACE(f, item)) {
439  continue;
440  }
441  if (item->offset == off) {
442  eprintf("XXX Should never happend\n");
443  return evalFlag(f, item);
444  }
445  nice = item;
446  break;
447  }
448  if (!nice && flags_at->off) {
449  flags_at = rz_flag_get_nearest_list(f, flags_at->off - 1, -1);
450  } else {
451  flags_at = NULL;
452  }
453  }
454  return nice ? evalFlag(f, nice) : NULL;
455 }
static bool isFunctionFlag(const char *n)
Definition: flag.c:398
#define IS_FI_NOTIN_SPACE(f, i)
Definition: flag.c:12
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 nice
Definition: sflib.h:61
#define eprintf(x, y...)
Definition: rlcc.c:7

References eprintf, evalFlag(), f, rz_flags_at_offset_t::flags, IS_FI_NOTIN_SPACE, isFunctionFlag(), nice, NULL, off, rz_flags_at_offset_t::off, rz_flag_item_t::offset, rz_flag_get_nearest_list(), and rz_return_val_if_fail.

Referenced by __refs(), __xrefs(), _CbInRangeAav(), add_single_addr_xrefs(), backtrace_vars(), cmd_print_bars(), core_flag_get_at_as_ref_type(), ds_pre_emulation(), ds_print_esil_analysis(), ds_print_lines_left(), ds_print_offset(), ds_show_xrefs(), fill_hist_offset(), get_backtrace_info(), getNameDelta(), prompt_add_offset(), rz_analysis_xrefs_from_list_handler(), rz_core_flag_describe(), rz_core_print_hexdump_byline_str(), rz_core_visual_title(), rz_core_visual_xrefs(), rz_flag_add_handler(), rz_flag_bind(), rz_seek_history_list_handler(), and trace_traverse_pre().

◆ rz_flag_get_by_spaces()

RZ_API RzFlagItem* rz_flag_get_by_spaces ( RzFlag f,
ut64  off,
  ... 
)

Definition at line 326 of file flag.c.

326  {
328 
329  const RzList *list = rz_flag_get_list(f, off);
330  RzFlagItem *ret = NULL;
331  const char *spacename;
332  RzSpace **spaces;
333  RzListIter *iter;
334  RzFlagItem *flg;
335  va_list ap, aq;
336  size_t n_spaces = 0, i;
337 
338  va_start(ap, off);
339  // some quick checks for common cases
340  if (rz_list_empty(list)) {
341  goto beach;
342  }
343  if (rz_list_length(list) == 1) {
344  ret = rz_list_get_top(list);
345  goto beach;
346  }
347 
348  // count spaces in the vaarg
349  va_copy(aq, ap);
350  spacename = va_arg(aq, const char *);
351  while (spacename) {
352  n_spaces++;
353  spacename = va_arg(aq, const char *);
354  }
355  va_end(aq);
356 
357  // get RzSpaces from the names
358  i = 0;
359  spaces = RZ_NEWS(RzSpace *, n_spaces);
360  spacename = va_arg(ap, const char *);
361  while (spacename) {
362  RzSpace *space = rz_flag_space_get(f, spacename);
363  if (space) {
364  spaces[i++] = space;
365  }
366  spacename = va_arg(ap, const char *);
367  }
368  n_spaces = i;
369 
370  ut64 min_space_i = n_spaces + 1;
371  rz_list_foreach (list, iter, flg) {
372  // get the "priority" of the flag flagspace and
373  // check if better than what we found so far
374  for (i = 0; i < n_spaces; i++) {
375  if (flg->space == spaces[i]) {
376  break;
377  }
378  if (i >= min_space_i) {
379  break;
380  }
381  }
382 
383  if (i < min_space_i) {
384  min_space_i = i;
385  ret = flg;
386  }
387  if (!min_space_i) {
388  // this is the best flag we can find, let's stop immediately
389  break;
390  }
391  }
392  free(spaces);
393 beach:
394  va_end(ap);
395  return ret ? evalFlag(f, ret) : NULL;
396 }
lzma_index ** i
Definition: index.h:629
RZ_API RZ_BORROW void * rz_list_get_top(RZ_NONNULL const RzList *list)
Returns the last element of the list.
Definition: list.c:457
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
RzSpace * space
Definition: rz_flag.h:40

References evalFlag(), f, free(), i, list(), NULL, off, rz_flag_get_list(), rz_list_get_top(), rz_list_length(), RZ_NEWS, rz_return_val_if_fail, rz_flag_item_t::space, spaces(), and ut64().

Referenced by core_flag_get_at_as_ref_type(), ds_print_demangled(), ds_print_fcn_name(), ds_show_xrefs(), propagate_types_among_used_variables(), rz_analysis_extract_rarg(), rz_core_analysis_function_strings_print(), rz_core_flag_get_by_spaces(), rz_flag_bind(), set_jump_realname(), and type_match().

◆ rz_flag_get_i()

◆ rz_flag_get_list()

◆ rz_flag_get_liststr()

RZ_API char* rz_flag_get_liststr ( RzFlag f,
ut64  off 
)

Definition at line 480 of file flag.c.

480  {
481  RzFlagItem *fi;
482  RzListIter *iter;
483  const RzList *list = rz_flag_get_list(f, off);
484  char *p = NULL;
485  rz_list_foreach (list, iter, fi) {
486  p = rz_str_appendf(p, "%s%s",
487  fi->realname, iter->n ? "," : "");
488  }
489  return p;
490 }
void * p
Definition: libc.cpp:67
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2

References f, list(), NULL, off, p, rz_flag_item_t::realname, rz_flag_get_list(), and rz_str_appendf().

Referenced by ds_print_show_bytes(), and rz_core_analysis_hasrefs_to_depth().

◆ rz_flag_get_nearest_list()

static RzFlagsAtOffset* rz_flag_get_nearest_list ( RzFlag f,
ut64  off,
int  dir 
)
static

Definition at line 83 of file flag.c.

83  {
84  RzFlagsAtOffset key = { .off = off };
85  RzFlagsAtOffset *flags = (dir >= 0)
86  ? rz_skiplist_get_geq(f->by_off, &key)
87  : rz_skiplist_get_leq(f->by_off, &key);
88  return (dir == 0 && flags && flags->off != off) ? NULL : flags;
89 }
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 static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
RZ_API void * rz_skiplist_get_geq(RzSkipList *list, void *data)
Definition: skiplist.c:273
RZ_API void * rz_skiplist_get_leq(RzSkipList *list, void *data)
Definition: skiplist.c:278

References f, flags, key, NULL, off, rz_skiplist_get_geq(), and rz_skiplist_get_leq().

Referenced by flags_at_offset(), remove_offsetmap(), rz_flag_get_at(), and rz_flag_get_list().

◆ rz_flag_item_clone()

RZ_API RzFlagItem* rz_flag_item_clone ( RzFlagItem item)

Definition at line 240 of file flag.c.

240  {
242 
244  if (!n) {
245  return NULL;
246  }
247  n->color = STRDUP_OR_NULL(item->color);
248  n->comment = STRDUP_OR_NULL(item->comment);
249  n->alias = STRDUP_OR_NULL(item->alias);
250  n->name = STRDUP_OR_NULL(item->name);
251  n->realname = STRDUP_OR_NULL(item->realname);
252  n->offset = item->offset;
253  n->size = item->size;
254  n->space = item->space;
255  return n;
256 }
#define STRDUP_OR_NULL(s)
Definition: flag.c:14
#define RZ_NEW0(x)
Definition: rz_types.h:284
char * color
Definition: rz_flag.h:41
char * comment
Definition: rz_flag.h:42

References rz_flag_item_t::alias, rz_flag_item_t::color, rz_flag_item_t::comment, n, rz_flag_item_t::name, NULL, rz_flag_item_t::offset, rz_flag_item_t::realname, RZ_NEW0, rz_return_val_if_fail, rz_flag_item_t::size, rz_flag_item_t::space, and STRDUP_OR_NULL.

Referenced by duplicate_flag().

◆ rz_flag_item_free()

RZ_API void rz_flag_item_free ( RzFlagItem item)

Definition at line 258 of file flag.c.

258  {
259  if (!item) {
260  return;
261  }
262  free(item->color);
263  free(item->comment);
264  free(item->alias);
265  /* release only one of the two pointers if they are the same */
266  free_item_name(item);
267  free(item->realname);
268  free(item);
269 }
static void free_item_name(RzFlagItem *item)
Definition: flag.c:73

References rz_flag_item_t::alias, rz_flag_item_t::color, rz_flag_item_t::comment, free(), free_item_name(), and rz_flag_item_t::realname.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), ht_free_flag(), rz_core_cmd_foreach(), and rz_flag_set().

◆ rz_flag_item_set_alias()

RZ_API void rz_flag_item_set_alias ( RzFlagItem item,
const char *  alias 
)

Definition at line 557 of file flag.c.

557  {
558  rz_return_if_fail(item);
559  free(item->alias);
560  item->alias = RZ_STR_ISEMPTY(alias) ? NULL : strdup(alias);
561 }
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67

References rz_flag_item_t::alias, free(), NULL, rz_return_if_fail, RZ_STR_ISEMPTY, and strdup().

Referenced by rz_flag_alias_handler().

◆ rz_flag_item_set_color()

RZ_API const char* rz_flag_item_set_color ( RzFlagItem item,
const char *  color 
)

Definition at line 578 of file flag.c.

578  {
580  free(item->color);
581  item->color = (color && *color) ? strdup(color) : NULL;
582  return item->color;
583 }
static int color
Definition: visual.c:20

References color, rz_flag_item_t::color, free(), NULL, rz_return_val_if_fail, and strdup().

Referenced by rz_core_visual_define(), and rz_flag_color_handler().

◆ rz_flag_item_set_comment()

RZ_API void rz_flag_item_set_comment ( RzFlagItem item,
const char *  comment 
)

Definition at line 564 of file flag.c.

564  {
565  rz_return_if_fail(item);
566  free(item->comment);
567  item->comment = RZ_STR_ISEMPTY(comment) ? NULL : strdup(comment);
568 }

References rz_flag_item_t::comment, free(), NULL, rz_return_if_fail, RZ_STR_ISEMPTY, and strdup().

Referenced by flag_set_comment(), and rz_core_bin_apply_symbols().

◆ rz_flag_item_set_realname()

RZ_API void rz_flag_item_set_realname ( RzFlagItem item,
const char *  realname 
)

Definition at line 571 of file flag.c.

571  {
572  rz_return_if_fail(item);
573  free_item_realname(item);
574  item->realname = RZ_STR_ISEMPTY(realname) ? NULL : strdup(realname);
575 }
static void free_item_realname(RzFlagItem *item)
Definition: flag.c:67

References free_item_realname(), NULL, rz_flag_item_t::realname, rz_return_if_fail, RZ_STR_ISEMPTY, and strdup().

Referenced by pdb_set_symbols(), reloc_set_flag(), rz_core_bin_apply_symbols(), and rz_flag_realname_handler().

◆ rz_flag_move()

RZ_API bool rz_flag_move ( RzFlag f,
ut64  at,
ut64  to 
)

Definition at line 741 of file flag.c.

741  {
742  rz_return_val_if_fail(f, false);
743  RzFlagItem *item = rz_flag_get_i(f, at);
744  if (item) {
745  rz_flag_set(f, item->name, to, item->size);
746  return true;
747  }
748  return false;
749 }
RZ_API RzFlagItem * rz_flag_get_i(RzFlag *f, ut64 off)
Definition: flag.c:317

References f, rz_flag_item_t::name, rz_flag_get_i(), rz_flag_set(), rz_return_val_if_fail, rz_flag_item_t::size, and to.

Referenced by rebase_helper(), and rz_flag_move_handler().

◆ rz_flag_new()

RZ_API RzFlag* rz_flag_new ( void  )

Definition at line 220 of file flag.c.

220  {
221  RzFlag *f = RZ_NEW0(RzFlag);
222  if (!f) {
223  return NULL;
224  }
225  f->num = rz_num_new(&num_callback, &str_callback, f);
226  if (!f->num) {
227  rz_flag_free(f);
228  return NULL;
229  }
230  f->base = 0;
231  f->zones = NULL;
232  f->tags = sdb_new0();
233  f->ht_name = ht_pp_new(NULL, ht_free_flag, NULL);
235  rz_list_free(f->zones);
236  new_spaces(f);
237  return f;
238 }
static ut64 num_callback(RzNum *user, const char *name, int *ok)
Definition: flag.c:48
static const char * str_callback(RzNum *user, ut64 off, int *ok)
Definition: flag.c:16
RZ_API RzFlag * rz_flag_free(RzFlag *f)
Definition: flag.c:271
static void new_spaces(RzFlag *f)
Definition: flag.c:214
static void ht_free_flag(HtPPKv *kv)
Definition: flag.c:184
static void flag_skiplist_free(void *data)
Definition: flag.c:34
static int flag_skiplist_cmp(const void *va, const void *vb)
Definition: flag.c:40
RZ_API RzNum * rz_num_new(RzNumCallback cb, RzNumCallback2 cb2, void *ptr)
Definition: unum.c:75
RZ_API RzSkipList * rz_skiplist_new(RzListFree freefn, RzListComparator comparefn)
Definition: skiplist.c:107
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43

References f, flag_skiplist_cmp(), flag_skiplist_free(), ht_free_flag(), new_spaces(), NULL, num_callback(), rz_flag_free(), rz_list_free(), RZ_NEW0, rz_num_new(), rz_skiplist_new(), sdb_new0(), and str_callback().

Referenced by rz_core_init().

◆ rz_flag_relocate()

RZ_API int rz_flag_relocate ( RzFlag f,
ut64  off,
ut64  off_mask,
ut64  to 
)

Definition at line 726 of file flag.c.

726  {
728  struct flag_relocate_t u = {
729  .f = f,
730  .off = off,
731  .off_mask = off_mask,
732  .neg_mask = ~(off_mask),
733  .to = to,
734  .n = 0
735  };
736 
738  return u.n;
739 }
static bool flag_relocate_foreach(RzFlagItem *fi, void *user)
Definition: flag.c:713
RZ_API void rz_flag_foreach(RzFlag *f, RzFlagItemCb cb, void *user)
Definition: flag.c:800

References flag_relocate_t::f, f, flag_relocate_foreach(), n, flag_relocate_t::n, off, flag_relocate_t::off_mask, rz_flag_foreach(), rz_return_val_if_fail, and to.

Referenced by rz_flag_relocate_handler().

◆ rz_flag_rename()

RZ_API int rz_flag_rename ( RzFlag f,
RzFlagItem item,
const char *  name 
)

Definition at line 587 of file flag.c.

587  {
588  rz_return_val_if_fail(f && item && name && *name, false);
589  return update_flag_item_name(f, item, name, false);
590 }
static bool update_flag_item_name(RzFlag *f, RzFlagItem *item, const char *newname, bool force)
Definition: flag.c:162

References f, rz_return_val_if_fail, and update_flag_item_name().

Referenced by function_rename(), rename_flag_ordinal(), rz_analysis_var_global_rename(), rz_core_analysis_autoname_all_fcns(), rz_core_analysis_function_rename(), rz_core_analysis_rename(), rz_core_visual_define(), rz_flag_bind(), and rz_flag_rename_handler().

◆ rz_flag_set()

RZ_API RzFlagItem* rz_flag_set ( RzFlag f,
const char *  name,
ut64  off,
ut32  size 
)

Definition at line 521 of file flag.c.

521  {
523 
524  bool is_new = false;
525  char *itemname = filter_item_name(name);
526  if (!itemname) {
527  return NULL;
528  }
529 
530  RzFlagItem *item = rz_flag_get(f, itemname);
531  free(itemname);
532  if (item && item->offset == off) {
533  item->size = size;
534  return item;
535  }
536 
537  if (!item) {
538  item = RZ_NEW0(RzFlagItem);
539  if (!item) {
540  goto err;
541  }
542  is_new = true;
543  }
544 
545  item->space = rz_flag_space_cur(f);
546  item->size = size;
547 
548  update_flag_item_offset(f, item, off + f->base, is_new, true);
549  update_flag_item_name(f, item, name, true);
550  return item;
551 err:
552  rz_flag_item_free(item);
553  return NULL;
554 }
static bool err
Definition: armass.c:435
static char * filter_item_name(const char *name)
Definition: flag.c:125
voidpf void uLong size
Definition: ioapi.h:138

References err, f, filter_item_name(), free(), NULL, off, rz_flag_item_t::offset, rz_flag_get(), rz_flag_item_free(), RZ_NEW0, rz_return_val_if_fail, rz_flag_item_t::size, rz_flag_item_t::space, update_flag_item_name(), and update_flag_item_offset().

Referenced by __core_analysis_fcn(), __handle_mouse_on_panel(), __rebase_flags(), _cb_hit(), _CbInRangeAav(), add_arch_platform_flag_comment_cb(), add_mmio_extended_flag_cb(), add_mmio_flag_cb(), add_new_func_symbol(), add_string_ref(), core_flg_class_set(), core_flg_fcn_set(), core_recover_golang_functions_go_1_16(), core_recover_golang_functions_go_1_18(), core_recover_golang_functions_go_1_2(), do_analysis_search(), do_asm_search(), do_syscall_search(), foreach_reg_set_or_clear(), function_rename(), pdb_set_symbols(), recover_string_at(), regs_to_flags(), rz_analysis_var_global_add(), rz_cmd_alias(), rz_core_analysis_flag_every_function(), rz_core_analysis_function_rename(), rz_core_analysis_rename(), rz_core_bin_apply_classes(), rz_core_bin_apply_entry(), rz_core_bin_apply_main(), rz_core_bin_apply_resources(), rz_core_bin_apply_sections(), rz_core_bin_apply_strings(), rz_core_bin_apply_symbols(), rz_core_bin_export_info(), rz_core_magic_at(), rz_core_visual_cmd(), rz_core_visual_define(), rz_flag_add_handler(), rz_flag_alias_handler(), rz_flag_append_handler(), rz_flag_bind(), rz_flag_move(), rz_flag_set_next(), set_new_xref(), and w32_list_heaps_blocks().

◆ rz_flag_set_next()

RZ_API RzFlagItem* rz_flag_set_next ( RzFlag f,
const char *  name,
ut64  off,
ut32  size 
)

Definition at line 494 of file flag.c.

494  {
496  if (!rz_flag_get(f, name)) {
497  return rz_flag_set(f, name, off, size);
498  }
499  int i, newNameSize = strlen(name);
500  char *newName = malloc(newNameSize + 16);
501  if (!newName) {
502  return NULL;
503  }
504  strcpy(newName, name);
505  for (i = 0;; i++) {
506  snprintf(newName + newNameSize, 15, ".%d", i);
507  if (!rz_flag_get(f, newName)) {
508  RzFlagItem *fi = rz_flag_set(f, newName, off, size);
509  if (fi) {
510  free(newName);
511  return fi;
512  }
513  }
514  }
515  return NULL;
516 }
snprintf
Definition: kernel.h:364
void * malloc(size_t size)
Definition: malloc.c:123

References f, free(), i, malloc(), NULL, off, rz_flag_get(), rz_flag_set(), rz_return_val_if_fail, and snprintf.

Referenced by apply_maps_as_flags(), reloc_set_flag(), rz_analysis_dwarf_integrate_functions(), and rz_core_analysis_esil().

◆ rz_flag_unset()

RZ_API bool rz_flag_unset ( RzFlag f,
RzFlagItem item 
)

Definition at line 597 of file flag.c.

597  {
598  rz_return_val_if_fail(f && item, false);
599  remove_offsetmap(f, item);
600  ht_pp_delete(f->ht_name, item->name);
601  return true;
602 }
static void remove_offsetmap(RzFlag *f, RzFlagItem *item)
Definition: flag.c:91

References f, rz_flag_item_t::name, remove_offsetmap(), and rz_return_val_if_fail.

Referenced by rz_analysis_var_global_free(), rz_core_bin_apply_symbols(), rz_flag_bind(), rz_flag_unset_all_in_space(), rz_flag_unset_name(), rz_flag_unset_off(), unset_foreach(), and unset_off_foreach().

◆ rz_flag_unset_all()

RZ_API void rz_flag_unset_all ( RzFlag f)

Definition at line 677 of file flag.c.

677  {
679  ht_pp_free(f->ht_name);
680  f->ht_name = ht_pp_new(NULL, ht_free_flag, NULL);
681  rz_skiplist_purge(f->by_off);
682  rz_spaces_fini(&f->spaces);
683  new_spaces(f);
684 }
RZ_API void rz_skiplist_purge(RzSkipList *list)
Definition: skiplist.c:128

References f, ht_free_flag(), new_spaces(), NULL, rz_return_if_fail, rz_skiplist_purge(), and rz_spaces_fini().

Referenced by rz_flag_remove_all_handler(), rz_open_close_all_handler(), and rz_serialize_flag_load().

◆ rz_flag_unset_all_in_space()

RZ_API void rz_flag_unset_all_in_space ( RzFlag f,
const char *  space_name 
)

Unset all flag items in the space with the given name.

Parameters
fan RzFlag
space_namename of the space

Definition at line 692 of file flag.c.

692  {
693  rz_flag_space_push(f, space_name);
694  RzList *flags = rz_flag_all_list(f, true);
695  RzFlagItem *flag;
696  RzListIter *iter;
697  rz_list_foreach (flags, iter, flag) {
698  rz_flag_unset(f, flag);
699  }
700  rz_flag_space_pop(f);
702 }
RZ_API RzList * rz_flag_all_list(RzFlag *f, bool by_space)
Definition: flag.c:463

References f, flags, rz_flag_all_list(), rz_flag_unset(), and rz_list_free().

Referenced by rz_analysis_all_esil_functions_handler(), rz_analysis_all_esil_handler(), rz_core_debug_map_update_flags(), rz_platform_index_add_flags_comments(), and rz_platform_profile_add_flag_every_io().

◆ rz_flag_unset_all_off()

RZ_API bool rz_flag_unset_all_off ( RzFlag f,
ut64  off 
)

Definition at line 635 of file flag.c.

635  {
636  rz_return_val_if_fail(f, false);
637  struct unset_off_foreach_t u = { f, off };
638  ht_pp_foreach(f->ht_name, unset_off_foreach, &u);
639  return true;
640 }
static bool unset_off_foreach(void *user, const void *k, const void *v)
Definition: flag.c:622

References f, off, rz_return_val_if_fail, and unset_off_foreach().

Referenced by recover_string_at(), and rz_flag_remove_handler().

◆ rz_flag_unset_glob()

RZ_API int rz_flag_unset_glob ( RzFlag f,
const char *  glob 
)

Definition at line 660 of file flag.c.

660  {
662 
663  struct unset_foreach_t u = { .f = f, .n = 0 };
665  return u.n;
666 }
static bool unset_foreach(RzFlagItem *fi, void *user)
Definition: flag.c:647
RzFlag * f
Definition: flag.c:643

References unset_foreach_t::f, f, unset_foreach_t::n, rz_flag_foreach_glob(), rz_return_val_if_fail, and unset_foreach().

Referenced by rz_flag_remove_handler().

◆ rz_flag_unset_name()

RZ_API bool rz_flag_unset_name ( RzFlag f,
const char *  name 
)

Definition at line 670 of file flag.c.

670  {
671  rz_return_val_if_fail(f, false);
672  RzFlagItem *item = ht_pp_find(f->ht_name, name, NULL);
673  return item && rz_flag_unset(f, item);
674 }

References f, NULL, rz_flag_unset(), and rz_return_val_if_fail.

Referenced by foreach_reg_set_or_clear(), function_rename(), rz_core_analysis_esil_init_mem_del(), rz_core_analysis_undefine(), rz_core_visual_cmd(), rz_core_visual_trackflags(), and rz_flag_bind().

◆ rz_flag_unset_off()

RZ_API bool rz_flag_unset_off ( RzFlag f,
ut64  off 
)

Definition at line 608 of file flag.c.

608  {
609  rz_return_val_if_fail(f, false);
610  RzFlagItem *item = rz_flag_get_i(f, off);
611  if (item && rz_flag_unset(f, item)) {
612  return true;
613  }
614  return false;
615 }

References f, off, rz_flag_get_i(), rz_flag_unset(), and rz_return_val_if_fail.

Referenced by rz_analysis_dwarf_integrate_functions(), rz_core_visual_cmd(), and rz_flag_bind().

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_flag  )

◆ set_name()

static void set_name ( RzFlagItem item,
char *  name 
)
static

Definition at line 136 of file flag.c.

136  {
137  free_item_name(item);
138  item->name = name;
139  free_item_realname(item);
140  item->realname = item->name;
141 }
const char * name
Definition: op.c:541

References free_item_name(), free_item_realname(), name, rz_flag_item_t::name, and rz_flag_item_t::realname.

Referenced by update_flag_item_name().

◆ str_callback()

static const char* str_callback ( RzNum user,
ut64  off,
int ok 
)
static

Definition at line 16 of file flag.c.

16  {
17  RzFlag *f = (RzFlag *)user;
18  if (ok) {
19  *ok = 0;
20  }
21  if (f) {
22  const RzList *list = rz_flag_get_list(f, off);
24  if (item) {
25  if (ok) {
26  *ok = true;
27  }
28  return item->name;
29  }
30  }
31  return NULL;
32 }

References f, list(), rz_flag_item_t::name, NULL, off, ok, rz_flag_get_list(), and rz_list_get_top().

Referenced by rz_flag_new().

◆ unset_flags_space()

static bool unset_flags_space ( RzFlagItem fi,
void *  user 
)
static

Definition at line 195 of file flag.c.

195  {
196  fi->space = NULL;
197  return true;
198 }

References NULL, and rz_flag_item_t::space.

Referenced by unset_flagspace().

◆ unset_flagspace()

static void unset_flagspace ( RzEvent ev,
int  type,
void *  user,
void *  data 
)
static

Definition at line 207 of file flag.c.

207  {
208  RzSpaces *sp = (RzSpaces *)ev->user;
210  const RzSpaceEvent *spe = (const RzSpaceEvent *)data;
212 }
static bool unset_flags_space(RzFlagItem *fi, void *user)
Definition: flag.c:195
struct rz_space_event_t::@311::@313 unset

References container_of, rz_space_event_t::data, f, NULL, rz_flag_foreach_space(), sp, spaces(), rz_space_event_t::unset, unset_flags_space(), and rz_event_t::user.

Referenced by new_spaces().

◆ unset_foreach()

static bool unset_foreach ( RzFlagItem fi,
void *  user 
)
static

Definition at line 647 of file flag.c.

647  {
648  struct unset_foreach_t *u = (struct unset_foreach_t *)user;
649  if (IS_FI_NOTIN_SPACE(u->f, fi)) {
650  return true;
651  }
652  rz_flag_unset(u->f, fi);
653  u->n++;
654  return true;
655 }

References unset_foreach_t::f, IS_FI_NOTIN_SPACE, unset_foreach_t::n, and rz_flag_unset().

Referenced by rz_flag_unset_glob().

◆ unset_off_foreach()

static bool unset_off_foreach ( void *  user,
const void *  k,
const void *  v 
)
static

Definition at line 622 of file flag.c.

622  {
623  struct unset_off_foreach_t *u = (struct unset_off_foreach_t *)user;
624  RzFlagItem *fi = (RzFlagItem *)v;
625  if (u->offset == fi->offset) {
626  rz_flag_unset(u->f, fi);
627  }
628  return true;
629 }
const char * v
Definition: dsignal.c:12
RzFlag * f
Definition: flag.c:618

References unset_off_foreach_t::f, unset_off_foreach_t::offset, rz_flag_item_t::offset, rz_flag_unset(), and v.

Referenced by rz_flag_unset_all_off().

◆ update_flag_item_name()

static bool update_flag_item_name ( RzFlag f,
RzFlagItem item,
const char *  newname,
bool  force 
)
static

Definition at line 162 of file flag.c.

162  {
163  if (!f || !item || !newname) {
164  return false;
165  }
166  if (!force && (item->name == newname || (item->name && !strcmp(item->name, newname)))) {
167  return false;
168  }
169  char *fname = filter_item_name(newname);
170  if (!fname) {
171  return false;
172  }
173  bool res = (item->name)
174  ? ht_pp_update_key(f->ht_name, item->name, fname)
175  : ht_pp_insert(f->ht_name, fname, item);
176  if (res) {
177  set_name(item, fname);
178  return true;
179  }
180  free(fname);
181  return false;
182 }
static void set_name(RzFlagItem *item, char *name)
Definition: flag.c:136

References f, filter_item_name(), create_tags_rz::fname, free(), rz_flag_item_t::name, and set_name().

Referenced by rz_flag_rename(), and rz_flag_set().

◆ update_flag_item_offset()

static bool update_flag_item_offset ( RzFlag f,
RzFlagItem item,
ut64  newoff,
bool  is_new,
bool  force 
)
static

Definition at line 143 of file flag.c.

143  {
144  if (item->offset != newoff || force) {
145  if (!is_new) {
146  remove_offsetmap(f, item);
147  }
148  item->offset = newoff;
149 
150  RzFlagsAtOffset *flagsAtOffset = flags_at_offset(f, newoff);
151  if (!flagsAtOffset) {
152  return false;
153  }
154 
155  rz_list_append(flagsAtOffset->flags, item);
156  return true;
157  }
158 
159  return false;
160 }
static RzFlagsAtOffset * flags_at_offset(RzFlag *f, ut64 off)
Definition: flag.c:102

References f, rz_flags_at_offset_t::flags, flags_at_offset(), rz_flag_item_t::offset, remove_offsetmap(), and rz_list_append().

Referenced by flag_relocate_foreach(), and rz_flag_set().