diff --git a/librz/bin/format/ne/ne.c b/librz/bin/format/ne/ne.c index d6ece2314a5..ee00e54d063 100644 --- a/librz/bin/format/ne/ne.c +++ b/librz/bin/format/ne/ne.c @@ -118,6 +118,46 @@ static void ne_sanitize_name(char *name, ut16 count) { } } +static const char *get_reloc_type_name(const ut8 src_type, const ut8 flag) { +#define CONCAT_RELOC_STR(a, b) a b +#define NE_RELOC_TARGET_TYPE(src_type_name, flag) \ + switch (flag) { \ + case INTERNAL_REF: \ + return CONCAT_RELOC_STR(src_type_name, "_INTERNAL_REF"); \ + case IMPORTED_ORD: \ + return CONCAT_RELOC_STR(src_type_name, "_IMPORTED_ORD"); \ + case IMPORTED_NAME: \ + return CONCAT_RELOC_STR(src_type_name, "_IMPORTED_NAME"); \ + case OSFIXUP: \ + return CONCAT_RELOC_STR(src_type_name, "_OSFIXUP"); \ + case ADDITIVE: \ + return CONCAT_RELOC_STR(src_type_name, "_ADDITIVE"); \ + default: \ + RZ_LOG_ERROR("Unknown NE relocation target flag %d\n", flag); \ + return CONCAT_RELOC_STR(src_type_name, "_UNKNOWN"); \ + } + + switch (src_type) { + case LOBYTE: + NE_RELOC_TARGET_TYPE("LOBYTE", flag); + case SEL_16: + NE_RELOC_TARGET_TYPE("SEL_16", flag); + case POI_32: + NE_RELOC_TARGET_TYPE("POI_32", flag); + case OFF_16: + NE_RELOC_TARGET_TYPE("OFF_16", flag); + case POI_48: + NE_RELOC_TARGET_TYPE("POI_48", flag); + case OFF_32: + NE_RELOC_TARGET_TYPE("OFF_32", flag); + default: + RZ_LOG_ERROR("Unknown NE relocation source type %d\n", flag); + NE_RELOC_TARGET_TYPE("UNKNOWN", flag); + } +#undef NE_RELOC_TARGET_TYPE +#undef CONCAT_RELOC_STR +} + RzPVector /**/ *rz_bin_ne_get_symbols(rz_bin_ne_obj_t *bin) { RzBinSymbol *sym; ut16 off = bin->ne_header->ResidNamTable + bin->header_offset; @@ -537,22 +577,7 @@ RzPVector /**/ *rz_bin_ne_get_relocs(rz_bin_ne_obj_t *bin) { rz_buf_read_le16_offset(bin->buf, &offset, &rel.align1); rz_buf_read_le16_offset(bin->buf, &offset, &rel.func_ord); reloc->paddr = seg->paddr + rel.offset; - switch (rel.type) { - case LOBYTE: - reloc->type = RZ_BIN_RELOC_8; - break; - case SEL_16: - case OFF_16: - reloc->type = RZ_BIN_RELOC_16; - break; - case POI_32: - case OFF_32: - reloc->type = RZ_BIN_RELOC_32; - break; - case POI_48: - reloc->type = RZ_BIN_RELOC_64; - break; - } + reloc->print_name = get_reloc_type_name(rel.type & NE_RELOC_SRC_MASK, rel.flags & NE_RELOC_TARGET_MASK); if (rel.flags & (IMPORTED_ORD | IMPORTED_NAME)) { RzBinImport *imp = RZ_NEW0(RzBinImport); diff --git a/librz/bin/format/ne/ne_specs.h b/librz/bin/format/ne/ne_specs.h index 96e68c61229..a3548fe5fe3 100644 --- a/librz/bin/format/ne/ne_specs.h +++ b/librz/bin/format/ne/ne_specs.h @@ -4,6 +4,9 @@ #ifndef NE_SPECS_H #define NE_SPECS_H +#define NE_RELOC_SRC_MASK 0x0F +#define NE_RELOC_TARGET_MASK 0x03 + enum { LOBYTE = 0, SEL_16 = 2, diff --git a/test/db/formats/ne b/test/db/formats/ne index 98df8447e01..f265c320add 100644 --- a/test/db/formats/ne +++ b/test/db/formats/ne @@ -50,24 +50,24 @@ ir~WIN87EM ir~:0..9 EOF EXPECT=<