Rizin
unix-like reverse engineering framework and cli tools
cmd_regs.c File Reference
#include <rz_core.h>
#include "../core_private.h"

Go to the source code of this file.

Macros

#define SYNC_READ(type, failed)
 
#define SYNC_READ_LIST(ritems, failed)
 
#define SYNC_WRITE(type, failed)
 

Functions

 HEAPTYPE (ut64)
 
static RzListfilter_reg_items (RzReg *reg, RZ_NULLABLE const char *filter)
 
static void format_reg_value (RzReg *reg, RzRegItem *item, char *out, size_t out_size)
 Format the value of a register as a nice hex string. More...
 
static bool reg_has_changed (RzReg *reg, RzRegItem *item)
 Check whether the given item's value has changed in the last step. More...
 
static void print_reg_not_found (const char *arg)
 
RZ_API bool rz_core_reg_assign_sync (RZ_NONNULL RzCore *core, RZ_NONNULL RzReg *reg, RzCmdRegSync sync_cb, RZ_NONNULL const char *name, ut64 val)
 
static RzCmdStatus assign_reg (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, RZ_NONNULL const char *arg, size_t eq_pos)
 (Sub)handler for register assignments like reg=0x42 More...
 
static const char * get_reg_color (RzCore *core, RzReg *reg, RzRegItem *item)
 
static const char * get_reg_role_name (RzReg *reg, RzRegItem *item)
 
RZ_API RZ_OWN RzListrz_core_reg_filter_items_sync (RZ_NONNULL RzCore *core, RZ_NONNULL RzReg *reg, RzCmdRegSync sync_cb, RZ_NULLABLE const char *filter)
 
static RzCmdStatus show_regs_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const char *filter, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_regs_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_regs_columns_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
static RzCmdStatus references_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, RzList *ritems, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_regs_references_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, RzOutputMode mode)
 
static int valgroup_regcmp (const void *a, const void *b)
 
static bool valgroup_regcb (void *u, const ut64 k, const void *v)
 
RZ_IPI void rz_regs_show_valgroup (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const RzList *list)
 
RZ_IPI RzCmdStatus rz_regs_valgroup_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_push_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_pop_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_swap_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_zero_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_hexdump_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_stack_size_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_arenas_write_hex_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_regs_args_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_reg_types_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_roles_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_flags_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv, bool unset)
 
RZ_IPI RzCmdStatus rz_reg_profile_handler (RzCore *core, RzReg *reg, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_reg_profile_comments_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_profile_open_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_profile_gdb_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_cond_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reg_cc_handler (RzCore *core, RzReg *reg, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_regs_diff_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_regs_prev_handler (RzCore *core, RzReg *reg, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_regs_fpu_handler (RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, int argc, const char **argv)
 

Macro Definition Documentation

◆ SYNC_READ

#define SYNC_READ (   type,
  failed 
)
Value:
do { \
failed = false; \
if (sync_cb && !sync_cb(core, type, false)) { \
RZ_LOG_ERROR("Failed to read registers.\n"); \
failed = true; \
} \
} while (0)
int type
Definition: mipsasm.c:17

Definition at line 9 of file cmd_regs.c.

◆ SYNC_READ_LIST

#define SYNC_READ_LIST (   ritems,
  failed 
)
Value:
do { \
failed = false; \
if (rz_list_length(ritems) == 1) { \
SYNC_READ(((RzRegItem *)rz_list_head(ritems))->type, failed); \
} else if (rz_list_length(ritems) > 1) { \
SYNC_READ(RZ_REG_TYPE_ANY, failed); \
} \
} while (0)
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35

Definition at line 17 of file cmd_regs.c.

◆ SYNC_WRITE

#define SYNC_WRITE (   type,
  failed 
)
Value:
do { \
failed = false; \
if (sync_cb && !sync_cb(core, type, true)) { \
RZ_LOG_ERROR("Failed to write registers.\n"); \
failed = true; \
} \
rz_core_reg_update_flags(core); \
} while (0)

Definition at line 26 of file cmd_regs.c.

Function Documentation

◆ assign_reg()

static RzCmdStatus assign_reg ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
RZ_NONNULL const char *  arg,
size_t  eq_pos 
)
static

(Sub)handler for register assignments like reg=0x42

Parameters
argthe full argument string, like "reg = 0x42"
eq_posindex of the '=' in arg

Definition at line 159 of file cmd_regs.c.

159  {
160  char *str = strdup(arg);
161  if (!str) {
162  return RZ_CMD_STATUS_ERROR;
163  }
164  str[eq_pos] = 0;
165  char *val = str + eq_pos + 1;
166  rz_str_trim(str);
167  rz_str_trim(val);
168  ut64 nval = rz_num_math(core->num, val);
169  return rz_core_reg_assign_sync(core, reg, sync_cb, str, nval) ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
170 }
ut16 val
Definition: armass64_const.h:6
RZ_API bool rz_core_reg_assign_sync(RZ_NONNULL RzCore *core, RZ_NONNULL RzReg *reg, RzCmdRegSync sync_cb, RZ_NONNULL const char *name, ut64 val)
Definition: cmd_regs.c:138
#define reg(n)
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_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
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
RzNum * num
Definition: rz_core.h:316
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_core_t::num, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_reg_assign_sync(), rz_num_math(), rz_str_trim(), cmd_descs_generate::str, strdup(), ut64(), and val.

Referenced by rz_regs_handler().

◆ filter_reg_items()

static RzList* filter_reg_items ( RzReg reg,
RZ_NULLABLE const char *  filter 
)
static

Definition at line 36 of file cmd_regs.c.

