diff --git a/librz/core/cmd/cmd_analysis.c b/librz/core/cmd/cmd_analysis.c index 604d93d7ed8..16098ff8258 100644 --- a/librz/core/cmd/cmd_analysis.c +++ b/librz/core/cmd/cmd_analysis.c @@ -2013,6 +2013,24 @@ RZ_IPI RzCmdStatus rz_analysis_global_variable_rename_handler(RzCore *core, int return RZ_CMD_STATUS_OK; } +RZ_IPI RzCmdStatus rz_analysis_global_variable_print_handler(RzCore *core, int argc, const char **argv) { + const char *name = argv[1]; + RzAnalysisVarGlobal *glob = rz_analysis_var_global_get_byname(core->analysis, name); + if (!glob) { + RZ_LOG_ERROR("Global variable '%s' does not exist!\n", name); + return RZ_CMD_STATUS_ERROR; + } + char *fmt = rz_type_as_format_pair(core->analysis->typedb, glob->type); + if (RZ_STR_ISEMPTY(fmt)) { + free(fmt); + return RZ_CMD_STATUS_ERROR; + } + // TODO: Convert to the API + rz_core_cmdf(core, "pf %s @ 0x%08" PFMT64x "\n", fmt, glob->addr); + free(fmt); + return RZ_CMD_STATUS_OK; +} + RZ_IPI RzCmdStatus rz_analysis_global_variable_retype_handler(RzCore *core, int argc, const char **argv) { const char *name = argv[1]; const char *type = argv[2]; diff --git a/librz/core/cmd/cmd_type.c b/librz/core/cmd/cmd_type.c index 076f19b2b31..8e21828687a 100644 --- a/librz/core/cmd/cmd_type.c +++ b/librz/core/cmd/cmd_type.c @@ -92,6 +92,7 @@ static RzCmdStatus type_format_print(RzCore *core, const char *type, ut64 addres free(fmt); return RZ_CMD_STATUS_ERROR; } + // TODO: Convert to the API rz_core_cmdf(core, "pf %s @ 0x%08" PFMT64x "\n", fmt, address); free(fmt); return RZ_CMD_STATUS_OK; @@ -117,6 +118,7 @@ static RzCmdStatus type_format_print_variable(RzCore *core, const char *type, co return RZ_CMD_STATUS_ERROR; } ut64 addr = rz_core_analysis_var_addr(core, var); + // TODO: Convert to the API rz_core_cmdf(core, "pf %s @ 0x%08" PFMT64x "\n", fmt, addr); free(fmt); return RZ_CMD_STATUS_OK; @@ -129,6 +131,7 @@ static RzCmdStatus type_format_print_value(RzCore *core, const char *type, ut64 free(fmt); return RZ_CMD_STATUS_ERROR; } + // TODO: Convert to the API rz_core_cmdf(core, "pf %s @v:0x%08" PFMT64x "\n", fmt, val); free(fmt); return RZ_CMD_STATUS_OK; @@ -141,6 +144,7 @@ static RzCmdStatus type_format_print_hexstring(RzCore *core, const char *type, c free(fmt); return RZ_CMD_STATUS_ERROR; } + // TODO: Convert to the API rz_core_cmdf(core, "pf %s @x:%s", fmt, hexpairs); free(fmt); return RZ_CMD_STATUS_OK; diff --git a/librz/core/cmd_descs/cmd_analysis.yaml b/librz/core/cmd_descs/cmd_analysis.yaml index 4cfcc946612..1cea05080ee 100644 --- a/librz/core/cmd_descs/cmd_analysis.yaml +++ b/librz/core/cmd_descs/cmd_analysis.yaml @@ -1564,6 +1564,13 @@ commands: type: RZ_CMD_ARG_TYPE_GLOBAL_VAR - name: new_var_name type: RZ_CMD_ARG_TYPE_STRING + - name: avgp + summary: print the global variable value + type: RZ_CMD_DESC_TYPE_ARGV + cname: analysis_global_variable_print + args: + - name: name + type: RZ_CMD_ARG_TYPE_GLOBAL_VAR - name: avgt summary: change the global variable type type: RZ_CMD_DESC_TYPE_ARGV diff --git a/librz/core/cmd_descs/cmd_descs.c b/librz/core/cmd_descs/cmd_descs.c index bde8078f5aa..5dbe655e50f 100644 --- a/librz/core/cmd_descs/cmd_descs.c +++ b/librz/core/cmd_descs/cmd_descs.c @@ -248,6 +248,7 @@ static const RzCmdDescArg analysis_global_variable_add_args[3]; static const RzCmdDescArg analysis_global_variable_delete_byaddr_args[2]; static const RzCmdDescArg analysis_global_variable_delete_byname_args[2]; static const RzCmdDescArg analysis_global_variable_rename_args[3]; +static const RzCmdDescArg analysis_global_variable_print_args[2]; static const RzCmdDescArg analysis_global_variable_retype_args[3]; static const RzCmdDescArg analysis_rtti_demangle_class_name_args[2]; static const RzCmdDescArg analysis_xrefs_set_0_args[2]; @@ -4848,6 +4849,19 @@ static const RzCmdDescHelp analysis_global_variable_rename_help = { .args = analysis_global_variable_rename_args, }; +static const RzCmdDescArg analysis_global_variable_print_args[] = { + { + .name = "name", + .type = RZ_CMD_ARG_TYPE_GLOBAL_VAR, + + }, + { 0 }, +}; +static const RzCmdDescHelp analysis_global_variable_print_help = { + .summary = "print the global variable value", + .args = analysis_global_variable_print_args, +}; + static const RzCmdDescArg analysis_global_variable_retype_args[] = { { .name = "var_name", @@ -19478,6 +19492,9 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) { RzCmdDesc *analysis_global_variable_rename_cd = rz_cmd_desc_argv_new(core->rcmd, avg_cd, "avgn", rz_analysis_global_variable_rename_handler, &analysis_global_variable_rename_help); rz_warn_if_fail(analysis_global_variable_rename_cd); + RzCmdDesc *analysis_global_variable_print_cd = rz_cmd_desc_argv_new(core->rcmd, avg_cd, "avgp", rz_analysis_global_variable_print_handler, &analysis_global_variable_print_help); + rz_warn_if_fail(analysis_global_variable_print_cd); + RzCmdDesc *analysis_global_variable_retype_cd = rz_cmd_desc_argv_new(core->rcmd, avg_cd, "avgt", rz_analysis_global_variable_retype_handler, &analysis_global_variable_retype_help); rz_warn_if_fail(analysis_global_variable_retype_cd); diff --git a/librz/core/cmd_descs/cmd_descs.h b/librz/core/cmd_descs/cmd_descs.h index 1ded283effd..48414911714 100644 --- a/librz/core/cmd_descs/cmd_descs.h +++ b/librz/core/cmd_descs/cmd_descs.h @@ -561,6 +561,8 @@ RZ_IPI RzCmdStatus rz_analysis_global_variable_delete_byaddr_handler(RzCore *cor RZ_IPI RzCmdStatus rz_analysis_global_variable_delete_byname_handler(RzCore *core, int argc, const char **argv); // "avgn" RZ_IPI RzCmdStatus rz_analysis_global_variable_rename_handler(RzCore *core, int argc, const char **argv); +// "avgp" +RZ_IPI RzCmdStatus rz_analysis_global_variable_print_handler(RzCore *core, int argc, const char **argv); // "avgt" RZ_IPI RzCmdStatus rz_analysis_global_variable_retype_handler(RzCore *core, int argc, const char **argv); // "avr" diff --git a/test/db/cmd/cmd_avg b/test/db/cmd/cmd_avg index c86ca2ab223..3916d1e84c4 100644 --- a/test/db/cmd/cmd_avg +++ b/test/db/cmd/cmd_avg @@ -111,3 +111,32 @@ EXPECT_ERR=<