[SHIMENG] Mark modified dll's as visited, and apply shims to newly loaded dlls
authorMark Jansen <mark.jansen@reactos.org>
Tue, 29 Aug 2017 20:21:58 +0000 (22:21 +0200)
committerMark Jansen <mark.jansen@reactos.org>
Tue, 9 Jan 2018 21:43:36 +0000 (22:43 +0100)
dll/appcompat/apphelp/shimeng.c

index 26e64b0..0d95d61 100644 (file)
@@ -833,6 +833,12 @@ VOID SeiHookImports(PLDR_DATA_TABLE_ENTRY LdrEntry)
         return;
     }
 
+    if (LdrEntry->Flags & LDRP_COMPAT_DATABASE_PROCESSED)
+    {
+        SHIMENG_INFO("Skipping module 0x%p \"%wZ\" because it was already processed\n", LdrEntry->DllBase, &LdrEntry->BaseDllName);
+        return;
+    }
+
     ImportDescriptor = RtlImageDirectoryEntryToData(DllBase, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &Size);
     if (!ImportDescriptor)
     {
@@ -902,6 +908,9 @@ VOID SeiHookImports(PLDR_DATA_TABLE_ENTRY LdrEntry)
             }
         }
     }
+
+    /* Mark this module as processed. */
+    LdrEntry->Flags |= LDRP_COMPAT_DATABASE_PROCESSED;
 }
 
 
@@ -1185,12 +1194,18 @@ VOID NTAPI SE_ProcessDying(VOID)
 VOID WINAPI SE_DllLoaded(PLDR_DATA_TABLE_ENTRY LdrEntry)
 {
     SHIMENG_INFO("%sINIT. loading DLL \"%wZ\"\n", g_bShimDuringInit ? "" : "AFTER ", &LdrEntry->BaseDllName);
+
+    SeiHookImports(LdrEntry);
+
     NotifyShims(SHIM_REASON_DLL_LOAD, LdrEntry);
 }
 
 VOID WINAPI SE_DllUnloaded(PLDR_DATA_TABLE_ENTRY LdrEntry)
 {
     SHIMENG_INFO("(%p)\n", LdrEntry);
+
+    /* Should we unhook here? */
+
     NotifyShims(SHIM_REASON_DLL_UNLOAD, LdrEntry);
 }