From 2b1ff0100668df2c1e65cdc6693149168c1b75c5 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 17 Feb 2010 09:41:20 +0100 Subject: [PATCH] version: Improve detection of builtin libraries. --- dlls/version/info.c | 26 +++++++++----------------- dlls/version/resource.c | 4 ++++ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/dlls/version/info.c b/dlls/version/info.c index 8db40bca4c2..e7f7077e72b 100644 --- a/dlls/version/info.c +++ b/dlls/version/info.c @@ -238,7 +238,7 @@ typedef struct */ DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle ) { - DWORD len, offset, magic = 0; + DWORD len, offset, magic = 1; HFILE lzfd; HMODULE hModule; OFSTRUCT ofs; @@ -263,7 +263,8 @@ DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle ) magic = find_version_resource( lzfd, &len, &offset ); LZClose( lzfd ); } - else if ((hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE ))) + + if ((magic == 1) && (hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE ))) { HRSRC hRsrc = FindResourceW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO), MAKEINTRESOURCEW(VS_FILE_INFO) ); @@ -274,11 +275,6 @@ DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle ) } FreeLibrary( hModule ); } - else - { - SetLastError( ofs.nErrCode ); - return 0; - } switch (magic) { @@ -306,7 +302,7 @@ DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle ) return (len * 2) + 4; default: - SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND); + SetLastError( lzfd == HFILE_ERROR ? ofs.nErrCode : ERROR_RESOURCE_DATA_NOT_FOUND ); return 0; } } @@ -340,7 +336,7 @@ BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data ) { static const char signature[4] = "FE2X"; - DWORD len, offset, magic = 0; + DWORD len, offset, magic = 1; HFILE lzfd; OFSTRUCT ofs; HMODULE hModule; @@ -357,14 +353,15 @@ BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle, if ((lzfd = LZOpenFileW( (LPWSTR)filename, &ofs, OF_READ )) != HFILE_ERROR) { - if ((magic = find_version_resource( lzfd, &len, &offset ))) + if ((magic = find_version_resource( lzfd, &len, &offset )) > 1) { LZSeek( lzfd, offset, 0 /* SEEK_SET */ ); len = LZRead( lzfd, data, min( len, datasize ) ); } LZClose( lzfd ); } - else if ((hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE ))) + + if ((magic == 1) && (hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE ))) { HRSRC hRsrc = FindResourceW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO), MAKEINTRESOURCEW(VS_FILE_INFO) ); @@ -378,11 +375,6 @@ BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle, } FreeLibrary( hModule ); } - else - { - SetLastError( ofs.nErrCode ); - return FALSE; - } switch (magic) { @@ -407,7 +399,7 @@ BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle, return TRUE; default: - SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND); + SetLastError( lzfd == HFILE_ERROR ? ofs.nErrCode : ERROR_RESOURCE_DATA_NOT_FOUND ); return FALSE; } } diff --git a/dlls/version/resource.c b/dlls/version/resource.c index 9af07fed756..68cda3fd579 100644 --- a/dlls/version/resource.c +++ b/dlls/version/resource.c @@ -101,7 +101,11 @@ static int read_xx_header( HFILE lzfd ) if ( sizeof(mzh) != LZRead( lzfd, (LPSTR)&mzh, sizeof(mzh) ) ) return 0; if ( mzh.e_magic != IMAGE_DOS_SIGNATURE ) + { + if (!memcmp( &mzh, "\177ELF", 4 )) return 1; /* ELF */ + if (*(UINT *)&mzh == 0xfeedface || *(UINT *)&mzh == 0xcefaedfe) return 1; /* Mach-O */ return 0; + } LZSeek( lzfd, mzh.e_lfanew, SEEK_SET ); if ( 2 != LZRead( lzfd, magic, 2 ) )