feat(libSceNpCommon): implement sce::np::NpCommId and sceNpUtilParseTitleId #13408

Merged
hypermoist merged 1 commit from upstream-pr/13408 into main 2026-10-30 22:52:45 +00:00
hypermoist commented 2026-10-30 13:51:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-30T13:51:37Z.


What

Implements sce::np::NpCommId (23 exports) and the C export sceNpUtilParseTitleId from libSceNpCommon.sprx of firmware 13.60 (read from disassembly, not measured on a console).

  • Already a stub on main: C2(const SceNpCommunicationId&) had a placeholder int (void) declaration.
  • Missing from AnyPS5: the other 23 are exported by the module but were not declared.

Types (in Api.hpp):

  • NpCommunicationId (12 bytes): char data[9], term, uint8_t num, dummy.
  • NpCommIdObject (24 bytes): a vtable, then that id at +8. The vtable is {0, 0, D1, D0}.

The class mirrors sce::np::NpTitleId from #12899 and reuses its format helpers.

sceNpUtilParseTitleId(parts, text):

  • a null text returns 0x80550601;
  • a text of 13 or more characters, or without _ at index 9, returns 0x8055060A;
  • otherwise it zeroes the 12 bytes, copies the first 9 characters, and stores strtol(text + 10) cut to a byte in num.

NpCommId exports:

  • C1/C2: default (zeroed), copy, and from a SceNpCommunicationId. They copy all 12 bytes, including the spare one.
  • D1/D2: do nothing. D0 frees through sce::np::Object::operator delete(void*).
  • Clear: zeroes the id. IsEmpty: data[0] == 0 && num == 0.
  • Equals (object or plain id), ==, !=: compare the first 9 characters with strncmp and the num byte. The terminator and the spare byte don't count.
  • Equals(const char*): false unless the text is exactly AAAA99999_99 (four letters, five digits, _, two digits). Otherwise it compares the 9 characters and strtol of the suffix with num.
  • Parse(text) and Parse(text, length): reject anything that isn't exactly 12 characters in that format with 0x80559E11, leaving the object unchanged. Otherwise they call sceNpUtilParseTitleId; the sized form parses a NUL-terminated copy of the 12 characters.
  • Build(text, size): zeroes size bytes of the output, then calls sceNpUtilBuildTitleId. Parse and Build return only negative results.

One deliberate difference: the module's sceNpUtilParseTitleId reads text[9] whatever the string's length, past the end of a string shorter than 10 characters. This implementation checks the length first. The debt file records this.

Tested

The results below are for head 8def0125e68. Linux (CachyOS, GCC 16.2, Release):

  • ctest --test-dir build -R 'np_common|public_headers' --output-on-failure passed 70/70.
  • guest_np_common_runtime passed 3 of 3 runs.
  • The full suite (3,006 tests) passed apart from guest_freetype. That one fails here because my local 3rdparty/freetype checkout is not at the pinned commit; this PR does not touch FreeType.

Firmware differential: 26,501 cases, run from the module's code under unicorn and replayed through this implementation, with 0 mismatches.

  • Coverage: every export except D0.
  • Text inputs:
    • valid ids;
    • ids with one character changed (lower case, digits in the letter part, signs, spaces, high bytes);
    • truncated and over-long strings;
    • unusual suffixes;
    • for the sized Parse, lengths other than 12, with junk after the text.
  • Other inputs: random and near-equal ids for the comparisons, and buffer sizes 0–39 for Build.
  • Compared: the result, and the object's 16 bytes after the vtable (including padding) or the output buffer with an 8-byte margin. The prior object state is an input column.
  • Corruption check: a copy with 2% of the expected outputs corrupted gives 517 mismatches.
  • Generator: np_comm_id_make_cases.py and np_comm_id_replay.cpp in this gist, with the emucall.py runner. It needs a decrypted module, which is not attached.

Guest test: TestCommIdObjects in GuestNpCommonRuntime.cpp checks:

  • sceNpUtilParseTitleId on a valid id and on each rejection;
  • Parse keeping the number, leaving the object unchanged when it rejects, and the sized form reading only its length;
  • Build clearing the buffer and needing 13 bytes;
  • the comparisons ignoring the spare byte but not the number;
  • copying from a plain id, and Clear;
  • D0 freeing through the allocator stored by Object::operator new.

