Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(ngx-signer): match the system directory, verify a copy of the caller's structs

raymondchinsee5436ca6866
diff --git a/ngx-signer-patch/README.md b/ngx-signer-patch/README.md
index 7d4fec9..72b4532 100644
--- a/ngx-signer-patch/README.md
+++ b/ngx-signer-patch/README.md
@@ -7,10 +7,18 @@ NVIDIA Streamline loads an NGX core only when it carries an NVIDIA Authenticode
never offered DLSS. Games calling NGX directly (Death Stranding) were unaffected.
`winecx-ngx-signer.patch` (against winecx `e0aa380`) wraps `CryptQueryObject` (crypt32) and
-`WinVerifyTrust` (wintrust): with `NOTPROTON_NGX_SIGNER` set, a check of
-`...\system32\nvngx.dll` or `_nvngx.dll` by path is answered from an NVIDIA-signed Streamline
-module next to the game executable (`sl.interposer.dll`, `sl.common.dll` or `nvngx_dlss.dll`).
-Every other path is untouched. `compat_run.sh` sets the variable only with `NVAPI=1` on D3DMetal.
+`WinVerifyTrust` (wintrust): with `NOTPROTON_NGX_SIGNER` set, a check of `nvngx.dll` or
+`_nvngx.dll` by path in the system directory (`GetSystemDirectoryW()`, not any folder named
+`system32`) is answered from an NVIDIA-signed Streamline module next to the game executable
+(`sl.interposer.dll`, `sl.common.dll` or `nvngx_dlss.dll`). Every other path is untouched.
+`compat_run.sh` sets the variable only with `NVAPI=1` on D3DMetal. `WinVerifyTrust` runs a
+redirected check on a heap copy of the caller's `WINTRUST_DATA` and `WINTRUST_FILE_INFO`, so
+the caller's structs are only written where Windows writes them too (`hWVTStateData`); a
+`WTD_STATEACTION_VERIFY` copy stays alive until its `WTD_STATEACTION_CLOSE`.
+
+The committed `crypt32-winecx-11.17.dll` and `wintrust-winecx-11.17.dll` predate those two
+changes (system-directory match, struct copy). They need a rebuild, a DLSS check in a
+Streamline game, and new pins in `FreeEngineWinecx.swift`.
Verified 2026-10-12: RE Requiem lists NVIDIA DLSS; 007 First Light logs
`Loaded NGXCore from path (C:\windows\system32\nvngx.dll)`.
diff --git a/ngx-signer-patch/winecx-ngx-signer.patch b/ngx-signer-patch/winecx-ngx-signer.patch
index 1d93e29..db42cae 100644
--- a/ngx-signer-patch/winecx-ngx-signer.patch
+++ b/ngx-signer-patch/winecx-ngx-signer.patch
@@ -1,8 +1,8 @@
diff --git a/dlls/crypt32/object.c b/dlls/crypt32/object.c
-index 8a4a161b..fc88b3fa 100644
+index 8a4a161b..f7833b68 100644
--- a/dlls/crypt32/object.c
+++ b/dlls/crypt32/object.c
-@@ -767,7 +767,7 @@ static BOOL CRYPT_QueryPFXObject(DWORD dwObjectType, const void *pvObject,
+@@ -767,7 +767,7 @@
return ret;
}
@@ -11,10 +11,12 @@ index 8a4a161b..fc88b3fa 100644
DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
DWORD dwFlags, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
DWORD *pdwFormatType, HCERTSTORE *phCertStore, HCRYPTMSG *phMsg,
-@@ -863,6 +863,54 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject,
+@@ -861,6 +861,58 @@
+ SetLastError(CRYPT_E_NO_MATCH);
+ TRACE("returning %d\n", ret);
return ret;
- }
-
++}
++
+/* NotProton: Apple's MetalFX DLSS bridge (nvngx-on-metalfx, linked as system32 nvngx.dll)
+ * carries no NVIDIA signature, and the NGX loader inside NVIDIA Streamline refuses an
+ * unsigned NGX core, so Streamline games never offer DLSS. When the run script sets
@@ -23,16 +25,20 @@ index 8a4a161b..fc88b3fa 100644
+static const WCHAR *notproton_ngx_signer( const WCHAR *path, WCHAR *buf, DWORD len )
+{
+ static const WCHAR * const signed_modules[] = { L"sl.interposer.dll", L"sl.common.dll", L"nvngx_dlss.dll" };
++ WCHAR sysdir[MAX_PATH];
+ const WCHAR *base;
+ WCHAR *slash;
-+ DWORD i;
++ DWORD i, sysdir_len;
+
+ if (!path || !GetEnvironmentVariableW( L"NOTPROTON_NGX_SIGNER", NULL, 0 )) return path;
+ base = wcsrchr( path, '\\' );
+ if (!base) return path;
+ base++;
+ if (wcsicmp( base, L"nvngx.dll" ) && wcsicmp( base, L"_nvngx.dll" )) return path;
-+ if (base - path < 10 || wcsnicmp( base - 10, L"\\system32\\", 10 )) return path;
++ /* Only the system directory's copy, not any folder that happens to be called system32. */
++ sysdir_len = GetSystemDirectoryW( sysdir, ARRAY_SIZE(sysdir) );
++ if (!sysdir_len || sysdir_len >= ARRAY_SIZE(sysdir)) return path;
++ if ((DWORD)(base - 1 - path) != sysdir_len || wcsnicmp( path, sysdir, sysdir_len )) return path;
+ if (!GetModuleFileNameW( NULL, buf, len ) || !(slash = wcsrchr( buf, '\\' ))) return path;
+ for (i = 0; i < ARRAY_SIZE(signed_modules); i++)
+ {
@@ -61,19 +67,18 @@ index 8a4a161b..fc88b3fa 100644
+ return crypt_query_object(dwObjectType, pvObject, dwExpectedContentTypeFlags,
+ dwExpectedFormatTypeFlags, dwFlags, pdwMsgAndCertEncodingType, pdwContentType,
+ pdwFormatType, phCertStore, phMsg, ppvContext);
-+}
-+
+ }
+
static BOOL WINAPI CRYPT_FormatHexString(DWORD dwCertEncodingType,
- DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
- LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
diff --git a/dlls/wintrust/wintrust_main.c b/dlls/wintrust/wintrust_main.c
-index a9b1587e..b72094ea 100644
+index a9b1587e..5cc951b6 100644
--- a/dlls/wintrust/wintrust_main.c
+++ b/dlls/wintrust/wintrust_main.c
-@@ -655,6 +655,39 @@ static void dump_wintrust_data(WINTRUST_DATA *data)
+@@ -654,6 +654,104 @@
+ * NOTES
* Trust providers can be found at:
* HKLM\SOFTWARE\Microsoft\Cryptography\Providers\Trust\
- */
++ */
+/* NotProton: Apple's MetalFX DLSS bridge (nvngx-on-metalfx, linked as system32 nvngx.dll)
+ * carries no NVIDIA signature, and the NGX loader inside NVIDIA Streamline refuses an
+ * unsigned NGX core, so Streamline games never offer DLSS. When the run script sets
@@ -82,16 +87,20 @@ index a9b1587e..b72094ea 100644
+static const WCHAR *notproton_ngx_signer( const WCHAR *path, WCHAR *buf, DWORD len )
+{
+ static const WCHAR * const signed_modules[] = { L"sl.interposer.dll", L"sl.common.dll", L"nvngx_dlss.dll" };
++ WCHAR sysdir[MAX_PATH];
+ const WCHAR *base;
+ WCHAR *slash;
-+ DWORD i;
++ DWORD i, sysdir_len;
+
+ if (!path || !GetEnvironmentVariableW( L"NOTPROTON_NGX_SIGNER", NULL, 0 )) return path;
+ base = wcsrchr( path, '\\' );
+ if (!base) return path;
+ base++;
+ if (wcsicmp( base, L"nvngx.dll" ) && wcsicmp( base, L"_nvngx.dll" )) return path;
-+ if (base - path < 10 || wcsnicmp( base - 10, L"\\system32\\", 10 )) return path;
++ /* Only the system directory's copy, not any folder that happens to be called system32. */
++ sysdir_len = GetSystemDirectoryW( sysdir, ARRAY_SIZE(sysdir) );
++ if (!sysdir_len || sysdir_len >= ARRAY_SIZE(sysdir)) return path;
++ if ((DWORD)(base - 1 - path) != sysdir_len || wcsnicmp( path, sysdir, sysdir_len )) return path;
+ if (!GetModuleFileNameW( NULL, buf, len ) || !(slash = wcsrchr( buf, '\\' ))) return path;
+ for (i = 0; i < ARRAY_SIZE(signed_modules); i++)
+ {
@@ -104,39 +113,113 @@ index a9b1587e..b72094ea 100644
+ return path;
+}
+
++/* A redirected check runs on a copy of the caller's WINTRUST_DATA and WINTRUST_FILE_INFO,
++ * so the caller's structs are never written (they may be read-only) except hWVTStateData,
++ * the state handle WinVerifyTrust hands back. The copy is on the heap because with
++ * WTD_STATEACTION_VERIFY the provider state keeps pointing at it until the
++ * WTD_STATEACTION_CLOSE call; live copies are tracked so that call can free them. */
++struct ngx_trust_copy
++{
++ WINTRUST_DATA data;
++ WINTRUST_FILE_INFO file;
++ WCHAR path[MAX_PATH];
++};
++
++static SRWLOCK ngx_copies_lock = SRWLOCK_INIT;
++static struct ngx_trust_copy *ngx_copies[16];
++
++static BOOL ngx_copy_track( struct ngx_trust_copy *copy )
++{
++ BOOL tracked = FALSE;
++ DWORD i;
++
++ AcquireSRWLockExclusive( &ngx_copies_lock );
++ for (i = 0; i < ARRAY_SIZE(ngx_copies) && !tracked; i++)
++ if (!ngx_copies[i]) ngx_copies[i] = copy, tracked = TRUE;
++ ReleaseSRWLockExclusive( &ngx_copies_lock );
++ return tracked;
++}
++
++/* Removes and returns the tracked copy whose WINTRUST_DATA is data, or NULL. */
++static struct ngx_trust_copy *ngx_copy_untrack( const WINTRUST_DATA *data )
++{
++ struct ngx_trust_copy *found = NULL;
++ DWORD i;
++
++ if (!data) return NULL;
++ AcquireSRWLockExclusive( &ngx_copies_lock );
++ for (i = 0; i < ARRAY_SIZE(ngx_copies) && !found; i++)
++ if (ngx_copies[i] && &ngx_copies[i]->data == data) found = ngx_copies[i], ngx_copies[i] = NULL;
++ ReleaseSRWLockExclusive( &ngx_copies_lock );
++ return found;
++}
++
++/* The copy to verify instead of data, or NULL when data's file is not redirected. */
++static struct ngx_trust_copy *ngx_trust_copy( const WINTRUST_DATA *data )
++{
++ struct ngx_trust_copy *copy;
++ WCHAR signer[MAX_PATH];
++ const WCHAR *path;
++
++ if (!data || data->dwUnionChoice != WTD_CHOICE_FILE || !data->pFile || data->pFile->hFile)
++ return NULL;
++ path = notproton_ngx_signer( data->pFile->pcwszFilePath, signer, ARRAY_SIZE(signer) );
++ if (path == data->pFile->pcwszFilePath) return NULL;
++ if (!(copy = calloc( 1, sizeof(*copy) ))) return NULL;
++ memcpy( &copy->data, data, min( data->cbStruct, sizeof(copy->data) ) );
++ memcpy( &copy->file, data->pFile, min( data->pFile->cbStruct, sizeof(copy->file) ) );
++ lstrcpynW( copy->path, path, ARRAY_SIZE(copy->path) );
++ copy->file.pcwszFilePath = copy->path;
++ copy->data.pFile = &copy->file;
++ return copy;
++}
++
+/***********************************************************************
+ * WinVerifyTrust (WINTRUST.@) with the NotProton NGX signer redirect
-+ */
+ */
LONG WINAPI WinVerifyTrust( HWND hwnd, GUID *ActionID, LPVOID ActionData )
{
- static const GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,
-@@ -667,9 +700,21 @@ LONG WINAPI WinVerifyTrust( HWND hwnd, GUID *ActionID, LPVOID ActionData )
+@@ -667,8 +765,22 @@
LONG err = ERROR_SUCCESS;
WINTRUST_DATA *actionData = ActionData;
-+ WINTRUST_FILE_INFO *ngx_file = NULL;
-+ LPCWSTR ngx_path = NULL;
-+ WCHAR ngx_signer[MAX_PATH];
++ WINTRUST_DATA *callerData = ActionData;
++ struct ngx_trust_copy *ngx_copy, *ngx_closed = NULL;
++ CRYPT_PROVIDER_DATA *ngx_state;
+
TRACE("(%p, %s, %p)\n", hwnd, debugstr_guid(ActionID), ActionData);
dump_wintrust_data(ActionData);
-
-+ if (actionData && actionData->dwUnionChoice == WTD_CHOICE_FILE && actionData->pFile &&
-+ !actionData->pFile->hFile)
++
++ if ((ngx_copy = ngx_trust_copy( callerData )))
+ {
-+ ngx_file = actionData->pFile;
-+ ngx_path = ngx_file->pcwszFilePath;
-+ ngx_file->pcwszFilePath = notproton_ngx_signer( ngx_path, ngx_signer, ARRAY_SIZE(ngx_signer) );
++ ActionData = actionData = &ngx_copy->data;
++ /* A CLOSE frees the copy its VERIFY left in the provider state. */
++ if (WVT_ISINSTRUCT(WINTRUST_DATA, actionData->cbStruct, dwStateAction) &&
++ actionData->dwStateAction == WTD_STATEACTION_CLOSE &&
++ (ngx_state = actionData->hWVTStateData))
++ ngx_closed = ngx_copy_untrack( ngx_state->pWintrustData );
+ }
-+
+
/* Support for known old-style callers: */
if (IsEqualGUID(ActionID, &published_software))
- err = WINTRUST_PublishedSoftware(hwnd, ActionID, ActionData);
-@@ -709,6 +754,7 @@ LONG WINAPI WinVerifyTrust( HWND hwnd, GUID *ActionID, LPVOID ActionData )
+@@ -709,6 +821,20 @@
}
}
-+ if (ngx_file) ngx_file->pcwszFilePath = ngx_path;
++ if (ngx_copy)
++ {
++ if (callerData->hWVTStateData != ngx_copy->data.hWVTStateData)
++ callerData->hWVTStateData = ngx_copy->data.hWVTStateData;
++ /* The provider state of a VERIFY points at the copy until its CLOSE. */
++ if (!ngx_copy->data.hWVTStateData || !ngx_copy_track( ngx_copy ))
++ {
++ if (ngx_copy->data.hWVTStateData)
++ FIXME( "NotProton: too many open NGX signer checks, the copy is leaked\n" );
++ else
++ free( ngx_copy );
++ }
++ }
++ free( ngx_closed );
if (err) SetLastError(err);
TRACE("returning %08lx\n", err);
return err;