Include non '__imp_' names and bug fixes
authorRobert Pengelly <robertapengelly@hotmail.com>
Sat, 10 May 2025 01:36:55 +0000 (02:36 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sat, 10 May 2025 01:36:55 +0000 (02:36 +0100)
ld.c
pe.c

diff --git a/ld.c b/ld.c
index 1f4c4cebb179c86910696e4a131d0e0144f29615..0d8adf99ab4259bfd92ced4aa5d0e951d49d6980 100644 (file)
--- 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 00669ce6767b9ddb66b2bc2338963bf817c5f58b..725adfc0d29f9e78f1a37183cfebdc0437d66b44 100644 (file)
--- 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);
     
     }