Skip to content

shader_split: read encrypted legacy Unreal paks with the key from main - #1646

Closed
Haseenesss wants to merge 1 commit into
seedds:mainfrom
Haseenesss:ue-legacy-pak-key
Closed

Haseenesss wants to merge 1 commit into
seedds:mainfrom
Haseenesss:ue-legacy-pak-key

Conversation

@Haseenesss

@Haseenesss Haseenesss commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Little Nightmares II stopped at [RED] the shader split found no shaders in main or the RomFS. Its shaders are inline in the cooked packages of one legacy pak (version 8), as in Unreal Engine 4.18, but the pak's index and entries are AES-encrypted. ue_legacy_jobs opened legacy paks without a key, so the index did not parse and the pak was left out. The paks with shader code archives already took their key from main with uepak.find_key; the inline path did not.

The change:

  • ue_legacy_jobs(files, mains=...): when a pak's footer says the index is encrypted, it tries each main the split is given with uepak.find_key, and each job carries the key, so ue_legacy_shaders decrypts the entries too. With no key in any main the pak is reported in red and skipped, as other unreadable paks are.
  • uepak.find_key(..., first=()): keys found earlier are tried before code_keys and the windows, so a second pak of the same game does not search again.
  • A pak with no encryption gets the same job tuples as before.
  • docs/reference/shaders.md: the entry "An encrypted legacy Unreal pak with the shaders inline"; docs/agents/symptoms.md regenerated.

Reported in LNPANDY/NX2Apple#877, where this is carried as a patch until it lands here.

Checked

  • Tests: python3 -m unittest dm.tools.tests.test_uepak_legacy_key (new, 4 tests: a synthetic encrypted version 4 pak and main, no game files; the jobs carry the key, the next main is tried, no key gives the red line and skips the pak, a job reads the encrypted files) passes, and so do test_uepak_key, test_uepak_iostore, test_uepak_v8, test_split_unreadable, test_split_narc, test_split_viper, test_nsp_incremental, test_nsp_experimental_builder, test_romfs_read and test_docs.
  • Games run, with title ID and version: Little Nightmares II, 010097100EDD6000, 1.4 (v262144), Mac app with a provisional profile. Before: the split found 0 shaders. After: ✓ [5/8] shader split (9:38): 20,170 shaders from 57 files, and all 20,170 Mac shaders built. The game reaches the title screen at about 30 fps (1,064 draws per frame, every shader key in the shader map, no errors in the log), and it was played into the first chapter for a while with nothing wrong seen.
  • Devices and OS: Apple M2, macOS 27.2.
  • regress.py check (full, --runs 2) on Little Nightmares II 010097100EDD6000, the game I have whose pak takes this path (a pak without encryption gets the same jobs as before, and the chain and host are unchanged). The provisional profile has no smoke.tsv, so a local route was used for this check only (fresh save, no presses, the title screen; not committed). The REGRESSION is one run's frame p99 (51.05 ms in candidate run 2; 36.2 to 36.9 ms in the other three) while fps, screenshots, shaders, MSL, interface and [RED] lines are unchanged and both revisions run the same host and chain: load noise from other work on the Mac (prebuild 44 to 124 s from run to run). An earlier one-run check was discarded because stray key presses moved the baseline past the title screen.
report.md

regress.py check (full): REGRESSION

Baseline d99a161b6af312f9bac12673b5bf94edf81c1861^ d777f0a, candidate d99a161b6af312f9bac12673b5bf94edf81c1861 d99a161; Apple M2, macOS 27.2, Xcode 27.2; 726.6 s

game status shaders (base → cand) newly failing newly building changed MSL interface (new / known) boot fps p50 frame p99 ms peak MB prepare s new RED
Little Nightmares II 010097100EDD6000 REGRESSION 20170/20170 → 20170/20170 0 0 0 0 / 0 ok 29.9 → 29.8 36.66 → 51.05 2360 → 2362 None → None 0

Little Nightmares II 010097100EDD6000: REGRESSION

  • REGRESSION: frame p99 36.66 → 51.05 ms (+39.3 %)
  • known (baseline too): 4 shaders with bindless accesses the translator deleted
    • screenshots (s: dHash bits / RGB diff / baseline noise): 75: 1/0.3/0.22, 90: 0/0.31/0.13
    • baseline: exit None, first frame 25.9 s, max frame 1976, reached True, prepare None s, prebuild 44.7 s (3189 built, 0 failed), fps 29.9, p50/p99 34.69/36.66 ms, peak 2316 MB
    • baseline: exit None, first frame 26.2 s, max frame 1943, reached True, prepare None s, prebuild 124.2 s (3189 built, 0 failed), fps 29.8, p50/p99 34.67/36.19 ms, peak 2360 MB
    • candidate: exit None, first frame 26.4 s, max frame 1975, reached True, prepare None s, prebuild 54.9 s (3189 built, 0 failed), fps 29.8, p50/p99 34.71/36.9 ms, peak 2317 MB
    • candidate: exit None, first frame 23.3 s, max frame 1987, reached True, prepare None s, prebuild 70.4 s (3189 built, 0 failed), fps 29.1, p50/p99 33.41/51.05 ms, peak 2362 MB
    • time: chain 47.5 s, smoke 678.6 s

Docs

  • The finding is in its game note or its docs/reference/<subsystem>.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index)
  • A chain tool changed: dmsh_chain.py --header was run and dm/gfx/nvn/dmsh_chain.h is part of the change (no chain change)
  • No game files, keys or data extracted from a game in the change or the attachments

🤖 Generated with Claude Code

