Fix interaction of ob with o:

This commit is contained in:
Khairul Kasmiran 2020-03-30 22:16:37 +08:00 committed by radare
parent 513de59576
commit cd2715dc95
2 changed files with 26 additions and 7 deletions

View File

@ -1604,16 +1604,24 @@ static int cmd_open(void *data, const char *input) {
if (len < 1) { if (len < 1) {
len = core->blocksize; len = core->blocksize;
} }
char *uri = r_str_newf ("malloc://%d", len); char *uri = r_str_newf ("malloc://%d", len);
ut8 *data = calloc (len, 1); ut8 *data = calloc (len, 1);
r_io_read_at (core->io, core->offset, data, len); r_io_read_at (core->io, core->offset, data, len);
RIODesc *fd = r_io_open (core->io, uri, R_PERM_R | R_PERM_W, 0); if (file = r_core_file_open (core, uri, R_PERM_RWX, 0)) {
if (fd) { fd = file->fd;
r_io_desc_write (fd, data, len); core->num->value = fd;
} r_core_bin_load (core, uri, 0);
RIODesc *desc = r_io_desc_get (core->io, fd);
if (desc) {
// TODO: why r_io_desc_write() fails?
r_io_desc_write_at (desc, 0, data, len);
}
} else {
eprintf ("Cannot %s\n", uri);
}
free (uri); free (uri);
free (data); free (data);
} }
break; break;
case 'm': // "om" case 'm': // "om"
cmd_open_map (core, input); cmd_open_map (core, input);

View File

@ -305,13 +305,24 @@ EXPECT=<<EOF
0x00000010 2021 2223 2425 2627 2829 2a2b 2c2d 2e2f !"#$%&'()*+,-./ 0x00000010 2021 2223 2425 2627 2829 2a2b 2c2d 2e2f !"#$%&'()*+,-./
2 fd: 4 +0x00000000 0x00000000 - 0x000000ff rw- 2 fd: 4 +0x00000000 0x00000000 - 0x000000ff rwx
1 fd: 3 +0x00000000 0x00000000 - 0x000001ff rwx 1 fd: 3 +0x00000000 0x00000000 - 0x000001ff rwx
0x00000010 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f ................ 0x00000010 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f ................
EOF EOF
RUN RUN
NAME=o: ob fix
FILE=--
CMDS=<<EOF
o: 1024
ob
EOF
EXPECT=<<EOF
0 3 x86-64 ba:0x00000000 sz:1024 malloc://1024
EOF
RUN
NAME=o-* NAME=o-*
FILE=- FILE=-
EXPECT=<<EOF EXPECT=<<EOF