* Make io.gdb plugin work again

* Fix more unused var bugs
This commit is contained in:
pancake 2011-04-06 12:26:19 +02:00
parent fd8545e76e
commit 8b27aa6723
8 changed files with 51 additions and 43 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2010 pancake<@nopcode.org> */
/* radare - LGPL - Copyright 2010-2011 pancake<@nopcode.org> */
#include <stdio.h>
#include <string.h>
@ -150,14 +150,13 @@ static int getlist(char *op) {
static int getshift(const char *str) {
if (!str) return 0;
while (str && *str&&!atoi (str))
while (str && *str && !atoi (str))
str++;
return atoi(str)/2;
return atoi (str)>>1;
}
static void arm_opcode_parse(ArmOpcode *ao, const char *str) {
int i;
memset (ao, 0, sizeof (ArmOpcode));
strncpy (ao->op, str, sizeof (ao->op)-1);
strcpy (ao->opstr, str);
@ -173,7 +172,7 @@ static void arm_opcode_parse(ArmOpcode *ao, const char *str) {
ao->a[i]++;
}
for (i=0; i<16; i++)
while (ao->a[i]&&*ao->a[i]==' ')
while (ao->a[i] && *ao->a[i]==' ')
ao->a[i]++;
}

View File

@ -125,6 +125,7 @@ R_API RConfigNode *r_config_set(RConfig *cfg, const char *name, const char *valu
}
}
} else {
oi = UT64_MAX;
if (!cfg->lock) {
node = r_config_node_new (name, value);
if (value && (!strcmp(value,"true")||!strcmp(value,"false"))) {
@ -140,7 +141,8 @@ R_API RConfigNode *r_config_set(RConfig *cfg, const char *name, const char *valu
if (node && node->callback) {
int ret = node->callback (cfg->user, node);
if (ret == R_FALSE) {
node->i_value = oi;
if (oi != UT64_MAX)
node->i_value = oi;
free (node->value);
node->value = strdup (ov);
return NULL;

View File

@ -604,7 +604,7 @@ static int cmd_zign(void *data, const char *input) {
RAnalFcn *fcni;
RListIter *iter;
RSignItem *item;
int i, fd, len;
int i, fd = -1, len;
char *ptr, *name;
switch (input[0]) {
@ -1848,6 +1848,7 @@ static void r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
if (!v && !strcmp (str, "data"))
return;
p = strdup (str);
fmt = p;
// processing newlinez
for (q=p; *q; q++)
if (q[0]=='\\' && q[1]=='n') {
@ -3571,7 +3572,7 @@ static int cmd_open(void *data, const char *input) {
RCoreFile *file;
ut64 addr;
char *ptr;
int num;
int num = -1;
switch (*input) {
case '\0':
@ -3749,20 +3750,17 @@ static int cmd_meta(void *data, const char *input) {
default:
{
RAnalFcn *f;
char *ptr = strdup(input+2), *pattern, *varsub;
char *ptr = strdup(input+2), *pattern = NULL, *varsub = NULL;
ut64 offset = -1LL;
int n = r_str_word_set0 (ptr), i;
int i, n = r_str_word_set0 (ptr);
if (n > 2) {
switch(n) {
case 3:
varsub = r_str_word_get0 (ptr, 2);
case 2:
pattern = r_str_word_get0 (ptr, 1);
case 1:
offset = r_num_math (core->num, r_str_word_get0 (ptr, 0));
case 3: varsub = r_str_word_get0 (ptr, 2);
case 2: pattern = r_str_word_get0 (ptr, 1);
case 1: offset = r_num_math (core->num, r_str_word_get0 (ptr, 0));
}
if ((f = r_anal_fcn_find (core->anal, offset, R_ANAL_FCN_TYPE_NULL)) != NULL) {
if (pattern && varsub)
for (i = 0; i < R_ANAL_VARSUBS; i++)
if (f->varsubs[i].pat[0] == '\0' || !strcmp (f->varsubs[i].pat, pattern)) {
strncpy (f->varsubs[i].pat, pattern, 1024);

View File

@ -54,7 +54,7 @@ R_API void r_fs_del (RFS *fs, RFSPlugin *p) {
/* mountpoint */
R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 delta) {
RFSPlugin *p;
RFSRoot *root;
RFSRoot *root = NULL;
char *str;
if (path[0] != '/') {

View File

@ -171,15 +171,14 @@ R_API int r_io_read(RIO *io, ut8 *buf, int len) {
}
#endif
off = io->off;
if (r_io_map_select (io, io->off)) {
if (io->plugin && io->plugin->read) {
if (io->plugin->read != NULL)
ret = io->plugin->read (io, io->fd, buf, len);
else eprintf ("IO plugin for fd=%d has no read()\n", io->fd->fd);
} else ret = read (io->fd->fd, buf, len);
if (ret>0 && ret<len)
memset (buf+ret, 0xff, len-ret);
}
r_io_map_select (io, io->off);
if (io->plugin && io->plugin->read) {
if (io->plugin->read != NULL)
ret = io->plugin->read (io, io->fd, buf, len);
else eprintf ("IO plugin for fd=%d has no read()\n", io->fd->fd);
} else ret = read (io->fd->fd, buf, len);
if (ret>0 && ret<len)
memset (buf+ret, 0xff, len-ret);
// this must be before?? r_io_cache_read (io, io->off, buf, len);
r_io_seek (io, off, R_IO_SEEK_SET);
return ret;

View File

@ -46,7 +46,7 @@ R_API RIOMap *r_io_map_add(struct r_io_t *io, int fd, int flags, ut64 delta, ut6
R_API int r_io_map_select(RIO *io, ut64 off) {
ut64 delta = 0;
ut64 fd = -1;
ut64 fd = -1;//io->fd;
RIOMap *im;
RListIter *iter;
r_list_foreach (io->maps, iter, im) { // _prev?

View File

@ -8,11 +8,11 @@
#include "../../debug/p/libgdbwrap/interface.c"
typedef struct {
int fd;
RSocket *fd;
gdbwrap_t *desc;
} RIOGdb;
#define RIOGDB_FD(x) (((RIOGdb*)(x))->fd)
#define RIOGDB_DESC(x) (((RIOGdb*)(x))->desc)
#define RIOGDB_DESC(x) (((RIOGdb*)(x->data))->desc)
#define RIOGDB_IS_VALID(x) (x && x->plugin==&r_io_plugin_gdb && x->data)
static int __plugin_open(RIO *io, const char *file) {
@ -21,7 +21,7 @@ static int __plugin_open(RIO *io, const char *file) {
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
char host[128], *port;
int _fd;
RSocket *_fd;
RIOGdb *riog;
if (!__plugin_open (io, file))
return NULL;
@ -32,15 +32,15 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
return NULL;
}
*port = '\0';
_fd = r_socket_connect (host, port+1);
if (_fd == -1) {
eprintf ("Cannot connect to host.\n");
return NULL;
_fd = r_socket_new (host, port+1, R_FALSE);
if (_fd) {
riog = R_NEW (RIOGdb);
riog->fd = _fd;
riog->desc = gdbwrap_init (_fd->fd);
return r_io_desc_new (&r_io_plugin_gdb, _fd->fd, file, rw, mode, riog);
}
riog = R_NEW (RIOGdb);
riog->fd = _fd;
riog->desc = gdbwrap_init (_fd);
return r_io_desc_new (&r_io_plugin_gdb, _fd, file, rw, mode, riog);
eprintf ("gdb.io.open: Cannot connect to host.\n");
return NULL;
}
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
@ -49,6 +49,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
}
static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
//if (whence==2) return UT64_MAX;
return offset;
}
@ -58,13 +59,22 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
char *ptr = gdbwrap_readmem (RIOGDB_DESC (fd), (la32)io->off, count);
if (ptr == NULL)
return -1;
//eprintf ("READ %llx (%s)\n", (ut64)io->off, ptr);
return r_hex_str2bin (ptr, buf);
}
return -1;
}
static int __close(RIODesc *fd) {
// TODO
return -1;
}
static int __system(RIO *io, RIODesc *fd, const char *cmd) {
/* XXX: test only for x86-32 */
gdbwrap_gdbreg32 *reg = gdbwrap_readgenreg (RIOGDB_DESC (fd));
printf ("------ eax %x\n", reg->eax);
printf ("------ eip %x\n", reg->eip);
printf ("------ esp %x\n", reg->esp);
return -1;
}
@ -78,6 +88,6 @@ struct r_io_plugin_t r_io_plugin_gdb = {
.write = __write,
.plugin_open = __plugin_open,
.lseek = __lseek,
.system = NULL,
.system = __system,
.debug = (void *)1,
};

View File

@ -161,7 +161,7 @@ static RIODesc *rap__open(struct r_io_t *io, const char *pathname, int rw, int m
#warning TODO: implement rap:/:9999 listen mode
return r_io_desc_new (&r_io_plugin_rap, rior->fd->fd, pathname, rw, mode, rior);
}
if ((rap_fd = r_socket_new (ptr, port, R_FALSE))==-1) {
if ((rap_fd = r_socket_new (ptr, port, R_FALSE))==NULL) {
eprintf ("Cannot connect to '%s' (%d)\n", ptr, p);
return NULL;
}
@ -199,7 +199,7 @@ static int rap__system(RIO *io, RIODesc *fd, const char *command) {
RSocket *s = RIORAP_FD (fd);
ut8 buf[1024];
char *ptr;
int ret, i, j;
int ret, i, j = 0;
// send
buf[0] = RMT_SYSTEM;