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

Go to the source code of this file.

Functions

static bool load_theme (RzCore *core, const char *path)
 
static bool pal_seek (RzCore *core, RzConsPalSeekMode mode, const char *file, RzListIter *iter)
 
RZ_API bool rz_core_theme_load (RzCore *core, const char *name)
 
static void list_themes_in_path (HtPU *themes, const char *path)
 
RZ_API char * rz_core_theme_get (RzCore *core)
 
static bool dict2keylist (void *user, const void *key, const ut64 value)
 
RZ_API RZ_OWN RzListrz_core_theme_list (RZ_NONNULL RzCore *core)
 Returns the list of the rizin themes. More...
 
RZ_API void rz_core_theme_nextpal (RzCore *core, RzConsPalSeekMode mode)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_list_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_display_palette_css_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_set_default_palette_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_set_random_palette_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_set_colorful_palette_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_load_previous_theme_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_load_next_theme_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_list_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_load_theme_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_list_current_theme_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_list_reload_current_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_current_instruction_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_instruction_word_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_list_current_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_remove_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_remove_current_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_eval_getset_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_eval_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_eval_reset_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_eval_bool_invert_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_eval_editor_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_eval_readonly_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_eval_spaces_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_eval_type_handler (RzCore *core, int argc, const char **argv)
 

Function Documentation

◆ dict2keylist()

static bool dict2keylist ( void *  user,
const void *  key,
const ut64  value 
)
static

Definition at line 107 of file cmd_eval.c.

107  {
108  RzList *list = (RzList *)user;
110  return true;
111 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
static void list(RzEgg *egg)
Definition: rz-gg.c:52
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
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")

References key, list(), rz_list_append(), and strdup().

Referenced by rz_core_theme_list().

◆ list_themes_in_path()

static void list_themes_in_path ( HtPU *  themes,
const char *  path 
)
static

Definition at line 91 of file cmd_eval.c.

91  {
93  const char *fn;
95  rz_list_foreach (files, iter, fn) {
96  if (*fn && *fn != '.') {
97  ht_pu_insert(themes, fn, 1);
98  }
99  }
101 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
Definition: file_opts.h:46
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
RZ_API RzList * rz_sys_dir(const char *path)
Definition: sys.c:216

References files, fn, path, rz_list_free(), and rz_sys_dir().

Referenced by rz_core_theme_list().

◆ load_theme()

static bool load_theme ( RzCore core,
const char *  path 
)
static

Definition at line 9 of file cmd_eval.c.

9  {
10  if (!rz_file_exists(path)) {
11  return false;
12  }
13  core->cmdfilter = "ec ";
14  bool res = rz_core_cmd_file(core, path);
15  if (res) {
17  }
18  core->cmdfilter = NULL;
19  return res;
20 }
RZ_API int rz_core_cmd_file(RzCore *core, const char *file)
Definition: cmd.c:5341
#define NULL
Definition: cris-opc.c:27
RZ_API void rz_cons_pal_update_event(void)
Definition: pal.c:652
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
char * cmdfilter
Definition: rz_core.h:371

References rz_core_t::cmdfilter, NULL, path, rz_cons_pal_update_event(), rz_core_cmd_file(), and rz_file_exists().

Referenced by rz_core_theme_load().

◆ pal_seek()

static bool pal_seek ( RzCore core,
RzConsPalSeekMode  mode,
const char *  file,
RzListIter iter 
)
static

Definition at line 22 of file cmd_eval.c.

22  {
23  const char *fn = rz_str_lchr(file, '/');
24  if (!fn) {
25  fn = file;
26  }
27  switch (mode) {
29  const char *next_fn = iter->n ? iter->n->data : NULL;
30  if (!core->curtheme) {
31  return true;
32  }
33  if (next_fn && !strcmp(next_fn, core->curtheme)) {
34  free(core->curtheme);
35  core->curtheme = strdup(fn);
36  return false;
37  }
38  break;
39  }
40  case RZ_CONS_PAL_SEEK_NEXT: {
41  const char *prev_fn = iter->p ? iter->p->data : NULL;
42  if (!core->curtheme) {
43  return true;
44  }
45  if (prev_fn && !strcmp(prev_fn, core->curtheme)) {
46  free(core->curtheme);
47  core->curtheme = strdup(fn);
48  return false;
49  }
50  break;
51  }
52  }
53  return true;
54 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
const char int mode
Definition: ioapi.h:137
@ RZ_CONS_PAL_SEEK_NEXT
Definition: rz_cons.h:462
@ RZ_CONS_PAL_SEEK_PREVIOUS
Definition: rz_cons.h:461
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
Definition: gzappend.c:170
char * curtheme
Definition: rz_core.h:372
static int file
Definition: z80asm.c:58

References rz_core_t::curtheme, file, fn, free(), NULL, RZ_CONS_PAL_SEEK_NEXT, RZ_CONS_PAL_SEEK_PREVIOUS, rz_str_lchr(), and strdup().

Referenced by rz_core_theme_nextpal().

◆ rz_cmd_eval_color_display_palette_css_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_display_palette_css_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 197 of file cmd_eval.c.

197  {
198  rz_cons_pal_list('c', argv[1]);
199  return RZ_CMD_STATUS_OK;
200 }
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
RZ_API void rz_cons_pal_list(int rad, const char *arg)
Definition: pal.c:528
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24

References argv, RZ_CMD_STATUS_OK, and rz_cons_pal_list().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_highlight_current_instruction_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_current_instruction_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 285 of file cmd_eval.c.

285  {
286  char *dup = rz_str_newf("bgonly %s", argv[1]);
287  char *color_code = rz_cons_pal_parse(dup, NULL);
288  RZ_FREE(dup);
289  if (!color_code) {
290  eprintf("Unknown color %s\n", argv[1]);
291  return RZ_CMD_STATUS_ERROR;
292  }
294  const char *str = rz_meta_get_string(core->analysis, RZ_META_TYPE_HIGHLIGHT, core->offset);
295  dup = rz_str_newf("%s \"%s\"", str ? str : "", color_code ? color_code : rz_cons_singleton()->context->pal.wordhl);
297  RZ_FREE(color_code);
298  RZ_FREE(dup);
299  return RZ_CMD_STATUS_OK;
300 }
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
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 dup
Definition: sflib.h:68
RZ_API const char * rz_meta_get_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr)
Definition: meta.c:146
RZ_API bool rz_meta_set_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, const char *s)
Definition: meta.c:141
RZ_API char * rz_cons_pal_parse(const char *str, RzColor *outcol)
Definition: pal.c:281
#define eprintf(x, y...)
Definition: rlcc.c:7
@ RZ_META_TYPE_HIGHLIGHT
Definition: rz_analysis.h:296
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_FREE(x)
Definition: rz_types.h:369
ut64 offset
Definition: rz_core.h:301
RzAnalysis * analysis
Definition: rz_core.h:322

