ReactOS  0.4.15-dev-1392-g3014417
res.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for res.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NAME_FROM_RESOURCE_ENTRY(RootDirectory, Entry)   ((Entry)->NameIsString ? (ULONG_PTR)(RootDirectory) + (Entry)->NameOffset : (Entry)->Id)
 

Functions

NTSTATUS find_entry (PVOID BaseAddress, LDR_RESOURCE_INFO *info, ULONG level, void **ret, int want_dir)
 
int page_fault (ULONG ExceptionCode)
 
static int is_data_file_module (PVOID BaseAddress)
 
int push_language (USHORT *list, ULONG pos, WORD lang)
 
IMAGE_RESOURCE_DIRECTORYfind_first_entry (IMAGE_RESOURCE_DIRECTORY *dir, void *root, int want_dir)
 
IMAGE_RESOURCE_DIRECTORYfind_entry_by_id (IMAGE_RESOURCE_DIRECTORY *dir, WORD id, void *root, int want_dir)
 
IMAGE_RESOURCE_DIRECTORYfind_entry_by_name (IMAGE_RESOURCE_DIRECTORY *dir, LPCWSTR name, void *root, int want_dir)
 
static NTSTATUS LdrpAccessResource (PVOID BaseAddress, IMAGE_RESOURCE_DATA_ENTRY *entry, void **ptr, ULONG *size)
 
NTSTATUS NTAPI LdrFindResource_U (PVOID BaseAddress, PLDR_RESOURCE_INFO ResourceInfo, ULONG Level, PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry)
 
NTSTATUS NTAPI LdrAccessResource (IN PVOID BaseAddress, IN PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry, OUT PVOID *Resource OPTIONAL, OUT PULONG Size OPTIONAL)
 
NTSTATUS NTAPI LdrFindResourceDirectory_U (IN PVOID BaseAddress, IN PLDR_RESOURCE_INFO info, IN ULONG level, OUT PIMAGE_RESOURCE_DIRECTORY *addr)
 
static LONG LdrpCompareResourceNames_U (_In_ PUCHAR ResourceData, _In_ PIMAGE_RESOURCE_DIRECTORY_ENTRY Entry, _In_ ULONG_PTR CompareName)
 
NTSTATUS NTAPI LdrEnumResources (_In_ PVOID ImageBase, _In_ PLDR_RESOURCE_INFO ResourceInfo, _In_ ULONG Level, _Inout_ ULONG *ResourceCount, _Out_writes_to_(*ResourceCount, *ResourceCount) LDR_ENUM_RESOURCE_INFO *Resources)
 

Macro Definition Documentation

◆ NAME_FROM_RESOURCE_ENTRY

#define NAME_FROM_RESOURCE_ENTRY (   RootDirectory,
  Entry 
)    ((Entry)->NameIsString ? (ULONG_PTR)(RootDirectory) + (Entry)->NameOffset : (Entry)->Id)

Definition at line 288 of file res.c.

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file res.c.

Function Documentation

◆ find_entry()

NTSTATUS find_entry ( PVOID  BaseAddress,
LDR_RESOURCE_INFO info,
ULONG  level,
void **  ret,
int  want_dir 
)

Definition at line 570 of file libsupp.c.

