[PATCH 3/3] mscoree: Fallback to assembly name if codebase path is invalid.

Rémi Bernon rbernon at codeweavers.com
Fri Oct 23 01:51:46 CDT 2020


Also use the InprocServer32 key values if there's no subkeys, as shown
by the test results.

L.A.Noire game crashes on startup after failing to load its ErrorHandler
assembly, that has an invalid CodeBase path in the registry.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/mscoree/corruntimehost.c | 44 ++++++++++++++++++++++++-----------
 dlls/mscoree/tests/comtest.c  |  3 ++-
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c
index a5b378b9251..61839512bf6 100644
--- a/dlls/mscoree/corruntimehost.c
+++ b/dlls/mscoree/corruntimehost.c
@@ -1707,6 +1707,7 @@ HRESULT create_monodata(REFIID riid, LPVOID *ppObj )
     HKEY key, subkey;
     LONG res;
     int offset = 0;
+    HANDLE file = INVALID_HANDLE_VALUE;
     DWORD numKeys, keyLength;
     WCHAR codebase[MAX_PATH + 8];
     WCHAR classname[350], subkeyName[256];
@@ -1742,7 +1743,12 @@ HRESULT create_monodata(REFIID riid, LPVOID *ppObj )
                 offset = lstrlenW(wszFileSlash);
 
             lstrcpyW(filename, codebase + offset);
+
+            file = CreateFileW(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
         }
+
+        if (file != INVALID_HANDLE_VALUE)
+            CloseHandle(file);
         else
         {
             WCHAR assemblyname[MAX_PATH + 8];
@@ -1751,27 +1757,37 @@ HRESULT create_monodata(REFIID riid, LPVOID *ppObj )
             WARN("CodeBase value cannot be found, trying Assembly.\n");
             /* get the last subkey of InprocServer32 */
             res = RegQueryInfoKeyW(key, 0, 0, 0, &numKeys, 0, 0, 0, 0, 0, 0, 0);
-            if (res != ERROR_SUCCESS || numKeys == 0)
-                goto cleanup;
-            numKeys--;
-            keyLength = ARRAY_SIZE(subkeyName);
-            res = RegEnumKeyExW(key, numKeys, subkeyName, &keyLength, 0, 0, 0, 0);
-            if (res != ERROR_SUCCESS)
-                goto cleanup;
-            res = RegOpenKeyExW(key, subkeyName, 0, KEY_READ, &subkey);
-            if (res != ERROR_SUCCESS)
-                goto cleanup;
-            dwBufLen = MAX_PATH + 8;
-            res = RegGetValueW(subkey, NULL, wszAssembly, RRF_RT_REG_SZ, NULL, assemblyname, &dwBufLen);
-            RegCloseKey(subkey);
             if (res != ERROR_SUCCESS)
                 goto cleanup;
+            if (numKeys > 0)
+            {
+                numKeys--;
+                keyLength = ARRAY_SIZE(subkeyName);
+                res = RegEnumKeyExW(key, numKeys, subkeyName, &keyLength, 0, 0, 0, 0);
+                if (res != ERROR_SUCCESS)
+                    goto cleanup;
+                res = RegOpenKeyExW(key, subkeyName, 0, KEY_READ, &subkey);
+                if (res != ERROR_SUCCESS)
+                    goto cleanup;
+                dwBufLen = MAX_PATH + 8;
+                res = RegGetValueW(subkey, NULL, wszAssembly, RRF_RT_REG_SZ, NULL, assemblyname, &dwBufLen);
+                RegCloseKey(subkey);
+                if (res != ERROR_SUCCESS)
+                    goto cleanup;
+            }
+            else
+            {
+                dwBufLen = MAX_PATH + 8;
+                res = RegGetValueW(key, NULL, wszAssembly, RRF_RT_REG_SZ, NULL, assemblyname, &dwBufLen);
+                if (res != ERROR_SUCCESS)
+                    goto cleanup;
+            }
 
             hr = get_file_from_strongname(assemblyname, filename, MAX_PATH);
             if (FAILED(hr))
             {
                 /*
-                 * The registry doesn't have a CodeBase entry and it's not in the GAC.
+                 * The registry doesn't have a CodeBase entry or the file isn't there, and it's not in the GAC.
                  *
                  * Use the Assembly Key to retrieve the filename.
                  *    Assembly : REG_SZ : AssemblyName, Version=X.X.X.X, Culture=neutral, PublicKeyToken=null
diff --git a/dlls/mscoree/tests/comtest.c b/dlls/mscoree/tests/comtest.c
index 659eb9059a7..b62d527bb95 100644
--- a/dlls/mscoree/tests/comtest.c
+++ b/dlls/mscoree/tests/comtest.c
@@ -180,7 +180,8 @@ static void run_registry_test(run_type run)
     ok(ret == ERROR_SUCCESS, "RegSetKeyValueA returned %x\n", ret);
 
     hr = CoCreateInstance(&CLSID_Test, NULL, CLSCTX_INPROC_SERVER, &IID_ITest, (void**)&test);
-    todo_wine ok(hr == result_expected, "Expected %x, got %x\n", result_expected, hr);
+    todo_wine_if(result_expected != S_OK)
+    ok(hr == result_expected, "Expected %x, got %x\n", result_expected, hr);
 
     if (hr == S_OK)
     {
-- 
2.28.0




More information about the wine-devel mailing list