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
Improve launch argument handling to match the behavior of Linux Steam
NotProtonNote9f97f755ba9
diff --git a/Makefile b/Makefileindex da08415..4a742a7 100644--- a/Makefile+++ b/Makefile@@ -36,6 +36,7 @@ SRCS := \dylib/hooks/hook_webui.c \dylib/hooks/hook_webpatch.c \dylib/hooks/hook_spawn.c \+ dylib/hooks/hook_launch.c \dylib/feats/compat.c \dylib/feats/webui.c \dylib/feats/compatsvc.c \@@ -55,17 +56,19 @@ TARGET := $(OUT_DIR)/notproton.dylibOBJS := $(patsubst %.c,$(OUT_DIR)/%.o,$(SRCS))DEPS := $(OBJS:.o=.d)-.PHONY: all clean rebuild dobby deploy dylib-install sigcheck app-payload app app-zip \+.PHONY: all clean rebuild dobby deploy dylib dylib-install sigcheck app-payload app app-zip \anchorcheck sigdb-fixtures webpatch-fixtures peicon-fixtures panel-behavior app-tests \tests-list overlay-shim overlay-shim-install overlay-shim-tests \overlay-shim-bench iconmaker icon \appinfo helpers-install ntdll-resolve bridge runcheck compatcheck \- compatsvc-check scriptcheck FORCE+ compatsvc-check scriptcheck envcheck launch-shell FORCEAPP_PAYLOAD := app/Sources/NotProtonApp/Resources/payloadall: $(TARGET) $(APP_PAYLOAD)+dylib: $(TARGET)+# SwiftPM's `.copy("Resources/payload")` in Package.swift needs this directory# to exist$(APP_PAYLOAD):@@ -85,6 +88,10 @@ runcheck:shellcheck dylib/feats/compat_run.sh && sh -n dylib/feats/compat_run.sh && \echo "==> runcheck: the run script lints and parses clean"+envcheck:+ @if [ ! -f dylib/tests/envcheck.sh ]; then $(call SKIP,envcheck,dylib/tests/envcheck.sh); exit 0; fi; \+ sh dylib/tests/envcheck.sh dylib/feats/compat_run.sh+# runcheck owns compat_run.sh, whose warnings wait for a change that can move# the embedded __text baselineSCRIPTS := $(shell git ls-files '*.sh' 2>/dev/null | grep -v '^dylib/feats/compat_run\.sh$$')@@ -213,6 +220,15 @@ webpatch-fixtures:if [ $$fail -ne 0 ]; then exit 1; fi; \echo "==> gate table and $$n webpatch fixtures: anchors intact, drift refused"+LAUNCH_SHELL := $(OUT_DIR)/launch-shell++launch-shell:+ @if [ ! -f dylib/tests/launch-shell.c ]; then $(call SKIP,launch-shell,dylib/tests/launch-shell.c); exit 0; fi; \+ mkdir -p $(OUT_DIR) && \+ $(CC) -arch $(ARCH) -mmacosx-version-min=$(MIN_VER) -std=c17 -g -O1 \+ -Wall -Wextra -Wno-unused-parameter -Idylib -o $(LAUNCH_SHELL) dylib/tests/launch-shell.c && \+ $(LAUNCH_SHELL)+SPAWN_ENV := $(OUT_DIR)/spawn-envspawn-env:diff --git a/app/Tests/NotProtonAppTests/LaunchEnvTests.swift b/app/Tests/NotProtonAppTests/LaunchEnvTests.swiftnew file mode 100644index 0000000..3ab4fd4--- /dev/null+++ b/app/Tests/NotProtonAppTests/LaunchEnvTests.swift@@ -0,0 +1,67 @@+import Foundation+import Testing++@testable import NotProtonApp++@Suite("Launch environment")+struct LaunchEnvTests {++ private static func runScript() throws -> String {+ let repo = URL(filePath: #filePath)+ .deletingLastPathComponent()+ .deletingLastPathComponent()+ .deletingLastPathComponent()+ .deletingLastPathComponent()+ return try String(+ contentsOf: repo.appending(path: "dylib/feats/compat_run.sh"), encoding: .utf8)+ }++ private static func line(containing needles: String...) throws -> String {+ let script = try runScript()+ return try #require(+ script.split(separator: "\n")+ .first { line in needles.allSatisfy(line.contains) }+ .map(String.init),+ "compat_run.sh no longer has a line containing \(needles.joined(separator: " and "))")+ }++ @Test("A launch option cannot unhook the steamclient overrides")+ func overridesKeepTheTrioLast() throws {+ let line = try Self.line(+ containing: "export WINEDLLOVERRIDES=", "steamclient=n;steamclient64=n;lsteamclient=b")+ let user = try #require(line.range(of: "${WINEDLLOVERRIDES:+"))+ let trio = try #require(line.range(of: "steamclient=n;steamclient64=n;lsteamclient=b"))+ #expect(+ user.lowerBound < trio.lowerBound,+ "the trio must follow the launch option, because ntdll keeps the last setting")+ }++ @Test("A launch option cannot shadow the runner's own dlls")+ func dllPathKeepsTheRunnerFirst() throws {+ let line = try Self.line(containing: "export WINEDLLPATH=", "x86_64-windows")+ let runner = try #require(line.range(of: "$CX_ROOT/lib/wine/x86_64-windows"))+ let user = try #require(line.range(of: "${WINEDLLPATH:+"))+ #expect(+ runner.lowerBound < user.lowerBound,+ "the runner must precede the launch option, because the loader takes the first match")+ }++ @Test("The prefix and loader are not taken from launch options")+ func ownedVarsAreOverwritten() throws {+ _ = try Self.line(containing: "export WINEPREFIX=", "STEAM_COMPAT_DATA_PATH")++ let script = try Self.runScript()+ for name in ["WINEPREFIX", "WINELOADER", "WINESERVER"] {+ #expect(+ !script.contains("${\(name):-"),+ "\(name) must not fall back to what it inherits, which a launch option now sets")+ }++ let path = try Self.line(containing: "export PATH=")+ let runner = try #require(path.range(of: "$CX_ROOT/bin"))+ let inherited = try #require(path.range(of: ":$PATH"))+ #expect(+ runner.lowerBound < inherited.lowerBound,+ "the runner's tools must precede an inherited PATH, which a launch option now sets")+ }+}diff --git a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift b/app/Tests/NotProtonAppTests/PrefixToolsTests.swiftindex 1cc8ac5..66a65b1 100644--- a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift+++ b/app/Tests/NotProtonAppTests/PrefixToolsTests.swift@@ -75,6 +75,7 @@ struct PrefixToolsTests {let environment = PrefixTools.environment(prefix: samplePrefix(), runner: runner)let dllPath = try exported("WINEDLLPATH")+ .replacingOccurrences(of: "${WINEDLLPATH:+:$WINEDLLPATH}", with: "").replacingOccurrences(of: "$CX_ROOT", with: runner.path(percentEncoded: false)).replacingOccurrences(of: "$wine_unix", with: layout.unixDir.path(percentEncoded: false))diff --git a/app/Tests/NotProtonAppTests/ToggleAgreementTests.swift b/app/Tests/NotProtonAppTests/ToggleAgreementTests.swiftindex 002186a..5d24830 100644--- a/app/Tests/NotProtonAppTests/ToggleAgreementTests.swift+++ b/app/Tests/NotProtonAppTests/ToggleAgreementTests.swift@@ -1,11 +1,8 @@-import Darwinimport Foundationimport Testing@testable import NotProtonApp-// webpatch.c writes the Compatibility page toggles and compat_run.sh decides which tokens are-// environment rather than game arguments. Nothing at build time holds the two together.@Suite("Toggle agreement")struct ToggleAgreementTests {@@ -33,26 +30,27 @@ struct ToggleAgreementTests {return names}- static func allowedPatterns(in compat: String) throws -> [String] {- let line = try #require(- compat.split(separator: "\n").first { $0.contains("*=*|") },- "compat_run.sh no longer has a launch option allowlist")- return line.matches(of: try Regex(#"([A-Z0-9_]+\*?=\*)"#))- .map { String($0[1].substring ?? "") }- }+ static let ownedNames: Set<String> = ["WINEPREFIX", "WINELOADER", "WINESERVER", "PATH"]- @Test("Every Compatibility page toggle is exported rather than passed to the game")+ @Test("Every Compatibility page toggle reaches the game as an environment variable")func togglesAreNamespaced() throws {- let names = try Self.toggleNames(in: try Self.source("dylib/feats/webpatch.c"))- let patterns = try Self.allowedPatterns(in: try Self.source("dylib/feats/compat_run.sh"))+ let webpatch = try Self.source("dylib/feats/webpatch.c")+ let names = try Self.toggleNames(in: webpatch)#expect(names.count >= 8, "found \(names.count) toggles, the parse looks wrong")- #expect(!patterns.isEmpty)++ #expect(+ webpatch.contains(#"v.push(\"%command%\")"#),+ "webpatch.c no longer writes %command%, so the toggles would reach the game as arguments"+ )for name in names.sorted() {- let token = "\(name)=1"- let covered = patterns.contains { fnmatch($0, token, 0) == 0 }- #expect(covered, "\(name) matches no allowlist pattern in compat_run.sh, so it reads as unset")+ #expect(+ !Self.ownedNames.contains(name),+ "\(name) is set by compat_run.sh, so the panel would write a value it overwrites")+ #expect(+ name.allSatisfy { $0.isASCII && ($0.isLetter || $0.isNumber || $0 == "_") },+ "\(name) is not a name sh can export, so it would reach the game as an argument")}}}diff --git a/dylib/core/loader.c b/dylib/core/loader.cindex 1a97a99..49de7e3 100644--- a/dylib/core/loader.c+++ b/dylib/core/loader.c@@ -155,6 +155,10 @@ static void *install_thread(void *unused) {return NULL;}+ // Everything else aborts on a stale signature database,+ // but this hooks a name and not an address.+ np_hooks_launch_install(mh, slide);+uintptr_t text_base = 0;size_t text_size = 0;diff --git a/dylib/core/macho.c b/dylib/core/macho.cindex e511c18..6fd2762 100644--- a/dylib/core/macho.c+++ b/dylib/core/macho.c@@ -1,5 +1,7 @@#include "macho.h"#include <mach-o/dyld.h>+#include <mach-o/nlist.h>+#include <sys/mman.h>#include <signal.h>#include <string.h>#include <unistd.h>@@ -183,3 +185,70 @@ int np_get_section_containing(const struct mach_header_64 *mh, intptr_t slide,}return -1;}++int np_rebind_import(const struct mach_header_64 *mh, intptr_t slide,+ const char *symbol, void *replacement) {+ if (!mh || !symbol || !replacement) return -1;++ const struct symtab_command *symtab = NULL;+ const struct dysymtab_command *dysymtab = NULL;+ const struct segment_command_64 *linkedit = NULL;+ const uint8_t *cursor = (const uint8_t *)(mh + 1);++ for (uint32_t i = 0; i < mh->ncmds; i++) {+ const struct load_command *lc = (const struct load_command *)cursor;+ if (lc->cmdsize < sizeof(*lc))+ return -1;+ if (lc->cmd == LC_SYMTAB)+ symtab = (const struct symtab_command *)cursor;+ else if (lc->cmd == LC_DYSYMTAB)+ dysymtab = (const struct dysymtab_command *)cursor;+ else if (lc->cmd == LC_SEGMENT_64+ && strcmp(((const struct segment_command_64 *)cursor)->segname, SEG_LINKEDIT) == 0)+ linkedit = (const struct segment_command_64 *)cursor;+ cursor += lc->cmdsize;+ }+ if (!symtab || !dysymtab || !linkedit || !dysymtab->nindirectsyms)+ return -1;++ uintptr_t base = (uintptr_t)slide + linkedit->vmaddr - linkedit->fileoff;+ const struct nlist_64 *syms = (const struct nlist_64 *)(base + symtab->symoff);+ const char *strings = (const char *)(base + symtab->stroff);+ const uint32_t *indirect = (const uint32_t *)(base + dysymtab->indirectsymoff);++ int rebound = 0;+ cursor = (const uint8_t *)(mh + 1);+ for (uint32_t i = 0; i < mh->ncmds; i++) {+ const struct load_command *lc = (const struct load_command *)cursor;+ cursor += lc->cmdsize;+ if (lc->cmd != LC_SEGMENT_64)+ continue;++ const struct segment_command_64 *seg = (const struct segment_command_64 *)lc;+ const struct section_64 *sect = (const struct section_64 *)(seg + 1);+ for (uint32_t j = 0; j < seg->nsects; j++, sect++) {+ uint32_t type = sect->flags & SECTION_TYPE;+ if (type != S_LAZY_SYMBOL_POINTERS && type != S_NON_LAZY_SYMBOL_POINTERS)+ continue;++ void **slots = (void **)((uintptr_t)slide + sect->addr);+ for (uint64_t k = 0; k < sect->size / sizeof(void *); k++) {+ uint32_t index = indirect[sect->reserved1 + k];+ if (index & (INDIRECT_SYMBOL_LOCAL | INDIRECT_SYMBOL_ABS) || index >= symtab->nsyms)+ continue;+ if (strcmp(strings + syms[index].n_un.n_strx, symbol) != 0)+ continue;++ // __DATA_CONST is read-only once dyld is done with it.+ uintptr_t page = (uintptr_t)&slots[k] & ~(uintptr_t)(getpagesize() - 1);+ if (mprotect((void *)page, (size_t)getpagesize(), PROT_READ | PROT_WRITE) != 0)+ continue;+ slots[k] = replacement;+ if (strcmp(seg->segname, "__DATA_CONST") == 0)+ mprotect((void *)page, (size_t)getpagesize(), PROT_READ);+ rebound++;+ }+ }+ }+ return rebound;+}diff --git a/dylib/core/macho.h b/dylib/core/macho.hindex 9fc8641..c1909bf 100644--- a/dylib/core/macho.h+++ b/dylib/core/macho.h@@ -21,4 +21,7 @@ int np_get_section_containing(const struct mach_header_64 *mh, intptr_t slide,int np_function_bounds(const struct mach_header_64 *mh, intptr_t slide,uintptr_t addr, uintptr_t *out_start, uintptr_t *out_end);+int np_rebind_import(const struct mach_header_64 *mh, intptr_t slide,+ const char *symbol, void *replacement);+#endif // NOTPROTON_CORE_MACHO_Hdiff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 65ede0b..545578b 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -5,24 +5,10 @@ set -everb="$1"shift || true-# Options set from the Compatibility page are passed along as-# launch options.-launch_env=""-argc=$#-argi=0-while [ "$argi" -lt "$argc" ]; do- arg="$1"- shift- case "$arg" in- CX_GRAPHICS*=*|D3DM_*=*|DXMT_*=*|DXVK_*=*|MTL_*=*|NOTPROTON_*=*|ROSETTA_*=*|WINE*=*)- # shellcheck disable=SC2163 # arg is a NAME=VALUE pair, which export takes as an assignment- export "$arg"- launch_env="$launch_env $arg"- ;;- *) set -- "$@" "$arg" ;;- esac- argi=$((argi+1))-done+# hook_launch.c passes the launch options through a shell before this script runs, matching+# Linux Steam. A NAME=value option placed ahead of %command% is an environment variable,+# and anything after %command% is a launch argument passed to the game.+launch_args="$*"case "$verb" ingetcompatpath)@@ -53,7 +39,8 @@ if [ "$np_flavor" = rosetta ] || [ ! -x "$WINELOADER" ] || [ ! -x "$WINESERVER"[ -x "$WINESERVER" ] || WINESERVER="$CX_ROOT/CrossOver-Hosted Application/wineserver-x86"fiexport WINELOADER WINESERVER-export WINEDLLPATH="$CX_ROOT/lib/wine/x86_64-windows:$wine_unix"+# If two WINEDLLPATH directories have the same DLL, Wine uses the one listed first.+export WINEDLLPATH="$CX_ROOT/lib/wine/x86_64-windows:$wine_unix${WINEDLLPATH:+:$WINEDLLPATH}"export PATH="$CX_ROOT/bin:$PATH"if [ -n "$STEAM_COMPAT_DATA_PATH" ]; then@@ -285,7 +272,7 @@ lay_out_proton_profile() {if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenexport WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"mkdir -p "$WINEPREFIX"- msync_from=launch-options+ msync_from=environmentif [ -z "$WINEMSYNC" ] && [ -r "$STEAM_COMPAT_DATA_PATH/notproton-msync" ]; thenWINEMSYNC=$(tr -d ' \t\n' \< "$STEAM_COMPAT_DATA_PATH/notproton-msync" 2>/dev/null || true)@@ -410,7 +397,8 @@ if [ -d "$bridge_src" ] && [ -n "$WINEPREFIX" ]; theninstall_lsteamclient_triggerinstall_legacy_steam_dllexport WINEDLLPATH="$prefix_steam:$WINEDLLPATH"- export WINEDLLOVERRIDES="steamclient=n;steamclient64=n;lsteamclient=b"+ # If the same DLL appears twice in WINEDLLOVERRIDES, the last entry wins.+ export WINEDLLOVERRIDES="${WINEDLLOVERRIDES:+$WINEDLLOVERRIDES;}steamclient=n;steamclient64=n;lsteamclient=b"native_client="$STEAM_COMPAT_CLIENT_INSTALL_PATH"if [ -z "$native_client" ]; thennative_client="$HOME/Library/Application Support/Steam/Steam.AppBundle/Steam/Contents/MacOS"@@ -419,12 +407,13 @@ if [ -d "$bridge_src" ] && [ -n "$WINEPREFIX" ]; theninstall_legacycompatecho "=== bridge staged into $prefix_steam ===" >> "$log" 2>&1 || trueecho "WINEDLLPATH=$WINEDLLPATH" >> "$log" 2>&1 || true+ echo "WINEDLLOVERRIDES=$WINEDLLOVERRIDES" >> "$log" 2>&1 || trueecho "STEAM_COMPAT_CLIENT_INSTALL_PATH=$STEAM_COMPAT_CLIENT_INSTALL_PATH" >> "$log" 2>&1 || truefiexport WINEDEBUG="${WINEDEBUG:-err+all,fixme-all}"trap - EXIT-echo "launch_env=$launch_env" >> "$log" 2>&1 || true+echo "launch_args=$launch_args" >> "$log" 2>&1 || trueecho "=== launching ($verb): $WINELOADER $* ===" >> "$log" 2>&1 || truetarget="$1"diff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.cindex 51bf9be..eb216ac 100644--- a/dylib/feats/webpatch.c+++ b/dylib/feats/webpatch.c@@ -116,9 +116,12 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {ARG "=>{" \"const t=" ARG ".details,o=t.strLaunchOptions||\"\"," \"g=k=>{const p=o.split(\" \").find(x=>x.indexOf(k+\"=\")===0);return p?p.slice(k.length+1):\"\"}," \- "s=ps=>{const a=o.split(\" \").filter(x=>x&&!ps.some(p=>x.indexOf(p[0]+\"=\")===0));" \- "ps.forEach(p=>{if(p[1])a.unshift(p[0]+\"=\"+p[1])});" \- "SteamClient.Apps.SetAppLaunchOptions(t.unAppID,a.join(\" \"))}," \+ "s=ps=>{const a=o.split(\" \").filter(x=>x&&!ps.some(p=>x.indexOf(p[0]+\"=\")===0))," \+ "v=ps.filter(p=>p[1]).map(p=>p[0]+\"=\"+p[1]);" \+ "if(v.length&&a.indexOf(\"%command%\")<0)v.push(\"%command%\");" \+ "const r=v.concat(a);" \+ "SteamClient.Apps.SetAppLaunchOptions(t.unAppID," \+ "1===r.length&&\"%command%\"===r[0]?\"\":r.join(\" \"))}," \"T=(ks,l,on,off)=>(0," RT ".jsx)(" BARREL ".Yh,{className:\"MSCXRow\",label:l," \"checked:g(ks[0])===on," \"onChange:v=>s(ks.map(k=>[k,v?on:(off||\"\")]))},ks[0])," \diff --git a/dylib/hooks/hook_launch.c b/dylib/hooks/hook_launch.cnew file mode 100644index 0000000..af7af84--- /dev/null+++ b/dylib/hooks/hook_launch.c@@ -0,0 +1,93 @@+// Makes Steam's Launch Options behave the way they do on Linux.+#include "hooks.h"+#include "../core/macho.h"+#include "../util/log.h"++#include <dlfcn.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>++#define NP_PARSE_SYM_POSIX \+ "_Z28V_ParseShellCommandLinePOSIXPKcR10CUtlVectorI10CUtlString10CUtlMemoryIS2_EEiPS0_"++typedef int (*fn_parse_shell)(const char *cmd, void *argv, int max, const char **rest);++static fn_parse_shell orig_parse_shell;++static size_t np_quote(char *out, const char *s) {+ size_t n = 0;++ out[n++] = '\'';+ for (; *s; s++) {+ if (*s == '\'') {+ memcpy(out + n, "'\\''", 4);+ n += 4;+ } else {+ out[n++] = *s;+ }+ }+ out[n++] = '\'';+ return n;+}++// Shell, followed by the command line as one argument.+static char *np_launch_shell(const char *cmd, const char *shell, int max, const char **rest) {+ // np_hook_parse_shell frees the wrapped copy before its caller reads *rest.+ if (!cmd || max != -1 || rest)+ return NULL;++ const char *lead = shell ? "" : "/bin/sh -c ";+ size_t cap = strlen(lead) + 4 * strlen(cmd) + 3+ + (shell ? 4 * strlen(shell) + 3 : 0) + 1;+ char *out = malloc(cap);+ size_t n = strlen(lead);++ if (!out)+ return NULL;++ memcpy(out, lead, n);+ if (shell) {+ n += np_quote(out + n, shell);+ out[n++] = ' ';+ }+ n += np_quote(out + n, cmd);+ out[n] = 0;+ return out;+}++static int np_hook_parse_shell(const char *cmd, void *argv, int max, const char **rest) {+ const char *shell = getenv("STEAM_GAME_LAUNCH_SHELL");+ char *wrapped = np_launch_shell(cmd, shell, max, rest);++ if (wrapped)+ NP_LOG("[launch] handed to %s: %s", shell ? shell : "/bin/sh -c", cmd);++ int rc = orig_parse_shell(wrapped ? wrapped : cmd, argv, max, rest);+ free(wrapped);+ return rc;+}++void np_hooks_launch_install(const struct mach_header_64 *mh, intptr_t slide) {+ if (np_hooks_env_lists_label("NOTPROTON_DISABLE", "launch")) {+ NP_WARN("[launch] DISABLED via NOTPROTON_DISABLE, launches keep running "+ "without a shell");+ return;+ }++ // dlsym takes the name without the leading underscore the symbol table carries.+ orig_parse_shell = (fn_parse_shell)dlsym(RTLD_DEFAULT, NP_PARSE_SYM_POSIX);+ if (!orig_parse_shell) {+ NP_WARN("[launch] V_ParseShellCommandLinePOSIX: unresolved, launches keep "+ "running without a shell");+ return;+ }++ int rebound = np_rebind_import(mh, slide, "_" NP_PARSE_SYM_POSIX,+ (void *)np_hook_parse_shell);+ if (rebound > 0)+ NP_LOG("[launch] V_ParseShellCommandLinePOSIX: %d import slot(s) rebound", rebound);+ else+ NP_WARN("[launch] V_ParseShellCommandLinePOSIX: no import slot in steamclient "+ "(rc=%d), launches keep running without a shell", rebound);+}diff --git a/dylib/hooks/hooks.h b/dylib/hooks/hooks.hindex 1604f00..2cf3242 100644--- a/dylib/hooks/hooks.h+++ b/dylib/hooks/hooks.h@@ -60,6 +60,10 @@ int np_hooks_install_steamui(const struct mach_header_64 *mh, intptr_t slide,// NOTPROTON_DISABLE uses this to skip named hooks.int np_hooks_env_lists_label(const char *var, const char *label);+// Resolved by symbol name instead of the signature database, so %command% keeps working+// on a client that is newer than the database.+void np_hooks_launch_install(const struct mach_header_64 *mh, intptr_t slide);+// Resolved from libc rather than the signature database, and installed before the client// can spawn anything, so this one does not wait for steamclient the way the rest do.void np_hooks_spawn_install(void);diff --git a/dylib/tests/envcheck.sh b/dylib/tests/envcheck.shnew file mode 100755index 0000000..e75b40c--- /dev/null+++ b/dylib/tests/envcheck.sh@@ -0,0 +1,44 @@+#!/bin/sh+# shellcheck disable=SC2034,SC2154+set -e+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"+[ -f "$SRC" ] || { echo "envcheck: $SRC not present, skipped"; exit 0; }++strip() { sed 's/^[[:space:]]*//'; }+dllpath_line=$(grep 'export WINEDLLPATH=' "$SRC" | grep 'x86_64-windows' | strip)+overrides_line=$(grep 'export WINEDLLOVERRIDES=' "$SRC" | grep 'lsteamclient=b' | strip)+[ -n "$dllpath_line" ] || { echo "FAIL: WINEDLLPATH merge not found"; exit 1; }+[ -n "$overrides_line" ] || { echo "FAIL: WINEDLLOVERRIDES merge not found"; exit 1; }++fails=0+ok() { printf ' ok %s\n' "$1"; }+bad() { printf ' FAIL %s\n want [%s]\n got [%s]\n' "$1" "$2" "$3"; fails=$((fails + 1)); }+is() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "$2" "$3"; fi; }++echo "== WINEDLLPATH (first match wins, runner first) =="+CX_ROOT=/R+wine_unix=/R/lib/wine/x86_64-unix+WINEDLLPATH=""+eval "$dllpath_line"+is "no user value" "/R/lib/wine/x86_64-windows:/R/lib/wine/x86_64-unix" "$WINEDLLPATH"+WINEDLLPATH="/user/dir"+eval "$dllpath_line"+is "user value last" "/R/lib/wine/x86_64-windows:/R/lib/wine/x86_64-unix:/user/dir" "$WINEDLLPATH"++echo "== WINEDLLOVERRIDES (last wins, trio last) =="+WINEDLLOVERRIDES=""+eval "$overrides_line"+is "no user value" "steamclient=n;steamclient64=n;lsteamclient=b" "$WINEDLLOVERRIDES"+WINEDLLOVERRIDES="winhttp=n,b"+eval "$overrides_line"+is "user value first" "winhttp=n,b;steamclient=n;steamclient64=n;lsteamclient=b" "$WINEDLLOVERRIDES"+WINEDLLOVERRIDES="lsteamclient=n"+eval "$overrides_line"+is "trio outranks user" "lsteamclient=n;steamclient=n;steamclient64=n;lsteamclient=b" "$WINEDLLOVERRIDES"++if [ "$fails" -eq 0 ]; then+ echo "==> envcheck: all assertions hold"+else+ echo "==> envcheck: $fails failed"+ exit 1+fidiff --git a/dylib/tests/launch-shell.c b/dylib/tests/launch-shell.cnew file mode 100644index 0000000..101a0a0--- /dev/null+++ b/dylib/tests/launch-shell.c@@ -0,0 +1,106 @@+#include "../hooks/hook_launch.c"++#include <stdio.h>++int np_log_level = 0;+FILE *np_log_file = NULL;++int np_rebind_import(const struct mach_header_64 *mh, intptr_t slide,+ const char *symbol, void *replacement) {+ (void)mh; (void)slide; (void)symbol; (void)replacement;+ return -1;+}++int np_hooks_env_lists_label(const char *var, const char *label) {+ (void)var; (void)label;+ return 0;+}++static int failures;+static const char *shell;++static void wraps(const char *in, const char *want) {+ char *got = np_launch_shell(in, shell, -1, NULL);++ if (!got || strcmp(got, want) != 0) {+ printf("FAIL %s\n want: %s\n got: %s\n", in, want, got ? got : "(unchanged)");+ failures++;+ } else {+ printf(" ok %s\n", in);+ }+ free(got);+}++int main(void) {+ printf("== a NAME=VALUE prefix reaches the shell that promotes it ==\n");+ wraps("LSFGM_ENV=1 /g/game.exe", "/bin/sh -c 'LSFGM_ENV=1 /g/game.exe'");+ wraps("A=1 B=2 /g/game.exe", "/bin/sh -c 'A=1 B=2 /g/game.exe'");+ wraps("A=1 /g/game.exe -windowed", "/bin/sh -c 'A=1 /g/game.exe -windowed'");+ wraps(" A=1 /g/game.exe", "/bin/sh -c ' A=1 /g/game.exe'");++ wraps("A=1", "/bin/sh -c 'A=1'");++ printf("== the quotes Steam substitutes survive byte for byte ==\n");+ wraps("A=1 \"/Program Files/game.exe\"",+ "/bin/sh -c 'A=1 \"/Program Files/game.exe\"'");+ wraps("A='x y' /g/game.exe", "/bin/sh -c 'A='\\''x y'\\'' /g/game.exe'");+ wraps("A=1 '/p/.'/run waitforexitandrun '/g/g 64.exe'",+ "/bin/sh -c 'A=1 '\\''/p/.'\\''/run waitforexitandrun '\\''/g/g 64.exe'\\'''");++ printf("== what only a shell would act on reaches one ==\n");+ wraps("/g/game.exe > /tmp/log", "/bin/sh -c '/g/game.exe > /tmp/log'");+ wraps("/g/game.exe | tee /tmp/log", "/bin/sh -c '/g/game.exe | tee /tmp/log'");+ wraps("/g/game.exe && echo done", "/bin/sh -c '/g/game.exe && echo done'");+ wraps("/g/game.exe; echo done", "/bin/sh -c '/g/game.exe; echo done'");+ wraps("/g/game.exe $HOME", "/bin/sh -c '/g/game.exe $HOME'");+ wraps("/g/game.exe \"$HOME\"", "/bin/sh -c '/g/game.exe \"$HOME\"'");+ wraps("/g/game.exe ~/save", "/bin/sh -c '/g/game.exe ~/save'");+ wraps("/g/game.exe *.cfg", "/bin/sh -c '/g/game.exe *.cfg'");++ printf("== a plain command line reaches the shell too, as on Linux ==\n");+ wraps("/g/game.exe", "/bin/sh -c '/g/game.exe'");+ wraps("/g/game.exe -windowed", "/bin/sh -c '/g/game.exe -windowed'");+ wraps("\"/Program Files/game.exe\" -windowed",+ "/bin/sh -c '\"/Program Files/game.exe\" -windowed'");+ wraps("gamemoderun /g/game.exe", "/bin/sh -c 'gamemoderun /g/game.exe'");+ wraps("/g/game.exe '$HOME'", "/bin/sh -c '/g/game.exe '\\''$HOME'\\'''");+ wraps("", "/bin/sh -c ''");+ wraps(";touch ~", "/bin/sh -c ';touch ~'");++ printf("== STEAM_GAME_LAUNCH_SHELL stands in for /bin/sh -c as one argument ==\n");+ shell = "/usr/bin/env";+ wraps("A=1 /g/game.exe", "'/usr/bin/env' 'A=1 /g/game.exe'");+ shell = "/opt/my shell";+ wraps("/g/game.exe", "'/opt/my shell' '/g/game.exe'");+ shell = "";+ wraps("/g/game.exe", "'' '/g/game.exe'");+ shell = NULL;++ printf("== a capped argument count keeps the caller on its own buffer ==\n");+ const char *rest = NULL;+ char *got = np_launch_shell("A=1 /g/game.exe", NULL, 2, NULL);++ if (got) {+ printf("FAIL a capped count must not rewrite, but it became: %s\n", got);+ failures++;+ } else {+ printf(" ok a capped count is left alone\n");+ }+ free(got);++ got = np_launch_shell("A=1 /g/game.exe", NULL, -1, &rest);+ if (got) {+ printf("FAIL a remainder request must not rewrite, but it became: %s\n", got);+ failures++;+ } else {+ printf(" ok a remainder request is left alone\n");+ }+ free(got);++ if (failures) {+ printf("\n%d assertion(s) failed\n", failures);+ return 1;+ }+ printf("\n==> launch-shell: all assertions hold\n");+ return 0;+}