ReactOS 0.4.15-dev-8390-g075894b
peloader.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef VOID(NTAPIPELDR_IMPORTDLL_LOAD_CALLBACK) (_In_ PCSTR FileName)
 

Functions

BOOLEAN PeLdrLoadImage (_In_ PCSTR FilePath, _In_ TYPE_OF_MEMORY MemoryType, _Out_ PVOID *ImageBasePA)
 Loads the specified image from the file.
 
BOOLEAN PeLdrAllocateDataTableEntry (IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
 
VOID PeLdrFreeDataTableEntry (_In_ PLDR_DATA_TABLE_ENTRY Entry)
 
BOOLEAN PeLdrScanImportDescriptorTable (IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
 
BOOLEAN PeLdrCheckForLoadedDll (IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)
 
PVOID PeLdrInitSecurityCookie (_In_ PLDR_DATA_TABLE_ENTRY LdrEntry)
 

Variables

PELDR_IMPORTDLL_LOAD_CALLBACK PeLdrImportDllLoadCallback
 

Typedef Documentation

◆ PELDR_IMPORTDLL_LOAD_CALLBACK

typedef VOID(NTAPI * PELDR_IMPORTDLL_LOAD_CALLBACK) (_In_ PCSTR FileName)

Definition at line 23 of file peloader.h.

Function Documentation

◆ PeLdrAllocateDataTableEntry()

BOOLEAN PeLdrAllocateDataTableEntry ( IN OUT PLIST_ENTRY  ModuleListHead,
IN PCCH  BaseDllName,
IN PCCH  FullDllName,
IN PVOID  BasePA,
OUT PLDR_DATA_TABLE_ENTRY NewEntry 
)

Definition at line 681 of file peloader.c.

687{
688 PVOID BaseVA = PaToVa(BasePA);
689 PWSTR BaseDllNameBuffer, Buffer;
690 PLDR_DATA_TABLE_ENTRY DataTableEntry;
691 PIMAGE_NT_HEADERS NtHeaders;
693
694 TRACE("PeLdrAllocateDataTableEntry('%s', '%s', %p)\n",
695 BaseDllName, FullDllName, BasePA);
696
697 /* Allocate memory for a data table entry, zero-initialize it */
700 if (DataTableEntry == NULL)
701 return FALSE;
702
703 /* Get NT headers from the image */
704 NtHeaders = RtlImageNtHeader(BasePA);
705
706 /* Initialize corresponding fields of DTE based on NT headers value */
707 RtlZeroMemory(DataTableEntry, sizeof(LDR_DATA_TABLE_ENTRY));
708 DataTableEntry->DllBase = BaseVA;
709 DataTableEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage;
710 DataTableEntry->EntryPoint = RVA(BaseVA, NtHeaders->OptionalHeader.AddressOfEntryPoint);
711 DataTableEntry->SectionPointer = 0;
712 DataTableEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum;
713
714 /* Initialize BaseDllName field (UNICODE_STRING) from the Ansi BaseDllName
715 by simple conversion - copying each character */
716 Length = (USHORT)(strlen(BaseDllName) * sizeof(WCHAR));
718 if (Buffer == NULL)
719 {
720 FrLdrHeapFree(DataTableEntry, TAG_WLDR_DTE);
721 return FALSE;
722 }
723
724 /* Save Buffer, in case of later failure */
725 BaseDllNameBuffer = Buffer;
726
727 DataTableEntry->BaseDllName.Length = Length;
728 DataTableEntry->BaseDllName.MaximumLength = Length;
729 DataTableEntry->BaseDllName.Buffer = PaToVa(Buffer);
730
732 Length /= sizeof(WCHAR);
733 while (Length--)
734 {
735 *Buffer++ = *BaseDllName++;
736 }
737
738 /* Initialize FullDllName field (UNICODE_STRING) from the Ansi FullDllName
739 using the same method */
740 Length = (USHORT)(strlen(FullDllName) * sizeof(WCHAR));
742 if (Buffer == NULL)
743 {
744 FrLdrHeapFree(BaseDllNameBuffer, TAG_WLDR_NAME);
745 FrLdrHeapFree(DataTableEntry, TAG_WLDR_DTE);
746 return FALSE;
747 }
748
749 DataTableEntry->FullDllName.Length = Length;
750 DataTableEntry->FullDllName.MaximumLength = Length;
751 DataTableEntry->FullDllName.Buffer = PaToVa(Buffer);
752
754 Length /= sizeof(WCHAR);
755 while (Length--)
756 {
757 *Buffer++ = *FullDllName++;
758 }
759
760 /* Initialize what's left - LoadCount which is 1, and set Flags so that
761 we know this entry is processed */
762 DataTableEntry->Flags = LDRP_ENTRY_PROCESSED;
763 DataTableEntry->LoadCount = 1;
764
765 /* Honour the FORCE_INTEGRITY flag */
767 {
768 /*
769 * On Vista and above, the LDRP_IMAGE_INTEGRITY_FORCED flag must be set
770 * if IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY is set in the image header.
771 * This is done after the image has been loaded and the digital signature
772 * check has passed successfully. (We do not do it yet!)
773 *
774 * Several OS functionality depend on the presence of this flag.
775 * For example, when using Object-Manager callbacks the latter will call
776 * MmVerifyCallbackFunction() to verify whether the flag is present.
777 * If not callbacks will not work.
778 * (See Windows Internals Part 1, 6th edition, p. 176.)
779 */
780 DataTableEntry->Flags |= LDRP_IMAGE_INTEGRITY_FORCED;
781 }
782
783 /* Insert this DTE to a list in the LPB */
785 TRACE("Inserting DTE %p, name='%.*S' DllBase=%p\n", DataTableEntry,
786 DataTableEntry->BaseDllName.Length / sizeof(WCHAR),
787 VaToPa(DataTableEntry->BaseDllName.Buffer),
788 DataTableEntry->DllBase);
789
790 /* Save pointer to a newly allocated and initialized entry */
791 *NewEntry = DataTableEntry;
792
793 /* Return success */
794 return TRUE;
795}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
FORCEINLINE VOID FrLdrHeapFree(PVOID MemoryPointer, ULONG Tag)
Definition: mm.h:181
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: mm.h:174
struct _LDR_DATA_TABLE_ENTRY * PLDR_DATA_TABLE_ENTRY
Definition: bufpool.h:45
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
FORCEINLINE PVOID PaToVa(PVOID Pa)
Definition: conversion.h:22
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define RtlImageNtHeader
Definition: compat.h:806
#define InsertTailList(ListHead, Entry)
#define RVA(m, b)
Definition: freeldr.h:28
#define TAG_WLDR_DTE
Definition: winldr.h:13
#define TAG_WLDR_NAME
Definition: winldr.h:15
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
#define LDRP_IMAGE_INTEGRITY_FORCED
Definition: ldrtypes.h:41
#define LDRP_ENTRY_PROCESSED
Definition: ldrtypes.h:44
_In_ PCWSTR FullDllName
Definition: ldrtypes.h:247
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY
Definition: ntimage.h:456
unsigned short USHORT
Definition: pedump.c:61
#define TRACE(s)
Definition: solgame.cpp:4
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
Definition: btrfs_drv.h:1876
USHORT LoadCount
Definition: ntddk_ex.h:208
PVOID EntryPoint
Definition: ntddk_ex.h:203
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1882
ULONG SizeOfImage
Definition: ldrtypes.h:143
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
PVOID DllBase
Definition: btrfs_drv.h:1880
ULONG Flags
Definition: ntddk_ex.h:207
PVOID SectionPointer
Definition: ntddk_ex.h:213
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
ULONG CheckSum
Definition: btrfs_drv.h:1886
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by LoadBootDeviceDriver(), LoadModule(), PeLdrpLoadAndScanReferencedDll(), and WinLdrLoadDeviceDriver().

◆ PeLdrCheckForLoadedDll()

BOOLEAN PeLdrCheckForLoadedDll ( IN OUT PLIST_ENTRY  ModuleListHead,
IN PCH  DllName,
OUT PLDR_DATA_TABLE_ENTRY LoadedEntry 
)

Definition at line 561 of file peloader.c.

565{
566 PLDR_DATA_TABLE_ENTRY DataTableEntry;
567 LIST_ENTRY *ModuleEntry;
568
569 TRACE("PeLdrCheckForLoadedDll: DllName %s\n", DllName);
570
571 /* Just go through each entry in the LoadOrderList and compare loaded module's
572 name with a given name */
573 ModuleEntry = ModuleListHead->Flink;
574 while (ModuleEntry != ModuleListHead)
575 {
576 /* Get pointer to the current DTE */
577 DataTableEntry = CONTAINING_RECORD(ModuleEntry,
579 InLoadOrderLinks);
580
581 TRACE("PeLdrCheckForLoadedDll: DTE %p, EP %p, base %p name '%.*ws'\n",
582 DataTableEntry, DataTableEntry->EntryPoint, DataTableEntry->DllBase,
583 DataTableEntry->BaseDllName.Length / 2, VaToPa(DataTableEntry->BaseDllName.Buffer));
584
585 /* Compare names */
586 if (PeLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName))
587 {
588 /* Yes, found it, report pointer to the loaded module's DTE
589 to the caller and increase load count for it */
590 *LoadedEntry = DataTableEntry;
591 DataTableEntry->LoadCount++;
592 TRACE("PeLdrCheckForLoadedDll: LoadedEntry %X\n", DataTableEntry);
593 return TRUE;
594 }
595
596 /* Go to the next entry */
597 ModuleEntry = ModuleEntry->Flink;
598 }
599
600 /* Nothing found */
601 return FALSE;
602}
static BOOLEAN PeLdrpCompareDllName(IN PCH DllName, IN PUNICODE_STRING UnicodeName)
Definition: peloader.c:77
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by PeLdrpBindImportName(), PeLdrScanImportDescriptorTable(), and WinLdrLoadDeviceDriver().

◆ PeLdrFreeDataTableEntry()

VOID PeLdrFreeDataTableEntry ( _In_ PLDR_DATA_TABLE_ENTRY  Entry)

Definition at line 798 of file peloader.c.

801{
802 // ASSERT(ModuleListHead);
803 ASSERT(Entry);
804
805 RemoveEntryList(&Entry->InLoadOrderLinks);
806 FrLdrHeapFree(VaToPa(Entry->FullDllName.Buffer), TAG_WLDR_NAME);
807 FrLdrHeapFree(VaToPa(Entry->BaseDllName.Buffer), TAG_WLDR_NAME);
809}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define ASSERT(a)
Definition: mode.c:44
base of all file and directory entries
Definition: entries.h:83

Referenced by LoadBootDeviceDriver(), LoadWindowsCore(), PeLdrpLoadAndScanReferencedDll(), and WinLdrLoadDeviceDriver().

◆ PeLdrInitSecurityCookie()

PVOID PeLdrInitSecurityCookie ( _In_ PLDR_DATA_TABLE_ENTRY  LdrEntry)

◆ PeLdrLoadImage()

BOOLEAN PeLdrLoadImage ( _In_ PCSTR  FilePath,
_In_ TYPE_OF_MEMORY  MemoryType,
_Out_ PVOID ImageBasePA 
)

Loads the specified image from the file.

PeLdrLoadImage doesn't perform any additional operations on the file path, it just directly calls the file I/O routines. It then relocates the image so that it's ready to be used when paging is enabled.

Note
Addressing mode: physical.

Definition at line 823 of file peloader.c.

827{
828 ULONG FileId;
829 PVOID PhysicalBase;
830 PVOID VirtualBase = NULL;
831 UCHAR HeadersBuffer[SECTOR_SIZE * 2];
832 PIMAGE_NT_HEADERS NtHeaders;
833 PIMAGE_SECTION_HEADER SectionHeader;
834 ULONG VirtualSize, SizeOfRawData, NumberOfSections;
838
839 TRACE("PeLdrLoadImage('%s', %ld)\n", FilePath, MemoryType);
840
841 /* Open the image file */
843 if (Status != ESUCCESS)
844 {
845 WARN("ArcOpen('%s') failed. Status: %u\n", FilePath, Status);
846 return FALSE;
847 }
848
849 /* Load the first 2 sectors of the image so we can read the PE header */
850 Status = ArcRead(FileId, HeadersBuffer, SECTOR_SIZE * 2, &BytesRead);
851 if (Status != ESUCCESS)
852 {
853 ERR("ArcRead('%s') failed. Status: %u\n", FilePath, Status);
854 ArcClose(FileId);
855 return FALSE;
856 }
857
858 /* Now read the MZ header to get the offset to the PE Header */
859 NtHeaders = RtlImageNtHeader(HeadersBuffer);
860 if (!NtHeaders)
861 {
862 ERR("No NT header found in \"%s\"\n", FilePath);
863 ArcClose(FileId);
864 return FALSE;
865 }
866
867 /* Ensure this is executable image */
869 {
870 ERR("Not an executable image \"%s\"\n", FilePath);
871 ArcClose(FileId);
872 return FALSE;
873 }
874
875 /* Store number of sections to read and a pointer to the first section */
876 NumberOfSections = NtHeaders->FileHeader.NumberOfSections;
877 SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
878
879 /* Try to allocate this memory; if it fails, allocate somewhere else */
880 PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage,
881 (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)),
882 MemoryType);
883
884 if (PhysicalBase == NULL)
885 {
886 /* Don't fail, allocate again at any other "low" place */
887 PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType);
888
889 if (PhysicalBase == NULL)
890 {
891 ERR("Failed to alloc %lu bytes for image %s\n", NtHeaders->OptionalHeader.SizeOfImage, FilePath);
892 ArcClose(FileId);
893 return FALSE;
894 }
895 }
896
897 /* This is the real image base, in form of a virtual address */
898 VirtualBase = PaToVa(PhysicalBase);
899
900 TRACE("Base PA: 0x%X, VA: 0x%X\n", PhysicalBase, VirtualBase);
901
902 /* Copy headers from already read data */
903 RtlCopyMemory(PhysicalBase, HeadersBuffer, min(NtHeaders->OptionalHeader.SizeOfHeaders, sizeof(HeadersBuffer)));
904 /* If headers are quite big, request next bytes from file */
905 if (NtHeaders->OptionalHeader.SizeOfHeaders > sizeof(HeadersBuffer))
906 {
907 Status = ArcRead(FileId, (PUCHAR)PhysicalBase + sizeof(HeadersBuffer), NtHeaders->OptionalHeader.SizeOfHeaders - sizeof(HeadersBuffer), &BytesRead);
908 if (Status != ESUCCESS)
909 {
910 ERR("ArcRead('%s') failed. Status: %u\n", FilePath, Status);
911 // UiMessageBox("Error reading headers.");
912 ArcClose(FileId);
913 goto Failure;
914 }
915 }
916
917 /*
918 * On Vista and above, a digital signature check is performed when the image
919 * has the IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY flag set in its header.
920 * (We of course do not perform this check yet!)
921 */
922
923 /* Reload the NT Header */
924 NtHeaders = RtlImageNtHeader(PhysicalBase);
925
926 /* Load the first section */
927 SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
928
929 /* Walk through each section and read it (check/fix any possible
930 bad situations, if they arise) */
931 for (i = 0; i < NumberOfSections; i++)
932 {
933 VirtualSize = SectionHeader->Misc.VirtualSize;
934 SizeOfRawData = SectionHeader->SizeOfRawData;
935
936 /* Handle a case when VirtualSize equals 0 */
937 if (VirtualSize == 0)
938 VirtualSize = SizeOfRawData;
939
940 /* If PointerToRawData is 0, then force its size to be also 0 */
941 if (SectionHeader->PointerToRawData == 0)
942 {
943 SizeOfRawData = 0;
944 }
945 else
946 {
947 /* Cut the loaded size to the VirtualSize extents */
948 if (SizeOfRawData > VirtualSize)
949 SizeOfRawData = VirtualSize;
950 }
951
952 /* Actually read the section (if its size is not 0) */
953 if (SizeOfRawData != 0)
954 {
955 /* Seek to the correct position */
956 Position.QuadPart = SectionHeader->PointerToRawData;
957 Status = ArcSeek(FileId, &Position, SeekAbsolute);
958
959 TRACE("SH->VA: 0x%X\n", SectionHeader->VirtualAddress);
960
961 /* Read this section from the file, size = SizeOfRawData */
962 Status = ArcRead(FileId, (PUCHAR)PhysicalBase + SectionHeader->VirtualAddress, SizeOfRawData, &BytesRead);
963 if (Status != ESUCCESS)
964 {
965 ERR("PeLdrLoadImage(): Error reading section from file!\n");
966 break;
967 }
968 }
969
970 /* Size of data is less than the virtual size: fill up the remainder with zeroes */
971 if (SizeOfRawData < VirtualSize)
972 {
973 TRACE("PeLdrLoadImage(): SORD %d < VS %d\n", SizeOfRawData, VirtualSize);
974 RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG_PTR)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData);
975 }
976
977 SectionHeader++;
978 }
979
980 /* We are done with the file, close it */
981 ArcClose(FileId);
982
983 /* If loading failed, return right now */
984 if (Status != ESUCCESS)
985 goto Failure;
986
987 /* Relocate the image, if it needs it */
988 if (NtHeaders->OptionalHeader.ImageBase != (ULONG_PTR)VirtualBase)
989 {
990 WARN("Relocating %p -> %p\n", NtHeaders->OptionalHeader.ImageBase, VirtualBase);
991 Status = LdrRelocateImageWithBias(PhysicalBase,
992 (ULONG_PTR)VirtualBase - (ULONG_PTR)PhysicalBase,
993 "FreeLdr",
994 ESUCCESS,
995 ESUCCESS, /* In case of conflict still return success */
996 ENOEXEC);
997 if (Status != ESUCCESS)
998 goto Failure;
999 }
1000
1001 /* Fill output parameters */
1002 *ImageBasePA = PhysicalBase;
1003
1004 TRACE("PeLdrLoadImage() done, PA = %p\n", *ImageBasePA);
1005 return TRUE;
1006
1007Failure:
1008 /* Cleanup and bail out */
1009 MmFreeMemory(PhysicalBase);
1010 return FALSE;
1011}
PCWSTR FilePath
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:220
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: fs.c:245
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
#define SECTOR_SIZE
Definition: fs.h:22
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:238
PVOID MmAllocateMemoryAtAddress(SIZE_T MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:85
VOID MmFreeMemory(PVOID MemoryPointer)
Definition: mm.c:215
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
#define ENOEXEC
Definition: errno.h:14
Status
Definition: gdiplustypes.h:25
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 min(a, b)
Definition: monoChain.cc:55
#define KSEG0_BASE
Definition: ketypes.h:354
ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
Definition: image.c:474
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
@ ESUCCESS
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
@ SeekAbsolute
Definition: arc.h:59
@ OpenReadOnly
Definition: arc.h:65
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
union _IMAGE_SECTION_HEADER::@1557 Misc
DWORD PointerToRawData
Definition: pedump.c:290
static COORD Position
Definition: mouse.c:34
char * PSTR
Definition: typedefs.h:51
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by LoadBootDeviceDriver(), LoadModule(), PeLdrpLoadAndScanReferencedDll(), and WinLdrLoadDeviceDriver().

◆ PeLdrScanImportDescriptorTable()

BOOLEAN PeLdrScanImportDescriptorTable ( IN OUT PLIST_ENTRY  ModuleListHead,
IN PCCH  DirectoryPath,
IN PLDR_DATA_TABLE_ENTRY  ScanDTE 
)

Definition at line 605 of file peloader.c.

609{
610 PLDR_DATA_TABLE_ENTRY DataTableEntry;
611 PIMAGE_IMPORT_DESCRIPTOR ImportTable;
612 ULONG ImportTableSize;
613 PCH ImportName;
615
616 /* Get a pointer to the import table of this image */
617 ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase),
618 TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
619
620#if DBG
621 {
622 UNICODE_STRING BaseName;
623 BaseName.Buffer = VaToPa(ScanDTE->BaseDllName.Buffer);
624 BaseName.MaximumLength = ScanDTE->BaseDllName.MaximumLength;
625 BaseName.Length = ScanDTE->BaseDllName.Length;
626 TRACE("PeLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%X\n",
627 &BaseName, ImportTable);
628 }
629#endif
630
631 /* If image doesn't have any import directory - just return success */
632 if (ImportTable == NULL)
633 return TRUE;
634
635 /* Loop through all entries */
636 for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
637 {
638 /* Get pointer to the name */
639 ImportName = (PCH)VaToPa(RVA(ScanDTE->DllBase, ImportTable->Name));
640 TRACE("PeLdrScanImportDescriptorTable(): Looking at %s\n", ImportName);
641
642 /* In case we get a reference to ourselves - just skip it */
643 if (PeLdrpCompareDllName(ImportName, &ScanDTE->BaseDllName))
644 continue;
645
646 /* Load the DLL if it is not already loaded */
647 if (!PeLdrCheckForLoadedDll(ModuleListHead, ImportName, &DataTableEntry))
648 {
650 DirectoryPath,
651 ImportName,
652 &ScanDTE->InLoadOrderLinks,
653 &DataTableEntry);
654 if (!Success)
655 {
656 ERR("PeLdrpLoadAndScanReferencedDll() failed\n");
657 return Success;
658 }
659 }
660
661 /* Scan its import address table */
663 DataTableEntry->DllBase,
664 ScanDTE->DllBase,
665 (PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk),
666 DirectoryPath,
667 &ScanDTE->InLoadOrderLinks);
668
669 if (!Success)
670 {
671 ERR("PeLdrpScanImportAddressTable() failed: ImportName = '%s', DirectoryPath = '%s'\n",
672 ImportName, DirectoryPath);
673 return Success;
674 }
675 }
676
677 return TRUE;
678}
unsigned char BOOLEAN
DWORD RVA
Definition: compat.h:1262
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
@ Success
Definition: eventcreate.c:712
CHAR * PCH
Definition: ntbasedef.h:391
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
static BOOLEAN PeLdrpScanImportAddressTable(IN OUT PLIST_ENTRY ModuleListHead, IN PVOID DllBase, IN PVOID ImageBase, IN PIMAGE_THUNK_DATA ThunkData, IN PCSTR DirectoryPath, IN PLIST_ENTRY Parent)
Definition: peloader.c:453
BOOLEAN PeLdrCheckForLoadedDll(IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)
Definition: peloader.c:561
static BOOLEAN PeLdrpLoadAndScanReferencedDll(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PCH ImportName, IN PLIST_ENTRY Parent OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry)
Definition: peloader.c:389

Referenced by LoadBootDeviceDriver(), LoadWindowsCore(), PeLdrpLoadAndScanReferencedDll(), and WinLdrLoadDeviceDriver().

Variable Documentation

◆ PeLdrImportDllLoadCallback

PELDR_IMPORTDLL_LOAD_CALLBACK PeLdrImportDllLoadCallback
extern

Definition at line 28 of file peloader.c.

Referenced by LoadAndBootWindowsCommon(), and PeLdrpLoadAndScanReferencedDll().