2014-03-27 16:34:17 +01:00
|
|
|
#ifndef R2_FLAGS_H
|
|
|
|
#define R2_FLAGS_H
|
2009-02-05 22:08:46 +01:00
|
|
|
|
|
|
|
#include <r_types.h>
|
2011-05-21 21:05:21 +02:00
|
|
|
#include <r_util.h>
|
2010-12-24 00:51:01 +01:00
|
|
|
#include <r_list.h>
|
2017-07-10 22:42:15 +03:00
|
|
|
#include <r_skiplist.h>
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2013-06-18 12:09:23 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-10-27 01:02:26 +02:00
|
|
|
// TODO: rename to r_flag_XXX api
|
2013-06-14 02:51:33 +02:00
|
|
|
R_LIB_VERSION_HEADER(r_flag);
|
|
|
|
|
2015-04-11 04:33:37 +02:00
|
|
|
#define R_FLAG_NAME_SIZE 512
|
2015-11-08 23:38:42 +01:00
|
|
|
#define R_FLAG_SPACES_MAX 128
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2016-10-06 02:40:26 +02:00
|
|
|
/* zones.c */
|
|
|
|
|
|
|
|
#define R_FLAG_ZONE_USE_SDB 0
|
|
|
|
|
|
|
|
typedef struct r_flag_zone_item_t {
|
|
|
|
ut64 from;
|
|
|
|
ut64 to;
|
|
|
|
#if R_FLAG_ZONE_USE_SDB
|
|
|
|
const char *name;
|
|
|
|
#else
|
|
|
|
char *name;
|
|
|
|
#endif
|
|
|
|
} RFlagZoneItem;
|
|
|
|
|
|
|
|
/* flag.c */
|
|
|
|
|
2017-07-10 22:42:15 +03:00
|
|
|
typedef struct r_flags_at_offset_t {
|
|
|
|
ut64 off;
|
|
|
|
RList *flags; /* list of RFlagItem at offset */
|
|
|
|
} RFlagsAtOffset;
|
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
typedef struct r_flag_item_t {
|
2016-02-22 10:18:08 +01:00
|
|
|
char *name; /* unique name, escaped to avoid issues with r2 shell */
|
|
|
|
char *realname; /* real name, without any escaping */
|
|
|
|
ut64 offset; /* offset flagged by this item */
|
|
|
|
ut64 size; /* size of the flag item */
|
|
|
|
int space; /* flag space this item belongs to */
|
|
|
|
char *color; /* item color */
|
|
|
|
char *comment; /* item comment */
|
|
|
|
char *alias; /* used to define a flag based on a math expression (e.g. foo + 3) */
|
2010-01-26 01:28:33 +01:00
|
|
|
} RFlagItem;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
typedef struct r_flag_t {
|
2016-02-22 10:18:08 +01:00
|
|
|
st64 base; /* base address for all flag items */
|
|
|
|
int space_idx; /* index of the selected space in spaces array */
|
|
|
|
bool space_strict; /* when true returned flag items must belong to the selected space */
|
|
|
|
char *spaces[R_FLAG_SPACES_MAX]; /* array of flag spaces */
|
2014-09-01 02:24:38 +02:00
|
|
|
RNum *num;
|
2017-07-10 22:42:15 +03:00
|
|
|
RSkipList *by_off; /* flags sorted by offset, value=RFlagsAtOffset */
|
2017-02-12 16:58:41 +01:00
|
|
|
SdbHash *ht_name; /* hashmap key=item name, value=RList of items */
|
2016-02-22 10:18:08 +01:00
|
|
|
RList *flags; /* list of RFlagItem contained in the flag */
|
2015-04-03 20:38:34 +02:00
|
|
|
RList *spacestack;
|
2016-08-16 00:59:31 +02:00
|
|
|
PrintfCallback cb_printf;
|
2016-10-06 02:40:26 +02:00
|
|
|
#if R_FLAG_ZONE_USE_SDB
|
|
|
|
Sdb *zones;
|
|
|
|
#else
|
|
|
|
RList *zones;
|
|
|
|
#endif
|
2010-01-26 01:28:33 +01:00
|
|
|
} RFlag;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2014-09-26 14:24:33 +02:00
|
|
|
/* compile time dependency */
|
|
|
|
|
2016-09-05 20:42:04 +02:00
|
|
|
typedef bool (*RFlagExistAt)(RFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off);
|
2014-09-26 14:24:33 +02:00
|
|
|
typedef RFlagItem* (*RFlagGet)(RFlag *f, const char *name);
|
2016-12-01 10:48:00 +01:00
|
|
|
typedef RFlagItem* (*RFlagGetAt)(RFlag *f, ut64 addr, bool closest);
|
2016-02-20 15:38:46 +01:00
|
|
|
typedef RFlagItem* (*RFlagSet)(RFlag *f, const char *name, ut64 addr, ut32 size);
|
2014-09-26 14:24:33 +02:00
|
|
|
typedef int (*RFlagSetSpace)(RFlag *f, const char *name);
|
|
|
|
|
|
|
|
typedef struct r_flag_bind_t {
|
|
|
|
int init;
|
|
|
|
RFlag *f;
|
2016-09-05 20:42:04 +02:00
|
|
|
RFlagExistAt exist_at;
|
2014-09-26 14:24:33 +02:00
|
|
|
RFlagGet get;
|
2015-11-12 13:47:44 +01:00
|
|
|
RFlagGetAt get_at;
|
2014-09-26 14:24:33 +02:00
|
|
|
RFlagSet set;
|
|
|
|
RFlagSetSpace set_fs;
|
|
|
|
} RFlagBind;
|
|
|
|
|
|
|
|
#define r_flag_bind_init(x) memset(&x,0,sizeof(x))
|
|
|
|
R_API int r_flag_bind(RFlag *io, RFlagBind *bnd);
|
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
#ifdef R_API
|
2015-01-13 03:40:01 +01:00
|
|
|
R_API RFlag * r_flag_new(void);
|
2010-04-09 17:13:35 +02:00
|
|
|
R_API RFlag * r_flag_free(RFlag *f);
|
2015-05-07 12:12:55 +02:00
|
|
|
R_API void r_flag_list(RFlag *f, int rad, const char *pfx);
|
2016-09-05 20:42:04 +02:00
|
|
|
R_API bool r_flag_exist_at(RFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off);
|
2010-04-09 17:13:35 +02:00
|
|
|
R_API RFlagItem *r_flag_get(RFlag *f, const char *name);
|
|
|
|
R_API RFlagItem *r_flag_get_i(RFlag *f, ut64 off);
|
2013-09-03 22:45:43 +02:00
|
|
|
R_API RFlagItem *r_flag_get_i2(RFlag *f, ut64 off);
|
2016-12-01 10:48:00 +01:00
|
|
|
R_API RFlagItem *r_flag_get_at(RFlag *f, ut64 off, bool closest);
|
2014-11-20 01:14:47 +01:00
|
|
|
R_API const RList* /*<RFlagItem*>*/ r_flag_get_list(RFlag *f, ut64 off);
|
2015-01-17 01:56:20 +01:00
|
|
|
R_API char *r_flag_get_liststr(RFlag *f, ut64 off);
|
2016-02-20 15:25:27 +01:00
|
|
|
R_API int r_flag_unset(RFlag *f, RFlagItem *item);
|
|
|
|
R_API int r_flag_unset_name(RFlag *f, const char *name);
|
|
|
|
R_API int r_flag_unset_off(RFlag *f, ut64 addr);
|
2015-01-22 02:22:29 +01:00
|
|
|
R_API void r_flag_unset_all (RFlag *f);
|
2016-02-20 15:38:46 +01:00
|
|
|
R_API RFlagItem *r_flag_set(RFlag *fo, const char *name, ut64 addr, ut32 size);
|
2016-11-15 12:55:09 +01:00
|
|
|
R_API RFlagItem *r_flag_set_next(RFlag *fo, const char *name, ut64 addr, ut32 size);
|
2010-04-09 11:32:17 +02:00
|
|
|
R_API int r_flag_sort(RFlag *f, int namesort);
|
2014-09-01 02:24:38 +02:00
|
|
|
R_API void r_flag_item_set_alias(RFlagItem *item, const char *alias);
|
2012-10-26 10:00:22 +02:00
|
|
|
R_API void r_flag_item_free (RFlagItem *item);
|
|
|
|
R_API void r_flag_item_set_comment(RFlagItem *item, const char *comment);
|
2016-02-21 13:05:40 +01:00
|
|
|
R_API void r_flag_item_set_realname(RFlagItem *item, const char *realname);
|
2011-05-21 21:05:21 +02:00
|
|
|
R_API int r_flag_unset_glob(RFlag *f, const char *name);
|
|
|
|
R_API int r_flag_rename(RFlag *f, RFlagItem *item, const char *name);
|
2013-08-29 03:19:16 +02:00
|
|
|
R_API int r_flag_relocate (RFlag *f, ut64 off, ut64 off_mask, ut64 to);
|
2014-03-02 05:41:45 +01:00
|
|
|
R_API int r_flag_move (RFlag *f, ut64 at, ut64 to);
|
2014-08-19 01:47:02 +02:00
|
|
|
R_API const char *r_flag_color(RFlag *f, RFlagItem *it, const char *color);
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2009-02-17 10:59:26 +01:00
|
|
|
/* spaces */
|
2011-02-17 01:34:29 +01:00
|
|
|
R_API int r_flag_space_get(RFlag *f, const char *name);
|
2011-02-17 00:58:54 +01:00
|
|
|
R_API const char *r_flag_space_get_i(RFlag *f, int idx);
|
2015-07-17 11:10:28 +02:00
|
|
|
R_API const char *r_flag_space_cur(RFlag *f);
|
2014-09-26 14:24:33 +02:00
|
|
|
R_API int r_flag_space_set(RFlag *f, const char *name);
|
2016-03-29 00:39:50 +02:00
|
|
|
R_API int r_flag_count (RFlag *f, const char *name);
|
2015-01-22 02:22:29 +01:00
|
|
|
R_API int r_flag_space_unset (RFlag *f, const char *fs);
|
2013-01-17 03:29:46 +01:00
|
|
|
R_API int r_flag_space_list(RFlag *f, int mode);
|
2013-03-07 23:47:41 +01:00
|
|
|
R_API int r_flag_space_rename (RFlag *f, const char *oname, const char *nname);
|
2015-04-03 20:38:34 +02:00
|
|
|
R_API int r_flag_space_pop(RFlag *f);
|
|
|
|
R_API int r_flag_space_push(RFlag *f, const char *name);
|
2017-05-02 05:46:43 +02:00
|
|
|
R_API int r_flag_space_stack_list(RFlag *f, int mode);
|
2016-10-06 02:40:26 +02:00
|
|
|
|
|
|
|
/* zones */
|
|
|
|
|
|
|
|
R_API void r_flag_zone_item_free(void *a);
|
|
|
|
R_API bool r_flag_zone_add(RFlag *fz, const char *name, ut64 addr);
|
|
|
|
R_API bool r_flag_zone_del(RFlag *fz, const char *name);
|
|
|
|
R_API bool r_flag_zone_around(RFlag *fz, ut64 addr, const char **prev, const char **next);
|
|
|
|
R_API bool r_flag_zone_list(RFlag *fz, int mode);
|
|
|
|
R_API bool r_flag_zone_reset(RFlag *f);
|
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
#endif
|
2009-02-17 10:59:26 +01:00
|
|
|
|
2013-06-18 12:09:23 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-05 22:08:46 +01:00
|
|
|
#endif
|