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

Go to the source code of this file.

Functions

RZ_API RzRegrz_core_reg_default (RzCore *core)
 Get the currently relevant RzReg. More...
 
RZ_API ut64 rz_core_reg_getv_by_role_or_name (RzCore *core, const char *name)
 rz_reg_getv_by_role_or_name() on rz_core_reg_default() More...
 
RZ_API bool rz_core_reg_set_by_role_or_name (RzCore *core, const char *name, ut64 num)
 set on rz_core_reg_default() More...
 
RZ_IPI RzListrz_core_reg_flags_candidates (RzCore *core, RzReg *reg)
 
static void regs_to_flags (RzCore *core, RzReg *regs)
 
RZ_API void rz_core_reg_update_flags (RzCore *core)
 Update or create flags for all registers where it makes sense. More...
 
RZ_IPI void rz_core_reg_print_diff (RzReg *reg, RzList *items)
 Print registers that have changed since the last step (drd/ard) More...
 

Function Documentation

◆ regs_to_flags()

static void regs_to_flags ( RzCore core,
RzReg regs 
)
static

Definition at line 82 of file creg.c.

82  {
83  rz_return_if_fail(core && regs);
85  if (!l) {
86  return;
87  }
88  rz_flag_space_push(core->flags, RZ_FLAGS_FS_REGISTERS);
90  RzRegItem *reg;
91  rz_list_foreach (l, iter, reg) {
92  ut64 regval = rz_reg_get_value(regs, reg);
93  rz_flag_set(core->flags, reg->name, regval, reg->size / 8);
94  }
95  rz_flag_space_pop(core->flags);
96  rz_list_free(l);
97 }
static char * regs[]
Definition: analysis_sh.c:203
RZ_IPI RzList * rz_core_reg_flags_candidates(RzCore *core, RzReg *reg)
Definition: creg.c:60
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
#define reg(n)
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define RZ_FLAGS_FS_REGISTERS
Definition: rz_core.h:61
RzFlag * flags
Definition: rz_core.h:330
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_core_t::flags, reg, regs, rz_core_reg_flags_candidates(), rz_flag_set(), RZ_FLAGS_FS_REGISTERS, rz_list_free(), rz_reg_get_value(), rz_return_if_fail, and ut64().

Referenced by rz_core_reg_update_flags().

◆ rz_core_reg_default()

RZ_API RzReg* rz_core_reg_default ( RzCore core)

Get the currently relevant RzReg.

Depending on whether or not the core is in debug mode, this returns the RzReg from debug or analysis (emulation). Before using this function, think twice whether it would not make more sense to use core->dbg->reg or analysis->dbg->reg directly, depending on what you want to do with it.

Definition at line 17 of file creg.c.

17  {
18  return rz_core_is_debug(core) ? core->dbg->reg : core->analysis->reg;
19 }
RZ_API bool rz_core_is_debug(RzCore *core)
Check whether the core is in debug mode (equivalent to cfg.debug)
Definition: cdebug.c:13
RzAnalysis * analysis
Definition: rz_core.h:322
RzDebug * dbg
Definition: rz_core.h:329
RzReg * reg
Definition: rz_debug.h:286

References rz_core_t::analysis, rz_core_t::dbg, rz_analysis_t::reg, rz_debug_t::reg, and rz_core_is_debug().

Referenced by autocmplt_reg(), cmd_print_format(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), foreach_reg_set_or_clear(), num_callback(), rz_core_arg_get(), rz_core_cmd_foreach3(), rz_core_debug_print_status(), rz_core_print_disasm(), and rz_core_reg_update_flags().

◆ rz_core_reg_flags_candidates()

RZ_IPI RzList* rz_core_reg_flags_candidates ( RzCore core,
RzReg reg 
)

Construct the list of registers that should be applied as flags by default (e.g. because their size matches the pointer size)

Definition at line 60 of file creg.c.

