mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-10 00:02:39 +00:00
Handle e cmd.pdc=<tab> and improve e cmd.pdc=? autocompletion ##shell (#14337)
This commit is contained in:
parent
77c043c582
commit
e553241ccf
@ -416,6 +416,21 @@ static bool cb_asmassembler(void *user, void *data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void update_cmdpdc_options(RCore *core, RConfigNode *node) {
|
||||
r_return_if_fail (core && core->assembler && node);
|
||||
RListIter *iter;
|
||||
r_list_purge (node->options);
|
||||
char *opts = r_core_cmd_str (core, "e cmd.pdc=?");
|
||||
RList *optl = r_str_split_list (opts, "\n");
|
||||
char *opt;
|
||||
node->options->free = free;
|
||||
r_list_foreach (optl, iter, opt) {
|
||||
SETOPTIONS (node, strdup (opt), NULL);
|
||||
}
|
||||
r_list_free (optl);
|
||||
free (opts);
|
||||
}
|
||||
|
||||
static void update_asmcpu_options(RCore *core, RConfigNode *node) {
|
||||
RAsmPlugin *h;
|
||||
RListIter *iter;
|
||||
@ -1092,30 +1107,35 @@ static bool cb_cfg_fortunes_type(void *user, void *data) {
|
||||
}
|
||||
|
||||
static bool cb_cmdpdc(void *user, void *data) {
|
||||
RCore *core = (RCore *) user;
|
||||
RConfigNode *node = (RConfigNode *)data;
|
||||
if (node->value[0] == '?') {
|
||||
r_cons_printf ("pdc\n");
|
||||
// spaguetti
|
||||
char *retdec = r_file_path ("r2retdec");
|
||||
if (retdec) {
|
||||
if (retdec && *retdec == '/') {
|
||||
r_cons_printf ("!*r2retdec\n");
|
||||
free (retdec);
|
||||
}
|
||||
char *ghidra = r_file_path ("r2ghidra");
|
||||
if (ghidra) {
|
||||
if (ghidra && *ghidra == '/') {
|
||||
r_cons_printf ("!*r2ghidra\n");
|
||||
free (ghidra);
|
||||
}
|
||||
char *r2jadx = r_file_path ("r2jadx");
|
||||
if (r2jadx) {
|
||||
if (r2jadx && *r2jadx == '/') {
|
||||
r_cons_printf ("!*r2jadx\n");
|
||||
free (r2jadx);
|
||||
}
|
||||
char *r2snow = r_file_path ("r2snow");
|
||||
if (r2snow) {
|
||||
if (r2snow && *r2snow == '/') {
|
||||
r_cons_printf (".!r2snow\n");
|
||||
free (r2snow);
|
||||
}
|
||||
RConfigNode *r2dec = r_config_node_get (core->config, "r2dec.asm");
|
||||
if (r2dec) {
|
||||
r_cons_printf ("pdd\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -3200,7 +3220,9 @@ R_API int r_core_config_init(RCore *core) {
|
||||
SETPREF ("cmd.hit", "", "Run when a search hit is found");
|
||||
SETPREF ("cmd.open", "", "Run when file is opened");
|
||||
SETPREF ("cmd.load", "", "Run when binary is loaded");
|
||||
SETCB ("cmd.pdc", "", &cb_cmdpdc, "Select pseudo-decompiler command to run after pdc");
|
||||
RConfigNode *cmdpdc = NODECB ("cmd.pdc", "", &cb_cmdpdc);
|
||||
SETDESC (cmdpdc, "Select pseudo-decompiler command to run after pdc");
|
||||
update_cmdpdc_options (core, cmdpdc);
|
||||
SETCB ("cmd.log", "", &cb_cmdlog, "Every time a new T log is added run this command");
|
||||
SETPREF ("cmd.prompt", "", "Prompt commands");
|
||||
SETCB ("cmd.repeat", "false", &cb_cmdrepeat, "Empty command an alias for '..' (repeat last command)");
|
||||
@ -3516,3 +3538,8 @@ R_API int r_core_config_init(RCore *core) {
|
||||
r_config_lock (cfg, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API void r_core_config_update(RCore *core) {
|
||||
RConfigNode *cmdpdc = r_config_node_get (core->config, "cmd.pdc");
|
||||
update_cmdpdc_options (core, cmdpdc);
|
||||
}
|
||||
|
@ -2249,10 +2249,9 @@ static void tmpenvs_free(void *item) {
|
||||
}
|
||||
|
||||
static bool set_tmp_arch(RCore *core, char *arch, char **tmparch) {
|
||||
if (tmparch == NULL ) {
|
||||
if (!tmparch) {
|
||||
eprintf ("tmparch should be set\n");
|
||||
}
|
||||
|
||||
*tmparch = strdup (r_config_get (core->config, "asm.arch"));
|
||||
r_config_set (core->config, "asm.arch", arch);
|
||||
core->fixedarch = true;
|
||||
@ -2260,10 +2259,9 @@ static bool set_tmp_arch(RCore *core, char *arch, char **tmparch) {
|
||||
}
|
||||
|
||||
static bool set_tmp_bits(RCore *core, int bits, char **tmpbits) {
|
||||
if (tmpbits == NULL) {
|
||||
if (!tmpbits) {
|
||||
eprintf ("tmpbits should be set\n");
|
||||
}
|
||||
|
||||
*tmpbits = strdup (r_config_get (core->config, "asm.bits"));
|
||||
r_config_set_i (core->config, "asm.bits", bits);
|
||||
core->fixedbits = true;
|
||||
|
@ -16,6 +16,7 @@ static const char *help_msg_L[] = {
|
||||
"La", "", "list asm/anal plugins (aL, e asm.arch=" "??" ")",
|
||||
"Lc", "", "list core plugins",
|
||||
"Ld", "", "list debug plugins (same as dL)",
|
||||
"LD", "", "list supported decompilers (e cmd.pdc=?)",
|
||||
"Lm", "", "list fs plugins (same as mL)",
|
||||
"Lh", "", "list hash plugins (same as ph)",
|
||||
"Li", "", "list bin plugins (same as iL)",
|
||||
@ -329,10 +330,10 @@ static int cmd_plugins(void *data, const char *input) {
|
||||
r_core_cmd_help (core, help_msg_L);
|
||||
break;
|
||||
case 'm': // "Lm"
|
||||
r_core_cmd0 (core, "mL");
|
||||
r_core_cmdf (core, "mL%s", input + 1);
|
||||
break;
|
||||
case 'd': // "Ld"
|
||||
r_core_cmd0 (core, "dL");
|
||||
r_core_cmdf (core, "dL%s", input + 1);
|
||||
break;
|
||||
case 'h': // "Lh"
|
||||
r_core_cmd0 (core, "ph"); // rahash2 -L is more verbose
|
||||
@ -340,6 +341,13 @@ static int cmd_plugins(void *data, const char *input) {
|
||||
case 'a': // "La"
|
||||
r_core_cmd0 (core, "e asm.arch=??");
|
||||
break;
|
||||
case 'D': // "LD"
|
||||
if (input[1] == ' ') {
|
||||
r_core_cmdf (core, "e cmd.pdc=%s", r_str_trim_ro (input + 2));
|
||||
} else {
|
||||
r_core_cmd0 (core, "e cmd.pdc=?");
|
||||
}
|
||||
break;
|
||||
case 'l': // "Ll"
|
||||
r_core_cmd0 (core, "#!");
|
||||
break;
|
||||
|
@ -1358,6 +1358,9 @@ static bool find_e_opts(RCore *core, RLineCompletion *completion, RLineBuffer *b
|
||||
RRegexMatch pmatch[2];
|
||||
bool ret = false;
|
||||
|
||||
// required to get the new list of items to autocomplete for cmd.pdc at least
|
||||
r_core_config_update (core);
|
||||
|
||||
if (r_regex_exec (rx, buf->data, nmatch, pmatch, 1)) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -361,6 +361,7 @@ R_API void r_core_wait(RCore *core);
|
||||
R_API RCore *r_core_ncast(ut64 p);
|
||||
R_API RCore *r_core_cast(void *p);
|
||||
R_API int r_core_config_init(RCore *core);
|
||||
R_API void r_core_config_update(RCore *core);
|
||||
R_API int r_core_prompt(RCore *core, int sync);
|
||||
R_API int r_core_prompt_exec(RCore *core);
|
||||
R_API int r_core_lines_initcache (RCore *core, ut64 start_addr, ut64 end_addr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user