Rizin
unix-like reverse engineering framework and cli tools
cmd_remote.c File Reference
#include "rz_cmd.h"
#include "rz_core.h"

Go to the source code of this file.

Functions

static int getArg (char ch, int def)
 
RZ_IPI int rz_equal_g_handler_old (void *data, const char *input)
 
RZ_IPI int rz_equal_h_handler_old (void *data, const char *input)
 
RZ_IPI int rz_equal_H_handler_old (void *data, const char *input)
 
RZ_IPI int rz_cmd_remote (void *data, const char *input)
 
RZ_IPI RzCmdStatus rz_remote_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_send_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI int rz_io_system_run_oldhandler (void *data, const char *input)
 
RZ_IPI RzCmdStatus rz_remote_add_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_del_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_open_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_mode_enable_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_mode_disable_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_rap_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_rap_bg_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_remote_tcp_handler (RzCore *core, int argc, const char **argv)
 

Variables

static const char * help_msg_equal []
 
static const char * help_msg_equalh []
 
static const char * help_msg_equalg []
 

Function Documentation

◆ getArg()

static int getArg ( char  ch,
int  def 
)
static

Definition at line 59 of file cmd_remote.c.

59  {
60  switch (ch) {
61  case '&':
62  case '-':
63  return ch;
64  }
65  return def;
66 }
int def(FILE *source, FILE *dest, int level)
Definition: zpipe.c:36

References def().

Referenced by rz_equal_g_handler_old(), rz_equal_h_handler_old(), and rz_equal_H_handler_old().

◆ rz_cmd_remote()

RZ_IPI int rz_cmd_remote ( void *  data,
const char *  input 
)

Definition at line 99 of file cmd_remote.c.

99  {
100  RzCore *core = (RzCore *)data;
101  switch (*input) {
102  case '\0': // "R"
103  rz_core_rtr_list(core);
104  break;
105  case 'j': // "Rj"
106  eprintf("TODO: list connections in json\n");
107  break;
108  case '!': // "R!"
109  if (input[1] == 'q') {
110  RZ_FREE(core->cmdremote);
111  } else if (input[1] == '=') { // R!=0 or R!= for iosystem
112  RZ_FREE(core->cmdremote);
113  core->cmdremote = rz_str_trim_dup(input + 2);
114  } else {
115  char *res = rz_io_system(core->io, input + 1);
116  if (res) {
117  rz_cons_printf("%s\n", res);
118  free(res);
119  }
120  }
121  break;
122  case '+': // "R+"
123  rz_core_rtr_add(core, input + 1);
124  break;
125  case '-': // "R-"
126  rz_core_rtr_remove(core, input + 1);
127  break;
128  // case ':': rz_core_rtr_cmds (core, input + 1); break;
129  case '<': // "R<"
130  rz_core_rtr_pushout(core, input + 1);
131  break;
132  case '=': // "R="
133  rz_core_rtr_session(core, input + 1);
134  break;
135  case 'g': // "Rg"
136  rz_equal_g_handler_old(core, input + 1);
137  break;
138  case 'h': // "Rh"
139  rz_equal_h_handler_old(core, input + 1);
140  break;
141  case 'H': // "RH"
142  rz_equal_H_handler_old(core, input + 1);
143  break;
144  case '?': // "R?"
146  break;
147  default:
148  rz_core_rtr_cmd(core, input);
149  break;
150  }
151  return 0;
152 }
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
Definition: cmd.c:163
RZ_IPI int rz_equal_h_handler_old(void *data, const char *input)
Definition: cmd_remote.c:78
RZ_IPI int rz_equal_H_handler_old(void *data, const char *input)
Definition: cmd_remote.c:88
RZ_IPI int rz_equal_g_handler_old(void *data, const char *input)
Definition: cmd_remote.c:68
static const char * help_msg_equal[]
Definition: cmd_remote.c:9
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API void rz_core_rtr_session(RzCore *core, const char *input)
Definition: rtr.c:814
RZ_API void rz_core_rtr_list(RzCore *core)
Definition: rtr.c:631
RZ_API void rz_core_rtr_add(RzCore *core, const char *_input)
Definition: rtr.c:651
RZ_API void rz_core_rtr_remove(RzCore *core, const char *input)
Definition: rtr.c:793
RZ_API void rz_core_rtr_pushout(RzCore *core, const char *input)
Definition: rtr.c:582
RZ_API void rz_core_rtr_cmd(RzCore *core, const char *input)
Definition: rtr.c:850
RZ_API char * rz_io_system(RzIO *io, const char *cmd)
Definition: io.c:411
RZ_API char * rz_str_trim_dup(const char *str)
Definition: str_trim.c:78
#define RZ_FREE(x)
Definition: rz_types.h:369
RzIO * io
Definition: rz_core.h:313
char * cmdremote
Definition: rz_core.h:369
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References rz_core_t::cmdremote, eprintf, free(), help_msg_equal, input(), rz_core_t::io, rz_cons_printf(), rz_core_cmd_help(), rz_core_rtr_add(), rz_core_rtr_cmd(), rz_core_rtr_list(), rz_core_rtr_pushout(), rz_core_rtr_remove(), rz_core_rtr_session(), rz_equal_g_handler_old(), rz_equal_h_handler_old(), rz_equal_H_handler_old(), RZ_FREE, rz_io_system(), and rz_str_trim_dup().

