aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/KernelWatchdog.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn/KernelWatchdog.cs')
-rw-r--r--ShiftOS_TheReturn/KernelWatchdog.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs
new file mode 100644
index 0000000..1b59b25
--- /dev/null
+++ b/ShiftOS_TheReturn/KernelWatchdog.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using static ShiftOS.Objects.ShiftFS.Utils;
+
+namespace ShiftOS.Engine
+{
+ public static class KernelWatchdog
+ {
+ public static void Log(string e, string desc)
+ {
+ string line = $"[{DateTime.Now}] <{e}> {desc}";
+ if (FileExists("0:/system/data/kernel.log"))
+ {
+ string contents = ReadAllText("0:/system/data/kernel.log");
+ contents += Environment.NewLine + line;
+ WriteAllText("0:/system/data/kernel.log", contents);
+ }
+ else
+ {
+ WriteAllText("0:/system/data/kernel.log", line);
+ }
+ }
+
+ public static bool InKernelMode { get; private set; }
+ public static bool MudConnected { get; set; }
+
+ public static bool IsSafe(Type type)
+ {
+ if (InKernelMode == true)
+ return true;
+
+ foreach (var attrib in type.GetCustomAttributes(false))
+ {
+ if (attrib is KernelModeAttribute)
+ return false;
+ }
+ return true;
+ }
+
+ public static bool IsSafe(MethodInfo type)
+ {
+ if (InKernelMode == true)
+ return true;
+
+ foreach (var attrib in type.GetCustomAttributes(false))
+ {
+ if (attrib is KernelModeAttribute)
+ return false;
+ }
+ return true;
+ }
+
+
+ public static void EnterKernelMode()
+ {
+ InKernelMode = true;
+ Console.WriteLine("<kernel> Watchdog deactivated, system-level access granted.");
+ }
+
+ public static void LeaveKernelMode()
+ {
+ InKernelMode = false;
+ Console.WriteLine("<kernel> Kernel mode disabled.");
+ }
+ }
+}