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

Open
opened 2026-11-26 20:17:55 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/400
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: feat/mfplat-offline-shim


📝 Commits (5)

  • 600511b mfplat_offline: add offline IMFSourceResolver proxy and console drive rewrite
  • f8ebf0b Merge remote-tracking branch 'ubiq/main' into feat/mfplat-offline-shim
  • b99a982 mfplat_offline: default-deny URL classifier, cache mfplat.dll, narrow docs
  • b2c1920 mfplat_offline: refuse mixed-slash and post-authority UNC forms as UNC (#400 review)
  • 54e65f8 Merge remote-tracking branch 'ubiq/main' into feat/mfplat-offline-shim

📊 Changes

9 files changed (+842 additions, -3 deletions)

View changed files

📝 docs/runtime_imports.md (+16 -1)
📝 runtime/CMakeLists.txt (+17 -0)
📝 runtime/shims/file_system.cpp (+12 -0)
📝 runtime/shims/file_system.h (+7 -0)
➕ runtime/shims/mfplat_offline.cpp (+425 -0)
➕ runtime/shims/mfplat_offline.h (+37 -0)
📝 runtime/shims/registry.cpp (+1 -1)
➕ runtime/test/mfplat_offline_test.cpp (+326 -0)
📝 scripts/build_runtime.ps1 (+1 -1)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/400 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/mfplat-offline-shim` --- ### 📝 Commits (5) - [`600511b`](https://github.com/ubiquitarianism/leonida/commit/600511bf8b4de6ec83b91234908bebb25f01a1d3) mfplat_offline: add offline IMFSourceResolver proxy and console drive rewrite - [`f8ebf0b`](https://github.com/ubiquitarianism/leonida/commit/f8ebf0b3f021462149a86c20e3ab104d0bd299bb) Merge remote-tracking branch 'ubiq/main' into feat/mfplat-offline-shim - [`b99a982`](https://github.com/ubiquitarianism/leonida/commit/b99a982863dcb55d964a84691c33d249937c0bbf) mfplat_offline: default-deny URL classifier, cache mfplat.dll, narrow docs - [`b2c1920`](https://github.com/ubiquitarianism/leonida/commit/b2c1920600d4bca721292ce75e1bbeb3aacf49c1) mfplat_offline: refuse mixed-slash and post-authority UNC forms as UNC (#400 review) - [`54e65f8`](https://github.com/ubiquitarianism/leonida/commit/54e65f873e177f99ca093442ae38968f8de43d49) Merge remote-tracking branch 'ubiq/main' into feat/mfplat-offline-shim ### 📊 Changes **9 files changed** (+842 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/runtime_imports.md` (+16 -1) 📝 `runtime/CMakeLists.txt` (+17 -0) 📝 `runtime/shims/file_system.cpp` (+12 -0) 📝 `runtime/shims/file_system.h` (+7 -0) ➕ `runtime/shims/mfplat_offline.cpp` (+425 -0) ➕ `runtime/shims/mfplat_offline.h` (+37 -0) 📝 `runtime/shims/registry.cpp` (+1 -1) ➕ `runtime/test/mfplat_offline_test.cpp` (+326 -0) 📝 `scripts/build_runtime.ps1` (+1 -1) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#452
No description provided.