Rizin
unix-like reverse engineering framework and cli tools
cmd_interpret.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2020 ret2libc <sirmy15@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_cmd.h>
5 #include <rz_core.h>
6 #include <cmd_descs.h>
7 #include "../core_private.h"
8 
9 RZ_IPI RzCmdStatus rz_interpret_handler(RzCore *core, int argc, const char **argv) {
10  if (argc == 1) {
12  return RZ_CMD_STATUS_OK;
13  } else if (argc == 2) {
14  int tmp_html = rz_cons_singleton()->is_html;
16  char *cmd_output = rz_core_cmd_str(core, argv[1]);
17  rz_cons_singleton()->is_html = tmp_html;
18  if (!cmd_output) {
19  return RZ_CMD_STATUS_ERROR;
20  }
21  rz_core_cmd(core, cmd_output, 0);
22  free(cmd_output);
23  return RZ_CMD_STATUS_OK;
24  }
25  return RZ_CMD_STATUS_ERROR;
26 }
27 
28 RZ_IPI RzCmdStatus rz_interpret_output_handler(RzCore *core, int argc, const char **argv) {
29  char *str = rz_core_cmd_str_pipe(core, argv[1]);
30  if (!str) {
31  return RZ_CMD_STATUS_ERROR;
32  }
33  rz_core_cmd(core, str, 0);
34  free(str);
35  return RZ_CMD_STATUS_OK;
36 }
37 
38 RZ_IPI RzCmdStatus rz_repeat_forward_handler(RzCore *core, int argc, const char **argv) {
40  return RZ_CMD_STATUS_OK;
41 }
42 
43 RZ_IPI RzCmdStatus rz_interpret_script_handler(RzCore *core, int argc, const char **argv) {
44  const char *script_file = argv[1];
45  if (*script_file == '$') {
46  rz_core_cmd0(core, script_file);
47  } else {
48  if (!rz_core_run_script(core, script_file)) {
49  eprintf("Cannot find script '%s'\n", script_file);
50  core->num->value = 1;
51  } else {
52  core->num->value = 0;
53  }
54  }
55  return RZ_CMD_STATUS_OK;
56 }
57 
59  rz_core_run_script(core, "-");
60  return RZ_CMD_STATUS_OK;
61 }
62 
63 RZ_IPI RzCmdStatus rz_interpret_pipe_handler(RzCore *core, int argc, const char **argv) {
64  rz_core_run_script(core, argv[1]);
65  return RZ_CMD_STATUS_OK;
66 }
67 
68 RZ_IPI RzCmdStatus rz_interpret_macro_handler(RzCore *core, int argc, const char **argv) {
69  rz_cmd_macro_call(&core->rcmd->macro, argv[1]);
70  return RZ_CMD_STATUS_OK;
71 }
72 
75  return RZ_CMD_STATUS_OK;
76 }
#define RZ_IPI
Definition: analysis_wasm.c:11
RZ_API char * rz_core_cmd_str_pipe(RzCore *core, const char *cmd)
Definition: cmd.c:5438
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
RZ_API int rz_core_cmd(RzCore *core, const char *cstr, int log)
Definition: cmd.c:5328
RZ_API bool rz_core_run_script(RzCore *core, RZ_NONNULL const char *file)
Definition: cmd.c:457
RZ_IPI bool rz_core_cmd_lastcmd_repeat(RzCore *core, bool next)
Definition: cmd.c:216
RZ_API char * rz_core_cmd_str(RzCore *core, const char *cmd)
Executes a rizin command and returns the stdout as a string.
Definition: cmd.c:5513
RZ_API int rz_cmd_macro_call_multiple(RzCmdMacro *mac, const char *name)
Definition: cmd_api.c:1997
RZ_API int rz_cmd_macro_call(RzCmdMacro *mac, const char *name)
Definition: cmd_api.c:1993
RZ_IPI RzCmdStatus rz_interpret_macro_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:68
RZ_IPI RzCmdStatus rz_interpret_editor_2_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:58
RZ_IPI RzCmdStatus rz_repeat_forward_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:38
RZ_IPI RzCmdStatus rz_interpret_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:9
RZ_IPI RzCmdStatus rz_interpret_macro_multiple_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:73
RZ_IPI RzCmdStatus rz_interpret_output_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:28
RZ_IPI RzCmdStatus rz_interpret_script_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:43
RZ_IPI RzCmdStatus rz_interpret_pipe_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_interpret.c:63
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define eprintf(x, y...)
Definition: rlcc.c:7
enum rz_cmd_status_t RzCmdStatus
@ 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
RzCmdMacro macro
Definition: rz_cmd.h:482
bool is_html
Definition: rz_cons.h:505
RzCmd * rcmd
Definition: rz_core.h:319
RzNum * num
Definition: rz_core.h:316
ut64 value
Definition: rz_num.h:63