Skip to content

Commit

Permalink
flags: new fdt command to print more information about flag
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed May 18, 2024
1 parent d9a10a9 commit b8991fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
31 changes: 30 additions & 1 deletion librz/core/cmd/cmd_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ RZ_IPI void rz_core_flag_describe(RzCore *core, ut64 addr, bool strict_offset, R
return;
}
PJ *pj = state->d.pj;
rz_cmd_state_output_set_columnsf(state, "ssXXds", "name", "realname",
"vaddr", "paddr", "size", "comment");
switch (state->mode) {
case RZ_OUTPUT_MODE_JSON:
pj_o(pj);
Expand All @@ -341,6 +343,21 @@ RZ_IPI void rz_core_flag_describe(RzCore *core, ut64 addr, bool strict_offset, R
}
pj_end(pj);
break;
case RZ_OUTPUT_MODE_TABLE: {
// Print realname if exists and asm.flags.real is enabled
const char *name = core->flags->realnames && f->realname ? f->realname : f->name;
ut64 paddr = rz_io_v2p(core->io, addr);
if (f->offset != addr) {
char *descr_name = rz_str_newf("%s + %d", name, (int)(addr - f->offset));
rz_table_add_rowf(state->d.t, "ssXXds", f->name, descr_name,
addr, paddr, f->size, f->comment);
free(descr_name);
} else {
rz_table_add_rowf(state->d.t, "ssXXds", f->name, name, addr,
paddr, f->size, f->comment);
}
break;
}
case RZ_OUTPUT_MODE_STANDARD: {
// Print realname if exists and asm.flags.real is enabled
const char *name = core->flags->realnames && f->realname ? f->realname : f->name;
Expand Down Expand Up @@ -369,6 +386,8 @@ RZ_IPI RzCmdStatus rz_flag_describe_at_handler(RzCore *core, int argc, const cha
}
PJ *pj = state->d.pj;
rz_cmd_state_output_array_start(state);
rz_cmd_state_output_set_columnsf(state, "ssXXds", "name", "realname",
"vaddr", "paddr", "size", "comment");
RzFlagItem *flag;
RzListIter *iter;
// Sometimes an address has multiple flags assigned to, show them all
Expand All @@ -385,14 +404,24 @@ RZ_IPI RzCmdStatus rz_flag_describe_at_handler(RzCore *core, int argc, const cha
}
pj_end(pj);
break;
case RZ_OUTPUT_MODE_STANDARD:
case RZ_OUTPUT_MODE_TABLE: {
// Print realname if exists and asm.flags.real is enabled
const char *name = core->flags->realnames && flag->realname ? flag->realname : flag->name;
ut64 paddr = rz_io_v2p(core->io, flag->offset);
rz_table_add_rowf(state->d.t, "ssXXds", flag->name, name,
flag->offset, paddr, flag->size, flag->comment);
break;
}
case RZ_OUTPUT_MODE_STANDARD: {
// Print realname if exists and asm.flags.real is enabled
if (core->flags->realnames && flag->realname) {
rz_cons_println(flag->realname);
} else {
rz_cons_println(flag->name);
}
break;
}

default:
rz_warn_if_reached();
break;
Expand Down
4 changes: 2 additions & 2 deletions librz/core/cmd_descs/cmd_descs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21123,10 +21123,10 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) {
RzCmdDesc *flag_comment_cd = rz_cmd_desc_argv_new(core->rcmd, f_cd, "fC", rz_flag_comment_handler, &flag_comment_help);
rz_warn_if_fail(flag_comment_cd);

RzCmdDesc *fd_cd = rz_cmd_desc_group_state_new(core->rcmd, f_cd, "fd", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_JSON, rz_flag_describe_handler, &flag_describe_help, &fd_help);
RzCmdDesc *fd_cd = rz_cmd_desc_group_state_new(core->rcmd, f_cd, "fd", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_TABLE | RZ_OUTPUT_MODE_JSON, rz_flag_describe_handler, &flag_describe_help, &fd_help);
rz_warn_if_fail(fd_cd);
rz_cmd_desc_set_default_mode(fd_cd, RZ_OUTPUT_MODE_STANDARD);
RzCmdDesc *flag_describe_at_cd = rz_cmd_desc_argv_state_new(core->rcmd, fd_cd, "fd.", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_JSON, rz_flag_describe_at_handler, &flag_describe_at_help);
RzCmdDesc *flag_describe_at_cd = rz_cmd_desc_argv_state_new(core->rcmd, fd_cd, "fd.", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_TABLE | RZ_OUTPUT_MODE_JSON, rz_flag_describe_at_handler, &flag_describe_at_help);
rz_warn_if_fail(flag_describe_at_cd);
rz_cmd_desc_set_default_mode(flag_describe_at_cd, RZ_OUTPUT_MODE_STANDARD);

Expand Down
2 changes: 2 additions & 0 deletions librz/core/cmd_descs/cmd_flag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ commands:
default_mode: RZ_OUTPUT_MODE_STANDARD
modes:
- RZ_OUTPUT_MODE_STANDARD
- RZ_OUTPUT_MODE_TABLE
- RZ_OUTPUT_MODE_JSON
args: []
- name: fd.
Expand All @@ -215,6 +216,7 @@ commands:
default_mode: RZ_OUTPUT_MODE_STANDARD
modes:
- RZ_OUTPUT_MODE_STANDARD
- RZ_OUTPUT_MODE_TABLE
- RZ_OUTPUT_MODE_JSON
args: []
- name: fdw
Expand Down

0 comments on commit b8991fa

Please sign in to comment.