2014-07-30 20:12:48 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2014 - pancake */
|
2016-05-03 02:52:41 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "r_config.h"
|
|
|
|
#include "r_cons.h"
|
|
|
|
#include "r_core.h"
|
2014-07-30 20:12:48 +00:00
|
|
|
|
2017-07-26 13:08:48 +00:00
|
|
|
// TODO #7967 help refactor: move to another place
|
|
|
|
static const char *help_msg_L[] = {
|
|
|
|
"Usage:", "L", "[-name][ file] # see oL, iL, dL, ...",
|
|
|
|
"L", "", "List all plugins loaded by RCore.lib",
|
|
|
|
"L-", "duk", "Unload plugin matching in filename",
|
|
|
|
"L", " blah."R_LIB_EXT, "Load plugin file",
|
2017-11-22 14:25:34 +00:00
|
|
|
"Ls", "", "list RCore plugins",
|
|
|
|
"Ls", " java", "run RCore java plugin",
|
2017-07-26 13:08:48 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_T[] = {
|
|
|
|
"Usage:", "T", "[-][ num|msg]",
|
|
|
|
"T", "", "List all Text log messages",
|
|
|
|
"T", " message", "Add new log message",
|
|
|
|
"T", " 123", "List log from 123",
|
|
|
|
"T", " 10 3", "List 3 log messages starting from 10",
|
|
|
|
"T*", "", "List in radare commands",
|
|
|
|
"T-", "", "Delete all logs",
|
|
|
|
"T-", " 123", "Delete logs before 123",
|
|
|
|
"Tl", "", "Get last log message id",
|
|
|
|
"Tj", "", "List in json format",
|
|
|
|
"Tm", " [idx]", "Display log messages without index",
|
|
|
|
"Ts", "", "List files in current directory (see pwd, cd)",
|
|
|
|
"TT", "", "Enter into the text log chat console",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO #7967 help refactor: move L to another place
|
2017-07-27 12:52:17 +00:00
|
|
|
static void cmd_log_init(RCore *core) {
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, L);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, T);
|
2017-07-26 13:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 01:30:00 +00:00
|
|
|
static int textlog_chat(RCore *core) {
|
2014-08-28 01:11:13 +00:00
|
|
|
char prompt[64];
|
|
|
|
char buf[1024];
|
|
|
|
int lastmsg = 0;
|
|
|
|
const char *me = r_config_get (core->config, "cfg.user");
|
|
|
|
char msg[1024];
|
|
|
|
|
|
|
|
eprintf ("Type '/help' for commands:\n");
|
2017-03-25 01:30:00 +00:00
|
|
|
snprintf (prompt, sizeof (prompt) - 1, "[%s]> ", me);
|
2014-08-28 01:11:13 +00:00
|
|
|
r_line_set_prompt (prompt);
|
|
|
|
for (;;) {
|
|
|
|
r_core_log_list (core, lastmsg, 0, 0);
|
|
|
|
lastmsg = core->log->last;
|
2017-03-25 01:30:00 +00:00
|
|
|
if (r_cons_fgets (buf, sizeof (buf) - 1, 0, NULL) < 0) {
|
2014-08-28 01:11:13 +00:00
|
|
|
return 1;
|
2017-03-25 01:30:00 +00:00
|
|
|
}
|
|
|
|
if (!*buf) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-28 01:11:13 +00:00
|
|
|
if (!strcmp (buf, "/help")) {
|
|
|
|
eprintf ("/quit quit the chat (same as ^D)\n");
|
|
|
|
eprintf ("/name <nick> set cfg.user name\n");
|
|
|
|
eprintf ("/log show full log\n");
|
|
|
|
eprintf ("/clear clear text log messages\n");
|
|
|
|
} else if (!strncmp (buf, "/name ", 6)) {
|
2017-03-25 01:30:00 +00:00
|
|
|
snprintf (msg, sizeof (msg) - 1, "* '%s' is now known as '%s'", me, buf + 6);
|
2014-08-28 01:11:13 +00:00
|
|
|
r_core_log_add (core, msg);
|
2017-03-25 01:30:00 +00:00
|
|
|
r_config_set (core->config, "cfg.user", buf + 6);
|
2014-08-28 01:11:13 +00:00
|
|
|
me = r_config_get (core->config, "cfg.user");
|
2017-03-25 01:30:00 +00:00
|
|
|
snprintf (prompt, sizeof (prompt) - 1, "[%s]> ", me);
|
2014-08-28 01:11:13 +00:00
|
|
|
r_line_set_prompt (prompt);
|
|
|
|
return 0;
|
|
|
|
} else if (!strcmp (buf, "/log")) {
|
|
|
|
r_core_log_list (core, 0, 0, 0);
|
|
|
|
return 0;
|
|
|
|
} else if (!strcmp (buf, "/clear")) {
|
2017-03-25 01:30:00 +00:00
|
|
|
// r_core_log_del (core, 0);
|
2014-08-28 01:11:13 +00:00
|
|
|
r_core_cmd0 (core, "T-");
|
|
|
|
return 0;
|
|
|
|
} else if (!strcmp (buf, "/quit")) {
|
|
|
|
return 0;
|
2017-03-25 01:30:00 +00:00
|
|
|
} else if (*buf == '/') {
|
2014-08-28 02:41:33 +00:00
|
|
|
eprintf ("Unknown command: %s\n", buf);
|
2014-08-28 01:11:13 +00:00
|
|
|
} else {
|
2017-03-25 01:30:00 +00:00
|
|
|
snprintf (msg, sizeof (msg) - 1, "[%s] %s", me, buf);
|
2014-08-28 01:11:13 +00:00
|
|
|
r_core_log_add (core, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-07-30 20:12:48 +00:00
|
|
|
static int cmd_log(void *data, const char *input) {
|
2017-03-25 01:30:00 +00:00
|
|
|
RCore *core = (RCore *) data;
|
2015-04-19 11:39:10 +00:00
|
|
|
const char *arg, *input2;
|
2015-04-19 02:32:48 +00:00
|
|
|
int n, n2;
|
|
|
|
|
2017-03-25 01:30:00 +00:00
|
|
|
if (!input) {
|
2015-04-19 02:32:48 +00:00
|
|
|
return 1;
|
2017-03-25 01:30:00 +00:00
|
|
|
}
|
2015-04-19 02:32:48 +00:00
|
|
|
|
2017-03-25 01:30:00 +00:00
|
|
|
input2 = (input && *input)? input + 1: "";
|
2015-04-19 02:32:48 +00:00
|
|
|
arg = strchr (input2, ' ');
|
|
|
|
n = atoi (input2);
|
2017-03-25 01:30:00 +00:00
|
|
|
n2 = arg? atoi (arg + 1): 0;
|
2014-07-30 20:12:48 +00:00
|
|
|
|
|
|
|
switch (*input) {
|
|
|
|
case 'e': // shell: less
|
2017-03-25 01:30:00 +00:00
|
|
|
{
|
2014-07-30 20:12:48 +00:00
|
|
|
char *p = strchr (input, ' ');
|
|
|
|
if (p) {
|
2017-03-25 01:30:00 +00:00
|
|
|
char *b = r_file_slurp (p + 1, NULL);
|
2014-07-30 20:12:48 +00:00
|
|
|
if (b) {
|
2015-10-29 11:54:19 +00:00
|
|
|
r_cons_less_str (b, NULL);
|
2014-07-30 20:12:48 +00:00
|
|
|
free (b);
|
2017-03-25 01:30:00 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("File not found\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eprintf ("Usage: less [filename]\n");
|
2014-07-30 20:12:48 +00:00
|
|
|
}
|
2017-03-25 01:30:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-07-30 20:12:48 +00:00
|
|
|
case 'l':
|
2017-03-25 01:30:00 +00:00
|
|
|
r_cons_printf ("%d\n", core->log->last - 1);
|
2014-07-30 20:12:48 +00:00
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
r_core_log_del (core, n);
|
|
|
|
break;
|
2017-07-26 13:08:48 +00:00
|
|
|
case '?':
|
|
|
|
r_core_cmd_help (core, help_msg_T);
|
|
|
|
break;
|
2014-08-28 01:11:13 +00:00
|
|
|
case 'T':
|
2015-02-12 16:23:30 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.interactive")) {
|
|
|
|
textlog_chat (core);
|
2017-03-25 01:30:00 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Only available when the screen is interactive\n");
|
|
|
|
}
|
2014-08-28 01:11:13 +00:00
|
|
|
break;
|
2014-07-30 20:12:48 +00:00
|
|
|
case ' ':
|
2017-03-25 01:30:00 +00:00
|
|
|
if (n > 0) {
|
2014-07-31 03:20:48 +00:00
|
|
|
r_core_log_list (core, n, n2, *input);
|
|
|
|
} else {
|
2017-03-25 01:30:00 +00:00
|
|
|
r_core_log_add (core, input + 1);
|
2014-07-30 20:12:48 +00:00
|
|
|
}
|
2014-07-31 03:20:48 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
2017-03-25 01:30:00 +00:00
|
|
|
if (n > 0) {
|
2014-07-31 03:20:48 +00:00
|
|
|
r_core_log_list (core, n, 1, 't');
|
|
|
|
} else {
|
|
|
|
r_core_log_list (core, n, 0, 't');
|
|
|
|
}
|
|
|
|
break;
|
2014-07-30 20:12:48 +00:00
|
|
|
case 'j':
|
|
|
|
case '*':
|
|
|
|
case '\0':
|
|
|
|
r_core_log_list (core, n, n2, *input);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-28 23:37:54 +00:00
|
|
|
|
|
|
|
static int cmd_plugins(void *data, const char *input) {
|
|
|
|
RCore *core = (RCore *) data;
|
|
|
|
switch (input[0]) {
|
|
|
|
case 0:
|
|
|
|
r_lib_list (core->lib);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
r_lib_close (core->lib, input + 2);
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
r_lib_open (core->lib, input + 2);
|
|
|
|
break;
|
|
|
|
case '?':
|
2017-07-26 13:08:48 +00:00
|
|
|
r_core_cmd_help (core, help_msg_L);
|
2017-05-28 23:37:54 +00:00
|
|
|
break;
|
2018-03-09 08:01:16 +00:00
|
|
|
case 's': {
|
|
|
|
RListIter *iter;
|
|
|
|
RCorePlugin *cp;
|
|
|
|
switch (input[1]) {
|
|
|
|
case 'j': {
|
2018-03-09 14:16:31 +00:00
|
|
|
r_cons_printf("[");
|
2018-03-09 08:01:16 +00:00
|
|
|
bool is_first_element = true;
|
|
|
|
r_list_foreach (core->rcmd->plist, iter, cp) {
|
2018-03-09 14:16:31 +00:00
|
|
|
r_cons_printf ("%s{\"Name\":\"%s\",\"Description\":\"%s\"}",
|
2018-03-09 08:01:16 +00:00
|
|
|
is_first_element? "" : ",", cp->name, cp->desc);
|
|
|
|
is_first_element = false;
|
|
|
|
}
|
2018-03-09 14:16:31 +00:00
|
|
|
r_cons_printf("]\n");
|
2018-03-09 08:01:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0 :
|
2017-11-22 14:25:34 +00:00
|
|
|
r_list_foreach (core->rcmd->plist, iter, cp) {
|
|
|
|
r_cons_printf ("%s: %s\n", cp->name, cp->desc);
|
|
|
|
}
|
|
|
|
break;
|
2018-03-09 08:01:16 +00:00
|
|
|
default:
|
|
|
|
return r_core_cmd0 (core, input + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-05-28 23:37:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|