From ea1689e7b06a5f03a882bde9ee566939e9171330 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 22 Aug 2014 12:44:24 +0200 Subject: [PATCH] kernel32: Add detection of fake dlls when determining a binary type. --- dlls/kernel32/kernel_private.h | 5 +++-- dlls/kernel32/module.c | 12 ++++++++++++ dlls/kernel32/process.c | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h index 5c6c197c159..76611d74fae 100644 --- a/dlls/kernel32/kernel_private.h +++ b/dlls/kernel32/kernel_private.h @@ -75,8 +75,9 @@ enum binary_type BINARY_UNIX_LIB }; -#define BINARY_FLAG_DLL 0x01 -#define BINARY_FLAG_64BIT 0x02 +#define BINARY_FLAG_DLL 0x01 +#define BINARY_FLAG_64BIT 0x02 +#define BINARY_FLAG_FAKEDLL 0x04 struct binary_info { diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c index 514b6be7dce..ca4cf41ff5e 100644 --- a/dlls/kernel32/module.c +++ b/dlls/kernel32/module.c @@ -339,6 +339,9 @@ void MODULE_get_binary_info( HANDLE hfile, struct binary_info *info ) { if (len >= sizeof(ext_header.nt.FileHeader)) { + static const char fakedll_signature[] = "Wine placeholder DLL"; + char buffer[sizeof(fakedll_signature)]; + info->type = BINARY_PE; info->arch = ext_header.nt.FileHeader.Machine; if (ext_header.nt.FileHeader.Characteristics & IMAGE_FILE_DLL) @@ -356,6 +359,15 @@ void MODULE_get_binary_info( HANDLE hfile, struct binary_info *info ) info->flags |= BINARY_FLAG_64BIT; break; } + + if (header.mz.e_lfanew >= sizeof(header.mz) + sizeof(fakedll_signature) && + SetFilePointer( hfile, sizeof(header.mz), NULL, SEEK_SET ) == sizeof(header.mz) && + ReadFile( hfile, buffer, sizeof(fakedll_signature), &len, NULL ) && + len == sizeof(fakedll_signature) && + !memcmp( buffer, fakedll_signature, sizeof(fakedll_signature) )) + { + info->flags |= BINARY_FLAG_FAKEDLL; + } } } else if (!memcmp( &ext_header.os2.ne_magic, "NE", 2 )) diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index 2566ac493b7..301c64abe4c 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -2342,9 +2342,10 @@ static BOOL create_process_impl( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_A else switch (binary_info.type) { case BINARY_PE: - TRACE( "starting %s as Win%d binary (%p-%p, arch %04x)\n", + TRACE( "starting %s as Win%d binary (%p-%p, arch %04x%s)\n", debugstr_w(name), (binary_info.flags & BINARY_FLAG_64BIT) ? 64 : 32, - binary_info.res_start, binary_info.res_end, binary_info.arch ); + binary_info.res_start, binary_info.res_end, binary_info.arch, + (binary_info.flags & BINARY_FLAG_FAKEDLL) ? ", fakedll" : "" ); retv = create_process( hFile, name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr, inherit, flags, startup_info, info, unixdir, &binary_info, FALSE ); break;