Implement reverse rap for system()

This commit is contained in:
pancake 2015-06-09 01:45:39 +02:00
parent 62e9ea5310
commit 03aa69b261
7 changed files with 60 additions and 11 deletions

View File

@ -89,6 +89,11 @@ static int core_cmd_callback (void *user, const char *cmd) {
return r_core_cmd0 (core, cmd);
}
static char *core_cmdstr_callback (void *user, const char *cmd) {
RCore *core = (RCore *)user;
return r_core_cmd_str (core, cmd);
}
static ut64 getref (RCore *core, int n, char t, int type) {
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
RListIter *iter;
@ -884,7 +889,8 @@ R_API int r_core_init(RCore *core) {
core->io = r_io_new ();
core->io->ff = 1;
core->io->user = (void *)core;
core->io->core_cmd_cb = core_cmd_callback;
core->io->cb_core_cmd = core_cmd_callback;
core->io->cb_core_cmdstr = core_cmdstr_callback;
core->sign = r_sign_new ();
core->search = r_search_new (R_SEARCH_KEYWORD);
r_io_undo_enable (core->io, 1, 0); // TODO: configurable via eval

View File

@ -874,8 +874,8 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn) {
" TAB - select previous node\n"
" t/f - follow true/false edges\n"
" e - toggle edge-lines style (diagonal/square)\n"
" n - toggle mini-graph\n"
" O - toggle disasm mode\n"
" p - toggle mini-graph\n"
" u - select previous node\n"
" V - toggle basicblock / call graphs\n"
" x/X - jump to xref/ref\n"
@ -957,7 +957,7 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn) {
case 'e':
can->linemode = !!!can->linemode;
break;
case 'n':
case 'p':
graph_toggle_small_nodes(g);
break;
case 'u':

View File

@ -140,14 +140,15 @@ typedef struct r_io_t {
RList *files;
RList *cache;
int zeromap;
//XXX: Need by rap
void *user;
int (*core_cmd_cb)(void *user, const char *str);
RCache *buffer;
int buffer_enabled;
int ff;
int autofd;
char *runprofile;
/* Core Callbacks (used by rap) */
void *user;
int (*cb_core_cmd)(void *user, const char *str);
char* (*cb_core_cmdstr)(void *user, const char *str);
} RIO;
typedef struct r_io_plugin_t {

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2014 - pancake */
/* radare - LGPL - Copyright 2008-2015 - pancake */
#include "r_io.h"
#include "r_util.h"
@ -931,6 +931,9 @@ static ut8 * r_io_desc_read (RIO *io, RIODesc * desc, ut64 *out_sz) {
off = io->off;
if (*out_sz == UT64_MAX) return buf;
if (*out_sz > 0xffffff) {
return buf;
}
buf = malloc (*out_sz);
@ -938,7 +941,7 @@ static ut8 * r_io_desc_read (RIO *io, RIODesc * desc, ut64 *out_sz) {
if (!buf || !desc->plugin->read (io, desc, buf, *out_sz)) {
free (buf);
io->off = off;
return R_FALSE;
return NULL;
}
}
io->off = off;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2011-2014 - pancake */
/* radare - LGPL - Copyright 2011-2015 - pancake */
// TODO: implement the rap API in r_socket ?
#include "r_io.h"
@ -269,9 +269,44 @@ static int rap__system(RIO *io, RIODesc *fd, const char *command) {
r_socket_write (s, buf, i+5);
r_socket_flush (s);
/* read reverse cmds */
for (;;) {
ret = r_socket_read_block (s, buf, 1);
if (ret != 1) {
return -1;
}
/* system back in the middle */
/* TODO: all pkt handlers should check for reverse queries */
if (buf[0] == RMT_SYSTEM) {
char *res, *str;
ut32 reslen = 0, cmdlen = 0;
// run io->cmdstr
// return back the string
buf[0] |= RMT_REPLY;
ret = r_socket_read_block (s, buf+1, 4);
r_mem_copyendian ((ut8*)&cmdlen, buf+1, 4, ENDIAN);
if (cmdlen+1==0) // check overflow
cmdlen = 0;
str = calloc (1, cmdlen+1);
ret = r_socket_read_block (s, (ut8*)str, cmdlen);
//eprintf ("RUN CMD(%s)\n", str);
res = io->cb_core_cmdstr (io->user, str);
reslen = strlen (res);
free (str);
r_mem_copyendian ((ut8*)buf+1, (const ut8*)&reslen,
sizeof(ut32), ENDIAN);
free (res);
memcpy (buf+5, res, reslen);
r_socket_write (s, buf, 5+reslen);
r_socket_flush (s);
} else {
break;
}
}
// read
ret = r_socket_read_block (s, buf, 5);
if (ret != 5)
ret = r_socket_read_block (s, buf+1, 4);
if (ret != 4)
return -1;
if (buf[0] != (op | RMT_REPLY)) {
eprintf ("Unexpected system reply\n");
@ -280,6 +315,10 @@ static int rap__system(RIO *io, RIODesc *fd, const char *command) {
r_mem_copyendian ((ut8*)&i, buf+1, 4, ENDIAN);
ret = 0;
if (i>0xffff) {
eprintf ("Invalid length\n");
return -1;
}
ptr = (char *)malloc (i+1);
if (ptr) {
int ir;

BIN
media/images/r2emoji.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
media/images/r2sticker.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB