Skip to content

Commit

Permalink
Fix #16210 - Show error message and update help for we ##io
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Apr 7, 2020
1 parent 3a95531 commit 39b676b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libr/core/cio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 22 additions & 12 deletions libr/core/cmd_write.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2019 - pancake */
/* radare - LGPL - Copyright 2009-2020 - pancake */

#include "r_crypto.h"
#include "r_config.h"
Expand Down Expand Up @@ -80,12 +80,12 @@ static const char *help_msg_wc[] = {
};

static const char *help_msg_we[] = {
"Usage", "", "write extend",
"wen", " <num>", "insert num null bytes at current offset",
"weN", " <addr> <len>", "insert bytes at address",
"Usage", "", "write extend # resize the file",
"wen", " <num>", "extend the underlying file inserting NUM null bytes at current offset",
"weN", " <addr> <len>", "extend current file and insert bytes at address",
"wes", " <addr> <dist> <block_size>", "shift a blocksize left or write in the editor",
"wex", " <hex_bytes>", "insert bytes at current offset",
"weX", " <addr> <hex_bytes>", "insert bytes at address",
"wex", " <hex_bytes>", "insert bytes at current offset by extending the file",
"weX", " <addr> <hex_bytes>", "insert bytes at address by extending the file",
NULL
};

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 39b676b

Please sign in to comment.