Moving the bin_obj (internal format into RBinObject proper

This commit is contained in:
Adam Pridgen 2014-01-17 12:40:04 -06:00
parent 9669d404a5
commit 285e9ee1ef
15 changed files with 128 additions and 123 deletions

View File

@ -60,7 +60,7 @@ static int java_revisit_bb_anal_recursive_descent(RAnal *anal, RAnalState *state
static const RBinJavaObj * get_java_bin_obj(RAnal *anal) {
RBin *b = anal->binb.bin;
ut8 is_java = (b && b->cur.curplugin && strcmp (b->cur.curplugin->name, "java") == 0) ? 1 : 0;
return is_java ? b->cur.bin_obj : NULL;
return is_java ? b->cur.o->bin_obj : NULL;
}
static RList * get_java_bin_obj_list(RAnal *anal) {

View File

@ -15,7 +15,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
RBin *b = a->binb.bin;
if (b->cur.curplugin) {
if (!strcmp (b->cur.curplugin->name, "java")) { // XXX slow
obj = b->cur.bin_obj; //o;
obj = b->cur.o->bin_obj; //o;
//eprintf("Handling: %s disasm.\n", b->cur.file);
}
}

View File

@ -14,7 +14,7 @@ static int load(RBinArch *arch) {
}
static int destroy(RBinArch *arch) {
//r_bin_bios_free ((struct r_bin_bios_obj_t*)arch->bin_obj);
//r_bin_bios_free ((struct r_bin_bios_obj_t*)arch->o->bin_obj);
return R_TRUE;
}

View File

@ -17,8 +17,8 @@
#endif
static int load(RBinArch *arch) {
arch->bin_obj = r_bin_dex_new_buf (arch->buf);
return arch->bin_obj ? R_TRUE: R_FALSE;
arch->o->bin_obj = r_bin_dex_new_buf (arch->buf);
return arch->o->bin_obj ? R_TRUE: R_FALSE;
}
static ut64 baddr(RBinArch *arch) {
@ -95,7 +95,7 @@ static RBinInfo *info(RBinArch *arch) {
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy (ret->type, "DEX CLASS", R_BIN_SIZEOF_STRINGS);
ret->has_va = R_FALSE;
version = r_bin_dex_get_version (arch->bin_obj);
version = r_bin_dex_get_version (arch->o->bin_obj);
strncpy (ret->bclass, version, R_BIN_SIZEOF_STRINGS);
free (version);
strncpy (ret->rclass, "class", R_BIN_SIZEOF_STRINGS);
@ -141,7 +141,7 @@ static RBinInfo *info(RBinArch *arch) {
}
static RList* strings (RBinArch *arch) {
struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *) arch->bin_obj;
struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *) arch->o->bin_obj;
RBinString *ptr = NULL;
RList *ret = NULL;
int i, len;
@ -372,13 +372,13 @@ static int dex_loadcode(RBinArch *arch, RBinDexObj *bin) {
}
static RList* imports (RBinArch *arch) {
RBinDexObj *bin = (RBinDexObj*) arch->bin_obj;
RBinDexObj *bin = (RBinDexObj*) arch->o->bin_obj;
if (bin->imports_list)
return bin->imports_list;
dex_loadcode (arch, bin);
return bin->imports_list;
#if 0
struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *) arch->bin_obj;
struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *) arch->o->bin_obj;
int i;
RList *ret = NULL;
RBinImport *ptr;
@ -423,7 +423,7 @@ free (methodname);
#endif
}
static RList* methods (RBinArch *arch) {
RBinDexObj *bin = (RBinDexObj*) arch->bin_obj;
RBinDexObj *bin = (RBinDexObj*) arch->o->bin_obj;
if (bin->methods_list)
return bin->methods_list;
dex_loadcode (arch, bin);
@ -435,7 +435,7 @@ static void __r_bin_class_free(RBinClass *p) {
}
static RList* classes (RBinArch *arch) {
struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *) arch->bin_obj;
struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *) arch->o->bin_obj;
struct dex_class_t entry;
RList *ret = NULL;
RBinClass *class;
@ -485,7 +485,7 @@ static RList* classes (RBinArch *arch) {
static RList* entries(RBinArch *arch) {
RListIter *iter;
RBinDexObj *bin = (RBinDexObj*) arch->bin_obj;
RBinDexObj *bin = (RBinDexObj*) arch->o->bin_obj;
RList *ret = r_list_new ();
RBinAddr *ptr = R_NEW0 (RBinAddr);
RBinSymbol *m;
@ -504,7 +504,7 @@ static RList* entries(RBinArch *arch) {
//TODO
static int getoffset (RBinArch *arch, int type, int idx) {
struct r_bin_dex_obj_t *dex = arch->bin_obj;
struct r_bin_dex_obj_t *dex = arch->o->bin_obj;
switch (type) {
case 'm': // methods
if (dex->header.method_size > idx)
@ -531,7 +531,7 @@ static int getoffset (RBinArch *arch, int type, int idx) {
}
static RList* sections(RBinArch *arch) {
struct r_bin_dex_obj_t *bin = arch->bin_obj;
struct r_bin_dex_obj_t *bin = arch->o->bin_obj;
RList *ml = methods (arch);
RBinSection *ptr = NULL;
int ns, fsymsz = 0;

View File

@ -8,22 +8,22 @@
#include "elf/elf.h"
static int load(RBinArch *arch) {
if (!(arch->bin_obj = Elf_(r_bin_elf_new_buf) (arch->buf)))
if (!(arch->o->bin_obj = Elf_(r_bin_elf_new_buf) (arch->buf)))
return R_FALSE;
return R_TRUE;
}
static int destroy(RBinArch *arch) {
Elf_(r_bin_elf_free) ((struct Elf_(r_bin_elf_obj_t)*)arch->bin_obj);
Elf_(r_bin_elf_free) ((struct Elf_(r_bin_elf_obj_t)*)arch->o->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBinArch *arch) {
return Elf_(r_bin_elf_get_baddr) (arch->bin_obj);
return Elf_(r_bin_elf_get_baddr) (arch->o->bin_obj);
}
static ut64 boffset(RBinArch *arch) {
return Elf_(r_bin_elf_get_boffset) (arch->bin_obj);
return Elf_(r_bin_elf_get_boffset) (arch->o->bin_obj);
}
static RBinAddr* binsym(RBinArch *arch, int sym) {
@ -31,16 +31,16 @@ static RBinAddr* binsym(RBinArch *arch, int sym) {
RBinAddr *ret = NULL;
switch (sym) {
case R_BIN_SYM_ENTRY:
addr = Elf_(r_bin_elf_get_entry_offset) (arch->bin_obj);
addr = Elf_(r_bin_elf_get_entry_offset) (arch->o->bin_obj);
break;
case R_BIN_SYM_MAIN:
addr = Elf_(r_bin_elf_get_main_offset) (arch->bin_obj);
addr = Elf_(r_bin_elf_get_main_offset) (arch->o->bin_obj);
break;
case R_BIN_SYM_INIT:
addr = Elf_(r_bin_elf_get_init_offset) (arch->bin_obj);
addr = Elf_(r_bin_elf_get_init_offset) (arch->o->bin_obj);
break;
case R_BIN_SYM_FINI:
addr = Elf_(r_bin_elf_get_fini_offset) (arch->bin_obj);
addr = Elf_(r_bin_elf_get_fini_offset) (arch->o->bin_obj);
break;
}
if (addr && (ret = R_NEW0 (RBinAddr)))
@ -58,7 +58,7 @@ static RList* entries(RBinArch *arch) {
if (!(ptr = R_NEW (RBinAddr)))
return ret;
memset (ptr, '\0', sizeof (RBinAddr));
ptr->offset = ptr->rva = Elf_(r_bin_elf_get_entry_offset) (arch->bin_obj);
ptr->offset = ptr->rva = Elf_(r_bin_elf_get_entry_offset) (arch->o->bin_obj);
r_list_append (ret, ptr);
return ret;
}
@ -72,7 +72,7 @@ static RList* sections(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if ((section = Elf_(r_bin_elf_get_sections) (arch->bin_obj))) {
if ((section = Elf_(r_bin_elf_get_sections) (arch->o->bin_obj))) {
for (i = 0; !section[i].last; i++) {
if (!section[i].size) continue;
if (!(ptr = R_NEW0 (RBinSection)))
@ -101,7 +101,7 @@ static RList* sections(RBinArch *arch) {
int found = 0;
#define USE_PHDR 1
#if USE_PHDR
struct Elf_(r_bin_elf_obj_t)* obj = arch->bin_obj;
struct Elf_(r_bin_elf_obj_t)* obj = arch->o->bin_obj;
int i, n, num = obj->ehdr.e_phnum;
Elf_(Phdr)* phdr = obj->phdr;
for (i=n=0; i<num; i++) {
@ -129,7 +129,7 @@ static RList* sections(RBinArch *arch) {
}
#endif
if (!arch->size) {
struct Elf_(r_bin_elf_obj_t) *bin = arch->bin_obj;
struct Elf_(r_bin_elf_obj_t) *bin = arch->o->bin_obj;
arch->size = bin? bin->size: 0x9999;
}
if (found == 0) {
@ -152,10 +152,10 @@ static RList* symbols(RBinArch *arch) {
RBinSymbol *ptr = NULL;
ut64 base = 0;
struct r_bin_elf_symbol_t *symbol = NULL;
struct Elf_(r_bin_elf_obj_t) *bin = arch->bin_obj;
struct Elf_(r_bin_elf_obj_t) *bin = arch->o->bin_obj;
int i;
int has_va = Elf_(r_bin_elf_has_va) (arch->bin_obj);
int has_va = Elf_(r_bin_elf_has_va) (arch->o->bin_obj);
if (!has_va) {
// find base address for non-linked object (.o) //
if (arch->o->sections) {
@ -174,7 +174,7 @@ static RList* symbols(RBinArch *arch) {
return NULL;
ret->free = free;
if (!(symbol = Elf_(r_bin_elf_get_symbols) (arch->bin_obj, R_BIN_ELF_SYMBOLS)))
if (!(symbol = Elf_(r_bin_elf_get_symbols) (arch->o->bin_obj, R_BIN_ELF_SYMBOLS)))
return ret;
for (i = 0; !symbol[i].last; i++) {
if (!(ptr = R_NEW0 (RBinSymbol)))
@ -193,7 +193,7 @@ static RList* symbols(RBinArch *arch) {
}
free (symbol);
if (!(symbol = Elf_(r_bin_elf_get_symbols) (arch->bin_obj, R_BIN_ELF_IMPORTS)))
if (!(symbol = Elf_(r_bin_elf_get_symbols) (arch->o->bin_obj, R_BIN_ELF_IMPORTS)))
return ret;
for (i = 0; !symbol[i].last; i++) {
if (!symbol[i].size)
@ -222,13 +222,13 @@ static RList* imports(RBinArch *arch) {
RList *ret = NULL;
RBinImport *ptr = NULL;
struct r_bin_elf_symbol_t *import = NULL;
struct Elf_(r_bin_elf_obj_t) *bin = arch->bin_obj;
struct Elf_(r_bin_elf_obj_t) *bin = arch->o->bin_obj;
int i;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(import = Elf_(r_bin_elf_get_symbols) (arch->bin_obj, R_BIN_ELF_IMPORTS)))
if (!(import = Elf_(r_bin_elf_get_symbols) (arch->o->bin_obj, R_BIN_ELF_IMPORTS)))
return ret;
for (i = 0; !import[i].last; i++) {
if (!(ptr = R_NEW (RBinImport)))
@ -254,7 +254,7 @@ static RList* libs(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(libs = Elf_(r_bin_elf_get_libs) (arch->bin_obj)))
if (!(libs = Elf_(r_bin_elf_get_libs) (arch->o->bin_obj)))
return ret;
for (i = 0; !libs[i].last; i++) {
ptr = strdup (libs[i].name);
@ -357,13 +357,13 @@ static RList* relocs(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if ((got_addr = Elf_ (r_bin_elf_get_section_addr) (arch->bin_obj, ".got")) == -1 &&
(got_addr = Elf_ (r_bin_elf_get_section_addr) (arch->bin_obj, ".got.plt")) == -1)
if ((got_addr = Elf_ (r_bin_elf_get_section_addr) (arch->o->bin_obj, ".got")) == -1 &&
(got_addr = Elf_ (r_bin_elf_get_section_addr) (arch->o->bin_obj, ".got.plt")) == -1)
return ret;
if (!(relocs = Elf_(r_bin_elf_get_relocs) (arch->bin_obj)))
if (!(relocs = Elf_(r_bin_elf_get_relocs) (arch->o->bin_obj)))
return ret;
for (i = 0; !relocs[i].last; i++) {
if (!(ptr = reloc_convert(arch->bin_obj, &relocs[i], got_addr)))
if (!(ptr = reloc_convert(arch->o->bin_obj, &relocs[i], got_addr)))
break;
r_list_append (ret, ptr);
}
@ -379,44 +379,44 @@ static RBinInfo* info(RBinArch *arch) {
return NULL;
ret->lang = "c";
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
if ((str = Elf_(r_bin_elf_get_rpath)(arch->bin_obj))) {
if ((str = Elf_(r_bin_elf_get_rpath)(arch->o->bin_obj))) {
strncpy (ret->rpath, str, R_BIN_SIZEOF_STRINGS);
free (str);
} else strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
if (!(str = Elf_(r_bin_elf_get_file_type) (arch->bin_obj)))
if (!(str = Elf_(r_bin_elf_get_file_type) (arch->o->bin_obj)))
return NULL;
strncpy (ret->type, str, R_BIN_SIZEOF_STRINGS);
ret->has_pi = (strstr (str, "DYN"))? 1: 0;
free (str);
if (!(str = Elf_(r_bin_elf_get_elf_class) (arch->bin_obj)))
if (!(str = Elf_(r_bin_elf_get_elf_class) (arch->o->bin_obj)))
return NULL;
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
if (!(str = Elf_(r_bin_elf_get_osabi_name) (arch->bin_obj)))
if (!(str = Elf_(r_bin_elf_get_osabi_name) (arch->o->bin_obj)))
return NULL;
strncpy (ret->os, str, R_BIN_SIZEOF_STRINGS);
free (str);
if (!(str = Elf_(r_bin_elf_get_osabi_name) (arch->bin_obj)))
if (!(str = Elf_(r_bin_elf_get_osabi_name) (arch->o->bin_obj)))
return NULL;
strncpy (ret->subsystem, str, R_BIN_SIZEOF_STRINGS);
free (str);
if (!(str = Elf_(r_bin_elf_get_machine_name) (arch->bin_obj)))
if (!(str = Elf_(r_bin_elf_get_machine_name) (arch->o->bin_obj)))
return NULL;
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
if (!(str = Elf_(r_bin_elf_get_arch) (arch->bin_obj)))
if (!(str = Elf_(r_bin_elf_get_arch) (arch->o->bin_obj)))
return NULL;
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
strncpy (ret->rclass, "elf", R_BIN_SIZEOF_STRINGS);
ret->bits = Elf_(r_bin_elf_get_bits) (arch->bin_obj);
ret->big_endian = Elf_(r_bin_elf_is_big_endian) (arch->bin_obj);
ret->has_va = Elf_(r_bin_elf_has_va) (arch->bin_obj);
ret->bits = Elf_(r_bin_elf_get_bits) (arch->o->bin_obj);
ret->big_endian = Elf_(r_bin_elf_is_big_endian) (arch->o->bin_obj);
ret->has_va = Elf_(r_bin_elf_has_va) (arch->o->bin_obj);
ret->dbg_info = 0;
if (!Elf_(r_bin_elf_get_stripped) (arch->bin_obj))
if (!Elf_(r_bin_elf_get_stripped) (arch->o->bin_obj))
ret->dbg_info |= 0x04 | 0x08 | 0x10;
else ret->dbg_info |= 0x01;
if (Elf_(r_bin_elf_get_static) (arch->bin_obj))
if (Elf_(r_bin_elf_get_static) (arch->o->bin_obj))
ret->dbg_info |= 0x02;
return ret;
}
@ -430,7 +430,7 @@ static RList* fields(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(field = Elf_(r_bin_elf_get_fields) (arch->bin_obj)))
if (!(field = Elf_(r_bin_elf_get_fields) (arch->o->bin_obj)))
return ret;
for (i = 0; !field[i].last; i++) {
if (!(ptr = R_NEW (RBinField)))
@ -563,7 +563,7 @@ static int size(RBinArch *arch) {
static ut64 get_elf_vaddr (RBinArch *arch, ut64 baddr, ut64 paddr, ut64 vaddr) {
//NOTE(aaSSfxxx): since RVA is vaddr - "official" image base, we just need to add imagebase to vaddr
struct Elf_(r_bin_elf_obj_t)* obj = arch->bin_obj;
struct Elf_(r_bin_elf_obj_t)* obj = arch->o->bin_obj;
return obj->baddr - obj->boffset + vaddr;
}

View File

@ -43,7 +43,7 @@ static int load(RBinArch *arch) {
}
static int destroy(RBinArch *arch) {
//r_bin_fs_free ((struct r_bin_fs_obj_t*)arch->bin_obj);
//r_bin_fs_free ((struct r_bin_fs_obj_t*)arch->o->bin_obj);
return R_TRUE;
}

View File

@ -52,7 +52,7 @@ static int load(RBinArch *arch) {
bin_obj = r_bin_java_new_buf (arch->buf, arch->o->loadaddr, arch->o->kv);
if (bin_obj) {
if (arch->o->kv == NULL) arch->o->kv = bin_obj->kv;
arch->bin_obj = bin_obj;
arch->o->bin_obj = bin_obj;
bin_obj->AllJavaBinObjs = BIN_OBJS_ADDRS;
// XXX - /\ this is a hack, but (one way but) necessary to get access to
// the object addrs from anal. If only global variables are used,
@ -79,14 +79,14 @@ static int load(RBinArch *arch) {
}
static int destroy(RBinArch *arch) {
r_bin_java_free ((struct r_bin_java_obj_t*)arch->bin_obj);
r_bin_java_free ((struct r_bin_java_obj_t*)arch->o->bin_obj);
sdb_free (BIN_OBJS_ADDRS);
BIN_OBJS_ADDRS = NULL;
return R_TRUE;
}
static RList* entries(RBinArch *arch) {
return r_bin_java_get_entrypoints (arch->bin_obj);
return r_bin_java_get_entrypoints (arch->o->bin_obj);
}
static ut64 baddr(RBinArch *arch) {
@ -94,15 +94,15 @@ static ut64 baddr(RBinArch *arch) {
}
static RList* classes(RBinArch *arch) {
return r_bin_java_get_classes((struct r_bin_java_obj_t*)arch->bin_obj);
return r_bin_java_get_classes((struct r_bin_java_obj_t*)arch->o->bin_obj);
}
static RList* symbols(RBinArch *arch) {
return r_bin_java_get_symbols ((struct r_bin_java_obj_t*)arch->bin_obj);
return r_bin_java_get_symbols ((struct r_bin_java_obj_t*)arch->o->bin_obj);
}
static RList* strings(RBinArch *arch) {
return r_bin_java_get_strings((struct r_bin_java_obj_t*)arch->bin_obj);
return r_bin_java_get_strings((struct r_bin_java_obj_t*)arch->o->bin_obj);
}
static RBinInfo* info(RBinArch *arch) {
@ -116,7 +116,7 @@ static RBinInfo* info(RBinArch *arch) {
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS-1);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS-1);
strncpy (ret->type, "JAVA CLASS", R_BIN_SIZEOF_STRINGS-1);
version = r_bin_java_get_version (arch->bin_obj);
version = r_bin_java_get_version (arch->o->bin_obj);
strncpy (ret->bclass, version, R_BIN_SIZEOF_STRINGS-1);
free (version);
ret->has_va = 0;
@ -148,7 +148,7 @@ static int retdemangle(const char *str) {
}
static RBinAddr* binsym(RBinArch *arch, int sym) {
return r_bin_java_get_entrypoint(arch->bin_obj, sym);
return r_bin_java_get_entrypoint(arch->o->bin_obj, sym);
}
static RList* lines(RBinArch *arch) {
@ -156,7 +156,7 @@ static RList* lines(RBinArch *arch) {
char *file = strdup (arch->file);
RList *list = r_list_new ();
RBinJavaObj *b = arch->bin_obj;
RBinJavaObj *b = arch->o->bin_obj;
file = r_str_replace (file, ".class", ".java", 0);
for (i=0; i<b->lines.count; i++) {
RBinDwarfRow *row = R_NEW (RBinDwarfRow);
@ -168,15 +168,15 @@ static RList* lines(RBinArch *arch) {
}
static RList* sections(RBinArch *arch) {
return r_bin_java_get_sections (arch->bin_obj);
return r_bin_java_get_sections (arch->o->bin_obj);
}
static RList* fields(RBinArch *arch) {
return r_bin_java_get_fields (arch->bin_obj);
return r_bin_java_get_fields (arch->o->bin_obj);
}
static RList* libs(RBinArch *arch) {
return r_bin_java_get_lib_names (arch->bin_obj);
return r_bin_java_get_lib_names (arch->o->bin_obj);
}
RBinPlugin r_bin_plugin_java = {

View File

@ -7,20 +7,20 @@
#include "mach0/mach0.h"
static int load(RBinArch *arch) {
if (!(arch->bin_obj = MACH0_(r_bin_mach0_new_buf) (arch->buf)))
if (!(arch->o->bin_obj = MACH0_(r_bin_mach0_new_buf) (arch->buf)))
return R_FALSE;
struct MACH0_(r_bin_mach0_obj_t) *mo = arch->bin_obj;
struct MACH0_(r_bin_mach0_obj_t) *mo = arch->o->bin_obj;
arch->o->kv = mo->kv;
return R_TRUE;
}
static int destroy(RBinArch *arch) {
MACH0_(r_bin_mach0_free) (arch->bin_obj);
MACH0_(r_bin_mach0_free) (arch->o->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBinArch *arch) {
return MACH0_(r_bin_mach0_get_baddr) (arch->bin_obj);
return MACH0_(r_bin_mach0_get_baddr) (arch->o->bin_obj);
}
static RList* entries(RBinArch *arch) {
@ -31,7 +31,7 @@ static RList* entries(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(entry = MACH0_(r_bin_mach0_get_entrypoint) (arch->bin_obj)))
if (!(entry = MACH0_(r_bin_mach0_get_entrypoint) (arch->o->bin_obj)))
return ret;
if ((ptr = R_NEW0 (RBinAddr))) {
ptr->offset = entry->offset;
@ -51,7 +51,7 @@ static RList* sections(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(sections = MACH0_(r_bin_mach0_get_sections) (arch->bin_obj)))
if (!(sections = MACH0_(r_bin_mach0_get_sections) (arch->o->bin_obj)))
return ret;
for (i = 0; !sections[i].last; i++) {
if (!(ptr = R_NEW0 (RBinSection)))
@ -78,7 +78,7 @@ static RList* symbols(RBinArch *arch) {
if (!ret) return NULL;
ret->free = free;
if (!(symbols = MACH0_(r_bin_mach0_get_symbols) (arch->bin_obj)))
if (!(symbols = MACH0_(r_bin_mach0_get_symbols) (arch->o->bin_obj)))
return ret;
for (i = 0; !symbols[i].last; i++) {
if (!symbols[i].name[0] || symbols[i].addr<100) continue;
@ -103,7 +103,7 @@ static RList* symbols(RBinArch *arch) {
}
static RList* imports(RBinArch *arch) {
struct MACH0_(r_bin_mach0_obj_t) *bin = arch->bin_obj;
struct MACH0_(r_bin_mach0_obj_t) *bin = arch->o->bin_obj;
struct r_bin_mach0_import_t *imports = NULL;
const char *name, *type;
RBinImport *ptr = NULL;
@ -113,7 +113,7 @@ static RList* imports(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(imports = MACH0_(r_bin_mach0_get_imports) (arch->bin_obj)))
if (!(imports = MACH0_(r_bin_mach0_get_imports) (arch->o->bin_obj)))
return ret;
for (i = 0; !imports[i].last; i++) {
if (!(ptr = R_NEW (RBinImport)))
@ -149,13 +149,13 @@ static RList* relocs(RBinArch *arch) {
RList *ret = NULL;
RBinReloc *ptr = NULL;
struct r_bin_mach0_reloc_t *relocs = NULL;
struct MACH0_(r_bin_mach0_obj_t) *bin = arch->bin_obj;
struct MACH0_(r_bin_mach0_obj_t) *bin = arch->o->bin_obj;
int i;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(relocs = MACH0_(r_bin_mach0_get_relocs) (arch->bin_obj)))
if (!(relocs = MACH0_(r_bin_mach0_get_relocs) (arch->o->bin_obj)))
return ret;
for (i = 0; !relocs[i].last; i++) {
// TODO(eddyb) filter these out earlier.
@ -184,7 +184,7 @@ static RList* libs(RBinArch *arch) {
RList *ret = r_list_new ();
if (!ret) return NULL;
ret->free = free;
if ((libs = MACH0_(r_bin_mach0_get_libs) (arch->bin_obj))) {
if ((libs = MACH0_(r_bin_mach0_get_libs) (arch->o->bin_obj))) {
for (i = 0; !libs[i].last; i++) {
ptr = strdup (libs[i].name);
r_list_append (ret, ptr);
@ -202,32 +202,32 @@ static RBinInfo* info(RBinArch *arch) {
ret->lang = "c";
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
if ((str = MACH0_(r_bin_mach0_get_class) (arch->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_class) (arch->o->bin_obj))) {
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
strncpy (ret->rclass, "mach0", R_BIN_SIZEOF_STRINGS);
strncpy (ret->os, MACH0_(r_bin_mach0_get_os) (arch->bin_obj),
strncpy (ret->os, MACH0_(r_bin_mach0_get_os) (arch->o->bin_obj),
R_BIN_SIZEOF_STRINGS);
strncpy (ret->subsystem, "darwin", R_BIN_SIZEOF_STRINGS);
if ((str = MACH0_(r_bin_mach0_get_cputype) (arch->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_cputype) (arch->o->bin_obj))) {
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = MACH0_(r_bin_mach0_get_cpusubtype) (arch->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_cpusubtype) (arch->o->bin_obj))) {
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = MACH0_(r_bin_mach0_get_filetype) (arch->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_filetype) (arch->o->bin_obj))) {
strncpy (ret->type, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
ret->bits = MACH0_(r_bin_mach0_get_bits) (arch->bin_obj);
ret->big_endian = MACH0_(r_bin_mach0_is_big_endian) (arch->bin_obj);
ret->bits = MACH0_(r_bin_mach0_get_bits) (arch->o->bin_obj);
ret->big_endian = MACH0_(r_bin_mach0_is_big_endian) (arch->o->bin_obj);
/* TODO detailed debug info */
ret->dbg_info = 0;
ret->has_va = R_TRUE;
ret->has_pi = MACH0_(r_bin_mach0_is_pie) (arch->bin_obj);
ret->has_pi = MACH0_(r_bin_mach0_is_pie) (arch->o->bin_obj);
return ret;
}
@ -416,7 +416,7 @@ static RBinAddr* binsym(RBinArch *arch, int sym) {
RBinAddr *ret = NULL;
switch (sym) {
case R_BIN_SYM_MAIN:
addr = MACH0_(r_bin_mach0_get_main) (arch->bin_obj);
addr = MACH0_(r_bin_mach0_get_main) (arch->o->bin_obj);
if (!addr || !(ret = R_NEW0 (RBinAddr)))
return NULL;
ret->offset = ret->rva = addr;

View File

@ -165,7 +165,7 @@ static RBinAddr* binsym(RBinArch *arch, int sym) {
RBinAddr *ret = NULL;
switch (sym) {
case R_BIN_SYM_MAIN:
addr = MACH0_(r_bin_mach0_get_main) (arch->bin_obj);
addr = MACH0_(r_bin_mach0_get_main) (arch->o->bin_obj);
if (!addr || !(ret = R_NEW (RBinAddr)))
return NULL;
memset (ret, '\0', sizeof (RBinAddr));

View File

@ -7,18 +7,18 @@
#include "pe/pe.h"
static int load(RBinArch *arch) {
if(!(arch->bin_obj = PE_(r_bin_pe_new_buf) (arch->buf)))
if(!(arch->o->bin_obj = PE_(r_bin_pe_new_buf) (arch->buf)))
return R_FALSE;
return R_TRUE;
}
static int destroy(RBinArch *arch) {
PE_(r_bin_pe_free) ((struct PE_(r_bin_pe_obj_t)*)arch->bin_obj);
PE_(r_bin_pe_free) ((struct PE_(r_bin_pe_obj_t)*)arch->o->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBinArch *arch) {
return PE_(r_bin_pe_get_image_base) (arch->bin_obj);
return PE_(r_bin_pe_get_image_base) (arch->o->bin_obj);
}
static RBinAddr* binsym(RBinArch *arch, int type) {
@ -28,7 +28,7 @@ static RBinAddr* binsym(RBinArch *arch, int type) {
if (!(ret = R_NEW (RBinAddr)))
return NULL;
memset (ret, '\0', sizeof (RBinAddr));
ret->offset = ret->rva = PE_(r_bin_pe_get_main_offset) (arch->bin_obj);
ret->offset = ret->rva = PE_(r_bin_pe_get_main_offset) (arch->o->bin_obj);
break;
}
return ret;
@ -42,7 +42,7 @@ static RList* entries(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(entry = PE_(r_bin_pe_get_entrypoint) (arch->bin_obj)))
if (!(entry = PE_(r_bin_pe_get_entrypoint) (arch->o->bin_obj)))
return ret;
if ((ptr = R_NEW (RBinAddr))) {
ptr->offset = entry->offset;
@ -62,7 +62,7 @@ static RList* sections(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(sections = PE_(r_bin_pe_get_sections)(arch->bin_obj)))
if (!(sections = PE_(r_bin_pe_get_sections)(arch->o->bin_obj)))
return NULL;
for (i = 0; !sections[i].last; i++) {
if (!(ptr = R_NEW0 (RBinSection)))
@ -96,7 +96,7 @@ static RList* symbols(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(symbols = PE_(r_bin_pe_get_exports)(arch->bin_obj)))
if (!(symbols = PE_(r_bin_pe_get_exports)(arch->o->bin_obj)))
return ret;
for (i = 0; !symbols[i].last; i++) {
if (!(ptr = R_NEW0 (RBinSymbol)))
@ -138,9 +138,9 @@ static RList* imports(RBinArch *arch) {
ret->free = free;
relocs->free = free;
((struct PE_(r_bin_pe_obj_t)*)arch->bin_obj)->relocs = relocs;
((struct PE_(r_bin_pe_obj_t)*)arch->o->bin_obj)->relocs = relocs;
if (!(imports = PE_(r_bin_pe_get_imports)(arch->bin_obj)))
if (!(imports = PE_(r_bin_pe_get_imports)(arch->o->bin_obj)))
return ret;
for (i = 0; !imports[i].last; i++) {
if (!(ptr = R_NEW (RBinImport)))
@ -176,7 +176,7 @@ static RList* imports(RBinArch *arch) {
}
static RList* relocs(RBinArch *arch) {
return ((struct PE_(r_bin_pe_obj_t)*)arch->bin_obj)->relocs;
return ((struct PE_(r_bin_pe_obj_t)*)arch->o->bin_obj)->relocs;
}
static RList* libs(RBinArch *arch) {
@ -188,7 +188,7 @@ static RList* libs(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(libs = PE_(r_bin_pe_get_libs)(arch->bin_obj)))
if (!(libs = PE_(r_bin_pe_get_libs)(arch->o->bin_obj)))
return ret;
for (i = 0; !libs[i].last; i++) {
ptr = strdup (libs[i].name);
@ -204,41 +204,41 @@ static RBinInfo* info(RBinArch *arch) {
if (!ret) return NULL;
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
if ((str = PE_(r_bin_pe_get_class) (arch->bin_obj))) {
if ((str = PE_(r_bin_pe_get_class) (arch->o->bin_obj))) {
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
strncpy (ret->rclass, "pe", R_BIN_SIZEOF_STRINGS);
if ((str = PE_(r_bin_pe_get_os) (arch->bin_obj))) {
if ((str = PE_(r_bin_pe_get_os) (arch->o->bin_obj))) {
strncpy (ret->os, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = PE_(r_bin_pe_get_arch) (arch->bin_obj))) {
if ((str = PE_(r_bin_pe_get_arch) (arch->o->bin_obj))) {
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = PE_(r_bin_pe_get_machine) (arch->bin_obj))) {
if ((str = PE_(r_bin_pe_get_machine) (arch->o->bin_obj))) {
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = PE_(r_bin_pe_get_subsystem) (arch->bin_obj))) {
if ((str = PE_(r_bin_pe_get_subsystem) (arch->o->bin_obj))) {
strncpy (ret->subsystem, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if (PE_(r_bin_pe_is_dll) (arch->bin_obj))
if (PE_(r_bin_pe_is_dll) (arch->o->bin_obj))
strncpy (ret->type, "DLL (Dynamic Link Library)", R_BIN_SIZEOF_STRINGS);
else strncpy (ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_STRINGS);
ret->bits = PE_(r_bin_pe_get_bits) (arch->bin_obj);
ret->big_endian = PE_(r_bin_pe_is_big_endian) (arch->bin_obj);
ret->bits = PE_(r_bin_pe_get_bits) (arch->o->bin_obj);
ret->big_endian = PE_(r_bin_pe_is_big_endian) (arch->o->bin_obj);
ret->dbg_info = 0;
ret->has_va = R_TRUE;
if (!PE_(r_bin_pe_is_stripped_debug) (arch->bin_obj))
if (!PE_(r_bin_pe_is_stripped_debug) (arch->o->bin_obj))
ret->dbg_info |= 0x01;
if (PE_(r_bin_pe_is_stripped_line_nums) (arch->bin_obj))
if (PE_(r_bin_pe_is_stripped_line_nums) (arch->o->bin_obj))
ret->dbg_info |= 0x04;
if (PE_(r_bin_pe_is_stripped_local_syms) (arch->bin_obj))
if (PE_(r_bin_pe_is_stripped_local_syms) (arch->o->bin_obj))
ret->dbg_info |= 0x08;
if (PE_(r_bin_pe_is_stripped_relocs) (arch->bin_obj))
if (PE_(r_bin_pe_is_stripped_relocs) (arch->o->bin_obj))
ret->dbg_info |= 0x10;
return ret;
}

View File

@ -8,18 +8,18 @@
#include "te/te.h"
static int load(RBinArch *arch) {
if(!(arch->bin_obj = r_bin_te_new_buf (arch->buf)))
if(!(arch->o->bin_obj = r_bin_te_new_buf (arch->buf)))
return R_FALSE;
return R_TRUE;
}
static int destroy(RBinArch *arch) {
r_bin_te_free ((struct r_bin_te_obj_t*)arch->bin_obj);
r_bin_te_free ((struct r_bin_te_obj_t*)arch->o->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBinArch *arch) {
return r_bin_te_get_image_base (arch->bin_obj);
return r_bin_te_get_image_base (arch->o->bin_obj);
}
static RBinAddr* binsym(RBinArch *arch, int type) {
@ -29,7 +29,7 @@ static RBinAddr* binsym(RBinArch *arch, int type) {
if (!(ret = R_NEW (RBinAddr)))
return NULL;
memset (ret, '\0', sizeof (RBinAddr));
ret->offset = ret->rva = r_bin_te_get_main_offset (arch->bin_obj);
ret->offset = ret->rva = r_bin_te_get_main_offset (arch->o->bin_obj);
break;
}
return ret;
@ -43,7 +43,7 @@ static RList* entries(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(entry = r_bin_te_get_entrypoint (arch->bin_obj)))
if (!(entry = r_bin_te_get_entrypoint (arch->o->bin_obj)))
return ret;
if ((ptr = R_NEW (RBinAddr))) {
ptr->offset = entry->offset;
@ -63,7 +63,7 @@ static RList* sections(RBinArch *arch) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(sections = r_bin_te_get_sections(arch->bin_obj)))
if (!(sections = r_bin_te_get_sections(arch->o->bin_obj)))
return NULL;
for (i = 0; !sections[i].last; i++) {
if (!(ptr = R_NEW0 (RBinSection)))
@ -105,24 +105,24 @@ static RBinInfo* info(RBinArch *arch) {
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy (ret->bclass, "TE", R_BIN_SIZEOF_STRINGS);
strncpy (ret->rclass, "te", R_BIN_SIZEOF_STRINGS);
if ((str = r_bin_te_get_os (arch->bin_obj))) {
if ((str = r_bin_te_get_os (arch->o->bin_obj))) {
strncpy (ret->os, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = r_bin_te_get_arch (arch->bin_obj))) {
if ((str = r_bin_te_get_arch (arch->o->bin_obj))) {
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = r_bin_te_get_machine (arch->bin_obj))) {
if ((str = r_bin_te_get_machine (arch->o->bin_obj))) {
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = r_bin_te_get_subsystem (arch->bin_obj))) {
if ((str = r_bin_te_get_subsystem (arch->o->bin_obj))) {
strncpy (ret->subsystem, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
strncpy (ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_STRINGS);
ret->bits = r_bin_te_get_bits (arch->bin_obj);
ret->bits = r_bin_te_get_bits (arch->o->bin_obj);
ret->big_endian = 1;
ret->dbg_info = 0;
ret->has_va = R_TRUE;

View File

@ -5,11 +5,11 @@
#include "elf/elf.h"
static ut64 scn_resize(RBinArch *arch, const char *name, ut64 size) {
return Elf_(r_bin_elf_resize_section) (arch->bin_obj, name, size);
return Elf_(r_bin_elf_resize_section) (arch->o->bin_obj, name, size);
}
static int rpath_del(RBinArch *arch) {
return Elf_(r_bin_elf_del_rpath) (arch->bin_obj);
return Elf_(r_bin_elf_del_rpath) (arch->o->bin_obj);
}
#if !R_BIN_ELF64

View File

@ -284,6 +284,7 @@ R_API int r_core_bin_load(RCore *r, const char *file, ut64 baddr) {
if (r->bin->cur.curplugin && !strcmp (r->bin->cur.curplugin->name, "dex")) {
r_core_cmd0 (r, "\"(fix-dex,wx `#sha1 $s-32 @32` @12 ; wx `#adler32 $s-12 @12` @8)\"\n");
}
if (r->bin) r_bin_bind(r->bin, &(r->anal->binb));
if (r_config_get_i (r->config, "file.analyze"))
r_core_cmd0 (r, "aa");
return R_TRUE;

View File

@ -264,6 +264,10 @@ R_API int r_core_block_read(RCore *core, int next) {
if (!core->io->va)
return -1;
}
if (core->bin) {
//r_bin_bind (core->bin, &(core->assembler->binb));
//r_bin_bind (core->bin, &(core->anal->binb));
}
return (int)r_io_read (core->io, core->block, core->blocksize);
}

View File

@ -115,6 +115,7 @@ typedef struct r_bin_object_t {
int referenced;
int lang;
Sdb *kv;
void *bin_obj; // internal pointer used by formats
} RBinObject;
// XXX: this is a copy of RBinObject
@ -126,7 +127,6 @@ typedef struct r_bin_arch_t {
int rawstr;
ut64 offset;
RBinObject *o;
void *bin_obj; // internal pointer used by formats
struct r_bin_plugin_t *curplugin;
ut64 loadaddr;
} RBinArch;