Rizin
unix-like reverse engineering framework and cli tools
reg.c File Reference
#include <rz_list.h>
#include <rz_reg.h>
#include <rz_util.h>

Go to the source code of this file.

Functions

 RZ_LIB_VERSION (rz_reg)
 
RZ_API const char * rz_reg_32_to_64 (RzReg *reg, const char *rreg32)
 
RZ_API const char * rz_reg_64_to_32 (RzReg *reg, const char *rreg64)
 
RZ_API const char * rz_reg_get_type (int idx)
 
RZ_API const char * rz_reg_get_name_by_type (RzReg *reg, const char *alias_name)
 
RZ_API int rz_reg_type_by_name (const char *str)
 Returns the register type for the given type abbreviation. More...
 
RZ_API void rz_reg_item_free (RzRegItem *item)
 
RZ_API int rz_reg_get_name_idx (const char *type)
 
RZ_API bool rz_reg_set_name (RZ_NONNULL RzReg *reg, RzRegisterId role, RZ_NONNULL const char *name)
 
RZ_API const char * rz_reg_get_name (RzReg *reg, int role)
 
RZ_API RzRegItemrz_reg_get_by_role (RzReg *reg, RzRegisterId role)
 
RZ_API const char * rz_reg_get_role (int role)
 
RZ_API int rz_reg_role_by_name (RZ_NONNULL const char *str)
 Get the RzRegisterId with the given name or -1. More...
 
RZ_API void rz_reg_free_internal (RzReg *reg, bool init)
 
static int regcmp (RzRegItem *a, RzRegItem *b)
 
RZ_API void rz_reg_reindex (RzReg *reg)
 
RZ_API RzRegItemrz_reg_index_get (RzReg *reg, int idx)
 
RZ_API void rz_reg_free (RzReg *reg)
 
RZ_API RzRegrz_reg_new (void)
 
RZ_API bool rz_reg_is_readonly (RzReg *reg, RzRegItem *item)
 
RZ_API ut64 rz_reg_setv (RzReg *reg, const char *name, ut64 val)
 
RZ_API ut64 rz_reg_getv (RzReg *reg, const char *name)
 
RZ_API ut64 rz_reg_getv_by_role_or_name (RzReg *reg, const char *name)
 
RZ_API RzRegItemrz_reg_get (RzReg *reg, const char *name, int type)
 
RZ_API RzRegItemrz_reg_get_by_role_or_name (RzReg *reg, const char *name)
 
RZ_API const RzListrz_reg_get_list (RzReg *reg, int type)
 
RZ_API RzRegItemrz_reg_get_at (RzReg *reg, int type, int regsize, int delta)
 
RZ_API RzRegItemrz_reg_next_diff (RzReg *reg, int type, const ut8 *buf, int buflen, RzRegItem *prev_ri, int regsize)
 
RZ_API RzRegSetrz_reg_regset_get (RzReg *r, int type)
 
static bool foreach_reg_cb (RzIntervalNode *node, void *user)
 
RZ_API RZ_OWN RzListrz_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. More...
 

Variables

static const char * types [RZ_REG_TYPE_LAST+1]
 
static const char * roles [RZ_REG_NAME_LAST+1]
 

Function Documentation

◆ foreach_reg_cb()

static bool foreach_reg_cb ( RzIntervalNode node,
void *  user 
)
static

Definition at line 461 of file reg.c.

461  {
462  RzRegItem *from_list = user;
463  RzRegItem *from_tree = node->data;
464  if (from_list == from_tree) {
465  return true;
466  }
467  // Check if from_list is covered entirely by from_tree, but is also smaller than it.
468  // We already know that
469  // from_tree->offset <= from_list->offset < from_tree->offset + from_tree->size
470  if (from_list->offset + from_list->size > from_tree->offset + from_tree->size) {
471  // from_list expands beyond from_tree, so it's not covered
472  return true;
473  }
474  if (from_list->offset + from_list->size == from_tree->offset + from_tree->size) {
475  // they end at the same position, so it is covered entirely, but is it also smaller?
476  if (from_list->offset == from_tree->offset) {
477  // nope
478  return true;
479  }
480  }
481  // from_list ends before from_tree, so it is covered and smaller
482  return false;
483 }
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120
int offset
Offset into register profile in bits.
Definition: rz_reg.h:121

References rz_interval_node_t::data, rz_reg_item_t::offset, and rz_reg_item_t::size.

Referenced by rz_reg_filter_items_covered().

◆ regcmp()

static int regcmp ( RzRegItem a,
RzRegItem b 
)
static

Definition at line 237 of file reg.c.

237  {
238  int offa = (a->offset * 16) + a->size;
239  int offb = (b->offset * 16) + b->size;
240  return (offa > offb) - (offa < offb);
241 }
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, and b.

Referenced by rz_reg_reindex().

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_reg  )

◆ rz_reg_32_to_64()

RZ_API const char* rz_reg_32_to_64 ( RzReg reg,
const char *  rreg32 
)

Definition at line 17 of file reg.c.

