Skip to content

Commit 458882f

Browse files
committed
pre-1.1 update
1 parent 0099c18 commit 458882f

7 files changed

Lines changed: 4291 additions & 35 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ endif()
6969

7070

7171
# add executable
72-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
72+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}")
7373
add_executable(${TARGET} "src/cli.cpp")
7474
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 20)
7575
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD_REQUIRED ON)
@@ -79,7 +79,7 @@ set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD_REQUIRED ON)
7979
include(CTest)
8080
#find_package(Python REQUIRED)
8181
enable_testing()
82-
add_test(executable, "${CMAKE_SOURCE_DIR}/bin/${TARGET}")
82+
add_test(executable, "${BUILD_DIR}/${TARGET}")
8383
#if(NOT MSVC)
8484
#add_test(
8585
# checks
@@ -91,7 +91,7 @@ add_test(executable, "${CMAKE_SOURCE_DIR}/bin/${TARGET}")
9191
# release stuff
9292
if (NOT MSVC)
9393
if(CMAKE_BUILD_TYPE MATCHES "Release")
94-
install(TARGETS ${TARGET} DESTINATION bin)
94+
install(TARGETS ${TARGET} DESTINATION ${CMAKE_SOURCE_DIR})
9595
install(FILES "src/vmaware.hpp" DESTINATION /usr/include)
9696
endif()
9797
elseif(MSVC)

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ The library is:
2121
- Able to guess the VM brand
2222
- Able to add your own custom VM detection techniques
2323
- Memoized, meaning past results are cached and retrieved if ran again for performance benefits
24-
- MIT and GPL-3.0 compliant code support
2524

2625
- - -
2726

