Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
fix(game-mode): keep WineHQ's loader off the hardened runtime
raymondchinsa68ebf9981e0
diff --git a/helpers/prepare-game-loader.swift b/helpers/prepare-game-loader.swiftindex b6bd229..d1609f7 100644--- a/helpers/prepare-game-loader.swift+++ b/helpers/prepare-game-loader.swift@@ -79,12 +79,12 @@ func embeddedPlistSection(_ data: Data) throws -> Range<Int>? {return plist}-func runCodesign(_ arguments: [String]) throws -> Data {+func runCodesign(_ arguments: [String], stderr: Bool = false) throws -> Data {let process = Process()let output = Pipe()process.executableURL = URL(fileURLWithPath: "/usr/bin/codesign")process.arguments = arguments- process.standardOutput = output+ if stderr { process.standardError = output } else { process.standardOutput = output }try process.run()let data = output.fileHandleForReading.readDataToEndOfFile()process.waitUntilExit()@@ -150,14 +150,21 @@ func prepare(_ target: URL, _ info: URL) throws {let attributes = try files.attributesOfItem(atPath: target.path)try files.setAttributes([.posixPermissions: attributes[.posixPermissions] ?? 0o755], ofItemAtPath: staged.path)- // CrossOver's loader is signed with the hardened runtime and entitlements; a free- // runtime's loader (WineCX) is not signed at all. Re-signing that one under the- // hardened runtime with no entitlements would refuse the DYLD_INSERT_LIBRARIES the- // launcher relies on, so it gets a plain ad hoc signature instead.- let signed = (try? runCodesign(["-d", target.path])) != nil+ // CrossOver's loader is signed with the hardened runtime and entitlements; WineCX's is not+ // signed at all and WineHQ's is signed ad hoc without the hardened runtime. Adding the+ // hardened runtime to those would turn on library validation, which refuses their+ // ntdll.so ("different Team IDs") and the DYLD_INSERT_LIBRARIES the launcher relies on,+ // so only a loader that already had it keeps it.+ let details = (try? runCodesign(["-dv", target.path], stderr: true)).map {+ String(decoding: $0, as: UTF8.self)+ }+ let signed = details != nil+ let hardened = details?.split(separator: "\n").contains {+ $0.hasPrefix("CodeDirectory") && $0.contains("runtime")+ } ?? falselet entitlements = signed ? try runCodesign(["-d", "--entitlements", ":-", target.path]) : Data()var arguments = ["--force", "--sign", "-", "--identifier", identity]- if signed { arguments += ["--options", "runtime"] }+ if hardened { arguments += ["--options", "runtime"] }if !entitlements.isEmpty {_ = try PropertyListSerialization.propertyList(from: entitlements, format: nil)let file = temporary.appendingPathComponent("entitlements.plist")diff --git a/helpers/tests/game-metadata.py b/helpers/tests/game-metadata.pyindex 8fdf1bc..d4db65a 100644--- a/helpers/tests/game-metadata.py+++ b/helpers/tests/game-metadata.py@@ -39,6 +39,20 @@ with tempfile.TemporaryDirectory(prefix="np-game-metadata-") as folder:assert runner.read_bytes() == before, "shared runner inode was modified"assert runner.stat().st_ino != wine.stat().st_inosubprocess.run(["codesign", "--verify", "--strict", str(wine)], check=True)++ def flags(path):+ out = subprocess.run(["codesign", "-dv", str(path)], capture_output=True, text=True).stderr+ return next(l for l in out.splitlines() if l.startswith("CodeDirectory"))++ # WineHQ's loader is ad hoc without the hardened runtime; adding it breaks ntdll.so loading+ assert "runtime" not in flags(wine), "a loader without the hardened runtime gained it"+ (root / "hardened").mkdir()+ hardened = root / "hardened" / "wine"+ subprocess.run(["clang", str(c), "-Wl,-sectcreate,__TEXT,__info_plist," + str(embedded),+ "-o", str(hardened)], check=True)+ subprocess.run(["codesign", "-s", "-", "--options", "runtime", str(hardened)], check=True)+ subprocess.run([str(tool), str(hardened), str(info)], check=True)+ assert "runtime" in flags(hardened), "a hardened loader lost the hardened runtime"blob = wine.read_bytes()assert b"com.notproton.launcher.999" in blob and b"LSSupportsGameMode" in blobsubprocess.run([str(tool), str(wine), str(info)], check=True)