17  {
18  int i, j = -1;
20  RzRegItem *item;
21  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
22  rz_list_foreach (reg->regset[i].regs, iter, item) {
23  if (item->size == 32 && !rz_str_casecmp(rreg32, item->name)) {
24  j = item->offset;
25  break;
26  }
27  }
28  }
29  if (j != -1) {
30  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
31  rz_list_foreach (reg->regset[i].regs, iter, item) {
32  if (item->offset == j && item->size == 64) {
33  return item->name;
34  }
35  }
36  }
37  }
38  return NULL;
39 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
#define reg(n)
@ RZ_REG_TYPE_LAST
Definition: rz_reg.h:34
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
Definition: str.c:121
char * name
Definition: rz_reg.h:118

References i, rz_reg_item_t::name, NULL, rz_reg_item_t::offset, reg, RZ_REG_TYPE_LAST, rz_str_casecmp(), and rz_reg_item_t::size.

Referenced by anop_esil(), get_regname(), and get_src_regname().

◆ rz_reg_64_to_32()

RZ_API const char* rz_reg_64_to_32 ( RzReg reg,
const char *  rreg64 
)

Definition at line 44 of file reg.c.

44  {
45  int i, j = -1;
47  RzRegItem *item;
48  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
49  rz_list_foreach (reg->regset[i].regs, iter, item) {
50  if (item->size == 64 && !rz_str_casecmp(rreg64, item->name)) {
51  j = item->offset;
52  break;
53  }
54  }
55  }
56  if (j != -1) {
57  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
58  rz_list_foreach (reg->regset[i].regs, iter, item) {
59  if (item->offset == j && item->size == 32) {
60  return item->name;
61  }
62  }
63  }
64  }
65  return NULL;
66 }

References i, rz_reg_item_t::name, NULL, rz_reg_item_t::offset, reg, RZ_REG_TYPE_LAST, rz_str_casecmp(), and rz_reg_item_t::size.

Referenced by do_syscall_search().

◆ rz_reg_filter_items_covered()

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.

Parameters
regslist of RzRegItem

Definition at line 489 of file reg.c.

489  {
491  RzList *ret = rz_list_new();
492  if (!ret) {
493  return NULL;
494  }
495  RzIntervalTree t;
497  RzRegItem *item;
498  RzListIter *it;
499  rz_list_foreach (regs, it, item) {
500  if (item->offset < 0 || item->size <= 0) {
501  continue;
502  }
503  rz_interval_tree_insert(&t, item->offset, item->offset + item->size - 1, item);
504  }
505  rz_list_foreach (regs, it, item) {
506  if (item->offset < 0 || item->size <= 0) {
507  rz_list_push(ret, item);
508  continue;
509  }
510  if (!rz_interval_tree_all_in(&t, item->offset, true, foreach_reg_cb, item)) {
511  // foreach_reg_cb break-ed so it found a cover
512  continue;
513  }
514  rz_list_push(ret, item);
515  }
517  return ret;
518 }
static char * regs[]
Definition: analysis_sh.c:203
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
static bool foreach_reg_cb(RzIntervalNode *node, void *user)
Definition: reg.c:461
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_interval_tree_all_in(RzIntervalTree *tree, ut64 value, bool end_inclusive, RzIntervalIterCb cb, void *user)
Definition: intervaltree.c:262
RZ_API void rz_interval_tree_init(RzIntervalTree *tree, RzIntervalNodeFree free)
Definition: intervaltree.c:101
RZ_API bool rz_interval_tree_insert(RzIntervalTree *tree, ut64 start, ut64 end, void *data)
Definition: intervaltree.c:121
RZ_API void rz_interval_tree_fini(RzIntervalTree *tree)
Definition: intervaltree.c:114

References foreach_reg_cb(), NULL, rz_reg_item_t::offset, regs, rz_interval_tree_all_in(), rz_interval_tree_fini(), rz_interval_tree_init(), rz_interval_tree_insert(), rz_list_new(), rz_list_push(), rz_return_val_if_fail, and rz_reg_item_t::size.

Referenced by filter_reg_items(), rz_core_debug_print_status(), and rz_il_reg_binding_derive().

◆ rz_reg_free()

RZ_API void rz_reg_free ( RzReg reg)

Definition at line 279 of file reg.c.