572 {
573  ULONG size;
574  void *root;
575  IMAGE_RESOURCE_DIRECTORY *resdirptr;
576  USHORT list[9]; /* list of languages to try */
577  int i, pos = 0;
578  LCID user_lcid, system_lcid;
579 
582  if (size < sizeof(*resdirptr)) return STATUS_RESOURCE_DATA_NOT_FOUND;
583  resdirptr = root;
584 
585  if (!level--) goto done;
586  if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Type, root, want_dir || level )))
588  if (!level--) return STATUS_SUCCESS;
589 
590  resdirptr = *ret;
591  if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Name, root, want_dir || level )))
593  if (!level--) return STATUS_SUCCESS;
594  if (level) return STATUS_INVALID_PARAMETER; /* level > 3 */
595 
596  /* 1. specified language */
597  pos = push_language( list, pos, info->Language );
598 
599  /* 2. specified language with neutral sublanguage */
601 
602  /* 3. neutral language with neutral sublanguage */
604 
605  /* if no explicitly specified language, try some defaults */
606  if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL)
607  {
608  /* user defaults, unless SYS_DEFAULT sublanguage specified */
609  if (SUBLANGID(info->Language) != SUBLANG_SYS_DEFAULT)
610  {
611  /* 4. current thread locale language */
612  pos = push_language( list, pos, LANGIDFROMLCID(NtCurrentTeb()->CurrentLocale) );
613 
614  if (NT_SUCCESS(NtQueryDefaultLocale(TRUE, &user_lcid)))
615  {
616  /* 5. user locale language */
617  pos = push_language( list, pos, LANGIDFROMLCID(user_lcid) );
618 
619  /* 6. user locale language with neutral sublanguage */
621  }
622  }
623 
624  /* now system defaults */
625 
626  if (NT_SUCCESS(NtQueryDefaultLocale(FALSE, &system_lcid)))
627  {
628  /* 7. system locale language */
629  pos = push_language( list, pos, LANGIDFROMLCID( system_lcid ) );
630 
631  /* 8. system locale language with neutral sublanguage */
633  }
634 
635  /* 9. English */
637  }
638 
639  resdirptr = *ret;
640  for (i = 0; i < pos; i++)
641  if ((*ret = find_entry_by_id( resdirptr, list[i], root, want_dir ))) return STATUS_SUCCESS;
642 
643  /* if no explicitly specified language, return the first entry */
644  if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL)
645  {
646  if ((*ret = find_first_entry( resdirptr, root, want_dir ))) return STATUS_SUCCESS;
647  }
649 
650 done:
651  *ret = resdirptr;
652  return STATUS_SUCCESS;
653 }
GLint level
Definition: gl.h:1546
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
IMAGE_RESOURCE_DIRECTORY * find_entry_by_name(IMAGE_RESOURCE_DIRECTORY *dir, LPCWSTR name, void *root, int want_dir)
Definition: res.c:130
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define LANG_NEUTRAL
Definition: nls.h:22
struct _root root
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD LCID
Definition: nls.h:13
#define SUBLANG_NEUTRAL
Definition: nls.h:167
#define SUBLANG_SYS_DEFAULT
Definition: nls.h:169
#define FALSE
Definition: types.h:117
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
GLsizeiptr size
Definition: glext.h:5919
IMAGE_RESOURCE_DIRECTORY * find_entry_by_id(IMAGE_RESOURCE_DIRECTORY *dir, WORD id, void *root, int want_dir)
Definition: res.c:95
IMAGE_RESOURCE_DIRECTORY * find_first_entry(IMAGE_RESOURCE_DIRECTORY *dir, void *root, int want_dir)
Definition: res.c:75
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define LANG_ENGLISH
Definition: nls.h:52
int ret
#define STATUS_RESOURCE_DATA_NOT_FOUND
Definition: ntstatus.h:373
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
#define LANGIDFROMLCID(l)
Definition: nls.h:18
Definition: _list.h:228
int push_language(USHORT *list, ULONG pos, WORD lang)
Definition: res.c:61
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define STATUS_RESOURCE_LANG_NOT_FOUND
Definition: ntstatus.h:648
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_RESOURCE_NAME_NOT_FOUND
Definition: ntstatus.h:375
NTSTATUS NTAPI NtQueryDefaultLocale(IN BOOLEAN UserProfile, OUT PLCID DefaultLocaleId)
Definition: locale.c:162
unsigned int ULONG
Definition: retypes.h:1
#define MAKELANGID(p, s)
Definition: nls.h:15
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define STATUS_RESOURCE_TYPE_NOT_FOUND
Definition: ntstatus.h:374
#define SUBLANGID(l)
Definition: nls.h:17

Referenced by LdrFindResource_U(), and LdrFindResourceDirectory_U().

◆ find_entry_by_id()

IMAGE_RESOURCE_DIRECTORY* find_entry_by_id ( IMAGE_RESOURCE_DIRECTORY dir,
WORD  id,
void root,
int  want_dir 
)

Definition at line 95 of file res.c.

