// EnsureHelperToolPresent checks if helper tool exists and extracts it if not.
// On Mac OS, it also checks and set the file's owner to root:wheel and the setuid bit,
// it will request user to input password through a dialog to gain the rights to do so.
// path: absolute or relative path of the file to be checked and generated if
// not exists. Note - relative paths are resolved relative to the system-
// specific folder for aplication resources.
// prompt: the message to be shown on the dialog.
// iconPath: the full path of the icon to be shown on the dialog.
func EnsureHelperToolPresent(path string, prompt string, iconFullPath string) (err error) {mu.Lock()defer mu.Unlock()assertName := "pac"// Load different binaries for 32bit and 64bit Windows respectively.if runtime.GOOS == "windows" {suffix := "_386.exe"// https://blogs.msdn.microsoft.com/david.wang/2006/03/27/howto-detect-process-bitness/if strings.EqualFold(os.Getenv("PROCESSOR_ARCHITECTURE"), "amd64") ||strings.EqualFold(os.Getenv("PROCESSOR_ARCHITEW6432"), "amd64") {suffix = "_amd64.exe"}assertName = assertName + suffix}pacBytes, err := Asset(assertName)if err != nil {return fmt.Errorf("Unable to access pac asset: %v", err)}be, err = byteexec.New(pacBytes, path)if err != nil {return fmt.Errorf("Unable to extract helper tool: %v", err)}return ensureElevatedOnDarwin(be, prompt, iconFullPath)
}
pac.On和pac.Off
就是簡單的命令行調用,調用EnsureHelperToolPresent生成的二進制文件.在windows下就相當于sysproxy-cmd.exe on xxxx這樣