Convert p2 and p8 commands to rzshell (#4250)
This commit is contained in:
parent
01c0159f6e
commit
f98ab29273
5 changed files with 132 additions and 43 deletions
|
|
@ -2335,7 +2335,7 @@ RZ_IPI RzCmdStatus rz_print_instructions_function_handler(RzCore *core, int argc
|
|||
const RzAnalysisFunction *f = rz_analysis_get_fcn_in(core->analysis, core->offset,
|
||||
RZ_ANALYSIS_FCN_TYPE_FCN | RZ_ANALYSIS_FCN_TYPE_SYM);
|
||||
if (!f) {
|
||||
RZ_LOG_ERROR("Cannot function at the specified address\n");
|
||||
RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
|
||||
return RZ_CMD_STATUS_ERROR;
|
||||
}
|
||||
ut64 fcn_size = rz_analysis_function_linear_size((RzAnalysisFunction *)f);
|
||||
|
|
@ -2375,7 +2375,6 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) {
|
|||
RzCore *core = (RzCore *)data;
|
||||
st64 l;
|
||||
int i, len, ret;
|
||||
ut8 *block;
|
||||
ut32 tbs = core->blocksize;
|
||||
ut64 n, off;
|
||||
ut64 tmpseek = UT64_MAX;
|
||||
|
|
@ -2458,8 +2457,6 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) {
|
|||
rz_core_seek(core, off, SEEK_SET);
|
||||
rz_core_block_read(core);
|
||||
}
|
||||
// TODO After core->block is removed, this should be changed to a block read.
|
||||
block = core->block;
|
||||
switch (*input) {
|
||||
case 'j': // "pj"
|
||||
if (input[1] == '?') {
|
||||
|
|
@ -2524,37 +2521,6 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) {
|
|||
}
|
||||
rz_cons_break_pop();
|
||||
break;
|
||||
case '2': // "p2"
|
||||
if (l) {
|
||||
if (input[1] == '?') {
|
||||
rz_cons_printf("|Usage: p2 [number of bytes representing tiles]\n"
|
||||
"NOTE: Only full tiles will be printed\n");
|
||||
} else {
|
||||
core_print_2bpp_tiles(core, len / 16);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '8': // "p8"
|
||||
if (input[1] == '?') {
|
||||
rz_cons_printf("|Usage: p8[fj] [len] 8bit hexpair list of bytes (see pcj)\n");
|
||||
rz_cons_printf(" p8 : print hexpairs string\n");
|
||||
rz_cons_printf(" p8f : print hexpairs of function (linear)\n");
|
||||
rz_cons_printf(" p8j : print hexpairs in JSON array\n");
|
||||
} else if (l) {
|
||||
if (!rz_core_block_size(core, len)) {
|
||||
len = core->blocksize;
|
||||
}
|
||||
if (input[1] == 'j') { // "p8j"
|
||||
rz_core_cmdf(core, "pcj %s", input + 2);
|
||||
} else if (input[1] == 'f') { // "p8f"
|
||||
rz_core_cmdf(core, "p8 $FS @ $FB");
|
||||
} else {
|
||||
rz_core_block_read(core);
|
||||
block = core->block;
|
||||
rz_print_bytes(core->print, block, len, "%02x");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
rz_core_cmd_help(core, help_msg_p);
|
||||
break;
|
||||
|
|
@ -6702,3 +6668,52 @@ RZ_IPI RzCmdStatus rz_cmd_print_format_value_handler(RzCore *core, int argc, con
|
|||
RZ_IPI RzCmdStatus rz_cmd_print_format_write_handler(RzCore *core, int argc, const char **argv) {
|
||||
return print_format_write(core, argv[1], argv[2]);
|
||||
}
|
||||
|
||||
RZ_IPI RzCmdStatus rz_cmd_print_2bpp_tiles_handler(RzCore *core, int argc, const char **argv) {
|
||||
size_t len = argc > 1 ? rz_num_math(core->num, argv[1]) : core->blocksize;
|
||||
if (len == 0) {
|
||||
return RZ_CMD_STATUS_OK;
|
||||
}
|
||||
core_print_2bpp_tiles(core, len / 16);
|
||||
return RZ_CMD_STATUS_OK;
|
||||
}
|
||||
|
||||
static RzCmdStatus print_8bit_hexpair(RzCore *core, ut64 addr, size_t len) {
|
||||
ut8 *buf = malloc(len);
|
||||
if (!buf) {
|
||||
RZ_LOG_ERROR("core: cannot allocate %zu byte(s)\n", len);
|
||||
return RZ_CMD_STATUS_ERROR;
|
||||
}
|
||||
rz_io_read_at(core->io, addr, buf, len);
|
||||
rz_print_bytes(core->print, buf, len, "%02x");
|
||||
return RZ_CMD_STATUS_OK;
|
||||
}
|
||||
|
||||
RZ_IPI RzCmdStatus rz_cmd_print_8bit_hexpair_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
|
||||
size_t len = argc > 1 ? rz_num_math(core->num, argv[1]) : core->blocksize;
|
||||
if (len == 0) {
|
||||
return RZ_CMD_STATUS_OK;
|
||||
}
|
||||
if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
|
||||
return print_8bit_hexpair(core, core->offset, len);
|
||||
}
|
||||
char *code = rz_lang_byte_array(core->block, len, RZ_LANG_BYTE_ARRAY_JSON);
|
||||
if (RZ_STR_ISEMPTY(code)) {
|
||||
free(code);
|
||||
return RZ_CMD_STATUS_ERROR;
|
||||
}
|
||||
rz_cons_print(code);
|
||||
free(code);
|
||||
return RZ_CMD_STATUS_OK;
|
||||
}
|
||||
|
||||
RZ_IPI RzCmdStatus rz_cmd_print_8bit_hexpair_function_handler(RzCore *core, int argc, const char **argv) {
|
||||
RzAnalysisFunction *f = rz_analysis_first_function_in(core->analysis, core->offset);
|
||||
if (!f) {
|
||||
RZ_LOG_ERROR("Cannot find function at 0x%08" PFMT64x "\n", core->offset);
|
||||
return RZ_CMD_STATUS_ERROR;
|
||||
}
|
||||
size_t len = rz_analysis_function_linear_size(f);
|
||||
ut64 addr = rz_analysis_function_min_addr(f);
|
||||
return print_8bit_hexpair(core, addr, len);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -566,6 +566,8 @@ static const RzCmdDescArg open_maps_prioritize_binid_args[2];
|
|||
static const RzCmdDescArg open_maps_deprioritize_args[2];
|
||||
static const RzCmdDescArg open_maps_prioritize_fd_args[2];
|
||||
static const RzCmdDescArg open_exchange_args[3];
|
||||
static const RzCmdDescArg cmd_print_2bpp_tiles_args[2];
|
||||
static const RzCmdDescArg cmd_print_8bit_hexpair_args[2];
|
||||
static const RzCmdDescArg print_bitstream_args[3];
|
||||
static const RzCmdDescArg print_byte_bitstream_args[2];
|
||||
static const RzCmdDescArg hex_of_assembly_args[2];
|
||||
|
|
@ -12568,6 +12570,47 @@ static const RzCmdDescHelp open_exchange_help = {
|
|||
static const RzCmdDescHelp cmd_print_help = {
|
||||
.summary = "Print commands",
|
||||
};
|
||||
static const RzCmdDescArg cmd_print_2bpp_tiles_args[] = {
|
||||
{
|
||||
.name = "n",
|
||||
.type = RZ_CMD_ARG_TYPE_RZNUM,
|
||||
.flags = RZ_CMD_ARG_FLAG_LAST,
|
||||
.optional = true,
|
||||
|
||||
},
|
||||
{ 0 },
|
||||
};
|
||||
static const RzCmdDescHelp cmd_print_2bpp_tiles_help = {
|
||||
.summary = "Print 8x8 2bpp tiles.",
|
||||
.args = cmd_print_2bpp_tiles_args,
|
||||
};
|
||||
|
||||
static const RzCmdDescHelp p8_help = {
|
||||
.summary = "Print 8bit hexpair list of bytes.",
|
||||
};
|
||||
static const RzCmdDescArg cmd_print_8bit_hexpair_args[] = {
|
||||
{
|
||||
.name = "n",
|
||||
.type = RZ_CMD_ARG_TYPE_RZNUM,
|
||||
.flags = RZ_CMD_ARG_FLAG_LAST,
|
||||
.optional = true,
|
||||
|
||||
},
|
||||
{ 0 },
|
||||
};
|
||||
static const RzCmdDescHelp cmd_print_8bit_hexpair_help = {
|
||||
.summary = "Print 8bit hexpair list of bytes.",
|
||||
.args = cmd_print_8bit_hexpair_args,
|
||||
};
|
||||
|
||||
static const RzCmdDescArg cmd_print_8bit_hexpair_function_args[] = {
|
||||
{ 0 },
|
||||
};
|
||||
static const RzCmdDescHelp cmd_print_8bit_hexpair_function_help = {
|
||||
.summary = "Print 8bit hexpair list of bytes in function (linear).",
|
||||
.args = cmd_print_8bit_hexpair_function_args,
|
||||
};
|
||||
|
||||
static const RzCmdDescArg print_bitstream_args[] = {
|
||||
{
|
||||
.name = "n",
|
||||
|
|
@ -21521,6 +21564,14 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) {
|
|||
|
||||
RzCmdDesc *cmd_print_cd = rz_cmd_desc_oldinput_new(core->rcmd, root_cd, "p", rz_cmd_print, &cmd_print_help);
|
||||
rz_warn_if_fail(cmd_print_cd);
|
||||
RzCmdDesc *cmd_print_2bpp_tiles_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_print_cd, "p2", rz_cmd_print_2bpp_tiles_handler, &cmd_print_2bpp_tiles_help);
|
||||
rz_warn_if_fail(cmd_print_2bpp_tiles_cd);
|
||||
|
||||
RzCmdDesc *p8_cd = rz_cmd_desc_group_state_new(core->rcmd, cmd_print_cd, "p8", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_JSON, rz_cmd_print_8bit_hexpair_handler, &cmd_print_8bit_hexpair_help, &p8_help);
|
||||
rz_warn_if_fail(p8_cd);
|
||||
RzCmdDesc *cmd_print_8bit_hexpair_function_cd = rz_cmd_desc_argv_new(core->rcmd, p8_cd, "p8f", rz_cmd_print_8bit_hexpair_function_handler, &cmd_print_8bit_hexpair_function_help);
|
||||
rz_warn_if_fail(cmd_print_8bit_hexpair_function_cd);
|
||||
|
||||
RzCmdDesc *print_bitstream_cd = rz_cmd_desc_argv_modes_new(core->rcmd, cmd_print_cd, "pb", RZ_OUTPUT_MODE_STANDARD, rz_print_bitstream_handler, &print_bitstream_help);
|
||||
rz_warn_if_fail(print_bitstream_cd);
|
||||
|
||||
|
|
|
|||
|
|
@ -1728,6 +1728,12 @@ RZ_IPI RzCmdStatus rz_open_maps_deprioritize_handler(RzCore *core, int argc, con
|
|||
RZ_IPI RzCmdStatus rz_open_maps_prioritize_fd_handler(RzCore *core, int argc, const char **argv);
|
||||
// "ox"
|
||||
RZ_IPI RzCmdStatus rz_open_exchange_handler(RzCore *core, int argc, const char **argv);
|
||||
// "p2"
|
||||
RZ_IPI RzCmdStatus rz_cmd_print_2bpp_tiles_handler(RzCore *core, int argc, const char **argv);
|
||||
// "p8"
|
||||
RZ_IPI RzCmdStatus rz_cmd_print_8bit_hexpair_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state);
|
||||
// "p8f"
|
||||
RZ_IPI RzCmdStatus rz_cmd_print_8bit_hexpair_function_handler(RzCore *core, int argc, const char **argv);
|
||||
// "pb"
|
||||
RZ_IPI RzCmdStatus rz_print_bitstream_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode);
|
||||
// "pB"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,31 @@
|
|||
---
|
||||
name: cmd_print
|
||||
commands:
|
||||
- name: p2
|
||||
summary: Print 8x8 2bpp tiles.
|
||||
cname: cmd_print_2bpp_tiles
|
||||
args:
|
||||
- name: n
|
||||
type: RZ_CMD_ARG_TYPE_RZNUM
|
||||
optional: true
|
||||
- name: p8
|
||||
summary: Print 8bit hexpair list of bytes.
|
||||
subcommands:
|
||||
- name: p8
|
||||
summary: Print 8bit hexpair list of bytes.
|
||||
cname: cmd_print_8bit_hexpair
|
||||
type: RZ_CMD_DESC_TYPE_ARGV_STATE
|
||||
modes:
|
||||
- RZ_OUTPUT_MODE_STANDARD
|
||||
- RZ_OUTPUT_MODE_JSON
|
||||
args:
|
||||
- name: n
|
||||
type: RZ_CMD_ARG_TYPE_RZNUM
|
||||
optional: true
|
||||
- name: p8f
|
||||
summary: Print 8bit hexpair list of bytes in function (linear).
|
||||
cname: cmd_print_8bit_hexpair_function
|
||||
args: []
|
||||
- name: pb
|
||||
summary: Print bitstream of <n> bits, skipping the first <skip> bits.
|
||||
cname: print_bitstream
|
||||
|
|
|
|||
|
|
@ -271,14 +271,6 @@ EXPECT=<<EOF
|
|||
EOF
|
||||
RUN
|
||||
|
||||
NAME=p8 -10
|
||||
FILE=malloc://1024
|
||||
CMDS=wx 90909090909090909090 ; s 10 ; p8 -10
|
||||
EXPECT=<<EOF
|
||||
90909090909090909090
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=pi 3
|
||||
FILE=malloc://512
|
||||
CMDS=<<EOF
|
||||
|
|
|
|||
Loading…
Reference in a new issue