97 {
99  int min, max, pos;
100 
101  entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
102  min = dir->NumberOfNamedEntries;
103  max = min + dir->NumberOfIdEntries - 1;
104  while (min <= max)
105  {
106  pos = (min + max) / 2;
107  if (entry[pos].Id == id)
108  {
109  if (!entry[pos].DataIsDirectory == !want_dir)
110  {
111  DPRINT("root %p dir %p id %04x ret %p\n",
112  root, dir, id, (const char*)root + entry[pos].OffsetToDirectory);
113  return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
114  }
115  break;
116  }
117  if (entry[pos].Id > id) max = pos - 1;
118  else min = pos + 1;
119  }
120  DPRINT("root %p dir %p id %04x not found\n", root, dir, id );
121  return NULL;
122 }
#define max(a, b)
Definition: svc.c:63
DWORD Id
void DPRINT(...)
Definition: polytest.cpp:61
unsigned int dir
Definition: maze.c:112
uint32_t entry
Definition: isohybrid.c:63
Definition: pedump.c:413
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112

Referenced by find_entry(), and find_entry_by_name().

◆ find_entry_by_name()

IMAGE_RESOURCE_DIRECTORY* find_entry_by_name ( IMAGE_RESOURCE_DIRECTORY dir,
LPCWSTR  name,
void root,
int  want_dir 
)

Definition at line 130 of file res.c.

133 {
136  int min, max, res, pos;
137  size_t namelen;
138 
139  if (!((ULONG_PTR)name & 0xFFFF0000)) return find_entry_by_id( dir, (ULONG_PTR)name & 0xFFFF, root, want_dir );
140  entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
141  namelen = wcslen(name);
142  min = 0;
143  max = dir->NumberOfNamedEntries - 1;
144  while (min <= max)
145  {
146  pos = (min + max) / 2;
147  str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const char *)root + entry[pos].NameOffset);
148  res = _wcsnicmp( name, str->NameString, str->Length );
149  if (!res && namelen == str->Length)
150  {
151  if (!entry[pos].DataIsDirectory == !want_dir)
152  {
153  DPRINT("root %p dir %p name %ws ret %p\n",
154  root, dir, name, (const char*)root + entry[pos].OffsetToDirectory);
155  return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
156  }
157  break;
158  }
159  if (res < 0) max = pos - 1;
160  else min = pos + 1;
161  }
162  DPRINT("root %p dir %p name %ws not found\n", root, dir, name);
163  return NULL;
164 }
#define max(a, b)
Definition: svc.c:63
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
IMAGE_RESOURCE_DIRECTORY * find_entry_by_id(IMAGE_RESOURCE_DIRECTORY *dir, WORD id, void *root, int want_dir)
Definition: res.c:95
GLint namelen
Definition: glext.h:7232
uint32_t ULONG_PTR
Definition: typedefs.h:65
const WCHAR * str
void DPRINT(...)
Definition: polytest.cpp:61
unsigned int dir
Definition: maze.c:112
uint32_t entry
Definition: isohybrid.c:63
Definition: pedump.c:413
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
Definition: name.c:38
GLuint res
Definition: glext.h:9613
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by find_entry(), and search_manifest_in_module().

◆ find_first_entry()

IMAGE_RESOURCE_DIRECTORY* find_first_entry ( IMAGE_RESOURCE_DIRECTORY dir,
void root,
int  want_dir 
)

Definition at line 75 of file res.c.

77 {
79  int pos;
80 
81  for (pos = 0; pos < dir->NumberOfNamedEntries + dir->NumberOfIdEntries; pos++)
82  {
83  if (!entry[pos].DataIsDirectory == !want_dir)
84  return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
85  }
86  return NULL;
87 }
unsigned int dir
Definition: maze.c:112
uint32_t entry
Definition: isohybrid.c:63
Definition: pedump.c:413
#define NULL
Definition: types.h:112

Referenced by find_entry(), and search_manifest_in_module().

◆ is_data_file_module()

static int is_data_file_module ( PVOID  BaseAddress)
static

Definition at line 50 of file res.c.

51 {
52  return (ULONG_PTR)BaseAddress & 1;
53 }
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404

