Skip to content

Commit a1cea61

Browse files
authored
Create arifacts.go
1 parent 1ec25b1 commit a1cea61

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package VMArtifacts
2+
import (
3+
"fmt"
4+
"strings"
5+
"os"
6+
"path/filepath"
7+
)
8+
// VMArtifactsDetect checks for the presence of files and directories related to VirtualBox and VMware.
9+
// It returns true if any of the bad files or directories are detected, otherwise false.
10+
func VMArtifactsDetect() bool {
11+
badFileNames := []string{"VBoxMouse.sys", "VBoxGuest.sys", "VBoxSF.sys", "VBoxVideo.sys", "vmmouse.sys", "vboxogl.dll"}
12+
badDirs := []string{`C:\Program Files\VMware`, `C:\Program Files\oracle\virtualbox guest additions`}
13+
14+
system32Folder := os.Getenv("SystemRoot") + `\System32`
15+
files, err := filepath.Glob(filepath.Join(system32Folder, "*"))
16+
if err != nil {
17+
fmt.Printf("Error accessing System32 folder: %v\n", err)
18+
return false
19+
}
20+
21+
for _, file := range files {
22+
fileName := strings.ToLower(filepath.Base(file))
23+
for _, badFileName := range badFileNames {
24+
if fileName == strings.ToLower(badFileName) {
25+
return true
26+
}
27+
}
28+
}
29+
30+
for _, badDir := range badDirs {
31+
if _, err := os.Stat(badDir); err == nil {
32+
return true
33+
}
34+
}
35+
36+
return false
37+
}

0 commit comments

Comments
 (0)