Restore SEBPatch
This commit is contained in:
23
SafeExamBrowser.WindowsApi.Contracts/Events/KeyModifier.cs
Normal file
23
SafeExamBrowser.WindowsApi.Contracts/Events/KeyModifier.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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;
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The key modifiers which can be detected by a keyboard hook.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum KeyModifier
|
||||
{
|
||||
None = 0,
|
||||
Alt = 0b1,
|
||||
Ctrl = 0b10
|
||||
}
|
||||
}
|
20
SafeExamBrowser.WindowsApi.Contracts/Events/KeyState.cs
Normal file
20
SafeExamBrowser.WindowsApi.Contracts/Events/KeyState.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The key states which can be detected by a keyboard hook.
|
||||
/// </summary>
|
||||
public enum KeyState
|
||||
{
|
||||
Unknown = 0,
|
||||
Pressed,
|
||||
Released
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The callback for a keyboard hook. Return <c>true</c> to consume (i.e. block) the user input, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
public delegate bool KeyboardHookCallback(int keyCode, KeyModifier modifier, KeyState state);
|
||||
}
|
22
SafeExamBrowser.WindowsApi.Contracts/Events/MouseButton.cs
Normal file
22
SafeExamBrowser.WindowsApi.Contracts/Events/MouseButton.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The mouse buttons which can be detected by a mouse hook.
|
||||
/// </summary>
|
||||
public enum MouseButton
|
||||
{
|
||||
Unknown = 0,
|
||||
Auxiliary,
|
||||
Left,
|
||||
Middle,
|
||||
Right
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The mouse button states which can be detected by a mouse hook.
|
||||
/// </summary>
|
||||
public enum MouseButtonState
|
||||
{
|
||||
Unknown = 0,
|
||||
Pressed,
|
||||
Released
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The callback for a mouse hook. Return <c>true</c> to consume (i.e. block) the user input, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
public delegate bool MouseHookCallback(MouseButton button, MouseButtonState state, MouseInformation info);
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The mouse information which can be detected by a mouse hook.
|
||||
/// </summary>
|
||||
public class MouseInformation
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether the mouse event originates from a touch input by the user.
|
||||
/// </summary>
|
||||
public bool IsTouch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The X coordinate of the current mouse position.
|
||||
/// </summary>
|
||||
public int X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Y coordinate of the current mouse position.
|
||||
/// </summary>
|
||||
public int Y { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that a process has terminated with the specified exit code.
|
||||
/// </summary>
|
||||
public delegate void ProcessTerminatedEventHandler(int exitCode);
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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;
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the callback for system event hooks.
|
||||
/// </summary>
|
||||
public delegate void SystemEventCallback(IntPtr window);
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Event handler fired by the <see cref="ITerminationActivator"/> when the user would like to terminate the application.
|
||||
/// </summary>
|
||||
public delegate void TerminationActivatorEventHandler();
|
||||
}
|
21
SafeExamBrowser.WindowsApi.Contracts/IBounds.cs
Normal file
21
SafeExamBrowser.WindowsApi.Contracts/IBounds.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines rectangular bounds, e.g. used for display-related operations.
|
||||
/// </summary>
|
||||
public interface IBounds
|
||||
{
|
||||
int Left { get; }
|
||||
int Top { get; }
|
||||
int Right { get; }
|
||||
int Bottom { get; }
|
||||
}
|
||||
}
|
40
SafeExamBrowser.WindowsApi.Contracts/IDesktop.cs
Normal file
40
SafeExamBrowser.WindowsApi.Contracts/IDesktop.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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;
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a desktop and defines its functionality.
|
||||
/// </summary>
|
||||
public interface IDesktop
|
||||
{
|
||||
/// <summary>
|
||||
/// The handle identifying the desktop.
|
||||
/// </summary>
|
||||
IntPtr Handle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the desktop.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Activates the desktop.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">If the desktop could not be activated.</exception>
|
||||
void Activate();
|
||||
|
||||
/// <summary>
|
||||
/// Closes the desktop.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">If the desktop could not be closed.</exception>
|
||||
void Close();
|
||||
}
|
||||
}
|
34
SafeExamBrowser.WindowsApi.Contracts/IDesktopFactory.cs
Normal file
34
SafeExamBrowser.WindowsApi.Contracts/IDesktopFactory.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// The factory for desktops of the operating system.
|
||||
/// </summary>
|
||||
public interface IDesktopFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new desktop with the given name.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">If the desktop could not be created.</exception>
|
||||
IDesktop CreateNew(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new desktop with a random name.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">If the desktop could not be created.</exception>
|
||||
IDesktop CreateRandom();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the currently active desktop.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">If the current desktop could not be retrieved.</exception>
|
||||
IDesktop GetCurrent();
|
||||
}
|
||||
}
|
26
SafeExamBrowser.WindowsApi.Contracts/IDesktopMonitor.cs
Normal file
26
SafeExamBrowser.WindowsApi.Contracts/IDesktopMonitor.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides funcionality to monitor a desktop, i.e. ensure a given desktop remains active even when a desktop switch is performed.
|
||||
/// </summary>
|
||||
public interface IDesktopMonitor
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts to monitor the given desktop.
|
||||
/// </summary>
|
||||
void Start(IDesktop desktop);
|
||||
|
||||
/// <summary>
|
||||
/// Stops the monitoring.
|
||||
/// </summary>
|
||||
void Stop();
|
||||
}
|
||||
}
|
36
SafeExamBrowser.WindowsApi.Contracts/IExplorerShell.cs
Normal file
36
SafeExamBrowser.WindowsApi.Contracts/IExplorerShell.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines an abstraction of the Windows explorer shell (i.e. the process controlling the GUI of the operating system).
|
||||
/// </summary>
|
||||
public interface IExplorerShell
|
||||
{
|
||||
/// <summary>
|
||||
/// Hides all currently opened windows. The explorer shell needs to be running in order to execute this operation!
|
||||
/// </summary>
|
||||
void HideAllWindows();
|
||||
|
||||
/// <summary>
|
||||
/// Restores all previously hidden windows. The explorer shell needs to be running in order to execute this operation!
|
||||
/// </summary>
|
||||
void RestoreAllWindows();
|
||||
|
||||
/// <summary>
|
||||
/// Starts the Windows explorer shell, if it isn't already running.
|
||||
/// </summary>
|
||||
void Start();
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully terminates the Windows explorer shell, if it is running.
|
||||
/// </summary>
|
||||
void Terminate();
|
||||
}
|
||||
}
|
228
SafeExamBrowser.WindowsApi.Contracts/INativeMethods.cs
Normal file
228
SafeExamBrowser.WindowsApi.Contracts/INativeMethods.cs
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.Generic;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines and wraps the functionality available via the native Windows API.
|
||||
/// </summary>
|
||||
public interface INativeMethods
|
||||
{
|
||||
/// <summary>
|
||||
/// Brings the window with the given handle to the foreground and activates it.
|
||||
/// </summary>
|
||||
void ActivateWindow(IntPtr handle);
|
||||
|
||||
/// <summary>
|
||||
/// Deregisters a previously registered keyboard hook.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the hook could not be successfully removed.
|
||||
/// </exception>
|
||||
void DeregisterKeyboardHook(Guid hookId);
|
||||
|
||||
/// <summary>
|
||||
/// Deregisters a previously registered mouse hook.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the hook could not be successfully removed.
|
||||
/// </exception>
|
||||
void DeregisterMouseHook(Guid hookId);
|
||||
|
||||
/// <summary>
|
||||
/// Deregisters a previously registered system event hook.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the event hook could not be successfully removed.
|
||||
/// </exception>
|
||||
void DeregisterSystemEventHook(Guid hookId);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to disable the sticky keys feature of the operating system. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool DisableStickyKeys();
|
||||
|
||||
/// <summary>
|
||||
/// Empties the clipboard.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the emptying of the clipboard failed.
|
||||
/// </exception>
|
||||
void EmptyClipboard();
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to enable the sticky keys feature of the operating system. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool EnableStickyKeys();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the current position of the mouse cursor.
|
||||
/// </summary>
|
||||
(int x, int y) GetCursorPosition();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a collection of handles to all currently open (i.e. visible) windows.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the open windows could not be retrieved.
|
||||
/// </exception>
|
||||
IEnumerable<IntPtr> GetOpenWindows();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the process identifier for the specified window handle.
|
||||
/// </summary>
|
||||
uint GetProcessIdFor(IntPtr window);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a window handle to the Windows taskbar. Returns <c>IntPtr.Zero</c> if the taskbar could not be found (i.e. if it isn't running).
|
||||
/// </summary>
|
||||
IntPtr GetShellWindowHandle();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the process identifier of the main Windows explorer instance controlling desktop and taskbar or <c>0</c>, if the process isn't running.
|
||||
/// </summary>
|
||||
uint GetShellProcessId();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the path of the currently configured wallpaper image, or an empty string, if there is no wallpaper set.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the wallpaper path could not be retrieved.
|
||||
/// </exception>
|
||||
string GetWallpaperPath();
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve the icon of the given window. Returns a handle to the icon, or <see cref="IntPtr.Zero"/> if the icon could not be retrieved.
|
||||
/// </summary>
|
||||
IntPtr GetWindowIcon(IntPtr window);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the title of the window with the given handle, or an empty string if the given window does not have a title.
|
||||
/// </summary>
|
||||
string GetWindowTitle(IntPtr window);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the currently configured working area of the primary screen.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the working area could not be retrieved.
|
||||
/// </exception>
|
||||
IBounds GetWorkingArea();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this computer is connected to the internet. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool HasInternetConnection();
|
||||
|
||||
/// <summary>
|
||||
/// Hides the given window. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool HideWindow(IntPtr window);
|
||||
|
||||
/// <summary>
|
||||
/// Minimizes all open windows.
|
||||
/// </summary>
|
||||
void MinimizeAllOpenWindows();
|
||||
|
||||
/// <summary>
|
||||
/// Instructs the main Windows explorer process to shut down.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the message could not be successfully posted. Does not apply if the process isn't running!
|
||||
/// </exception>
|
||||
void PostCloseMessageToShell();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a keyboard hook for the given callback. Returns the identifier of the newly registered hook.
|
||||
/// </summary>
|
||||
Guid RegisterKeyboardHook(KeyboardHookCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a mouse hook for the given callback. Returns the identifier of the newly registered hook.
|
||||
/// </summary>
|
||||
Guid RegisterMouseHook(MouseHookCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a system event which will invoke the specified callback when a window has received mouse capture. Returns the identifier of
|
||||
/// the newly registered Windows event hook.
|
||||
/// </summary>
|
||||
Guid RegisterSystemCaptureStartEvent(SystemEventCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a system event which will invoke the specified callback when the foreground window has changed. Returns the identifier of the
|
||||
/// newly registered Windows event hook.
|
||||
/// </summary>
|
||||
Guid RegisterSystemForegroundEvent(SystemEventCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the currently configured desktop wallpaper.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the wallpaper could not be removed.
|
||||
/// </exception>
|
||||
void RemoveWallpaper();
|
||||
|
||||
/// <summary>
|
||||
/// Restores the specified window to its original size and position.
|
||||
/// </summary>
|
||||
void RestoreWindow(IntPtr window);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to resume the thread referenced by the given thread identifier. Returns <c>true</c> if the thread was successfully resumed,
|
||||
/// otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool ResumeThread(int threadId);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a close message to the given window.
|
||||
/// </summary>
|
||||
void SendCloseMessageTo(IntPtr window);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the always on state for the display and the operating system according to the given parameters, i.e. keeps all displays powered on
|
||||
/// and/or prevents Windows from entering sleep mode or standby when set to <c>true</c> respectively.
|
||||
/// </summary>
|
||||
void SetAlwaysOnState(bool display = true, bool system = true);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the wallpaper to the image located at the specified file path.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the wallpaper could not be set.
|
||||
/// </exception>
|
||||
void SetWallpaper(string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the working area of the primary screen according to the given dimensions.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">
|
||||
/// If the working area could not be set.
|
||||
/// </exception>
|
||||
void SetWorkingArea(IBounds bounds);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to suspend the thread referenced by the given thread identifier. Returns <c>true</c> if the thread was successfully suspended,
|
||||
/// otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool SuspendThread(int threadId);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve the state of the sticky keys feature of the operating system. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool TryGetStickyKeys(out IStickyKeysState state);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to set the state of the sticky keys feature of the operating system. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool TrySetStickyKeys(IStickyKeysState state);
|
||||
}
|
||||
}
|
71
SafeExamBrowser.WindowsApi.Contracts/IProcess.cs
Normal file
71
SafeExamBrowser.WindowsApi.Contracts/IProcess.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a process and defines its functionality.
|
||||
/// </summary>
|
||||
public interface IProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether the process has been terminated.
|
||||
/// </summary>
|
||||
bool HasTerminated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The process identifier.
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The file name of the process executable.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The original file name of the process executable, if available.
|
||||
/// </summary>
|
||||
string OriginalName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The full path of the process executable.
|
||||
/// </summary>
|
||||
string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The thumbprint of the certificate used to sign the process executable, or <c>default(string)</c> if the executable isn't signed.
|
||||
/// </summary>
|
||||
string Signature { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when the process has terminated.
|
||||
/// </summary>
|
||||
event ProcessTerminatedEventHandler Terminated;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string with the most important additional information about the process (not already contained in <c>ToString()</c>).
|
||||
/// </summary>
|
||||
string GetAdditionalInfo();
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to gracefully terminate the process by closing its main window. This will only work for interactive processes which have a main
|
||||
/// window. Optionally waits the specified amount of time for the process to terminate. Returns <c>true</c> if the process has terminated,
|
||||
/// otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool TryClose(int timeout_ms = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to immediately kill the process. Optionally waits the specified amount of time for the process to terminate. Returns <c>true</c>
|
||||
/// if the process has terminated, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool TryKill(int timeout_ms = 0);
|
||||
}
|
||||
}
|
40
SafeExamBrowser.WindowsApi.Contracts/IProcessFactory.cs
Normal file
40
SafeExamBrowser.WindowsApi.Contracts/IProcessFactory.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.Collections.Generic;
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// The factory for processes, to be used whenever a new process needs to be created (for internal components and external applications).
|
||||
/// </summary>
|
||||
public interface IProcessFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows to define the desktop on which new processes should be started. If no startup desktop is specified, processes will be
|
||||
/// started on the same desktop which was active when the application itself was started.
|
||||
/// </summary>
|
||||
IDesktop StartupDesktop { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all currently running processes.
|
||||
/// </summary>
|
||||
IList<IProcess> GetAllRunning();
|
||||
|
||||
/// <summary>
|
||||
/// Starts a new process with the given command-line arguments.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ComponentModel.Win32Exception">If the process could not be started.</exception>
|
||||
IProcess StartNew(string path, params string[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve a process by its identifier. Returns <c>true</c> if a process was found, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
bool TryGetById(int id, out IProcess process);
|
||||
}
|
||||
}
|
31
SafeExamBrowser.WindowsApi.Contracts/IStickyKeysState.cs
Normal file
31
SafeExamBrowser.WindowsApi.Contracts/IStickyKeysState.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.WindowsApi.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a state of the sticky keys feature of the operating system.
|
||||
/// </summary>
|
||||
public interface IStickyKeysState
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether the feature is available.
|
||||
/// </summary>
|
||||
bool IsAvailable { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the feature is enabled.
|
||||
/// </summary>
|
||||
bool IsEnabled { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the hotkey for the feature is active.
|
||||
/// </summary>
|
||||
bool IsHotkeyActive { get; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SafeExamBrowser.WindowsApi.Contracts")]
|
||||
[assembly: AssemblyDescription("Safe Exam Browser")]
|
||||
[assembly: AssemblyCompany("ETH Zürich")]
|
||||
[assembly: AssemblyProduct("SafeExamBrowser.WindowsApi.Contracts")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024 ETH Zürich, IT Services")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("7016f080-9aa5-41b2-a225-385ad877c171")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7016F080-9AA5-41B2-A225-385AD877C171}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SafeExamBrowser.WindowsApi.Contracts</RootNamespace>
|
||||
<AssemblyName>SafeExamBrowser.WindowsApi.Contracts</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Events\KeyboardHookCallback.cs" />
|
||||
<Compile Include="Events\KeyModifier.cs" />
|
||||
<Compile Include="Events\KeyState.cs" />
|
||||
<Compile Include="Events\MouseButton.cs" />
|
||||
<Compile Include="Events\MouseButtonState.cs" />
|
||||
<Compile Include="Events\MouseHookCallback.cs" />
|
||||
<Compile Include="Events\MouseInformation.cs" />
|
||||
<Compile Include="Events\ProcessTerminatedEventHandler.cs" />
|
||||
<Compile Include="Events\SystemEventCallback.cs" />
|
||||
<Compile Include="Events\TerminationActivatorEventHandler.cs" />
|
||||
<Compile Include="IBounds.cs" />
|
||||
<Compile Include="IDesktop.cs" />
|
||||
<Compile Include="IDesktopFactory.cs" />
|
||||
<Compile Include="IDesktopMonitor.cs" />
|
||||
<Compile Include="IExplorerShell.cs" />
|
||||
<Compile Include="INativeMethods.cs" />
|
||||
<Compile Include="IProcess.cs" />
|
||||
<Compile Include="IProcessFactory.cs" />
|
||||
<Compile Include="IStickyKeysState.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Reference in New Issue
Block a user