feat(tools): replay prosper's console measurements against the built modules #17730

Merged
LeandroLP23 merged 3 commits from upstream-pr/17730 into main 2026-11-12 04:58:39 +00:00
LeandroLP23 commented 2026-11-09 13:17:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-09T13:17:22Z.


What

Adds tools/library-oracle/, which replays prosper's published PS5 console measurements against the built AnyPS5 modules. The measurements cover 747 calls in nine families: libSceRtc, libc, libSceHttp/libSceNet, POSIX, libSceUserService, libkernel and libSceAgc sizes and packet builders. Several debt entries already cite them, but nothing replayed them.

  • replay.cpp (library_oracle_replay, EXCLUDE_FROM_ALL):

    • loads the unpatched modules with LoadLibrary or dlopen and calls each export with the six SysV integer registers (APS5_VABI) and two zero arguments on the stack, so a function that reads a seventh or eighth argument the case does not give sees 0;
    • builds the arguments from prosper's case grammar: integers, input and output buffers, strings, pointer outputs, Agc command-buffer descriptors, and objects and values from earlier cases;
    • compares the return (32 or 64 bits), buffers, pointer offsets and command dwords the way prosper's own replay does;
    • skips redacted and volatile values.
  • library_oracle.py:

    • downloads the measurements from a pinned prosper commit and checks each file's SHA-256. prosper has no licence, so nothing is copied into the repository.
    • runs one family at a time, and restarts the replay without a case that crashes, hangs or lets an exception escape, recording what happened to it;
    • compares the results with known.tsv and exits non-zero on anything new. It also reports known lines that now match, so a fix removes them.
  • known.tsv: every current difference with its reason, 164 lines plus one skip:

    Group Lines Reason
    AGC packet builders that throw 117 AnyPS5 throws for arguments the console encodes; 6 of the AGC lines (4 throws, 2 differences) are ACQUIRE_MEM, which #18479 fixes
    AGC packets that differ 39 packets unlike the console's
    Semaphores 3 the use-after-free that #10558 fixes
    sceHttpUriEscape short buffer 1 #12056 fixes it
    sceKernelWaitEqueue with 0 events 1 #15123 fixes it
    Default stack size 1 1 MiB on purpose, already in the libkernel debt
    Other 2 an IPv6 inet_ntop that leaves stale bytes after the string, and a void function's return register
    Skip 1 sceHttpUriUnescape, which reads the process parameters only the title loader sets up
  • test_library_oracle.py (CTest library_oracle) covers:

    • crash, hang and exception recovery;
    • the known-file classification, including hang and crash counting as one;
    • --write-known;
    • digest checking and caching.

    It needs no build and no network.

  • docs/dev/REVERSE_ENGINEERING.md: one paragraph under the sources section.

Tested

Windows 11, MinGW GCC Release build on main f57c971559.

  • python3 tools/library-oracle/library_oracle.py runs all nine families in under a minute and prints 164 known findings, 0 new, 0 now matching. It exits 0.
  • Negative control: with the kx_eq_wait_zero_events line removed from the known file, it prints NEW diff kx_eq_wait_zero_events ... and exits 1.
  • Replay checked by tampering: changing two measured values in a copy of the RTC file reports both.
  • Unit tests: ctest -R ^library_oracle$ passes.
  • Linux: replay.cpp compiles with GCC 14 (gcc:14 container, -Wall -Wextra, -ldl) and runs. I did not replay Linux-built modules. macOS is not tested.
  • Conventions: tools/check_conventions.py --base origin/main passes.
  • Overlap: tools/pr_overlap.py --branch merged all 38 overlapping pull requests cleanly. The 13 it could not compare touch the top-level CMakeLists.txt and already conflict with main. Among them, #17558 also edits REVERSE_ENGINEERING.md, but at the end of the file, not near this paragraph.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5224495514 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17730). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-11-09T13:17:22Z. --- ### What Adds `tools/library-oracle/`, which replays [prosper](https://github.com/mattias800/prosper)'s published PS5 console measurements against the built AnyPS5 modules. The measurements cover 747 calls in nine families: libSceRtc, libc, libSceHttp/libSceNet, POSIX, libSceUserService, libkernel and libSceAgc sizes and packet builders. Several debt entries already cite them, but nothing replayed them. - **`replay.cpp`** (`library_oracle_replay`, `EXCLUDE_FROM_ALL`): - loads the unpatched modules with `LoadLibrary` or `dlopen` and calls each export with the six SysV integer registers (`APS5_VABI`) and two zero arguments on the stack, so a function that reads a seventh or eighth argument the case does not give sees 0; - builds the arguments from prosper's case grammar: integers, input and output buffers, strings, pointer outputs, Agc command-buffer descriptors, and objects and values from earlier cases; - compares the return (32 or 64 bits), buffers, pointer offsets and command dwords the way prosper's own replay does; - skips redacted and volatile values. - **`library_oracle.py`:** - downloads the measurements from a pinned prosper commit and checks each file's SHA-256. prosper has no licence, so nothing is copied into the repository. - runs one family at a time, and restarts the replay without a case that crashes, hangs or lets an exception escape, recording what happened to it; - compares the results with `known.tsv` and exits non-zero on anything new. It also reports known lines that now match, so a fix removes them. - **`known.tsv`:** every current difference with its reason, 164 lines plus one skip: | Group | Lines | Reason | |---|---|---| | AGC packet builders that throw | 117 | AnyPS5 throws for arguments the console encodes; 6 of the AGC lines (4 throws, 2 differences) are ACQUIRE_MEM, which #18479 fixes | | AGC packets that differ | 39 | packets unlike the console's | | Semaphores | 3 | the use-after-free that #10558 fixes | | `sceHttpUriEscape` short buffer | 1 | #12056 fixes it | | `sceKernelWaitEqueue` with 0 events | 1 | #15123 fixes it | | Default stack size | 1 | 1 MiB on purpose, already in the libkernel debt | | Other | 2 | an IPv6 `inet_ntop` that leaves stale bytes after the string, and a `void` function's return register | | Skip | 1 | `sceHttpUriUnescape`, which reads the process parameters only the title loader sets up | - **`test_library_oracle.py`** (CTest `library_oracle`) covers: - crash, hang and exception recovery; - the known-file classification, including hang and crash counting as one; - `--write-known`; - digest checking and caching. It needs no build and no network. - **`docs/dev/REVERSE_ENGINEERING.md`:** one paragraph under the sources section. ### Tested Windows 11, MinGW GCC Release build on `main` `f57c971559`. - `python3 tools/library-oracle/library_oracle.py` runs all nine families in under a minute and prints `164 known findings, 0 new, 0 now matching`. It exits 0. - **Negative control:** with the `kx_eq_wait_zero_events` line removed from the known file, it prints `NEW diff kx_eq_wait_zero_events ...` and exits 1. - **Replay checked by tampering:** changing two measured values in a copy of the RTC file reports both. - **Unit tests:** `ctest -R ^library_oracle$` passes. - **Linux:** `replay.cpp` compiles with GCC 14 (`gcc:14` container, `-Wall -Wextra`, `-ldl`) and runs. I did not replay Linux-built modules. macOS is not tested. - **Conventions:** `tools/check_conventions.py --base origin/main` passes. - **Overlap:** `tools/pr_overlap.py --branch` merged all 38 overlapping pull requests cleanly. The 13 it could not compare touch the top-level `CMakeLists.txt` and already conflict with `main`. Among them, #17558 also edits `REVERSE_ENGINEERING.md`, but at the end of the file, not near this paragraph. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!17730
No description provided.