- Add plugin bin_mach0 (initial support for sections, imports and symbols)
* r_bin_pe
  - Minor fixup
This commit is contained in:
Nibble 2010-01-15 02:08:38 +01:00
parent 3d667dbdd9
commit 61480f889e
8 changed files with 126 additions and 8 deletions

View File

@ -21,6 +21,7 @@ extern struct r_bin_handle_t r_bin_plugin_elf;
extern struct r_bin_handle_t r_bin_plugin_elf64;
extern struct r_bin_handle_t r_bin_plugin_pe;
extern struct r_bin_handle_t r_bin_plugin_pe64;
extern struct r_bin_handle_t r_bin_plugin_mach0;
extern struct r_bin_handle_t r_bin_plugin_java;
extern struct r_bin_handle_t r_bin_plugin_dummy;

View File

@ -252,6 +252,7 @@ static int r_bin_mach0_init(struct r_bin_mach0_obj_t* bin)
bin->ntoc = 0;
bin->modtab = NULL;
bin->nmodtab = 0;
bin->baddr = 0;
bin->size = lseek(bin->fd, 0, SEEK_END);
if (!r_bin_mach0_init_hdr(bin)) {
ERR("Warning: File is not MACH0\n");
@ -359,6 +360,11 @@ struct r_bin_mach0_entrypoint_t* r_bin_mach0_get_entrypoints(struct r_bin_mach0_
return NULL;
}
ut64 r_bin_mach0_get_baddr(struct r_bin_mach0_obj_t* bin)
{
return UT64_MIN;
}
#ifdef MAIN
int main(int argc, char *argv[])
{

View File

@ -73,6 +73,7 @@ struct r_bin_mach0_section_t* r_bin_mach0_get_sections(struct r_bin_mach0_obj_t*
struct r_bin_mach0_symbol_t* r_bin_mach0_get_symbols(struct r_bin_mach0_obj_t* bin);
struct r_bin_mach0_import_t* r_bin_mach0_get_imports(struct r_bin_mach0_obj_t* bin);
struct r_bin_mach0_entrypoint_t* r_bin_mach0_get_entrypoints(struct r_bin_mach0_obj_t* bin);
ut64 r_bin_mach0_get_baddr(struct r_bin_mach0_obj_t* bin);
#if 0
int r_bin_mach0_get_arch(r_bin_mach0_obj*, char*);

View File

@ -7,7 +7,7 @@ CFLAGS+=-DLIL_ENDIAN=1 -D__UNIX__ -g -DR_DEBUG=0
foo: all
ALL_TARGETS=
FORMATS=elf.mk elf64.mk pe.mk pe64.mk java.mk dummy.mk
FORMATS=elf.mk elf64.mk pe.mk pe64.mk mach0.mk java.mk dummy.mk
include $(FORMATS)
all: ${ALL_TARGETS}

View File

@ -3,19 +3,27 @@
#include <r_types.h>
#include <r_lib.h>
#include <r_bin.h>
#include "mach0/mach0.h"
static int bopen(struct r_bin_t *bin)
{
struct r_bin_mach0_obj_t* mach0_obj;
if(!(bin->bin_obj = r_bin_mach0_new(bin->file)))
return -1;
mach0_obj = (struct r_bin_mach0_obj_t*)bin->bin_obj;
bin->fd = mach0_obj->fd;
return bin->fd;
}
static int bclose(struct r_bin_t *bin)
{
free(bin->bin_obj);
r_bin_mach0_free((struct r_bin_mach0_obj_t*)bin->bin_obj);
return R_TRUE;
}
static ut64 baddr(struct r_bin_t *bin)
{
return -0x1000; /* huh */
return r_bin_mach0_get_baddr((struct r_bin_mach0_obj_t*)bin->bin_obj);
}
static int check(struct r_bin_t *bin)
@ -27,12 +35,103 @@ static int check(struct r_bin_t *bin)
lseek(bin->fd, 0, SEEK_SET);
read(bin->fd, buf, 4);
close(bin->fd);
if (!memcmp(buf, "\xce\xfa\xed\xfa", 4))
if (!memcmp(buf, "\xce\xfa\xed\xfa", 4) ||
!memcmp(buf, "\xfe\xed\xfa\xce", 4))
ret = R_TRUE;
}
return ret;
}
static struct r_bin_section_t* sections(struct r_bin_t *bin)
{
int count, i;
struct r_bin_section_t *ret = NULL;
struct r_bin_mach0_section_t *sections = NULL;
if (!(sections = r_bin_mach0_get_sections((struct r_bin_mach0_obj_t*)bin->bin_obj)))
return NULL;
for (count = 0; sections && !sections[count].last; count++);
if (count == 0)
return NULL;
if ((ret = malloc((count + 1) * sizeof(struct r_bin_section_t))) == NULL)
return NULL;
memset(ret, '\0', (count + 1) * sizeof(struct r_bin_section_t));
for (i = 0; sections && !sections[i].last; i++) {
strncpy(ret[i].name, (char*)sections[i].name, R_BIN_SIZEOF_STRINGS);
ret[i].size = sections[i].size;
ret[i].vsize = sections[i].size;
ret[i].offset = sections[i].offset;
ret[i].rva = sections[i].addr;
ret[i].characteristics = 0;
ret[i].last = 0;
}
ret[i].last = 1;
free(sections);
return ret;
}
static struct r_bin_symbol_t* symbols(struct r_bin_t *bin)
{
int count, i;
struct r_bin_symbol_t *ret = NULL;
struct r_bin_mach0_symbol_t *symbols = NULL;
if (!(symbols = r_bin_mach0_get_symbols((struct r_bin_mach0_obj_t*)bin->bin_obj)))
return NULL;
for (count = 0; symbols && !symbols[count].last; count++);
if (count == 0)
return NULL;
if ((ret = malloc((count + 1) * sizeof(struct r_bin_symbol_t))) == NULL)
return NULL;
memset(ret, '\0', (count + 1) * sizeof(struct r_bin_symbol_t));
for (i = 0; symbols && !symbols[i].last; i++) {
strncpy(ret[i].name, (char*)symbols[i].name, R_BIN_SIZEOF_STRINGS);
strncpy(ret[i].forwarder, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy(ret[i].type, "NONE", R_BIN_SIZEOF_STRINGS);
ret[i].rva = symbols[i].addr;
ret[i].offset = symbols[i].offset;
ret[i].size = symbols[i].size;
ret[i].ordinal = 0;
ret[i].last = 0;
}
ret[i].last = 1;
free(symbols);
return ret;
}
static struct r_bin_import_t* imports(struct r_bin_t *bin)
{
int count, i;
struct r_bin_import_t *ret = NULL;
struct r_bin_mach0_import_t *imports = NULL;
if (!(imports = r_bin_mach0_get_imports((struct r_bin_mach0_obj_t*)bin->bin_obj)))
return NULL;
for (count = 0; imports && !imports[count].last; count++);
if (count == 0)
return NULL;
if ((ret = malloc((count + 1) * sizeof(struct r_bin_import_t))) == NULL)
return NULL;
memset(ret, '\0', (count + 1) * sizeof(struct r_bin_import_t));
for (i = 0; imports && !imports[i].last; i++) {
strncpy(ret[i].name, (char*)imports[i].name, R_BIN_SIZEOF_STRINGS);
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy(ret[i].type, "NONE", R_BIN_SIZEOF_STRINGS);
ret[i].rva = imports[i].addr;
ret[i].offset = imports[i].offset;
ret[i].ordinal = 0;
ret[i].hint = 0;
ret[i].last = 0;
}
ret[i].last = 1;
free(imports);
return ret;
}
struct r_bin_handle_t r_bin_plugin_mach0 = {
.name = "mach0",
.desc = "mach0 bin plugin",
@ -42,13 +141,12 @@ struct r_bin_handle_t r_bin_plugin_mach0 = {
.close = &bclose,
.check = &check,
.baddr = &baddr,
.entry = &entry,
.sections = &sections,
.symbols = &symbols,
.imports = &imports,
.strings = NULL,
.info = &info,
.fields = &fields,
.info = NULL,
.fields = NULL,
};
#ifndef CORELIB

View File

@ -63,7 +63,7 @@ static struct r_bin_section_t* sections(struct r_bin_t *bin)
for (i = 0; i < sections_count; i++) {
strncpy(ret[i].name, (char*)section[i].name, R_BIN_SIZEOF_STRINGS);
ret[i].size = section[i].size;
ret[i].vsize = section->vsize;
ret[i].vsize = section[i].vsize;
ret[i].offset = section[i].offset;
ret[i].rva = section[i].rva;
ret[i].characteristics = 0;

11
libr/bin/p/mach0.mk Normal file
View File

@ -0,0 +1,11 @@
OBJ_MACH0=bin_mach0.o ../format/mach0/mach0.o
STATIC_OBJ+=${OBJ_MACH0}
TARGET_MACH0=bin_mach0.so
ALL_TARGETS+=${TARGET_MACH0}
${TARGET_MACH0}: ${OBJ_MACH0}
${CC} ${CFLAGS} -o ${TARGET_MACH0} ${OBJ_MACH0}
@#strip -s ${TARGET_MACH0}

View File

@ -8,6 +8,7 @@ bin.elf64
bin.java
bin.pe
bin.pe64
bin.mach0
bininfo.addr2line
bp.arm
bp.x86