feat(tools): list a guest's imports without running it, and report the imports a run touches #38

Open
github-bot wants to merge 2 commits from github-bot/gh-38 into main AGit
Owner

@⁠wildheathen on GitHub · 2026-11-21 19:28 UTC · original
wildheathen:feat/import-diagnostics → main · +589 −1 · 7 files · 2 commits · open

Summary

Two small diagnostics that show which entry points a title wants from us, without needing a title in the repository:

  • tools/list_guest_imports.py: reads the static import table of a PE32/PE32+ image (DLL name, symbol or ordinal) without running it. --dll filters, --json writes a machine-readable report, --missing-from <header> marks the imports the given ABI header does not declare. Truncated or malformed files are reported as an error message, not a traceback.
  • scarlettx boot ... --dump-imports: at the end of the run (or on Ctrl+C, since real titles do not return) prints the auto-stub imports with their call counts and the names the guest resolved with GetProcAddress, unresolved ones first. GetProcAddress is overridden in src/loader/guest_modules.cpp to record DLL, symbol, hit count and whether the host found it. Ordinal requests are recorded as #n and the pointer is never dereferenced. A first miss is logged to stderr only when --dump-imports is on, so normal runs stay quiet.

The static table only covers imports; delay-loaded ones and run-time resolutions are exactly what --dump-imports adds.

Tests

tests/test_guest_loader.cpp covers the lookup registry: a resolved name, a missing name, repeats aggregated into one entry with the right hit count, and ordinal lookups (valid and invalid) that are recorded and never dereferenced.

Verification

  • Built with MSVC + Ninja x64. Full suite: everything passes except the three tests that already fail on an unmodified origin/main (test_boot_hello_scarlett, test_boot_rt_showcase, test_d3d12_guest_texture; see #1 and #2).
  • Ran list_guest_imports.py on the built hello_scarlett.exe (lists its xgameruntime.dll imports) and on a 300-byte truncation of it (reports "truncated file").
**@⁠wildheathen** on GitHub · 2026-11-21 19:28 UTC · [original](https://github.com/Freminet/ScarlettX/pull/38) `wildheathen:feat/import-diagnostics` → `main` · +589 −1 · 7 files · 2 commits · open ## Summary Two small diagnostics that show which entry points a title wants from us, without needing a title in the repository: - **`tools/list_guest_imports.py`**: reads the static import table of a PE32/PE32+ image (DLL name, symbol or ordinal) without running it. `--dll` filters, `--json` writes a machine-readable report, `--missing-from <header>` marks the imports the given ABI header does not declare. Truncated or malformed files are reported as an error message, not a traceback. - **`scarlettx boot ... --dump-imports`**: at the end of the run (or on Ctrl+C, since real titles do not return) prints the auto-stub imports with their call counts and the names the guest resolved with `GetProcAddress`, unresolved ones first. `GetProcAddress` is overridden in `src/loader/guest_modules.cpp` to record DLL, symbol, hit count and whether the host found it. Ordinal requests are recorded as `#n` and the pointer is never dereferenced. A first miss is logged to stderr only when `--dump-imports` is on, so normal runs stay quiet. The static table only covers imports; delay-loaded ones and run-time resolutions are exactly what `--dump-imports` adds. ## Tests `tests/test_guest_loader.cpp` covers the lookup registry: a resolved name, a missing name, repeats aggregated into one entry with the right hit count, and ordinal lookups (valid and invalid) that are recorded and never dereferenced. ## Verification - Built with MSVC + Ninja x64. Full suite: everything passes except the three tests that already fail on an unmodified `origin/main` (`test_boot_hello_scarlett`, `test_boot_rt_showcase`, `test_d3d12_guest_texture`; see #1 and #2). - Ran `list_guest_imports.py` on the built `hello_scarlett.exe` (lists its `xgameruntime.dll` imports) and on a 300-byte truncation of it (reports "truncated file").
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:56:43 +00:00
This pull request has changes conflicting with the target branch.
  • src/main.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/38/head:github-bot/gh-38'
git switch 'github-bot/gh-38'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-38'
git switch 'github-bot/gh-38'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-38'
git switch 'github-bot/gh-38'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-38'
git switch 'main'
git merge --squash 'github-bot/gh-38'
git switch 'main'
git merge --ff-only 'github-bot/gh-38'
git switch 'main'
git merge 'github-bot/gh-38'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.