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);
}
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);
if (invalid_plugin) {
*invalid_plugin = false;
}
RzConfig *cfg = NULL;
if (!rz_str_startswith(config_str, "plugins")) {
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, '.');
bool cfg_found = false;
if (!second_dot) {
if (RZ_STR_ISEMPTY(first_dot + 1)) {
return NULL;
}
cfg = ht_sp_find(core->plugin_configs, first_dot + 1, &cfg_found);
} else {
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) {
RZ_LOG_DEBUG("Did not find plugin config with name '%s'\n", config_str);
if (invalid_plugin) {
*invalid_plugin = true;
}
return NULL;
}
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) {
int 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;
}
RzConfig *cfg = NULL;
if (!(cfg = eval_get_config_obj_by_key(core, key))) {
print_all_plugin_configs(core);
return RZ_CMD_STATUS_OK;
RzCmdStatus status;
RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, key, &status);
if (!cfg) {
rz_list_free(l);
return status;
}
if (llen == 1 && rz_str_endswith(key, ".")) {
// 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) {
const char *arg = argc > 1 ? argv[1] : "";
RzConfig *cfg = NULL;
if (!(cfg = eval_get_config_obj_by_key(core, arg))) {
print_all_plugin_configs(core);
return RZ_CMD_STATUS_OK;
RzCmdStatus status;
RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, arg, &status);
if (!cfg) {
return status;
}
rz_core_config_print_all(cfg, arg, state);
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) {
RzConfig *cfg = NULL;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) {
print_all_plugin_configs(core);
return RZ_CMD_STATUS_OK;
RzCmdStatus status;
RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
if (!cfg) {
return status;
}
if (!rz_config_toggle(cfg, 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) {
RzConfig *cfg = NULL;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) {
print_all_plugin_configs(core);
return RZ_CMD_STATUS_OK;
RzCmdStatus status;
RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
if (!cfg) {
return status;
}
char *val = rz_config_get_as_string(cfg, argv[1]);
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) {
RzConfig *cfg = NULL;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) {
print_all_plugin_configs(core);
return RZ_CMD_STATUS_OK;
RzCmdStatus status;
RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
if (!cfg) {
return status;
}
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) {
RzConfig *cfg = NULL;
if (!(cfg = eval_get_config_obj_by_key(core, argv[1]))) {
print_all_plugin_configs(core);
return RZ_CMD_STATUS_OK;
RzCmdStatus status;
RzConfig *cfg = eval_get_config_obj_by_key_or_error(core, argv[1], &status);
if (!cfg) {
return status;
}
RzConfigNode *node = rz_config_node_get(cfg, argv[1]);
if (!node) {

View file

@ -193,15 +193,15 @@ zoom.to=0
EOF
RUN
NAME=List and set plugin configurations
NAME=List and set hexagon plugin configurations
FILE==
CMDS=<<EOF
el plugins
el plugins.hexagon
# Should print nothing
el plugins
el plugins.hexagon
e asm.arch=hexagon
# Now it should print the hexagon options.
el plugins.
el plugins.hexagon
# Check if it only prints a specific sub-category.
el plugins.hexagon.imm
# Check if a value change is performed properly.
@ -215,16 +215,42 @@ pi 1
# Disable plugin.
e asm.arch=x86
# Should print no hexagon options anymore
el plugins.
el plugins.hexagon
EOF
EXPECT=<<EOF
plugins.hexagon.imm.hash=true
plugins.hexagon.imm.sign=true
plugins.hexagon.reg.alias=true
plugins.hexagon.sdk=false
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.reg.alias: Print the alias of registers (Alias from C0 = SA0).
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.sign: True: Print them with sign. False: Print signed immediates in unsigned representation.
[ allocframe(SP,#0x8):raw
[ allocframe(SP,0x8):raw
EOF
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