References rz_core_t::analysis, argv, dup, eprintf, NULL, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_pal_parse(), rz_cons_singleton(), RZ_FREE, rz_meta_get_string(), rz_meta_set_string(), RZ_META_TYPE_HIGHLIGHT, rz_str_newf(), and cmd_descs_generate::str.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_highlight_instruction_word_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_instruction_word_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 302 of file cmd_eval.c.

302  {
303  char *color_code = NULL, *dup = NULL;
304  if (argc == 3) {
305  dup = rz_str_newf("bgonly %s", argv[2]);
306  color_code = rz_cons_pal_parse(dup, NULL);
307  RZ_FREE(dup);
308  if (!color_code) {
309  eprintf("Unknown color %s\n", argv[2]);
310  return RZ_CMD_STATUS_ERROR;
311  }
312  }
314  const char *str = rz_meta_get_string(core->analysis, RZ_META_TYPE_HIGHLIGHT, core->offset);
315  dup = rz_str_newf("%s \"%s%s\"", str, argv[1], color_code ? color_code : rz_cons_singleton()->context->pal.wordhl);
317  RZ_FREE(dup);
318  RZ_FREE(color_code);
319  return RZ_CMD_STATUS_OK;
320 }

References rz_core_t::analysis, argv, dup, eprintf, NULL, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_pal_parse(), rz_cons_singleton(), RZ_FREE, rz_meta_get_string(), rz_meta_set_string(), RZ_META_TYPE_HIGHLIGHT, rz_str_newf(), and cmd_descs_generate::str.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_highlight_list_current_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_list_current_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 322 of file cmd_eval.c.

