Skip to content

feat(tools): add a Zig CPK tool that needs no .NET - #73

Merged
endercodezz merged 3 commits into
masterfrom
feat/zig-cpk-tool-65
Nov 6, 2026
Merged

endercodezz merged 3 commits into
masterfrom
feat/zig-cpk-tool-65

Conversation

@endercodezz

@endercodezz endercodezz commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

What changed

New tools/cpk (Zig 0.17.1, host only): one executable for CPK inspection, with no .NET SDK or NuGet restore.

  • list <iso> <cpk path> [substring] or list <file.cpk> [substring]: directory, name, offset, stored and extracted size, compressed flag.
  • extract ... <out dir>: files under their CPK directories, with CRILAYLA decompression. All output paths are checked before the first write; .., absolute paths and names unsafe on Windows stop the extraction.
  • check-trace <iso> <io-trace.csv> [prefix=hostdir ...]: the cpk-check verification of --io-trace reads.

experiments/cpk-check stays as the independent oracle. CI gets a CPK tool job on Linux and Windows, like BinDiff. It is not a required check. tools/cpk/check.py --download reuses BinDiff's pinned, hash-checked Zig download.

Verification

Against CriFsV2Lib on the local ULUS-10512 ISO:

Check Result
list of umd0.cpk and umd1.cpk 5,860 + 338 files, identical line for line
extract, all files, not a sample 6,198 of 6,198 byte-identical, 5,018 of them compressed
check-trace on the 20M replay same verdict: cpk reads=40 header/toc=4 file_matched=36 mismatched=0 unclassified=0 non_cpk=2493
check-trace with one hash changed both report the same MISMATCH line, mismatched=1, exit 1

python tools/cpk/check.py: format check, Debug and safe unit tests, 18/18 CLI tests on synthetic fixtures (stored and CRILAYLA files, masked tables, an ISO, path traversal, truncated tables, 250 damaged archives through list and extract: exit 0 or 2, never a panic).

Found while testing

  • Panic on full pipes. With Zig 0.17.1, list | anything from Git Bash panicked once the pipe filled: those pipes are asynchronous, and the writers treat PENDING as unreachable. stdout now goes through WriteFile on Windows. Python's pipes are synchronous, so the regression test builds an overlapped pipe; the build before the fix fails it with exit 3.
  • Cold list. Reading each file's magic made one cold list take 33 s, against 0.13 s warm [INFERRED: seeks across the image, seen once]. The flag now comes from the TOC, which gives the same 5,018 files. extract still decides by the magic.

tools/bindiff had the same panic: #74, fixed in #75.

Not verified

Closes #65

tools/cpk lists and extracts CPK archives straight from the ISO or a
loose mod.cpk, and checks --io-trace reads, as one executable. Inputs are
community files: every offset is checked, and output paths are validated
before the first write. experiments/cpk-check stays as the oracle.

On Windows stdout goes through WriteFile: the Zig 0.17.1 file writers
panic when an asynchronous Git Bash pipe fills up.

Verified on ULUS-10512 against CriFsV2Lib: 6,198 files listed the same
and extracted byte-identical, same check-trace verdict on the 20M replay
and on a trace with a changed hash. tools/cpk/check.py: 18/18 CLI tests,
including 250 damaged archives. Linux: cross-build only, run by CI.
@github-actions
github-actions Bot enabled auto-merge November 6, 2026 14:41
@endercodezz
endercodezz disabled auto-merge November 6, 2026 14:43
zig fmt needs LF, so tools/cpk gets the eol=lf rule of tools/bindiff for
Windows checkouts. The CLI tests decoded output strictly: a damaged name
is not valid UTF-8, which only showed on Linux.

Verified: tools/cpk/check.py passes locally, CI reruns both platforms.
Verified: CI job CPK tool passes on ubuntu-24.04 and windows-2022.
@endercodezz
endercodezz enabled auto-merge November 6, 2026 14:47
@endercodezz
endercodezz merged commit 343d550 into master Nov 6, 2026
8 checks passed
@endercodezz
endercodezz deleted the feat/zig-cpk-tool-65 branch November 6, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools: CPK list/extract/trace check in Zig (no .NET needed)

1 participant