From d816f18c4b0b34099963330dd57295a5821d4067 Mon Sep 17 00:00:00 2001 From: Yousha Aleayoub Date: Sat, 16 Jan 2021 22:20:25 +0330 Subject: [PATCH 1/4] Remove unused ref. Update version info. Add CLSCompliant attribute. --- FirewallCleanup/Properties/AssemblyInfo.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/FirewallCleanup/Properties/AssemblyInfo.cs b/FirewallCleanup/Properties/AssemblyInfo.cs index 056d128..f421897 100644 --- a/FirewallCleanup/Properties/AssemblyInfo.cs +++ b/FirewallCleanup/Properties/AssemblyInfo.cs @@ -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("")] @@ -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)] From 03f95c58795d517e2bf241d6c7475f38ad4fda13 Mon Sep 17 00:00:00 2001 From: Yousha Aleayoub Date: Sat, 16 Jan 2021 22:21:08 +0330 Subject: [PATCH 2/4] Remove unused ref. Cleanup code. --- FirewallCleanup/Program.cs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/FirewallCleanup/Program.cs b/FirewallCleanup/Program.cs index c340b74..039d77c 100644 --- a/FirewallCleanup/Program.cs +++ b/FirewallCleanup/Program.cs @@ -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(); + } + } } From a4477256273f9db4480a96a2b571d361f61940cf Mon Sep 17 00:00:00 2001 From: Yousha Aleayoub Date: Sat, 16 Jan 2021 22:21:34 +0330 Subject: [PATCH 3/4] Minor improvements. --- FirewallCleanup/FWIfz.cs | 78 +++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/FirewallCleanup/FWIfz.cs b/FirewallCleanup/FWIfz.cs index 2c2305a..6d7a501 100644 --- a/FirewallCleanup/FWIfz.cs +++ b/FirewallCleanup/FWIfz.cs @@ -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; + } + } } From 914628e79e30484504e2f5ea5a5f913e08a4c29f Mon Sep 17 00:00:00 2001 From: Yousha Aleayoub Date: Sat, 16 Jan 2021 22:22:04 +0330 Subject: [PATCH 4/4] Remove unused ref. Update project attributes. Signed-off-by: Yousha Aleayoub --- FirewallCleanup/FirewallCleanup.csproj | 35 ++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/FirewallCleanup/FirewallCleanup.csproj b/FirewallCleanup/FirewallCleanup.csproj index 81c9803..dfe11a3 100644 --- a/FirewallCleanup/FirewallCleanup.csproj +++ b/FirewallCleanup/FirewallCleanup.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 1 + 1.0.2.1 + false + false + true AnyCPU @@ -35,15 +50,13 @@ app.manifest + + FirewallCleanup.Program + - - - - - @@ -65,5 +78,17 @@ True + + + False + Microsoft .NET Framework 4.6.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file