Honor bin.verbose in COFF too

This commit is contained in:
pancake 2017-01-22 10:27:48 +01:00
parent a1a1e059dc
commit 65cdab1746
5 changed files with 30 additions and 30 deletions

View File

@ -1,9 +1,11 @@
/* radare - LGPL - Copyright 2008-2016 pancake, inisider */
/* radare - LGPL - Copyright 2008-2017 pancake, inisider */
#include <r_util.h>
#include "coff.h"
#define bprintf if(obj->verbose)eprintf
bool r_coff_supported_arch(const ut8 *buf) {
ut16 arch = *(ut16*)buf;
switch (arch) {
@ -179,24 +181,25 @@ static bool r_bin_coff_init_symtable(struct r_bin_coff_obj *obj) {
return true;
}
static int r_bin_coff_init(struct r_bin_coff_obj *obj, RBuffer *buf) {
static int r_bin_coff_init(struct r_bin_coff_obj *obj, RBuffer *buf, bool verbose) {
obj->b = r_buf_new ();
obj->size = buf->length;
obj->verbose = verbose;
if (!r_buf_set_bytes (obj->b, buf->buf, obj->size)){
r_buf_free (obj->b);
return false;
}
if (!r_bin_coff_init_hdr (obj)) {
eprintf ("Warning: failed to init hdr\n");
bprintf ("Warning: failed to init hdr\n");
return false;
}
r_bin_coff_init_opt_hdr (obj);
if (!r_bin_coff_init_scn_hdr (obj)) {
eprintf ("Warning: failed to init section header\n");
bprintf ("Warning: failed to init section header\n");
return false;
}
if (!r_bin_coff_init_symtable (obj)) {
eprintf ("Warning: failed to init symtable\n");
bprintf ("Warning: failed to init symtable\n");
return false;
}
return true;
@ -208,8 +211,8 @@ void r_bin_coff_free(struct r_bin_coff_obj *obj) {
R_FREE (obj);
}
struct r_bin_coff_obj* r_bin_coff_new_buf(struct r_buf_t *buf) {
struct r_bin_coff_obj* r_bin_coff_new_buf(RBuffer *buf, bool verbose) {
struct r_bin_coff_obj* bin = R_NEW0 (struct r_bin_coff_obj);
r_bin_coff_init (bin, buf);
r_bin_coff_init (bin, buf, verbose);
return bin;
}

View File

@ -22,10 +22,11 @@ struct r_bin_coff_obj {
size_t size;
ut8 endian;
Sdb *kv;
bool verbose;
};
bool r_coff_supported_arch(const ut8 *buf); /* Reads two bytes from buf. */
struct r_bin_coff_obj* r_bin_coff_new_buf(struct r_buf_t *buf);
struct r_bin_coff_obj* r_bin_coff_new_buf(RBuffer *buf, bool verbose);
void r_bin_coff_free(struct r_bin_coff_obj *obj);
RBinAddr *r_coff_get_entry(struct r_bin_coff_obj *obj);
char *r_coff_symbol_name (struct r_bin_coff_obj *obj, void *ptr);

View File

@ -14,12 +14,12 @@ static int is_valid_omf_type(ut8 type) {
OMF_COMDAT, OMF_COMDAT32, OMF_LINSYM, OMF_LINSYM32,
OMF_ALIAS, OMF_NBKPAT, OMF_NBKPAT32, OMF_LLNAMES, OMF_VERNUM,
OMF_VENDEXT, 0};
for (; types[ct]; ct++)
if (type == types[ct])
for (; types[ct]; ct++) {
if (type == types[ct]) {
return true;
eprintf ("Invalid record type\n");
}
}
// eprintf ("Invalid record type\n");
return false;
}
@ -48,19 +48,17 @@ int r_bin_checksum_omf_ok(const char *buf, ut64 buf_size) {
}
checksum += buf[size - 1];
}
if (checksum)
eprintf ("Invalid record checksum\n");
if (checksum) {
// eprintf ("Invalid record checksum\n");
}
return !checksum ? true : false;
}
static ut16 omf_get_idx(const char *buf) {
ut16 idx;
if (*buf & 0x80)
idx = (*buf & 0x7f) * 0x100 + buf[1];
else idx = *buf;
return idx;
if (*buf & 0x80) {
return (ut16)((*buf & 0x7f) * 0x100 + buf[1]);
}
return *buf;
}
static void free_lname(OMF_multi_datas *lname) {

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2014-2016 - Fedor Sakharov */
/* radare - LGPL - Copyright 2014-2017 - Fedor Sakharov */
#include <r_types.h>
#include <r_util.h>
@ -22,15 +22,12 @@ static Sdb* get_sdb(RBinObject *o) {
}
static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb) {
void *res = NULL;
RBuffer *tbuf = NULL;
if (!buf || !sz || sz == UT64_MAX) {
return NULL;
}
tbuf = r_buf_new();
RBuffer *tbuf = r_buf_new();
r_buf_set_bytes (tbuf, buf, sz);
res = r_bin_coff_new_buf(tbuf);
void *res = r_bin_coff_new_buf (tbuf, arch->rbin->verbose);
r_buf_free (tbuf);
return res;
}
@ -59,7 +56,6 @@ static RBinAddr *binsym(RBinFile *arch, int sym) {
return NULL;
}
static bool _fill_bin_symbol(struct r_bin_coff_obj *bin, int idx, RBinSymbol **sym) {
RBinSymbol *ptr = *sym;
char * coffname = NULL;

View File

@ -24,7 +24,9 @@ static int check_bytes(const ut8 *buf, ut64 length) {
rc = !memcmp (buf, "\x64\x79\x6c\x64", 4);
if (rc) {
dyld64 = strstr (arch, "64") != NULL;
eprintf ("Arch: %s\n", arch);
if (arch && *arch) {
eprintf ("Arch: %s\n", arch);
}
}
}
return rc;