60  {
62  if (!l) {
63  return NULL;
64  }
66  RzList *ret = rz_list_new();
67  if (!ret) {
68  return NULL;
69  }
72  RzRegItem *item;
73  rz_list_foreach (l, iter, item) {
74  if (size != 0 && size != item->size && item != pc) {
75  continue;
76  }
77  rz_list_push(ret, item);
78  }
79  return ret;
80 }
RZ_API int rz_analysis_get_address_bits(RzAnalysis *analysis)
The actual size of an address in bits.
Definition: analysis.c:303
#define NULL
Definition: cris-opc.c:27
voidpf void uLong size
Definition: ioapi.h:138
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_by_role(RzReg *reg, RzRegisterId role)
Definition: reg.c:154
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
Definition: reg.c:389
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120

References rz_core_t::analysis, NULL, pc, reg, rz_analysis_get_address_bits(), rz_list_new(), rz_list_push(), rz_reg_get_by_role(), rz_reg_get_list(), RZ_REG_NAME_PC, RZ_REG_TYPE_GPR, and rz_reg_item_t::size.

Referenced by regs_to_flags(), and rz_reg_flags_handler().

◆ rz_core_reg_getv_by_role_or_name()

RZ_API ut64 rz_core_reg_getv_by_role_or_name ( RzCore core,
const char *  name 
)

rz_reg_getv_by_role_or_name() on rz_core_reg_default()

Definition at line 24 of file creg.c.

24  {
25  // this logic has to be in sync with rz_core_reg_default().
26  if (rz_core_is_debug(core)) {
27  // call this instead of rz_reg_getv_... directly because it also syncs
28  return rz_debug_reg_get(core->dbg, name);
29  }
31 }
RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name)
Definition: dreg.c:99
RZ_API ut64 rz_reg_getv_by_role_or_name(RzReg *reg, const char *name)
Definition: reg.c:338
Definition: z80asm.h:102

References rz_core_t::analysis, rz_core_t::dbg, rz_analysis_t::reg, rz_core_is_debug(), rz_debug_reg_get(), and rz_reg_getv_by_role_or_name().

Referenced by num_callback(), rz_core_arg_get(), rz_core_seek_to_register(), and rz_core_syscall_as_string().

◆ rz_core_reg_print_diff()

RZ_IPI void rz_core_reg_print_diff ( RzReg reg,
RzList items 
)

Print registers that have changed since the last step (drd/ard)

Definition at line 116 of file creg.c.

116  {
117  RzListIter *iter;
118  RzRegItem *item;
119  rz_list_foreach (items, iter, item) {
120  ut64 newval = rz_reg_get_value(reg, item);
121  rz_reg_arena_swap(reg, false);
122  ut64 oldval = rz_reg_get_value(reg, item);
123  rz_reg_arena_swap(reg, false);
124  ut64 delta = newval - oldval;
125  if (delta) {
127  "%s = 0x%" PFMT64x " was 0x%" PFMT64x " delta 0x%" PFMT64x "\n",
128  item->name, newval, oldval, delta);
129  }
130  }
131 }
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
Definition: arena.c:196
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define PFMT64x
Definition: rz_types.h:393
char * name
Definition: rz_reg.h:118
static st64 delta
Definition: vmenus.c:2425

References delta, rz_reg_item_t::name, PFMT64x, reg, rz_cons_printf(), rz_reg_arena_swap(), rz_reg_get_value(), and ut64().

Referenced by rz_core_debug_print_status(), and rz_regs_diff_handler().

◆ rz_core_reg_set_by_role_or_name()

RZ_API bool rz_core_reg_set_by_role_or_name ( RzCore core,
const char *  name,
ut64  num 
)

set on rz_core_reg_default()

This also makes sure that, in debug mode, registers are synced, and updates flags if there are any.

Definition at line 39 of file creg.c.

