-
Notifications
You must be signed in to change notification settings - Fork 737
/
Copy pathtypes_windows.go
57 lines (46 loc) · 1.57 KB
/
types_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package ebpf
import (
"fmt"
"os"
"golang.org/x/sys/windows"
"github.com/cilium/ebpf/internal/efw"
"github.com/cilium/ebpf/internal/platform"
)
// WindowsProgramTypeForGUID resolves a GUID to a ProgramType.
//
// The GUID must be in the form of "{XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}".
//
// Returns an error wrapping [os.ErrNotExist] if the GUID is not recignized.
func WindowsProgramTypeForGUID(guid string) (ProgramType, error) {
progTypeGUID, err := windows.GUIDFromString(guid)
if err != nil {
return 0, fmt.Errorf("parse GUID: %w", err)
}
rawProgramType, err := efw.EbpfGetBpfProgramType(progTypeGUID)
if err != nil {
return 0, fmt.Errorf("get program type: %w", err)
}
if rawProgramType == 0 {
return 0, fmt.Errorf("program type not found for GUID %v: %w", guid, os.ErrNotExist)
}
return ProgramTypeForPlatform(platform.Windows, rawProgramType)
}
// WindowsAttachTypeForGUID resolves a GUID to an AttachType.
//
// The GUID must be in the form of "{XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}".
//
// Returns an error wrapping [os.ErrNotExist] if the GUID is not recignized.
func WindowsAttachTypeForGUID(guid string) (AttachType, error) {
attachTypeGUID, err := windows.GUIDFromString(guid)
if err != nil {
return 0, fmt.Errorf("parse GUID: %w", err)
}
rawAttachType, err := efw.EbpfGetBpfAttachType(attachTypeGUID)
if err != nil {
return 0, fmt.Errorf("get attach type: %w", err)
}
if rawAttachType == 0 {
return 0, fmt.Errorf("attach type not found for GUID %v: %w", attachTypeGUID, os.ErrNotExist)
}
return AttachTypeForPlatform(platform.Windows, rawAttachType)
}