Skip to content

Commit

Permalink
Convert pm to rz-shell
Browse files Browse the repository at this point in the history
  • Loading branch information
officialcjunior committed Sep 14, 2021
1 parent a1eb41a commit cbc9c9f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions librz/core/cmd_descs/cmd_descs.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static const RzCmdDescArg plugins_io_print_args[2];
static const RzCmdDescArg cmd_print_gadget_add_args[6];
static const RzCmdDescArg cmd_print_gadget_move_args[6];
static const RzCmdDescArg cmd_print_msg_digest_args[2];
static const RzCmdDescArg cmd_print_magic_args[2];
static const RzCmdDescArg project_save_args[2];
static const RzCmdDescArg project_open_args[2];
static const RzCmdDescArg project_open_no_bin_io_args[2];
Expand Down Expand Up @@ -3257,6 +3258,21 @@ static const RzCmdDescHelp cmd_print_timestamp_ntfs_help = {
.args = cmd_print_timestamp_ntfs_args,
};

static const RzCmdDescArg cmd_print_magic_args[] = {
{
.name = "file/directory",
.type = RZ_CMD_ARG_TYPE_STRING,
.flags = RZ_CMD_ARG_FLAG_LAST,
.optional = true,

},
{ 0 },
};
static const RzCmdDescHelp cmd_print_magic_help = {
.summary = "Print libmagic data",
.args = cmd_print_magic_args,
};

static const RzCmdDescHelp P_help = {
.summary = "Project management",
};
Expand Down Expand Up @@ -6183,6 +6199,9 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) {
RzCmdDesc *cmd_print_timestamp_ntfs_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_print_timestamp_cd, "ptn", rz_cmd_print_timestamp_ntfs_handler, &cmd_print_timestamp_ntfs_help);
rz_warn_if_fail(cmd_print_timestamp_ntfs_cd);

RzCmdDesc *cmd_print_magic_cd = rz_cmd_desc_argv_modes_new(core->rcmd, cmd_print_cd, "pm", RZ_OUTPUT_MODE_JSON, rz_cmd_print_magic_handler, &cmd_print_magic_help);
rz_warn_if_fail(cmd_print_magic_cd);

RzCmdDesc *P_cd = rz_cmd_desc_group_new(core->rcmd, root_cd, "P", NULL, NULL, &P_help);
rz_warn_if_fail(P_cd);
RzCmdDesc *project_save_cd = rz_cmd_desc_argv_new(core->rcmd, P_cd, "Ps", rz_project_save_handler, &project_save_help);
Expand Down
1 change: 1 addition & 0 deletions librz/core/cmd_descs/cmd_descs.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ RZ_IPI RzCmdStatus rz_cmd_print_timestamp_current_handler(RzCore *core, int argc
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_dos_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_hfs_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_ntfs_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_magic_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode);
RZ_IPI int rz_cmd_print(void *data, const char *input);
RZ_IPI RzCmdStatus rz_project_save_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_project_open_handler(RzCore *core, int argc, const char **argv);
Expand Down
9 changes: 9 additions & 0 deletions librz/core/cmd_descs/cmd_print.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,12 @@ commands:
summary: Print NTFS time (64 bit `cfg.bigendian`, since January 1, 1601)
cname: cmd_print_timestamp_ntfs
args: []
- name: pm
summary: Print libmagic data
cname: cmd_print_magic
args:
- name: file/directory
type: RZ_CMD_ARG_TYPE_STRING
optional: true
modes:
- RZ_OUTPUT_MODE_JSON
13 changes: 13 additions & 0 deletions librz/core/cmd_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,19 @@ RZ_IPI RzCmdStatus rz_cmd_print_msg_digest_algo_list_handler(RzCore *core, int a
return rz_core_hash_plugins_print(state);
}

RZ_IPI RzCmdStatus rz_cmd_print_magic_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode) {
if (mode == RZ_OUTPUT_MODE_JSON) {
PJ *pj = pj_new();
rz_core_magic(core, argv[1], true, pj);
rz_cons_println(pj_string(pj));
pj_free(pj);
} else {
// XXX: need cmd_magic header for rz_core_magic
rz_core_magic(core, argv[1], true, NULL);
}
return RZ_CMD_STATUS_OK;
}

// XXX blocksize is missing
static void cmd_print_pv(RzCore *core, const char *input, bool useBytes) {
const char *stack[] = {
Expand Down

0 comments on commit cbc9c9f

Please sign in to comment.