Rizin
unix-like reverse engineering framework and cli tools
creg.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 Florian Märkl <info@florianmaerkl.de>
2 // SPDX-FileCopyrightText: 2021 ret2libc <sirmy15@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_core.h>
6 #include "core_private.h"
7 
18  return rz_core_is_debug(core) ? core->dbg->reg : core->analysis->reg;
19 }
20 
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 }
32 
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 }
57 
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 }
81 
82 static void regs_to_flags(RzCore *core, RzReg *regs) {
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 }
98 
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 }
112 
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 int rz_analysis_get_address_bits(RzAnalysis *analysis)
The actual size of an address in bits.
Definition: analysis.c:303
static char * regs[]
Definition: analysis_sh.c:203
#define RZ_IPI
Definition: analysis_wasm.c:11
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
Definition: arena.c:196
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
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define RZ_API
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 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 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: creg.c:24
RZ_API bool rz_core_reg_set_by_role_or_name(RzCore *core, const char *name, ut64 num)
set on rz_core_reg_default()
Definition: creg.c:39
RZ_IPI RzList * rz_core_reg_flags_candidates(RzCore *core, RzReg *reg)
Definition: creg.c:60
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
#define NULL
Definition: cris-opc.c:27
RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name)
Definition: dreg.c:99
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
Definition: dreg.c:9
RZ_API int rz_debug_reg_set(struct rz_debug_t *dbg, const char *name, ut64 num)
Definition: dreg.c:89
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
voidpf void uLong size
Definition: ioapi.h:138
#define reg(n)
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 void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
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(RzReg *reg, RzRegisterId role)
Definition: reg.c:154
RZ_API RzRegItem * rz_reg_get_by_role_or_name(RzReg *reg, const char *name)
Definition: reg.c:378
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
Definition: reg.c:389
RZ_API ut64 rz_reg_getv_by_role_or_name(RzReg *reg, const char *name)
Definition: reg.c:338
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186
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
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
RZ_API RzSpace * rz_spaces_get(RzSpaces *sp, const char *name)
Definition: spaces.c:82
#define PFMT64x
Definition: rz_types.h:393
Definition: z80asm.h:102
RzAnalysis * analysis
Definition: rz_core.h:322
RzDebug * dbg
Definition: rz_core.h:329
RzFlag * flags
Definition: rz_core.h:330
RzReg * reg
Definition: rz_debug.h:286
RzSpaces spaces
Definition: rz_flag.h:47
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120
char * name
Definition: rz_reg.h:118
static st64 delta
Definition: vmenus.c:2425
ut64(WINAPI *w32_GetEnabledXStateFeatures)()