From 425fe596f48791dd322b0a8fe3de87c84c92b831 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 13 May 2011 10:22:28 +0200 Subject: [PATCH] * Fix many warning messages * Initial implementation of r_debug_rap * Implement 'dcu from to' (ranged stop point) * Use RList in r_lib (list.h has been deprecated) --- TODO | 1 - binr/radare2/radare2.c | 2 +- libr/bp/io.c | 34 +++----- libr/core/cmd.c | 16 +++- libr/debug/p/debug_gdb.c | 10 +-- libr/debug/p/debug_native.c | 6 +- libr/debug/p/debug_rap.c | 91 ++++++++++++++++++++ libr/debug/p/gdb.mk | 1 + libr/debug/p/libgdbwrap/gdbwrapper.c | 77 ++++++++--------- libr/debug/p/libgdbwrap/include/gdbwrapper.h | 4 +- libr/debug/p/rap.mk | 21 +++++ libr/debug/plugin.c | 1 + libr/include/r_lib.h | 8 +- libr/lib/lib.c | 85 +++++++++--------- plugins.def.cfg | 1 + 15 files changed, 230 insertions(+), 128 deletions(-) create mode 100644 libr/debug/p/debug_rap.c create mode 100644 libr/debug/p/rap.mk diff --git a/TODO b/TODO index 42511d428d..829ba9f3de 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ |__\__|_|__|___/__|__|_\__\___/ |____(_)____/ -* Continue until offset range (dcu from to) ## implement * x86/32-x86/64 the -e asm.bits should * Make r_io happy with RList * We need a 64 bit x86 assembler working!! nasm fails diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index 434c7dd138..15ee7d08fd 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -170,7 +170,7 @@ int main(int argc, char **argv) { fh = r_core_file_open (&r, file, perms, 0LL); if (fh != NULL) { - const char *arch = r_config_get (&r, "asm.arch"); + //const char *arch = r_config_get (r.config, "asm.arch"); // TODO: move into if (debug) .. if (is_gdb) r_debug_use (r.dbg, "gdb"); else r_debug_use (r.dbg, "native"); diff --git a/libr/bp/io.c b/libr/bp/io.c index 00c30dc4c9..3aeb4a1fbc 100644 --- a/libr/bp/io.c +++ b/libr/bp/io.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ +/* radare - LGPL - Copyright 2009-2011 pancake */ #include #include "../config.h" @@ -57,27 +57,22 @@ R_API int r_debug_bp_add(struct r_debug_t *dbg, ut64 addr, int size, int hw, int R_API int r_bp_restore(struct r_bp_t *bp, int set) { RListIter *iter; RBreakpointItem *b; - int handled; r_list_foreach (bp->bps, iter, b) { - if(bp->breakpoint) - handled = bp->breakpoint (bp->user, set, b->addr, b->hw, b->rwx); - else - handled = R_FALSE; - + if (bp->breakpoint && bp->breakpoint (bp->user, set, b->addr, b->hw, b->rwx)) + continue; /* write obytes from every breakpoint in r_bp if not handled by plugin */ - if (!handled) - if (set) { - eprintf("Setting bp at 0x%x\n", b->addr); - if (b->hw || !b->obytes) - eprintf ("hw breakpoints not supported yet\n"); - else bp->iob.write_at (bp->iob.io, b->addr, b->obytes, b->size); - } else { - eprintf("Clearing bp at 0x%x\n", b->addr); - if (b->hw || !b->bbytes) - eprintf ("hw breakpoints not supported yet\n"); - else bp->iob.write_at (bp->iob.io, b->addr, b->bbytes, b->size); - } + if (set) { + eprintf ("Setting bp at 0x%x\n", b->addr); + if (b->hw || !b->obytes) + eprintf ("hw breakpoints not supported yet\n"); + else bp->iob.write_at (bp->iob.io, b->addr, b->obytes, b->size); + } else { + eprintf ("Clearing bp at 0x%x\n", b->addr); + if (b->hw || !b->bbytes) + eprintf ("hw breakpoints not supported yet\n"); + else bp->iob.write_at (bp->iob.io, b->addr, b->bbytes, b->size); + } } return R_TRUE; @@ -85,7 +80,6 @@ R_API int r_bp_restore(struct r_bp_t *bp, int set) { R_API int r_bp_recoil(RBreakpoint *bp, ut64 addr) { RBreakpointItem *b = r_bp_at_addr (bp, addr, 0); //XXX Don't care about rwx - if (b) { //eprintf("HIT AT ADDR 0x%"PFMT64x"\n", addr); //eprintf(" recoil = %d\n", b->recoil); diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 084d5381ad..50b22e2015 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -78,8 +78,7 @@ static int bypassbp(RCore *core) { r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, R_FALSE); addr = r_debug_reg_get (core->dbg, "pc"); RBreakpointItem *bpi = r_bp_get (core->dbg->bp, addr); - if (!bpi) - return R_FALSE; + if (!bpi) return R_FALSE; /* XXX 2 if libr/debug/debug.c:226 is enabled */ r_debug_step (core->dbg, 1); return R_TRUE; @@ -4720,8 +4719,17 @@ static int cmd_debug(void *data, const char *input) { break; case 'u': ptr = strchr (input+3, ' '); - if (ptr) { - eprintf ("Continue until address range not yet implemented\n"); + if (ptr) { // TODO: put '\0' in *ptr to avoid + ut64 from, to, pc; + from = r_num_math (core->num, input+3); + to = r_num_math (core->num, ptr+1); + do { + r_debug_step (core->dbg, 1); + r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, R_FALSE); + pc = r_debug_reg_get (core->dbg, "pc"); + eprintf ("Continue 0x%08"PFMT64x" > 0x%08"PFMT64x" < 0x%08"PFMT64x"\n", + from, pc, to); + } while (pc < from || pc > to); return 1; } addr = r_num_math (core->num, input+2); diff --git a/libr/debug/p/debug_gdb.c b/libr/debug/p/debug_gdb.c index 7ebba6dbc4..60018b7a37 100644 --- a/libr/debug/p/debug_gdb.c +++ b/libr/debug/p/debug_gdb.c @@ -33,14 +33,14 @@ static int r_debug_gdb_step(RDebug *dbg) { } static int r_debug_gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { - gdbwrap_readgenreg(desc); - gdbwrap_getreg_buffer(desc,buf,desc->reg_size*desc->num_registers); + gdbwrap_readgenreg (desc); + gdbwrap_getreg_buffer (desc, buf, desc->reg_size*desc->num_registers); return desc->num_registers*desc->reg_size; } static int r_debug_gdb_reg_write(int pid, int tid, int type, const ut8 *buf, int size) { - gdbwrap_setreg_buffer(desc,buf,desc->reg_size*desc->num_registers); - gdbwrap_shipallreg(desc); + gdbwrap_setreg_buffer (desc, buf, desc->reg_size*desc->num_registers); + gdbwrap_shipallreg (desc); return R_TRUE; // XXX Error check } @@ -105,7 +105,7 @@ static const char *r_debug_gdb_reg_profile(RDebug *dbg) { case R_SYS_ARCH_SH: break; default: - arch = R_SYS_ARCH; + arch = r_sys_arch_id (R_SYS_ARCH); break; } switch (arch) { diff --git a/libr/debug/p/debug_native.c b/libr/debug/p/debug_native.c index 622254865b..9c7c237d3c 100644 --- a/libr/debug/p/debug_native.c +++ b/libr/debug/p/debug_native.c @@ -948,9 +948,9 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags)); return R_FALSE; } -int tid = dbg->tid; -if (tid == dbg->pid) - tid = 0; + int tid = dbg->tid; + if (tid == dbg->pid) + tid = 0; if (inferior_thread_count>0) { /* TODO: allow to choose the thread */ gp_count = R_DEBUG_STATE_SZ; diff --git a/libr/debug/p/debug_rap.c b/libr/debug/p/debug_rap.c new file mode 100644 index 0000000000..a8bf63c0a7 --- /dev/null +++ b/libr/debug/p/debug_rap.c @@ -0,0 +1,91 @@ +/* radare - LGPL - Copyright 2011 pancake */ + +#include +#include + +static int r_debug_rap_step(RDebug *dbg) { + r_io_system (dbg->iob.io, "ds"); + return R_TRUE; +} + +static int r_debug_rap_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { + r_io_system (dbg->iob.io, "dr"); + return 0; +} + +static int r_debug_rap_reg_write(int pid, int tid, int type, const ut8 *buf, int size) { + return R_FALSE; // XXX Error check +} + +static int r_debug_rap_continue(RDebug *dbg, int pid, int tid, int sig) { + r_io_system (dbg->iob.io, "dc"); + return R_TRUE; +} + +static int r_debug_rap_wait(int pid) { + /* do nothing */ + return R_TRUE; +} + +static int r_debug_rap_attach(RDebug *dbg, int pid) { +// XXX TODO PID must be a socket here !!1 + RIODesc *d = dbg->iob.io->fd; + if (d && d->plugin && d->plugin->name) { + + if (!strcmp ("rap", d->plugin->name)) { + eprintf ("SUCCESS: rap attach with inferior rap rio worked\n"); + } else { + eprintf ("ERROR: Underlaying IO descriptor is not a GDB one..\n"); + } + } + return R_TRUE; +} + +static int r_debug_rap_detach(int pid) { +// XXX TODO PID must be a socket here !!1 +// close (pid); + //XXX Maybe we should continue here? + return R_TRUE; +} + +static const char *r_debug_rap_reg_profile(RDebug *dbg) { + r_io_system (dbg->iob.io, "drp"); + return NULL; +} + +static int r_debug_rap_breakpoint (void *user, int type, ut64 addr, int hw, int rwx){ + //r_io_system (dbg->iob.io, "db"); + return R_FALSE; +} + +struct r_debug_plugin_t r_debug_plugin_rap = { + .name = "rap", + /* TODO: Add support for more architectures here */ + .arch = 0xff, + .bits = R_SYS_BITS_32, + .init = NULL, + .step = r_debug_rap_step, + .cont = r_debug_rap_continue, + .attach = &r_debug_rap_attach, + .detach = &r_debug_rap_detach, + .wait = &r_debug_rap_wait, + .pids = NULL, + .tids = NULL, + .threads = NULL, + .kill = NULL, + .frames = NULL, + .map_get = NULL, + .breakpoint = &r_debug_rap_breakpoint, + .reg_read = &r_debug_rap_reg_read, + .reg_write = &r_debug_rap_reg_write, + .reg_profile = (void *)r_debug_rap_reg_profile, + //.bp_write = &r_debug_rap_bp_write, + //.bp_read = &r_debug_rap_bp_read, +}; + +#ifndef CORELIB +struct r_lib_struct_t radare_plugin = { + .type = R_LIB_TYPE_DBG, + .data = &r_debug_plugin_rap +}; +#endif diff --git a/libr/debug/p/gdb.mk b/libr/debug/p/gdb.mk index e8360e514f..ea7aa47ce1 100644 --- a/libr/debug/p/gdb.mk +++ b/libr/debug/p/gdb.mk @@ -9,6 +9,7 @@ ifeq (${OSTYPE},solaris) LDFLAGS+=-lsocket endif +LDFLAGS+=-L../../util -lr_util OBJ_GDB=debug_gdb.o #libgdbwrap/gdbwrapper.o diff --git a/libr/debug/p/libgdbwrap/gdbwrapper.c b/libr/debug/p/libgdbwrap/gdbwrapper.c index e83b7d424b..20f9ba782f 100644 --- a/libr/debug/p/libgdbwrap/gdbwrapper.c +++ b/libr/debug/p/libgdbwrap/gdbwrapper.c @@ -48,7 +48,7 @@ void gdbwrap_setreg(gdbwrap_t *desc, ut32 idx, ut64 value){ } } -void gdbwrap_getreg_buffer(gdbwrap_t *desc, char *buf, ut32 size){ +void gdbwrap_getreg_buffer(gdbwrap_t *desc, unsigned char *buf, ut32 size){ if ( desc->reg_size*desc->num_registers > size ) size = desc->reg_size*desc->num_registers; @@ -56,32 +56,28 @@ void gdbwrap_getreg_buffer(gdbwrap_t *desc, char *buf, ut32 size){ memcpy(buf,desc->regs,size); } -void gdbwrap_setreg_buffer(gdbwrap_t *desc, char *buf , ut32 size){ - if ( desc->reg_size*desc->num_registers > size ) +void gdbwrap_setreg_buffer(gdbwrap_t *desc, const unsigned char *buf , ut32 size){ + if (desc->reg_size*desc->num_registers > size) size = desc->reg_size*desc->num_registers; memcpy (desc->regs, buf, size); } ut64 gdbwrap_getreg(gdbwrap_t *desc, ut32 idx){ - ut64 ret=-1; - if ( idx >= desc->num_registers){ + ut64 ret = -1; + if (idx >= desc->num_registers){ fprintf(stderr, "Wrong register index %d\n",idx); - } - switch( desc->reg_size ) { - case 1: - ret = *(desc->regs+idx); - break; - case 2: - ret = *(ut16 *)(desc->regs+idx*2); - break; - case 4: - ret = *(ut32 *)(desc->regs + idx*4 ); - break; - case 8: - ret = *(ut64 *)(desc->regs + idx*8 ); - break; - default: - fprintf(stderr,"Unsupported register size!"); + } else + switch (desc->reg_size ) { + case 1: ret = *(desc->regs+idx); + break; + case 2: ret = *(ut16 *)(desc->regs+idx*2); + break; + case 4: ret = *(ut32 *)(desc->regs + idx*4 ); + break; + case 8: ret = *(ut64 *)(desc->regs + idx*8 ); + break; + default: + fprintf (stderr,"Unsupported register size!"); } return ret; } @@ -244,28 +240,23 @@ static uint8_t gdbwrap_calc_checksum(gdbwrap_t *desc, const char *str) } -static char *gdbwrap_make_message(gdbwrap_t *desc, const char *query) -{ - uint8_t checksum = gdbwrap_calc_checksum(desc, query); - unsigned max_query_size = (desc->max_packet_size - - strlen(GDBWRAP_BEGIN_PACKET) - - strlen(GDBWRAP_END_PACKET) - - sizeof(checksum)); +static char *gdbwrap_make_message(gdbwrap_t *desc, const char *query) { + uint8_t checksum = gdbwrap_calc_checksum(desc, query); + unsigned max_query_size = (desc->max_packet_size - strlen(GDBWRAP_BEGIN_PACKET) + - strlen(GDBWRAP_END_PACKET) - sizeof(checksum)); - /* Sometimes C sucks... Basic source and destination checking. We do - not check the overlapping tho.*/ - if (strlen(query) < max_query_size && query != desc->packet) - { - int ret = snprintf(desc->packet, desc->max_packet_size, "%s%s%s%.2x", - GDBWRAP_BEGIN_PACKET, query, GDBWRAP_END_PACKET, checksum); - ASSERT(ret > 0); - } - else - { - ASSERT(FALSE); - } - - return desc->packet; + /* Sometimes C sucks... Basic source and destination checking. We do + not check the overlapping tho.*/ + if (strlen(query) < max_query_size && query != desc->packet) { + int ret = snprintf(desc->packet, desc->max_packet_size, "%s%s%s%.2x", + GDBWRAP_BEGIN_PACKET, query, GDBWRAP_END_PACKET, checksum); + if (ret <1) { + fprintf (stderr, "snprintf failed\n"); + return NULL; + } + return desc->packet; + } + return NULL; } @@ -773,7 +764,7 @@ int gdbwrap_simplesetbp(gdbwrap_t *desc, la32 linaddr) return 1; } -void gdbwrap_simplesethwbp(gdbwrap_t *desc, la32 linaddr) +int gdbwrap_simplesethwbp(gdbwrap_t *desc, la32 linaddr) { char *ret; char packet[MSG_BUF]; diff --git a/libr/debug/p/libgdbwrap/include/gdbwrapper.h b/libr/debug/p/libgdbwrap/include/gdbwrapper.h index b4974a918c..c22fe86800 100644 --- a/libr/debug/p/libgdbwrap/include/gdbwrapper.h +++ b/libr/debug/p/libgdbwrap/include/gdbwrapper.h @@ -106,7 +106,7 @@ char *gdbwrap_remotecmd(gdbwrap_t *desc, char *cmd); u_char gdbwrap_lasterror(gdbwrap_t *desc); gdbmemap_t gdbwrap_memorymap_get(); ut64 gdbwrap_getreg(gdbwrap_t *desc, ut32 idx); -void gdbwrap_getreg_buffer(gdbwrap_t *desc, char *buf, ut32 size); +void gdbwrap_getreg_buffer(gdbwrap_t *desc, unsigned char *buf, ut32 size); void gdbwrap_setreg(gdbwrap_t *desc, ut32 idx, ut64 value); -void gdbwrap_setreg_buffer(gdbwrap_t *desc, char *buf, ut32 size); +void gdbwrap_setreg_buffer(gdbwrap_t *desc, const unsigned char *buf, ut32 size); #endif diff --git a/libr/debug/p/rap.mk b/libr/debug/p/rap.mk new file mode 100644 index 0000000000..e019ee7d14 --- /dev/null +++ b/libr/debug/p/rap.mk @@ -0,0 +1,21 @@ +CFLAGS+=-Ip/librapwrap/include +ifeq (${OSTYPE},windows) +LDFLAGS+=-lwsock32 +endif +ifeq (${OSTYPE},solaris) +LDFLAGS+=-lsocket +endif + +OBJ_RAP=debug_rap.o +#librapwrap/rapwrapper.o + +#librapwrap/rapwrapper.o: +# ${CC} -c ${CFLAGS} ${LDFLAGS} -o p/librapwrap/rapwrapper.o p/librapwrap/rapwrapper.c + +STATIC_OBJ+=${OBJ_RAP} +TARGET_RAP=debug_rap.${EXT_SO} + +ALL_TARGETS+=${TARGET_RAP} + +${TARGET_RAP}: ${OBJ_RAP} + ${CC} -shared ${OBJ_RAP} ${CFLAGS} ${LDFLAGS} -o ${TARGET_RAP} diff --git a/libr/debug/plugin.c b/libr/debug/plugin.c index 49f4fe971c..9a2a906aa5 100644 --- a/libr/debug/plugin.c +++ b/libr/debug/plugin.c @@ -5,6 +5,7 @@ /* plugin pointers */ extern RDebugPlugin r_debug_plugin_native; +extern RDebugPlugin r_debug_plugin_rap; extern RDebugPlugin r_debug_plugin_gdb; static RDebugPlugin *debug_static_plugins[] = diff --git a/libr/include/r_lib.h b/libr/include/r_lib.h index e8f8f906a6..19e712bae9 100644 --- a/libr/include/r_lib.h +++ b/libr/include/r_lib.h @@ -5,7 +5,7 @@ // TODO: use 4 chars to idnetify plugin type #include "r_types.h" -#include "list.h" +#include "r_list.h" // rename to '.' ?? #define R_LIB_SEPARATOR "." @@ -28,7 +28,6 @@ typedef struct r_lib_plugin_t { void *data; /* user pointer */ struct r_lib_handler_t *handler; void *dl_handler; // DL HANDLER - struct list_head list; } RLibPlugin; /* store list of initialized plugin handlers */ @@ -38,7 +37,6 @@ typedef struct r_lib_handler_t { void *user; /* user pointer */ int (*constructor)(struct r_lib_plugin_t *, void *user, void *data); int (*destructor)(struct r_lib_plugin_t *, void *user, void *data); - struct list_head list; } RLibHandler; /* this structure should be pointed by the 'radare_plugin' symbol @@ -70,8 +68,8 @@ typedef struct r_lib_t { /* only one handler per handler-id allowed */ /* this is checked in add_handler function */ char symname[32]; - struct list_head plugins; - struct list_head handlers; + RList /*RLibPlugin*/ *plugins; + RList /*RLibHandler*/ *handlers; } RLib; #ifdef R_API diff --git a/libr/lib/lib.c b/libr/lib/lib.c index 751047283d..f0a81b4e49 100644 --- a/libr/lib/lib.c +++ b/libr/lib/lib.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2008-2010 pancake */ +/* radare - LGPL - Copyright 2008-2011 pancake */ #include "r_types.h" #include "r_util.h" @@ -63,13 +63,11 @@ R_API int r_lib_dl_close(void *handler) { /* ---- */ R_API RLib *r_lib_new(const char *symname) { - RLib *lib; - - lib = R_NEW (RLib); + RLib *lib = R_NEW (RLib); if (lib) { r_lib_debug_enabled = r_sys_getenv ("R_DEBUG")?R_TRUE:R_FALSE; - INIT_LIST_HEAD (&lib->handlers); - INIT_LIST_HEAD (&lib->plugins); + lib->handlers = r_list_new (); + lib->plugins = r_list_new (); strncpy (lib->symname, symname, sizeof (lib->symname)-1); } return lib; @@ -100,9 +98,9 @@ R_API int r_lib_run_handler(RLib *lib, RLibPlugin *plugin, RLibStruct *symbol) { } R_API RLibHandler *r_lib_get_handler(RLib *lib, int type) { - struct list_head *pos; - list_for_each_prev (pos, &lib->handlers) { - RLibHandler *h = list_entry (pos, RLibHandler, list); + RLibHandler *h; + RListIter *iter; + r_list_foreach (lib->handlers, iter, h) { if (h->type == type) return h; } @@ -110,14 +108,14 @@ R_API RLibHandler *r_lib_get_handler(RLib *lib, int type) { } R_API R_API int r_lib_close(RLib *lib, const char *file) { - struct list_head *pos; - list_for_each_prev (pos, &lib->plugins) { - RLibPlugin *h = list_entry(pos, RLibPlugin, list); - if ((file==NULL || (!strcmp(file, h->file))) && h->handler->destructor != NULL) { - int ret = h->handler->destructor(h, h->handler->user, h->data); - free(h->file); - list_del(&h->list); - free(h); + RLibPlugin *p; + RListIter *iter; + r_list_foreach (lib->plugins, iter, p) { + if ((file==NULL || (!strcmp(file, p->file))) && p->handler->destructor != NULL) { + int ret = p->handler->destructor (p, p->handler->user, p->data); + free (p->file); + r_list_delete (lib->plugins, iter); + free (p); return ret; } } @@ -145,18 +143,18 @@ static int samefile(const char *a, const char *b) { len = strlen (ptr+1) + 1; memmove (ptr, ptr+1, len); } - } while(ptr); - ret = strcmp(sa,sb)?R_FALSE:R_TRUE; + } while (ptr); + ret = strcmp (sa,sb)? R_FALSE: R_TRUE; } - free(sa); - free(sb); + free (sa); + free (sb); return ret; } R_API int r_lib_open(RLib *lib, const char *file) { RLibPlugin *p; - struct list_head *pos; + RListIter *iter; RLibStruct *stru; void * handler; int ret; @@ -179,28 +177,27 @@ R_API int r_lib_open(RLib *lib, const char *file) { return R_FAIL; } - list_for_each_prev(pos, &lib->plugins) { - RLibPlugin *p = list_entry(pos, RLibPlugin, list); - if (samefile(file, p->file)) { - r_lib_dl_close(handler); + r_list_foreach (lib->plugins, iter, p) { + if (samefile (file, p->file)) { + r_lib_dl_close (handler); return R_FAIL; } } - p = R_NEW(RLibPlugin); + p = R_NEW (RLibPlugin); p->type = stru->type; p->data = stru->data; - p->file = strdup(file); + p->file = strdup (file); p->dl_handler = handler; - p->handler = r_lib_get_handler(lib, p->type); + p->handler = r_lib_get_handler (lib, p->type); - ret = r_lib_run_handler(lib, p, stru); + ret = r_lib_run_handler (lib, p, stru); if (ret == R_FAIL) { IFDBG eprintf ("Library handler has failed for '%s'\n", file); free (p->file); free (p); r_lib_dl_close (handler); - } else list_add (&p->list, &lib->plugins); + } else r_list_append (lib->plugins, p); return ret; } @@ -237,11 +234,11 @@ R_API int r_lib_add_handler(RLib *lib, int (*dt)(RLibPlugin *, void *, void *), /* destructor */ void *user) { - struct list_head *pos; + RLibHandler *h; + RListIter *iter; RLibHandler *handler = NULL; - list_for_each_prev(pos, &lib->handlers) { - RLibHandler *h = list_entry(pos, RLibHandler, list); + r_list_foreach (lib->handlers, iter, h) { if (type == h->type) { IFDBG eprintf ("Redefining library handler constructor for %d\n", type); handler = h; @@ -249,13 +246,13 @@ R_API int r_lib_add_handler(RLib *lib, } } if (handler == NULL) { - handler = R_NEW(RLibHandler); + handler = R_NEW (RLibHandler); if (handler == NULL) return R_FALSE; handler->type = type; - list_add(&handler->list, &lib->handlers); + r_list_append (lib->handlers, handler); } - strncpy(handler->desc, desc, sizeof(handler->desc)); + strncpy (handler->desc, desc, sizeof (handler->desc)); handler->user = user; handler->constructor = cb; handler->destructor = dt; @@ -264,12 +261,12 @@ R_API int r_lib_add_handler(RLib *lib, } R_API int r_lib_del_handler(RLib *lib, int type) { - struct list_head *pos; + RLibHandler *h; + RListIter *iter; // TODO: remove all handlers for that type? or only one? - list_for_each_prev(pos, &lib->handlers) { - RLibHandler *h = list_entry(pos, RLibHandler, list); + r_list_foreach (lib->handlers, iter, h) { if (type == h->type) { - list_del(&(h->list)); + r_list_delete (lib->handlers, iter); return R_TRUE; } } @@ -278,7 +275,8 @@ R_API int r_lib_del_handler(RLib *lib, int type) { /* XXX _list methods must be deprecated before r2-1.0 */ R_API void r_lib_list(RLib *lib) { - struct list_head *pos; + RListIter *iter; + RLibPlugin *p; #if 0 printf("Plugin Plugins:\n"); list_for_each_prev(pos, &lib->handlers) { @@ -287,8 +285,7 @@ R_API void r_lib_list(RLib *lib) { } #endif //printf("Loaded plugins:\n"); - list_for_each_prev(pos, &lib->plugins) { - RLibPlugin *p = list_entry(pos, RLibPlugin, list); + r_list_foreach (lib->plugins, iter, p) { printf(" %5s %p %s \n", r_lib_types_get(p->type), p->handler->destructor, p->file); } } diff --git a/plugins.def.cfg b/plugins.def.cfg index 51c5b84ac0..0d28211f16 100644 --- a/plugins.def.cfg +++ b/plugins.def.cfg @@ -45,6 +45,7 @@ cmd.dummy crypto.aes debug.native debug.gdb +debug.rap fs.fat fs.ntfs fs.ext2