diff options
| author | Michael <[email protected]> | 2017-06-29 13:33:17 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-06-29 13:33:17 -0400 |
| commit | c6b5db16c0edc23296ad41810d4a9fff8e8664b0 (patch) | |
| tree | aa5a9f80d93e5422a57599970d98cb71215a3d6a /ShiftOS.WinForms | |
| parent | 07b2e388817ae50731808c1870bf74ccbda855ba (diff) | |
| download | shiftos_thereturn-c6b5db16c0edc23296ad41810d4a9fff8e8664b0.tar.gz shiftos_thereturn-c6b5db16c0edc23296ad41810d4a9fff8e8664b0.tar.bz2 shiftos_thereturn-c6b5db16c0edc23296ad41810d4a9fff8e8664b0.zip | |
console garbler virus
Diffstat (limited to 'ShiftOS.WinForms')
| -rw-r--r-- | ShiftOS.WinForms/ShiftOS.WinForms.csproj | 1 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Viruses/ConsoleGarble.cs | 50 |
2 files changed, 51 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 432a417..65c658f 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -476,6 +476,7 @@ </Compile> <Compile Include="VirtualEnvironments.cs" /> <Compile Include="Viruses\BeeperVirus.cs" /> + <Compile Include="Viruses\ConsoleGarble.cs" /> <Compile Include="Viruses\CPLeach.cs" /> <Compile Include="Viruses\WindowsEverywhere.cs" /> <Compile Include="VirusTestCommands.cs" /> diff --git a/ShiftOS.WinForms/Viruses/ConsoleGarble.cs b/ShiftOS.WinForms/Viruses/ConsoleGarble.cs new file mode 100644 index 0000000..2b83846 --- /dev/null +++ b/ShiftOS.WinForms/Viruses/ConsoleGarble.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; +using System.Windows.Forms; + +namespace ShiftOS.WinForms.Viruses +{ + [Virus("console_garble", "Console Garbler", "Sends random characters to stdout which can muck up your Terminal. The threatlevel determines the rate at which characters are sent.")] + public class ConsoleGarble : IVirus + { + Timer timer = null; + Random rnd = null; + + public void Disinfect() + { + timer.Stop(); + timer = null; + rnd = null; + } + + public void Infect(int threatlevel) + { + rnd = new Random(); + timer = new Timer(); + timer.Interval = 6000 / threatlevel; + timer.Tick += (o, a) => + { + var oldFG = ConsoleEx.ForegroundColor; + var oldBG = ConsoleEx.BackgroundColor; + var character = (char)rnd.Next(255); + while (!char.IsLetterOrDigit(character)) + character = (char)rnd.Next(255); + var ccolormax = Enum.GetValues(typeof(ConsoleColor)).Cast<int>().Max(); + + ConsoleEx.BackgroundColor = (ConsoleColor)rnd.Next(ccolormax); + ConsoleEx.ForegroundColor = (ConsoleColor)rnd.Next(ccolormax); + + Console.Write(character); + ConsoleEx.OnFlush?.Invoke(); + + ConsoleEx.BackgroundColor = oldBG; + ConsoleEx.ForegroundColor = oldFG; + }; + timer.Start(); + } + } +} |
