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 5, 2020
1 parent 6b31b40 commit 08bec0c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion libr/core/cio.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,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
2 changes: 1 addition & 1 deletion libr/core/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
line = strdup (cmd);
line = r_str_replace (line, "\\\"", "\"", true);
if (p && *p && p[1] == '|') {
str = r_str_trim_head_ro (p + 2);
str = (char *)r_str_trim_head_ro (p + 2);
r_core_cmd_pipe (core, cmd, str);
} else {
r_cmd_call (core->rcmd, line);
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 08bec0c

Please sign in to comment.