Duplicate resource directory searching routines instead of calling

pe_resource.c internal functions.
Made GetFileResource16 and GetFileResourceSize16 callable directly
instead of defining extra internal functions.
This commit is contained in:
Alexandre Julliard 2000-10-23 01:38:29 +00:00
parent c1c41cd64e
commit b85a6adc58
6 changed files with 123 additions and 86 deletions

View File

@ -12,6 +12,7 @@
#include "winreg.h"
#include "winver.h"
#include "wine/winestring.h"
#include "wine/winuser16.h"
#include "wine/unicode.h"
#include "winerror.h"
#include "heap.h"
@ -272,13 +273,13 @@ DWORD WINAPI GetFileVersionInfoSizeA( LPCSTR filename, LPDWORD handle )
TRACE("(%s,%p)\n", debugstr_a(filename), handle );
len = GetFileResourceSize( filename,
len = GetFileResourceSize16( filename,
MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
&offset );
if (!len) return 0;
ret = GetFileResource( filename,
ret = GetFileResource16( filename,
MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
offset, sizeof( buf ), buf );
@ -327,7 +328,7 @@ DWORD WINAPI GetFileVersionInfoA( LPCSTR filename, DWORD handle,
TRACE("(%s,%ld,size=%ld,data=%p)\n",
debugstr_a(filename), handle, datasize, data );
if ( !GetFileResource( filename, MAKEINTRESOURCEA(VS_FILE_INFO),
if ( !GetFileResource16( filename, MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
handle, datasize, data ) )
return FALSE;
@ -356,7 +357,7 @@ DWORD WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle,
TRACE("(%s,%ld,size=%ld,data=%p)\n",
debugstr_a(fn), handle, datasize, data );
if ( !GetFileResource( fn, MAKEINTRESOURCEA(VS_FILE_INFO),
if ( !GetFileResource16( fn, MAKEINTRESOURCEA(VS_FILE_INFO),
MAKEINTRESOURCEA(VS_VERSION_INFO),
handle, datasize, data ) )
retv = FALSE;

View File

@ -11,6 +11,9 @@
#include <sys/types.h>
#include <unistd.h>
#include "wine/unicode.h"
#include "heap.h"
#include "neexe.h"
#include "module.h"
#include "winver.h"
@ -20,6 +23,95 @@
DEFAULT_DEBUG_CHANNEL(ver);
/**********************************************************************
* find_entry_by_id
*
* Find an entry by id in a resource directory
* Copied from loader/pe_resource.c
*/
static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
WORD id, const void *root )
{
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
int min, max, pos;
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
min = dir->NumberOfNamedEntries;
max = min + dir->NumberOfIdEntries - 1;
while (min <= max)
{
pos = (min + max) / 2;
if (entry[pos].u1.Id == id)
return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].u2.s.OffsetToDirectory);
if (entry[pos].u1.Id > id) max = pos - 1;
else min = pos + 1;
}
return NULL;
}
/**********************************************************************
* find_entry_default
*
* Find a default entry in a resource directory
* Copied from loader/pe_resource.c
*/
static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
const void *root )
{
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry->u2.s.OffsetToDirectory);
}
/**********************************************************************
* 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;
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 );
}
if ((nameW = HEAP_strdupAtoW( GetProcessHeap(), 0, name )))
{
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
const IMAGE_RESOURCE_DIR_STRING_U *str;
int min, max, res, pos, namelen = strlenW(nameW);
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
min = 0;
max = dir->NumberOfNamedEntries - 1;
while (min <= max)
{
pos = (min + max) / 2;
str = (IMAGE_RESOURCE_DIR_STRING_U *)((char *)root + entry[pos].u1.s.NameOffset);
res = strncmpiW( nameW, str->NameString, str->Length );
if (!res && namelen == str->Length)
{
ret = (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].u2.s.OffsetToDirectory);
break;
}
if (res < 0) max = pos - 1;
else min = pos + 1;
}
HeapFree( GetProcessHeap(), 0, nameW );
}
return ret;
}
/***********************************************************************
* read_xx_header [internal]
*/
@ -126,7 +218,7 @@ static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
const IMAGE_RESOURCE_DIRECTORY *resPtr;
const IMAGE_RESOURCE_DATA_ENTRY *resData;
int i, nSections;
BOOL ret = FALSE;
/* Read in PE header */
pehdoffset = LZSeek( lzfd, 0, SEEK_CUR );
@ -181,40 +273,29 @@ static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
}
LZSeek( lzfd, sections[i].PointerToRawData, SEEK_SET );
if ( resSectionSize != LZRead( lzfd, resSection, resSectionSize ) )
{
HeapFree( GetProcessHeap(), 0, resSection );
HeapFree( GetProcessHeap(), 0, sections );
return FALSE;
}
if ( resSectionSize != LZRead( lzfd, resSection, resSectionSize ) ) goto done;
/* Find resource */
resDir = resSection + (resDataDir->VirtualAddress - sections[i].VirtualAddress);
resPtr = (PIMAGE_RESOURCE_DIRECTORY)resDir;
resPtr = GetResDirEntryA( resPtr, typeid, resDir, FALSE );
resPtr = find_entry_by_name( resPtr, typeid, resDir );
if ( !resPtr )
{
TRACE("No typeid entry found for %p\n", typeid );
HeapFree( GetProcessHeap(), 0, resSection );
HeapFree( GetProcessHeap(), 0, sections );
return FALSE;
goto done;
}
resPtr = GetResDirEntryA( resPtr, resid, resDir, FALSE );
resPtr = find_entry_by_name( resPtr, resid, resDir );
if ( !resPtr )
{
TRACE("No resid entry found for %p\n", resid );
HeapFree( GetProcessHeap(), 0, resSection );
HeapFree( GetProcessHeap(), 0, sections );
return FALSE;
goto done;
}
resPtr = GetResDirEntryA( resPtr, 0, resDir, TRUE );
resPtr = find_entry_default( resPtr, resDir );
if ( !resPtr )
{
TRACE("No default language entry found for %p\n", resid );
HeapFree( GetProcessHeap(), 0, resSection );
HeapFree( GetProcessHeap(), 0, sections );
return FALSE;
goto done;
}
/* Find resource data section */
@ -228,27 +309,27 @@ static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
if ( i == nSections )
{
TRACE("Couldn't find resource data section\n" );
HeapFree( GetProcessHeap(), 0, resSection );
HeapFree( GetProcessHeap(), 0, sections );
return FALSE;
goto done;
}
/* Return resource data */
if ( resLen ) *resLen = resData->Size;
if ( resOff ) *resOff = resData->OffsetToData - sections[i].VirtualAddress
+ sections[i].PointerToRawData;
ret = TRUE;
done:
HeapFree( GetProcessHeap(), 0, resSection );
HeapFree( GetProcessHeap(), 0, sections );
return TRUE;
return ret;
}
/***********************************************************************
* GetFileResourceSize32 [internal]
/*************************************************************************
* GetFileResourceSize16 [VER.2]
*/
DWORD WINAPI GetFileResourceSize( LPCSTR lpszFileName,
LPCSTR lpszResType, LPCSTR lpszResId,
LPDWORD lpdwFileOffset )
DWORD WINAPI GetFileResourceSize16( LPCSTR lpszFileName, LPCSTR lpszResType,
LPCSTR lpszResId, LPDWORD lpdwFileOffset )
{
BOOL retv = FALSE;
HFILE lzfd;
@ -279,12 +360,12 @@ DWORD WINAPI GetFileResourceSize( LPCSTR lpszFileName,
return retv? reslen : 0;
}
/***********************************************************************
* GetFileResource32 [internal]
/*************************************************************************
* GetFileResource16 [VER.3]
*/
DWORD WINAPI GetFileResource( LPCSTR lpszFileName,
LPCSTR lpszResType, LPCSTR lpszResId,
DWORD dwFileOffset,
DWORD WINAPI GetFileResource16( LPCSTR lpszFileName, LPCSTR lpszResType,
LPCSTR lpszResId, DWORD dwFileOffset,
DWORD dwResLen, LPVOID lpvData )
{
BOOL retv = FALSE;

View File

@ -4,8 +4,8 @@ owner version
#1 DLLENTRYPOINT
2 pascal GetFileResourceSize(str segptr segptr ptr) GetFileResourceSize16
3 pascal GetFileResource(str segptr segptr long long ptr) GetFileResource16
2 pascal GetFileResourceSize(str str str ptr) GetFileResourceSize16
3 pascal GetFileResource(str str str long long ptr) GetFileResource16
6 pascal GetFileVersionInfoSize(str ptr) GetFileVersionInfoSize16
7 pascal GetFileVersionInfo(str long long ptr) GetFileVersionInfo16
8 pascal VerFindFile(word str str str ptr ptr ptr ptr) VerFindFile16

View File

@ -13,39 +13,6 @@
DEFAULT_DEBUG_CHANNEL(ver);
/*************************************************************************
* GetFileResourceSize16 [VER.2]
*/
DWORD WINAPI GetFileResourceSize16( LPCSTR lpszFileName,
SEGPTR spszResType, SEGPTR spszResId,
LPDWORD lpdwFileOffset )
{
LPCSTR lpszResType = HIWORD( spszResType )? PTR_SEG_TO_LIN( spszResType )
: (LPCSTR)spszResType;
LPCSTR lpszResId = HIWORD( spszResId )? PTR_SEG_TO_LIN( spszResId )
: (LPCSTR)spszResId;
return GetFileResourceSize( lpszFileName,
lpszResType, lpszResId, lpdwFileOffset );
}
/*************************************************************************
* GetFileResource16 [VER.3]
*/
DWORD WINAPI GetFileResource16( LPCSTR lpszFileName,
SEGPTR spszResType, SEGPTR spszResId,
DWORD dwFileOffset,
DWORD dwResLen, LPVOID lpvData )
{
LPCSTR lpszResType = HIWORD( spszResType )? PTR_SEG_TO_LIN( spszResType )
: (LPCSTR)spszResType;
LPCSTR lpszResId = HIWORD( spszResId )? PTR_SEG_TO_LIN( spszResId )
: (LPCSTR)spszResId;
return GetFileResource( lpszFileName, lpszResType, lpszResId,
dwFileOffset, dwResLen, lpvData );
}
/*************************************************************************
* GetFileVersionInfoSize16 [VER.6]
*/

View File

@ -960,8 +960,8 @@ VOID WINAPI EnableSystemTimers16(void);
BOOL16 WINAPI EnumTaskWindows16(HTASK16,WNDENUMPROC16,LPARAM);
BOOL16 WINAPI GrayString16(HDC16,HBRUSH16,GRAYSTRINGPROC16,LPARAM,
INT16,INT16,INT16,INT16,INT16);
DWORD WINAPI GetFileResourceSize16(LPCSTR,SEGPTR,SEGPTR,LPDWORD);
DWORD WINAPI GetFileResource16(LPCSTR,SEGPTR,SEGPTR,DWORD,DWORD,LPVOID);
DWORD WINAPI GetFileResourceSize16(LPCSTR,LPCSTR,LPCSTR,LPDWORD);
DWORD WINAPI GetFileResource16(LPCSTR,LPCSTR,LPCSTR,DWORD,DWORD,LPVOID);
BYTE WINAPI GetTempDrive(BYTE);
FARPROC16 WINAPI SetTaskSignalProc(HTASK16,FARPROC16);

View File

@ -164,18 +164,6 @@ DWORD WINAPI GetFileVersionInfoW(LPCWSTR,DWORD,DWORD,LPVOID);
/* 20 GETFILEVERSIONINFORAW */
#ifdef __WINE__
DWORD WINAPI GetFileResourceSize( LPCSTR lpszFileName,
LPCSTR lpszResType, LPCSTR lpszResId,
LPDWORD lpdwFileOffset );
DWORD WINAPI GetFileResource( LPCSTR lpszFileName,
LPCSTR lpszResType, LPCSTR lpszResId,
DWORD dwFileOffset,
DWORD dwResLen, LPVOID lpvData );
#endif /* __WINE__ */
#endif /* RC_INVOKED */
#ifdef __cplusplus