Add r_core_cmd_tobuf()

This commit is contained in:
Lazula 2021-09-23 07:07:20 -05:00 committed by pancake
parent 6e85aa2970
commit 6a04be09ed
2 changed files with 29 additions and 0 deletions

View File

@ -5543,6 +5543,34 @@ R_API char *r_core_cmd_str(RCore *core, const char *cmd) {
return retstr;
}
/* get command output in raw bytes */
R_API RBuffer *r_core_cmd_tobuf(RCore *core, const char *cmd) {
r_cons_push ();
core->cons->context->noflush = true;
core->cons->context->cmd_str_depth++;
if (r_core_cmd0 (core, cmd) == -1) {
//eprintf ("Invalid command: %s\n", cmd);
if (--core->cons->context->cmd_str_depth == 0) {
core->cons->context->noflush = false;
r_cons_flush ();
}
r_cons_pop ();
return NULL;
}
if (--core->cons->context->cmd_str_depth == 0) {
core->cons->context->noflush = false;
}
r_cons_filter ();
RBuffer *out = r_buf_new_with_bytes ((const ut8*)r_cons_get_buffer (), r_cons_get_buffer_len ());
r_cons_pop ();
r_cons_echo (NULL);
return out;
}
/* run cmd in the main task synchronously */
R_API int r_core_cmd_task_sync(RCore *core, const char *cmd, bool log) {
RCoreTask *task = core->tasks.main_task;

View File

@ -433,6 +433,7 @@ 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_strf(RCore *core, const char *fmt, ...) R_PRINTF_CHECK(2, 3);
R_API char *r_core_cmd_str_pipe(RCore *core, const char *cmd);
R_API RBuffer *r_core_cmd_tobuf(RCore *core, const char *cmd);
R_API int r_core_cmd_file(RCore *core, const char *file);
R_API int r_core_cmd_lines(RCore *core, const char *lines);
R_API int r_core_cmd_command(RCore *core, const char *command);