cmd_write: add command names beside case labels (#10941)

This commit is contained in:
Fangrui Song 2018-08-05 10:32:18 -07:00 committed by radare
parent 594a438741
commit 95094a3c3e

View File

@ -13,7 +13,7 @@ static const char *help_msg_w[] = {
"w0"," [len]","write 'len' bytes with value 0x00",
"w6","[de] base64/hex","write base64 [d]ecoded or [e]ncoded string",
"wa","[?] push ebp","write opcode, separated by ';' (use '\"' around the command)",
"waf"," file","assemble file and write bytes",
"waf"," f.asm","assemble file and write bytes",
"wao","[?] op","modify opcode (change conditional of jump. nop, etc)",
"wA","[?] r 0","alter/modify opcode at current seek (see wA?)",
"wb"," 010203","fill current block with cyclic hexpairs",
@ -43,7 +43,7 @@ static const char *help_msg_wa[] = {
"wa", " nop", "write nopcode using asm.arch and asm.bits",
"wa*", " mov eax, 33", "show 'wx' op with hexpair bytes of assembled opcode",
"\"wa nop;nop\"", "" , "assemble more than one instruction (note the quotes)",
"waf", "foo.asm" , "assemble file and write bytes",
"waf", " f.asm" , "assemble file and write bytes",
"wao?", "", "show help for assembler operation on current opcode (hack)",
NULL
};
@ -65,7 +65,7 @@ static const char *help_msg_wc[] = {
"wc","","list all write changes",
"wcj","","list all write changes in JSON",
"wc-"," [from] [to]","remove write op at curseek or given addr",
"wc+"," [addr]","commit change from cache to io",
"wc+"," [from] [to]","commit change from cache to io",
"wc*","","\"\" in radare commands",
"wcr","","reset all write changes in cache",
"wci","","commit write cache",
@ -849,8 +849,7 @@ static int cmd_write(void *data, const char *input) {
}
}
break;
case 'e': // "we"
{
case 'e': { // "we"
ut64 addr = 0, len = 0, b_size = 0;
st64 dist = 0;
ut8* bytes = NULL;
@ -905,28 +904,7 @@ static int cmd_write(void *data, const char *input) {
free (bytes);
}
break;
case 'X':
if (input[2] == ' ') {
addr = r_num_math (core->num, input+3);
input += 3;
while (*input && *input != ' ') input++;
input++;
len = *input ? strlen (input) : 0;
bytes = len > 1? malloc (len+1) : NULL;
len = bytes ? r_hex_str2bin (input, bytes) : 0;
if (len > 0) {
//ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, addr, len);
if (cmd_suc) {
r_core_write_at (core, addr, bytes, len);
}
core->offset = addr;
r_core_block_read (core);
}
free (bytes);
}
break;
case 's':
case 's': // "wes"
input += 3;
while (*input && *input == ' ') input++;
len = strlen (input);
@ -953,7 +931,28 @@ static int cmd_write(void *data, const char *input) {
}
free (input_shadow);
break;
case '?':
case 'X': // "weX"
if (input[2] == ' ') {
addr = r_num_math (core->num, input+3);
input += 3;
while (*input && *input != ' ') input++;
input++;
len = *input ? strlen (input) : 0;
bytes = len > 1? malloc (len+1) : NULL;
len = bytes ? r_hex_str2bin (input, bytes) : 0;
if (len > 0) {
//ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, addr, len);
if (cmd_suc) {
r_core_write_at (core, addr, bytes, len);
}
core->offset = addr;
r_core_block_read (core);
}
free (bytes);
}
break;
case '?': // "we?"
default:
cmd_suc = false;
break;
@ -963,7 +962,7 @@ static int cmd_write(void *data, const char *input) {
}
}
break;
case 'p':
case 'p': // "wp"
if (input[1]=='-' || (input[1]==' ' && input[2]=='-')) {
char *out = r_core_editor (core, NULL, NULL);
if (out) {
@ -982,7 +981,7 @@ static int cmd_write(void *data, const char *input) {
}
}
break;
case 'u':
case 'u': // "wu"
// TODO: implement it in an API RCore.write_unified_hexpatch() is ETOOLONG
if (input[1]==' ') {
char *data = r_file_slurp (input+2, NULL);
@ -1036,7 +1035,7 @@ static int cmd_write(void *data, const char *input) {
eprintf ("|Usage: wu [unified-diff-patch] # see 'cu'\n");
}
break;
case 'r': //wr
case 'r': // "wr"
off = r_num_math (core->num, input+1);
len = (int)off;
if (len > 0) {
@ -1051,7 +1050,7 @@ static int cmd_write(void *data, const char *input) {
} else eprintf ("Cannot allocate %d byte(s)\n", len);
}
break;
case 'A':
case 'A': // "wA"
switch (input[1]) {
case ' ':
if (input[2] && input[3]==' ') {
@ -1072,25 +1071,24 @@ static int cmd_write(void *data, const char *input) {
break;
}
break;
case 'c':
case 'c': // "wc"
switch (input[1]) {
case 'i':
r_io_cache_commit (core->io, 0, UT64_MAX);
r_core_block_read (core);
case '\0': // "wc"
//if (!r_config_get_i (core->config, "io.cache"))
// eprintf ("[warning] e io.cache must be true\n");
r_io_cache_list (core->io, 0);
break;
case 'r':
r_io_cache_reset (core->io, true);
/* Before loading the core block we have to make sure that if
* the cache wrote past the original EOF these changes are no
* longer displayed. */
memset (core->block, 0xff, core->blocksize);
r_core_block_read (core);
case '?': // "wc?"
r_core_cmd_help (core, help_msg_wc);
break;
case '+':
if (input[2]=='*') {
case '*': // "wc*"
r_io_cache_list (core->io, 1);
break;
case '+': // "wc+"
if (input[2]=='*') { // "wc+*"
//r_io_cache_reset (core->io, true);
eprintf ("TODO\n");
} else if (input[2]==' ') {
} else if (input[2]==' ') { // "wc+ "
char *p = strchr (input+3, ' ');
ut64 to, from;
from = r_num_math (core->num, input+3);
@ -1110,10 +1108,10 @@ static int cmd_write(void *data, const char *input) {
r_io_cache_commit (core->io, core->offset, core->offset+1);
}
break;
case '-':
if (input[2]=='*') {
case '-': // "wc-"
if (input[2]=='*') { // "wc-*"
r_io_cache_reset (core->io, true);
} else if (input[2]==' ') {
} else if (input[2]==' ') { // "wc- "
char *p = strchr (input+3, ' ');
ut64 to, from;
if (p) {
@ -1137,22 +1135,23 @@ static int cmd_write(void *data, const char *input) {
memset (core->block, 0xff, core->blocksize);
r_core_block_read (core);
break;
case 'p':
cmd_write_pcache (core, &input[2]);
case 'i': // "wci"
r_io_cache_commit (core->io, 0, UT64_MAX);
r_core_block_read (core);
break;
case '?':
r_core_cmd_help (core, help_msg_wc);
break;
case '*':
r_io_cache_list (core->io, 1);
break;
case 'j':
case 'j': // "wcj"
r_io_cache_list (core->io, 2);
break;
case '\0':
//if (!r_config_get_i (core->config, "io.cache"))
// eprintf ("[warning] e io.cache must be true\n");
r_io_cache_list (core->io, 0);
case 'p': // "wcp"
cmd_write_pcache (core, &input[2]);
break;
case 'r': // "wcr"
r_io_cache_reset (core->io, true);
/* Before loading the core block we have to make sure that if
* the cache wrote past the original EOF these changes are no
* longer displayed. */
memset (core->block, 0xff, core->blocksize);
r_core_block_read (core);
break;
}
break;
@ -1325,7 +1324,7 @@ static int cmd_write(void *data, const char *input) {
case 'f': // "wf"
cmd_wf (core, input);
break;
case 'w':
case 'w': // "ww"
str++;
len = (len - 1) << 1;
tmp = (len > 0) ? malloc (len + 1) : NULL;
@ -1346,6 +1345,9 @@ static int cmd_write(void *data, const char *input) {
break;
case 'x': // "wx"
switch (input[1]) {
case ' ': // "wx "
cmd_write_hexpair (core, input + 1);
break;
case 'f': // "wxf"
arg = (const char *)(input + ((input[2]==' ')? 3: 2));
if (!strcmp (arg, "-")) {
@ -1393,9 +1395,6 @@ static int cmd_write(void *data, const char *input) {
}
}
break;
case ' ': // "wx ..."
cmd_write_hexpair (core, input + 1);
break;
default:
r_core_cmd_help (core, help_msg_wx);
break;
@ -1483,7 +1482,7 @@ static int cmd_write(void *data, const char *input) {
} else eprintf ("Cannot malloc %d\n", len+1);
break;
}
case 'm':
case 'm': // "wm"
size = r_hex_str2bin (input+1, (ut8*)str);
switch (input[1]) {
case '\0':
@ -1509,13 +1508,13 @@ static int cmd_write(void *data, const char *input) {
break;
}
break;
case 'v':
case 'v': // "wv"
cmd_write_value (core, input);
break;
case 'o':
case 'o': // "wo"
cmd_write_op (core, input);
break;
case 'd':
case 'd': // "wd"
if (input[1] && input[1]==' ') {
char *arg, *inp = strdup (input+2);
arg = strchr (inp, ' ');
@ -1531,7 +1530,7 @@ static int cmd_write(void *data, const char *input) {
free (inp);
} else eprintf ("Usage: wd [source-offset] [length] @ [dest-offset]\n");
break;
case 's':
case 's': // "ws"
if (str && *str && str[1]) {
len = r_str_unescape (str+1);
if (len>255) {
@ -1549,7 +1548,7 @@ static int cmd_write(void *data, const char *input) {
} else eprintf ("Too short.\n");
break;
default:
case '?':
case '?': // "w?"
if (core->oobi) {
eprintf ("Writing oobi buffer!\n");
r_io_use_fd (core->io, core->file->fd);