Skip to content

Commit

Permalink
Port ae command to RzShell
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Nov 23, 2024
1 parent 3556a7e commit 5c37cca
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
38 changes: 21 additions & 17 deletions librz/core/cmd/cmd_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,12 +1443,6 @@ static void __analysis_esil_function(RzCore *core, ut64 addr) {

static void cmd_analysis_esil(RzCore *core, const char *input) {
RzAnalysisEsil *esil = core->analysis->esil;
int stacksize = rz_config_get_i(core->config, "esil.stack.depth");
int iotrap = rz_config_get_i(core->config, "esil.iotrap");
int romem = rz_config_get_i(core->config, "esil.romem");
int stats = rz_config_get_i(core->config, "esil.stats");
int noNULL = rz_config_get_i(core->config, "esil.noNULL");
unsigned int addrsize = rz_config_get_i(core->config, "esil.addr.size");

switch (input[0]) {
case 'p':
Expand Down Expand Up @@ -1476,17 +1470,6 @@ static void cmd_analysis_esil(RzCore *core, const char *input) {
RZ_LOG_ERROR("core: esil vm not initialized. run `aei`\n");
}
break;
case ' ': // "ae "
// rz_analysis_esil_eval (core->analysis, input+1);
if (!esil && !(core->analysis->esil = esil = rz_analysis_esil_new(stacksize, iotrap, addrsize))) {
return;
}
rz_analysis_esil_setup(esil, core->analysis, romem, stats, noNULL); // setup io
rz_analysis_esil_set_pc(esil, core->offset);
rz_analysis_esil_parse(esil, input + 1);
rz_core_esil_dumpstack(esil);
rz_analysis_esil_stack_free(esil);
break;
case 'k': // "aek"
switch (input[1]) {
case '\0': // "aek"
Expand Down Expand Up @@ -6563,3 +6546,24 @@ RZ_IPI RzCmdStatus rz_analysis_data_trampoline_handler(RzCore *core, int argc, c
print_trampolines(core, minimum, maximum, bits / 8);
return RZ_CMD_STATUS_OK;
}

RZ_IPI RzCmdStatus rz_analyze_esil_eval_expr_handler(RzCore *core, int argc, const char **argv) {
int stacksize = rz_config_get_i(core->config, "esil.stack.depth");
int iotrap = rz_config_get_i(core->config, "esil.iotrap");
int romem = rz_config_get_i(core->config, "esil.romem");
int stats = rz_config_get_i(core->config, "esil.stats");
int noNULL = rz_config_get_i(core->config, "esil.noNULL");
unsigned int addrsize = rz_config_get_i(core->config, "esil.addr.size");

RzAnalysisEsil *esil = core->analysis->esil;

if (!esil && !(core->analysis->esil = esil = rz_analysis_esil_new(stacksize, iotrap, addrsize))) {
return RZ_CMD_STATUS_ERROR;
}
rz_analysis_esil_setup(esil, core->analysis, romem, stats, noNULL); // setup io
rz_analysis_esil_set_pc(esil, core->offset);
rz_analysis_esil_parse(esil, argv[0]);
rz_core_esil_dumpstack(esil);
rz_analysis_esil_stack_free(esil);
return RZ_CMD_STATUS_OK;
}
10 changes: 10 additions & 0 deletions librz/core/cmd_descs/cmd_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2402,3 +2402,13 @@ commands:
modes:
- RZ_OUTPUT_MODE_STANDARD
- RZ_OUTPUT_MODE_JSON
- name: cmd_esil
summary: ESIL analysis commands
subcommands:
- name: ae
summary: Analyze all flags starting with sym. and entry
cname: analyze_esil_eval_expr
args:
- name: expr
type: RZ_CMD_ARG_TYPE_STRING
optional: true
24 changes: 24 additions & 0 deletions librz/core/cmd_descs/cmd_descs.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ static const RzCmdDescArg analysis_syscall_dump_assembly_args[2];
static const RzCmdDescArg analysis_syscall_dump_c_args[2];
static const RzCmdDescArg analysis_syscall_name_args[2];
static const RzCmdDescArg analysis_syscall_number_args[2];
static const RzCmdDescArg analyze_esil_eval_expr_args[2];
static const RzCmdDescArg block_args[2];
static const RzCmdDescArg block_decrease_args[2];
static const RzCmdDescArg block_increase_args[2];
Expand Down Expand Up @@ -6440,6 +6441,24 @@ static const RzCmdDescHelp list_plugins_help = {
.args = list_plugins_args,
};

static const RzCmdDescHelp cmd_esil_help = {
.summary = "ESIL analysis commands",
};
static const RzCmdDescArg analyze_esil_eval_expr_args[] = {
{
.name = "expr",
.type = RZ_CMD_ARG_TYPE_STRING,
.flags = RZ_CMD_ARG_FLAG_LAST,
.optional = true,

},
{ 0 },
};
static const RzCmdDescHelp analyze_esil_eval_expr_help = {
.summary = "Analyze all flags starting with sym. and entry",
.args = analyze_esil_eval_expr_args,
};

static const RzCmdDescHelp b_help = {
.summary = "Display or change the block size",
};
Expand Down Expand Up @@ -20279,6 +20298,11 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) {
RzCmdDesc *list_plugins_cd = rz_cmd_desc_argv_state_new(core->rcmd, cmd_analysis_cd, "aL", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_JSON, rz_list_plugins_handler, &list_plugins_help);
rz_warn_if_fail(list_plugins_cd);

RzCmdDesc *cmd_esil_cd = rz_cmd_desc_group_new(core->rcmd, cmd_analysis_cd, "cmd_esil", NULL, NULL, &cmd_esil_help);
rz_warn_if_fail(cmd_esil_cd);
RzCmdDesc *analyze_esil_eval_expr_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_esil_cd, "ae", rz_analyze_esil_eval_expr_handler, &analyze_esil_eval_expr_help);
rz_warn_if_fail(analyze_esil_eval_expr_cd);

RzCmdDesc *b_cd = rz_cmd_desc_group_state_new(core->rcmd, root_cd, "b", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_JSON | RZ_OUTPUT_MODE_RIZIN, rz_block_handler, &block_help, &b_help);
rz_warn_if_fail(b_cd);
RzCmdDesc *block_decrease_cd = rz_cmd_desc_argv_new(core->rcmd, b_cd, "b-", rz_block_decrease_handler, &block_decrease_help);
Expand Down
2 changes: 2 additions & 0 deletions librz/core/cmd_descs/cmd_descs.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ RZ_IPI RzCmdStatus rz_analysis_syscall_name_handler(RzCore *core, int argc, cons
RZ_IPI RzCmdStatus rz_analysis_syscall_number_handler(RzCore *core, int argc, const char **argv);
// "aL"
RZ_IPI RzCmdStatus rz_list_plugins_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state);
// "ae"
RZ_IPI RzCmdStatus rz_analyze_esil_eval_expr_handler(RzCore *core, int argc, const char **argv);
// "a"
RZ_IPI int rz_cmd_analysis(void *data, const char *input);
// "b"
Expand Down

0 comments on commit 5c37cca

Please sign in to comment.