39  {
40  bool ret;
41  // this logic has to be in sync with rz_core_reg_default().
42  if (rz_core_is_debug(core)) {
43  // call this instead of rz_reg_set... directly because it also syncs
44  ret = rz_debug_reg_set(core->dbg, name, num);
45  } else {
47  if (!ri) {
48  return false;
49  }
50  ret = rz_reg_set_value(core->analysis->reg, ri, num);
51  }
52  if (ret && rz_spaces_get(&core->flags->spaces, RZ_FLAGS_FS_REGISTERS)) {
54  }
55  return ret;
56 }
RZ_API void rz_core_reg_update_flags(RzCore *core)
Update or create flags for all registers where it makes sense.
Definition: creg.c:106
RZ_API int rz_debug_reg_set(struct rz_debug_t *dbg, const char *name, ut64 num)
Definition: dreg.c:89
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 static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
RZ_API RzRegItem * rz_reg_get_by_role_or_name(RzReg *reg, const char *name)
Definition: reg.c:378
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186
RZ_API RzSpace * rz_spaces_get(RzSpaces *sp, const char *name)
Definition: spaces.c:82
RzSpaces spaces
Definition: rz_flag.h:47

References rz_core_t::analysis, rz_core_t::dbg, rz_core_t::flags, num, rz_analysis_t::reg, rz_core_is_debug(), rz_core_reg_update_flags(), rz_debug_reg_set(), RZ_FLAGS_FS_REGISTERS, rz_reg_get_by_role_or_name(), rz_reg_set_value(), rz_spaces_get(), and rz_flag_t::spaces.

Referenced by __handle_cursor_mode(), __handle_menu(), __panels_process(), rz_core_arg_set(), rz_core_visual_cmd(), and rz_core_visual_graph().

◆ rz_core_reg_update_flags()

RZ_API void rz_core_reg_update_flags ( RzCore core)

Update or create flags for all registers where it makes sense.

Registers are taken either from rz_core_reg_default(). "makes sens" currently means regs that have the same size as an address, but this may change in case a better heuristic is found.

Definition at line 106 of file creg.c.

106  {
107  if (rz_core_is_debug(core) && !rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false)) {
108  return;
109  }
110  regs_to_flags(core, rz_core_reg_default(core));
111 }
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
static void regs_to_flags(RzCore *core, RzReg *regs)
Definition: creg.c:82
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
Definition: dreg.c:9

References rz_core_t::dbg, regs_to_flags(), rz_core_is_debug(), rz_core_reg_default(), rz_debug_reg_sync(), and RZ_REG_TYPE_GPR.

Referenced by __print_disassembly_cb(), rz_analysis_appcall_handler(), rz_analysis_continue_until_addr_handler(), rz_analysis_continue_until_breakpoint_handler(), rz_analysis_continue_until_esil_handler(), rz_analysis_continue_until_except_handler(), rz_cmd_debug_step_cond_handler(), rz_cmd_debug_step_prog_handler(), rz_core_analysis_continue_until_call(), rz_core_analysis_continue_until_syscall(), rz_core_analysis_esil_init_mem(), rz_core_analysis_esil_step_over(), rz_core_analysis_esil_step_over_until(), rz_core_analysis_esil_step_over_untilexpr(), rz_core_analysis_il_reinit(), rz_core_analysis_set_reg(), rz_core_cmd_subst(), rz_core_debug_continue(), rz_core_debug_continue_until(), rz_core_debug_single_step_in(), rz_core_debug_single_step_over(), rz_core_debug_step_back(), rz_core_debug_step_one(), rz_core_debug_step_over(), rz_core_debug_step_skip(), rz_core_debug_step_until_frame(), rz_core_esil_continue_back(), rz_core_esil_step_back(), rz_core_file_reopen(), rz_core_il_step(), rz_core_link_stroff(), rz_core_reg_set_by_role_or_name(), rz_core_setup_debugger(), rz_core_visual(), rz_core_visual_prompt(), rz_il_step_back_handler(), rz_il_step_handler(), rz_il_step_until_addr_handler(), rz_il_step_until_expr_handler(), rz_il_step_until_opt_handler(), step_line(), step_until(), step_until_esil(), step_until_flag(), step_until_inst(), and step_until_optype().