279  {
280  if (reg) {
281  rz_reg_free_internal(reg, false);
282  free(reg);
283  }
284 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_reg_free_internal(RzReg *reg, bool init)
Definition: reg.c:191

References free(), reg, and rz_reg_free_internal().

Referenced by rz_analysis_free(), rz_debug_free(), and setup_regs().

◆ rz_reg_free_internal()

RZ_API void rz_reg_free_internal ( RzReg reg,
bool  init 
)

Definition at line 191 of file reg.c.

191  {
193  ut32 i;
194 
195  rz_list_free(reg->roregs);
196  reg->roregs = NULL;
197  RZ_FREE(reg->reg_profile_str);
198  RZ_FREE(reg->reg_profile_cmt);
199  rz_list_free(reg->reg_profile.alias);
200  rz_list_free(reg->reg_profile.defs);
201  reg->reg_profile.alias = 0;
202  reg->reg_profile.defs = 0;
203 
204  for (i = 0; i < RZ_REG_NAME_LAST; i++) {
205  if (reg->name[i]) {
206  RZ_FREE(reg->name[i]);
207  }
208  }
209  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
210  ht_pp_free(reg->regset[i].ht_regs);
211  reg->regset[i].ht_regs = NULL;
212  if (!reg->regset[i].pool) {
213  continue;
214  }
215  if (init) {
216  rz_list_free(reg->regset[i].regs);
217  reg->regset[i].regs = rz_list_newf((RzListFree)rz_reg_item_free);
218  } else {
219  rz_list_free(reg->regset[i].regs);
220  reg->regset[i].regs = NULL;
221  // Ensure arena is freed and its registered in the pool
222  if (!rz_list_delete_data(reg->regset[i].pool, reg->regset[i].arena)) {
223  rz_reg_arena_free(reg->regset[i].arena);
224  }
225  reg->regset[i].arena = NULL;
226  rz_list_free(reg->regset[i].pool);
227  reg->regset[i].pool = NULL;
228  }
229  }
230  if (!init) {
231  rz_list_free(reg->allregs);
232  reg->allregs = NULL;
233  }
234  reg->size = 0;
235 }
RZ_API void rz_reg_arena_free(RzRegArena *ra)
Definition: arena.c:189
uint32_t ut32
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 bool rz_list_delete_data(RZ_NONNULL RzList *list, void *ptr)
Deletes an entry in the list by searching for a pointer.
Definition: list.c:148
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_reg_item_free(RzRegItem *item)
Definition: reg.c:96
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
@ RZ_REG_NAME_LAST
Definition: rz_reg.h:71
#define RZ_FREE(x)
Definition: rz_types.h:369
bool init
Definition: core.c:77

References i, init, NULL, reg, RZ_FREE, rz_list_delete_data(), rz_list_free(), rz_list_newf(), rz_reg_arena_free(), rz_reg_item_free(), RZ_REG_NAME_LAST, RZ_REG_TYPE_LAST, and rz_return_if_fail.

Referenced by rz_reg_free(), and rz_reg_set_profile_string().

◆ rz_reg_get()

RZ_API RzRegItem* rz_reg_get ( RzReg reg,
const char *  name,
int  type 
)

Definition at line 344 of file reg.c.

344  {
345  int i, e;
347  // TODO: define flag register as RZ_REG_TYPE_FLG
348  if (type == RZ_REG_TYPE_FLG) {
350  }
351  if (type == -1) {
352  i = 0;
354  int alias = rz_reg_get_name_idx(name);
355  if (alias != -1) {
356  const char *nname = rz_reg_get_name(reg, alias);
357  if (nname) {
358  name = nname;
359  }
360  }
361  } else {
362  i = type;
363  e = type + 1;
364  }
365  for (; i < e; i++) {
366  HtPP *pp = reg->regset[i].ht_regs;
367  if (pp) {
368  bool found = false;
369  RzRegItem *item = ht_pp_find(pp, name, &found);
370  if (found) {
371  return item;
372  }
373  }
374  }
375  return NULL;
376 }
#define e(frag)
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
int type
Definition: mipsasm.c:17
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API int rz_reg_get_name_idx(const char *type)
Definition: reg.c:102
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
@ RZ_REG_TYPE_FLG
Definition: rz_reg.h:27
Definition: z80asm.h:102

References e, found, i, NULL, reg, rz_reg_get_name(), rz_reg_get_name_idx(), RZ_REG_TYPE_FLG, RZ_REG_TYPE_GPR, RZ_REG_TYPE_LAST, rz_return_val_if_fail, and type.

