Implemented LdrFindResource_U and LdrAccessResource

svn path=/trunk/; revision=768
This commit is contained in:
Boudewijn Dekker 1999-11-14 13:04:46 +00:00
parent b0ff680e0e
commit abd233d61a
4 changed files with 199 additions and 32 deletions

View file

@ -221,6 +221,16 @@ typedef struct _IMAGE_IMPORT_BY_NAME {
#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
// Predefined resource types ... there may be some more, but I don't have
// the information yet. .....sang cho.....
#define RT_NEWRESOURCE 0x2000
#define RT_ERROR 0x7fff
#define NEWBITMAP (RT_BITMAP|RT_NEWRESOURCE)
#define NEWMENU (RT_MENU|RT_NEWRESOURCE)
#define NEWDIALOG (RT_DIALOG|RT_NEWRESOURCE)
//
// Resource Format.
//
@ -239,28 +249,6 @@ typedef struct _IMAGE_IMPORT_BY_NAME {
// This is consistant with the syntax of the .RC file and the .RES file.
//
// Predefined resource types ... there may be some more, but I don't have
// the information yet. .....sang cho.....
#define RT_NEWRESOURCE 0x2000
#define RT_ERROR 0x7fff
#define NEWBITMAP (RT_BITMAP|RT_NEWRESOURCE)
#define NEWMENU (RT_MENU|RT_NEWRESOURCE)
#define NEWDIALOG (RT_DIALOG|RT_NEWRESOURCE)
typedef struct _IMAGE_RESOURCE_DIRECTORY {
DWORD Characteristics;
DWORD TimeDateStamp;
WORD MajorVersion;
WORD MinorVersion;
WORD NumberOfNamedEntries;
WORD NumberOfIdEntries;
// IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[1];
} IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
#define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
#define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
//
// Each directory contains the 32-bit Name of the entry and an offset,
@ -279,9 +267,25 @@ typedef struct _IMAGE_RESOURCE_DIRECTORY {
typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
DWORD Name;
DWORD OffsetToData;
DWORD OffsetToData;
} IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
typedef struct _IMAGE_RESOURCE_DIRECTORY {
DWORD Characteristics;
DWORD TimeDateStamp;
WORD MajorVersion;
WORD MinorVersion;
WORD NumberOfNamedEntries;
WORD NumberOfIdEntries;
IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[0];
} IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
#define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
#define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
//
// For resource directory entries that have actual string names, the Name
// field of the directory entry points to an object of the following type.

View file

@ -1,4 +1,4 @@
; $Id: ntdll.def,v 1.20 1999/11/12 12:01:10 dwelch Exp $
; $Id: ntdll.def,v 1.21 1999/11/14 13:04:01 ariadne Exp $
;
; ReactOS Operating System
;
@ -556,4 +556,5 @@ LdrGetExportByOrdinal
LdrLoadDll
LdrMapNTDllForProcess
LdrUnloadDll
LdrFindResource_U
LdrAccessResource

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.13 1999/11/02 08:55:38 dwelch Exp $
/* $Id: utils.c,v 1.14 1999/11/14 12:59:53 ariadne Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -929,4 +929,164 @@ NTSTATUS LdrUnloadDll(PDLL Dll)
return Status;
}
static IMAGE_RESOURCE_DIRECTORY_ENTRY * LdrGetNextEntry(IMAGE_RESOURCE_DIRECTORY *ResourceDir, LPWSTR ResourceName, ULONG Offset)
{
WORD NumberOfNamedEntries;
WORD NumberOfIdEntries;
WORD Entries;
ULONG Length;
if ( (((ULONG)ResourceDir) & 0xF0000000) != 0 ) {
return (IMAGE_RESOURCE_DIRECTORY_ENTRY *)NULL;
}
NumberOfIdEntries = ResourceDir->NumberOfIdEntries;
NumberOfNamedEntries = ResourceDir->NumberOfNamedEntries;
if ( ( NumberOfIdEntries + NumberOfNamedEntries) == 0) {
return &ResourceDir->DirectoryEntries[0];
}
if ( HIWORD(ResourceName) != 0 ) {
Length = wcslen(ResourceName);
Entries = ResourceDir->NumberOfNamedEntries;
do {
IMAGE_RESOURCE_DIR_STRING_U *DirString;
Entries--;
DirString = (IMAGE_RESOURCE_DIR_STRING_U *)(((ULONG)ResourceDir->DirectoryEntries[Entries].Name & (~0xF0000000)) + Offset);
if ( DirString->Length == Length && wcscmp(DirString->NameString, ResourceName ) == 0 ) {
return &ResourceDir->DirectoryEntries[Entries];
}
} while (Entries > 0);
}
else {
Entries = ResourceDir->NumberOfIdEntries + ResourceDir->NumberOfNamedEntries;
do {
Entries--;
if ( (LPWSTR)ResourceDir->DirectoryEntries[Entries].Name == ResourceName ) {
return &ResourceDir->DirectoryEntries[Entries];
}
} while (Entries > ResourceDir->NumberOfNamedEntries);
}
return NULL;
}
NTSTATUS LdrFindResource_U(DLL *Dll, IMAGE_RESOURCE_DATA_ENTRY **ResourceDataEntry,LPWSTR ResourceName, ULONG ResourceType,ULONG Language)
{
IMAGE_RESOURCE_DIRECTORY *ResourceTypeDir;
IMAGE_RESOURCE_DIRECTORY *ResourceNameDir;
IMAGE_RESOURCE_DIRECTORY *ResourceLangDir;
IMAGE_RESOURCE_DIRECTORY_ENTRY *ResourceTypeDirEntry;
IMAGE_RESOURCE_DIRECTORY_ENTRY *ResourceNameDirEntry;
IMAGE_RESOURCE_DIRECTORY_ENTRY *ResourceLangDirEntry;
PIMAGE_OPTIONAL_HEADER OptionalHeader;
ULONG Offset;
OptionalHeader = & Dll->Headers->OptionalHeader;
ResourceTypeDir = (PIMAGE_RESOURCE_DIRECTORY)
OptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
ResourceTypeDir = (PIMAGE_RESOURCE_DIRECTORY)
((ULONG)ResourceTypeDir + (ULONG)Dll->BaseAddress);
Offset = (ULONG)ResourceTypeDir;
ResourceTypeDirEntry = LdrGetNextEntry(ResourceTypeDir, (LPWSTR)ResourceType, Offset);
if ( ResourceTypeDirEntry != NULL ) {
ResourceNameDir = (IMAGE_RESOURCE_DIRECTORY*)((ResourceTypeDirEntry->OffsetToData & (~0xF0000000)) + Offset);
ResourceNameDirEntry = LdrGetNextEntry(ResourceNameDir, ResourceName, Offset);
if ( ResourceNameDirEntry != NULL ) {
ResourceLangDir = (IMAGE_RESOURCE_DIRECTORY*)((ResourceNameDirEntry->OffsetToData & (~0xF0000000)) + Offset);
ResourceLangDirEntry = LdrGetNextEntry(ResourceLangDir, (LPWSTR)Language, Offset);
if ( ResourceLangDirEntry != NULL ) {
*ResourceDataEntry = (IMAGE_RESOURCE_DATA_ENTRY *)(ResourceLangDirEntry->OffsetToData +
(ULONG)ResourceTypeDir);
return STATUS_SUCCESS;
}
else {
return -1;
}
}
else {
return -1;
}
}
return -1;
}
NTSTATUS LdrAccessResource(DLL *Dll, IMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry, void **Data)
{
PIMAGE_SECTION_HEADER Sections;
int i;
if ( Data == NULL )
return -1;
if ( ResourceDataEntry == NULL )
return -1;
if ( Dll == NULL )
return -1;
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(Dll->BaseAddress);
for ( i = 0;
(i < Dll->Headers->FileHeader.NumberOfSections);
i++
)
{
if (Sections[i].VirtualAddress <= ResourceDataEntry->OffsetToData
&& Sections[i].VirtualAddress + Sections[i].Misc.VirtualSize > ResourceDataEntry->OffsetToData )
break;
}
if ( i == Dll->Headers->FileHeader.NumberOfSections ) {
*Data = NULL;
return -1;
}
*Data = (void *)(((ULONG)Dll->BaseAddress + ResourceDataEntry->OffsetToData - (ULONG)Sections[i].VirtualAddress) +
(ULONG)Sections[i].PointerToRawData);
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -1,9 +1,11 @@
#include <ddk/ntddk.h>
#define STUB(x) void x(void) { UNICODE_STRING UnicodeString; \
RtlInitUnicodeString(&UnicodeString,\
L"NTDLL: Stub for "#x"\n"); \
NtDisplayString(&UnicodeString); }
#define STUB(x) void x(void) { \
UNICODE_STRING UnicodeString; \
RtlInitUnicodeString(&UnicodeString,\
L"NTDLL: Stub for "#x"\n"); \
NtDisplayString(&UnicodeString); }
// ?Allocate@CBufferAllocator@@UAEPAXK@Z
STUB(PropertyLengthAsVariant)
@ -36,12 +38,12 @@ STUB(KiRaiseUserExceptionDispatcher)
STUB(KiUserApcDispatcher)
STUB(KiUserCallbackDispatcher)
STUB(KiUserExceptionDispatcher)
STUB(LdrAccessResource)
STUB(LdrDisableThreadCalloutsForDll)
STUB(LdrEnumResources)
STUB(LdrFindEntryForAddress)
STUB(LdrFindResourceDirectory_U)
STUB(LdrFindResource_U)
STUB(LdrGetDllHandle)
STUB(LdrGetProcedureAddress)
STUB(LdrInitializeThunk)