Skip to content

Commit

Permalink
api improved
Browse files Browse the repository at this point in the history
gui improved
Nlog added
Localization added
  • Loading branch information
erdnussflips committed Dec 21, 2015
1 parent dfc655f commit 4e3cd2c
Show file tree
Hide file tree
Showing 51 changed files with 943 additions and 420 deletions.
12 changes: 0 additions & 12 deletions WindowsAdvancedFirewallApi/ApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,5 @@ internal class ApiConstants

public const string REGISTRY_KEY_EVENTLOG = @"SYSTEM\CurrentControlSet\Services\EventLog\";
public const string REGISTRY_KEY_FIREWALL_LOG = REGISTRY_KEY_EVENTLOG + FIREWALL_EVENT_PROTOCOL;

internal enum EventID
{
FIREWALL_SETTING_GENERAL = WFEvents.WFGlobalConfigurationChangedEvent,
FIREWALL_SETTING_PROFILE = WFEvents.WFProfileConfigurationChangedEvent,

FIREWALL_RULE_ADDED = WFEvents.WFRuleAddEvent,
FIREWALL_RULE_MODIFIED = WFEvents.WFRuleChangeEvent,
FIREWALL_RULE_DELETED = WFEvents.WFRuleDeleteEvent,

FIREWALL_NETWORKINTERFACE_CHANGED = WFEvents.WFInterfaceProfileChangedEvent
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsAdvancedFirewallApi.Events.Objects;

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
Expand All @@ -13,6 +14,7 @@ public abstract class FirewallBaseEventArgs : EventArgs
protected static Logger LOG = LogManager.GetCurrentClassLogger();

protected EventLogEntry FirewallLogEvent { get; set; }
public long LogId { get; protected set; }
public long EventId { get; protected set; }
public DateTime ModifyingTime { get; protected set; }

Expand All @@ -26,8 +28,20 @@ internal FirewallBaseEventArgs(EventLogEntry eventArgs)
}

FirewallLogEvent = eventArgs;
LogId = FirewallLogEvent.Index;
EventId = FirewallLogEvent.InstanceId;
ModifyingTime = FirewallLogEvent.TimeGenerated;
}
}

