Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Mac app: skip the exFAT "._" files that break the pack

lucaszhongsj09bc20acb560
diff --git a/patches/0057-mac-app-keep-the-finder-files-of-an-exfat-volume.patch b/patches/0057-mac-app-keep-the-finder-files-of-an-exfat-volume.patch
new file mode 100644
index 00000000..d14b864f
--- /dev/null
+++ b/patches/0057-mac-app-keep-the-finder-files-of-an-exfat-volume.patch
@@ -0,0 +1,169 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: lucaszhongsj <[email protected]>
+Date: Mon, 2 Nov 2026 04:33:47 +0800
+Subject: [PATCH] mac app: keep the Finder "._" files of an exFAT volume out of
+ the bundle
+
+On a volume without native extended attributes (exFAT, the build folder or
+the output on an external drive) each file's attributes live in a "._name"
+file beside it, which breaks the pack four ways: the input globs take those
+names for modules, shaders and fonts and the fixups check fails on one,
+copystat cannot set the flags of a copy (chflags: Operation not permitted),
+a recursive copy carries the sidecars into the app, and codesign reads the
+one beside the launcher as a code object that is not signed and refuses the
+whole bundle: "code object is not signed at all", In subcomponent.
+
+Skip them in the globs, copy without extended attributes (-X, cp rejects
+it together with -c) and with shutil.copy instead of copy2 for the host,
+and strip what a copy or the compiler leaves from the staged bundle before
+codesign reads it, retrying with the attributes cleared if it refuses one.
+Strip again afterwards: codesign sets an attribute on what it signs.
+
+Upstream-Status: pending
+Reason: a build folder or an app on exFAT keeps every file's attributes in a ._name file beside it: the inputs, the copies and codesign all break on them (issue #486)
+Issue: LNPANDY/NX2Apple#486
+
+---
+ dm/mac/pack_app.py | 38 ++++++++++++++++++++++--------
+ dm/tools/tests/test_nsp_mac_app.py | 18 +++++++++++++-
+ 2 files changed, 45 insertions(+), 11 deletions(-)
+
+diff --git a/dm/mac/pack_app.py b/dm/mac/pack_app.py
+index 48f2ac9..f974315 100755
+--- a/dm/mac/pack_app.py
++++ b/dm/mac/pack_app.py
+@@ -8,7 +8,8 @@
+ # plus AppIcon.icns from the game's icon (sips, iconutil) and the Info.plist keys the launcher reads (DMTitleID, DMRomfsMarker, DMLanguage).
+ # The large folders are APFS clones (cp -c) when the app is on the same APFS volume as the build, so they take no space; plain copies otherwise.
+ # Signing: the inner host first, then the bundle (codesign --force --sign <identity>; '-' = ad-hoc), without the hardened runtime: the host maps the game's code executable, which the hardened
+-# runtime refuses without entitlements, and so the app cannot be notarized.
++# runtime refuses without entitlements, and so the app cannot be notarized. The bundle is stripped of its "._name" files first: on exFAT (an external drive for the build or the app) every
++# file's extended attributes live in such a file beside it, and codesign reads each one as a code object that is not signed, which fails the whole bundle.
+ # Usage: pack_app.py <out.app> --host <dmhost> --patched <dir> --romfs <image or dir> --msl <dir> --tables <profile dir> --font <dir> --title-id <id> --name <name> [options]
+ # Reuses <out.app> while <out.app>.key matches; otherwise writes <out.app>.partial and swaps it in at the end. Prints "step: ..." and "app: <path>[, reused (inputs unchanged)]".
+ import argparse, ctypes, hashlib, json, os, plistlib, re, shutil, stat, subprocess, sys, tempfile
+@@ -25,11 +26,16 @@ TABLES = ('shader_map.tsv', 'pso_manifest.tsv', 'c1_full.tsv', 'cb_extent.tsv',
+ PSO_FILES = ('*.mtl4a', 'prebuilt.tsv', 'rest_pairs.tsv', 'archive.tsv') # what the app takes of pso_offline.py's output folder
+ EXE = 'nxnative' # the launcher's file name (Contents/MacOS/nxnative)
+ ICON_SIZES = (16, 32, 128, 256, 512)
++DETRITUS = ('.DS_Store',) # Finder leftovers beside the AppleDouble "._name" files, see detritus() and strip_detritus()
+
+
+ def step(msg): print(f'step: {msg}', flush=True)
+
+
++def detritus(name): # a volume without native extended attributes (exFAT, an external drive) keeps each file's attributes in a "._name" file beside it: not an input, and not something the bundle may carry
++ return name.startswith('._') or name in DETRITUS
++
++
+ def run(cmd):
+ r = subprocess.run([str(c) for c in cmd], capture_output=True, text=True)
+ if r.returncode: raise SystemExit(f'{Path(str(cmd[0])).name} failed ({r.returncode}): {(r.stderr or r.stdout).strip()[-1500:]}')
+@@ -58,8 +64,8 @@ def tree_bytes(d):
+ return sum((Path(r) / f).stat().st_size for r, _, fs in os.walk(d) for f in fs)
+
+
+-def copy(srcs, dst, clone): # cp -R of each source to dst (a new path for one folder, an existing folder for files); -c clones (batched under ARG_MAX)
+- cmd = ['/bin/cp', '-R'] + (['-c'] if clone else [])
++def copy(srcs, dst, clone): # cp -R of each source to dst (a new path for one folder, an existing folder for files); -c clones, -X keeps a copy's extended attributes out of the app (cp rejects -c -X together)
++ cmd = ['/bin/cp', '-R'] + (['-c'] if clone else ['-X'])
+ pointer = ctypes.sizeof(ctypes.c_void_p)
+ def arg_bytes(p): return len(os.fsencode(p)) + 1 + pointer
+ # exec's limit includes encoded strings, NULs and argv/envp pointers. Reserve 2 KiB for alignment and platform overhead (as POSIX xargs does).
+@@ -141,13 +147,25 @@ def source_commit(): # DMCommit: the checkout that packed the app (scripts/bug
+ return head + ('+dirty' if dirty else '') if head else None
+
+
++def strip_detritus(app): # the "._name" files a copy from or onto an exFAT volume leaves in the bundle: codesign reads each one as a code object and refuses the bundle ("code object is not signed at all")
++ for parent, _, files in os.walk(app):
++ for n in files:
++ if detritus(n):
++ try: (Path(parent) / n).unlink()
++ except OSError: pass # a ._ file the volume maps to the attributes of the file it belongs to: gone with them
++
++
+ def sign(app, identity, codesign): # the inner host first, then the bundle (its resources and the launcher); no --options runtime (see the top)
++ strip_detritus(app) # before codesign reads the bundle, so that a build folder or an output folder on exFAT is not a signing failure
+ host = app / 'Contents/MacOS/dmhost'
+ for target in (host, app):
+ try: run([codesign, '--force', '--sign', identity, target])
+ except SystemExit as e:
+- if 'detritus' not in str(e): raise
+- run(['xattr', '-cr', app]); run([codesign, '--force', '--sign', identity, target]) # Finder information or resource forks on copied files: codesign refuses them
++ if not any(s in str(e) for s in ('detritus', '._', 'not signed at all')): raise
++ subprocess.run(['xattr', '-cr', str(app)], capture_output=True) # Finder information or resource forks on copied files: codesign refuses them
++ strip_detritus(app)
++ run([codesign, '--force', '--sign', identity, target])
++ strip_detritus(app) # codesign sets an attribute on what it signs, which is a "._name" file again on exFAT: the signature still verifies without it, and a later --force would refuse it
+
+
+ def digest(path):
+@@ -177,19 +195,19 @@ def selected_inputs(a):
+ p = getattr(a, name)
+ if p and not (rfs.Path(p).is_dir() if name == 'romfs' else Path(p).is_dir()): raise SystemExit(f'no {name} directory at {p}')
+ if a.marker and not (rfs.Path(a.romfs) / a.marker).exists(): raise SystemExit(f'no RomFS at {a.romfs} (missing {a.marker})')
+- mods = sorted({p for pat in MODULE_FILES for p in Path(a.patched).glob(pat)})
++ mods = sorted({p for pat in MODULE_FILES for p in Path(a.patched).glob(pat) if not detritus(p.name)})
+ if not any(p.name.endswith('.patched.bin') for p in mods): raise SystemExit(f'no rewritten module in {a.patched}')
+ for p in mods:
+ if p.name.endswith('.patched.bin') and not p.with_name(p.name.removesuffix('.patched.bin') + '.fixups.tsv').is_file():
+ raise SystemExit(f'no rewriter fixups for {p}')
+- msls = sorted(p for pat in MSL_FILES for p in Path(a.msl).glob(pat) if p.is_file() and p.name != '_b_build.json')
++ msls = sorted(p for pat in MSL_FILES for p in Path(a.msl).glob(pat) if p.is_file() and p.name != '_b_build.json' and not detritus(p.name))
+ if not any(p.suffix == '.metallib' for p in msls): raise SystemExit(f'no shader libraries at {a.msl}')
+- pso = sorted({p for pat in PSO_FILES for p in Path(a.pso).glob(pat)}) if a.pso else []
++ pso = sorted({p for pat in PSO_FILES for p in Path(a.pso).glob(pat) if not detritus(p.name)}) if a.pso else []
+ if a.pso and (not any(p.suffix == '.mtl4a' for p in pso) or not (Path(a.pso) / 'prebuilt.tsv').is_file()):
+ raise SystemExit(f'no pipeline archive with its prebuilt.tsv in {a.pso}')
+ tables = [Path(a.tables) / n for n in TABLES if (Path(a.tables) / n).is_file()]
+ pairs = Path(a.pso_pairs) if a.pso_pairs and not any(p.name == 'pso_pairs.tsv' for p in tables) else None
+- fonts = sorted(Path(a.font).glob('*.ttf'))
++ fonts = sorted(p for p in Path(a.font).glob('*.ttf') if not detritus(p.name))
+ files = [Path(a.host)] + mods + msls + pso + tables + fonts + ([pairs] if pairs else [])
+ files += [Path(p) for p in (a.env_file, a.settings, a.icon) if p]
+ for p in files:
+@@ -257,7 +275,7 @@ def pack(a):
+ if need + (1 << 30) > free: raise SystemExit(f'the app needs {need / 2**30:.1f} GB on the volume of {out.parent} (no APFS clones from the build there) and {free / 2**30:.1f} GB are free')
+ step(f'launcher and host ({"clones" if clone["romfs"] else "copies"} of the game files)')
+ build_launcher(mac / EXE, minos, clang, swiftc, sdk)
+- shutil.copy2(a.host, mac / 'dmhost')
++ shutil.copy(a.host, mac / 'dmhost') # data and mode, not the build's extended attributes (copy2 would carry them into the app)
+ copy(mods, dm, clone['mods'])
+ if tables: copy(tables, dm, False)
+ if pairs: shutil.copyfile(pairs, dm / 'pso_pairs.tsv') # the split's copy, for a profile without the table
+diff --git a/dm/tools/tests/test_nsp_mac_app.py b/dm/tools/tests/test_nsp_mac_app.py
+index 958926b..0fdd6e4 100644
+--- a/dm/tools/tests/test_nsp_mac_app.py
++++ b/dm/tools/tests/test_nsp_mac_app.py
+@@ -58,7 +58,7 @@ class Copy(unittest.TestCase):
+ pack_app.copy(iter(srcs), dst, clone)
+ self.assertGreater(run.call_count, 1)
+ copied = []
+- flags = ['/bin/cp', '-R'] + (['-c'] if clone else [])
++ flags = ['/bin/cp', '-R'] + (['-c'] if clone else ['-X']) # a clone keeps the attributes, a copy leaves them out (cp rejects -c -X)
+ for call in run.call_args_list:
+ cmd = call.args[0]
+ self.assertEqual(cmd[:len(flags)], flags); self.assertEqual(cmd[-1], dst)
+@@ -272,6 +272,22 @@ class PackReuse(unittest.TestCase):
+ self.assertFalse((dm / 'c1_full.tsv').exists())
+ (self.tmp / 'patched/new.patched.bin').unlink(); (self.tmp / 'patched/new.fixups.tsv').unlink(); self.assert_repacked()
+
++ def test_finder_detritus_is_not_an_input_and_never_reaches_the_bundle(self):
++ # An exFAT build folder (an external drive) keeps a file's extended attributes in a "._name" file beside it: taken as an input they would be packed as a module or a
++ # shader, and left in the bundle they fail codesign ("code object is not signed at all", In subcomponent: Contents/MacOS/._nxnative).
++ for name in ('patched/._main.patched.bin', 'msl/._k.metallib', 'font/._nintendo_ext.ttf', 'pso/._gpu.mtl4a', 'romfs/._marker'):
++ (self.tmp / name).write_bytes(b'appledouble')
++ (self.tmp / 'romfs/.DS_Store').write_bytes(b'finder')
++ self.pack()
++ out = Path(self.args.out)
++ self.assertEqual(list(out.rglob('._*')), [])
++ self.assertEqual(list(out.rglob('.DS_Store')), [])
++ info = plistlib.loads((out / 'Contents/Info.plist').read_bytes())
++ self.assertEqual(info['DMModuleFiles'], ['main.cuts.tsv', 'main.fixups.tsv', 'main.gates.tsv', 'main.obs.tsv', 'main.patched.bin', 'nro.tsv'])
++ self.assertEqual(sorted(p.name for p in (out / 'Contents/Resources/dm/font').iterdir()), ['nintendo_ext.ttf'])
++ self.assertEqual(sorted(p.name for p in (out / 'Contents/Resources/pso').iterdir()), ['archive.tsv', 'gpu.mtl4a', 'prebuilt.tsv', 'rest_pairs.tsv'])
++ self.assert_reused()
++
+ def test_output_path_and_optional_inputs_invalidate(self):
+ self.pack()
+ old = Path(self.args.out); new = old.with_name('Other.app')
diff --git a/patches/series b/patches/series
index bc25b64e..ca92d972 100644
--- a/patches/series
+++ b/patches/series
@@ -34,3 +34,4 @@
0054-front-mac-start-with-the-pointer-hidden-when-the.patch
0055-ios-shell-declare-en-and-zh-hans-in-cfbundleloca.patch
0056-ios-shell-declare-every-language-of-frontend-l10.patch
+0057-mac-app-keep-the-finder-files-of-an-exfat-volume.patch