using System.Collections; using System.Collections.Generic; using System.Linq; namespace Vanara.PInvoke; public static partial class FwpUClnt { /// The FWPM_CALLOUT_CHANGE_CALLBACK0 function is used to add custom behavior to the callout change notification process. /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter of the FwpmCalloutSubscribeChanges0 function. /// /// /// Type: FWPM_CALLOUT_CHANGE0* /// The change notification information. /// /// None /// /// Call FwpmCalloutSubscribeChanges0 to register this callback function. /// /// FWPM_CALLOUT_CHANGE_CALLBACK0 is a specific implementation of FWPM_CALLOUT_CHANGE_CALLBACK. See WFP Version-Independent Names /// and Targeting Specific Versions of Windows for more information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_callout_change_callback0 FWPM_CALLOUT_CHANGE_CALLBACK0 // FwpmCalloutChangeCallback0; void FwpmCalloutChangeCallback0( [in] void *context, [in] const FWPM_CALLOUT_CHANGE0 *change ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_CALLOUT_CHANGE_CALLBACK0")] public delegate void FWPM_CALLOUT_CHANGE_CALLBACK0([In, Optional] IntPtr context, in FWPM_CALLOUT_CHANGE0 change); /// The FWPM_CONNECTION_CALLBACK0 function is used to add custom behavior to the connection object subscription process. /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter of the FwpmConnectionSubscribe0 function. /// /// /// Type: FWPM_CONNECTION_EVENT_TYPE /// The type of connection object change event. /// /// /// Type: FWPM_CONNECTION0* /// The connection object change information. /// /// None /// Call FwpmConnectionSubscribe0 to register this callback function. // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_connection_callback0 FWPM_CONNECTION_CALLBACK0 // FwpmConnectionCallback0; void FwpmConnectionCallback0( [in, out] void *context, [in] FWPM_CONNECTION_EVENT_TYPE eventType, [in] const // FWPM_CONNECTION0 *connection ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_CONNECTION_CALLBACK0")] public delegate void FWPM_CONNECTION_CALLBACK0([In, Out, Optional] IntPtr context, FWPM_CONNECTION_EVENT_TYPE eventType, in FWPM_CONNECTION0 connection); /// /// /// A callback function, which you implement, that is invoked with notifications regarding changes to dynamic keyword address /// (FW_DYNAMIC_KEYWORD_ADDRESS0) objects. See FwpmDynamicKeywordSubscribe0. /// /// For more info, and code examples, see Firewall dynamic keywords. /// /// /// Type: _In_opt_ void* /// Not used. /// /// /// Type: _In_opt_ void* /// The value you pass to FwpmDynamicKeywordSubscribe0 as the context argument. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_dynamic_keyword_callback0 FWPM_DYNAMIC_KEYWORD_CALLBACK0 // FwpmDynamicKeywordCallback0; void FwpmDynamicKeywordCallback0( void *notification, void *context ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_DYNAMIC_KEYWORD_CALLBACK0")] public delegate void FWPM_DYNAMIC_KEYWORD_CALLBACK0([In, Optional] IntPtr notification, [In, Optional] IntPtr context); /// The FWPM_FILTER_CHANGE_CALLBACK0 function is used to added custom behavior to the filter change notification process. /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter passed to the FwpmFilterSubscribeChanges0 function. /// /// /// Type: FWPM_FILTER_CHANGE0* /// The change notification information. /// /// None /// /// Call FwpmFilterSubscribeChanges0 to register this callback function. /// /// FWPM_FILTER_CHANGE_CALLBACK0 is a specific implementation of FWPM_FILTER_CHANGE_CALLBACK. See WFP Version-Independent Names /// and Targeting Specific Versions of Windows for more information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_filter_change_callback0 FWPM_FILTER_CHANGE_CALLBACK0 // FwpmFilterChangeCallback0; void FwpmFilterChangeCallback0( [in] void *context, [in] const FWPM_FILTER_CHANGE0 *change ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_FILTER_CHANGE_CALLBACK0")] public delegate void FWPM_FILTER_CHANGE_CALLBACK0([In, Optional] IntPtr context, in FWPM_FILTER_CHANGE0 change); /// /// The FWPM_NET_EVENT_CALLBACK0 function is used to add custom behavior to the net event subscription process. /// /// NoteFWPM_NET_EVENT_CALLBACK0 is the specific implementation of FWPM_NET_EVENT_CALLBACK used in Windows 7. See WFP /// Version-Independent Names and Targeting Specific Versions of Windows for more information. For Windows 8, FWPM_NET_EVENT_CALLBACK1 is available. /// /// /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter of the FwpmNetEventSubscribe0 function. /// /// /// Type: FWPM_NET_EVENT1* /// The net event information. /// /// None /// Call FwpmNetEventSubscribe0 to register this callback function. // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_net_event_callback0 FWPM_NET_EVENT_CALLBACK0 // FwpmNetEventCallback0; void FwpmNetEventCallback0( [in, out] void *context, [in] const FWPM_NET_EVENT1 *event ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_NET_EVENT_CALLBACK0")] public delegate void FWPM_NET_EVENT_CALLBACK0([In, Out, Optional] IntPtr context, in FWPM_NET_EVENT1 @event); /// /// The FWPM_NET_EVENT_CALLBACK1 function is used to add custom behavior to the net event subscription process. /// /// NoteFWPM_NET_EVENT_CALLBACK1 is the specific implementation of FWPM_NET_EVENT_CALLBACK used in Windows 8 and later. See /// WFP Version-Independent Names and Targeting Specific Versions of Windows for more information. For Windows 7, /// FWPM_NET_EVENT_CALLBACK0 is available. /// /// /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter of the FwpmNetEventSubscribe1 function. /// /// /// Type: const FWPM_NET_EVENT2* /// The net event information. /// /// None /// Call FwpmNetEventSubscribe1 to register this callback function. // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_net_event_callback1 FWPM_NET_EVENT_CALLBACK1 // FwpmNetEventCallback1; void FwpmNetEventCallback1( [in, out] void *context, [in] const FWPM_NET_EVENT2 *event ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_NET_EVENT_CALLBACK1")] public delegate void FWPM_NET_EVENT_CALLBACK1([In, Out, Optional] IntPtr context, in FWPM_NET_EVENT2 @event); /// /// The FWPM_NET_EVENT_CALLBACK2 function is used to add custom behavior to the net event subscription process. /// /// NoteFWPM_NET_EVENT_CALLBACK2 is the specific implementation of FWPM_NET_EVENT_CALLBACK used in Windows 10, version 1607 /// and later. See WFP Version-Independent Names and Targeting Specific Versions of Windows for more information. For Windows 8, /// FWPM_NET_EVENT_CALLBACK1 is available. For Windows 7, FWPM_NET_EVENT_CALLBACK0 is available. /// /// /// /// Optional context pointer. It contains the value of the context parameter of the FwpmNetEventSubscribe2 function. /// /// The net event information. /// None /// Call FwpmNetEventSubscribe2 to register this callback function. // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_net_event_callback2 FWPM_NET_EVENT_CALLBACK2 // FwpmNetEventCallback2; void FwpmNetEventCallback2( [in, out] void *context, [in] const FWPM_NET_EVENT3 *event ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_NET_EVENT_CALLBACK2")] public delegate void FWPM_NET_EVENT_CALLBACK2([In, Out, Optional] IntPtr context, in FWPM_NET_EVENT3 @event); /// /// The FWPM_PROVIDER_CHANGE_CALLBACK0 function is used to add custom behavior to the provider change notification process. /// /// /// Type: void* /// /// Optional context pointer. It contains the value of the context parameter passed to the FwpmProviderSubscribeChanges0 function. /// /// /// /// Type: FWPM_PROVIDER_CHANGE0* /// The change notification information. /// /// None /// /// Call FwpmProviderSubscribeChanges0 to register this callback function. /// /// FWPM_PROVIDER_CHANGE_CALLBACK0 is a specific implementation of FWPM_PROVIDER_CHANGE_CALLBACK. See WFP Version-Independent /// Names and Targeting Specific Versions of Windows for more information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_provider_change_callback0 FWPM_PROVIDER_CHANGE_CALLBACK0 // FwpmProviderChangeCallback0; void FwpmProviderChangeCallback0( [in] void *context, [in] const FWPM_PROVIDER_CHANGE0 *change ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_PROVIDER_CHANGE_CALLBACK0")] public delegate void FWPM_PROVIDER_CHANGE_CALLBACK0([In, Optional] IntPtr context, in FWPM_PROVIDER_CHANGE0 change); /// /// The FWPM_PROVIDER_CONTEXT_CHANGE_CALLBACK0 function is used to add custom behavior to the provider context change notification process. /// /// /// Type: void* /// /// Optional context pointer. It contains the value of the context parameter passed to the FwpmProviderContextSubscribeChanges0 function. /// /// /// /// Type: FWPM_PROVIDER_CONTEXT_CHANGE0* /// The change notification information. /// /// None /// /// Call FwpmProviderContextSubscribeChanges0 to register this callback function. /// /// FWPM_PROVIDER_CONTEXT_CHANGE_CALLBACK0 is a specific implementation of FWPM_PROVIDER_CONTEXT_CHANGE_CALLBACK. See WFP /// Version-Independent Names and Targeting Specific Versions of Windows for more information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_provider_context_change_callback0 // FWPM_PROVIDER_CONTEXT_CHANGE_CALLBACK0 FwpmProviderContextChangeCallback0; void FwpmProviderContextChangeCallback0( [in] void // *context, [in] const FWPM_PROVIDER_CONTEXT_CHANGE0 *change ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_PROVIDER_CONTEXT_CHANGE_CALLBACK0")] public delegate void FWPM_PROVIDER_CONTEXT_CHANGE_CALLBACK0([In, Optional] IntPtr context, in FWPM_PROVIDER_CONTEXT_CHANGE0 change); /// /// The FWPM_SUBLAYER_CHANGE_CALLBACK0 function is used to added custom behavior to the sublayer change notification process. /// /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter of the FwpmSubLayerSubscribeChanges0 function. /// /// /// Type: FWPM_SUBLAYER_CHANGE0* /// The change notification information. /// /// None /// /// Call FwpmSubLayerSubscribeChanges0 to register this callback function. /// /// FWPM_SUBLAYER_CHANGE_CALLBACK0 is a specific implementation of FWPM_SUBLAYER_CHANGE_CALLBACK. See WFP Version-Independent /// Names and Targeting Specific Versions of Windows for more information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_sublayer_change_callback0 FWPM_SUBLAYER_CHANGE_CALLBACK0 // FwpmSublayerChangeCallback0; void FwpmSublayerChangeCallback0( [in] void *context, [in] const FWPM_SUBLAYER_CHANGE0 *change ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_SUBLAYER_CHANGE_CALLBACK0")] public delegate void FWPM_SUBLAYER_CHANGE_CALLBACK0([In, Optional] IntPtr context, in FWPM_SUBLAYER_CHANGE0 change); /// The FWPM_SYSTEM_PORTS_CALLBACK0 function is used to add custom behavior to the system port subscription process. /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter of the FwpmSystemPortsSubscribe0 function. /// /// /// Type: FWPM_SYSTEM_PORTS0* /// The system port information. /// /// None /// /// Call FwpmSystemPortsSubscribe0 to register this callback function. /// /// FWPM_SYSTEM_PORTS_CALLBACK0 is a specific implementation of FWPM_SYSTEM_PORTS_CALLBACK. See WFP Version-Independent Names and /// Targeting Specific Versions of Windows for more information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_system_ports_callback0 FWPM_SYSTEM_PORTS_CALLBACK0 // FwpmSystemPortsCallback0; void FwpmSystemPortsCallback0( [in, out] void *context, [in] const FWPM_SYSTEM_PORTS0 *sysPorts ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_SYSTEM_PORTS_CALLBACK0")] public delegate void FWPM_SYSTEM_PORTS_CALLBACK0([In, Out, Optional] IntPtr context, in FWPM_SYSTEM_PORTS0 sysPorts); /// The FWPM_VSWITCH_EVENT_CALLBACK0 function is used to add custom behavior to the vSwitch event subscription process. /// /// Type: void* /// Optional context pointer. It contains the value of the context parameter of the FwpmvSwitchEventSubscribe0 function. /// /// /// Type: FWPM_VSWITCH_EVENT0* /// The vSwitch event information. /// /// This callback function does not return a value. /// /// Call FwpmvSwitchEventSubscribe0 to register this callback function. /// /// FWPM_VSWITCH_EVENT_CALLBACK0 is a specific implementation of FWPM_VSWITCH_EVENT_CALLBACK. See WFP Version-Independent Names /// and Targeting Specific Versions of Windows for more information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-fwpm_vswitch_event_callback0 FWPM_VSWITCH_EVENT_CALLBACK0 // FwpmVswitchEventCallback0; DWORD FwpmVswitchEventCallback0( [in, out] void *context, [in] const FWPM_VSWITCH_EVENT0 *vSwitchEvent ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.FWPM_VSWITCH_EVENT_CALLBACK0")] public delegate uint FWPM_VSWITCH_EVENT_CALLBACK0([In, Out, Optional] IntPtr context, in FWPM_VSWITCH_EVENT0 vSwitchEvent); /// /// The IPSEC_KEY_MANAGER_DICTATE_KEY0 function is used by the Trusted Intermediary Agent (TIA) to dictate keys for the SA being negotiated. /// /// Information about the inbound SA. /// Information about the outbound SA. /// /// if the keying module should randomly generate keys in the event that the TIA is unable to supply keys; /// otherwise, . /// /// /// Type: DWORD /// /// /// Return code/value /// Description /// /// /// ERROR_SUCCESS
0
/// The keys were successsfully dictated. ///
/// /// FWP_E_* error code
0x80320001—0x80320039
/// A Windows Filtering Platform (WFP) specific error. See WFP Error Codes for details. ///
/// /// RPC_* error code
0x80010001—0x80010122
/// Failure to communicate with the remote or local firewall engine. ///
///
///
/// /// Call IPsecKeyManagerAddAndRegister0 to invoke this function pointer. If the weight specified in /// IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0 for a TIA is higher than that of any peer, IPSEC_KEY_MANAGER_DICTATE_KEY0 will be invoked. /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-ipsec_key_manager_dictate_key0 IPSEC_KEY_MANAGER_DICTATE_KEY0 // IpsecKeyManagerDictateKey0; DWORD IpsecKeyManagerDictateKey0( IPSEC_SA_DETAILS1 *inboundSaDetails, IPSEC_SA_DETAILS1 // *outboundSaDetails, BOOL *keyingModuleGenKey ) {...} [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.IPSEC_KEY_MANAGER_DICTATE_KEY0")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate Win32Error IPSEC_KEY_MANAGER_DICTATE_KEY0(ref IPSEC_SA_DETAILS1 inboundSaDetails, ref IPSEC_SA_DETAILS1 outboundSaDetails, [MarshalAs(UnmanagedType.Bool)] out bool keyingModuleGenKey); /// /// The IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0 function indicates whether the Trusted Intermediary Agent (TIA) will dictate the /// keys for the SA being negotiated. /// /// Specifies the traffic for which keys should be set or retrieved. /// if the TIA will dictate the keys; otherwise, . /// Specifies the weight that this TIA should be given compared to any peers. /// /// Call IPsecKeyManagerAddAndRegister to register this function pointer. /// If the TIA wants to dictate the keys, and its weight is higher than that of any peers, IPsec will subsequently call IPSEC_KEY_MANAGER_DICTATE_KEY0. /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-ipsec_key_manager_key_dictation_check0 // IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0 IpsecKeyManagerKeyDictationCheck0; void IpsecKeyManagerKeyDictationCheck0( [in] const // IKEEXT_TRAFFIC0 *ikeTraffic, [out] BOOL *willDictateKey, [out] UINT32 *weight ) {...} [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0(in IKEEXT_TRAFFIC0 ikeTraffic, [MarshalAs(UnmanagedType.Bool)] out bool willDictateKey, out uint weight); /// /// The IPSEC_KEY_MANAGER_NOTIFY_KEY0 function is used to notify Trusted Intermediary Agents (TIAs) of the keys for the SA being negotiated. /// /// Information about the inbound SA. /// Information about the outbound SA. /// Call IPsecKeyManagerAddAndRegister to register this function pointer. // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-ipsec_key_manager_notify_key0 IPSEC_KEY_MANAGER_NOTIFY_KEY0 // IpsecKeyManagerNotifyKey0; void IpsecKeyManagerNotifyKey0( [in] const IPSEC_SA_DETAILS1 *inboundSa, [in] const IPSEC_SA_DETAILS1 // *outboundSa ) {...} [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.IPSEC_KEY_MANAGER_NOTIFY_KEY0")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void IPSEC_KEY_MANAGER_NOTIFY_KEY0(in IPSEC_SA_DETAILS1 inboundSa, in IPSEC_SA_DETAILS1 outboundSa); /// /// The IPSEC_SA_CONTEXT_CALLBACK0 function is used to add custom behavior to the IPsec security association (SA) context /// subscription process. /// /// Call IPsecSaContextSubscribe0 to register this callback function. // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nc-fwpmu-ipsec_sa_context_callback0 IPSEC_SA_CONTEXT_CALLBACK0 // IpsecSaContextCallback0; void IpsecSaContextCallback0( [in, out] void *context, [in] const IPSEC_SA_CONTEXT_CHANGE0 *change ) {...} [PInvokeData("fwpmu.h", MSDNShortId = "NC:fwpmu.IPSEC_SA_CONTEXT_CALLBACK0")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void IPSEC_SA_CONTEXT_CALLBACK0([In, Out] IntPtr context, in IPSEC_SA_CONTEXT_CHANGE0 change); internal delegate Win32Error ArrayFunc(HFWPENG engineHandle, HANDLE enumHandle, uint numEntriesRequested, out SafeFwpmMem entries, out uint numEntriesReturned); internal delegate Win32Error CreateEnumHandleFunc(HFWPENG engineHandle, IntPtr enumTemplate, out HANDLE enumHandle); internal delegate Win32Error DestroyEnumHandleFunc(HFWPENG engineHandle, HANDLE enumHandle); internal delegate Win32Error GetById(HFWPENG engineHandle, TIn id, out SafeFwpmMem value) where TIn : struct; internal delegate Win32Error GetByKey(HFWPENG engineHandle, in Guid key, out SafeFwpmMem value); internal delegate Win32Error GetSubs(HFWPENG engineHandle, out SafeFwpmMem entries, out uint numEntriesReturned); /// Flags for FwpmDynamicKeywordSubscribe0. [PInvokeData("fwpmu.h", MSDNShortId = "NF:fwpmu.FwpmDynamicKeywordSubscribe0")] [Flags] public enum FWPM_NOTIFY : ulong { /// /// Notifications will be delivered only for objects that have the FW_DYNAMIC_KEYWORD_ADDRESS_FLAGS_AUTO_RESOLVE flag set. /// FWPM_NOTIFY_ADDRESSES_AUTO_RESOLVE = 0x01, /// /// Notifications will be delivered only for objects that don't have the FW_DYNAMIC_KEYWORD_ADDRESS_FLAGS_AUTO_RESOLVE flag set. /// FWPM_NOTIFY_ADDRESSES_NON_AUTO_RESOLVE = 0x02, /// FWPM_NOTIFY_ADDRESSES_ALL = FWPM_NOTIFY_ADDRESSES_AUTO_RESOLVE | FWPM_NOTIFY_ADDRESSES_NON_AUTO_RESOLVE, /// FWPM_NOTIFY_GRANULAR = 0x04, } /// Flags for FwpmIPsecTunnelAdd. [Flags] public enum FWPM_TUNNEL_FLAG : uint { /// Adds a point-to-point tunnel to the system. FWPM_TUNNEL_FLAG_POINT_TO_POINT = 0x00000001, /// Enables virtual interface-based IPsec tunnel mode. FWPM_TUNNEL_FLAG_ENABLE_VIRTUAL_IF_TUNNELING = 0x00000002, /// Reserved. FWPM_TUNNEL_FLAG_RESERVED0 = 0x00000004, } /// Flags for FwpmTransactionBegin0. [Flags] public enum FWPM_TXN : uint { /// Begin read-only transaction. FWPM_TXN_READ_ONLY = 0x00000001 } /// IPsec SA flag [PInvokeData("fwpmu.h", MSDNShortId = "NF:fwpmu.IPsecSaContextUpdate0")] [Flags] public enum IPSEC_SA_BUNDLE_UPDATE : ulong { /// Updates the [IPSEC_SA_DETAILS1](/windows/desktop/api/ipsectypes/ns-ipsectypes-ipsec_sa_details1) structure. IPSEC_SA_DETAILS_UPDATE_TRAFFIC = 0x01, /// Updates the [IPSEC_SA_DETAILS1](/windows/desktop/api/ipsectypes/ns-ipsectypes-ipsec_sa_details1) structure. IPSEC_SA_DETAILS_UPDATE_UDP_ENCAPSULATION = 0x02, /// Updates the [IPSEC_SA_BUNDLE1](/windows/desktop/api/ipsectypes/ns-ipsectypes-ipsec_sa_bundle1) structure. IPSEC_SA_BUNDLE_UPDATE_FLAGS = 0x04, /// Updates the [IPSEC_SA_BUNDLE1](/windows/desktop/api/ipsectypes/ns-ipsectypes-ipsec_sa_bundle1) structure. IPSEC_SA_BUNDLE_UPDATE_NAP_CONTEXT = 0x08, /// Updates the [IPSEC_SA_BUNDLE1](/windows/desktop/api/ipsectypes/ns-ipsectypes-ipsec_sa_bundle1) structure. IPSEC_SA_BUNDLE_UPDATE_KEY_MODULE_STATE = 0x10, /// Updates the [IPSEC_SA_BUNDLE1](/windows/desktop/api/ipsectypes/ns-ipsectypes-ipsec_sa_bundle1) structure. IPSEC_SA_BUNDLE_UPDATE_PEER_V4_PRIVATE_ADDRESS = 0x20, /// Updates the [IPSEC_SA_BUNDLE1](/windows/desktop/api/ipsectypes/ns-ipsectypes-ipsec_sa_bundle1) structure. IPSEC_SA_BUNDLE_UPDATE_MM_SA_ID = 0x40, } internal static Win32Error FwpmGenericEnum(CreateEnumHandleFunc create, ArrayFunc enum0, DestroyEnumHandleFunc destroy, [In] HFWPENG engineHandle, out SafeFwpmArray entries, TTemplate? template = null) where TElem : struct where TTemplate : struct { entries = new(IntPtr.Zero, 0, true); using SafeCoTaskMemStruct pTempl = template; Win32Error err = create(engineHandle, pTempl, out HANDLE hEnum); if (err.Succeeded) { try { err = enum0(engineHandle, hEnum, Kernel32.INFINITE, out SafeFwpmMem mem, out var c); entries = new(mem, c, true); return err; } finally { _=destroy(engineHandle, hEnum); } } return err; } internal static Win32Error FwpmGenericGetById(GetById func, HFWPENG engineHandle, TIn id, out SafeFwpmStruct value) where T : struct where TIn : struct { Win32Error err = func(engineHandle, id, out SafeFwpmMem mem); value = mem; return err; } internal static Win32Error FwpmGenericGetByKey(GetByKey func, HFWPENG engineHandle, in Guid key, out SafeFwpmStruct value) where T : struct { Win32Error err = func(engineHandle, key, out SafeFwpmMem mem); value = mem; return err; } internal static Win32Error FwpmGenericGetSubs(GetSubs func, HFWPENG engineHandle, out SafeFwpmArray entries) where T : struct { Win32Error err = func(engineHandle, out SafeFwpmMem mem, out var c); entries = new(mem, c); return err; } /// Provides a handle to a callout change subscription. [StructLayout(LayoutKind.Sequential)] public struct HFWPCALLOUTCHANGE : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPCALLOUTCHANGE(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPCALLOUTCHANGE NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPCALLOUTCHANGE h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPCALLOUTCHANGE h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPCALLOUTCHANGE(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPCALLOUTCHANGE h1, HFWPCALLOUTCHANGE h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPCALLOUTCHANGE h1, HFWPCALLOUTCHANGE h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPCALLOUTCHANGE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a connection event. [StructLayout(LayoutKind.Sequential)] public struct HFWPCONNEVENT : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPCONNEVENT(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPCONNEVENT NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPCONNEVENT h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPCONNEVENT h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPCONNEVENT(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPCONNEVENT h1, HFWPCONNEVENT h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPCONNEVENT h1, HFWPCONNEVENT h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPCONNEVENT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a FWP Session Engine. [StructLayout(LayoutKind.Sequential)] public struct HFWPENG : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPENG(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPENG NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPENG h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPENG h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPENG(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPENG h1, HFWPENG h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPENG h1, HFWPENG h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPENG h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a subscriptor for dynamic keywords. [StructLayout(LayoutKind.Sequential)] public struct HFWPMDYNKEYSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMDYNKEYSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMDYNKEYSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMDYNKEYSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMDYNKEYSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMDYNKEYSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMDYNKEYSUB h1, HFWPMDYNKEYSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMDYNKEYSUB h1, HFWPMDYNKEYSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMDYNKEYSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a filter subscription. [StructLayout(LayoutKind.Sequential)] public struct HFWPMFILTERSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMFILTERSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMFILTERSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMFILTERSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMFILTERSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMFILTERSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMFILTERSUB h1, HFWPMFILTERSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMFILTERSUB h1, HFWPMFILTERSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMFILTERSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a network event. [StructLayout(LayoutKind.Sequential)] public struct HFWPMNETEVTSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMNETEVTSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMNETEVTSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMNETEVTSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMNETEVTSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMNETEVTSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMNETEVTSUB h1, HFWPMNETEVTSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMNETEVTSUB h1, HFWPMNETEVTSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMNETEVTSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a provider context subscription. [StructLayout(LayoutKind.Sequential)] public struct HFWPMPROVCTXSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMPROVCTXSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMPROVCTXSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMPROVCTXSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMPROVCTXSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMPROVCTXSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMPROVCTXSUB h1, HFWPMPROVCTXSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMPROVCTXSUB h1, HFWPMPROVCTXSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMPROVCTXSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a provider subscription. [StructLayout(LayoutKind.Sequential)] public struct HFWPMPROVSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMPROVSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMPROVSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMPROVSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMPROVSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMPROVSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMPROVSUB h1, HFWPMPROVSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMPROVSUB h1, HFWPMPROVSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMPROVSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a SubLayer subscription. [StructLayout(LayoutKind.Sequential)] public struct HFWPMSUBLAYERSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMSUBLAYERSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMSUBLAYERSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMSUBLAYERSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMSUBLAYERSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMSUBLAYERSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMSUBLAYERSUB h1, HFWPMSUBLAYERSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMSUBLAYERSUB h1, HFWPMSUBLAYERSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMSUBLAYERSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a switch event subscription. [StructLayout(LayoutKind.Sequential)] public struct HFWPMSWITCHEVTSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMSWITCHEVTSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMSWITCHEVTSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMSWITCHEVTSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMSWITCHEVTSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMSWITCHEVTSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMSWITCHEVTSUB h1, HFWPMSWITCHEVTSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMSWITCHEVTSUB h1, HFWPMSWITCHEVTSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMSWITCHEVTSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a system ports subscription. [StructLayout(LayoutKind.Sequential)] public struct HFWPMSYSPORTSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HFWPMSYSPORTSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HFWPMSYSPORTSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HFWPMSYSPORTSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HFWPMSYSPORTSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HFWPMSYSPORTSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HFWPMSYSPORTSUB h1, HFWPMSYSPORTSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HFWPMSYSPORTSUB h1, HFWPMSYSPORTSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HFWPMSYSPORTSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to an IPSec key manager registration. [StructLayout(LayoutKind.Sequential)] public struct HIPSECKEYMGRREG : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HIPSECKEYMGRREG(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HIPSECKEYMGRREG NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HIPSECKEYMGRREG h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HIPSECKEYMGRREG h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HIPSECKEYMGRREG(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HIPSECKEYMGRREG h1, HIPSECKEYMGRREG h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HIPSECKEYMGRREG h1, HIPSECKEYMGRREG h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HIPSECKEYMGRREG h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// Provides a handle to a IPsec SA context subscription. [StructLayout(LayoutKind.Sequential)] public struct HIPSECSACTXSUB : IHandle { private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HIPSECSACTXSUB(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HIPSECSACTXSUB NULL => new(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Implements the operator !. /// The handle. /// The result of the operator. public static bool operator !(HIPSECSACTXSUB h1) => h1.IsNull; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HIPSECSACTXSUB h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HIPSECSACTXSUB(IntPtr h) => new(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HIPSECSACTXSUB h1, HIPSECSACTXSUB h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HIPSECSACTXSUB h1, HIPSECSACTXSUB h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HIPSECSACTXSUB h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// /// The IPSEC_KEY_MANAGER_CALLBACKS0 structure specifies the set of callbacks which should be invoked by IPsec at various stages /// of SA negotiation /// /// /// If the IPSEC_KEY_MANAGER_FLAG_DICTATE_KEY flag is set, all three callbacks must be specified; otherwise, only the /// keyNotify callback should be specified. /// // https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/ns-fwpmu-ipsec_key_manager_callbacks0 typedef struct // _IPSEC_KEY_MANAGER_CALLBACKS0 { GUID reserved; UINT32 flags; IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0 keyDictationCheck; // IPSEC_KEY_MANAGER_DICTATE_KEY0 keyDictation; IPSEC_KEY_MANAGER_NOTIFY_KEY0 keyNotify; } IPSEC_KEY_MANAGER_CALLBACKS0; [PInvokeData("fwpmu.h", MSDNShortId = "NS:fwpmu._IPSEC_KEY_MANAGER_CALLBACKS0")] [StructLayout(LayoutKind.Sequential)] public struct IPSEC_KEY_MANAGER_CALLBACKS0 { /// /// Type: GUID /// Reserved for system use. /// public Guid reserved; /// /// Type: UINT32 /// Reserved for system use. /// public uint flags; /// /// Type: IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0 /// /// Specifies that the Trusted Intermediary Agent (TIA) will dictate the keys for the SA being negotiated. Only used if the /// IPSEC_DICTATE_KEY flag is set. /// /// public IPSEC_KEY_MANAGER_KEY_DICTATION_CHECK0 keyDictationCheck; /// /// Type: IPSEC_KEY_MANAGER_DICTATE_KEY0 /// Allows the TIA to dictate the keys for the SA being negotiated. Only used if the IPSEC_DICTATE_KEY flag is set. /// public IPSEC_KEY_MANAGER_DICTATE_KEY0 keyDictation; /// /// Type: IPSEC_KEY_MANAGER_NOTIFY_KEY0 /// Notifies the TIA of the keys for the SA being negotiated. /// public IPSEC_KEY_MANAGER_NOTIFY_KEY0 keyNotify; } /// Provides a for memory returned by FWP functions that is disposed using . public class SafeFwpmArray : SafeHANDLE, IReadOnlyList where T : struct { private readonly bool byRef; internal SafeFwpmArray(IntPtr preexistingHandle, SizeT count, bool byRef = false) : base(preexistingHandle, true) { Count = count; this.byRef = byRef; } internal SafeFwpmArray(SafeFwpmMem preexistingHandle, SizeT count, bool byRef = false) : this(preexistingHandle.ReleaseOwnership(), count, byRef) { } /// Initializes a new instance of the class. private SafeFwpmArray() : base(IntPtr.Zero, true) { } /// public int Count { get; private set; } /// public T this[int index] => index >= 0 && index < Count ? Enumerate().ElementAt(index) : throw new ArgumentOutOfRangeException(nameof(index)); /// public IEnumerator GetEnumerator() => Enumerate().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// protected override bool InternalReleaseHandle() { FwpmFreeMemory0(ref handle); handle = default; return true; } private IEnumerable Enumerate() => byRef ? handle.ToIEnum(Count).Select(p => p.Convert(uint.MaxValue, CharSet.Unicode)) : handle.ToIEnum(Count); } /// Provides a for memory returned by FWP functions that is disposed using . public class SafeFwpmMem : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeFwpmMem(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeFwpmMem() : base(IntPtr.Zero, true) { } /// Performs an explicit conversion from to . /// The safe handle. /// The result of the conversion. public static explicit operator PSECURITY_DESCRIPTOR(SafeFwpmMem h) => h.handle; /// Extracts an array of elements from this memory. /// The type of the array element to return. /// The element count. /// /// if set to the array is extracted from a list of pointers to , rather than an array /// of elements. /// /// An array of type of length . public T[] ToArray(SizeT elemCount, bool byRef) => byRef ? Array.ConvertAll(handle.ToArray(elemCount) ?? new IntPtr[0], p => p.Convert(uint.MaxValue, CharSet.Unicode)) : handle.ToArray(elemCount) ?? new T[0]; /// Extracts a structure from this memory. /// The type of the structure to extract. /// The structure or if the handle is invalid. public T? ToStructure() where T : struct => handle.ToNullableStructure(); /// protected override bool InternalReleaseHandle() { FwpmFreeMemory0(ref handle); handle = default; return true; } } /// Provides a for memory returned by FWP functions that is disposed using . public class SafeFwpmStruct : SafeHANDLE where T : struct { internal SafeFwpmStruct(IntPtr preexistingHandle) : base(preexistingHandle, true) { } /// Initializes a new instance of the class. private SafeFwpmStruct() : base(IntPtr.Zero, true) { } /// Gets the nullable value of the structue pointed to in memory. /// The value. public T? Value => handle.ToNullableStructure(); /// Performs an implicit conversion from to . /// The pointer. /// The result of the conversion. public static implicit operator SafeFwpmStruct(SafeFwpmMem p) => new(p.ReleaseOwnership()); /// Performs an implicit conversion from to . /// The safe handle. /// The result of the conversion. public static implicit operator T(SafeFwpmStruct h) => h.Value.GetValueOrDefault(); /// protected override bool InternalReleaseHandle() { FwpmFreeMemory0(ref handle); handle = default; return true; } } /// Provides a for that is disposed using . public class SafeHFWPENG : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeHFWPENG(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeHFWPENG() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HFWPENG(SafeHFWPENG h) => h.handle; /// protected override bool InternalReleaseHandle() => FwpmEngineClose0(handle).Succeeded; } }