Referenced by agraph_refresh(), analysis_fill_ai_rg(), analysis_fill_r0_reg_ref(), analysis_regrel_jump(), anop_esil(), backtrace_fuzzy(), backtrace_x86_32(), backtrace_x86_32_analysis(), backtrace_x86_64(), backtrace_x86_64_analysis(), cmd_print_format(), cs_reg2reg(), esil_6502_init(), esil_bigger(), esil_bigger_equal(), esil_cmp(), esil_gb_init(), esil_internal_sizeof_reg(), esil_smaller(), esil_smaller_equal(), filter_reg_items(), gb_analysis_add_hl(), gb_analysis_add_sp(), gb_analysis_and_bit(), gb_analysis_and_res(), gb_analysis_cb_rl(), gb_analysis_cb_rlc(), gb_analysis_cb_rr(), gb_analysis_cb_rrc(), gb_analysis_cb_sla(), gb_analysis_cb_sra(), gb_analysis_cb_srl(), gb_analysis_cb_swap(), gb_analysis_cond(), gb_analysis_id(), gb_analysis_jmp_hl(), gb_analysis_load(), gb_analysis_load_hl(), gb_analysis_mov_hl_sp(), gb_analysis_mov_ime(), gb_analysis_mov_imm(), gb_analysis_mov_reg(), gb_analysis_mov_scf(), gb_analysis_mov_sp_hl(), gb_analysis_or_set(), gb_analysis_pp(), gb_analysis_store(), gb_analysis_store_hl(), gb_analysis_xoaasc(), gb_analysis_xoaasc_imm(), gb_analysis_xor_ccf(), gb_analysis_xor_cpl(), get_regname(), get_src_regname(), getFunctionNamePrefix(), i8051_reg_read(), i8051_reg_write(), internal_esil_reg_read(), internal_esil_reg_write(), internal_esil_reg_write_no_null(), ispackedreg(), mips_op(), num_callback(), parse_reg64_name(), parse_reg_name(), pic_midrange_reg_write(), retype_callee_arg(), riscv_op(), rsp_op(), run_basic_block_analysis(), rz_analysis_dwarf_integrate_functions(), rz_analysis_esil_get_parm_type(), rz_analysis_esil_trace_op(), rz_analysis_extract_rarg(), rz_analysis_function_rebase_vars(), rz_analysis_function_vars_regs_getref_handler(), rz_analysis_function_vars_regs_handler(), rz_analysis_function_vars_regs_setref_handler(), rz_analysis_get_delta_jmptbl_info(), rz_analysis_get_jmptbl_info(), rz_analysis_var_get_argnum(), rz_core_analysis_set_reg(), rz_core_analysis_type_match(), rz_core_disasm_pde(), rz_core_esil_continue_back(), rz_core_link_stroff(), rz_core_reg_assign_sync(), rz_core_rtr_gdb_cb(), rz_debug_add_checkpoint(), rz_debug_continue_back(), rz_debug_continue_kill(), rz_debug_execute(), rz_debug_gdb_reg_write(), rz_debug_qnx_reg_write(), rz_debug_wait(), rz_il_reg_binding_exactly(), rz_il_vm_sync_from_reg(), rz_il_vm_sync_to_reg(), rz_main_rizin(), rz_reg_get_by_role(), rz_reg_get_by_role_or_name(), rz_reg_get_value_by_role(), rz_reg_getv(), rz_reg_set_profile_string(), rz_reg_set_value_by_role(), rz_reg_setv(), rz_regs_args_handler(), rz_regs_fpu_handler(), set_retval(), trace_hook_reg_write(), value_fill_addr_reg_disp(), and value_fill_addr_reg_regdelta().

◆ rz_reg_get_at()

RZ_API RzRegItem* rz_reg_get_at ( RzReg reg,
int  type,
int  regsize,
int  delta 
)

Definition at line 414 of file reg.c.

414  {
416  const RzList *list = rz_reg_get_list(reg, type);
417  RzRegItem *ri;
418  RzListIter *iter;
419  rz_list_foreach (list, iter, ri) {
420  if (ri->size == regsize) {
421  if (BITS2BYTES(ri->offset) == delta) {
422  return ri;
423  }
424  }
425  }
426  return NULL;
427 }
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
Definition: reg.c:389
#define BITS2BYTES(x)
Definition: rz_types.h:280
static st64 delta
Definition: vmenus.c:2425

References BITS2BYTES, delta, list(), NULL, rz_reg_item_t::offset, reg, rz_reg_get_list(), rz_return_val_if_fail, rz_reg_item_t::size, and type.

◆ rz_reg_get_by_role()

RZ_API RzRegItem* rz_reg_get_by_role ( RzReg reg,
RzRegisterId  role 
)

Definition at line 154 of file reg.c.

154  {
156  const char *name = rz_reg_get_name(reg, role);
157  if (!name) {
158  return NULL;
159  }
161 }
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35

References NULL, reg, rz_reg_get(), rz_reg_get_name(), RZ_REG_TYPE_ANY, and rz_return_val_if_fail.

Referenced by rz_core_reg_flags_candidates(), rz_debug_continue_syscalls(), and rz_reg_get_by_role_or_name().

◆ rz_reg_get_by_role_or_name()

RZ_API RzRegItem* rz_reg_get_by_role_or_name ( RzReg reg,
const char *  name 
)

Definition at line 378 of file reg.c.

378  {
379  int role = rz_reg_get_name_idx(name);
380  if (role != -1) {
381  RzRegItem *r = rz_reg_get_by_role(reg, role);
382  if (r) {
383  return r;
384  }
385  }
387 }
#define r
Definition: crypto_rc6.c:12
RZ_API RzRegItem * rz_reg_get_by_role(RzReg *reg, RzRegisterId role)
Definition: reg.c:154

References r, reg, rz_reg_get(), rz_reg_get_by_role(), rz_reg_get_name_idx(), and RZ_REG_TYPE_ANY.

Referenced by rz_core_reg_set_by_role_or_name(), rz_debug_num_callback(), rz_debug_reg_set(), and rz_reg_getv_by_role_or_name().

◆ rz_reg_get_list()

RZ_API const RzList* rz_reg_get_list ( RzReg reg,
int  type 
)

Definition at line 389 of file reg.c.

