Skip to content

Commit 3b91815

Browse files
authored
Merge pull request #92 from kernelwernel/dev
Dev
2 parents 15f3027 + 651fcfa commit 3b91815

13 files changed

+999
-694
lines changed

.github/workflows/build_run_win_32.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ cmake -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 17 2022" -A Win32 -S ..
66
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.com" "VMAware.sln" /Build "Release|Win32" /Project "vmaware" /ProjectConfig "Release|Win32"
77
cd Release
88
vmaware.exe
9+
vmaware.exe --discard-hyper-v

.github/workflows/build_run_win_64.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ cmake -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 17 2022" -A x64 -S ..
66
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.com" "VMAware.sln" /Build "Release|x64" /Project "vmaware" /ProjectConfig "Release|x64"
77
cd Release
88
vmaware.exe
9+
vmaware.exe --discard-hyper-v

.github/workflows/cmake-multi-platform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ jobs:
7272
working-directory: ${{ steps.strings.outputs.build-output-dir }}
7373
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
7474
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
75-
run: ctest --build-config --rerun-failed --output-on-failure ${{ matrix.build_type }}
75+
run: ctest --build-config --rerun-failed --verbose --output-on-failure ${{ matrix.build_type }}

CMakeLists.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ project(
77
)
88

99

10+
# set c++ standard
11+
if(NOT DEFINED CMAKE_CXX_STANDARD)
12+
set(CMAKE_CXX_STANDARD 20)
13+
endif()
14+
15+
1016
# compiler flags
11-
set(CMAKE_CXX_STANDARD 20)
1217
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1318
set(CMAKE_CXX_EXTENSIONS OFF)
1419

1520
if (MSVC)
16-
set(CMAKE_CXX_FLAGS "/Wall /W4 /std:c++20 /EHsc")
21+
set(CMAKE_CXX_FLAGS "/Wall /W4 /EHsc")
1722
else()
18-
set(CMAKE_CXX_FLAGS "-Wextra -Wall -Wextra -Wconversion -Wdouble-promotion -Wno-unused-parameter -Wno-unused-function -Wno-sign-conversion -fmax-errors=20")
23+
set(CMAKE_CXX_FLAGS "-Wextra -Wall -Wextra -Wconversion -Wdouble-promotion -Wno-unused-parameter -Wno-unused-function -Wno-sign-conversion")
1924
endif()
2025

2126
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
2227
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -lstdc++ -lm")
23-
else()
24-
message("Unsupported compiler")
2528
endif()
2629

2730

@@ -61,7 +64,7 @@ if (MSVC)
6164
elseif(LINUX)
6265
if(CMAKE_BUILD_TYPE MATCHES "Debug")
6366
MESSAGE(STATUS "Build set to debug mode")
64-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DDEBUG -O0 -fsanitize=address")
67+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fmax-errors=20 -DDEBUG -O0 -fsanitize=address")
6568
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
6669
MESSAGE(STATUS "Build set to release mode")
6770
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
@@ -77,7 +80,9 @@ endif()
7780
# add executable
7881
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}")
7982
add_executable(${TARGET} "src/cli.cpp")
80-
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 20)
83+
if(NOT DEFINED CMAKE_CXX_STANDARD)
84+
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 20)
85+
endif()
8186
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD_REQUIRED ON)
8287

8388

@@ -91,13 +96,6 @@ else()
9196
add_test(executable, "${BUILD_DIR}/${TARGET}")
9297
endif()
9398

94-
#if(NOT MSVC)
95-
#add_test(
96-
# checks
97-
# ${Python_EXECUTABLE} "${CMAKE_SOURCE_DIR}/cmake/ctest_checks.py"
98-
#)
99-
#endif()
100-
10199

102100
# release stuff
103101
if (NOT MSVC)

auxiliary/arg_checks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#
1111
# =============================================================
1212
#
13-
# This is just an internal script for CI/CD. The main goal is to
14-
# check whether all of the techniques are actually updated since
15-
# keeping track of the docs, the cli, and the table isn't easy,
16-
# so I'm automating the checks in case I forget to update any.
13+
# This is just an internal script for CI/CD. The main goal is to
14+
# check whether all of the techniques are actually updated since
15+
# keeping track of the docs, the cli, and the table isn't easy,
16+
# so I'm automating the checks in case I forget to update any.
1717
#
1818
# ===============================================================
1919
#

