[ros-diffs] [fireball] 51084: [NTDLL] - Implement fetching address of a security cookie in an image. Still not used even if it's present there. - Silence some debug prints.

fireball at svn.reactos.org fireball at svn.reactos.org
Thu Mar 17 14:25:59 UTC 2011


Author: fireball
Date: Thu Mar 17 14:25:59 2011
New Revision: 51084

URL: http://svn.reactos.org/svn/reactos?rev=51084&view=rev
Log:
[NTDLL]
- Implement fetching address of a security cookie in an image. Still not used even if it's present there.
- Silence some debug prints.

Modified:
    trunk/reactos/dll/ntdll/ldr/ldrinit.c

Modified: trunk/reactos/dll/ntdll/ldr/ldrinit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrinit.c?rev=51084&r1=51083&r2=51084&view=diff
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/ldrinit.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/ldrinit.c [iso-8859-1] Thu Mar 17 14:25:59 2011
@@ -343,6 +343,62 @@
     // Ignored atm
 }
 
+PVOID
+NTAPI
+LdrpFetchAddressOfSecurityCookie(PVOID BaseAddress, ULONG SizeOfImage)
+{
+    PIMAGE_LOAD_CONFIG_DIRECTORY ConfigDir;
+    ULONG DirSize;
+    PVOID Cookie = NULL;
+
+    /* Check NT header first */
+    if (!RtlImageNtHeader(BaseAddress)) return NULL;
+
+    /* Get the pointer to the config directory */
+    ConfigDir = RtlImageDirectoryEntryToData(BaseAddress,
+                                             TRUE,
+                                             IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
+                                             &DirSize);
+
+    /* Check for sanity */
+    if (!ConfigDir ||
+        (DirSize != 64 && ConfigDir->Size != DirSize) ||
+        (ConfigDir->Size < 0x48))
+        return NULL;
+
+    /* Now get the cookie */
+    Cookie = (PVOID)ConfigDir->SecurityCookie;
+
+    /* Check this cookie */
+    if (Cookie == NULL ||
+        (PCHAR)Cookie <= (PCHAR)BaseAddress ||
+        (PCHAR)Cookie >= (PCHAR)BaseAddress + SizeOfImage)
+    {
+        Cookie = NULL;
+    }
+
+    /* Return validated security cookie */
+    return Cookie;
+}
+
+PVOID
+NTAPI
+LdrpInitSecurityCookie(PLDR_DATA_TABLE_ENTRY LdrEntry)
+{
+    PVOID Cookie;
+
+    /* Fetch address of the cookie */
+    Cookie = LdrpFetchAddressOfSecurityCookie(LdrEntry->DllBase, LdrEntry->SizeOfImage);
+
+    if (Cookie)
+    {
+        UNIMPLEMENTED;
+        Cookie = NULL;
+    }
+
+    return Cookie;
+}
+
 NTSTATUS
 NTAPI
 LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
@@ -361,7 +417,7 @@
     PTEB OldTldTeb;
     BOOLEAN DllStatus;
 
-    DPRINT1("LdrpRunInitializeRoutines() called for %wZ\n", &LdrpImageEntry->BaseDllName);
+    DPRINT("LdrpRunInitializeRoutines() called for %wZ\n", &LdrpImageEntry->BaseDllName);
 
     /* Check the Loader Lock */
     LdrpEnsureLoaderLockIsHeld();
@@ -417,8 +473,7 @@
             if (!(LdrEntry->Flags & LDRP_ENTRY_PROCESSED))
             {
                 /* Setup the Cookie for the DLL */
-                //LdrpInitSecurityCookie(LdrEntry);
-                UNIMPLEMENTED;
+                LdrpInitSecurityCookie(LdrEntry);
 
                 /* Check for valid entrypoint */
                 if (LdrEntry->EntryPoint)
@@ -474,7 +529,7 @@
         /* Get an entry */
         LdrEntry = LdrRootEntry[i];
 
-        /* FIXME: Verifiy NX Compat */
+        /* FIXME: Verify NX Compat */
 
         /* Move to next entry */
         i++;
@@ -534,8 +589,11 @@
             }
 
             /* Call the Entrypoint */
-            DPRINT1("%wZ - Calling entry point at %x for thread attaching\n",
-                    &LdrEntry->BaseDllName, EntryPoint);
+            if (ShowSnaps)
+            {
+                DPRINT1("%wZ - Calling entry point at %p for DLL_PROCESS_ATTACH\n",
+                        &LdrEntry->BaseDllName, EntryPoint);
+            }
             DllStatus = LdrpCallDllEntry(EntryPoint,
                                          LdrEntry->DllBase,
                                          DLL_PROCESS_ATTACH,




More information about the Ros-diffs mailing list