389  {
390  if (type == RZ_REG_TYPE_ANY) {
391  return reg->allregs;
392  }
393 
394  RzList *regs;
395  int i, mask;
396  if (type < 0 || type > (RZ_REG_TYPE_LAST - 1)) {
397  return NULL;
398  }
399 
400  regs = reg->regset[type].regs;
401  if (rz_list_length(regs) == 0) {
402  mask = ((int)1 << type);
403  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
404  if (reg->regset[i].maskregstype & mask) {
405  regs = reg->regset[i].regs;
406  }
407  }
408  }
409 
410  return regs;
411 }
#define mask()
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
static int
Definition: sfsocketcall.h:114

References i, int, mask, NULL, reg, regs, rz_list_length(), RZ_REG_TYPE_ANY, RZ_REG_TYPE_LAST, and type.

Referenced by autocmplt_reg(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), fillRegisterValues(), filter(), foreach_reg_set_or_clear(), rop_classify_arithmetic(), rop_classify_arithmetic_const(), rop_classify_constant(), rop_classify_mov(), rz_core_cmd_foreach3(), rz_core_debug_ri(), rz_core_reg_flags_candidates(), and rz_reg_get_at().

◆ rz_reg_get_name()

RZ_API const char* rz_reg_get_name ( RzReg reg,
int  role 
)

Definition at line 147 of file reg.c.

147  {
148  if (reg && role >= 0 && role < RZ_REG_NAME_LAST) {
149  return reg->name[role];
150  }
151  return NULL;
152 }

References NULL, reg, and RZ_REG_NAME_LAST.

Referenced by __init_panel_param(), __panels_check_stackbase(), __replaceRegisters(), agraph_refresh(), analysis_emul_init(), asciiart_backtrace(), backtrace_fuzzy(), backtrace_vars(), backtrace_windows(), do_syscall_search(), ds_print_esil_analysis(), ds_print_esil_analysis_fini(), ds_print_esil_analysis_init(), extract_arg(), filter_reg_items(), get_reg_role_name(), getpcfromstack(), internal_esil_reg_write_no_null(), linux_handle_signals(), list_vars(), num_callback(), prepend_current_pc(), rz_analysis_extract_vars(), rz_analysis_function_get_json(), rz_analysis_function_vars_handler(), rz_analysis_var_addr(), rz_core_analysis_continue_until_call(), rz_core_analysis_continue_until_syscall(), rz_core_analysis_esil(), rz_core_analysis_esil_emulate(), rz_core_analysis_esil_step_over(), rz_core_analysis_set_reg(), rz_core_analysis_type_match(), rz_core_esil_step(), rz_core_get_func_args(), rz_core_link_stroff(), rz_core_print_disasm(), rz_core_print_func_args(), rz_core_syscall_as_string(), rz_debug_gdb_reg_write(), rz_debug_qnx_reg_write(), rz_debug_step_soft(), rz_il_reg_binding_derive(), rz_il_vm_sync_from_reg(), rz_il_vm_sync_to_reg(), rz_reg_get(), rz_reg_get_by_role(), rz_reg_get_name_by_type(), rz_reg_get_value_by_role(), rz_reg_set_value_by_role(), rz_regs_args_handler(), and type_pos_hit().

◆ rz_reg_get_name_by_type()

RZ_API const char* rz_reg_get_name_by_type ( RzReg reg,
const char *  alias_name 
)

Definition at line 72 of file reg.c.

72  {
73  const int n = rz_reg_get_name_idx(alias_name);
74  return (n != -1) ? rz_reg_get_name(reg, n) : NULL;
75 }
int n
Definition: mipsasm.c:19

References n, NULL, reg, rz_reg_get_name(), and rz_reg_get_name_idx().

Referenced by rz_reg_profile_to_cc().

◆ rz_reg_get_name_idx()

RZ_API int rz_reg_get_name_idx ( const char *  type)

Definition at line 102 of file reg.c.