Referenced by LdrpAccessResource().

◆ LdrAccessResource()

NTSTATUS NTAPI LdrAccessResource ( IN PVOID  BaseAddress,
IN PIMAGE_RESOURCE_DATA_ENTRY  ResourceDataEntry,
OUT PVOID *Resource  OPTIONAL,
OUT PULONG Size  OPTIONAL 
)

Definition at line 244 of file res.c.

248 {
249  return LdrpAccessResource( BaseAddress, ResourceDataEntry, Resource, Size );
250 }
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
static NTSTATUS LdrpAccessResource(PVOID BaseAddress, IMAGE_RESOURCE_DATA_ENTRY *entry, void **ptr, ULONG *size)
Definition: res.c:170

Referenced by LoadResource().

◆ LdrEnumResources()

NTSTATUS NTAPI LdrEnumResources ( _In_ PVOID  ImageBase,
_In_ PLDR_RESOURCE_INFO  ResourceInfo,
_In_ ULONG  Level,
_Inout_ ULONG ResourceCount,
_Out_writes_to_ *, *ResourceCount LDR_ENUM_RESOURCE_INFO Resources 
)

Definition at line 343 of file res.c.

349 {
350  PUCHAR ResourceData;
352  ULONG i, j, k;
353  ULONG NumberOfTypeEntries, NumberOfNameEntries, NumberOfLangEntries;
354  ULONG Count, MaxResourceCount;
355  PIMAGE_RESOURCE_DIRECTORY TypeDirectory, NameDirectory, LangDirectory;
356  PIMAGE_RESOURCE_DIRECTORY_ENTRY TypeEntry, NameEntry, LangEntry;
357  PIMAGE_RESOURCE_DATA_ENTRY DataEntry;
358  ULONG Size;
359  LONG Result;
360 
361  /* If the caller wants data, get the maximum count of entries */
362  MaxResourceCount = (Resources != NULL) ? *ResourceCount : 0;
363 
364  /* Default to 0 */
365  *ResourceCount = 0;
366 
367  /* Locate the resource directory */
368  ResourceData = RtlImageDirectoryEntryToData(ImageBase,
369  TRUE,
371  &Size);
372  if (ResourceData == NULL)
374 
375  /* The type directory is at the root, followed by the entries */
376  TypeDirectory = (PIMAGE_RESOURCE_DIRECTORY)ResourceData;
377  TypeEntry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(TypeDirectory + 1);
378 
379  /* Get the number of entries in the type directory */
380  NumberOfTypeEntries = TypeDirectory->NumberOfNamedEntries +
381  TypeDirectory->NumberOfIdEntries;
382 
383  /* Start with 0 resources and status success */
385  Count = 0;
386 
387  /* Loop all entries in the type directory */
388  for (i = 0; i < NumberOfTypeEntries; ++i, ++TypeEntry)
389  {
390  /* Check if comparison of types is requested */
392  {
393  /* Compare the type with the requested Type */
394  Result = LdrpCompareResourceNames_U(ResourceData,
395  TypeEntry,
396  ResourceInfo->Type);
397 
398  /* Not equal, continue with next entry */
399  if (Result != 0) continue;
400  }
401 
402  /* The entry must point to the name directory */
403  if (!TypeEntry->DataIsDirectory)
404  {
406  }
407 
408  /* Get a pointer to the name subdirectory and it's first entry */
409  NameDirectory = (PIMAGE_RESOURCE_DIRECTORY)(ResourceData +
410  TypeEntry->OffsetToDirectory);
411  NameEntry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(NameDirectory + 1);
412 
413  /* Get the number of entries in the name directory */
414  NumberOfNameEntries = NameDirectory->NumberOfNamedEntries +
415  NameDirectory->NumberOfIdEntries;
416 
417  /* Loop all entries in the name directory */
418  for (j = 0; j < NumberOfNameEntries; ++j, ++NameEntry)
419  {
420  /* Check if comparison of names is requested */
422  {
423  /* Compare the name with the requested name */
424  Result = LdrpCompareResourceNames_U(ResourceData,
425  NameEntry,
426  ResourceInfo->Name);
427 
428  /* Not equal, continue with next entry */
429  if (Result != 0) continue;
430  }
431 
432  /* The entry must point to the language directory */
433  if (!NameEntry->DataIsDirectory)
434  {
436  }
437 
438  /* Get a pointer to the language subdirectory and it's first entry */
439  LangDirectory = (PIMAGE_RESOURCE_DIRECTORY)(ResourceData +
440  NameEntry->OffsetToDirectory);
441  LangEntry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(LangDirectory + 1);
442 
443  /* Get the number of entries in the language directory */
444  NumberOfLangEntries = LangDirectory->NumberOfNamedEntries +
445  LangDirectory->NumberOfIdEntries;
446 
447  /* Loop all entries in the language directory */
448  for (k = 0; k < NumberOfLangEntries; ++k, ++LangEntry)
449  {
450  /* Check if comparison of languages is requested */
452  {
453  /* Compare the language with the requested language */
454  Result = LdrpCompareResourceNames_U(ResourceData,
455  LangEntry,
456  ResourceInfo->Language);
457 
458  /* Not equal, continue with next entry */
459  if (Result != 0) continue;
460  }
461 
462  /* This entry must point to data */
463  if (LangEntry->DataIsDirectory)
464  {
466  }
467 
468  /* Get a pointer to the data entry */
469  DataEntry = (PIMAGE_RESOURCE_DATA_ENTRY)(ResourceData +
470  LangEntry->OffsetToData);
471 
472  /* Check if there is still space to store the data */
473  if (Count < MaxResourceCount)
474  {
475  /* There is, fill the entry */
476  Resources[Count].Type =
477  NAME_FROM_RESOURCE_ENTRY(ResourceData, TypeEntry);
478  Resources[Count].Name =
479  NAME_FROM_RESOURCE_ENTRY(ResourceData, NameEntry);
480  Resources[Count].Language =
481  NAME_FROM_RESOURCE_ENTRY(ResourceData, LangEntry);
482  Resources[Count].Data = (PUCHAR)ImageBase + DataEntry->OffsetToData;
483  Resources[Count].Reserved = 0;
484  Resources[Count].Size = DataEntry->Size;
485  }
486  else
487  {
488  /* There is not enough space, save error status */
490  }
491 
492  /* Count this resource */
493  ++Count;
494  }
495  }
496  }
497 
498  /* Return the number of matching resources */
499  *ResourceCount = Count;
500  return Status;
501 }
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
ULONG OffsetToDirectory
Definition: ntimage.h:194
DWORD OffsetToData
Definition: pedump.c:416
#define TRUE
Definition: types.h:120
#define RESOURCE_TYPE_LEVEL
Definition: ldrtypes.h:30
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define RESOURCE_NAME_LEVEL
Definition: ldrtypes.h:31
struct _IMAGE_RESOURCE_DIRECTORY * PIMAGE_RESOURCE_DIRECTORY
long LONG
Definition: pedump.c:60
struct _IMAGE_RESOURCE_DATA_ENTRY * PIMAGE_RESOURCE_DATA_ENTRY
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: pedump.c:457
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
Status
Definition: gdiplustypes.h:24
DWORD OffsetToData
Definition: pedump.c:459
int Count
Definition: noreturn.cpp:7
static LONG LdrpCompareResourceNames_U(_In_ PUCHAR ResourceData, _In_ PIMAGE_RESOURCE_DIRECTORY_ENTRY Entry, _In_ ULONG_PTR CompareName)
Definition: res.c:293
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
static ULONG ResourceCount
Definition: inbv.c:92
#define STATUS_RESOURCE_DATA_NOT_FOUND
Definition: ntstatus.h:373
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
#define NAME_FROM_RESOURCE_ENTRY(RootDirectory, Entry)
Definition: res.c:288
struct _IMAGE_RESOURCE_DIRECTORY_ENTRY * PIMAGE_RESOURCE_DIRECTORY_ENTRY
Definition: pedump.c:413
ULONG DataIsDirectory
Definition: ntimage.h:195
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
#define RESOURCE_LANGUAGE_LEVEL
Definition: ldrtypes.h:32
int k
Definition: mpi.c:3369
DWORD Size
Definition: pedump.c:460

