feat(libSceNpCommon): implement sce::np::NpTitleSecret #12919

Merged
hypermoist merged 6 commits from upstream-pr/12919 into main 2026-11-02 17:25:37 +00:00
hypermoist commented 2026-10-29 14:21:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-29T14:21:43Z.


What

Implements 24 sce::np::NpTitleSecret exports from libSceNpCommon.sprx of firmware 13.60 (read from disassembly, not measured on a console). Two of them were NotImplemented stubs with placeholder int (void) declarations (C2(const NpTitleSecret&) and C2(const SceNpTitleSecret&)). The other 22 are exported by the module but were missing from AnyPS5.

Two exports of the class stay stubs, because open PRs implement them:

  • Clear (#12823);
  • operator!=(const NpTitleSecret&, const SceNpTitleSecret&) (#12866).

The object is 136 bytes: a vtable pointer, then the existing 128-byte NpTitleSecret (SceNpTitleSecret). It is declared as NpTitleSecretObject in Api.hpp, next to NpTitleIdObject from #12899.

  • Constructors (C1/C2):
    • the default constructor zeroes the 128 bytes;
    • the copy constructors take them from another NpTitleSecret or from a SceNpTitleSecret;
    • (const void*, size_t) copies 128 bytes. The module asserts size == (128) and panics otherwise; AnyPS5 throws std::invalid_argument there, as for the other firmware assertions, and the debt file says so.
  • operator=: copies the 128 bytes and leaves the vtable unchanged.
  • Destructors: D1/D2 do nothing. D0 frees through sce::np::Object::operator delete(void*) (#12836). The vtable is {0, 0, D1, D0}.
  • SetSecretData(const void*, size_t): returns 0x80559E11 with the object unchanged unless the size is 128.
  • IsEmpty: checks whether all 128 bytes are zero.
  • Equals:
    • with a size, false unless it is 128;
    • the NpTitleSecret and SceNpTitleSecret forms, operator== (3 forms) and operator!= (2 forms) compare all 128 bytes.
  • ParseHex(NpTitleSecret*, const char*, size_t) / BuildHex(const NpTitleSecret&, char*, size_t, bool): call sceNpStrnParseHex / sceNpStrBuildHex on the 128 bytes and return only negative results, as the module does (result & (result >> 31)).

Tested

Linux (CachyOS, GCC 16.2, Release): ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed. TestTitleSecretObjects in GuestNpCommonRuntime.cpp checks:

  • the size rules of SetSecretData, Equals and the data constructor (including its assertion);
  • that every byte takes part in the comparisons;
  • the copy constructors and assignment;
  • the BuildHex buffer size and a BuildHex → ParseHex round trip with ParseHex's length errors;
  • D0 freeing through the allocator stored by Object::operator new.

Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran the exports under unicorn (x86-64 emulation on a PC, not a console).

  • Corpus: 15,500 cases:
    • the constructors and operator=: 300 each;
    • SetSecretData and BuildHex: 2,000 each;
    • ParseHex: 3,000;
    • Equals with a size: 1,000;
    • IsEmpty and each other comparison: 600 each.
    • The inputs are zero secrets, one-bit and one-byte differences, random secrets, sizes around 128, and hex strings around 256 digits with invalid characters.
  • What was recorded: the result, whether the vtable slot was written, and the 128 secret bytes, or the whole output buffer plus 4 guard bytes.
  • Result: 0 mismatches against current main, which includes the sceNpStrnParseHex fix from #12913. Before #12913 was merged, the 289 ParseHex cases with a refused low digit differed because of that function. 20 corrupted expectations add exactly 20 mismatches.

The generator and harness are np_title_secret_make_cases.py / np_title_secret_replay.cpp in https://gist.github.com/hypermoist/1834cf221fd737cdb4cca272cc1156d1. The gist has no module or recorded output.

Windows not built. Not run on a console.

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: #12899 (stacked on it, so the new object sits next to NpTitleIdObject), which is merged with main. #12836 (D0 uses sce::np::Object::operator delete) and #12913 (the ParseHex fix) are merged. Other open PRs touching neighbouring lines: #11601, #12825, #12829, #12830 and #12859 touch neighbouring stub, declaration or include lines. Whichever lands second needs a trivial merge, and I will do it.
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5069740012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12919). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-29T14:21:43Z. --- ### What Implements 24 `sce::np::NpTitleSecret` exports from `libSceNpCommon.sprx` of firmware 13.60 (read from disassembly, not measured on a console). Two of them were `NotImplemented` stubs with placeholder `int (void)` declarations (`C2(const NpTitleSecret&)` and `C2(const SceNpTitleSecret&)`). The other 22 are exported by the module but were missing from AnyPS5. Two exports of the class stay stubs, because open PRs implement them: - `Clear` (#12823); - `operator!=(const NpTitleSecret&, const SceNpTitleSecret&)` (#12866). The object is 136 bytes: a vtable pointer, then the existing 128-byte `NpTitleSecret` (`SceNpTitleSecret`). It is declared as `NpTitleSecretObject` in `Api.hpp`, next to `NpTitleIdObject` from #12899. - **Constructors (C1/C2):** - the default constructor zeroes the 128 bytes; - the copy constructors take them from another `NpTitleSecret` or from a `SceNpTitleSecret`; - `(const void*, size_t)` copies 128 bytes. The module asserts `size == (128)` and panics otherwise; AnyPS5 throws `std::invalid_argument` there, as for the other firmware assertions, and the debt file says so. - **`operator=`:** copies the 128 bytes and leaves the vtable unchanged. - **Destructors:** `D1`/`D2` do nothing. `D0` frees through `sce::np::Object::operator delete(void*)` (#12836). The vtable is `{0, 0, D1, D0}`. - **`SetSecretData(const void*, size_t)`:** returns `0x80559E11` with the object unchanged unless the size is 128. - **`IsEmpty`:** checks whether all 128 bytes are zero. - **`Equals`:** - with a size, false unless it is 128; - the `NpTitleSecret` and `SceNpTitleSecret` forms, `operator==` (3 forms) and `operator!=` (2 forms) compare all 128 bytes. - **`ParseHex(NpTitleSecret*, const char*, size_t)` / `BuildHex(const NpTitleSecret&, char*, size_t, bool)`:** call `sceNpStrnParseHex` / `sceNpStrBuildHex` on the 128 bytes and return only negative results, as the module does (`result & (result >> 31)`). ### Tested Linux (CachyOS, GCC 16.2, Release): `ctest --test-dir build -R 'np_common|public_headers' --output-on-failure`, 70/70 passed. `TestTitleSecretObjects` in `GuestNpCommonRuntime.cpp` checks: - the size rules of `SetSecretData`, `Equals` and the data constructor (including its assertion); - that every byte takes part in the comparisons; - the copy constructors and assignment; - the `BuildHex` buffer size and a `BuildHex` → `ParseHex` round trip with ParseHex's length errors; - `D0` freeing through the allocator stored by `Object::operator new`. **Comparison against the firmware code:** I relinked the 13.60 module with this repo's relinker and ran the exports under unicorn (x86-64 emulation on a PC, not a console). - **Corpus:** 15,500 cases: - the constructors and `operator=`: 300 each; - `SetSecretData` and `BuildHex`: 2,000 each; - `ParseHex`: 3,000; - `Equals` with a size: 1,000; - `IsEmpty` and each other comparison: 600 each. - The inputs are zero secrets, one-bit and one-byte differences, random secrets, sizes around 128, and hex strings around 256 digits with invalid characters. - **What was recorded:** the result, whether the vtable slot was written, and the 128 secret bytes, or the whole output buffer plus 4 guard bytes. - **Result:** **0 mismatches** against current `main`, which includes the `sceNpStrnParseHex` fix from #12913. Before #12913 was merged, the 289 `ParseHex` cases with a refused low digit differed because of that function. 20 corrupted expectations add exactly 20 mismatches. The generator and harness are `np_title_secret_make_cases.py` / `np_title_secret_replay.cpp` in https://gist.github.com/hypermoist/1834cf221fd737cdb4cca272cc1156d1. The gist has no module or recorded output. Windows not built. Not run on a console. ### 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: #12899 (stacked on it, so the new object sits next to `NpTitleIdObject`), which is merged with `main`. #12836 (`D0` uses `sce::np::Object::operator delete`) and #12913 (the `ParseHex` fix) are merged. Other open PRs touching neighbouring lines: #11601, #12825, #12829, #12830 and #12859 touch neighbouring stub, declaration or include lines. Whichever lands second needs a trivial merge, and I will do it. - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CnRJay commented 2026-11-01 19:54:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:13Z.

Review: COMMENTED


Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (Unblocks: none is allowed), and it contained no code review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729937618 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12919#pullrequestreview-5729937618). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:54:13Z. **Review:** COMMENTED --- Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (`Unblocks: none` is allowed), and it contained no code review.
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!12919
No description provided.