tam
This commit is contained in:
@@ -40,13 +40,27 @@ var systemAllowed = map[string]bool{
|
||||
"simple_care_v1.0": true,
|
||||
}
|
||||
|
||||
func getVisibleProcesses() (map[uint32]string, error) {
|
||||
type ProcessInfo struct {
|
||||
Name string
|
||||
BundleID string
|
||||
}
|
||||
|
||||
func getVisibleProcesses() (map[uint32]ProcessInfo, error) {
|
||||
script := `tell application "System Events"
|
||||
set nameList to name of every process whose visible is true
|
||||
set pidList to unix id of every process whose visible is true
|
||||
set out to ""
|
||||
repeat with i from 1 to count of nameList
|
||||
set out to out & item i of nameList & ":" & item i of pidList & "\n"
|
||||
set procList to every process whose visible is true
|
||||
repeat with p in procList
|
||||
try
|
||||
set nameStr to name of p
|
||||
set pidVal to unix id of p
|
||||
set bid to bundle identifier of p
|
||||
if bid is missing value then
|
||||
set bid to ""
|
||||
end if
|
||||
set out to out & nameStr & "|" & pidVal & "|" & bid & "\n"
|
||||
on error
|
||||
-- ignore
|
||||
end try
|
||||
end repeat
|
||||
return out
|
||||
end tell`
|
||||
@@ -55,22 +69,29 @@ end tell`
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
procs := make(map[uint32]string)
|
||||
procs := make(map[uint32]ProcessInfo)
|
||||
lines := strings.Split(string(out), "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
idx := strings.LastIndex(line, ":")
|
||||
if idx == -1 {
|
||||
parts := strings.Split(line, "|")
|
||||
if len(parts) < 2 {
|
||||
continue
|
||||
}
|
||||
pName := line[:idx]
|
||||
pIdStr := line[idx+1:]
|
||||
pName := parts[0]
|
||||
pIdStr := parts[1]
|
||||
bundleID := ""
|
||||
if len(parts) >= 3 {
|
||||
bundleID = parts[2]
|
||||
}
|
||||
var pid uint32
|
||||
if _, err := fmt.Sscanf(pIdStr, "%d", &pid); err == nil {
|
||||
procs[pid] = pName
|
||||
procs[pid] = ProcessInfo{
|
||||
Name: pName,
|
||||
BundleID: bundleID,
|
||||
}
|
||||
}
|
||||
}
|
||||
return procs, nil
|
||||
@@ -98,11 +119,13 @@ func (b *Blocker) checkAndKill() {
|
||||
}
|
||||
|
||||
myPid := uint32(os.Getpid())
|
||||
for pid, name := range procs {
|
||||
pNameLower := strings.ToLower(name)
|
||||
for pid, info := range procs {
|
||||
pNameLower := strings.ToLower(info.Name)
|
||||
bundleIDLower := strings.ToLower(info.BundleID)
|
||||
|
||||
// 1. Always allow our app, system/critical developer tools, or agent helpers
|
||||
if pid == myPid || (currentExec != "" && pNameLower == currentExec) || systemAllowed[pNameLower] || strings.Contains(pNameLower, "antigravity") {
|
||||
// 1. Always allow our app, system/critical developer tools, or agent helpers (and Antigravity IDE)
|
||||
isAntigravity := strings.Contains(pNameLower, "antigravity") || strings.Contains(bundleIDLower, "antigravity")
|
||||
if pid == myPid || (currentExec != "" && pNameLower == currentExec) || systemAllowed[pNameLower] || isAntigravity {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -118,14 +141,14 @@ func (b *Blocker) checkAndKill() {
|
||||
// 3. If not allowed, kill the application
|
||||
if !allowed {
|
||||
if b.OnBlocked != nil {
|
||||
b.OnBlocked(name, name)
|
||||
b.OnBlocked(info.Name, info.Name)
|
||||
}
|
||||
log.Printf("[BLOCKER] KILLED unauthorized application: %s (PID: %d)", name, pid)
|
||||
log.Printf("[BLOCKER] KILLED unauthorized application: %s (PID: %d)", info.Name, pid)
|
||||
proc, err := os.FindProcess(int(pid))
|
||||
if err == nil {
|
||||
errKill := proc.Kill()
|
||||
if errKill == nil && b.OnKill != nil {
|
||||
b.OnKill(name, name)
|
||||
b.OnKill(info.Name, info.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user