mfplat_offline: add offline Media Foundation source-resolver proxy and console path rewrite (RT-MF-OFFLINE) #400

Closed
Andretuta wants to merge 5 commits from upstream-pr/400 into main
Andretuta commented 2026-11-24 04:43:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T04:43:40Z.


Claimed in the coordination issue as: RT-MF-OFFLINE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121796272)

What and why

Titles that play intro and UI videos through Media Foundation (mfplat.dll!MFCreateSourceResolver) pass console drive paths (GAME:, G:, T:) or file:// URLs and could otherwise reach external hosts via http://, https://, rtsp://, mms://, or UNC shares.

This PR adds a partial mfplat.dll shim (runtime/shims/mfplat_offline.{h,cpp}) that wraps the host IMFSourceResolver COM object in a strict proxy:

  • Adds rt::fs::resolve_read_path in runtime/shims/file_system.{h,cpp} so Media Foundation shares the exact overlay-first / package-fallback resolution and path-traversal refusal used by Win32 file I/O.
  • Refuses non-local URLs (http, https, rtsp, mms, \server\share, //server/share, \\?\UNC\..., remote file://host/...) with MF_E_UNSUPPORTED_SCHEME (0xC00D36C3) before touching the host resolver.
  • Rewrites GAME:, G:, T: and percent-encoded local file:/// / file://localhost/ URLs to resolved host paths on both CreateObjectFromURL and BeginCreateObjectFromURL, while forwarding byte-stream methods and CancelObjectCreation unchanged.
  • Refuses unknown QueryInterface IIDs on the proxy so callers cannot unwrap the raw host resolver and bypass the offline gate.
  • Leaves all other mfplat.dll exports forwarded to the native Windows Media Foundation DLL so built-in H.264/AAC/Bink pipelines continue to work.
  • Registers mfplat_offline_test in runtime/CMakeLists.txt, updates scripts/build_runtime.ps1 fallback $files, and documents mfplat.dll in docs/runtime_imports.md.

Tested

  • Compiled and ran runtime/test/mfplat_offline_test.cpp locally with Clang 23 (-std=c++20 -O2 -Wall -Wextra -Werror): 30 check(s), 0 failure(s).
  • Ran python -I scripts/check_no_game_data.py on all touched files: exit 0.
  • Ran python -I tests/test_build_runtime_fallback.py and python -I tests/test_docs_links.py: all tests passed.

GPUs tested: n/a (CPU-only Media Foundation COM proxy & URL classifier tests)

AI-assisted: yes

Update after review (merged with current main)

  • The URL check is now default-deny: only GAME:/G:/T: console paths, absolute drive paths (X:\ or X:/) and file: URLs with an empty or localhost host that name one of those reach Media Foundation. Relative and drive-relative paths, \??\ and \\.\ device paths, whitespace before a scheme, and driveless or UNC-shaped file: URLs (including percent-encoded %5C%5Chost) are refused with MF_E_UNSUPPORTED_SCHEME.
  • A host drive path the title names itself on a DRIVE_REMOTE drive is refused; console paths still resolve under the configured game/overlay folders.
  • MFCreateSourceResolver loads mfplat.dll once (no per-call LoadLibraryExW reference leak) and returns the real load/export error.
  • Docs and header comments say only the IMFSourceResolver URL methods are gated (not byte streams or MFCreateSourceReaderFromURL).
  • Tested: mfplat_offline_test 44 checks, 0 failures (clang 23 / mingw x64); docs tests 50 passed.

Update after the second review

  • Two leading separators of either kind (\\, //, /\, \/) are a UNC share, as Windows reads them, and are refused as unc. A file: URL whose path starts with two or more separators after the authority and percent-decoding is refused as UNC too.
  • New tests for file:////server/share/a.mp4, file://localhost//server/share, /\server\share, \/server and file:///%2F%2Fserver. The mixed-slash ones fail on the previous head.
  • Docs: only the resolver's URL methods are gated; MFCreateSourceReaderFromURL, MFCreateFile and byte streams reach the host. The host's mfreadwrite.dll delay-imports MFCreateSourceResolver itself (tools/pe_inspect.py on Windows 10 22H2), so a source reader uses the unwrapped resolver.
  • Where the title calls MFCreateSourceResolver: its import table (tools/import_call_sites.py) has one call to MFPlat.DLL!MFCreateSourceResolver (RVA 0x33a4d25) and, 0x6a bytes later in the same function, the only call to MFReadWrite.dll!MFCreateSourceReaderFromMediaSource (0x33a4d8f). It imports neither MFCreateSourceReaderFromURL nor MFCreateFile, and tools/pe_inspect.py lists no Media Foundation DLL among its run-time load candidates. So the title's one way to open media is resolver -> media source -> source reader, and the resolver is the wrapped one. Cited in docs/runtime_imports.md.
  • Dropped "Depends on #357": nothing from it is used.
  • Tested: MSVC 14.44 / Windows SDK 10.0.26100, mfplat_offline_test 49 checks, 0 failures; docs tests 47 passed.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — runtime shim only)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466224572 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/400). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T04:43:40Z. --- Claimed in the coordination issue as: `RT-MF-OFFLINE` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121796272) ### What and why Titles that play intro and UI videos through Media Foundation (`mfplat.dll!MFCreateSourceResolver`) pass console drive paths (`GAME:`, `G:`, `T:`) or `file://` URLs and could otherwise reach external hosts via `http://`, `https://`, `rtsp://`, `mms://`, or UNC shares. This PR adds a partial `mfplat.dll` shim (`runtime/shims/mfplat_offline.{h,cpp}`) that wraps the host `IMFSourceResolver` COM object in a strict proxy: - Adds `rt::fs::resolve_read_path` in `runtime/shims/file_system.{h,cpp}` so Media Foundation shares the exact overlay-first / package-fallback resolution and path-traversal refusal used by Win32 file I/O. - Refuses non-local URLs (`http`, `https`, `rtsp`, `mms`, `\server\share`, `//server/share`, `\\?\UNC\...`, remote `file://host/...`) with `MF_E_UNSUPPORTED_SCHEME` (`0xC00D36C3`) before touching the host resolver. - Rewrites `GAME:`, `G:`, `T:` and percent-encoded local `file:///` / `file://localhost/` URLs to resolved host paths on both `CreateObjectFromURL` and `BeginCreateObjectFromURL`, while forwarding byte-stream methods and `CancelObjectCreation` unchanged. - Refuses unknown `QueryInterface` IIDs on the proxy so callers cannot unwrap the raw host resolver and bypass the offline gate. - Leaves all other `mfplat.dll` exports forwarded to the native Windows Media Foundation DLL so built-in H.264/AAC/Bink pipelines continue to work. - Registers `mfplat_offline_test` in `runtime/CMakeLists.txt`, updates `scripts/build_runtime.ps1` fallback `$files`, and documents `mfplat.dll` in `docs/runtime_imports.md`. ### Tested - Compiled and ran `runtime/test/mfplat_offline_test.cpp` locally with Clang 23 (`-std=c++20 -O2 -Wall -Wextra -Werror`): **30 check(s), 0 failure(s)**. - Ran `python -I scripts/check_no_game_data.py` on all touched files: exit 0. - Ran `python -I tests/test_build_runtime_fallback.py` and `python -I tests/test_docs_links.py`: all tests passed. GPUs tested: n/a (CPU-only Media Foundation COM proxy & URL classifier tests) AI-assisted: yes ### Update after review (merged with current `main`) - The URL check is now **default-deny**: only `GAME:`/`G:`/`T:` console paths, absolute drive paths (`X:\` or `X:/`) and `file:` URLs with an empty or `localhost` host that name one of those reach Media Foundation. Relative and drive-relative paths, `\??\` and `\\.\` device paths, whitespace before a scheme, and driveless or UNC-shaped `file:` URLs (including percent-encoded `%5C%5Chost`) are refused with `MF_E_UNSUPPORTED_SCHEME`. - A host drive path the title names itself on a `DRIVE_REMOTE` drive is refused; console paths still resolve under the configured game/overlay folders. - `MFCreateSourceResolver` loads `mfplat.dll` once (no per-call `LoadLibraryExW` reference leak) and returns the real load/export error. - Docs and header comments say only the `IMFSourceResolver` URL methods are gated (not byte streams or `MFCreateSourceReaderFromURL`). - Tested: `mfplat_offline_test` 44 checks, 0 failures (clang 23 / mingw x64); docs tests 50 passed. ### Update after the second review - Two leading separators of either kind (`\\`, `//`, `/\`, `\/`) are a UNC share, as Windows reads them, and are refused as `unc`. A `file:` URL whose path starts with two or more separators after the authority and percent-decoding is refused as UNC too. - New tests for `file:////server/share/a.mp4`, `file://localhost//server/share`, `/\server\share`, `\/server` and `file:///%2F%2Fserver`. The mixed-slash ones fail on the previous head. - Docs: only the resolver's URL methods are gated; `MFCreateSourceReaderFromURL`, `MFCreateFile` and byte streams reach the host. The host's `mfreadwrite.dll` delay-imports `MFCreateSourceResolver` itself (`tools/pe_inspect.py` on Windows 10 22H2), so a source reader uses the unwrapped resolver. - **Where the title calls `MFCreateSourceResolver`:** its import table (`tools/import_call_sites.py`) has one call to `MFPlat.DLL!MFCreateSourceResolver` (RVA `0x33a4d25`) and, 0x6a bytes later in the same function, the only call to `MFReadWrite.dll!MFCreateSourceReaderFromMediaSource` (`0x33a4d8f`). It imports neither `MFCreateSourceReaderFromURL` nor `MFCreateFile`, and `tools/pe_inspect.py` lists no Media Foundation DLL among its run-time load candidates. So the title's one way to open media is resolver -> media source -> source reader, and the resolver is the wrapped one. Cited in `docs/runtime_imports.md`. - Dropped "Depends on #357": nothing from it is used. - Tested: MSVC 14.44 / Windows SDK 10.0.26100, `mfplat_offline_test` 49 checks, 0 failures; docs tests 47 passed. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — runtime shim only) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ubiquitarianism commented 2026-11-24 04:51:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ubiquitarianism on 2026-11-24T04:51:24Z.