102  {
104  if (type[0] && type[1] && !type[2])
105  switch (*type | (type[1] << 8)) {
106  /* flags */
107  case 'Z' + ('F' << 8): return RZ_REG_NAME_ZF;
108  case 'S' + ('F' << 8): return RZ_REG_NAME_SF;
109  case 'C' + ('F' << 8): return RZ_REG_NAME_CF;
110  case 'O' + ('F' << 8): return RZ_REG_NAME_OF;
111  /* gpr */
112  case 'P' + ('C' << 8): return RZ_REG_NAME_PC;
113  case 'S' + ('R' << 8): return RZ_REG_NAME_SR;
114  case 'L' + ('R' << 8): return RZ_REG_NAME_LR;
115  case 'S' + ('P' << 8): return RZ_REG_NAME_SP;
116  case 'B' + ('P' << 8): return RZ_REG_NAME_BP;
117  case 'S' + ('N' << 8): return RZ_REG_NAME_SN;
118  /* args */
119  case 'A' + ('0' << 8): return RZ_REG_NAME_A0;
120  case 'A' + ('1' << 8): return RZ_REG_NAME_A1;
121  case 'A' + ('2' << 8): return RZ_REG_NAME_A2;
122  case 'A' + ('3' << 8): return RZ_REG_NAME_A3;
123  case 'A' + ('4' << 8): return RZ_REG_NAME_A4;
124  case 'A' + ('5' << 8): return RZ_REG_NAME_A5;
125  case 'A' + ('6' << 8): return RZ_REG_NAME_A6;
126  case 'A' + ('7' << 8): return RZ_REG_NAME_A7;
127  case 'A' + ('8' << 8): return RZ_REG_NAME_A8;
128  case 'A' + ('9' << 8): return RZ_REG_NAME_A9;
129  /* return values */
130  case 'R' + ('0' << 8): return RZ_REG_NAME_R0;
131  case 'R' + ('1' << 8): return RZ_REG_NAME_R1;
132  case 'R' + ('2' << 8): return RZ_REG_NAME_R2;
133  case 'R' + ('3' << 8): return RZ_REG_NAME_R3;
134  }
135  return -1;
136 }
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_A4
Definition: rz_reg.h:53
@ RZ_REG_NAME_SN
Definition: rz_reg.h:70
@ RZ_REG_NAME_A9
Definition: rz_reg.h:58
@ RZ_REG_NAME_A5
Definition: rz_reg.h:54
@ RZ_REG_NAME_A6
Definition: rz_reg.h:55
@ RZ_REG_NAME_A3
Definition: rz_reg.h:52
@ RZ_REG_NAME_A2
Definition: rz_reg.h:51
@ RZ_REG_NAME_BP
Definition: rz_reg.h:46
@ RZ_REG_NAME_ZF
Definition: rz_reg.h:65
@ RZ_REG_NAME_OF
Definition: rz_reg.h:68
@ RZ_REG_NAME_R2
Definition: rz_reg.h:62
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
@ RZ_REG_NAME_R1
Definition: rz_reg.h:61
@ RZ_REG_NAME_A1
Definition: rz_reg.h:50
@ RZ_REG_NAME_CF
Definition: rz_reg.h:67
@ RZ_REG_NAME_SF
Definition: rz_reg.h:66
@ RZ_REG_NAME_A7
Definition: rz_reg.h:56
@ RZ_REG_NAME_SR
Definition: rz_reg.h:45
@ RZ_REG_NAME_LR
Definition: rz_reg.h:47
@ RZ_REG_NAME_A8
Definition: rz_reg.h:57
@ RZ_REG_NAME_A0
Definition: rz_reg.h:49
@ RZ_REG_NAME_R0
Definition: rz_reg.h:60
@ RZ_REG_NAME_R3
Definition: rz_reg.h:63

References RZ_REG_NAME_A0, RZ_REG_NAME_A1, RZ_REG_NAME_A2, RZ_REG_NAME_A3, RZ_REG_NAME_A4, RZ_REG_NAME_A5, RZ_REG_NAME_A6, RZ_REG_NAME_A7, RZ_REG_NAME_A8, RZ_REG_NAME_A9, RZ_REG_NAME_BP, RZ_REG_NAME_CF, RZ_REG_NAME_LR, RZ_REG_NAME_OF, RZ_REG_NAME_PC, RZ_REG_NAME_R0, RZ_REG_NAME_R1, RZ_REG_NAME_R2, RZ_REG_NAME_R3, RZ_REG_NAME_SF, RZ_REG_NAME_SN, RZ_REG_NAME_SP, RZ_REG_NAME_SR, RZ_REG_NAME_ZF, rz_return_val_if_fail, and type.

Referenced by num_callback(), parse_alias(), rz_analysis_function_get_json(), rz_core_analysis_set_reg(), rz_reg_get(), rz_reg_get_by_role_or_name(), and rz_reg_get_name_by_type().

◆ rz_reg_get_role()

RZ_API const char* rz_reg_get_role ( int  role)

Definition at line 172 of file reg.c.

172  {
173  if (role >= 0 && role < RZ_REG_NAME_LAST) {
174  return roles[role];
175  }
176  return NULL;
177 }
static const char * roles[RZ_REG_NAME_LAST+1]
Definition: reg.c:163

References NULL, roles, and RZ_REG_NAME_LAST.

Referenced by __replaceRegisters(), autocmplt_cmd_arg_reg_filter(), get_reg_role_name(), rz_reg_profile_handler(), and rz_reg_roles_handler().

◆ rz_reg_get_type()

RZ_API const char* rz_reg_get_type ( int  idx)

Definition at line 68 of file reg.c.

68  {
69  return (idx >= 0 && idx < RZ_REG_TYPE_LAST) ? types[idx] : NULL;
70 }
int idx
Definition: setup.py:197
static const char * types[RZ_REG_TYPE_LAST+1]
Definition: reg.c:10

References setup::idx, NULL, RZ_REG_TYPE_LAST, and types.

Referenced by autocmplt_cmd_arg_reg_filter(), autocmplt_cmd_arg_reg_type(), isFlag(), rz_reg_arenas_handler(), rz_reg_profile_handler(), rz_reg_types_handler(), and show_regs_handler().

◆ rz_reg_getv()

◆ rz_reg_getv_by_role_or_name()

RZ_API ut64 rz_reg_getv_by_role_or_name ( RzReg reg,
const char *  name 
)

Definition at line 338 of file reg.c.

338  {
341  return ri ? rz_reg_get_value(reg, ri) : UT64_MAX;
342 }
RZ_API RzRegItem * rz_reg_get_by_role_or_name(RzReg *reg, const char *name)
Definition: reg.c:378