public abstract class FirewallBaseEventArgs<TData> : FirewallBaseEventArgs
where TData : FirewallBaseObject, new()
{
protected TData Data { get; set; }

internal FirewallBaseEventArgs(EventLogEntry @event) : base(@event)
{
Data = new TData();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public abstract class FirewallEventArgs<TData> : FirewallDataEventArgs<TData> where TData : FirewallBaseObject, new()
public abstract class FirewallEventArgs<TData> : FirewallBaseEventArgs<TData> where TData : FirewallBaseObject, new()
{
public int Origin { get; protected set; }
public string ModifyingUser { get; protected set; }
public string ModifyingApplication { get; protected set; }

internal FirewallEventArgs(EventLogEntry @event) : base(@event)
{
}

protected void SetAttributes(int iOrigin, int iModifiyingUser, int iModifyingApplication)
protected void SetAttributes(int iModifiyingUser)
{
LOG.Debug("ReplacementStrings: {0}", string.Join(",", FirewallLogEvent.ReplacementStrings));

Origin = PrimitiveUtils.ParseInteger(FirewallLogEvent.ReplacementStrings[iOrigin], 0);
ModifyingUser = FirewallLogEvent.ReplacementStrings[iModifiyingUser];
ModifyingApplication = FirewallLogEvent.ReplacementStrings[iModifyingApplication];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NLog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsAdvancedFirewallApi.Events.Objects;
using WindowsAdvancedFirewallApi.Utils;

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public abstract class FirewallExtendedApplicationEventArgs<TData> : FirewallEventArgs<TData> where TData : FirewallBaseObject, new()
{
public string ModifyingApplication { get; protected set; }

internal FirewallExtendedApplicationEventArgs(EventLogEntry @event) : base(@event)
{
}

protected void SetAttributes(int iModifiyingUser, int iModifyingApplication)
{
SetAttributes(iModifiyingUser);

ModifyingApplication = FirewallLogEvent.ReplacementStrings[iModifyingApplication];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NLog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsAdvancedFirewallApi.Events.Objects;
using WindowsAdvancedFirewallApi.Utils;

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public abstract class FirewallExtendedOriginEventArgs<TData> : FirewallExtendedApplicationEventArgs<TData> where TData : FirewallBaseObject, new()
{
public int Origin { get; protected set; }

internal FirewallExtendedOriginEventArgs(EventLogEntry @event) : base(@event)
{
}

protected void SetAttributes(int iOrigin, int iModifiyingUser, int iModifyingApplication)
{
SetAttributes(iModifiyingUser, iModifyingApplication);

Origin = PrimitiveUtils.ParseInteger(FirewallLogEvent.ReplacementStrings[iOrigin], 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public class FirewallHistoryLoadingStatusChangedEventArgs
{
public int LoadedCount { get; internal set; }
public int MaxCount { get; internal set; }
public FirewallBaseEventArgs CurrentLoadedEvent { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public class FirewallNetworkInterfaceProfileChanged : FirewallDataEventArgs<FirewallNetworkInterfaceProfile>
public class FirewallNetworkInterfaceProfileChangedEventArgs : FirewallBaseEventArgs<FirewallNetworkInterfaceProfile>
{
public FirewallNetworkInterfaceProfile NetworkInterface
{
get { return Data; }
protected set { Data = value; }
}

public FirewallNetworkInterfaceProfileChanged(EventLogEntry @event) : base(@event)
public FirewallNetworkInterfaceProfileChangedEventArgs(EventLogEntry @event) : base(@event)
{
SetAttributes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public class FirewallProfileSettingEventArgs : FirewallSettingEventArgs
public class FirewallProfileSettingEventArgs : FirewallSettingEventArgs<FirewallProfileSetting>
{
internal FirewallProfileSettingEventArgs(EventLogEntry @event) : base(@event)
{
SetAttributes();
}

protected new void SetAttributes()
protected void SetAttributes()
{
SetAttributes(5, 6, 7);
SetSettingAttributes(1, 2, 3, 4);
SetSettingAttributes(1, 3, 2, 4);

Setting.Profiles = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[0], FirewallBaseObject.Profile.Unkown);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,29 @@ public FirewallRuleAddedEventArgs(EventLogEntry @event) : base(@event)
protected void SetAttributes()
{
SetAttributes(2, 21, 22);
SetRuleAttributes(0, 1);

try
{
Rule.Id = FirewallLogEvent.ReplacementStrings[0];
Rule.Name = FirewallLogEvent.ReplacementStrings[1];
Rule.ApplicationPath = FirewallLogEvent.ReplacementStrings[3];
Rule.ServiceName = FirewallLogEvent.ReplacementStrings[4];
Rule.Direction = int.Parse(FirewallLogEvent.ReplacementStrings[5]);
Rule.Protocol = int.Parse(FirewallLogEvent.ReplacementStrings[6]);
Rule.LocalPorts = FirewallLogEvent.ReplacementStrings[7];
Rule.RemotePorts = FirewallLogEvent.ReplacementStrings[8];
Rule.Action = FirewallLogEvent.ReplacementStrings[9];
Rule.Profiles = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[10], FirewallBaseObject.Profile.Unkown);
Rule.LocalAddresses = FirewallLogEvent.ReplacementStrings[11];
Rule.RemoteAddresses = FirewallLogEvent.ReplacementStrings[12];
Rule.RemoteMachineAuthorizationList = FirewallLogEvent.ReplacementStrings[13];
Rule.RemoteUserAuthorizationList = FirewallLogEvent.ReplacementStrings[14];
Rule.EmbeddedContext = FirewallLogEvent.ReplacementStrings[15];
Rule.Flags = int.Parse(FirewallLogEvent.ReplacementStrings[16]);
Rule.Active = Convert.ToBoolean(int.Parse(FirewallLogEvent.ReplacementStrings[17]));
Rule.EdgeTraversal = int.Parse(FirewallLogEvent.ReplacementStrings[18]);
Rule.LooseSourceMapped = int.Parse(FirewallLogEvent.ReplacementStrings[19]);
Rule.SecurityOptions = int.Parse(FirewallLogEvent.ReplacementStrings[20]);
Rule.SchemaVersion = int.Parse(FirewallLogEvent.ReplacementStrings[23]);
Rule.Status = long.Parse(FirewallLogEvent.ReplacementStrings[24]);
Rule.LocalOnlyMapped = int.Parse(FirewallLogEvent.ReplacementStrings[25]);
}
catch (Exception ex) when (ex is ArgumentNullException || ex is FormatException || ex is OverflowException)
{
LOG.Info(string.Format("Primitive parse error: {0}", string.Join(",", FirewallLogEvent.ReplacementStrings)));
LOG.Debug(ex);
}
Rule.ApplicationPath = FirewallLogEvent.ReplacementStrings[3];
Rule.ServiceName = FirewallLogEvent.ReplacementStrings[4];
Rule.Direction = FirewallLogEvent.ReplacementStrings[5].ParseInteger(0);
Rule.Protocol = FirewallLogEvent.ReplacementStrings[6].ParseInteger();
Rule.LocalPorts = FirewallLogEvent.ReplacementStrings[7];
Rule.RemotePorts = FirewallLogEvent.ReplacementStrings[8];
Rule.Action = FirewallLogEvent.ReplacementStrings[9];
Rule.Profiles = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[10], FirewallBaseObject.Profile.Unkown);
Rule.LocalAddresses = FirewallLogEvent.ReplacementStrings[11];
Rule.RemoteAddresses = FirewallLogEvent.ReplacementStrings[12];
Rule.RemoteMachineAuthorizationList = FirewallLogEvent.ReplacementStrings[13];
Rule.RemoteUserAuthorizationList = FirewallLogEvent.ReplacementStrings[14];
Rule.EmbeddedContext = FirewallLogEvent.ReplacementStrings[15];
Rule.Flags = FirewallLogEvent.ReplacementStrings[16].ParseInteger();
Rule.Active = Convert.ToBoolean(FirewallLogEvent.ReplacementStrings[17].ParseInteger(0));
Rule.EdgeTraversal = FirewallLogEvent.ReplacementStrings[18].ParseInteger(0);
Rule.LooseSourceMapped = FirewallLogEvent.ReplacementStrings[19].ParseInteger(0);
Rule.SecurityOptions = FirewallLogEvent.ReplacementStrings[20].ParseInteger(0);
Rule.SchemaVersion = FirewallLogEvent.ReplacementStrings[23].ParseInteger(0);
Rule.Status = FirewallLogEvent.ReplacementStrings[24].ParseLong(0);
Rule.LocalOnlyMapped = FirewallLogEvent.ReplacementStrings[25].ParseInteger(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public abstract class FirewallRuleBaseEventArgs : FirewallEventArgs<FirewallRule>
public abstract class FirewallRuleBaseEventArgs : FirewallExtendedOriginEventArgs<FirewallRule>
{
public FirewallRule Rule
{
Expand All @@ -20,5 +20,11 @@ public FirewallRule Rule
internal FirewallRuleBaseEventArgs(EventLogEntry @event) : base(@event)
{
}

protected void SetRuleAttributes(int iRuleId, int iRuleName)
{
Rule.Id = FirewallLogEvent.ReplacementStrings[iRuleId];
Rule.Name = FirewallLogEvent.ReplacementStrings[iRuleName];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ public class FirewallRuleDeletedEventArgs : FirewallRuleBaseEventArgs
{
public FirewallRuleDeletedEventArgs(EventLogEntry @event) : base(@event)
{
SetAttributes();
}

public void SetAttributes()
{
SetAttributes(2, 3);
SetRuleAttributes(0, 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,56 @@

namespace WindowsAdvancedFirewallApi.Events.Arguments
{
public class FirewallSettingEventArgs : FirewallEventArgs<FirewallSetting>
public class FirewallSettingEventArgs<TSetting> : FirewallExtendedOriginEventArgs<TSetting> where TSetting : FirewallSetting, new()
{
public FirewallSetting Setting
public TSetting Setting
{
get { return Data; }
protected set { Data = value; }
}

internal FirewallSettingEventArgs(EventLogEntry @event) : base(@event)
{
SetAttributes();
}

protected void SetAttributes()
{
SetAttributes(4, 5, 6);
SetSettingAttributes(0, 1, 2, 3);
}

protected void SetSettingAttributes(int iSettingType, int iSettingValue, int iSettingValueSize, int iSettingValueDisplay)
{
Setting.Type = EnumUtils.ParseStringValue(FirewallLogEvent.ReplacementStrings[iSettingType], FirewallSetting.SettingType.Unkown);
Setting.ValueSize = FirewallLogEvent.ReplacementStrings[iSettingValueSize].ParseInteger(0);

var settingValue = FirewallLogEvent.ReplacementStrings[iSettingValue];
if (settingValue == string.Empty)
{
Setting.Value = FirewallSetting.SettingValue.Empty;
Setting.Value = FirewallSetting.ValueTypes.Common.Empty;
}
else
{
Setting.Value = EnumUtils.ParseStringValue(settingValue, FirewallSetting.SettingValue.Unkown);
if (Setting.Type == FirewallSetting.SettingType.IncomingStandardAction
|| Setting.Type == FirewallSetting.SettingType.OutgoingStandardAction)
{
Setting.Value = EnumUtils.ParseStringValue(settingValue, FirewallSetting.ValueTypes.StandardAction.Unkown);
}
else
{
Setting.Value = EnumUtils.ParseStringValue(settingValue, FirewallSetting.ValueTypes.Common.Unkown);
}
}

Setting.ValueSize = FirewallLogEvent.ReplacementStrings[iSettingValueSize].ParseInteger(0);
Setting.ValueString = FirewallLogEvent.ReplacementStrings[iSettingValueDisplay];
}
}

public class FirewallSettingEventArgs : FirewallSettingEventArgs<FirewallSetting>
{
internal FirewallSettingEventArgs(EventLogEntry @event) : base(@event)
{
SetAttributes();
}

protected void SetAttributes()
{
SetAttributes(4, 5, 6);
SetSettingAttributes(0, 2, 1, 3);
}
}
}
Loading

0 comments on commit 4e3cd2c

Please sign in to comment.