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);
        }
        internal SafeBuffer ToBuffer(DisposableList list)
        {
            switch (Address.AddressFamily)
            {
            case AddressFamily.InterNetwork:
                return(list.AddStructureRef(new FWP_V4_ADDR_AND_MASK()
                {
                    addr = BitConverter.ToUInt32(Address.GetAddressBytes().Reverse().ToArray(), 0),
                    mask = BitConverter.ToUInt32(Mask.GetAddressBytes().Reverse().ToArray(), 0),
                }));

            case AddressFamily.InterNetworkV6:
                return(list.AddStructureRef(new FWP_V6_ADDR_AND_MASK()
                {
                    addr = Address.GetAddressBytes(),
                    prefixLength = (byte)PrefixLength
                }));

            default:
                throw new ArgumentException("Invalid address family.");
            }
        }
Beispiel #3
0
        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));
        }