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

Go to the source code of this file.

Classes

struct  print_flag_t
 
struct  FlagTableData
 

Functions

static bool print_flag_name (RzFlagItem *fi, void *user)
 
static bool print_flag_json (RzFlagItem *flag, void *user)
 
static bool print_flag_rizin (RzFlagItem *flag, void *user)
 
static bool print_flag_orig_name (RzFlagItem *flag, void *user)
 
static bool __tableItemCallback (RzFlagItem *flag, void *user)
 
static void flag_print (RzFlag *f, RzCmdStateOutput *state, ut64 range_from, ut64 range_to, bool in_range)
 
RZ_IPI void rz_core_flag_print (RzFlag *f, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_flag_real_name_print (RzFlag *f, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_flag_range_print (RzFlag *f, RzCmdStateOutput *state, ut64 range_from, ut64 range_to)
 

Function Documentation

◆ __tableItemCallback()

static bool __tableItemCallback ( RzFlagItem flag,
void *  user 
)
static

Definition at line 102 of file cflag.c.

102  {
103  FlagTableData *ftd = user;
104  if (!RZ_STR_ISEMPTY(flag->name)) {
105  RzTable *t = ftd->t;
106  const char *spaceName = (flag->space && flag->space->name) ? flag->space->name : "";
107  rz_table_add_rowf(t, "Xdss", flag->offset, flag->size, spaceName, flag->name);
108  }
109  return true;
110 }
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
RzTable * t
Definition: cflag.c:99
RzSpace * space
Definition: rz_flag.h:40
ut64 offset
Definition: rz_flag.h:38
char * name
Definition: rz_flag.h:35
char * name
Definition: rz_spaces.h:29

References rz_flag_item_t::name, rz_space_t::name, rz_flag_item_t::offset, RZ_STR_ISEMPTY, rz_table_add_rowf(), rz_flag_item_t::size, rz_flag_item_t::space, and FlagTableData::t.

Referenced by flag_print().

◆ flag_print()

static void flag_print ( RzFlag f,
RzCmdStateOutput state,
ut64  range_from,
ut64  range_to,
bool  in_range 
)
static

Definition at line 112 of file cflag.c.

112  {
114  switch (state->mode) {
116  rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_name, f);
117  break;
119  struct print_flag_t u = {
120  .f = f,
121  .in_range = in_range,
122  .range_from = range_from,
123  .range_to = range_to,
124  .real = false
125  };
126  rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_orig_name, &u);
127  break;
128  }
129  case RZ_OUTPUT_MODE_JSON: {
130  struct print_flag_t u = {
131  .f = f,
132  .pj = state->d.pj,
133  .in_range = in_range,
134  .range_from = range_from,
135  .range_to = range_to,
136  .real = false
137  };
138  pj_a(state->d.pj);
139  rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_json, &u);
140  pj_end(state->d.pj);
141  break;
142  }
143  case RZ_OUTPUT_MODE_RIZIN: {
144  struct print_flag_t u = {
145  .f = f,
146  .in_range = in_range,
147  .range_from = range_from,
148  .range_to = range_to,
149  .fs = NULL,
150  };
151  rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_rizin, &u);
152  break;
153  }
154  case RZ_OUTPUT_MODE_TABLE: {
155  FlagTableData ftd = { 0 };
156  ftd.t = state->d.t;
157  rz_cmd_state_output_set_columnsf(state, "Xdss", "addr", "size", "space", "name");
158 
159  RzSpace *curSpace = rz_flag_space_cur(f);
160  rz_flag_foreach_space(f, curSpace, __tableItemCallback, &ftd);
161  break;
162  }
163  default:
165  break;
166  }
167 }
static bool print_flag_name(RzFlagItem *fi, void *user)
Definition: cflag.c:20
static bool __tableItemCallback(RzFlagItem *flag, void *user)
Definition: cflag.c:102
static bool print_flag_rizin(RzFlagItem *flag, void *user)
Definition: cflag.c:48
static bool print_flag_json(RzFlagItem *flag, void *user)
Definition: cflag.c:25
static bool print_flag_orig_name(RzFlagItem *flag, void *user)
Definition: cflag.c:83
RZ_API void rz_cmd_state_output_set_columnsf(RzCmdStateOutput *state, const char *fmt,...)
Specify the columns of the command output.
Definition: cmd_api.c:2589
#define NULL
Definition: cris-opc.c:27
RZ_API void rz_flag_foreach_space(RzFlag *f, const RzSpace *space, RzFlagItemCb cb, void *user)
Definition: flag.c:826
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define f(i)
Definition: sha256.c:46
ut64 range_from
Definition: cflag.c:14
RzFlag * f
Definition: cflag.c:11
ut64 range_to
Definition: cflag.c:15
bool in_range
Definition: cflag.c:13
Definition: dis.h:43

