Function vmw_backdoor::is_vmware_cpu
source · pub fn is_vmware_cpu() -> bool
Expand description
Check whether this is running on VMware virtual CPU.
- CPUID leaf 0x1 (ECX) contains the virtualization bit.
- CPUID leaf 0x4000_0000 (EBX+ECX+EDX) contains the vendor label.
Examples found in repository?
examples/check-backdoor.rs (line 5)
4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
let is_vmw = vmw::is_vmware_cpu();
println!("VMware CPU detected: {}.", is_vmw);
let mut backdoor = vmw::access_backdoor_privileged().unwrap();
println!("Raised I/O access to reach backdoor port.");
let found = match backdoor.probe_vmware_backdoor() {
Ok(()) => true,
Err(_) => false,
};
println!("VMware backdoor detected: {}.", found);
}
More examples
examples/report-agent.rs (line 5)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() {
let is_vmw = vmw::is_vmware_cpu();
eprintln!("VMware CPU detected: {}.", is_vmw);
if !is_vmw {
panic!("Hypervisor not present");
}
let mut backdoor = vmw::probe_backdoor_privileged().unwrap();
eprintln!("Got backdoor access.");
let mut erpc = backdoor.open_enhanced_chan().unwrap();
eprintln!("Got ERPC channel: {:?}.", erpc);
erpc.report_agent().unwrap();
eprintln!("Reported agent.");
}
examples/log.rs (line 11)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let msg = match env::args().collect::<Vec<_>>().get(1) {
Some(val) => val.clone(),
None => "Hello world (from vmw_backdoor)".to_string(),
};
let is_vmw = vmw::is_vmware_cpu();
eprintln!("VMware CPU detected: {}.", is_vmw);
if !is_vmw {
panic!("Hypervisor not present");
}
let mut backdoor = vmw::probe_backdoor_privileged().unwrap();
eprintln!("Got backdoor access.");
let mut erpc = backdoor.open_enhanced_chan().unwrap();
eprintln!("Got ERPC channel: {:?}.", erpc);
erpc.log(&msg).unwrap();
eprintln!("Sent log message: {}.", msg);
}
examples/get-guestinfo.rs (line 11)
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
fn main() {
let key = match env::args().collect::<Vec<_>>().get(1) {
Some(val) => val.clone(),
None => panic!("missing argument: key name"),
};
let is_vmw = vmw::is_vmware_cpu();
eprintln!("VMware CPU detected: {}.", is_vmw);
if !is_vmw {
panic!("Hypervisor not present");
}
let mut backdoor = vmw::probe_backdoor_privileged().unwrap();
eprintln!("Got backdoor access.");
let mut erpc = backdoor.open_enhanced_chan().unwrap();
eprintln!("Got ERPC channel: {:?}.", erpc);
match erpc.get_guestinfo(key.as_bytes()).unwrap() {
Some(val) => {
eprintln!("Got value for key '{}'.", key);
println!("{}", String::from_utf8_lossy(&val));
}
None => panic!("Guestinfo property not found."),
};
}