Skip to content

Commit

Permalink
Fix NE relocation naming
Browse files Browse the repository at this point in the history
* Name NE relocations by combining `src` and `flag`
* Fix old test + add additional tests
  • Loading branch information
Roeegg2 committed Nov 20, 2024
1 parent 266fe6b commit 232a69d
Show file tree
Hide file tree
Showing 2 changed files with 1,244 additions and 34 deletions.
55 changes: 39 additions & 16 deletions librz/bin/format/ne/ne.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 /*<RzBinSymbol *>*/ *rz_bin_ne_get_symbols(rz_bin_ne_obj_t *bin) {
RzBinSymbol *sym;
ut16 off = bin->ne_header->ResidNamTable + bin->header_offset;
Expand Down Expand Up @@ -537,22 +575,7 @@ RzPVector /*<RzBinReloc *>*/ *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);
Expand Down
Loading

0 comments on commit 232a69d

Please sign in to comment.