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

Open
github-bot wants to merge 5 commits from github-bot/gh-400 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 04:43 UTC · original
ubiquitarianism:feat/mfplat-offline-shim → main · +842 −3 · 9 files · 5 commits · open

Claimed in the coordination issue as: RT-MF-OFFLINE (#14)

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

**@⁠Andretuta** on GitHub · 2026-11-24 04:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/400) `ubiquitarianism:feat/mfplat-offline-shim` → `main` · +842 −3 · 9 files · 5 commits · open Claimed in the coordination issue as: `RT-MF-OFFLINE` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### 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)
Blocks network URL schemes (http, https, rtsp, mms, UNC shares, remote
file:// hosts) with MF_E_UNSUPPORTED_SCHEME and rewrites GAME:, G:, and
T: paths through rt::fs::resolve_read_path before delegating to the host
Media Foundation source resolver.
- resolve_media_url accepts only GAME:/G:/T: console paths, absolute drive paths
  (X:\ or X:/) and empty/localhost file: URLs naming one of those. Relative,
  drive-relative, rooted, \??\ and \.\ device paths, whitespace before a scheme,
  driveless or UNC-shaped file: URLs (incl. percent-encoded) are refused with
  MF_E_UNSUPPORTED_SCHEME instead of being forwarded to Media Foundation.
- A host drive path the title names itself on a DRIVE_REMOTE drive is refused;
  console paths keep resolving under the configured game/overlay folders.
- MFCreateSourceResolver loads mfplat.dll once (no per-call LoadLibraryExW
  reference leak) and reports the real load/export error.
- Header, file comment and docs/runtime_imports.md say only the
  IMFSourceResolver URL methods are gated (not byte streams or
  MFCreateSourceReaderFromURL).
- 14 new refusal checks; the old "relative path passes through" check now
  expects refusal.

AI-assisted. Tested: mfplat_offline_test (clang 23 / mingw x64, 44 checks),
docs tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Two leading separators of either kind (\, //, /\, \/) are a UNC share, as Windows reads them.
- A file: URL whose path, after the authority and percent-decoding, starts with two or more
  separators is refused as UNC (file:////server/share, file://localhost//server/share).
- Tests for those forms; the mixed-slash ones fail on the previous head (labelled "relative").
- docs: only the resolver's URL methods are gated (MFCreateSourceReaderFromURL, MFCreateFile and byte
  streams reach the host; the host mfreadwrite.dll delay-imports MFCreateSourceResolver itself). The
  title's import table has one MFCreateSourceResolver call, followed in the same function by its only
  MFCreateSourceReaderFromMediaSource call, and no MFCreateSourceReaderFromURL or MFCreateFile import.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
#	runtime/shims/registry.cpp
#	scripts/build_runtime.ps1
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:57:53 +00:00
Author
Owner

@⁠ubiquitarianism on GitHub · 2026-11-24 04:51 UTC · original

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.

**@⁠ubiquitarianism** on GitHub · 2026-11-24 04:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/400#issuecomment-7122400162) 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.
This pull request has changes conflicting with the target branch.
  • scripts/build_runtime.ps1
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/400/head:github-bot/gh-400'
git switch 'github-bot/gh-400'

Merge

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