Skip to content

Commit

Permalink
updated vmaware.hpp and cli.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
utoshu committed Sep 23, 2024
1 parent 31f0689 commit 2e8f8ba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ void general() {
checker(VM::WSL_PROC, "WSL string in /proc");
checker(VM::ANYRUN_DRIVER, "ANY.RUN driver");
checker(VM::ANYRUN_DIRECTORY, "ANY.RUN directory");
checker(VM::DXDIAG_CHECK, "DXDIAG check");

std::printf("\n");

Expand Down
51 changes: 49 additions & 2 deletions src/vmaware.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* ██╗ ██╗███╗ ███╗ █████╗ ██╗ ██╗ █████╗ ██████╗ ███████╗
* ██║ ██║████╗ ████║██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝
* ██║ ██║██╔████╔██║███████║██║ █╗ ██║███████║██████╔╝█████╗
Expand Down Expand Up @@ -437,6 +437,7 @@ struct VM {
WSL_PROC,
ANYRUN_DRIVER,
ANYRUN_DIRECTORY,
DXDIAG_CHECK,

// start of non-technique flags (THE ORDERING IS VERY SPECIFIC HERE AND MIGHT BREAK SOMETHING IF RE-ORDERED)
NO_MEMO,
Expand Down Expand Up @@ -9054,6 +9055,51 @@ struct VM {
return false;
}

/**
* @brief Use dxdiag CLI to query for VM information
* @category Windows
* @author utoshu
*/
[[nodiscard]] static bool dxdiag_check() try {
#if (!MSVC)
return false;
#else
if (system("dxdiag /t output.txt") != 0) {
debug("DXDIAG_CHECK: failed to run dxdiag");
return false;
}

std::ifstream infile("output.txt");
if (!infile.is_open()) {
debug("DXDIAG_CHECK: failed to open output.txt");
return false;
}

std::string line;
bool found = false;
while (std::getline(infile, line)) {
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
if (line.find("virtualbox") != std::string::npos || line.find("vmware") != std::string::npos || line.find("hyper-v") != std::string::npos) {
found = true;
break;
}
}

infile.close();

if (found) {
return core::add(VMWARE);
std::remove("output.txt");
}

return false;
#endif
}
catch (...) {
debug("DXDIAG_CHECK: caught error, returned false");
return false;
}


/**
* @brief Check for any.run driver presence
Expand Down Expand Up @@ -10372,5 +10418,6 @@ const std::map<VM::enum_flags, VM::core::technique> VM::core::technique_table =
{ VM::PODMAN_FILE, { 15, VM::podman_file, true } },
{ VM::WSL_PROC, { 30, VM::wsl_proc_subdir, false } },
{ VM::ANYRUN_DRIVER, { 65, VM::anyrun_driver, false } },
{ VM::ANYRUN_DIRECTORY, { 35, VM::anyrun_directory, false } }
{ VM::ANYRUN_DIRECTORY, { 35, VM::anyrun_directory, false } },
{ VM::DXDIAG_CHECK, { 100, VM::dxdiag_check, false }}
};

0 comments on commit 2e8f8ba

Please sign in to comment.