Update Safe Exam Browser Patch to 3.10.0.826

This commit is contained in:
2025-09-16 16:32:31 +02:00
parent 4827ae1afc
commit dd82d45ed8
320 changed files with 8445 additions and 5295 deletions

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using SafeExamBrowser.UserInterface.Contracts;
namespace SafeExamBrowser.UserInterface.Shared
{
public abstract class Guardable
{
private readonly IWindowGuard windowGuard;
public Guardable(IWindowGuard windowGuard = default)
{
this.windowGuard = windowGuard;
}
protected T Guard<T>(T window)
{
windowGuard?.Register(window);
return window;
}
}
}

View File

@@ -71,6 +71,7 @@
<Compile Include="Activators\TaskviewKeyboardActivator.cs" />
<Compile Include="Activators\TerminationActivator.cs" />
<Compile Include="Activators\TouchActivator.cs" />
<Compile Include="Guardable.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
@@ -80,6 +81,7 @@
<Compile Include="Utilities\Thumbnail.cs" />
<Compile Include="Utilities\VisualExtensions.cs" />
<Compile Include="Utilities\WindowExtensions.cs" />
<Compile Include="WindowGuard.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SafeExamBrowser.Core.Contracts\SafeExamBrowser.Core.Contracts.csproj">

View File

@@ -16,11 +16,12 @@ namespace SafeExamBrowser.UserInterface.Shared.Utilities
public static class WindowExtensions
{
private const int GWL_STYLE = -16;
private const uint MF_BYCOMMAND = 0x00000000;
private const uint MF_ENABLED = 0x00000000;
private const uint MF_GRAYED = 0x00000001;
private const uint MF_BYCOMMAND = 0x0;
private const uint MF_ENABLED = 0x0;
private const uint MF_GRAYED = 0x1;
private const uint SC_CLOSE = 0xF060;
private const uint SWP_SHOWWINDOW = 0x0040;
private const uint SWP_SHOWWINDOW = 0x40;
private const uint WDA_EXCLUDEFROMCAPTURE = 0x11;
private const int WS_SYSMENU = 0x80000;
private static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
@@ -47,6 +48,25 @@ namespace SafeExamBrowser.UserInterface.Shared.Utilities
}
}
public static bool ExcludeFromCapture(this Window window)
{
var helper = new WindowInteropHelper(window);
return SetWindowDisplayAffinity(helper.Handle, WDA_EXCLUDEFROMCAPTURE);
}
public static void ExecuteWithAccess(this Window window, Action action)
{
if (window.CheckAccess())
{
action();
}
else
{
window.Dispatcher.Invoke(action);
}
}
public static void HideCloseButton(this Window window)
{
var helper = new WindowInteropHelper(window);
@@ -75,6 +95,9 @@ namespace SafeExamBrowser.UserInterface.Shared.Utilities
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern bool SetWindowDisplayAffinity(IntPtr hwnd, uint dwAffinity);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Windows;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.UserInterface.Contracts;
using SafeExamBrowser.UserInterface.Shared.Utilities;
namespace SafeExamBrowser.UserInterface.Shared
{
public class WindowGuard : IWindowGuard
{
private readonly ConcurrentStack<Window> cache;
private readonly ILogger logger;
private bool? active;
public WindowGuard(ILogger logger)
{
this.cache = new ConcurrentStack<Window>();
this.logger = logger;
}
public void Activate()
{
active = true;
while (cache.Any())
{
if (cache.TryPop(out var window))
{
Guard(window);
}
}
}
public void Deactivate()
{
active = false;
cache.Clear();
}
public void Register(object @object)
{
if (@object is Window window)
{
window.ExecuteWithAccess(() => window.Loaded += (o, a) => Triage(window));
}
else
{
throw new ArgumentException($"The given object '{@object}' is not an application window!", nameof(@object));
}
}
private void Guard(Window window)
{
window.ExecuteWithAccess(() =>
{
var info = $"{window.GetType().Name}";
try
{
var success = window.ExcludeFromCapture();
if (success)
{
logger.Debug($"Successfully guarded window '{info}'.");
}
else
{
logger.Warn($"Failed to guard window '{info}'!");
}
}
catch (Exception e)
{
logger.Error($"Failed to guard window '{info}'!", e);
}
});
}
private void Triage(Window window)
{
if (active == true)
{
Guard(window);
}
else if (!active.HasValue)
{
cache.Push(window);
}
}
}
}