[FREELDR] peloader.c: Minor nits

This commit is contained in:
Hermès Bélusca-Maïto
2026-05-06 17:49:18 +02:00
parent 581edfe58e
commit 07f36b52aa

View File

@@ -51,12 +51,11 @@ PeLdrpFetchAddressOfSecurityCookie(PVOID BaseAddress, ULONG SizeOfImage)
TRUE,
IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
&DirSize);
/* Check for sanity */
/* Validate it */
if (!ConfigDir ||
DirSize < RTL_SIZEOF_THROUGH_FIELD(IMAGE_LOAD_CONFIG_DIRECTORY, SecurityCookie))
{
/* Invalid directory*/
/* Invalid directory */
return NULL;
}
@@ -329,11 +328,9 @@ PeLdrpBindImportName(
/* Get pointer to the export directory of loaded DLL */
RefExportDirectory = (PIMAGE_EXPORT_DIRECTORY)
RtlImageDirectoryEntryToData(VaToPa(DataTableEntry->DllBase),
TRUE,
IMAGE_DIRECTORY_ENTRY_EXPORT,
&RefExportSize);
/* Fail if it's NULL */
TRUE,
IMAGE_DIRECTORY_ENTRY_EXPORT,
&RefExportSize);
if (RefExportDirectory)
{
UCHAR Buffer[128];
@@ -476,11 +473,11 @@ PeLdrpScanImportAddressTable(
}
else
{
ExportDirectory =
(PIMAGE_EXPORT_DIRECTORY)RtlImageDirectoryEntryToData(VaToPa(DllBase),
TRUE,
IMAGE_DIRECTORY_ENTRY_EXPORT,
&ExportSize);
ExportDirectory = (PIMAGE_EXPORT_DIRECTORY)
RtlImageDirectoryEntryToData(VaToPa(DllBase),
TRUE,
IMAGE_DIRECTORY_ENTRY_EXPORT,
&ExportSize);
}
TRACE("PeLdrpScanImportAddressTable(): ExportDirectory 0x%p\n", ExportDirectory);
@@ -551,13 +548,11 @@ PeLdrInitSecurityCookie(PLDR_DATA_TABLE_ENTRY LdrEntry)
/* Fetch address of the cookie */
Cookie = PeLdrpFetchAddressOfSecurityCookie(VaToPa(LdrEntry->DllBase), LdrEntry->SizeOfImage);
if (!Cookie)
return NULL;
/* Check if it's a default one */
if ((*Cookie == DEFAULT_SECURITY_COOKIE) ||
(*Cookie == 0))
if ((*Cookie == DEFAULT_SECURITY_COOKIE) || (*Cookie == 0))
{
/* Generate new cookie using cookie address and time as seed */
NewCookie = (ULONG_PTR)Cookie ^ (ULONG_PTR)ArcGetRelativeTime();
@@ -638,8 +633,11 @@ PeLdrScanImportDescriptorTable(
BOOLEAN Success;
/* Get a pointer to the import table of this image */
ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase),
TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)
RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase),
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
&ImportTableSize);
#if DBG
{
@@ -693,7 +691,6 @@ PeLdrScanImportDescriptorTable(
ThunkData,
DirectoryPath,
&ScanDTE->InLoadOrderLinks);
if (!Success)
{
ERR("PeLdrpScanImportAddressTable() failed: ImportName = '%s', DirectoryPath = '%s'\n",
@@ -909,12 +906,10 @@ PeLdrLoadImageEx(
PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage,
(PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)),
MemoryType);
if (PhysicalBase == NULL)
{
/* Don't fail, allocate again at any other "low" place */
PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType);
if (PhysicalBase == NULL)
{
ERR("Failed to alloc %lu bytes for image %s\n", NtHeaders->OptionalHeader.SizeOfImage, FilePath);