Expose RCore.cmdCall() and fix b64: command + add tests ##shell

* Run r2 commands without evaluating any special char
This commit is contained in:
pancake 2022-12-02 23:30:01 +01:00
parent fa7fc5b6cd
commit 903b5f6864
4 changed files with 33 additions and 5 deletions

View File

@ -3,7 +3,7 @@ V35ARMV7_ARCH?=arch-armv7
V35ARMV7_SRCDIR=$(V35ARM64_HOME)/$(V35ARMV7_ARCH)/armv7_disasm/
V35ARMV7_CFLAGS=-I$(V35ARMV7_SRCDIR)
V35ARMV7_CFLAGS=-DUNUSED=''
V35ARMV7_CFLAGS=-DUNUSED=R_UNUSED
V35ARMV7_OBJS+=armv7.o
V35ARMV7_LINK=$(addprefix $(V35ARMV7_SRCDIR),$(V35ARMV7_OBJS))

View File

@ -238,6 +238,7 @@ static RCoreHelpMessage help_msg_b = {
"b", "+3", "increase blocksize by 3",
"b", "-16", "decrease blocksize by 16",
"b*", "", "display current block size in r2 command",
"b64:", "AA=", "receive a base64 string that is executed without evaluating special chars",
"bf", " foo", "set block size to flag size",
"bj", "", "display block size information in JSON",
"bm", " 1M", "set max block size",
@ -2416,10 +2417,10 @@ static int cmd_bsize(void *data, const char *input) {
int len = 0;
char *cmd = (char *)sdb_decode (input + 3, &len);
cmd[len] = 0;
r_core_cmd0 (core, cmd);
r_core_cmd_call (core, cmd);
free (cmd);
} else {
eprintf ("Usage: b64:P2UgaGVsbG8K - decode base64 and run command\n");
r_core_cmd_help_match (core, help_msg_b, "b64:", false);
}
break;
case 'm': // "bm"
@ -3589,6 +3590,8 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
// XXX: do not flush here, we need r_cons_push () and r_cons_pop()
r_cons_flush ();
// XXX: we must import register flags in C
// r_core_cmd_subst (core, ".dr*");
// r_core_cmd_subst (core, cr);
(void)r_core_cmd0 (core, ".dr*");
(void)r_core_cmd0 (core, cr);
}
@ -4566,8 +4569,8 @@ ignore:
cmd = r_str_trim_nc (cmd);
if (ptr2) {
if (strlen (ptr + 1) == 13 && strlen (ptr2 + 1) == 6 &&
!strncmp (ptr + 1, "0x", 2) &&
!strncmp (ptr2 + 1, "0x", 2)) {
r_str_startswith (ptr + 1, "0x") &&
r_str_startswith (ptr2 + 1, "0x")) {
/* 0xXXXX:0xYYYY */
} else if (strlen (ptr + 1) == 9 && strlen (ptr2 + 1) == 4) {
/* XXXX:YYYY */
@ -5924,6 +5927,11 @@ R_API char *r_core_cmd_strf(RCore *core, const char *fmt, ...) {
return ret;
}
// run an r2 command without evaluating any special character
R_API int r_core_cmd_call(RCore *core, const char *cmd) {
return r_cmd_call (core->rcmd, cmd);
}
/* return: pointer to a buffer with the output of the command */
R_API char *r_core_cmd_str(RCore *core, const char *cmd) {
r_return_val_if_fail (core, NULL);

View File

@ -448,6 +448,7 @@ R_API void r_core_cmd_r(RCore *core, const char *cmd);
R_API void r_core_cmd_queue(RCore *core, const char *line);
R_API void r_core_cmd_queue_wait(RCore *core);
R_API void r_core_cmd_init(RCore *core);
R_API int r_core_cmd_call(RCore *core, const char *cmd);
R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd);
R_API char *r_core_cmd_str(RCore *core, const char *cmd);
R_API char *r_core_cmd_str_r(RCore *core, const char *cmd);

View File

@ -19,3 +19,22 @@ EXPECT=<<EOF
{"blocksize":100,"blocksize_limit":52428800}
EOF
RUN
NAME=b64
FILE=-
CMDS=<<EOF
b64?
"p6es ?e hello;?e world"
b64:`_`
p6ds P2UgaGVsbG87P2Ugd29ybGQ=
`p6ds P2UgaGVsbG87P2Ugd29ybGQ=`
EOF
EXPECT=<<EOF
| b64:AA= receive a base64 string that is executed without evaluating special chars
P2UgaGVsbG87P2Ugd29ybGQ=
hello;?e world
?e hello;?e world
hello
world
EOF
RUN