Restore SEBPatch

This commit is contained in:
2025-06-01 11:56:28 +02:00
parent 8c656e3137
commit 00707825b4
1009 changed files with 5005 additions and 6502 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
* 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
@@ -34,27 +34,77 @@ namespace SafeExamBrowser.Monitoring.System.Components
internal void StartMonitoring()
{
registry.ValueChanged += Registry_ValueChanged;
logger.Info("Started monitoring cursors.");
if (registry.TryGetNames(RegistryValue.UserHive.Cursors_Key, out var names))
{
foreach (var name in names)
{
registry.StartMonitoring(RegistryValue.UserHive.Cursors_Key, name);
}
logger.Info("Started monitoring cursors.");
}
else
{
logger.Warn("Failed to start monitoring cursor registry values!");
}
}
internal void StopMonitoring()
{
registry.ValueChanged -= Registry_ValueChanged;
logger.Info("Stopped monitoring cursors.");
if (registry.TryGetNames(RegistryValue.UserHive.Cursors_Key, out var names))
{
foreach (var name in names)
{
registry.StopMonitoring(RegistryValue.UserHive.Cursors_Key, name);
}
logger.Info("Stopped monitoring cursors.");
}
else
{
logger.Warn("Failed to stop monitoring cursor registry values!");
}
}
internal bool Verify()
{
logger.Info($"Starting cursor verification...");
logger.Info("Cursor configuration successfully verified.");
var success = true;
var success = registry.TryGetNames(RegistryValue.UserHive.Cursors_Key, out var cursors);
if (success)
{
foreach (var cursor in cursors.Where(c => !string.IsNullOrWhiteSpace(c)))
{
success &= VerifyCursor(cursor);
}
if (success)
{
logger.Info("Cursor configuration successfully verified.");
}
else
{
logger.Warn("Cursor configuration is compromised!");
}
}
else
{
logger.Error("Failed to verify cursor configuration!");
}
return success;
}
private void Registry_ValueChanged(string key, string name, object oldValue, object newValue)
{
if (key == RegistryValue.UserHive.Cursors_Key)
{
HandleCursorChange(key, name, oldValue, newValue);
}
}
private void HandleCursorChange(string key, string name, object oldValue, object newValue)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
* 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
@@ -29,6 +29,7 @@ namespace SafeExamBrowser.Monitoring.System.Components
internal void StartMonitoring()
{
registry.ValueChanged += Registry_ValueChanged;
registry.StartMonitoring(RegistryValue.MachineHive.EaseOfAccess_Key, RegistryValue.MachineHive.EaseOfAccess_Name);
logger.Info("Started monitoring ease of access.");
}
@@ -36,6 +37,7 @@ namespace SafeExamBrowser.Monitoring.System.Components
internal void StopMonitoring()
{
registry.ValueChanged -= Registry_ValueChanged;
registry.StopMonitoring(RegistryValue.MachineHive.EaseOfAccess_Key, RegistryValue.MachineHive.EaseOfAccess_Name);
logger.Info("Stopped monitoring ease of access.");
}
@@ -43,14 +45,36 @@ namespace SafeExamBrowser.Monitoring.System.Components
internal bool Verify()
{
logger.Info($"Starting ease of access verification...");
logger.Info("Ease of access configuration successfully verified.");
return true;
var success = registry.TryRead(RegistryValue.MachineHive.EaseOfAccess_Key, RegistryValue.MachineHive.EaseOfAccess_Name, out var value);
if (success)
{
if (value is string s && string.IsNullOrWhiteSpace(s))
{
logger.Info("Ease of access configuration successfully verified.");
}
else
{
logger.Warn($"Ease of access configuration is compromised: '{value}'!");
success = false;
}
}
else
{
success = true;
logger.Info("Ease of access configuration successfully verified (value does not exist).");
}
return success;
}
private void Registry_ValueChanged(string key, string name, object oldValue, object newValue)
{
if (key == RegistryValue.MachineHive.EaseOfAccess_Key)
{
HandleEaseOfAccessChange(key, name, oldValue, newValue);
}
}
private void HandleEaseOfAccessChange(string key, string name, object oldValue, object newValue)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
* 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
@@ -33,13 +33,54 @@ namespace SafeExamBrowser.Monitoring.System.Components
internal bool Disable()
{
var success = nativeMethods.TryGetStickyKeys(out var state);
return true;
if (success)
{
success = nativeMethods.DisableStickyKeys();
if (success)
{
original = state;
logger.Info($"Disabled sticky keys (original state: {ToString(state)}).");
}
else
{
logger.Error($"Failed to disable sticky keys (original state: {ToString(state)})!");
}
}
else
{
logger.Error("Failed to retrieve sticky keys state!");
}
return success;
}
internal bool Enable()
{
return true;
var success = nativeMethods.TryGetStickyKeys(out var state);
if (success)
{
success = nativeMethods.EnableStickyKeys();
if (success)
{
original = state;
logger.Info($"Enabled sticky keys (original state: {ToString(state)}).");
}
else
{
logger.Error($"Failed to enable sticky keys (original state: {ToString(state)})!");
}
}
else
{
logger.Error("Failed to retrieve sticky keys state!");
}
return success;
}
internal bool Revert()
@@ -85,7 +126,17 @@ namespace SafeExamBrowser.Monitoring.System.Components
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (nativeMethods.TryGetStickyKeys(out var state))
{
if (state.IsEnabled || state.IsHotkeyActive)
{
HandleStickyKeysChange(state);
}
}
else
{
logger.Error("Failed to monitor sticky keys state!");
}
}
private void HandleStickyKeysChange(IStickyKeysState state)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
* 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
@@ -55,42 +55,43 @@ namespace SafeExamBrowser.Monitoring.System.Components
private void SystemEvents_EventsThreadShutdown(object sender, EventArgs e)
{
logger.Warn("System event thread is about to be terminated!");
}
private void SystemEvents_InstalledFontsChanged(object sender, EventArgs e)
{
logger.Info("Installed fonts changed.");
}
private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
logger.Info($"Power mode changed: {e.Mode}.");
}
private void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
{
logger.Warn($"User session ended! Reason: {e.Reason}.");
}
private void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
logger.Warn($"User session is ending! Reason: {e.Reason}.");
}
private void SystemEvents_SessionChanged(object sender, SessionSwitchEventArgs e)
{
logger.Info($"User session change detected: {e.Reason}.");
Task.Run(() => SessionChanged?.Invoke());
}
private void SystemEvents_TimeChanged(object sender, EventArgs e)
{
logger.Info("Time changed.");
}
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
logger.Info($"User preference changed. Category: {e.Category}.");
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
* 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