mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-06 18:13:46 +00:00
Handle invalid subcommands and refactor 'ec' ##shell
This commit is contained in:
parent
61f235d532
commit
39cd603d63
89
dist/plugins-cfg/plugins.emscripten.cfg
vendored
89
dist/plugins-cfg/plugins.emscripten.cfg
vendored
@ -1,78 +1,39 @@
|
||||
STATIC="
|
||||
anal.null
|
||||
arch.6502
|
||||
arch.arm
|
||||
arch.arm_cs
|
||||
arch.bf
|
||||
arch.bpf
|
||||
arch.dalvik
|
||||
arch.gb
|
||||
arch.mips_cs
|
||||
arch.null
|
||||
arch.ppc_gnu
|
||||
arch.pyc
|
||||
arch.riscv
|
||||
arch.wasm
|
||||
arch.x86_cs
|
||||
arch.x86_nz
|
||||
arch.z80
|
||||
esil.null
|
||||
esil.dummy
|
||||
arch.arm_cs
|
||||
arch.dalvik
|
||||
arch.mips_cs
|
||||
bin.any
|
||||
bin.dex
|
||||
bin.elf
|
||||
bin.elf64
|
||||
bin.fs
|
||||
bin.mach0
|
||||
bin.mach064
|
||||
bin.pe
|
||||
bin.pe64
|
||||
bin_xtr.xtr_fatmach0
|
||||
bp.null
|
||||
cmd.dummy
|
||||
egg.xor
|
||||
lang.pipe
|
||||
core.agD
|
||||
core.a2f
|
||||
crypto.base64
|
||||
crypto.ed25519
|
||||
crypto.xor
|
||||
crypto.aes
|
||||
fs.posix
|
||||
fs.io
|
||||
fs.r2
|
||||
fs.fat
|
||||
fs.zip
|
||||
fs.cpio
|
||||
bin.any
|
||||
bin.elf
|
||||
bin.elf64
|
||||
bin.dex
|
||||
bin.pe
|
||||
bin.wad
|
||||
bin.art
|
||||
bin.mz
|
||||
bin.pe64
|
||||
bin.mach0
|
||||
bin.mach064
|
||||
bin.wasm
|
||||
bin_xtr.xtr_fatmach0
|
||||
bin_xtr.xtr_sep64
|
||||
core.agD
|
||||
core.a2f
|
||||
core.sixref
|
||||
bp.null
|
||||
bp.arm
|
||||
bp.riscv
|
||||
cmd.dummy
|
||||
egg.xor
|
||||
lang.spp
|
||||
lang.pipe
|
||||
debug.esil
|
||||
debug.null
|
||||
io.debug
|
||||
io.malloc
|
||||
io.mmap
|
||||
io.self
|
||||
io.socket
|
||||
io.sparse
|
||||
io.fd
|
||||
io.rbuf
|
||||
io.ihex
|
||||
io.http
|
||||
io.tcpslurp
|
||||
io.null
|
||||
esil.null
|
||||
fs.io
|
||||
io.default
|
||||
io.malloc
|
||||
parse.null_pseudo
|
||||
parse.x86_pseudo
|
||||
parse.arm_pseudo
|
||||
parse.att2intel
|
||||
parse.wasm_pseudo
|
||||
parse.z80_pseudo
|
||||
parse.dalvik_pseudo
|
||||
parse.mips_pseudo
|
||||
"
|
||||
SHARED="
|
||||
parse.6502_pseudo
|
||||
"
|
||||
|
@ -412,6 +412,221 @@ static bool is_static_theme(const char *th) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool cmd_ec(RCore *core, const char *input) {
|
||||
switch (input[1]) {
|
||||
case 'd': // "ecd"
|
||||
r_cons_pal_init (core->cons->context);
|
||||
break;
|
||||
case '?':
|
||||
r_core_cmd_help (core, help_msg_ec);
|
||||
break;
|
||||
case 'o': // "eco"
|
||||
switch (input[2]) {
|
||||
case 'j':
|
||||
nextpal (core, 'j');
|
||||
break;
|
||||
case '*':
|
||||
r_core_cmd_callf (core, "cat %s", core->themepath);
|
||||
break;
|
||||
case '!':
|
||||
free (r_core_editor (core, core->themepath, NULL));
|
||||
cmd_load_theme (core, core->theme); // reload
|
||||
break;
|
||||
case ' ':
|
||||
cmd_load_theme (core, input + 3);
|
||||
break;
|
||||
case 'o':
|
||||
cmd_load_theme (core, core->theme);
|
||||
break;
|
||||
case 'c':
|
||||
case '.':
|
||||
r_cons_printf ("%s\n", core->theme);
|
||||
break;
|
||||
case '?':
|
||||
r_core_cmd_help (core, help_msg_eco);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
RList *themes_list = r_core_list_themes (core);
|
||||
RListIter *th_iter;
|
||||
const char *th;
|
||||
const RConsTheme *themes = r_cons_themes ();
|
||||
const RConsTheme *theme = themes;
|
||||
while (theme && theme->name) {
|
||||
const char *th = theme->name;
|
||||
if (input[2] == 'q') {
|
||||
r_cons_printf ("%s\n", th);
|
||||
} else if (core->theme && !strcmp (core->theme, th)) {
|
||||
r_cons_printf ("- %s\n", th);
|
||||
} else {
|
||||
r_cons_printf (" %s\n", th);
|
||||
}
|
||||
theme++;
|
||||
}
|
||||
r_list_foreach (themes_list, th_iter, th) {
|
||||
if (is_static_theme (th)) {
|
||||
continue;
|
||||
}
|
||||
if (input[2] == 'q') {
|
||||
r_cons_printf ("%s\n", th);
|
||||
} else if (core->theme && !strcmp (core->theme, th)) {
|
||||
r_cons_printf ("- %s\n", th);
|
||||
} else {
|
||||
r_cons_printf (" %s\n", th);
|
||||
}
|
||||
}
|
||||
r_list_free (themes_list);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 's': // "ecs"
|
||||
r_cons_pal_show ();
|
||||
break;
|
||||
case '*': // "ec*"
|
||||
r_cons_pal_list (1, NULL);
|
||||
break;
|
||||
case 'h': // echo
|
||||
if (input[2] == 'o') {
|
||||
r_core_echo (core, input + 3);
|
||||
} else {
|
||||
r_cons_pal_list ('h', NULL);
|
||||
}
|
||||
break;
|
||||
case 'j': // "ecj"
|
||||
r_cons_pal_list ('j', NULL);
|
||||
break;
|
||||
case 'c': // "ecc"
|
||||
r_cons_pal_list ('c', input + 2);
|
||||
break;
|
||||
case '\0': // "ec"
|
||||
r_cons_pal_list (0, NULL);
|
||||
break;
|
||||
case 'r': // "ecr"
|
||||
r_cons_pal_random ();
|
||||
break;
|
||||
case 'n': // "ecn"
|
||||
nextpal (core, 'n');
|
||||
break;
|
||||
case 'p': // "ecp"
|
||||
nextpal (core, 'p');
|
||||
break;
|
||||
case 'H': { // "ecH"
|
||||
char *color_code = NULL;
|
||||
char *word = NULL;
|
||||
int argc = 0;
|
||||
int delta = (input[2])? 3: 2;
|
||||
char** argv = r_str_argv (r_str_trim_head_ro (input + delta), &argc);
|
||||
switch (input[2]) {
|
||||
case '?':
|
||||
r_core_cmd_help (core, help_msg_ecH);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '-': // ecH-
|
||||
if (input[3] == '*') {
|
||||
r_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, 0, UT64_MAX);
|
||||
} else {
|
||||
r_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, 1);
|
||||
// r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, "");
|
||||
}
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '.':
|
||||
r_meta_print_list_in_function (core->anal, R_META_TYPE_HIGHLIGHT, 0, core->offset, NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '\0':
|
||||
r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 0, NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case 'j':
|
||||
r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 'j', NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '*':
|
||||
r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, '*', NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case ' ':
|
||||
case 'i': // "ecHi"
|
||||
if (argc) {
|
||||
char *dup = r_str_newf ("bgonly %s", argv[0]);
|
||||
color_code = r_cons_pal_parse (dup, NULL);
|
||||
R_FREE (dup);
|
||||
if (!color_code) {
|
||||
R_LOG_ERROR ("Unknown color %s", argv[0]);
|
||||
r_str_argv_free (argv);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'w': // "ecHw"
|
||||
if (!argc) {
|
||||
r_core_cmd_help_match (core, help_msg_ecH, "ecHw");
|
||||
r_str_argv_free (argv);
|
||||
return true;
|
||||
}
|
||||
word = strdup (argv[0]);
|
||||
if (argc > 1) {
|
||||
char *dup = r_str_newf ("bgonly %s", argv[1]);
|
||||
color_code = r_cons_pal_parse (dup, NULL);
|
||||
R_FREE (dup);
|
||||
if (!color_code) {
|
||||
R_LOG_ERROR ("Unknown color %s", argv[1]);
|
||||
r_str_argv_free (argv);
|
||||
free (word);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
R_LOG_INFO ("See ecH?");
|
||||
r_str_argv_free (argv);
|
||||
return true;
|
||||
}
|
||||
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, "");
|
||||
const char *str = r_meta_get_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset);
|
||||
char *dup = r_str_newf ("%s \"%s%s\"", r_str_get (str), r_str_get (word),
|
||||
color_code ? color_code : r_cons_singleton ()->context->pal.wordhl);
|
||||
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, dup);
|
||||
r_str_argv_free (argv);
|
||||
R_FREE (word);
|
||||
R_FREE (dup);
|
||||
}
|
||||
break;
|
||||
case ' ':
|
||||
{
|
||||
char *p = strdup (input + 2);
|
||||
char *q = strchr (p, '=');
|
||||
if (!q) {
|
||||
q = strchr (p, ' ');
|
||||
}
|
||||
if (q) {
|
||||
// Set color
|
||||
*q++ = 0;
|
||||
if (r_cons_pal_set (p, q)) {
|
||||
r_cons_pal_update_event ();
|
||||
}
|
||||
} else {
|
||||
char color[32] = {0};
|
||||
RColor rcolor = r_cons_pal_get (p);
|
||||
r_cons_rgb_str (color, sizeof (color), &rcolor);
|
||||
if (*color) {
|
||||
eprintf ("(%s)(%sCOLOR"Color_RESET")\n", p, color);
|
||||
} else {
|
||||
R_LOG_ERROR ("Invalid palette color '%s'", p);
|
||||
}
|
||||
}
|
||||
free (p);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
r_core_return_invalid_command (core, "ec", input[1]);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int cmd_eval(void *data, const char *input) {
|
||||
RCore *core = (RCore *)data;
|
||||
switch (input[0]) {
|
||||
@ -529,198 +744,7 @@ static int cmd_eval(void *data, const char *input) {
|
||||
r_config_list (core->config, NULL, 'q');
|
||||
break;
|
||||
case 'c': // "ec"
|
||||
switch (input[1]) {
|
||||
case 'd': // "ecd"
|
||||
r_cons_pal_init (core->cons->context);
|
||||
break;
|
||||
case '?':
|
||||
r_core_cmd_help (core, help_msg_ec);
|
||||
break;
|
||||
case 'o': // "eco"
|
||||
if (input[2] == 'j') {
|
||||
nextpal (core, 'j');
|
||||
} else if (input[2] == '*') {
|
||||
r_core_cmd_callf (core, "cat %s", core->themepath);
|
||||
} else if (input[2] == '!') {
|
||||
char *res = r_core_editor (core, core->themepath, NULL);
|
||||
free (res);
|
||||
cmd_load_theme (core, core->theme); // reload
|
||||
} else if (input[2] == ' ') {
|
||||
cmd_load_theme (core, input + 3);
|
||||
} else if (input[2] == 'o') {
|
||||
cmd_load_theme (core, core->theme);
|
||||
} else if (input[2] == 'c' || input[2] == '.') {
|
||||
r_cons_printf ("%s\n", core->theme);
|
||||
} else if (input[2] == '?') {
|
||||
r_core_cmd_help (core, help_msg_eco);
|
||||
} else {
|
||||
RList *themes_list = r_core_list_themes (core);
|
||||
RListIter *th_iter;
|
||||
const char *th;
|
||||
const RConsTheme *themes = r_cons_themes ();
|
||||
const RConsTheme *theme = themes;
|
||||
while (theme && theme->name) {
|
||||
const char *th = theme->name;
|
||||
if (input[2] == 'q') {
|
||||
r_cons_printf ("%s\n", th);
|
||||
} else if (core->theme && !strcmp (core->theme, th)) {
|
||||
r_cons_printf ("- %s\n", th);
|
||||
} else {
|
||||
r_cons_printf (" %s\n", th);
|
||||
}
|
||||
theme++;
|
||||
}
|
||||
r_list_foreach (themes_list, th_iter, th) {
|
||||
if (is_static_theme (th)) {
|
||||
continue;
|
||||
}
|
||||
if (input[2] == 'q') {
|
||||
r_cons_printf ("%s\n", th);
|
||||
} else if (core->theme && !strcmp (core->theme, th)) {
|
||||
r_cons_printf ("- %s\n", th);
|
||||
} else {
|
||||
r_cons_printf (" %s\n", th);
|
||||
}
|
||||
}
|
||||
r_list_free (themes_list);
|
||||
}
|
||||
break;
|
||||
case 's': // "ecs"
|
||||
r_cons_pal_show ();
|
||||
break;
|
||||
case '*': // "ec*"
|
||||
r_cons_pal_list (1, NULL);
|
||||
break;
|
||||
case 'h': // echo
|
||||
if (input[2] == 'o') {
|
||||
r_core_echo (core, input + 3);
|
||||
} else {
|
||||
r_cons_pal_list ('h', NULL);
|
||||
}
|
||||
break;
|
||||
case 'j': // "ecj"
|
||||
r_cons_pal_list ('j', NULL);
|
||||
break;
|
||||
case 'c': // "ecc"
|
||||
r_cons_pal_list ('c', input + 2);
|
||||
break;
|
||||
case '\0': // "ec"
|
||||
r_cons_pal_list (0, NULL);
|
||||
break;
|
||||
case 'r': // "ecr"
|
||||
r_cons_pal_random ();
|
||||
break;
|
||||
case 'n': // "ecn"
|
||||
nextpal (core, 'n');
|
||||
break;
|
||||
case 'p': // "ecp"
|
||||
nextpal (core, 'p');
|
||||
break;
|
||||
case 'H': { // "ecH"
|
||||
char *color_code = NULL;
|
||||
char *word = NULL;
|
||||
int argc = 0;
|
||||
int delta = (input[2])? 3: 2;
|
||||
char** argv = r_str_argv (r_str_trim_head_ro (input + delta), &argc);
|
||||
switch (input[2]) {
|
||||
case '?':
|
||||
r_core_cmd_help (core, help_msg_ecH);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '-': // ecH-
|
||||
if (input[3] == '*') {
|
||||
r_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, 0, UT64_MAX);
|
||||
} else {
|
||||
r_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, 1);
|
||||
// r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, "");
|
||||
}
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '.':
|
||||
r_meta_print_list_in_function (core->anal, R_META_TYPE_HIGHLIGHT, 0, core->offset, NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '\0':
|
||||
r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 0, NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case 'j':
|
||||
r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 'j', NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case '*':
|
||||
r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, '*', NULL);
|
||||
r_str_argv_free (argv);
|
||||
return false;
|
||||
case ' ':
|
||||
case 'i': // "ecHi"
|
||||
if (argc) {
|
||||
char *dup = r_str_newf ("bgonly %s", argv[0]);
|
||||
color_code = r_cons_pal_parse (dup, NULL);
|
||||
R_FREE (dup);
|
||||
if (!color_code) {
|
||||
R_LOG_ERROR ("Unknown color %s", argv[0]);
|
||||
r_str_argv_free (argv);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'w': // "ecHw"
|
||||
if (!argc) {
|
||||
r_core_cmd_help_match (core, help_msg_ecH, "ecHw");
|
||||
r_str_argv_free (argv);
|
||||
return true;
|
||||
}
|
||||
word = strdup (argv[0]);
|
||||
if (argc > 1) {
|
||||
char *dup = r_str_newf ("bgonly %s", argv[1]);
|
||||
color_code = r_cons_pal_parse (dup, NULL);
|
||||
R_FREE (dup);
|
||||
if (!color_code) {
|
||||
R_LOG_ERROR ("Unknown color %s", argv[1]);
|
||||
r_str_argv_free (argv);
|
||||
free (word);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
R_LOG_INFO ("See ecH?");
|
||||
r_str_argv_free (argv);
|
||||
return true;
|
||||
}
|
||||
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, "");
|
||||
const char *str = r_meta_get_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset);
|
||||
char *dup = r_str_newf ("%s \"%s%s\"", r_str_get (str), r_str_get (word),
|
||||
color_code ? color_code : r_cons_singleton ()->context->pal.wordhl);
|
||||
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, dup);
|
||||
r_str_argv_free (argv);
|
||||
R_FREE (word);
|
||||
R_FREE (dup);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
char *p = strdup (input + 2);
|
||||
char *q = strchr (p, '=');
|
||||
if (!q) {
|
||||
q = strchr (p, ' ');
|
||||
}
|
||||
if (q) {
|
||||
// Set color
|
||||
*q++ = 0;
|
||||
if (r_cons_pal_set (p, q)) {
|
||||
r_cons_pal_update_event ();
|
||||
}
|
||||
} else {
|
||||
char color[32];
|
||||
RColor rcolor = r_cons_pal_get (p);
|
||||
r_cons_rgb_str (color, sizeof (color), &rcolor);
|
||||
eprintf ("(%s)(%sCOLOR"Color_RESET")\n", p, color);
|
||||
}
|
||||
free (p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
return cmd_ec (core, input);
|
||||
case 'd': // "ed"
|
||||
if (input[1] == '?') {
|
||||
r_core_cmd_help_contains (core, help_msg_e, "ed");
|
||||
|
Loading…
Reference in New Issue
Block a user