- else
- {
- /* It's reference by name, we have to look it up in the export directory */
- if (!ProcessForwards)
- {
- /* AddressOfData in thunk entry will become a virtual address (from relative) */
- //TRACE("WinLdrpBindImportName(): ThunkData->u1.AOD was %p\n", ThunkData->u1.AddressOfData);
- ThunkData->u1.AddressOfData =
- (ULONG_PTR)RVA(ImageBase, ThunkData->u1.AddressOfData);
- //TRACE("WinLdrpBindImportName(): ThunkData->u1.AOD became %p\n", ThunkData->u1.AddressOfData);
- }
-
- /* Get the import name */
- ImportData = VaToPa((PVOID)ThunkData->u1.AddressOfData);
-
- /* Get pointers to Name and Ordinal tables (RVA -> VA) */
- NameTable = VaToPa(RVA(DllBase, ExportDirectory->AddressOfNames));
- OrdinalTable = VaToPa(RVA(DllBase, ExportDirectory->AddressOfNameOrdinals));
-
- //TRACE("NameTable 0x%X, OrdinalTable 0x%X, ED->AddressOfNames 0x%X, ED->AOFO 0x%X\n",
- // NameTable, OrdinalTable, ExportDirectory->AddressOfNames, ExportDirectory->AddressOfNameOrdinals);
-
- /* Get the hint, convert it to a physical pointer */
- Hint = ((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Hint;
- //TRACE("HintIndex %d\n", Hint);
-
- /* Get the export name from the hint */
- ExportName = VaToPa(RVA(DllBase, NameTable[Hint]));
-
- /* If Hint is less than total number of entries in the export directory,
- and import name == export name, then we can just get it from the OrdinalTable */
- if ((Hint < ExportDirectory->NumberOfNames) &&
- (strcmp(ExportName, (PCHAR)ImportData->Name) == 0))
- {
- Ordinal = OrdinalTable[Hint];
- //TRACE("WinLdrpBindImportName(): Ordinal %d\n", Ordinal);
- }
- else
- {
- /* It's not the easy way, we have to lookup import name in the name table.
- Let's use a binary search for this task. */
-
- //TRACE("WinLdrpBindImportName() looking up the import name using binary search...\n");
-
- /* Low boundary is set to 0, and high boundary to the maximum index */
- Low = 0;
- High = ExportDirectory->NumberOfNames - 1;