Skip to content

Commit

Permalink
Add block count
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidy committed Nov 18, 2016
1 parent 09ccfd7 commit f67e565
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 86 deletions.
8 changes: 4 additions & 4 deletions PoMs/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

<supportedRuntime version="v2.0.50727" sku="Client"/></startup>
</configuration>
Binary file added PoMs/Jommans-Mushroom-Search.ico
Binary file not shown.
50 changes: 30 additions & 20 deletions PoMs/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions PoMs/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public partial class MainWindow : Form
private int SLEEPTIME = 2000;
private int trashold = 5;
private List<int> suspendetPS = new List<int>(100);
private int blockcount = 0;

public MainWindow()
{
Expand Down Expand Up @@ -78,8 +79,8 @@ private void psscanner_DoWork(object sender, DoWorkEventArgs e)
}
else
{
PSEventEntry entry = monitor.getPSEvent();
if (start < start.AddDays(1))
PSEventEntry entry = monitor.checkSystem();
if (start < start.AddDays(1) && entry != null)
{
if (entry.malware)
{
Expand Down Expand Up @@ -121,6 +122,7 @@ private void porcessManager(int pid)
{
controller.SuspendProcess(pid);
suspendetPS.Add(pid);
blockcount++;
}
}
catch (ArgumentException ex)
Expand Down Expand Up @@ -149,13 +151,20 @@ private void releaseProcessButton_Click(object sender, EventArgs e)
if (!Process.GetProcessById(pid).HasExited)
{
controller.ResumeProcess(pid);
blockcount--;
}

}
catch (ArgumentException ex)
{
// do nothing - process already closed
}
}
}

private void notifyIcon_Click(object sender, EventArgs e)
{
blockcountMenu.Text = "Blocked tasks: " + blockcount;
}
}
}
12 changes: 6 additions & 6 deletions PoMs/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="notifyIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="notifyIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="contextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="contextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>130, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="notifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAkAAAAAAAEAIABhtAAAlgAAAICAAAABACAAKAgBAPe0AABgYAAAAQAgAKiUAAAfvQEASEgAAAEA
Expand Down Expand Up @@ -3596,7 +3596,7 @@
AAAAgAAAAAAAAAAAAAAAAAEAABADAAD4BwAA/g8AAP//AAA=
</value>
</data>
<metadata name="psscanner.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="psscanner.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>285, 17</value>
</metadata>
</root>
49 changes: 48 additions & 1 deletion PoMs/PoMs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PoMs</RootNamespace>
<AssemblyName>PoMs</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>C:\Users\TraubS\Desktop\PoMs\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -31,6 +48,21 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>60AFE4355BA2B462CA868C28A2C69F2B476E98B4</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>PoMs_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Jommans-Mushroom-Search.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -67,7 +99,9 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="PoMs_TemporaryKey.pfx" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -84,6 +118,19 @@
<ItemGroup>
<Content Include="img\Search-icon - Copy.png" />
<Content Include="img\Search-icon.png" />
<Content Include="Jommans-Mushroom-Search.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
70 changes: 64 additions & 6 deletions PoMs/PowerMon.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.Eventing.Reader;
using System.Security.Principal;
using System.Diagnostics;

namespace PoMs
{
Expand All @@ -11,20 +12,16 @@ class PowerMon
/// Read the value from threshold
/// </summary>
DateTime run = DateTime.Now;
PSEventEntry entry = new PSEventEntry();
int timespan = 2500;

PSEventEntry entry = new PSEventEntry();
/// <summary>
/// Pulls out the PowerShell events from the event log
/// </summary>
/// <returns>PSEventEntry object with the latest event properties</returns>
public PSEventEntry getPSEvent()
private PSEventEntry getPSEvent()
{
// event id 40962 and 4104

entry.malware = false;
entry.opencommand = false;

string logType = "Microsoft-Windows-PowerShell/Operational";
string query = $"*[System[(EventID='4104' or EventID='40962') and TimeCreated[timediff(@SystemTime) <= {timespan}]]]";

Expand Down Expand Up @@ -53,5 +50,66 @@ public PSEventEntry getPSEvent()
}
return entry;
}
private int getPSProcess()
{
// get all processes on the local machine

Process[] localPS = Process.GetProcessesByName("Windows PowerShell");

if (localPS.Length < 0)
{
for (int i=0; i<localPS.Length; i++)
{
return localPS[i].Id;
}
}
return 0;
}
private int getISEProcess()
{
Process[] localAll = Process.GetProcesses();

Process[] localISE = Process.GetProcessesByName("Windows PowerShell ISE");

if (localISE.Length < 0)
{
for (int i = 0; i < localISE.Length; i++)
{
return localISE[i].Id;
}
}
return 0;
}

public PSEventEntry checkSystem ()
{
entry.malware = false;
entry.opencommand = false;
int processID = getISEProcess();
// check if a PowerShell process ISE is running
if (getISEProcess() > 0)
{
entry.processID = processID;
entry.runcount = entry.runcount + 1;
entry.opencommand = true;
return entry;
}
// check if a PowerShell process is running
processID = getPSProcess();
if (getISEProcess() > 0)
{
entry.processID = processID;
entry.runcount = entry.runcount + 1;
entry.opencommand = true;
return entry;
}
// if no process found -- check the eventlog
PSEventEntry event_tmp = getPSEvent();
if(event_tmp.processID != 0)
{
return event_tmp;
}
return event_tmp;
}
}
}
3 changes: 0 additions & 3 deletions PoMs/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PoMs
Expand Down
Loading

0 comments on commit f67e565

Please sign in to comment.