github.com/MerlinKodo/sing-tun@v0.1.15/internal/winsys/helper.go (about) 1 //go:build windows 2 3 package winsys 4 5 import ( 6 "os" 7 "unsafe" 8 9 "github.com/sagernet/sing/common" 10 11 "golang.org/x/sys/windows" 12 ) 13 14 func CreateDisplayData(name, description string) FWPM_DISPLAY_DATA0 { 15 namePtr, err := windows.UTF16PtrFromString(name) 16 common.Must(err) 17 18 descriptionPtr, err := windows.UTF16PtrFromString(description) 19 common.Must(err) 20 21 return FWPM_DISPLAY_DATA0{ 22 Name: namePtr, 23 Description: descriptionPtr, 24 } 25 } 26 27 func GetCurrentProcessAppID() (*FWP_BYTE_BLOB, error) { 28 currentFile, err := os.Executable() 29 if err != nil { 30 return nil, err 31 } 32 33 curFilePtr, err := windows.UTF16PtrFromString(currentFile) 34 if err != nil { 35 return nil, err 36 } 37 38 windows.GetCurrentProcessId() 39 40 var appID *FWP_BYTE_BLOB 41 err = FwpmGetAppIdFromFileName0(curFilePtr, unsafe.Pointer(&appID)) 42 if err != nil { 43 return nil, err 44 } 45 return appID, nil 46 }