auxiliary/cpuid_fuzzer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*
1111
* ===============================================================
1212
*
13-
* This program serves as an internal tool for fuzzing cpuid values
14-
* and comparing them between baremetal outputs and VM outputs.
13+
* This program serves as an internal tool for fuzzing cpuid values
14+
* and comparing them between baremetal outputs and VM outputs.
1515
*
1616
* ===============================================================
1717
*

auxiliary/test_standards.sh

100644100755
Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,47 @@
1010
#
1111
# ===============================================================
1212
#
13-
# This script is designed to test different C++ standards to see
14-
# if there are any edgecases before releasing it
13+
# This script is designed to test different C++ standards to see
14+
# if there are any edgecases before releasing it
1515
#
1616
# ===============================================================
1717
#
1818
# - Made by: @kernelwernel (https://github.com/kernelwernel)
1919
# - Repository: https://github.com/kernelwernel/VMAware
2020
# - License: GPL 3.0
2121

22+
clear
2223

24+
current_dir=$(pwd)
25+
rm -rf build/
26+
mkdir build/ 2>/dev/null
27+
cd build/
28+
29+
standards=("11" "14" "17" "20" "23")
30+
31+
for version in "${standards[@]}"; do
32+
echo "[LOG] Running cmake with $version standard"
33+
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=$version ../..
34+
35+
echo "[LOG] make"
36+
make
37+
make_status=$?
38+
39+
if [ $make_status -ne 0 ]; then
40+
exit
41+
fi
42+
43+
cp ../../build/vmaware .
44+
45+
echo "[LOG] ./vmaware"
46+
./vmaware 2>&1
47+
vmaware_status=$?
48+
49+
if [ $vmaware_status -ne 0 ]; then
50+
exit
51+
fi
52+
done
53+
54+
cd $(current_dir)
55+
56+
rm -rf build

auxiliary/updater.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#
1111
# ===============================================================
1212
#
13-
# This is an internal script to update the VMAware
14-
# header file's banner automatically and much more reliably.
15-
# For example, it'll update the line numbers for the sections
16-
# header, and other basic information.
13+
# This is an internal script to update the VMAware
14+
# header file's banner automatically and much more reliably.
15+
# For example, it'll update the line numbers for the sections
16+
# header, and other basic information.
1717
#
1818
# ===============================================================
1919
#

auxiliary/vmtest.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1+
/**
2+
* ██╗ ██╗███╗ ███╗ █████╗ ██╗ ██╗ █████╗ ██████╗ ███████╗
3+
* ██║ ██║████╗ ████║██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝
4+
* ██║ ██║██╔████╔██║███████║██║ █╗ ██║███████║██████╔╝█████╗
5+
* ╚██╗ ██╔╝██║╚██╔╝██║██╔══██║██║███╗██║██╔══██║██╔══██╗██╔══╝
6+
* ╚████╔╝ ██║ ╚═╝ ██║██║ ██║╚███╔███╔╝██║ ██║██║ ██║███████╗
7+
* ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
8+
*
9+
* C++ VM detection library
10+
*
11+
* ===============================================================
12+
*
13+
* This program serves as a testing ground, it's not interesting tbh
14+
* so I recommend you move on
15+
*
16+
* ===============================================================
17+
*
18+
* - Made by: @kernelwernel (https://github.com/kernelwernel)
19+
* - Repository: https://github.com/kernelwernel/VMAware
20+
* - License: GPL 3.0
21+
*/
22+
123
#include "../src/vmaware.hpp"
224
#include <iostream>
325

426
int main(void) {
5-
std::cout << VM::detect() << "\n";
27+
const bool test1 = VM::detect();
28+
const bool test2 = VM::detect(VM::ALL);
29+
const bool test3 = VM::detect(VM::DEFAULT);
30+
const bool test4 = VM::detect(VM::DEFAULT, VM::ALL);
31+
const bool test5 = VM::detect(VM::DEFAULT, VM::DISABLE(VM::RDTSC));
32+
const bool test6 = VM::detect(VM::DEFAULT, VM::DISABLE(VM::RDTSC), VM::EXTREME);
33+
const bool test7 = VM::detect(VM::NO_MEMO, VM::EXTREME, VM::MULTIPLE, VM::DISCARD_HYPERV_DEFAULT);
634
return 0;
735
}