◆ rz_equal_g_handler_old()

RZ_IPI int rz_equal_g_handler_old ( void *  data,
const char *  input 
)

Definition at line 68 of file cmd_remote.c.

68  {
69  RzCore *core = (RzCore *)data;
70  if (input[0] == '?') {
72  } else {
73  rz_core_rtr_gdb(core, getArg(input[0], 'g'), input);
74  }
75  return 0;
76 }
static int getArg(char ch, int def)
Definition: cmd_remote.c:59
static const char * help_msg_equalg[]
Definition: cmd_remote.c:51
RZ_API int rz_core_rtr_gdb(RzCore *core, int launch, const char *path)
Definition: rtr.c:571

References getArg(), help_msg_equalg, input(), rz_core_cmd_help(), and rz_core_rtr_gdb().

Referenced by rz_cmd_remote(), and rzshell_cmddescs_init().

◆ rz_equal_h_handler_old()

RZ_IPI int rz_equal_h_handler_old ( void *  data,
const char *  input 
)

Definition at line 78 of file cmd_remote.c.

78  {
79  RzCore *core = (RzCore *)data;
80  if (input[0] == '?') {
82  } else {
83  rz_core_rtr_http(core, getArg(input[0], 'h'), 'h', input);
84  }
85  return 0;
86 }
static const char * help_msg_equalh[]
Definition: cmd_remote.c:38
RZ_API int rz_core_rtr_http(RzCore *core, int launch, int browse, const char *path)
Definition: rtr_http.c:491

References getArg(), help_msg_equalh, input(), rz_core_cmd_help(), and rz_core_rtr_http().

Referenced by rz_cmd_remote(), and rzshell_cmddescs_init().

◆ rz_equal_H_handler_old()

RZ_IPI int rz_equal_H_handler_old ( void *  data,
const char *  input 
)

Definition at line 88 of file cmd_remote.c.

88  {
89  RzCore *core = (RzCore *)data;
90  if (input[0] == '?') {
92  } else {
93  const char *arg = rz_str_trim_head_ro(input);
94  rz_core_rtr_http(core, getArg(input[0], 'H'), 'H', arg);
95  }
96  return 0;
97 }
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86

References getArg(), help_msg_equalh, input(), rz_core_cmd_help(), rz_core_rtr_http(), and rz_str_trim_head_ro().

Referenced by rz_cmd_remote(), rz_core_run_script(), and rzshell_cmddescs_init().

◆ rz_io_system_run_oldhandler()

RZ_IPI int rz_io_system_run_oldhandler ( void *  data,
const char *  input 
)

Definition at line 174 of file cmd_remote.c.

174  {
175  RzCore *core = (RzCore *)data;
176  char *res = rz_io_system(core->io, input);
177  if (res) {
178  rz_cons_printf("%s\n", res);
179  free(res);
180  }
181  return 0;
182 }

References free(), input(), rz_core_t::io, rz_cons_printf(), and rz_io_system().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_add_handler()

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

Definition at line 184 of file cmd_remote.c.