322  {
323  RzCmdStateOutput state = { 0 };
328  return RZ_CMD_STATUS_OK;
329 }
RZ_API bool rz_cmd_state_output_init(RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.
Definition: cmd_api.c:2634
RZ_API void rz_cmd_state_output_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
Definition: cmd_api.c:2603
RZ_API void rz_cmd_state_output_print(RZ_NONNULL RzCmdStateOutput *state)
Print the output accumulated in state to RzCons, if necessary.
Definition: cmd_api.c:2668
RZ_IPI void rz_core_meta_print_list_in_function(RzCore *core, RzAnalysisMetaType type, ut64 addr, RzCmdStateOutput *state)
Definition: cmeta.c:370
@ RZ_META_TYPE_COMMENT
Definition: rz_analysis.h:295
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
Represent the output state of a command handler.
Definition: rz_cmd.h:91
Definition: dis.h:43

References rz_core_t::offset, rz_cmd_state_output_fini(), rz_cmd_state_output_init(), rz_cmd_state_output_print(), RZ_CMD_STATUS_OK, rz_core_meta_print_list_in_function(), RZ_META_TYPE_COMMENT, and RZ_OUTPUT_MODE_STANDARD.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_highlight_list_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 227 of file cmd_eval.c.

227  {
228  RzCmdStateOutput state = { 0 };
233  return RZ_CMD_STATUS_OK;
234 }
RZ_IPI void rz_core_meta_print_list_all(RzCore *core, RzAnalysisMetaType type, RzCmdStateOutput *state)
Definition: cmeta.c:364

References rz_cmd_state_output_fini(), rz_cmd_state_output_init(), rz_cmd_state_output_print(), RZ_CMD_STATUS_OK, rz_core_meta_print_list_all(), and RZ_META_TYPE_HIGHLIGHT.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_highlight_remove_all_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_remove_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 331 of file cmd_eval.c.

331  {
333  return RZ_CMD_STATUS_OK;
334 }
RZ_API void rz_meta_del(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, ut64 size)
Definition: meta.c:187
#define UT64_MAX
Definition: rz_types_base.h:86

References rz_core_t::analysis, RZ_CMD_STATUS_OK, rz_meta_del(), RZ_META_TYPE_HIGHLIGHT, and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_highlight_remove_current_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_highlight_remove_current_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 336 of file cmd_eval.c.

336  {
338  return RZ_CMD_STATUS_OK;
339 }

References rz_core_t::analysis, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_meta_del(), and RZ_META_TYPE_HIGHLIGHT.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_list_current_theme_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_list_current_theme_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 275 of file cmd_eval.c.

275  {
277  return RZ_CMD_STATUS_OK;
278 }
RZ_API char * rz_core_theme_get(RzCore *core)
Definition: cmd_eval.c:103
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233

References RZ_CMD_STATUS_OK, rz_cons_println(), and rz_core_theme_get().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_list_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 167 of file cmd_eval.c.

167  {
168  if (argc == 3) {
169  if (!rz_cons_pal_set(argv[1], argv[2])) {
170  return RZ_CMD_STATUS_ERROR;
171  }
173  return RZ_CMD_STATUS_OK;
174  } else if (argc == 2) {
175  char color[32];
177  rz_cons_rgb_str(color, sizeof(color), &rcolor);
178  eprintf("(%s)(%sCOLOR" Color_RESET ")\n", argv[1], color);
179  return RZ_CMD_STATUS_OK;
180  }
181  switch (mode) {
184  break;
185  case RZ_OUTPUT_MODE_JSON:
186  rz_cons_pal_list('j', NULL);
187  break;
190  break;
191  default:
192  return RZ_CMD_STATUS_ERROR;
193  };
194  return RZ_CMD_STATUS_OK;
195 }
RZ_API RzColor rz_cons_pal_get(const char *key)
Definition: pal.c:626
RZ_API int rz_cons_pal_set(const char *key, const char *val)
Definition: pal.c:611
RzColor rcolor
Definition: pal.c:97
RZ_API char * rz_cons_rgb_str(char *outstr, size_t sz, const RzColor *rcolor)
Definition: rgb.c:318
#define Color_RESET
Definition: rz_cons.h:617
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
static int color
Definition: visual.c:20

References argv, color, Color_RESET, eprintf, NULL, rcolor, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_pal_get(), rz_cons_pal_list(), rz_cons_pal_set(), rz_cons_pal_update_event(), rz_cons_rgb_str(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, and RZ_OUTPUT_MODE_STANDARD.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_list_reload_current_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_list_reload_current_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 280 of file cmd_eval.c.

280  {
282  return RZ_CMD_STATUS_OK;
283 }
RZ_API bool rz_core_theme_load(RzCore *core, const char *name)
Definition: cmd_eval.c:56

References RZ_CMD_STATUS_OK, rz_core_theme_get(), and rz_core_theme_load().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_load_next_theme_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_load_next_theme_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 222 of file cmd_eval.c.

222  {
224  return RZ_CMD_STATUS_OK;
225 }
RZ_API void rz_core_theme_nextpal(RzCore *core, RzConsPalSeekMode mode)
Definition: cmd_eval.c:148

References RZ_CMD_STATUS_OK, RZ_CONS_PAL_SEEK_NEXT, and rz_core_theme_nextpal().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_load_previous_theme_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_load_previous_theme_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 217 of file cmd_eval.c.

217  {
219  return RZ_CMD_STATUS_OK;
220 }

References RZ_CMD_STATUS_OK, RZ_CONS_PAL_SEEK_PREVIOUS, and rz_core_theme_nextpal().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_load_theme_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_load_theme_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 236 of file cmd_eval.c.

236  {
237  RzList *themes_list = NULL;
238  RzListIter *th_iter;
239  PJ *pj = state->d.pj;
240  const char *th;
241  if (argc == 2) {
242  return bool2status(rz_core_theme_load(core, argv[1]));
243  }
244  themes_list = rz_core_theme_list(core);
245  if (!themes_list) {
246  return RZ_CMD_STATUS_ERROR;
247  }
248  if (state->mode == RZ_OUTPUT_MODE_JSON) {
249  pj_a(pj);
250  }
251  rz_list_foreach (themes_list, th_iter, th) {
252  switch (state->mode) {
253  case RZ_OUTPUT_MODE_JSON: {
254  pj_s(pj, th);
255  break;
256  }
258  rz_cons_printf("%s\n", th);
259  break;
260  default:
261  if (core->curtheme && !strcmp(core->curtheme, th)) {
262  rz_cons_printf("> %s\n", th);
263  } else {
264  rz_cons_printf(" %s\n", th);
265  }
266  }
267  }
268  if (state->mode == RZ_OUTPUT_MODE_JSON) {
269  pj_end(pj);
270  }
271  rz_list_free(themes_list);
272  return RZ_CMD_STATUS_OK;
273 }
RZ_API RZ_OWN RzList * rz_core_theme_list(RZ_NONNULL RzCore *core)
Returns the list of the rizin themes.
Definition: cmd_eval.c:119
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
Definition: rz_pj.h:12

References argv, bool2status(), rz_core_t::curtheme, NULL, pj_a(), pj_end(), pj_s(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_theme_list(), rz_core_theme_load(), rz_list_free(), RZ_OUTPUT_MODE_JSON, and RZ_OUTPUT_MODE_QUIET.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_set_colorful_palette_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_set_colorful_palette_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 212 of file cmd_eval.c.

212  {
214  return RZ_CMD_STATUS_OK;
215 }
RZ_API void rz_cons_pal_show(void)
Definition: pal.c:501

References RZ_CMD_STATUS_OK, and rz_cons_pal_show().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_set_default_palette_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_set_default_palette_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 202 of file cmd_eval.c.

202  {
203  rz_cons_pal_init(core->cons->context);
204  return RZ_CMD_STATUS_OK;
205 }
RZ_API void rz_cons_pal_init(RzConsContext *ctx)
Definition: pal.c:154
RzConsContext * context
Definition: rz_cons.h:502
RzCons * cons
Definition: rz_core.h:312

References rz_core_t::cons, rz_cons_t::context, RZ_CMD_STATUS_OK, and rz_cons_pal_init().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_eval_color_set_random_palette_handler()

RZ_IPI RzCmdStatus rz_cmd_eval_color_set_random_palette_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 207 of file cmd_eval.c.

207  {
209  return RZ_CMD_STATUS_OK;
210 }
RZ_API void rz_cons_pal_random(void)
Definition: pal.c:270

References RZ_CMD_STATUS_OK, and rz_cons_pal_random().

Referenced by rzshell_cmddescs_init().

◆ rz_core_theme_get()

RZ_API char* rz_core_theme_get ( RzCore core)

◆ rz_core_theme_list()

RZ_API RZ_OWN RzList* rz_core_theme_list ( RZ_NONNULL RzCore core)

Returns the list of the rizin themes.

Parameters
coreThe RzCore struct to use
Returns
On success, an RzList pointer, otherwise NULL.

Definition at line 119 of file cmd_eval.c.

119  {
121 
122  HtPU *themes = ht_pu_new0();
123  if (!themes) {
124  return NULL;
125  }
126 
128  if (path) {
129  list_themes_in_path(themes, path);
130  RZ_FREE(path);
131  }
132 
134  if (path) {
135  list_themes_in_path(themes, path);
136  RZ_FREE(path);
137  }
138 
140  rz_list_append(list, strdup("default"));
141  ht_pu_foreach(themes, dict2keylist, list);
142 
144  ht_pu_free(themes);
145  return list;
146 }
static void list_themes_in_path(HtPU *themes, const char *path)
Definition: cmd_eval.c:91
static bool dict2keylist(void *user, const void *key, const ut64 value)
Definition: cmd_eval.c:107
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 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
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
int(* RzListComparator)(const void *value, const void *list_data)
Definition: rz_list.h:33
RZ_API RZ_OWN char * rz_path_home_prefix(RZ_NULLABLE const char *path)
Return path prefixed by the home prefix.
Definition: path.c:182
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
#define RZ_THEMES
Definition: rz_userconf.h:76

References dict2keylist(), free(), list(), list_themes_in_path(), NULL, path, RZ_FREE, rz_list_append(), rz_list_newf(), rz_list_sort(), rz_path_home_prefix(), rz_path_system(), rz_return_val_if_fail, RZ_THEMES, and strdup().

Referenced by __load_config_menu(), autocomplete_theme(), rz_cmd_eval_color_load_theme_handler(), and rz_core_theme_nextpal().

◆ rz_core_theme_load()

RZ_API bool rz_core_theme_load ( RzCore core,
const char *  name 
)

Definition at line 56 of file cmd_eval.c.

56  {
57  bool failed = false;
58  if (!name || !*name) {
59  return false;
60  }
61  if (!rz_str_cmp(name, "default", strlen(name))) {
62  core->curtheme = rz_str_dup(core->curtheme, name);
64  return true;
65  }
66 
67  char *home_themes = rz_path_home_prefix(RZ_THEMES);
68  char *system_themes = rz_path_system(RZ_THEMES);
69  char *home_file = rz_file_path_join(home_themes, name);
70  char *system_file = rz_file_path_join(system_themes, name);
71  free(system_themes);
72  free(home_themes);
73 
74  if (!load_theme(core, home_file)) {
75  if (load_theme(core, system_file)) {
76  core->curtheme = rz_str_dup(core->curtheme, name);
77  } else {
78  if (load_theme(core, name)) {
79  core->curtheme = rz_str_dup(core->curtheme, name);
80  } else {
81  eprintf("eco: cannot open colorscheme profile (%s)\n", name);
82  failed = true;
83  }
84  }
85  }
86  free(home_file);
87  free(system_file);
88  return !failed;
89 }
static bool load_theme(RzCore *core, const char *path)
Definition: cmd_eval.c:9
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
RZ_API char * rz_str_dup(char *ptr, const char *string)
Definition: str.c:1021
RZ_API int rz_str_cmp(const char *dst, const char *orig, int len)
Definition: str.c:974
Definition: z80asm.h:102

References rz_core_t::cons, rz_cons_t::context, rz_core_t::curtheme, eprintf, free(), load_theme(), rz_cons_pal_init(), rz_file_path_join(), rz_path_home_prefix(), rz_path_system(), rz_str_cmp(), rz_str_dup(), and RZ_THEMES.

Referenced by __settings_colors_cb(), cb_scrrainbow(), rz_cmd_eval_color_list_reload_current_handler(), rz_cmd_eval_color_load_theme_handler(), and rz_core_theme_nextpal().

◆ rz_core_theme_nextpal()

RZ_API void rz_core_theme_nextpal ( RzCore core,
RzConsPalSeekMode  mode 
)

Definition at line 148 of file cmd_eval.c.

148  {
149  RzListIter *iter;
150  const char *fn;
152 
153  rz_list_foreach (files, iter, fn) {
154  if (*fn && *fn != '.') {
155  if (!pal_seek(core, mode, fn, iter)) {
156  goto done;
157  }
158  }
159  }
161  files = NULL;
162 done:
163  rz_core_theme_load(core, core->curtheme);
165 }
static bool pal_seek(RzCore *core, RzConsPalSeekMode mode, const char *file, RzListIter *iter)
Definition: cmd_eval.c:22
struct tab * done
Definition: enough.c:233

References rz_core_t::curtheme, done, files, fn, NULL, pal_seek(), rz_core_theme_list(), rz_core_theme_load(), and rz_list_free().

Referenced by __panels_process(), rz_cmd_eval_color_load_next_theme_handler(), rz_cmd_eval_color_load_previous_theme_handler(), rz_core_visual_analysis(), rz_core_visual_bit_editor(), rz_core_visual_cmd(), rz_core_visual_colors(), and rz_core_visual_graph().

◆ rz_eval_bool_invert_handler()

RZ_IPI RzCmdStatus rz_eval_bool_invert_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 392 of file cmd_eval.c.

392  {
393  if (!rz_config_toggle(core->config, argv[1])) {
394  eprintf("Cannot toggle config key '%s'\n", argv[1]);
395  return RZ_CMD_STATUS_ERROR;
396  }
397  return RZ_CMD_STATUS_OK;
398 }
RZ_API bool rz_config_toggle(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:97
RzConfig * config
Definition: rz_core.h:300

References argv, rz_core_t::config, eprintf, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_config_toggle().

Referenced by rzshell_cmddescs_init().

◆ rz_eval_editor_handler()

RZ_IPI RzCmdStatus rz_eval_editor_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 400 of file cmd_eval.c.

400  {
401  const char *val = rz_config_get(core->config, argv[1]);
402  if (!val) {
403  eprintf("Invalid config key '%s'", argv[1]);
404  return RZ_CMD_STATUS_ERROR;
405  }
406  char *p = rz_core_editor(core, NULL, val);
407  if (!p) {
408  return RZ_CMD_STATUS_ERROR;
409  }
410  rz_str_replace_char(p, '\n', ';');
411  rz_config_set(core->config, argv[1], p);
412  return RZ_CMD_STATUS_OK;
413 }
ut16 val
Definition: armass64_const.h:6
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
void * p
Definition: libc.cpp:67
RZ_API RZ_OWN char * rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
Definition: core.c:3214
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169

References argv, rz_core_t::config, eprintf, NULL, p, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get(), rz_config_set(), rz_core_editor(), rz_str_replace_char(), and val.

Referenced by rzshell_cmddescs_init().

◆ rz_eval_getset_handler()

RZ_IPI RzCmdStatus rz_eval_getset_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 341 of file cmd_eval.c.

341  {
342  int i;
343  for (i = 1; i < argc; i++) {
344  RzList *l = rz_str_split_duplist_n(argv[i], "=", 1, false);
345  if (!l) {
346  return RZ_CMD_STATUS_ERROR;
347  }
348  size_t llen = rz_list_length(l);
349  if (!llen) {
350  return RZ_CMD_STATUS_ERROR;
351  }
352  char *key = rz_list_get_n(l, 0);
353  if (RZ_STR_ISEMPTY(key)) {
354  eprintf("No string specified before `=`. Make sure to use the format <key>=<value> without spaces.\n");
355  continue;
356  }
357 
358  if (llen == 1 && rz_str_endswith(key, ".")) {
359  // no value was set, only key with ".". List possible sub-keys.
360  RzCmdStateOutput state = { 0 };
365  } else if (llen == 1) {
366  // no value was set, show the value of the key
367  const char *v = rz_config_get(core->config, key);
368  if (!v) {
369  eprintf("Invalid config key '%s'\n", key);
370  return RZ_CMD_STATUS_ERROR;
371  }
372  rz_cons_printf("%s\n", v);
373  } else if (llen == 2) {
374  char *value = rz_list_get_n(l, 1);
375  rz_config_set(core->config, key, value);
376  }
377  rz_list_free(l);
378  }
379  return RZ_CMD_STATUS_OK;
380 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_core_config_print_all(RzConfig *cfg, const char *str, RzCmdStateOutput *state)
Prints the configuation variables with their description and its values.
Definition: cconfig.c:1770
static int value
Definition: cmd_api.c:93
const char * v
Definition: dsignal.c:12
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329
RZ_API RzList * rz_str_split_duplist_n(const char *str, const char *c, int n, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3485

References argv, rz_core_t::config, eprintf, i, key, rz_cmd_state_output_fini(), rz_cmd_state_output_init(), rz_cmd_state_output_print(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get(), rz_config_set(), rz_cons_printf(), rz_core_config_print_all(), rz_list_free(), rz_list_get_n(), rz_list_length(), RZ_OUTPUT_MODE_QUIET, rz_str_endswith(), RZ_STR_ISEMPTY, rz_str_split_duplist_n(), v, and value.

Referenced by rzshell_cmddescs_init().

◆ rz_eval_list_handler()

RZ_IPI RzCmdStatus rz_eval_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 382 of file cmd_eval.c.

382  {
383  const char *arg = argc > 1 ? argv[1] : "";
385  return RZ_CMD_STATUS_OK;
386 }

References argv, rz_core_t::config, RZ_CMD_STATUS_OK, and rz_core_config_print_all().

Referenced by rzshell_cmddescs_init().

◆ rz_eval_readonly_handler()

RZ_IPI RzCmdStatus rz_eval_readonly_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 415 of file cmd_eval.c.

415  {
416  if (!rz_config_readonly(core->config, argv[1])) {
417  eprintf("Cannot make eval '%s' readonly.\n", argv[1]);
418  return RZ_CMD_STATUS_ERROR;
419  }
420  return RZ_CMD_STATUS_OK;
421 }
RZ_API bool rz_config_readonly(RzConfig *cfg, const char *key)
Definition: config.c:481

References argv, rz_core_t::config, eprintf, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_config_readonly().

Referenced by rzshell_cmddescs_init().

◆ rz_eval_reset_handler()

RZ_IPI RzCmdStatus rz_eval_reset_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 388 of file cmd_eval.c.

388  {
390 }
RZ_API int rz_core_config_init(RzCore *core)
Definition: cconfig.c:2830

References RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_config_init().

Referenced by rzshell_cmddescs_init().

◆ rz_eval_spaces_handler()

RZ_IPI RzCmdStatus rz_eval_spaces_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 423 of file cmd_eval.c.

423  {
424  const char *arg = argc > 1 ? argv[1] : NULL;
426  if (!list) {
427  return RZ_CMD_STATUS_ERROR;
428  }
429  RzListIter *iter;
430  char *name;
431  rz_list_foreach (list, iter, name) {
433  }
435  return RZ_CMD_STATUS_OK;
436 }
RZ_API RZ_OWN RzList * rz_core_config_in_space(RZ_NONNULL RzCore *core, RZ_NULLABLE const char *space)
Get config variable spaces.
Definition: cconfig.c:3759
const char * name
Definition: op.c:541

References argv, list(), name, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), rz_core_config_in_space(), and rz_list_free().

Referenced by rzshell_cmddescs_init().

◆ rz_eval_type_handler()

RZ_IPI RzCmdStatus rz_eval_type_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 438 of file cmd_eval.c.

438  {
439  RzConfigNode *node = rz_config_node_get(core->config, argv[1]);
440  if (!node) {
441  eprintf("Cannot find eval '%s'.\n", argv[1]);
442  return RZ_CMD_STATUS_ERROR;
443  }
444 
445  const char *type = rz_config_node_type(node);
446  if (!type) {
447  eprintf("Cannot find type of eval '%s'.\n", argv[1]);
448  return RZ_CMD_STATUS_ERROR;
449  }
451  return RZ_CMD_STATUS_OK;
452 }
RZ_API RZ_BORROW RzConfigNode * rz_config_node_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:48
RZ_API const char * rz_config_node_type(RzConfigNode *node)
Definition: config.c:155
int type
Definition: mipsasm.c:17

References argv, rz_core_t::config, eprintf, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_node_get(), rz_config_node_type(), rz_cons_println(), and type.

Referenced by rzshell_cmddescs_init().