References __tableItemCallback(), print_flag_t::f, f, print_flag_t::in_range, NULL, pj_a(), pj_end(), print_flag_json(), print_flag_name(), print_flag_orig_name(), print_flag_rizin(), print_flag_t::range_from, print_flag_t::range_to, rz_cmd_state_output_set_columnsf(), rz_flag_foreach_space(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_return_if_fail, rz_warn_if_reached, and FlagTableData::t.

Referenced by rz_core_flag_print(), and rz_core_flag_range_print().

◆ print_flag_json()

static bool print_flag_json ( RzFlagItem flag,
void *  user 
)
static

Definition at line 25 of file cflag.c.

25  {
26  struct print_flag_t *u = (struct print_flag_t *)user;
27  if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) {
28  return true;
29  }
30  pj_o(u->pj);
31  pj_ks(u->pj, "name", flag->name);
32  if (flag->name != flag->realname) {
33  pj_ks(u->pj, "realname", flag->realname);
34  }
35  pj_ki(u->pj, "size", flag->size);
36  if (flag->alias) {
37  pj_ks(u->pj, "alias", flag->alias);
38  } else {
39  pj_kn(u->pj, "offset", flag->offset);
40  }
41  if (flag->comment) {
42  pj_ks(u->pj, "comment", flag->comment);
43  }
44  pj_end(u->pj);
45  return true;
46 }
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
PJ * pj
Definition: cflag.c:12
char * alias
Definition: rz_flag.h:43
char * comment
Definition: rz_flag.h:42
char * realname
Definition: rz_flag.h:36

References rz_flag_item_t::alias, rz_flag_item_t::comment, print_flag_t::in_range, rz_flag_item_t::name, rz_flag_item_t::offset, print_flag_t::pj, pj_end(), pj_ki(), pj_kn(), pj_ks(), pj_o(), print_flag_t::range_from, print_flag_t::range_to, rz_flag_item_t::realname, and rz_flag_item_t::size.

Referenced by flag_print().

◆ print_flag_name()

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

Definition at line 20 of file cflag.c.

20  {
21  rz_cons_printf("%s\n", fi->name);
22  return true;
23 }
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202

References rz_flag_item_t::name, and rz_cons_printf().

Referenced by flag_print().

◆ print_flag_orig_name()

static bool print_flag_orig_name ( RzFlagItem flag,
void *  user 
)
static

Definition at line 83 of file cflag.c.

83  {
84  struct print_flag_t *u = (struct print_flag_t *)user;
85  if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) {
86  return true;
87  }
88  if (flag->alias) {
89  const char *n = u->real ? flag->realname : flag->name;
90  rz_cons_printf("%s %" PFMT64d " %s\n", flag->alias, flag->size, n);
91  } else {
92  const char *n = u->real ? flag->realname : (u->f->realnames ? flag->realname : flag->name);
93  rz_cons_printf("0x%08" PFMT64x " %" PFMT64d " %s\n", flag->offset, flag->size, n);
94  }
95  return true;
96 }
int n
Definition: mipsasm.c:19
#define PFMT64d
Definition: rz_types.h:394
#define PFMT64x
Definition: rz_types.h:393
bool real
Definition: cflag.c:17
bool realnames
Definition: rz_flag.h:49

References rz_flag_item_t::alias, print_flag_t::f, print_flag_t::in_range, n, rz_flag_item_t::name, rz_flag_item_t::offset, PFMT64d, PFMT64x, print_flag_t::range_from, print_flag_t::range_to, print_flag_t::real, rz_flag_item_t::realname, rz_flag_t::realnames, rz_cons_printf(), and rz_flag_item_t::size.

