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
Support Windows applications as non-Steam shortcuts
NotProtonNot0189651eb6b4
diff --git a/Makefile b/Makefileindex eee4b76..99ec16b 100644--- a/Makefile+++ b/Makefile@@ -23,12 +23,16 @@ SRCS := \dylib/core/loader.c \dylib/core/macho.c \dylib/resolver/anchor.c \+ dylib/resolver/aob.c \dylib/resolver/resolver.c \dylib/resolver/sigdb.c \dylib/util/log.c \dylib/util/file.c \+ dylib/util/peicon.c \dylib/hooks/hooks.c \dylib/hooks/hook_compat.c \+ dylib/hooks/hook_shortcut.c \+ dylib/hooks/hook_icon.c \dylib/hooks/hook_webui.c \dylib/hooks/hook_webpatch.c \dylib/hooks/hook_spawn.c \@@ -348,9 +352,11 @@ ICONMAKER := $(OUT_DIR)/iconmakericonmaker: $(ICONMAKER)-$(ICONMAKER): helpers/iconmaker.swift+$(ICONMAKER): helpers/iconmaker.swift dylib/util/peicon.c dylib/util/peicon.h@mkdir -p $(OUT_DIR)- swiftc -O -framework AppKit -o $@ $<+ $(CC) -c -O2 -Wall -Wextra -o $(OUT_DIR)/peicon-host.o dylib/util/peicon.c+ swiftc -O -framework AppKit -import-objc-header dylib/util/peicon.h \+ -o $@ helpers/iconmaker.swift $(OUT_DIR)/peicon-host.o@echo "==> Built $@"APPINFO := $(OUT_DIR)/appinfodiff --git a/dylib/core/loader.c b/dylib/core/loader.cindex 369451e..1a97a99 100644--- a/dylib/core/loader.c+++ b/dylib/core/loader.c@@ -19,6 +19,7 @@#include <libgen.h>#define STEAMCLIENT_DYLIB "steamclient.dylib"+#define STEAMUI_DYLIB "steamui.dylib"// The bootstrapper can take a while before the real client dylib appears...#define WAIT_TIMEOUT_MS 60000@@ -104,6 +105,40 @@ static pthread_t g_install;static int g_install_started;static int g_active;+static void install_steamui(np_sigdb_t *sigdb) {+ int required = np_required_for_module(sigdb, STEAMUI_DYLIB);+ if (required == 0) {+ NP_DBG("install_thread: no %s signatures in this database", STEAMUI_DYLIB);+ return;+ }++ const struct mach_header_64 *mh = NULL;+ intptr_t slide = 0;++ if (np_await_image(STEAMUI_DYLIB, WAIT_TIMEOUT_MS, &mh, &slide, NULL, 0) != 0) {+ NP_WARN("install_thread: %s absent after %d ms, its hooks stay off",+ STEAMUI_DYLIB, WAIT_TIMEOUT_MS);+ return;+ }++ np_resolve_result_t resolved = {0};+ int count = np_resolve_signatures(mh, slide, sigdb, STEAMUI_DYLIB, &resolved);+ NP_LOG("install_thread: %s signatures %d/%d resolved", STEAMUI_DYLIB, count, required);++ if (count < required)+ NP_WARN("install_thread: %s %d/%d signatures resolved; the hooks that did "+ "resolve still install, the rest stay off", STEAMUI_DYLIB, count,+ required);++ int total = 0;+ int installed = np_hooks_install_steamui(mh, slide, &resolved, &total);++ NP_LOG("install_thread: %s ready, %d/%d hooks installed",+ STEAMUI_DYLIB, installed, total);++ np_free_resolution(&resolved);+}+static void *install_thread(void *unused) {(void)unused;@@ -144,12 +179,10 @@ static void *install_thread(void *unused) {np_resolve_result_t resolved = {0};- int resolved_count = np_resolve_signatures(mh, slide, &sigdb, &resolved);- NP_LOG("install_thread: signatures %d/%d resolved", resolved_count, sigdb.sig_count);-- int required = 0;- for (int i = 0; i < sigdb.sig_count; i++)- if (!sigdb.signatures[i].deprecated) required++;+ int resolved_count = np_resolve_signatures(mh, slide, &sigdb, STEAMCLIENT_DYLIB,+ &resolved);+ int required = np_required_for_module(&sigdb, STEAMCLIENT_DYLIB);+ NP_LOG("install_thread: signatures %d/%d resolved", resolved_count, required);// Safety feature :)if (resolved_count < required) {@@ -176,6 +209,9 @@ static void *install_thread(void *unused) {"incomplete for this client build", installed, total);np_free_resolution(&resolved);++ install_steamui(&sigdb);+np_free_profile(&sigdb);return NULL;diff --git a/dylib/core/macho.c b/dylib/core/macho.cindex 680fa73..96029b1 100644--- a/dylib/core/macho.c+++ b/dylib/core/macho.c@@ -68,6 +68,80 @@ int np_find_segment(const struct mach_header_64 *mh, intptr_t slide,return -1;}+static const uint8_t *fn_starts_table(const struct mach_header_64 *mh,+ intptr_t slide, size_t *out_size) {+ const uint8_t *cursor = (const uint8_t *)(mh + 1);+ uint32_t remaining = mh->ncmds;++ const struct linkedit_data_command *fs = NULL;+ uint64_t le_vmaddr = 0, le_fileoff = 0;+ int have_le = 0;++ while (remaining--) {+ const struct load_command *lc = (const struct load_command *)cursor;+ if (lc->cmdsize < sizeof(*lc)) return NULL;++ if (lc->cmd == LC_FUNCTION_STARTS && lc->cmdsize >= sizeof(*fs)) {+ fs = (const struct linkedit_data_command *)cursor;+ } else if (lc->cmd == LC_SEGMENT_64) {+ const struct segment_command_64 *sc = (const struct segment_command_64 *)cursor;+ if (strncmp(sc->segname, SEG_LINKEDIT, sizeof(sc->segname)) == 0) {+ le_vmaddr = sc->vmaddr;+ le_fileoff = sc->fileoff;+ have_le = 1;+ }+ }+ cursor += lc->cmdsize;+ }++ if (!fs || !have_le || !fs->datasize) return NULL;+ if (fs->dataoff < le_fileoff) return NULL;++ *out_size = fs->datasize;+ return (const uint8_t *)(uintptr_t)(le_vmaddr + (fs->dataoff - le_fileoff)+ + (uint64_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) {+ if (!mh || !out_start || !out_end) return -1;++ size_t size = 0;+ const uint8_t *p = fn_starts_table(mh, slide, &size);+ if (!p) return -1;++ const uint8_t *end = p + size;+ uintptr_t va = (uintptr_t)mh;+ uintptr_t start = 0;++ while (p < end) {+ uint64_t delta = 0;+ unsigned shift = 0;+ int complete = 0;++ while (p < end) {+ uint8_t b = *p++;+ if (shift < 64) delta |= (uint64_t)(b & 0x7F) << shift;+ shift += 7;+ if (!(b & 0x80)) { complete = 1; break; }+ }+ if (!complete) break;+ if (!delta) break;++ va += (uintptr_t)delta;+ if (va <= addr) {+ start = va;+ continue;+ }+ if (!start) return -1;+ *out_start = start;+ *out_end = va;+ return 0;+ }++ return -1;+}+int np_get_section_containing(const struct mach_header_64 *mh, intptr_t slide,uintptr_t addr, uintptr_t *out_base,size_t *out_size) {diff --git a/dylib/core/macho.h b/dylib/core/macho.hindex 460be98..9fc8641 100644--- a/dylib/core/macho.h+++ b/dylib/core/macho.h@@ -18,4 +18,7 @@ int np_get_section_containing(const struct mach_header_64 *mh, intptr_t slide,uintptr_t addr, uintptr_t *out_base,size_t *out_size);+int np_function_bounds(const struct mach_header_64 *mh, intptr_t slide,+ uintptr_t addr, uintptr_t *out_start, uintptr_t *out_end);+#endif // NOTPROTON_CORE_MACHO_Hdiff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex d7ef1ef..6ef0a35 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -78,10 +78,22 @@ report_early_exit() {}trap report_early_exit EXIT-if [ -n "$STEAM_COMPAT_APP_ID" ]; then- export SteamAppId="$STEAM_COMPAT_APP_ID"- export SteamGameId="$STEAM_COMPAT_APP_ID"-fi+while :; do+ case "$STEAM_COMPAT_INSTALL_PATH" in+ ?*/) STEAM_COMPAT_INSTALL_PATH="${STEAM_COMPAT_INSTALL_PATH%/}" ;;+ *) break ;;+ esac+done+export STEAM_COMPAT_INSTALL_PATH++app_id="$STEAM_COMPAT_APP_ID"+case "$app_id" in ''|0) app_id="$SteamAppId" ;; esac+case "$app_id" in ''|0) app_id=$(basename "$STEAM_COMPAT_DATA_PATH" 2>/dev/null) ;; esac+case "$app_id" in ''|*[!0-9]*) app_id=0 ;; esac+echo "app_id=$app_id (STEAM_COMPAT_APP_ID=$STEAM_COMPAT_APP_ID)" >> "$log" 2>&1 || true++[ -n "$SteamAppId" ] || export SteamAppId="$app_id"+[ -n "$SteamGameId" ] || export SteamGameId="$app_id"prefix_machine() {dll="$WINEPREFIX/drive_c/windows/system32/ntdll.dll"@@ -427,7 +439,7 @@ fi# Fixes CrossOver window focus issuessteam_root="$(dirname "$(dirname "$(dirname "$STEAM_COMPAT_DATA_PATH")")")"-manifest="$steam_root/steamapps/appmanifest_$STEAM_COMPAT_APP_ID.acf"+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" ]; doclient_root=$(dirname "$client_root")@@ -439,7 +451,7 @@ meta_name=""meta_icon=""meta_clienticon=""if [ -x "$appinfo_tool" ] && [ -f "$appinfo_vdf" ]; then- meta=$("$appinfo_tool" "$appinfo_vdf" "$STEAM_COMPAT_APP_ID" 2>> "$log") || meta=""+ 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')@@ -453,7 +465,7 @@ fi# shellcheck disable=SC1003 # the pair deletes a literal backslash, not a quotebundle_name=$(printf '%s' "$game_name" | tr -d '/:"`$\\')game_name_xml=$(printf '%s' "$game_name" | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g')-loader_root="$HOME/Library/Application Support/notproton/launchers/$STEAM_COMPAT_APP_ID"+loader_root="$HOME/Library/Application Support/notproton/launchers/$app_id"mkdir -p "$loader_root"loader_app="$loader_root/$bundle_name.app"rm -rf "$loader_root"/*.app@@ -466,7 +478,7 @@ icon_arg=""resolve_icon() {set +eiconmaker="$HOME/Library/Application Support/notproton/iconmaker"- art_dir="$client_root/appcache/librarycache/$STEAM_COMPAT_APP_ID"+ art_dir="$client_root/appcache/librarycache/$app_id"art=""if [ -n "$meta_clienticon" ]; thenico="$loader_root/clienticon-$meta_clienticon.ico"@@ -474,7 +486,7 @@ resolve_icon() {find "$loader_root" -maxdepth 1 -name 'clienticon-*' ! -name "clienticon-$meta_clienticon.*" -delete 2>/dev/null || truefind "$absent" -mtime +14 -delete 2>/dev/null || trueif [ ! -s "$ico" ] && [ ! -f "$absent" ]; then- url="https://shared.fastly.steamstatic.com/community_assets/images/apps/$STEAM_COMPAT_APP_ID/$meta_clienticon.ico"+ 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@@ -505,6 +517,13 @@ resolve_icon() {[ -n "$found" ] && { art="$found"; break; }donefi+ # 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+ fiicon_source=""if [ -n "$art" ]; thenicon_source="$art $(stat -f %m "$art" 2>/dev/null || echo 0)"@@ -543,7 +562,7 @@ cat > "$loader_contents/Info.plist" <<PLIST<dict><key>CFBundleName</key><string>$game_name_xml</string><key>CFBundleDisplayName</key><string>$game_name_xml</string>- <key>CFBundleIdentifier</key><string>com.notproton.launcher.$STEAM_COMPAT_APP_ID</string>+ <key>CFBundleIdentifier</key><string>com.notproton.launcher.$app_id</string><key>CFBundleExecutable</key><string>launcher</string><key>CFBundlePackageType</key><string>APPL</string><key>CFBundleInfoDictionaryVersion</key><string>6.0</string>diff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.cindex 37fcc9f..51bf9be 100644--- a/dylib/feats/webpatch.c+++ b/dylib/feats/webpatch.c@@ -138,7 +138,8 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {"{data:\"dxmt\",label:\"DXMT\"}," \"{data:\"dxvk\",label:\"DXVK\"}," \"{data:\"wined3d\",label:\"WineD3D\"}];" \- "if((t.vecPlatforms||[]).indexOf(\"osx\")>=0&&!t.strCompatToolName)return null;" \+ "if(t.unAppID<2147483648&&(t.vecPlatforms||[]).indexOf(\"osx\")>=0" \+ "&&!t.strCompatToolName)return null;" \"return(0," RT ".jsx)(\"div\",{className:\"MSCXPanel\",children:(0," RT ".jsxs)(" RT ".Fragment,{children:[" \"(0," RT ".jsx)(\"style\",{children:" NP_CX_OPTIONS_CSS "})," \"(0," RT ".jsxs)(" BARREL ".XY,{label:\"Graphics\",children:[" \@@ -242,6 +243,15 @@ static const np_gate_t g_gates_selecttool[] = {"the Windows version.\"", 1 },};+static const np_gate_t g_fixes[] = {+ { "(\"#AddNonSteam_Filter_Exe_MacOS\"),rFilePatterns:[\"*.app\"]",+ "(\"#AddNonSteam_Filter_Exe_MacOS\"),rFilePatterns:[\"*.app\",\"*.exe\"]", 1 },+ { "{strFileTypeName:\"Image Files (*.tga,*.png)\",rFilePatterns:[\"*.tga\",\"*.png\"]}",+ "{strFileTypeName:\"Image Files (*.tga,*.png,*.exe)\","+ "rFilePatterns:[\"*.tga\",\"*.png\",\"*.exe\"]}", 1 },+};+#define NP_FIX_COUNT (sizeof(g_fixes) / sizeof(g_fixes[0]))+typedef struct {const char *name;const char *probe;@@ -287,25 +297,38 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,}shape = &g_shapes[i];}- if (!shape)+ int fix_on[NP_FIX_COUNT];+ size_t fix_live = 0;+ for (size_t f = 0; f < NP_FIX_COUNT; f++) {+ size_t n = count_matches(s, src_len, g_fixes[f].find);+ fix_on[f] = n == (size_t)g_fixes[f].expect;+ if (fix_on[f]) { fix_live++; continue; }+ if (n)+ NP_WARN("webpatch: fix %zu expected %d occurrence(s), found %zu; "+ "leaving it alone", f, g_fixes[f].expect, n);+ }++ if (!shape && !fix_live)return NULL; // Not the part carrying the compat UI.- if (out_shape)- *out_shape = shape->name;-- int drifted = 0;- for (size_t g = 0; g < shape->count; g++) {- size_t n = count_matches(s, src_len, shape->gates[g].find);- if (n != (size_t)shape->gates[g].expect) {- NP_WARN("webpatch: [%s] gate %zu expected %d occurrence(s), found %zu",- shape->name, g, shape->gates[g].expect, n);- drifted = 1;+ if (shape) {+ if (out_shape)+ *out_shape = shape->name;++ int drifted = 0;+ for (size_t g = 0; g < shape->count; g++) {+ size_t n = count_matches(s, src_len, shape->gates[g].find);+ if (n != (size_t)shape->gates[g].expect) {+ NP_WARN("webpatch: [%s] gate %zu expected %d occurrence(s), found %zu",+ shape->name, g, shape->gates[g].expect, n);+ drifted = 1;+ }+ }+ if (drifted) {+ NP_ERR("webpatch: [%s] compat UI left unpatched, a Steam update moved the "+ "anchors", shape->name);+ return NULL;}- }- if (drifted) {- NP_ERR("webpatch: [%s] compat UI left unpatched, a Steam update moved the "- "anchors", shape->name);- return NULL;}np_out_t out = {0};@@ -313,10 +336,15 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,for (size_t i = 0; i < src_len; ) {const np_gate_t *hit = NULL;size_t used = 0;- for (size_t g = 0; g < shape->count; g++) {+ for (size_t g = 0; shape && g < shape->count; g++) {used = match_at(s, src_len, i, shape->gates[g].find, caps);if (used) { hit = &shape->gates[g]; break; }}+ for (size_t f = 0; !hit && f < NP_FIX_COUNT; f++) {+ if (!fix_on[f]) continue;+ used = match_at(s, src_len, i, g_fixes[f].find, caps);+ if (used) { hit = &g_fixes[f]; break; }+ }int ok = hit ? out_expand(&out, hit->replace, caps): out_put(&out, s + i, 1);if (!ok) { free(out.buf); return NULL; }@@ -326,6 +354,7 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,if (!out_reserve(&out, 0)) { free(out.buf); return NULL; }out.buf[out.len] = '\0';*out_len = out.len;- NP_LOG("webpatch: [%s] %zu gates applied", shape->name, shape->count);+ NP_LOG("webpatch: [%s] %zu gates, %zu fixes applied",+ shape ? shape->name : "no compat UI", shape ? shape->count : 0, fix_live);return out.buf;}diff --git a/dylib/hooks/hook_icon.c b/dylib/hooks/hook_icon.cnew file mode 100644index 0000000..a0ab8a8--- /dev/null+++ b/dylib/hooks/hook_icon.c@@ -0,0 +1,222 @@+// Icon logic for non-Steam shortcuts+#include "hooks.h"+#include "../util/log.h"+#include "../util/peicon.h"++#include <dlfcn.h>+#include <limits.h>+#include <pthread.h>+#include <stdlib.h>+#include <string.h>+#include <sys/stat.h>++#define NP_ICON_MAX_SIDE 4096++typedef void *(*np_icon_render_fn)(const char *const *path_slot, int size);++static np_icon_render_fn g_render_orig;++typedef struct { double x, y; } np_pt_t;+typedef struct { double w, h; } np_sz_t;+typedef struct { np_pt_t origin; np_sz_t size; } np_rect_t;++typedef void *(*msg_0_t)(void *, void *);+typedef void *(*msg_id_t)(void *, void *, void *);+typedef void *(*msg_bytes_t)(void *, void *, void *, unsigned long, signed char);+typedef void (*msg_long_t)(void *, void *, long);+typedef void (*msg_size_t)(void *, void *, np_sz_t);+typedef void (*msg_draw_t)(void *, void *, np_rect_t, np_rect_t, unsigned long, double);+typedef void *(*msg_rep_t)(void *, void *, unsigned char **, long, long, long, long,+ signed char, signed char, void *, long, long);++static void *(*np_get_class)(const char *);+static void *(*np_sel)(const char *);+static void *g_msg_send;+static void (*np_release)(void *);+static void *(*np_pool_push)(void);+static void (*np_pool_pop)(void *);+static void *g_device_rgb;++static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;+static char *g_cache_path;+static void *g_cache_ico;+static size_t g_cache_len;+static long g_cache_mtime;+static long long g_cache_size;++static int runtime_ready(void) {+ static int checked;+ static int ok;++ if (checked) return ok;+ checked = 1;++ np_get_class = (void *(*)(const char *))dlsym(RTLD_DEFAULT, "objc_getClass");+ np_sel = (void *(*)(const char *))dlsym(RTLD_DEFAULT, "sel_registerName");+ g_msg_send = dlsym(RTLD_DEFAULT, "objc_msgSend");+ np_release = (void (*)(void *))dlsym(RTLD_DEFAULT, "objc_release");+ np_pool_push = (void *(*)(void))dlsym(RTLD_DEFAULT, "objc_autoreleasePoolPush");+ np_pool_pop = (void (*)(void *))dlsym(RTLD_DEFAULT, "objc_autoreleasePoolPop");++ void **rgb = (void **)dlsym(RTLD_DEFAULT, "NSDeviceRGBColorSpace");+ if (rgb) g_device_rgb = *rgb;++ ok = np_get_class && np_sel && g_msg_send && np_release &&+ np_pool_push && np_pool_pop && g_device_rgb;+ if (!ok) NP_WARN("icon: AppKit runtime unavailable, leaving icons to Steam");+ return ok;+}++static void *ico_copy_for_path(const char *path, size_t *out_len) {+ struct stat st;+ char unquoted[PATH_MAX];++ if (!path || !*path) return NULL;++ size_t len = strlen(path);+ if (len >= 2 && path[0] == '"' && path[len - 1] == '"') {+ if (len - 2 >= sizeof(unquoted)) return NULL;+ memcpy(unquoted, path + 1, len - 2);+ unquoted[len - 2] = '\0';+ path = unquoted;+ }++ if (stat(path, &st) != 0 || !S_ISREG(st.st_mode)) return NULL;++ pthread_mutex_lock(&g_lock);++ int hit = g_cache_ico && g_cache_path &&+ strcmp(g_cache_path, path) == 0 &&+ g_cache_mtime == (long)st.st_mtime &&+ g_cache_size == (long long)st.st_size;++ if (!hit) {+ pthread_mutex_unlock(&g_lock);++ size_t len = 0;+ void *ico = np_pe_icon_ico(path, &len);+ if (!ico) return NULL;+ char *dup = strdup(path);+ NP_LOG("icon: read an icon out of '%s'", path);++ pthread_mutex_lock(&g_lock);+ free(g_cache_ico);+ free(g_cache_path);+ g_cache_ico = ico;+ g_cache_len = len;+ g_cache_path = dup;+ g_cache_mtime = (long)st.st_mtime;+ g_cache_size = (long long)st.st_size;+ }++ void *copy = NULL;+ if (g_cache_len) {+ copy = malloc(g_cache_len);+ if (copy) {+ memcpy(copy, g_cache_ico, g_cache_len);+ *out_len = g_cache_len;+ }+ }+ pthread_mutex_unlock(&g_lock);+ return copy;+}++static void *render(void *bytes, size_t len, int side) {+ void *pool = np_pool_push();++ void *data = ((msg_bytes_t)g_msg_send)(+ np_get_class("NSData"),+ np_sel("dataWithBytesNoCopy:length:freeWhenDone:"),+ bytes, (unsigned long)len, 1);++ if (!data) {+ free(bytes);+ np_pool_pop(pool);+ return NULL;+ }++ void *img = ((msg_id_t)g_msg_send)(+ ((msg_0_t)g_msg_send)(np_get_class("NSImage"), np_sel("alloc")),+ np_sel("initWithData:"), data);+ if (!img) {+ np_pool_pop(pool);+ return NULL;+ }++ void *rep = ((msg_rep_t)g_msg_send)(+ ((msg_0_t)g_msg_send)(np_get_class("NSBitmapImageRep"), np_sel("alloc")),+ np_sel("initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:"+ "samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:"+ "bitsPerPixel:"),+ NULL, side, side, 8, 4, 1, 0, g_device_rgb, 4L * side, 32);++ if (!rep) {+ np_release(img);+ np_pool_pop(pool);+ return NULL;+ }++ void *gc = np_get_class("NSGraphicsContext");+ void *ctx = ((msg_id_t)g_msg_send)(gc, np_sel("graphicsContextWithBitmapImageRep:"), rep);+ if (!ctx) {+ np_release(img);+ np_release(rep);+ np_pool_pop(pool);+ return NULL;+ }++ ((msg_long_t)g_msg_send)(ctx, np_sel("setImageInterpolation:"), 2);+ ((msg_0_t)g_msg_send)(gc, np_sel("saveGraphicsState"));+ ((msg_id_t)g_msg_send)(gc, np_sel("setCurrentContext:"), ctx);++ np_sz_t size = { (double)side, (double)side };+ np_rect_t dst = { { 0.0, 0.0 }, { (double)side, (double)side } };+ np_rect_t src = { { 0.0, 0.0 }, { 0.0, 0.0 } };++ ((msg_size_t)g_msg_send)(img, np_sel("setSize:"), size);+ ((msg_draw_t)g_msg_send)(img, np_sel("drawInRect:fromRect:operation:fraction:"),+ dst, src, 1, 1.0);++ ((msg_0_t)g_msg_send)(gc, np_sel("restoreGraphicsState"));++ np_release(img);+ np_pool_pop(pool);+ return rep;+}++static void *np_icon_render(const char *const *path_slot, int side) {+ const char *path = path_slot ? *path_slot : NULL;++ if (side <= 0 || side > NP_ICON_MAX_SIDE || !path || !runtime_ready())+ return g_render_orig ? g_render_orig(path_slot, side) : NULL;++ size_t len = 0;+ void *bytes = ico_copy_for_path(path, &len);+ if (!bytes)+ return g_render_orig ? g_render_orig(path_slot, side) : NULL;++ void *rep = render(bytes, len, side);+ if (!rep)+ return g_render_orig ? g_render_orig(path_slot, side) : NULL;++ return rep;+}++static np_patch_entry_t g_hooks[] = {+ {+ .label = "shortcut-icon",+ .signature = "steamui::ShortcutIconRender",+ .entry = (void *)np_icon_render,+ .trampoline = (void **)&g_render_orig,+ .tolerate_missing = 1,+ .mode = NP_PATCH_REPLACE,+ },+};++int np_hooks_icon_count(void) {+ return (int)(sizeof(g_hooks) / sizeof(g_hooks[0]));+}++np_patch_entry_t *np_hooks_icon_defs(void) {+ return g_hooks;+}diff --git a/dylib/hooks/hook_shortcut.c b/dylib/hooks/hook_shortcut.cnew file mode 100644index 0000000..d1c0959--- /dev/null+++ b/dylib/hooks/hook_shortcut.c@@ -0,0 +1,62 @@+// Enables selecting/using Windows applications as non-steam shortcuts inside the Steam client+#include "hooks.h"+#include "../util/log.h"++#include <string.h>+#include <strings.h>++typedef int (*np_ext_matches_fn)(const char *const *path_slot,+ const char *const *want_slot);++static np_ext_matches_fn g_ext_matches_orig;++static const char *file_extension(const char *path) {+ if (!path) return NULL;++ const char *dot = NULL;+ for (const char *p = path; *p; p++) {+ if (*p == '/') dot = NULL;+ else if (*p == '.') dot = p;+ }+ return (dot && dot[1]) ? dot + 1 : NULL;+}++static int np_ext_matches(const char *const *path_slot, const char *const *want_slot) {+ if (g_ext_matches_orig && g_ext_matches_orig(path_slot, want_slot))+ return 1;++ const char *want = want_slot ? *want_slot : NULL;+ const char *path = path_slot ? *path_slot : NULL;+ const char *ext = file_extension(path);++ if (!want || !ext)+ return 0;++ if (!g_ext_matches_orig && strcasecmp(ext, want) == 0)+ return 1;++ if (strcasecmp(want, "app") != 0 || strcasecmp(ext, "exe") != 0)+ return 0;++ NP_DBG("shortcut: treating '%s' as shortcut-able where only .app is asked for", path);+ return 1;+}++static np_patch_entry_t g_hooks[] = {+ {+ .label = "shortcut-exe",+ .signature = "steamui::ShortcutExtensionMatches",+ .entry = (void *)np_ext_matches,+ .trampoline = (void **)&g_ext_matches_orig,+ .tolerate_missing = 0,+ .mode = NP_PATCH_REPLACE,+ },+};++int np_hooks_shortcut_count(void) {+ return (int)(sizeof(g_hooks) / sizeof(g_hooks[0]));+}++np_patch_entry_t *np_hooks_shortcut_defs(void) {+ return g_hooks;+}diff --git a/dylib/hooks/hooks.c b/dylib/hooks/hooks.cindex 006b4cd..af2df36 100644--- a/dylib/hooks/hooks.c+++ b/dylib/hooks/hooks.c@@ -43,6 +43,11 @@ static const np_hook_group_t np_groups[] = {{ "webui", np_hooks_webui_count, np_hooks_webui_defs },};+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 },+};+// Installs one entry. Returns 1 when the patch lands, 0 when it is skipped or fails.static int np_apply_entry(np_resolve_result_t *resolved, const char *group,np_patch_entry_t *e) {@@ -78,6 +83,42 @@ static int np_apply_entry(np_resolve_result_t *resolved, const char *group,return 0;}+static int install_groups(const np_hook_group_t *groups, size_t n_groups,+ np_resolve_result_t *resolved, int *total_out) {+ int total = 0;+ int landed = 0;++ for (size_t g = 0; g < n_groups; g++) {+ const np_hook_group_t *group = &groups[g];+ np_patch_entry_t *entries = group->entries();+ int n = group->count();+ for (int i = 0; i < n; i++) {+ total++;+ landed += np_apply_entry(resolved, group->group, &entries[i]);+ }+ }++ if (total_out)+ *total_out = total;+ return landed;+}++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;++ int total = 0;+ int landed = install_groups(np_steamui_groups,+ sizeof(np_steamui_groups) / sizeof(np_steamui_groups[0]),+ resolved, &total);++ if (total_out)+ *total_out = total;+ NP_LOG("hooks: steamui %d/%d installed", landed, total);+ return landed;+}+int np_hooks_install_all(const struct mach_header_64 *mh, intptr_t slide,np_resolve_result_t *resolved, int *total_out) {np_hooks_compat_set_helpers(@@ -103,17 +144,9 @@ int np_hooks_install_all(const struct mach_header_64 *mh, intptr_t slide,np_webui_dump_routes();np_hooks_webui_bind(mh, slide, register_fn, dispatch_fn);- int total = 0;- int landed = 0;- for (size_t g = 0; g < sizeof(np_groups) / sizeof(np_groups[0]); g++) {- const np_hook_group_t *group = &np_groups[g];- np_patch_entry_t *entries = group->entries();- int n = group->count();- for (int i = 0; i < n; i++) {- total++;- landed += np_apply_entry(resolved, group->group, &entries[i]);- }- }+ int total = 0;+ int landed = install_groups(np_groups, sizeof(np_groups) / sizeof(np_groups[0]),+ resolved, &total);np_hooks_compat_publish_originals();diff --git a/dylib/hooks/hooks.h b/dylib/hooks/hooks.hindex 027eae6..1604f00 100644--- a/dylib/hooks/hooks.h+++ b/dylib/hooks/hooks.h@@ -44,9 +44,18 @@ np_patch_entry_t *np_hooks_webui_defs(void);void np_hooks_webui_bind(const struct mach_header_64 *mh, intptr_t slide,uintptr_t register_fn, uintptr_t dispatch_fn);+int np_hooks_shortcut_count(void);+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_install_all(const struct mach_header_64 *mh, intptr_t slide,np_resolve_result_t *resolved, int *total_out);+int np_hooks_install_steamui(const struct mach_header_64 *mh, intptr_t slide,+ np_resolve_result_t *resolved, int *total_out);+// True when `label` is one entry of the comma-separated value of env var `var`.// NOTPROTON_DISABLE uses this to skip named hooks.int np_hooks_env_lists_label(const char *var, const char *label);diff --git a/dylib/resolver/anchor.c b/dylib/resolver/anchor.cindex 8ebdcd2..d513207 100644--- a/dylib/resolver/anchor.c+++ b/dylib/resolver/anchor.c@@ -238,19 +238,62 @@ static uintptr_t scan_for_insn(uintptr_t text, size_t text_sz,}// The sole matching instruction pair inside one function body-static uintptr_t body_end(uintptr_t fn, uintptr_t text, size_t text_sz) {+static uintptr_t body_end(const struct mach_header_64 *mh, intptr_t slide,+ uintptr_t fn, uintptr_t text, size_t text_sz) {uintptr_t cap = fn + NP_FN_SPAN_MAX;uintptr_t bound = text + text_sz;if (cap > bound) cap = bound;++ uintptr_t start, end;+ if (np_function_bounds(mh, slide, fn, &start, &end) == 0 &&+ start == fn && end > fn && end <= bound)+ return end < cap ? end : cap;+for (uintptr_t pc = fn + 4; pc + 4 <= cap; pc += 4) {if (is_entry_insn(pc)) return pc;}return cap;}-static uintptr_t sole_insn_pair(uintptr_t fn, uintptr_t text, size_t text_sz,+static uintptr_t nth_call_target(const struct mach_header_64 *mh, intptr_t slide,+ uintptr_t fn, uintptr_t text, size_t text_sz,+ int nth) {+ uintptr_t end = body_end(mh, slide, fn, text, text_sz);+ uintptr_t limit = text + text_sz - 4;+ int seen = 0;++ for (uintptr_t pc = fn; pc + 4 <= end; pc += 4) {+ uintptr_t t = bl_target(pc, *(const uint32_t *)pc);+ if (!t) continue;+ if (++seen != nth) continue;+ if (t < text || t > limit) return 0;++ uintptr_t through = b_target(t, *(const uint32_t *)t);+ if (through && through >= text && through <= limit) t = through;+ return t;+ }+ return 0;+}++static uintptr_t walk_call_path(const struct mach_header_64 *mh, intptr_t slide,+ uintptr_t fn, uintptr_t text, size_t text_sz,+ const np_anchor_t *anchor) {+ if (anchor->call_depth < 1 || anchor->call_depth > NP_CALL_PATH_MAX) {+ NP_WARN("anchor: call_depth=%d outside 1..%d", anchor->call_depth,+ NP_CALL_PATH_MAX);+ return 0;+ }+ for (int i = 0; i < anchor->call_depth; i++) {+ fn = nth_call_target(mh, slide, fn, text, text_sz, anchor->call_path[i]);+ if (!fn) return 0;+ }+ return np_looks_like_prologue(fn) ? fn : 0;+}++static uintptr_t sole_insn_pair(const struct mach_header_64 *mh, intptr_t slide,+ uintptr_t fn, uintptr_t text, size_t text_sz,const np_insn_pair_t *p) {- uintptr_t end = body_end(fn, text, text_sz);+ uintptr_t end = body_end(mh, slide, fn, text, text_sz);uintptr_t found = 0;for (uintptr_t pc = fn; pc + 8 <= end; pc += 4) {@@ -319,7 +362,8 @@ uintptr_t np_locate_anchor(const struct mach_header_64 *mh, intptr_t slide,}if (anchor->kind != NP_MATCH_STRING &&- anchor->kind != NP_MATCH_INSN_PAIR_IN_FN) return 0;+ anchor->kind != NP_MATCH_INSN_PAIR_IN_FN &&+ anchor->kind != NP_MATCH_CALL_TARGET) return 0;uintptr_t fn;if (anchor->caller_hops > 0) {@@ -336,7 +380,9 @@ uintptr_t np_locate_anchor(const struct mach_header_64 *mh, intptr_t slide,if (!fn) return 0;if (anchor->kind == NP_MATCH_INSN_PAIR_IN_FN)- return sole_insn_pair(fn, text_base, text_size, &anchor->pair);+ return sole_insn_pair(mh, slide, fn, text_base, text_size, &anchor->pair);+ if (anchor->kind == NP_MATCH_CALL_TARGET)+ return walk_call_path(mh, slide, fn, text_base, text_size, anchor);return fn;}diff --git a/dylib/resolver/anchor.h b/dylib/resolver/anchor.hindex faa8155..be2a286 100644--- a/dylib/resolver/anchor.h+++ b/dylib/resolver/anchor.h@@ -14,8 +14,12 @@ typedef enum {// counting from a string loadNP_MATCH_INSN_PAIR_IN_FN, // the sole adjacent opcode pair inside the function// a string reference identifies+ NP_MATCH_AOB,+ NP_MATCH_CALL_TARGET,} np_match_kind_t;+#define NP_CALL_PATH_MAX 4+typedef struct {uint32_t first, first_mask;uint32_t second, second_mask;@@ -42,6 +46,9 @@ typedef struct {int caller_hops;int caller_tail;++ int call_path[NP_CALL_PATH_MAX];+ int call_depth;} np_anchor_t;// Upper bound on a function body when scanning for a pair.diff --git a/dylib/resolver/resolver.c b/dylib/resolver/resolver.cindex 0fe0ba7..02fde0e 100644--- a/dylib/resolver/resolver.c+++ b/dylib/resolver/resolver.c@@ -2,6 +2,7 @@#include "resolver.h"#include "anchor.h"+#include "aob.h"#include "../core/macho.h"#include "../util/log.h"@@ -42,12 +43,57 @@ static void push(np_resolve_result_t *r, const char *name, uintptr_t addr) {}// Single-signature resolution+static uintptr_t scan_aob(np_sig_entry_t *sig, uintptr_t text, size_t text_sz) {+ if (!sig->aob_hex[0]) return 0;++ np_byte_pattern_t pat;+ if (np_compile_pattern(sig->aob_hex, &pat) != 0) {+ NP_WARN("resolver: '%s' has an unparseable byte pattern", sig->name);+ return 0;+ }++ uintptr_t hit = np_scan_sole_match(text, text_sz, &pat);+ np_release_pattern(&pat);+ if (!hit) return 0;++ return hit + (intptr_t)sig->match_offset;+}+static uintptr_t try_anchor(np_sig_entry_t *sig,const struct mach_header_64 *mh, intptr_t slide,uintptr_t text, size_t text_sz) {- if (sig->anchor.kind == NP_MATCH_NONE) return 0;- uintptr_t addr = np_locate_anchor(mh, slide, text, text_sz, &sig->anchor);- if (!addr) return 0;+ if (sig->anchor.kind == NP_MATCH_AOB) {+ uintptr_t addr = scan_aob(sig, text, text_sz);+ if (addr) NP_LOG("resolver: '%s' -> 0x%lx [aob]", sig->name, (unsigned long)addr);+ return addr;+ }++ uintptr_t addr = 0;+ if (sig->anchor.kind != NP_MATCH_NONE)+ addr = np_locate_anchor(mh, slide, text, text_sz, &sig->anchor);++ uintptr_t alt = scan_aob(sig, text, text_sz);++ if (!addr) {+ if (!alt) return 0;++ uintptr_t start = 0, end = 0;+ if (np_function_bounds(mh, slide, alt, &start, &end) == 0 && start != alt) {+ NP_WARN("resolver: '%s' byte pattern hit 0x%lx is inside 0x%lx, not a "+ "function start; rejecting", sig->name, (unsigned long)alt,+ (unsigned long)start);+ return 0;+ }++ NP_LOG("resolver: '%s' -> 0x%lx [aob, anchor did not resolve]",+ sig->name, (unsigned long)alt);+ return alt;+ }++ if (alt && alt != addr)+ NP_WARN("resolver: '%s' anchor 0x%lx disagrees with byte pattern 0x%lx; "+ "keeping the anchor", sig->name, (unsigned long)addr,+ (unsigned long)alt);NP_LOG("resolver: '%s' -> 0x%lx [anchor]", sig->name, (unsigned long)addr);return addr;@@ -72,26 +118,40 @@ static int usable_code_address(const char *name, uintptr_t addr,}// Public API+int np_required_for_module(const np_sigdb_t *sigdb, const char *module) {+ if (!sigdb || !module) return 0;+ int n = 0;+ for (int i = 0; i < sigdb->sig_count; i++) {+ const np_sig_entry_t *sig = &sigdb->signatures[i];+ if (!sig->deprecated && strcmp(sig->module, module) == 0)+ n++;+ }+ return n;+}+int np_resolve_signatures(const struct mach_header_64 *mh, intptr_t slide,- np_sigdb_t *sigdb, np_resolve_result_t *out) {- if (!mh || !sigdb || !out) return 0;+ np_sigdb_t *sigdb, const char *module,+ np_resolve_result_t *out) {+ if (!mh || !sigdb || !module || !out) return 0;memset(out, 0, sizeof(*out));uintptr_t text;size_t text_sz;if (np_find_segment(mh, slide, "__TEXT", &text, &text_sz) != 0) {- NP_ERR("resolver: __TEXT segment not found, cannot scan");+ NP_ERR("resolver: __TEXT segment not found in %s, cannot scan", module);return 0;}- NP_LOG("resolver: scanning __TEXT @ 0x%lx (%zu bytes) for %d signatures",- text, text_sz, sigdb->sig_count);+ NP_LOG("resolver: scanning %s __TEXT @ 0x%lx (%zu bytes)", module, text, text_sz);int resolved = 0;for (int i = 0; i < sigdb->sig_count; i++) {np_sig_entry_t *sig = &sigdb->signatures[i];+ if (strcmp(sig->module, module) != 0)+ continue;+if (sig->deprecated) {push(out, sig->name, 0);continue;@@ -108,7 +168,8 @@ int np_resolve_signatures(const struct mach_header_64 *mh, intptr_t slide,push(out, sig->name, addr);}- NP_LOG("resolver: %d/%d signatures resolved", resolved, sigdb->sig_count);+ NP_LOG("resolver: %s %d/%d signatures resolved", module, resolved,+ np_required_for_module(sigdb, module));return resolved;}diff --git a/dylib/resolver/resolver.h b/dylib/resolver/resolver.hindex 24654bf..def7b22 100644--- a/dylib/resolver/resolver.h+++ b/dylib/resolver/resolver.h@@ -21,9 +21,13 @@ typedef struct {// True when the 32-bit value at `addr` looks like a common AArch64 prologue.int np_looks_like_prologue(uintptr_t addr);-// Resolve every signature in `sigdb` against the live image at `mh`+`slide`.+// Resolve the signatures in `sigdb` that name `module` against the live image at+// `mh`+`slide`. Entries belonging to another image are left out of `out`.int np_resolve_signatures(const struct mach_header_64 *mh, intptr_t slide,- np_sigdb_t *sigdb, np_resolve_result_t *out);+ np_sigdb_t *sigdb, const char *module,+ np_resolve_result_t *out);++int np_required_for_module(const np_sigdb_t *sigdb, const char *module);uintptr_t np_lookup_address(const np_resolve_result_t *result, const char *name);void np_free_resolution(np_resolve_result_t *result);diff --git a/dylib/resolver/sigdb.c b/dylib/resolver/sigdb.cindex e36fb1c..aeeefaf 100644--- a/dylib/resolver/sigdb.c+++ b/dylib/resolver/sigdb.c@@ -75,6 +75,23 @@ static int load_insn_pair(cJSON *anchor_obj, np_insn_pair_t *p) {return 0;}+static int load_call_path(cJSON *obj, np_anchor_t *a) {+ cJSON *arr = cJSON_GetObjectItem(obj, "call_path");+ if (!arr || !cJSON_IsArray(arr)) return -1;++ int n = cJSON_GetArraySize(arr);+ if (n < 1 || n > NP_CALL_PATH_MAX) return -1;++ for (int i = 0; i < n; i++) {+ cJSON *e = cJSON_GetArrayItem(arr, i);+ if (!e || !cJSON_IsNumber(e)) return -1;+ if (e->valueint < 1) return -1;+ a->call_path[i] = e->valueint;+ }+ a->call_depth = n;+ return 0;+}+static void load_anchor(cJSON *sig_obj, np_anchor_t *a) {cJSON *obj = cJSON_GetObjectItem(sig_obj, "anchor");if (!obj || !cJSON_IsObject(obj)) return;@@ -98,6 +115,14 @@ static void load_anchor(cJSON *sig_obj, np_anchor_t *a) {a->kind = NP_MATCH_NONE;return;}+ } else if (strcmp(ks, "call_target") == 0) {+ a->kind = NP_MATCH_CALL_TARGET;+ str_field(obj, "value", a->str, sizeof(a->str));+ if (load_call_path(obj, a) != 0) {+ NP_WARN("sigdb: anchor '%s' has no usable call_path; ignoring it", a->str);+ a->kind = NP_MATCH_NONE;+ return;+ }} else if (strcmp(ks, "vtable_slot") == 0) {a->va = hex_field(obj, "va");// A missing or unparseable va reads as zero@@ -108,6 +133,9 @@ static void load_anchor(cJSON *sig_obj, np_anchor_t *a) {}a->kind = NP_MATCH_VTABLE_SLOT;return; // refinements below are string-only+ } else if (strcmp(ks, "aob") == 0) {+ a->kind = NP_MATCH_AOB;+ return;} else {return;}@@ -171,15 +199,25 @@ int np_load_profile(const char *path, np_sigdb_t *out) {np_sig_entry_t *e = &out->signatures[i++];str_field(elem, "name", e->name, sizeof(e->name));+ str_field(elem, "module", e->module, sizeof(e->module));str_field(elem, "aob_hex", e->aob_hex, sizeof(e->aob_hex));e->func_addr_this_build = hex_field(elem, "func_addr_this_build");+ if (!e->module[0])+ memcpy(e->module, NP_MODULE_DEFAULT, sizeof(NP_MODULE_DEFAULT));+if ((v = cJSON_GetObjectItem(elem, "deprecated")))e->deprecated = cJSON_IsTrue(v);if ((v = cJSON_GetObjectItem(elem, "match_offset")))e->match_offset = (int32_t)v->valueint;load_anchor(elem, &e->anchor);++ if (e->anchor.kind == NP_MATCH_AOB && !e->aob_hex[0]) {+ NP_WARN("sigdb: '%s' anchors on its byte pattern but carries none; "+ "ignoring it", e->name);+ e->anchor.kind = NP_MATCH_NONE;+ }}}diff --git a/dylib/resolver/sigdb.h b/dylib/resolver/sigdb.hindex 4958930..d9a2c3b 100644--- a/dylib/resolver/sigdb.h+++ b/dylib/resolver/sigdb.h@@ -6,8 +6,11 @@#include <stddef.h>#include "anchor.h"+#define NP_MODULE_DEFAULT "steamclient.dylib"+typedef struct {char name[128];+ char module[64];char aob_hex[4096];uintptr_t func_addr_this_build;int deprecated;diff --git a/dylib/tests/anchorcheck.c b/dylib/tests/anchorcheck.cindex 9187084..d823873 100644--- a/dylib/tests/anchorcheck.c+++ b/dylib/tests/anchorcheck.c@@ -17,8 +17,9 @@#include <stdlib.h>#include <string.h>-#define STEAMCLIENT \- "/Library/Application Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/steamclient.dylib"+#define STEAM_MACOS \+ "/Library/Application Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/"+#define MAX_IMAGES 4#define SIGDB_DIR "signatures/macos.arm64"#define MAX_DBS 16@@ -41,6 +42,57 @@ static const struct mach_header_64 *find_image(const char *suffix,return NULL;}+typedef struct {+ char module[64];+ const struct mach_header_64 *mh;+ intptr_t slide;+ uintptr_t text;+ size_t text_sz;+ const char *path;+} image_t;++static image_t g_images[MAX_IMAGES];+static int g_image_count;++static const image_t *image_for(const char *module) {+ for (int i = 0; i < g_image_count; i++)+ if (strcmp(g_images[i].module, module) == 0) return &g_images[i];+ return NULL;+}++static int load_image(const char *module) {+ if (image_for(module)) return 0;+ if (g_image_count >= MAX_IMAGES) return -1;++ const char *home = getenv("HOME");+ char path[1024], suffix[128];+ snprintf(path, sizeof(path), "%s%s%s", home ? home : "", STEAM_MACOS, module);+ snprintf(suffix, sizeof(suffix), "/%s", module);++ if (!dlopen(path, RTLD_LAZY | RTLD_LOCAL)) {+ fprintf(stderr, "dlopen failed: %s\n", dlerror());+ return -1;+ }++ image_t *im = &g_images[g_image_count];+ im->mh = find_image(suffix, &im->slide, &im->path);+ if (!im->mh) {+ fprintf(stderr, "%s not found after dlopen\n", module);+ return -1;+ }+ if (np_find_segment(im->mh, im->slide, "__TEXT", &im->text, &im->text_sz) != 0) {+ fprintf(stderr, "%s has no __TEXT\n", module);+ return -1;+ }+ snprintf(im->module, sizeof(im->module), "%s", module);+ g_image_count++;++ printf("image : %s\n", im->path);+ printf("slide : 0x%lx\n", (unsigned long)im->slide);+ printf("__TEXT : 0x%lx (%zu bytes)\n\n", im->text, im->text_sz);+ return 0;+}+// An independent read on the anchor result, meaningful only against the build the// pattern was recorded from.static uintptr_t resolve_by_aob(np_sig_entry_t *sig,@@ -67,6 +119,8 @@ static const char *kind_name(np_match_kind_t k) {case NP_MATCH_VTABLE_SLOT: return "vtable_slot";case NP_MATCH_INSN_AFTER_STRING: return "insn_after_string";case NP_MATCH_INSN_PAIR_IN_FN: return "insn_pair";+ case NP_MATCH_AOB: return "aob";+ case NP_MATCH_CALL_TARGET: return "call_target";default: return "none";}}@@ -91,6 +145,7 @@ typedef struct {int unresolved;int recorded_match;int recorded_total;+ int loaded;} dbcheck_t;// Class vptrs per client build, read off the disassembly. These address data rather than@@ -171,9 +226,8 @@ static int collect_dbs(char paths[][512], int max) {// One database against the live image: what its anchors found, and what its// recorded evidence claims.-static int check_db(dbcheck_t *db, const struct mach_header_64 *mh, intptr_t slide,- uintptr_t text, size_t text_sz) {- if (np_load_profile(db->path, &db->sigdb) != 0) {+static int check_db(dbcheck_t *db) {+ if (!db->loaded && np_load_profile(db->path, &db->sigdb) != 0) {fprintf(stderr, "cannot load sigdb '%s'\n", db->path);return -1;}@@ -191,13 +245,20 @@ static int check_db(dbcheck_t *db, const struct mach_header_64 *mh, intptr_t slir->recorded = sig->func_addr_this_build;r->has_pattern = sig->aob_hex[0] != '\0';+ const image_t *im = image_for(sig->module);+ if (!im) {+ fprintf(stderr, "no image loaded for module '%s'\n", sig->module);+ return -1;+ }+uintptr_t anc = (sig->anchor.kind == NP_MATCH_NONE)? 0- : np_locate_anchor(mh, slide, text, text_sz, &sig->anchor);- uintptr_t aob = resolve_by_aob(sig, text, text_sz);+ : np_locate_anchor(im->mh, im->slide, im->text, im->text_sz,+ &sig->anchor);+ uintptr_t aob = resolve_by_aob(sig, im->text, im->text_sz);- r->anchor = anc ? anc - (uintptr_t)slide : 0;- r->aob = aob ? aob - (uintptr_t)slide : 0;+ r->anchor = anc ? anc - (uintptr_t)im->slide : 0;+ r->aob = aob ? aob - (uintptr_t)im->slide : 0;if (!r->anchor) db->unresolved++;if (r->recorded) {@@ -233,10 +294,10 @@ static int report_db(const dbcheck_t *db, int is_live) {const char *verdict;if (r->kind == NP_MATCH_NONE) { verdict = "NO ANCHOR"; bad++; }- else if (!r->anchor) { verdict = "ANCHOR FAILED"; bad++; }- // A pattern from another build landing somewhere else is the hazard that- // keeps patterns out of the resolver, so it is worth seeing. Not a failure:- // nothing resolves from it.+ else if (!r->anchor) { verdict = (r->has_pattern && r->aob)+ ? "anchor failed, aob resolves"+ : "UNRESOLVED";+ if (!(r->has_pattern && r->aob)) bad++; }else if (!is_live) { verdict = (r->has_pattern && r->aob && r->aob != r->anchor)? "stale pattern hit elsewhere": "resolved"; }@@ -297,31 +358,7 @@ int main(int argc, char **argv) {const char *home = getenv("HOME");if (!home) { fprintf(stderr, "HOME unset\n"); return 3; }- char dylib[1024];- snprintf(dylib, sizeof(dylib), "%s%s", home, STEAMCLIENT);-- void *handle = dlopen(dylib, RTLD_LAZY | RTLD_LOCAL);- if (!handle) {- fprintf(stderr, "dlopen failed: %s\n", dlerror());- return 3;- }-- intptr_t slide = 0;- const char *loaded_path = NULL;- const struct mach_header_64 *mh =- find_image("/steamclient.dylib", &slide, &loaded_path);- if (!mh) { fprintf(stderr, "steamclient image not found after dlopen\n"); return 3; }-- uintptr_t text;- size_t text_sz;- if (np_find_segment(mh, slide, "__TEXT", &text, &text_sz) != 0) {- fprintf(stderr, "__TEXT not found\n");- return 3;- }-- printf("image : %s\n", loaded_path);- printf("slide : 0x%lx\n", (unsigned long)slide);- printf("__TEXT : 0x%lx (%zu bytes)\n\n", text, text_sz);+ if (load_image(NP_MODULE_DEFAULT) != 0) return 3;char paths[MAX_DBS][512];int n = 0;@@ -333,7 +370,16 @@ int main(int argc, char **argv) {dbcheck_t dbs[MAX_DBS] = {0};for (int i = 0; i < n; i++) {snprintf(dbs[i].path, sizeof(dbs[i].path), "%s", paths[i]);- if (check_db(&dbs[i], mh, slide, text, text_sz) != 0) return 2;+ if (np_load_profile(dbs[i].path, &dbs[i].sigdb) != 0) {+ fprintf(stderr, "cannot load sigdb '%s'\n", dbs[i].path);+ return 2;+ }+ dbs[i].loaded = 1;+ for (int j = 0; j < dbs[i].sigdb.sig_count; j++)+ if (load_image(dbs[i].sigdb.signatures[j].module) != 0) return 3;+ }+ for (int i = 0; i < n; i++) {+ if (check_db(&dbs[i]) != 0) return 2;}int live = pick_live(dbs, n);@@ -347,7 +393,8 @@ int main(int argc, char **argv) {"checked. Anchors are what the dylib resolves from, so this is not a ""failure.\n");} else {- bad += run_rtti(mh, slide, text, text_sz, dbs[live].build);+ const image_t *sc = image_for(NP_MODULE_DEFAULT);+ bad += run_rtti(sc->mh, sc->slide, sc->text, sc->text_sz, dbs[live].build);}for (int i = 0; i < n; i++) {diff --git a/dylib/tests/gatecheck.c b/dylib/tests/gatecheck.cindex 8c91845..1a85e9b 100644--- a/dylib/tests/gatecheck.c+++ b/dylib/tests/gatecheck.c@@ -25,6 +25,30 @@ static void wrong(const char *fmt, ...) {// Invariants the transform relies on but cannot check at run time. A replacement still// holding its own anchor would be found again next pass, and an anchor inside another// anchor would make the result depend on table order rather than on the chunk.+static void check_gate(const char *nm, size_t i, const np_gate_t *a,+ const np_gate_t *group, size_t group_n) {+ if (!a->find || !*a->find) wrong("[%s] gate %zu has no anchor", nm, i);+ if (!a->replace || !*a->replace) wrong("[%s] gate %zu has no replacement", nm, i);+ if (a->expect < 1) wrong("[%s] gate %zu expects %d hits", nm, i, a->expect);+ if (a->find && a->replace && strcmp(a->find, a->replace) == 0)+ wrong("[%s] gate %zu replaces its anchor with itself", nm, i);+ if (a->find && a->replace && *a->find && strstr(a->replace, a->find))+ wrong("[%s] gate %zu replacement still contains its own anchor", nm, i);+ // A capture the replacement reads but the anchor never binds would+ // expand to nothing, so the transform would refuse at run time.+ for (const char *r = a->replace; r && *r; r++) {+ int ci = cap_index((unsigned char)*r);+ if (ci >= 0 && !strchr(a->find, *r))+ wrong("[%s] gate %zu replacement reads capture %d, anchor never binds it",+ nm, i, ci + 1);+ }+ for (size_t j = 0; j < group_n; j++) {+ if (i == j || !a->find || !group[j].find || !*group[j].find) continue;+ if (strstr(a->find, group[j].find))+ wrong("[%s] gate %zu anchor contains gate %zu anchor", nm, i, j);+ }+}+static void selfcheck(void) {size_t total = 0;for (size_t sh = 0; sh < NP_SHAPE_COUNT; sh++) {@@ -36,32 +60,23 @@ static void selfcheck(void) {if (strcmp(S->probe, g_shapes[o].probe) == 0)wrong("[%s] and [%s] share a probe", nm, g_shapes[o].name);}- for (size_t i = 0; i < S->count; i++) {- const np_gate_t *a = &S->gates[i];- if (!a->find || !*a->find) wrong("[%s] gate %zu has no anchor", nm, i);- if (!a->replace || !*a->replace) wrong("[%s] gate %zu has no replacement", nm, i);- if (a->expect < 1) wrong("[%s] gate %zu expects %d hits", nm, i, a->expect);- if (a->find && a->replace && strcmp(a->find, a->replace) == 0)- wrong("[%s] gate %zu replaces its anchor with itself", nm, i);- if (a->find && a->replace && *a->find && strstr(a->replace, a->find))- wrong("[%s] gate %zu replacement still contains its own anchor", nm, i);- // A capture the replacement reads but the anchor never binds would- // expand to nothing, so the transform would refuse at run time.- for (const char *r = a->replace; r && *r; r++) {- int ci = cap_index((unsigned char)*r);- if (ci >= 0 && !strchr(a->find, *r))- wrong("[%s] gate %zu replacement reads capture %d, anchor never binds it",- nm, i, ci + 1);- }- for (size_t j = 0; j < S->count; j++) {- if (i == j || !a->find || !S->gates[j].find || !*S->gates[j].find) continue;- if (strstr(a->find, S->gates[j].find))- wrong("[%s] gate %zu anchor contains gate %zu anchor", nm, i, j);- }- }+ for (size_t i = 0; i < S->count; i++)+ check_gate(nm, i, &S->gates[i], S->gates, S->count);total += S->count;}- printf("%zu shapes, %zu gates checked\n", NP_SHAPE_COUNT, total);++ for (size_t f = 0; f < NP_FIX_COUNT; f++) {+ check_gate("fix", f, &g_fixes[f], g_fixes, NP_FIX_COUNT);+ for (size_t sh = 0; sh < NP_SHAPE_COUNT; sh++)+ for (size_t g = 0; g < g_shapes[sh].count; g++)+ if (strstr(g_fixes[f].find, g_shapes[sh].gates[g].find) ||+ strstr(g_shapes[sh].gates[g].find, g_fixes[f].find))+ wrong("fix %zu and [%s] gate %zu share an anchor",+ f, g_shapes[sh].name, g);+ }++ printf("%zu shapes, %zu gates, %zu fixes checked\n",+ NP_SHAPE_COUNT, total, NP_FIX_COUNT);}static uint8_t *slurp(const char *path, size_t *len) {@@ -99,6 +114,16 @@ static void check_output(const char *out, size_t out_len) {< (size_t)S->gates[g].expect)wrong("[%s] gate %zu replacement is missing from the patch", S->name, g);}+ for (size_t f = 0; f < NP_FIX_COUNT; f++) {+ size_t anchor = count_matches(out, out_len, g_fixes[f].find);+ size_t repl = count_matches(out, out_len, g_fixes[f].replace);+ if (!anchor && !repl) continue;+ if (anchor)+ wrong("fix %zu anchor survived the patch", f);+ if (repl < (size_t)g_fixes[f].expect)+ wrong("fix %zu replacement is missing from the patch", f);+ }+// This pass is meant to be refused, so its drift report is not a finding.size_t again_len = 0;int saved = np_log_level;diff --git a/dylib/tests/panel-behavior/behavior.js b/dylib/tests/panel-behavior/behavior.jsindex 53d9973..3438f1c 100644--- a/dylib/tests/panel-behavior/behavior.js+++ b/dylib/tests/panel-behavior/behavior.js@@ -16,6 +16,9 @@ for (const form of Object.keys(FORMS)) {t.ok(P({ details: details('', { vecPlatforms: ['osx'], strCompatToolName: '' }) }) === null,'a mac build with nothing pinned renders no panel');+ t.ok(P({ details: details('', { unAppID: 3420702832, vecPlatforms: ['osx'],+ strCompatToolName: '' }) }) !== null,+ 'a shortcut renders the panel before a tool name reaches the page');let r = nodes('');t.ok(toggles(r).length === 5 && sections(r).length === 2, 'automatic shows five toggles in two sections');diff --git a/dylib/util/peicon.c b/dylib/util/peicon.cnew file mode 100644index 0000000..7f37611--- /dev/null+++ b/dylib/util/peicon.c@@ -0,0 +1,306 @@+// extracts icon from Windows application binary, used for non-Steam shortcuts+#include "peicon.h"++#include <fcntl.h>+#include <stdint.h>+#include <stdlib.h>+#include <string.h>+#include <sys/mman.h>+#include <sys/stat.h>+#include <unistd.h>++#define NP_PE_MAX_SECTIONS 96+#define NP_PE_MAX_LEAVES 4096+#define NP_PE_MAX_IMAGE (16 * 1024 * 1024)+#define NP_PE_MAX_DEPTH 3++#define NP_RT_ICON 3+#define NP_RT_GROUP_ICON 14++typedef struct {+ uint32_t va;+ uint32_t size;+ uint32_t raw;+ uint32_t raw_size;+} np_sect_t;++typedef struct {+ uint32_t type;+ uint32_t id;+ uint32_t rva;+ uint32_t size;+} np_leaf_t;++typedef struct {+ const uint8_t *p;+ size_t n;+ np_sect_t sects[NP_PE_MAX_SECTIONS];+ int nsects;+ np_leaf_t *leaves;+ int nleaves;+} np_pe_t;++static int rd_u8(const np_pe_t *pe, size_t off, uint8_t *out) {+ if (off >= pe->n) return 0;+ *out = pe->p[off];+ return 1;+}++static int rd_u16(const np_pe_t *pe, size_t off, uint16_t *out) {+ if (pe->n < 2 || off > pe->n - 2) return 0;+ *out = (uint16_t)((uint16_t)pe->p[off] | ((uint16_t)pe->p[off + 1] << 8));+ return 1;+}++static int rd_u32(const np_pe_t *pe, size_t off, uint32_t *out) {+ if (pe->n < 4 || off > pe->n - 4) return 0;+ *out = (uint32_t)pe->p[off] | ((uint32_t)pe->p[off + 1] << 8) |+ ((uint32_t)pe->p[off + 2] << 16) | ((uint32_t)pe->p[off + 3] << 24);+ return 1;+}++static int rva_to_off(const np_pe_t *pe, uint32_t rva, size_t *out) {+ for (int i = 0; i < pe->nsects; i++) {+ const np_sect_t *s = &pe->sects[i];+ uint32_t span = s->size > s->raw_size ? s->size : s->raw_size;+ if (rva >= s->va && (uint64_t)rva < (uint64_t)s->va + span) {+ *out = (size_t)s->raw + (size_t)(rva - s->va);+ return 1;+ }+ }+ return 0;+}++static int read_sections(np_pe_t *pe, size_t peo, int count, size_t opt_size) {+ if (count <= 0 || count > NP_PE_MAX_SECTIONS) return 0;++ size_t cursor = peo + 24 + opt_size;+ for (int i = 0; i < count; i++) {+ np_sect_t s;+ if (!rd_u32(pe, cursor + 8, &s.size) ||+ !rd_u32(pe, cursor + 12, &s.va) ||+ !rd_u32(pe, cursor + 16, &s.raw_size) ||+ !rd_u32(pe, cursor + 20, &s.raw)) return 0;+ pe->sects[pe->nsects++] = s;+ cursor += 40;+ }+ return 1;+}++static void walk(np_pe_t *pe, size_t base, size_t node, int depth,+ uint32_t type, uint32_t id) {+ uint16_t named, ids;+ if (depth >= NP_PE_MAX_DEPTH || pe->nleaves >= NP_PE_MAX_LEAVES) return;+ if (!rd_u16(pe, node + 12, &named) || !rd_u16(pe, node + 14, &ids)) return;++ int total = (int)named + (int)ids;+ for (int i = 0; i < total; i++) {+ size_t entry = node + 16 + (size_t)i * 8;+ uint32_t name_field, off_field;+ if (!rd_u32(pe, entry, &name_field) || !rd_u32(pe, entry + 4, &off_field)) return;++ uint32_t rtype = depth == 0 ? name_field : type;+ uint32_t rid = depth == 1 ? name_field : id;++ if (off_field & 0x80000000u) {+ walk(pe, base, base + (off_field & 0x7FFFFFFFu), depth + 1, rtype, rid);+ if (pe->nleaves >= NP_PE_MAX_LEAVES) return;+ continue;+ }++ size_t at = base + off_field;+ np_leaf_t leaf;+ if (!rd_u32(pe, at, &leaf.rva) || !rd_u32(pe, at + 4, &leaf.size)) return;+ leaf.type = rtype;+ leaf.id = rid;+ pe->leaves[pe->nleaves++] = leaf;+ if (pe->nleaves >= NP_PE_MAX_LEAVES) return;+ }+}++static const np_leaf_t *lowest_group(const np_pe_t *pe) {+ const np_leaf_t *best = NULL;+ for (int i = 0; i < pe->nleaves; i++) {+ const np_leaf_t *l = &pe->leaves[i];+ if (l->type != NP_RT_GROUP_ICON) continue;+ if (!best || l->id < best->id) best = l;+ }+ return best;+}++static const np_leaf_t *image_with_id(const np_pe_t *pe, uint32_t id) {+ for (int i = 0; i < pe->nleaves; i++) {+ const np_leaf_t *l = &pe->leaves[i];+ if (l->type == NP_RT_ICON && l->id == id) return l;+ }+ return NULL;+}++static void put_u16(uint8_t *p, uint16_t v) {+ p[0] = (uint8_t)(v & 0xFF);+ p[1] = (uint8_t)(v >> 8);+}++static void put_u32(uint8_t *p, uint32_t v) {+ p[0] = (uint8_t)(v & 0xFF);+ p[1] = (uint8_t)((v >> 8) & 0xFF);+ p[2] = (uint8_t)((v >> 16) & 0xFF);+ p[3] = (uint8_t)((v >> 24) & 0xFF);+}++static void *build_ico(np_pe_t *pe, uint32_t rsrc_rva, size_t *out_len) {+ size_t base;+ if (!rva_to_off(pe, rsrc_rva, &base)) return NULL;++ walk(pe, base, base, 0, 0, 0);++ const np_leaf_t *group = lowest_group(pe);+ if (!group) return NULL;++ size_t group_at;+ uint16_t count;+ if (!rva_to_off(pe, group->rva, &group_at)) return NULL;+ if (group->size < 6) return NULL;+ if (!rd_u16(pe, group_at + 4, &count) || count == 0) return NULL;+ if (group->size < 6 + (uint32_t)count * 14) return NULL;++ const np_leaf_t **picked = calloc(count, sizeof(*picked));+ uint8_t *records = calloc(count, 16);+ if (!picked || !records) {+ free(picked);+ free(records);+ return NULL;+ }++ int written = 0;+ size_t payload = 0;++ for (int i = 0; i < (int)count; i++) {+ size_t e = group_at + 6 + (size_t)i * 14;+ uint8_t w, h, colors;+ uint16_t planes, bits, id;+ size_t at;++ if (!rd_u8(pe, e, &w) || !rd_u8(pe, e + 1, &h) || !rd_u8(pe, e + 2, &colors) ||+ !rd_u16(pe, e + 4, &planes) || !rd_u16(pe, e + 6, &bits) ||+ !rd_u16(pe, e + 12, &id)) continue;++ const np_leaf_t *img = image_with_id(pe, id);+ if (!img || img->size == 0 || img->size > NP_PE_MAX_IMAGE) continue;+ if (!rva_to_off(pe, img->rva, &at)) continue;+ if (pe->n < img->size || at > pe->n - img->size) continue;++ uint8_t *r = records + (size_t)written * 16;+ r[0] = w;+ r[1] = h;+ r[2] = colors;+ r[3] = 0;+ put_u16(r + 4, planes);+ put_u16(r + 6, bits);+ put_u32(r + 8, img->size);+ picked[written] = img;+ written++;+ payload += img->size;+ }++ if (written == 0) {+ free(picked);+ free(records);+ return NULL;+ }++ size_t header = 6 + (size_t)written * 16;+ size_t total = header + payload;+ uint8_t *ico = malloc(total);+ if (!ico) {+ free(picked);+ free(records);+ return NULL;+ }++ put_u16(ico, 0);+ put_u16(ico + 2, 1);+ put_u16(ico + 4, (uint16_t)written);++ size_t at = header;+ for (int i = 0; i < written; i++) {+ uint8_t *r = ico + 6 + (size_t)i * 16;+ memcpy(r, records + (size_t)i * 16, 16);+ put_u32(r + 12, (uint32_t)at);++ size_t src = 0;+ if (!rva_to_off(pe, picked[i]->rva, &src)) continue;+ memcpy(ico + at, pe->p + src, picked[i]->size);+ at += picked[i]->size;+ }++ free(picked);+ free(records);+ *out_len = total;+ return ico;+}++static void *icon_from_map(const uint8_t *map, size_t len, size_t *out_len) {+ np_pe_t pe;+ memset(&pe, 0, sizeof(pe));+ pe.p = map;+ pe.n = len;++ uint16_t mz;+ uint32_t peo32, sig;+ if (!rd_u16(&pe, 0, &mz) || mz != 0x5A4D) return NULL;+ if (!rd_u32(&pe, 0x3C, &peo32)) return NULL;++ size_t peo = peo32;+ if (!rd_u32(&pe, peo, &sig) || sig != 0x00004550) return NULL;++ uint16_t nsects, opt_size, magic;+ if (!rd_u16(&pe, peo + 6, &nsects) || !rd_u16(&pe, peo + 20, &opt_size) ||+ !rd_u16(&pe, peo + 24, &magic)) return NULL;++ size_t dir_base, count_at;+ if (magic == 0x10B) {+ dir_base = peo + 24 + 96;+ count_at = peo + 24 + 92;+ } else if (magic == 0x20B) {+ dir_base = peo + 24 + 112;+ count_at = peo + 24 + 108;+ } else {+ return NULL;+ }++ uint32_t dir_count, rsrc_rva;+ if (!rd_u32(&pe, count_at, &dir_count) || dir_count <= 2) return NULL;+ if (!rd_u32(&pe, dir_base + 16, &rsrc_rva) || rsrc_rva == 0) return NULL;++ if (!read_sections(&pe, peo, (int)nsects, opt_size)) return NULL;++ pe.leaves = calloc(NP_PE_MAX_LEAVES, sizeof(*pe.leaves));+ if (!pe.leaves) return NULL;++ void *ico = build_ico(&pe, rsrc_rva, out_len);+ free(pe.leaves);+ return ico;+}++void *np_pe_icon_ico(const char *path, size_t *out_len) {+ if (!path || !*path || !out_len) return NULL;++ int fd = open(path, O_RDONLY | O_CLOEXEC);+ if (fd < 0) return NULL;++ struct stat st;+ if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_size <= 0x40) {+ close(fd);+ return NULL;+ }++ size_t len = (size_t)st.st_size;+ void *map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);+ close(fd);+ if (map == MAP_FAILED) return NULL;++ void *ico = icon_from_map(map, len, out_len);+ munmap(map, len);+ return ico;+}diff --git a/dylib/util/peicon.h b/dylib/util/peicon.hnew file mode 100644index 0000000..8474d2a--- /dev/null+++ b/dylib/util/peicon.h@@ -0,0 +1,8 @@+#ifndef NP_PEICON_H+#define NP_PEICON_H++#include <stddef.h>++void *np_pe_icon_ico(const char *path, size_t *out_len);++#endifdiff --git a/helpers/iconmaker.swift b/helpers/iconmaker.swiftindex d22043a..b694b64 100644--- a/helpers/iconmaker.swift+++ b/helpers/iconmaker.swift@@ -1,20 +1,32 @@// Reads an image and produces a macOS .icns masked to the continuous rounded// 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> <output.icns>+// Usage: iconmaker <input-image|input.exe> <output.icns>import AppKitimport Foundationguard CommandLine.arguments.count == 3 else {- fputs("usage: iconmaker <input-image> <output.icns>\n", stderr)+ fputs("usage: iconmaker <input-image|input.exe> <output.icns>\n", stderr)exit(1)}let inputPath = CommandLine.arguments[1]let outputPath = CommandLine.arguments[2]-guard let srcImage = NSImage(contentsOfFile: inputPath) else {+private func loadImage(_ path: String) -> NSImage? {+ var length = 0+ if let raw = np_pe_icon_ico(path, &length) {+ let ico = Data(bytesNoCopy: raw, count: length, deallocator: .free)+ if !ico.isEmpty, let image = NSImage(data: ico) {+ FileHandle.standardError.write(Data("iconmaker: using icon from PE resources\n".utf8))+ return image+ }+ }+ return NSImage(contentsOfFile: path)+}++guard let srcImage = loadImage(inputPath) else {fputs("iconmaker: cannot read \(inputPath)\n", stderr)exit(1)}diff --git a/signatures/macos.arm64/1788400362.json b/signatures/macos.arm64/1788400362.jsonindex 009b37a..6c1321f 100644--- a/signatures/macos.arm64/1788400362.json+++ b/signatures/macos.arm64/1788400362.json@@ -167,6 +167,36 @@"kind": "string","value": "GetWildcardMapping: Invalid unAppID k_nAppIdAll"}+ },+ {+ "name": "steamui::ShortcutExtensionMatches",+ "module": "steamui.dylib",+ "aob_hex": "F4 4F BE A9 FD 7B 01 A9 FD 43 00 91 F3 03 01 AA 00 00 40 F9 ?? ?? ?? ?? C0 00 00 B4 61 02 40 F9 02 00 B0 12 ?? ?? ?? ?? 1F 00 00 71 E0 17 9F 1A FD 7B 41 A9 F4 4F C2 A8 C0 03 5F D6",+ "func_addr_this_build": "0x9ee44",+ "anchor": {+ "kind": "call_target",+ "value": "CSteamApp::GetShortcut() only valid for shortcuts",+ "call_path": [+ 5,+ 4+ ]+ }+ },+ {+ "name": "steamui::ShortcutIconRender",+ "module": "steamui.dylib",+ "aob_hex": "FF C3 01 D1 E9 23 02 6D F8 5F 03 A9 F6 57 04 A9 F4 4F 05 A9 FD 7B 06 A9 FD 83 01 91 F4 03 01 AA F5 03 00 AA ?? ?? ?? ??",+ "func_addr_this_build": "0x9ef90",+ "anchor": {+ "kind": "call_target",+ "value": "strIconDataBase64",+ "nth_xref": 2,+ "call_path": [+ 11,+ 3,+ 2+ ]+ }}]}diff --git a/signatures/macos.arm64/1789086785.json b/signatures/macos.arm64/1789086785.jsonindex be5ec37..b1ba94a 100644--- a/signatures/macos.arm64/1789086785.json+++ b/signatures/macos.arm64/1789086785.json@@ -164,6 +164,34 @@"kind": "string","value": "GetWildcardMapping: Invalid unAppID k_nAppIdAll"}+ },+ {+ "name": "steamui::ShortcutExtensionMatches",+ "module": "steamui.dylib",+ "aob_hex": "F4 4F BE A9 FD 7B 01 A9 FD 43 00 91 F3 03 01 AA 00 00 40 F9 ?? ?? ?? ?? C0 00 00 B4 61 02 40 F9 02 00 B0 12 ?? ?? ?? ?? 1F 00 00 71 E0 17 9F 1A FD 7B 41 A9 F4 4F C2 A8 C0 03 5F D6",+ "anchor": {+ "kind": "call_target",+ "value": "CSteamApp::GetShortcut() only valid for shortcuts",+ "call_path": [+ 5,+ 4+ ]+ }+ },+ {+ "name": "steamui::ShortcutIconRender",+ "module": "steamui.dylib",+ "aob_hex": "FF C3 01 D1 E9 23 02 6D F8 5F 03 A9 F6 57 04 A9 F4 4F 05 A9 FD 7B 06 A9 FD 83 01 91 F4 03 01 AA F5 03 00 AA ?? ?? ?? ??",+ "anchor": {+ "kind": "call_target",+ "value": "strIconDataBase64",+ "nth_xref": 2,+ "call_path": [+ 11,+ 3,+ 2+ ]+ }}]}