Mutation check: I changed 9 single lines, one at a time, and the differential catches all 9 (15–4,128 mismatches each):

  • the parse length bound;
  • the number parsed from the wrong offset;
  • the parse output not zeroed;
  • the number left out of the comparisons;
  • the number left out of IsEmpty;
  • the last suffix digit not checked;
  • Build not clearing the buffer;
  • the sized Parse ignoring its length;
  • Equals(const char*) ignoring the number.

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: none.
    • This PR lands before #13120. #13120 declares 23 of these exports as NotImplemented stubs (all but the C2 stub already on main), so it drops them from InventoryExports.cpp after this lands. Agreed with its author (comment): #13120 has removed the 23 declarations and declares Depends on: #13130, #13270, #13277, #13281, #13345, #13408.
    • Neighbouring lines only, no shared exports: #12852, #12859, #12919, #13130, #13270, #13277, #13281 and #13345 (all mine) touch nearby stub, declaration, test or debt lines. Either order works; 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:5085436848 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13408). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-30T13:51:37Z. --- ### What Implements `sce::np::NpCommId` (23 exports) and the C export `sceNpUtilParseTitleId` from `libSceNpCommon.sprx` of firmware 13.60 (read from disassembly, not measured on a console). - **Already a stub on `main`:** `C2(const SceNpCommunicationId&)` had a placeholder `int (void)` declaration. - **Missing from AnyPS5:** the other 23 are exported by the module but were not declared. **Types** (in `Api.hpp`): - `NpCommunicationId` (12 bytes): `char data[9]`, `term`, `uint8_t num`, `dummy`. - `NpCommIdObject` (24 bytes): a vtable, then that id at `+8`. The vtable is `{0, 0, D1, D0}`. The class mirrors `sce::np::NpTitleId` from #12899 and reuses its format helpers. **`sceNpUtilParseTitleId(parts, text)`:** - a null text returns `0x80550601`; - a text of 13 or more characters, or without `_` at index 9, returns `0x8055060A`; - otherwise it zeroes the 12 bytes, copies the first 9 characters, and stores `strtol(text + 10)` cut to a byte in `num`. **`NpCommId` exports:** - **C1/C2:** default (zeroed), copy, and from a `SceNpCommunicationId`. They copy all 12 bytes, including the spare one. - **D1/D2:** do nothing. **D0** frees through `sce::np::Object::operator delete(void*)`. - **`Clear`:** zeroes the id. **`IsEmpty`:** `data[0] == 0 && num == 0`. - **`Equals` (object or plain id), `==`, `!=`:** compare the first 9 characters with `strncmp` and the `num` byte. The terminator and the spare byte don't count. - **`Equals(const char*)`:** false unless the text is exactly `AAAA99999_99` (four letters, five digits, `_`, two digits). Otherwise it compares the 9 characters and `strtol` of the suffix with `num`. - **`Parse(text)` and `Parse(text, length)`:** reject anything that isn't exactly 12 characters in that format with `0x80559E11`, leaving the object unchanged. Otherwise they call `sceNpUtilParseTitleId`; the sized form parses a NUL-terminated copy of the 12 characters. - **`Build(text, size)`:** zeroes `size` bytes of the output, then calls `sceNpUtilBuildTitleId`. `Parse` and `Build` return only negative results. **One deliberate difference:** the module's `sceNpUtilParseTitleId` reads `text[9]` whatever the string's length, past the end of a string shorter than 10 characters. This implementation checks the length first. The debt file records this. ### Tested The results below are for head `8def0125e68`. Linux (CachyOS, GCC 16.2, Release): - `ctest --test-dir build -R 'np_common|public_headers' --output-on-failure` passed 70/70. - `guest_np_common_runtime` passed 3 of 3 runs. - The full suite (3,006 tests) passed apart from `guest_freetype`. That one fails here because my local `3rdparty/freetype` checkout is not at the pinned commit; this PR does not touch FreeType. **Firmware differential:** 26,501 cases, run from the module's code under unicorn and replayed through this implementation, with 0 mismatches. - **Coverage:** every export except `D0`. - **Text inputs:** - valid ids; - ids with one character changed (lower case, digits in the letter part, signs, spaces, high bytes); - truncated and over-long strings; - unusual suffixes; - for the sized `Parse`, lengths other than 12, with junk after the text. - **Other inputs:** random and near-equal ids for the comparisons, and buffer sizes 0–39 for `Build`. - **Compared:** the result, and the object's 16 bytes after the vtable (including padding) or the output buffer with an 8-byte margin. The prior object state is an input column. - **Corruption check:** a copy with 2% of the expected outputs corrupted gives 517 mismatches. - **Generator:** `np_comm_id_make_cases.py` and `np_comm_id_replay.cpp` in [this gist](https://gist.github.com/hypermoist/1834cf221fd737cdb4cca272cc1156d1), with the `emucall.py` runner. It needs a decrypted module, which is not attached. **Guest test:** `TestCommIdObjects` in `GuestNpCommonRuntime.cpp` checks: - `sceNpUtilParseTitleId` on a valid id and on each rejection; - `Parse` keeping the number, leaving the object unchanged when it rejects, and the sized form reading only its length; - `Build` clearing the buffer and needing 13 bytes; - the comparisons ignoring the spare byte but not the number; - copying from a plain id, and `Clear`; - `D0` freeing through the allocator stored by `Object::operator new`. **Mutation check:** I changed 9 single lines, one at a time, and the differential catches all 9 (15–4,128 mismatches each): - the parse length bound; - the number parsed from the wrong offset; - the parse output not zeroed; - the number left out of the comparisons; - the number left out of `IsEmpty`; - the last suffix digit not checked; - `Build` not clearing the buffer; - the sized `Parse` ignoring its length; - `Equals(const char*)` ignoring the number. 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: none. - **This PR lands before #13120.** #13120 declares 23 of these exports as `NotImplemented` stubs (all but the `C2` stub already on `main`), so it drops them from `InventoryExports.cpp` after this lands. Agreed with its author ([comment](https://github.com/boykopovar/AnyPS5/pull/13120#issuecomment-6524510290)): #13120 has removed the 23 declarations and declares `Depends on: #13130, #13270, #13277, #13281, #13345, #13408`. - **Neighbouring lines only, no shared exports:** #12852, #12859, #12919, #13130, #13270, #13277, #13281 and #13345 (all mine) touch nearby stub, declaration, test or debt lines. Either order works; 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)
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!13408
No description provided.