36  {
38  // default
39  if (RZ_STR_ISEMPTY(filter)) {
40  // default selection (only gpr, omit smaller regs that are fully covered by larger ones)
41  return rz_reg_filter_items_covered(reg->regset[RZ_REG_TYPE_GPR].regs);
42  }
43  // all
44  if (!strcmp(filter, "all")) {
45  return rz_list_clone(reg->allregs);
46  }
47  // bit size
48  char *end = NULL;
49  unsigned long bits = strtoul(filter, &end, 0);
50  if (!*end) {
51  RzList *ret = rz_list_new();
52  if (!ret) {
53  return NULL;
54  }
56  RzRegItem *ri;
57  rz_list_foreach (reg->regset[RZ_REG_TYPE_GPR].regs, iter, ri) {
58  if (ri->size == bits) {
59  rz_list_push(ret, ri);
60  }
61  }
62  return ret;
63  }
64  // type
66  if (type >= 0) {
67  return rz_list_clone(reg->regset[type].regs);
68  }
69  // role
70  int role = rz_reg_role_by_name(filter);
71  if (role >= 0) {
72  const char *itemname = rz_reg_get_name(reg, role);
73  if (!itemname) {
74  return NULL;
75  }
76  filter = itemname; // fallthrough to the below query with the resolved reg name
77  }
78  // single register name
80  if (!ri) {
81  return NULL;
82  }
83  return rz_list_new_from_array((const void **)&ri, 1);
84 }
int bits(struct state *s, int need)
Definition: blast.c:72
#define NULL
Definition: cris-opc.c:27
RZ_API RZ_OWN RzList * rz_list_clone(RZ_NONNULL const RzList *list)
Shallow copies of the list (but doesn't free its elements)
Definition: list.c:496
RZ_API RZ_OWN RzList * rz_list_new_from_array(RZ_NONNULL const void **arr, size_t arr_size)
Allocates a new RzList and adds an array elements to it.
Definition: list.c:260
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API int rz_reg_role_by_name(RZ_NONNULL const char *str)
Get the RzRegisterId with the given name or -1.
Definition: reg.c:180
RZ_API int rz_reg_type_by_name(const char *str)
Returns the register type for the given type abbreviation.
Definition: reg.c:83
RZ_API RZ_OWN RzList * rz_reg_filter_items_covered(RZ_BORROW RZ_NONNULL const RzList *regs)
Filter out all register items that are smaller than but covered entirely by some other register.
Definition: reg.c:489
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120

References bits(), test_evm::end, NULL, reg, rz_list_clone(), rz_list_new(), rz_list_new_from_array(), rz_list_push(), rz_reg_filter_items_covered(), rz_reg_get(), rz_reg_get_name(), rz_reg_role_by_name(), RZ_REG_TYPE_ANY, rz_reg_type_by_name(), RZ_REG_TYPE_GPR, rz_return_val_if_fail, RZ_STR_ISEMPTY, rz_reg_item_t::size, and type.

Referenced by rz_core_reg_filter_items_sync(), rz_reg_flags_handler(), rz_regs_references_handler(), and rz_regs_valgroup_handler().

◆ format_reg_value()

static void format_reg_value ( RzReg reg,
RzRegItem item,
char *  out,
size_t  out_size 
)
static

Format the value of a register as a nice hex string.

Definition at line 87 of file cmd_regs.c.

87  {
88  // TODO: This could be done much nicer with RzBitVector, but it's not in RzUtil yet :-(
89  if (item->size < 80) {
90  ut64 value = rz_reg_get_value(reg, item);
91  snprintf(out, out_size, "0x%08" PFMT64x, value);
92  } else {
93  utX valueBig;
94  rz_reg_get_value_big(reg, item, &valueBig);
95  switch (item->size) {
96  case 80:
97  snprintf(out, out_size, "0x%04x%016" PFMT64x "", valueBig.v80.High, valueBig.v80.Low);
98  break;
99  case 96:
100  snprintf(out, out_size, "0x%08x%016" PFMT64x "", valueBig.v96.High, valueBig.v96.Low);
101  break;
102  case 128:
103  snprintf(out, out_size, "0x%016" PFMT64x "%016" PFMT64x "", valueBig.v128.High, valueBig.v128.Low);
104  break;
105  case 256:
106  snprintf(out, out_size, "0x%016" PFMT64x "%016" PFMT64x "%016" PFMT64x "%016" PFMT64x "",
107  valueBig.v256.High.High, valueBig.v256.High.Low, valueBig.v256.Low.High, valueBig.v256.Low.Low);
108  break;
109  default:
110  snprintf(out, out_size, "ERROR");
111  }
112  }
113 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static int value
Definition: cmd_api.c:93
snprintf
Definition: kernel.h:364
RZ_API ut64 rz_reg_get_value_big(RzReg *reg, RzRegItem *item, utX *val)
Definition: rvalue.c:60
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
#define PFMT64x
Definition: rz_types.h:393
st64 High
Definition: rz_types_base.h:53
ut64 Low
Definition: rz_types_base.h:52
ut128 Low
Definition: rz_types_base.h:56
ut128 High
Definition: rz_types_base.h:57
ut16 High
Definition: rz_types_base.h:45
ut64 Low
Definition: rz_types_base.h:44
ut64 Low
Definition: rz_types_base.h:48
ut32 High
Definition: rz_types_base.h:49
ut256 v256
Definition: rz_types_base.h:63
ut80 v80
Definition: rz_types_base.h:60
ut128 v128
Definition: rz_types_base.h:62
ut96 v96
Definition: rz_types_base.h:61

References _ut80::High, _ut96::High, _ut128::High, _ut256::High, _ut80::Low, _ut96::Low, _ut128::Low, _ut256::Low, out, PFMT64x, reg, rz_reg_get_value(), rz_reg_get_value_big(), rz_reg_item_t::size, snprintf, ut64(), _utX::v128, _utX::v256, _utX::v80, _utX::v96, and value.

Referenced by rz_regs_columns_handler(), and show_regs_handler().

◆ get_reg_color()

static const char* get_reg_color ( RzCore core,
RzReg reg,
RzRegItem item 
)
static

Definition at line 172 of file cmd_regs.c.

172  {
173  if (!rz_config_get_i(core->config, "scr.color")) {
174  return NULL;
175  }
176  if (reg_has_changed(reg, item)) {
177  return (core->cons && core->cons->context->pal.creg)
178  ? core->cons->context->pal.creg
179  : Color_BWHITE;
180  }
181  return NULL;
182 }
static bool reg_has_changed(RzReg *reg, RzRegItem *item)
Check whether the given item's value has changed in the last step.
Definition: cmd_regs.c:116
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
#define Color_BWHITE
Definition: rz_cons.h:644
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502
RzCons * cons
Definition: rz_core.h:312
RzConfig * config
Definition: rz_core.h:300

References Color_BWHITE, rz_core_t::config, rz_core_t::cons, rz_cons_t::context, rz_cons_printable_palette_t::creg, NULL, rz_cons_context_t::pal, reg, reg_has_changed(), and rz_config_get_i().

Referenced by references_handler(), rz_regs_columns_handler(), and show_regs_handler().

◆ get_reg_role_name()

static const char* get_reg_role_name ( RzReg reg,
RzRegItem item 
)
static

Definition at line 184 of file cmd_regs.c.

184  {
185  for (int i = 0; i < RZ_REG_NAME_LAST; i++) {
186  const char *t = rz_reg_get_name(reg, i);
187  if (t && !strcmp(t, item->name)) {
188  return rz_reg_get_role(i);
189  }
190  }
191  return NULL;
192 }
lzma_index ** i
Definition: index.h:629
RZ_API const char * rz_reg_get_role(int role)
Definition: reg.c:172
@ RZ_REG_NAME_LAST
Definition: rz_reg.h:71
char * name
Definition: rz_reg.h:118

References i, rz_reg_item_t::name, NULL, reg, rz_reg_get_name(), rz_reg_get_role(), and RZ_REG_NAME_LAST.

Referenced by references_handler(), and show_regs_handler().

◆ HEAPTYPE()

HEAPTYPE ( ut64  )

◆ print_reg_not_found()

static void print_reg_not_found ( const char *  arg)
static

Definition at line 124 of file cmd_regs.c.

124  {
125  RZ_LOG_ERROR("No such register or register type: \"%s\"\n", rz_str_get(arg));
126 }
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187

References RZ_LOG_ERROR, and rz_str_get().

Referenced by rz_reg_flags_handler(), rz_regs_columns_handler(), rz_regs_references_handler(), rz_regs_valgroup_handler(), and show_regs_handler().

◆ references_handler()

static RzCmdStatus references_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
RzList ritems,
RzOutputMode  mode 
)
static

Definition at line 346 of file cmd_regs.c.

346  {
347  bool failed;
348  SYNC_READ_LIST(ritems, failed);
349  if (failed) {
350  return RZ_CMD_STATUS_ERROR;
351  }
352 
353  int use_colors = rz_config_get_i(core->config, "scr.color");
354 
355  int had_colors = use_colors;
356  if (use_colors && mode == RZ_OUTPUT_MODE_JSON) {
357  use_colors = 0;
358  // for rz_core_analysis_hasrefs() below
359  rz_config_set_i(core->config, "scr.color", 0);
360  }
361 
362  RzTable *t = rz_core_table(core);
363  rz_table_set_columnsf(t, "ssss", "role", "reg", "value", "refstr");
364  RzListIter *iter;
365  RzRegItem *r;
366  rz_list_foreach (ritems, iter, r) {
368  const char *color = mode == RZ_OUTPUT_MODE_JSON ? NULL : get_reg_color(core, reg, r);
369  char *namestr = rz_str_newf("%s%s%s", rz_str_get(color), r->name, color ? Color_RESET : "");
370  char *valuestr = rz_str_newf("%s0x%" PFMT64x "%s", rz_str_get(color), value, color ? Color_RESET : "");
371  char *rrstr = rz_core_analysis_hasrefs(core, value, true);
372  rz_table_add_rowf(t, "ssss", rz_str_get(get_reg_role_name(reg, r)), namestr, valuestr, rz_str_get(rrstr));
373  free(namestr);
374  free(valuestr);
375  free(rrstr);
376  }
377 
378  if (mode == RZ_OUTPUT_MODE_JSON && had_colors) {
379  rz_config_set_i(core->config, "scr.color", had_colors);
380  }
381 
383  rz_cons_print(s);
384  if (mode == RZ_OUTPUT_MODE_JSON) {
385  rz_cons_print("\n");
386  }
387  free(s);
388  rz_table_free(t);
389  return RZ_CMD_STATUS_OK;
390 }
#define SYNC_READ_LIST(ritems, failed)
Definition: cmd_regs.c:17
static const char * get_reg_color(RzCore *core, RzReg *reg, RzRegItem *item)
Definition: cmd_regs.c:172
static const char * get_reg_role_name(RzReg *reg, RzRegItem *item)
Definition: cmd_regs.c:184
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
#define r
Definition: crypto_rc6.c:12
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
const char int mode
Definition: ioapi.h:137
RZ_API RzTable * rz_core_table(RzCore *core)
Definition: core.c:3449
RZ_API char * rz_core_analysis_hasrefs(RzCore *core, ut64 value, int mode)
Definition: core.c:1805
static RzSocket * s
Definition: rtr.c:28
#define Color_RESET
Definition: rz_cons.h:617
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
RZ_API RZ_OWN char * rz_table_tojson(RzTable *t)
Convert RzTable to json format.
Definition: table.c:626
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114
RZ_API void rz_table_set_columnsf(RzTable *t, const char *fmt,...)
Specify the types and names of the referenced table.
Definition: table.c:234
RZ_API char * rz_table_tostring(RzTable *t)
Definition: table.c:510
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
static int color
Definition: visual.c:20

References color, Color_RESET, rz_core_t::config, free(), get_reg_color(), get_reg_role_name(), NULL, PFMT64x, r, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_i(), rz_config_set_i(), rz_core_analysis_hasrefs(), rz_core_table(), RZ_OUTPUT_MODE_JSON, rz_reg_get_value(), rz_str_get(), rz_str_newf(), rz_table_add_rowf(), rz_table_free(), rz_table_set_columnsf(), rz_table_tojson(), rz_table_tostring(), s, SYNC_READ_LIST, ut64(), and value.

Referenced by rz_regs_args_handler(), and rz_regs_references_handler().

◆ reg_has_changed()

static bool reg_has_changed ( RzReg reg,
RzRegItem item 
)
static

Check whether the given item's value has changed in the last step.

Definition at line 116 of file cmd_regs.c.

116  {
117  ut64 value = rz_reg_get_value(reg, item);
118  rz_reg_arena_swap(reg, false);
119  ut64 old = rz_reg_get_value(reg, item);
120  rz_reg_arena_swap(reg, false);
121  return old != value;
122 }
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
Definition: arena.c:196

References reg, rz_reg_arena_swap(), rz_reg_get_value(), ut64(), and value.

Referenced by get_reg_color().

◆ rz_core_reg_assign_sync()

RZ_API bool rz_core_reg_assign_sync ( RZ_NONNULL RzCore core,
RZ_NONNULL RzReg reg,
RzCmdRegSync  sync_cb,
RZ_NONNULL const char *  name,
ut64  val 
)

Register assignment like reg=0x42

Parameters
coreThe RzCore instance
regThe RzReg instance
sync_cbCallback for synchronizing register state in command
nameRegister name
valValue
Returns
success

Definition at line 138 of file cmd_regs.c.

138  {
139  rz_return_val_if_fail(core && reg && name, false);
141  if (!ri) {
142  return false;
143  }
144  bool failed;
145  SYNC_READ(ri->type, failed);
146  if (failed) {
147  return false;
148  }
149  rz_reg_set_value(reg, ri, val);
150  SYNC_WRITE(ri->type, failed);
151  return true;
152 }
#define SYNC_WRITE(type, failed)
Definition: cmd_regs.c:26
#define SYNC_READ(type, failed)
Definition: cmd_regs.c:9
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186
Definition: z80asm.h:102
RzRegisterType type
Register type.
Definition: rz_reg.h:119

References reg, rz_reg_get(), rz_reg_set_value(), RZ_REG_TYPE_ANY, rz_return_val_if_fail, SYNC_READ, SYNC_WRITE, rz_reg_item_t::type, and val.

Referenced by assign_reg().

◆ rz_core_reg_filter_items_sync()

RZ_API RZ_OWN RzList* rz_core_reg_filter_items_sync ( RZ_NONNULL RzCore core,
RZ_NONNULL RzReg reg,
RzCmdRegSync  sync_cb,
RZ_NULLABLE const char *  filter 
)

Filter a list of RzRegItem and sync read

Parameters
coreThe RzCore instance
regThe RzReg instance
sync_cbCallback for synchronizing register state in command
filterFilter registers
Returns
List of RzRegItem

Definition at line 203 of file cmd_regs.c.

203  {
204  rz_return_val_if_fail(core && reg, NULL);
205  RzList *ritems = filter_reg_items(reg, filter);
206  if (!ritems) {
207  return NULL;
208  }
209 
210  bool failed;
211  SYNC_READ_LIST(ritems, failed);
212  if (failed) {
213  rz_list_free(ritems);
214  return NULL;
215  }
216  return ritems;
217 }
static RzList * filter_reg_items(RzReg *reg, RZ_NULLABLE const char *filter)
Definition: cmd_regs.c:36
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References filter_reg_items(), NULL, reg, rz_list_free(), rz_return_val_if_fail, and SYNC_READ_LIST.

Referenced by rz_regs_columns_handler(), and show_regs_handler().

◆ rz_reg_arenas_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 483 of file cmd_regs.c.

483  {
484  int i, j;
485  RzRegArena *a;
486  RzListIter *iter;
487  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
488  RzRegSet *rs = &reg->regset[i];
489  j = 0;
490  rz_list_foreach (rs->pool, iter, a) {
491  rz_cons_printf("%s %p %d %d %s %d\n",
492  (a == rs->arena) ? "*" : ".", a,
493  i, j, rz_reg_get_type(i), a->size);
494  j++;
495  }
496  }
497  return RZ_CMD_STATUS_OK;
498 }
#define rs()
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API const char * rz_reg_get_type(int idx)
Definition: reg.c:68
@ RZ_REG_TYPE_LAST
Definition: rz_reg.h:34
#define a(i)
Definition: sha256.c:41

