[LDR][APPHELP] Add a shim that disables manifest compatibility version parsing 1858/head
authorMark Jansen <mark.jansen@reactos.org>
Mon, 19 Aug 2019 00:33:13 +0000 (02:33 +0200)
committerMark Jansen <mark.jansen@reactos.org>
Mon, 19 Aug 2019 10:08:06 +0000 (12:08 +0200)
dll/appcompat/apphelp/hsdb.c
dll/ntdll/ldr/ldrinit.c
media/sdb/sysmain.xml
sdk/include/reactos/compat_undoc.h

index f04312e..89eb628 100644 (file)
@@ -29,7 +29,7 @@ typedef struct _ShimData
 } ShimData;
 
 #define SHIMDATA_MAGIC  0xAC0DEDAB
-
+#define REACTOS_COMPATVERSION_IGNOREMANIFEST 0xffffffff
 
 C_ASSERT(SHIMDATA_MAGIC == REACTOS_SHIMDATA_MAGIC);
 C_ASSERT(sizeof(ShimData) == sizeof(ReactOS_ShimData));
@@ -739,7 +739,8 @@ BOOL WINAPI SdbPackAppCompatData(HSDB hsdb, PSDBQUERYRESULT pQueryResult, PVOID*
         if (SdbQueryData(hsdb, pQueryResult->atrLayers[n], L"SHIMVERSIONNT", &dwType, &dwValue, &dwValueSize) == ERROR_SUCCESS &&
             dwType == REG_DWORD && dwValueSize == sizeof(dwValue))
         {
-            dwValue = (dwValue % 100) | ((dwValue / 100) << 8);
+            if (dwValue != REACTOS_COMPATVERSION_IGNOREMANIFEST)
+                dwValue = (dwValue % 100) | ((dwValue / 100) << 8);
             if (dwValue > pData->dwRosProcessCompatVersion)
                 pData->dwRosProcessCompatVersion = dwValue;
         }
index 16a3361..c23783a 100644 (file)
@@ -1541,9 +1541,17 @@ VOID
 NTAPI
 LdrpInitializeProcessCompat(PVOID* pOldShimData)
 {
-    static const GUID* GuidOrder[] = { &COMPAT_GUID_WIN10, &COMPAT_GUID_WIN81, &COMPAT_GUID_WIN8,
-                                       &COMPAT_GUID_WIN7, &COMPAT_GUID_VISTA };
-    static const DWORD GuidVersions[] = { WINVER_WIN10, WINVER_WIN81, WINVER_WIN8, WINVER_WIN7, WINVER_VISTA };
+    static const struct
+    {
+        const GUID* Guid;
+        const DWORD Version;
+    } KnownCompatGuids[] = {
+        { &COMPAT_GUID_WIN10, _WIN32_WINNT_WIN10 },
+        { &COMPAT_GUID_WIN81, _WIN32_WINNT_WINBLUE },
+        { &COMPAT_GUID_WIN8, _WIN32_WINNT_WIN8 },
+        { &COMPAT_GUID_WIN7, _WIN32_WINNT_WIN7 },
+        { &COMPAT_GUID_VISTA, _WIN32_WINNT_VISTA },
+    };
 
     ULONG Buffer[(sizeof(COMPATIBILITY_CONTEXT_ELEMENT) * 10 + sizeof(ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION)) / sizeof(ULONG)];
     ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION* ContextCompatInfo;
@@ -1552,8 +1560,6 @@ LdrpInitializeProcessCompat(PVOID* pOldShimData)
     DWORD n, cur;
     ReactOS_ShimData* pShimData = *pOldShimData;
 
-    C_ASSERT(RTL_NUMBER_OF(GuidOrder) == RTL_NUMBER_OF(GuidVersions));
-
     if (pShimData)
     {
         if (pShimData->dwMagic != REACTOS_SHIMDATA_MAGIC ||
@@ -1564,7 +1570,14 @@ LdrpInitializeProcessCompat(PVOID* pOldShimData)
         }
         if (pShimData->dwRosProcessCompatVersion)
         {
-            DPRINT1("LdrpInitializeProcessCompat: ProcessCompatVersion already set to 0x%x\n", pShimData->dwRosProcessCompatVersion);
+            if (pShimData->dwRosProcessCompatVersion == REACTOS_COMPATVERSION_IGNOREMANIFEST)
+            {
+                DPRINT1("LdrpInitializeProcessCompat: ProcessCompatVersion set to ignore manifest\n");
+            }
+            else
+            {
+                DPRINT1("LdrpInitializeProcessCompat: ProcessCompatVersion already set to 0x%x\n", pShimData->dwRosProcessCompatVersion);
+            }
             return;
         }
     }
@@ -1590,12 +1603,12 @@ LdrpInitializeProcessCompat(PVOID* pOldShimData)
         return;
 
     /* Search for known GUID's, starting from newest to oldest. */
-    for (cur = 0; cur < RTL_NUMBER_OF(GuidOrder); ++cur)
+    for (cur = 0; cur < RTL_NUMBER_OF(KnownCompatGuids); ++cur)
     {
         for (n = 0; n < ContextCompatInfo->ElementCount; ++n)
         {
             if (ContextCompatInfo->Elements[n].Type == ACTCX_COMPATIBILITY_ELEMENT_TYPE_OS &&
-                RtlCompareMemory(&ContextCompatInfo->Elements[n].Id, GuidOrder[cur], sizeof(GUID)) == sizeof(GUID))
+                RtlCompareMemory(&ContextCompatInfo->Elements[n].Id, KnownCompatGuids[cur].Guid, sizeof(GUID)) == sizeof(GUID))
             {
                 /* If this process did not need shim data before, allocate and store it */
                 if (pShimData == NULL)
@@ -1619,8 +1632,8 @@ LdrpInitializeProcessCompat(PVOID* pOldShimData)
                 }
 
                 /* Store the highest found version, and bail out. */
-                pShimData->dwRosProcessCompatVersion = GuidVersions[cur];
-                DPRINT1("LdrpInitializeProcessCompat: Found guid for winver 0x%x\n", GuidVersions[cur]);
+                pShimData->dwRosProcessCompatVersion = KnownCompatGuids[cur].Version;
+                DPRINT1("LdrpInitializeProcessCompat: Found guid for winver 0x%x\n", KnownCompatGuids[cur].Version);
                 return;
             }
         }
index 7afab95..c41413a 100644 (file)
                 <DLLFILE>aclayers.dll</DLLFILE>
             </SHIM>
 
-            <SHIM NAME="HideShimEnv">
+            <!--<SHIM NAME="HideShimEnv">
                 <DLLFILE>aclayers.dll</DLLFILE>
-            </SHIM>
+            </SHIM>-->
 
             <FLAG NAME="GetShortPathNameNT4">
                 <FLAG_MASK_KERNEL>1</FLAG_MASK_KERNEL>
 
         <!-- Backwards compatibility layers, incomplete! -->
 
+        <LAYER NAME="IgnoreManifestCompatVersion">
+            <DATA NAME="SHIMVERSIONNT" DATA_DWORD="0xffffffff" />   <!-- REACTOS_COMPATVERSION_IGNOREMANIFEST -->
+        </LAYER>
+
         <LAYER NAME="WIN95">
             <SHIM_REF NAME="Win95VersionLie" />
             <SHIM_REF NAME="ForceDXSetupSuccess" />
index fc6a047..44212ef 100644 (file)
@@ -13,21 +13,16 @@ typedef struct _ReactOS_ShimData
 
 
 #define REACTOS_SHIMDATA_MAGIC  0xAC0DEDAB
+#define REACTOS_COMPATVERSION_UNINITIALIZED 0xfffffffe
+#define REACTOS_COMPATVERSION_IGNOREMANIFEST 0xffffffff
 
-#ifndef WINVER_VISTA
-#define WINVER_VISTA    0x0600
-#define WINVER_WIN7     0x0601
-#define WINVER_WIN8     0x0602
-#define WINVER_WIN81    0x0603
-#define WINVER_WIN10    0x0a00
-#endif
-
+// Returns values in the form of _WIN32_WINNT_VISTA, _WIN32_WINNT_WIN7 etc
 static
 inline
 DWORD RosGetProcessCompatVersion(VOID)
 {
-    static DWORD g_CompatVersion = 0xffffffff;
-    if (g_CompatVersion == 0xffffffff)
+    static DWORD g_CompatVersion = REACTOS_COMPATVERSION_UNINITIALIZED;
+    if (g_CompatVersion == REACTOS_COMPATVERSION_UNINITIALIZED)
     {
         ReactOS_ShimData* pShimData = (ReactOS_ShimData*)NtCurrentPeb()->pShimData;
         if (pShimData && pShimData->dwMagic == REACTOS_SHIMDATA_MAGIC &&
@@ -36,7 +31,7 @@ DWORD RosGetProcessCompatVersion(VOID)
             g_CompatVersion = pShimData->dwRosProcessCompatVersion;
         }
     }
-    return g_CompatVersion != 0xffffffff ? g_CompatVersion : 0;
+    return g_CompatVersion < REACTOS_COMPATVERSION_UNINITIALIZED ? g_CompatVersion : 0;
 }