* Added RBinBind type and logic

- Refactoring required to allow RAsm retrieve info from RBin
  - Will be used by dalvik and java disassemblers
This commit is contained in:
pancake 2011-06-26 20:29:24 +02:00
parent 7e8aba2198
commit 868acc4059
6 changed files with 46 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -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));

View File

@ -4,6 +4,7 @@
#define _INCLUDE_R_ASM_H_
#include <r_types.h>
#include <r_bin.h> // only for binding, no hard dep required
#include <list.h>
#include <r_util.h>
@ -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);

View File

@ -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);