Skip to content

Commit

Permalink
cmd: filtering La commands output (#4786)
Browse files Browse the repository at this point in the history
  • Loading branch information
well-mannered-goat authored Dec 26, 2024
1 parent f517248 commit d771043
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 18 deletions.
28 changes: 18 additions & 10 deletions librz/core/casm.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ static const char *has_esil(RzCore *core, const char *name) {
return "___";
}

RZ_API RzCmdStatus rz_core_asm_plugin_print(RzCore *core, RzAsmPlugin *ap, const char *arch, RzCmdStateOutput *state, const char *license) {
const char *feat2, *feat;
RZ_API RzCmdStatus rz_core_asm_plugin_print(RzCore *core, RzAsmPlugin *ap, RzCmdStateOutput *state, const char *license, const char *flags) {
const char *feat2;
char feat[6] = "__";
char bits[32];
PJ *pj = state->d.pj;
bits[0] = 0;
Expand All @@ -120,17 +121,24 @@ RZ_API RzCmdStatus rz_core_asm_plugin_print(RzCore *core, RzAsmPlugin *ap, const
strcat(bits, "64");
}
}
feat = "__";

if (ap->assemble && ap->disassemble) {
feat = "ad";
strcpy(feat, "ad");
}
if (ap->assemble && !ap->disassemble) {
feat = "a_";
strcpy(feat, "a_");
}
if (!ap->assemble && ap->disassemble) {
feat = "_d";
strcpy(feat, "_d");
}
feat2 = has_esil(core, ap->name);
strcat(feat, feat2);

for (int i = 0; flags && flags[i] != '\0'; i++) {
if (strchr(feat, flags[i]) == NULL) {
return RZ_CMD_STATUS_OK;
}
}
switch (state->mode) {
case RZ_OUTPUT_MODE_QUIET: {
rz_cons_println(ap->name);
Expand All @@ -146,8 +154,8 @@ RZ_API RzCmdStatus rz_core_asm_plugin_print(RzCore *core, RzAsmPlugin *ap, const
break;
}
case RZ_OUTPUT_MODE_STANDARD: {
rz_cons_printf("%s%s %-10s %-11s %-7s %s",
feat, feat2, bits, ap->name, license, ap->desc);
rz_cons_printf("%s %-10s %-11s %-7s %s",
feat, bits, ap->name, license, ap->desc);
if (ap->author) {
rz_cons_printf(" (by %s)", ap->author);
}
Expand All @@ -165,7 +173,7 @@ RZ_API RzCmdStatus rz_core_asm_plugin_print(RzCore *core, RzAsmPlugin *ap, const
return RZ_CMD_STATUS_OK;
}

RZ_API RzCmdStatus rz_core_asm_plugins_print(RZ_NONNULL RZ_BORROW RzCore *core, RZ_NULLABLE const char *arch, RZ_OUT RzCmdStateOutput *state) {
RZ_API RzCmdStatus rz_core_asm_plugins_print(RZ_NONNULL RZ_BORROW RzCore *core, RZ_NULLABLE const char *arch, RZ_OUT RzCmdStateOutput *state, RZ_NULLABLE const char *flags) {
rz_return_val_if_fail(core && state, RZ_CMD_STATUS_ERROR);
int i;
RzAsm *a = core->rasm;
Expand Down Expand Up @@ -197,7 +205,7 @@ RZ_API RzCmdStatus rz_core_asm_plugins_print(RZ_NONNULL RZ_BORROW RzCore *core,
const char *license = ap->license
? ap->license
: "unknown";
status = rz_core_asm_plugin_print(core, ap, arch, state, license);
status = rz_core_asm_plugin_print(core, ap, state, license, flags);
if (status != RZ_CMD_STATUS_OK) {
rz_iterator_free(iter);
rz_list_free(plugin_list);
Expand Down
4 changes: 2 additions & 2 deletions librz/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ static bool cb_asmcpu(void *user, void *data) {
/* print verbose help instead of plain option listing */
RzCmdStateOutput state = { 0 };
rz_cmd_state_output_init(&state, RZ_OUTPUT_MODE_STANDARD);
rz_core_asm_plugins_print(core, rz_config_get(core->config, "asm.arch"), &state);
rz_core_asm_plugins_print(core, rz_config_get(core->config, "asm.arch"), &state, NULL);
rz_cmd_state_output_print(&state);
rz_cmd_state_output_fini(&state);
return 0;
Expand Down Expand Up @@ -500,7 +500,7 @@ static bool cb_asmarch(void *user, void *data) {
/* print more verbose help instead of plain option values */
RzCmdStateOutput state = { 0 };
rz_cmd_state_output_init(&state, RZ_OUTPUT_MODE_STANDARD);
rz_core_asm_plugins_print(core, NULL, &state);
rz_core_asm_plugins_print(core, NULL, &state, NULL);
rz_cmd_state_output_print(&state);
rz_cmd_state_output_fini(&state);
return false;
Expand Down
2 changes: 1 addition & 1 deletion librz/core/cmd/cmd_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -5497,7 +5497,7 @@ RZ_IPI RzCmdStatus rz_list_mne_handler(RzCore *core, int argc, const char **argv
}

RZ_IPI RzCmdStatus rz_list_plugins_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
return rz_core_asm_plugins_print(core, NULL, state);
return rz_core_asm_plugins_print(core, NULL, state, NULL);
}

RZ_IPI RzCmdStatus rz_analyse_name_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
Expand Down
5 changes: 4 additions & 1 deletion librz/core/cmd/cmd_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ RZ_IPI RzCmdStatus rz_plugins_lang_print_handler(RzCore *core, int argc, const c
}

RZ_IPI RzCmdStatus rz_plugins_asm_print_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
return rz_core_asm_plugins_print(core, NULL, state);
if (argc > 1) {
return rz_core_asm_plugins_print(core, NULL, state, argv[1]);
}
return rz_core_asm_plugins_print(core, NULL, state, NULL);
}

RZ_IPI RzCmdStatus rz_plugins_core_print_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
Expand Down
8 changes: 8 additions & 0 deletions librz/core/cmd_descs/cmd_descs.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ static const RzCmdDescArg sdb_namespace_dump_args[3];
static const RzCmdDescArg sdb_namespace_load_args[3];
static const RzCmdDescArg plugins_load_args[2];
static const RzCmdDescArg plugins_unload_args[2];
static const RzCmdDescArg plugins_asm_print_args[2];
static const RzCmdDescArg plugins_debug_print_args[2];
static const RzCmdDescArg plugins_io_print_args[2];
static const RzCmdDescArg open_args[4];
Expand Down Expand Up @@ -12160,6 +12161,13 @@ static const RzCmdDescHelp plugins_lang_print_help = {
};

static const RzCmdDescArg plugins_asm_print_args[] = {
{
.name = "features",
.type = RZ_CMD_ARG_TYPE_STRING,
.flags = RZ_CMD_ARG_FLAG_LAST,
.optional = true,

},
{ 0 },
};
static const RzCmdDescHelp plugins_asm_print_help = {
Expand Down
5 changes: 4 additions & 1 deletion librz/core/cmd_descs/cmd_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ commands:
cname: plugins_asm_print
summary: List the asm/analysis plugins
type: RZ_CMD_DESC_TYPE_ARGV_STATE
args: []
args:
- name: features
type: RZ_CMD_ARG_TYPE_STRING
optional: true
modes:
- RZ_OUTPUT_MODE_QUIET
- RZ_OUTPUT_MODE_STANDARD
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ RZ_API RzList /*<RzCoreAsmHit *>*/ *rz_core_asm_hit_list_new(void);
RZ_API void rz_core_asm_hit_free(void *_hit);
RZ_API void rz_core_set_asm_configs(RzCore *core, char *arch, ut32 bits, int segoff);
RZ_API char *rz_core_asm_search(RzCore *core, const char *input);
RZ_API RzCmdStatus rz_core_asm_plugins_print(RZ_NONNULL RZ_BORROW RzCore *core, RZ_NULLABLE const char *arch, RZ_OUT RzCmdStateOutput *state);
RZ_API RzCmdStatus rz_core_asm_plugins_print(RZ_NONNULL RZ_BORROW RzCore *core, RZ_NULLABLE const char *arch, RZ_OUT RzCmdStateOutput *state, RZ_NULLABLE const char *flags);
RZ_API RzList /*<RzCoreAsmHit *>*/ *rz_core_asm_strsearch(RzCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte, int mode);
RZ_API RzList /*<RzCoreAsmHit *>*/ *rz_core_asm_bwdisassemble(RzCore *core, ut64 addr, int n, int len);
RZ_API RzList /*<RzCoreAsmHit *>*/ *rz_core_asm_back_disassemble_instr(RzCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding);
Expand Down
2 changes: 1 addition & 1 deletion librz/main/rz-asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ RZ_API int rz_main_rz_asm(int argc, const char *argv[]) {
core->analysis = as->analysis;
RzCmdStateOutput state = { 0 };
rz_cmd_state_output_init(&state, as->json ? RZ_OUTPUT_MODE_JSON : RZ_OUTPUT_MODE_STANDARD);
rz_core_asm_plugins_print(core, opt.argv[opt.ind], &state);
rz_core_asm_plugins_print(core, opt.argv[opt.ind], &state, NULL);
rz_cmd_state_output_print(&state);
rz_cmd_state_output_fini(&state);
rz_cons_flush();
Expand Down
136 changes: 135 additions & 1 deletion test/db/cmd/cmd_list

Large diffs are not rendered by default.

0 comments on commit d771043

Please sign in to comment.