Skip to content

Commit

Permalink
Removed temp rule functionality (didn't work), and moved all resource…
Browse files Browse the repository at this point in the history
…s to a single common resource file.
  • Loading branch information
AtlasHackert committed May 30, 2017
1 parent c5af11d commit 15f1da7
Show file tree
Hide file tree
Showing 16 changed files with 745 additions and 1,183 deletions.
19 changes: 9 additions & 10 deletions Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@
<Compile Include="Helpers\UACHelper.cs" />
<Compile Include="Helpers\WindowHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\Resources.Designer.cs">
<Compile Include="Properties\Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="Settings.Designer.cs">
Expand All @@ -141,14 +141,6 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<CustomToolNamespace>Wokhan.WindowsFirewallNotifier.Common</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Settings.settings">
Expand All @@ -159,6 +151,13 @@
<ItemGroup>
<Resource Include="Resources\Shield.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>del WFN.config
Expand Down
2 changes: 1 addition & 1 deletion Common/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static void initDriveMapping()
{
throw new Win32Exception(Marshal.GetLastWin32Error(), "Call to QueryDosDevice failed!");
}
deviceNameMap.Add(sb.ToString().ToLower() + "\\", trimmedDrive);
deviceNameMap.Add(sb.ToString().ToLower() + "\\", trimmedDrive); //FIXME: Switch to ToUpper?
}
}
catch (Exception e)
Expand Down
45 changes: 11 additions & 34 deletions Common/Helpers/FirewallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.IO;
using System.Windows.Media;
using Wokhan.WindowsFirewallNotifier.Common.Properties;

