version: Simplify the resource loading since we always load the same type and id now.
This commit is contained in:
parent
3ed5986dd6
commit
f6fc2dba07
|
@ -38,7 +38,7 @@
|
|||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(ver);
|
||||
|
||||
extern DWORD find_resource( HFILE lzfd, LPCSTR type, LPCSTR id, DWORD *reslen, DWORD *offset );
|
||||
extern DWORD find_version_resource( HFILE lzfd, DWORD *reslen, DWORD *offset );
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
|
@ -355,8 +355,7 @@ static DWORD VERSION_GetFileVersionInfo_16( LPCSTR filename, DWORD datasize, LPV
|
|||
|
||||
if (lzfd >= 0)
|
||||
{
|
||||
if (find_resource( lzfd, MAKEINTRESOURCEA(VS_FILE_INFO), MAKEINTRESOURCEA(VS_VERSION_INFO),
|
||||
&len, &offset ))
|
||||
if (find_version_resource( lzfd, &len, &offset ))
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "windef.h"
|
||||
#include "winbase.h"
|
||||
#include "lzexpand.h"
|
||||
#include "winver.h"
|
||||
|
||||
#include "wine/unicode.h"
|
||||
#include "wine/winbase16.h"
|
||||
|
@ -88,56 +89,6 @@ static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_
|
|||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* find_entry_by_name
|
||||
*
|
||||
* Find an entry by name in a resource directory
|
||||
* Copied from loader/pe_resource.c
|
||||
*/
|
||||
static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_name( const IMAGE_RESOURCE_DIRECTORY *dir,
|
||||
LPCSTR name, const void *root )
|
||||
{
|
||||
const IMAGE_RESOURCE_DIRECTORY *ret = NULL;
|
||||
LPWSTR nameW;
|
||||
DWORD namelen;
|
||||
|
||||
if (!HIWORD(name)) return find_entry_by_id( dir, LOWORD(name), root );
|
||||
if (name[0] == '#')
|
||||
{
|
||||
return find_entry_by_id( dir, atoi(name+1), root );
|
||||
}
|
||||
|
||||
namelen = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
|
||||
if ((nameW = HeapAlloc( GetProcessHeap(), 0, namelen * sizeof(WCHAR) )))
|
||||
{
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
|
||||
const IMAGE_RESOURCE_DIR_STRING_U *str;
|
||||
int min, max, res, pos;
|
||||
|
||||
MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, namelen );
|
||||
namelen--; /* remove terminating null */
|
||||
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
||||
min = 0;
|
||||
max = dir->NumberOfNamedEntries - 1;
|
||||
while (min <= max)
|
||||
{
|
||||
pos = (min + max) / 2;
|
||||
str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const char *)root + entry[pos].u1.s1.NameOffset);
|
||||
res = strncmpiW( nameW, str->NameString, str->Length );
|
||||
if (!res && namelen == str->Length)
|
||||
{
|
||||
ret = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].u2.s3.OffsetToDirectory);
|
||||
break;
|
||||
}
|
||||
if (res < 0) max = pos - 1;
|
||||
else min = pos + 1;
|
||||
}
|
||||
HeapFree( GetProcessHeap(), 0, nameW );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* read_xx_header [internal]
|
||||
*/
|
||||
|
@ -171,9 +122,10 @@ static int read_xx_header( HFILE lzfd )
|
|||
/***********************************************************************
|
||||
* find_ne_resource [internal]
|
||||
*/
|
||||
static BOOL find_ne_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
||||
DWORD *resLen, DWORD *resOff )
|
||||
static BOOL find_ne_resource( HFILE lzfd, 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;
|
||||
|
@ -206,55 +158,23 @@ static BOOL find_ne_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
|||
|
||||
/* Find resource */
|
||||
typeInfo = (NE_TYPEINFO *)(resTab + 2);
|
||||
|
||||
if (HIWORD(typeid) != 0) /* named type */
|
||||
{
|
||||
BYTE len = strlen( typeid );
|
||||
while (typeInfo->type_id)
|
||||
{
|
||||
if (!(typeInfo->type_id & 0x8000))
|
||||
{
|
||||
BYTE *p = resTab + typeInfo->type_id;
|
||||
if ((*p == len) && !strncasecmp( (char*)p+1, typeid, len )) goto found_type;
|
||||
}
|
||||
if (typeInfo->type_id == typeid) goto found_type;
|
||||
typeInfo = (NE_TYPEINFO *)((char *)(typeInfo + 1) +
|
||||
typeInfo->count * sizeof(NE_NAMEINFO));
|
||||
}
|
||||
}
|
||||
else /* numeric type id */
|
||||
{
|
||||
WORD id = LOWORD(typeid) | 0x8000;
|
||||
while (typeInfo->type_id)
|
||||
{
|
||||
if (typeInfo->type_id == id) goto found_type;
|
||||
typeInfo = (NE_TYPEINFO *)((char *)(typeInfo + 1) +
|
||||
typeInfo->count * sizeof(NE_NAMEINFO));
|
||||
}
|
||||
}
|
||||
TRACE("No typeid entry found for %p\n", typeid );
|
||||
TRACE("No typeid entry found\n" );
|
||||
HeapFree( GetProcessHeap(), 0, resTab );
|
||||
return FALSE;
|
||||
|
||||
found_type:
|
||||
nameInfo = (NE_NAMEINFO *)(typeInfo + 1);
|
||||
|
||||
if (HIWORD(resid) != 0) /* named resource */
|
||||
{
|
||||
BYTE len = strlen( resid );
|
||||
for (count = typeInfo->count; count > 0; count--, nameInfo++)
|
||||
{
|
||||
BYTE *p = resTab + nameInfo->id;
|
||||
if (nameInfo->id & 0x8000) continue;
|
||||
if ((*p == len) && !strncasecmp( (char*)p+1, resid, len )) goto found_name;
|
||||
}
|
||||
}
|
||||
else /* numeric resource id */
|
||||
{
|
||||
WORD id = LOWORD(resid) | 0x8000;
|
||||
for (count = typeInfo->count; count > 0; count--, nameInfo++)
|
||||
if (nameInfo->id == id) goto found_name;
|
||||
}
|
||||
TRACE("No resid entry found for %p\n", typeid );
|
||||
if (nameInfo->id == resid) goto found_name;
|
||||
|
||||
TRACE("No resid entry found\n" );
|
||||
HeapFree( GetProcessHeap(), 0, resTab );
|
||||
return FALSE;
|
||||
|
||||
|
@ -270,8 +190,7 @@ static BOOL find_ne_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
|||
/***********************************************************************
|
||||
* find_pe_resource [internal]
|
||||
*/
|
||||
static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
||||
DWORD *resLen, DWORD *resOff )
|
||||
static BOOL find_pe_resource( HFILE lzfd, DWORD *resLen, DWORD *resOff )
|
||||
{
|
||||
IMAGE_NT_HEADERS pehd;
|
||||
DWORD pehdoffset;
|
||||
|
@ -344,22 +263,22 @@ static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
|||
resDir = resSection + (resDataDir->VirtualAddress - sections[i].VirtualAddress);
|
||||
|
||||
resPtr = resDir;
|
||||
resPtr = find_entry_by_name( resPtr, typeid, resDir );
|
||||
resPtr = find_entry_by_id( resPtr, VS_FILE_INFO, resDir );
|
||||
if ( !resPtr )
|
||||
{
|
||||
TRACE("No typeid entry found for %p\n", typeid );
|
||||
TRACE("No typeid entry found\n" );
|
||||
goto done;
|
||||
}
|
||||
resPtr = find_entry_by_name( resPtr, resid, resDir );
|
||||
resPtr = find_entry_by_id( resPtr, VS_VERSION_INFO, resDir );
|
||||
if ( !resPtr )
|
||||
{
|
||||
TRACE("No resid entry found for %p\n", resid );
|
||||
TRACE("No resid entry found\n" );
|
||||
goto done;
|
||||
}
|
||||
resPtr = find_entry_default( resPtr, resDir );
|
||||
if ( !resPtr )
|
||||
{
|
||||
TRACE("No default language entry found for %p\n", resid );
|
||||
TRACE("No default language entry found\n" );
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -391,19 +310,19 @@ static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
|||
|
||||
|
||||
/***********************************************************************
|
||||
* find_resource [internal]
|
||||
* find_version_resource [internal]
|
||||
*/
|
||||
DWORD find_resource( HFILE lzfd, LPCSTR type, LPCSTR id, DWORD *reslen, DWORD *offset )
|
||||
DWORD find_version_resource( HFILE lzfd, DWORD *reslen, DWORD *offset )
|
||||
{
|
||||
DWORD magic = read_xx_header( lzfd );
|
||||
|
||||
switch (magic)
|
||||
{
|
||||
case IMAGE_OS2_SIGNATURE:
|
||||
if (!find_ne_resource( lzfd, type, id, reslen, offset )) magic = 0;
|
||||
if (!find_ne_resource( lzfd, reslen, offset )) magic = 0;
|
||||
break;
|
||||
case IMAGE_NT_SIGNATURE:
|
||||
if (!find_pe_resource( lzfd, type, id, reslen, offset )) magic = 0;
|
||||
if (!find_pe_resource( lzfd, reslen, offset )) magic = 0;
|
||||
break;
|
||||
}
|
||||
return magic;
|
||||
|
|
Loading…
Reference in New Issue