fix(tools): report guest copies through a cast and offset #21686

Merged
Ethan-Hainline merged 1 commit from upstream-pr/21686 into main 2026-11-18 06:39:54 +00:00
Ethan-Hainline commented 2026-11-16 15:29:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ethan-Hainline on 2026-11-16T15:29:56Z.


What

guest_pointer_audit.py misses a raw guest copy when the parameter reaches the call through a cast and an offset:

std::memcpy(&value, static_cast<const std::uint8_t*>(mode) + 0x10, sizeof(value));

names_parameter strips leading casts in a loop. After static_cast<...> is removed, the text is (mode) + 0x10, and the next iteration strips (mode) as a C-style cast, leaving + 0x10; the parameter no longer matches. The tool therefore reports nothing for this call.

This matches the parameter before each strip, accepting an optional leading (. A plain mode, (mode) + 4, static_cast<T*>(mode), and static_cast<T*>(mode) + 0x10 all match; an unrelated pointer with an offset (other + 0x10) still does not.

On current main the audit goes from 3,171 findings in 2,594 exported functions to 3,229 in 2,648: 58 existing raw copies that were invisible. Most are the memcpy(..., (T*)parameter + offset, ...) pattern. It also surfaces sceVideoOutSysIsModeS3d in libSceVideoOut, the library the GuestPtr pilot converts; that conversion follow-up covers it.

No gate changes: the default report still exits 0, and the --require-zero gate is not on main yet.

Tested

  • python tools/tests/test_guest_pointer_audit.py: 23/23 passed, including the new cast-plus-offset, (mode) + 4 and unrelated-pointer cases.
  • Full run: 3,229 findings; libSceVideoOut reports 22 with the new matcher.
  • python tools/check_conventions.py --base upstream/main --head HEAD passes.

Checklist

  • Based on current main; no other open PR implements the same change
  • 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:5339867065 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21686). Originally posted by [Ethan-Hainline](https://github.com/Ethan-Hainline) on 2026-11-16T15:29:56Z. --- ### What `guest_pointer_audit.py` misses a raw guest copy when the parameter reaches the call through a cast **and an offset**: ```cpp std::memcpy(&value, static_cast<const std::uint8_t*>(mode) + 0x10, sizeof(value)); ``` `names_parameter` strips leading casts in a loop. After `static_cast<...>` is removed, the text is `(mode) + 0x10`, and the next iteration strips `(mode)` as a C-style cast, leaving ` + 0x10`; the parameter no longer matches. The tool therefore reports nothing for this call. This matches the parameter before each strip, accepting an optional leading `(`. A plain `mode`, `(mode) + 4`, `static_cast<T*>(mode)`, and `static_cast<T*>(mode) + 0x10` all match; an unrelated pointer with an offset (`other + 0x10`) still does not. On current `main` the audit goes from **3,171** findings in 2,594 exported functions to **3,229** in 2,648: 58 existing raw copies that were invisible. Most are the `memcpy(..., (T*)parameter + offset, ...)` pattern. It also surfaces `sceVideoOutSysIsModeS3d` in `libSceVideoOut`, the library the GuestPtr pilot converts; that conversion follow-up covers it. No gate changes: the default report still exits 0, and the `--require-zero` gate is not on `main` yet. ### Tested - `python tools/tests/test_guest_pointer_audit.py`: **23/23 passed**, including the new cast-plus-offset, `(mode) + 4` and unrelated-pointer cases. - Full run: 3,229 findings; `libSceVideoOut` reports 22 with the new matcher. - `python tools/check_conventions.py --base upstream/main --head HEAD` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same change - [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
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!21686
No description provided.