mirror of
git://source.winehq.org/git/wine.git
synced 2024-11-01 11:08:45 +00:00
kernelbase: Remove support for LZ files in 32-bit version functions.
Windows doesn't support it either. Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
4cb8497c8f
commit
9fba161dfd
1 changed files with 61 additions and 89 deletions
|
@ -36,7 +36,6 @@
|
|||
#include "winuser.h"
|
||||
#include "winnls.h"
|
||||
#include "winternl.h"
|
||||
#include "lzexpand.h"
|
||||
#include "winerror.h"
|
||||
|
||||
#include "kernelbase.h"
|
||||
|
@ -208,58 +207,32 @@ static const IMAGE_RESOURCE_DIRECTORY *find_entry_language( const IMAGE_RESOURCE
|
|||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* read_xx_header [internal]
|
||||
*/
|
||||
static int read_xx_header( HFILE lzfd )
|
||||
static DWORD read_data( HANDLE handle, DWORD offset, void *data, DWORD len )
|
||||
{
|
||||
IMAGE_DOS_HEADER mzh;
|
||||
char magic[3];
|
||||
DWORD res;
|
||||
|
||||
LZSeek( lzfd, 0, SEEK_SET );
|
||||
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 ) )
|
||||
return 0;
|
||||
|
||||
LZSeek( lzfd, mzh.e_lfanew, SEEK_SET );
|
||||
|
||||
if ( magic[0] == 'N' && magic[1] == 'E' )
|
||||
return IMAGE_OS2_SIGNATURE;
|
||||
if ( magic[0] == 'P' && magic[1] == 'E' )
|
||||
return IMAGE_NT_SIGNATURE;
|
||||
|
||||
magic[2] = '\0';
|
||||
WARN("Can't handle %s files.\n", magic );
|
||||
return 0;
|
||||
SetFilePointer( handle, offset, NULL, FILE_BEGIN );
|
||||
if (!ReadFile( handle, data, len, &res, NULL )) res = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* find_ne_resource [internal]
|
||||
*/
|
||||
static BOOL find_ne_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff )
|
||||
static BOOL find_ne_resource( HANDLE handle, DWORD *resLen, DWORD *resOff )
|
||||
{
|
||||
const WORD typeid = VS_FILE_INFO | 0x8000;
|
||||
const WORD resid = VS_VERSION_INFO | 0x8000;
|
||||
IMAGE_OS2_HEADER nehd;
|
||||
NE_TYPEINFO *typeInfo;
|
||||
NE_NAMEINFO *nameInfo;
|
||||
DWORD nehdoffset;
|
||||
DWORD nehdoffset = *resOff;
|
||||
LPBYTE resTab;
|
||||
DWORD resTabSize;
|
||||
int count;
|
||||
|
||||
/* Read in NE header */
|
||||
nehdoffset = LZSeek( lzfd, 0, SEEK_CUR );
|
||||
if ( sizeof(nehd) != LZRead( lzfd, (LPSTR)&nehd, sizeof(nehd) ) ) return FALSE;
|
||||
if (read_data( handle, nehdoffset, &nehd, sizeof(nehd) ) != sizeof(nehd)) return FALSE;
|
||||
|
||||
resTabSize = nehd.ne_restab - nehd.ne_rsrctab;
|
||||
if ( !resTabSize )
|
||||
|
@ -272,8 +245,7 @@ static BOOL find_ne_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff )
|
|||
resTab = HeapAlloc( GetProcessHeap(), 0, resTabSize );
|
||||
if ( !resTab ) return FALSE;
|
||||
|
||||
LZSeek( lzfd, nehd.ne_rsrctab + nehdoffset, SEEK_SET );
|
||||
if ( resTabSize != LZRead( lzfd, (char*)resTab, resTabSize ) )
|
||||
if (read_data( handle, nehd.ne_rsrctab + nehdoffset, resTab, resTabSize ) != resTabSize)
|
||||
{
|
||||
HeapFree( GetProcessHeap(), 0, resTab );
|
||||
return FALSE;
|
||||
|
@ -303,8 +275,8 @@ static BOOL find_ne_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff )
|
|||
|
||||
found_name:
|
||||
/* Return resource data */
|
||||
if ( resLen ) *resLen = nameInfo->length << *(WORD *)resTab;
|
||||
if ( resOff ) *resOff = nameInfo->offset << *(WORD *)resTab;
|
||||
*resLen = nameInfo->length << *(WORD *)resTab;
|
||||
*resOff = nameInfo->offset << *(WORD *)resTab;
|
||||
|
||||
HeapFree( GetProcessHeap(), 0, resTab );
|
||||
return TRUE;
|
||||
|
@ -313,27 +285,26 @@ static BOOL find_ne_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff )
|
|||
/***********************************************************************
|
||||
* find_pe_resource [internal]
|
||||
*/
|
||||
static BOOL find_pe_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff, DWORD flags )
|
||||
static BOOL find_pe_resource( HANDLE handle, DWORD *resLen, DWORD *resOff, DWORD flags )
|
||||
{
|
||||
union
|
||||
{
|
||||
IMAGE_NT_HEADERS32 nt32;
|
||||
IMAGE_NT_HEADERS64 nt64;
|
||||
} pehd;
|
||||
DWORD pehdoffset;
|
||||
DWORD pehdoffset = *resOff;
|
||||
PIMAGE_DATA_DIRECTORY resDataDir;
|
||||
PIMAGE_SECTION_HEADER sections;
|
||||
LPBYTE resSection;
|
||||
DWORD section_size, data_size;
|
||||
DWORD len, section_size, data_size;
|
||||
const void *resDir;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resPtr;
|
||||
const IMAGE_RESOURCE_DATA_ENTRY *resData;
|
||||
int i, len, nSections;
|
||||
int i, nSections;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
/* Read in PE header */
|
||||
pehdoffset = LZSeek( lzfd, 0, SEEK_CUR );
|
||||
len = LZRead( lzfd, (LPSTR)&pehd, sizeof(pehd) );
|
||||
len = read_data( handle, pehdoffset, &pehd, sizeof(pehd) );
|
||||
if (len < sizeof(pehd.nt32.FileHeader)) return FALSE;
|
||||
if (len < sizeof(pehd)) memset( (char *)&pehd + len, 0, sizeof(pehd) - len );
|
||||
|
||||
|
@ -362,10 +333,8 @@ static BOOL find_pe_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff, DWORD fl
|
|||
if ( !sections ) return FALSE;
|
||||
|
||||
len = FIELD_OFFSET( IMAGE_NT_HEADERS32, OptionalHeader ) + pehd.nt32.FileHeader.SizeOfOptionalHeader;
|
||||
LZSeek( lzfd, pehdoffset + len, SEEK_SET );
|
||||
|
||||
if ( nSections * sizeof(IMAGE_SECTION_HEADER) !=
|
||||
LZRead( lzfd, (LPSTR)sections, nSections * sizeof(IMAGE_SECTION_HEADER) ) )
|
||||
if (read_data( handle, pehdoffset + len, sections, nSections * sizeof(IMAGE_SECTION_HEADER) ) !=
|
||||
nSections * sizeof(IMAGE_SECTION_HEADER))
|
||||
{
|
||||
HeapFree( GetProcessHeap(), 0, sections );
|
||||
return FALSE;
|
||||
|
@ -395,8 +364,7 @@ static BOOL find_pe_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff, DWORD fl
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
LZSeek( lzfd, sections[i].PointerToRawData, SEEK_SET );
|
||||
if (data_size != LZRead( lzfd, (char*)resSection, data_size )) goto done;
|
||||
if (read_data( handle, sections[i].PointerToRawData, resSection, data_size ) != data_size) goto done;
|
||||
if (data_size < section_size) memset( (char *)resSection + data_size, 0, section_size - data_size );
|
||||
|
||||
/* Find resource */
|
||||
|
@ -437,9 +405,8 @@ static BOOL find_pe_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff, DWORD fl
|
|||
}
|
||||
|
||||
/* Return resource data */
|
||||
if ( resLen ) *resLen = resData->Size;
|
||||
if ( resOff ) *resOff = resData->OffsetToData - sections[i].VirtualAddress
|
||||
+ sections[i].PointerToRawData;
|
||||
*resLen = resData->Size;
|
||||
*resOff = resData->OffsetToData - sections[i].VirtualAddress + sections[i].PointerToRawData;
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
|
@ -452,19 +419,27 @@ static BOOL find_pe_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff, DWORD fl
|
|||
/***********************************************************************
|
||||
* find_version_resource [internal]
|
||||
*/
|
||||
static DWORD find_version_resource( HFILE lzfd, DWORD *reslen, DWORD *offset, DWORD flags )
|
||||
static DWORD find_version_resource( HANDLE handle, DWORD *reslen, DWORD *offset, DWORD flags )
|
||||
{
|
||||
DWORD magic = read_xx_header( lzfd );
|
||||
IMAGE_DOS_HEADER mzh;
|
||||
WORD magic;
|
||||
|
||||
if (read_data( handle, 0, &mzh, sizeof(mzh) ) != sizeof(mzh)) return 0;
|
||||
if (mzh.e_magic != IMAGE_DOS_SIGNATURE) return 0;
|
||||
|
||||
if (read_data( handle, mzh.e_lfanew, &magic, sizeof(magic) ) != sizeof(magic)) return 0;
|
||||
*offset = mzh.e_lfanew;
|
||||
|
||||
switch (magic)
|
||||
{
|
||||
case IMAGE_OS2_SIGNATURE:
|
||||
if (!find_ne_resource( lzfd, reslen, offset )) magic = 0;
|
||||
if (!find_ne_resource( handle, reslen, offset )) magic = 0;
|
||||
break;
|
||||
case IMAGE_NT_SIGNATURE:
|
||||
if (!find_pe_resource( lzfd, reslen, offset, flags )) magic = 0;
|
||||
if (!find_pe_resource( handle, reslen, offset, flags )) magic = 0;
|
||||
break;
|
||||
}
|
||||
WARN( "Can't handle %04x files.\n", magic );
|
||||
return magic;
|
||||
}
|
||||
|
||||
|
@ -620,16 +595,14 @@ DWORD WINAPI GetFileVersionInfoSizeA( LPCSTR filename, LPDWORD handle )
|
|||
/******************************************************************************
|
||||
* GetFileVersionInfoSizeExW (kernelbase.@)
|
||||
*/
|
||||
DWORD WINAPI GetFileVersionInfoSizeExW( DWORD flags, LPCWSTR filename, LPDWORD handle )
|
||||
DWORD WINAPI GetFileVersionInfoSizeExW( DWORD flags, LPCWSTR filename, LPDWORD ret_handle )
|
||||
{
|
||||
DWORD len, offset, magic = 1;
|
||||
HFILE lzfd;
|
||||
HMODULE hModule;
|
||||
OFSTRUCT ofs;
|
||||
|
||||
TRACE("(0x%x,%s,%p)\n", flags, debugstr_w(filename), handle );
|
||||
TRACE("(0x%x,%s,%p)\n", flags, debugstr_w(filename), ret_handle );
|
||||
|
||||
if (handle) *handle = 0;
|
||||
if (ret_handle) *ret_handle = 0;
|
||||
|
||||
if (!filename)
|
||||
{
|
||||
|
@ -644,13 +617,7 @@ DWORD WINAPI GetFileVersionInfoSizeExW( DWORD flags, LPCWSTR filename, LPDWORD h
|
|||
if (flags & ~FILE_VER_GET_LOCALISED)
|
||||
FIXME("flags 0x%x ignored\n", flags & ~FILE_VER_GET_LOCALISED);
|
||||
|
||||
if ((lzfd = LZOpenFileW( (LPWSTR)filename, &ofs, OF_READ )) != HFILE_ERROR)
|
||||
{
|
||||
magic = find_version_resource( lzfd, &len, &offset, flags );
|
||||
LZClose( lzfd );
|
||||
}
|
||||
|
||||
if ((magic == 1) && (hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
|
||||
if ((hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
|
||||
{
|
||||
HRSRC hRsrc = NULL;
|
||||
if (!(flags & FILE_VER_GET_LOCALISED))
|
||||
|
@ -670,6 +637,15 @@ DWORD WINAPI GetFileVersionInfoSizeExW( DWORD flags, LPCWSTR filename, LPDWORD h
|
|||
FreeLibrary( hModule );
|
||||
}
|
||||
|
||||
if (magic == 1)
|
||||
{
|
||||
HANDLE handle = CreateFileW( filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, 0, 0 );
|
||||
if (handle == INVALID_HANDLE_VALUE) return 0;
|
||||
magic = find_version_resource( handle, &len, &offset, flags );
|
||||
CloseHandle( handle );
|
||||
}
|
||||
|
||||
switch (magic)
|
||||
{
|
||||
case IMAGE_OS2_SIGNATURE:
|
||||
|
@ -696,9 +672,7 @@ DWORD WINAPI GetFileVersionInfoSizeExW( DWORD flags, LPCWSTR filename, LPDWORD h
|
|||
return (len * 2) + 4;
|
||||
|
||||
default:
|
||||
if (lzfd == HFILE_ERROR)
|
||||
SetLastError(ofs.nErrCode);
|
||||
else if (GetVersion() & 0x80000000) /* Windows 95/98 */
|
||||
if (GetVersion() & 0x80000000) /* Windows 95/98 */
|
||||
SetLastError(ERROR_FILE_NOT_FOUND);
|
||||
else
|
||||
SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
|
||||
|
@ -731,17 +705,15 @@ DWORD WINAPI GetFileVersionInfoSizeExA( DWORD flags, LPCSTR filename, LPDWORD ha
|
|||
/***********************************************************************
|
||||
* GetFileVersionInfoExW (kernelbase.@)
|
||||
*/
|
||||
BOOL WINAPI GetFileVersionInfoExW( DWORD flags, LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data )
|
||||
BOOL WINAPI GetFileVersionInfoExW( DWORD flags, LPCWSTR filename, DWORD ignored, DWORD datasize, LPVOID data )
|
||||
{
|
||||
static const char signature[4] = "FE2X";
|
||||
DWORD len, offset, magic = 1;
|
||||
HFILE lzfd;
|
||||
OFSTRUCT ofs;
|
||||
HMODULE hModule;
|
||||
VS_VERSION_INFO_STRUCT32* vvis = data;
|
||||
|
||||
TRACE("(0x%x,%s,%d,size=%d,data=%p)\n",
|
||||
flags, debugstr_w(filename), handle, datasize, data );
|
||||
flags, debugstr_w(filename), ignored, datasize, data );
|
||||
|
||||
if (!data)
|
||||
{
|
||||
|
@ -751,17 +723,7 @@ BOOL WINAPI GetFileVersionInfoExW( DWORD flags, LPCWSTR filename, DWORD handle,
|
|||
if (flags & ~FILE_VER_GET_LOCALISED)
|
||||
FIXME("flags 0x%x ignored\n", flags & ~FILE_VER_GET_LOCALISED);
|
||||
|
||||
if ((lzfd = LZOpenFileW( (LPWSTR)filename, &ofs, OF_READ )) != HFILE_ERROR)
|
||||
{
|
||||
if ((magic = find_version_resource( lzfd, &len, &offset, flags )) > 1)
|
||||
{
|
||||
LZSeek( lzfd, offset, 0 /* SEEK_SET */ );
|
||||
len = LZRead( lzfd, data, min( len, datasize ) );
|
||||
}
|
||||
LZClose( lzfd );
|
||||
}
|
||||
|
||||
if ((magic == 1) && (hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
|
||||
if ((hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
|
||||
{
|
||||
HRSRC hRsrc = NULL;
|
||||
if (!(flags & FILE_VER_GET_LOCALISED))
|
||||
|
@ -784,6 +746,16 @@ BOOL WINAPI GetFileVersionInfoExW( DWORD flags, LPCWSTR filename, DWORD handle,
|
|||
FreeLibrary( hModule );
|
||||
}
|
||||
|
||||
if (magic == 1)
|
||||
{
|
||||
HANDLE handle = CreateFileW( filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, 0, 0 );
|
||||
if (handle == INVALID_HANDLE_VALUE) return 0;
|
||||
if ((magic = find_version_resource( handle, &len, &offset, flags )))
|
||||
len = read_data( handle, offset, data, min( len, datasize ));
|
||||
CloseHandle( handle );
|
||||
}
|
||||
|
||||
switch (magic)
|
||||
{
|
||||
case IMAGE_OS2_SIGNATURE:
|
||||
|
@ -807,7 +779,7 @@ BOOL WINAPI GetFileVersionInfoExW( DWORD flags, LPCWSTR filename, DWORD handle,
|
|||
return TRUE;
|
||||
|
||||
default:
|
||||
SetLastError( lzfd == HFILE_ERROR ? ofs.nErrCode : ERROR_RESOURCE_DATA_NOT_FOUND );
|
||||
SetLastError( ERROR_RESOURCE_DATA_NOT_FOUND );
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue