diff --git a/libr/core/cmd_write.c b/libr/core/cmd_write.c index b7f154237f..486c9536c1 100644 --- a/libr/core/cmd_write.c +++ b/libr/core/cmd_write.c @@ -14,7 +14,7 @@ static const char *help_msg_w[] = { "waF"," f.asm","assemble file and write bytes and show 'wx' op with hexpair bytes of assembled code", "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", + "wb"," 011001","write bits in bit big endian", "wB","[-]0xVALUE","set or unset bits with given value", "wc","[?][jir+-*?]","write cache list/undo/commit/reset (io.cache)", "wd"," [off] [n]","duplicate N bytes from offset at current seek (memcpy) (see y?)", @@ -29,6 +29,7 @@ static const char *help_msg_w[] = { "wt","[?] file [sz]","write to file (from current seek, blocksize or sz bytes)", "ww"," foobar","write wide string 'f\\x00o\\x00o\\x00b\\x00a\\x00r\\x00'", "wx","[?][fs] 9090","write two intel nops (from wxfile or wxseek)", + "wX"," 1b2c3d","fill current block with cyclic hexpairs", "wv","[?] eip+34","write 32-64 bit value honoring cfg.bigendian", "wz"," string","write zero terminated string (like w + \\x00)", NULL @@ -1917,6 +1918,28 @@ repeat: } static int cmd_wb(void *data, const char *input) { + RCore *core = (RCore *)data; + ut8 b = core->block[0]; + char *ui = r_str_newf ("%sb", r_str_trim_head_ro (input)); + int uil = strlen (ui) - 1; + int n = r_num_get (NULL, ui); + free (ui); + if (uil > 8) { + eprintf ("wb only operates on bytes\n"); + } else if (uil > 0) { + int shift = 8 - uil; + b <<= shift; + b >>= shift; + b |= (n << shift); + r_io_write_at (core->io, core->offset, &b, 1); + } else { + eprintf ("Usage: wb 010101 (see pb)\n"); + } + + return 0; +} + +static int cmd_wX(void *data, const char *input) { RCore *core = (RCore *)data; size_t len = strlen (input); const size_t buf_size = len + 2; @@ -2091,6 +2114,9 @@ static int cmd_write(void *data, const char *input) { case 'b': // "wb" cmd_wb (core, input + 1); break; + case 'X': // "wX" + cmd_wX (core, input + 1); + break; case 'B': // "wB" cmd_wB (data, input + 1); break; diff --git a/test/db/cmd/0000 b/test/db/cmd/0000 index 547146c576..e4604aee03 100644 --- a/test/db/cmd/0000 +++ b/test/db/cmd/0000 @@ -5,7 +5,7 @@ CMDS=<