From ec81122b92259015623e89dbcf15b68dc4491546 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Sat, 10 May 2025 02:36:55 +0100 Subject: [PATCH] Include non '__imp_' names and bug fixes --- ld.c | 4 ++-- pe.c | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ld.c b/ld.c index 1f4c4ce..0d8adf9 100644 --- a/ld.c +++ b/ld.c @@ -112,7 +112,7 @@ static int read_object_file (const char *filename, unsigned char *data, unsigned } report_at (program_name, 0, REPORT_ERROR, "%s: unrecognised file format", filename); - return 1; + return -1; } @@ -135,7 +135,7 @@ static int read_archive_memeber (unsigned char *pos, const char *filename) { int ret; if (memcmp (pos, ALREADY_READ, sizeof (ALREADY_READ)) == 0) { - return 0; + return 1; } hdr = (struct ar_header *) pos; diff --git a/pe.c b/pe.c index 00669ce..725adfc 100644 --- a/pe.c +++ b/pe.c @@ -295,11 +295,11 @@ void pe_interpret_dot_drectve_section (/*const char *filename, unsigned char *da if (strncmp (p, "-export:", 8) == 0 || strncmp (p, "/EXPORT:", 8) == 0) { + struct name_list *name_list; char *q, saved_ch; - int data; - struct name_list *name_list; char *comma; + int data = 0; p += 8; @@ -1024,14 +1024,20 @@ static void write_implib (struct export_name *export_names, unsigned long num_na fseek (outfile, sizeof (struct ar_header), SEEK_CUR); offset2 = ftell (outfile); - symbol_count = swap_bytes (3 + num_names, 4); + symbol_count = swap_bytes (3 + (num_names * 2), 4); offset2 += write_data (outfile, &symbol_count, 4); - fseek (outfile, (3 + num_names) * 4, SEEK_CUR); + fseek (outfile, (3 + (num_names * 2)) * 4, SEEK_CUR); offset2 = ftell (outfile); - for (info = info_list; info; info = info->next) { + for (info = info_list, i = 0; info; info = info->next, i++) { + + if (i >= 3) { + offset2 += write_data (outfile, info->name + 6, (info->name_length - 6) + 1); + } + offset2 += write_data (outfile, info->name, info->name_length + 1); + } fseek (outfile, offset, SEEK_SET); @@ -1429,11 +1435,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na } - if (kill_at) { - type |= IMPORT_NAME_UNDECORATE << 2; - } + type |= (kill_at ? IMPORT_NAME_UNDECORATE : IMPORT_NAME_NOPREFIX) << 2; - integer_to_array (type | (IMPORT_NAME_NOPREFIX << 2), import_hdr.Type, 2); + integer_to_array (type, import_hdr.Type, 2); offset2 += write_data (outfile, &import_hdr, sizeof (import_hdr)); name = xmalloc (1 + strlen (export_names[i].name) + 1); @@ -1460,6 +1464,10 @@ static void write_implib (struct export_name *export_names, unsigned long num_na offset3 = offsets[1 + i]; offset3 = swap_bytes (offset3, 4); + if (i >= 3) { + offset2 += write_data (outfile, &offset3, 4); + } + offset2 += write_data (outfile, &offset3, 4); } -- 2.34.1