From 20d13d0b788c807d54cd8d0896350818989fd5fe Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 18 Sep 2017 15:41:43 +0200 Subject: [PATCH] libwine: Also apply the load delta to the FirstThunk table. Signed-off-by: Alexandre Julliard --- libs/wine/loader.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libs/wine/loader.c b/libs/wine/loader.c index 172bfa0f270..c07042a583e 100644 --- a/libs/wine/loader.c +++ b/libs/wine/loader.c @@ -320,22 +320,27 @@ static inline void fixup_rva_dwords( DWORD *ptr, int delta, unsigned int count ) } +/* fixup an array of name/ordinal RVAs by adding the specified delta */ +static inline void fixup_rva_names( UINT_PTR *ptr, int delta ) +{ + while (*ptr) + { + if (!(*ptr & IMAGE_ORDINAL_FLAG)) *ptr += delta; + ptr++; + } +} + + /* fixup RVAs in the import directory */ static void fixup_imports( IMAGE_IMPORT_DESCRIPTOR *dir, BYTE *base, int delta ) { - UINT_PTR *ptr; - while (dir->Name) { fixup_rva_dwords( &dir->u.OriginalFirstThunk, delta, 1 ); fixup_rva_dwords( &dir->Name, delta, 1 ); fixup_rva_dwords( &dir->FirstThunk, delta, 1 ); - ptr = (UINT_PTR *)(base + (dir->u.OriginalFirstThunk ? dir->u.OriginalFirstThunk : dir->FirstThunk)); - while (*ptr) - { - if (!(*ptr & IMAGE_ORDINAL_FLAG)) *ptr += delta; - ptr++; - } + if (dir->u.OriginalFirstThunk) fixup_rva_names( (UINT_PTR *)(base + dir->u.OriginalFirstThunk), delta ); + if (dir->FirstThunk) fixup_rva_names( (UINT_PTR *)(base + dir->FirstThunk), delta ); dir++; } }