Little Nightmares II keeps its shaders inline in the cooked packages of
Helios-Switch.pak, a version 8 pak whose index and entries are
AES-encrypted. ue_legacy_jobs opened it without a key, so the index did
not parse, the pak was left out, and the shader split found no shaders.

ue_legacy_jobs now looks for the key in the game's mains (base and
update) with uepak.find_key when the footer says the index is encrypted,
and passes it with each job, so ue_legacy_shaders decrypts the entries
too. A key found once is tried first on the next pak. With no key in
main the pak is reported in red and skipped, as before.

The rebuilt game finds 20,170 shaders and reaches the title screen on
the Mac, where it plays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers tools Tools and scripts (dm/tools, scripts) docs Documentation labels Nov 7, 2026
thehobbit85 pushed a commit to LNPANDY/NX2Apple that referenced this pull request Nov 7, 2026
Little Nightmares II keeps its shaders inline in an encrypted version 8
pak, and the shader split found none. Patch 0089 makes ue_legacy_jobs
take the key from main, as the paks with shader code archives already
do. Forwarded as seedds/nxnative#1646.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seedds added a commit that referenced this pull request Nov 7, 2026
… encrypted, with the key from main: Little Nightmares II's shaders are found (PR #1646)

Little Nightmares II keeps its shaders inline in the cooked packages of
Helios-Switch.pak, a version 8 pak whose index and entries are
AES-encrypted. ue_legacy_jobs opened legacy paks without a key, so the
split said the pak cannot be read and found no shaders.

uepak.Keys is now the one key finder for a game's paks: no key for a
pak whose index is in the clear, else the key find_key finds in the
first main (base game, then update) that opens it; each main is loaded
once, and a key found is tried first on the next pak. ue_legacy_jobs
passes the key with each job, so ue_legacy_shaders decrypts the entries
too; uepak.job (the shader code archives) and uepak.py list use it in
place of their own lookups. find_key tries the known keys before
code_keys, which reads all of main's code.

Little Nightmares II (1.4): 20,170 shaders from 57 files; it reaches the
title screen and plays on the Mac. OCTOPATH TRAVELER 0's uepak.job
output is byte-identical to before.

Co-authored-by: Haseenesss <18624035+Haseenesss@users.noreply.github.com>
@seedds

seedds commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Landed as 050580d with you credited as co-author. Thanks for the clear diagnosis and the tests.

Changes on top of yours:

  • uepak.Keys(mains) is now the one key finder: the inline path (ue_legacy_jobs), the shader code archives (uepak.job) and uepak.py list all use it in place of their own lookups. It gives no key for a pak whose index is in the clear. Otherwise it finds the key in the first main that opens the pak, loads each main once, and tries a key it already found first.
  • find_key(first=) built (*first, *code_keys(img, lo)), which scanned all of main's code before trying the known key. The known keys now go first. A new test in test_uepak_key.py covers this.
  • The symptom now quotes the red line the split printed before the fix (the pak cannot be read (…: the index is encrypted and no key was given)).

OCTOPATH TRAVELER 0's uepak.job output is byte-identical to before.

@seedds seedds closed this Nov 7, 2026
gnosticgeek pushed a commit to gnosticgeek/nxforge that referenced this pull request Nov 7, 2026
… encrypted, with the key from main: Little Nightmares II's shaders are found (PR seedds#1646)

Little Nightmares II keeps its shaders inline in the cooked packages of
Helios-Switch.pak, a version 8 pak whose index and entries are
AES-encrypted. ue_legacy_jobs opened legacy paks without a key, so the
split said the pak cannot be read and found no shaders.

uepak.Keys is now the one key finder for a game's paks: no key for a
pak whose index is in the clear, else the key find_key finds in the
first main (base game, then update) that opens it; each main is loaded
once, and a key found is tried first on the next pak. ue_legacy_jobs
passes the key with each job, so ue_legacy_shaders decrypts the entries
too; uepak.job (the shader code archives) and uepak.py list use it in
place of their own lookups. find_key tries the known keys before
code_keys, which reads all of main's code.

Little Nightmares II (1.4): 20,170 shaders from 57 files; it reaches the
title screen and plays on the Mac. OCTOPATH TRAVELER 0's uepak.job
output is byte-identical to before.

Co-authored-by: Haseenesss <18624035+Haseenesss@users.noreply.github.com>
(cherry picked from commit 050580d)
gnosticgeek pushed a commit to gnosticgeek/nxforge that referenced this pull request Nov 7, 2026
…ue from upstream seedds#1646)

Pyright cannot see the length of the tuple behind self.imgs, so the star
call into find_key(img, lo, hi, pak) failed lint-python on release-0.14.0.
Same call, named.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016qteK6QbhFrzr2Vop9t34k
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
… encrypted, with the key from main: Little Nightmares II's shaders are found (PR seedds#1646)

Little Nightmares II keeps its shaders inline in the cooked packages of
Helios-Switch.pak, a version 8 pak whose index and entries are
AES-encrypted. ue_legacy_jobs opened legacy paks without a key, so the
split said the pak cannot be read and found no shaders.

uepak.Keys is now the one key finder for a game's paks: no key for a
pak whose index is in the clear, else the key find_key finds in the
first main (base game, then update) that opens it; each main is loaded
once, and a key found is tried first on the next pak. ue_legacy_jobs
passes the key with each job, so ue_legacy_shaders decrypts the entries
too; uepak.job (the shader code archives) and uepak.py list use it in
place of their own lookups. find_key tries the known keys before
code_keys, which reads all of main's code.

Little Nightmares II (1.4): 20,170 shaders from 57 files; it reaches the
title screen and plays on the Mac. OCTOPATH TRAVELER 0's uepak.job
output is byte-identical to before.

Co-authored-by: Haseenesss <18624035+Haseenesss@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants