diff --git a/libr/asm/asm.c b/libr/asm/asm.c index 15b3c3583c..45199da093 100644 --- a/libr/asm/asm.c +++ b/libr/asm/asm.c @@ -89,6 +89,7 @@ R_API RAsm *r_asm_new() { if (a) { a->user = NULL; a->cur = NULL; + a->binb.bin = NULL; a->bits = 32; a->big_endian = 0; a->pc = 0; @@ -419,3 +420,9 @@ R_API char *r_asm_op_get_hex(RAsmOp *op) { R_API char *r_asm_op_get_asm(RAsmOp *op) { return strdup (op->buf_asm); } + +R_API int r_asm_get_offset(RAsm *a, int type, int idx) { // link to rbin + if (a && a->binb.bin && a->binb.get_offset) + return a->binb.get_offset (a->binb.bin, type, idx); + return -1; +} diff --git a/libr/bin/bin.c b/libr/bin/bin.c index fd2bfb3cb1..968060b9cb 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -391,6 +391,18 @@ R_API void r_bin_set_user_ptr(RBin *bin, void *user) { bin->user = user; } +static int getoffset (RBin *bin, int type, int idx) { + RBinArch *a = &bin->curarch; + if (a && a->curplugin && a->curplugin->get_offset) + return a->curplugin->get_offset (a, type, idx); + return -1; +} + +R_API void r_bin_bind (RBin *bin, RBinBind *b) { + b->bin = bin; + b->get_offset = getoffset; +} + R_API RBinObj *r_bin_get_object(RBin *bin, int flags) { int i; RBinObj *obj = R_NEW (RBinObj); diff --git a/libr/bin/p/bin_dex.c b/libr/bin/p/bin_dex.c index 78a20beecc..bd4b4293a3 100644 --- a/libr/bin/p/bin_dex.c +++ b/libr/bin/p/bin_dex.c @@ -108,6 +108,16 @@ static RList* classes (RBinArch *arch) { return ret; } +static int getoffset (RBinArch *arch, int type, int idx) { + struct r_bin_dex_obj_t *dex = arch->bin_obj; + switch (type) { + case 's': // symbol name + // dex->header.method_offset + return 0; // TODO: must be the offset to the ptr + } + return 0; +} + struct r_bin_plugin_t r_bin_plugin_dex = { .name = "dex", .desc = "dex format bin plugin", @@ -129,6 +139,7 @@ struct r_bin_plugin_t r_bin_plugin_dex = { .relocs = NULL, .meta = NULL, .write = NULL, + .get_offset = &getoffset }; #ifndef CORELIB diff --git a/libr/core/core.c b/libr/core/core.c index 513b2ad2fb..cc04ea9149 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -317,6 +317,7 @@ R_API int r_core_init(RCore *core) { core->search = r_search_new (R_SEARCH_KEYWORD); r_io_undo_enable (core->io, 1, 0); // TODO: configurable via eval core->fs = r_fs_new (); + r_bin_bind (core->bin, &(core->assembler->binb)); r_io_bind (core->io, &(core->search->iob)); r_io_bind (core->io, &(core->print->iob)); r_io_bind (core->io, &(core->anal->iob)); diff --git a/libr/include/r_asm.h b/libr/include/r_asm.h index af59ea6ded..3b0d1c99e5 100644 --- a/libr/include/r_asm.h +++ b/libr/include/r_asm.h @@ -4,6 +4,7 @@ #define _INCLUDE_R_ASM_H_ #include +#include // only for binding, no hard dep required #include #include @@ -70,6 +71,7 @@ typedef struct r_asm_t { void *user; struct r_asm_plugin_t *cur; RList *plugins; + RBinBind binb; } RAsm; typedef int (*RAsmModifyCallback)(RAsm *a, ut8 *buf, int field, ut64 val); diff --git a/libr/include/r_bin.h b/libr/include/r_bin.h index 89c23df616..fe0b747502 100644 --- a/libr/include/r_bin.h +++ b/libr/include/r_bin.h @@ -37,6 +37,7 @@ enum { R_BIN_NM_ANY=-1, }; + // XXX: isnt this a copy of Obj ? typedef struct r_bin_arch_t { char *file; @@ -77,7 +78,7 @@ typedef struct r_bin_xtr_plugin_t { int (*extract)(RBin *bin, int idx); int (*load)(RBin *bin); int (*destroy)(RBin *bin); - struct list_head list; + struct list_head list; // TODO deprecate!!! } RBinXtrPlugin; typedef struct r_bin_plugin_t { @@ -102,7 +103,8 @@ typedef struct r_bin_plugin_t { int (*demangle_type)(const char *str); struct r_bin_meta_t *meta; struct r_bin_write_t *write; - struct list_head list; + int (*get_offset)(RBinArch *arch, int type, int idx); + struct list_head list; // TODO deprecate!!! } RBinPlugin; typedef struct r_bin_addr_t { @@ -211,7 +213,16 @@ typedef struct r_bin_obj_t { // TODO: has_dbg_syms... maybe flags? } RBinObj; +typedef int (*RBinGetOffset)(RBin *bin, int type, int idx); + +typedef struct r_bin_bind_t { + RBin *bin; + RBinGetOffset get_offset; +} RBinBind; + + #ifdef R_API +R_API void r_bin_bind(RBin *b, struct r_bin_bind_t *bnd); /* bin.c */ R_API int r_bin_add(RBin *bin, RBinPlugin *foo); R_API int r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo);