Rizin
unix-like reverse engineering framework and cli tools
rz_flag.h
Go to the documentation of this file.
1 #ifndef RZ_FLAGS_H
2 #define RZ_FLAGS_H
3 
4 #include <rz_types.h>
5 #include <rz_util.h>
6 #include <rz_list.h>
7 #include <rz_skiplist.h>
8 #include <rz_util/rz_serialize.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 // TODO: rename to rz_flag_XXX api
16 
17 #define RZ_FLAG_NAME_SIZE 512
18 
19 /* zones.c */
20 
21 typedef struct rz_flag_zone_item_t {
24  char *name;
26 
27 /* flag.c */
28 
29 typedef struct rz_flags_at_offset_t {
31  RzList *flags; /* list of RzFlagItem at offset */
33 
34 typedef struct rz_flag_item_t {
35  char *name; /* unique name, escaped to avoid issues with rizin shell */
36  char *realname; /* real name, without any escaping */
37  bool demangled; /* real name from demangling? */
38  ut64 offset; /* offset flagged by this item */
39  ut64 size; /* size of the flag item */
40  RzSpace *space; /* flag space this item belongs to */
41  char *color; /* item color */
42  char *comment; /* item comment */
43  char *alias; /* used to define a flag based on a math expression (e.g. foo + 3) */
45 
46 typedef struct rz_flag_t {
47  RzSpaces spaces; /* handle flag spaces */
48  st64 base; /* base address for all flag items */
49  bool realnames;
52  RzSkipList *by_off; /* flags sorted by offset, value=RzFlagsAtOffset */
53  HtPP *ht_name; /* hashmap key=item name, value=RzFlagItem * */
54  RzList /*<RzFlagZoneItem *>*/ *zones;
56 
57 /* compile time dependency */
58 
59 typedef bool (*RzFlagExistAt)(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off);
60 typedef RzFlagItem *(*RzFlagGet)(RzFlag *f, const char *name);
61 typedef RzFlagItem *(*RzFlagGetAtAddr)(RzFlag *f, ut64);
62 typedef RzFlagItem *(*RzFlagGetAt)(RzFlag *f, ut64 addr, bool closest);
63 typedef RzFlagItem *(*RzFlagGetAtBySpaces)(RzFlag *f, ut64 off, ...);
64 typedef const RzList /*<RzFlagItem *>*/ *(*RzFlagGetList)(RzFlag *f, ut64 addr);
65 typedef RzFlagItem *(*RzFlagSet)(RzFlag *f, const char *name, ut64 addr, ut32 size);
66 typedef bool (*RzFlagUnset)(RzFlag *f, RzFlagItem *item);
67 typedef bool (*RzFlagUnsetName)(RzFlag *f, const char *name);
69 typedef RzSpace *(*RzFlagSetSpace)(RzFlag *f, const char *name);
70 typedef bool (*RzFlagPopSpace)(RzFlag *f);
71 typedef bool (*RzFlagPushSpace)(RzFlag *f, const char *name);
72 typedef int (*RzFlagRename)(RzFlag *f, RzFlagItem *item, const char *name);
73 
74 typedef bool (*RzFlagItemCb)(RzFlagItem *fi, void *user);
75 
76 typedef struct rz_flag_bind_t {
77  int init;
93 
94 #define rz_flag_bind_init(x) memset(&x, 0, sizeof(x))
95 RZ_API void rz_flag_bind(RzFlag *io, RzFlagBind *bnd);
96 
97 #ifdef RZ_API
100 RZ_API bool rz_flag_exist_at(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off);
101 RZ_API RzFlagItem *rz_flag_get(RzFlag *f, const char *name);
104 RZ_API RzFlagItem *rz_flag_get_at(RzFlag *f, ut64 off, bool closest);
105 RZ_API RzList /*<RzFlagItem *>*/ *rz_flag_all_list(RzFlag *f, bool by_space);
106 RZ_API const RzList /*<RzFlagItem *>*/ *rz_flag_get_list(RzFlag *f, ut64 off);
108 RZ_API bool rz_flag_unset(RzFlag *f, RzFlagItem *item);
109 RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name);
113 RZ_API void rz_flag_unset_all_in_space(RzFlag *f, const char *space_name);
114 RZ_API RzFlagItem *rz_flag_set(RzFlag *fo, const char *name, ut64 addr, ut32 size);
116 RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias);
118 RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment);
119 RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname);
120 RZ_API const char *rz_flag_item_set_color(RzFlagItem *item, const char *color);
122 RZ_API int rz_flag_unset_glob(RzFlag *f, const char *name);
123 RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name);
124 RZ_API int rz_flag_relocate(RzFlag *f, ut64 off, ut64 off_mask, ut64 to);
125 RZ_API bool rz_flag_move(RzFlag *f, ut64 at, ut64 to);
126 RZ_API int rz_flag_count(RzFlag *f, const char *glob);
127 RZ_API void rz_flag_foreach(RzFlag *f, RzFlagItemCb cb, void *user);
128 RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user);
130 RZ_API void rz_flag_foreach_glob(RzFlag *f, const char *glob, RzFlagItemCb cb, void *user);
131 RZ_API void rz_flag_foreach_space(RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user);
132 RZ_API void rz_flag_foreach_space_glob(RzFlag *f, const char *glob, const RzSpace *space, RzFlagItemCb cb, void *user);
133 
134 /* spaces */
135 static inline RzSpace *rz_flag_space_get(RzFlag *f, const char *name) {
136  return rz_spaces_get(&f->spaces, name);
137 }
138 
139 static inline RzSpace *rz_flag_space_cur(RzFlag *f) {
140  return rz_spaces_current(&f->spaces);
141 }
142 
143 static inline const char *rz_flag_space_cur_name(RzFlag *f) {
144  return rz_spaces_current_name(&f->spaces);
145 }
146 
147 static inline RzSpace *rz_flag_space_set(RzFlag *f, const char *name) {
148  return rz_spaces_set(&f->spaces, name);
149 }
150 
151 static inline bool rz_flag_space_unset(RzFlag *f, const char *name) {
152  return rz_spaces_unset(&f->spaces, name);
153 }
154 
155 static inline bool rz_flag_space_rename(RzFlag *f, const char *oname, const char *nname) {
156  return rz_spaces_rename(&f->spaces, oname, nname);
157 }
158 
159 static inline bool rz_flag_space_push(RzFlag *f, const char *name) {
160  return rz_spaces_push(&f->spaces, name);
161 }
162 
163 static inline bool rz_flag_space_pop(RzFlag *f) {
164  return rz_spaces_pop(&f->spaces);
165 }
166 
167 static inline int rz_flag_space_count(RzFlag *f, const char *name) {
168  return rz_spaces_count(&f->spaces, name);
169 }
170 
171 static inline bool rz_flag_space_is_empty(RzFlag *f) {
172  return rz_spaces_is_empty(&f->spaces);
173 }
174 
175 #define rz_flag_space_foreach(f, it, s) rz_spaces_foreach(&(f)->spaces, (it), (s))
176 
177 /* tags */
178 RZ_API RZ_OWN RzList /*<char *>*/ *rz_flag_tags_list(RzFlag *f);
179 RZ_API void rz_flag_tags_set(RzFlag *f, const char *name, const char *words);
180 RZ_API void rz_flag_tags_reset(RzFlag *f, const char *name);
181 RZ_API RzList /*<RzFlagItem *>*/ *rz_flag_tags_get(RzFlag *f, const char *name);
182 
183 /* zones */
184 
185 RZ_API void rz_flag_zone_item_free(void *a);
186 RZ_API bool rz_flag_zone_add(RzFlag *fz, const char *name, ut64 addr);
187 RZ_API bool rz_flag_zone_del(RzFlag *fz, const char *name);
188 RZ_API bool rz_flag_zone_around(RzFlag *fz, ut64 addr, const char **prev, const char **next);
190 RZ_API RzList /*<char *>*/ *rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows);
191 
192 /* serialize */
193 
194 RZ_API void rz_serialize_flag_zones_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzList /*<RzFlagZoneItem *>*/ *zones);
198 
199 #endif
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif
#define RZ_API
uint16_t ut16
uint32_t ut32
RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name)
Definition: flag.c:587
RZ_API RzFlagItem * rz_flag_get_i(RzFlag *f, ut64 off)
Definition: flag.c:317
RZ_API void rz_flag_foreach_space_glob(RzFlag *f, const char *glob, const RzSpace *space, RzFlagItemCb cb, void *user)
Definition: flag.c:822
RZ_API RzFlagItem * rz_flag_item_clone(RzFlagItem *item)
Definition: flag.c:240
RZ_API RzFlag * rz_flag_free(RzFlag *f)
Definition: flag.c:271
RZ_API int rz_flag_count(RzFlag *f, const char *glob)
Definition: flag.c:776
RZ_API void rz_flag_item_free(RzFlagItem *item)
Definition: flag.c:258
RZ_API void rz_flag_foreach_range(RZ_NONNULL RzFlag *f, ut64 from, ut64 to, RzFlagItemCb cb, void *user)
Definition: flag.c:813
RZ_API const char * rz_flag_item_set_color(RzFlagItem *item, const char *color)
Definition: flag.c:578
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.
Definition: flag.c:692
RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment)
Definition: flag.c:564
RZ_API RzFlagItem * rz_flag_set_next(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:494
RZ_API const RzList * rz_flag_get_list(RzFlag *f, ut64 off)
Definition: flag.c:475
RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user)
Definition: flag.c:804
RZ_API bool rz_flag_unset_all_off(RzFlag *f, ut64 off)
Definition: flag.c:635
RZ_API RzList * rz_flag_all_list(RzFlag *f, bool by_space)
Definition: flag.c:463
RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias)
Definition: flag.c:557
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
RZ_API char * rz_flag_get_liststr(RzFlag *f, ut64 off)
Definition: flag.c:480
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 void rz_flag_unset_all(RzFlag *f)
Definition: flag.c:677
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 bool rz_flag_move(RzFlag *f, ut64 at, ut64 to)
Definition: flag.c:741
RZ_API RzFlagItem * rz_flag_get_by_spaces(RzFlag *f, ut64 off,...)
Definition: flag.c:326
RZ_API int rz_flag_unset_glob(RzFlag *f, const char *glob)
Definition: flag.c:660
RZ_API void rz_flag_foreach_space(RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user)
Definition: flag.c:826
RZ_API int rz_flag_relocate(RzFlag *f, ut64 off, ut64 off_mask, ut64 to)
Definition: flag.c:726
RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname)
Definition: flag.c:571
RZ_API RzFlag * rz_flag_new(void)
Definition: flag.c:220
RZ_API void rz_flag_foreach_glob(RzFlag *f, const char *glob, RzFlagItemCb cb, void *user)
Definition: flag.c:818
RZ_API bool rz_flag_unset_off(RzFlag *f, ut64 off)
Definition: flag.c:608
RZ_API void rz_flag_foreach(RzFlag *f, RzFlagItemCb cb, void *user)
Definition: flag.c:800
voidpf void uLong size
Definition: ioapi.h:138
const char * name
Definition: op.c:541
int off
Definition: pal.c:13
RzFlagItem *(* RzFlagGetAtBySpaces)(RzFlag *f, ut64 off,...)
Definition: rz_flag.h:63
RzFlagItem *(* RzFlagSet)(RzFlag *f, const char *name, ut64 addr, ut32 size)
Definition: rz_flag.h:65
RZ_LIB_VERSION_HEADER(rz_flag)
const RzList *(* RzFlagGetList)(RzFlag *f, ut64 addr)
Definition: rz_flag.h:64
struct rz_flag_t RzFlag
bool(* RzFlagItemCb)(RzFlagItem *fi, void *user)
Definition: rz_flag.h:74
int(* RzFlagRename)(RzFlag *f, RzFlagItem *item, const char *name)
Definition: rz_flag.h:72
bool(* RzFlagPushSpace)(RzFlag *f, const char *name)
Definition: rz_flag.h:71
struct rz_flag_zone_item_t RzFlagZoneItem
bool(* RzFlagUnset)(RzFlag *f, RzFlagItem *item)
Definition: rz_flag.h:66
RzFlagItem *(* RzFlagGet)(RzFlag *f, const char *name)
Definition: rz_flag.h:60
bool(* RzFlagUnsetName)(RzFlag *f, const char *name)
Definition: rz_flag.h:67
RZ_API void rz_flag_bind(RzFlag *io, RzFlagBind *bnd)
Definition: flag.c:752
struct rz_flag_item_t RzFlagItem
RzFlagItem *(* RzFlagGetAt)(RzFlag *f, ut64 addr, bool closest)
Definition: rz_flag.h:62
bool(* RzFlagUnsetOff)(RzFlag *f, ut64 addr)
Definition: rz_flag.h:68
bool(* RzFlagPopSpace)(RzFlag *f)
Definition: rz_flag.h:70
RzSpace *(* RzFlagSetSpace)(RzFlag *f, const char *name)
Definition: rz_flag.h:69
struct rz_flag_bind_t RzFlagBind
bool(* RzFlagExistAt)(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off)
Definition: rz_flag.h:59
struct rz_flags_at_offset_t RzFlagsAtOffset
RZ_API RzSpace * rz_spaces_get(RzSpaces *sp, const char *name)
Definition: spaces.c:82
RZ_API bool rz_spaces_push(RzSpaces *sp, const char *name)
Definition: spaces.c:177
RZ_API RzSpace * rz_spaces_set(RzSpaces *sp, const char *name)
Definition: spaces.c:122
static const char * rz_spaces_current_name(RzSpaces *sp)
Definition: rz_spaces.h:95
RZ_API int rz_spaces_count(RzSpaces *sp, const char *name)
Definition: spaces.c:167
RZ_API bool rz_spaces_pop(RzSpaces *sp)
Definition: spaces.c:185
static bool rz_spaces_is_empty(RzSpaces *sp)
Definition: rz_spaces.h:99
static RzSpace * rz_spaces_current(RzSpaces *sp)
Definition: rz_spaces.h:91
RZ_API bool rz_spaces_rename(RzSpaces *sp, const char *oname, const char *nname)
Definition: spaces.c:196
RZ_API bool rz_spaces_unset(RzSpaces *sp, const char *name)
Definition: spaces.c:141
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define st64
Definition: rz_types_base.h:10
RZ_API bool rz_serialize_flag_zones_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzList *zones, RZ_NULLABLE RzSerializeResultInfo *res)
RZ_API void rz_serialize_flag_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzFlag *flag)
RZ_API bool rz_serialize_flag_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzFlag *flag, RZ_NULLABLE RzSerializeResultInfo *res)
RZ_API void rz_serialize_flag_zones_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzList *zones)
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
static int
Definition: sfsocketcall.h:114
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
Definition: z80asm.h:102
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
RzSpace * space
Definition: rz_flag.h:40
char * color
Definition: rz_flag.h:41
char * alias
Definition: rz_flag.h:43
ut64 offset
Definition: rz_flag.h:38
char * comment
Definition: rz_flag.h:42
char * realname
Definition: rz_flag.h:36
char * name
Definition: rz_flag.h:35
bool demangled
Definition: rz_flag.h:37
HtPP * ht_name
Definition: rz_flag.h:53
RzList * zones
Definition: rz_flag.h:54
RzSkipList * by_off
Definition: rz_flag.h:52
bool realnames
Definition: rz_flag.h:49
RzNum * num
Definition: rz_flag.h:51
RzSpaces spaces
Definition: rz_flag.h:47
Sdb * tags
Definition: rz_flag.h:50
st64 base
Definition: rz_flag.h:48
RzList * flags
Definition: rz_flag.h:31
Definition: sdb.h:63
#define bool
Definition: sysdefs.h:146
RZ_API void rz_flag_tags_set(RzFlag *f, const char *name, const char *words)
Definition: tags.c:6
RZ_API void rz_flag_tags_reset(RzFlag *f, const char *name)
Definition: tags.c:29
RZ_API RzList * rz_flag_tags_get(RzFlag *f, const char *name)
Definition: tags.c:53
RZ_API RZ_OWN RzList * rz_flag_tags_list(RzFlag *f)
Definition: tags.c:12
static int color
Definition: visual.c:20
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const char * cb[]
Definition: z80_tab.h:176
static int addr
Definition: z80asm.c:58
RZ_API bool rz_flag_zone_reset(RzFlag *f)
Definition: zones.c:51
RZ_API bool rz_flag_zone_around(RzFlag *f, ut64 addr, const char **prev, const char **next)
Definition: zones.c:75
RZ_API RzList * rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows)
Definition: zones.c:130
RZ_API bool rz_flag_zone_del(RzFlag *f, const char *name)
Definition: zones.c:57
RZ_API bool rz_flag_zone_add(RzFlag *f, const char *name, ut64 addr)
Definition: zones.c:29
RZ_API void rz_flag_zone_item_free(void *a)
Definition: zones.c:69