Resolve KnownDLL names from System32 before package images #178

Manually merged
github merged 4 commits from gh-pr/178/head into gh-pr/178/base 2026-11-26 21:32:30 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 18:01 UTC · original
Vonsek:knowndlls-before-package → main · +205 −9 · 5 files · 4 commits · merged 2026-11-22 03:58 UTC

Change

The Windows loader maps a module named in the \KnownDlls object directory from System32 before it searches the application directory. docs/experiments.md listed this as not modeled. pe_inventory.py let any uniquely named package image decide the import, so a package file called kernel32.dll (or any other known DLL name) replaced the System32 export table in package_resolution, at the first hop and at forwarder hops. dependency_paths.py then added that file to the reachable graph and could report bundled_export_missing for imports that the loader satisfies from System32.

  • pe_inventory.known_dlls() enumerates the host's \KnownDlls directory with NtOpenDirectoryObject/NtQueryDirectoryObject and keeps the Section entries. It adds ntdll.dll, which is mapped into every process before imports are resolved. The directory can list more modules than the KnownDLLs registry value, so the scanner reads the directory itself.
  • resolve_desktop() takes an optional known_dlls set. A known name skips the package lookup and selects the System32 image. API-set contracts keep their own route. With package resolution enabled, the hop gets known_dll: true.
  • scan() passes the set to package resolution and records it under known_dlls in the report. desktop_resolution does not change.
  • dependency_paths.trace() does not treat a package image as loaded when the first package hop is a known DLL. It reports the edge with its System32 status and desktop_chain.

Verification

  • Linux: python -B tests/intake/paths_check.py passes. Before the change it fails: resolve_desktop() does not accept the known-DLL set. With only dependency_paths.py reverted, it fails the new path-graph assertions. The new cases cover a known name with and without the set, a known name whose package copy exports an extra symbol, a packaged forwarder whose next hop is a known DLL (in a different case), an API-set contract, and the path report for both a missing and a present System32 export.
  • Linux stand-in for bundled_export_forwarders: fixtures built with clang --target=x86_64-pc-windows-msvc and lld-link /nodefaultlib, with a source-built kernel32.dll in a temporary System32 and known_dlls replaced by a test double. It passes with the change; without it the package copy decides KERNEL32 imports and gives export_not_found.
  • Windows: ctest --preset dev --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders' -V at ee2f38e (rebased on main; the earlier run at b4e01fe gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12: 3/3 passed (conditional_import_paths, static_exe_intake, bundled_export_forwarders). The full ctest --preset dev --no-tests=error passed 107/107, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped. known_dlls() returned 42 names on Windows 11 build 26200.9974 (x64): the Section entries of \KnownDlls together with ntdll.dll, including kernel32.dll, kernelbase.dll, ucrtbase.dll, ws2_32.dll and the wow64*.dll modules. This is the first run of the NtQueryDirectoryObject enumeration on Windows.

Evidence and follow-up

  • Dynamic-link library search order: known DLLs come before the application folder for both packaged and unpackaged apps.
  • Other modules already loaded before the image are not modeled, nor is DLL redirection.
  • The pre-executable baseline in docs/experiments.md is unchanged. Its 16 package DLLs were not checked against the host's known-DLL names in this change.
