Compare commits

...
Author SHA1 Message Date
poli0981andClaude Opus 5.5 2c586b6012 fix: what SonarCloud found that was real - Explorer by full path and quoted, the action pinned, two string reads bounded, module renamed, three C# smells (beta.24 PR-2)
- App: one Services/Explorer helper starts %WINDIR%\explorer.exe by full path and
  always quotes the path (S4036; three of five call sites passed it bare). Tests.
- Workflows: ilammy/msvc-dev-cmd pinned to its v1.13.0 commit (S7637).
- Native: FlGuardRulesFilePath returns wcsnlen(out, cap); the NVAPI bridge
  measures the driver's branch name with strnlen over its buffer (S5813);
  `module` renamed in the hook inventory and dllmain (S1669, rename only, no
  code change); fl-probe-hookprofile drops compound assignment on a volatile
  (S6191, deprecated in C++20).
- PipeServer.RunAsync loops while not cancelled and ends cancelled (S2190);
  ProcessLauncher's unused static Start overload is removed (S3427); a launch's
  own session passes CancellationToken.None with its reason (S8949).
- 13_CI_CD §SonarCloud: the 17 accepted S5813 sites with why each string is
  terminated; S3869 accepted (no SafeHandle overload from CsWin32 here).
- Dependabot #314 (VS Threading Analyzers 18.12.1, Meziantou 3.0.307): the
  first-start view model's answer task (VSTHRD003) and one test fake's
  synchronous wait (VSTHRD002) are suppressed with their reasons; the whole
  solution builds with both the current and the bumped analyzers.

Gate: ./build.ps1 check ALL GATES PASSED (312 s); 32/32 native tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 17:12:16 +07:00
22 changed files with 205 additions and 71 deletions

No files matched your search

