[pr-fix][input][startup] mousehook: nothing is read past the end of the title image #418

Open
iBooM72 wants to merge 1 commit from iboom72/mousehook-reads-inside-image into main AGit
Contributor

What it changes

  • The problem on main: read from the code only, not seen in a log. mousehook::install (crates/darner-hle/src/mousehook.rs:1815) reads the 1.0.2.1 prologue at base + 0xe4e3d0 for every title, before any setting is checked. If that doesn't match, it still goes on to hook_entry at the same address. With a title or build whose image is smaller than about 15 MB, those reads land past the image's end.

What changes:

  • bytes() returns nothing past the image's SizeOfImage. darner-hle already reads that from the mapped headers in runtime::image_size, which set_main_image uses; it is now pub(crate).
  • install stops before any hook when the prologue isn't the known build's. It logs the same "prologue … differs (another title/build?)" warning as before.

With the known build nothing changes: the prologue matches and the same hooks are installed.

How it was tested

  • Tested revision: 2520657d (on main f3840d73)
  • Commands and results:
    • cargo test -p darner-hle --lib --locked mousehook: 9 passed, including the new bytes_reads_nothing_past_the_image.
    • cargo clippy -p darner-hle --lib --locked -- -D warnings: clean.
  • The new test bytes_reads_nothing_past_the_image uses a synthetic 0x100-byte image header.
  • Changes a default: no
  • Gates run on that revision: none of the three workspace gates.
  • Gameplay: not run. With the known build the code path is the same; a start should still log "native mouse camera hook installed".
  • Hardware dependence: none.
  • Coverage gaps: not run with another title.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Not run in the game; see above.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #276 makes the same runtime::image_size change (pub(crate)) to bound its own DualSense hooks; the two merge cleanly in either order. #185 adds fixed-offset hooks bounded by the constant IMAGE_MAX. #399 edits mousehook.rs (the capture log). Each merges with this branch without a conflict (git merge-tree against their current heads).
  • Replaces or overlaps: none found

Checked with AI assistance (Claude Code).

🤖 Generated with Claude Code

<!-- Thanks for the pull request. Start the title with its type (pr-fix, pr-feature, pr-performance, pr-diagnostics, pr-refactor, pr-docs or pr-tests) and the area tags, like [pr-fix][memory]. This host has no labels yet, so the tags stay in the title. --> ## What it changes - The problem on main: read from the code only, not seen in a log. `mousehook::install` (`crates/darner-hle/src/mousehook.rs:1815`) reads the 1.0.2.1 prologue at `base + 0xe4e3d0` for every title, before any setting is checked. If that doesn't match, it still goes on to `hook_entry` at the same address. With a title or build whose image is smaller than about 15 MB, those reads land past the image's end. What changes: - `bytes()` returns nothing past the image's `SizeOfImage`. darner-hle already reads that from the mapped headers in `runtime::image_size`, which `set_main_image` uses; it is now `pub(crate)`. - `install` stops before any hook when the prologue isn't the known build's. It logs the same "prologue … differs (another title/build?)" warning as before. With the known build nothing changes: the prologue matches and the same hooks are installed. ## How it was tested - Tested revision: `2520657d` (on `main` `f3840d73`) - Commands and results: - `cargo test -p darner-hle --lib --locked mousehook`: 9 passed, including the new `bytes_reads_nothing_past_the_image`. - `cargo clippy -p darner-hle --lib --locked -- -D warnings`: clean. - The new test `bytes_reads_nothing_past_the_image` uses a synthetic 0x100-byte image header. - Changes a default: no - Gates run on that revision: none of the three workspace gates. - Gameplay: not run. With the known build the code path is the same; a start should still log "native mouse camera hook installed". - Hardware dependence: none. - Coverage gaps: not run with another title. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). Not run in the game; see above. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #276 makes the same `runtime::image_size` change (`pub(crate)`) to bound its own DualSense hooks; the two merge cleanly in either order. #185 adds fixed-offset hooks bounded by the constant `IMAGE_MAX`. #399 edits `mousehook.rs` (the capture log). Each merges with this branch without a conflict (`git merge-tree` against their current heads). - Replaces or overlaps: none found Checked with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
install read the 1.0.2.1 prologue at base + 0xe4e3d0 for every title,
before any setting was checked, and went on to hook it whatever it found.
With a title or build whose image is smaller, that read lands past the
image's end. bytes() now returns nothing past SizeOfImage, which darner-hle
already reads from the mapped headers (runtime::image_size), and install
stops before any hook when the prologue is not the known build's.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/418/head:iboom72/mousehook-reads-inside-image'
git switch 'iboom72/mousehook-reads-inside-image'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'iboom72/mousehook-reads-inside-image'
git switch 'iboom72/mousehook-reads-inside-image'
git rebase 'main'
git switch 'main'
git merge --ff-only 'iboom72/mousehook-reads-inside-image'
git switch 'iboom72/mousehook-reads-inside-image'
git rebase 'main'
git switch 'main'
git merge --no-ff 'iboom72/mousehook-reads-inside-image'
git switch 'main'
git merge --squash 'iboom72/mousehook-reads-inside-image'
git switch 'main'
git merge --ff-only 'iboom72/mousehook-reads-inside-image'
git switch 'main'
git merge 'iboom72/mousehook-reads-inside-image'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!418
No description provided.