From dbf02ecf61c5cb5775be817f4cb06d4fe352669b Mon Sep 17 00:00:00 2001 From: utoshu Date: Sun, 13 Oct 2024 23:18:52 +0200 Subject: [PATCH 1/6] add gpu_chiptype detection method --- src/cli.cpp | 1 + src/vmaware.hpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/cli.cpp b/src/cli.cpp index 1f756a5..2b7aa70 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -514,6 +514,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::GPU_CHIPTYPE, "GPU Chiptype"); std::printf("\n"); diff --git a/src/vmaware.hpp b/src/vmaware.hpp index 4419120..e243838 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -439,6 +439,7 @@ struct VM { WSL_PROC, ANYRUN_DRIVER, ANYRUN_DIRECTORY, + GPU_CHIPTYPE, // start of settings technique flags (THE ORDERING IS VERY SPECIFIC HERE AND MIGHT BREAK SOMETHING IF RE-ORDERED) NO_MEMO, @@ -9127,6 +9128,49 @@ struct VM { return false; } + /** + * @brief Use wmic to get the GPU/videocontrollers chip type. + * @category Windows + * @author utoshu + */ + +[[nodiscard]] static bool gpu_chiptype() try { +#if (!MSVC) + return false; +#else + std::string command = "wmic path win32_videocontroller get videoprocessor"; + std::string result = ""; + + FILE* pipe = _popen(command.c_str(), "r"); + if (!pipe) { + debug("GPU_CHIPTYPE: failed to run wmic command"); + return false; + } + + char buffer[128]; + while (!feof(pipe)) { + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + _pclose(pipe); + + std::transform(result.begin(), result.end(), result.begin(), ::tolower); + + if (result.find("vmware") != std::string::npos || + result.find("virtualbox") != std::string::npos || + result.find("hyper-v") != std::string::npos) { + core::add(VMWARE); + return true; + } + + return false; +#endif +} +catch (...) { + debug("GPU_CHIPTYPE: caught error, returned false"); + return false; +} + /** * @brief Check for any.run driver presence @@ -10708,5 +10752,6 @@ const std::map 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::GPU_CHIPTYPE, { 100, VM::gpu_chiptype, false }} }; From 4ce70c99bde0989b0b91878adafbda3b1da8425c Mon Sep 17 00:00:00 2001 From: kernel <77142078+kernelwernel@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:29:43 +0100 Subject: [PATCH 2/6] added credits --- README.md | 1 + src/vmaware.hpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cad345d..435880f 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ And if you found this project useful, a star would be appreciated :) - Eric Parker's discord community - [ShellCode33](https://github.com/ShellCode33) - [Georgii Gennadev (D00Movenok)](https://github.com/D00Movenok) +- [utoshu](https://github.com/utoshu)
diff --git a/src/vmaware.hpp b/src/vmaware.hpp index e243838..1a19234 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -8,7 +8,7 @@ * * C++ VM detection library * - * - Made by: @kernelwernel (https://github.com/kernelwernel) + * - Made by: kernelwernel (https://github.com/kernelwernel) * - Contributed by: * - Requiem (https://github.com/NotRequiem) * - Alex (https://github.com/greenozon) @@ -16,6 +16,7 @@ * - Vladyslav Miachkov (https://github.com/fameowner99) * - Alan Tse (https://github.com/alandtse) * - Georgii Gennadev (https://github.com/D00Movenok) + * - utoshu (https://github.com/utoshu) * - Repository: https://github.com/kernelwernel/VMAware * - Docs: https://github.com/kernelwernel/VMAware/docs/documentation.md * - Full credits: https://github.com/kernelwernel/VMAware#credits-and-contributors-%EF%B8%8F From 45e4ad941350f305b9a657a0a30d51acbf2abc17 Mon Sep 17 00:00:00 2001 From: kernel <77142078+kernelwernel@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:35:01 +0100 Subject: [PATCH 3/6] slight changes for standard syntax of the library --- src/vmaware.hpp | 56 ++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/src/vmaware.hpp b/src/vmaware.hpp index 1a19234..3c7aba6 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -9129,48 +9129,42 @@ struct VM { return false; } - /** + + /** * @brief Use wmic to get the GPU/videocontrollers chip type. * @category Windows * @author utoshu */ - -[[nodiscard]] static bool gpu_chiptype() try { + [[nodiscard]] static bool gpu_chiptype() try { #if (!MSVC) - return false; + return false; #else - std::string command = "wmic path win32_videocontroller get videoprocessor"; - std::string result = ""; + std::string command = "wmic path win32_videocontroller get videoprocessor"; + auto ptr = util::sys_result(command); - FILE* pipe = _popen(command.c_str(), "r"); - if (!pipe) { - debug("GPU_CHIPTYPE: failed to run wmic command"); - return false; - } + const std::string result = *ptr; - char buffer[128]; - while (!feof(pipe)) { - if (fgets(buffer, 128, pipe) != NULL) - result += buffer; - } - _pclose(pipe); + std::transform(result.begin(), result.end(), result.begin(), ::tolower); - std::transform(result.begin(), result.end(), result.begin(), ::tolower); + if (util::find(result, "vmware")) { + return core::add(VMWARE); + } - if (result.find("vmware") != std::string::npos || - result.find("virtualbox") != std::string::npos || - result.find("hyper-v") != std::string::npos) { - core::add(VMWARE); - return true; - } + if (util::find(result, "virtualbox")) { + return core::add(VBOX); + } - return false; -#endif -} -catch (...) { - debug("GPU_CHIPTYPE: caught error, returned false"); - return false; -} + if (util::find(result, "hyper-v")) { + return core::add(HYPERV); + } + + return false; + #endif + } + catch (...) { + debug("GPU_CHIPTYPE: caught error, returned false"); + return false; + } /** From 29d8d3333e8b72fc4e991235ffafa4ed701bb272 Mon Sep 17 00:00:00 2001 From: kernel <77142078+kernelwernel@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:40:21 +0100 Subject: [PATCH 4/6] fix attempt --- src/vmaware.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vmaware.hpp b/src/vmaware.hpp index 3c7aba6..a92b767 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -9139,7 +9139,7 @@ struct VM { #if (!MSVC) return false; #else - std::string command = "wmic path win32_videocontroller get videoprocessor"; + const char* command = "wmic path win32_videocontroller get videoprocessor"; auto ptr = util::sys_result(command); const std::string result = *ptr; From b55b3d958f218c00aa9ae14a68c7b00f80b523e4 Mon Sep 17 00:00:00 2001 From: kernel <77142078+kernelwernel@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:48:29 +0100 Subject: [PATCH 5/6] final fix (i hope) --- src/vmaware.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vmaware.hpp b/src/vmaware.hpp index a92b767..e8c2096 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -9142,7 +9142,7 @@ struct VM { const char* command = "wmic path win32_videocontroller get videoprocessor"; auto ptr = util::sys_result(command); - const std::string result = *ptr; + std::string result = *ptr; std::transform(result.begin(), result.end(), result.begin(), ::tolower); From c49aa8c702d1de07c0cfe976701fbbe351d06894 Mon Sep 17 00:00:00 2001 From: kernel <77142078+kernelwernel@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:55:48 +0100 Subject: [PATCH 6/6] revert back to initial code --- src/vmaware.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/vmaware.hpp b/src/vmaware.hpp index e8c2096..8824374 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -9139,10 +9139,21 @@ struct VM { #if (!MSVC) return false; #else - const char* command = "wmic path win32_videocontroller get videoprocessor"; - auto ptr = util::sys_result(command); - - std::string result = *ptr; + std::string command = "wmic path win32_videocontroller get videoprocessor"; + std::string result = ""; + + FILE* pipe = _popen(command.c_str(), "r"); + if (!pipe) { + debug("GPU_CHIPTYPE: failed to run wmic command"); + return false; + } + + char buffer[128]; + while (!feof(pipe)) { + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + _pclose(pipe); std::transform(result.begin(), result.end(), result.begin(), ::tolower);