References a, i, reg, rs, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_get_type(), and RZ_REG_TYPE_LAST.

◆ rz_reg_arenas_hexdump_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_hexdump_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 544 of file cmd_regs.c.

544  {
545  int t = RZ_REG_TYPE_GPR;
546  if (argc > 1) {
547  t = rz_reg_type_by_name(argv[1]);
548  if (t < 0) {
549  RZ_LOG_ERROR("No such register type: \"%s\"\n", argv[2]);
550  return RZ_CMD_STATUS_ERROR;
551  }
552  }
553  bool failed;
554  SYNC_READ(t, failed);
555  if (failed) {
556  return RZ_CMD_STATUS_ERROR;
557  }
558  int len = 0;
559  ut8 *buf = rz_reg_get_bytes(reg, t, &len);
560  if (buf) {
561  rz_core_print_hexdump(core, 0LL, buf, len, 32, 4, 1);
562  free(buf);
563  }
564  return RZ_CMD_STATUS_OK;
565 }
size_t len
Definition: 6502dis.c:15
RZ_API ut8 * rz_reg_get_bytes(RzReg *reg, int type, int *size)
Definition: arena.c:8
RZ_IPI void rz_core_print_hexdump(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL const ut8 *buf, int len, int base, int step, size_t zoomsz)
Definition: cprint.c:161
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40

