feat(libSceNpCommon): implement title ID and secret comparisons #12866

Merged
xdCloudy merged 7 commits from upstream-pr/12866 into main 2026-11-12 06:57:20 +00:00
xdCloudy commented 2026-10-29 13:16:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xdCloudy on 2026-10-29T13:16:13Z.


What

Implement only the two title-value comparisons in libSceNpCommon. Title-ID equality compares 12 bytes from the raw value against 12 bytes at object offset 8. Title-secret inequality compares 128 bytes at object offset 8 against the raw 128-byte secret. The object prefix and bytes outside those ranges are excluded.

Firmware 13.60 libSceNpCommon.sprx, SHA-256 AB696280CAF5CF465C62E00D1785FB4348B59A7E376D7C6802453419E5765CD0: entry 0x1a780, NID 6jHOZ6fItFU, establishes the title-ID range; entry 0x1abe0, NID 7b5y1XSa+KQ, establishes the secret range and inequality. These were inspected statically, not executed on a console. Guest reads use GuestCopyIn; null, unreadable or overflowing addresses throw std::runtime_error as an explicit host choice. Native invalid-pointer faults remain unmeasured.

Time/RtcTick operators are left to #12859 and are not part of this PR. Current upstream main 5bae1a4bc2 is integrated; the net diff remains four intended files. Adjacent shared-file changes may need merge-order reconciliation.

Tested

