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
Add support for the Rosetta version of CrossOver in the FEX Preview
NotProtonNot160968c6e44a
diff --git a/app/Package.swift b/app/Package.swiftindex ba0b564..7b18779 100644--- a/app/Package.swift+++ b/app/Package.swift@@ -27,6 +27,7 @@ let package = Package(.copy("Resources/payload.manifest"),.copy("Resources/valve-packages.manifest"),.copy("Resources/detour2.bin"),+ .copy("Resources/detour2-fex.bin"),.copy("Resources/detour32.bin"),.copy("Resources/detour32-fex.bin"),.copy("Resources/detour64-fex.bin"),diff --git a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift b/app/Sources/NotProtonApp/Model/NtdllPatcher.swiftindex 0fffcdf..79634b4 100644--- a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift+++ b/app/Sources/NotProtonApp/Model/NtdllPatcher.swift@@ -44,7 +44,7 @@ enum NtdllPatcher {NtdllPatch(arch: .x86_64Windows,payloadResource: "detour2",- payloadSHA256: "4ce2ddc11c433fe15f78633fc5c1fda8b27fa642426cb26378f7d7d7b54a79f8",+ payloadSHA256: "8504714bba0195439cb5b44c89f25c68dbb7f01bae6f72ca0a258a0daec3e244",caveRVA: 0x80be0,payloadRVA: 0x80be0,hooks: [@@ -75,6 +75,21 @@ enum NtdllPatcher {],// FEX patches"27.0.0.40921-fex": [+ NtdllPatch(+ arch: .x86_64Windows,+ payloadResource: "detour2-fex",+ payloadSHA256: "6af3f36658907cc94c096e432006807d6997bd970560f2579df748d6fd6e2bc6",+ caveRVA: 0x79394,+ payloadRVA: 0x793a0,+ hooks: [+ NtdllHook(rva: 0x34b2e, stolen: [0x48, 0x8b, 0x84, 0x24, 0x10, 0x01, 0x00, 0x00]),+ ],+ caveSize: 3180,+ cavePad: 0xcc,+ machine: 0x8664,+ magic: 0x20b,+ imageBase: 0x1_7000_0000+ ),NtdllPatch(arch: .i386Windows,payloadResource: "detour32-fex",@@ -93,7 +108,7 @@ enum NtdllPatcher {NtdllPatch(arch: .aarch64Windows,payloadResource: "detour64-fex",- payloadSHA256: "bee4ee13c235bd5de3cb6ce840b9695effd5623132f6dc0d137496d6a5330f5e",+ payloadSHA256: "68a458ec9c32041c79fdd622d18e91cfbe825a5292cae362d310930e34dd598e",caveRVA: 0xf1185,payloadRVA: 0xf1190,hooks: [@@ -428,7 +443,7 @@ enum NtdllPatcher {var written: [WineArch] = []for patch in patches(for: build) {- let destination = bridge.appending(path: "wine/\(patch.arch.rawValue)/ntdll.dll")+ let destination = stagedCopy(of: patch.arch, in: bridge)if Digest.sha256IfPresent(destination) == build.patchedNtdll[patch.arch] { continue }@@ -442,17 +457,68 @@ enum NtdllPatcher {return written}- private static func prune(keeping arches: [WineArch], in bridge: URL) {- let fm = FileManager.default+ static func snapshot(bridge: URL) throws -> [WineArch: Data] {+ var saved: [WineArch: Data] = [:]- for arch in WineArch.allCases where !arches.contains(arch) {- let directory = bridge.appending(path: "wine/\(arch.rawValue)")- try? fm.removeItem(at: directory.appending(path: "ntdll.dll"))+ for arch in WineArch.allCases {+ let copy = stagedCopy(of: arch, in: bridge)+ guard FileManager.default.fileExists(atPath: copy.path(percentEncoded: false)) else { continue }+ do {+ saved[arch] = try Data(contentsOf: copy)+ } catch {+ throw StepFailure(+ step: step,+ detail: "\(copy.path(percentEncoded: false)) could not be read. \(error.localizedDescription)"+ )+ }+ }++ return saved+ }++ static func restore(_ saved: [WineArch: Data], bridge: URL) throws {+ for arch in WineArch.allCases {+ let copy = stagedCopy(of: arch, in: bridge)- let path = directory.path(percentEncoded: false)- if let left = try? fm.contentsOfDirectory(atPath: path), left.isEmpty {- try? fm.removeItem(at: directory)+ if let data = saved[arch] {+ if (try? Data(contentsOf: copy)) != data {+ try atomicReplace(copy, with: data, step: step)+ }+ continue}++ do {+ try removeStagedCopy(of: arch, in: bridge)+ } catch {+ throw StepFailure(+ step: step,+ detail: "\(copy.path(percentEncoded: false)) could not be removed. \(error.localizedDescription)"+ )+ }+ }+ }++ private static func stagedCopy(of arch: WineArch, in bridge: URL) -> URL {+ bridge.appending(path: "wine/\(arch.rawValue)/ntdll.dll")+ }++ private static func removeStagedCopy(of arch: WineArch, in bridge: URL) throws {+ let fm = FileManager.default+ let copy = stagedCopy(of: arch, in: bridge)++ if fm.fileExists(atPath: copy.path(percentEncoded: false)) {+ try fm.removeItem(at: copy)+ }++ let directory = copy.deletingLastPathComponent()+ if let left = try? fm.contentsOfDirectory(atPath: directory.path(percentEncoded: false)), left.isEmpty {+ try fm.removeItem(at: directory)+ }+ }++ private static func prune(keeping arches: [WineArch], in bridge: URL) {+ for arch in WineArch.allCases where !arches.contains(arch) {+ try? removeStagedCopy(of: arch, in: bridge)}}diff --git a/app/Sources/NotProtonApp/Model/RunnerPatcher.swift b/app/Sources/NotProtonApp/Model/RunnerPatcher.swiftindex 988c526..fb8e022 100644--- a/app/Sources/NotProtonApp/Model/RunnerPatcher.swift+++ b/app/Sources/NotProtonApp/Model/RunnerPatcher.swift@@ -14,14 +14,19 @@ enum RunnerPatcher {]static func builtins(in root: URL) -> [(arch: String, name: String)] {- windowsBuiltins + [(arch: unixArch(in: root), name: "lsteamclient.so")]+ windowsBuiltins + unixArches(in: root).map { (arch: $0, name: "lsteamclient.so") }}- static func unixArch(in root: URL) -> String {+ static func unixArches(in root: URL) -> [String] {let arches = unixLoaders(in: root).compactMap { loader inloader.pathComponents.last { $0.hasSuffix("-unix") }}- return arches.contains("aarch64-unix") ? "aarch64-unix" : "x86_64-unix"+ let present = ["aarch64-unix", "x86_64-unix"].filter { arches.contains($0) }+ return present.isEmpty ? ["x86_64-unix"] : present+ }++ static func unixArch(in root: URL) -> String {+ unixArches(in: root)[0]}struct Outcome: Sendable {diff --git a/app/Sources/NotProtonApp/Model/RunnerSetup.swift b/app/Sources/NotProtonApp/Model/RunnerSetup.swiftindex fd182f4..4e765de 100644--- a/app/Sources/NotProtonApp/Model/RunnerSetup.swift+++ b/app/Sources/NotProtonApp/Model/RunnerSetup.swift@@ -68,11 +68,8 @@ enum RunnerSetup {throw StepFailure(step: "Verify CrossOver license", detail: status.detail)}- let previous = RunnerStore.currentBuild(runners: runners)- .flatMap(SupportedRunners.build(id:))- .flatMap { $0 != build && RunnerInstaller.hasClone(forBuild: $0.id, runners: runners) ? $0 : nil }-try verify(build, root)+ let saved = try NtdllPatcher.snapshot(bridge: bridge)do {report(.staging)@@ -85,18 +82,14 @@ enum RunnerSetup {report(.finished)return Outcome(build: build, staged: staged, installed: installed)} catch {- if let previous {- do {- _ = try stage(- previous, SupportPaths.clonedRoot(forBuild: previous.id, runners: runners), bridge- )- } catch let restorationError {- throw StepFailure(- step: switchStep,- detail: "\(error.localizedDescription) Restoring the previous build also failed: "- + restorationError.localizedDescription- )- }+ do {+ try NtdllPatcher.restore(saved, bridge: bridge)+ } catch let restorationError {+ throw StepFailure(+ step: switchStep,+ detail: "\(error.localizedDescription) Restoring the previous build also failed: "+ + restorationError.localizedDescription+ )}throw error}diff --git a/app/Sources/NotProtonApp/Model/SupportedRunner.swift b/app/Sources/NotProtonApp/Model/SupportedRunner.swiftindex 16e8fb3..07eb551 100644--- a/app/Sources/NotProtonApp/Model/SupportedRunner.swift+++ b/app/Sources/NotProtonApp/Model/SupportedRunner.swift@@ -48,7 +48,7 @@ enum SupportedRunners {.i386Windows: "94cc7c14c1e9dcf58ef501015c115f8405c73b2a65cefe31faa5d9e47f36e58b",],patchedNtdll: [- .x86_64Windows: "b21f4bace5a7a0cfef0f74cef9b27561f6eb3ad38daf76f36b186ca0677c2b2c",+ .x86_64Windows: "b6a98622fb8f7e6a998bc038f442b17d257da3df5e9e135f0c35f7bbc46ea5d6",.i386Windows: "25bfde1f50ee96485763968ef10b9d9ad35e38214232f17ebdc009b098af44a0",]),@@ -58,12 +58,14 @@ enum SupportedRunners {flavor: "fex",loaderSHA256: "7a6ea337c9caf2217454bec9537371e5d8ca302406bbed40b65316c1a636c4ab",cleanNtdll: [+ .x86_64Windows: "f4fa556a3dc20f6e966a803f5de554359227a61a24cd5b5a2ad88a427ceeec58",.i386Windows: "09474795d6f306163cebab6429819999fcff50e07dbc4b067a90ec4f74a3a7d7",.aarch64Windows: "7823d71fbce6c9947163bf8b96beb299eabb02878245bcaf6759f2a22e81f071",],patchedNtdll: [+ .x86_64Windows: "fa8cd8fe7c4c19effade92d55b00fa946b630ab13cbb6721076848238c1dcf6a",.i386Windows: "e799ea02418294588ee353a90b967358be316a3044ff9515b28aa1ce07e63981",- .aarch64Windows: "560939a0f6e58314fc9d79fe6f839dce2b181f829ae58dca195fa142fcf40f39",+ .aarch64Windows: "f40810193a5ef2520774288f354a8604f5ba91828315f643b3ee6688b873dc3f",]),]diff --git a/app/Sources/NotProtonApp/Resources/detour2-fex.bin b/app/Sources/NotProtonApp/Resources/detour2-fex.binnew file mode 100755index 0000000..d39c654Binary files /dev/null and b/app/Sources/NotProtonApp/Resources/detour2-fex.bin differdiff --git a/app/Sources/NotProtonApp/Resources/detour2.bin b/app/Sources/NotProtonApp/Resources/detour2.binindex 2ee1810..30101f4 100644Binary files a/app/Sources/NotProtonApp/Resources/detour2.bin and b/app/Sources/NotProtonApp/Resources/detour2.bin differdiff --git a/app/Sources/NotProtonApp/Resources/detour64-fex.bin b/app/Sources/NotProtonApp/Resources/detour64-fex.binindex 3edf831..48b0692 100755Binary files a/app/Sources/NotProtonApp/Resources/detour64-fex.bin and b/app/Sources/NotProtonApp/Resources/detour64-fex.bin differdiff --git a/app/Sources/NotProtonApp/Resources/payload.manifest b/app/Sources/NotProtonApp/Resources/payload.manifestindex 7121fb4..1c0f806 100644--- a/app/Sources/NotProtonApp/Resources/payload.manifest+++ b/app/Sources/NotProtonApp/Resources/payload.manifest@@ -7,6 +7,7 @@ built x86_64-unix/lsteamclient.sobuilt aarch64-unix/lsteamclient.sopatched wine/i386-windows/ntdll.dllpatched wine/x86_64-windows/ntdll.dll+patched wine/aarch64-windows/ntdll.dllvalve steamclient.dllvalve steamclient64.dllvalve tier0_s64.dlldiff --git a/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift b/app/Tests/NotProtonAppTests/NtdllPatcherTests.swiftindex a94edc5..f15da80 100644--- a/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift+++ b/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift@@ -431,16 +431,15 @@ struct NtdllStagingTests {hashes[arch] = try Digest.sha256(of: file)}- // The FEX flavor, which patches i386 and aarch64 and leaves x86_64 alone.let build = RunnerBuild(bundleVersion: "27.0.0.40921",releaseVersion: "20260821",- flavor: "fex",+ flavor: nil,loaderSHA256: "unused",cleanNtdll: [:],patchedNtdll: [+ .x86_64Windows: hashes[.x86_64Windows]!,.i386Windows: hashes[.i386Windows]!,- .aarch64Windows: hashes[.aarch64Windows]!,])return (bridge, build)@@ -457,12 +456,40 @@ struct NtdllStagingTests {#expect(written.isEmpty)let fm = FileManager.default- for arch in [WineArch.i386Windows, .aarch64Windows] {+ for arch in [WineArch.x86_64Windows, .i386Windows] {let kept = bridge.appending(path: "wine/\(arch.rawValue)/ntdll.dll")#expect(fm.fileExists(atPath: kept.path(percentEncoded: false)))}- let foreign = bridge.appending(path: "wine/x86_64-windows/ntdll.dll")+ let foreign = bridge.appending(path: "wine/aarch64-windows/ntdll.dll")#expect(!fm.fileExists(atPath: foreign.path(percentEncoded: false)))}}++@Suite("Pinned patch payloads")+struct PinnedPatchPayloadTests {++ @Test("Every pinned patch ships a payload that matches its pin")+ func everyPinnedPayloadResolves() throws {+ for (buildID, patches) in NtdllPatcher.byBuild {+ for patch in patches {+ #expect(throws: Never.self, "\(buildID) \(patch.arch.rawValue)") {+ _ = try NtdllPatcher.payload(for: patch)+ }+ }+ }+ }++ @Test("Every pinned payload fits inside the cave it is written to")+ func everyPinnedPayloadFitsItsCave() throws {+ for (buildID, patches) in NtdllPatcher.byBuild {+ for patch in patches {+ let payload = try NtdllPatcher.payload(for: patch)+ let where_ = "\(buildID) \(patch.arch.rawValue)"+ #expect(patch.payloadRVA >= patch.caveRVA, "\(where_) starts before its cave")+ let end = patch.payloadRVA + payload.count+ #expect(end <= patch.caveRVA + patch.caveSize, "\(where_) overruns its cave")+ }+ }+ }+}diff --git a/app/Tests/NotProtonAppTests/PayloadManifestTests.swift b/app/Tests/NotProtonAppTests/PayloadManifestTests.swiftindex c7fcbbc..8cb195e 100644--- a/app/Tests/NotProtonAppTests/PayloadManifestTests.swift+++ b/app/Tests/NotProtonAppTests/PayloadManifestTests.swift@@ -10,11 +10,9 @@ struct PayloadManifestTests {func shippedManifestIsComplete() throws {let manifest = try PayloadManifest.bundled()- // Nineteen files in the split a working install proved: seven built here, two- // patched on device, ten from pinned Valve client packages.- #expect(manifest.entries.count == 19)+ #expect(manifest.entries.count == 20)#expect(manifest.paths(origin: .built).count == 7)- #expect(manifest.paths(origin: .patched).count == 2)+ #expect(manifest.paths(origin: .patched).count == 3)#expect(manifest.paths(origin: .valve).count == 10)// Every payload file is fetchable from Valve or produced here, which is what dropping@@ -22,11 +20,10 @@ struct PayloadManifestTests {#expect(PayloadOrigin.allCases.filter(\.isFetchable) == [.valve])#expect(PayloadOrigin.allCases.count == 3)- // The patched entries are the two ntdlls and nothing else. Anything else- // marked patched would be staged from a file the app is not allowed to ship.#expect(Set(manifest.paths(origin: .patched)) == ["wine/i386-windows/ntdll.dll","wine/x86_64-windows/ntdll.dll",+ "wine/aarch64-windows/ntdll.dll",])}@@ -93,11 +90,11 @@ struct PayloadInspectionTests {let state = PayloadInspector.inspect(bridge: bridge)#expect(state.manifestProblem == nil)- #expect(state.expected == 19)+ #expect(state.expected == 20)#expect(state.present == 10)#expect(state.missing(origin: .valve).isEmpty)#expect(state.missing(origin: .built).count == 7)- #expect(state.missing(origin: .patched).count == 2)+ #expect(state.missing(origin: .patched).count == 3)#expect(!state.isComplete)}}diff --git a/app/Tests/NotProtonAppTests/RunnerPatcherTests.swift b/app/Tests/NotProtonAppTests/RunnerPatcherTests.swiftindex 1e35a9d..b9e1724 100644--- a/app/Tests/NotProtonAppTests/RunnerPatcherTests.swift+++ b/app/Tests/NotProtonAppTests/RunnerPatcherTests.swift@@ -170,8 +170,11 @@ struct RunnerPatcherTests {try write("lib/wine/aarch64-unix/wine.app/Contents/MacOS/wine")#expect(RunnerPatcher.unixArch(in: root) == "aarch64-unix")+ #expect(RunnerPatcher.unixArches(in: root) == ["aarch64-unix", "x86_64-unix"])+let arches = RunnerPatcher.builtins(in: root).map(\.arch)- #expect(arches == RunnerPatcher.windowsBuiltins.map(\.arch) + ["aarch64-unix"])+ #expect(+ arches == RunnerPatcher.windowsBuiltins.map(\.arch) + ["aarch64-unix", "x86_64-unix"])#expect(RunnerPatcher.builtins(in: root).allSatisfy { $0.name.hasPrefix("lsteamclient") })}}diff --git a/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift b/app/Tests/NotProtonAppTests/RunnerSwitchTests.swiftindex a63ac7a..5322f5e 100644--- a/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift+++ b/app/Tests/NotProtonAppTests/RunnerSwitchTests.swift@@ -35,6 +35,33 @@ struct RunnerSwitchTests {return runners}+ private static func stagedCopy(_ arch: WineArch, in bridge: URL) -> URL {+ bridge.appending(path: "wine/\(arch.rawValue)/ntdll.dll")+ }++ private static func writeStaged(for build: RunnerBuild, into bridge: URL) throws {+ for arch in build.patchedNtdll.keys {+ try atomicReplace(stagedCopy(arch, in: bridge), with: Data("\(build.id) \(arch.rawValue)".utf8), step: "test")+ }+ }++ private static func seedBridge(_ bridge: URL, with copies: [WineArch: String]) throws -> [WineArch: Data] {+ var seeded: [WineArch: Data] = [:]+ for (arch, text) in copies {+ seeded[arch] = Data(text.utf8)+ try atomicReplace(stagedCopy(arch, in: bridge), with: seeded[arch]!, step: "test")+ }+ return seeded+ }++ private static func bridgeContents(_ bridge: URL) -> [WineArch: Data] {+ var found: [WineArch: Data] = [:]+ for arch in WineArch.allCases {+ if let data = try? Data(contentsOf: stagedCopy(arch, in: bridge)) { found[arch] = data }+ }+ return found+ }+private func activate(_ build: RunnerBuild,runners: URL,@@ -48,8 +75,9 @@ struct RunnerSwitchTests {bridge: runners.appending(path: "bridge"),license: { _ in license },verify: { _, _ in },- stage: { build, _, _ in+ stage: { build, _, bridge incalls.staged.append(build.id)+ try Self.writeStaged(for: build, into: bridge)return []},patch: { build, _, _ in@@ -91,11 +119,13 @@ struct RunnerSwitchTests {#expect(calls.currentWhilePatching == Self.rosetta.id)}- @Test("A failed switch keeps the old build and restages its ntdll")+ @Test("A failed switch keeps the old build and puts its bridge copies back")func failedSwitchRestoresPrevious() throws {let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])defer { try? FileManager.default.removeItem(at: runners) }try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)+ let bridge = runners.appending(path: "bridge")+ let seeded = try Self.seedBridge(bridge, with: [.x86_64Windows: "old x86_64", .i386Windows: "old i386"])let calls = Calls()#expect(throws: StepFailure.self) {@@ -103,27 +133,75 @@ struct RunnerSwitchTests {}#expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)- #expect(calls.staged == [Self.fex.id, Self.rosetta.id])+ #expect(calls.staged == [Self.fex.id])+ #expect(Self.bridgeContents(bridge) == seeded)+ #expect(!FileManager.default.fileExists(+ atPath: bridge.appending(path: "wine/aarch64-windows").path(percentEncoded: false)))+ }++ @Test("A failed switch away from a build the app no longer lists puts its bridge copies back")+ func failedSwitchFromUnlistedBuild() throws {+ let unlisted = "26.0.0.1"+ #expect(SupportedRunners.build(id: unlisted) == nil)++ let runners = try makeRunners(cloning: [Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }+ try FileManager.default.createDirectory(+ at: SupportPaths.clonedRoot(forBuild: unlisted, runners: runners).appending(path: "lib/wine"),+ withIntermediateDirectories: true+ )+ try RunnerInstaller.pointCurrent(atBuild: unlisted, runners: runners)+ let bridge = runners.appending(path: "bridge")+ let seeded = try Self.seedBridge(bridge, with: [.x86_64Windows: "old x86_64", .i386Windows: "old i386"])++ let calls = Calls()+ #expect(throws: StepFailure.self) {+ try activate(Self.fex, runners: runners, calls: calls, failPatch: true)+ }++ #expect(RunnerStore.currentBuild(runners: runners) == unlisted)+ #expect(Self.bridgeContents(bridge) == seeded)+ }++ @Test("A failed first setup leaves no staged copies behind")+ func failedFirstSetupLeavesBridgeEmpty() throws {+ let runners = try makeRunners(cloning: [Self.fex])+ defer { try? FileManager.default.removeItem(at: runners) }+ let bridge = runners.appending(path: "bridge")++ let calls = Calls()+ #expect(throws: StepFailure.self) {+ try activate(Self.fex, runners: runners, calls: calls, failPatch: true)+ }++ #expect(RunnerStore.currentBuild(runners: runners) == nil)+ #expect(calls.staged == [Self.fex.id])+ #expect(Self.bridgeContents(bridge).isEmpty)}@Test("A failed bridge restore reports both failures")func failedRestoreIsReported() throws {let runners = try makeRunners(cloning: [Self.rosetta, Self.fex])- defer { try? FileManager.default.removeItem(at: runners) }+ let bridge = runners.appending(path: "bridge")+ let locked = bridge.appending(path: "wine/x86_64-windows")+ defer {+ try? FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: locked.path(percentEncoded: false))+ try? FileManager.default.removeItem(at: runners)+ }try RunnerInstaller.pointCurrent(atBuild: Self.rosetta.id, runners: runners)+ _ = try Self.seedBridge(bridge, with: [.x86_64Windows: "old x86_64"])- var staged: [String] = []let failure = try #require(throws: StepFailure.self) {try RunnerSetup.activate(Self.fex,runners: runners,+ bridge: bridge,license: { _ in Self.licensed },verify: { _, _ in },- stage: { build, _, _ in- staged.append(build.id)- if build == Self.rosetta {- throw StepFailure(step: "restore", detail: "disk full")- }+ stage: { build, _, bridge in+ try Self.writeStaged(for: build, into: bridge)+ try FileManager.default.setAttributes(+ [.posixPermissions: 0o555], ofItemAtPath: locked.path(percentEncoded: false))return []},patch: { _, _, _ in@@ -132,11 +210,10 @@ struct RunnerSwitchTests {)}- #expect(staged == [Self.fex.id, Self.rosetta.id])#expect(RunnerStore.currentBuild(runners: runners) == Self.rosetta.id)#expect(failure.detail.contains("patch failed"))#expect(failure.detail.contains("Restoring the previous build also failed"))- #expect(failure.detail.contains("disk full"))+ #expect(failure.detail.contains("x86_64-windows"))}@Test("A build with no clone is refused without touching anything")diff --git a/dylib/feats/compat.c b/dylib/feats/compat.cindex 163d066..2b613b1 100644--- a/dylib/feats/compat.c+++ b/dylib/feats/compat.c@@ -14,7 +14,10 @@// the tool's name contains "proton" so without a match every AutoCloud rule silently// skips the app.#define TOOL_DIR_NAME "notproton"-#define TOOL_DISPLAY_NAME "CrossOver Preview"+#define TOOL_DIR_NAME_ROSETTA "notproton-fex-rosetta"+#define TOOL_DISPLAY_FEX "CrossOver Preview (FEX)"+#define TOOL_DISPLAY_ROSETTA "CrossOver Preview (Rosetta)"+#define TOOL_DISPLAY_ROSETTA_ONLY "CrossOver Preview (Rosetta build)"#define COMPAT_MANAGER_ENABLED_OFF 0x7B0#define COMPAT_TOOL_STRIDE 0x130@@ -36,15 +39,15 @@ static const char TOOL_MANIFEST[] =// Steam's compatibilitytools.d scanner registers a tool when this file is present// in the tool subdirectory. install_path is "." because the manifest lives inside// the tool directory. to_oslist is macos-static const char TOOL_DECLARATION[] =+static const char TOOL_DECLARATION_FMT[] ="\"compatibilitytools\"\n""{\n"" \"compat_tools\"\n"" {\n"- " \"" TOOL_DIR_NAME "\"\n"+ " \"%s\"\n"" {\n"" \"install_path\" \".\"\n"- " \"display_name\" \"" TOOL_DISPLAY_NAME "\"\n"+ " \"display_name\" \"%s\"\n"" \"from_oslist\" \"windows\"\n"" \"to_oslist\" \"macos\"\n"" }\n"@@ -290,34 +293,47 @@ void np_compat_export_tools_path(void) {tools_dir);}-int np_compat_ensure_tool_manifest(void) {+static int has_fex_runner(void) {const char *home = np_home_dir();- if (!home) return -1;+ if (!home) return 0;- char tools_dir[512];- snprintf(tools_dir, sizeof(tools_dir),- "%s/Library/Application Support/Steam/compatibilitytools.d", home);+ char base[512];+ snprintf(base, sizeof(base),+ "%s/Library/Application Support/notproton/runners/current", home);- if (ensure_dir(tools_dir) != 0) {- NP_WARN("np_compat_ensure_tool_manifest: cannot create %s", tools_dir);- return -1;- }+ char path[768];+ snprintf(path, sizeof(path),+ "%s/lib/wine/aarch64-unix/wine.app/Contents/MacOS/wine", base);+ if (access(path, X_OK) != 0) return 0;- char tool_dir[512];- snprintf(tool_dir, sizeof(tool_dir), "%s/%s", tools_dir, TOOL_DIR_NAME);+ snprintf(path, sizeof(path), "%s/CrossOver-Hosted Application/wineserver-arm64", base);+ return access(path, X_OK) == 0;+}++static const char *primary_display_name(void) {+ return has_fex_runner() ? TOOL_DISPLAY_FEX : TOOL_DISPLAY_ROSETTA_ONLY;+}++static int write_tool(const char *tools_dir, const char *name,+ const char *display, const char *flavor) {+ char tool_dir[640];+ snprintf(tool_dir, sizeof(tool_dir), "%s/%s", tools_dir, name);if (ensure_dir(tool_dir) != 0) {NP_WARN("np_compat_ensure_tool_manifest: cannot create %s", tool_dir);return -1;}- char path[512];+ char declaration[512];+ snprintf(declaration, sizeof(declaration), TOOL_DECLARATION_FMT, name, display);++ char path[768];int wrote = 0;// Rewritten every launch so field changes take effect. A rescan replaces it in// place rather than adding a second copy.snprintf(path, sizeof(path), "%s/compatibilitytool.vdf", tool_dir);- if (write_file(path, TOOL_DECLARATION, 0) == 0) wrote++;+ if (write_file(path, declaration, 0) == 0) wrote++;else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);snprintf(path, sizeof(path), "%s/toolmanifest.vdf", tool_dir);@@ -332,12 +348,65 @@ int np_compat_ensure_tool_manifest(void) {if (write_file(path, RUN_SCRIPT, 1) == 0) wrote++;else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);+ char flavor_line[32];+ snprintf(flavor_line, sizeof(flavor_line), "%s\n", flavor);+ snprintf(path, sizeof(path), "%s/flavor", tool_dir);+ if (write_file(path, flavor_line, 0) == 0) wrote++;+ else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);+if (wrote > 0)NP_LOG("np_compat_ensure_tool_manifest: wrote %d file(s) to %s", wrote, tool_dir);return 0;}+static void remove_tool(const char *tools_dir, const char *name) {+ char tool_dir[640];+ snprintf(tool_dir, sizeof(tool_dir), "%s/%s", tools_dir, name);+ if (access(tool_dir, F_OK) != 0) return;++ static const char *const files[] = {+ "compatibilitytool.vdf", "toolmanifest.vdf", "run", "flavor",+ };++ char path[768];+ for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) {+ snprintf(path, sizeof(path), "%s/%s", tool_dir, files[i]);+ unlink(path);+ }++ if (rmdir(tool_dir) == 0)+ NP_LOG("np_compat_ensure_tool_manifest: removed %s", tool_dir);+}++int np_compat_ensure_tool_manifest(void) {+ const char *home = np_home_dir();+ if (!home) return -1;++ char tools_dir[512];+ snprintf(tools_dir, sizeof(tools_dir),+ "%s/Library/Application Support/Steam/compatibilitytools.d", home);++ if (ensure_dir(tools_dir) != 0) {+ NP_WARN("np_compat_ensure_tool_manifest: cannot create %s", tools_dir);+ return -1;+ }++ int fex = has_fex_runner();++ if (write_tool(tools_dir, TOOL_DIR_NAME,+ fex ? TOOL_DISPLAY_FEX : TOOL_DISPLAY_ROSETTA_ONLY,+ fex ? "fex" : "rosetta") != 0)+ return -1;++ if (fex)+ write_tool(tools_dir, TOOL_DIR_NAME_ROSETTA, TOOL_DISPLAY_ROSETTA, "rosetta");+ else+ remove_tool(tools_dir, TOOL_DIR_NAME_ROSETTA);++ return 0;+}+const char *np_compat_tool_dir(void) {static char dir[512];static int resolved = 0;@@ -522,7 +591,7 @@ void np_compat_register_crossover(void *compat_mgr) {memset(tool, 0, sizeof(tool));static const char name[] = TOOL_DIR_NAME;- static const char display[] = TOOL_DISPLAY_NAME;+ const char *display = primary_display_name();static const char from_oslist[] = "windows";static const char to_oslist[] = "macos";diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 6ef0a35..65ede0b 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -36,10 +36,17 @@ export CX_ROOT# cxcompatdb resolves its database through CX_HOME and logs an error for# every module loaded without it :(export CX_HOME="$HOME/Library/Application Support/CrossOver"+np_flavor=""+CDPATH=''+np_tool_dir=$(cd -- "$(dirname -- "$0")" 2>/dev/null && pwd) || np_tool_dir=""+if [ -n "$np_tool_dir" ] && [ -r "$np_tool_dir/flavor" ]; then+ read -r np_flavor < "$np_tool_dir/flavor" || np_flavor=""+fi+wine_unix="$CX_ROOT/lib/wine/aarch64-unix"WINELOADER="$wine_unix/wine.app/Contents/MacOS/wine"WINESERVER="$CX_ROOT/CrossOver-Hosted Application/wineserver-arm64"-if [ ! -x "$WINELOADER" ] || [ ! -x "$WINESERVER" ]; then+if [ "$np_flavor" = rosetta ] || [ ! -x "$WINELOADER" ] || [ ! -x "$WINESERVER" ]; thenwine_unix="$CX_ROOT/lib/wine/x86_64-unix"WINELOADER="$wine_unix/wine"WINESERVER="$CX_ROOT/CrossOver-Hosted Application/wineserver"@@ -379,15 +386,12 @@ install_legacycompat() {}bridge_files="steamclient64.dll steamclient.dll tier0_s64.dll vstdlib_s64.dll"-bridge_files="$bridge_files lsteamclient.dll lsteamclient.so steam.exe"+bridge_files="$bridge_files lsteamclient.dll steam.exe"if [ -d "$bridge_src" ] && [ -n "$WINEPREFIX" ]; thenstage_step="bridge staging"mkdir -p "$prefix_steam"for f in $bridge_files; dosrc="$bridge_src/$f"- if [ "$f" = lsteamclient.so ]; then- src="$bridge_src/${wine_unix##*/}/$f"- fiif [ ! -f "$src" ]; thenecho "=== bridge missing $f ===" >> "$log" 2>&1 || truecontinuediff --git a/ntdll-patch/apply.py b/ntdll-patch/apply.pyindex f2d526d..2e1b679 100644--- a/ntdll-patch/apply.py+++ b/ntdll-patch/apply.py@@ -2,13 +2,36 @@# Development tool. The real patcher lives in the app (NtdllPatcher.swift).# This is the original Python version, kept for validating patches against# new CrossOver builds.+import hashlibimport osimport syssys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))from resolve import PE, resolve, shell_vars # noqa: E402-DEFAULT_PAYLOAD = {0x8664: "detour2.bin", 0x14c: "detour32.bin", 0xaa64: "detour64-fex.bin"}+# A new build needs its ntdll hash added here and in build-ntdll.sh.+PAYLOAD_BY_CLEAN_SHA = {+ "04c7200b6645decb7c2d1ba6b0195abc9af83257072558d11aa72cc067ac3377": "detour2.bin",+ "94cc7c14c1e9dcf58ef501015c115f8405c73b2a65cefe31faa5d9e47f36e58b": "detour32.bin",+ "f4fa556a3dc20f6e966a803f5de554359227a61a24cd5b5a2ad88a427ceeec58": "detour2-fex.bin",+ "09474795d6f306163cebab6429819999fcff50e07dbc4b067a90ec4f74a3a7d7": "detour32-fex.bin",+ "7823d71fbce6c9947163bf8b96beb299eabb02878245bcaf6759f2a22e81f071": "detour64-fex.bin",+}++UNAMBIGUOUS_PAYLOAD = {0xaa64: "detour64-fex.bin"}+KNOWN_MACHINES = (0x8664, 0x14c, 0xaa64)+++def default_payload(src, machine):+ with open(src, "rb") as f:+ digest = hashlib.sha256(f.read()).hexdigest()+ if digest in PAYLOAD_BY_CLEAN_SHA:+ return PAYLOAD_BY_CLEAN_SHA[digest]+ if machine in UNAMBIGUOUS_PAYLOAD:+ return UNAMBIGUOUS_PAYLOAD[machine]+ raise SystemExit(f"{src}: sha256 {digest} matches no known clean ntdll, and machine "+ f"{machine:#x} has more than one detour, pass payload.bin as the "+ f"third argument")def main():@@ -20,10 +43,10 @@ def main():r = resolve(src)v = shell_vars(src)- if r['machine'] not in DEFAULT_PAYLOAD:+ if r['machine'] not in KNOWN_MACHINES:raise SystemExit(f"{src}: machine {r['machine']:#x} carries no detour")payload_path = sys.argv[3] if len(sys.argv) > 3 \- else os.path.join(here, DEFAULT_PAYLOAD[r['machine']])+ else os.path.join(here, default_payload(src, r['machine']))detour = open(payload_path, "rb").read()payload_rva = int(v['NP_PAYLOAD_RVA'], 16)fill = r['fill']diff --git a/ntdll-patch/build-ntdll.sh b/ntdll-patch/build-ntdll.shindex 4e3b90b..747aea4 100755--- a/ntdll-patch/build-ntdll.sh+++ b/ntdll-patch/build-ntdll.sh@@ -15,13 +15,15 @@ OUT="${OUT:-$here/build}"ROSETTA_CLEAN_X86_64=04c7200b6645decb7c2d1ba6b0195abc9af83257072558d11aa72cc067ac3377ROSETTA_CLEAN_I386=94cc7c14c1e9dcf58ef501015c115f8405c73b2a65cefe31faa5d9e47f36e58b-ROSETTA_PATCHED_X86_64=b21f4bace5a7a0cfef0f74cef9b27561f6eb3ad38daf76f36b186ca0677c2b2c+ROSETTA_PATCHED_X86_64=b6a98622fb8f7e6a998bc038f442b17d257da3df5e9e135f0c35f7bbc46ea5d6ROSETTA_PATCHED_I386=25bfde1f50ee96485763968ef10b9d9ad35e38214232f17ebdc009b098af44a0+FEX_CLEAN_X86_64=f4fa556a3dc20f6e966a803f5de554359227a61a24cd5b5a2ad88a427ceeec58FEX_CLEAN_I386=09474795d6f306163cebab6429819999fcff50e07dbc4b067a90ec4f74a3a7d7FEX_CLEAN_AARCH64=7823d71fbce6c9947163bf8b96beb299eabb02878245bcaf6759f2a22e81f071+FEX_PATCHED_X86_64=fa8cd8fe7c4c19effade92d55b00fa946b630ab13cbb6721076848238c1dcf6aFEX_PATCHED_I386=e799ea02418294588ee353a90b967358be316a3044ff9515b28aa1ce07e63981-FEX_PATCHED_AARCH64=560939a0f6e58314fc9d79fe6f839dce2b181f829ae58dca195fa142fcf40f39+FEX_PATCHED_AARCH64=f40810193a5ef2520774288f354a8604f5ba91828315f643b3ee6688b873dc3finstall=0[ "${1:-}" = "--install" ] && install=1@@ -54,7 +56,7 @@ ficase "$FLAVOR" inrosetta) tools="x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc" ;;- fex) tools="i686-w64-mingw32-gcc clang ld.lld" ;;+ fex) tools="x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc clang ld.lld" ;;*) die "unknown flavor $FLAVOR, expected rosetta or fex" ;;esac@@ -108,8 +110,11 @@ case "$FLAVOR" in"$ROSETTA_CLEAN_I386" "$ROSETTA_PATCHED_I386";;fex)- # The 64 bit guest is served by the arm64 ntdll under FEX- ARCHES="i386-windows aarch64-windows"+ # The FEX build ships a version of Wine that runs through Rosetta as well as+ # the FEX/ARM version, so all three ntdlls need patching.+ ARCHES="x86_64-windows i386-windows aarch64-windows"+ patch_one x86_64-windows build.sh fex detour2-fex.bin \+ "$FEX_CLEAN_X86_64" "$FEX_PATCHED_X86_64"patch_one i386-windows build32.sh fex detour32-fex.bin \"$FEX_CLEAN_I386" "$FEX_PATCHED_I386"patch_one aarch64-windows build64.sh fex detour64-fex.bin \diff --git a/ntdll-patch/detour.c b/ntdll-patch/detour.cindex 6c75831..29cd3a0 100644--- a/ntdll-patch/detour.c+++ b/ntdll-patch/detour.c@@ -31,7 +31,7 @@ struct export_dir { u32 flags; u32 stamp; u16 maj; u16 min; u32 name;u32 base; u32 nfuncs; u32 nnames;u32 addr_funcs; u32 addr_names; u32 addr_ords; };-#define LDR_DONT_CALL_DLLMAIN 0x20000000+#define LDR_DONT_RESOLVE_REFS 0x00000002// WINE_MODREF, x86_64 layout.#define WM_DLLBASE(wm) (*(void **)((u8 *)(wm) + 0x30))@@ -97,12 +97,18 @@ static void write_jump(u8 *src, void *tgt)src[10] = 0xFF; src[11] = 0xE0;}+// mov eax, 1 ; ret+static void write_true_stub(u8 *src)+{+ src[0] = 0xB8; src[1] = 0x01; src[2] = 0x00; src[3] = 0x00; src[4] = 0x00;+ src[5] = 0xC3;+}+// Rewrite every named export of sc64 that lsteamclient also exports so it jumps to the// lsteamclient one, plus the entry point.static void setup_trampolines(struct ctx *c, u8 *sc64, u8 *lsteam){struct nt_headers *snt = (struct nt_headers *)(sc64 + ((struct dos_header *)sc64)->e_lfanew);- struct nt_headers *lnt = (struct nt_headers *)(lsteam + ((struct dos_header *)lsteam)->e_lfanew);struct export_dir *se;u32 *snames, *sfuncs, i;u16 *sords;@@ -110,7 +116,7 @@ static void setup_trampolines(struct ctx *c, u8 *sc64, u8 *lsteam)u64 size = snt->opt.size_of_image;u32 oldp;- // make the whole sc64 image writable andexecutable so export stubs can be overwritten //+ // make the whole sc64 image writable and executable so export stubs can be overwrittenif (c->protect((void *)~0ull, &base, &size, 0x40 /*RWX*/, &oldp) != 0)return;@@ -128,8 +134,10 @@ static void setup_trampolines(struct ctx *c, u8 *sc64, u8 *lsteam)write_jump(sc64 + sfuncs[sords[i]], tgt);}- if (snt->opt.entry_point && lnt->opt.entry_point)- write_jump(sc64 + snt->opt.entry_point, lsteam + lnt->opt.entry_point);+ // Report success instead of forwarding. lsteamclient's DllMain has to run while+ // Windows is loading lsteamclient, not while it is loading this stub.+ if (snt->opt.entry_point)+ write_true_stub(sc64 + snt->opt.entry_point);}// True when the MODREF basename (wm+0x60, a NUL-terminated wide string) is@@ -170,5 +178,5 @@ void detour_build_module(struct ctx *c, void *wm, void *load_path)setup_trampolines(c, sc64, lsteam);- *WM_FLAGS(wm) |= LDR_DONT_CALL_DLLMAIN;+ *WM_FLAGS(wm) |= LDR_DONT_RESOLVE_REFS;}diff --git a/ntdll-patch/link.ld b/ntdll-patch/link.ldindex 04ce3b1..05e2660 100644--- a/ntdll-patch/link.ld+++ b/ntdll-patch/link.ld@@ -1,4 +1,4 @@-// x86_64 ntdll.dll cave layout, link time only+/* x86_64 ntdll.dll cave layout, link time only */SECTIONS {. = CAVE_VA;.cave : {diff --git a/ntdll-patch/link32.ld b/ntdll-patch/link32.ldindex 192a2a2..ea38db6 100644--- a/ntdll-patch/link32.ld+++ b/ntdll-patch/link32.ld@@ -1,4 +1,4 @@-// i386 ntdll.dll cave layout, link time only+/* i386 ntdll.dll cave layout, link time only */SECTIONS {. = CAVE_VA;.cave : SUBALIGN(1) {diff --git a/ntdll-patch/link64.ld b/ntdll-patch/link64.ldindex 560cc4e..e086f05 100644--- a/ntdll-patch/link64.ld+++ b/ntdll-patch/link64.ld@@ -1,4 +1,4 @@-// aarch64 ntdll.dll cave layout, link time only+/* aarch64 ntdll.dll cave layout, link time only */SECTIONS {. = CAVE_VA;.cave : {diff --git a/ntdll-patch/resolve.py b/ntdll-patch/resolve.pyindex ea1fa38..a9ab712 100755--- a/ntdll-patch/resolve.py+++ b/ntdll-patch/resolve.py@@ -14,7 +14,7 @@ PINNED = {'04c7200b6645decb7c2d1ba6b0195abc9af83257072558d11aa72cc067ac3377':{'hookRVA': 0x51f15, 'stolen': '4883bc24f000000000', 'caveRVA': 0x80be0, 'wm': 'rsi','resume': 0x51f1e, 'load_path': 0xd0,- 'payload': '4ce2ddc11c433fe15f78633fc5c1fda8b27fa642426cb26378f7d7d7b54a79f8',+ 'payload': '8504714bba0195439cb5b44c89f25c68dbb7f01bae6f72ca0a258a0daec3e244','exports': {'LdrGetDllHandle': 0x1700176d0, 'LdrLoadDll': 0x1700181f0,'NtProtectVirtualMemory': 0x17000f640}},'94cc7c14c1e9dcf58ef501015c115f8405c73b2a65cefe31faa5d9e47f36e58b':@@ -24,6 +24,12 @@ PINNED = {'exports': {'LdrGetDllHandle': 0x7bc125b0, 'LdrLoadDll': 0x7bc130a0,'NtProtectVirtualMemory': 0x7bc0d764, 'NtOpenFile': 0x7bc0d594,'NtReadFile': 0x7bc0d2c4, 'NtClose': 0x7bc0d354}},+ 'f4fa556a3dc20f6e966a803f5de554359227a61a24cd5b5a2ad88a427ceeec58':+ {'hookRVA': 0x34b2e, 'stolen': '488b842410010000', 'caveRVA': 0x79394, 'wm': 'rbx',+ 'resume': 0x34b36, 'load_path': 0x98,+ 'payload': '6af3f36658907cc94c096e432006807d6997bd970560f2579df748d6fd6e2bc6',+ 'exports': {'LdrGetDllHandle': 0x17002f530, 'LdrLoadDll': 0x17002ce70,+ 'NtProtectVirtualMemory': 0x17005549c}},'09474795d6f306163cebab6429819999fcff50e07dbc4b067a90ec4f74a3a7d7':{'hookRVA': 0x2ee12, 'stolen': '8b4514a802', 'caveRVA': 0x6b2fe, 'caveSize': 3330,'resume': 0x2ee17, 'wm': 'esi', 'load_path': -0x3c,@@ -44,7 +50,7 @@ PINNED = {# exported NtProtectVirtualMemory is a syscall thunk whose dispatcher is null.'guest': {'LdrLoadDll': 0x9f698, 'LdrGetDllHandle': 0x9f698,'NtProtectVirtualMemory': 0xea8cc},- 'payload': 'bee4ee13c235bd5de3cb6ce840b9695effd5623132f6dc0d137496d6a5330f5e',+ 'payload': '68a458ec9c32041c79fdd622d18e91cfbe825a5292cae362d310930e34dd598e','exports': {'LdrGetDllHandle': 0x180043328, 'LdrLoadDll': 0x180040e94,'NtProtectVirtualMemory': 0x180065db0}},}