diff --git a/libr/core/vmarks.c b/libr/core/vmarks.c index 4605bb7571..9bc42113b2 100644 --- a/libr/core/vmarks.c +++ b/libr/core/vmarks.c @@ -1,23 +1,25 @@ -/* radare - LGPL - Copyright 2009-2015 - pancake */ +/* radare - LGPL - Copyright 2009-2016 - pancake */ #include /* maybe move this into RCore */ static bool marks_init = false; -static ut64 marks[UT8_MAX+1]; +static ut64 marks[UT8_MAX + 1]; R_API void r_core_visual_mark_reset(RCore *core) { int i; marks_init = true; - for (i=0; idata == NULL) + if (!fd || !fd->data) { return -1; + } + if (count > 1024) { + count = 1024; + } snprintf (fmt, sizeof (fmt), "{\"op\":\"read\",\"address\":%"PFMT64d",\"count\":%d}", io->off, count); rv = r2p_write (R2P (fd), fmt); - if (rv <1) { + if (rv < 1) { eprintf ("r2p_write: error\n"); return -1; } res = r2p_read (R2P (fd)); + /* TODO: parse json back */ r = strstr (res, "result"); - if (r) { rescount = atoi (r+6+2); } + if (r) { + rescount = atoi (r + 6 + 2); + } r = strstr (res, "data"); if (r) { char *arr = strchr (r, ':'); - if (!arr) goto beach; - if (arr[1]!='[') goto beach; + if (!arr || arr[1]!='[') { + goto beach; + } arr += 2; - for (num[0]=numi=bufi=0; bufichild, pathname, rw, mode, r2p): NULL; @@ -156,7 +166,7 @@ RIOPlugin r_io_plugin_r2pipe = { .open = __open, .close = __close, .read = __read, - .check = __plugin_open, + .check = __check, .lseek = __lseek, .write = __write, .system = __system diff --git a/libr/socket/r2pipe.c b/libr/socket/r2pipe.c index 46431a263d..51462d3e2b 100644 --- a/libr/socket/r2pipe.c +++ b/libr/socket/r2pipe.c @@ -1,6 +1,7 @@ -/* radare - LGPL - Copyright 2015 - pancake */ +/* radare - LGPL - Copyright 2015-2016 - pancake */ #include +#include #include #define R2P_MAGIC 0x329193 @@ -133,12 +134,17 @@ R_API R2Pipe *r2p_open(const char *cmd) { if (r2p->child) { 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) { eprintf ("Failed to read 1 byte\n"); r2p_close (r2p); return NULL; } + if (ch == 0x00) { + eprintf ("[+] r2pipe-io link stablished\n"); + } +#endif } else { int rc = 0; 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) { char *cmd; int ret, len; - if (!r2p || !str) + if (!r2p || !str) { return -1; + } len = strlen (str) + 1; /* include \x00 */ cmd = malloc (len + 2); if (!cmd) return 0; memcpy (cmd, str, len); - cmd[len++] = '\n'; - cmd[len] = 0; #if __WINDOWS__ && !defined(__CYGWIN__) DWORD dwWritten = -1; WriteFile (r2p->pipe, cmd, len, &dwWritten, NULL); @@ -233,7 +238,7 @@ R_API char *r2p_read(R2Pipe *r2p) { if (!bSuccess || !buf[0]) { return NULL; } - if (dwRead>0) { + if (dwRead > 0) { buf[dwRead] = 0; } buf[bufsz-1] = 0;