[ros-diffs] [tkreuzer] 56247: [FREELDR] - Refactor some multiply used overly complex expressions into human readable variable names - Output some useful debuginfo when an import could bot be resolved

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Tue Mar 27 09:47:11 UTC 2012


Author: tkreuzer
Date: Tue Mar 27 09:47:10 2012
New Revision: 56247

URL: http://svn.reactos.org/svn/reactos?rev=56247&view=rev
Log:
[FREELDR]
- Refactor some multiply used overly complex expressions into human readable variable names
- Output some useful debuginfo when an import could bot be resolved

Modified:
    trunk/reactos/boot/freeldr/freeldr/windows/peloader.c

Modified: trunk/reactos/boot/freeldr/freeldr/windows/peloader.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/peloader.c?rev=56247&r1=56246&r2=56247&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] Tue Mar 27 09:47:10 2012
@@ -156,7 +156,8 @@
 
 		if (!Status)
 		{
-			ERR("WinLdrpScanImportAddressTable() failed\n");
+			ERR("WinLdrpScanImportAddressTable() failed: ImportName = '%s', DirectoryPath = '%s'\n",
+				ImportName, DirectoryPath);
 			return Status;
 		}
 	}
@@ -507,6 +508,8 @@
 	PUSHORT OrdinalTable;
 	LONG High, Low, Middle, Result;
 	ULONG Hint;
+    PIMAGE_IMPORT_BY_NAME ImportData;
+    PCHAR ExportName;
 
 	//TRACE("WinLdrpBindImportName(): DllBase 0x%X, ImageBase 0x%X, ThunkData 0x%X, ExportDirectory 0x%X, ExportSize %d, ProcessForwards 0x%X\n",
 	//	DllBase, ImageBase, ThunkData, ExportDirectory, ExportSize, ProcessForwards);
@@ -540,9 +543,12 @@
 			//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 = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNames));
-		OrdinalTable = (PUSHORT)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNameOrdinals));
+		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);
@@ -551,15 +557,13 @@
 		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(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]),
-			       (PCHAR)VaToPa( RVA(DllBase, NameTable[Hint])) ) == 0
-			)
-			)
+		if ((Hint < ExportDirectory->NumberOfNames) &&
+			(strcmp(ExportName, (PCHAR)ImportData->Name) == 0))
 		{
 			Ordinal = OrdinalTable[Hint];
 			//TRACE("WinLdrpBindImportName(): Ordinal %d\n", Ordinal);
@@ -579,11 +583,13 @@
 			while (High >= Low)
 			{
 				/* Divide by 2 by shifting to the right once */
-				Middle = (Low + High) >> 1;
+				Middle = (Low + High) / 2;
+
+				/* Get the name from the name table */
+				ExportName = VaToPa(RVA(DllBase, NameTable[Middle]));
 
 				/* Compare the names */
-				Result = strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]),
-					(PCHAR)VaToPa(RVA(DllBase, NameTable[Middle])));
+				Result = strcmp(ExportName, (PCHAR)ImportData->Name);
 
 				/*TRACE("Binary search: comparing Import '__', Export '%s'\n",*/
 					/*VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name[0]),*/
@@ -595,12 +601,12 @@
 
 
 				/* Depending on result of strcmp, perform different actions */
-				if (Result < 0)
+				if (Result > 0)
 				{
 					/* Adjust top boundary */
 					High = Middle - 1;
 				}
-				else if (Result > 0)
+				else if (Result < 0)
 				{
 					/* Adjust bottom boundary */
 					Low = Middle + 1;
@@ -616,7 +622,7 @@
 			if (High < Low)
 			{
 				//Print(L"Error in binary search\n");
-				ERR("Error in binary search!\n");
+				ERR("Did not find export '%s'!\n", (PCHAR)ImportData->Name);
 				return FALSE;
 			}
 




More information about the Ros-diffs mailing list