File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ func DoesFileExist(path string) bool {
26
26
return ! os .IsNotExist (err )
27
27
}
28
28
29
- func DoesFileContain (file * os.File , stringToBeFound string ) bool {
29
+ func DoesFileContain (file * os.File , stringsToBeFound ... string ) bool {
30
30
reader := bufio .NewReader (file )
31
31
32
32
for {
@@ -41,8 +41,10 @@ func DoesFileContain(file *os.File, stringToBeFound string) bool {
41
41
return false
42
42
}
43
43
44
- if strings .Contains (line , stringToBeFound ) {
45
- return true
44
+ for _ , stringToBeFound := range stringsToBeFound {
45
+ if strings .Contains (line , stringToBeFound ) {
46
+ return true
47
+ }
46
48
}
47
49
}
48
50
}
Original file line number Diff line number Diff line change @@ -153,6 +153,18 @@ func checkXenProcFile() bool {
153
153
return DoesFileExist ("/proc/xen" )
154
154
}
155
155
156
+ func checkKernelModules () bool {
157
+
158
+ file , err := os .Open ("/proc/modules" )
159
+
160
+ if err != nil {
161
+ PrintError (err )
162
+ return false
163
+ }
164
+
165
+ return DoesFileContain (file , "vboxguest" )
166
+ }
167
+
156
168
/*
157
169
Public function returning true if a VM is detected.
158
170
If so, a non-empty string is also returned to tell how it was detected.
@@ -168,6 +180,10 @@ func IsRunningInVirtualMachine() (bool, string) {
168
180
return true , "CPU Vendor (cpuid space)"
169
181
}
170
182
183
+ if checkKernelModules () {
184
+ return true , "Kernel module (/proc/modules)"
185
+ }
186
+
171
187
if checkUML () {
172
188
return true , "CPU Vendor (/proc/cpuinfo)"
173
189
}
You can’t perform that action at this time.
0 commit comments