33#define COOKIE_MAX 0x0000FFFFFFFFFFFFll
34#define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll
36#define DEFAULT_SECURITY_COOKIE 0xBB40E64E
95 TRACE(
"PeLdrpCompareDllName: %s and %wZ, Length = %d "
156 PCHAR ExportName, ForwarderName;
166 WARN(
"DllBase == NULL\n");
171 ThunkName =
VaToPa(ThunkName);
172 ThunkData =
VaToPa(ThunkData);
184 if (!ProcessForwards)
188 ThunkName->u1.AddressOfData =
194 ImportData =
VaToPa((
PVOID)ThunkName->u1.AddressOfData);
197 NameTable =
VaToPa(
RVA(DllBase, ExportDirectory->AddressOfNames));
198 OrdinalTable =
VaToPa(
RVA(DllBase, ExportDirectory->AddressOfNameOrdinals));
204 Hint = ImportData->
Hint;
208 ExportName =
VaToPa(
RVA(DllBase, NameTable[Hint]));
212 if ((Hint < ExportDirectory->NumberOfNames) &&
215 Ordinal = OrdinalTable[Hint];
227 High = ExportDirectory->NumberOfNames - 1;
236 ExportName =
VaToPa(
RVA(DllBase, NameTable[Middle]));
265 ERR(
"Did not find export '%s'!\n", (
PCHAR)ImportData->
Name);
270 Ordinal = OrdinalTable[Middle];
276 if (Ordinal >= ExportDirectory->NumberOfFunctions)
278 ERR(
"Ordinal number is invalid!\n");
296 CHAR ForwardDllName[256];
298 TRACE(
"PeLdrpBindImportName(): ForwarderName %s\n", ForwarderName);
301 RtlCopyMemory(ForwardDllName, ForwarderName,
sizeof(ForwardDllName));
324 ERR(
"PeLdrpLoadAndScanReferencedDll() failed to load forwarder dll.\n");
337 if (RefExportDirectory)
345 ImportName =
strrchr(ForwarderName,
'.') + 1;
354 ImportByName->
Hint = 0;
372 ThunkData->u1 = RefThunkData.
u1;
437 TRACE(
"PeLdrScanImportDescriptorTable() calling ourselves for '%.*S'\n",
438 (*DataTableEntry)->BaseDllName.Length /
sizeof(
WCHAR),
439 VaToPa((*DataTableEntry)->BaseDllName.Buffer));
444 ERR(
"PeLdrScanImportDescriptorTable() failed\n");
467 TRACE(
"PeLdrpScanImportAddressTable(): "
468 "DllBase 0x%p, ImageBase 0x%p, ThunkName 0x%p, ThunkData 0x%p\n",
469 DllBase, ImageBase, ThunkName, ThunkData);
474 ERR(
"DllBase == NULL\n");
485 TRACE(
"PeLdrpScanImportAddressTable(): ExportDirectory 0x%p\n", ExportDirectory);
488 if (!ExportDirectory)
490 ERR(
"No ExportDir, DllBase = %p (%p)\n", DllBase,
VaToPa(DllBase));
540 ERR(
"Failed to allocate DTE for freeldr\n");
567 if (NewCookie > COOKIE_MAX)
573 if ((NewCookie == 0) || (NewCookie == *
Cookie))
595 TRACE(
"PeLdrCheckForLoadedDll: DllName %s\n", DllName);
607 TRACE(
"PeLdrCheckForLoadedDll: DTE %p, EP %p, Base %p, Name '%.*S'\n",
617 *LoadedEntry = DataTableEntry;
619 TRACE(
"PeLdrCheckForLoadedDll: LoadedEntry 0x%p\n", DataTableEntry);
624 ModuleEntry = ModuleEntry->
Flink;
639 ULONG ImportTableSize;
652 BaseName.
Length = ScanDTE->BaseDllName.Length;
653 TRACE(
"PeLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%p\n",
654 &BaseName, ImportTable);
670 TRACE(
"PeLdrScanImportDescriptorTable(): Looking at %s\n", ImportName);
682 &ScanDTE->InLoadOrderLinks,
686 ERR(
"PeLdrpLoadAndScanReferencedDll() failed\n");
698 &ScanDTE->InLoadOrderLinks);
702 ERR(
"PeLdrpScanImportAddressTable() failed: ImportName = '%s', DirectoryPath = '%s'\n",
703 ImportName, DirectoryPath);
725 TRACE(
"PeLdrAllocateDataTableEntry('%s', '%s', %p)\n",
731 if (DataTableEntry ==
NULL)
739 DataTableEntry->
DllBase = BaseVA;
756 BaseDllNameBuffer =
Buffer;
766 *
Buffer++ = *BaseDllName++;
816 TRACE(
"Inserting DTE %p, name='%.*S' DllBase=%p\n", DataTableEntry,
822 *NewEntry = DataTableEntry;
866 ULONG VirtualSize, SizeOfRawData, NumberOfSections;
916 if (PhysicalBase ==
NULL)
921 if (PhysicalBase ==
NULL)
930 VirtualBase = KernelMapping ?
PaToVa(PhysicalBase) : PhysicalBase;
932 TRACE(
"Base PA: 0x%p, VA: 0x%p\n", PhysicalBase, VirtualBase);
963 for (
i = 0;
i < NumberOfSections;
i++)
969 if (VirtualSize == 0)
970 VirtualSize = SizeOfRawData;
980 if (SizeOfRawData > VirtualSize)
981 SizeOfRawData = VirtualSize;
985 if (SizeOfRawData != 0)
997 ERR(
"PeLdrLoadImage(): Error reading section from file!\n");
1003 if (SizeOfRawData < VirtualSize)
1005 TRACE(
"PeLdrLoadImage(): SORD %d < VS %d\n", SizeOfRawData, VirtualSize);
1034 *ImageBasePA = PhysicalBase;
1036 TRACE(
"PeLdrLoadImage() done, PA = %p\n", *ImageBasePA);
1083 ERR(
"Failed to allocate DTE for '%s'\n",
FilePath);
1093 ERR(
"Failed to resolve imports for '%s'\n",
FilePath);
int strcmp(const char *String1, const char *String2)
ACPI_SIZE strlen(const char *String)
char * strchr(const char *String, int ch)
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
ULONG ArcGetRelativeTime(VOID)
#define DBG_DEFAULT_CHANNEL(ch)
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
ARC_STATUS ArcClose(_In_ ULONG FileId)
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
PVOID MmAllocateMemoryAtAddress(SIZE_T MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType)
VOID MmFreeMemory(PVOID MemoryPointer)
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
FORCEINLINE VOID FrLdrHeapFree(PVOID MemoryPointer, ULONG Tag)
FORCEINLINE PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
struct _LDR_DATA_TABLE_ENTRY * PLDR_DATA_TABLE_ENTRY
FORCEINLINE PVOID VaToPa(PVOID Va)
FORCEINLINE PVOID PaToVa(PVOID Pa)
#define IMAGE_DIRECTORY_ENTRY_EXPORT
struct _IMAGE_EXPORT_DIRECTORY * PIMAGE_EXPORT_DIRECTORY
#define RtlImageDirectoryEntryToData
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
#define InitializeListHead(ListHead)
IN PDCB IN POEM_STRING IN PUNICODE_STRING UnicodeName
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
LIST_ENTRY * ModuleListHead
#define LDRP_IMAGE_INTEGRITY_FORCED
#define LDRP_DRIVER_DEPENDENT_DLL
#define LDRP_ENTRY_PROCESSED
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
_In_ ULONG _In_ ULONG _In_ ULONG Length
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
#define IMAGE_SNAP_BY_ORDINAL(Ordinal)
#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY
#define IMAGE_FIRST_SECTION(NtHeader)
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
#define IMAGE_FILE_EXECUTABLE_IMAGE
#define IMAGE_DIRECTORY_ENTRY_IMPORT
struct _IMAGE_IMPORT_BY_NAME * PIMAGE_IMPORT_BY_NAME
#define IMAGE_ORDINAL(Ordinal)
BOOLEAN PeLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
static BOOLEAN PeLdrpBindImportName(_Inout_ PLIST_ENTRY ModuleListHead, _In_ PVOID DllBase, _In_ PVOID ImageBase, _In_ PIMAGE_THUNK_DATA ThunkName, _Inout_ PIMAGE_THUNK_DATA ThunkData, _In_ PIMAGE_EXPORT_DIRECTORY ExportDirectory, _In_ ULONG ExportSize, _In_ BOOLEAN ProcessForwards, _In_ PCSTR DirectoryPath, _In_ PLIST_ENTRY Parent)
VOID PeLdrFreeDataTableEntry(_In_ PLDR_DATA_TABLE_ENTRY Entry)
BOOLEAN PeLdrCheckForLoadedDll(IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)
PELDR_IMPORTDLL_LOAD_CALLBACK PeLdrImportDllLoadCallback
BOOLEAN PeLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BaseVA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
#define DEFAULT_SECURITY_COOKIE
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)
static BOOLEAN PeLdrpCompareDllName(IN PCH DllName, IN PUNICODE_STRING UnicodeName)
static PVOID PeLdrpFetchAddressOfSecurityCookie(PVOID BaseAddress, ULONG SizeOfImage)
BOOLEAN PeLdrLoadBootImage(_In_ PCSTR FilePath, _In_ PCSTR BaseDllName, _Out_ PVOID *ImageBase, _Out_ PLDR_DATA_TABLE_ENTRY *DataTableEntry)
BOOLEAN PeLdrInitializeModuleList(VOID)
BOOLEAN PeLdrLoadImageEx(_In_ PCSTR FilePath, _In_ TYPE_OF_MEMORY MemoryType, _Out_ PVOID *ImageBasePA, _In_ BOOLEAN KernelMapping)
Loads the specified image from the file.
PVOID PeLdrInitSecurityCookie(PLDR_DATA_TABLE_ENTRY LdrEntry)
BOOLEAN PeLdrLoadImage(_In_ PCSTR FilePath, _In_ TYPE_OF_MEMORY MemoryType, _Out_ PVOID *ImageBasePA)
static BOOLEAN PeLdrpScanImportAddressTable(_Inout_ PLIST_ENTRY ModuleListHead, _In_ PVOID DllBase, _In_ PVOID ImageBase, _In_ PIMAGE_THUNK_DATA ThunkName, _Inout_ PIMAGE_THUNK_DATA ThunkData, _In_ PCSTR DirectoryPath, _In_ PLIST_ENTRY Parent)
LIST_ENTRY FrLdrModuleList
VOID(NTAPI * PELDR_IMPORTDLL_LOAD_CALLBACK)(_In_ PCSTR FileName)
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
enum _TYPE_OF_MEMORY TYPE_OF_MEMORY
PULONG MinorVersion OPTIONAL
base of all file and directory entries
union _IMAGE_THUNK_DATA32::@2143 u1
UNICODE_STRING FullDllName
LIST_ENTRY InLoadOrderLinks
UNICODE_STRING BaseDllName
struct _LIST_ENTRY * Flink
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
_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
static WLX_DISPATCH_VERSION_1_4 FunctionTable
_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
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie