internal FWPM_FILTER0 ToStruct(DisposableList list) { FWPM_FILTER0 ret = new FWPM_FILTER0(); ret.filterKey = FilterKey; ret.layerKey = LayerKey; ret.subLayerKey = SubLayerKey; ret.displayData.name = Name; ret.displayData.description = Description; ret.flags = Flags; ret.weight = Weight.ToStruct(list); ret.action.type = ActionType; if (ActionType.HasFlag(FirewallActionType.Callout)) { ret.action.action.calloutKey = CalloutKey; } else { ret.action.action.filterType = FilterType; } if (ProviderKey != Guid.Empty) { ret.providerKey = list.AddStructureRef(ProviderKey).DangerousGetHandle(); } if (Conditions.Count > 0) { ret.numFilterConditions = Conditions.Count; ret.filterCondition = list.AddList(Conditions.Select(c => c.ToStruct(list))).DangerousGetHandle(); } return(ret); }
SafeBuffer IFirewallEnumTemplate <FirewallFilter> .ToTemplateBuffer(DisposableList list) { FirewallActionType action_type = ActionType; switch (action_type) { case FirewallActionType.Permit: case FirewallActionType.Block: action_type &= ~FirewallActionType.Terminating; break; } var template = new FWPM_FILTER_ENUM_TEMPLATE0 { layerKey = LayerKey, flags = Flags, providerKey = ProviderKey.HasValue ? list.AddResource(ProviderKey.Value.ToBuffer()).DangerousGetHandle() : IntPtr.Zero, actionMask = action_type }; var valid_conditions = Conditions.Where(c => !FirewallConditionGuids.IsUserId(c.FieldKey)); int count = valid_conditions.Count(); if (count > 0) { template.numFilterConditions = count; template.filterCondition = list.AddList(valid_conditions.Select(c => c.ToStruct(list))).DangerousGetHandle(); } return(list.AddStructure(template)); }
SafeBuffer IFirewallEnumTemplate <FirewallNetEvent> .ToTemplateBuffer(DisposableList list) { var template = new FWPM_NET_EVENT_ENUM_TEMPLATE0 { startTime = new Luid(StartTime.ToFileTime()), endTime = new Luid(EndTime.ToFileTime()) }; var conditions = Conditions.Where(IsValidCondition).Select(ConvertUserId); int count = conditions.Count(); if (count > 0) { template.numFilterConditions = count; template.filterCondition = list.AddList(conditions.Select(c => c.ToStruct(list))).DangerousGetHandle(); } return(list.AddStructureRef(template)); }