References reg, rz_reg_get_by_role_or_name(), rz_reg_get_value(), rz_return_val_if_fail, and UT64_MAX.

Referenced by backtrace_generic(), rz_core_reg_getv_by_role_or_name(), and rz_debug_reg_get().

◆ rz_reg_index_get()

RZ_API RzRegItem* rz_reg_index_get ( RzReg reg,
int  idx 
)

Definition at line 262 of file reg.c.

262  {
263  RzRegItem *r;
264  RzListIter *iter;
265  if (idx < 0) {
266  return NULL;
267  }
268  if (!reg->allregs) {
270  }
271  rz_list_foreach (reg->allregs, iter, r) {
272  if (r->index == idx) {
273  return r;
274  }
275  }
276  return NULL;
277 }
RZ_API void rz_reg_reindex(RzReg *reg)
Definition: reg.c:243

References setup::idx, NULL, r, reg, and rz_reg_reindex().

Referenced by core_analysis_var_list_show(), ds_show_functions(), rz_analysis_function_set_var(), rz_core_analysis_type_match(), rz_core_analysis_var_display(), and var_variables_show().

◆ rz_reg_is_readonly()

RZ_API bool rz_reg_is_readonly ( RzReg reg,
RzRegItem item 
)

Definition at line 311 of file reg.c.

311  {
312  const char *name;
313  RzListIter *iter;
314  if (!reg->roregs) {
315  return false;
316  }
317  // XXX O(n)
318  rz_list_foreach (reg->roregs, iter, name) {
319  if (!strcmp(item->name, name)) {
320  return true;
321  }
322  }
323  return false;
324 }
const char * name
Definition: op.c:541

References name, rz_reg_item_t::name, and reg.

Referenced by rz_reg_set_value().

◆ rz_reg_item_free()

RZ_API void rz_reg_item_free ( RzRegItem item)

Definition at line 96 of file reg.c.

96  {
97  free(item->name);
98  free(item->flags);
99  free(item);
100 }
char * flags
Definition: rz_reg.h:124

References rz_reg_item_t::flags, free(), and rz_reg_item_t::name.

Referenced by add_item_to_regset(), rz_reg_free_internal(), and rz_reg_new().

◆ rz_reg_new()

RZ_API RzReg* rz_reg_new ( void  )

Definition at line 286 of file reg.c.

286  {
287  RzRegArena *arena;
288  RzReg *reg = RZ_NEW0(RzReg);
289  int i;
290  if (!reg) {
291  return NULL;
292  }
293  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
294  arena = rz_reg_arena_new(0);
295  if (!arena) {
296  free(reg);
297  return NULL;
298  }
299  reg->regset[i].pool = rz_list_newf((RzListFree)rz_reg_arena_free);
300  reg->regset[i].regs = rz_list_newf((RzListFree)rz_reg_item_free);
301  rz_list_push(reg->regset[i].pool, arena);
302  reg->regset[i].arena = arena;
303  }
305  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
306  reg->regset[i].cur = rz_list_tail(reg->regset[i].pool);
307  }
308  return reg;
309 }
RZ_API int rz_reg_arena_push(RzReg *reg)
Definition: arena.c:236
RZ_API RzRegArena * rz_reg_arena_new(size_t size)
Definition: arena.c:170
#define RZ_NEW0(x)
Definition: rz_types.h:284

References free(), i, NULL, reg, rz_list_newf(), rz_list_push(), RZ_NEW0, rz_reg_arena_free(), rz_reg_arena_new(), rz_reg_arena_push(), rz_reg_item_free(), and RZ_REG_TYPE_LAST.

Referenced by rz_analysis_new(), rz_debug_new(), and setup_regs().

◆ rz_reg_next_diff()

RZ_API RzRegItem* rz_reg_next_diff ( RzReg reg,
int  type,
const ut8 buf,
int  buflen,
RzRegItem prev_ri,
int  regsize 
)

Definition at line 430 of file reg.c.

430  {
432  if (type < 0 || type > (RZ_REG_TYPE_LAST - 1)) {
433  return NULL;
434  }
435  RzRegArena *arena = reg->regset[type].arena;
436  int prev_offset = prev_ri ? (prev_ri->offset / 8) + (prev_ri->size / 8) : 0;
437  RzList *list = reg->regset[type].regs;
438  RzRegItem *ri;
439  RzListIter *iter;
440  int offset;
441  rz_list_foreach (list, iter, ri) {
442  offset = ri->offset / 8;
443  if (offset > prev_offset) {
444  if (memcmp(arena->bytes + offset, buf + offset, ri->size / 8)) {
445  return ri;
446  }
447  }
448  }
449  return NULL;
450 }
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
ut8 * bytes
Definition: rz_reg.h:131

References rz_reg_arena_t::bytes, list(), NULL, rz_reg_item_t::offset, reg, RZ_REG_TYPE_LAST, rz_return_val_if_fail, rz_reg_item_t::size, and type.

Referenced by rz_debug_gdb_reg_write(), and rz_debug_qnx_reg_write().

