2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-31 11:11:54 +01:00
|
|
|
* Implementation of VERSION.DLL - Resource Access routines
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-31 11:11:54 +01:00
|
|
|
* Copyright 1996,1997 Marcus Meissner
|
|
|
|
* Copyright 1997 David Cuthbert
|
|
|
|
* Copyright 1999 Ulrich Weigand
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
|
|
|
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-01-31 11:11:54 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-02-10 23:15:21 +01:00
|
|
|
#include <sys/types.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2000-11-16 01:28:52 +01:00
|
|
|
#include "winbase.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "lzexpand.h"
|
2000-10-23 03:38:29 +02:00
|
|
|
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "wine/winuser16.h"
|
1999-02-17 14:51:06 +01:00
|
|
|
#include "winver.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ver);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-10-23 03:38:29 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* 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;
|
2000-12-19 04:38:53 +01:00
|
|
|
if (entry[pos].u1.s2.Id == id)
|
2000-12-20 00:31:52 +01:00
|
|
|
return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].u2.s3.OffsetToDirectory);
|
2000-12-19 04:38:53 +01:00
|
|
|
if (entry[pos].u1.s2.Id > id) max = pos - 1;
|
2000-10-23 03:38:29 +02:00
|
|
|
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);
|
2000-12-20 00:31:52 +01:00
|
|
|
return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry->u2.s3.OffsetToDirectory);
|
2000-10-23 03:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* 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;
|
2000-11-16 01:28:52 +01:00
|
|
|
DWORD namelen;
|
2000-10-23 03:38:29 +02:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
namelen = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
|
|
|
|
if ((nameW = HeapAlloc( GetProcessHeap(), 0, namelen * sizeof(WCHAR) )))
|
2000-10-23 03:38:29 +02:00
|
|
|
{
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
|
|
|
|
const IMAGE_RESOURCE_DIR_STRING_U *str;
|
2000-11-16 01:28:52 +01:00
|
|
|
int min, max, res, pos;
|
2000-10-23 03:38:29 +02:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, namelen );
|
|
|
|
namelen--; /* remove terminating null */
|
2000-10-23 03:38:29 +02:00
|
|
|
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
|
|
|
min = 0;
|
|
|
|
max = dir->NumberOfNamedEntries - 1;
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
pos = (min + max) / 2;
|
2000-11-10 23:34:39 +01:00
|
|
|
str = (IMAGE_RESOURCE_DIR_STRING_U *)((char *)root + entry[pos].u1.s1.NameOffset);
|
2000-10-23 03:38:29 +02:00
|
|
|
res = strncmpiW( nameW, str->NameString, str->Length );
|
|
|
|
if (!res && namelen == str->Length)
|
|
|
|
{
|
2000-12-20 00:31:52 +01:00
|
|
|
ret = (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].u2.s3.OffsetToDirectory);
|
2000-10-23 03:38:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res < 0) max = pos - 1;
|
|
|
|
else min = pos + 1;
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, nameW );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-31 11:11:54 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* read_xx_header [internal]
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static int read_xx_header( HFILE lzfd )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
IMAGE_DOS_HEADER mzh;
|
|
|
|
char magic[3];
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
LZSeek( lzfd, 0, SEEK_SET );
|
2003-04-30 19:15:06 +02:00
|
|
|
if ( sizeof(mzh) != LZRead( lzfd, (LPSTR)&mzh, sizeof(mzh) ) )
|
1999-01-31 11:11:54 +01:00
|
|
|
return 0;
|
|
|
|
if ( mzh.e_magic != IMAGE_DOS_SIGNATURE )
|
|
|
|
return 0;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
LZSeek( lzfd, mzh.e_lfanew, SEEK_SET );
|
|
|
|
if ( 2 != LZRead( lzfd, magic, 2 ) )
|
1999-01-31 11:11:54 +01:00
|
|
|
return 0;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
LZSeek( lzfd, mzh.e_lfanew, SEEK_SET );
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
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';
|
1999-05-14 10:17:14 +02:00
|
|
|
WARN("Can't handle %s files.\n", magic );
|
1999-01-31 11:11:54 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* load_ne_resource [internal]
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static BOOL find_ne_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
1999-01-31 11:11:54 +01:00
|
|
|
DWORD *resLen, DWORD *resOff )
|
|
|
|
{
|
|
|
|
IMAGE_OS2_HEADER nehd;
|
|
|
|
NE_TYPEINFO *typeInfo;
|
|
|
|
NE_NAMEINFO *nameInfo;
|
|
|
|
DWORD nehdoffset;
|
|
|
|
LPBYTE resTab;
|
|
|
|
DWORD resTabSize;
|
2000-11-16 01:28:52 +01:00
|
|
|
int count;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Read in NE header */
|
1999-02-26 12:11:13 +01:00
|
|
|
nehdoffset = LZSeek( lzfd, 0, SEEK_CUR );
|
2003-04-30 19:15:06 +02:00
|
|
|
if ( sizeof(nehd) != LZRead( lzfd, (LPSTR)&nehd, sizeof(nehd) ) ) return 0;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
resTabSize = nehd.ne_restab - nehd.ne_rsrctab;
|
1999-01-31 11:11:54 +01:00
|
|
|
if ( !resTabSize )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("No resources in NE dll\n" );
|
1999-01-31 11:11:54 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Read in resource table */
|
1999-01-31 11:11:54 +01:00
|
|
|
resTab = HeapAlloc( GetProcessHeap(), 0, resTabSize );
|
|
|
|
if ( !resTab ) return FALSE;
|
|
|
|
|
2000-04-18 13:58:24 +02:00
|
|
|
LZSeek( lzfd, nehd.ne_rsrctab + nehdoffset, SEEK_SET );
|
1999-02-26 12:11:13 +01:00
|
|
|
if ( resTabSize != LZRead( lzfd, resTab, resTabSize ) )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, resTab );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find resource */
|
|
|
|
typeInfo = (NE_TYPEINFO *)(resTab + 2);
|
2000-11-16 01:28:52 +01:00
|
|
|
|
|
|
|
if (HIWORD(typeid) != 0) /* named type */
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
BYTE len = strlen( typeid );
|
|
|
|
while (typeInfo->type_id)
|
|
|
|
{
|
|
|
|
if (!(typeInfo->type_id & 0x8000))
|
|
|
|
{
|
|
|
|
BYTE *p = resTab + typeInfo->type_id;
|
|
|
|
if ((*p == len) && !strncasecmp( p+1, typeid, len )) goto found_type;
|
|
|
|
}
|
|
|
|
typeInfo = (NE_TYPEINFO *)((char *)(typeInfo + 1) +
|
|
|
|
typeInfo->count * sizeof(NE_NAMEINFO));
|
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
2000-11-16 01:28:52 +01:00
|
|
|
else /* numeric type id */
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
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));
|
|
|
|
}
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
2000-11-16 01:28:52 +01:00
|
|
|
TRACE("No typeid entry found for %p\n", typeid );
|
|
|
|
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( 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 );
|
|
|
|
HeapFree( GetProcessHeap(), 0, resTab );
|
|
|
|
return FALSE;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
found_name:
|
1999-01-31 11:11:54 +01:00
|
|
|
/* Return resource data */
|
1999-02-09 15:15:48 +01:00
|
|
|
if ( resLen ) *resLen = nameInfo->length << *(WORD *)resTab;
|
|
|
|
if ( resOff ) *resOff = nameInfo->offset << *(WORD *)resTab;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, resTab );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* load_pe_resource [internal]
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
1999-01-31 11:11:54 +01:00
|
|
|
DWORD *resLen, DWORD *resOff )
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS pehd;
|
|
|
|
DWORD pehdoffset;
|
|
|
|
PIMAGE_DATA_DIRECTORY resDataDir;
|
|
|
|
PIMAGE_SECTION_HEADER sections;
|
|
|
|
LPBYTE resSection;
|
|
|
|
DWORD resSectionSize;
|
2000-10-19 22:29:53 +02:00
|
|
|
const void *resDir;
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY *resPtr;
|
|
|
|
const IMAGE_RESOURCE_DATA_ENTRY *resData;
|
1999-01-31 11:11:54 +01:00
|
|
|
int i, nSections;
|
2000-10-23 03:38:29 +02:00
|
|
|
BOOL ret = FALSE;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
/* Read in PE header */
|
1999-02-26 12:11:13 +01:00
|
|
|
pehdoffset = LZSeek( lzfd, 0, SEEK_CUR );
|
2003-04-30 19:15:06 +02:00
|
|
|
if ( sizeof(pehd) != LZRead( lzfd, (LPSTR)&pehd, sizeof(pehd) ) ) return 0;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
resDataDir = pehd.OptionalHeader.DataDirectory+IMAGE_FILE_RESOURCE_DIRECTORY;
|
|
|
|
if ( !resDataDir->Size )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("No resources in PE dll\n" );
|
1999-01-31 11:11:54 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in section table */
|
2002-06-01 01:06:46 +02:00
|
|
|
nSections = pehd.FileHeader.NumberOfSections;
|
|
|
|
sections = HeapAlloc( GetProcessHeap(), 0,
|
1999-01-31 11:11:54 +01:00
|
|
|
nSections * sizeof(IMAGE_SECTION_HEADER) );
|
|
|
|
if ( !sections ) return FALSE;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
LZSeek( lzfd, pehdoffset +
|
1999-01-31 11:11:54 +01:00
|
|
|
sizeof(DWORD) + /* Signature */
|
|
|
|
sizeof(IMAGE_FILE_HEADER) +
|
|
|
|
pehd.FileHeader.SizeOfOptionalHeader, SEEK_SET );
|
|
|
|
|
|
|
|
if ( nSections * sizeof(IMAGE_SECTION_HEADER) !=
|
2003-04-30 19:15:06 +02:00
|
|
|
LZRead( lzfd, (LPSTR)sections, nSections * sizeof(IMAGE_SECTION_HEADER) ) )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, sections );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find resource section */
|
|
|
|
for ( i = 0; i < nSections; i++ )
|
|
|
|
if ( resDataDir->VirtualAddress >= sections[i].VirtualAddress
|
|
|
|
&& resDataDir->VirtualAddress < sections[i].VirtualAddress +
|
|
|
|
sections[i].SizeOfRawData )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( i == nSections )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, sections );
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("Couldn't find resource section\n" );
|
1999-01-31 11:11:54 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in resource section */
|
2002-06-01 01:06:46 +02:00
|
|
|
resSectionSize = sections[i].SizeOfRawData;
|
1999-01-31 11:11:54 +01:00
|
|
|
resSection = HeapAlloc( GetProcessHeap(), 0, resSectionSize );
|
2002-06-01 01:06:46 +02:00
|
|
|
if ( !resSection )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, sections );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
LZSeek( lzfd, sections[i].PointerToRawData, SEEK_SET );
|
2000-10-23 03:38:29 +02:00
|
|
|
if ( resSectionSize != LZRead( lzfd, resSection, resSectionSize ) ) goto done;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
/* Find resource */
|
2000-10-19 22:29:53 +02:00
|
|
|
resDir = resSection + (resDataDir->VirtualAddress - sections[i].VirtualAddress);
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
resPtr = (PIMAGE_RESOURCE_DIRECTORY)resDir;
|
2000-10-23 03:38:29 +02:00
|
|
|
resPtr = find_entry_by_name( resPtr, typeid, resDir );
|
1999-01-31 11:11:54 +01:00
|
|
|
if ( !resPtr )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("No typeid entry found for %p\n", typeid );
|
2000-10-23 03:38:29 +02:00
|
|
|
goto done;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
2000-10-23 03:38:29 +02:00
|
|
|
resPtr = find_entry_by_name( resPtr, resid, resDir );
|
1999-01-31 11:11:54 +01:00
|
|
|
if ( !resPtr )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("No resid entry found for %p\n", resid );
|
2000-10-23 03:38:29 +02:00
|
|
|
goto done;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
2000-10-23 03:38:29 +02:00
|
|
|
resPtr = find_entry_default( resPtr, resDir );
|
1999-01-31 11:11:54 +01:00
|
|
|
if ( !resPtr )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("No default language entry found for %p\n", resid );
|
2000-10-23 03:38:29 +02:00
|
|
|
goto done;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find resource data section */
|
|
|
|
resData = (PIMAGE_RESOURCE_DATA_ENTRY)resPtr;
|
|
|
|
for ( i = 0; i < nSections; i++ )
|
|
|
|
if ( resData->OffsetToData >= sections[i].VirtualAddress
|
|
|
|
&& resData->OffsetToData < sections[i].VirtualAddress +
|
|
|
|
sections[i].SizeOfRawData )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( i == nSections )
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("Couldn't find resource data section\n" );
|
2000-10-23 03:38:29 +02:00
|
|
|
goto done;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return resource data */
|
1999-02-09 15:15:48 +01:00
|
|
|
if ( resLen ) *resLen = resData->Size;
|
|
|
|
if ( resOff ) *resOff = resData->OffsetToData - sections[i].VirtualAddress
|
|
|
|
+ sections[i].PointerToRawData;
|
2000-10-23 03:38:29 +02:00
|
|
|
ret = TRUE;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
2000-10-23 03:38:29 +02:00
|
|
|
done:
|
1999-01-31 11:11:54 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, resSection );
|
|
|
|
HeapFree( GetProcessHeap(), 0, sections );
|
2000-10-23 03:38:29 +02:00
|
|
|
return ret;
|
1999-01-31 11:11:54 +01:00
|
|
|
}
|
|
|
|
|
2000-10-23 03:38:29 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* GetFileResourceSize [VER.2]
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
2000-10-23 03:38:29 +02:00
|
|
|
DWORD WINAPI GetFileResourceSize16( LPCSTR lpszFileName, LPCSTR lpszResType,
|
|
|
|
LPCSTR lpszResId, LPDWORD lpdwFileOffset )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL retv = FALSE;
|
|
|
|
HFILE lzfd;
|
1999-01-31 11:11:54 +01:00
|
|
|
OFSTRUCT ofs;
|
|
|
|
DWORD reslen;
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("(%s,type=0x%lx,id=0x%lx,off=%p)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
debugstr_a(lpszFileName), (LONG)lpszResType, (LONG)lpszResId,
|
1999-01-31 11:11:54 +01:00
|
|
|
lpszResId );
|
|
|
|
|
2003-04-30 19:15:06 +02:00
|
|
|
lzfd = LZOpenFileA( (LPSTR)lpszFileName, &ofs, OF_READ );
|
2001-01-02 20:56:21 +01:00
|
|
|
if ( lzfd < 0 ) return 0;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
switch ( read_xx_header( lzfd ) )
|
|
|
|
{
|
|
|
|
case IMAGE_OS2_SIGNATURE:
|
2002-06-01 01:06:46 +02:00
|
|
|
retv = find_ne_resource( lzfd, lpszResType, lpszResId,
|
1999-01-31 11:11:54 +01:00
|
|
|
&reslen, lpdwFileOffset );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMAGE_NT_SIGNATURE:
|
2002-06-01 01:06:46 +02:00
|
|
|
retv = find_pe_resource( lzfd, lpszResType, lpszResId,
|
1999-01-31 11:11:54 +01:00
|
|
|
&reslen, lpdwFileOffset );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
LZClose( lzfd );
|
1999-01-31 11:11:54 +01:00
|
|
|
return retv? reslen : 0;
|
|
|
|
}
|
|
|
|
|
2000-10-23 03:38:29 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* GetFileResource [VER.3]
|
1999-01-31 11:11:54 +01:00
|
|
|
*/
|
2000-10-23 03:38:29 +02:00
|
|
|
DWORD WINAPI GetFileResource16( LPCSTR lpszFileName, LPCSTR lpszResType,
|
|
|
|
LPCSTR lpszResId, DWORD dwFileOffset,
|
1999-01-31 11:11:54 +01:00
|
|
|
DWORD dwResLen, LPVOID lpvData )
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL retv = FALSE;
|
|
|
|
HFILE lzfd;
|
1999-01-31 11:11:54 +01:00
|
|
|
OFSTRUCT ofs;
|
1999-02-02 11:39:33 +01:00
|
|
|
DWORD reslen = dwResLen;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
TRACE("(%s,type=0x%lx,id=0x%lx,off=%ld,len=%ld,data=%p)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
debugstr_a(lpszFileName), (LONG)lpszResType, (LONG)lpszResId,
|
1999-01-31 11:11:54 +01:00
|
|
|
dwFileOffset, dwResLen, lpvData );
|
|
|
|
|
2003-04-30 19:15:06 +02:00
|
|
|
lzfd = LZOpenFileA( (LPSTR)lpszFileName, &ofs, OF_READ );
|
2001-01-02 20:56:21 +01:00
|
|
|
if ( lzfd < 0 ) return 0;
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
if ( !dwFileOffset )
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
switch ( read_xx_header( lzfd ) )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
|
|
|
case IMAGE_OS2_SIGNATURE:
|
2002-06-01 01:06:46 +02:00
|
|
|
retv = find_ne_resource( lzfd, lpszResType, lpszResId,
|
1999-01-31 11:11:54 +01:00
|
|
|
&reslen, &dwFileOffset );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMAGE_NT_SIGNATURE:
|
2002-06-01 01:06:46 +02:00
|
|
|
retv = find_pe_resource( lzfd, lpszResType, lpszResId,
|
1999-01-31 11:11:54 +01:00
|
|
|
&reslen, &dwFileOffset );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if ( !retv )
|
1999-01-31 11:11:54 +01:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
LZClose( lzfd );
|
1999-01-31 11:11:54 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
LZSeek( lzfd, dwFileOffset, SEEK_SET );
|
|
|
|
reslen = LZRead( lzfd, lpvData, min( reslen, dwResLen ) );
|
|
|
|
LZClose( lzfd );
|
1999-01-31 11:11:54 +01:00
|
|
|
|
|
|
|
return reslen;
|
|
|
|
}
|
|
|
|
|