Skip to content

Commit

Permalink
Move the aei command into a separate internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Nov 17, 2023
1 parent 2e64ce0 commit 231b5f1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 69 deletions.
81 changes: 41 additions & 40 deletions libr/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ static bool cb_dbgbackend(void *user, void *data) {
RDebugPlugin *plugin = R_UNWRAP3 (core->dbg, current, plugin);
if (plugin) {
const char *name = plugin->meta.name;
r_core_cmd0 (core, "aei");
// cmd_aei (core);
free (node->value);
node->value = strdup (name);
}
Expand Down Expand Up @@ -3922,6 +3922,46 @@ R_API int r_core_config_init(RCore *core) {
SETI ("stack.size", 64, "size in bytes of stack hexdump in visual debug");
SETI ("stack.delta", 0, "delta for the stack dump");

/* cmd */
SETCB ("cmd.demangle", "false", &cb_bdc, "run xcrun swift-demangle and similar if available (SLOW)");
SETICB ("cmd.depth", 10, &cb_cmddepth, "maximum command depth");
SETPREF ("cmd.undo", "true", "stack `uc` undo commands when running some commands like w, af, CC, ..");
SETPREF ("cmd.bp", "", "run when a breakpoint is hit");
SETPREF ("cmd.onsyscall", "", "run when a syscall is hit");
SETICB ("cmd.hitinfo", 1, &cb_debug_hitinfo, "show info when a tracepoint/breakpoint is hit");
SETPREF ("cmd.stack", "", "command to display the stack in visual debug mode");
SETPREF ("cmd.cprompt", "", "column visual prompt commands");
SETPREF ("cmd.gprompt", "", "graph visual prompt commands");
SETPREF ("cmd.hit", "", "run when a search hit is found");
#if R2__UNIX__
SETPREF ("cmd.usr1", "", "run when SIGUSR1 signal is received");
SETPREF ("cmd.usr2", "", "run when SIGUSR2 signal is received");
#endif
SETPREF ("cmd.open", "", "run when file is opened");
SETPREF ("cmd.load", "", "run when binary is loaded");
SETPREF ("cmd.bbgraph", "", "show the output of this command in the graph basic blocks");
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)");
SETPREF ("cmd.fcn.new", "", "run when new function is analyzed");
SETPREF ("cmd.fcn.delete", "", "run when a function is deleted");
SETPREF ("cmd.fcn.rename", "", "run when a function is renamed");
SETPREF ("cmd.visual", "", "replace current print mode");
SETPREF ("cmd.vprompt", "", "visual prompt commands");
SETPREF ("cmd.step", "", "run command on every debugger step");

SETCB ("cmd.esil.pin", "", &cb_cmd_esil_pin, "command to execute everytime a pin is hit by the program counter");
SETCB ("cmd.esil.step", "", &cb_cmd_esil_step, "command to run before performing a step in the emulator");
SETCB ("cmd.esil.stepout", "", &cb_cmd_esil_step_out, "command to run after performing a step in the emulator");
SETCB ("cmd.esil.mdev", "", &cb_cmd_esil_mdev, "command to run when memory device address is accessed");
SETCB ("cmd.esil.intr", "", &cb_cmd_esil_intr, "command to run when an esil interrupt happens");
SETCB ("cmd.esil.trap", "", &cb_cmd_esil_trap, "command to run when an esil trap happens");
SETCB ("cmd.esil.todo", "", &cb_cmd_esil_todo, "command to run when the esil instruction contains TODO");
SETCB ("cmd.esil.ioer", "", &cb_cmd_esil_ioer, "command to run when esil fails to IO (invalid read/write)");

SETCB ("dbg.maxsnapsize", "32M", &cb_dbg_maxsnapsize, "dont make snapshots of maps bigger than a specific size");
SETCB ("dbg.wrap", "false", &cb_dbg_wrap, "enable the ptrace-wrap abstraction layer (needed for debugging from iaito)");
SETCB ("dbg.libs", "", &cb_dbg_libs, "If set stop when loading matching libname");
Expand Down Expand Up @@ -3989,45 +4029,6 @@ R_API int r_core_config_init(RCore *core) {
SETICB ("dbg.btdepth", 128, &cb_dbgbtdepth, "depth of backtrace");


/* cmd */
SETCB ("cmd.demangle", "false", &cb_bdc, "run xcrun swift-demangle and similar if available (SLOW)");
SETICB ("cmd.depth", 10, &cb_cmddepth, "maximum command depth");
SETPREF ("cmd.undo", "true", "stack `uc` undo commands when running some commands like w, af, CC, ..");
SETPREF ("cmd.bp", "", "run when a breakpoint is hit");
SETPREF ("cmd.onsyscall", "", "run when a syscall is hit");
SETICB ("cmd.hitinfo", 1, &cb_debug_hitinfo, "show info when a tracepoint/breakpoint is hit");
SETPREF ("cmd.stack", "", "command to display the stack in visual debug mode");
SETPREF ("cmd.cprompt", "", "column visual prompt commands");
SETPREF ("cmd.gprompt", "", "graph visual prompt commands");
SETPREF ("cmd.hit", "", "run when a search hit is found");
#if R2__UNIX__
SETPREF ("cmd.usr1", "", "run when SIGUSR1 signal is received");
SETPREF ("cmd.usr2", "", "run when SIGUSR2 signal is received");
#endif
SETPREF ("cmd.open", "", "run when file is opened");
SETPREF ("cmd.load", "", "run when binary is loaded");
SETPREF ("cmd.bbgraph", "", "show the output of this command in the graph basic blocks");
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)");
SETPREF ("cmd.fcn.new", "", "run when new function is analyzed");
SETPREF ("cmd.fcn.delete", "", "run when a function is deleted");
SETPREF ("cmd.fcn.rename", "", "run when a function is renamed");
SETPREF ("cmd.visual", "", "replace current print mode");
SETPREF ("cmd.vprompt", "", "visual prompt commands");
SETPREF ("cmd.step", "", "run command on every debugger step");

SETCB ("cmd.esil.pin", "", &cb_cmd_esil_pin, "command to execute everytime a pin is hit by the program counter");
SETCB ("cmd.esil.step", "", &cb_cmd_esil_step, "command to run before performing a step in the emulator");
SETCB ("cmd.esil.stepout", "", &cb_cmd_esil_step_out, "command to run after performing a step in the emulator");
SETCB ("cmd.esil.mdev", "", &cb_cmd_esil_mdev, "command to run when memory device address is accessed");
SETCB ("cmd.esil.intr", "", &cb_cmd_esil_intr, "command to run when an esil interrupt happens");
SETCB ("cmd.esil.trap", "", &cb_cmd_esil_trap, "command to run when an esil trap happens");
SETCB ("cmd.esil.todo", "", &cb_cmd_esil_todo, "command to run when the esil instruction contains TODO");
SETCB ("cmd.esil.ioer", "", &cb_cmd_esil_ioer, "command to run when esil fails to IO (invalid read/write)");

/* filesystem */
n = NODECB ("fs.view", "normal", &cb_fsview);
Expand Down
47 changes: 25 additions & 22 deletions libr/core/cmd_anal.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ static bool cmd_anal_aaft(RCore *core) {
seek = core->offset;
r_reg_arena_push (core->anal->reg);
r_reg_arena_zero (core->anal->reg);
r_core_cmd_call (core, "aei");
cmd_aei (core);
r_core_cmd_call (core, "aeim");
int saved_arena_size = 0;
ut8 *saved_arena = r_reg_arena_peek (core->anal->reg, &saved_arena_size);
Expand Down Expand Up @@ -7595,6 +7595,29 @@ static void cmd_debug_stack_init(RCore *core, int argc, char **argv, char **envp
r_buf_free (b);
}

R_IPI void cmd_aei(RCore *core) {
REsil *esil = esil_new_setup (core);
if (esil) {
r_esil_free (core->anal->esil);
core->anal->esil = esil;
r_esil_reset (esil);
const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC);
if (pc && r_reg_getv (core->anal->reg, pc) == 0LL) {
reg_name_roll_set (core, "PC", core->offset);
}
}
/* restore user settings for interrupt handling */
{
const char *s = r_config_get (core->config, "cmd.esil.intr");
if (s) {
char *my = strdup (s);
if (my) {
r_config_set (core->config, "cmd.esil.intr", my);
free (my);
}
}
}
}
R_IPI int core_type_by_addr(RCore *core, ut64 addr) {
const RList *list = r_flag_get_list (core->flags, addr);
RListIter *iter;
Expand Down Expand Up @@ -8255,27 +8278,7 @@ static void cmd_anal_esil(RCore *core, const char *input, bool verbose) {
r_esil_reset (esil);
break;
case 0: // "aei"
esil = esil_new_setup (core);
if (esil) {
r_esil_free (core->anal->esil);
core->anal->esil = esil;
r_esil_reset (esil);
const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC);
if (pc && r_reg_getv (core->anal->reg, pc) == 0LL) {
reg_name_roll_set (core, "PC", core->offset);
}
}
/* restore user settings for interrupt handling */
{
const char *s = r_config_get (core->config, "cmd.esil.intr");
if (s) {
char *my = strdup (s);
if (my) {
r_config_set (core->config, "cmd.esil.intr", my);
free (my);
}
}
}
cmd_aei (core);
break;
default:
cmd_esil_mem (core, "?");
Expand Down
6 changes: 3 additions & 3 deletions libr/core/cmd_debug.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4280,15 +4280,15 @@ static void r_core_debug_esil(RCore *core, const char *input) {
if (r_debug_esil_watch_empty (core->dbg)) {
R_LOG_ERROR ("no esil watchpoints defined");
} else {
r_core_cmd_call (core, "aei");
cmd_aei (core);
r_debug_esil_prestep (core->dbg, r_config_get_i (core->config, "esil.prestep"));
r_debug_esil_continue (core->dbg);
}
break;
case 's': // "des"
if (input[1] == 'u' && input[2] == ' ') { // "desu"
ut64 addr, naddr, fin = r_num_math (core->num, input + 2);
r_core_cmd_call (core, "aei");
cmd_aei (core);
addr = r_debug_reg_get (core->dbg, "PC");
while (addr != fin) {
r_debug_esil_prestep (core->dbg, r_config_get_i (
Expand All @@ -4304,7 +4304,7 @@ static void r_core_debug_esil(RCore *core, const char *input) {
} else if (input[1] == '?' || !input[1]) {
r_core_cmd_help (core, help_msg_des);
} else {
r_core_cmd_call (core, "aei");
cmd_aei (core);
r_debug_esil_prestep (core->dbg, r_config_get_i (core->config, "esil.prestep"));
// continue
r_debug_esil_step (core->dbg, r_num_math (core->num, input + 1));
Expand Down
7 changes: 3 additions & 4 deletions libr/core/cmd_search.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ static void do_esil_search(RCore *core, struct search_parameters *param, const c
const int stats = r_config_get_i (core->config, "esil.stats");
if (!core->anal->esil) {
// initialize esil vm
r_core_cmd_call (core, "aei");
cmd_aei (core);
if (!core->anal->esil) {
core->anal->esil = r_esil_new (stacksize, iotrap, addrsize);
R_LOG_ERROR ("Cannot initialize the ESIL vm");
Expand Down Expand Up @@ -2037,8 +2037,7 @@ static void do_syscall_search(RCore *core, struct search_parameters *param) {
return;
}

r_core_cmd0 (core, "aei"); // requied to have core->anal->esil initialized.. imho esil should never be NULL!
// r_core_cmd0 (core, "aeim");
cmd_aei (core);// requied to have core->anal->esil initialized.. imho esil should never be NULL!
ut64 oldoff = core->offset;
#if !USE_EMULATION
int syscallNumber = 0;
Expand Down Expand Up @@ -2420,7 +2419,7 @@ static void do_unkjmp_search(RCore *core, struct search_parameters *param, bool
}
if (!core->anal->esil) {
// initialize esil vm
r_core_cmd_call (core, "aei");
cmd_aei (core);
if (!core->anal->esil) {
R_LOG_ERROR ("Cannot initialize the ESIL vm");
return;
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ R_API int r_core_set_file_by_name(RBin * bin, const char *name);
R_API void r_core_debug_rr(RCore *core, RReg *reg, int mode);

/* fortune */
R_IPI void cmd_aei(RCore *core);
R_IPI RList *r_core_fortune_types(void);
R_API void r_core_fortune_list_types(void);
R_API void r_core_fortune_list(RCore *core);
Expand Down

0 comments on commit 231b5f1

Please sign in to comment.