feat(libSceNpCommon): implement sce::np::NpCommId and sceNpUtilParseTitleId #13408
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13408"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-30T13:51:37Z.
What
Implements
sce::np::NpCommId(23 exports) and the C exportsceNpUtilParseTitleIdfromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console).main:C2(const SceNpCommunicationId&)had a placeholderint (void)declaration.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::NpTitleIdfrom #12899 and reuses its format helpers.sceNpUtilParseTitleId(parts, text):0x80550601;_at index 9, returns0x8055060A;strtol(text + 10)cut to a byte innum.NpCommIdexports:SceNpCommunicationId. They copy all 12 bytes, including the spare one.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 withstrncmpand thenumbyte. The terminator and the spare byte don't count.Equals(const char*): false unless the text is exactlyAAAA99999_99(four letters, five digits,_, two digits). Otherwise it compares the 9 characters andstrtolof the suffix withnum.Parse(text)andParse(text, length): reject anything that isn't exactly 12 characters in that format with0x80559E11, leaving the object unchanged. Otherwise they callsceNpUtilParseTitleId; the sized form parses a NUL-terminated copy of the 12 characters.Build(text, size): zeroessizebytes of the output, then callssceNpUtilBuildTitleId.ParseandBuildreturn only negative results.One deliberate difference: the module's
sceNpUtilParseTitleIdreadstext[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-failurepassed 70/70.guest_np_common_runtimepassed 3 of 3 runs.guest_freetype. That one fails here because my local3rdparty/freetypecheckout 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.
D0.Parse, lengths other than 12, with junk after the text.Build.np_comm_id_make_cases.pyandnp_comm_id_replay.cppin this gist, with theemucall.pyrunner. It needs a decrypted module, which is not attached.Guest test:
TestCommIdObjectsinGuestNpCommonRuntime.cppchecks:sceNpUtilParseTitleIdon a valid id and on each rejection;Parsekeeping the number, leaving the object unchanged when it rejects, and the sized form reading only its length;Buildclearing the buffer and needing 13 bytes;Clear;D0freeing through the allocator stored byObject::operator new.Mutation check: I changed 9 single lines, one at a time, and the differential catches all 9 (15–4,128 mismatches each):
IsEmpty;Buildnot clearing the buffer;Parseignoring its length;Equals(const char*)ignoring the number.Windows not built. Not run on a console.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)NotImplementedstubs (all but theC2stub already onmain), so it drops them fromInventoryExports.cppafter this lands. Agreed with its author (comment): #13120 has removed the 23 declarations and declaresDepends on: #13130, #13270, #13277, #13281, #13345, #13408.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