Referenced by Test_Data(), and Test_Parameters().

◆ LdrFindResource_U()

NTSTATUS NTAPI LdrFindResource_U ( PVOID  BaseAddress,
PLDR_RESOURCE_INFO  ResourceInfo,
ULONG  Level,
PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry 
)

Definition at line 209 of file res.c.

213 {
214  void *res;
216 
217  _SEH2_TRY
218  {
219  if (ResourceInfo)
220  {
221  DPRINT( "module %p type %lx name %lx lang %04lx level %lu\n",
222  BaseAddress, ResourceInfo->Type,
223  Level > 1 ? ResourceInfo->Name : 0,
224  Level > 2 ? ResourceInfo->Language : 0, Level );
225  }
226 
227  status = find_entry( BaseAddress, ResourceInfo, Level, &res, FALSE );
228  if (NT_SUCCESS(status))
229  *ResourceDataEntry = res;
230  }
232  {
234  }
235  _SEH2_END;
236  return status;
237 }
LONG NTSTATUS
Definition: precomp.h:26
int page_fault(ULONG ExceptionCode)
Definition: res.c:37
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
ULONG_PTR Type
Definition: ldrtypes.h:181
_SEH2_TRY
Definition: create.c:4226
#define FALSE
Definition: types.h:117
ULONG_PTR Name
Definition: ldrtypes.h:182
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS find_entry(PVOID BaseAddress, LDR_RESOURCE_INFO *info, ULONG level, void **ret, int want_dir)
Definition: libsupp.c:570
_SEH2_END
Definition: create.c:4400
ULONG_PTR Language
Definition: ldrtypes.h:183
GLuint res
Definition: glext.h:9613
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by find_resourceA(), and find_resourceW().