@@ -52,17 +51,17 @@ int main() {
5251

5352
<br>
5453

55-
## Structure
54+
## Structure ⚙️
5655

5756
<p align="center">
58-
<img src="assets/vmaware.drawio.svg" align="center" width="500" title="VMAware">
57+
<img src="assets/vmaware.drawio.svg" align="center" title="VMAware">
5958
<br>
6059
</p>
6160

6261
<br>
6362

6463
## CLI tool 🔧
65-
This project also provides a tiny, but handy CLI tool utilising the full potential of what the library can do. Also, running the CLI as root would give better results.
64+
This project also provides a tiny, but handy CLI tool utilising the full potential of what the library can do. Also, running the CLI as root/admin would give better results.
6665

6766
<img src="assets/demo.png" width="500" title="cli">
6867

docs/documentation.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,44 @@ int main() {
178178
<br>
179179

180180
## `VM::add_custom()`
181-
This function allows you to add your own custom VM detection techniques to the system. The first parameter is the percentage score (0 to 100) of how likely it's a VM if your custom code returns `true`
181+
This function allows you to add your own custom VM detection techniques to the scoring system. The first parameter is the percentage score (0 to 100) of how likely it's a VM if your custom code returns `true`, and the second parameter should either be a lambda, a function pointer, or a `std::function<bool()>`
182+
182183
```cpp
183-
// Example 1 with std::function
184-
std::function<bool()> new_technique = []() -> bool {
185-
// add your VM detection code here
186-
return true;
187-
};
184+
// Example 1 with function pointers
185+
186+
bool new_technique() {
187+
// add your VM detection code here
188+
return true;
189+
}
188190

189-
VM::add_custom(1, new_technique);
191+
VM::add_custom(50, new_technique);
190192
```
191193
192194
```cpp
193-
// Example 2 with lambdas
194-
VM::add_custom(69, []() -> bool { return true; });
195+
// Example 2 with lambdas
195196
196-
auto new_technique = []() -> bool {
197-
// add your VM detection code here
198-
return true;
199-
}
197+
VM::add_custom(50, []() -> bool {
198+
// add your VM detection code here
199+
return true;
200+
});
201+
202+
auto new_technique = []() -> bool {
203+
// add your VM detection code here
204+
return true;
205+
}
206+
207+
VM::add_custom(50, new_technique);
208+
```
209+
210+
```cpp
211+
// Example 3 with std::function
212+
213+
std::function<bool()> new_technique = []() -> bool {
214+
// add your VM detection code here
215+
return true;
216+
};
200217

201-
VM::add_custom(69, new_technique);
218+
VM::add_custom(50, new_technique);
202219
```
203220
204221
<br>

papers/emul-detect.pdf

1.09 MB
Binary file not shown.

src/cli.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#endif
1414

1515
constexpr const char* ver = "1.1";
16-
constexpr const char* date = "January 2024";
16+
constexpr const char* date = "March 2024";
1717
constexpr const char* bold = "\033[1m";
1818
constexpr const char* ansi_exit = "\x1B[0m";
1919
constexpr const char* red = "\x1B[38;2;239;75;75m";
@@ -63,6 +63,7 @@ R"(Usage:
6363
Options:
6464
-h | --help prints this help menu
6565
-v | --version print version and other stuff
66+
-d | --detect returns the result as a boolean (1 = VM, 0 = baremetal)
6667
-s | --stdout returns either 0 or 1 to STDOUT without any text output (0 = VM, 1 = baremetal)
6768
-b | --brand returns the VM brand string (consult documentation for full output list)
6869
-p | --percent returns the VM percentage between 0 and 100
@@ -230,7 +231,7 @@ int main(int argc, char* argv[]) {
230231
conclusion_color = green_orange;
231232
conclusion_message = likely;
232233
} else if (percent < 100) {
233-
conclusion_color = green_orange;
234+
conclusion_color = green;
234235
conclusion_message = very_likely;
235236
} else if (percent == 100) {
236237
conclusion_color = green;
@@ -251,7 +252,7 @@ int main(int argc, char* argv[]) {
251252
const char* arg = args.at(1);
252253

253254
auto cmp = [](const char* a, const char* b) -> bool {
254-
return (strcmp(a, b) == 0);
255+
return (std::strcmp(a, b) == 0);
255256
};
256257

257258
if (cmp(arg, "-s") || cmp(arg, "--stdout")) {
@@ -268,6 +269,9 @@ int main(int argc, char* argv[]) {
268269
} else if (cmp(arg, "-p") || cmp(arg, "--percent")) {
269270
std::cout << VM::percentage() << "\n";
270271
return 0;
272+
} else if (cmp(arg, "-d") || cmp(arg, "--detect")) {
273+
std::cout << VM::detect() << "\n";
274+
return 0;
271275
} else {
272276
std::cerr << "Unknown argument provided, consult the help menu with --help\n";
273277
return 1;

src/vmaware.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* ██║ ██║██╔████╔██║███████║██║ █╗ ██║███████║██████╔╝█████╗
55
* ╚██╗ ██╔╝██║╚██╔╝██║██╔══██║██║███╗██║██╔══██║██╔══██╗██╔══╝
66
* ╚████╔╝ ██║ ╚═╝ ██║██║ ██║╚███╔███╔╝██║ ██║██║ ██║███████╗
7-
* ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ 1.1 version
7+
* ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ 1.1 (March 2024)
88
*
99
* A C++ VM detection library
1010
*
@@ -2375,7 +2375,7 @@ struct VM {
23752375
_T("C:\\windows\\System32\\VBoxControl.exe"),
23762376
_T("C:\\windows\\System32\\vboxoglerrorspu.dll"),
23772377
_T("C:\\windows\\System32\\vboxoglfeedbackspu.dll"),
2378-
} };
2378+
} };
23792379

23802380
for (const auto file : files) {
23812381
if (util::exists(file)) {
@@ -2634,7 +2634,6 @@ struct VM {
26342634

26352635
/**
26362636
* @brief Check VBox network provider string
2637-
* @todo fix WNetGetProviderName linker error
26382637
*/
26392638
[[nodiscard]] static bool vbox_network_share() try {
26402639
if (util::disabled(VBOX_NETWORK)) {
@@ -3147,9 +3146,9 @@ struct VM {
31473146

31483147

31493148
/**
3150-
* @brief check VM through alternative RDTSC technique with VMEXIT
3151-
* @category x86
3152-
*/
3149+
* @brief check VM through alternative RDTSC technique with VMEXIT
3150+
* @category x86
3151+
*/
31533152
[[nodiscard]] static bool rdtsc_vmexit() try {
31543153
if (util::disabled(RDTSC_VMEXIT)) {
31553154
return false;
@@ -4221,11 +4220,14 @@ struct VM {
42214220
}
42224221
}
42234222

4224-
if (!custom_table.empty()) {
4225-
for (const auto& pair : custom_table) {
4226-
if (pair.run()) {
4227-
points += pair.points;
4228-
}
4223+
if (custom_table.empty()) {
4224+
return points;
4225+
}
4226+
4227+
// for custom VM techniques
4228+
for (const auto& pair : custom_table) {
4229+
if (pair.run()) {
4230+
points += pair.points;
42294231
}
42304232
}
42314233

0 commit comments

Comments
 (0)