From 7a76f2f3e113a717b6e91b7c55b66f40004464ad Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Mon, 17 Feb 2014 00:02:47 +0400 Subject: [PATCH 1/8] coff: Initial commit --- libr/bin/format/coff/coff.c | 192 ++++++++++++++++++++++++++++++ libr/bin/format/coff/coff.h | 47 ++++++++ libr/bin/format/coff/coff_specs.h | 113 ++++++++++++++++++ libr/bin/p/Makefile | 2 +- libr/bin/p/bin_coff.c | 151 +++++++++++++++++++++++ libr/bin/p/coff.mk | 10 ++ libr/include/r_bin.h | 1 + plugins.def.cfg | 1 + 8 files changed, 516 insertions(+), 1 deletion(-) create mode 100644 libr/bin/format/coff/coff.c create mode 100644 libr/bin/format/coff/coff.h create mode 100644 libr/bin/format/coff/coff_specs.h create mode 100644 libr/bin/p/bin_coff.c create mode 100644 libr/bin/p/coff.mk diff --git a/libr/bin/format/coff/coff.c b/libr/bin/format/coff/coff.c new file mode 100644 index 0000000000000..8dc2aea84235a --- /dev/null +++ b/libr/bin/format/coff/coff.c @@ -0,0 +1,192 @@ +#include + +#include "coff.h" + +int coff_supported_arch(const ut8 *buf) +{ + ut16 arch = *(ut16*)buf; + int ret; + + switch (arch) { + case 0x8300: + ret = R_TRUE; + break; + default: + ret = R_FALSE; + } + + return R_TRUE; +} + +static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) +{ + size_t offset = 0; + + obj->endian = !LIL_ENDIAN; + + r_mem_copyendian((ut8*)&(obj->hdr.machine), obj->b->buf, + sizeof(ut16), obj->endian); + offset += sizeof(ut16); + + printf("machine 0x%x\n", obj->hdr.machine); + + r_mem_copyendian((ut8*)&(obj->hdr.sections_num), obj->b->buf + offset, + sizeof(ut16), obj->endian); + + offset += sizeof(ut16); + + printf("sections num %x\n", obj->hdr.sections_num); + + r_mem_copyendian((ut8*)&obj->hdr.timestamp, obj->b->buf + offset, + sizeof(ut32), obj->endian); + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&obj->hdr.symtable_offset, obj->b->buf + offset, + sizeof(ut32), obj->endian); + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->hdr.symbols_num), obj->b->buf + offset, + sizeof(ut32), obj->endian); + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->hdr.opt_hdr_size), obj->b->buf + offset, + sizeof(ut16), obj->endian); + offset += sizeof(ut16); + printf("opt hdr size %u\n", obj->hdr.opt_hdr_size); + + r_mem_copyendian((ut8*)&(obj->hdr.flags), obj->b->buf + offset, + sizeof(ut16), obj->endian); + + return R_TRUE; +} + +static int r_bin_coff_init_opt_hdr(struct r_bin_coff_obj *obj) +{ + return R_TRUE; +} + +static int r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) +{ + size_t i, offset = obj->hdr.opt_hdr_size + 20; + + obj->scn_hdrs = calloc(obj->hdr.sections_num, + sizeof(struct coff_scn_hdr)); + + for (i = 0; i < obj->hdr.sections_num; i++) { + strncpy(obj->scn_hdrs[i].name, (char*)(obj->b->buf + offset), 8); + printf("section name %s\n", obj->scn_hdrs[i].name); + + offset += 8; + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].virtual_size), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].virtual_addr), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + printf("virtial addr %x\n", obj->scn_hdrs[i].virtual_addr); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].raw_data_size), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].raw_data_pointer), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + printf("raw_data_pointer %x\n", obj->scn_hdrs[i].raw_data_pointer); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].reloc_pointer), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].linenum_pointer), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].reloc_num), + obj->b->buf + offset, sizeof(ut16), obj->endian); + + offset += sizeof(ut16); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].linenum_num), + obj->b->buf + offset, sizeof(ut16), obj->endian); + + offset += sizeof(ut16); + + r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].flags), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + } + + return 0; +} + +static int r_bin_coff_init_symtable(struct r_bin_coff_obj *obj) +{ + size_t i, offset = obj->hdr.symtable_offset; + ut32 short_name, ofst; + + obj->symbols = calloc(obj->hdr.symbols_num, + sizeof(struct coff_symbol)); + + for (i = 0; i < obj->hdr.symbols_num; i++) { + r_mem_copyendian((ut8*)&short_name, obj->b->buf + offset, + sizeof(ut32), obj->endian); + + if (short_name) { + obj->symbols[i].name = malloc(sizeof(char) * 9); + strncpy(obj->symbols[i].name, + (char*)(obj->b->buf + offset), 8); + obj->symbols[i].name[8] = '\0'; + offset += 8; + } else { + offset += sizeof(ut32); + r_mem_copyendian((ut8*)&ofst, obj->b->buf + offset, + sizeof(ut32), obj->endian); + + obj->symbols[i].name = strdup((char*)(obj->b->buf + + obj->hdr.symtable_offset + ofst + + obj->hdr.symbols_num * 18)); + offset += sizeof(ut32); + } + + offset += 10; +// printf ("symbol %s\n", obj->symbols[i].name); + } +} + +static int r_bin_coff_init(struct r_bin_coff_obj *obj, struct r_buf_t *buf) +{ + obj->b = buf; + obj->size = buf->length; + + r_bin_coff_init_hdr(obj); + r_bin_coff_init_opt_hdr(obj); + + r_bin_coff_init_scn_hdr(obj); + r_bin_coff_init_symtable(obj); + + return R_TRUE; +} + +void r_bin_coff_free(struct r_bin_coff_obj *obj) +{ +} + +struct r_bin_coff_obj* r_bin_coff_new_buf(struct r_buf_t *buf) +{ + struct r_bin_coff_obj* bin = R_NEW0(struct r_bin_coff_obj); + + r_bin_coff_init(bin, buf); + + return bin; +} diff --git a/libr/bin/format/coff/coff.h b/libr/bin/format/coff/coff.h new file mode 100644 index 0000000000000..b498b1f91c910 --- /dev/null +++ b/libr/bin/format/coff/coff.h @@ -0,0 +1,47 @@ +/* radare - LGPL - Copyright 2014 Fedor Sakharov */ + +#ifndef COFF_H +#define COFF_H + +#include +#include + +#include "coff_specs.h" + +struct coff_scn_hdr { + char name[9]; + ut32 virtual_size; + ut32 virtual_addr; + ut32 raw_data_size; + ut32 raw_data_pointer; + ut32 reloc_pointer; + ut32 linenum_pointer; + ut16 reloc_num; + ut16 linenum_num; + ut32 flags; +}; + +struct coff_symbol { + char *name; + ut32 value; + ut16 scn_num; + ut16 type; + ut8 storage_class; + ut8 aux_sym_num; +}; + +struct r_bin_coff_obj { + struct coff_hdr hdr; + struct coff_opt_hdr opt_hdr; + struct coff_scn_hdr *scn_hdrs; + struct coff_symbol *symbols; + + struct r_buf_t *b; + size_t size; + ut8 endian; +}; + +int coff_supported_arch(const ut8 *buf); +struct r_bin_coff_obj* r_bin_coff_new_buf(struct r_buf_t *buf); + +#endif /* COFF_H */ diff --git a/libr/bin/format/coff/coff_specs.h b/libr/bin/format/coff/coff_specs.h new file mode 100644 index 0000000000000..943653e03b344 --- /dev/null +++ b/libr/bin/format/coff/coff_specs.h @@ -0,0 +1,113 @@ +/* radare - LGPL - Copyright 2014 - Fedor Sakharov */ +#ifndef COFF_SPECS_H +#define COFF_SPECS_H + +#include + +#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 +#define IMAGE_SCN_CNT_CODE 0x00000020 +#define IMAGE_SCN_CNT_INIT_DATA 0x00000040 +#define IMAGE_SCN_LNK_OTHER 0x00000100 +#define IMAGE_SCN_LNK_INFO 0x00000200 +#define IMAGE_SCN_LNK_REMOVE 0x00000800 +#define IMAGE_SCN_LNK_COMDAT 0x00001000 +#define IMAGE_SCN_GPREL 0x00008000 +#define IMAGE_SCN_MEM_PURGEABLE 0x00010000 +#define IMAGE_SCN_MEM_16BIT 0x00020000 +#define IMAGE_SCN_MEM_LOCKED 0x00040000 +#define IMAGE_SCN_MEM_PRELOAD 0x00080000 +#define IMAGE_SCN_ALIGN_1BYTES 0x00100000 +#define IMAGE_SCN_ALIGN_2BYTES 0x00200000 +#define IMAGE_SCN_ALIGN_4BYTES 0x00300000 +#define IMAGE_SCN_ALIGN_8BYTES 0x00400000 +#define IMAGE_SCN_ALIGN_16BYTES 0x00500000 +#define IMAGE_SCN_ALIGN_32BYTES 0x00600000 +#define IMAGE_SCN_ALIGN_64BYTES 0x00700000 +#define IMAGE_SCN_ALIGN_128BYTES 0x00800000 +#define IMAGE_SCN_ALIGN_256BYTES 0x00900000 +#define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 +#define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 +#define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 +#define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 +#define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 +#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 +#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 +#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 +#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 +#define IMAGE_SCN_MEM_SHARED 0x10000000 +#define IMAGE_SCN_MEM_EXECUTE 0x20000000 +#define IMAGE_SCN_MEM_READ 0x40000000 +#define IMAGE_SCN_MEM_WRITE 0x80000000 + +#define IMAGE_SYM_TYPE_NULL 0 +#define IMAGE_SYM_TYPE_VOID 1 +#define IMAGE_SYM_TYPE_CHAR 2 +#define IMAGE_SYM_TYPE_SHORT 3 +#define IMAGE_SYM_TYPE_INT 4 +#define IMAGE_SYM_TYPE_LONG 5 +#define IMAGE_SYM_TYPE_FLOAT 6 +#define IMAGE_SYM_TYPE_DOUBLE 7 +#define IMAGE_SYM_TYPE_STRUCT 8 +#define IMAGE_SYM_TYPE_UNION 9 +#define IMAGE_SYM_TYPE_ENUM 10 +#define IMAGE_SYM_TYPE_MOE 11 +#define IMAGE_SYM_TYPE_BYTE 12 +#define IMAGE_SYM_TYPE_WORD 13 +#define IMAGE_SYM_TYPE_UINT 14 +#define IMAGE_SYM_TYPE_DWORD 15 + +#define IMAGE_SYM_DTYPE_NULL 0 +#define IMAGE_SYM_DTYPE_POINTER 1 +#define IMAGE_SYM_DTYPE_FUNCTION 2 +#define IMAGE_SYM_DTYPE_ARRAY 3 + +#define IMAGE_SYM_CLASS_END_OF_FUNCTION 0xFF +#define IMAGE_SYM_CLASS_NULL 0 +#define IMAGE_SYM_CLASS_AUTOMATIC 1 +#define IMAGE_SYM_CLASS_EXTERNAL 2 +#define IMAGE_SYM_CLASS_STATIC 3 +#define IMAGE_SYM_CLASS_REGISTER 4 +#define IMAGE_SYM_CLASS_EXTERNAL_DEF 5 +#define IMAGE_SYM_CLASS_LABEL 6 +#define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7 +#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8 +#define IMAGE_SYM_CLASS_ARGUMENT 9 +#define IMAGE_SYM_CLASS_STRUCT_TAG 10 +#define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11 +#define IMAGE_SYM_CLASS_UNION_TAG 12 +#define IMAGE_SYM_CLASS_TYPE_DEFINITION 13 +#define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14 +#define IMAGE_SYM_CLASS_ENUM_TAG 15 +#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16 +#define IMAGE_SYM_CLASS_REGISTER_PARAM 17 +#define IMAGE_SYM_CLASS_BIT_FIELD 18 +#define IMAGE_SYM_CLASS_BLOCK 100 +#define IMAGE_SYM_CLASS_FUNCTION 101 +#define IMAGE_SYM_CLASS_END_OF_STRUCT 102 +#define IMAGE_SYM_CLASS_FILE 103 +#define IMAGE_SYM_CLASS_SECTION 104 +#define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105 +#define IMAGE_SYM_CLASS_CLR_TOKEN 107 + +struct coff_hdr { + ut16 machine; + ut16 sections_num; + ut32 timestamp; + ut32 symtable_offset; + ut32 symbols_num; + ut16 opt_hdr_size; + ut16 flags; +}; + +struct coff_opt_hdr { + ut16 magic; + ut8 major_linker_version; + ut8 minor_linker_version; + ut32 size_of_code; + ut32 size_of_init_data; + ut32 size_of_uninit_data; + ut32 entry_point; + ut32 base_of_code; +}; + +#endif /* COFF_SPECS_H */ diff --git a/libr/bin/p/Makefile b/libr/bin/p/Makefile index 618c11c962de6..4f7d85449585b 100644 --- a/libr/bin/p/Makefile +++ b/libr/bin/p/Makefile @@ -9,7 +9,7 @@ foo: all ALL_TARGETS= FORMATS=any.mk elf.mk elf64.mk pe.mk pe64.mk te.mk mach0.mk FORMATS+=bios.mk mach064.mk fatmach0.mk dyldcache.mk java.mk -FORMATS+=dex.mk fs.mk ningb.mk +FORMATS+=dex.mk fs.mk ningb.mk coff.mk include $(FORMATS) all: ${ALL_TARGETS} diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c new file mode 100644 index 0000000000000..f05ece3ac0586 --- /dev/null +++ b/libr/bin/p/bin_coff.c @@ -0,0 +1,151 @@ +/* radare - LGPL - Copyright 2014 - Fedor Sakharov */ + +#include +#include +#include +#include + +#include "coff/coff.h" + +static int load(RBinFile *arch) +{ + if (!(arch->o->bin_obj = r_bin_coff_new_buf(arch->buf))) + return R_FALSE; + return R_TRUE; +} + +static int destroy(RBinFile *arch) +{ + r_bin_coff_free((struct r_bin_coff_obj*)arch->o->bin_obj); + return R_TRUE; +} + +static ut64 baddr(RBinFile *arch) +{ + return 0; +} + +static RBinAddr *binsym(RBinFile *arch, int sym) +{ + return NULL; +} + +static RList *entries(RBinFile *arch) +{ + return NULL; +} + +static RList *sections(RBinFile *arch) +{ + size_t i; + RList *ret = NULL; + RBinSection *ptr = NULL; + struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)(arch->o->bin_obj); + + ret = r_list_new(); + + if (!ret) + return NULL; + + for (i = 0; i < obj->hdr.sections_num; i++) { + ptr = R_NEW0 (RBinSection); + + strncpy(ptr->name, obj->scn_hdrs[i].name, R_BIN_SIZEOF_STRINGS); + + ptr->size = obj->scn_hdrs[i].raw_data_size; + ptr->vsize = obj->scn_hdrs[i].virtual_size; + ptr->offset = obj->scn_hdrs[i].raw_data_pointer; + ptr->rva = obj->scn_hdrs[i].virtual_addr; + + r_list_append (ret, ptr); + } + + return ret; +} + +static RList *symbols(RBinFile *arch) +{ + return NULL; +} + +static RList *imports(RBinFile *arch) +{ + return NULL; +} + +static RList *libs(RBinFile *arch) +{ + return NULL; +} + +static RList *relocs(RBinFile *arch) +{ + return NULL; +} + +static RBinInfo *info(RBinFile *arch) +{ + RBinInfo *ret = R_NEW0(RBinInfo); + return ret; +} + +static RList *fields(RBinFile *arch) +{ + return NULL; +} + +static RBuffer *create(RBin *bin, const ut8 *code, int codelen, + const ut8 *data, int datalen) +{ + return NULL; +} + +static int size(RBinFile *arch) +{ + return 0; +} + +static int check(RBinFile *arch) +{ + printf("check\n"); + if (arch && arch->buf && arch->buf->buf) { + if (coff_supported_arch(arch->buf->buf)) + return R_TRUE; + } + return R_TRUE; +} + +RBinPlugin r_bin_plugin_coff = { + .name = "coff", + .desc = "COFF format r_bin plugin", + .license = "LGPL3", + .init = NULL, + .fini = NULL, + .load = &load, + .destroy = &destroy, + .check = &check, + .baddr = &baddr, + .boffset = NULL, + .binsym = &binsym, + .entries = &entries, + .sections = §ions, + .symbols = &symbols, + .imports = &imports, + .strings = NULL, + .info = &info, + .fields = &fields, + .size = &size, + .libs = &libs, + .relocs = &relocs, + .meta = NULL, + .create = &create, + .write = NULL, + .get_vaddr = NULL, +}; + +#ifndef CORELIB +struct r_lib_struct_t radare_plugin = { + .type = R_LIB_TYPE_BIN, + .data = &r_bin_plugin_coff +}; +#endif diff --git a/libr/bin/p/coff.mk b/libr/bin/p/coff.mk new file mode 100644 index 0000000000000..3914508f55e94 --- /dev/null +++ b/libr/bin/p/coff.mk @@ -0,0 +1,10 @@ +OBJ_COFF=bin_coff.o +OBJ_COFF+=../format/coff/coff.o + +STATIC_OBJ+=${OBJ_COFF} +TARGET_COFF=bin_coff.${EXT_SO} + +ALL_TARGETS+=${TARGET_COFF} + +${TARGET_COFF}: ${OBJ_COFF} + ${CC} $(call libname,bin_coff) ${CFLAGS} $(LDFLAGS) ${OBJ_COFF} diff --git a/libr/include/r_bin.h b/libr/include/r_bin.h index 77ffca11c3b70..762d713a9237c 100644 --- a/libr/include/r_bin.h +++ b/libr/include/r_bin.h @@ -384,6 +384,7 @@ extern RBinPlugin r_bin_plugin_dex; extern RBinPlugin r_bin_plugin_dummy; extern RBinPlugin r_bin_plugin_rar; extern RBinPlugin r_bin_plugin_ningb; +extern RBinPlugin r_bin_plugin_coff; extern RBinXtrPlugin r_bin_xtr_plugin_fatmach0; extern RBinXtrPlugin r_bin_xtr_plugin_dyldcache; diff --git a/plugins.def.cfg b/plugins.def.cfg index bdfea0db81bf3..cab2b82fd447a 100644 --- a/plugins.def.cfg +++ b/plugins.def.cfg @@ -71,6 +71,7 @@ bin.pe bin.mz bin.pe64 bin.te +bin.coff bin.mach0 bin.mach064 bin.ningb From 906bb8b3ff19602a04cd090fa2263eae3710ca5a Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Tue, 18 Feb 2014 17:42:24 +0400 Subject: [PATCH 2/8] coff: Implement optional header, symbols and sections. --- libr/bin/format/coff/coff.c | 85 +++++++++++++++++++++++++++++++------ libr/bin/p/bin_coff.c | 55 ++++++++++++++++++++++-- 2 files changed, 123 insertions(+), 17 deletions(-) diff --git a/libr/bin/format/coff/coff.c b/libr/bin/format/coff/coff.c index 8dc2aea84235a..9433d6deeec43 100644 --- a/libr/bin/format/coff/coff.c +++ b/libr/bin/format/coff/coff.c @@ -28,15 +28,11 @@ static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) sizeof(ut16), obj->endian); offset += sizeof(ut16); - printf("machine 0x%x\n", obj->hdr.machine); - r_mem_copyendian((ut8*)&(obj->hdr.sections_num), obj->b->buf + offset, sizeof(ut16), obj->endian); offset += sizeof(ut16); - printf("sections num %x\n", obj->hdr.sections_num); - r_mem_copyendian((ut8*)&obj->hdr.timestamp, obj->b->buf + offset, sizeof(ut32), obj->endian); offset += sizeof(ut32); @@ -52,7 +48,6 @@ static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) r_mem_copyendian((ut8*)&(obj->hdr.opt_hdr_size), obj->b->buf + offset, sizeof(ut16), obj->endian); offset += sizeof(ut16); - printf("opt hdr size %u\n", obj->hdr.opt_hdr_size); r_mem_copyendian((ut8*)&(obj->hdr.flags), obj->b->buf + offset, sizeof(ut16), obj->endian); @@ -62,7 +57,49 @@ static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) static int r_bin_coff_init_opt_hdr(struct r_bin_coff_obj *obj) { - return R_TRUE; + size_t offset = 20; + + r_mem_copyendian((ut8*)&(obj->opt_hdr.magic), obj->b->buf + offset, + sizeof(ut16), obj->endian); + + offset += sizeof(ut16); + + r_mem_copyendian((ut8*)&(obj->opt_hdr.major_linker_version), + obj->b->buf + offset, sizeof(ut8), obj->endian); + + offset += sizeof(ut8); + + r_mem_copyendian((ut8*)&(obj->opt_hdr.minor_linker_version), + obj->b->buf + offset, sizeof(ut8), obj->endian); + + offset += sizeof(ut8); + + r_mem_copyendian((ut8*)&(obj->opt_hdr.size_of_code), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->opt_hdr.size_of_init_data), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->opt_hdr.size_of_uninit_data), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->opt_hdr.entry_point), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->opt_hdr.base_of_code), + obj->b->buf + offset, sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + return 0; } static int r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) @@ -74,7 +111,6 @@ static int r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) for (i = 0; i < obj->hdr.sections_num; i++) { strncpy(obj->scn_hdrs[i].name, (char*)(obj->b->buf + offset), 8); - printf("section name %s\n", obj->scn_hdrs[i].name); offset += 8; r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].virtual_size), @@ -85,8 +121,6 @@ static int r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].virtual_addr), obj->b->buf + offset, sizeof(ut32), obj->endian); - printf("virtial addr %x\n", obj->scn_hdrs[i].virtual_addr); - offset += sizeof(ut32); r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].raw_data_size), @@ -97,8 +131,6 @@ static int r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].raw_data_pointer), obj->b->buf + offset, sizeof(ut32), obj->endian); - printf("raw_data_pointer %x\n", obj->scn_hdrs[i].raw_data_pointer); - offset += sizeof(ut32); r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].reloc_pointer), @@ -159,8 +191,35 @@ static int r_bin_coff_init_symtable(struct r_bin_coff_obj *obj) offset += sizeof(ut32); } - offset += 10; -// printf ("symbol %s\n", obj->symbols[i].name); + r_mem_copyendian((ut8*)&(obj->symbols[i].value), + obj->b->buf + offset, + sizeof(ut32), obj->endian); + + offset += sizeof(ut32); + + r_mem_copyendian((ut8*)&(obj->symbols[i].scn_num), + obj->b->buf + offset, + sizeof(ut16), obj->endian); + + offset += sizeof(ut16); + + r_mem_copyendian((ut8*)&(obj->symbols[i].type), + obj->b->buf + offset, + sizeof(ut16), obj->endian); + + offset += sizeof(ut16); + + r_mem_copyendian((ut8*)&(obj->symbols[i].storage_class), + obj->b->buf + offset, + sizeof(ut8), obj->endian); + + offset += sizeof(ut8); + + r_mem_copyendian((ut8*)&(obj->symbols[i].aux_sym_num), + obj->b->buf + offset, + sizeof(ut8), obj->endian); + + offset += sizeof(ut8); } } diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index f05ece3ac0586..a3dc5977b8315 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -32,7 +32,25 @@ static RBinAddr *binsym(RBinFile *arch, int sym) static RList *entries(RBinFile *arch) { - return NULL; + RList *ret; + RBinAddr *ptr = NULL; + struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)arch->o->bin_obj; + + if (!(ret = r_list_new ())) + return NULL; + + ret->free = free; + + if (!(ptr = R_NEW (RBinAddr))) + return ret; + + memset (ptr, '\0', sizeof (RBinAddr)); + + ptr->offset = ptr->rva = obj->opt_hdr.entry_point; + + r_list_append(ret, ptr); + + return ret; } static RList *sections(RBinFile *arch) @@ -40,7 +58,7 @@ static RList *sections(RBinFile *arch) size_t i; RList *ret = NULL; RBinSection *ptr = NULL; - struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)(arch->o->bin_obj); + struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)arch->o->bin_obj; ret = r_list_new(); @@ -65,7 +83,36 @@ static RList *sections(RBinFile *arch) static RList *symbols(RBinFile *arch) { - return NULL; + size_t i; + RList *ret = NULL; + RBinSymbol *ptr = NULL; + + struct r_bin_coff_obj *obj= (struct r_bin_coff_obj*)arch->o->bin_obj; + + if (!(ret = r_list_new())) + return ret; + + ret->free = free; + + for (i = 0; i < obj->hdr.symbols_num; i++) { + if (!(ptr = R_NEW0 (RBinSymbol))) + break; + + strncpy (ptr->name, obj->symbols[i].name, + R_BIN_SIZEOF_STRINGS); + strncpy (ptr->forwarder, "NONE", + R_BIN_SIZEOF_STRINGS); + strncpy (ptr->bind, "", R_BIN_SIZEOF_STRINGS); + strncpy (ptr->type, "UNKNOWN", R_BIN_SIZEOF_STRINGS); + ptr->rva = obj->symbols[i].value; + ptr->offset = obj->symbols[i].value; + ptr->size = 0; + ptr->ordinal = 0; + + r_list_append (ret, ptr); + } + + return ret; } static RList *imports(RBinFile *arch) @@ -86,6 +133,7 @@ static RList *relocs(RBinFile *arch) static RBinInfo *info(RBinFile *arch) { RBinInfo *ret = R_NEW0(RBinInfo); + ret->has_va = 1; return ret; } @@ -107,7 +155,6 @@ static int size(RBinFile *arch) static int check(RBinFile *arch) { - printf("check\n"); if (arch && arch->buf && arch->buf->buf) { if (coff_supported_arch(arch->buf->buf)) return R_TRUE; From ead69073ed2ea4a4479d886cbab2a43093cf7f82 Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Tue, 18 Feb 2014 20:08:55 +0400 Subject: [PATCH 3/8] coff: Small fixups and coff bin object free implementation. --- libr/bin/format/coff/coff.c | 9 +++++++++ libr/bin/format/coff/coff.h | 1 + libr/bin/p/bin_coff.c | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/libr/bin/format/coff/coff.c b/libr/bin/format/coff/coff.c index 9433d6deeec43..05caa372f1960 100644 --- a/libr/bin/format/coff/coff.c +++ b/libr/bin/format/coff/coff.c @@ -221,6 +221,8 @@ static int r_bin_coff_init_symtable(struct r_bin_coff_obj *obj) offset += sizeof(ut8); } + + return 0; } static int r_bin_coff_init(struct r_bin_coff_obj *obj, struct r_buf_t *buf) @@ -239,6 +241,13 @@ static int r_bin_coff_init(struct r_bin_coff_obj *obj, struct r_buf_t *buf) void r_bin_coff_free(struct r_bin_coff_obj *obj) { + if (obj->scn_hdrs) + free(obj->scn_hdrs); + + if (obj->symbols) + free(obj->symbols); + + free(obj); } struct r_bin_coff_obj* r_bin_coff_new_buf(struct r_buf_t *buf) diff --git a/libr/bin/format/coff/coff.h b/libr/bin/format/coff/coff.h index b498b1f91c910..151939af22957 100644 --- a/libr/bin/format/coff/coff.h +++ b/libr/bin/format/coff/coff.h @@ -43,5 +43,6 @@ struct r_bin_coff_obj { int coff_supported_arch(const ut8 *buf); struct r_bin_coff_obj* r_bin_coff_new_buf(struct r_buf_t *buf); +void r_bin_coff_free(struct r_bin_coff_obj *obj); #endif /* COFF_H */ diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index a3dc5977b8315..91fe2e5e20f35 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -110,6 +110,8 @@ static RList *symbols(RBinFile *arch) ptr->ordinal = 0; r_list_append (ret, ptr); + + i += obj->symbols[i].aux_sym_num; } return ret; @@ -134,6 +136,13 @@ static RBinInfo *info(RBinFile *arch) { RBinInfo *ret = R_NEW0(RBinInfo); ret->has_va = 1; + struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)arch->o->bin_obj; + + strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS); + strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS); + ret->big_endian = obj->endian; + ret->dbg_info = 0; + return ret; } From 7da39c208ef1bff41e1b234058acc10b67c73fbb Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Tue, 18 Feb 2014 20:59:33 +0400 Subject: [PATCH 4/8] coff: Try to detect coff. Only h8300 now. --- libr/bin/format/coff/coff.c | 4 ++-- libr/bin/format/coff/coff_specs.h | 24 ++++++++++++++++++++++++ libr/bin/p/bin_coff.c | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/libr/bin/format/coff/coff.c b/libr/bin/format/coff/coff.c index 05caa372f1960..9fec28dba550a 100644 --- a/libr/bin/format/coff/coff.c +++ b/libr/bin/format/coff/coff.c @@ -8,14 +8,14 @@ int coff_supported_arch(const ut8 *buf) int ret; switch (arch) { - case 0x8300: + case IMAGE_FILE_MACHINE_H8300: ret = R_TRUE; break; default: ret = R_FALSE; } - return R_TRUE; + return ret; } static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) diff --git a/libr/bin/format/coff/coff_specs.h b/libr/bin/format/coff/coff_specs.h index 943653e03b344..77c007581e178 100644 --- a/libr/bin/format/coff/coff_specs.h +++ b/libr/bin/format/coff/coff_specs.h @@ -4,6 +4,30 @@ #include +#define IMAGE_FILE_MACHINE_UNKNOWN 0x0 +#define IMAGE_FILE_MACHINE_AM33 0x1d3 +#define IMAGE_FILE_MACHINE_AMD64 0x8664 +#define IMAGE_FILE_MACHINE_ARM 0x1c0 +#define IMAGE_FILE_MACHINE_ARMNT 0x1c4 +#define IMAGE_FILE_MACHINE_ARM64 0xaa64 +#define IMAGE_FILE_MACHINE_EBC 0xebc +#define IMAGE_FILE_MACHINE_I386 0x14c +#define IMAGE_FILE_MACHINE_IA64 0x200 +#define IMAGE_FILE_MACHINE_M32R 0x9041 +#define IMAGE_FILE_MACHINE_MIPS16 0x266 +#define IMAGE_FILE_MACHINE_MIPSFPU 0x366 +#define IMAGE_FILE_MACHINE_MIPSFPU16 0x466 +#define IMAGE_FILE_MACHINE_POWERPC 0x1f0 +#define IMAGE_FILE_MACHINE_POWERPCFP 0x1f1 +#define IMAGE_FILE_MACHINE_R4000 0x166 +#define IMAGE_FILE_MACHINE_SH3 0x1a2 +#define IMAGE_FILE_MACHINE_SH3DSP 0x1a3 +#define IMAGE_FILE_MACHINE_SH4 0x1a6 +#define IMAGE_FILE_MACHINE_SH5 0x1a8 +#define IMAGE_FILE_MACHINE_THUMB 0x1c2 +#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x169 +#define IMAGE_FILE_MACHINE_H8300 0x0083 + #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 #define IMAGE_SCN_CNT_CODE 0x00000020 #define IMAGE_SCN_CNT_INIT_DATA 0x00000040 diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index 91fe2e5e20f35..3913b20a97e5c 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -168,7 +168,7 @@ static int check(RBinFile *arch) if (coff_supported_arch(arch->buf->buf)) return R_TRUE; } - return R_TRUE; + return R_FALSE; } RBinPlugin r_bin_plugin_coff = { From 35e84450a318ca74722311971c55e844bca619cc Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Wed, 19 Feb 2014 21:10:20 +0400 Subject: [PATCH 5/8] Adds some fixes to support x86, amd64 and h8000 together. --- libr/bin/format/coff/coff.c | 18 +++++++++++++++--- libr/bin/p/bin_coff.c | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libr/bin/format/coff/coff.c b/libr/bin/format/coff/coff.c index 9fec28dba550a..ae581c3989347 100644 --- a/libr/bin/format/coff/coff.c +++ b/libr/bin/format/coff/coff.c @@ -8,6 +8,8 @@ int coff_supported_arch(const ut8 *buf) int ret; switch (arch) { + case IMAGE_FILE_MACHINE_AMD64: + case IMAGE_FILE_MACHINE_I386: case IMAGE_FILE_MACHINE_H8300: ret = R_TRUE; break; @@ -22,10 +24,17 @@ static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) { size_t offset = 0; - obj->endian = !LIL_ENDIAN; - r_mem_copyendian((ut8*)&(obj->hdr.machine), obj->b->buf, - sizeof(ut16), obj->endian); + obj->hdr.machine = *(ut16*)obj->b->buf; + + switch(obj->hdr.machine) { + case IMAGE_FILE_MACHINE_H8300: + obj->endian = !LIL_ENDIAN; + break; + default: + obj->endian = LIL_ENDIAN; + } + offset += sizeof(ut16); r_mem_copyendian((ut8*)&(obj->hdr.sections_num), obj->b->buf + offset, @@ -59,6 +68,9 @@ static int r_bin_coff_init_opt_hdr(struct r_bin_coff_obj *obj) { size_t offset = 20; + if (obj->hdr.opt_hdr_size == 0) + return 0; + r_mem_copyendian((ut8*)&(obj->opt_hdr.magic), obj->b->buf + offset, sizeof(ut16), obj->endian); diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index 3913b20a97e5c..22f336e4a1d57 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -143,6 +143,27 @@ static RBinInfo *info(RBinFile *arch) ret->big_endian = obj->endian; ret->dbg_info = 0; + switch (obj->hdr.machine) { + case IMAGE_FILE_MACHINE_I386: + strncpy(ret->machine, "i386", R_BIN_SIZEOF_STRINGS); + strncpy(ret->arch, "x86", R_BIN_SIZEOF_STRINGS); + ret->bits = 32; + break; + case IMAGE_FILE_MACHINE_AMD64: + strncpy(ret->machine, "AMD 64", R_BIN_SIZEOF_STRINGS); + strncpy(ret->arch, "x86", R_BIN_SIZEOF_STRINGS); + ret->bits = 64; + break; + case IMAGE_FILE_MACHINE_H8300: + strncpy(ret->machine, "H8300", R_BIN_SIZEOF_STRINGS); + strncpy(ret->arch, "h8300", R_BIN_SIZEOF_STRINGS); + ret->bits = 16; + break; + default: + + strncpy(ret->machine, "unknown", R_BIN_SIZEOF_STRINGS); + } + return ret; } From 1dafb6b029a3406683bc211870e4fbfb9a15d52a Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Thu, 20 Feb 2014 12:34:09 +0400 Subject: [PATCH 6/8] coff: Use beginning of .text section if no entry point specified. --- libr/bin/p/bin_coff.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index 22f336e4a1d57..447f9b99a0700 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -32,6 +32,7 @@ static RBinAddr *binsym(RBinFile *arch, int sym) static RList *entries(RBinFile *arch) { + size_t i; RList *ret; RBinAddr *ptr = NULL; struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)arch->o->bin_obj; @@ -46,7 +47,19 @@ static RList *entries(RBinFile *arch) memset (ptr, '\0', sizeof (RBinAddr)); - ptr->offset = ptr->rva = obj->opt_hdr.entry_point; + if (obj->hdr.opt_hdr_size) { + ptr->offset = ptr->rva = obj->opt_hdr.entry_point; + } else { + for (i = 0; i < obj->hdr.sections_num; i++) { + if (!strcmp(obj->scn_hdrs[i].name, ".text")) { + ptr->offset = obj->scn_hdrs[i].virtual_addr; + ptr->rva = obj->scn_hdrs[i].virtual_addr; + break; + } + } + } + + printf("offset %x rva %x\n", ptr->offset, ptr->rva); r_list_append(ret, ptr); @@ -160,7 +173,6 @@ static RBinInfo *info(RBinFile *arch) ret->bits = 16; break; default: - strncpy(ret->machine, "unknown", R_BIN_SIZEOF_STRINGS); } From d31c3623cce3167b1d57838278c71fe9e212c0fd Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Thu, 20 Feb 2014 13:37:51 +0400 Subject: [PATCH 7/8] coff: Let's support TI coff and tms320 files. --- libr/bin/format/coff/coff.c | 15 ++++++++++++++- libr/bin/format/coff/coff_specs.h | 17 +++++++++++++++++ libr/bin/p/bin_coff.c | 16 ++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libr/bin/format/coff/coff.c b/libr/bin/format/coff/coff.c index ae581c3989347..9d6b829d8d319 100644 --- a/libr/bin/format/coff/coff.c +++ b/libr/bin/format/coff/coff.c @@ -11,6 +11,7 @@ int coff_supported_arch(const ut8 *buf) case IMAGE_FILE_MACHINE_AMD64: case IMAGE_FILE_MACHINE_I386: case IMAGE_FILE_MACHINE_H8300: + case IMAGE_FILE_TI_COFF: ret = R_TRUE; break; default: @@ -24,7 +25,6 @@ static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) { size_t offset = 0; - obj->hdr.machine = *(ut16*)obj->b->buf; switch(obj->hdr.machine) { @@ -61,6 +61,15 @@ static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) r_mem_copyendian((ut8*)&(obj->hdr.flags), obj->b->buf + offset, sizeof(ut16), obj->endian); + offset += sizeof(ut16); + + if (obj->hdr.machine == IMAGE_FILE_TI_COFF) { + r_mem_copyendian((ut8*)&(obj->hdr.target_id), obj->b->buf + offset, + sizeof(ut16), obj->endian); + + printf("%x\n", obj->hdr.target_id); + } + return R_TRUE; } @@ -118,6 +127,10 @@ static int r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) { size_t i, offset = obj->hdr.opt_hdr_size + 20; + if (obj->hdr.machine == IMAGE_FILE_TI_COFF) { + offset += 2; + } + obj->scn_hdrs = calloc(obj->hdr.sections_num, sizeof(struct coff_scn_hdr)); diff --git a/libr/bin/format/coff/coff_specs.h b/libr/bin/format/coff/coff_specs.h index 77c007581e178..efd54804b1e1d 100644 --- a/libr/bin/format/coff/coff_specs.h +++ b/libr/bin/format/coff/coff_specs.h @@ -28,6 +28,22 @@ #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x169 #define IMAGE_FILE_MACHINE_H8300 0x0083 +#define IMAGE_FILE_TI_COFF 0xc1 +#define IMAGE_FILE_MACHINE_TMS470 0x0097 +#define IMAGE_FILE_MACHINE_TMS320C54 0x0098 +#define IMAGE_FILE_MACHINE_TMS320C60 0x0099 +#define IMAGE_FILE_MACHINE_TMS320C55 0x009C +#define IMAGE_FILE_MACHINE_TMS320C28 0x009D +#define IMAGE_FILE_MACHINE_MSP430 0x00A0 +#define IMAGE_FILE_MACHINE_TMS320C55PLUS 0x00A1 + +#define IMAGE_FLAGS_TI_F_RELFLG 0x0001 +#define IMAGE_FLAGS_TI_F_EXEC 0x0002 +#define IMAGE_FLAGS_TI_F_LNNO 0x0004 +#define IMAGE_FLAGS_TI_F_LSYMS 0x0008 +#define IMAGE_FLAGS_TI_F_BIG 0x0200 +#define IMAGE_FLAGS_TI_F_LITTLE 0x0100 + #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 #define IMAGE_SCN_CNT_CODE 0x00000020 #define IMAGE_SCN_CNT_INIT_DATA 0x00000040 @@ -121,6 +137,7 @@ struct coff_hdr { ut32 symbols_num; ut16 opt_hdr_size; ut16 flags; + ut16 target_id; // TI COFF specific }; struct coff_opt_hdr { diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index 447f9b99a0700..1ca0b2ec3dbfc 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -172,6 +172,22 @@ static RBinInfo *info(RBinFile *arch) strncpy(ret->arch, "h8300", R_BIN_SIZEOF_STRINGS); ret->bits = 16; break; + + case IMAGE_FILE_TI_COFF: + if (obj->hdr.target_id == IMAGE_FILE_MACHINE_TMS320C54) { + strncpy(ret->machine, "c54x", R_BIN_SIZEOF_STRINGS); + strncpy(ret->arch, "tms320", R_BIN_SIZEOF_STRINGS); + ret->bits = 32; + } else if (obj->hdr.target_id == IMAGE_FILE_MACHINE_TMS320C55) { + strncpy(ret->machine, "c55x", R_BIN_SIZEOF_STRINGS); + strncpy(ret->arch, "tms320", R_BIN_SIZEOF_STRINGS); + ret->bits = 32; + } else if (obj->hdr.target_id == IMAGE_FILE_MACHINE_TMS320C55PLUS) { + strncpy(ret->machine, "c55x+", R_BIN_SIZEOF_STRINGS); + strncpy(ret->arch, "tms320", R_BIN_SIZEOF_STRINGS); + ret->bits = 32; + } + break; default: strncpy(ret->machine, "unknown", R_BIN_SIZEOF_STRINGS); } From dff9e0d4205f6fee2b7ef26d6dce940a2ffbe4ec Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Thu, 20 Feb 2014 14:01:49 +0400 Subject: [PATCH 8/8] coff: Remove debug prints. --- libr/bin/format/coff/coff.c | 6 ++++-- libr/bin/p/bin_coff.c | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libr/bin/format/coff/coff.c b/libr/bin/format/coff/coff.c index 9d6b829d8d319..1304797d25b92 100644 --- a/libr/bin/format/coff/coff.c +++ b/libr/bin/format/coff/coff.c @@ -61,13 +61,14 @@ static int r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) r_mem_copyendian((ut8*)&(obj->hdr.flags), obj->b->buf + offset, sizeof(ut16), obj->endian); + if (obj->hdr.flags & IMAGE_FLAGS_TI_F_LITTLE) { + obj->endian = LIL_ENDIAN; + } offset += sizeof(ut16); if (obj->hdr.machine == IMAGE_FILE_TI_COFF) { r_mem_copyendian((ut8*)&(obj->hdr.target_id), obj->b->buf + offset, sizeof(ut16), obj->endian); - - printf("%x\n", obj->hdr.target_id); } return R_TRUE; @@ -181,6 +182,7 @@ static int r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) r_mem_copyendian((ut8*)&(obj->scn_hdrs[i].flags), obj->b->buf + offset, sizeof(ut32), obj->endian); + offset += sizeof(ut32); } diff --git a/libr/bin/p/bin_coff.c b/libr/bin/p/bin_coff.c index 1ca0b2ec3dbfc..bd68fa126a0c7 100644 --- a/libr/bin/p/bin_coff.c +++ b/libr/bin/p/bin_coff.c @@ -59,8 +59,6 @@ static RList *entries(RBinFile *arch) } } - printf("offset %x rva %x\n", ptr->offset, ptr->rva); - r_list_append(ret, ptr); return ret;