Refixes for omf

This commit is contained in:
pancake 2018-07-16 17:22:16 +02:00
parent b3d0224071
commit a59bbbb50e
3 changed files with 15 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2015-2018 nodepad, pancake */
/* radare - LGPL - Copyright 2015-2016 nodepad, pancake */
#include "mz.h"
#include <btree.h>
@ -16,7 +16,7 @@ int r_bin_mz_get_entrypoint (const struct r_bin_mz_obj_t *bin) {
/* Value of CS in DOS header may be negative */
const short cs = bin->dos_header->cs;
ut32 pa = bin->dos_header->header_paragraphs + cs;
const ut32 paddr = (pa << 4) + bin->dos_header->ip;
const ut32 paddr = (pa<<4) + bin->dos_header->ip;
if (paddr < bin->dos_file_size) {
return paddr;
}
@ -25,7 +25,7 @@ int r_bin_mz_get_entrypoint (const struct r_bin_mz_obj_t *bin) {
// This function reads from the file buffer,
// thus using endian-agnostic functions
static int cmp_segs(const void *a, const void *b) {
int cmp_segs(const void *a, const void *b) {
const ut16 * const ma = (const ut16 * const)a;
const ut16 * const mb = (const ut16 * const)b;
if (!ma || !mb) {
@ -40,7 +40,7 @@ static void trv_segs (const void *seg, const void *segs) {
const ut8 * const mseg = (const ut8 * const)seg;
ut16 ** const msegs = (ut16 **)segs;
if (mseg && msegs && *msegs) {
r_write_le16 (*msegs, r_read_le16 (mseg));
r_write_le16(*msegs, r_read_le16(mseg));
*msegs = *msegs + 1;
}
}
@ -72,28 +72,25 @@ struct r_bin_mz_segment_t * r_bin_mz_get_segments(const struct r_bin_mz_obj_t *b
#if 1
struct btree_node *tree;
struct r_bin_mz_segment_t *ret;
// ut16 *segments,
int i, num_segs;
ut64 paddr;
const ut16 first_segment = 0;
const ut16 stack_segment = bin->dos_header->ss;
const MZ_image_relocation_entry * const relocs = bin->relocation_entries;
int num_relocs = bin->dos_header->num_relocs;
const int num_relocs = bin->dos_header->num_relocs;
const ut64 last_parag = ((bin->dos_file_size + 0xF) >> 4) - \
bin->dos_header->header_paragraphs;
btree_init (&tree);
for (i = 0; i < num_relocs; i++) {
ut64 paddr = r_bin_mz_seg_to_paddr (bin, relocs[i].segment) + relocs[i].offset;
paddr = r_bin_mz_seg_to_paddr (bin, relocs[i].segment) + relocs[i].offset;
if ((paddr + 2) < bin->dos_file_size) {
int left = 0;
ut8 *bb = r_buf_get_at (bin->b, paddr, &left);
int left;
ut16 *curr_seg = r_buf_get_at (bin->b, paddr, &left);
/* Add segment only if it's located inside dos executable data */
if (left > 4 && r_read_le16 (bb) <= last_parag) {
int le = r_read_le16 (bb);
btree_add (&tree, bb, cmp_segs);
} else {
num_relocs = i;
break;
if (left >= 2 && r_read_le16 (curr_seg) <= last_parag) {
btree_add (&tree, curr_seg, cmp_segs);
}
}
}

View File

@ -1,5 +1,3 @@
/* radare2 - LGPL - Copyright 2009-2018 - pancake, ampotos */
#include "omf.h"
static int is_valid_omf_type(ut8 type) {
@ -33,7 +31,7 @@ int r_bin_checksum_omf_ok(const char *buf, ut64 buf_size) {
return false;
}
size = ut8p_bw (buf + 1);
if (size + 3 >= buf_size) {
if (buf_size < size + 3) {
eprintf ("Invalid record (too short)\n");
return false;
}

View File

@ -1999,8 +1999,8 @@ static int bin_symbols_internal(RCore *r, int mode, ut64 laddr, int va, ut64 at,
}
}
} else {
const char *bind = r_str_get (symbol->bind);
const char *type = r_str_get (symbol->type);
const char *bind = symbol->bind? symbol->bind: "NONE";
const char *type = symbol->type? symbol->type: "NONE";
const char *name = r_str_get (sn.demname? sn.demname: symbol->name);
// const char *fwd = r_str_get (symbol->forwarder);
r_cons_printf ("%03u 0x%08"PFMT64x" 0x%08"PFMT64x" "
@ -2008,10 +2008,6 @@ static int bin_symbols_internal(RCore *r, int mode, ut64 laddr, int va, ut64 at,
symbol->ordinal,
symbol->paddr, addr, bind, type,
symbol->size, *name? " ": "", name);
// r_cons_printf ("vaddr=0x%08"PFMT64x" paddr=0x%08"PFMT64x" ord=%03u "
// "fwd=%s sz=%u bind=%s type=%s name=%s\n",
// addr, symbol->paddr, symbol->ordinal, fwd,
// symbol->size, bind, type, name);
}
snFini (&sn);
i++;
@ -2047,11 +2043,6 @@ static int bin_symbols_internal(RCore *r, int mode, ut64 laddr, int va, ut64 at,
if (IS_MODE_JSON (mode) && !printHere) {
r_cons_printf ("]");
}
#if 0
if (IS_MODE_NORMAL (mode) && !at) {
r_cons_printf ("\n%i %s\n", i, exponly ? "exports" : "symbols");
}
#endif
r_space_set (&r->anal->meta_spaces, NULL);
return true;