Fix windows route

This commit is contained in:
世界 2022-09-29 18:59:33 +08:00
parent 6bad0c2380
commit a93592a9b5
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
9 changed files with 662 additions and 26 deletions

46
internal/winsys/helper.go Normal file
View file

@ -0,0 +1,46 @@
//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
}