/* radare - LGPL - Copyright 2010-2011 pancake */ #include #include #include #include #include "../../debug/p/libgdbwrap/gdbwrapper.c" #include "../../debug/p/libgdbwrap/interface.c" typedef struct { RSocket *fd; gdbwrap_t *desc; } RIOGdb; #define RIOGDB_FD(x) (((RIOGdb*)(x))->fd) #define RIOGDB_DESC(x) (((RIOGdb*)(x->data))->desc) #define RIOGDB_IS_VALID(x) (x && x->plugin==&r_io_plugin_gdb && x->data) #define NUM_REGS 28 static int __plugin_open(RIO *io, const char *file) { return (!memcmp (file, "gdb://", 6)); } static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { char host[128], *port; RSocket *_fd; RIOGdb *riog; if (!__plugin_open (io, file)) return NULL; strncpy (host, file+6, sizeof (host)-1); port = strchr (host , ':'); if (!port) { eprintf ("Port not specified. Please use gdb://[host]:[port]\n"); return NULL; } *port = '\0'; _fd = r_socket_new (host, port+1, R_FALSE); if (_fd) { riog = R_NEW (RIOGdb); riog->fd = _fd; riog->desc = gdbwrap_init (_fd->fd,NUM_REGS,4); return r_io_desc_new (&r_io_plugin_gdb, _fd->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) { gdbwrap_writemem (RIOGDB_DESC (fd), io->off, (void *)buf, count); return count; } static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { //if (whence==2) return UT64_MAX; return offset; } static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { memset (buf, 0xff, count); if (RIOGDB_IS_VALID (fd)) { char *ptr = gdbwrap_readmem (RIOGDB_DESC (fd), (la32)io->off, count); if (ptr == NULL) return -1; 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 */ if(!strcmp(cmd,"regs")){ int i; gdbwrap_readgenreg (RIOGDB_DESC (fd)); for(i=0;i