Skip to content

sync dev #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
The library is:
- Very easy to use
- Cross-platform (Windows + MacOS + Linux)
- Features up to 115+ unique VM detection techniques [[list](https://github.com/kernelwernel/VMAware/blob/main/docs/documentation.md#flag-table)]
- Features up to 115 unique VM detection techniques [[list](https://github.com/kernelwernel/VMAware/blob/main/docs/documentation.md#flag-table)]
- Features the most cutting-edge techniques
- Able to detect 65+ VM brands including VMware, VirtualBox, QEMU, Hyper-V, and much more [[list](https://github.com/kernelwernel/VMAware/blob/main/docs/documentation.md#brand-table)]
- Able to beat VM hardeners
Expand Down Expand Up @@ -238,7 +238,7 @@ You can view the full docs [here](docs/documentation.md). All the details such a

> I would've made it strictly MIT so proprietary software can make use of the library, but some of the techniques employed are from GPL projects, and I have no choice but to use the same license for legal reasons.
>
> This gave me an idea to make an MIT version without all of the GPL code so it can also be used without forcing your code to be open source. It should be noted that the MIT version removes <b>7</b> techniques out of 116 (as of 2.0 version), and the lesser the number of techniques, the less accurate the overall result might be.
> This gave me an idea to make an MIT version without all of the GPL code so it can also be used without forcing your code to be open source. It should be noted that the MIT version removes <b>7</b> techniques out of 115 (as of 2.0 version), and the lesser the number of techniques, the less accurate the overall result might be.

</details>

Expand Down
81 changes: 57 additions & 24 deletions auxiliary/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* ===============================================================
*
* Benchmark Utility: Measures performance of VM detection primitives
* VMAwareBenchmark Utility: Measures performance of VM detection primitives
* with cross-platform nanosecond precision timing and adaptive unit
* formatting. Supports Windows, Linux, and macOS.
*
Expand All @@ -20,7 +20,7 @@
* - License: GPL 3.0
*/

#include "../src/vmaware.hpp"
#include "vmaware.hpp"
#include <iostream>
#include <string>
#include <cmath>
Expand All @@ -33,7 +33,7 @@
#include <mach/mach_time.h>
#endif

class Benchmark {
class VMAwareBenchmark {
public:
static uint64_t get_timestamp() {
#if defined(_WIN32)
Expand Down Expand Up @@ -82,40 +82,73 @@ int main(void) {
std::string vm_brand, vm_type;
uint8_t vm_percent;

// Benchmark VM::detect()
start = Benchmark::get_timestamp();
/* ================================================ NO MEMOIZATION CATEGORY ================================================ */

// VMAwareBenchmark VM::detect(VM::NO_MEMO)
start = VMAwareBenchmark::get_timestamp();
is_detected = VM::detect(VM::NO_MEMO);
end = VMAwareBenchmark::get_timestamp();
const double detect_time_no_memo = VMAwareBenchmark::get_elapsed(start, end);

// VMAwareBenchmark VM::brand()
start = VMAwareBenchmark::get_timestamp();
vm_brand = VM::brand(VM::NO_MEMO);
end = VMAwareBenchmark::get_timestamp();
const double brand_time_no_memo = VMAwareBenchmark::get_elapsed(start, end);

// VMAwareBenchmark VM::type()
start = VMAwareBenchmark::get_timestamp();
vm_type = VM::type(VM::NO_MEMO);
end = VMAwareBenchmark::get_timestamp();
const double type_time_no_memo = VMAwareBenchmark::get_elapsed(start, end);

// VMAwareBenchmark VM::percentage()
start = VMAwareBenchmark::get_timestamp();
vm_percent = VM::percentage(VM::NO_MEMO);
end = VMAwareBenchmark::get_timestamp();
const double percent_time_no_memo = VMAwareBenchmark::get_elapsed(start, end);

/* ================================================ DEFAULT CATEGORY ================================================ */

// VMAwareBenchmark VM::detect()
start = VMAwareBenchmark::get_timestamp();
is_detected = VM::detect();
end = Benchmark::get_timestamp();
const double detect_time = Benchmark::get_elapsed(start, end);
end = VMAwareBenchmark::get_timestamp();
const double detect_time = VMAwareBenchmark::get_elapsed(start, end);

// Benchmark VM::brand()
start = Benchmark::get_timestamp();
// VMAwareBenchmark VM::brand()
start = VMAwareBenchmark::get_timestamp();
vm_brand = VM::brand();
end = Benchmark::get_timestamp();
const double brand_time = Benchmark::get_elapsed(start, end);
end = VMAwareBenchmark::get_timestamp();
const double brand_time = VMAwareBenchmark::get_elapsed(start, end);

// Benchmark VM::type()
start = Benchmark::get_timestamp();
// VMAwareBenchmark VM::type()
start = VMAwareBenchmark::get_timestamp();
vm_type = VM::type();
end = Benchmark::get_timestamp();
const double type_time = Benchmark::get_elapsed(start, end);
end = VMAwareBenchmark::get_timestamp();
const double type_time = VMAwareBenchmark::get_elapsed(start, end);

// Benchmark VM::percentage()
start = Benchmark::get_timestamp();
// VMAwareBenchmark VM::percentage()
start = VMAwareBenchmark::get_timestamp();
vm_percent = VM::percentage();
end = Benchmark::get_timestamp();
const double percent_time = Benchmark::get_elapsed(start, end);
end = VMAwareBenchmark::get_timestamp();
const double percent_time = VMAwareBenchmark::get_elapsed(start, end);

// Program output
std::cout << (is_detected ? "Virtual machine detected!\n" : "Running on baremetal\n")
<< "VM name: " << vm_brand << "\n"
<< "VM type: " << vm_type << "\n"
<< "VM certainty: " << static_cast<int>(vm_percent) << "%\n\n"
<< "Benchmark Results:\n"
<< "VM::detect(): " << Benchmark::format_duration(detect_time) << "\n"
<< "VM::brand(): " << Benchmark::format_duration(brand_time) << "\n"
<< "VM::type(): " << Benchmark::format_duration(type_time) << "\n"
<< "VM::percentage(): " << Benchmark::format_duration(percent_time) << "\n";
<< "Benchmark Results (Default):\n"
<< "VM::detect(): " << VMAwareBenchmark::format_duration(detect_time) << "\n"
<< "VM::brand(): " << VMAwareBenchmark::format_duration(brand_time) << "\n"
<< "VM::type(): " << VMAwareBenchmark::format_duration(type_time) << "\n"
<< "VM::percentage(): " << VMAwareBenchmark::format_duration(percent_time) << "\n\n"
<< "Benchmark Results (not cached):\n"
<< "VM::detect(VM::NO_MEMO): " << VMAwareBenchmark::format_duration(detect_time_no_memo) << "\n"
<< "VM::brand(VM::NO_MEMO): " << VMAwareBenchmark::format_duration(brand_time_no_memo) << "\n"
<< "VM::type(VM::NO_MEMO): " << VMAwareBenchmark::format_duration(type_time_no_memo) << "\n"
<< "VM::percentage(VM::NO_MEMO): " << VMAwareBenchmark::format_duration(percent_time_no_memo) << "\n\n";

return 0;
}
1 change: 0 additions & 1 deletion docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ VMAware provides a convenient way to not only check for VMs, but also have the f
| `VM::DEVICE_STRING` | Check if bogus device string would be accepted | Windows | 25% | | | | |
| `VM::BLUESTACKS_FOLDERS` | Check for the presence of BlueStacks-specific folders | Linux | 5% | | | | |
| `VM::CPUID_SIGNATURE` | Check for signatures in leaf 0x40000001 in CPUID | | 95% | | | | |
| `VM::HYPERV_BITMASK` | Check for Hyper-V CPUID bitmask range for reserved values | | 20% | | | | |
| `VM::KVM_BITMASK` | Check for KVM CPUID bitmask range for reserved values | | 40% | | | | |
| `VM::KGT_SIGNATURE` | Check for Intel KGT (Trusty branch) hypervisor signature in CPUID | | 80% | | | | |
| `VM::QEMU_VIRTUAL_DMI` | Check for presence of QEMU in the /sys/devices/virtual/dmi/id directory | Linux | 40% | | | | |
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
|------|---------|
| `cli.cpp` | Entire CLI tool code |
| `vmaware.hpp` | Official and original library header in GPL-3.0, most likely what you're looking for. |
| `vmaware_MIT.hpp` | Same as above but in MIT. But this removes 7 techniques out of 116 |
| `vmaware_MIT.hpp` | Same as above but in MIT. But this removes 7 techniques out of 115 |


> [!IMPORTANT]
Expand Down
6 changes: 1 addition & 5 deletions src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ bool is_unsupported(VM::enum_flags flag) {
case VM::GENERAL_HOSTNAME:
case VM::BLUESTACKS_FOLDERS:
case VM::CPUID_SIGNATURE:
case VM::HYPERV_BITMASK:
case VM::KVM_BITMASK:
case VM::KGT_SIGNATURE:
case VM::QEMU_VIRTUAL_DMI:
Expand Down Expand Up @@ -447,7 +446,6 @@ bool is_unsupported(VM::enum_flags flag) {
case VM::SCREEN_RESOLUTION:
case VM::DEVICE_STRING:
case VM::CPUID_SIGNATURE:
case VM::HYPERV_BITMASK:
case VM::KVM_BITMASK:
case VM::KGT_SIGNATURE:
case VM::DRIVER_NAMES:
Expand Down Expand Up @@ -498,7 +496,6 @@ bool is_unsupported(VM::enum_flags flag) {
case VM::XEON_THREAD_MISMATCH:
case VM::CPUID_BITSET:
case VM::CPUID_SIGNATURE:
case VM::HYPERV_BITMASK:
case VM::KVM_BITMASK:
case VM::KGT_SIGNATURE:
case VM::AMD_SEV:
Expand Down Expand Up @@ -949,7 +946,6 @@ void general() {
checker(VM::DEVICE_STRING, "bogus device string");
checker(VM::BLUESTACKS_FOLDERS, "BlueStacks folders");
checker(VM::CPUID_SIGNATURE, "CPUID signatures");
checker(VM::HYPERV_BITMASK, "Hyper-V CPUID reserved bitmask");
checker(VM::KVM_BITMASK, "KVM CPUID reserved bitmask");
checker(VM::KGT_SIGNATURE, "Intel KGT signature");
checker(VM::QEMU_VIRTUAL_DMI, "QEMU virtual DMI directory");
Expand Down Expand Up @@ -1138,7 +1134,7 @@ void general() {
if (char_count <= 60) {
continue;
} else {
if ((char_count - 1) >= (max_line_length + 3)) {
if ((char_count - 1) >= (static_cast<unsigned long long>(max_line_length) + 3)) {
it = divided_description.insert(it + 1, "\n");
char_count = it->length() + 1;
} else {
Expand Down
Loading