From 232a69d733b39d234bacd4922081ec6b00dedb91 Mon Sep 17 00:00:00 2001 From: Roee Toledano Date: Wed, 20 Nov 2024 18:43:38 +0200 Subject: [PATCH] Fix NE relocation naming * Name NE relocations by combining `src` and `flag` * Fix old test + add additional tests --- librz/bin/format/ne/ne.c | 55 +- test/db/formats/ne | 1223 +++++++++++++++++++++++++++++++++++++- 2 files changed, 1244 insertions(+), 34 deletions(-) diff --git a/librz/bin/format/ne/ne.c b/librz/bin/format/ne/ne.c index d6ece2314a5..22559c93f91 100644 --- a/librz/bin/format/ne/ne.c +++ b/librz/bin/format/ne/ne.c @@ -118,6 +118,44 @@ 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(a, b) a b +#define NE_RELOC_TARGET_TYPE(src_type_name, flag) \ + switch (flag) { \ + case INTERNAL_REF: \ + return CONCAT(src_type_name, "_INTERNAL_REF"); \ + case IMPORTED_ORD: \ + return CONCAT(src_type_name, "_IMPORTED_ORD"); \ + case IMPORTED_NAME: \ + return CONCAT(src_type_name, "_IMPORTED_NAME"); \ + case OSFIXUP: \ + return CONCAT(src_type_name, "_OSFIXUP"); \ + case ADDITIVE: \ + return CONCAT(src_type_name, "_ADDITIVE"); \ + default: \ + return CONCAT(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: + NE_RELOC_TARGET_TYPE("UNKNOWN", flag); + } +#undef NE_RELOC_TARGET_TYPE +#undef CONCAT +} + 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 +575,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, rel.flags); if (rel.flags & (IMPORTED_ORD | IMPORTED_NAME)) { RzBinImport *imp = RZ_NEW0(RzBinImport); diff --git a/test/db/formats/ne b/test/db/formats/ne index 98df8447e01..f7070c7e9f8 100644 --- a/test/db/formats/ne +++ b/test/db/formats/ne @@ -50,24 +50,24 @@ ir~WIN87EM ir~:0..9 EOF EXPECT=<