Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

Windows games that are added as non-Steam shortcuts are run with the global default compatibility tool

NotProtonNot1893a3a8672f
diff --git a/Makefile b/Makefile
index fdcfdd3..327889f 100644
--- a/Makefile
+++ b/Makefile
@@ -44,6 +44,7 @@ SRCS := \
dylib/feats/compat.c \
dylib/feats/webui.c \
dylib/feats/compatsvc.c \
+ dylib/feats/usershortcuts.c \
dylib/feats/webpatch.c \
dylib/feats/input_access.c \
vendor/cJSON.c
diff --git a/dylib/feats/compat.c b/dylib/feats/compat.c
index bb398ca..42a993d 100644
--- a/dylib/feats/compat.c
+++ b/dylib/feats/compat.c
@@ -2,6 +2,8 @@
#include "compat.h"
#include "../util/log.h"
#include "../util/file.h"
+#include "../util/a64.h"
+#include "../util/ptr.h"
#include <dirent.h>
#include <pthread.h>
@@ -20,6 +22,7 @@
#define TOOL_RUN "/run"
#define COMPAT_MANAGER_ENABLED_OFF 0x7B0
+#define COMPAT_MANAGER_USER_OFF 0x300 // CUser *
#define COMPAT_TOOL_STRIDE 0x130
#define COMPAT_TOOL_FLAGS_OFF 0x28 // bit 0: tool needs no downloaded app
#define COMPAT_TOOL_FLAG_NO_APP 0x1
@@ -266,6 +269,45 @@ uint32_t np_compat_enabled_off(void) {
return g_enabled_off;
}
+static uint32_t g_windows_only_off;
+
+int np_compat_probe_windows_only_off(uintptr_t get_wildcard_mapping, uintptr_t lookup) {
+ if (!get_wildcard_mapping || !lookup) return 0;
+
+ // The offset only exists in the code. Right before calling the lookup,
+ // GetWildcardMapping puts manager + offset in x0. An x0 built from SP is a
+ // local variable.
+ for (uintptr_t pc = get_wildcard_mapping; pc < get_wildcard_mapping + 0x100; pc += 4) {
+ uintptr_t target;
+ if (!a64_bl(pc, *(const uint32_t *)pc, &target) || target != lookup) continue;
+
+ for (int back = 1; back <= 4 && pc - 4u * back >= get_wildcard_mapping; back++) {
+ uint32_t rd, rn, imm;
+ if (a64_add_imm(*(const uint32_t *)(pc - 4u * back), &rd, &rn, &imm) &&
+ rd == 0 && rn != A64_SP) {
+ g_windows_only_off = imm;
+ NP_LOG("np_compat_probe_windows_only_off: windows-only table at 0x%x", imm);
+ return 1;
+ }
+ }
+ break;
+ }
+ NP_WARN("np_compat_probe_windows_only_off: no table argument for 0x%lx in 0x%lx",
+ (unsigned long)lookup, (unsigned long)get_wildcard_mapping);
+ return 0;
+}
+
+bool np_compat_is_windows_only_table(const void *compat_mgr, const void *map) {
+ return compat_mgr && g_windows_only_off &&
+ map == (const uint8_t *)compat_mgr + g_windows_only_off;
+}
+
+void *np_compat_user(const void *compat_mgr) {
+ if (!compat_mgr) return NULL;
+ uint64_t user = *(const uint64_t *)((const uint8_t *)compat_mgr + COMPAT_MANAGER_USER_OFF);
+ return np_plausible_ptr(user) ? (void *)(uintptr_t)user : NULL;
+}
+
uint32_t np_compat_tool_off(uint32_t reference_off) {
if (reference_off < COMPAT_TOOL_INSTALL_OFF) return reference_off;
return (uint32_t)((int32_t)reference_off + g_tool_shift);
diff --git a/dylib/feats/compat.h b/dylib/feats/compat.h
index 9ae2334..07d9c6e 100644
--- a/dylib/feats/compat.h
+++ b/dylib/feats/compat.h
@@ -40,6 +40,13 @@ int np_compat_probe_tool_layout(uintptr_t appid_gate, uintptr_t oslist_gate);
int np_compat_probe_enabled_off(uintptr_t bis_enabled);
uint32_t np_compat_enabled_off(void);
+// Reads the windows-only table's offset out of the lookup call in GetWildcardMapping,
+// returns 0 when the call is not found.
+int np_compat_probe_windows_only_off(uintptr_t get_wildcard_mapping, uintptr_t lookup);
+bool np_compat_is_windows_only_table(const void *compat_mgr, const void *map);
+
+void *np_compat_user(const void *compat_mgr);
+
// Live position of a field by its reference offset. Fields ahead of the
// insertion point come back unchanged.
uint32_t np_compat_tool_off(uint32_t reference_off);
diff --git a/dylib/feats/usershortcuts.c b/dylib/feats/usershortcuts.c
new file mode 100644
index 0000000..4f9355c
--- /dev/null
+++ b/dylib/feats/usershortcuts.c
@@ -0,0 +1,237 @@
+// Non-Steam shortcuts
+#include "usershortcuts.h"
+#include "../core/macho.h"
+#include "../resolver/anchor.h"
+#include "../util/a64.h"
+#include "../util/log.h"
+#include "../util/ptr.h"
+
+#include <mach/mach.h>
+#include <stdatomic.h>
+#include <stddef.h>
+#include <string.h>
+#include <strings.h>
+
+#define SHORTCUTS_TYPE "14CUserShortcuts"
+
+#define USER_SCAN_SPAN 0x10000
+#define SCAN_CHUNK 0x1000
+
+// CUtlRBTree node links, -1 for none.
+#define NODE_LEFT_OFF 0
+#define NODE_RIGHT_OFF 4
+#define NODE_NONE (-1)
+#define TREE_DEPTH_MAX 64
+
+// Set on every shortcut appid.
+#define SHORTCUT_APPID_BIT 0x80000000u
+
+#define SHORTCUT_SPAN 0x100
+
+#define PROBE_SPAN 0x180
+#define NOTIFY_SPAN 0x40
+#define NO_REG 32
+#define MOV_W0_1 0x52800020u
+
+typedef struct {
+ uint32_t root;
+ uint32_t nodes;
+ uint32_t stride;
+ uint32_t key;
+ uint32_t value;
+ uint32_t exe;
+ uint32_t remote;
+} layout_t;
+
+static layout_t g_layout;
+static int g_have_layout;
+static uintptr_t g_vptr;
+static _Atomic uint32_t g_shortcuts_off;
+static _Atomic uintptr_t g_scan_missed; // CUser the last scan came up empty on
+
+// Whether a shortcut belongs to Steam Remote Play is the first field the
+// "shortcut changed" event at the end of SetShortcutExe reads.
+static int probe_remote(uintptr_t notify, uint32_t *off) {
+ for (uintptr_t pc = notify; pc < notify + NOTIFY_SPAN; pc += 4) {
+ uint32_t rn, rt;
+ if (a64_ldr_uimm(*(const uint32_t *)pc, 1, &rn, &rt, off) && rn == 1) return 1;
+ }
+ return 0;
+}
+
+static int probe_layout(uintptr_t set_shortcut_exe, uintptr_t text, size_t text_sz) {
+ if (!set_shortcut_exe) return 0;
+
+ layout_t l = {0};
+ uint32_t nodes_reg = NO_REG, node_reg = NO_REG, value_reg = NO_REG;
+ int have_root = 0, have_key = 0, have_exe = 0;
+ uintptr_t last_bl = 0, notify = 0;
+
+ for (uintptr_t pc = set_shortcut_exe; pc < set_shortcut_exe + PROBE_SPAN; pc += 4) {
+ uint32_t w = *(const uint32_t *)pc, rd, rn, rt, imm;
+
+ if (!have_root && a64_ldr_uimm(w, 0, &rn, &rt, &imm) && rn == 0) {
+ l.root = imm;
+ have_root = 1;
+ } else if (nodes_reg == NO_REG && a64_ldr_uimm(w, 1, &rn, &rt, &imm) && rn == 0) {
+ l.nodes = imm;
+ nodes_reg = rt;
+ } else if (node_reg == NO_REG && nodes_reg != NO_REG &&
+ a64_add_lsl(w, &rd, &rn, &imm) && rn == nodes_reg) {
+ l.stride = imm < 32 ? 1u << imm : 0;
+ node_reg = rd;
+ } else if (node_reg != NO_REG && !have_key &&
+ a64_ldr_uimm(w, 0, &rn, &rt, &imm) && rn == node_reg) {
+ l.key = imm;
+ have_key = 1;
+ } else if (node_reg != NO_REG && value_reg == NO_REG &&
+ a64_ldr_uimm(w, 1, &rn, &rt, &imm) && rn == node_reg) {
+ l.value = imm;
+ value_reg = rt;
+ } else if (value_reg != NO_REG && !have_exe &&
+ a64_add_imm(w, &rd, &rn, &imm) && rd == 0 && rn == value_reg) {
+ l.exe = imm;
+ have_exe = 1;
+ } else if (have_exe && w == MOV_W0_1) {
+ notify = last_bl;
+ break;
+ } else if (have_exe) {
+ a64_bl(pc, w, &last_bl);
+ }
+ }
+
+ if (notify < text || notify + NOTIFY_SPAN > text + text_sz)
+ notify = 0;
+ if (!have_root || !have_key || !have_exe || !notify || !probe_remote(notify, &l.remote)) {
+ NP_WARN("np_usershortcuts_bind: 0x%lx does not read like SetShortcutExe "
+ "(root %d key %d exe %d notify 0x%lx)", (unsigned long)set_shortcut_exe,
+ have_root, have_key, have_exe, (unsigned long)notify);
+ return 0;
+ }
+ if (l.stride < 16 || l.stride > 64 || l.key + 4 > l.stride || l.value + 8 > l.stride) {
+ NP_ERR("np_usershortcuts_bind: node stride %u key 0x%x value 0x%x do not fit "
+ "a tree node", l.stride, l.key, l.value);
+ return 0;
+ }
+ if (l.exe + 8 > SHORTCUT_SPAN || l.remote + 8 > SHORTCUT_SPAN) {
+ NP_ERR("np_usershortcuts_bind: exe 0x%x remote 0x%x lie past a shortcut",
+ l.exe, l.remote);
+ return 0;
+ }
+
+ g_layout = l;
+ g_have_layout = 1;
+ NP_LOG("np_usershortcuts_bind: root 0x%x nodes 0x%x stride %u key 0x%x value 0x%x "
+ "exe 0x%x remote 0x%x", l.root, l.nodes, l.stride, l.key, l.value, l.exe, l.remote);
+ return 1;
+}
+
+int np_usershortcuts_bind(const struct mach_header_64 *mh, intptr_t slide,
+ uintptr_t set_shortcut_exe) {
+ uintptr_t text = 0;
+ size_t text_sz = 0;
+ if (mh && set_shortcut_exe &&
+ np_get_section_containing(mh, slide, set_shortcut_exe, &text, &text_sz) == 0)
+ g_vptr = np_rtti_vptr(mh, slide, text, text_sz, SHORTCUTS_TYPE);
+ if (!g_vptr)
+ NP_WARN("np_usershortcuts_bind: no %s vtable", SHORTCUTS_TYPE);
+
+ return probe_layout(set_shortcut_exe, text, text_sz) && g_vptr;
+}
+
+// The scan runs past the end of CUser, so a plain load could crash.
+static uint32_t find_shortcuts_off(uintptr_t user) {
+ uint8_t chunk[SCAN_CHUNK];
+ for (uint32_t base = 0; base < USER_SCAN_SPAN; base += SCAN_CHUNK) {
+ vm_size_t got = 0;
+ if (vm_read_overwrite(mach_task_self(), (vm_address_t)(user + base), SCAN_CHUNK,
+ (vm_address_t)chunk, &got) != KERN_SUCCESS)
+ return 0;
+ for (uint32_t i = 0; i + sizeof(uintptr_t) <= got; i += sizeof(uintptr_t)) {
+ uintptr_t v;
+ memcpy(&v, chunk + i, sizeof(v));
+ if (v == g_vptr) return base + i;
+ }
+ }
+ return 0;
+}
+
+static const uint8_t *user_shortcuts(const void *user) {
+ if (!np_plausible_ptr((uint64_t)(uintptr_t)user)) return NULL;
+
+ uint32_t off = atomic_load(&g_shortcuts_off);
+ if (!off) {
+ if (atomic_load(&g_scan_missed) == (uintptr_t)user) return NULL;
+ off = find_shortcuts_off((uintptr_t)user);
+ if (!off) {
+ atomic_store(&g_scan_missed, (uintptr_t)user);
+ NP_ERR("np_usershortcuts_runs_exe: no CUserShortcuts within 0x%x of CUser %p; "
+ "Windows shortcuts keep no default tool", USER_SCAN_SPAN, user);
+ return NULL;
+ }
+ atomic_store(&g_shortcuts_off, off);
+ NP_LOG("np_usershortcuts_runs_exe: CUserShortcuts at CUser+0x%x", off);
+ }
+
+ const uint8_t *shortcuts = (const uint8_t *)user + off;
+ if (*(const uintptr_t *)shortcuts != g_vptr) return NULL;
+ return shortcuts;
+}
+
+static void bad_table(const char *what, uint64_t v) {
+ static const char once = 0;
+ if (np_log_first_hit(&once, 0))
+ NP_ERR("np_usershortcuts_runs_exe: %s 0x%llx is not one this reads; "
+ "Windows shortcuts keep no default tool", what, (unsigned long long)v);
+}
+
+static const uint8_t *find_shortcut(const uint8_t *shortcuts, uint32_t appid) {
+ const uint8_t *nodes = *(const uint8_t *const *)(shortcuts + g_layout.nodes);
+ if (!np_plausible_ptr((uint64_t)(uintptr_t)nodes)) {
+ bad_table("node array", (uint64_t)(uintptr_t)nodes);
+ return NULL;
+ }
+
+ int32_t i = *(const int32_t *)(shortcuts + g_layout.root);
+ for (int depth = 0; i != NODE_NONE; depth++) {
+ if (i < 0 || depth == TREE_DEPTH_MAX) {
+ bad_table("node index", (uint32_t)i);
+ return NULL;
+ }
+ const uint8_t *node = nodes + (size_t)i * g_layout.stride;
+ uint32_t key = *(const uint32_t *)(node + g_layout.key);
+ if (key == appid) {
+ uint64_t shortcut = *(const uint64_t *)(node + g_layout.value);
+ if (np_plausible_ptr(shortcut)) return (const uint8_t *)(uintptr_t)shortcut;
+ bad_table("shortcut", shortcut);
+ return NULL;
+ }
+ i = *(const int32_t *)(node + (key > appid ? NODE_LEFT_OFF : NODE_RIGHT_OFF));
+ }
+ return NULL;
+}
+
+bool np_usershortcuts_runs_exe(const void *user, uint32_t appid) {
+ if (!(appid & SHORTCUT_APPID_BIT) || !g_have_layout || !g_vptr)
+ return false;
+
+ const uint8_t *shortcuts = user_shortcuts(user);
+ if (!shortcuts) return false;
+
+ const uint8_t *shortcut = find_shortcut(shortcuts, appid);
+ if (!shortcut) return false;
+
+ if (*(const uint64_t *)(shortcut + g_layout.remote) != 0) return false;
+
+ const char *exe = *(const char *const *)(shortcut + g_layout.exe);
+ if (!exe) return false;
+ if (!np_plausible_addr((uint64_t)(uintptr_t)exe)) {
+ bad_table("exe string", (uint64_t)(uintptr_t)exe);
+ return false;
+ }
+ if (!*exe) return false;
+
+ // Steam quotes a path picked with Browse.
+ const char *dot = strrchr(exe, '.');
+ return dot && (strcasecmp(dot + 1, "exe") == 0 || strcasecmp(dot + 1, "exe\"") == 0);
+}
diff --git a/dylib/feats/usershortcuts.h b/dylib/feats/usershortcuts.h
new file mode 100644
index 0000000..e920365
--- /dev/null
+++ b/dylib/feats/usershortcuts.h
@@ -0,0 +1,18 @@
+// Non-Steam shortcuts
+#ifndef NOTPROTON_FEATS_USERSHORTCUTS_H
+#define NOTPROTON_FEATS_USERSHORTCUTS_H
+
+#include <mach-o/loader.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+// Finds the CUserShortcuts vtable and reads the table layout out of SetShortcutExe,
+// returns 1 when both are found.
+int np_usershortcuts_bind(const struct mach_header_64 *mh, intptr_t slide,
+ uintptr_t set_shortcut_exe);
+
+// True for a shortcut to a Windows .exe that isn't from Steam Remote Play.
+// Linux Steam runs these with the default compatibility tool.
+bool np_usershortcuts_runs_exe(const void *user, uint32_t appid);
+
+#endif // NOTPROTON_FEATS_USERSHORTCUTS_H
diff --git a/dylib/hooks/hook_compat.c b/dylib/hooks/hook_compat.c
index a896877..d2aada0 100644
--- a/dylib/hooks/hook_compat.c
+++ b/dylib/hooks/hook_compat.c
@@ -2,6 +2,7 @@
#include "hooks.h"
#include "../feats/compat.h"
#include "../feats/compatsvc.h"
+#include "../feats/usershortcuts.h"
#include "../util/ptr.h"
#include "../util/log.h"
#include <stdint.h>
@@ -89,6 +90,30 @@ static void *hook_FindToolForTargetApp(void *self, uint32_t appid) {
return crossover;
}
+static void *orig_WindowsOnlyLookup = NULL;
+// Returns a bool, but the whole register is passed through in case this resolves
+// to the wrong function.
+typedef uint64_t (*fn_WindowsOnlyLookup)(const void *map, const uint32_t *appid,
+ const uint8_t *fallback);
+
+static uint64_t hook_WindowsOnlyLookup(const void *map, const uint32_t *appid,
+ const uint8_t *fallback) {
+ fn_WindowsOnlyLookup orig = (fn_WindowsOnlyLookup)orig_WindowsOnlyLookup;
+ if (!orig) {
+ static const char once = 0;
+ if (np_log_first_hit(&once, 0))
+ NP_ERR("hook_WindowsOnlyLookup: no original, reporting every key missing");
+ return fallback ? *fallback : 0;
+ }
+ uint64_t found = orig(map, appid, fallback);
+ if ((uint32_t)found || !appid)
+ return found;
+ void *mgr = np_compat_manager();
+ if (!np_compat_is_windows_only_table(mgr, map))
+ return found;
+ return np_usershortcuts_runs_exe(np_compat_user(mgr), *appid);
+}
+
static void *orig_InternalSpecifyCompatTool = NULL;
typedef uint64_t (*fn_InternalSpecifyCompatTool)(void *self, uint64_t appid,
const char *name, void *config,
@@ -203,6 +228,12 @@ static np_patch_entry_t g_hooks[] = {
.entry = (void *)hook_FindToolForTargetApp,
.trampoline = &orig_FindToolForTargetApp,
},
+ {
+ .label = "CCompatManager::WindowsOnlyLookup",
+ .signature = "CCompatManager::WindowsOnlyLookup",
+ .entry = (void *)hook_WindowsOnlyLookup,
+ .trampoline = &orig_WindowsOnlyLookup,
+ },
{
.label = "CCompatManager::InternalSpecifyCompatTool",
.signature = "CCompatManager::InternalSpecifyCompatTool",
diff --git a/dylib/hooks/hooks.c b/dylib/hooks/hooks.c
index cb773d2..a306215 100644
--- a/dylib/hooks/hooks.c
+++ b/dylib/hooks/hooks.c
@@ -4,6 +4,7 @@
#include "../core/macho.h"
#include "../feats/webui.h"
#include "../feats/compat.h"
+#include "../feats/usershortcuts.h"
#include "../util/log.h"
#include <stdlib.h>
#include <string.h>
@@ -133,6 +134,11 @@ int np_hooks_install_all(const struct mach_header_64 *mh, intptr_t slide,
np_lookup_address(resolved, "CCompatManager::GetOSListOverrideForApp.oslist_gate"));
np_compat_probe_enabled_off(
np_lookup_address(resolved, "CCompatManager::BIsCompatibilityToolEnabled"));
+ np_compat_probe_windows_only_off(
+ np_lookup_address(resolved, "CCompatManager::GetWildcardMapping"),
+ np_lookup_address(resolved, "CCompatManager::WindowsOnlyLookup"));
+ np_usershortcuts_bind(mh, slide,
+ np_lookup_address(resolved, "CUserShortcuts::SetShortcutExe"));
uintptr_t register_fn = np_lookup_address(resolved,
"CWebUIJobDispatcher::RegisterHandler");
diff --git a/dylib/tests/anchorcheck.c b/dylib/tests/anchorcheck.c
index ae73882..cc341d5 100644
--- a/dylib/tests/anchorcheck.c
+++ b/dylib/tests/anchorcheck.c
@@ -159,6 +159,7 @@ static const struct { uint64_t build; const char *type_name; uintptr_t vptr; } e
{1790904859, "40CCompatManager_SpecifyCompatTool_Request", 0x16ad2b0},
{1790904859, "41CCompatManager_SpecifyCompatTool_Response", 0x16ad360},
{1790904859, "40CCompatManager_StateChanged_Notification", 0x16ad410},
+ {1790904859, "14CUserShortcuts", 0x1793de0},
};
static int run_rtti(const struct mach_header_64 *mh, intptr_t slide,
diff --git a/dylib/tests/compatcheck.c b/dylib/tests/compatcheck.c
index dde5d90..8b5521d 100644
--- a/dylib/tests/compatcheck.c
+++ b/dylib/tests/compatcheck.c
@@ -2,6 +2,7 @@
// reaches it through a function pointer an installer sets. Including the unit rather than
// linking points the probes at synthesised instructions and the pointers at stubs. No Steam.
#include "../feats/compat.c"
+#include "../feats/usershortcuts.c"
#include <stdio.h>
#include <pthread.h>
@@ -27,6 +28,18 @@ const char *np_home_dir(void) {
return "/nonexistent";
}
+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) {
+ (void)mh; (void)slide; (void)addr; (void)out_base; (void)out_size;
+ return -1;
+}
+
+uintptr_t np_rtti_vptr(const struct mach_header_64 *mh, intptr_t slide,
+ uintptr_t text_base, size_t text_size, const char *type_name) {
+ (void)mh; (void)slide; (void)text_base; (void)text_size; (void)type_name;
+ return 0;
+}
+
static int failures;
static void check(int ok, const char *what) {
@@ -446,6 +459,206 @@ static void installed_fn_cases(void) {
check(last_priority == 0, "mapping an app to no tool at all reaches the client as nothing");
}
+static const uint32_t SET_SHORTCUT_EXE[] = {
+ 0xD10103FF, 0xA90157F6, 0xA9024FF4, 0xA9037BFD, 0x9100C3FD, 0xAA0303F3, 0xB940380A,
+ 0x3100055F, 0x54000200, 0xAA0003F4, 0xF9402808, 0x91001109, 0x93407D4A, 0x8B0A150B,
+ 0xB940116D, 0xAA0803EC, 0x6B0101BF, 0x54000068, 0xAA0903EC, 0x54000222, 0xD37BE94A,
+ 0xB86A698A, 0x3100055F, 0x54FFFEA1, 0xB40000D3, 0xF90003E1, 0x900056E1, 0x912B9021,
+ 0xAA1303E0, 0x94167236, 0x52800000, 0xA9437BFD, 0xA9424FF4, 0xA94157F6, 0x910103FF,
+ 0xD65F03C0, 0xF9400D75, 0x910042A0, 0xAA0203E1, 0x9416718C, 0xAA1503E0, 0xAA1303E1,
+ 0x9400000B, 0xB40000B3, 0xF9400268, 0xB4000068, 0x39400108, 0x35FFFDE8, 0xAA1403E0,
+ 0xAA1503E1, 0x97FFFDB6, 0x52800020, 0x17FFFFEB,
+};
+#define SET_EXE_NOTIFY_BL 50
+
+static const uint32_t SHORTCUT_NOTIFY[] = {
+ 0xD100C3FF, 0xA9014FF4, 0xA9027BFD, 0x910083FD, 0xAA0003F3, 0xB9400028, 0xB9000BE8,
+ 0xF9403428, 0xF100011F, 0x1A9F07E8, 0x390033E8, 0xF9400414,
+};
+
+static const uint32_t GET_WILDCARD_MAPPING[] = {
+ 0xD10143FF, 0xA90257F6, 0xA9034FF4, 0xA9047BFD, 0x910103FD, 0x34000541, 0xAA0103F4,
+ 0xAA0003F5, 0xB90017FF, 0x910FE000, 0x910053E1, 0x97FFFF0B, 0xAA0003F3, 0xB4000180,
+ 0xF9400268, 0xB9401108, 0x7103E91F, 0x5400010B, 0xF90003F4, 0xF0008E20, 0x912A6000,
+ 0x900077E1, 0x91024C21, 0x97E8D865, 0x14000023, 0xB9001FF4, 0x39006FFF, 0x911A62A0,
+ 0x910073E1, 0x91006FE2, 0x97FF0A8C, 0x340003C0,
+};
+#define WILDCARD_LOOKUP_BL 30
+
+#define NOTIFY_AT 64
+
+static uintptr_t bl_dest(const uint32_t *at) {
+ uintptr_t target = 0;
+ a64_bl((uintptr_t)at, *at, &target);
+ return target;
+}
+
+static void shortcut_probe_cases(void) {
+ static uint32_t code[NOTIFY_AT + 16];
+ memcpy(code, SET_SHORTCUT_EXE, sizeof(SET_SHORTCUT_EXE));
+ memcpy(code + NOTIFY_AT, SHORTCUT_NOTIFY, sizeof(SHORTCUT_NOTIFY));
+ code[SET_EXE_NOTIFY_BL] = 0x94000000u | (uint32_t)(NOTIFY_AT - SET_EXE_NOTIFY_BL);
+
+ check(probe_layout((uintptr_t)code, (uintptr_t)code, sizeof(code)) == 1,
+ "SetShortcutExe gives up the table layout");
+ check(g_layout.root == 0x38 && g_layout.nodes == 0x50 && g_layout.stride == 32,
+ "the tree root, node array and stride come from the walk");
+ check(g_layout.key == 0x10 && g_layout.value == 0x18,
+ "a node keys on the appid and points at the shortcut");
+ check(g_layout.exe == 0x10 && g_layout.remote == 0x68,
+ "the exe string and the remote id come from the setter and its notify");
+
+ layout_t kept = g_layout;
+ code[SET_EXE_NOTIFY_BL] = 0xD503201Fu;
+ check(probe_layout((uintptr_t)code, (uintptr_t)code, sizeof(code)) == 0,
+ "a setter that never notifies is refused");
+ check(memcmp(&g_layout, &kept, sizeof(kept)) == 0, "a refused walk keeps the last layout");
+ check(probe_layout(0, 0, 0) == 0, "an unresolved setter is refused");
+ code[SET_EXE_NOTIFY_BL] = 0x94000000u | (uint32_t)(NOTIFY_AT - SET_EXE_NOTIFY_BL);
+ check(probe_layout((uintptr_t)code, (uintptr_t)code, NOTIFY_AT * 4) == 0,
+ "a notify outside the text section is refused");
+
+ const uint32_t *call = &GET_WILDCARD_MAPPING[WILDCARD_LOOKUP_BL];
+ check(np_compat_probe_windows_only_off((uintptr_t)GET_WILDCARD_MAPPING,
+ bl_dest(call)) == 1,
+ "the lookup call in GetWildcardMapping gives up its table");
+ check(g_windows_only_off == 0x698, "the table is the call's first argument");
+
+ g_windows_only_off = 0;
+ check(np_compat_probe_windows_only_off((uintptr_t)GET_WILDCARD_MAPPING,
+ bl_dest(call) + 4) == 0,
+ "a lookup GetWildcardMapping never calls is refused");
+ check(g_windows_only_off == 0, "a refused probe leaves no table");
+}
+
+#define TEST_USER_SIZE 0x10000
+#define TEST_SHORTCUTS_OFF 0x5CC8
+#define TEST_GATE_OFF 0x698
+#define TEST_MANAGER_SIZE 0x800
+
+typedef struct {
+ uint8_t *mgr;
+ uint8_t *user;
+ uint8_t nodes[3][32];
+ uint8_t *shortcut[3];
+} shortcut_world_t;
+
+static const uint32_t world_appid[3] = { 0x80000002u, 0x80000001u, 0x80000003u };
+
+static void put_node(shortcut_world_t *w, int i, int32_t left, int32_t right) {
+ memcpy(w->nodes[i] + NODE_LEFT_OFF, &left, sizeof(left));
+ memcpy(w->nodes[i] + NODE_RIGHT_OFF, &right, sizeof(right));
+ memcpy(w->nodes[i] + 0x10, &world_appid[i], sizeof(uint32_t));
+ memcpy(w->nodes[i] + 0x18, &w->shortcut[i], sizeof(uint8_t *));
+}
+
+static void set_exe(shortcut_world_t *w, int i, const char *exe) {
+ memcpy(w->shortcut[i] + 0x10, &exe, sizeof(exe));
+}
+
+static void build_world(shortcut_world_t *w) {
+ w->mgr = calloc(1, TEST_MANAGER_SIZE);
+ w->user = calloc(1, TEST_USER_SIZE);
+ memcpy(w->mgr + COMPAT_MANAGER_USER_OFF, &w->user, sizeof(w->user));
+
+ uint8_t *shortcuts = w->user + TEST_SHORTCUTS_OFF;
+ memcpy(shortcuts, &g_vptr, sizeof(g_vptr));
+ int32_t root = 0;
+ memcpy(shortcuts + 0x38, &root, sizeof(root));
+ uint8_t *nodes = &w->nodes[0][0];
+ memcpy(shortcuts + 0x50, &nodes, sizeof(nodes));
+
+ for (int i = 0; i < 3; i++) w->shortcut[i] = calloc(1, 0x80);
+ put_node(w, 0, 1, 2);
+ put_node(w, 1, NODE_NONE, NODE_NONE);
+ put_node(w, 2, NODE_NONE, NODE_NONE);
+}
+
+static void free_world(shortcut_world_t *w) {
+ for (int i = 0; i < 3; i++) free(w->shortcut[i]);
+ free(w->user);
+ free(w->mgr);
+}
+
+static void shortcut_exe_cases(void) {
+ static const char vptr_target = 0;
+ g_vptr = (uintptr_t)&vptr_target;
+ atomic_store(&g_shortcuts_off, 0);
+ atomic_store(&g_scan_missed, 0);
+
+ shortcut_world_t w = {0};
+ build_world(&w);
+
+ set_exe(&w, 0, "\"C:\\Games\\Game.EXE\"");
+ set_exe(&w, 1, "/Applications/Game/run.exe");
+ set_exe(&w, 2, "\"/Applications/Game.app\"");
+
+ check(np_usershortcuts_runs_exe(w.user, world_appid[0]), "a quoted browsed exe takes the default");
+ check(atomic_load(&g_shortcuts_off) == TEST_SHORTCUTS_OFF,
+ "the table is found inside CUser by its vptr");
+ check(np_usershortcuts_runs_exe(w.user, world_appid[1]), "a typed unquoted exe takes the default");
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[2]), "a Mac app is left alone");
+ check(!np_usershortcuts_runs_exe(w.user, 0x80000004u), "an appid with no shortcut is left alone");
+ check(!np_usershortcuts_runs_exe(w.user, 0x00000002u), "a Steam appid is never a shortcut");
+ check(!np_usershortcuts_runs_exe(NULL, world_appid[0]), "no user answers no");
+
+ set_exe(&w, 2, "C:\\Games\\setup.Exe");
+ check(np_usershortcuts_runs_exe(w.user, world_appid[2]), "the extension matches in any case");
+ set_exe(&w, 2, "C:\\Games\\launch.exe.bat");
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[2]), "only the last extension counts");
+ set_exe(&w, 2, "C:\\Games.exe\\launcher");
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[2]), "a dot in a folder name is no extension");
+ set_exe(&w, 2, "");
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[2]), "an empty exe is left alone");
+ set_exe(&w, 2, NULL);
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[2]), "a shortcut with no exe is left alone");
+ set_exe(&w, 2, (const char *)(uintptr_t)0x10);
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[2]), "an exe pointer below 4 GB is not read");
+ set_exe(&w, 2, &"C:\\Games\\setup.exe"[1]);
+ check(np_usershortcuts_runs_exe(w.user, world_appid[2]), "an unaligned exe string is still read");
+
+ put_node(&w, 2, NODE_NONE, 0);
+ check(!np_usershortcuts_runs_exe(w.user, 0x80000004u), "a looping tree stops at the depth cap");
+ put_node(&w, 2, NODE_NONE, -2);
+ check(!np_usershortcuts_runs_exe(w.user, 0x80000004u), "a corrupt node index stops the walk");
+ put_node(&w, 2, NODE_NONE, NODE_NONE);
+
+ uint64_t remote = 0x1234;
+ memcpy(w.shortcut[1] + 0x68, &remote, sizeof(remote));
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[1]), "a remote client's shortcut is left alone");
+ remote = 0;
+ memcpy(w.shortcut[1] + 0x68, &remote, sizeof(remote));
+
+ check(np_compat_user(w.mgr) == w.user, "the manager hands over its CUser");
+ g_windows_only_off = TEST_GATE_OFF;
+ check(np_compat_is_windows_only_table(w.mgr, w.mgr + TEST_GATE_OFF),
+ "the probed table is the windows-only one");
+ check(!np_compat_is_windows_only_table(w.mgr, w.mgr + TEST_GATE_OFF - 0x60),
+ "any other table is not");
+ check(!np_compat_is_windows_only_table(NULL, w.mgr + TEST_GATE_OFF),
+ "no manager has no table");
+ g_windows_only_off = 0;
+ check(!np_compat_is_windows_only_table(w.mgr, w.mgr),
+ "without a probed table nothing matches");
+
+ memset(w.user + TEST_SHORTCUTS_OFF, 0, sizeof(uintptr_t));
+ atomic_store(&g_shortcuts_off, 0);
+ check(!np_usershortcuts_runs_exe(w.user, world_appid[0]), "a CUser with no table answers no");
+ check(atomic_load(&g_scan_missed) == (uintptr_t)w.user, "the failed search is remembered");
+
+ uint8_t *other = calloc(1, TEST_USER_SIZE);
+ memcpy(other + TEST_SHORTCUTS_OFF, w.user + TEST_SHORTCUTS_OFF, 0x60);
+ memcpy(other + TEST_SHORTCUTS_OFF, &g_vptr, sizeof(g_vptr));
+ check(np_usershortcuts_runs_exe(other, world_appid[0]), "a new CUser is searched again");
+
+ int32_t empty = NODE_NONE;
+ memcpy(other + TEST_SHORTCUTS_OFF + 0x38, &empty, sizeof(empty));
+ check(!np_usershortcuts_runs_exe(other, world_appid[0]), "an empty tree has no shortcuts");
+ free(other);
+
+ free_world(&w);
+}
+
int main(void) {
concurrent_fallback_cases();
probe_cases();
@@ -456,6 +669,8 @@ int main(void) {
tool_launch_cases();
stale_tool_cases();
installed_fn_cases();
+ shortcut_probe_cases();
+ shortcut_exe_cases();
if (failures) {
printf("==> compat: %d check(s) failed\n", failures);
diff --git a/dylib/util/a64.h b/dylib/util/a64.h
new file mode 100644
index 0000000..754a4f6
--- /dev/null
+++ b/dylib/util/a64.h
@@ -0,0 +1,46 @@
+// arm64 instruction decoders
+#ifndef NOTPROTON_UTIL_A64_H
+#define NOTPROTON_UTIL_A64_H
+
+#include <stdint.h>
+
+#define A64_SP 31u
+
+// LDR Wt/Xt,[Xn,#imm], unsigned offset, scaled to bytes.
+static inline int a64_ldr_uimm(uint32_t w, int wide, uint32_t *rn, uint32_t *rt,
+ uint32_t *off) {
+ uint32_t op = wide ? 0xF9400000u : 0xB9400000u;
+ if ((w & 0xFFC00000u) != op) return 0;
+ *rt = w & 0x1Fu;
+ *rn = (w >> 5) & 0x1Fu;
+ *off = ((w >> 10) & 0xFFFu) * (wide ? 8u : 4u);
+ return 1;
+}
+
+// ADD Xd,Xn,#imm without the 12-bit shift.
+static inline int a64_add_imm(uint32_t w, uint32_t *rd, uint32_t *rn, uint32_t *imm) {
+ if ((w & 0xFFC00000u) != 0x91000000u) return 0;
+ *rd = w & 0x1Fu;
+ *rn = (w >> 5) & 0x1Fu;
+ *imm = (w >> 10) & 0xFFFu;
+ return 1;
+}
+
+// ADD Xd,Xn,Xm,LSL #imm.
+static inline int a64_add_lsl(uint32_t w, uint32_t *rd, uint32_t *rn, uint32_t *shift) {
+ if ((w & 0xFFE00000u) != 0x8B000000u) return 0;
+ *rd = w & 0x1Fu;
+ *rn = (w >> 5) & 0x1Fu;
+ *shift = (w >> 10) & 0x3Fu;
+ return 1;
+}
+
+static inline int a64_bl(uintptr_t pc, uint32_t w, uintptr_t *target) {
+ if ((w & 0xFC000000u) != 0x94000000u) return 0;
+ // Sign-extend 26 bits without signed left-shift overflow.
+ int64_t imm = (int64_t)((w & 0x03FFFFFFu) ^ 0x2000000u) - 0x2000000;
+ *target = pc + (uintptr_t)(imm * 4);
+ return 1;
+}
+
+#endif // NOTPROTON_UTIL_A64_H
diff --git a/dylib/util/ptr.h b/dylib/util/ptr.h
index 96962b4..e3d725f 100644
--- a/dylib/util/ptr.h
+++ b/dylib/util/ptr.h
@@ -4,9 +4,14 @@
#include <stdint.h>
-static inline int np_plausible_ptr(uint64_t v) {
+static inline int np_plausible_addr(uint64_t v) {
if (v < 0x100000000ULL) return 0; // below 4 GB (image/stack guard)
if (v >= 0x800000000000ULL) return 0; // kernel space
+ return 1;
+}
+
+static inline int np_plausible_ptr(uint64_t v) {
+ if (!np_plausible_addr(v)) return 0;
if (v & 0x7) return 0; // not 8-byte aligned
return 1;
}
diff --git a/signatures/macos.arm64/1788400362.json b/signatures/macos.arm64/1788400362.json
index 0e5507e..d0f7f7b 100644
--- a/signatures/macos.arm64/1788400362.json
+++ b/signatures/macos.arm64/1788400362.json
@@ -168,6 +168,25 @@
"value": "GetWildcardMapping: Invalid unAppID k_nAppIdAll"
}
},
+ {
+ "name": "CCompatManager::WindowsOnlyLookup",
+ "aob_hex": "",
+ "anchor": {
+ "kind": "call_target",
+ "value": "GetWildcardMapping: Invalid unAppID k_nAppIdAll",
+ "call_path": [
+ 3
+ ]
+ }
+ },
+ {
+ "name": "CUserShortcuts::SetShortcutExe",
+ "aob_hex": "FF 03 01 D1 F6 57 01 A9 F4 4F 02 A9 FD 7B 03 A9 FD C3 00 91 F3 03 03 AA 0A 38 40 B9 5F 05 00 31 ?? ?? ?? ?? F4 03 00 AA 08 28 40 F9 09 11 00 91 4A 7D 40 93 0B 15 0A 8B 6D 11 40 B9 EC 03 08 AA BF 01 01 6B ?? ?? ?? ?? EC 03 09 AA ?? ?? ?? ?? 4A E9 7B D3 8A 69 6A B8 5F 05 00 31 ?? ?? ?? ?? ?? ?? ?? ?? E1 03 00 F9",
+ "anchor": {
+ "kind": "string",
+ "value": "shortcut not found for app id %u"
+ }
+ },
{
"name": "LaunchBuilder::SteamVRSupportCheck",
"aob_hex": "F6 57 BD A9 F4 4F 01 A9 FD 7B 02 A9 FD 83 00 91 F3 03 01 AA 08 00 40 F9 08 29 40 F9 00 01 3F D6",
diff --git a/signatures/macos.arm64/1789086785.json b/signatures/macos.arm64/1789086785.json
index 1f3e16d..c25cc2d 100644
--- a/signatures/macos.arm64/1789086785.json
+++ b/signatures/macos.arm64/1789086785.json
@@ -165,6 +165,25 @@
"value": "GetWildcardMapping: Invalid unAppID k_nAppIdAll"
}
},
+ {
+ "name": "CCompatManager::WindowsOnlyLookup",
+ "aob_hex": "",
+ "anchor": {
+ "kind": "call_target",
+ "value": "GetWildcardMapping: Invalid unAppID k_nAppIdAll",
+ "call_path": [
+ 3
+ ]
+ }
+ },
+ {
+ "name": "CUserShortcuts::SetShortcutExe",
+ "aob_hex": "FF 03 01 D1 F6 57 01 A9 F4 4F 02 A9 FD 7B 03 A9 FD C3 00 91 F3 03 03 AA 0A 38 40 B9 5F 05 00 31 ?? ?? ?? ?? F4 03 00 AA 08 28 40 F9 09 11 00 91 4A 7D 40 93 0B 15 0A 8B 6D 11 40 B9 EC 03 08 AA BF 01 01 6B ?? ?? ?? ?? EC 03 09 AA ?? ?? ?? ?? 4A E9 7B D3 8A 69 6A B8 5F 05 00 31 ?? ?? ?? ?? ?? ?? ?? ?? E1 03 00 F9",
+ "anchor": {
+ "kind": "string",
+ "value": "shortcut not found for app id %u"
+ }
+ },
{
"name": "LaunchBuilder::SteamVRSupportCheck",
"aob_hex": "F6 57 BD A9 F4 4F 01 A9 FD 7B 02 A9 FD 83 00 91 F3 03 01 AA 08 00 40 F9 08 29 40 F9 00 01 3F D6",
diff --git a/signatures/macos.arm64/1790904859.json b/signatures/macos.arm64/1790904859.json
index 2af2d7b..11b7806 100644
--- a/signatures/macos.arm64/1790904859.json
+++ b/signatures/macos.arm64/1790904859.json
@@ -164,6 +164,27 @@
},
"func_addr_this_build": "0x6a503c"
},
+ {
+ "name": "CCompatManager::WindowsOnlyLookup",
+ "aob_hex": "",
+ "anchor": {
+ "kind": "call_target",
+ "value": "GetWildcardMapping: Invalid unAppID k_nAppIdAll",
+ "call_path": [
+ 3
+ ]
+ },
+ "func_addr_this_build": "0x66727c"
+ },
+ {
+ "name": "CUserShortcuts::SetShortcutExe",
+ "aob_hex": "FF 03 01 D1 F6 57 01 A9 F4 4F 02 A9 FD 7B 03 A9 FD C3 00 91 F3 03 03 AA 0A 38 40 B9 5F 05 00 31 ?? ?? ?? ?? F4 03 00 AA 08 28 40 F9 09 11 00 91 4A 7D 40 93 0B 15 0A 8B 6D 11 40 B9 EC 03 08 AA BF 01 01 6B ?? ?? ?? ?? EC 03 09 AA ?? ?? ?? ?? 4A E9 7B D3 8A 69 6A B8 5F 05 00 31 ?? ?? ?? ?? ?? ?? ?? ?? E1 03 00 F9",
+ "anchor": {
+ "kind": "string",
+ "value": "shortcut not found for app id %u"
+ },
+ "func_addr_this_build": "0xb03e44"
+ },
{
"name": "LaunchBuilder::SteamVRSupportCheck",
"aob_hex": "F6 57 BD A9 F4 4F 01 A9 FD 7B 02 A9 FD 83 00 91 F3 03 01 AA 08 00 40 F9 08 29 40 F9 00 01 3F D6",