2003-04-30 01:00:48 +02:00
|
|
|
/*
|
|
|
|
* PE file resources
|
|
|
|
*
|
|
|
|
* Copyright 1995 Thomas Sandford
|
|
|
|
* Copyright 1996 Martin von Loewis
|
|
|
|
* Copyright 2003 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* Based on the Win16 resource handling code in loader/resource.c
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
|
|
|
* Copyright 1995 Alexandre Julliard
|
|
|
|
* Copyright 1997 Marcus Meissner
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-04-30 01:00:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2003-11-27 01:59:36 +01:00
|
|
|
#include "wine/port.h"
|
2003-04-30 01:00:48 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-04-30 01:00:48 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2003-04-30 01:00:48 +02:00
|
|
|
#include "windef.h"
|
2003-08-20 20:22:31 +02:00
|
|
|
#include "winbase.h"
|
2003-04-30 01:00:48 +02:00
|
|
|
#include "winnt.h"
|
|
|
|
#include "winternl.h"
|
2019-11-13 20:55:03 +01:00
|
|
|
#include "ntdll_misc.h"
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2003-04-30 01:00:48 +02:00
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(resource);
|
|
|
|
|
2010-02-10 11:43:59 +01:00
|
|
|
#define IS_INTRESOURCE(x) (((ULONG_PTR)(x) >> 16) == 0)
|
|
|
|
|
2003-04-30 01:00:48 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* is_data_file_module
|
|
|
|
*
|
|
|
|
* Check if a module handle is for a LOAD_LIBRARY_AS_DATAFILE module.
|
|
|
|
*/
|
2013-10-29 21:54:12 +01:00
|
|
|
static inline BOOL is_data_file_module( HMODULE hmod )
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
return (ULONG_PTR)hmod & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* push_language
|
|
|
|
*
|
|
|
|
* push a language in the list of languages to try
|
|
|
|
*/
|
|
|
|
static inline int push_language( WORD *list, int pos, WORD lang )
|
|
|
|
{
|
|
|
|
int i;
|
2003-04-30 19:12:14 +02:00
|
|
|
for (i = 0; i < pos; i++) if (list[i] == lang) return pos;
|
2003-04-30 01:00:48 +02:00
|
|
|
list[pos++] = lang;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* find_first_entry
|
|
|
|
*
|
|
|
|
* Find the first suitable entry in a resource directory
|
|
|
|
*/
|
|
|
|
static const IMAGE_RESOURCE_DIRECTORY *find_first_entry( const IMAGE_RESOURCE_DIRECTORY *dir,
|
|
|
|
const void *root, int want_dir )
|
|
|
|
{
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
for (pos = 0; pos < dir->NumberOfNamedEntries + dir->NumberOfIdEntries; pos++)
|
|
|
|
{
|
2013-04-29 09:19:17 +02:00
|
|
|
if (!entry[pos].u2.s2.DataIsDirectory == !want_dir)
|
|
|
|
return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].u2.s2.OffsetToDirectory);
|
2003-04-30 01:00:48 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* find_entry_by_id
|
|
|
|
*
|
|
|
|
* Find an entry by id in a resource directory
|
|
|
|
*/
|
|
|
|
static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
|
|
|
|
WORD id, const void *root, int want_dir )
|
|
|
|
{
|
|
|
|
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;
|
2013-04-29 09:19:17 +02:00
|
|
|
if (entry[pos].u.Id == id)
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
2013-04-29 09:19:17 +02:00
|
|
|
if (!entry[pos].u2.s2.DataIsDirectory == !want_dir)
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
TRACE("root %p dir %p id %04x ret %p\n",
|
2013-04-29 09:19:17 +02:00
|
|
|
root, dir, id, (const char*)root + entry[pos].u2.s2.OffsetToDirectory);
|
|
|
|
return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].u2.s2.OffsetToDirectory);
|
2003-04-30 01:00:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-04-29 09:19:17 +02:00
|
|
|
if (entry[pos].u.Id > id) max = pos - 1;
|
2003-04-30 01:00:48 +02:00
|
|
|
else min = pos + 1;
|
|
|
|
}
|
|
|
|
TRACE("root %p dir %p id %04x not found\n", root, dir, id );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* find_entry_by_name
|
|
|
|
*
|
|
|
|
* Find an entry by name in a resource directory
|
|
|
|
*/
|
|
|
|
static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_name( const IMAGE_RESOURCE_DIRECTORY *dir,
|
|
|
|
LPCWSTR name, const void *root,
|
|
|
|
int want_dir )
|
|
|
|
{
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
|
|
|
|
const IMAGE_RESOURCE_DIR_STRING_U *str;
|
|
|
|
int min, max, res, pos, namelen;
|
|
|
|
|
2010-02-10 11:43:59 +01:00
|
|
|
if (IS_INTRESOURCE(name)) return find_entry_by_id( dir, LOWORD(name), root, want_dir );
|
2003-04-30 01:00:48 +02:00
|
|
|
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
2020-03-31 11:50:16 +02:00
|
|
|
namelen = wcslen(name);
|
2003-04-30 01:00:48 +02:00
|
|
|
min = 0;
|
|
|
|
max = dir->NumberOfNamedEntries - 1;
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
pos = (min + max) / 2;
|
2013-04-29 09:19:17 +02:00
|
|
|
str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const char *)root + entry[pos].u.s.NameOffset);
|
2020-03-31 11:55:51 +02:00
|
|
|
res = wcsncmp( name, str->NameString, str->Length );
|
2003-04-30 01:00:48 +02:00
|
|
|
if (!res && namelen == str->Length)
|
|
|
|
{
|
2013-04-29 09:19:17 +02:00
|
|
|
if (!entry[pos].u2.s2.DataIsDirectory == !want_dir)
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
TRACE("root %p dir %p name %s ret %p\n",
|
2013-04-29 09:19:17 +02:00
|
|
|
root, dir, debugstr_w(name), (const char*)root + entry[pos].u2.s2.OffsetToDirectory);
|
|
|
|
return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].u2.s2.OffsetToDirectory);
|
2003-04-30 01:00:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res < 0) max = pos - 1;
|
|
|
|
else min = pos + 1;
|
|
|
|
}
|
|
|
|
TRACE("root %p dir %p name %s not found\n", root, dir, debugstr_w(name) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* find_entry
|
|
|
|
*
|
|
|
|
* Find a resource entry
|
|
|
|
*/
|
|
|
|
static NTSTATUS find_entry( HMODULE hmod, const LDR_RESOURCE_INFO *info,
|
|
|
|
ULONG level, const void **ret, int want_dir )
|
|
|
|
{
|
|
|
|
ULONG size;
|
|
|
|
const void *root;
|
|
|
|
const IMAGE_RESOURCE_DIRECTORY *resdirptr;
|
|
|
|
WORD list[9]; /* list of languages to try */
|
|
|
|
int i, pos = 0;
|
|
|
|
|
|
|
|
root = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &size );
|
|
|
|
if (!root) return STATUS_RESOURCE_DATA_NOT_FOUND;
|
2009-09-24 13:14:47 +02:00
|
|
|
if (size < sizeof(*resdirptr)) return STATUS_RESOURCE_DATA_NOT_FOUND;
|
2003-04-30 01:00:48 +02:00
|
|
|
resdirptr = root;
|
|
|
|
|
|
|
|
if (!level--) goto done;
|
|
|
|
if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Type, root, want_dir || level )))
|
|
|
|
return STATUS_RESOURCE_TYPE_NOT_FOUND;
|
|
|
|
if (!level--) return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
resdirptr = *ret;
|
|
|
|
if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Name, root, want_dir || level )))
|
|
|
|
return STATUS_RESOURCE_NAME_NOT_FOUND;
|
|
|
|
if (!level--) return STATUS_SUCCESS;
|
|
|
|
if (level) return STATUS_INVALID_PARAMETER; /* level > 3 */
|
|
|
|
|
|
|
|
/* 1. specified language */
|
|
|
|
pos = push_language( list, pos, info->Language );
|
|
|
|
|
|
|
|
/* 2. specified language with neutral sublanguage */
|
|
|
|
pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(info->Language), SUBLANG_NEUTRAL ) );
|
|
|
|
|
|
|
|
/* 3. neutral language with neutral sublanguage */
|
|
|
|
pos = push_language( list, pos, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ) );
|
|
|
|
|
|
|
|
/* if no explicitly specified language, try some defaults */
|
|
|
|
if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL)
|
|
|
|
{
|
|
|
|
/* user defaults, unless SYS_DEFAULT sublanguage specified */
|
|
|
|
if (SUBLANGID(info->Language) != SUBLANG_SYS_DEFAULT)
|
|
|
|
{
|
|
|
|
/* 4. current thread locale language */
|
|
|
|
pos = push_language( list, pos, LANGIDFROMLCID(NtCurrentTeb()->CurrentLocale) );
|
|
|
|
|
|
|
|
/* 5. user locale language */
|
|
|
|
pos = push_language( list, pos, LANGIDFROMLCID(user_lcid) );
|
|
|
|
|
|
|
|
/* 6. user locale language with neutral sublanguage */
|
|
|
|
pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(user_lcid), SUBLANG_NEUTRAL ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now system defaults */
|
|
|
|
|
|
|
|
/* 7. system locale language */
|
|
|
|
pos = push_language( list, pos, LANGIDFROMLCID( system_lcid ) );
|
|
|
|
|
|
|
|
/* 8. system locale language with neutral sublanguage */
|
|
|
|
pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(system_lcid), SUBLANG_NEUTRAL ) );
|
|
|
|
|
|
|
|
/* 9. English */
|
|
|
|
pos = push_language( list, pos, MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
resdirptr = *ret;
|
|
|
|
for (i = 0; i < pos; i++)
|
|
|
|
if ((*ret = find_entry_by_id( resdirptr, list[i], root, want_dir ))) return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* if no explicitly specified language, return the first entry */
|
|
|
|
if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL)
|
|
|
|
{
|
|
|
|
if ((*ret = find_first_entry( resdirptr, root, want_dir ))) return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
return STATUS_RESOURCE_LANG_NOT_FOUND;
|
|
|
|
|
|
|
|
done:
|
|
|
|
*ret = resdirptr;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* LdrFindResourceDirectory_U (NTDLL.@)
|
|
|
|
*/
|
2019-01-27 06:58:09 +01:00
|
|
|
NTSTATUS WINAPI DECLSPEC_HOTPATCH LdrFindResourceDirectory_U( HMODULE hmod, const LDR_RESOURCE_INFO *info,
|
2003-05-07 05:21:26 +02:00
|
|
|
ULONG level, const IMAGE_RESOURCE_DIRECTORY **dir )
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
const void *res;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2004-09-22 21:36:24 +02:00
|
|
|
__TRY
|
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
if (info) TRACE( "module %p type %s name %s lang %04x level %d\n",
|
2003-05-07 05:21:26 +02:00
|
|
|
hmod, debugstr_w((LPCWSTR)info->Type),
|
2003-12-13 02:34:40 +01:00
|
|
|
level > 1 ? debugstr_w((LPCWSTR)info->Name) : "",
|
|
|
|
level > 2 ? info->Language : 0, level );
|
2003-04-30 01:00:48 +02:00
|
|
|
|
|
|
|
status = find_entry( hmod, info, level, &res, TRUE );
|
2003-05-07 05:21:26 +02:00
|
|
|
if (status == STATUS_SUCCESS) *dir = res;
|
2003-04-30 01:00:48 +02:00
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
return GetExceptionCode();
|
|
|
|
}
|
|
|
|
__ENDTRY;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* LdrFindResource_U (NTDLL.@)
|
|
|
|
*/
|
2019-01-27 06:58:09 +01:00
|
|
|
NTSTATUS WINAPI DECLSPEC_HOTPATCH LdrFindResource_U( HMODULE hmod, const LDR_RESOURCE_INFO *info,
|
2003-04-30 01:00:48 +02:00
|
|
|
ULONG level, const IMAGE_RESOURCE_DATA_ENTRY **entry )
|
|
|
|
{
|
|
|
|
const void *res;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2004-09-22 21:36:24 +02:00
|
|
|
__TRY
|
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
if (info) TRACE( "module %p type %s name %s lang %04x level %d\n",
|
2003-05-07 05:21:26 +02:00
|
|
|
hmod, debugstr_w((LPCWSTR)info->Type),
|
2003-12-13 02:34:40 +01:00
|
|
|
level > 1 ? debugstr_w((LPCWSTR)info->Name) : "",
|
|
|
|
level > 2 ? info->Language : 0, level );
|
2003-04-30 01:00:48 +02:00
|
|
|
|
|
|
|
status = find_entry( hmod, info, level, &res, FALSE );
|
|
|
|
if (status == STATUS_SUCCESS) *entry = res;
|
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
return GetExceptionCode();
|
|
|
|
}
|
|
|
|
__ENDTRY;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-02 15:18:20 +01:00
|
|
|
/* don't penalize other platforms stuff needed on i386 for compatibility */
|
|
|
|
#ifdef __i386__
|
2017-07-25 11:48:24 +02:00
|
|
|
NTSTATUS WINAPI DECLSPEC_HIDDEN access_resource( HMODULE hmod, const IMAGE_RESOURCE_DATA_ENTRY *entry,
|
|
|
|
void **ptr, ULONG *size )
|
2005-11-02 15:18:20 +01:00
|
|
|
#else
|
|
|
|
static inline NTSTATUS access_resource( HMODULE hmod, const IMAGE_RESOURCE_DATA_ENTRY *entry,
|
|
|
|
void **ptr, ULONG *size )
|
|
|
|
#endif
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
ULONG dirsize;
|
|
|
|
|
|
|
|
if (!RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &dirsize ))
|
|
|
|
status = STATUS_RESOURCE_DATA_NOT_FOUND;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ptr)
|
|
|
|
{
|
2018-03-06 16:08:10 +01:00
|
|
|
BOOL is_data_file = is_data_file_module(hmod);
|
|
|
|
hmod = (HMODULE)((ULONG_PTR)hmod & ~3);
|
|
|
|
if (is_data_file)
|
|
|
|
*ptr = RtlImageRvaToVa( RtlImageNtHeader(hmod), hmod, entry->OffsetToData, NULL );
|
|
|
|
else
|
|
|
|
*ptr = (char *)hmod + entry->OffsetToData;
|
2003-04-30 01:00:48 +02:00
|
|
|
}
|
|
|
|
if (size) *size = entry->Size;
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2003-04-30 01:00:48 +02:00
|
|
|
{
|
|
|
|
return GetExceptionCode();
|
|
|
|
}
|
|
|
|
__ENDTRY;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2005-11-02 15:18:20 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* LdrAccessResource (NTDLL.@)
|
2005-11-23 20:14:04 +01:00
|
|
|
*
|
|
|
|
* NOTE
|
|
|
|
* On x86, Shrinker, an executable compressor, depends on the
|
|
|
|
* "call access_resource" instruction being there.
|
2005-11-02 15:18:20 +01:00
|
|
|
*/
|
|
|
|
#ifdef __i386__
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC( LdrAccessResource, 16,
|
2005-11-23 19:55:06 +01:00
|
|
|
"pushl %ebp\n\t"
|
|
|
|
"movl %esp, %ebp\n\t"
|
|
|
|
"subl $4,%esp\n\t"
|
|
|
|
"pushl 24(%ebp)\n\t"
|
|
|
|
"pushl 20(%ebp)\n\t"
|
|
|
|
"pushl 16(%ebp)\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t"
|
|
|
|
"pushl 8(%ebp)\n\t"
|
|
|
|
"call " __ASM_NAME("access_resource") "\n\t"
|
|
|
|
"leave\n\t"
|
|
|
|
"ret $16"
|
2007-01-13 00:38:07 +01:00
|
|
|
)
|
2005-11-02 15:18:20 +01:00
|
|
|
#else
|
|
|
|
NTSTATUS WINAPI LdrAccessResource( HMODULE hmod, const IMAGE_RESOURCE_DATA_ENTRY *entry,
|
|
|
|
void **ptr, ULONG *size )
|
|
|
|
{
|
|
|
|
return access_resource( hmod, entry, ptr, size );
|
|
|
|
}
|
|
|
|
#endif
|
2003-04-30 01:00:48 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* RtlFindMessage (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlFindMessage( HMODULE hmod, ULONG type, ULONG lang,
|
|
|
|
ULONG msg_id, const MESSAGE_RESOURCE_ENTRY **ret )
|
|
|
|
{
|
|
|
|
const MESSAGE_RESOURCE_DATA *data;
|
|
|
|
const MESSAGE_RESOURCE_BLOCK *block;
|
|
|
|
const IMAGE_RESOURCE_DATA_ENTRY *rsrc;
|
|
|
|
LDR_RESOURCE_INFO info;
|
|
|
|
NTSTATUS status;
|
|
|
|
void *ptr;
|
2004-08-14 01:53:44 +02:00
|
|
|
unsigned int i;
|
2003-04-30 01:00:48 +02:00
|
|
|
|
|
|
|
info.Type = type;
|
|
|
|
info.Name = 1;
|
|
|
|
info.Language = lang;
|
|
|
|
|
|
|
|
if ((status = LdrFindResource_U( hmod, &info, 3, &rsrc )) != STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
if ((status = LdrAccessResource( hmod, rsrc, &ptr, NULL )) != STATUS_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
data = ptr;
|
|
|
|
block = data->Blocks;
|
|
|
|
for (i = 0; i < data->NumberOfBlocks; i++, block++)
|
|
|
|
{
|
|
|
|
if (msg_id >= block->LowId && msg_id <= block->HighId)
|
|
|
|
{
|
|
|
|
const MESSAGE_RESOURCE_ENTRY *entry;
|
|
|
|
|
2004-06-15 02:47:00 +02:00
|
|
|
entry = (const MESSAGE_RESOURCE_ENTRY *)((const char *)data + block->OffsetToEntries);
|
2003-04-30 01:00:48 +02:00
|
|
|
for (i = msg_id - block->LowId; i > 0; i--)
|
2004-06-15 02:47:00 +02:00
|
|
|
entry = (const MESSAGE_RESOURCE_ENTRY *)((const char *)entry + entry->Length);
|
2003-04-30 01:00:48 +02:00
|
|
|
*ret = entry;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return STATUS_MESSAGE_NOT_FOUND;
|
|
|
|
}
|