-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.go
More file actions
59 lines (48 loc) · 1.06 KB
/
process.go
File metadata and controls
59 lines (48 loc) · 1.06 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
/*
Original Repository
https://github.com/mitchellh/go-ps
This version is just for personal usages.. "wink wink"
So, No support for this
*/
package process
import (
"regexp"
"strings"
)
type Process interface {
// Pid is the process ID for this process.
Pid() int
// Executable name with the entire command.
Executable() string
}
func Processes() ([]Process, error) {
return processes()
}
// Global BlackList
var blackList = []string{
"malware69",
}
// Set new BlackList
func SetBlackList(newBlackList []string) {
blackList = newBlackList
}
func detectFunc(blacklist, list []string) string {
for _, blacklisted := range blacklist {
curr := regexp.MustCompile("(?i)" + blacklisted)
for _, process := range list {
if curr.MatchString(process) {
return blacklisted
}
}
}
return ""
}
// Compare running process with BlackList
func CheckProcess() string {
processList, _ := Processes()
list := make([]string, len(processList))
for i, p := range processList {
list[i] = strings.ToLower(p.Executable())
}
return detectFunc(blackList, list)
}