From c6e050fa69552e023d18df2cf1255a2a827f1bcc Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 19 Jul 2022 10:36:20 +0200 Subject: [PATCH 1/2] Print list of DLLs which still overlap after rebasing --- rebase.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/rebase.c b/rebase.c index 1f9f74b..8ca65cc 100644 --- a/rebase.c +++ b/rebase.c @@ -47,6 +47,7 @@ BOOL load_image_info (); BOOL merge_image_info (); BOOL collect_image_info (const char *pathname); void print_image_info (); +static void print_overlapped (); BOOL rebase (const char *pathname, ULONG64 *new_image_base, BOOL down_flag); void parse_args (int argc, char *argv[]); unsigned long long string_to_ulonglong (const char *string); @@ -323,6 +324,10 @@ main (int argc, char *argv[]) } fprintf (stderr, " %s\n", img_info_list[i].name); } + /* Print list of DLLs which still overlap. This could occur if DLLs are + not rebaseable or if --merge-files is used incorrectly. */ + if (img_info_size) + print_overlapped (); if (save_image_info () < 0) return 2; } @@ -1149,6 +1154,39 @@ print_image_info () } } +static void +print_overlapped () +{ + BOOL header; + int i; + char overlaps[img_info_size]; + memset (overlaps, 0, img_info_size); + qsort (img_info_list, img_info_size, sizeof (img_info_t), img_info_cmp); + for (header = FALSE, i = 0; i < img_info_size; ++i) + { + int j; + if (img_info_list[i].flag.needs_rebasing) + continue; /* Rebase failed. */ + for (j = i + 1; j < img_info_size; ++j) + { + if (img_info_list[j].flag.needs_rebasing) + continue; /* Rebase failed. */ + if (img_info_list[i].base + img_info_list[i].slot_size + offset + <= img_info_list[j].base) + break; + overlaps[i] = overlaps[j] = 1; + } + if (!overlaps[i]) + continue; + if (!header) + { + fputs ("\nThe following DLLs still overlap:\n", stderr); + header = TRUE; + } + fprintf (stderr, " %s\n", img_info_list[i].name); + } +} + BOOL rebase (const char *pathname, ULONG64 *new_image_base, BOOL down_flag) { -- 2.37.1