184  {
185  char *args = rz_str_array_join(argv + 1, argc - 1, " ");
186  rz_core_rtr_add(core, args);
187  free(args);
188  return RZ_CMD_STATUS_OK;
189 }
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int args
Definition: mipsasm.c:18
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
RZ_API char * rz_str_array_join(const char **a, size_t n, const char *sep)
Definition: str.c:3861

References args, argv, free(), RZ_CMD_STATUS_OK, rz_core_rtr_add(), and rz_str_array_join().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_del_handler()

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

Definition at line 191 of file cmd_remote.c.

191  {
192  char *args = rz_str_array_join(argv + 1, argc - 1, " ");
193  rz_core_rtr_remove(core, args);
194  free(args);
195  return RZ_CMD_STATUS_OK;
196 }

References args, argv, free(), RZ_CMD_STATUS_OK, rz_core_rtr_remove(), and rz_str_array_join().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_handler()

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

Definition at line 154 of file cmd_remote.c.

154  {
155  if (argc == 1) {
156  rz_core_rtr_list(core);
157  return RZ_CMD_STATUS_OK;
158  } else if (argc == 3) {
159  char *args = rz_str_array_join(argv + 1, argc - 1, " ");
160  rz_core_rtr_cmd(core, args);
161  free(args);
162  return RZ_CMD_STATUS_OK;
163  }
164  return RZ_CMD_STATUS_ERROR;
165 }
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26