**@⁠Vonsek** on GitHub · 2026-11-21 18:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178) `Vonsek:knowndlls-before-package` → `main` · +205 −9 · 5 files · 4 commits · merged 2026-11-22 03:58 UTC ## Change The Windows loader maps a module named in the `\KnownDlls` object directory from System32 before it searches the application directory. `docs/experiments.md` listed this as not modeled. `pe_inventory.py` let any uniquely named package image decide the import, so a package file called `kernel32.dll` (or any other known DLL name) replaced the System32 export table in `package_resolution`, at the first hop and at forwarder hops. `dependency_paths.py` then added that file to the reachable graph and could report `bundled_export_missing` for imports that the loader satisfies from System32. - `pe_inventory.known_dlls()` enumerates the host's `\KnownDlls` directory with `NtOpenDirectoryObject`/`NtQueryDirectoryObject` and keeps the `Section` entries. It adds `ntdll.dll`, which is mapped into every process before imports are resolved. The directory can list more modules than the `KnownDLLs` registry value, so the scanner reads the directory itself. - `resolve_desktop()` takes an optional `known_dlls` set. A known name skips the package lookup and selects the System32 image. API-set contracts keep their own route. With package resolution enabled, the hop gets `known_dll: true`. - `scan()` passes the set to package resolution and records it under `known_dlls` in the report. `desktop_resolution` does not change. - `dependency_paths.trace()` does not treat a package image as loaded when the first package hop is a known DLL. It reports the edge with its System32 status and `desktop_chain`. ## Verification - Linux: `python -B tests/intake/paths_check.py` passes. Before the change it fails: `resolve_desktop()` does not accept the known-DLL set. With only `dependency_paths.py` reverted, it fails the new path-graph assertions. The new cases cover a known name with and without the set, a known name whose package copy exports an extra symbol, a packaged forwarder whose next hop is a known DLL (in a different case), an API-set contract, and the path report for both a missing and a present System32 export. - Linux stand-in for `bundled_export_forwarders`: fixtures built with `clang --target=x86_64-pc-windows-msvc` and `lld-link /nodefaultlib`, with a source-built `kernel32.dll` in a temporary `System32` and `known_dlls` replaced by a test double. It passes with the change; without it the package copy decides KERNEL32 imports and gives `export_not_found`. - Windows: `ctest --preset dev --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders' -V` at ee2f38e (rebased on main; the earlier run at b4e01fe gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12: 3/3 passed (`conditional_import_paths`, `static_exe_intake`, `bundled_export_forwarders`). The full `ctest --preset dev --no-tests=error` passed 107/107, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. `known_dlls()` returned 42 names on Windows 11 build 26200.9974 (x64): the `Section` entries of `\KnownDlls` together with `ntdll.dll`, including `kernel32.dll`, `kernelbase.dll`, `ucrtbase.dll`, `ws2_32.dll` and the `wow64*.dll` modules. This is the first run of the `NtQueryDirectoryObject` enumeration on Windows. ## Evidence and follow-up - [Dynamic-link library search order](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order): known DLLs come before the application folder for both packaged and unpackaged apps. - Other modules already loaded before the image are not modeled, nor is DLL redirection. - The pre-executable baseline in `docs/experiments.md` is unchanged. Its 16 package DLLs were not checked against the host's known-DLL names in this change.
The loader maps a module listed in the \KnownDlls object directory from
System32 before it searches the application directory. The PE inventory
let a package file with the same base name decide the import, at the
first hop and at forwarder hops, and dependency_paths treated that file
as loaded. Read the host's \KnownDlls directory, plus ntdll.dll, and
route those names to System32 in package resolution. Mark the hop with
known_dll and keep the package copy out of the path graph.
A known DLL is mapped from System32, so dependency_paths skipped the package copy and fell back to the first hop's desktop status. A forwarder in the System32 module can still name a packaged module: that module is loaded, and the package chain's terminal status decides the edge. trace() now queues those packaged hops (reason 'forwarder') and reports the chain's status with package_chain. paths_check covers a KnownDLL export forwarding to a packaged module, with the target present and with its export missing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:32:28 +00:00
github manually merged commit 5893e76614 into gh-pr/178/base 2026-11-26 21:32:30 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 18:16 UTC · original

GitHub reports a conflict on b4e01feb. Please reconcile the KnownDLL resolution and its fixtures with the current dependency inventory before marking ready, and run the direct and forwarded resolution cases together.

**@⁠R0Y00** on GitHub · 2026-11-21 18:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7067130590) GitHub reports a conflict on `b4e01feb`. Please reconcile the KnownDLL resolution and its fixtures with the current dependency inventory before marking ready, and run the direct and forwarded resolution cases together.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 18:27 UTC · original · edited 2026-11-21 18:32 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:32:45.176313Z ee2f38e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 18:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7067267886) · edited 2026-11-21 18:32 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"ee2f38eb8c73d51e5a2034630e781ff21bd24870","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T18:32:45.176313Z">2026-11-21T18:32:45.176313Z</relative-time> | `ee2f38e` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
@ -41,1 +42,4 @@
package = row.get("package_resolution")
if package and package["chain"][0].get("known_dll"):
# The loader maps a known DLL from System32, so a package copy with that name is not loaded.
providers = []
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 18:32 UTC · original

P2 Badge Preserve packaged forwarder hops after a KnownDLL first hop

When a bundled KnownDLL name resolves from System32 and its export forwards to a non-known packaged DLL, resolve_desktop() records that later packaged hop in package_resolution. Clearing providers here bypasses package-chain processing and makes trace() use only desktop_resolution, so the forwarded target is marked unlinked and its import gaps disappear. This reproduces with synthetic known.Value -> target.Value export tables. If the System32 target exports Value but the packaged target does not, the graph also hides the export_not_found already recorded in package_resolution. Exclude the known-named copy without discarding later packaged hops or the package chain's terminal status.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 18:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#discussion_r4654311768) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve packaged forwarder hops after a KnownDLL first hop** When a bundled KnownDLL name resolves from System32 and its export forwards to a non-known packaged DLL, `resolve_desktop()` records that later packaged hop in `package_resolution`. Clearing `providers` here bypasses package-chain processing and makes `trace()` use only `desktop_resolution`, so the forwarded target is marked unlinked and its import gaps disappear. This reproduces with synthetic `known.Value -> target.Value` export tables. If the System32 target exports `Value` but the packaged target does not, the graph also hides the `export_not_found` already recorded in `package_resolution`. Exclude the known-named copy without discarding later packaged hops or the package chain's terminal status. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 19:15 UTC · original