◆ rz_reg_regset_get()

RZ_API RzRegSet* rz_reg_regset_get ( RzReg r,
int  type 
)

Definition at line 452 of file reg.c.

452  {
454  if (type < 0 || type >= RZ_REG_TYPE_LAST) {
455  return NULL;
456  }
457  RzRegSet *rs = &r->regset[type];
458  return rs->arena ? rs : NULL;
459 }
#define rs()

References NULL, r, rs, RZ_REG_TYPE_LAST, rz_return_val_if_fail, and type.

Referenced by ds_print_esil_analysis_fini(), ds_print_esil_analysis_init(), rz_core_analysis_address(), rz_reg_arena_dup(), rz_reg_arena_peek(), and rz_reg_arena_poke().

◆ rz_reg_reindex()

RZ_API void rz_reg_reindex ( RzReg reg)

Definition at line 243 of file reg.c.

243  {
244  int i, index;
245  RzListIter *iter;
246  RzRegItem *r;
248  for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
249  rz_list_foreach (reg->regset[i].regs, iter, r) {
250  rz_list_append(all, r);
251  }
252  }
254  index = 0;
255  rz_list_foreach (all, iter, r) {
256  r->index = index++;
257  }
258  rz_list_free(reg->allregs);
259  reg->allregs = all;
260 }
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
Definition: list.c:743
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
static int regcmp(RzRegItem *a, RzRegItem *b)
Definition: reg.c:237
int(* RzListComparator)(const void *value, const void *list_data)
Definition: rz_list.h:33

References test_group_name::all, i, NULL, r, reg, regcmp(), rz_list_append(), rz_list_free(), rz_list_newf(), rz_list_sort(), and RZ_REG_TYPE_LAST.

Referenced by rz_reg_index_get(), and rz_reg_set_profile_string().

◆ rz_reg_role_by_name()

RZ_API int rz_reg_role_by_name ( RZ_NONNULL const char *  str)

Get the RzRegisterId with the given name or -1.

Definition at line 180 of file reg.c.

180  {
182  int i;
183  for (i = 0; i < RZ_REG_NAME_LAST && roles[i]; i++) {
184  if (!strcmp(roles[i], str)) {
185  return i;
186  }
187  }
188  return -1;
189 }

References i, roles, RZ_REG_NAME_LAST, rz_return_val_if_fail, and cmd_descs_generate::str.

Referenced by filter_reg_items().

◆ rz_reg_set_name()

RZ_API bool rz_reg_set_name ( RZ_NONNULL RzReg reg,
RzRegisterId  role,
RZ_NONNULL const char *  name 
)

Definition at line 138 of file reg.c.

138  {
139  rz_return_val_if_fail(reg && name, false);
140  if (role >= 0 && role < RZ_REG_NAME_LAST) {
141  reg->name[role] = rz_str_dup(reg->name[role], name);
142  return true;
143  }
144  return false;
145 }
RZ_API char * rz_str_dup(char *ptr, const char *string)
Definition: str.c:1021

References reg, RZ_REG_NAME_LAST, rz_return_val_if_fail, and rz_str_dup().

Referenced by rz_reg_set_reg_profile().

◆ rz_reg_setv()

RZ_API ut64 rz_reg_setv ( RzReg reg,
const char *  name,
ut64  val 
)

◆ rz_reg_type_by_name()

RZ_API int rz_reg_type_by_name ( const char *  str)

Returns the register type for the given type abbreviation.

Parameters
strThe type abbreviation (gpr, flg, sys etc.)
Returns
int The register type or -1 on failure.

Definition at line 83 of file reg.c.

83  {
85  for (ut32 i = 0; i < RZ_REG_TYPE_LAST && types[i]; i++) {
86  if (!strcmp(types[i], str)) {
87  return i;
88  }
89  }
90  if (!strcmp(str, "all")) {
91  return RZ_REG_TYPE_ANY;
92  }
93  return -1;
94 }

References i, RZ_REG_TYPE_ANY, RZ_REG_TYPE_LAST, rz_return_val_if_fail, cmd_descs_generate::str, and types.

Referenced by expect_reg_type_by_name(), filter_reg_items(), rz_reg_arenas_hexdump_handler(), rz_reg_arenas_write_hex_handler(), and rz_reg_arenas_zero_handler().

Variable Documentation

◆ roles

const char* roles[RZ_REG_NAME_LAST+1]
static
Initial value:
= {
"PC", "SP", "SR", "BP", "LR",
"A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9",
"R0", "R1", "R2", "R3",
"ZF", "SF", "CF", "OF",
"SN",
}

Definition at line 163 of file reg.c.

Referenced by rz_reg_get_role(), and rz_reg_role_by_name().

◆ types

const char* types[RZ_REG_TYPE_LAST+1]
static
Initial value:
= {
"gpr", "drx", "fpu", "mmx", "xmm", "ymm", "flg", "seg", "sys", "sec", "vc", "vcc", "ctr", NULL
}

Definition at line 10 of file reg.c.

Referenced by rz_reg_get_type(), and rz_reg_type_by_name().