Resolve KnownDLL names from System32 before package images #177

Merged
Vonsek merged 4 commits from upstream-pr/178 into main 2026-11-22 03:58:15 +00:00
Vonsek commented 2026-11-21 18:01:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T18:01:40Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532474283 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T18:01:40Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:41:41 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:41:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:32:42Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007288250 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#pullrequestreview-6007288250). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T18:32:42Z. **Review:** COMMENTED --- <!-- 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>
Vonsek commented 2026-11-24 06:41:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:40:28Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007727928 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#pullrequestreview-6007727928). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:40:28Z. **Review:** COMMENTED --- _No description provided._
R0Y00 commented 2026-11-24 06:47:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:16:19Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067130590 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7067130590). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T18:16:19Z. --- 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.
chatgpt-codex-connector[bot commented 2026-11-24 06:47:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:27:23Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067267886 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7067267886). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T18:27:23Z. --- <!-- 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>
R0Y00 commented 2026-11-24 06:47:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:15:02Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067879224 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7067879224). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:15:02Z. --- 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.
Vonsek commented 2026-11-24 06:47:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:40:29Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068194293 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7068194293). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:40:29Z. --- 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.
R0Y00 commented 2026-11-24 06:47:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:00:55Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068441192 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#issuecomment-7068441192). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T20:00:55Z. --- 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.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:32:42Z.

Code review location: tools/dependency_paths.py; line 43

@@ -38,6 +38,9 @@ def trace(report, entry):
                           "LoadLibraryExA", "LoadLibraryExW"}:
                 lookups.append(dict(image=image, symbol=symbol, kind=kind))
             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 = []

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654311768 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#discussion_r4654311768). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T18:32:42Z. **Code review location:** `tools/dependency_paths.py`; line 43 ~~~~diff @@ -38,6 +38,9 @@ def trace(report, entry): "LoadLibraryExA", "LoadLibraryExW"}: lookups.append(dict(image=image, symbol=symbol, kind=kind)) 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 = [] ~~~~ --- **<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 -->
Vonsek commented 2026-11-24 06:50:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:40:28Z.

Code review location: tools/dependency_paths.py; line 43

@@ -38,6 +38,9 @@ def trace(report, entry):
                           "LoadLibraryExA", "LoadLibraryExW"}:
                 lookups.append(dict(image=image, symbol=symbol, kind=kind))
             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 = []

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'.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654626659 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/178#discussion_r4654626659). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:40:28Z. **Code review location:** `tools/dependency_paths.py`; line 43 ~~~~diff @@ -38,6 +38,9 @@ def trace(report, entry): "LoadLibraryExA", "LoadLibraryExW"}: lookups.append(dict(image=image, symbol=symbol, kind=kind)) 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 = [] ~~~~ --- 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'`.
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
R0Y00/Xbox2Windows!177
No description provided.