+1 -1
View File
@@ -47,7 +47,7 @@ jobs:
global-json-file: global.json
- name: Set up MSVC (x64)
uses: ilammy/msvc-dev-cmd@v1
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
with:
arch: x64
+1 -1
View File
@@ -47,7 +47,7 @@ jobs:
- name: Set up MSVC (x64)
if: matrix.language == 'cpp'
uses: ilammy/msvc-dev-cmd@v1
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
with:
arch: x64
+1 -1
View File
@@ -66,7 +66,7 @@ jobs:
global-json-file: global.json
- name: Set up MSVC (x64)
uses: ilammy/msvc-dev-cmd@v1
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
with:
arch: x64
+16
View File
@@ -36,6 +36,22 @@ numeric core and does not move; the heading is the full version — corrected 20
records the triage of the 341 issues the last analysis left — the rules this project breaks by design and why, the
false positives, and the ones the next change fixes — with the steps to mark them in SonarCloud.
### Fixed
- **Opening a folder in Explorer** — the logs, the data folder, the licences, a bug report's zip and the folder named
after a failed start — starts `explorer.exe` from the Windows folder by its full path, never a program of that name
found on the search path, and always hands it the path in quotes (three of the five places passed it bare).
- **What SonarCloud found that was real** (developers only): the one third-party GitHub Action is pinned to its
commit; two string reads in native code are bounded by their buffer (the guard's rules-file path handed to the Agent,
and the driver's branch name the NVAPI bridge copies); the pipe server's accept loop states that it ends only when
cancelled; a launch's own session names its absent stop token (`CancellationToken.None`, with the reason) where it
wrote `default` — the same value, now said on purpose; an unused overload of
the process launcher that hid the other is gone; the identifier `module` (a C++20 keyword in some positions) is
renamed in the hook layer — a rename only, no code changes; and a hook-overhead probe no longer uses a compound
assignment on a `volatile`, which C++20 deprecates. The analyzers Dependabot updates in #314 flag the first-start
window's own answer task and one test fake's synchronous wait; both are suppressed with their reasons, so that update
can merge.
## [0.1.0-beta.23] - 2026-10-14
**The twenty-third pre-release: a game's artwork on its page, in a band that takes the picture's colour, and pages
+19 -2
View File
@@ -7,7 +7,7 @@ FrameLedger uses the **`poli0981/.github` ops repo** where its templates fit, an
## Workflows (`.github/workflows/`)
### `ci.yml` — push to `main` + all PRs + `workflow_dispatch` (added 2026-10-04) · **repo-local**
- `runs-on: windows-latest`, .NET SDK pinned by `global.json` via `actions/setup-dotnet`, MSVC via `ilammy/msvc-dev-cmd`, NuGet cached.
- `runs-on: windows-latest`, .NET SDK pinned by `global.json` via `actions/setup-dotnet`, MSVC via `ilammy/msvc-dev-cmd` (pinned to its v1.13.0 commit since beta.24 — the one third-party action, SonarCloud `githubactions:S7637`; Dependabot moves the pin), NuGet cached.
- Single step of substance: **`./build.ps1 check`** — the same script, with the same switches (none), a developer runs before pushing. The gate list lives in `12_BUILD` §Local quality gate, **once**, rather than being restated here where it goes stale.
- ~~**`-SkipIntegration` is the one place local and CI deliberately differ**~~ — **gone since 2026-09-06.** From 2026-08-05 CI passed it for a measured reason: §S16 puts the injecting process's ancestors in the scan set, a .NET test host loads `System.Security.Cryptography.ProtectedData.dll`, and the guard's `protect` fragment refused our own harness (§S19(b)). The signer half now verifies that module's embedded signature offline and reads `O=Microsoft Corporation` on the compiled-in bound, so the `Category=Integration` cases run here — **nine** when this was written, **20 across six classes** as of 2026-09-13 (Agent 6, CaptureHost 7, Infrastructure 7); count them with `grep -rl 'Category", "Integration' tests` rather than trusting either number — and a green CI IS evidence for the managed drain and the capture host's end-to-end behaviour. The switch remains in `build.ps1`, loud, for a developer who must.
- **The hosted runner refuses guard scans intermittently — THREE failures in eight gate runs, measured
@@ -251,7 +251,7 @@ the comment below; the rest are fixed in the same train (beta.24 PR-2).
| `cpp:S8417` atomics should be sequentially consistent | 225 | **Accept** — by design | The SPSC ring and the hook counters use explicit acquire/release and relaxed orders on purpose (`07_IPC`); sequential consistency would add fences on the per-present path. |
| `csharpsquid:S6640` unsafe code blocks | 31 | **Accept** — by design | Interop with the native layer and the shared-memory mirror, confined to `Infrastructure` and `Shared` (CLAUDE.md: the native layer is reachable only through `Infrastructure`). |
| `cpp:S6232` union type-punning | 24 | **False positive** | `LARGE_INTEGER.QuadPart` is how the Windows API returns the value. |
| `cpp:S5813` bounds when computing string length | 19 | **Accept** where the string is a literal or the API guarantees its terminator; fixed where a buffer bound is at hand | Each site is listed in beta.24 PR-2. |
| `cpp:S5813` bounds when computing string length | 19 | **Accept** for the 17 below; the 2 with a buffer bound at hand were bounded (beta.24 PR-2: `FlGuardRulesFilePath` reads `wcsnlen(out, cap)`, the NVAPI bridge `strnlen` over the driver's `NvAPI_ShortString`) | Every string measured is NUL-terminated by construction — see the list under this table. |
| `csharpsquid:S2077` dynamic SQL | 3 | **False positive** | A `PRAGMA` argument cannot be bound; the values are an `int` and closed sets of constants (`wal_checkpoint` mode, the tri-state column), never user text. |
| `cpp:S935` `FlGetBuildId` returns no value | 1 | **False positive** | `FL_BUILD_ID` is defined by the build (`12_BUILD` §Version); the analysis compiles without it. |
| `cpp:S3519` out-of-bounds `memcpy` | 1 | **False positive** | `fl_patch_check.h` reads the prologue of a function this DLL hooked, under SEH, by design (`17_HOOK_ENGINE` §Unhooking). |
@@ -259,6 +259,23 @@ the comment below; the rest are fixed in the same train (beta.24 PR-2).
| `csharpsquid:S3869` `DangerousGetHandle` | 1 | **Accept** | `ParentDump` passes the dump file's handle to `MiniDumpWriteDump` inside the `using` that owns the stream, on the same thread, so it cannot be released during the call; CsWin32 generates no `SafeHandle` overload here (`NativeMethods.json`: `useSafeHandles: false`). |
| `cpp:S1669`, `cpp:S6191`, `csharpsquid:S4036`, `githubactions:S7637`, `csharpsquid:S2190`, `S3427`, `S8949` | 35 | **Fixed** in beta.24 PR-2 — 5 of the 23 `S1669` were in the vendored Vulkan headers and leave with the exclusions | — |
**`cpp:S5813`, the 17 accepted, and why each string is terminated** (lines as of beta.24):
- `fl_ac_rules.cpp` — `IStartsWith`/`IContains` (`:38`, `:43-44`) and `TokenIs` (`:74`) measure rule fragments and
literals the guard itself holds; `:151` and `:288` measure a value `CopyToken` has just written, which refuses a token
that does not fit and always writes the terminator; `CopyLiteral` (`:176`) measures a compiled literal; `:834`
measures `SHGetKnownFolderPath`'s answer, terminated by the API.
- `fl_guard.cpp:109` — the guard's own DLL path, built and terminated by its caller before injection.
- `fl_guard_sources.cpp` — `:345` measures the executable's path the guard read itself and walked to its terminator
in the loop just above; `:753` the install root the guard resolved from it; `VdfValue` (`:582`) measures the
compiled keys its callers pass (`"installdir"`, `"appid"`), and `AllDigits` (`:617`) a value `VdfValue` copied with
its own bound.
- `fl_prescan.cpp` — `IsKernelDriverName` (`:40`) measures a name the directory walk handed over terminated;
`SegmentIs` (`:181`) a literal; `:337` the executable's folder the pre-scan built itself.
- `layer.cpp:99` (the Vulkan layer) — a leaf of `GetModuleFileNameA`'s result, which the line above has already
checked is shorter than `MAX_PATH`, so it is terminated.
- `fl-baseline-probe/main.cpp:55` — a literal (a developer probe, not shipped).
**The owner's steps** after the next analysis of `main`: for each rule above, open
`https://sonarcloud.io/project/issues?id=poli0981_frameledger&resolved=false&rules=<rule>`, select all, *Bulk change*,
choose *Accept* or *False positive* and paste the comment. Optionally, *Administration ▸ General Settings ▸ Analysis
+55
View File
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.Diagnostics;
using System.IO;
namespace FrameLedger.App.Services;
/// <summary>
/// Opens a folder, or a file selected in its folder, in Windows Explorer — the one way the App does it (beta.24 PR-2).
/// </summary>
/// <remarks>
/// <para>
/// <b>Started by its full path in the Windows folder, never by a name the <c>PATH</c> resolves</b> (SonarCloud
/// <c>csharpsquid:S4036</c>): five places started <c>"explorer.exe"</c> by name, so a program of that name earlier on
/// the search path would have been run in its place.
/// </para>
/// <para>
/// <b>The path is always quoted</b>, as two of the five already did: a bare one leaves Explorer to guess where it ends,
/// and its command line is a list of comma-separated switches. A trailing separator is dropped first, because
/// <c>\"</c> would read as an escaped quote.
/// </para>
/// </remarks>
internal static class Explorer
{
/// <summary><c>%WINDIR%\explorer.exe</c>.</summary>
public static string ExecutablePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
/// <summary>Explorer's arguments that open <paramref name="folder"/>.</summary>
public static string FolderArguments(string folder)
{
ArgumentException.ThrowIfNullOrWhiteSpace(folder);
return Quote(folder);
}
/// <summary>Explorer's arguments that open the folder <paramref name="file"/> is in, with it selected.</summary>
public static string SelectArguments(string file)
{
ArgumentException.ThrowIfNullOrWhiteSpace(file);
return "/select," + Quote(file);
}
/// <summary>Opens <paramref name="folder"/>; throws what <see cref="Process.Start(ProcessStartInfo)"/> throws.</summary>
public static void OpenFolder(string folder) => Start(FolderArguments(folder));
/// <summary>Opens the folder <paramref name="file"/> is in, with it selected; throws what <see cref="Process.Start(ProcessStartInfo)"/> throws.</summary>
public static void ShowFile(string file) => Start(SelectArguments(file));
private static void Start(string arguments)
{
using Process? _ = Process.Start(new ProcessStartInfo(ExecutablePath, arguments) { UseShellExecute = true });
}
private static string Quote(string path) => "\"" + Path.TrimEndingDirectorySeparator(path.Trim('"')) + "\"";
}
@@ -2,7 +2,6 @@
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Windows;
@@ -26,7 +25,7 @@ internal static class StartupFailureDialog
try
{
using Process? _ = Process.Start(new ProcessStartInfo("explorer.exe", logsDirectory) { UseShellExecute = true });
Explorer.OpenFolder(logsDirectory);
}
catch (Exception ex) when (ex is Win32Exception or InvalidOperationException)
{
@@ -2,7 +2,6 @@
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using CommunityToolkit.Mvvm.Input;
@@ -36,7 +35,7 @@ public sealed partial class BugReportPreviewViewModel
{
try
{
using Process? _ = Process.Start(new ProcessStartInfo("explorer.exe", "/select,\"" + _model.ZipPath + "\"") { UseShellExecute = true });
Explorer.ShowFile(_model.ZipPath);
}
catch (Exception ex) when (ex is Win32Exception or InvalidOperationException)
{
@@ -80,6 +80,7 @@ public sealed partial class FirstRunViewModel : ObservableObject, IDisposable
public IUrlOpener Urls => _urls;
/// <summary>True when the user accepted (and the rows are written), false when they declined or closed the window.</summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD003:Avoid awaiting foreign Tasks", Justification = "the task of this view model's own TaskCompletionSource, completed by the window's buttons on the dispatcher; FirstRunFlow awaits it for the user's answer, and RunContinuationsAsynchronously keeps the completion from running the waiter inline (VS Threading Analyzers 18.12 flag it; Dependabot #314)")]
public Task<bool> Outcome => _outcome.Task;
public bool IsLegalStep => Step == LegalStep;
@@ -2,7 +2,6 @@
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
@@ -120,7 +119,7 @@ public sealed partial class LogsViewModel : ObservableObject
{
try
{
using Process? _ = Process.Start(new ProcessStartInfo("explorer.exe", UiPaths.Logs) { UseShellExecute = true });
Explorer.OpenFolder(UiPaths.Logs);
}
catch (Exception ex) when (ex is Win32Exception or InvalidOperationException)
{
@@ -2,7 +2,6 @@
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using CommunityToolkit.Mvvm.ComponentModel;
@@ -191,7 +190,7 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable,
{
try
{
using Process? _ = Process.Start(new ProcessStartInfo("explorer.exe", UiPaths.DataDirectory) { UseShellExecute = true });
Explorer.OpenFolder(UiPaths.DataDirectory);
}
catch (Exception ex) when (ex is Win32Exception or InvalidOperationException)
{
@@ -2,7 +2,6 @@
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
@@ -81,7 +80,7 @@ public partial class AboutWindow : FluentWindow
try
{
using Process? _ = Process.Start(new ProcessStartInfo("explorer.exe", "\"" + LicencesFolder + "\"") { UseShellExecute = true });
Explorer.OpenFolder(LicencesFolder);
}
catch (Exception ex) when (ex is Win32Exception or InvalidOperationException)
{
@@ -343,7 +343,10 @@ public sealed class CaptureOrchestrator
_log($"election: pid {elected.Value.Pid} ({path}) is the newest tracked descendant; attaching");
if (current is not null && current.SessionGuid == launched.SessionGuid)
{
session = _recorder.RecordAsync(Attach(path, row?.Name, null, default), ct);
// No stop token: this session runs under the launch's own entry and StopSession cannot address it
// (its summary above). CancellationToken.None says so: ct, the host's shutdown, is the recording's own
// token (RecordAsync's second argument), and as the stop token it would turn a shutdown into a user stop.
session = _recorder.RecordAsync(Attach(path, row?.Name, null, CancellationToken.None), ct);
}
else
{
@@ -60,24 +60,12 @@ public sealed class ProcessLauncher : IProcessLauncher
}
/// <inheritdoc />
public (int Pid, ITargetLiveness Alive)? Start(string exePath, string arguments) => Start(exePath, arguments, _environment, _enableVulkanLayer);
public (int Pid, ITargetLiveness Alive)? Start(string exePath, string arguments) => StartCore(exePath, arguments, _environment, _enableVulkanLayer, out _);
/// <inheritdoc />
public (int Pid, ITargetLiveness Alive)? Start(string exePath, string arguments, out int? win32Error) =>
StartCore(exePath, arguments, _environment, _enableVulkanLayer, out win32Error);
/// <summary>Start <paramref name="exePath"/> with <paramref name="arguments"/>; null when it could not be started or pinned.</summary>
/// <param name="exePath">The consented executable.</param>
/// <param name="arguments">Its own command line, verbatim.</param>
/// <param name="environment">
/// Variables added to the child's environment — the Vulkan layer's, from
/// <c>VkLayerLaunchEnvironment</c>, when the layer is staged beside this host (P1 item 3).
/// </param>
/// <param name="enableVulkanLayer">False leaves <see cref="VkLayerLaunchEnvironment.EnableVariable"/> unset (the kill switch, decision D7).</param>
public static (int Pid, ITargetLiveness Alive)? Start(string exePath, string arguments,
IReadOnlyDictionary<string, string>? environment = null, bool enableVulkanLayer = true) =>
StartCore(exePath, arguments, environment, enableVulkanLayer, out _);
/// <summary>The start, keeping the Win32 error of one that failed (beta.8: it was swallowed, and the user read only "could not start").</summary>
private static (int Pid, ITargetLiveness Alive)? StartCore(string exePath, string arguments,
IReadOnlyDictionary<string, string>? environment, bool enableVulkanLayer, out int? error)
@@ -93,7 +93,7 @@ public sealed class PipeServer : IIpcEventPublisher, IDisposable
public async Task RunAsync(CancellationToken ct)
{
var failures = new AcceptFailures(_log);
while (true)
while (!ct.IsCancellationRequested)
{
await _slots.WaitAsync(ct).ConfigureAwait(false);
NamedPipeServerStream? stream = null;
@@ -123,6 +123,10 @@ public sealed class PipeServer : IIpcEventPublisher, IDisposable
_clients[id] = client;
client.Start(ct);
}
// The loop's only way out is cancellation, and the task ends cancelled as it did when the wait threw
// (SonarCloud csharpsquid:S2190 read the old while (true) as a loop that never ends).
ct.ThrowIfCancellationRequested();
}
public void Publish<T>(string type, T payload)
@@ -88,7 +88,8 @@ std::int32_t FlGuardRulesFilePath(wchar_t* out, std::int32_t cap) {
out[0] = L'\0'; // never hand back a partial path: it names a different file
return 0;
}
return static_cast<std::int32_t>(wcslen(out));
// Bounded by the caller's buffer, never only by the terminator (SonarCloud cpp:S5813, beta.24).
return static_cast<std::int32_t>(wcsnlen(out, static_cast<std::size_t>(cap)));
}
std::int32_t FlGuardBuildId(char* out, std::int32_t cap) {
@@ -326,7 +326,9 @@ FL_NV_API int32_t FlNvDriverVersion(uint32_t* version, char* branch, uint32_t br
}
*version = v;
if (branch != nullptr && branchCapacity > 0u) {
const size_t n = std::strlen(b);
// Bounded by the buffer, not by the terminator: the string is the driver's, and a driver that filled all
// NVAPI_SHORT_STRING_MAX bytes without one must not send this read past it (SonarCloud cpp:S5813, beta.24).
const size_t n = strnlen(b, sizeof(b));
const size_t copy = n < branchCapacity - 1u ? n : branchCapacity - 1u;
std::memcpy(branch, b, copy);
branch[copy] = '\0';
@@ -278,9 +278,9 @@ constexpr bool SameA(const char* a, const char* b) noexcept {
}
// Which leaf slot a row's module is, exactly as spelled in the table. -1 if none.
constexpr int FfxLeafOfExact(const wchar_t* module) noexcept {
constexpr int FfxLeafOfExact(const wchar_t* moduleName) noexcept {
for (uint32_t i = 0; i < kFfxLeafCount; ++i) {
if (SameW(module, kFfxLeafModules[i])) {
if (SameW(moduleName, kFfxLeafModules[i])) {
return static_cast<int>(i);
}
}
@@ -289,12 +289,12 @@ constexpr int FfxLeafOfExact(const wchar_t* module) noexcept {
// The runtime twin: the loader is case-insensitive about module names, so this is
// too. dllmain's installer indexes its per-leaf storage with the result.
inline int FfxLeafOf(const wchar_t* module) noexcept {
if (module == nullptr) {
inline int FfxLeafOf(const wchar_t* moduleName) noexcept {
if (moduleName == nullptr) {
return -1;
}
for (uint32_t i = 0; i < kFfxLeafCount; ++i) {
if (_wcsicmp(module, kFfxLeafModules[i]) == 0) {
if (_wcsicmp(moduleName, kFfxLeafModules[i]) == 0) {
return static_cast<int>(i);
}
}
@@ -353,9 +353,9 @@ inline constexpr const wchar_t* kModuleSlInterposer = L"sl.interposer.dll";
inline constexpr const char* kSymbolSlSetTag = "slSetTag";
inline constexpr const char* kSymbolSlSetTagForFrame = "slSetTagForFrame";
constexpr bool InventoryHasRow(const wchar_t* module, const char* symbol) noexcept {
constexpr bool InventoryHasRow(const wchar_t* moduleName, const char* symbol) noexcept {
#define FL_ROW_HAS(mod, sym, family) \
if (SameW(mod, module) && SameA(sym, symbol)) { \
if (SameW(mod, moduleName) && SameA(sym, symbol)) { \
return true; \
}
FL_HOOK_INVENTORY(FL_ROW_HAS)
@@ -374,9 +374,9 @@ static_assert(InventoryHasRow(kModuleFfxFsr3Host, kSymbolFfxFsr3DispatchUpscale)
// without a leaf would resolve, reach InstallByFamily, and find no slot -- and the
// installer's answer to that is to install nothing, silently, which is the shape
// this whole file exists to make loud.
constexpr bool FfxDispatchRowExistsFor(const wchar_t* module) noexcept {
constexpr bool FfxDispatchRowExistsFor(const wchar_t* moduleName) noexcept {
#define FL_FFX_ROW_FOR(mod, sym, family) \
if (SameW(mod, module) && SameA(sym, "ffxDispatch")) { \
if (SameW(mod, moduleName) && SameA(sym, "ffxDispatch")) { \
return true; \
}
FL_HOOK_INVENTORY(FL_FFX_ROW_FOR)
@@ -392,9 +392,9 @@ constexpr bool EveryFfxDispatchRowIsALeaf() noexcept {
#undef FL_FFX_ROW_IS_LEAF
return true;
}
constexpr bool AnyRowNames(const wchar_t* module) noexcept {
constexpr bool AnyRowNames(const wchar_t* moduleName) noexcept {
#define FL_ANY_ROW_NAMES(mod, sym, family) \
if (SameW(mod, module)) { \
if (SameW(mod, moduleName)) { \
return true; \
}
FL_HOOK_INVENTORY(FL_ANY_ROW_NAMES)
@@ -511,20 +511,20 @@ inline bool SpeaksFsr3Host(HMODULE h) noexcept {
GetProcAddress(h, "ffxFsr3SkipPresent") != nullptr;
}
inline bool SpeaksExpectedAbi(const wchar_t* module, HMODULE h) noexcept {
if (module == nullptr) {
inline bool SpeaksExpectedAbi(const wchar_t* moduleName, HMODULE h) noexcept {
if (moduleName == nullptr) {
return false;
}
if (_wcsicmp(module, L"sl.interposer.dll") == 0) {
if (_wcsicmp(moduleName, L"sl.interposer.dll") == 0) {
return SpeaksStreamline2(h);
}
if (_wcsicmp(module, kModuleFfxFsr3Host) == 0) {
if (_wcsicmp(moduleName, kModuleFfxFsr3Host) == 0) {
return SpeaksFsr3Host(h);
}
// THE AMD ARM, by leaf name, for the same reason the Streamline arm is by name:
// the loader also exports all five and is not a leaf, so a prefix test would
// approve a module the inventory deliberately does not hook.
if (FfxLeafOf(module) >= 0) {
if (FfxLeafOf(moduleName) >= 0) {
return SpeaksFfxApi(h);
}
return true;
@@ -549,19 +549,19 @@ inline bool SpeaksExpectedAbi(const wchar_t* module, HMODULE h) noexcept {
// would do the same thing irreversibly; a plain reference is the smaller claim.
//
// Allocation-free and syscall-cheap: two documented calls, no enumeration.
inline void* ResolveScoped(const wchar_t* module, const char* symbol) noexcept {
if (module == nullptr || symbol == nullptr) {
inline void* ResolveScoped(const wchar_t* moduleName, const char* symbol) noexcept {
if (moduleName == nullptr || symbol == nullptr) {
return nullptr;
}
HMODULE h = nullptr;
if (!GetModuleHandleExW(0, module, &h) || h == nullptr) {
if (!GetModuleHandleExW(0, moduleName, &h) || h == nullptr) {
return nullptr; // the game has not loaded it; that is an answer, not a failure
}
// A module of the right NAME whose ABI is not ours is the same answer as no
// module: we cannot read its arguments, so we do not hook it. See
// SpeaksExpectedAbi -- this is the Witcher 3 case, and refusing here is what
// keeps a wrong upscaler name out of the record.
if (!SpeaksExpectedAbi(module, h)) {
if (!SpeaksExpectedAbi(moduleName, h)) {
return nullptr;
}
return reinterpret_cast<void*>(GetProcAddress(h, symbol));
@@ -606,9 +606,9 @@ inline void* ResolveScoped(const wchar_t* module, const char* symbol) noexcept {
// Is a module of this name in the process right now? UNCHANGED_REFCOUNT, unlike
// ResolveScoped: the census patches nothing, so it has no reason to keep the
// module alive and takes the smaller claim. Allocation-free, one documented call.
inline bool IsModuleLoaded(const wchar_t* module) noexcept {
inline bool IsModuleLoaded(const wchar_t* moduleName) noexcept {
HMODULE h = nullptr;
return GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, module, &h) && h != nullptr;
return GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, moduleName, &h) && h != nullptr;
}
// One census pass. Always carries FL_CENSUS_RAN, so a word without it means the
+15 -15
View File
@@ -1990,9 +1990,9 @@ void PublishSlTagCensus() noexcept {
// that is not there is the ordinary case, a mapped module without the export is
// the one a bug report needs to say.
const char* g_symbolMissingSeen[16]{};
void NoteSymbolMissingOnce(const wchar_t* module, const char* symbol) noexcept {
void NoteSymbolMissingOnce(const wchar_t* moduleName, const char* symbol) noexcept {
HMODULE h = nullptr;
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, module, &h) || h == nullptr) {
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, moduleName, &h) || h == nullptr) {
return;
}
for (const char*& seen : g_symbolMissingSeen) {
@@ -2007,18 +2007,18 @@ void NoteSymbolMissingOnce(const wchar_t* module, const char* symbol) noe
}
}
bool InstallRow(const wchar_t* module, const char* symbol, uint32_t family, void* detour, void** original,
bool InstallRow(const wchar_t* moduleName, const char* symbol, uint32_t family, void* detour, void** original,
std::atomic<uint32_t>& live) noexcept {
if (live.load(std::memory_order_acquire) != 0) {
return true;
}
void* target = fl::inventory::ResolveScoped(module, symbol);
void* target = fl::inventory::ResolveScoped(moduleName, symbol);
if (target == nullptr) {
// The game has not loaded Streamline, or loaded a generation whose ABI we
// do not speak (#71). An answer, not a failure -- logged once when the
// module IS there and the symbol is not, which is the shape worth reading.
NoteSymbolMissingOnce(module, symbol);
NoteSymbolMissingOnce(moduleName, symbol);
return false;
}
@@ -2036,13 +2036,13 @@ bool InstallRow(const wchar_t* module, const char* symbol, uint32_t family, void
// is the safe direction: an unbound row is a table entry somebody added without
// writing its hook, and hooking it with a neighbour's body is exactly what this
// function exists to stop.
bool InstallByFamily(const wchar_t* module, const char* symbol, uint32_t family) noexcept {
bool InstallByFamily(const wchar_t* moduleName, const char* symbol, uint32_t family) noexcept {
// EQUALITY AGAINST THE COMPOUND CONSTANT, not `& FL_HOOK_UPSCALER_IDENTITY`. A
// bit test would bind any future row that happens to include identity to THIS
// detour -- which is the neighbour's-body defect this function exists to stop,
// and it would arrive silently because the row would still install.
if (family == fl::inventory::kFamilyEvaluateFeature) {
return InstallRow(module, symbol, family, reinterpret_cast<void*>(&Hook_SlEvaluateFeature),
return InstallRow(moduleName, symbol, family, reinterpret_cast<void*>(&Hook_SlEvaluateFeature),
reinterpret_cast<void**>(&g_origSlEvaluateFeature), g_upscalerIdentityLive);
}
if (family == static_cast<uint32_t>(fl::FL_HOOK_UPSCALER_PARAMS)) {
@@ -2060,7 +2060,7 @@ bool InstallByFamily(const wchar_t* module, const char* symbol, uint32_t family)
if (patched.load(std::memory_order_acquire) != 0) {
return true;
}
void* target = fl::inventory::ResolveScoped(module, symbol);
void* target = fl::inventory::ResolveScoped(moduleName, symbol);
if (target == nullptr) {
return false; // not loaded, a generation without this export, or an ABI we do not speak
}
@@ -2075,7 +2075,7 @@ bool InstallByFamily(const wchar_t* module, const char* symbol, uint32_t family)
return true;
}
if (family == static_cast<uint32_t>(fl::FL_HOOK_FG_EVALUATIONS)) {
return InstallRow(module, symbol, family, reinterpret_cast<void*>(&Hook_SlGetNewFrameToken),
return InstallRow(moduleName, symbol, family, reinterpret_cast<void*>(&Hook_SlGetNewFrameToken),
reinterpret_cast<void**>(&g_origSlGetNewFrameToken), g_frameTokensLive);
}
if (family == fl::inventory::kFamilyFfxDispatch) {
@@ -2096,15 +2096,15 @@ bool InstallByFamily(const wchar_t* module, const char* symbol, uint32_t family)
// nothing: fl_hook_inventory.h's static_asserts make the latter unreachable for
// the rows as written, and installing nothing is the safe direction for a row
// somebody adds later.
const int leaf = fl::inventory::FfxLeafOf(module);
const int leaf = fl::inventory::FfxLeafOf(moduleName);
if (leaf < 0) {
if (_wcsicmp(module, fl::inventory::kModuleFfxFsr3Host) != 0) {
if (_wcsicmp(moduleName, fl::inventory::kModuleFfxFsr3Host) != 0) {
return false;
}
if (g_fsr3HostPatched.load(std::memory_order_acquire) != 0) {
return true;
}
void* target = fl::inventory::ResolveScoped(module, symbol);
void* target = fl::inventory::ResolveScoped(moduleName, symbol);
if (target == nullptr) {
return false; // not loaded, or a module of the name that does not speak the 3.0 host ABI
}
@@ -2119,7 +2119,7 @@ bool InstallByFamily(const wchar_t* module, const char* symbol, uint32_t family)
if (g_ffxPatched[slot].load(std::memory_order_acquire) != 0) {
return true;
}
void* target = fl::inventory::ResolveScoped(module, symbol);
void* target = fl::inventory::ResolveScoped(moduleName, symbol);
if (target == nullptr) {
return false; // not loaded, or a module of the name that does not speak ffx-api
}
@@ -3386,12 +3386,12 @@ __declspec(dllexport) void FlRequestUnhook() {
} // extern "C"
BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID) {
BOOL APIENTRY DllMain(HMODULE self, DWORD reason, LPVOID) {
if (reason == DLL_PROCESS_ATTACH) {
// ONLY these two calls. Everything else -- mapping creation, MinHook,
// dummy-device creation, hook installation -- happens on the init thread,
// outside the loader lock.
DisableThreadLibraryCalls(module);
DisableThreadLibraryCalls(self);
g_initThread = CreateThread(nullptr, 0, InitThread, nullptr, 0, nullptr);
}
// No DLL_PROCESS_DETACH teardown: 17_HOOK_ENGINE §Unhooking is explicit that
@@ -53,8 +53,10 @@ using TargetFn = int(__stdcall*)(int);
// function body with enough bytes to patch.
__declspec(noinline) int __stdcall TargetFunction(int x) {
volatile int acc = x;
acc += 1;
acc *= 2;
// Plain assignments, not += / *=: a compound assignment to a volatile is deprecated in C++20 (SonarCloud
// cpp:S6191, beta.24). Same loads and stores, so the body MinHook patches is unchanged in kind.
acc = acc + 1;
acc = acc * 2;
return acc;
}
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.IO;
using FluentAssertions;
using FrameLedger.App.Services;
namespace FrameLedger.App.Tests;
/// <summary>
/// Explorer is started by its full path and handed a quoted path (beta.24 PR-2, SonarCloud <c>csharpsquid:S4036</c>):
/// never a name the search path resolves, never a path Explorer has to guess the end of. Nothing here starts it.
/// </summary>
public sealed class ExplorerTests
{
[Fact]
public void ItIsTheOneInTheWindowsFolder()
{
string windows = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
Explorer.ExecutablePath.Should().Be(Path.Combine(windows, "explorer.exe"));
Path.IsPathRooted(Explorer.ExecutablePath).Should().BeTrue("a bare name would be resolved through PATH");
}
[Fact]
public void AFolderIsQuotedWhateverItHoldsAndLosesItsTrailingSeparator()
{
Explorer.FolderArguments(@"C:\Users\Ann Lee\AppData\Local\FrameLedger\logs")
.Should().Be("\"C:\\Users\\Ann Lee\\AppData\\Local\\FrameLedger\\logs\"");
Explorer.FolderArguments(@"D:\Games\Dying Light, The Beast\")
.Should().Be("\"D:\\Games\\Dying Light, The Beast\"", "a trailing \\ before the closing quote would escape it");
Explorer.FolderArguments("\"C:\\already quoted\"").Should().Be("\"C:\\already quoted\"", "a quoted path is not quoted twice");
}
[Fact]
public void AFileIsSelectedInItsFolder() =>
Explorer.SelectArguments(@"C:\Users\Ann Lee\Desktop\frameledger-bug.zip")
.Should().Be("/select,\"C:\\Users\\Ann Lee\\Desktop\\frameledger-bug.zip\"");
[Theory]
[InlineData("")]
[InlineData(" ")]
public void NoPathIsRefused(string path)
{
FluentActions.Invoking(() => Explorer.FolderArguments(path)).Should().Throw<ArgumentException>();
FluentActions.Invoking(() => Explorer.SelectArguments(path)).Should().Throw<ArgumentException>();
}
}
@@ -388,6 +388,7 @@ public sealed class GameDetailViewModelTests
// The fake Agent answers Written; the real one would have stamped the row — mirror that here so the reload shows it.
agent.Answer = r =>
{
#pragma warning disable VSTHRD002 // the fake Agent's answer is synchronous by its interface, and Microsoft.Data.Sqlite completes this write synchronously anyway
_ = new Infrastructure.Persistence.SqliteGameConsentStore(s.Db).RecordOperatorAcknowledgementAsync(new Application.Consent.OperatorAcknowledgement
{
Fingerprint = game.Fingerprint,
@@ -395,6 +396,7 @@ public sealed class GameDetailViewModelTests
AcknowledgedAt = DateTimeOffset.UtcNow,
Provenance = Domain.Consent.ConsentProvenance.ConsentDialog,
}, Ct).AsTask().GetAwaiter().GetResult();
#pragma warning restore VSTHRD002
return IpcCodec.Decode(IpcCodec.Encode(IpcMessageType.HookEnabledAck, "1", new HookEnabledAck(r.GameId, true, "Written", "clean")));
};
vm.ToggleHookingCommand.Execute(null);