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
@@ -49,7 +49,41 @@ namespace SafeExamBrowser.WindowsApi.Desktops
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
var handle = User32.OpenInputDesktop(0, false, (uint) AccessMask.DESKTOP_NONE);
var name = default(string);
var nameLength = 0;
if (handle != IntPtr.Zero)
{
User32.GetUserObjectInformation(handle, Constant.UOI_NAME, IntPtr.Zero, 0, ref nameLength);
var namePointer = Marshal.AllocHGlobal(nameLength);
var success = User32.GetUserObjectInformation(handle, Constant.UOI_NAME, namePointer, nameLength, ref nameLength);
if (success)
{
name = Marshal.PtrToStringAnsi(namePointer);
Marshal.FreeHGlobal(namePointer);
if (name?.Equals(desktop.Name, StringComparison.OrdinalIgnoreCase) != true)
{
logger.Warn($"Detected desktop switch to '{name}' [{handle}], trying to reactivate {desktop}...");
desktop.Activate();
}
}
else
{
logger.Warn("Failed to get name of currently active desktop!");
}
User32.CloseDesktop(handle);
}
else
{
logger.Warn("Failed to get currently active desktop!");
}
timer.Start();
}
}
}