lbrz/core/cmd: fix config print for plugins (#6567)

This commit is contained in:
MrQuantum1915 2026-07-09 19:55:59 +05:30 committed by GitHub
parent d2859bbfdd
commit de80709985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 85 additions and 34 deletions

View file

@ -444,8 +444,11 @@ static void print_all_plugin_configs(const RzCore *core) {
rz_cmd_state_output_fini(&state); rz_cmd_state_output_fini(&state);
} }
static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const char *config_str) { static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const char *config_str, bool *invalid_plugin) {
rz_return_val_if_fail(core && config_str, NULL); rz_return_val_if_fail(core && config_str, NULL);
if (invalid_plugin) {
*invalid_plugin = false;
}
RzConfig *cfg = NULL; RzConfig *cfg = NULL;
if (!rz_str_startswith(config_str, "plugins")) { if (!rz_str_startswith(config_str, "plugins")) {
return core->config; return core->config;
@ -459,6 +462,9 @@ static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const
const char *second_dot = strchr(first_dot + 1, '.'); const char *second_dot = strchr(first_dot + 1, '.');
bool cfg_found = false; bool cfg_found = false;
if (!second_dot) { if (!second_dot) {
if (RZ_STR_ISEMPTY(first_dot + 1)) {
return NULL;
}
cfg = ht_sp_find(core->plugin_configs, first_dot + 1, &cfg_found); cfg = ht_sp_find(core->plugin_configs, first_dot + 1, &cfg_found);
} else { } else {
char *config_name = rz_sub_str_ptr(config_str, first_dot + 1, second_dot - 1); char *config_name = rz_sub_str_ptr(config_str, first_dot + 1, second_dot - 1);
@ -467,11 +473,29 @@ static RZ_BORROW RzConfig *eval_get_config_obj_by_key(const RzCore *core, const
} }
if (!cfg_found) { if (!cfg_found) {
RZ_LOG_DEBUG("Did not find plugin config with name '%s'\n", config_str); RZ_LOG_DEBUG("Did not find plugin config with name '%s'\n", config_str);
if (invalid_plugin) {
*invalid_plugin = true;
}
return NULL; return NULL;
} }
return cfg; return cfg;
} }
static RZ_BORROW RzConfig *eval_get_config_obj_by_key_or_error(RzCore *core, const char *config_str, RzCmdStatus *status) {
bool invalid_plugin = false;
RzConfig *cfg = eval_get_config_obj_by_key(core, config_str, &invalid_plugin);
if (!cfg) {
if (invalid_plugin) {
RZ_LOG_ERROR("core: Invalid config key '%s'\n", config_str);
*status = RZ_CMD_STATUS_ERROR;
} else {
print_all_plugin_configs(core);
*status = RZ_CMD_STATUS_OK;
}
}
return cfg;
}
RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **argv) { RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **argv) {
int i; int i;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
@ -490,10 +514,11 @@ RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **a
continue; continue;
} }
RzConfig *cfg = NULL; RzCmdStatus status;
if (!(cfg = eval_get_config_obj_by_key(core, key))) { RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, key, &status);
print_all_plugin_configs(core); if (!cfg) {
return RZ_CMD_STATUS_OK; rz_list_free(l);
return status;
} }
if (llen == 1 && rz_str_endswith(key, ".")) { if (llen == 1 && rz_str_endswith(key, ".")) {
// no value was set, only key with ".". List possible sub-keys. // no value was set, only key with ".". List possible sub-keys.
@ -523,10 +548,10 @@ RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **a
RZ_IPI RzCmdStatus rz_eval_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) { RZ_IPI RzCmdStatus rz_eval_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
const char *arg = argc > 1 ? argv[1] : ""; const char *arg = argc > 1 ? argv[1] : "";
RzConfig *cfg = NULL; RzCmdStatus status;
if (!(cfg = eval_get_config_obj_by_key(core, arg))) { RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, arg, &status);
print_all_plugin_configs(core); if (!cfg) {
return RZ_CMD_STATUS_OK; return status;
} }
rz_core_config_print_all(cfg, arg, state); rz_core_config_print_all(cfg, arg, state);
return RZ_CMD_STATUS_OK; return RZ_CMD_STATUS_OK;
@ -538,10 +563,10 @@ RZ_IPI RzCmdStatus rz_eval_reset_handler(RzCore *core, int argc, const char **ar
} }
RZ_IPI RzCmdStatus rz_eval_bool_invert_handler(RzCore *core, int argc, const char **argv) { RZ_IPI RzCmdStatus rz_eval_bool_invert_handler(RzCore *core, int argc, const char **argv) {
RzConfig *cfg = NULL; RzCmdStatus status;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
print_all_plugin_configs(core); if (!cfg) {
return RZ_CMD_STATUS_OK; return status;
} }
if (!rz_config_toggle(cfg, argv[1])) { if (!rz_config_toggle(cfg, argv[1])) {
RZ_LOG_ERROR("core: Cannot toggle config key '%s'\n", argv[1]); RZ_LOG_ERROR("core: Cannot toggle config key '%s'\n", argv[1]);
@ -551,10 +576,10 @@ RZ_IPI RzCmdStatus rz_eval_bool_invert_handler(RzCore *core, int argc, const cha
} }
RZ_IPI RzCmdStatus rz_eval_editor_handler(RzCore *core, int argc, const char **argv) { RZ_IPI RzCmdStatus rz_eval_editor_handler(RzCore *core, int argc, const char **argv) {
RzConfig *cfg = NULL; RzCmdStatus status;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
print_all_plugin_configs(core); if (!cfg) {
return RZ_CMD_STATUS_OK; return status;
} }
char *val = rz_config_get_as_string(cfg, argv[1]); char *val = rz_config_get_as_string(cfg, argv[1]);
if (!val) { if (!val) {
@ -572,10 +597,10 @@ RZ_IPI RzCmdStatus rz_eval_editor_handler(RzCore *core, int argc, const char **a
} }
RZ_IPI RzCmdStatus rz_eval_readonly_handler(RzCore *core, int argc, const char **argv) { RZ_IPI RzCmdStatus rz_eval_readonly_handler(RzCore *core, int argc, const char **argv) {
RzConfig *cfg = NULL; RzCmdStatus status;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
print_all_plugin_configs(core); if (!cfg) {
return RZ_CMD_STATUS_OK; return status;
} }
if (!rz_config_set_readonly(cfg, argv[1], true)) { if (!rz_config_set_readonly(cfg, argv[1], true)) {
@ -601,10 +626,10 @@ RZ_IPI RzCmdStatus rz_eval_spaces_handler(RzCore *core, int argc, const char **a
} }
RZ_IPI RzCmdStatus rz_eval_type_handler(RzCore *core, int argc, const char **argv) { RZ_IPI RzCmdStatus rz_eval_type_handler(RzCore *core, int argc, const char **argv) {
RzConfig *cfg = NULL; RzCmdStatus status;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) { RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
print_all_plugin_configs(core); if (!cfg) {
return RZ_CMD_STATUS_OK; return status;
} }
RzConfigNode *node = rz_config_node_get(cfg, argv[1]); RzConfigNode *node = rz_config_node_get(cfg, argv[1]);
if (!node) { if (!node) {

View file

@ -193,15 +193,15 @@ zoom.to=0
EOF EOF
RUN RUN
NAME=List and set plugin configurations NAME=List and set hexagon plugin configurations
FILE== FILE==
CMDS=<<EOF CMDS=<<EOF
el plugins el plugins.hexagon
# Should print nothing # Should print nothing
el plugins el plugins.hexagon
e asm.arch=hexagon e asm.arch=hexagon
# Now it should print the hexagon options. # Now it should print the hexagon options.
el plugins. el plugins.hexagon
# Check if it only prints a specific sub-category. # Check if it only prints a specific sub-category.
el plugins.hexagon.imm el plugins.hexagon.imm
# Check if a value change is performed properly. # Check if a value change is performed properly.
@ -215,16 +215,42 @@ pi 1
# Disable plugin. # Disable plugin.
e asm.arch=x86 e asm.arch=x86
# Should print no hexagon options anymore # Should print no hexagon options anymore
el plugins. el plugins.hexagon
EOF EOF
EXPECT=<<EOF EXPECT=<<EOF
plugins.hexagon.imm.hash=true plugins.hexagon.imm.hash: Display ## before 32bit immediates and # before immidiates with other width.
plugins.hexagon.imm.sign=true plugins.hexagon.imm.sign: True: Print them with sign. False: Print signed immediates in unsigned representation.
plugins.hexagon.reg.alias=true plugins.hexagon.reg.alias: Print the alias of registers (Alias from C0 = SA0).
plugins.hexagon.sdk=false plugins.hexagon.sdk: Print packet syntax in objdump style.
plugins.hexagon.imm.hash: Display ## before 32bit immediates and # before immidiates with other width. plugins.hexagon.imm.hash: Display ## before 32bit immediates and # before immidiates with other width.
plugins.hexagon.imm.sign: True: Print them with sign. False: Print signed immediates in unsigned representation. plugins.hexagon.imm.sign: True: Print them with sign. False: Print signed immediates in unsigned representation.
[ allocframe(SP,#0x8):raw [ allocframe(SP,#0x8):raw
[ allocframe(SP,0x8):raw [ allocframe(SP,0x8):raw
EOF EOF
RUN RUN
NAME=Invalid plugin config key errors
FILE==
CMDS=<<EOF
e plugins.missing
e plugins.missing=true
e plugins.missing.
el plugins.missing
e! plugins.missing
ee plugins.missing
er plugins.missing
et plugins.missing
EOF
EXPECT=
EXPECT_ERR=<<EOF
ERROR: core: Invalid config key 'plugins.missing'
ERROR: core: Invalid config key 'plugins.missing'
ERROR: core: Invalid config key 'plugins.missing.'
ERROR: core: Invalid config key 'plugins.missing'
ERROR: core: Invalid config key 'plugins.missing'
ERROR: core: Invalid config key 'plugins.missing'
ERROR: core: Invalid config key 'plugins.missing'
ERROR: core: Invalid config key 'plugins.missing'
EOF
RUN