Holding for the offline gate. These forms reach the host as UNC paths:

  • file:////server/share/a.mp4
  • file://localhost//server/share
  • mixed-slash forms (/\server\share, \/server), which fall into the relative-path branch

Please:

  • refuse any file: URL whose path, after the authority and percent-decoding, starts with two or more slashes;
  • treat /\ and \/ as UNC;
  • add tests for those three forms;
  • say in the docs that only the source resolver is gated (MFCreateSourceReaderFromURL, MFCreateFile and byte streams still reach the host);
  • cite where the title is measured to call MFCreateSourceResolver;
  • drop 'Depends on #357' if nothing from it is used.

It also needs an MSVC build of mfplat_offline_test; so far it has only been tested with Clang.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7122400162 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/400#issuecomment-7122400162). Originally posted by [ubiquitarianism](https://github.com/ubiquitarianism) on 2026-11-24T04:51:24Z. --- Holding for the offline gate. These forms reach the host as UNC paths: - `file:////server/share/a.mp4` - `file://localhost//server/share` - mixed-slash forms (`/\server\share`, `\/server`), which fall into the relative-path branch Please: - refuse any `file:` URL whose path, after the authority and percent-decoding, starts with two or more slashes; - treat `/\` and `\/` as UNC; - add tests for those three forms; - say in the docs that only the source resolver is gated (`MFCreateSourceReaderFromURL`, `MFCreateFile` and byte streams still reach the host); - cite where the title is measured to call `MFCreateSourceResolver`; - drop 'Depends on #357' if nothing from it is used. It also needs an MSVC build of `mfplat_offline_test`; so far it has only been tested with Clang.
MoonEyes commented 2026-11-28 17:58:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:58:32Z.


Hi @Andretuta, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/shims/file_system.cpp, scripts/build_runtime.ps1), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243431406 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/400#issuecomment-7243431406). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:58:32Z. --- Hi @Andretuta, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/shims/file_system.cpp`, `scripts/build_runtime.ps1`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 17:20:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:20:38Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319147681 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/400#issuecomment-7319147681). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:20:38Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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
ProjectLeonida/mandy!400
No description provided.