-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge_whitelist.go
More file actions
113 lines (95 loc) · 2.78 KB
/
bridge_whitelist.go
File metadata and controls
113 lines (95 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"fmt"
"path/filepath"
"github.com/its-ernest/cura/pkg/whitelist"
"github.com/its-ernest/cura/pkg/memory"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// Whitelist exposed methods
// GetAppMap returns the current memory map to the UI
func (a *App) GetAppMap() map[string]memory.AppStatus {
return a.memoryManager.AppMap
}
// ToggleExemption flips the is_exempt status and persists
func (a *App) ToggleExemption(name string) {
a.configMu.Lock()
if app, ok := a.memoryManager.AppMap[name]; ok {
// toggle the state in the manager
app.IsExempt = !app.IsExempt
a.memoryManager.AppMap[name] = app
// persist the change to the toml file via the config
a.config.Apps = a.memoryManager.AppMap
a.configMu.Unlock()
a.SaveSettings(a.config)
status := "MONITORED"
if app.IsExempt {
status = "EXEMPT"
}
l.Write(fmt.Sprintf("CONFIG: %s is now %s", name, status))
} else {
a.configMu.Unlock()
}
}
// RemoveApp deletes an entry from the map
func (a *App) RemoveApp(name string) {
a.configMu.Lock()
delete(a.memoryManager.AppMap, name)
a.config.Apps = a.memoryManager.AppMap
a.configMu.Unlock()
a.SaveSettings(a.config)
l.Write(fmt.Sprintf("CONFIG: Removed %s", name))
}
// SelectProcess opens a native dialog and adds the result to the whitelist
func (a *App) SelectProcess() string {
//define options
options := runtime.OpenDialogOptions{
Title: "Select Process or Folder to Exempt",
Filters: []runtime.FileFilter{
{DisplayName: "Executables (*.exe)", Pattern: "*.exe"},
},
}
// open file dialog
path, err := runtime.OpenFileDialog(a.ctx, options)
if err != nil || path == "" {
return ""
}
// extract the name (e.g., "chrome.exe")
name := filepath.Base(path)
a.configMu.Lock()
// create the AppStatus struct for the process, then assign it
a.memoryManager.AppMap[name] = memory.AppStatus{
Directory: path,
IsExempt: true,
}
a.config.Apps = a.memoryManager.AppMap // Sync back to config
a.configMu.Unlock()
a.SaveSettings(a.config)
return name
}
func (a *App) RefreshApps() {
a.configMu.Lock()
rawApps, err := whitelist.GetWindowsApps()
if err != nil {
l.Write(fmt.Sprintf("ERROR: Registry scan failed: %v", err))
return
}
newCount := 0
for _, app := range rawApps {
// crucial: only add if it doesn't exist to avoid overwriting user 'IsExempt' settings
if _, exists := a.memoryManager.AppMap[app.Name]; !exists {
a.memoryManager.AppMap[app.Name] = memory.AppStatus{
Directory: app.ExePath,
IsExempt: false,
}
newCount++
}
}
// sync the local config and save if new apps were found
a.configMu.Unlock()
if newCount > 0 {
a.config.Apps = a.memoryManager.AppMap
a.SaveSettings(a.config)
l.Write(fmt.Sprintf("SYSTEM: Found %d new apps. Total registered: %d", newCount, len(a.memoryManager.AppMap)))
}
}