Skip to content

Commit

Permalink
Change aezv variable assignment to use "=".
Browse files Browse the repository at this point in the history
  • Loading branch information
treseco committed Apr 24, 2024
1 parent 5cae4cc commit 6019fe0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
38 changes: 31 additions & 7 deletions librz/core/cmd/cmd_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -4676,15 +4676,39 @@ RZ_IPI RzCmdStatus rz_il_vm_step_until_addr_handler(RzCore *core, int argc, cons
}

RZ_IPI RzCmdStatus rz_il_vm_status_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode) {
if (argc == 3) {
ut64 value = rz_num_math(core->num, argv[2]);
if (rz_core_analysis_il_vm_set(core, argv[1], value)) {
rz_cons_printf("%s = 0x%" PFMT64x "\n", argv[1], value);
if (argc > 1) {
RzList *l = rz_str_split_duplist_n(argv[1], "=", 1, true);
if (!l) {
return RZ_CMD_STATUS_ERROR;
}
} else {
// print variable or all variables
rz_core_analysis_il_vm_status(core, argc == 2 ? argv[1] : NULL, mode);
size_t llen = rz_list_length(l);
if (!llen) {
rz_list_free(l);
return RZ_CMD_STATUS_ERROR;
}
const char *varname = rz_list_get_n(l, 0);
if (RZ_STR_ISEMPTY(varname)) {
RZ_LOG_ERROR("core: No string specified before `=`. Make sure to use the format <var_name>=<value>.\n");
rz_list_free(l);
return RZ_CMD_STATUS_ERROR;
}

if (llen == 2) {
// assign variable
const char *valstr = rz_list_get_n(l, 1);
ut64 value = rz_num_math(core->num, valstr);
if (rz_core_analysis_il_vm_set(core, varname, value)) {
rz_cons_printf("%s = 0x%" PFMT64x "\n", varname, value);
}
} else {
// print variable
rz_core_analysis_il_vm_status(core, varname, mode);
}
rz_list_free(l);
return RZ_CMD_STATUS_OK;
}
// print all variables
rz_core_analysis_il_vm_status(core, NULL, mode);
return RZ_CMD_STATUS_OK;
}

Expand Down
9 changes: 4 additions & 5 deletions librz/core/cmd_descs/cmd_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ commands:
type: RZ_CMD_ARG_TYPE_RZNUM
- name: aezv
summary: Print or modify the current status of the RzIL Virtual Machine
args_str: " [<var_name> [= <val>]]"
cname: il_vm_status
type: RZ_CMD_DESC_TYPE_ARGV_MODES
modes:
Expand All @@ -1000,11 +1001,9 @@ commands:
- RZ_OUTPUT_MODE_JSON
- RZ_OUTPUT_MODE_QUIET
args:
- name: var_name
type: RZ_CMD_ARG_TYPE_STRING
optional: true
- name: number
type: RZ_CMD_ARG_TYPE_RZNUM
- name: var_name=value
type: RZ_CMD_ARG_TYPE_EVAL_FULL
flags: RZ_CMD_ARG_FLAG_LAST
optional: true
- name: ag
summary: Analysis graph commands
Expand Down
11 changes: 3 additions & 8 deletions librz/core/cmd_descs/cmd_descs.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static const RzCmdDescArg il_step_until_opt_args[2];
static const RzCmdDescArg il_vm_step_args[2];
static const RzCmdDescArg il_vm_step_with_events_args[2];
static const RzCmdDescArg il_vm_step_until_addr_args[2];
static const RzCmdDescArg il_vm_status_args[3];
static const RzCmdDescArg il_vm_status_args[2];
static const RzCmdDescArg analysis_graph_dataref_args[2];
static const RzCmdDescArg analysis_graph_dataref_global_args[2];
static const RzCmdDescArg analysis_graph_callgraph_function_args[2];
Expand Down Expand Up @@ -4048,14 +4048,8 @@ static const RzCmdDescHelp il_vm_step_until_addr_help = {

static const RzCmdDescArg il_vm_status_args[] = {
{
.name = "var_name",
.name = "var_name=value",
.type = RZ_CMD_ARG_TYPE_STRING,
.optional = true,

},
{
.name = "number",
.type = RZ_CMD_ARG_TYPE_RZNUM,
.flags = RZ_CMD_ARG_FLAG_LAST,
.optional = true,

Expand All @@ -4064,6 +4058,7 @@ static const RzCmdDescArg il_vm_status_args[] = {
};
static const RzCmdDescHelp il_vm_status_help = {
.summary = "Print or modify the current status of the RzIL Virtual Machine",
.args_str = " [<var_name> [= <val>]]",
.args = il_vm_status_args,
};

Expand Down
4 changes: 2 additions & 2 deletions test/db/cmd/cmd_aez
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ s 0
aezi
aezv
echo --
aezv PC 0x42
aezv PC=0x42
aezv
echo --
aezv ptr 0xc0ffee
aezv ptr=0xc0ffee
aezv
EOF
EXPECT=<<EOF
Expand Down
2 changes: 1 addition & 1 deletion test/db/rzil/tricore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ e io.cache=1
aaa
s main
aezi
aezv FCX 0x1
aezv FCX=0x1
aezsu 0x8000052e
ps @ obj.seckrit
EOF
Expand Down

0 comments on commit 6019fe0

Please sign in to comment.