[ros-diffs] [tkreuzer] 44320: [MM] MiReloadBootLoadedDrivers: - Allow images with relocations stripped. - Make sure NumberOfRvaAndSizes is *>* IMAGE_DIRECTORY_ENTRY_BASERELOC (== is not enough) - Move one ASSERT, remove a useless ASSERT

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Sun Nov 29 16:51:47 CET 2009


Author: tkreuzer
Date: Sun Nov 29 16:51:46 2009
New Revision: 44320

URL: http://svn.reactos.org/svn/reactos?rev=44320&view=rev
Log:
[MM]
MiReloadBootLoadedDrivers:
- Allow images with relocations stripped.
- Make sure NumberOfRvaAndSizes is *>* IMAGE_DIRECTORY_ENTRY_BASERELOC (== is not enough)
- Move one ASSERT, remove a useless ASSERT

Modified:
    branches/ros-amd64-bringup/reactos/ntoskrnl/mm/sysldr.c

Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/mm/sysldr.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskrnl/mm/sysldr.c?rev=44320&r1=44319&r2=44320&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/mm/sysldr.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/mm/sysldr.c [iso-8859-1] Sun Nov 29 16:51:46 2009
@@ -1200,10 +1200,13 @@
     PIMAGE_NT_HEADERS NtHeader;
     PLDR_DATA_TABLE_ENTRY LdrEntry;
     PIMAGE_FILE_HEADER FileHeader;
-    BOOLEAN ValidRelocs;
+    BOOLEAN ValidRelocs = FALSE;
     PIMAGE_DATA_DIRECTORY DataDirectory;
     PVOID DllBase, NewImageAddress;
     NTSTATUS Status;
+
+    /* Sanity check */
+    ASSERT(ExpInitializationPhase == 0);
 
     /* Loop driver list */
     for (NextEntry = LoaderBlock->LoadOrderListHead.Flink;
@@ -1230,32 +1233,28 @@
         /* Skip non-drivers */
         if (!NtHeader) continue;
 
-        /* Get the file header and make sure we can relocate */
+        /* Get the file header and check if we can relocate */
         FileHeader = &NtHeader->FileHeader;
-        if (FileHeader->Characteristics & IMAGE_FILE_RELOCS_STRIPPED) continue;
-        if (NtHeader->OptionalHeader.NumberOfRvaAndSizes <
-            IMAGE_DIRECTORY_ENTRY_BASERELOC) continue;
-
-        /* Everything made sense until now, check the relocation section too */
-        DataDirectory = &NtHeader->OptionalHeader.
-                        DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
-        if (!DataDirectory->VirtualAddress)
-        {
-            /* We don't really have relocations */
-            ValidRelocs = FALSE;
-        }
-        else
-        {
-            /* Make sure the size is valid */
-            if ((DataDirectory->VirtualAddress + DataDirectory->Size) >
-                LdrEntry->SizeOfImage)
+        if ( !(FileHeader->Characteristics & IMAGE_FILE_RELOCS_STRIPPED) &&
+             (NtHeader->OptionalHeader.NumberOfRvaAndSizes >
+              IMAGE_DIRECTORY_ENTRY_BASERELOC) )
+        {
+            /* Everything made sense until now, check the relocation section too */
+            DataDirectory = &NtHeader->OptionalHeader.
+                            DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
+            if (DataDirectory->VirtualAddress)
             {
-                /* They're not, skip */
-                continue;
+                /* Make sure the size is valid */
+                if ((DataDirectory->VirtualAddress + DataDirectory->Size) >
+                    LdrEntry->SizeOfImage)
+                {
+                    /* They're not, skip */
+                    continue;
+                }
+
+                /* We have relocations */
+                ValidRelocs = TRUE;
             }
-
-            /* We have relocations */
-            ValidRelocs = TRUE;
         }
 
         /* Remember the original address */
@@ -1270,9 +1269,7 @@
             while (TRUE);
         }
 
-        /* Sanity check */
         DPRINT("[Mm0]: Copying from: %p to: %p\n", DllBase, NewImageAddress);
-        ASSERT(ExpInitializationPhase == 0);
 
         /* Now copy the entire driver over */
         RtlCopyMemory(NewImageAddress, DllBase, LdrEntry->SizeOfImage);




More information about the Ros-diffs mailing list