Referenced by flag_print(), and rz_core_flag_real_name_print().

◆ print_flag_rizin()

static bool print_flag_rizin ( RzFlagItem flag,
void *  user 
)
static

Definition at line 48 of file cflag.c.

48  {
49  struct print_flag_t *u = (struct print_flag_t *)user;
50  char *comment_b64 = NULL, *tmp = NULL;
51  if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) {
52  return true;
53  }
54  if (!u->fs || flag->space != u->fs) {
55  u->fs = flag->space;
56  rz_cons_printf("fs %s\n", u->fs ? u->fs->name : "*");
57  }
58  if (RZ_STR_ISNOTEMPTY(flag->comment)) {
59  comment_b64 = rz_base64_encode_dyn((const ut8 *)flag->comment, strlen(flag->comment));
60  // prefix the armored string with "base64:"
61  if (comment_b64) {
62  tmp = rz_str_newf("base64:%s", comment_b64);
63  free(comment_b64);
64  comment_b64 = tmp;
65  }
66  }
67  if (flag->alias) {
68  rz_cons_printf("fa %s %s\n", flag->name, flag->alias);
69  if (comment_b64) {
70  rz_cons_printf("\"fC %s %s\"\n",
71  flag->name, rz_str_get(comment_b64));
72  }
73  } else {
74  rz_cons_printf("f %s %" PFMT64d " 0x%08" PFMT64x " %s\n",
75  flag->name, flag->size, flag->offset,
76  rz_str_get(comment_b64));
77  }
78 
79  free(comment_b64);
80  return true;
81 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
RZ_API char * rz_base64_encode_dyn(const ut8 *bin, size_t sz)
Definition: ubase64.c:92
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RzSpace * fs
Definition: cflag.c:16

References rz_flag_item_t::alias, rz_flag_item_t::comment, free(), print_flag_t::fs, print_flag_t::in_range, rz_flag_item_t::name, rz_space_t::name, NULL, rz_flag_item_t::offset, PFMT64d, PFMT64x, print_flag_t::range_from, print_flag_t::range_to, rz_base64_encode_dyn(), rz_cons_printf(), rz_str_get(), RZ_STR_ISNOTEMPTY, rz_str_newf(), rz_flag_item_t::size, rz_flag_item_t::space, and autogen_x86imm::tmp.

Referenced by flag_print().

◆ rz_core_flag_print()

RZ_IPI void rz_core_flag_print ( RzFlag f,
RzCmdStateOutput state 
)

Definition at line 169 of file cflag.c.

169  {
170  flag_print(f, state, UT64_MAX, UT64_MAX, false);
171 }
static void flag_print(RzFlag *f, RzCmdStateOutput *state, ut64 range_from, ut64 range_to, bool in_range)
Definition: cflag.c:112
#define UT64_MAX
Definition: rz_types_base.h:86

References f, flag_print(), and UT64_MAX.

Referenced by rz_flag_list_handler().

◆ rz_core_flag_range_print()

RZ_IPI void rz_core_flag_range_print ( RzFlag f,
RzCmdStateOutput state,
ut64  range_from,
ut64  range_to 
)

Definition at line 184 of file cflag.c.

184  {
185  flag_print(f, state, range_from, range_to, true);
186 }

References f, flag_print(), print_flag_t::range_from, and print_flag_t::range_to.

Referenced by rz_flag_list_at_handler(), and rz_flag_range_handler().

◆ rz_core_flag_real_name_print()

RZ_IPI void rz_core_flag_real_name_print ( RzFlag f,
RzCmdStateOutput state 
)

Definition at line 173 of file cflag.c.

173  {
174  struct print_flag_t u = {
175  .f = f,
176  .in_range = false,
177  .range_from = UT64_MAX,
178  .range_to = UT64_MAX,
179  .real = true
180  };
181  rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_orig_name, &u);
182 }

References print_flag_t::f, f, print_flag_orig_name(), rz_flag_foreach_space(), and UT64_MAX.