namespace Wokhan.WindowsFirewallNotifier.Common.Helpers
{
Expand Down Expand Up @@ -549,7 +550,7 @@ public static bool RemoveRule(string ruleName)
/// <param name="targetPort"></param>
/// <param name="localport"></param>
/// <returns></returns>
public static bool AddBlockRuleIndirect(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string[] services, int protocol, string target, string targetPort, string localport, bool useCurrentProfile)
public static bool AddBlockRuleIndirect(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string[] services, int protocol, string target, string targetPort, string localport, bool useCurrentProfile = true)
{
string param = Convert.ToBase64String(Encoding.Unicode.GetBytes(String.Format(indParamFormat, ruleName, currentPath, currentAppPkgId, localUserOwner, services != null ? String.Join(",", services) : null, protocol, target, targetPort, localport, useCurrentProfile, "B")));
return ProcessHelper.getProcessFeedback(WFNRuleManagerEXE, param, true, false);
Expand All @@ -567,9 +568,9 @@ public static bool AddBlockRuleIndirect(string ruleName, string currentPath, str
/// <param name="targetPort"></param>
/// <param name="localport"></param>
/// <returns></returns>
public static bool AddBlockRule(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string service, int protocol, string target, string targetPort, string localport, bool useCurrentProfile)
public static bool AddBlockRule(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string service, int protocol, string target, string targetPort, string localport, bool useCurrentProfile = true)
{
return AddRule(ruleName, currentPath, currentAppPkgId, localUserOwner, service, protocol, target, targetPort, localport, NET_FW_ACTION_.NET_FW_ACTION_BLOCK, false, useCurrentProfile);
return AddRule(ruleName, currentPath, currentAppPkgId, localUserOwner, service, protocol, target, targetPort, localport, NET_FW_ACTION_.NET_FW_ACTION_BLOCK, useCurrentProfile);
}

/// <summary>
Expand All @@ -584,7 +585,7 @@ public static bool AddBlockRule(string ruleName, string currentPath, string curr
/// <param name="targetPort"></param>
/// <param name="localport"></param>
/// <returns></returns>
public static bool AddAllowRuleIndirect(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string[] services, int protocol, string target, string targetPort, string localport, bool useCurrentProfile)
public static bool AddAllowRuleIndirect(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string[] services, int protocol, string target, string targetPort, string localport, bool useCurrentProfile = true)
{
string param = Convert.ToBase64String(Encoding.Unicode.GetBytes(String.Format(indParamFormat, ruleName, currentPath, currentAppPkgId, localUserOwner, services != null ? String.Join(",", services) : null, protocol, target, targetPort, localport, useCurrentProfile, "A")));
return ProcessHelper.getProcessFeedback(WFNRuleManagerEXE, param, true, false);
Expand All @@ -602,23 +603,11 @@ public static bool AddAllowRuleIndirect(string ruleName, string currentPath, str
/// <param name="targetPort"></param>
/// <param name="localport"></param>
/// <returns></returns>
public static bool AddAllowRule(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string service, int protocol, string target, string targetPort, string localport, bool useCurrentProfile)
public static bool AddAllowRule(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string service, int protocol, string target, string targetPort, string localport, bool useCurrentProfile = true)
{
return AddRule(ruleName, currentPath, currentAppPkgId, localUserOwner, service, protocol, target, targetPort, localport, NET_FW_ACTION_.NET_FW_ACTION_ALLOW, false, useCurrentProfile);
return AddRule(ruleName, currentPath, currentAppPkgId, localUserOwner, service, protocol, target, targetPort, localport, NET_FW_ACTION_.NET_FW_ACTION_ALLOW, useCurrentProfile);
}

public static bool AddTempRuleIndirect(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string[] services, int protocol, string target, string targetPort, string localport, bool useCurrentProfile)
{
string param = Convert.ToBase64String(Encoding.Unicode.GetBytes(String.Format(indParamFormat, ruleName, currentPath, currentAppPkgId, localUserOwner, services != null ? String.Join(",", services) : null, protocol, target, targetPort, localport, useCurrentProfile, "T")));
return ProcessHelper.getProcessFeedback(WFNRuleManagerEXE, param, true, true);
}

public static bool AddTempRule(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string service, int protocol, string target, string targetPort, string localport, bool useCurrentProfile)
{
return AddRule(ruleName, currentPath, currentAppPkgId, localUserOwner, service, protocol, target, targetPort, localport, NET_FW_ACTION_.NET_FW_ACTION_ALLOW, true, useCurrentProfile);
}


/// <summary>
///
/// </summary>
Expand All @@ -632,7 +621,7 @@ public static bool AddTempRule(string ruleName, string currentPath, string curre
/// <param name="localport"></param>
/// <param name="action"></param>
/// <returns></returns>
public static bool AddRule(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string service, int protocol, string target, string targetPort, string localport, NET_FW_ACTION_ action, bool isTemp, bool currentProfile = true)
public static bool AddRule(string ruleName, string currentPath, string currentAppPkgId, string localUserOwner, string service, int protocol, string target, string targetPort, string localport, NET_FW_ACTION_ action, bool currentProfile)
{
try
{
Expand Down Expand Up @@ -676,31 +665,19 @@ public static bool AddRule(string ruleName, string currentPath, string currentAp
if (!String.IsNullOrEmpty(localport))
{
firewallRule.LocalPorts = localport;

if (!isTemp)
{
firewallRule.Name += " [L:" + localport + "]";
}
firewallRule.Name += " [L:" + localport + "]";
}

if (!String.IsNullOrEmpty(target))
{
firewallRule.RemoteAddresses = target;

if (!isTemp)
{
firewallRule.Name += " [T:" + target + "]";
}
firewallRule.Name += " [T:" + target + "]";
}

if (!String.IsNullOrEmpty(targetPort))
{
firewallRule.RemotePorts = targetPort;

if (!isTemp)
{
firewallRule.Name += " [R:" + targetPort + "]";
}
firewallRule.Name += " [R:" + targetPort + "]";
}

firewallPolicy.Rules.Add(firewallRule);
Expand Down
7 changes: 4 additions & 3 deletions Common/Helpers/LogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#if DEBUG
using System.Runtime.CompilerServices;
#endif
using Wokhan.WindowsFirewallNotifier.Common.Properties;

namespace Wokhan.WindowsFirewallNotifier.Common.Helpers
{
Expand Down Expand Up @@ -97,7 +98,7 @@ static LogHelper()
{
if (!WindowsIdentity.GetCurrent().IsSystem) //Don't try to display a messagebox when we're SYSTEM, as this is not allowed.
{
MessageBox.Show(Common.Resources.MSG_LOG_FAILED, Common.Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Resources.MSG_LOG_FAILED, Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

Expand Down Expand Up @@ -276,9 +277,9 @@ private static void writeLog(string type, string msg)
{
if (!WindowsIdentity.GetCurrent().IsSystem) //Don't try to display a messagebox when we're SYSTEM, as this is not allowed.
{
MessageBox.Show(Common.Resources.MSG_LOG_FAILED, Common.Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Resources.MSG_LOG_FAILED, Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
#if DEBUG
MessageBox.Show(msg, Common.Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(msg, Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
#endif
}
}
Expand Down
Loading

0 comments on commit 15f1da7

Please sign in to comment.