When creating a sublayer, the function toSublayer0
is used to serialize the wf.Sublayer
struct into the required fwpmSublayer0
struct in order to pass into the Win32 API. The Flags
field should be set to fwpmSublayerFlagsPersistent
when the Persistent
option is set to true
.
This is the same process as when constructing the fwpmProvider0
structure as seen just below it in compose.go
:
// toSublayer0 converts sl into an arena-allocated fwpmSublayer0.
func toSublayer0(a *arena, sl *Sublayer) *fwpmSublayer0 {
ret := (*fwpmSublayer0)(a.Alloc(unsafe.Sizeof(fwpmSublayer0{})))
*ret = fwpmSublayer0{
SublayerKey: sl.ID,
DisplayData: fwpmDisplayData0{
Name: toUint16(a, sl.Name),
Description: toUint16(a, sl.Description),
},
ProviderKey: toGUID(a, windows.GUID(sl.Provider)),
ProviderData: fwpByteBlob{
Size: uint32(len(sl.ProviderData)),
Data: toBytes(a, sl.ProviderData),
},
Weight: sl.Weight,
}
return ret
}
// toProvider0 converts p into an arena-allocated fwpmProvider0.
func toProvider0(a *arena, p *Provider) *fwpmProvider0 {
ret := (*fwpmProvider0)(a.Alloc(unsafe.Sizeof(fwpmProvider0{})))
*ret = fwpmProvider0{
ProviderKey: p.ID,
DisplayData: fwpmDisplayData0{
Name: toUint16(a, p.Name),
Description: toUint16(a, p.Description),
},
ProviderData: fwpByteBlob{
Size: uint32(len(p.Data)),
Data: toBytes(a, p.Data),
},
ServiceName: toUint16(a, p.ServiceName),
}
if p.Persistent {
ret.Flags = fwpmProviderFlagsPersistent
}
return ret
}