sing-tun/internal/winsys/helper.go
2022-09-30 00:35:59 +08:00

46 lines
857 B
Go

//go:build windows
package winsys
import (
"os"
"unsafe"
"github.com/sagernet/sing/common"
"golang.org/x/sys/windows"
)
func CreateDisplayData(name, description string) FWPM_DISPLAY_DATA0 {
namePtr, err := windows.UTF16PtrFromString(name)
common.Must(err)
descriptionPtr, err := windows.UTF16PtrFromString(description)
common.Must(err)
return FWPM_DISPLAY_DATA0{
Name: namePtr,
Description: descriptionPtr,
}
}
func GetCurrentProcessAppID() (*FWP_BYTE_BLOB, error) {
currentFile, err := os.Executable()
if err != nil {
return nil, err
}
curFilePtr, err := windows.UTF16PtrFromString(currentFile)
if err != nil {
return nil, err
}
windows.GetCurrentProcessId()
var appID *FWP_BYTE_BLOB
err = FwpmGetAppIdFromFileName0(curFilePtr, unsafe.Pointer(&appID))
if err != nil {
return nil, err
}
return appID, nil
}