diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs
index dfb935e..ea6445c 100644
--- a/ShiftOS.WinForms/Program.cs
+++ b/ShiftOS.WinForms/Program.cs
@@ -188,17 +188,6 @@ namespace ShiftOS.WinForms
case FileType.Executable:
//NYI
throw new Exception();
- case FileType.Python:
- var p = new Engine.Scripting.PythonInterpreter();
- try
- {
- p.ExecuteFile(path);
- }
- catch (Exception ex)
- {
- Infobox.Show("{PY_EXCEPTION}", ex.Message);
- }
- break;
case FileType.Lua:
try
{
diff --git a/ShiftOS_TheReturn/AltTabWindow.Designer.cs b/ShiftOS_TheReturn/AltTabWindow.Designer.cs
deleted file mode 100644
index 74511bf..0000000
--- a/ShiftOS_TheReturn/AltTabWindow.Designer.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-namespace ShiftOS.Engine {
- partial class AltTabWindow {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing) {
- if (disposing && (components != null)) {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent() {
- this.SuspendLayout();
- //
- // AltTabWindow
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(284, 261);
- this.Name = "AltTabWindow";
- this.Text = "AltTabWindow";
- this.Load += new System.EventHandler(this.AltTabWindow_Load);
- this.ResumeLayout(false);
-
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/ShiftOS_TheReturn/AltTabWindow.cs b/ShiftOS_TheReturn/AltTabWindow.cs
deleted file mode 100644
index 26e7cce..0000000
--- a/ShiftOS_TheReturn/AltTabWindow.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace ShiftOS.Engine {
- public partial class AltTabWindow : Form {
- public AltTabWindow() {
- InitializeComponent();
- }
-
- internal void CycleBack() {
- Console.WriteLine("Cycle Backwards");
- }
-
- internal void CycleForwards() {
- Console.WriteLine("Cycle Forwards");
- }
-
- private void AltTabWindow_Load(object sender, EventArgs e) {
-
- }
- }
-}
diff --git a/ShiftOS_TheReturn/AltTabWindow.resx b/ShiftOS_TheReturn/AltTabWindow.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/ShiftOS_TheReturn/AltTabWindow.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs
index ed4d0e4..64cb72a 100644
--- a/ShiftOS_TheReturn/Commands.cs
+++ b/ShiftOS_TheReturn/Commands.cs
@@ -44,69 +44,10 @@ using ShiftOS.Objects.ShiftFS;
namespace ShiftOS.Engine
{
- [Namespace("virus")]
- public class VirusTestCommands
- {
- [Command("infect")]
- public static void InfectFileWithMUDVirus(Dictionary args)
- {
- string signature = "";
-
- if (args.ContainsKey("signature"))
- signature = args["signature"] as string;
- else
- throw new Exception("Virus signature not provided.");
-
- string script = "";
-
- Action scriptFound = new Action((s) =>
- {
- script = s;
- Virus v = new LuaVirus(s, 1);
- VirusEngine.Add(v);
- VirusEngine.Infect($"lua.{v.Signature}.1");
- });
-
- ServerManager.MessageReceived += (srv) =>
- {
- if (srv.Name == "mud_virus")
- {
- scriptFound?.Invoke(srv.Contents);
- scriptFound = null;
- }
- };
-
- ServerManager.SendMessage("getvirus", signature);
- }
- }
-
-
[RequiresUpgrade("mud_fundamentals")]
[Namespace("mud")]
public static class MUDCommands
{
- [Command("addvirus")]
- public static void Virus_AddToDatabase(Dictionary args)
- {
- string file = "";
- int threatLevel = 0;
-
-
- if (args.ContainsKey("file"))
- file = args["file"] as string;
- else
- throw new Exception("No 'file' argument provided.");
-
- if (args.ContainsKey("threatlevel"))
- threatLevel = Convert.ToInt32(args["threatlevel"].ToString());
-
- Virus lua = new LuaVirus(Utils.ReadAllText(file), threatLevel);
-
- Console.WriteLine("Virus uploaded to current multi-user domain successfully.");
-
- }
-
-
[Command("status")]
public static bool Status()
{
diff --git a/ShiftOS_TheReturn/CtrlTabMenu.cs b/ShiftOS_TheReturn/CtrlTabMenu.cs
deleted file mode 100644
index b29685b..0000000
--- a/ShiftOS_TheReturn/CtrlTabMenu.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ShiftOS.Engine {
- static class CtrlTabMenu {
- public static AltTabWindow altTabWindow;
-
- internal static void Show() {
- if(altTabWindow != null) {
- altTabWindow = new AltTabWindow();
- altTabWindow.Show();
- }
- }
-
- internal static void CycleBack() {
- altTabWindow.CycleBack();
- }
-
- internal static void CycleForwards() {
- altTabWindow.CycleForwards();
- }
- }
-}
diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs
index 72ab5ec..bea2568 100644
--- a/ShiftOS_TheReturn/Scripting.cs
+++ b/ShiftOS_TheReturn/Scripting.cs
@@ -27,9 +27,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using IronPython;
-using IronPython.Hosting;
-using Microsoft.Scripting.Hosting;
using System.Reflection;
using ShiftOS.Objects.ShiftFS;
using DynamicLua;
@@ -60,28 +57,52 @@ namespace ShiftOS.Engine.Scripting
//This temporary proxy() method will be used by the API prober.
Lua.proxy = new Func((objName) =>
{
- var asm = Assembly.GetExecutingAssembly();
- foreach (var type in asm.GetTypes())
+ foreach (var f in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
{
- if (type.Name == objName)
+ if (f.EndsWith(".exe") || f.EndsWith(".dll"))
{
- dynamic dynObj = Activator.CreateInstance(type);
- return dynObj;
- }
+ try
+ {
+ var asm = Assembly.LoadFile(f);
+ foreach (var type in asm.GetTypes())
+ {
+ if (type.Name == objName)
+ {
+ dynamic dynObj = Activator.CreateInstance(type);
+ return dynObj;
+ }
+
+ }
+ }
+ catch { }
+ }
}
throw new Exception("{CLASS_NOT_FOUND}");
});
- var thisasm = Assembly.GetExecutingAssembly();
- foreach (var type in thisasm.GetTypes())
+ foreach (var f in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
{
- foreach (var attr in type.GetCustomAttributes(false))
+ if (f.EndsWith(".exe") || f.EndsWith(".dll"))
{
- if (attr is ExposedAttribute)
+ try
{
- var eattr = attr as ExposedAttribute;
- Lua($"{eattr.Name} = proxy(\"{type.Name}\")");
+ var thisasm = Assembly.LoadFile(f);
+ foreach (var type in thisasm.GetTypes())
+ {
+ foreach (var attr in type.GetCustomAttributes(false))
+ {
+ if (attr is ExposedAttribute)
+ {
+ var eattr = attr as ExposedAttribute;
+ Lua($"{eattr.Name} = proxy(\"{type.Name}\")");
+ }
+ }
+ }
+ }
+ catch
+ {
+
}
}
}
@@ -127,382 +148,17 @@ namespace ShiftOS.Engine.Scripting
}
}
- public class LuaVirus : Virus
- {
- public override string Signature
- {
- get
- {
- return signature;
- }
- }
-
- public override int ThreatLevel
- {
- get
- {
- return _threatlevel;
- }
- }
-
- public override string Type
- {
- get
- {
- return "lua";
- }
- }
-
- private LuaInterpreter interpreter = null;
- private string signature = "unknown";
-
- private int _threatlevel = 0;
-
- public LuaVirus(string script, int threatLevel) : base()
- {
- _threatlevel = threatLevel;
-
- interpreter = new LuaInterpreter();
-
- Action mud_message = new Action((sig) =>
- {
- signature = sig;
- });
-
- ServerManager.MessageReceived += (msg) =>
- {
- if(msg.Name == "mud_virus_signature")
- {
- mud_message?.Invoke(msg.Contents);
- mud_message = null;
- }
- };
-
- ServerManager.SendMessage("mud_scanvirus", script);
-
- _script = script;
- }
-
-
- private string _script = "";
-
- public override void Activate()
- {
- interpreter.Execute(_script);
- }
-
- public override void Deactivate()
- {
- interpreter.Running = false;
- interpreter = null;
- }
- }
-
- [Exposed("consts")]
- public class Constants
- {
- public readonly DockStyle dock_none = DockStyle.None;
- public readonly DockStyle dock_top = DockStyle.Top;
- public readonly DockStyle dock_bottom = DockStyle.Bottom;
- public readonly DockStyle dock_left = DockStyle.Left;
- public readonly DockStyle dock_right = DockStyle.Right;
- public readonly DockStyle dock_fill = DockStyle.Fill;
-
- public readonly AnchorStyles anchor_none = 0x00;
- public readonly AnchorStyles anchor_top = AnchorStyles.Top;
- public readonly AnchorStyles anchor_bottom = AnchorStyles.Bottom;
- public readonly AnchorStyles anchor_left = AnchorStyles.Left;
- public readonly AnchorStyles anchor_right = AnchorStyles.Right;
-
- }
-
- [Exposed("shiftos")]
- public class CoreAPI
- {
- public void sleep(int ms) { Thread.Sleep(ms); }
-
- public bool isRunning() { return !SaveSystem.ShuttingDown; }
-
- public int random(int min, int max)
- {
- return new Random().Next(min, max);
- }
-
- public void info(string title, string message)
- {
- Infobox.Show(title, message);
- }
-
- public void executeCommand(string cmd)
- {
- TerminalBackend.InvokeCommand(cmd);
- }
-
- public void shutdown()
- {
- TerminalBackend.InvokeCommand("sys.shutdown");
- }
- }
- [Exposed("shiftorium")]
- public class ShiftoriumAPI
- {
- public dynamic[] getAvailable()
- {
- return Shiftorium.GetAvailable();
- }
-
- public dynamic[] getAll()
- {
- return Shiftorium.GetDefaults().ToArray();
- }
-
- public bool upgradeInstalled(string id)
- {
- return Shiftorium.UpgradeInstalled(id);
- }
-
- public bool buy(ShiftoriumUpgrade upgrade)
- {
- foreach (var upg in getAvailable())
- {
- if (upg.ID == upgrade && SaveSystem.CurrentSave.Codepoints >= upg.Cost)
- {
- return true;
- }
- }
- return false;
- }
- }
-
- [Exposed("gui")]
- public class GuiAPI
- {
- public void addControl(dynamic parent, dynamic child)
- {
- parent.Controls.Add(child);
- }
-
- public dynamic size(int width, int height)
- {
- return new System.Drawing.Size(width, height);
- }
-
- public dynamic point(int x, int y)
- {
- return new System.Drawing.Point(x, y);
- }
-
- public dynamic rect(dynamic p, dynamic s)
- {
- return new System.Drawing.Rectangle(p, s);
- }
-
- public dynamic rect(int x, int y, int w, int h)
- {
- return new System.Drawing.Rectangle(x, y, w, h);
- }
-
- public dynamic panel()
- {
- return new Panel();
- }
-
- public dynamic label()
- {
- return new Label();
- }
-
- public dynamic button()
- {
- return new Button();
- }
-
- public dynamic listbox()
- {
- return new ListBox();
- }
-
- public dynamic combobox()
- {
- return new ComboBox();
- }
-
- public dynamic textbox()
- {
- return new TextBox();
- }
-
- public dynamic window()
- {
- return new Form();
- }
-
- }
-
- [Exposed("color")]
- public class ColorAPI
- {
- public dynamic fromRgb(int r, int g, int b)
- {
- return System.Drawing.Color.FromArgb(r, g, b);
- }
-
- public dynamic fromArgb(int a, int r, int g, int b)
- {
- return System.Drawing.Color.FromArgb(a, r, g, b);
- }
-
- public dynamic fromName(string name)
- {
- return System.Drawing.Color.FromName(name);
- }
- }
-
- [Exposed("fonts")]
- public class FontsAPI
- {
- public readonly int style_regular = 0x00;
- public readonly int style_bold = 0x01;
- public readonly int style_italic = 0x02;
- public readonly int style_underline = 0x04;
- public readonly int style_strike = 0x08;
-
- public dynamic create(string name, float size, int style)
- {
- return new System.Drawing.Font(name, size, (System.Drawing.FontStyle)style);
- }
-
- }
-
- [Exposed("json")]
- public class JsonAPI
- {
- public string serialize(dynamic dynObj)
- {
- return JsonConvert.SerializeObject(dynObj);
- }
-
- public dynamic deserialize(string json)
- {
- return JsonConvert.DeserializeObject(json);
- }
- }
-
- [Exposed("fs")]
- public class FilesystemAPI
- {
- public void writeAllText(string target, string contents)
- {
- Utils.WriteAllText(target, contents);
- }
-
- public string readAllText(string file)
- {
- return Utils.ReadAllText(file);
- }
-
- public bool fileExists(string file)
- {
- return Utils.FileExists(file);
- }
-
- public bool directoryExists(string dir)
- {
- return Utils.DirectoryExists(dir);
- }
-
- public void createDirectory(string dir)
- {
- Utils.CreateDirectory(dir);
- }
-
- //experimental - no idea how arrays will be handled in Lua...
- public string[] getFiles(string dir)
- {
- return Utils.GetFiles(dir);
- }
-
- public string[] getDirectories(string dir)
- {
- return Utils.GetDirectories(dir);
- }
-
- public string mount(string mfsFile)
- {
- Utils.MountPersistent(mfsFile);
- return $"{Utils.Mounts.Count - 1}:";
- }
-
- public void unmount(int driveNum)
- {
- Utils.Mounts.RemoveAt(driveNum);
- }
-
- }
-
-
- public class PythonInterpreter
- {
- ScriptEngine python;
- ScriptScope pyScope;
- ScriptSource pySource;
-
- public PythonInterpreter()
- {
- python = Python.CreateEngine();
- pyScope = python.CreateScope();
- AddExposedObjects();
- }
-
- private void AddExposedObjects()
- {
- var asm = Assembly.GetExecutingAssembly();
- foreach(var type in asm.GetTypes())
- {
- foreach(var attr in type.GetCustomAttributes(false))
- {
- if(attr is ExposedAttribute)
- {
- var eattr = attr as ExposedAttribute;
- dynamic dynObj = Activator.CreateInstance(type);
- pyScope.SetVariable(eattr.Name, dynObj);
- }
- }
- }
- }
-
- public void ExecuteFile(string file)
- {
- if(Utils.FileExists(file))
- {
- Execute(Utils.ReadAllText(file));
- }
- else
- {
- throw new Exception("The file \"" + file + "\" was not found on the system.");
- }
- }
-
- public void Execute(string py)
- {
- Console.WriteLine("");
- pySource = python.CreateScriptSourceFromString(py, Microsoft.Scripting.SourceCodeKind.AutoDetect);
- pySource.Execute(pyScope);
- Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
- }
- }
-
public class ExposedAttribute : Attribute
{
///
- /// Marks the following class as exposed to the ShiftOS Scripting System.
+ /// If applied to a non-static class, the ShiftOS engine will see this class as a Lua object of the specified name.
///
- /// The object name that the Scripting System should use as the variable name for scripts.
- public ExposedAttribute(string objName)
+ /// The name of the Lua object
+ public ExposedAttribute(string name)
{
- Name = objName;
+ Name = name;
}
- public string Name { get; set; }
+ public string Name { get; private set; }
}
}
diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
index 18fac1d..ce22f3c 100644
--- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj
+++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
@@ -113,12 +113,6 @@
-
- Form
-
-
- AltTabWindow.cs
-
@@ -127,7 +121,6 @@
CrashHandler.cs
-
@@ -153,9 +146,6 @@
-
- AltTabWindow.cs
-
Infobox.cs
diff --git a/ShiftOS_TheReturn/VirusEngine.cs b/ShiftOS_TheReturn/VirusEngine.cs
index 21d4ab8..650db92 100644
--- a/ShiftOS_TheReturn/VirusEngine.cs
+++ b/ShiftOS_TheReturn/VirusEngine.cs
@@ -28,6 +28,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using Newtonsoft.Json;
using static ShiftOS.Objects.ShiftFS.Utils;
@@ -35,130 +36,53 @@ namespace ShiftOS.Engine
{
public static class VirusEngine
{
- private static List _infections = new List();
-
- public static void Add(Virus virus)
- {
- _infections.Add(virus);
- }
-
public static void InfectFile(string file, string virusid)
{
- string existing = "";
+ var infected = new List();
+ var hData = GetHeaderText(file);
- if(probeFile(file, out existing) == true)
+ if (hData == "")
{
- existing = existing.Replace("<>", "").Replace("<>", "");
-
- existing += ";" + virusid;
-
- existing = "<>" + existing + "<>";
-
- string c = ReadAllText(file);
-
- string temp = "";
-
- if(probeFile(file, out temp) == true)
- {
- c = c.Replace(temp, existing);
- }
- else
- {
- c = existing + c;
- }
- WriteAllText(file, c);
- return;
+ infected.Add(virusid);
}
else
{
- existing = "<>" + virusid + "<>";
- string c = ReadAllText(file);
- c = existing + c;
- WriteAllText(file, c);
- return;
+ infected = JsonConvert.DeserializeObject>(hData);
+ if (!infected.Contains(virusid))
+ infected.Add(virusid);
}
+ SetHeaderText(file, JsonConvert.SerializeObject(infected));
+ }
+ public static void DisinfectFile(string file, int threatlevel)
+ {
+ var infected = new List();
+ var hData = GetHeaderText(file);
+
+ if (hData != "")
+ {
+ infected = JsonConvert.DeserializeObject>(hData);
+ for (int i = 0; i < infected.Count; i++)
+ {
+ string[] splitID = infected[i].Split('.');
+ int th = Convert.ToInt32(splitID[splitID.Length - 1]);
+ if (th <= threatlevel)
+ {
+ infected.RemoveAt(i);
+ }
+ }
+ }
+
+ SetHeaderText(file, JsonConvert.SerializeObject(infected));
}
internal static string[] FindAllVirusesInFile(string file)
{
- string existing = "";
- if(probeFile(file, out existing) == true)
- {
- existing = existing.Replace("<>", "").Replace("<>", "");
- return existing.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); ;
- }
- else
- {
- return null;
- }
+ string hdata = GetHeaderText(file);
+ return (hdata != "") ? new string[0] : JsonConvert.DeserializeObject(hdata);
}
- private static bool probeFile(string file, out string existing)
- {
- int startIndex = 0;
- int endIndex = 0;
-
- bool found = false;
-
- string contents = ReadAllText(file);
-
- for(int i = 0; i < contents.Length; i++)
- {
- string end = "<>";
- try
- {
- if (contents.Substring(i, end.Length) == end)
- {
- endIndex = i + end.Length;
- found = true;
- break;
- }
- }
- catch { }
- }
-
- if (found == false) {
- existing = "<><>";
- }
- else
- {
- existing = contents.Substring(startIndex, endIndex);
- }
- return found;
- }
-
- public static void Infect(string virusid)
- {
- string[] id_split = virusid.Split('.');
-
- foreach(var v in _infections)
- {
- if(v.Type == id_split[0])
- {
- if(v.Signature == id_split[1])
- {
- if(v.ThreatLevel == Convert.ToInt32(id_split[2]))
- {
- var t = new Thread(new ThreadStart(() =>
- {
- v.Activate();
- }));
- t.IsBackground = true;
- t.Start();
- return;
- }
- }
- }
- }
- throw new Exception("Virus not found in the system.");
- }
-
- internal static void ProbeFileRaw(string filePath, out string existing)
- {
- probeFile(filePath, out existing);
- }
}
public abstract class Virus