References argv, free(), len, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_print_hexdump(), RZ_LOG_ERROR, rz_reg_get_bytes(), rz_reg_type_by_name(), RZ_REG_TYPE_GPR, and SYNC_READ.

◆ rz_reg_arenas_pop_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_pop_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 511 of file cmd_regs.c.

511  {
513  bool failed;
514  SYNC_WRITE(RZ_REG_TYPE_ANY, failed);
515  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
516 }
RZ_API void rz_reg_arena_pop(RzReg *reg)
Definition: arena.c:216

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_reg_arena_pop(), RZ_REG_TYPE_ANY, and SYNC_WRITE.

◆ rz_reg_arenas_push_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_push_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 500 of file cmd_regs.c.

500  {
501  bool failed;
502  SYNC_READ(RZ_REG_TYPE_ANY, failed);
503  if (failed) {
504  return RZ_CMD_STATUS_ERROR;
505  }
507  SYNC_WRITE(RZ_REG_TYPE_ANY, failed);
508  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
509 }
RZ_API int rz_reg_arena_push(RzReg *reg)
Definition: arena.c:236

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_reg_arena_push(), RZ_REG_TYPE_ANY, SYNC_READ, and SYNC_WRITE.

◆ rz_reg_arenas_stack_size_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_stack_size_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 567 of file cmd_regs.c.

567  {
568  rz_cons_printf("%d\n", (int)rz_list_length(reg->regset[0].pool));
569  return RZ_CMD_STATUS_OK;
570 }

References reg, RZ_CMD_STATUS_OK, rz_cons_printf(), and rz_list_length().

◆ rz_reg_arenas_swap_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_swap_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 518 of file cmd_regs.c.

518  {
519  bool failed;
520  SYNC_READ(RZ_REG_TYPE_ANY, failed);
521  if (failed) {
522  return RZ_CMD_STATUS_ERROR;
523  }
524  rz_reg_arena_swap(reg, false);
525  SYNC_WRITE(RZ_REG_TYPE_ANY, failed);
526  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
527 }

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_reg_arena_swap(), RZ_REG_TYPE_ANY, SYNC_READ, and SYNC_WRITE.

◆ rz_reg_arenas_write_hex_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_write_hex_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 572 of file cmd_regs.c.

