File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ func DoesFileExist(path string) bool {
2626 return ! os .IsNotExist (err )
2727}
2828
29- func DoesFileContain (file * os.File , stringToBeFound string ) bool {
29+ func DoesFileContain (file * os.File , stringsToBeFound ... string ) bool {
3030 reader := bufio .NewReader (file )
3131
3232 for {
@@ -41,8 +41,10 @@ func DoesFileContain(file *os.File, stringToBeFound string) bool {
4141 return false
4242 }
4343
44- if strings .Contains (line , stringToBeFound ) {
45- return true
44+ for _ , stringToBeFound := range stringsToBeFound {
45+ if strings .Contains (line , stringToBeFound ) {
46+ return true
47+ }
4648 }
4749 }
4850}
Original file line number Diff line number Diff line change @@ -153,6 +153,18 @@ func checkXenProcFile() bool {
153153 return DoesFileExist ("/proc/xen" )
154154}
155155
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+
156168/*
157169Public function returning true if a VM is detected.
158170If so, a non-empty string is also returned to tell how it was detected.
@@ -168,6 +180,10 @@ func IsRunningInVirtualMachine() (bool, string) {
168180 return true , "CPU Vendor (cpuid space)"
169181 }
170182
183+ if checkKernelModules () {
184+ return true , "Kernel module (/proc/modules)"
185+ }
186+
171187 if checkUML () {
172188 return true , "CPU Vendor (/proc/cpuinfo)"
173189 }
You can’t perform that action at this time.
0 commit comments