diff --git a/libr/core/cio.c b/libr/core/cio.c index 1e84689a61a32..1913844d9b5a7 100644 --- a/libr/core/cio.c +++ b/libr/core/cio.c @@ -421,7 +421,7 @@ R_API bool r_core_write_at(RCore *core, ut64 addr, const ut8 *buf, int size) { return ret; } -R_API int r_core_extend_at(RCore *core, ut64 addr, int size) { +R_API bool r_core_extend_at(RCore *core, ut64 addr, int size) { int ret; if (!core->io || !core->file || size < 1) { return false; diff --git a/libr/core/cmd_write.c b/libr/core/cmd_write.c index f5433ba1297cf..f16b93dccda94 100644 --- a/libr/core/cmd_write.c +++ b/libr/core/cmd_write.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2019 - pancake */ +/* radare - LGPL - Copyright 2009-2020 - pancake */ #include "r_crypto.h" #include "r_config.h" @@ -80,12 +80,12 @@ static const char *help_msg_wc[] = { }; static const char *help_msg_we[] = { - "Usage", "", "write extend", - "wen", " ", "insert num null bytes at current offset", - "weN", " ", "insert bytes at address", + "Usage", "", "write extend # resize the file", + "wen", " ", "extend the underlying file inserting NUM null bytes at current offset", + "weN", " ", "extend current file and insert bytes at address", "wes", " ", "shift a blocksize left or write in the editor", - "wex", " ", "insert bytes at current offset", - "weX", " ", "insert bytes at address", + "wex", " ", "insert bytes at current offset by extending the file", + "weX", " ", "insert bytes at address by extending the file", NULL }; @@ -879,12 +879,16 @@ static int cmd_write(void *data, const char *input) { switch (input[1]) { case 'n': // "wen" if (input[2] == ' ') { - len = *input ? r_num_math (core->num, input+3) : 0; + len = *input ? r_num_math (core->num, input+ 3) : 0; if (len > 0) { const ut64 cur_off = core->offset; cmd_suc = r_core_extend_at (core, core->offset, len); - core->offset = cur_off; - r_core_block_read (core); + if (cmd_suc) { + core->offset = cur_off; + r_core_block_read (core); + } else { + eprintf ("r_io_extend failed\n"); + } } } break; @@ -899,9 +903,13 @@ static int cmd_write(void *data, const char *input) { if (len > 0){ ut64 cur_off = core->offset; cmd_suc = r_core_extend_at (core, addr, len); - r_core_seek (core, cur_off, 1); - core->offset = addr; - r_core_block_read (core); + if (cmd_suc) { + r_core_seek (core, cur_off, 1); + core->offset = addr; + r_core_block_read (core); + } else { + eprintf ("r_io_extend failed\n"); + } } cmd_suc = true; } @@ -970,6 +978,8 @@ static int cmd_write(void *data, const char *input) { if (!r_core_write_at (core, addr, bytes, len)) { cmd_write_fail (core); } + } else { + eprintf ("r_io_extend failed\n"); } core->offset = addr; r_core_block_read (core); diff --git a/libr/include/r_core.h b/libr/include/r_core.h index 9c5f437505e29..9258d17048531 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -507,7 +507,7 @@ R_API int r_core_file_list(RCore *core, int mode); R_API int r_core_file_binlist(RCore *core); R_API bool r_core_file_bin_raise(RCore *core, ut32 num); R_API int r_core_seek_delta(RCore *core, st64 addr); -R_API int r_core_extend_at(RCore *core, ut64 addr, int size); +R_API bool r_core_extend_at(RCore *core, ut64 addr, int size); R_API bool r_core_write_at(RCore *core, ut64 addr, const ut8 *buf, int size); R_API int r_core_write_op(RCore *core, const char *arg, char op); R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op);