Refactor the pointer command to use the API (#3788)
* Add test for pointer read command `*` Test for `asm.bits=8` uses `asm.arch=6502` because `asm.bits=8` is unsupported for the default arch. * Fix pointer command `*` broken since move from `?` to `%` ##shell * Refactor to use appropriate existing API in `num_callback`
This commit is contained in:
parent
cafebbf9c3
commit
eb78e75cd4
3 changed files with 34 additions and 15 deletions
|
|
@ -908,12 +908,24 @@ RZ_IPI RzCmdStatus rz_push_escaped_handler(RzCore *core, int argc, const char **
|
|||
return res;
|
||||
}
|
||||
|
||||
static RzCmdStatus pointer_read(RzCore *core, const char *expr) {
|
||||
ut64 n = rz_num_math(core->num, expr);
|
||||
if (core->num->dbz) {
|
||||
RZ_LOG_ERROR("core: RzNum ERROR: Division by Zero\n");
|
||||
return RZ_CMD_STATUS_ERROR;
|
||||
}
|
||||
if (!rz_io_read_i(core->io, n, &n, core->rasm->bits / 8, core->print->big_endian)) {
|
||||
return RZ_CMD_STATUS_ERROR;
|
||||
}
|
||||
rz_cons_printf("0x%" PFMT64x "\n", n);
|
||||
return RZ_CMD_STATUS_OK;
|
||||
}
|
||||
|
||||
RZ_IPI RzCmdStatus rz_pointer_handler(RzCore *core, int argc, const char **argv) {
|
||||
int ret;
|
||||
switch (argc) {
|
||||
case 2:
|
||||
ret = rz_core_cmdf(core, "?v [%s]", argv[1]);
|
||||
return rz_cmd_int2status(ret);
|
||||
return pointer_read(core, argv[1]);
|
||||
case 3:
|
||||
if (rz_str_startswith(argv[2], "0x")) {
|
||||
ret = rz_core_cmdf(core, "wv %s @ %s", argv[2], argv[1]);
|
||||
|
|
|
|||
|
|
@ -576,21 +576,10 @@ static ut64 num_callback(RzNum *userptr, const char *str, int *ok) {
|
|||
if (ok) {
|
||||
*ok = 1;
|
||||
}
|
||||
ut8 buf[sizeof(ut64)] = RZ_EMPTY;
|
||||
(void)rz_io_read_at(core->io, n, buf, RZ_MIN(sizeof(buf), refsz));
|
||||
switch (refsz) {
|
||||
case 8:
|
||||
return rz_read_ble64(buf, core->print->big_endian);
|
||||
case 4:
|
||||
return rz_read_ble32(buf, core->print->big_endian);
|
||||
case 2:
|
||||
return rz_read_ble16(buf, core->print->big_endian);
|
||||
case 1:
|
||||
return rz_read_ble8(buf);
|
||||
default:
|
||||
RZ_LOG_ERROR("core: invalid reference size: %d (%s)\n", refsz, str);
|
||||
if (!rz_io_read_i(core->io, n, &n, refsz, core->print->big_endian)) {
|
||||
return 0LL;
|
||||
}
|
||||
return n;
|
||||
} break;
|
||||
case '$':
|
||||
if (ok) {
|
||||
|
|
|
|||
18
test/db/cmd/cmd_pointer
Normal file
18
test/db/cmd/cmd_pointer
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
NAME=pointer read
|
||||
FILE=malloc://1024
|
||||
CMDS=<<EOF
|
||||
wv8 0xdeadbeefdeadbeef
|
||||
*0
|
||||
*0 @e:asm.bits=64
|
||||
*0 @e:asm.bits=32
|
||||
*0 @e:asm.bits=16
|
||||
*0 @e:asm.arch=6502,asm.bits=8
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
0xdeadbeefdeadbeef
|
||||
0xdeadbeefdeadbeef
|
||||
0xdeadbeef
|
||||
0xbeef
|
||||
0xef
|
||||
EOF
|
||||
RUN
|
||||
Loading…
Reference in a new issue