-/* $Id: utils.c,v 1.17 1999/11/25 10:47:56 dwelch Exp $
+/* $Id: utils.c,v 1.18 1999/12/09 19:14:45 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
HANDLE FileHandle;
HANDLE SectionHandle;
PDLLMAIN_FUNC Entrypoint;
-
if ( Dll == NULL )
return -1;
-
if ( Name == NULL ) {
*Dll = &LdrDllListHead;
return STATUS_SUCCESS;
DPRINT("LdrLoadDll(Base %x, Name \"%s\")\n", Dll, Name);
-
-
/*
* Build the DLL's absolute name
*/
if ( strncmp(Name,"\\??\\",3) != 0 ) {
strcat(fqname, Name);
- }
+ }
else
strncpy(fqname, Name, 256);
DPRINT("fqname \"%s\"\n", fqname);
- /*
+ /*
* Open the DLL's image file.
*/
if (!NT_SUCCESS(Status))
{
DPRINT("NTDLL create section failed: Status = 0x%08x\n", Status);
- ZwClose(FileHandle);
+ ZwClose(FileHandle);
return Status;
}
/*
&InitialViewSize,
0,
MEM_COMMIT,
- PAGE_READWRITE
+ PAGE_READWRITE
);
if (!NT_SUCCESS(Status))
{
- dprintf("NTDLL.LDR: map view of section failed (Status %x)",
+ dprintf("NTDLL.LDR: map view of section failed (Status %x)\n",
Status);
- ZwClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
ZwClose(FileHandle);
-
+
(*Dll) = RtlAllocateHeap(
RtlGetProcessHeap(),
0,
if (((*Dll)->Headers->FileHeader.Characteristics & IMAGE_FILE_DLL) ==
- IMAGE_FILE_DLL)
+ IMAGE_FILE_DLL)
{
-
+
Entrypoint =
(PDLLMAIN_FUNC) LdrPEStartup(
ImageBase,
{
DPRINT("NTDLL.LDR: Entrypoint is NULL for \"%s\"\n", fqname);
}
- }
+ }
return STATUS_SUCCESS;
}
PIMAGE_EXPORT_DIRECTORY ExportDir;
DLL * current;
PIMAGE_OPTIONAL_HEADER OptionalHeader;
-
-
+
+
DPRINT("NTDLL.LdrFindDll(Name %s)\n", Name);
-
+
current = & LdrDllListHead;
-
+
// NULL is the current process
-
- if ( Name == NULL )
+
+ if ( Name == NULL )
{
*Dll = current;
return STATUS_SUCCESS;
}
-
+
do
{
OptionalHeader = & current->Headers->OptionalHeader;
DPRINT("Scanning %s %s\n",
ExportDir->Name + current->BaseAddress, Name);
- if (strcmp(ExportDir->Name + current->BaseAddress, Name) == 0)
+ if (_stricmp(ExportDir->Name + current->BaseAddress, Name) == 0)
{
*Dll = current;
current->ReferenceCount++;
current = current->Next;
} while (current != & LdrDllListHead);
-
+
DPRINT("Failed to find dll %s\n",Name);
-
+
return -1;
}
.VirtualAddress
)
);
-
+
ExOrdinals = (USHORT *)
RVA(
- Module->BaseAddress,
+ Module->BaseAddress,
ExportDir->AddressOfNameOrdinals
);
ExFunctions = (PDWORD *)
RVA(
- Module->BaseAddress,
+ Module->BaseAddress,
ExportDir->AddressOfFunctions
);
dprintf(
ULONG i;
PVOID ExName;
ULONG Ordinal;
-
+
// DPRINT(
// "LdrFindExport(Module %x, SymbolName %s)\n",
// Module,
// SymbolName
// );
-
+
ExportDir = (
Module->BaseAddress
+ (Module->Headers->OptionalHeader
);
ExOrdinals = (USHORT *)
RVA(
- Module->BaseAddress,
+ Module->BaseAddress,
ExportDir->AddressOfNameOrdinals
);
ExFunctions = (PDWORD *)
RVA(
- Module->BaseAddress,
+ Module->BaseAddress,
ExportDir->AddressOfFunctions
);
for ( i = 0;
", sorry\n"
);
return(STATUS_UNSUCCESSFUL);
-
+
default:
DPRINT("unexpected fixup type\n");
return STATUS_UNSUCCESSFUL;
ImageBase
+ *FunctionNameList
);
-
+
*ImportAddressList =
LdrGetExportByName(
Module,
{
PDLLMAIN_FUNC Entrypoint;
NTSTATUS Status;
-
+
if ( Dll == NULL || Dll == &LdrDllListHead )
return -1;
-
-
- if ( Dll->ReferenceCount > 1 )
+
+
+ if ( Dll->ReferenceCount > 1 )
{
Dll->ReferenceCount--;
return STATUS_SUCCESS;
}
- if ( Dll->Headers->FileHeader.Characteristics & IMAGE_FILE_DLL == IMAGE_FILE_DLL ) {
-
+ if (( Dll->Headers->FileHeader.Characteristics & IMAGE_FILE_DLL ) == IMAGE_FILE_DLL ) {
+
Entrypoint = (PDLLMAIN_FUNC) LdrPEStartup(Dll->BaseAddress,
Dll->SectionHandle);
if (Entrypoint != NULL)
Dll->BaseAddress);
ZwClose(Dll->SectionHandle);
-
+
return Status;
}
WORD NumberOfNamedEntries;
- WORD NumberOfIdEntries;
+ WORD NumberOfIdEntries;
WORD Entries;
ULONG Length;
NTSTATUS LdrAccessResource(DLL *Dll, IMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry, void **Data)
{
-
-
-
-
PIMAGE_SECTION_HEADER Sections;
int i;
if ( Dll == NULL )
return -1;
-
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(Dll->BaseAddress);
for ( i = 0;
i++
)
{
-
-
- if (Sections[i].VirtualAddress <= ResourceDataEntry->OffsetToData
+ 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 */