The conflict on the current head ee2f38eb is confined to tests/intake/forwarders_check.py. Please preserve the descriptor-name lookup cases from #230 and the KnownDLL forwarder cases when reconciling that file.

**@⁠R0Y00** on GitHub · 2026-11-21 19:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7067879224) The conflict on the current head `ee2f38eb` is confined to `tests/intake/forwarders_check.py`. Please preserve the descriptor-name lookup cases from #230 and the KnownDLL forwarder cases when reconciling that file.
@ -41,1 +42,4 @@
package = row.get("package_resolution")
if package and package["chain"][0].get("known_dll"):
# The loader maps a known DLL from System32, so a package copy with that name is not loaded.
providers = []
Author
Owner

@⁠Vonsek on GitHub · 2026-11-21 19:40 UTC · original

Fixed in 487ceda. With a KnownDLL first hop, trace() no longer drops the package chain: packaged modules named later in the chain are queued from the importing image with reason forwarder, and a non-present terminal status is reported as a finding with package_chain. tests/intake/paths_check.py adds known.Fwd -> target.Fwd and known.Gap -> target.Gap with a packaged target.dll that exports only Fwd: the first reaches bin/target.dll with no finding, the second reports export_not_found with the package chain even though the System32 target.dll exports Gap. Without the fix the test fails with KeyError: 'bin/target.dll'.

**@⁠Vonsek** on GitHub · 2026-11-21 19:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#discussion_r4654626659) Fixed in 487ceda. With a KnownDLL first hop, `trace()` no longer drops the package chain: packaged modules named later in the chain are queued from the importing image with reason `forwarder`, and a non-present terminal status is reported as a finding with `package_chain`. `tests/intake/paths_check.py` adds `known.Fwd -> target.Fwd` and `known.Gap -> target.Gap` with a packaged `target.dll` that exports only `Fwd`: the first reaches `bin/target.dll` with no finding, the second reports `export_not_found` with the package chain even though the System32 `target.dll` exports `Gap`. Without the fix the test fails with `KeyError: 'bin/target.dll'`.
Author
Owner

@⁠Vonsek on GitHub · 2026-11-21 19:40 UTC · original

Rebased on main 7233cec (d5a1d6f, plus 487ceda for the review finding). The only conflict was tests/intake/forwarders_check.py: the descriptor-name lookup cases from #230 (check_descriptor_names) and the KnownDLL forwarder cases now both run, in that order.

On Windows 11 26200.9974 (MSVC 14.44.35207, SDK 10.0.26100): ctest --preset dev --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders|dependency_paths_controls' -V passed 4/4, so the direct and forwarded resolution cases run together, and the full suite passed 121/121.

**@⁠Vonsek** on GitHub · 2026-11-21 19:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7068194293) Rebased on main 7233cec (d5a1d6f, plus 487ceda for the review finding). The only conflict was `tests/intake/forwarders_check.py`: the descriptor-name lookup cases from #230 (`check_descriptor_names`) and the KnownDLL forwarder cases now both run, in that order. On Windows 11 26200.9974 (MSVC 14.44.35207, SDK 10.0.26100): `ctest --preset dev --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders|dependency_paths_controls' -V` passed 4/4, so the direct and forwarded resolution cases run together, and the full suite passed 121/121.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 20:00 UTC · original

I verified the updated forwarder test and resolved the earlier thread. There is a related uncovered path in scan(): package_resolution is still populated only if bundled[dll]. If a KnownDLL is present only in System32 and forwards to a non-known packaged DLL, that condition skips the package-aware walk entirely. Please exercise this case without a shadow copy of the KnownDLL (starting from scan or its row-building logic), and keep the forwarded package reachable. The existing fixture sets package_resolution directly, which bypasses this condition.

**@⁠R0Y00** on GitHub · 2026-11-21 20:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7068441192) I verified the updated forwarder test and resolved the earlier thread. There is a related uncovered path in `scan()`: `package_resolution` is still populated only `if bundled[dll]`. If a KnownDLL is present only in System32 and forwards to a non-known packaged DLL, that condition skips the package-aware walk entirely. Please exercise this case without a shadow copy of the KnownDLL (starting from `scan` or its row-building logic), and keep the forwarded package reachable. The existing fixture sets `package_resolution` directly, which bypasses this condition.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 18:32 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee2f38eb8c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 18:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/178#pullrequestreview-6007288250) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `ee2f38eb8c` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.