Author: fireball Date: Wed Mar 23 12:25:53 2011 New Revision: 51123
URL: http://svn.reactos.org/svn/reactos?rev=51123&view=rev Log: [NTDLL/LDR] - Fix a few bugs (wrong variable usage, wrong variable initialization) which led to incorrect snapping of import address table. - Wrap LdrpSnapThunk() invocations into SEH.
Modified: trunk/reactos/dll/ntdll/ldr/ldrpe.c
Modified: trunk/reactos/dll/ntdll/ldr/ldrpe.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrpe.c?rev=5... ============================================================================== --- trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] Wed Mar 23 12:25:53 2011 @@ -44,13 +44,15 @@ ULONG IatSize; //PPEB Peb = NtCurrentPeb(); NTSTATUS Status; - PIMAGE_THUNK_DATA Thunk, OriginalThunk, FirstThunk; + PIMAGE_THUNK_DATA OriginalThunk, FirstThunk; LPSTR ImportName; ULONG ForwarderChain; PIMAGE_NT_HEADERS NtHeader; PIMAGE_SECTION_HEADER SectionHeader; ULONG i, Rva; ULONG OldProtect; + + DPRINT("LdrpSnapIAT(%wZ %wZ %p %d)\n", &ExportLdrEntry->BaseDllName, &ImportLdrEntry->BaseDllName, IatEntry, EntriesValid);
/* Get export directory */ ExportDirectory = RtlImageDirectoryEntryToData(ExportLdrEntry->DllBase, @@ -101,13 +103,13 @@ { IatSize = SectionHeader->SizeOfRawData; } - + /* Found it, get out */ break; }
/* No match, move to the next section */ - ++SectionHeader; + SectionHeader++; } }
@@ -154,17 +156,24 @@ ForwarderChain = (ULONG)FirstThunk->u1.Ordinal;
/* Snap the thunk */ - Status = LdrpSnapThunk(ExportLdrEntry->DllBase, - ImportLdrEntry->DllBase, - OriginalThunk, - FirstThunk, - ExportDirectory, - ExportSize, - TRUE, - ImportName); - - /* Move to the next thunk */ - FirstThunk++; + _SEH2_TRY + { + Status = LdrpSnapThunk(ExportLdrEntry->DllBase, + ImportLdrEntry->DllBase, + OriginalThunk, + FirstThunk, + ExportDirectory, + ExportSize, + TRUE, + ImportName); + + /* Move to the next thunk */ + FirstThunk++; + } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + /* Fail with the SEH error */ + Status = _SEH2_GetExceptionCode(); + } _SEH2_END;
/* If we messed up, exit */ if (!NT_SUCCESS(Status)) break; @@ -184,7 +193,7 @@ if ((IatEntry->Characteristics < NtHeader->OptionalHeader.SizeOfHeaders) || (IatEntry->Characteristics >= NtHeader->OptionalHeader.SizeOfImage)) { - /* Reuse it, this is a strange linked file */ + /* Refuse it, this is a strange linked file */ OriginalThunk = FirstThunk; } else @@ -203,18 +212,25 @@ while (OriginalThunk->u1.AddressOfData) { /* Snap the Thunk */ - Status = LdrpSnapThunk(ExportLdrEntry->DllBase, - ImportLdrEntry->DllBase, - OriginalThunk, - FirstThunk, - ExportDirectory, - ExportSize, - TRUE, - ImportName); - - /* Next thunks */ - OriginalThunk++; - Thunk++; + _SEH2_TRY + { + Status = LdrpSnapThunk(ExportLdrEntry->DllBase, + ImportLdrEntry->DllBase, + OriginalThunk, + FirstThunk, + ExportDirectory, + ExportSize, + TRUE, + ImportName); + + /* Next thunks */ + OriginalThunk++; + FirstThunk++; + } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + /* Fail with the SEH error */ + Status = _SEH2_GetExceptionCode(); + } _SEH2_END;
/* If we failed the snap, break out */ if (!NT_SUCCESS(Status)) break; @@ -498,7 +514,7 @@ //ULONG IatSize, i; LPSTR ImportName; NTSTATUS Status; - BOOLEAN AlreadyLoaded = FALSE, StaticEntriesValid = FALSE, SkipSnap = TRUE; + BOOLEAN AlreadyLoaded = FALSE, StaticEntriesValid = FALSE, SkipSnap = FALSE; PLDR_DATA_TABLE_ENTRY DllLdrEntry; PIMAGE_THUNK_DATA FirstThunk; PPEB Peb = NtCurrentPeb();