Windows x86_64, WinLibs GCC, CMake/Ninja Release, head 4a10a05642: built guest_np_common_tests and passed guest_np_common_ids and guest_np_common_clock (2/2). Coverage includes equal/unequal values, exact comparison bounds, prefix exclusion, null/unreadable operands and address-offset overflow. Conventions and diff whitespace checks passed. The earlier independent macOS ASan/UBSan review is separate from these local results. No console or new Linux runtime result is claimed; new-head hosted checks are pending.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5068701228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12866). Originally posted by [xdCloudy](https://github.com/xdCloudy) on 2026-10-29T13:16:13Z. --- ### What Implement only the two title-value comparisons in libSceNpCommon. Title-ID equality compares 12 bytes from the raw value against 12 bytes at object offset 8. Title-secret inequality compares 128 bytes at object offset 8 against the raw 128-byte secret. The object prefix and bytes outside those ranges are excluded. Firmware 13.60 libSceNpCommon.sprx, SHA-256 AB696280CAF5CF465C62E00D1785FB4348B59A7E376D7C6802453419E5765CD0: entry 0x1a780, NID 6jHOZ6fItFU, establishes the title-ID range; entry 0x1abe0, NID 7b5y1XSa+KQ, establishes the secret range and inequality. These were inspected statically, not executed on a console. Guest reads use GuestCopyIn; null, unreadable or overflowing addresses throw std::runtime_error as an explicit host choice. Native invalid-pointer faults remain unmeasured. Time/RtcTick operators are left to #12859 and are not part of this PR. Current upstream main 5bae1a4bc2 is integrated; the net diff remains four intended files. Adjacent shared-file changes may need merge-order reconciliation. ### Tested Windows x86_64, WinLibs GCC, CMake/Ninja Release, head 4a10a05642: built guest_np_common_tests and passed guest_np_common_ids and guest_np_common_clock (2/2). Coverage includes equal/unequal values, exact comparison bounds, prefix exclusion, null/unreadable operands and address-offset overflow. Conventions and diff whitespace checks passed. The earlier independent macOS ASan/UBSan review is separate from these local results. No console or new Linux runtime result is claimed; new-head hosted checks are pending. ### 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
rooklz commented 2026-10-29 13:21:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T13:21:23Z.

Review: COMMENTED


Reviewed at 49ea3e1b23 on macOS arm64 (Apple clang, C++20, ASan+UBSan). I built a standalone harness: your five functions and the copyGuest/copyGuestOffset helpers copied verbatim from PendingExportsRound7.cpp, a GuestCopyIn_nid_no_patch stand-in with the same contract as General.cpp:848 (null/overflow → false, otherwise a checked mach_vm_read_overwrite), and your new testIds/testClock rows unchanged. Your rows pass. merge-tree against main 157b02c4f1 is clean.

1. Same exports as #12859 (blocking: needs coordination). tools/pr_overlap.py --branch (1412 PRs probed) lists #12859 (hypermoist, sce::np::Time, opened 17 minutes before this PR) under Same exports for _ZN3sce2npeqERKNS0_4TimeES3_, _ZN3sce2npleERKNS0_4TimeERK10SceRtcTick and _ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE. #12859 puts all eighteen Time/RtcTick comparison operators in Runtime.cpp, typed const NpTime*/const RtcTick*. The two branches conflict in PendingExportsRound7.cpp and Api.hpp. That makes the checklist item "no other open PR implements the same functions" incorrect. I'd suggest dropping the three Time operators here and keeping the two title-ID/title-secret comparisons. The body's Overlap note will also need updating. pr_overlap also flags hunk-adjacency with #12818, #12823, #12830 and #12852 (Api.hpp/debt/test neighbours, no shared exports).

2. The unreadable-input false is an invented result. The body says the firmware dereferences its arguments directly and "does not show this fallback". On a null or unreadable pointer the console faults; it doesn't return false. CONTRIBUTING asks us to throw on unknown behaviour, not return a made-up success or failure value. Main has a precedent for this: libSceBeisobmf/Export.cpp:26/52/73/134 throws std::runtime_error("... is unreadable") when GuestCopyIn_nid_no_patch fails. Suggestion: have copyGuest/copyGuestOffset throw (or call NotImplemented_nid_no_patch(__func__)) instead of returning false. Turn the three "defensive false fallback" rows into throw expectations, and add a debt/libSceNpCommon.md line saying the invalid-pointer behaviour is unmeasured. It also matters for coverage: the four mutants your rows can't kill all sit on this path. They are: return true on an unreadable right operand in le and in ne; drop the offset > UINTPTR_MAX - address check, which is equivalent because GuestCopyIn refuses the wrapped address anyway; and the null-only check. A throw contract removes all of them.

3. Comparison mutants your rows miss (optional rows below). I ran 15 single-line mutants and your rows kill 7. These survive:

  • le as signed int64_t: the only boundary row is MAX<=MAX
  • le / eq / ne truncated to 32 bits: no tick differs only in the upper half
  • ne replaced with >: the only "different" row is MAX vs 0

The rows below go at the end of testClock. With them, every non-fallback mutant is killed (11/11). They pass on 49ea3e1b23:

    const RtcTick tickHigh{std::uint64_t{1} << 32};
    const std::uint64_t timeHigh = std::uint64_t{1} << 32;
    ok &= expect(_ZN3sce2npleERKNS0_4TimeERK10SceRtcTick(&timeZero, &tickMaximum), "time less-than-or-equal comparison treated the tick as signed");
    ok &= expect(!_ZN3sce2npleERKNS0_4TimeERK10SceRtcTick(&timeMaximum, &tickZero), "time less-than-or-equal comparison treated the time as signed");
    ok &= expect(_ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE(&tickZero, &timeOne), "a smaller tick compared equal to a larger time");
    ok &= expect(!_ZN3sce2npeqERKNS0_4TimeES3_(&timeHigh, &tickZero), "time equality ignored the upper 32 bits");
    ok &= expect(_ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE(&tickHigh, &timeZero), "tick inequality ignored the upper 32 bits");
    ok &= expect(!_ZN3sce2npleERKNS0_4TimeERK10SceRtcTick(&timeHigh, &tickOne), "time less-than-or-equal comparison ignored the upper 32 bits");

If the Time operators move to #12859 per point 1, these rows belong there instead.

Provenance: this is module disassembly with no proprietary code copied. That meets REVERSE_ENGINEERING.md for what the call does, and the body says plainly that nothing was run on a console. The title-ID offset 8 and title-secret offset 8 are consistent with #12823's NpTitleSecret::Clear, which keeps the first 8 bytes.

AI-assisted review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5698353831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12866#pullrequestreview-5698353831). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T13:21:23Z. **Review:** COMMENTED --- Reviewed at 49ea3e1b23 on macOS arm64 (Apple clang, C++20, ASan+UBSan). I built a standalone harness: your five functions and the `copyGuest`/`copyGuestOffset` helpers copied verbatim from `PendingExportsRound7.cpp`, a `GuestCopyIn_nid_no_patch` stand-in with the same contract as `General.cpp:848` (null/overflow → false, otherwise a checked `mach_vm_read_overwrite`), and your new `testIds`/`testClock` rows unchanged. Your rows pass. `merge-tree` against main 157b02c4f1 is clean. **1. Same exports as #12859 (blocking: needs coordination).** `tools/pr_overlap.py --branch` (1412 PRs probed) lists #12859 (hypermoist, `sce::np::Time`, opened 17 minutes before this PR) under **Same exports** for `_ZN3sce2npeqERKNS0_4TimeES3_`, `_ZN3sce2npleERKNS0_4TimeERK10SceRtcTick` and `_ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE`. #12859 puts all eighteen Time/RtcTick comparison operators in `Runtime.cpp`, typed `const NpTime*`/`const RtcTick*`. The two branches conflict in `PendingExportsRound7.cpp` and `Api.hpp`. That makes the checklist item "no other open PR implements the same functions" incorrect. I'd suggest dropping the three Time operators here and keeping the two title-ID/title-secret comparisons. The body's Overlap note will also need updating. pr_overlap also flags hunk-adjacency with #12818, #12823, #12830 and #12852 (Api.hpp/debt/test neighbours, no shared exports). **2. The unreadable-input `false` is an invented result.** The body says the firmware dereferences its arguments directly and "does not show this fallback". On a null or unreadable pointer the console faults; it doesn't return false. CONTRIBUTING asks us to throw on unknown behaviour, not return a made-up success or failure value. Main has a precedent for this: `libSceBeisobmf/Export.cpp:26/52/73/134` throws `std::runtime_error("... is unreadable")` when `GuestCopyIn_nid_no_patch` fails. Suggestion: have `copyGuest`/`copyGuestOffset` throw (or call `NotImplemented_nid_no_patch(__func__)`) instead of returning false. Turn the three "defensive false fallback" rows into throw expectations, and add a `debt/libSceNpCommon.md` line saying the invalid-pointer behaviour is unmeasured. It also matters for coverage: the four mutants your rows can't kill all sit on this path. They are: return `true` on an unreadable right operand in `le` and in `ne`; drop the `offset > UINTPTR_MAX - address` check, which is equivalent because `GuestCopyIn` refuses the wrapped address anyway; and the null-only check. A throw contract removes all of them. **3. Comparison mutants your rows miss (optional rows below).** I ran 15 single-line mutants and your rows kill 7. These survive: - `le` as signed `int64_t`: the only boundary row is MAX<=MAX - `le` / `eq` / `ne` truncated to 32 bits: no tick differs only in the upper half - `ne` replaced with `>`: the only "different" row is MAX vs 0 The rows below go at the end of `testClock`. With them, every non-fallback mutant is killed (11/11). They pass on 49ea3e1b23: ```cpp const RtcTick tickHigh{std::uint64_t{1} << 32}; const std::uint64_t timeHigh = std::uint64_t{1} << 32; ok &= expect(_ZN3sce2npleERKNS0_4TimeERK10SceRtcTick(&timeZero, &tickMaximum), "time less-than-or-equal comparison treated the tick as signed"); ok &= expect(!_ZN3sce2npleERKNS0_4TimeERK10SceRtcTick(&timeMaximum, &tickZero), "time less-than-or-equal comparison treated the time as signed"); ok &= expect(_ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE(&tickZero, &timeOne), "a smaller tick compared equal to a larger time"); ok &= expect(!_ZN3sce2npeqERKNS0_4TimeES3_(&timeHigh, &tickZero), "time equality ignored the upper 32 bits"); ok &= expect(_ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE(&tickHigh, &timeZero), "tick inequality ignored the upper 32 bits"); ok &= expect(!_ZN3sce2npleERKNS0_4TimeERK10SceRtcTick(&timeHigh, &tickOne), "time less-than-or-equal comparison ignored the upper 32 bits"); ``` If the Time operators move to #12859 per point 1, these rows belong there instead. **Provenance:** this is module disassembly with no proprietary code copied. That meets REVERSE_ENGINEERING.md for what the call does, and the body says plainly that nothing was run on a console. The title-ID offset 8 and title-secret offset 8 are consistent with #12823's `NpTitleSecret::Clear`, which keeps the first 8 bytes. AI-assisted review.
rooklz commented 2026-10-29 15:21:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T15:21:36Z.

Review: APPROVED


Re-reviewed at 8c4070dc37 on macOS arm64 (Apple clang, C++20, ASan+UBSan). Thanks for picking up all three points from my earlier review.

What changed. The three sce::np::Time operators are gone, and pr_overlap (1430 PRs probed) no longer reports any same-export overlap with #12859. copyGuest/copyGuestOffset now throw std::runtime_error instead of returning false. Each throw is pinned by rows covering null, unreadable (address 1) and offset-overflow (UINTPTR_MAX - 4) operands on both sides of both functions. The debt file has a line saying invalid-pointer behaviour is unmeasured and that the throw is an emulator-side choice. The two removed stub lines now match the new section.

Harness. This is the same standalone setup as before: both functions and the anonymous-namespace helpers copied verbatim from PendingExportsRound7.cpp, a GuestCopyIn_nid_no_patch stand-in matching General.cpp:848 (null/overflow → false, otherwise a checked mach_vm_read_overwrite), and your new testIds rows unchanged. PASS.

Mutants (18 single-line): 15 KILLED.

  • eq: size 11/13, right offset 7/9, left read at offset 8, ==→!=: all killed. The byte-20 row pins the upper bound and the byte-19 row pins the last compared byte.
  • ne: left offset 0/7/9, size 127, !=→==, right read at offset 8: all killed. The titleSecretObject[7] row pins the prefix exclusion.
  • throw→silent return in either helper, and runtime_error→logic_error: all killed.
  • The 3 survivors are equivalent: dropping the !source check in either helper, or dropping the offset > UINTPTR_MAX - address check. GuestCopyIn_nid_no_patch already refuses null and wrapped ranges, so the result is the same exception either way. No rows needed.

Gates. check_conventions --base upstream/main passes, git diff --check is clean, and merge-tree against main bb04a4f1ea is clean. CI: 5 pass, 5 skipped. pr_overlap reports only #12823 (NpTitleSecret::Clear). That's hunk adjacency on the include block, the neighbouring Api.hpp lines and the debt stub lines, with no shared exports, so it's just a merge-order rebase.

AI-assisted review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5700261730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12866#pullrequestreview-5700261730). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T15:21:36Z. **Review:** APPROVED --- Re-reviewed at 8c4070dc37 on macOS arm64 (Apple clang, C++20, ASan+UBSan). Thanks for picking up all three points from my earlier review. **What changed.** The three `sce::np::Time` operators are gone, and `pr_overlap` (1430 PRs probed) no longer reports any same-export overlap with #12859. `copyGuest`/`copyGuestOffset` now throw `std::runtime_error` instead of returning `false`. Each throw is pinned by rows covering null, unreadable (address 1) and offset-overflow (`UINTPTR_MAX - 4`) operands on both sides of both functions. The debt file has a line saying invalid-pointer behaviour is unmeasured and that the throw is an emulator-side choice. The two removed stub lines now match the new section. **Harness.** This is the same standalone setup as before: both functions and the anonymous-namespace helpers copied verbatim from `PendingExportsRound7.cpp`, a `GuestCopyIn_nid_no_patch` stand-in matching `General.cpp:848` (null/overflow → false, otherwise a checked `mach_vm_read_overwrite`), and your new `testIds` rows unchanged. **PASS.** **Mutants (18 single-line):** 15 KILLED. - eq: size 11/13, right offset 7/9, left read at offset 8, `==`→`!=`: all killed. The byte-20 row pins the upper bound and the byte-19 row pins the last compared byte. - ne: left offset 0/7/9, size 127, `!=`→`==`, right read at offset 8: all killed. The `titleSecretObject[7]` row pins the prefix exclusion. - throw→silent return in either helper, and `runtime_error`→`logic_error`: all killed. - The 3 survivors are equivalent: dropping the `!source` check in either helper, or dropping the `offset > UINTPTR_MAX - address` check. `GuestCopyIn_nid_no_patch` already refuses null and wrapped ranges, so the result is the same exception either way. No rows needed. **Gates.** `check_conventions --base upstream/main` passes, `git diff --check` is clean, and `merge-tree` against main bb04a4f1ea is clean. CI: 5 pass, 5 skipped. `pr_overlap` reports only #12823 (`NpTitleSecret::Clear`). That's hunk adjacency on the include block, the neighbouring `Api.hpp` lines and the debt stub lines, with no shared exports, so it's just a merge-order rebase. AI-assisted review.
CnRJay commented 2026-11-01 19:54:12 +00:00 (Migrated from github.com)

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

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:5729937568 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12866#pullrequestreview-5729937568). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:54:12Z. **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!12866
No description provided.