docs/documentation.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main() {
3333
* a single technique, use VM::check() instead. Also, read the flag table
3434
* at the end of this doc file for a full list of technique flags.
3535
*/
36-
bool is_vm2 = VM::detect(VM::BRAND, VM::MAC, VM::HYPERV_BIT);
36+
bool is_vm2 = VM::detect(VM::BRAND, VM::MAC, VM::HYPERVISOR_BIT);
3737

3838

3939
/**
@@ -66,10 +66,18 @@ int main() {
6666

6767

6868
/**
69+
* If you want to disable any techniques for whatever reason, use VM::DISABLE().
6970
* This will essentially mean "perform all the default flags, but only disable
7071
* the VM::RDTSC technique".
7172
*/
72-
bool is_vm6 = VM::detect(VM::DEFAULT & ~(VM::RDTSC));
73+
bool is_vm6 = VM::detect(VM::DISABLE(VM::RDTSC));
74+
75+
76+
/**
77+
* Same as above, but you can disable multiple techniques at the same time.
78+
*/
79+
bool is_vm6 = VM::detect(VM::DISABLE(VM::VMID, VM::RDTSC));
80+
7381
}
7482
```
7583

@@ -158,7 +166,7 @@ int main() {
158166
## `VM::check()`
159167
This takes a single flag argument and returns a `bool`. It's essentially the same as `VM::detect()` but it doesn't have a scoring system. It only returns the technique's effective output. The reason why this exists is because it allows end-users to have fine-grained control over what is being executed and what isn't.
160168

161-
`VM::detect()` is meant for a range of techniques to be evaluated in the bigger picture with weights and biases in its scoring system, while `VM::check()` is meant for a single technique to be evaluated without any points or anything extra. It just gives you what the technique has found on its own. For example:
169+
`VM::detect()` is meant for a range of techniques to be evaluated in the bigger picture with weights and biases in its scoring system, while `VM::check()` is meant for a single technique to be evaluated without any points or anything extra. It very simply just gives you what the technique has found on its own. For example:
162170

163171
```cpp
164172
#include "vmaware.hpp"
@@ -172,9 +180,6 @@ int main() {
172180
if (VM::check(VM::HYPERVISOR_BIT)) {
173181
std::cout << "Hypervisor bit is set, most definitely a VM!\n";
174182
}
175-
176-
// invalid, will throw an std::invalid_argument exception
177-
bool result = VM::check(VM::VMID | VM::HYPERVISOR_BIT);
178183
}
179184
```
180185

@@ -353,5 +358,5 @@ VMAware provides a convenient way to not only check for VMs, but also have the f
353358
| `VM::NO_MEMO` | This will disable memoization, meaning the result will not be fetched through a previous computation of the `VM::detect()` function. Use this if you're only using a single function from the `VM` struct for a performance boost. |
354359
| `VM::EXTREME` | This will disregard the weights/biases and its scoring system. It will essentially treat any technique that found a hit as a VM detection no matter how low that technique's certainty is, so if a single technique is positive then it will return true. |
355360
| `VM::DEFAULT` | This represents a range of flags which are enabled if no default argument is provided. The reason why this exists is to easily disable any bits manually (shown in the is_vm6 example in the `VM::detect()` section)
356-
| `VM::WIN_HYPERV_DEFAULT` | Windows 11 (and sometimes 10) may have Hyper-V as a default virtualisation software for any program even if the OS is running as host, which is one of the main hurdles of the library to overcome between host virtualisation and actual virtualisation. The library will discard any Hyper-V brand suspicions as not running in a VM. This flag will basically mean "I'm aware this program might be running in a default virtualised environment even if the user is only using the host environment, but I'll still count this as running in a VM anyway whether it's default virtualisation or manual virtualisation" |
361+
| `VM::DISCARD_HYPERV_DEFAULT` | Windows 11 (and sometimes 10) may have Hyper-V as a default virtualisation software for any program even if the OS is running as host, which is one of the main hurdles of the library to overcome between host virtualisation and actual virtualisation. The library will discard any Hyper-V brand suspicions as not running in a VM. This flag will basically mean "I'm aware this program might be running in a default virtualised environment even if the user is only using the host environment, but I'll still count this as running in a VM anyway whether it's default virtualisation or manually intended virtualisation" |
357362
| `VM::MULTIPLE` | This is specific to `VM::brand()`. This will basically return a `std::string` message of what brands could be involved. For example, it could return "`VMware or VirtualBox`" instead of having a single brand string output. |

0 commit comments

Comments
 (0)