◆ LdrFindResourceDirectory_U()

NTSTATUS NTAPI LdrFindResourceDirectory_U ( IN PVOID  BaseAddress,
IN PLDR_RESOURCE_INFO  info,
IN ULONG  level,
OUT PIMAGE_RESOURCE_DIRECTORY addr 
)

Definition at line 257 of file res.c.

261 {
262  void *res;
264 
265  _SEH2_TRY
266  {
267  if (info)
268  {
269  DPRINT( "module %p type %ws name %ws lang %04lx level %lu\n",
270  BaseAddress, (LPCWSTR)info->Type,
271  level > 1 ? (LPCWSTR)info->Name : L"",
272  level > 2 ? info->Language : 0, level );
273  }
274 
276  if (NT_SUCCESS(status))
277  *addr = res;
278  }
280  {
282  }
283  _SEH2_END;
284  return status;
285 }
GLint level
Definition: gl.h:1546
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
int page_fault(ULONG ExceptionCode)
Definition: res.c:37
_SEH2_TRY
Definition: create.c:4226
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
GLenum const GLvoid * addr
Definition: glext.h:9621
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS find_entry(PVOID BaseAddress, LDR_RESOURCE_INFO *info, ULONG level, void **ret, int want_dir)
Definition: libsupp.c:570
_SEH2_END
Definition: create.c:4400
GLuint res
Definition: glext.h:9613
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by EnumResourceLanguagesA(), EnumResourceLanguagesW(), EnumResourceNamesA(), EnumResourceNamesW(), EnumResourceTypesA(), and EnumResourceTypesW().

◆ LdrpAccessResource()

static NTSTATUS LdrpAccessResource ( PVOID  BaseAddress,
IMAGE_RESOURCE_DATA_ENTRY entry,
void **  ptr,
ULONG size 
)
static

Definition at line 170 of file res.c.

