mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-22 22:06:50 +00:00
Fix r2pipe:// (initial \x00 issue and cmd chop messages properly)
This commit is contained in:
parent
66772837c0
commit
7cf0e1b633
@ -1,4 +1,4 @@
|
|||||||
/* radare - LGPL - Copyright 2009-2015 - pancake */
|
/* radare - LGPL - Copyright 2009-2016 - pancake */
|
||||||
|
|
||||||
#include <r_core.h>
|
#include <r_core.h>
|
||||||
|
|
||||||
@ -9,14 +9,16 @@ static ut64 marks[UT8_MAX+1];
|
|||||||
R_API void r_core_visual_mark_reset(RCore *core) {
|
R_API void r_core_visual_mark_reset(RCore *core) {
|
||||||
int i;
|
int i;
|
||||||
marks_init = true;
|
marks_init = true;
|
||||||
for (i=0; i<UT8_MAX; i++)
|
for (i = 0; i < UT8_MAX; i++) {
|
||||||
marks[i] = UT64_MAX;
|
marks[i] = UT64_MAX;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
R_API void r_core_visual_mark_dump(RCore *core) {
|
R_API void r_core_visual_mark_dump(RCore *core) {
|
||||||
int i;
|
int i;
|
||||||
if (!marks_init)
|
if (!marks_init) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
for (i = 0; i < UT8_MAX; i++) {
|
for (i = 0; i < UT8_MAX; i++) {
|
||||||
if (marks[i] != UT64_MAX) {
|
if (marks[i] != UT64_MAX) {
|
||||||
r_cons_printf ("fV %d 0x%"PFMT64x"\n", i, marks[i]);
|
r_cons_printf ("fV %d 0x%"PFMT64x"\n", i, marks[i]);
|
||||||
@ -36,6 +38,7 @@ R_API void r_core_visual_mark(RCore *core, ut8 ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
R_API void r_core_visual_mark_seek(RCore *core, ut8 ch) {
|
R_API void r_core_visual_mark_seek(RCore *core, ut8 ch) {
|
||||||
if (marks_init && marks[ch] != UT64_MAX)
|
if (marks_init && marks[ch] != UT64_MAX) {
|
||||||
r_core_seek (core, marks[ch], 1);
|
r_core_seek (core, marks[ch], 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -11,12 +11,12 @@ if (!nfd_in || !nfd_out) {
|
|||||||
var fd_in = fs.createReadStream(null, {fd: nfd_in});
|
var fd_in = fs.createReadStream(null, {fd: nfd_in});
|
||||||
var fd_out = fs.createWriteStream(null, {fd: nfd_out});
|
var fd_out = fs.createWriteStream(null, {fd: nfd_out});
|
||||||
|
|
||||||
console.log ("Running r2pipe io using fds: ", nfd_in, nfd_out);
|
console.error ("Running r2pipe io using fds: ", nfd_in, nfd_out);
|
||||||
|
|
||||||
fd_in.on('data', function(data) {
|
fd_in.on('data', function(data) {
|
||||||
data = data.slice(0,-1);
|
data = data.slice(0,-1);
|
||||||
var obj_in = JSON.parse (data);
|
var obj_in = JSON.parse (data);
|
||||||
console.log ("got data(",obj_in,")");
|
console.error ("got data(",obj_in,")");
|
||||||
var obj = {result:obj_in.count, data:[1,2,3]};
|
var obj = {result:obj_in.count, data:[1,2,3]};
|
||||||
fd_out.write (JSON.stringify (obj)+"\x00");
|
fd_out.write (JSON.stringify (obj)+"\x00");
|
||||||
});
|
});
|
||||||
|
@ -37,18 +37,24 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
|
|||||||
res = r2p_read (R2P (fd));
|
res = r2p_read (R2P (fd));
|
||||||
/* TODO: parse json back */
|
/* TODO: parse json back */
|
||||||
r = strstr (res, "result");
|
r = strstr (res, "result");
|
||||||
if (r) { count = atoi (r+6+1); }
|
if (r) {
|
||||||
|
count = atoi (r + 6 + 1);
|
||||||
|
}
|
||||||
free (res);
|
free (res);
|
||||||
return rescount;
|
return rescount;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __read(RIO *io, RIODesc *fd, ut8 *buf, const int count) {
|
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
|
||||||
char fmt[4096], num[128];
|
char fmt[4096], num[128];
|
||||||
int rv, rescount = -1;
|
int rv, rescount = -1;
|
||||||
int bufi, numi;
|
int bufi, numi;
|
||||||
char *res, *r;
|
char *res, *r;
|
||||||
if (fd == NULL || fd->data == NULL)
|
if (!fd || !fd->data) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
if (count > 1024) {
|
||||||
|
count = 1024;
|
||||||
|
}
|
||||||
snprintf (fmt, sizeof (fmt),
|
snprintf (fmt, sizeof (fmt),
|
||||||
"{\"op\":\"read\",\"address\":%"PFMT64d",\"count\":%d}",
|
"{\"op\":\"read\",\"address\":%"PFMT64d",\"count\":%d}",
|
||||||
io->off, count);
|
io->off, count);
|
||||||
@ -58,14 +64,18 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, const int count) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
res = r2p_read (R2P (fd));
|
res = r2p_read (R2P (fd));
|
||||||
|
|
||||||
/* TODO: parse json back */
|
/* TODO: parse json back */
|
||||||
r = strstr (res, "result");
|
r = strstr (res, "result");
|
||||||
if (r) { rescount = atoi (r+6+2); }
|
if (r) {
|
||||||
|
rescount = atoi (r + 6 + 2);
|
||||||
|
}
|
||||||
r = strstr (res, "data");
|
r = strstr (res, "data");
|
||||||
if (r) {
|
if (r) {
|
||||||
char *arr = strchr (r, ':');
|
char *arr = strchr (r, ':');
|
||||||
if (!arr) goto beach;
|
if (!arr || arr[1]!='[') {
|
||||||
if (arr[1]!='[') goto beach;
|
goto beach;
|
||||||
|
}
|
||||||
arr += 2;
|
arr += 2;
|
||||||
for (num[0] = numi = bufi = 0; bufi < count && *arr; arr++) {
|
for (num[0] = numi = bufi = 0; bufi < count && *arr; arr++) {
|
||||||
switch (*arr) {
|
switch (*arr) {
|
||||||
@ -114,13 +124,13 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __plugin_open(RIO *io, const char *pathname, bool many) {
|
static bool __check(RIO *io, const char *pathname, bool many) {
|
||||||
return (!strncmp (pathname, "r2pipe://", 9));
|
return (!strncmp (pathname, "r2pipe://", 9));
|
||||||
}
|
}
|
||||||
|
|
||||||
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||||
R2Pipe *r2p = NULL;
|
R2Pipe *r2p = NULL;
|
||||||
if (__plugin_open (io, pathname, 0)) {
|
if (__check (io, pathname, 0)) {
|
||||||
r2p = r2p_open (pathname + 9);
|
r2p = r2p_open (pathname + 9);
|
||||||
}
|
}
|
||||||
return r2p? r_io_desc_new (&r_io_plugin_r2pipe,
|
return r2p? r_io_desc_new (&r_io_plugin_r2pipe,
|
||||||
@ -156,7 +166,7 @@ RIOPlugin r_io_plugin_r2pipe = {
|
|||||||
.open = __open,
|
.open = __open,
|
||||||
.close = __close,
|
.close = __close,
|
||||||
.read = __read,
|
.read = __read,
|
||||||
.check = __plugin_open,
|
.check = __check,
|
||||||
.lseek = __lseek,
|
.lseek = __lseek,
|
||||||
.write = __write,
|
.write = __write,
|
||||||
.system = __system
|
.system = __system
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* radare - LGPL - Copyright 2015 - pancake */
|
/* radare - LGPL - Copyright 2015-2016 - pancake */
|
||||||
|
|
||||||
#include <r_util.h>
|
#include <r_util.h>
|
||||||
|
#include <r_cons.h>
|
||||||
#include <r_socket.h>
|
#include <r_socket.h>
|
||||||
|
|
||||||
#define R2P_MAGIC 0x329193
|
#define R2P_MAGIC 0x329193
|
||||||
@ -133,12 +134,17 @@ R_API R2Pipe *r2p_open(const char *cmd) {
|
|||||||
|
|
||||||
if (r2p->child) {
|
if (r2p->child) {
|
||||||
char ch;
|
char ch;
|
||||||
eprintf ("Child is %d\n", r2p->child);
|
eprintf ("[+] r2pipe child is %d\n", r2p->child);
|
||||||
|
#if 0
|
||||||
if (read (r2p->output[0], &ch, 1) != 1) {
|
if (read (r2p->output[0], &ch, 1) != 1) {
|
||||||
eprintf ("Failed to read 1 byte\n");
|
eprintf ("Failed to read 1 byte\n");
|
||||||
r2p_close (r2p);
|
r2p_close (r2p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (ch == 0x00) {
|
||||||
|
eprintf ("[+] r2pipe-io link stablished\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
if (cmd && *cmd) {
|
if (cmd && *cmd) {
|
||||||
@ -198,14 +204,13 @@ R_API char *r2p_cmdf(R2Pipe *r2p, const char *fmt, ...) {
|
|||||||
R_API int r2p_write(R2Pipe *r2p, const char *str) {
|
R_API int r2p_write(R2Pipe *r2p, const char *str) {
|
||||||
char *cmd;
|
char *cmd;
|
||||||
int ret, len;
|
int ret, len;
|
||||||
if (!r2p || !str)
|
if (!r2p || !str) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
len = strlen (str) + 1; /* include \x00 */
|
len = strlen (str) + 1; /* include \x00 */
|
||||||
cmd = malloc (len + 2);
|
cmd = malloc (len + 2);
|
||||||
if (!cmd) return 0;
|
if (!cmd) return 0;
|
||||||
memcpy (cmd, str, len);
|
memcpy (cmd, str, len);
|
||||||
cmd[len++] = '\n';
|
|
||||||
cmd[len] = 0;
|
|
||||||
#if __WINDOWS__ && !defined(__CYGWIN__)
|
#if __WINDOWS__ && !defined(__CYGWIN__)
|
||||||
DWORD dwWritten = -1;
|
DWORD dwWritten = -1;
|
||||||
WriteFile (r2p->pipe, cmd, len, &dwWritten, NULL);
|
WriteFile (r2p->pipe, cmd, len, &dwWritten, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user