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
Proper icons for Steam game shortcuts
Logand52e64044e78
diff --git a/.github/workflows/app.yml b/.github/workflows/app.ymlindex e4992b2..fa60bdb 100644--- a/.github/workflows/app.yml+++ b/.github/workflows/app.yml@@ -118,6 +118,7 @@ jobs:make -s spawn-envmake -s compatcheckmake -s compatsvc-check+ make -s shortcutcheckmake -s launch-shellmake -s envcheckmake -s buildcheckdiff --git a/Makefile b/Makefileindex dd0eec0..418fae2 100644--- a/Makefile+++ b/Makefile@@ -35,6 +35,7 @@ SRCS := \dylib/hooks/hook_compat.c \dylib/hooks/hook_shortcut.c \dylib/hooks/hook_icon.c \+ dylib/hooks/hook_shortcut_bundle.c \dylib/hooks/hook_webui.c \dylib/hooks/hook_webpatch.c \dylib/hooks/hook_spawn.c \@@ -66,7 +67,7 @@ DEPS := $(OBJS:.o=.d)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 envcheck buildcheck settingscheck routecheck bridgecheck gamedrivecheck launchercheck launch-shell FORCE+ compatsvc-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck gamedrivecheck launchercheck launch-shell FORCEAPP_PAYLOAD := app/Sources/NotProtonApp/Resources/payload@@ -167,6 +168,18 @@ compatsvc-check:$(TEST_CC) -o $(COMPATSVC_CHECK) dylib/tests/compatsvc-check.c && \$(COMPATSVC_CHECK)+SHORTCUT_BUNDLE_CHECK := $(OUT_DIR)/shortcut-bundle-check+SHORTCUTCHECK := $(OUT_DIR)/shortcutcheck++shortcutcheck: $(OUT_DIR)/iconmaker+ @if [ ! -f dylib/tests/shortcutcheck.c ]; then $(call SKIP,shortcutcheck,dylib/tests/shortcutcheck.c); exit 0; fi; \+ mkdir -p $(OUT_DIR) && \+ $(TEST_CC) -o $(SHORTCUT_BUNDLE_CHECK) dylib/tests/shortcut-bundle-check.c && \+ $(SHORTCUT_BUNDLE_CHECK) && \+ $(TEST_CC) -o $(SHORTCUTCHECK) dylib/tests/shortcutcheck.c && \+ $(SHORTCUTCHECK) && \+ python3 dylib/tests/shortcut-launch.py $(OUT_DIR)/iconmaker+sigcheck:@if [ ! -f dylib/tests/sigcheck.py ]; then $(call SKIP,sigcheck,dylib/tests/sigcheck.py); exit 0; fi; \python3 dylib/tests/sigcheck.py@@ -443,13 +456,15 @@ ICONMAKER := $(OUT_DIR)/iconmakericonmaker: $(ICONMAKER)-$(ICONMAKER): helpers/iconmaker.swift dylib/util/peicon.c dylib/util/peicon.h+$(ICONMAKER): helpers/iconmaker.swift helpers/iconmaker.h dylib/util/peicon.c dylib/util/peicon.h helpers/shortcuts.h helpers/shortcuts.c@mkdir -p $(OUT_DIR)$(CC) -c -arch $(ARCH) -mmacosx-version-min=$(MIN_VER) $(AVAIL) -std=c17 -O2 \-Wall -Wextra -o $(OUT_DIR)/peicon-host.o dylib/util/peicon.c+ $(CC) -c -arch $(ARCH) -mmacosx-version-min=$(MIN_VER) $(AVAIL) -std=c17 -O2 \+ -Wall -Wextra -o $(OUT_DIR)/shortcuts-host.o helpers/shortcuts.cswiftc -O -target $(ARCH)-apple-macos$(MIN_VER) \- -framework AppKit -import-objc-header dylib/util/peicon.h \- -o $@ helpers/iconmaker.swift $(OUT_DIR)/peicon-host.o+ -framework AppKit -import-objc-header helpers/iconmaker.h \+ -o $@ helpers/iconmaker.swift $(OUT_DIR)/peicon-host.o $(OUT_DIR)/shortcuts-host.o@echo "==> Built $@"APPINFO := $(OUT_DIR)/appinfodiff --git a/dylib/feats/compat.c b/dylib/feats/compat.cindex 23af056..bfb97b7 100644--- a/dylib/feats/compat.c+++ b/dylib/feats/compat.c@@ -562,28 +562,25 @@ int np_compat_ensure_tool_manifest(void) {return failed ? -1 : 0;}-const char *np_compat_tool_dir(void) {- static char dir[640];- static int resolved = 0;-- if (resolved)- return dir[0] ? dir : NULL;+static char g_tool_dir[640];- resolved = 1;+static void resolve_tool_dir(void) {load_tool_list_once();if (g_tool_count > 0) {- snprintf(dir, sizeof(dir), "%s", g_tools[0].dir);- return dir;+ snprintf(g_tool_dir, sizeof(g_tool_dir), "%s", g_tools[0].dir);+ return;}char tools_dir[512];- if (tools_dir_path(tools_dir, sizeof(tools_dir)) != 0) {- dir[0] = '\0';- return NULL;- }- snprintf(dir, sizeof(dir), "%s/%s", tools_dir, TOOL_DIR_NAME);- return dir;+ if (tools_dir_path(tools_dir, sizeof(tools_dir)) == 0)+ snprintf(g_tool_dir, sizeof(g_tool_dir), "%s/%s", tools_dir, TOOL_DIR_NAME);+}++const char *np_compat_tool_dir(void) {+ static pthread_once_t once = PTHREAD_ONCE_INIT;+ pthread_once(&once, resolve_tool_dir);+ return g_tool_dir[0] ? g_tool_dir : NULL;}int np_compat_runs_tool(const char *cmd) {diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex c72dd4e..0a6149b 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -18,6 +18,125 @@ case "$verb" inesacnp_support="$HOME/Library/Application Support/notproton"+iconmaker="$np_support/iconmaker"++find_client_root() {+ client_root="$1"+ while [ -n "$client_root" ] && [ "$client_root" != "/" ] && [ ! -d "$client_root/appcache" ]; do+ client_root=$(dirname "$client_root")+ done+}++read_app_meta() {+ appinfo_tool="$np_support/appinfo"+ appinfo_vdf="$client_root/appcache/appinfo.vdf"+ meta_name=""+ meta_icon=""+ meta_clienticon=""+ if [ -x "$appinfo_tool" ] && [ -f "$appinfo_vdf" ]; then+ meta=$("$appinfo_tool" "$appinfo_vdf" "$app_id" 2>> "$log") || meta=""+ meta_name=$(printf '%s\n' "$meta" | sed -n 's/^name=//p')+ meta_icon=$(printf '%s\n' "$meta" | sed -n 's/^icon=//p')+ meta_clienticon=$(printf '%s\n' "$meta" | sed -n 's/^clienticon=//p')+ case "$meta_icon" in *[!0-9a-f]*) meta_icon="" ;; esac+ case "$meta_clienticon" in *[!0-9a-f]*) meta_clienticon="" ;; esac+ fi+}++resolve_icon() {+ set +e+ art_dir="$client_root/appcache/librarycache/$app_id"+ art=""+ ico=""+ if [ -n "$meta_clienticon" ]; then+ ico="$icon_root/clienticon-$meta_clienticon.ico"+ absent="$icon_root/clienticon-$meta_clienticon.absent"+ failed="$icon_root/clienticon-$meta_clienticon.failed"+ find "$icon_root" -maxdepth 1 -name 'clienticon-*' ! -name "clienticon-$meta_clienticon.*" -delete 2>/dev/null || true+ find "$absent" -mtime +14 -delete 2>/dev/null || true+ find "$failed" -mmin +60 -delete 2>/dev/null || true+ if [ ! -s "$ico" ] && [ ! -f "$absent" ] && [ ! -f "$failed" ]; then+ url="https://shared.fastly.steamstatic.com/community_assets/images/apps/$app_id/$meta_clienticon.ico"+ code=$(curl -fsL --connect-timeout 5 --max-time 20 -w '%{http_code}' -o "$ico.new" "$url" 2>>"$log")+ magic=$(od -An -tx1 -N4 "$ico.new" 2>/dev/null | tr -d ' \n')+ if [ "$magic" = "00000100" ]; then+ mv -f "$ico.new" "$ico"+ echo "fetched client icon $meta_clienticon" >> "$log" 2>&1 || true+ else+ rm -f "$ico.new"+ if [ "$code" = "404" ]; then+ : > "$absent"+ echo "no client icon published for $meta_clienticon" >> "$log" 2>&1 || true+ else+ : > "$failed"+ echo "client icon fetch for $meta_clienticon failed (http ${code:-none}), will retry in an hour" >> "$log" 2>&1 || true+ fi+ fi+ fi+ [ -s "$ico" ] && art="$ico"+ fi+ if [ -z "$art" ] && [ -n "$meta_icon" ] && [ -f "$art_dir/$meta_icon.jpg" ]; then+ art="$art_dir/$meta_icon.jpg"+ fi+ if [ -z "$art" ]; then+ art=$(find "$art_dir" -maxdepth 1 -type f -name '*.jpg' 2>/dev/null | grep -E '/[0-9a-f]{40}\.jpg$' | head -1)+ fi+ # Capsule art (horrible) fallback if no icon at all exists...+ if [ -z "$art" ]; then+ for name in library_600x900.jpg header.jpg; do+ found=$(find "$art_dir" -name "$name" 2>/dev/null | head -1)+ [ -n "$found" ] && { art="$found"; break; }+ done+ fi+ # non-Steam shortcuts have no art, so (as a temporary measure while I think of+ # better ways to solve for this) let's use the icon in the EXE itself instead.+ if [ -z "$art" ] && [ -f "$target" ]; then+ case "$(printf '%s' "$target" | tr '[:upper:]' '[:lower:]')" in+ *.exe) art="$target" ;;+ esac+ fi+ icon_source=""+ if [ -n "$art" ]; then+ icon_source="$art $(stat -f %m "$art" 2>/dev/null || echo 0)"+ fi+ icon_cache="$icon_root/game.icns"+ icon_status=1+ if [ -n "$art" ] && [ -s "$icon_cache" ] && [ "$(cat "$icon_root/notproton-icon.source" 2>/dev/null)" = "$icon_source" ]; then+ icon_status=0+ echo "icon reused from $art" >> "$log" 2>&1 || true+ elif [ -n "$art" ] && [ -x "$iconmaker" ]; then+ if "$iconmaker" "$art" "$icon_cache" >> "$log" 2>&1; then+ icon_status=0+ printf '%s\n' "$icon_source" > "$icon_root/notproton-icon.source"+ echo "icon built from $art" >> "$log" 2>&1 || true+ elif [ "$art" = "$ico" ]; then+ # A cached .ico that iconmaker rejects is corrupt and passes the size+ # guard on every launch, so drop it to force a clean fetch next time.+ rm -f "$ico"+ echo "discarded unreadable client icon $meta_clienticon" >> "$log" 2>&1 || true+ fi+ fi+ set -e+ return $icon_status+}++case "$verb" in+ shortcut-icons)+ app_id="$1"+ case "$app_id" in ''|0|*[!0-9]*) exit 1 ;; esac+ case "$2" in /*) ;; *) exit 1 ;; esac+ find_client_root "$2"+ icon_root="$np_support/shortcut-icons/$app_id"+ mkdir -p "$icon_root"+ log="$icon_root/icon.log"+ : > "$log"+ target=""+ read_app_meta+ resolve_icon && "$iconmaker" --shortcuts "$app_id" "$icon_cache" "$2/steam.icns" >> "$log" 2>&1 || true+ exit 0+ ;;+esac+# 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"@@ -1161,24 +1280,9 @@ fi# Fixes CrossOver window focus issuessteam_root="$(dirname "$(dirname "$(dirname "$STEAM_COMPAT_DATA_PATH")")")"manifest="$steam_root/steamapps/appmanifest_$app_id.acf"-client_root="$STEAM_COMPAT_CLIENT_INSTALL_PATH"-while [ -n "$client_root" ] && [ "$client_root" != "/" ] && [ ! -d "$client_root/appcache" ]; do- client_root=$(dirname "$client_root")-done+find_client_root "$STEAM_COMPAT_CLIENT_INSTALL_PATH"# Icon stuff-appinfo_tool="$HOME/Library/Application Support/notproton/appinfo"-appinfo_vdf="$client_root/appcache/appinfo.vdf"-meta_name=""-meta_icon=""-meta_clienticon=""-if [ -x "$appinfo_tool" ] && [ -f "$appinfo_vdf" ]; then- meta=$("$appinfo_tool" "$appinfo_vdf" "$app_id" 2>> "$log") || meta=""- meta_name=$(printf '%s\n' "$meta" | sed -n 's/^name=//p')- meta_icon=$(printf '%s\n' "$meta" | sed -n 's/^icon=//p')- meta_clienticon=$(printf '%s\n' "$meta" | sed -n 's/^clienticon=//p')- case "$meta_icon" in *[!0-9a-f]*) meta_icon="" ;; esac- case "$meta_clienticon" in *[!0-9a-f]*) meta_clienticon="" ;; esac-fi+read_app_metagame_name="$meta_name"if [ -z "$game_name" ] && [ -f "$manifest" ]; thengame_name=$(sed -n 's/.*"name"[[:space:]]*"\(.*\)".*/\1/p' "$manifest" | head -1)@@ -1202,82 +1306,10 @@ loader_res="$loader_contents/Resources"mkdir -p "$loader_macos" "$loader_res"icon_arg=""-resolve_icon() {- set +e- iconmaker="$HOME/Library/Application Support/notproton/iconmaker"- art_dir="$client_root/appcache/librarycache/$app_id"- art=""- if [ -n "$meta_clienticon" ]; then- ico="$loader_root/clienticon-$meta_clienticon.ico"- absent="$loader_root/clienticon-$meta_clienticon.absent"- failed="$loader_root/clienticon-$meta_clienticon.failed"- find "$loader_root" -maxdepth 1 -name 'clienticon-*' ! -name "clienticon-$meta_clienticon.*" -delete 2>/dev/null || true- find "$absent" -mtime +14 -delete 2>/dev/null || true- find "$failed" -mmin +60 -delete 2>/dev/null || true- if [ ! -s "$ico" ] && [ ! -f "$absent" ] && [ ! -f "$failed" ]; then- url="https://shared.fastly.steamstatic.com/community_assets/images/apps/$app_id/$meta_clienticon.ico"- code=$(curl -fsL --connect-timeout 5 --max-time 20 -w '%{http_code}' -o "$ico.new" "$url" 2>>"$log")- magic=$(od -An -tx1 -N4 "$ico.new" 2>/dev/null | tr -d ' \n')- if [ "$magic" = "00000100" ]; then- mv -f "$ico.new" "$ico"- echo "fetched client icon $meta_clienticon" >> "$log" 2>&1 || true- else- rm -f "$ico.new"- if [ "$code" = "404" ]; then- : > "$absent"- echo "no client icon published for $meta_clienticon" >> "$log" 2>&1 || true- else- : > "$failed"- echo "client icon fetch for $meta_clienticon failed (http ${code:-none}), will retry in an hour" >> "$log" 2>&1 || true- fi- fi- fi- [ -s "$ico" ] && art="$ico"- fi- if [ -z "$art" ] && [ -n "$meta_icon" ] && [ -f "$art_dir/$meta_icon.jpg" ]; then- art="$art_dir/$meta_icon.jpg"- fi- if [ -z "$art" ]; then- art=$(find "$art_dir" -maxdepth 1 -type f -name '*.jpg' 2>/dev/null | grep -E '/[0-9a-f]{40}\.jpg$' | head -1)- fi- # Capsule art (horrible) fallback if no icon at all exists...- if [ -z "$art" ]; then- for name in library_600x900.jpg header.jpg; do- found=$(find "$art_dir" -name "$name" 2>/dev/null | head -1)- [ -n "$found" ] && { art="$found"; break; }- done- fi- # non-Steam shortcuts have no art, so (as a temporary measure while I think of- # better ways to solve for this) let's use the icon in the EXE itself instead.- if [ -z "$art" ] && [ -f "$target" ]; then- case "$(printf '%s' "$target" | tr '[:upper:]' '[:lower:]')" in- *.exe) art="$target" ;;- esac- fi- icon_source=""- if [ -n "$art" ]; then- icon_source="$art $(stat -f %m "$art" 2>/dev/null || echo 0)"- fi- icon_cache="$loader_root/game.icns"- if [ -n "$art" ] && [ -s "$icon_cache" ] && [ "$(cat "$loader_root/notproton-icon.source" 2>/dev/null)" = "$icon_source" ] && cp -f "$icon_cache" "$loader_res/game.icns"; then- icon_arg=" <key>CFBundleIconFile</key><string>game</string>"- echo "icon reused from $art" >> "$log" 2>&1 || true- elif [ -n "$art" ] && [ -x "$iconmaker" ]; then- if "$iconmaker" "$art" "$icon_cache" >> "$log" 2>&1 && cp -f "$icon_cache" "$loader_res/game.icns"; then- icon_arg=" <key>CFBundleIconFile</key><string>game</string>"- printf '%s\n' "$icon_source" > "$loader_root/notproton-icon.source"- echo "icon built from $art" >> "$log" 2>&1 || true- elif [ "$art" = "$ico" ]; then- # A cached .ico that iconmaker rejects is corrupt and passes the size- # guard on every launch, so drop it to force a clean fetch next time.- rm -f "$ico"- echo "discarded unreadable client icon $meta_clienticon" >> "$log" 2>&1 || true- fi- fi- set -e- return 0-}-resolve_icon || true+icon_root="$loader_root"+if resolve_icon && cp -f "$icon_cache" "$loader_res/game.icns"; then+ icon_arg=" <key>CFBundleIconFile</key><string>game</string>"+fi[ -n "$icon_arg" ] || echo "no icon resolved, launching without one" >> "$log" 2>&1 || trueuielement_arg=""diff --git a/dylib/hooks/hook_shortcut_bundle.c b/dylib/hooks/hook_shortcut_bundle.cnew file mode 100644index 0000000..52ce454--- /dev/null+++ b/dylib/hooks/hook_shortcut_bundle.c@@ -0,0 +1,112 @@+// Give shortcuts nice icons instead of the generic icon Valve sets+#include "hooks.h"+#include "../feats/compat.h"+#include "../util/log.h"++#include <crt_externs.h>+#include <dispatch/dispatch.h>+#include <dlfcn.h>+#include <errno.h>+#include <fcntl.h>+#include <limits.h>+#include <signal.h>+#include <spawn.h>+#include <stdio.h>+#include <string.h>+#include <sys/wait.h>++#define NP_APP_KIND_OFF 0x3c+#define NP_APP_KIND_DLC 0x20++typedef uint64_t (*np_create_fn)(void *app, uint64_t desktop, uint64_t unused);+typedef uint32_t (*np_app_id_fn)(void *app);++static np_create_fn g_create_orig;+static dispatch_queue_t g_queue;+static char g_client[PATH_MAX];++static void update_icons(void *ctx) {+ uint32_t app_id = (uint32_t)(uintptr_t)ctx;+ const char *tool = np_compat_tool_dir();+ if (!tool) return;++ char run[PATH_MAX], id[16];+ snprintf(run, sizeof(run), "%s/run", tool);+ snprintf(id, sizeof(id), "%u", app_id);++ posix_spawn_file_actions_t actions;+ posix_spawnattr_t attr;+ sigset_t none, all;+ sigemptyset(&none);+ sigfillset(&all);+ if (posix_spawn_file_actions_init(&actions) != 0) return;+ if (posix_spawnattr_init(&attr) != 0) {+ posix_spawn_file_actions_destroy(&actions);+ return;+ }+ posix_spawn_file_actions_addopen(&actions, STDIN_FILENO, "/dev/null", O_RDONLY, 0);+ posix_spawn_file_actions_addopen(&actions, STDOUT_FILENO, "/dev/null", O_WRONLY, 0);+ posix_spawn_file_actions_addopen(&actions, STDERR_FILENO, "/dev/null", O_WRONLY, 0);+ posix_spawnattr_setsigmask(&attr, &none);+ posix_spawnattr_setsigdefault(&attr, &all);+ posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_CLOEXEC_DEFAULT);+ char *argv[] = { "/bin/sh", run, "shortcut-icons", id, g_client, NULL };+ pid_t pid;+ int rc = posix_spawn(&pid, argv[0], &actions, &attr, argv, *_NSGetEnviron());+ posix_spawnattr_destroy(&attr);+ posix_spawn_file_actions_destroy(&actions);+ if (rc != 0) {+ NP_WARN("shortcut-bundle: cannot run the icon update for %u (%d)", app_id, rc);+ return;+ }+ int status = 0;+ pid_t done;+ while ((done = waitpid(pid, &status, 0)) < 0 && errno == EINTR) {}+ if (done == pid && WIFEXITED(status))+ NP_LOG("shortcut-bundle: icon update for %u exited %d", app_id, WEXITSTATUS(status));+ else+ NP_WARN("shortcut-bundle: icon update for %u ended without an exit status", app_id);+}++void np_hooks_shortcut_bundle_bind(const struct mach_header_64 *steamui) {+ Dl_info info = {0};+ const char *slash = dladdr(steamui, &info) && info.dli_fname ? strrchr(info.dli_fname, '/') : NULL;+ if (!slash || slash - info.dli_fname >= (ptrdiff_t)sizeof(g_client)) {+ NP_WARN("shortcut-bundle: steamui path unknown, shortcut icons stay stock");+ return;+ }+ snprintf(g_client, sizeof(g_client), "%.*s", (int)(slash - info.dli_fname), info.dli_fname);+ g_queue = dispatch_queue_create("com.notproton.shortcut-bundle", DISPATCH_QUEUE_SERIAL);+}++static uint64_t np_shortcut_create(void *app, uint64_t desktop, uint64_t unused) {+ if (!g_create_orig) return 0;+ uint64_t ret = g_create_orig(app, desktop, unused);+ if (!ret || !app || *(const uint32_t *)((const char *)app + NP_APP_KIND_OFF) == NP_APP_KIND_DLC)+ return ret;++ // Vtable slot 0 returns the app ID. Steam writes run.sh with %d, so an ID past+ // INT32_MAX never matches.+ uint32_t app_id = (**(np_app_id_fn **)app)(app);+ if (!g_queue || !app_id || app_id > INT32_MAX || !np_compat_app_runs_tool(app_id)) return ret;+ dispatch_async_f(g_queue, (void *)(uintptr_t)app_id, update_icons);+ return ret;+}++static np_patch_entry_t g_hooks[] = {+ {+ .label = "shortcut-bundle-icon",+ .signature = "steamui::ShortcutCreate",+ .entry = (void *)np_shortcut_create,+ .trampoline = (void **)&g_create_orig,+ .mode = NP_PATCH_REPLACE,+ },+};++int np_hooks_shortcut_bundle_count(void) {+ return (int)(sizeof(g_hooks) / sizeof(g_hooks[0]));+}++np_patch_entry_t *np_hooks_shortcut_bundle_defs(void) {+ return g_hooks;+}diff --git a/dylib/hooks/hooks.c b/dylib/hooks/hooks.cindex 7762987..cb773d2 100644--- a/dylib/hooks/hooks.c+++ b/dylib/hooks/hooks.c@@ -45,8 +45,9 @@ static const np_hook_group_t np_groups[] = {};static const np_hook_group_t np_steamui_groups[] = {- { "shortcut", np_hooks_shortcut_count, np_hooks_shortcut_defs },- { "icon", np_hooks_icon_count, np_hooks_icon_defs },+ { "shortcut", np_hooks_shortcut_count, np_hooks_shortcut_defs },+ { "icon", np_hooks_icon_count, np_hooks_icon_defs },+ { "bundle", np_hooks_shortcut_bundle_count, np_hooks_shortcut_bundle_defs },};// Installs one entry. Returns 1 when the patch lands, 0 when it is skipped or fails.@@ -103,8 +104,8 @@ static int install_groups(const np_hook_group_t *groups, size_t n_groups,int np_hooks_install_steamui(const struct mach_header_64 *mh, intptr_t slide,np_resolve_result_t *resolved, int *total_out) {- (void)mh;(void)slide;+ np_hooks_shortcut_bundle_bind(mh);int total = 0;int landed = install_groups(np_steamui_groups,diff --git a/dylib/hooks/hooks.h b/dylib/hooks/hooks.hindex 90dd872..ba08132 100644--- a/dylib/hooks/hooks.h+++ b/dylib/hooks/hooks.h@@ -52,6 +52,11 @@ np_patch_entry_t *np_hooks_shortcut_defs(void);int np_hooks_icon_count(void);np_patch_entry_t *np_hooks_icon_defs(void);+int np_hooks_shortcut_bundle_count(void);+np_patch_entry_t *np_hooks_shortcut_bundle_defs(void);++void np_hooks_shortcut_bundle_bind(const struct mach_header_64 *steamui);+int np_hooks_install_all(const struct mach_header_64 *mh, intptr_t slide,np_resolve_result_t *resolved, int *total_out);diff --git a/dylib/tests/launchercheck.sh b/dylib/tests/launchercheck.shindex 1031aff..c81c1a1 100644--- a/dylib/tests/launchercheck.sh+++ b/dylib/tests/launchercheck.sh@@ -217,5 +217,43 @@ for failure in install backup signal signal-installed missing-stage restore; dois "$failure cleans staging" "0" "$(leftover)"done+echo "== launch Dock icon =="+icon_funcs=$(sed -n '/^find_client_root() {$/,/^case "\$verb" in$/p' "$SRC" | sed '$d')+icon_lines=$(sed -n '/^icon_arg=""$/,/^\[ -n "\$icon_arg" \] ||/p' "$SRC")+[ -n "$icon_funcs" ] && [ -n "$icon_lines" ] || { echo "FAIL: launch icon code not found"; exit 1; }+eval "$icon_funcs"+np_support="$T/support"+iconmaker="$np_support/iconmaker"+mkdir -p "$np_support" "$T/steam/appcache/librarycache/100"+printf '#!/bin/sh\nprintf "icon=abc123\\n"\n' > "$np_support/appinfo"+printf '#!/bin/sh\ncp "$1" "$2"\n' > "$iconmaker"+chmod 755 "$np_support/appinfo" "$iconmaker"+: > "$T/steam/appcache/appinfo.vdf"+printf 'game art' > "$T/steam/appcache/librarycache/100/abc123.jpg"+app_id=100+target=""+find_client_root "$T/steam/Steam.AppBundle/Steam/Contents/MacOS"+read_app_meta+loader_root="$T/launchers/100"+loader_res="$loader_root/new/Contents/Resources"+mkdir -p "$loader_res"+: > "$log"+eval "$icon_lines"+is "icon key set" " <key>CFBundleIconFile</key><string>game</string>" "$icon_arg"+is "bundle gets the artwork" "game art" "$(cat "$loader_res/game.icns")"+is "artwork cached with the launcher" "game art" "$(cat "$loader_root/game.icns")"+is "artwork built" "icon built from $T/steam/appcache/librarycache/100/abc123.jpg" "$(cat "$log")"+rm -f "$iconmaker" "$loader_res/game.icns"+: > "$log"+eval "$icon_lines"+is "cached artwork reused" "icon reused from $T/steam/appcache/librarycache/100/abc123.jpg" "$(cat "$log")"+is "reused artwork copied" "game art" "$(cat "$loader_res/game.icns")"+rm "$T/steam/appcache/librarycache/100/abc123.jpg" "$loader_res/game.icns"+: > "$log"+eval "$icon_lines"+is "no artwork, no icon key" "" "$icon_arg"+is "no artwork logged" "no icon resolved, launching without one" "$(cat "$log")"+if [ -d "$np_support/shortcut-icons" ]; then bad "launch leaves shortcut cache alone" "absent" "present"; else ok "launch leaves shortcut cache alone"; fi+[ "$fails" -eq 0 ] || { echo "launchercheck: $fails failed"; exit 1; }echo "launchercheck: all passed"diff --git a/dylib/tests/shortcut-bundle-check.c b/dylib/tests/shortcut-bundle-check.cnew file mode 100644index 0000000..a619386--- /dev/null+++ b/dylib/tests/shortcut-bundle-check.c@@ -0,0 +1,97 @@+#define posix_spawn fake_spawn+#include "../hooks/hook_shortcut_bundle.c"++#include <mach-o/dyld.h>++#include <assert.h>++int np_log_level;+FILE *np_log_file;++static uint32_t updated[16];+static int updated_count;+static uint64_t create_ret;+static int create_calls;++const char *np_compat_tool_dir(void) { return "/nonexistent-tool"; }+int np_compat_app_runs_tool(uint32_t appid) { return appid != 1510; }++int fake_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *actions,+ const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) {+ assert(strcmp(path, "/bin/sh") == 0 && strcmp(argv[1], "/nonexistent-tool/run") == 0);+ const char *image = _dyld_get_image_name(0);+ size_t dir = (size_t)(strrchr(image, '/') - image);+ assert(strcmp(argv[2], "shortcut-icons") == 0 && argv[5] == NULL);+ assert(strlen(argv[4]) == dir && strncmp(argv[4], image, dir) == 0);+ short flags = 0;+ sigset_t mask;+ assert(posix_spawnattr_getflags(attr, &flags) == 0 && posix_spawnattr_getsigmask(attr, &mask) == 0);+ assert(flags == (POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_CLOEXEC_DEFAULT));+ assert(!sigismember(&mask, SIGTERM) && !sigismember(&mask, SIGCHLD));+ if (updated_count < 16) updated[updated_count] = (uint32_t)strtoul(argv[3], NULL, 10);+ updated_count++;+ return ENOENT;+}++static uint64_t fake_create(void *app, uint64_t desktop, uint64_t unused) {+ create_calls++;+ return create_ret;+}++typedef struct {+ np_app_id_fn *vtable;+ uint8_t pad[NP_APP_KIND_OFF - sizeof(void *)];+ uint32_t kind;+ uint32_t id;+} fake_app_t;++static uint32_t fake_id(void *app) { return ((fake_app_t *)app)->id; }+static np_app_id_fn fake_vtable[] = { fake_id };++static uint64_t create(uint32_t id, uint32_t kind, int desktop) {+ fake_app_t app = { .vtable = fake_vtable, .kind = kind, .id = id };+ return np_shortcut_create(&app, (uint64_t)desktop, 0);+}++static void read_count(void *out) {+ *(int *)out = updated_count;+}++static int count(void) {+ int n = 0;+ if (g_queue) dispatch_sync_f(g_queue, &n, read_count);+ return n;+}++int main(void) {+ assert(np_hooks_shortcut_bundle_count() == 1);+ assert(strcmp(np_hooks_shortcut_bundle_defs()[0].signature, "steamui::ShortcutCreate") == 0);+ *(void **)np_hooks_shortcut_bundle_defs()[0].trampoline = (void *)fake_create;++ create_ret = 1;+ np_hooks_shortcut_bundle_bind(NULL);+ assert(create(440, 1, 1) == 1 && !g_queue);++ np_hooks_shortcut_bundle_bind((const struct mach_header_64 *)_dyld_get_image_header(0));+ assert(g_queue);+ create_ret = 0;+ assert(create(440, 1, 1) == 0);+ create_ret = 1;+ assert(create(440, NP_APP_KIND_DLC, 1) == 1);+ assert(create(0, 1, 1) == 1);+ assert(create(1510, 1, 1) == 1);+ assert(create(0x80000000u, 1, 1) == 1);+ assert(count() == 0);++ assert(create(440, 1, 1) == 1);+ assert(create(570, 1, 0) == 1);+ assert(count() == 2);+ assert(updated[0] == 440 && updated[1] == 570);++ assert(create(440, 1, 1) == 1);+ assert(count() == 3);+ assert(updated[2] == 440 && create_calls == 9);++ printf("shortcut-bundle-check: DLC, native, zero-ID, negative-ID, unbuilt and unbound shortcuts skipped, each create updated in order\n");+ return 0;+}diff --git a/dylib/tests/shortcut-launch.py b/dylib/tests/shortcut-launch.pynew file mode 100644index 0000000..0e64549--- /dev/null+++ b/dylib/tests/shortcut-launch.py@@ -0,0 +1,51 @@+import os+from pathlib import Path+import shutil+import subprocess+import sys+import tempfile+++with tempfile.TemporaryDirectory(prefix="np-shortcut-icons-") as temporary:+ root = Path(temporary)+ run = root / "Applications/Game.app/Contents/MacOS/run.sh"+ run.parent.mkdir(parents=True)+ run.write_text('#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/100\n\n')+ icon = root / "Applications/Game.app/Contents/Resources/shortcut.icns"+ icon.parent.mkdir()+ icon.write_bytes(b"old icon")+ shutil.copytree(root / "Applications", root / "Desktop")+ desktop_icon = root / "Desktop/Game.app/Contents/Resources/shortcut.icns"+ desktop_icon.write_bytes(b"user icon")++ support = root / "Library/Application Support/notproton"+ support.mkdir(parents=True)+ (support / "appinfo").write_text("#!/bin/sh\nprintf 'name=Game\\nicon=abc123\\n'\n")+ (support / "iconmaker").write_text(+ '#!/bin/sh\nif [ "$1" = --shortcuts ]; then exec "$REAL_ICONMAKER" "$@"; fi\ncp "$1" "$2"\n')+ for helper in ("appinfo", "iconmaker"):+ (support / helper).chmod(0o755)+ steam = root / "Steam"+ client = steam / "Steam.AppBundle/Steam/Contents/MacOS"+ client.mkdir(parents=True)+ (steam / "appcache").mkdir()+ (steam / "appcache/appinfo.vdf").write_bytes(b"vdf")+ art = steam / "appcache/librarycache/100/abc123.jpg"+ art.parent.mkdir(parents=True)+ art.write_bytes(b"game art")+ stock = client / "steam.icns"+ stock.write_bytes(b"old icon")+ env = dict(os.environ, HOME=str(root), REAL_ICONMAKER=str(Path(sys.argv[1]).resolve()))+ for app_id in ("", "0", "01x", "1;2"):+ assert subprocess.run(["/bin/sh", "dylib/feats/compat_run.sh", "shortcut-icons", app_id, str(client)],+ env=env, timeout=5).returncode == 1+ assert subprocess.run(["/bin/sh", "dylib/feats/compat_run.sh", "shortcut-icons", "100", "relative/MacOS"],+ env=env, timeout=5).returncode == 1+ subprocess.run(["/bin/sh", "dylib/feats/compat_run.sh", "shortcut-icons", "100", str(client)],+ env=env, check=True, timeout=10)+ assert icon.read_bytes() == b"game art"+ assert desktop_icon.read_bytes() == b"user icon"+ assert (support / "shortcut-icons/100/game.icns").read_bytes() == b"game art"+ assert not (support / "launchers").exists()++print("shortcut-launch: Steam-made shortcuts get artwork, custom icons and bad arguments are left alone")diff --git a/dylib/tests/shortcutcheck.c b/dylib/tests/shortcutcheck.cnew file mode 100644index 0000000..4da2474--- /dev/null+++ b/dylib/tests/shortcutcheck.c@@ -0,0 +1,384 @@+#include "../../helpers/shortcuts.c"++#include <ftw.h>+#include <limits.h>+#include <signal.h>+#include <stdarg.h>++typedef struct { char s[PATH_MAX]; } path_t;++static unsigned checks;+static char sandbox[PATH_MAX];+static const char header[] = "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/";++static void check(int condition, const char *name) {+ checks++;+ if (!condition) {+ fprintf(stderr, "shortcutcheck: failed: %s\nfixtures: %s\n", name, sandbox);+ exit(1);+ }+}++static path_t P(const char *format, ...) {+ path_t p;+ va_list args;+ va_start(args, format);+ int n = vsnprintf(p.s, sizeof(p.s), format, args);+ va_end(args);+ if (n < 0 || n >= (int)sizeof(p.s)) abort();+ return p;+}++static void mkdirs(const char *path) {+ path_t p = P("%s", path);+ for (char *c = p.s + 1; *c; c++) {+ if (*c != '/') continue;+ *c = 0;+ check(mkdir(p.s, 0755) == 0 || errno == EEXIST, "mkdir parent");+ *c = '/';+ }+ check(mkdir(p.s, 0755) == 0 || errno == EEXIST, "mkdir");+}++static void put_n(const char *path, const void *data, size_t length) {+ path_t parent = P("%s", path);+ *strrchr(parent.s, '/') = 0;+ mkdirs(parent.s);+ int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);+ check(fd >= 0 && write(fd, data, length) == (ssize_t)length && close(fd) == 0, path);+}++static void put(const char *path, const char *text) {+ put_n(path, text, strlen(text));+}++static int is(const char *path, const char *text) {+ char buffer[256];+ int fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);+ if (fd < 0) return 0;+ ssize_t n = read(fd, buffer, sizeof(buffer));+ close(fd);+ return n == (ssize_t)strlen(text) && memcmp(buffer, text, (size_t)n) == 0;+}++static int exists(const char *path) {+ struct stat st;+ return lstat(path, &st) == 0;+}++static int remove_entry(const char *path, const struct stat *st, int flag, struct FTW *ftw) {+ return remove(path);+}++static void remove_item(const char *path) {+ struct stat st;+ check(lstat(path, &st) == 0 && (S_ISDIR(st.st_mode) ? nftw(path, remove_entry, 16, FTW_DEPTH | FTW_PHYS)+ : unlink(path)) == 0, path);+}++static path_t fixture(const char *name) {+ path_t home = P("%s/%s", sandbox, name);+ mkdirs(P("%s/Applications", home.s).s);+ put(P("%s/steam.icns", home.s).s, "old icon");+ return home;+}++static void update(const char *home, const char *source) {+ np_shortcuts_icons(home, "440", source, P("%s/steam.icns", home).s);+}++static void put_script(const char *path, const char *appid) {+ put(path, P("%s%s\n\n", header, appid).s);+}++static path_t bundle_in(const char *home, const char *folder, const char *name, const char *appid) {+ path_t app = P("%s/%s/%s.app", home, folder, name);+ put_script(P("%s/Contents/MacOS/run.sh", app.s).s, appid);+ put(P("%s/Contents/Resources/shortcut.icns", app.s).s, "old icon");+ return app;+}++static path_t bundle(const char *home, const char *name, const char *appid) {+ return bundle_in(home, "Applications", name, appid);+}++static path_t icon_of(const char *app) {+ return P("%s/Contents/Resources/shortcut.icns", app);+}++static int read_ok(const char *path, size_t limit, const char *text) {+ blob_t data;+ int ok = read_at(AT_FDCWD, path, limit, &data);+ ok = ok && (!text || (data.length == strlen(text) && memcmp(data.bytes, text, data.length) == 0));+ free(data.bytes);+ return ok;+}++static void script_checks(void) {+ path_t home = fixture("scripts");+ path_t app = bundle(home.s, "Candidate", "440");+ path_t run = P("%s/Contents/MacOS/run.sh", app.s);+ path_t icon = icon_of(app.s);+ path_t source = P("%s/new.icns", home.s);+ put(source.s, "new icon");+ int fd = open(app.s, O_RDONLY | O_DIRECTORY | O_CLOEXEC);+ check(fd >= 0, "open script fixture");+ for (int i = 0; i < 3; i++) {+ const char *appid = (const char *[]){"1", "440", "2147483647"}[i];+ put_script(run.s, appid);+ check(is_shortcut(fd, appid), "Steam's script accepted");+ }+ put_script(run.s, "440");+ check(!is_shortcut(fd, "44") && !is_shortcut(fd, "4400") && !is_shortcut(fd, "0440"), "script for another ID rejected");++ static char oversized[4097];+ memset(oversized, '\n', sizeof(oversized));+ memcpy(oversized, header, strlen(header));+ const struct { const char *text; size_t length; } invalid[] = {+ { "", 0 },+ { header, strlen(header) },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/440", 0 },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/440\n", 0 },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/440\r\n", 0 },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/440\n\n\n", 0 },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nexport CUSTOM_LAUNCH=1\nopen steam://run/440\n\n", 0 },+ { "echo edited\n#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/440\n\n", 0 },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/440\n\necho edited\n", 0 },+ { "#!/bin/bash\n# edited file - do not edit\n\nopen steam://run/440\n\n", 0 },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/440\n\n\0", 71 },+ { "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/4\0000\n\n", 70 },+ { oversized, sizeof(oversized) },+ };+ for (size_t i = 0; i < sizeof(invalid) / sizeof(*invalid); i++) {+ put_n(run.s, invalid[i].text, invalid[i].length ? invalid[i].length : strlen(invalid[i].text));+ check(!is_shortcut(fd, "440"), "reject edited, truncated, NUL or oversized script");+ update(home.s, source.s);+ check(is(icon.s, "old icon"), "invalid script icon unchanged");+ }++ remove_item(run.s);+ check(mkfifo(run.s, 0600) == 0, "create script FIFO");+ check(!is_shortcut(fd, "440"), "FIFO script rejected without waiting for writer");+ update(home.s, source.s);+ check(is(icon.s, "old icon"), "FIFO script icon unchanged");+ close(fd);++ path_t input = P("%s/read-input", home.s);+ put(input.s, "abcd");+ check(read_ok(input.s, 4, "abcd"), "read_at exact bound");+ check(!read_ok(input.s, 3, NULL), "read_at oversized");+ put(input.s, "");+ check(!read_ok(input.s, 4, NULL), "read_at empty");+ check(!read_ok(home.s, 4096, NULL), "read_at directory");+ check(!read_ok(run.s, 4096, NULL), "read_at FIFO");+ remove_item(input.s);+ check(symlink(source.s, input.s) == 0, "create input symlink");+ check(!read_ok(input.s, 4096, NULL), "read_at symlink");+}++static void desktop_checks(void) {+ path_t home = fixture("desktop-icons");+ path_t app = bundle(home.s, "Target", "440");+ path_t desktop = bundle_in(home.s, "Desktop", "Target", "440");+ path_t other = bundle_in(home.s, "Desktop", "OtherGame", "570");+ path_t custom = bundle_in(home.s, "Desktop", "Customized", "440");+ path_t custom_run = P("%s/Contents/MacOS/run.sh", custom.s);+ path_t custom_script = P("%s440\n\necho customized\n", header);+ put(custom_run.s, custom_script.s);+ path_t fifo = bundle_in(home.s, "Desktop", "FIFO", "440");+ path_t run = P("%s/Contents/MacOS/run.sh", fifo.s);+ remove_item(run.s);+ check(mkfifo(run.s, 0600) == 0, "create Desktop script FIFO");+ path_t source = P("%s/source.icns", home.s);+ put(source.s, "new icon");+ update(home.s, source.s);+ check(is(icon_of(app.s).s, "new icon") && is(icon_of(desktop.s).s, "new icon"),+ "same-ID Applications and Desktop icons both updated");+ check(is(icon_of(other.s).s, "old icon") && is(icon_of(custom.s).s, "old icon") && is(icon_of(fifo.s).s, "old icon"),+ "unrelated, customized and FIFO Desktop icons unchanged");+ check(is(custom_run.s, custom_script.s), "customized Desktop script unchanged");++ for (int i = 0; i < 2; i++) {+ const char *folder = i ? "Desktop" : "Applications";+ const char *missing = i ? "Applications" : "Desktop";+ home = fixture(P("icons-only-%s", folder).s);+ app = bundle_in(home.s, folder, "Target", "440");+ if (i) remove_item(P("%s/Applications", home.s).s);+ check(!exists(P("%s/%s", home.s, missing).s), "other shortcut folder is missing");+ source = P("%s/source.icns", home.s);+ put(source.s, "new icon");+ update(home.s, source.s);+ check(is(icon_of(app.s).s, "new icon"), "missing sibling folder still updates the other");+ check(!exists(P("%s/%s", home.s, missing).s), "icon update does not create missing shortcut folder");+ }+}++static void symlink_checks(const char *folder) {+ const char *parts[] = {"", "Contents", "Contents/MacOS", "Contents/MacOS/run.sh",+ "Contents/Resources", "Contents/Resources/shortcut.icns"};+ for (size_t i = 0; i < sizeof(parts) / sizeof(*parts); i++) {+ path_t home = fixture(P("symlink-%s-%zu", folder, i).s);+ path_t app = bundle_in(home.s, folder, "Candidate", "440");+ path_t link_path = *parts[i] ? P("%s/%s", app.s, parts[i]) : app;+ path_t target = P("%s/outside-target", home.s);+ check(rename(link_path.s, target.s) == 0, "move symlink target outside shortcut folder");+ check(symlink(target.s, link_path.s) == 0, "create bundle component symlink");+ path_t source = P("%s/new.icns", home.s);+ put(source.s, "new icon");+ update(home.s, source.s);+ check(is(icon_of(app.s).s, "old icon"), P("icon update skips symlink: %s", parts[i]).s);+ check(exists(target.s), "symlink target retained");+ struct stat st;+ check(lstat(link_path.s, &st) == 0 && S_ISLNK(st.st_mode), "symlink itself unchanged");+ }+}++static int same_mtime(const struct stat *a, const struct stat *b) {+ return same_time(a->st_mtimespec, b->st_mtimespec);+}++static void icon_checks(void) {+ path_t home = fixture("icons");+ path_t app = bundle(home.s, "Target", "440");+ path_t other = bundle(home.s, "OtherGame", "570");+ path_t icon = icon_of(app.s);+ path_t source = P("%s/source.icns", home.s);+ path_t original = P("%s/hardlinked-original.icns", home.s);+ put(source.s, "new icon");+ check(link(icon.s, original.s) == 0, "hardlink original icon");+ int held = open(icon.s, O_RDONLY | O_CLOEXEC);+ check(held >= 0, "hold old icon inode");+ update(home.s, source.s);+ check(is(icon.s, "new icon"), "target icon updated");+ check(is(original.s, "old icon"), "hardlinked original not overwritten");+ struct stat before, after;+ check(fstat(held, &before) == 0 && stat(icon.s, &after) == 0 && before.st_ino != after.st_ino,+ "icon replacement uses new inode");+ char old[8];+ check(read(held, old, sizeof(old)) == sizeof(old) && memcmp(old, "old icon", sizeof(old)) == 0,+ "open reader retains complete old icon");+ close(held);+ check(is(icon_of(other.s).s, "old icon"), "other game ID isolated");++ struct timespec stamp[2] = {{1000000000, 123456000}, {1000000000, 123456000}};+ check(utimensat(AT_FDCWD, icon.s, stamp, 0) == 0 && utimensat(AT_FDCWD, app.s, stamp, 0) == 0,+ "set deterministic mtimes");+ struct stat app_before, app_after;+ check(stat(icon.s, &before) == 0 && stat(app.s, &app_before) == 0, "stat before same icon");+ update(home.s, source.s);+ check(stat(icon.s, &after) == 0 && before.st_ino == after.st_ino && same_mtime(&before, &after),+ "replaced icon is left alone on a second run");+ check(stat(app.s, &app_after) == 0 && same_mtime(&app_before, &app_after), "second run preserves bundle mtime");++ path_t resources = P("%s/Contents/Resources", app.s);+ put(icon.s, "old icon");+ put(source.s, "replacement");+ check(chmod(resources.s, 0500) == 0, "lock Resources directory");+ int writable = access(resources.s, W_OK) == 0;+ update(home.s, source.s);+ check(chmod(resources.s, 0700) == 0, "unlock Resources directory");+ if (!writable) check(is(icon.s, "old icon"), "locked directory leaves old icon intact");+ else fprintf(stderr, "shortcutcheck: locked-directory check skipped: permissions bypassed\n");+ check(exists(P("%s/Contents/MacOS/run.sh", app.s).s), "optional icon failure preserves launcher");+ DIR *dir = opendir(resources.s);+ int entries = 0;+ for (struct dirent *e; dir && (e = readdir(dir));)+ if (e->d_name[0] != '.' || strncmp(e->d_name, ".notproton-icon-", 16) == 0) entries++;+ if (dir) closedir(dir);+ check(entries == 1, "no temporary icon files left behind");+ update(home.s, source.s);+ check(is(icon.s, "replacement"), "unlocked directory gets the icon");+ remove_item(icon.s);+ update(home.s, source.s);+ check(!exists(icon.s), "missing icon is not created");+ remove_item(resources.s);+ update(home.s, source.s);+ check(!exists(resources.s) && exists(P("%s/Contents/MacOS/run.sh", app.s).s),+ "missing optional Resources leaves launcher intact");++ put(icon.s, "old icon");+ const char *kinds[] = {"missing", "empty", "directory", "fifo", "symlink", "oversized", "unreadable"};+ for (size_t i = 0; i < sizeof(kinds) / sizeof(*kinds); i++) {+ const char *kind = kinds[i];+ path_t bad = P("%s/%s", home.s, kind);+ if (!strcmp(kind, "empty")) put(bad.s, "");+ if (!strcmp(kind, "directory")) mkdirs(bad.s);+ if (!strcmp(kind, "fifo")) check(mkfifo(bad.s, 0600) == 0, "create source FIFO");+ if (!strcmp(kind, "symlink")) check(symlink(source.s, bad.s) == 0, "create source symlink");+ if (!strcmp(kind, "oversized")) {+ int fd = open(bad.s, O_WRONLY | O_CREAT | O_EXCL, 0600);+ check(fd >= 0 && ftruncate(fd, ICON_LIMIT + 1) == 0, "create oversized sparse icon source");+ close(fd);+ }+ if (!strcmp(kind, "unreadable")) {+ put(bad.s, "unreadable source");+ check(chmod(bad.s, 0000) == 0, "make source unreadable");+ if (access(bad.s, R_OK) == 0) {+ check(chmod(bad.s, 0600) == 0, "restore bypassed source permissions");+ fprintf(stderr, "shortcutcheck: unreadable-source check skipped: permissions bypassed\n");+ continue;+ }+ }+ update(home.s, bad.s);+ if (!strcmp(kind, "unreadable")) check(chmod(bad.s, 0600) == 0, "restore source permissions");+ check(is(icon.s, "old icon"), P("source error leaves icon unchanged: %s", kind).s);+ }++ home = fixture("finder-locked");+ app = bundle(home.s, "Locked", "440");+ source = P("%s/source.icns", home.s);+ put(source.s, "new icon");+ check(chflags(app.s, UF_IMMUTABLE) == 0, "Finder-lock bundle");+ update(home.s, source.s);+ check(chflags(app.s, 0) == 0, "unlock bundle after optional timestamp failure");+ check(is(icon_of(app.s).s, "new icon"), "Finder-locked bundle permits icon replacement without a timestamp update");+}++static void stock_checks(void) {+ path_t home = fixture("stock");+ path_t stock = P("%s/steam.icns", home.s);+ path_t source = P("%s/game.icns", home.s);+ put(source.s, "game art");+ path_t apps = bundle(home.s, "Game", "440");+ path_t desk = bundle_in(home.s, "Desktop", "Game", "440");+ path_t custom = bundle_in(home.s, "Desktop", "Custom", "440");+ path_t icon = icon_of(apps.s);+ put(icon_of(custom.s).s, "user icon");++ path_t linked = P("%s/linked-steam.icns", home.s);+ check(symlink(stock.s, linked.s) == 0, "create stock symlink");+ path_t missing = P("%s/missing", home.s);+ const char *bad[] = {missing.s, linked.s};+ for (int i = 0; i < 2; i++) {+ np_shortcuts_icons(home.s, "440", source.s, bad[i]);+ check(is(icon.s, "old icon"), "unusable stock file changes nothing");+ }+ np_shortcuts_icons(home.s, "440", stock.s, stock.s);+ check(is(icon.s, "old icon"), "stock artwork is not written over stock");++ update(home.s, source.s);+ check(is(icon.s, "game art"), "stock Applications icon replaced");+ check(is(icon_of(desk.s).s, "game art"), "stock Desktop icon replaced");+ check(is(icon_of(custom.s).s, "user icon"), "custom icon kept");+ put(source.s, "newer art");+ update(home.s, source.s);+ check(is(icon.s, "game art"), "replaced icon is not replaced again");+}++int main(void) {+ signal(SIGALRM, SIG_DFL);+ alarm(60);+ const char *tmp = getenv("TMPDIR");+ snprintf(sandbox, sizeof(sandbox), "%s/shortcutcheck.XXXXXX", tmp && *tmp ? tmp : "/tmp");+ check(mkdtemp(sandbox) != NULL, "create disposable sandbox");+ script_checks();+ desktop_checks();+ symlink_checks("Applications");+ symlink_checks("Desktop");+ icon_checks();+ stock_checks();+ remove_item(sandbox);+ alarm(0);+ printf("shortcutcheck: %u checks passed\n", checks);+ return 0;+}diff --git a/helpers/iconmaker.h b/helpers/iconmaker.hnew file mode 100644index 0000000..954d3a9--- /dev/null+++ b/helpers/iconmaker.h@@ -0,0 +1,4 @@+#pragma once++#include "../dylib/util/peicon.h"+#include "shortcuts.h"diff --git a/helpers/iconmaker.swift b/helpers/iconmaker.swiftindex 061f9e8..cec00ee 100644--- a/helpers/iconmaker.swift+++ b/helpers/iconmaker.swift@@ -2,10 +2,16 @@// rect (squircle) that native app icons use. Input is scaled to fill 1024x1024// and clipped. Output covers 16x16 through 512x512@2x.// Usage: iconmaker <input-image|input.exe> <output.icns>+// iconmaker --shortcuts <appid> <icon.icns> <stock.icns>import AppKitimport Foundation+if CommandLine.arguments.count == 5, CommandLine.arguments[1] == "--shortcuts" {+ np_shortcuts_icons(getenv("HOME"), CommandLine.arguments[2], CommandLine.arguments[3], CommandLine.arguments[4])+ exit(0)+}+guard CommandLine.arguments.count == 3 else {fputs("usage: iconmaker <input-image|input.exe> <output.icns>\n", stderr)exit(1)diff --git a/helpers/shortcuts.c b/helpers/shortcuts.cnew file mode 100644index 0000000..fe0a74d--- /dev/null+++ b/helpers/shortcuts.c@@ -0,0 +1,141 @@+#include "shortcuts.h"++#include <dirent.h>+#include <errno.h>+#include <fcntl.h>+#include <stdint.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/stat.h>+#include <unistd.h>++#define ICON_LIMIT (16 * 1024 * 1024)++typedef struct {+ unsigned char *bytes;+ size_t length;+} blob_t;++static int directory_at(int parent, const char *path) {+ return openat(parent, path, O_RDONLY | O_DIRECTORY | O_NOFOLLOW_ANY | O_CLOEXEC);+}++static int same_time(struct timespec a, struct timespec b) {+ return a.tv_sec == b.tv_sec && a.tv_nsec == b.tv_nsec;+}++static int read_at(int parent, const char *name, size_t limit, blob_t *out) {+ *out = (blob_t){0};+ int fd = openat(parent, name, O_RDONLY | O_NONBLOCK | O_NOFOLLOW | O_CLOEXEC);+ if (fd < 0) return 0;+ struct stat before, after;+ int ok = fstat(fd, &before) == 0 && S_ISREG(before.st_mode) && before.st_size > 0 &&+ (uint64_t)before.st_size <= limit && (out->bytes = malloc((size_t)before.st_size));+ size_t done = 0;+ while (ok && done < (size_t)before.st_size) {+ ssize_t n = read(fd, out->bytes + done, (size_t)before.st_size - done);+ if (n < 0 && errno == EINTR) continue;+ if (n <= 0) ok = 0;+ else done += (size_t)n;+ }+ ok = ok && fstat(fd, &after) == 0 && before.st_size == after.st_size &&+ same_time(before.st_mtimespec, after.st_mtimespec) &&+ same_time(before.st_ctimespec, after.st_ctimespec);+ close(fd);+ if (ok) {+ out->length = done;+ } else {+ free(out->bytes);+ out->bytes = NULL;+ }+ return ok;+}++static int same_blob(const blob_t *a, const blob_t *b) {+ return a->length == b->length && memcmp(a->bytes, b->bytes, a->length) == 0;+}++// Accepts only the run.sh Steam writes for this app, unedited.+static int is_shortcut(int app, const char *app_id) {+ char want[128];+ int n = snprintf(want, sizeof(want),+ "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/%s\n\n", app_id);+ int macos = directory_at(app, "Contents/MacOS");+ if (macos < 0) return 0;+ blob_t data;+ int ok = n < (int)sizeof(want) && read_at(macos, "run.sh", sizeof(want), &data);+ close(macos);+ if (!ok) return 0;+ ok = data.length == (size_t)n && memcmp(data.bytes, want, data.length) == 0;+ free(data.bytes);+ return ok;+}++static int same_entry(int parent, const char *name, int fd) {+ struct stat path, opened;+ return fstatat(parent, name, &path, AT_SYMLINK_NOFOLLOW) == 0 && fstat(fd, &opened) == 0 &&+ path.st_dev == opened.st_dev && path.st_ino == opened.st_ino;+}++static void replace_icon(int parent, const char *name, int app, int resources, const blob_t *icon) {+ char temp[64];+ snprintf(temp, sizeof(temp), ".notproton-icon-%d-%08x", (int)getpid(), arc4random());+ int fd = openat(resources, temp, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0644);+ if (fd < 0) return;+ size_t done = 0;+ while (done < icon->length) {+ ssize_t n = write(fd, icon->bytes + done, icon->length - done);+ if (n < 0 && errno == EINTR) continue;+ if (n <= 0) break;+ done += (size_t)n;+ }+ int error = close(fd);+ // Finder keeps showing a bundle's cached icon until the bundle's mtime changes.+ if (done == icon->length && error == 0 && same_entry(parent, name, app) &&+ renameat(resources, temp, resources, "shortcut.icns") == 0)+ futimens(app, NULL);+ unlinkat(resources, temp, 0);+}++static void update_folder(int home, const char *folder, const char *app_id,+ const blob_t *icon, const blob_t *stock) {+ int parent = directory_at(home, folder);+ if (parent < 0) return;+ DIR *dir = fdopendir(parent);+ if (!dir) {+ close(parent);+ return;+ }+ struct dirent *entry;+ while ((entry = readdir(dir))) {+ size_t len = strlen(entry->d_name);+ if (len <= 4 || strcmp(entry->d_name + len - 4, ".app") != 0) continue;+ int app = directory_at(parent, entry->d_name);+ if (app < 0) continue;+ int resources = is_shortcut(app, app_id) ? directory_at(app, "Contents/Resources") : -1;+ blob_t current;+ if (resources >= 0 && read_at(resources, "shortcut.icns", ICON_LIMIT, ¤t)) {+ if (same_blob(¤t, stock)) replace_icon(parent, entry->d_name, app, resources, icon);+ free(current.bytes);+ }+ if (resources >= 0) close(resources);+ close(app);+ }+ closedir(dir);+}++void np_shortcuts_icons(const char *home, const char *app_id, const char *icon_path, const char *stock_path) {+ if (!home || home[0] != '/' || !app_id || !icon_path || !stock_path) return;+ blob_t icon, stock;+ read_at(AT_FDCWD, icon_path, ICON_LIMIT, &icon);+ read_at(AT_FDCWD, stock_path, ICON_LIMIT, &stock);+ int dir = open(home, O_RDONLY | O_DIRECTORY | O_CLOEXEC);+ if (dir >= 0 && icon.bytes && stock.bytes && !same_blob(&icon, &stock)) {+ update_folder(dir, "Applications", app_id, &icon, &stock);+ update_folder(dir, "Desktop", app_id, &icon, &stock);+ }+ if (dir >= 0) close(dir);+ free(icon.bytes);+ free(stock.bytes);+}diff --git a/helpers/shortcuts.h b/helpers/shortcuts.hnew file mode 100644index 0000000..668a01d--- /dev/null+++ b/helpers/shortcuts.h@@ -0,0 +1,7 @@+#ifndef NP_SHORTCUTS_H+#define NP_SHORTCUTS_H++// Replaces shortcut.icns in the app's Steam shortcuts that still hold a copy of stock_path.+void np_shortcuts_icons(const char *home, const char *app_id, const char *icon_path, const char *stock_path);++#endifdiff --git a/signatures/macos.arm64/1788400362.json b/signatures/macos.arm64/1788400362.jsonindex f1cf09d..0e5507e 100644--- a/signatures/macos.arm64/1788400362.json+++ b/signatures/macos.arm64/1788400362.json@@ -205,6 +205,15 @@"@drawInRect:fromRect:operation:fraction:"]}+ },+ {+ "name": "steamui::ShortcutCreate",+ "module": "steamui.dylib",+ "aob_hex": "FF 83 07 D1 F8 5F 1A A9 F6 57 1B A9 F4 4F 1C A9 FD 7B 1D A9 FD 43 07 91 08 3C 40 B9 1F 81 00 71",+ "anchor": {+ "kind": "string",+ "value": "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/%d\n\n"+ }}]}diff --git a/signatures/macos.arm64/1789086785.json b/signatures/macos.arm64/1789086785.jsonindex 3534b0c..1f3e16d 100644--- a/signatures/macos.arm64/1789086785.json+++ b/signatures/macos.arm64/1789086785.json@@ -200,6 +200,15 @@"@drawInRect:fromRect:operation:fraction:"]}+ },+ {+ "name": "steamui::ShortcutCreate",+ "module": "steamui.dylib",+ "aob_hex": "FF 83 07 D1 F8 5F 1A A9 F6 57 1B A9 F4 4F 1C A9 FD 7B 1D A9 FD 43 07 91 08 3C 40 B9 1F 81 00 71",+ "anchor": {+ "kind": "string",+ "value": "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/%d\n\n"+ }}]}diff --git a/signatures/macos.arm64/1790904859.json b/signatures/macos.arm64/1790904859.jsonindex 1592df7..2af2d7b 100644--- a/signatures/macos.arm64/1790904859.json+++ b/signatures/macos.arm64/1790904859.json@@ -201,6 +201,15 @@]},"func_addr_this_build": "0xa55fc"+ },+ {+ "name": "steamui::ShortcutCreate",+ "module": "steamui.dylib",+ "aob_hex": "FF 83 07 D1 F8 5F 1A A9 F6 57 1B A9 F4 4F 1C A9 FD 7B 1D A9 FD 43 07 91 08 3C 40 B9 1F 81 00 71",+ "anchor": {+ "kind": "string",+ "value": "#!/bin/bash\n# autogenerated file - do not edit\n\nopen steam://run/%d\n\n"+ }}]}