fix(app): Windows keeps secrets out of captures by its real version
Before Windows 10 2004, SetWindowDisplayAffinity takes WDA_EXCLUDEFROMCAPTURE without failing and acts as WDA_MONITOR, so the fallback on a failure never ran and its comment was wrong (the short reading). Both apps' runners now choose by the real version, RtlGetVersion (GetVersionEx tells what the manifest claims): WDA_EXCLUDEFROMCAPTURE from build 19041 on, WDA_MONITOR before. Checked for syntax only: nothing here builds for Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
efc1c7ffd6
commit
7ac6eb75b4
2 changed files with 68 additions and 10 deletions
|
|
@ -12,6 +12,35 @@
|
||||||
#define WDA_EXCLUDEFROMCAPTURE 0x00000011
|
#define WDA_EXCLUDEFROMCAPTURE 0x00000011
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Whether this Windows keeps a window out of captures with
|
||||||
|
// WDA_EXCLUDEFROMCAPTURE: Windows 10 2004 (build 19041) and later. Before,
|
||||||
|
// it takes the value without failing and acts as WDA_MONITOR, so the
|
||||||
|
// version decides, not a failure. RtlGetVersion tells the real version;
|
||||||
|
// GetVersionEx tells what the app's manifest claims.
|
||||||
|
bool ExcludesFromCapture() {
|
||||||
|
using RtlGetVersionFunction = LONG(WINAPI*)(PRTL_OSVERSIONINFOW);
|
||||||
|
const HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
|
||||||
|
if (!ntdll) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto rtl_get_version = reinterpret_cast<RtlGetVersionFunction>(
|
||||||
|
GetProcAddress(ntdll, "RtlGetVersion"));
|
||||||
|
if (!rtl_get_version) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
RTL_OSVERSIONINFOW version = {};
|
||||||
|
version.dwOSVersionInfoSize = sizeof(version);
|
||||||
|
if (rtl_get_version(&version) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return version.dwMajorVersion > 10 ||
|
||||||
|
(version.dwMajorVersion == 10 && version.dwBuildNumber >= 19041);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
|
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
|
||||||
: project_(project) {}
|
: project_(project) {}
|
||||||
|
|
||||||
|
|
@ -60,11 +89,11 @@ void FlutterWindow::GuardScreen() {
|
||||||
result) {
|
result) {
|
||||||
if (call.method_name() == "hold") {
|
if (call.method_name() == "hold") {
|
||||||
secrets_shown_++;
|
secrets_shown_++;
|
||||||
// Before Windows 10 2004 the exclusion fails: the window shows
|
// Before Windows 10 2004 the window shows black in captures
|
||||||
// black in captures instead.
|
// instead.
|
||||||
if (!SetWindowDisplayAffinity(GetHandle(), WDA_EXCLUDEFROMCAPTURE)) {
|
static const bool excludes = ExcludesFromCapture();
|
||||||
SetWindowDisplayAffinity(GetHandle(), WDA_MONITOR);
|
SetWindowDisplayAffinity(
|
||||||
}
|
GetHandle(), excludes ? WDA_EXCLUDEFROMCAPTURE : WDA_MONITOR);
|
||||||
result->Success();
|
result->Success();
|
||||||
} else if (call.method_name() == "release") {
|
} else if (call.method_name() == "release") {
|
||||||
secrets_shown_ = secrets_shown_ > 0 ? secrets_shown_ - 1 : 0;
|
secrets_shown_ = secrets_shown_ > 0 ? secrets_shown_ - 1 : 0;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,35 @@
|
||||||
#define WDA_EXCLUDEFROMCAPTURE 0x00000011
|
#define WDA_EXCLUDEFROMCAPTURE 0x00000011
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Whether this Windows keeps a window out of captures with
|
||||||
|
// WDA_EXCLUDEFROMCAPTURE: Windows 10 2004 (build 19041) and later. Before,
|
||||||
|
// it takes the value without failing and acts as WDA_MONITOR, so the
|
||||||
|
// version decides, not a failure. RtlGetVersion tells the real version;
|
||||||
|
// GetVersionEx tells what the app's manifest claims.
|
||||||
|
bool ExcludesFromCapture() {
|
||||||
|
using RtlGetVersionFunction = LONG(WINAPI*)(PRTL_OSVERSIONINFOW);
|
||||||
|
const HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
|
||||||
|
if (!ntdll) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto rtl_get_version = reinterpret_cast<RtlGetVersionFunction>(
|
||||||
|
GetProcAddress(ntdll, "RtlGetVersion"));
|
||||||
|
if (!rtl_get_version) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
RTL_OSVERSIONINFOW version = {};
|
||||||
|
version.dwOSVersionInfoSize = sizeof(version);
|
||||||
|
if (rtl_get_version(&version) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return version.dwMajorVersion > 10 ||
|
||||||
|
(version.dwMajorVersion == 10 && version.dwBuildNumber >= 19041);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
|
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
|
||||||
: project_(project) {}
|
: project_(project) {}
|
||||||
|
|
||||||
|
|
@ -60,11 +89,11 @@ void FlutterWindow::GuardScreen() {
|
||||||
result) {
|
result) {
|
||||||
if (call.method_name() == "hold") {
|
if (call.method_name() == "hold") {
|
||||||
secrets_shown_++;
|
secrets_shown_++;
|
||||||
// Before Windows 10 2004 the exclusion fails: the window shows
|
// Before Windows 10 2004 the window shows black in captures
|
||||||
// black in captures instead.
|
// instead.
|
||||||
if (!SetWindowDisplayAffinity(GetHandle(), WDA_EXCLUDEFROMCAPTURE)) {
|
static const bool excludes = ExcludesFromCapture();
|
||||||
SetWindowDisplayAffinity(GetHandle(), WDA_MONITOR);
|
SetWindowDisplayAffinity(
|
||||||
}
|
GetHandle(), excludes ? WDA_EXCLUDEFROMCAPTURE : WDA_MONITOR);
|
||||||
result->Success();
|
result->Success();
|
||||||
} else if (call.method_name() == "release") {
|
} else if (call.method_name() == "release") {
|
||||||
secrets_shown_ = secrets_shown_ > 0 ? secrets_shown_ - 1 : 0;
|
secrets_shown_ = secrets_shown_ > 0 ? secrets_shown_ - 1 : 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue