use crate::engine::TechniqueResult;
#[cfg(target_os = "macos")]
use crate::brands;
#[cfg(target_os = "macos")]
use crate::util;
pub fn hw_memsize() -> TechniqueResult {
#[cfg(target_os = "macos")]
{
if let Some(memsize_str) = util::macos::sysctl_string("hw.memsize") {
if let Ok(memsize) = memsize_str.parse::<u64>() {
if memsize < 2 * 1024 * 1024 * 1024 {
return TechniqueResult::detected();
}
}
}
}
TechniqueResult::not_detected()
}
pub fn io_kit() -> TechniqueResult {
#[cfg(target_os = "macos")]
{
if let Some(output) = util::macos::ioreg(&["-l"]) {
let lower = output.to_lowercase();
if lower.contains("vmware") { return TechniqueResult::detected_with_brand(brands::VMWARE); }
if lower.contains("virtualbox") || lower.contains("vbox") {
return TechniqueResult::detected_with_brand(brands::VBOX);
}
if lower.contains("parallels") { return TechniqueResult::detected_with_brand(brands::PARALLELS); }
if lower.contains("qemu") { return TechniqueResult::detected_with_brand(brands::QEMU); }
}
}
TechniqueResult::not_detected()
}
pub fn mac_sip() -> TechniqueResult {
#[cfg(target_os = "macos")]
{
if let Some(val) = util::macos::sysctl_string("kern.hv_vmm_present") {
if val.trim() == "1" {
return TechniqueResult::detected();
}
}
}
TechniqueResult::not_detected()
}
pub fn ioreg_grep() -> TechniqueResult {
#[cfg(target_os = "macos")]
{
if let Some(output) = util::macos::ioreg(&["-rd1", "-c", "IOPlatformExpertDevice"]) {
let lower = output.to_lowercase();
if lower.contains("vmware") { return TechniqueResult::detected_with_brand(brands::VMWARE); }
if lower.contains("virtualbox") || lower.contains("vbox") {
return TechniqueResult::detected_with_brand(brands::VBOX);
}
if lower.contains("parallels") { return TechniqueResult::detected_with_brand(brands::PARALLELS); }
if lower.contains("qemu") { return TechniqueResult::detected_with_brand(brands::QEMU); }
if lower.contains("apple virtualization") || lower.contains("apple vz") {
return TechniqueResult::detected_with_brand(brands::APPLE_VZ);
}
}
}
TechniqueResult::not_detected()
}
pub fn hwmodel() -> TechniqueResult {
#[cfg(target_os = "macos")]
{
if let Some(model) = util::macos::sysctl_string("hw.model") {
if !model.contains("Mac") && !model.contains("mac") {
return TechniqueResult::detected();
}
}
}
TechniqueResult::not_detected()
}
pub fn mac_sys() -> TechniqueResult {
#[cfg(target_os = "macos")]
{
if let Some(output) = util::macos::system_profiler("SPHardwareDataType") {
let lower = output.to_lowercase();
if lower.contains("vmware") { return TechniqueResult::detected_with_brand(brands::VMWARE); }
if lower.contains("virtualbox") || lower.contains("vbox") {
return TechniqueResult::detected_with_brand(brands::VBOX);
}
if lower.contains("parallels") { return TechniqueResult::detected_with_brand(brands::PARALLELS); }
if lower.contains("qemu") { return TechniqueResult::detected_with_brand(brands::QEMU); }
if lower.contains("virtual machine") { return TechniqueResult::detected(); }
}
}
TechniqueResult::not_detected()
}