Skip to content

Commit

Permalink
Merge pull request #1 from Yousha/master
Browse files Browse the repository at this point in the history
Minor improvements.
  • Loading branch information
PoKeRGT authored Aug 23, 2021
2 parents 414daaf + 914628e commit dfd98e9
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 58 deletions.
78 changes: 45 additions & 33 deletions FirewallCleanup/FWIfz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,52 @@

namespace FirewallCleanup
{
class FWIfz
{
String pattern = @"\b[c-zC-Z]:\\";
internal class FWIfz
{
private readonly string pattern = @"\b[c-zC-Z]:\\";

public FWIfz()
{
int counter = 0;
Type tNetFwPolicy2 = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
INetFwPolicy2 fwPolicy2 = (INetFwPolicy2)Activator.CreateInstance(tNetFwPolicy2);
INetFwRules Rules = fwPolicy2.Rules;
IEnumerator rulesEnumerator = Rules.GetEnumerator();
foreach(INetFwRule rule in Rules)
internal FWIfz()
{
uint counter = 0;
Type tNetFwPolicy2 = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
INetFwPolicy2 fwPolicy2 = (INetFwPolicy2)Activator.CreateInstance(tNetFwPolicy2);
INetFwRules Rules = fwPolicy2.Rules;
IEnumerator rulesEnumerator = Rules.GetEnumerator();

foreach (INetFwRule rule in Rules)
{
string exePath = rule.ApplicationName;
if (!string.IsNullOrEmpty(exePath))
{
String exePath = rule.ApplicationName as string;
if (exePath != null && exePath.Length > 0)
{
if (rule.Action == 0)
{
if (!File.Exists(exePath))
{
if (Regex.IsMatch(exePath, pattern))
{
counter += 1;
Console.WriteLine(exePath);
fwPolicy2.Rules.Remove(rule.Name);
}
}
}
}
if (rule.Action == 0)
{
if (!File.Exists(exePath))
{
if (Regex.IsMatch(exePath, pattern))
{
counter++;
Console.WriteLine(exePath);
fwPolicy2.Rules.Remove(rule.Name);
}
}
}
}
Console.WriteLine("-");
Console.WriteLine(counter + " rules deleted.");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}

Console.WriteLine("-");

if (counter > 0)
{
Console.WriteLine(counter + " rule(s) deleted.");
}
else
{
Console.WriteLine("Nothing found.");
}

Console.WriteLine("Press any key to exit...");
Console.ReadKey();
Environment.ExitCode = 0;
}
}
}
35 changes: 30 additions & 5 deletions FirewallCleanup/FirewallCleanup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</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.2.1</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -35,15 +50,13 @@
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<StartupObject>FirewallCleanup.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FWIfz.cs" />
Expand All @@ -65,5 +78,17 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %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" />
</Project>
22 changes: 8 additions & 14 deletions FirewallCleanup/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirewallCleanup
namespace FirewallCleanup
{
class Program
{
static void Main(string[] args)
{
FWIfz fwi = new FWIfz();
}
}
internal static class Program
{
private static void Main(string[] args)
{
new FWIfz();
}
}
}
15 changes: 9 additions & 6 deletions FirewallCleanup/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Resources;
using System.Reflection;
using System.Runtime.InteropServices;
using System;

// La información general de un ensamblado se controla mediante el siguiente
// conjunto de atributos. Cambie estos valores de atributo para modificar la información
// asociada con un ensamblado.
[assembly: AssemblyTitle("FirewallCleanup")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Command line utility to remove invalid firewall rules.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FirewallCleanup")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +33,7 @@
// Puede especificar todos los valores o utilizar los números de compilación y de revisión predeterminados
// mediante el carácter '*', como se muestra a continuación:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.2.1")]
[assembly: AssemblyFileVersion("1.0.2.1")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: CLSCompliant(true)]

0 comments on commit dfd98e9

Please sign in to comment.