References args, argv, free(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_rtr_cmd(), rz_core_rtr_list(), and rz_str_array_join().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_mode_disable_handler()

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

Definition at line 211 of file cmd_remote.c.

211  {
212  RZ_FREE(core->cmdremote);
213  return RZ_CMD_STATUS_OK;
214 }

References rz_core_t::cmdremote, RZ_CMD_STATUS_OK, and RZ_FREE.

Referenced by rzshell_cmddescs_init().

◆ rz_remote_mode_enable_handler()

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

Definition at line 205 of file cmd_remote.c.

205  {
206  RZ_FREE(core->cmdremote);
207  core->cmdremote = rz_str_trim_dup(argc > 1 ? argv[1] : "0");
208  return RZ_CMD_STATUS_OK;
209 }

References argv, rz_core_t::cmdremote, RZ_CMD_STATUS_OK, RZ_FREE, and rz_str_trim_dup().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_open_handler()

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

Definition at line 198 of file cmd_remote.c.

198  {
199  char *args = rz_str_array_join(argv + 1, argc - 1, " ");
200  rz_core_rtr_session(core, args);
201  free(args);
202  return RZ_CMD_STATUS_OK;
203 }

References args, argv, free(), RZ_CMD_STATUS_OK, rz_core_rtr_session(), and rz_str_array_join().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_rap_bg_handler()

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

Definition at line 224 of file cmd_remote.c.

224  {
225  char *args = rz_str_array_join(argv + 1, argc - 1, " ");
226  args = rz_str_prepend(args, "&:");
227  rz_core_rtr_cmd(core, args);
228  free(args);
229  return RZ_CMD_STATUS_OK;
230 }
RZ_API char * rz_str_prepend(char *ptr, const char *string)
Definition: str.c:1027

References args, argv, free(), RZ_CMD_STATUS_OK, rz_core_rtr_cmd(), rz_str_array_join(), and rz_str_prepend().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_rap_handler()

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

Definition at line 216 of file cmd_remote.c.

216  {
217  char *args = rz_str_array_join(argv + 1, argc - 1, " ");
218  args = rz_str_prepend(args, ":");
219  rz_core_rtr_cmd(core, args);
220  free(args);
221  return RZ_CMD_STATUS_OK;
222 }

References args, argv, free(), RZ_CMD_STATUS_OK, rz_core_rtr_cmd(), rz_str_array_join(), and rz_str_prepend().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_send_handler()

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

Definition at line 167 of file cmd_remote.c.

167  {
168  char *args = rz_str_array_join(argv + 1, argc - 1, " ");
169  rz_core_rtr_pushout(core, args);
170  free(args);
171  return RZ_CMD_STATUS_OK;
172 }

References args, argv, free(), RZ_CMD_STATUS_OK, rz_core_rtr_pushout(), and rz_str_array_join().

Referenced by rzshell_cmddescs_init().

◆ rz_remote_tcp_handler()

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

Definition at line 232 of file cmd_remote.c.

232  {
233  if (argc == 2) {
234  rz_core_rtr_cmds(core, argv[1]);
235  return RZ_CMD_STATUS_OK;
236  } else if (argc == 3) {
237  char *host, *port = strchr(argv[1], ':');
238  if (port) {
239  host = rz_str_ndup(argv[1], port - argv[1]);
240  port = strdup(port + 1);
241  } else {
242  host = strdup("localhost");
243  port = strdup(argv[1]);
244  }
245  char *rbuf = rz_core_rtr_cmds_query(core, host, port, argv[2]);
246  if (rbuf) {
247  rz_cons_print(rbuf);
248  free(rbuf);
249  }
250  free(host);
251  free(port);
252  return RZ_CMD_STATUS_OK;
253  }
254  return RZ_CMD_STATUS_ERROR;
255 }
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")
RZ_API char * rz_core_rtr_cmds_query(RzCore *core, const char *host, const char *port, const char *cmd)
Definition: rtr.c:983
RZ_API int rz_core_rtr_cmds(RzCore *core, const char *port)
Definition: rtr.c:1225
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006

References argv, free(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_rtr_cmds(), rz_core_rtr_cmds_query(), rz_str_ndup(), and strdup().

Referenced by rzshell_cmddescs_init().

Variable Documentation

◆ help_msg_equal

const char* help_msg_equal[]
static
Initial value:
= {
"Usage:", " R[:!+-=ghH] [...]", " # connect with other instances of rizin",
"\nremote commands:", "", "",
"R", "", "list all open connections",
"R<", "[fd] cmd", "send output of local command to remote fd",
"R", "[fd] cmd", "exec cmd at remote 'fd' (last open is default one)",
"R!", " cmd", "run command via rz_io_system",
"R+", " [proto://]host:port", "connect to remote host:port (*rap://, raps://, tcp://, udp://, http://)",
"R-", "[fd]", "remove all hosts or host 'fd'",
"R=", "[fd]", "open remote session with host 'fd', 'q' to quit",
"R!=", "", "disable remote cmd mode",
"R=!", "", "enable remote cmd mode",
"\nservers:", "", "",
".:", "9000", "start the tcp server (echo x|nc ::1 9090 or curl ::1:9090/cmd/x)",
"R:", "port", "start the rap server (o rap://9999)",
"Rg", "[?]", "start the gdbserver",
"Rh", "[?]", "start the http webserver",
"RH", "[?]", "start the http webserver (and launch the web browser)",
"\nother:", "", "",
"R&", ":port", "start rap server in background (same as '& Rr')",
"R", ":host:port cmd", "run 'cmd' command on remote server",
"\nexamples:", "", "",
"R+", "tcp://localhost:9090/", "connect to: rizin -c.:9090 ./bin",
"R+", "rap://localhost:9090/", "connect to: rizin rap://:9090",
"R+", "http://localhost:9090/cmd/", "connect to: rizin -c'Rh 9090' bin",
"o ", "rap://:9090/", "start the rap server on tcp port 9090",
}
#define NULL
Definition: cris-opc.c:27

Definition at line 9 of file cmd_remote.c.

Referenced by rz_cmd_remote().

◆ help_msg_equalg

const char* help_msg_equalg[]
static
Initial value:
= {
"Usage:", " R[g] [...]", " # gdb server",
"gdbserver:", "", "",
"Rg", " port file [args]", "listen on 'port' debugging 'file' using gdbserver",
"Rg!", " port file [args]", "same as above, but debug protocol messages (like gdbserver --remote-debug)",
}

Definition at line 51 of file cmd_remote.c.

Referenced by rz_equal_g_handler_old().

◆ help_msg_equalh

const char* help_msg_equalh[]
static
Initial value:
= {
"Usage:", " R[hH] [...]", " # http server",
"http server:", "", "",
"Rh", " port", "listen for http connections (rizin -qcRH /bin/ls)",
"Rh-", "", "stop background webserver",
"Rh--", "", "stop foreground webserver",
"Rh*", "", "restart current webserver",
"Rh&", " port", "start http server in background",
"RH", " port", "launch browser and listen for http",
"RH&", " port", "launch browser and listen for http in background",
}

Definition at line 38 of file cmd_remote.c.

Referenced by rz_equal_h_handler_old(), and rz_equal_H_handler_old().