173 {
175 
176  _SEH2_TRY
177  {
178  ULONG dirsize;
179 
182  else
183  {
184  if (ptr)
185  {
187  {
188  PVOID mod = (PVOID)((ULONG_PTR)BaseAddress & ~1);
189  *ptr = RtlImageRvaToVa( RtlImageNtHeader(mod), mod, entry->OffsetToData, NULL );
190  }
191  else *ptr = (char *)BaseAddress + entry->OffsetToData;
192  }
193  if (size) *size = entry->Size;
194  }
195  }
197  {
199  }
200  _SEH2_END;
201  return status;
202 }
static int is_data_file_module(PVOID BaseAddress)
Definition: res.c:50
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define RtlImageRvaToVa
Definition: compat.h:666
int page_fault(ULONG ExceptionCode)
Definition: res.c:37
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
static PVOID ptr
Definition: dispmode.c:27
void * PVOID
Definition: retypes.h:9
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
GLsizeiptr size
Definition: glext.h:5919
#define STATUS_RESOURCE_DATA_NOT_FOUND
Definition: ntstatus.h:373
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
uint32_t entry
Definition: isohybrid.c:63
_SEH2_END
Definition: create.c:4400
#define NULL
Definition: types.h:112
#define RtlImageNtHeader
Definition: compat.h:665
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
static SERVICE_STATUS status
Definition: service.c:31
static int mod
Definition: i386-dis.c:1281
Definition: ps.c:97

Referenced by LdrAccessResource().

◆ LdrpCompareResourceNames_U()

static LONG LdrpCompareResourceNames_U ( _In_ PUCHAR  ResourceData,
_In_ PIMAGE_RESOURCE_DIRECTORY_ENTRY  Entry,
_In_ ULONG_PTR  CompareName 
)
static

Definition at line 293 of file res.c.

297 {
298  PIMAGE_RESOURCE_DIR_STRING_U ResourceString;
299  PWSTR String1, String2;
300  USHORT ResourceStringLength;
301  WCHAR Char1, Char2;
302 
303  /* Check if the resource name is an ID */
304  if (CompareName <= USHRT_MAX)
305  {
306  /* Just compare the 2 IDs */
307  return (CompareName - Entry->Id);
308  }
309  else
310  {
311  /* Get the resource string */
312  ResourceString = (PIMAGE_RESOURCE_DIR_STRING_U)(ResourceData +
313  Entry->NameOffset);
314 
315  /* Get the string length */
316  ResourceStringLength = ResourceString->Length;
317 
318  String1 = ResourceString->NameString;
320 
321  /* Loop all characters of the resource string */
322  while (ResourceStringLength--)
323  {
324  /* Get the next characters */
325  Char1 = *String1++;
326  Char2 = *String2++;
327 
328  /* Check if they don't match, or if the compare string ends */
329  if ((Char1 != Char2) || (Char2 == 0))
330  {
331  /* They don't match, fail */
332  return Char2 - Char1;
333  }
334  }
335 
336  /* All characters match, check if the compare string ends here */
337  return (*String2 == 0) ? 0 : 1;
338  }
339 }
uint16_t * PWSTR
Definition: typedefs.h:56
#define USHRT_MAX
Definition: limits.h:38
struct _IMAGE_RESOURCE_DIR_STRING_U * PIMAGE_RESOURCE_DIR_STRING_U
__wchar_t WCHAR
Definition: xmlstorage.h:180
static BOOL CompareName(LPCWSTR pszName1, LPCWSTR pszName2)
Definition: find.c:72
unsigned short USHORT
Definition: pedump.c:61
_In_ const STRING * String2
Definition: rtlfuncs.h:2291
base of all file and directory entries
Definition: entries.h:82

Referenced by LdrEnumResources().

◆ page_fault()

int page_fault ( ULONG  ExceptionCode)

Definition at line 37 of file res.c.

38 {
43 }
_Inout_ PIRP _In_ NTSTATUS ExceptionCode
Definition: cdprocs.h:1772
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:308
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define EXCEPTION_PRIV_INSTRUCTION
Definition: winbase.h:322

Referenced by LdrFindResource_U(), LdrFindResourceDirectory_U(), and LdrpAccessResource().

◆ push_language()

int push_language ( USHORT list,
ULONG  pos,
WORD  lang 
)

Definition at line 61 of file res.c.

62 {
63  ULONG i;
64  for (i = 0; i < pos; i++) if (list[i] == lang) return pos;
65  list[pos++] = lang;
66  return pos;
67 }
static const WCHAR lang[]
Definition: wbemdisp.c:287
Definition: _list.h:228
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int ULONG
Definition: retypes.h:1

Referenced by find_entry().