mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
dfb43905bb
Use the PE import table's OriginalFirstThunk array when scanning and resolving imports during DLL binding. It points to an array of pointer-sized IMAGE_THUNK_DATA structures which describe the functions being imported. On the other hand, the FirstThunk points to an array of pointers, whose initial values are a copy of those pointed to by OriginalFirstThunk, but are replaced by the actual function pointers determined at runtime, when a DLL is loaded (see PeLdrpBindImportName() function). If we were to use the FirstThunk array to find again later the imports by name or ordinal, we would fail because these are replaced by the addresses of the corresponding functions. This fixes loading kdcom.dll from Windows XP x64 with FreeLDR when testing on ReactOS x64. ```diff (freeldr\freeldr\lib\peloader.c:498) trace: PeLdrpScanImportAddressTable() ---- Calling PeLdrpBindImportName() in a loop (freeldr\freeldr\lib\peloader.c:501) trace: *** ThunkName->u1.AddressOfData = 00000000000070F0 (freeldr\freeldr\lib\peloader.c:502) trace: *** ThunkData->u1.AddressOfData = 0000000000573780 (freeldr\freeldr\lib\peloader.c:209) trace: !!! ExportDirectory->NumberOfNames 1504 -(freeldr\freeldr\lib\peloader.c:210) trace: !!! ImportHint 0 - ExportName 'CcCanIWrite' - ImportDataName '' +(freeldr\freeldr\lib\peloader.c:210) trace: !!! ImportHint 282 - ExportName 'HalPrivateDispatchTable' - ImportDataName 'HalPrivateDispatchTable' .... -(freeldr\freeldr\lib\peloader.c:268) err: Did not find export ''! -(freeldr\freeldr\lib\peloader.c:709) err: PeLdrpScanImportAddressTable() failed: ImportName = 'ntoskrnl.exe', DirectoryPath = 'multi(0)disk(0)rdisk(0)partition(2)\ReactOS\system32\' ``` ('-': lines before the fix; '+': lines after the fix) Code has been adapted based from the following functions: ntdll/ldr/ldrpe.c!LdrpSnapThunk() and LdrpSnapIAT() ntoskrnl/mm/ARM3/sysldr.c!MiSnapThunk() and MiResolveImageReferences() References: https://devblogs.microsoft.com/oldnewthing/20231129-00/?p=109077 https://devblogs.microsoft.com/oldnewthing/20231130-00/?p=109084 https://stackoverflow.com/questions/42413937/why-pe-need-original-first-thunkoft |
||
---|---|---|
.. | ||
armllb | ||
bcd | ||
bgfx | ||
bootdata | ||
environ | ||
freeldr | ||
rtl | ||
boot_images.cmake | ||
CMakeLists.txt |