mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-05 17:09:37 +00:00
Use a binary search to find entries in resource directories.
Fixed GetResDirEntryA/W prototypes.
This commit is contained in:
parent
cc7abe1f06
commit
81800b1f6d
|
@ -791,10 +791,10 @@ HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance,
|
|||
PIMAGE_DOS_HEADER dheader;
|
||||
PIMAGE_NT_HEADERS pe_header;
|
||||
PIMAGE_SECTION_HEADER pe_sections;
|
||||
PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
|
||||
PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
|
||||
const IMAGE_RESOURCE_DIRECTORY *rootresdir,*iconresdir,*icongroupresdir;
|
||||
const IMAGE_RESOURCE_DATA_ENTRY *idataent,*igdataent;
|
||||
int i,j;
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
|
||||
CURSORICONDIR **cids;
|
||||
|
||||
fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL);
|
||||
|
@ -836,7 +836,7 @@ HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance,
|
|||
goto end_4; /* failure */
|
||||
}
|
||||
|
||||
icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE);
|
||||
icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, rootresdir,FALSE);
|
||||
|
||||
if (!icongroupresdir)
|
||||
{ WARN("No Icongroupresourcedirectory!\n");
|
||||
|
@ -870,14 +870,15 @@ HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance,
|
|||
xresent = xresent+nIconIndex;
|
||||
|
||||
for (i=0;i<n;i++,xresent++)
|
||||
{ CURSORICONDIR *cid;
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir;
|
||||
{
|
||||
CURSORICONDIR *cid;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir;
|
||||
|
||||
/* go down this resource entry, name */
|
||||
resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
|
||||
|
||||
/* default language (0) */
|
||||
resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
||||
resdir = GetResDirEntryW(resdir,(LPWSTR)0,rootresdir,TRUE);
|
||||
igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
|
||||
|
||||
/* lookup address in mapped image for virtual address */
|
||||
|
@ -901,7 +902,7 @@ HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance,
|
|||
RetPtr[i] = LookupIconIdFromDirectoryEx(igdata,TRUE,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);
|
||||
}
|
||||
|
||||
iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE);
|
||||
iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,rootresdir,FALSE);
|
||||
|
||||
if (!iconresdir)
|
||||
{ WARN("No Iconresourcedirectory!\n");
|
||||
|
@ -909,9 +910,10 @@ HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance,
|
|||
}
|
||||
|
||||
for (i=0;i<n;i++)
|
||||
{ PIMAGE_RESOURCE_DIRECTORY xresdir;
|
||||
xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
|
||||
xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
||||
{
|
||||
const IMAGE_RESOURCE_DIRECTORY *xresdir;
|
||||
xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],rootresdir,FALSE);
|
||||
xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,rootresdir,TRUE);
|
||||
idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
|
||||
idata = NULL;
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ static BYTE * ICO_GetIconDirectory( LPBYTE peimage, LPicoICONDIR* lplpiID, ULONG
|
|||
* returns
|
||||
* failure:0; success: icon handle or nr of icons (nIconIndex-1)
|
||||
*/
|
||||
static HRESULT WINAPI ICO_ExtractIconExW(
|
||||
static HRESULT ICO_ExtractIconExW(
|
||||
LPCWSTR lpszExeFileName,
|
||||
HICON * RetPtr,
|
||||
INT nIconIndex,
|
||||
|
@ -202,18 +202,20 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
|
||||
/* Map the file */
|
||||
fmapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL );
|
||||
CloseHandle( hFile );
|
||||
if (!fmapping)
|
||||
{
|
||||
WARN("CreateFileMapping error %ld\n", GetLastError() );
|
||||
goto end_1;
|
||||
return hRet;
|
||||
}
|
||||
|
||||
if ( !(peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0)))
|
||||
{
|
||||
WARN("MapViewOfFile error %ld\n", GetLastError() );
|
||||
goto end_2;
|
||||
CloseHandle( fmapping );
|
||||
return hRet;
|
||||
}
|
||||
|
||||
CloseHandle( fmapping );
|
||||
|
||||
sig = USER32_GetResourceTable(peimage,&pData);
|
||||
|
||||
|
@ -303,9 +305,9 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
PIMAGE_DOS_HEADER dheader;
|
||||
PIMAGE_NT_HEADERS pe_header;
|
||||
PIMAGE_SECTION_HEADER pe_sections;
|
||||
PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
|
||||
PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
|
||||
const IMAGE_RESOURCE_DIRECTORY *rootresdir,*iconresdir,*icongroupresdir;
|
||||
const IMAGE_RESOURCE_DATA_ENTRY *idataent,*igdataent;
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
|
||||
int i,j;
|
||||
|
||||
dheader = (PIMAGE_DOS_HEADER)peimage;
|
||||
|
@ -329,14 +331,14 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
if (!rootresdir)
|
||||
{
|
||||
WARN("haven't found section for resource directory.\n");
|
||||
goto end_3; /* failure */
|
||||
goto end; /* failure */
|
||||
}
|
||||
|
||||
/* search for the group icon directory */
|
||||
if (!(icongroupresdir = GetResDirEntryW(rootresdir, RT_GROUP_ICONW, (DWORD)rootresdir, FALSE)))
|
||||
if (!(icongroupresdir = GetResDirEntryW(rootresdir, RT_GROUP_ICONW, rootresdir, FALSE)))
|
||||
{
|
||||
WARN("No Icongroupresourcedirectory!\n");
|
||||
goto end_3; /* failure */
|
||||
goto end; /* failure */
|
||||
}
|
||||
iconDirCount = icongroupresdir->NumberOfNamedEntries + icongroupresdir->NumberOfIdEntries;
|
||||
|
||||
|
@ -344,7 +346,7 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
if( nIcons == 0 )
|
||||
{
|
||||
hRet = iconDirCount;
|
||||
goto end_3; /* success */
|
||||
goto end; /* success */
|
||||
}
|
||||
|
||||
if( nIconIndex < 0 )
|
||||
|
@ -367,7 +369,7 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
if (nIconIndex < 0)
|
||||
{
|
||||
WARN("resource id %d not found\n", iId);
|
||||
goto end_3; /* failure */
|
||||
goto end; /* failure */
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -376,7 +378,7 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
if (nIconIndex >= iconDirCount)
|
||||
{
|
||||
WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
|
||||
goto end_3; /* failure */
|
||||
goto end; /* failure */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,13 +391,13 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
|
||||
for (i=0; i < nIcons; i++,xresent++)
|
||||
{
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir;
|
||||
|
||||
/* go down this resource entry, name */
|
||||
resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
|
||||
|
||||
/* default language (0) */
|
||||
resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
||||
resdir = GetResDirEntryW(resdir,(LPWSTR)0,rootresdir,TRUE);
|
||||
igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
|
||||
|
||||
/* lookup address in mapped image for virtual address */
|
||||
|
@ -413,22 +415,22 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
if (!igdata)
|
||||
{
|
||||
WARN("no matching real address for icongroup!\n");
|
||||
goto end_3; /* failure */
|
||||
goto end; /* failure */
|
||||
}
|
||||
RetPtr[i] = (HICON)LookupIconIdFromDirectoryEx(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
||||
}
|
||||
|
||||
if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE)))
|
||||
if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,rootresdir,FALSE)))
|
||||
{
|
||||
WARN("No Iconresourcedirectory!\n");
|
||||
goto end_3; /* failure */
|
||||
goto end; /* failure */
|
||||
}
|
||||
|
||||
for (i=0; i<nIcons; i++)
|
||||
{
|
||||
PIMAGE_RESOURCE_DIRECTORY xresdir;
|
||||
xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
|
||||
xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
||||
const IMAGE_RESOURCE_DIRECTORY *xresdir;
|
||||
xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],rootresdir,FALSE);
|
||||
xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,rootresdir,TRUE);
|
||||
idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
|
||||
idata = NULL;
|
||||
|
||||
|
@ -450,12 +452,9 @@ static HRESULT WINAPI ICO_ExtractIconExW(
|
|||
RetPtr[i] = (HICON) CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
||||
}
|
||||
hRet = S_OK; /* return first icon */
|
||||
goto end_3; /* sucess */
|
||||
} /* if(sig == IMAGE_NT_SIGNATURE) */
|
||||
|
||||
end_3: UnmapViewOfFile(peimage); /* success */
|
||||
end_2: CloseHandle(fmapping);
|
||||
end_1: _lclose( hFile);
|
||||
end: UnmapViewOfFile(peimage); /* success */
|
||||
return hRet;
|
||||
}
|
||||
|
||||
|
@ -509,7 +508,7 @@ HRESULT WINAPI PrivateExtractIconsW (
|
|||
|
||||
HRESULT WINAPI PrivateExtractIconsA (
|
||||
LPCSTR lpstrFile,
|
||||
DWORD nIndex,
|
||||
INT nIndex,
|
||||
DWORD sizeX,
|
||||
DWORD sizeY,
|
||||
HICON * phicon,
|
||||
|
@ -520,7 +519,7 @@ HRESULT WINAPI PrivateExtractIconsA (
|
|||
DWORD ret;
|
||||
LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile);
|
||||
|
||||
FIXME_(icon)("%s 0x%08lx 0x%08lx 0x%08lx %p 0x%08lx 0x%08x 0x%08lx stub\n",
|
||||
FIXME_(icon)("%s 0x%08x 0x%08lx 0x%08lx %p 0x%08lx 0x%08x 0x%08lx stub\n",
|
||||
lpstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y );
|
||||
|
||||
ret = PrivateExtractIconsW(lpwstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y);
|
||||
|
|
|
@ -122,9 +122,9 @@ static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
|||
PIMAGE_SECTION_HEADER sections;
|
||||
LPBYTE resSection;
|
||||
DWORD resSectionSize;
|
||||
DWORD resDir;
|
||||
PIMAGE_RESOURCE_DIRECTORY resPtr;
|
||||
PIMAGE_RESOURCE_DATA_ENTRY resData;
|
||||
const void *resDir;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resPtr;
|
||||
const IMAGE_RESOURCE_DATA_ENTRY *resData;
|
||||
int i, nSections;
|
||||
|
||||
|
||||
|
@ -189,8 +189,7 @@ static BOOL find_pe_resource( HFILE lzfd, LPCSTR typeid, LPCSTR resid,
|
|||
}
|
||||
|
||||
/* Find resource */
|
||||
resDir = (DWORD)resSection +
|
||||
(resDataDir->VirtualAddress - sections[i].VirtualAddress);
|
||||
resDir = resSection + (resDataDir->VirtualAddress - sections[i].VirtualAddress);
|
||||
|
||||
resPtr = (PIMAGE_RESOURCE_DIRECTORY)resDir;
|
||||
resPtr = GetResDirEntryA( resPtr, typeid, resDir, FALSE );
|
||||
|
|
|
@ -223,8 +223,10 @@ extern HRSRC PE_FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
|
|||
extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
|
||||
extern DWORD PE_SizeofResource(HRSRC);
|
||||
extern HGLOBAL PE_LoadResource(HMODULE,HRSRC);
|
||||
extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA(PIMAGE_RESOURCE_DIRECTORY,LPCSTR,DWORD,BOOL);
|
||||
extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY,LPCWSTR,DWORD,BOOL);
|
||||
extern const IMAGE_RESOURCE_DIRECTORY *GetResDirEntryA(const IMAGE_RESOURCE_DIRECTORY*,
|
||||
LPCSTR,LPCVOID,BOOL);
|
||||
extern const IMAGE_RESOURCE_DIRECTORY *GetResDirEntryW(const IMAGE_RESOURCE_DIRECTORY*,
|
||||
LPCWSTR,LPCVOID,BOOL);
|
||||
|
||||
/* loader/pe_image.c */
|
||||
extern WINE_MODREF *PE_LoadLibraryExA(LPCSTR, DWORD);
|
||||
|
|
|
@ -33,10 +33,10 @@ DEFAULT_DEBUG_CHANNEL(resource);
|
|||
*
|
||||
* Get the resource directory of a PE module
|
||||
*/
|
||||
static IMAGE_RESOURCE_DIRECTORY* get_resdir( HMODULE hmod )
|
||||
static const IMAGE_RESOURCE_DIRECTORY* get_resdir( HMODULE hmod )
|
||||
{
|
||||
IMAGE_DATA_DIRECTORY *dir;
|
||||
IMAGE_RESOURCE_DIRECTORY *ret = NULL;
|
||||
const IMAGE_DATA_DIRECTORY *dir;
|
||||
const IMAGE_RESOURCE_DIRECTORY *ret = NULL;
|
||||
|
||||
if (!hmod) hmod = GetModuleHandleA( NULL );
|
||||
else if (!HIWORD(hmod))
|
||||
|
@ -52,69 +52,141 @@ static IMAGE_RESOURCE_DIRECTORY* get_resdir( HMODULE hmod )
|
|||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* find_entry_by_name
|
||||
*
|
||||
* Find an entry by name in a resource directory
|
||||
*/
|
||||
static IMAGE_RESOURCE_DIRECTORY *find_entry_by_name( const IMAGE_RESOURCE_DIRECTORY *dir,
|
||||
LPCWSTR name, const char *root )
|
||||
{
|
||||
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
|
||||
const IMAGE_RESOURCE_DIR_STRING_U *str;
|
||||
int min, max, res, pos, namelen = strlenW(name);
|
||||
|
||||
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 *)(root + entry[pos].u1.s.NameOffset);
|
||||
res = strncmpiW( name, str->NameString, str->Length );
|
||||
if (!res && namelen == str->Length)
|
||||
return (IMAGE_RESOURCE_DIRECTORY *)(root + entry[pos].u2.s.OffsetToDirectory);
|
||||
if (res < 0) max = pos - 1;
|
||||
else min = pos + 1;
|
||||
}
|
||||
|
||||
/* now do a linear search just in case */
|
||||
for (pos = 0; pos < dir->NumberOfNamedEntries; pos++)
|
||||
{
|
||||
str = (IMAGE_RESOURCE_DIR_STRING_U *)(root + entry[pos].u1.s.NameOffset);
|
||||
if (namelen != str->Length) continue;
|
||||
if (!strncmpiW( name, str->NameString, str->Length ))
|
||||
{
|
||||
ERR( "entry '%s' required linear search, please report\n", debugstr_w(name) );
|
||||
return (IMAGE_RESOURCE_DIRECTORY *)(root + entry[pos].u2.s.OffsetToDirectory);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* find_entry_by_id
|
||||
*
|
||||
* Find an entry by id in a resource directory
|
||||
*/
|
||||
static IMAGE_RESOURCE_DIRECTORY *find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
|
||||
WORD id, const char *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 *)(root + entry[pos].u2.s.OffsetToDirectory);
|
||||
if (entry[pos].u1.Id > id) max = pos - 1;
|
||||
else min = pos + 1;
|
||||
}
|
||||
|
||||
/* now do a linear search just in case */
|
||||
min = dir->NumberOfNamedEntries;
|
||||
max = min + dir->NumberOfIdEntries - 1;
|
||||
for (pos = min; pos <= max; pos++)
|
||||
{
|
||||
if (entry[pos].u1.Id == id)
|
||||
{
|
||||
ERR( "entry %04x required linear search, please report\n", id );
|
||||
return (IMAGE_RESOURCE_DIRECTORY *)(root + entry[pos].u2.s.OffsetToDirectory);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* find_entry_default
|
||||
*
|
||||
* Find a default entry in a resource directory
|
||||
*/
|
||||
static IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
|
||||
const char *root )
|
||||
{
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
|
||||
|
||||
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
||||
if (dir->NumberOfNamedEntries || dir->NumberOfIdEntries)
|
||||
return (IMAGE_RESOURCE_DIRECTORY *)(root + entry->u2.s.OffsetToDirectory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* GetResDirEntryW
|
||||
*
|
||||
* Helper function - goes down one level of PE resource tree
|
||||
*
|
||||
*/
|
||||
PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
|
||||
LPCWSTR name,DWORD root,
|
||||
const IMAGE_RESOURCE_DIRECTORY *GetResDirEntryW(const IMAGE_RESOURCE_DIRECTORY *resdirptr,
|
||||
LPCWSTR name, LPCVOID root,
|
||||
BOOL allowdefault)
|
||||
{
|
||||
int entrynum;
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
|
||||
int namelen;
|
||||
|
||||
if (HIWORD(name)) {
|
||||
if (name[0]=='#') {
|
||||
if (HIWORD(name))
|
||||
{
|
||||
if (name[0]=='#')
|
||||
{
|
||||
char buf[10];
|
||||
if (!WideCharToMultiByte( CP_ACP, 0, name+1, -1, buf, sizeof(buf), NULL, NULL ))
|
||||
return NULL;
|
||||
return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
|
||||
return find_entry_by_id( resdirptr, atoi(buf), root );
|
||||
}
|
||||
entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdirptr + 1);
|
||||
namelen = strlenW(name);
|
||||
for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
|
||||
return find_entry_by_name( resdirptr, name, root );
|
||||
}
|
||||
else
|
||||
{
|
||||
PIMAGE_RESOURCE_DIR_STRING_U str =
|
||||
(PIMAGE_RESOURCE_DIR_STRING_U) (root +
|
||||
entryTable[entrynum].u1.s.NameOffset);
|
||||
if(namelen != str->Length)
|
||||
continue;
|
||||
if(strncmpiW(name,str->NameString,str->Length)==0)
|
||||
return (PIMAGE_RESOURCE_DIRECTORY) (
|
||||
root +
|
||||
entryTable[entrynum].u2.s.OffsetToDirectory);
|
||||
}
|
||||
return NULL;
|
||||
} else {
|
||||
entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
|
||||
(BYTE *) resdirptr +
|
||||
sizeof(IMAGE_RESOURCE_DIRECTORY) +
|
||||
resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
|
||||
for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
|
||||
if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
|
||||
return (PIMAGE_RESOURCE_DIRECTORY) (
|
||||
root +
|
||||
entryTable[entrynum].u2.s.OffsetToDirectory);
|
||||
/* just use first entry if no default can be found */
|
||||
if (allowdefault && !name && resdirptr->NumberOfIdEntries)
|
||||
return (PIMAGE_RESOURCE_DIRECTORY) (
|
||||
root +
|
||||
entryTable[0].u2.s.OffsetToDirectory);
|
||||
return NULL;
|
||||
const IMAGE_RESOURCE_DIRECTORY *ret;
|
||||
ret = find_entry_by_id( resdirptr, LOWORD(name), root );
|
||||
if (!ret && !name && allowdefault) ret = find_entry_default( resdirptr, root );
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* GetResDirEntryA
|
||||
*/
|
||||
PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA( PIMAGE_RESOURCE_DIRECTORY resdirptr,
|
||||
LPCSTR name, DWORD root,
|
||||
const IMAGE_RESOURCE_DIRECTORY *GetResDirEntryA( const IMAGE_RESOURCE_DIRECTORY *resdirptr,
|
||||
LPCSTR name, LPCVOID root,
|
||||
BOOL allowdefault )
|
||||
{
|
||||
PIMAGE_RESOURCE_DIRECTORY retv;
|
||||
const IMAGE_RESOURCE_DIRECTORY *retv;
|
||||
LPWSTR nameW = HIWORD(name)? HEAP_strdupAtoW( GetProcessHeap(), 0, name )
|
||||
: (LPWSTR)name;
|
||||
|
||||
|
@ -136,42 +208,34 @@ PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA( PIMAGE_RESOURCE_DIRECTORY resdirptr,
|
|||
*/
|
||||
HRSRC PE_FindResourceExW( HMODULE hmod, LPCWSTR name, LPCWSTR type, WORD lang )
|
||||
{
|
||||
PIMAGE_RESOURCE_DIRECTORY resdirptr = get_resdir(hmod);
|
||||
DWORD root;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdirptr = get_resdir(hmod);
|
||||
const void *root;
|
||||
HRSRC result;
|
||||
|
||||
if (!resdirptr) return 0;
|
||||
|
||||
root = (DWORD) resdirptr;
|
||||
root = resdirptr;
|
||||
if ((resdirptr = GetResDirEntryW(resdirptr, type, root, FALSE)) == NULL)
|
||||
return 0;
|
||||
if ((resdirptr = GetResDirEntryW(resdirptr, name, root, FALSE)) == NULL)
|
||||
return 0;
|
||||
|
||||
/* 1. Exact specified language */
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 2. Language with neutral sublanguage */
|
||||
lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
}
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 3. Neutral language with neutral sublanguage */
|
||||
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
}
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 4. Neutral language with default sublanguage */
|
||||
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
}
|
||||
result = (HRSRC)find_entry_by_id( resdirptr, lang, root );
|
||||
|
||||
found:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -189,14 +253,14 @@ HRSRC PE_FindResourceExW( HMODULE hmod, LPCWSTR name, LPCWSTR type, WORD lang )
|
|||
*/
|
||||
HRSRC PE_FindResourceW( HMODULE hmod, LPCWSTR name, LPCWSTR type )
|
||||
{
|
||||
PIMAGE_RESOURCE_DIRECTORY resdirptr = get_resdir(hmod);
|
||||
DWORD root;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdirptr = get_resdir(hmod);
|
||||
const void *root;
|
||||
HRSRC result;
|
||||
WORD lang;
|
||||
|
||||
if (!resdirptr) return 0;
|
||||
|
||||
root = (DWORD) resdirptr;
|
||||
root = resdirptr;
|
||||
if ((resdirptr = GetResDirEntryW(resdirptr, type, root, FALSE)) == NULL)
|
||||
return 0;
|
||||
if ((resdirptr = GetResDirEntryW(resdirptr, name, root, FALSE)) == NULL)
|
||||
|
@ -204,42 +268,28 @@ HRSRC PE_FindResourceW( HMODULE hmod, LPCWSTR name, LPCWSTR type )
|
|||
|
||||
/* 1. Neutral language with neutral sublanguage */
|
||||
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 2. Neutral language with default sublanguage */
|
||||
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
}
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 3. Current locale lang id */
|
||||
lang = LANGIDFROMLCID(GetUserDefaultLCID());
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
}
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 4. Current locale lang id with neutral sublanguage */
|
||||
lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
}
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 5. (!) LANG_ENGLISH, SUBLANG_DEFAULT */
|
||||
lang = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
|
||||
}
|
||||
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* 6. Return first in the list */
|
||||
result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)0, root, TRUE);
|
||||
}
|
||||
result = (HRSRC)find_entry_default( resdirptr, root );
|
||||
|
||||
found:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -270,8 +320,8 @@ DWORD PE_SizeofResource( HANDLE hRsrc )
|
|||
BOOL WINAPI EnumResourceTypesA( HMODULE hmod, ENUMRESTYPEPROCA lpfun, LONG lparam)
|
||||
{
|
||||
int i;
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir = get_resdir(hmod);
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir = get_resdir(hmod);
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
|
||||
BOOL ret;
|
||||
|
||||
if (!resdir) return FALSE;
|
||||
|
@ -312,8 +362,8 @@ BOOL WINAPI EnumResourceTypesA( HMODULE hmod, ENUMRESTYPEPROCA lpfun, LONG lpara
|
|||
BOOL WINAPI EnumResourceTypesW( HMODULE hmod, ENUMRESTYPEPROCW lpfun, LONG lparam)
|
||||
{
|
||||
int i;
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir = get_resdir(hmod);
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir = get_resdir(hmod);
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
|
||||
BOOL ret;
|
||||
|
||||
if (!resdir) return FALSE;
|
||||
|
@ -351,14 +401,14 @@ BOOL WINAPI EnumResourceTypesW( HMODULE hmod, ENUMRESTYPEPROCW lpfun, LONG lpara
|
|||
BOOL WINAPI EnumResourceNamesA( HMODULE hmod, LPCSTR type, ENUMRESNAMEPROCA lpfun, LONG lparam )
|
||||
{
|
||||
int i;
|
||||
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir;
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
|
||||
const IMAGE_RESOURCE_DIRECTORY *basedir = get_resdir(hmod);
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir;
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
|
||||
BOOL ret;
|
||||
|
||||
if (!basedir) return FALSE;
|
||||
|
||||
if (!(resdir = GetResDirEntryA(basedir,type,(DWORD)basedir,FALSE))) return FALSE;
|
||||
if (!(resdir = GetResDirEntryA(basedir,type,basedir,FALSE))) return FALSE;
|
||||
|
||||
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
|
||||
ret = FALSE;
|
||||
|
@ -396,14 +446,14 @@ BOOL WINAPI EnumResourceNamesA( HMODULE hmod, LPCSTR type, ENUMRESNAMEPROCA lpfu
|
|||
BOOL WINAPI EnumResourceNamesW( HMODULE hmod, LPCWSTR type, ENUMRESNAMEPROCW lpfun, LONG lparam )
|
||||
{
|
||||
int i;
|
||||
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir;
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
|
||||
const IMAGE_RESOURCE_DIRECTORY *basedir = get_resdir(hmod);
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir;
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
|
||||
BOOL ret;
|
||||
|
||||
if (!basedir) return FALSE;
|
||||
|
||||
resdir = GetResDirEntryW(basedir,type,(DWORD)basedir,FALSE);
|
||||
resdir = GetResDirEntryW(basedir,type,basedir,FALSE);
|
||||
if (!resdir)
|
||||
return FALSE;
|
||||
et = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
|
||||
|
@ -440,14 +490,14 @@ BOOL WINAPI EnumResourceLanguagesA( HMODULE hmod, LPCSTR type, LPCSTR name,
|
|||
ENUMRESLANGPROCA lpfun, LONG lparam )
|
||||
{
|
||||
int i;
|
||||
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir;
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
|
||||
const IMAGE_RESOURCE_DIRECTORY *basedir = get_resdir(hmod);
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir;
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
|
||||
BOOL ret;
|
||||
|
||||
if (!basedir) return FALSE;
|
||||
if (!(resdir = GetResDirEntryA(basedir,type,(DWORD)basedir,FALSE))) return FALSE;
|
||||
if (!(resdir = GetResDirEntryA(resdir,name,(DWORD)basedir,FALSE))) return FALSE;
|
||||
if (!(resdir = GetResDirEntryA(basedir,type,basedir,FALSE))) return FALSE;
|
||||
if (!(resdir = GetResDirEntryA(resdir,name,basedir,FALSE))) return FALSE;
|
||||
|
||||
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
|
||||
ret = FALSE;
|
||||
|
@ -468,17 +518,17 @@ BOOL WINAPI EnumResourceLanguagesW( HMODULE hmod, LPCWSTR type, LPCWSTR name,
|
|||
ENUMRESLANGPROCW lpfun, LONG lparam )
|
||||
{
|
||||
int i;
|
||||
PIMAGE_RESOURCE_DIRECTORY basedir = get_resdir(hmod);
|
||||
PIMAGE_RESOURCE_DIRECTORY resdir;
|
||||
PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
|
||||
const IMAGE_RESOURCE_DIRECTORY *basedir = get_resdir(hmod);
|
||||
const IMAGE_RESOURCE_DIRECTORY *resdir;
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
|
||||
BOOL ret;
|
||||
|
||||
if (!basedir) return FALSE;
|
||||
|
||||
resdir = GetResDirEntryW(basedir,type,(DWORD)basedir,FALSE);
|
||||
resdir = GetResDirEntryW(basedir,type,basedir,FALSE);
|
||||
if (!resdir)
|
||||
return FALSE;
|
||||
resdir = GetResDirEntryW(resdir,name,(DWORD)basedir,FALSE);
|
||||
resdir = GetResDirEntryW(resdir,name,basedir,FALSE);
|
||||
if (!resdir)
|
||||
return FALSE;
|
||||
et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resdir + 1);
|
||||
|
|
Loading…
Reference in a new issue