572  {
575  if (argc > 2) {
577  if (type < 0 || type >= RZ_REG_TYPE_LAST) {
578  RZ_LOG_ERROR("No such register type: \"%s\"\n", argv[2]);
579  return RZ_CMD_STATUS_ERROR;
580  }
581  }
582  bool failed;
583  SYNC_READ(type, failed);
584  if (failed) {
585  return RZ_CMD_STATUS_ERROR;
586  }
587  const char *hex = argv[1];
588  size_t maxsz = (strlen(hex) + 1) / 2;
589  if (!maxsz) {
590  return RZ_CMD_STATUS_ERROR;
591  }
592  ut8 *buf = malloc(maxsz);
593  if (!buf) {
594  return RZ_CMD_STATUS_ERROR;
595  }
596  int sz = rz_hex_str2bin(hex, buf);
597  if (sz <= 0) {
598  RZ_LOG_ERROR("Invalid hex string given.\n");
599  free(buf);
600  return RZ_CMD_STATUS_ERROR;
601  }
602  RzRegArena *a = reg->regset[type].arena;
603  if (!a || !a->bytes) {
604  free(buf);
605  // nothing to write, this is fine
606  return RZ_CMD_STATUS_OK;
607  }
608  memcpy(a->bytes, buf, RZ_MIN(sz, a->size));
609  free(buf);
610  SYNC_WRITE(type, failed);
611  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
612 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
Definition: malloc.c:123
static const char hex[16]
Definition: print.c:21
@ RZ_CMD_STATUS_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
RzRegisterType
Definition: rz_reg.h:20
#define RZ_MIN(x, y)

References a, argv, free(), hex, malloc(), memcpy(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_hex_str2bin(), RZ_LOG_ERROR, RZ_MIN, rz_reg_type_by_name(), RZ_REG_TYPE_GPR, RZ_REG_TYPE_LAST, rz_return_val_if_fail, SYNC_READ, SYNC_WRITE, and type.

◆ rz_reg_arenas_zero_handler()

RZ_IPI RzCmdStatus rz_reg_arenas_zero_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 529 of file cmd_regs.c.

529  {
530  int t = RZ_REG_TYPE_ANY;
531  if (argc > 1) {
532  t = rz_reg_type_by_name(argv[1]);
533  if (t < 0) {
534  RZ_LOG_ERROR("No such register type: \"%s\"\n", argv[2]);
535  return RZ_CMD_STATUS_ERROR;
536  }
537  }
539  bool failed;
540  SYNC_WRITE(t, failed);
541  return failed ? RZ_CMD_STATUS_ERROR : RZ_CMD_STATUS_OK;
542 }
RZ_API void rz_reg_arena_zero(RzReg *reg, RzRegisterType type)
Definition: arena.c:261

References argv, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, rz_reg_arena_zero(), RZ_REG_TYPE_ANY, rz_reg_type_by_name(), and SYNC_WRITE.

◆ rz_reg_cc_handler()

RZ_IPI RzCmdStatus rz_reg_cc_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 797 of file cmd_regs.c.

797  {
798  char *s = rz_reg_profile_to_cc(reg);
799  if (s) {
800  rz_cons_printf("%s\n", s);
801  free(s);
802  }
803  return RZ_CMD_STATUS_OK;
804 }
RZ_API char * rz_reg_profile_to_cc(RzReg *reg)
Definition: profile.c:652

References free(), reg, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_profile_to_cc(), and s.

◆ rz_reg_cond_handler()

RZ_IPI RzCmdStatus rz_reg_cond_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 776 of file cmd_regs.c.

776  {
777  bool failed;
778  SYNC_READ(RZ_REG_TYPE_ANY, failed);
779  if (failed) {
780  return RZ_CMD_STATUS_ERROR;
781  }
783  if (!rf) {
784  return RZ_CMD_STATUS_ERROR;
785  }
786  rz_cons_printf("| s:%d z:%d c:%d o:%d p:%d\n",
787  rf->s, rf->z, rf->c, rf->o, rf->p);
788  for (int i = 0; i < RZ_REG_COND_LAST; i++) {
789  rz_cons_printf("%d %s\n",
790  rz_reg_cond_bits(reg, i, rf),
792  }
793  free(rf);
794  return RZ_CMD_STATUS_OK;
795 }
RZ_API int rz_reg_cond_bits(RzReg *r, int type, RzRegFlags *f)
Definition: rcond.c:102
RZ_API RzRegFlags * rz_reg_cond_retrieve(RzReg *r, RzRegFlags *f)
Definition: rcond.c:219
RZ_API const char * rz_reg_cond_to_string(int n)
Definition: rcond.c:48
#define RZ_REG_COND_LAST
Definition: rz_reg.h:93

References rz_reg_flags_t::c, free(), i, NULL, rz_reg_flags_t::o, rz_reg_flags_t::p, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_cond_bits(), RZ_REG_COND_LAST, rz_reg_cond_retrieve(), rz_reg_cond_to_string(), RZ_REG_TYPE_ANY, rz_reg_flags_t::s, SYNC_READ, and rz_reg_flags_t::z.

◆ rz_reg_flags_handler()

RZ_IPI RzCmdStatus rz_reg_flags_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
bool  unset 
)

Definition at line 658 of file cmd_regs.c.

658  {
659  const char *filter = argc > 1 && *argv[1] ? argv[1] : NULL;
660  RzList *ritems;
661  if (filter) {
662  ritems = filter_reg_items(reg, filter);
663  if (!ritems) {
665  return RZ_CMD_STATUS_ERROR;
666  }
667  } else {
668  ritems = rz_core_reg_flags_candidates(core, reg);
669  if (!ritems) {
670  return RZ_CMD_STATUS_ERROR;
671  }
672  }
673  if (!unset) {
674  rz_cons_print("fss+ " RZ_FLAGS_FS_REGISTERS "\n");
675  bool failed;
676  SYNC_READ_LIST(ritems, failed);
677  if (failed) {
678  rz_list_free(ritems);
679  return RZ_CMD_STATUS_ERROR;
680  }
681  }
682  RzListIter *iter;
683  RzRegItem *item;
684  rz_list_foreach (ritems, iter, item) {
685  if (!unset) {
686  ut64 v = rz_reg_get_value(reg, item);
687  rz_cons_printf("f+ %s @ 0x%" PFMT64x "\n", item->name, v);
688  } else {
689  rz_cons_printf("f- %s\n", item->name);
690  }
691  }
692  if (!unset) {
693  rz_cons_print("fss-\n");
694  }
695  rz_list_free(ritems);
696  return RZ_CMD_STATUS_OK;
697 }
static void print_reg_not_found(const char *arg)
Definition: cmd_regs.c:124
RZ_IPI RzList * rz_core_reg_flags_candidates(RzCore *core, RzReg *reg)
Definition: creg.c:60
const char * v
Definition: dsignal.c:12
#define RZ_FLAGS_FS_REGISTERS
Definition: rz_core.h:61

References argv, filter_reg_items(), rz_reg_item_t::name, NULL, PFMT64x, print_reg_not_found(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_reg_flags_candidates(), RZ_FLAGS_FS_REGISTERS, rz_list_free(), rz_reg_get_value(), SYNC_READ_LIST, ut64(), and v.

◆ rz_reg_profile_comments_handler()

RZ_IPI RzCmdStatus rz_reg_profile_comments_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 749 of file cmd_regs.c.

749  {
750  if (reg->reg_profile_cmt) {
751  rz_cons_println(reg->reg_profile_cmt);
752  }
753  return RZ_CMD_STATUS_OK;
754 }
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233

References reg, RZ_CMD_STATUS_OK, and rz_cons_println().

◆ rz_reg_profile_gdb_handler()

RZ_IPI RzCmdStatus rz_reg_profile_gdb_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 762 of file cmd_regs.c.

762  {
764  char *rz_profile = rz_reg_parse_gdb_profile(argv[1]);
765  if (!rz_profile) {
766  RZ_LOG_ERROR("Cannot parse gdb profile.\n");
767  core->num->value = 1;
768  return RZ_CMD_STATUS_ERROR;
769  }
770  rz_cons_println(rz_profile);
771  core->num->value = 0;
772  free(rz_profile);
773  return RZ_CMD_STATUS_OK;
774 }
RZ_API char * rz_reg_parse_gdb_profile(const char *profile_file)
Definition: profile.c:631
ut64 value
Definition: rz_num.h:63

References argv, free(), rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_cons_println(), RZ_LOG_ERROR, rz_reg_parse_gdb_profile(), rz_return_val_if_fail, and rz_num_t::value.

◆ rz_reg_profile_handler()

RZ_IPI RzCmdStatus rz_reg_profile_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 699 of file cmd_regs.c.

699  {
700  switch (state->mode) {
702  if (reg->reg_profile_str) {
703  rz_cons_println(reg->reg_profile_str);
704  } else {
705  eprintf("No register profile defined.\n");
706  }
707  break;
708  case RZ_OUTPUT_MODE_JSON: {
709  RzListIter *iter;
710  RzRegItem *r;
711  int i;
712  PJ *pj = state->d.pj;
713  pj_o(pj);
714  pj_k(pj, "alias_info");
715  pj_a(pj);
716  for (i = 0; i < RZ_REG_NAME_LAST; i++) {
717  if (reg->name[i]) {
718  pj_o(pj);
719  pj_kn(pj, "role", i);
720  pj_ks(pj, "role_str", rz_reg_get_role(i));
721  pj_ks(pj, "reg", reg->name[i]);
722  pj_end(pj);
723  }
724  }
725  pj_end(pj);
726  pj_k(pj, "reg_info");
727  pj_a(pj);
728  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
729  rz_list_foreach (reg->regset[i].regs, iter, r) {
730  pj_o(pj);
731  pj_kn(pj, "type", r->type);
732  pj_ks(pj, "type_str", rz_reg_get_type(r->type));
733  pj_ks(pj, "name", r->name);
734  pj_kn(pj, "size", r->size);
735  pj_kn(pj, "offset", r->offset);
736  pj_end(pj);
737  }
738  }
739  pj_end(pj);
740  pj_end(pj);
741  break;
742  }
743  default:
744  break;
745  }
746  return RZ_CMD_STATUS_OK;
747 }
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
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
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
Definition: rz_pj.h:12
Definition: dis.h:43

References eprintf, i, pj_a(), pj_end(), pj_k(), pj_kn(), pj_ks(), pj_o(), r, reg, RZ_CMD_STATUS_OK, rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_reg_get_role(), rz_reg_get_type(), RZ_REG_NAME_LAST, and RZ_REG_TYPE_LAST.

◆ rz_reg_profile_open_handler()

RZ_IPI RzCmdStatus rz_reg_profile_open_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 756 of file cmd_regs.c.

756  {
759  return RZ_CMD_STATUS_OK;
760 }
RZ_API bool rz_reg_set_profile(RzReg *reg, const char *profile)
Definition: profile.c:486

References argv, reg, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_reg_set_profile(), and rz_return_val_if_fail.

◆ rz_reg_roles_handler()

RZ_IPI RzCmdStatus rz_reg_roles_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 647 of file cmd_regs.c.

647  {
648  for (int i = 0; i < RZ_REG_NAME_LAST; i++) {
649  rz_cons_print(rz_reg_get_role(i));
650  if (reg->name[i]) {
651  rz_cons_printf(" -> %s", reg->name[i]);
652  }
653  rz_cons_print("\n");
654  }
655  return RZ_CMD_STATUS_OK;
656 }

References i, reg, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_get_role(), and RZ_REG_NAME_LAST.

◆ rz_reg_types_handler()

RZ_IPI RzCmdStatus rz_reg_types_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv 
)

Definition at line 640 of file cmd_regs.c.

640  {
641  for (int i = 0; i < RZ_REG_TYPE_LAST; i++) {
643  }
644  return RZ_CMD_STATUS_OK;
645 }

References i, RZ_CMD_STATUS_OK, rz_cons_println(), rz_reg_get_type(), and RZ_REG_TYPE_LAST.

◆ rz_regs_args_handler()

RZ_IPI RzCmdStatus rz_regs_args_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 614 of file cmd_regs.c.

614  {
615  RzList *ritems = rz_list_new();
616  if (!ritems) {
617  return RZ_CMD_STATUS_ERROR;
618  }
619  for (int i = RZ_REG_NAME_A0; i <= RZ_REG_NAME_A9; i++) {
620  const char *name = rz_reg_get_name(reg, i);
621  if (!name) {
622  break;
623  }
625  if (!item) {
626  continue;
627  }
628  rz_list_push(ritems, item);
629  }
631  if (rz_list_empty(ritems)) {
632  eprintf("No argument roles defined.\n");
633  } else {
634  r = references_handler(core, reg, sync_cb, ritems, mode);
635  }
636  rz_list_free(ritems);
637  return r;
638 }
static RzCmdStatus references_handler(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, RzList *ritems, RzOutputMode mode)
Definition: cmd_regs.c:346
enum rz_cmd_status_t RzCmdStatus
@ RZ_REG_NAME_A9
Definition: rz_reg.h:58
@ RZ_REG_NAME_A0
Definition: rz_reg.h:49

References eprintf, i, r, references_handler(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_list_free(), rz_list_new(), rz_list_push(), rz_reg_get(), rz_reg_get_name(), RZ_REG_NAME_A0, RZ_REG_NAME_A9, and RZ_REG_TYPE_ANY.

◆ rz_regs_columns_handler()

RZ_IPI RzCmdStatus rz_regs_columns_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 298 of file cmd_regs.c.

298  {
299  const char *filter = argc > 1 ? argv[1] : NULL;
300  RzList *ritems = rz_core_reg_filter_items_sync(core, reg, sync_cb, filter);
301  if (!ritems) {
303  return RZ_CMD_STATUS_ERROR;
304  }
305 
306  int cols = 4; // how many registers in a row
307  int colwidth = 24;
308  RzListIter *iter;
309  RzRegItem *item;
310  char whites[32], content[300];
311  char strvalue[256] = { 0 };
312  size_t idx = 0;
313  rz_list_foreach (ritems, iter, item) {
314  const char *color = get_reg_color(core, reg, item);
315  if (color) {
316  rz_cons_print(color);
317  }
318  format_reg_value(reg, item, strvalue, sizeof(strvalue));
319  int len = snprintf(content, sizeof(content), "%7s %s", item->name, strvalue);
320  if (len < 0) {
321  break;
322  }
323  rz_cons_print(content);
324  if (color) {
325  rz_cons_print(Color_RESET);
326  }
327  if ((idx + 1) % cols) {
328  int rem = colwidth - strlen(content);
329  rem = RZ_MIN(sizeof(whites) - 1, RZ_MAX(0, rem));
330  memset(whites, ' ', rem);
331  whites[rem] = 0;
332  rz_cons_print(whites);
333  } else {
334  rz_cons_print("\n");
335  }
336  idx++;
337  }
338  if (idx % cols) {
339  // only print newline if not already done in the loop above
340  rz_cons_print("\n");
341  }
342  rz_list_free(ritems);
343  return RZ_CMD_STATUS_OK;
344 }
RZ_API RZ_OWN RzList * rz_core_reg_filter_items_sync(RZ_NONNULL RzCore *core, RZ_NONNULL RzReg *reg, RzCmdRegSync sync_cb, RZ_NULLABLE const char *filter)
Definition: cmd_regs.c:203
static void format_reg_value(RzReg *reg, RzRegItem *item, char *out, size_t out_size)
Format the value of a register as a nice hex string.
Definition: cmd_regs.c:87
return memset(p, 0, total)
int idx
Definition: setup.py:197
#define RZ_MAX(x, y)

References argv, color, Color_RESET, format_reg_value(), get_reg_color(), setup::idx, len, memset(), rz_reg_item_t::name, NULL, print_reg_not_found(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_reg_filter_items_sync(), rz_list_free(), RZ_MAX, RZ_MIN, and snprintf.

◆ rz_regs_diff_handler()

RZ_IPI RzCmdStatus rz_regs_diff_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 806 of file cmd_regs.c.

806  {
807  bool failed;
808  SYNC_READ(RZ_REG_TYPE_ANY, failed);
809  if (failed) {
810  return RZ_CMD_STATUS_ERROR;
811  }
812  rz_core_reg_print_diff(reg, reg->allregs);
813  return RZ_CMD_STATUS_OK;
814 }
RZ_IPI void rz_core_reg_print_diff(RzReg *reg, RzList *items)
Print registers that have changed since the last step (drd/ard)
Definition: creg.c:116

References reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_reg_print_diff(), RZ_REG_TYPE_ANY, and SYNC_READ.

◆ rz_regs_fpu_handler()

RZ_IPI RzCmdStatus rz_regs_fpu_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 824 of file cmd_regs.c.

824  {
825  // TODO: everything here needs to be rewritten. It was taken from the old "drf" command.
826  bool failed;
827  if (argc <= 1) {
828  // TODO: Do not use this hack to print fpu register:
829  // By sending a negative value, this is signalling all the way through to the debug plugin,
830  // which then does the printing.
831  // This should be rewritten directly above the RzReg.
832  SYNC_READ(-RZ_REG_TYPE_FPU, failed);
833  if (failed) {
834  return RZ_CMD_STATUS_ERROR;
835  }
836  return RZ_CMD_STATUS_OK;
837  }
838  char *name = rz_str_trim_dup(argv[1]);
839  char *eq = strchr(name, '=');
840  if (eq) {
841  *eq++ = 0;
842  }
843  char *p = strchr(name, ' ');
844  if (p) {
845  *p++ = 0;
846  }
848  SYNC_READ(RZ_REG_TYPE_GPR, failed);
849  if (failed) {
850  goto error;
851  }
852  SYNC_READ(RZ_REG_TYPE_FPU, failed);
853  if (failed) {
854  goto error;
855  }
856  RzRegItem *item = rz_reg_get(reg, name, -1);
857  if (item) {
858  if (eq) {
859  long double val = 0.0f;
860 #if __windows__
861  double dval = 0.0f;
862  sscanf(eq, "%lf", (double *)&dval);
863  val = dval;
864 #else
865  sscanf(eq, "%Lf", &val);
866 #endif
867  rz_reg_set_double(reg, item, val);
868  SYNC_WRITE(RZ_REG_TYPE_GPR, failed);
869  if (failed) {
870  goto error;
871  }
872  SYNC_WRITE(RZ_REG_TYPE_FPU, failed);
873  if (failed) {
874  goto error;
875  }
876  } else {
877  long double res = rz_reg_get_longdouble(reg, item);
878  rz_cons_printf("%Lf\n", res);
879  }
880  } else {
881  /* note, that negative type forces sync to print the regs from the backend */
882  eprintf("cannot find multimedia register '%s'\n", name);
883  }
884 
885 error:
886  free(name);
887  return ret;
888 }
RZ_API bool rz_reg_set_double(RzReg *reg, RzRegItem *item, double value)
Definition: double.c:40
RZ_API long double rz_reg_get_longdouble(RzReg *reg, RzRegItem *item)
Definition: double.c:67
void * p
Definition: libc.cpp:67
@ RZ_REG_TYPE_FPU
Definition: rz_reg.h:23
RZ_API char * rz_str_trim_dup(const char *str)
Definition: str_trim.c:78
void error(const char *msg)
Definition: untgz.c:593

References argv, eprintf, eq, error(), free(), p, reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_reg_get(), rz_reg_get_longdouble(), rz_reg_set_double(), RZ_REG_TYPE_FPU, RZ_REG_TYPE_GPR, rz_str_trim_dup(), SYNC_READ, SYNC_WRITE, and val.

◆ rz_regs_handler()

RZ_IPI RzCmdStatus rz_regs_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 283 of file cmd_regs.c.

283  {
284  const char *filter = argc > 1 ? argv[1] : NULL;
285 
286  // check if the argument is an assignment like reg=0x42
287  if (filter) {
288  char *eq = strchr(filter, '=');
289  if (eq) {
290  return assign_reg(core, reg, sync_cb, filter, eq - filter);
291  }
292  }
293 
294  // just show
295  return show_regs_handler(core, reg, sync_cb, filter, state);
296 }
static RzCmdStatus assign_reg(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, RZ_NONNULL const char *arg, size_t eq_pos)
(Sub)handler for register assignments like reg=0x42
Definition: cmd_regs.c:159
static RzCmdStatus show_regs_handler(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const char *filter, RzCmdStateOutput *state)
Definition: cmd_regs.c:219

References argv, assign_reg(), eq, NULL, reg, and show_regs_handler().

◆ rz_regs_prev_handler()

RZ_IPI RzCmdStatus rz_regs_prev_handler ( RzCore core,
RzReg reg,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 816 of file cmd_regs.c.

816  {
817  const char *filter = argc > 1 ? argv[1] : NULL;
818  rz_reg_arena_swap(reg, false);
819  RzCmdStatus r = show_regs_handler(core, reg, NULL, filter, state); // sync_cb = NULL on purpose to not overwrite
820  rz_reg_arena_swap(reg, false);
821  return r;
822 }

References argv, NULL, r, reg, rz_reg_arena_swap(), and show_regs_handler().

◆ rz_regs_references_handler()

RZ_IPI RzCmdStatus rz_regs_references_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 392 of file cmd_regs.c.

392  {
393  const char *filter = argc > 1 ? argv[1] : NULL;
394  RzList *ritems = filter_reg_items(reg, filter);
395  if (!ritems) {
397  return RZ_CMD_STATUS_ERROR;
398  }
399  RzCmdStatus r = references_handler(core, reg, sync_cb, ritems, mode);
400  rz_list_free(ritems);
401  return r;
402 }

References argv, filter_reg_items(), NULL, print_reg_not_found(), r, references_handler(), reg, RZ_CMD_STATUS_ERROR, and rz_list_free().

◆ rz_regs_show_valgroup()

RZ_IPI void rz_regs_show_valgroup ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
const RzList list 
)

Definition at line 423 of file cmd_regs.c.

423  {
424  int use_colors = rz_config_get_i(core->config, "scr.color");
425 
426  RzListIter *iter;
427  RzRegItem *r;
428  HtUP *db = ht_up_new0();
429  rz_list_foreach (list, iter, r) {
430  if (r->size != core->rasm->bits) {
431  continue;
432  }
434  RzList *list = ht_up_find(db, value, NULL);
435  if (!list) {
437  ht_up_update(db, value, list);
438  }
439  rz_list_append(list, r->name);
440  }
441 
442  RzList *sorted = rz_list_newf(free);
443  ht_up_foreach(db, valgroup_regcb, sorted);
444  ut64 *addr;
445  rz_list_foreach (sorted, iter, addr) {
446  rz_cons_printf("0x%08" PFMT64x " ", *addr);
447  RzList *list = ht_up_find(db, *addr, NULL);
448  if (list) {
449  RzListIter *iter;
450  const char *r;
451  if (use_colors) {
453  }
454  rz_list_foreach (list, iter, r) {
455  rz_cons_printf(" %s", r);
456  }
457  if (use_colors) {
459  }
460  char *rrstr = rz_core_analysis_hasrefs(core, *addr, true);
461  if (rrstr && *rrstr && strchr(rrstr, 'R')) {
462  rz_cons_printf(" ;%s%s", rrstr, use_colors ? Color_RESET : "");
463  }
464  rz_cons_newline();
465  }
466  }
467  rz_list_free(sorted);
468  ht_up_free(db);
469 }
static bool valgroup_regcb(void *u, const ut64 k, const void *v)
Definition: cmd_regs.c:416
RZ_API void rz_cons_strcat(const char *str)
Definition: cons.c:1263
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
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
#define Color_YELLOW
Definition: rz_cons.h:631
int bits
Definition: rz_asm.h:100
RzAsm * rasm
Definition: rz_core.h:323
static int addr
Definition: z80asm.c:58

References addr, rz_asm_t::bits, Color_RESET, Color_YELLOW, rz_core_t::config, free(), list(), NULL, PFMT64x, r, rz_core_t::rasm, reg, rz_config_get_i(), rz_cons_newline(), rz_cons_printf(), rz_cons_strcat(), rz_core_analysis_hasrefs(), rz_list_append(), rz_list_free(), rz_list_newf(), rz_reg_get_value(), ut64(), valgroup_regcb(), and value.

Referenced by rz_core_debug_ri(), and rz_regs_valgroup_handler().

◆ rz_regs_valgroup_handler()

RZ_IPI RzCmdStatus rz_regs_valgroup_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
int  argc,
const char **  argv 
)

Definition at line 471 of file cmd_regs.c.

471  {
472  const char *filter = argc > 1 ? argv[1] : NULL;
474  if (!list) {
476  return RZ_CMD_STATUS_ERROR;
477  }
478  rz_regs_show_valgroup(core, reg, sync_cb, list);
480  return RZ_CMD_STATUS_OK;
481 }
RZ_IPI void rz_regs_show_valgroup(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const RzList *list)
Definition: cmd_regs.c:423

References argv, filter_reg_items(), list(), NULL, print_reg_not_found(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_list_free(), and rz_regs_show_valgroup().

◆ show_regs_handler()

static RzCmdStatus show_regs_handler ( RzCore core,
RzReg reg,
RzCmdRegSync  sync_cb,
const char *  filter,
RzCmdStateOutput state 
)
static

Definition at line 219 of file cmd_regs.c.

219  {
220  RzList *ritems = rz_core_reg_filter_items_sync(core, reg, sync_cb, filter);
221  if (!ritems) {
223  return RZ_CMD_STATUS_ERROR;
224  }
225 
226  if (state->mode == RZ_OUTPUT_MODE_TABLE) {
227  rz_table_set_columnsf(state->d.t, "ssXxs", "role", "name", "value", "size", "type");
228  } else if (state->mode == RZ_OUTPUT_MODE_JSON) {
229  pj_o(state->d.pj);
230  }
231 
232  RzListIter *iter;
233  RzRegItem *item;
234  char buf[256] = { 0 };
235  rz_list_foreach (ritems, iter, item) {
236  switch (state->mode) {
238  format_reg_value(reg, item, buf, sizeof(buf));
239  const char *color = get_reg_color(core, reg, item);
240  if (color) {
241  rz_cons_print(color);
242  }
243  rz_cons_printf("%s = %s", item->name, buf);
244  if (color) {
245  rz_cons_print(Color_RESET);
246  }
247  rz_cons_print("\n");
248  break;
249  }
251  format_reg_value(reg, item, buf, sizeof(buf));
252  rz_cons_printf("%s\n", buf);
253  break;
255  format_reg_value(reg, item, buf, sizeof(buf));
256  rz_cons_printf("ar %s = %s\n", item->name, buf);
257  break;
259  rz_table_add_rowf(state->d.t, "ssXxs",
261  item->name, rz_reg_get_value(reg, item), (ut64)item->size, rz_reg_get_type(item->type));
262  break;
263  case RZ_OUTPUT_MODE_JSON:
264  if (item->size <= 64) {
265  pj_kn(state->d.pj, item->name, rz_reg_get_value(reg, item));
266  } else {
267  format_reg_value(reg, item, buf, sizeof(buf));
268  pj_ks(state->d.pj, item->name, buf);
269  }
270  break;
271  default:
272  break;
273  }
274  }
275  rz_list_free(ritems);
276 
277  if (state->mode == RZ_OUTPUT_MODE_JSON) {
278  pj_end(state->d.pj);
279  }
280  return RZ_CMD_STATUS_OK;
281 }
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41

References color, Color_RESET, format_reg_value(), get_reg_color(), get_reg_role_name(), rz_reg_item_t::name, pj_end(), pj_kn(), pj_ks(), pj_o(), print_reg_not_found(), reg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_reg_filter_items_sync(), rz_list_free(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_reg_get_type(), rz_reg_get_value(), rz_str_get(), rz_table_add_rowf(), rz_table_set_columnsf(), rz_reg_item_t::size, rz_reg_item_t::type, and ut64().

Referenced by rz_regs_handler(), and rz_regs_prev_handler().

◆ valgroup_regcb()

static bool valgroup_regcb ( void *  u,
const ut64  k,
const void *  v 
)
static

Definition at line 416 of file cmd_regs.c.

416  {
417  RzList *sorted = (RzList *)u;
418  ut64 *n = ut64_new(k);
420  return true;
421 }
static int valgroup_regcmp(const void *a, const void *b)
Definition: cmd_regs.c:404
const char * k
Definition: dsignal.c:11
RZ_API RZ_BORROW RzListIter * rz_list_add_sorted(RZ_NONNULL RzList *list, void *data, RZ_NONNULL RzListComparator cmp)
Adds an element to a sorted list via the RzListComparator.
Definition: list.c:518
int n
Definition: mipsasm.c:19

References k, n, rz_list_add_sorted(), ut64(), and valgroup_regcmp().

Referenced by rz_regs_show_valgroup().

◆ valgroup_regcmp()

static int valgroup_regcmp ( const void *  a,
const void *  b 
)
static

Definition at line 404 of file cmd_regs.c.

404  {
405  const ut64 *A = (const ut64 *)a;
406  const ut64 *B = (const ut64 *)b;
407  if (*A > *B) {
408  return 1;
409  }
410  if (*A == *B) {
411  return 0;
412  }
413  return -1;
414 }
#define A(x)
Definition: arc.h:165
#define B(x)
Definition: arc.h:166
#define b(i)
Definition: sha256.c:42

References a, A, b, B, and ut64().

Referenced by valgroup_regcb().