From d7f808e8e4efae61b5c16fbbc2429448ae29cec3 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 9 Sep 2022 00:05:18 +0200 Subject: [PATCH] Fix #20387 - woa 1 confusing error message ##shell * Better help messages and argument handling --- libr/core/cio.c | 4 +++- libr/core/cmd_write.c | 47 +++++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/libr/core/cio.c b/libr/core/cio.c index e67d56c8747d2..00f2570c7d03e 100644 --- a/libr/core/cio.c +++ b/libr/core/cio.c @@ -165,7 +165,7 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { if (arg) { // parse arg for key // r_hex_str2bin() is guaranteed to output maximum half the // input size, or 1 byte if there is just a single nibble. - str = (char *)malloc (strlen (arg) / 2 + 1); + str = (char *)malloc ((strlen (arg) / 2) + 1); if (!str) { goto beach; } @@ -288,12 +288,14 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { } } } else { +#if 0 bool be = r_config_get_i (core->config, "cfg.bigendian"); if (!be) { if (!__endian_swap ((ut8*)str, len, len)) { goto beach; } } +#endif for (i = j = 0; i < core->blocksize; i++) { switch (op) { case 'x': buf[i] ^= str[j]; break; diff --git a/libr/core/cmd_write.c b/libr/core/cmd_write.c index 09a7ebe8038c2..d1ffd12fd1cb8 100644 --- a/libr/core/cmd_write.c +++ b/libr/core/cmd_write.c @@ -100,27 +100,26 @@ static const char *help_msg_we[] = { }; static const char *help_msg_wo[] = { - "Usage:","wo[asmdxoArl24]"," [hexpairs] @ addr[!bsize]", - "wo[24aAdlmorwx]","", "without hexpair values, clipboard is used", - "wo2"," [val]","2= 2 byte endian swap (word)", - "wo4"," [val]", "4= 4 byte endian swap (dword)", - "wo8"," [val]", "8= 8 byte endian swap (qword)", - "woa"," [val]", "+= addition (f.ex: woa 0102)", - "woA"," [val]","&= and", - "wod"," [val]", "/= divide", - "woD","[algo] [key] [IV]","decrypt current block with given algo and key", - "woe"," [from to] [step] [wsz=1]",".. create sequence", - "woE"," [algo] [key] [IV]", "encrypt current block with given algo and key", - "woi","", "inverse bytes in current block", - "wol"," [val]","<<= shift left", - "wom"," [val]", "*= multiply", - "woo"," [val]","|= or", - "wop[DO]"," [arg]","De Bruijn Patterns", - "wor"," [val]", ">>= shift right", - "woR","","random bytes (alias for 'wr $b')", - "wos"," [val]", "-= substraction", - "wow"," [val]", "== write looped value (alias for 'wb')", - "wox"," [val]","^= xor (f.ex: wox 0x90)", + "Usage:","wo[asmdxoArl24]"," [hexpairs] @ addr[!bsize] write operation in current block", + "wo2", "", "2= 2 byte endian swap (word)", + "wo4", "", "4= 4 byte endian swap (dword)", + "wo8", "", "8= 8 byte endian swap (qword)", + "woa", " [hexpair]", "+= addition (f.ex: woa 0102)", + "woA", " [hexpair]", "&= and", + "wod", " [hexpair]", "/= divide", + "woD", "[algo] [key] [IV]", "decrypt current block with given algo and key", + "woE", " [algo] [key] [IV]", "encrypt current block with given algo and key", + "woe", " [from to] [step] [wsz=1]",".. create sequence", + "woi", "", "inverse bytes in current block", + "wol", " [val]", "<<= shift left", + "wom", " [val]", "*= multiply", + "woo", " [val]", "|= or", + "wop[DO]", " [arg]", "De Bruijn Patterns", + "wor", " [val]", ">>= shift right", + "woR", "", "random bytes (alias for 'wr $b')", + "wos", " [val]", "-= substraction", + "wow", " [val]", "== write looped value (alias for 'wb')", + "wox", " [val]", "^= xor (f.ex: wox 0x90)", NULL }; @@ -343,7 +342,11 @@ static int cmd_wo(void *data, const char *input) { case '2': // "wo2" case '4': // "wo4" case '8': // "wo8" - if (input[1]) { // parse val from arg + if (input[1] == '?') { // parse val from arg + char s[8]; + snprintf (s, sizeof (s), "wo%c", input[0]); + r_core_cmd_help_match (core, help_msg_wo, s, true); + } else if (input[1]) { // parse val from arg r_core_write_op (core, r_str_trim_head_ro (input + 2), input[0]); } else { // use clipboard instead of val r_core_write_op (core, NULL, input[0]);