Skip to content

Commit 1239cfb

Browse files
committed
split GPU techniques and made points post-processor
1 parent 9221fec commit 1239cfb

File tree

4 files changed

+106
-28
lines changed

4 files changed

+106
-28
lines changed

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ if (NOT MSVC)
119119
install(TARGETS ${TARGET} DESTINATION ${CMAKE_SOURCE_DIR})
120120
endif()
121121
elseif(MSVC)
122-
set(CMAKE_INSTALL_PREFIX "C:\\Program Files\\YourApplication")
123-
install(TARGETS ${TARGET} RUNTIME DESTINATION "bin")
124-
125-
set(HEADER_INSTALL_PATH "C:\\Program Files (x86)\\YourLibrary\\include")
126-
install(FILES "src/vmaware.hpp" DESTINATION "${HEADER_INSTALL_PATH}")
127-
install(FILES "src/vmaware_MIT.hpp" DESTINATION "${HEADER_INSTALL_PATH}")
122+
set(CMAKE_INSTALL_PREFIX "C:\\Program Files\\YourApplication")
123+
install(TARGETS ${TARGET} RUNTIME DESTINATION "bin")
124+
125+
set(HEADER_INSTALL_PATH "C:\\Program Files (x86)\\YourLibrary\\include")
126+
install(FILES "src/vmaware.hpp" DESTINATION "${HEADER_INSTALL_PATH}")
127+
install(FILES "src/vmaware_MIT.hpp" DESTINATION "${HEADER_INSTALL_PATH}")
128128
endif()

docs/documentation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ VMAware provides a convenient way to not only check for VMs, but also have the f
510510
| `VM::VM_SIDT` | Check for unknown IDT base address | Windows | 100% | | | | |
511511
| `VM::HDD_SERIAL` | Check for serial numbers of virtual disks | Windows | 100% | | | | |
512512
| `VM::PORT_CONNECTORS` | Check for physical connection ports | Windows | 25% | | | | This technique is known to false flag on devices like Surface Pro |
513-
| `VM::GPU` | Check for GPU capabilities and specific GPU signatures related to VMs | Windows | 100% | Admin | | | Admin only needed for some heuristics |
513+
| `VM::GPU_CAPABILITIES` | Check for GPU capabilities related to VMs | Windows | 100% | Admin | | | Admin only needed for some heuristics |
514+
| `VM::GPU_VM_STRINGS` | Check for specific GPU string signatures related to VMs | Windows | 100% | | | | |
514515
| `VM::VM_DEVICES` | Check for VM-specific devices | Windows | 45% | | | | |
515516
| `VM::IDT_GDT_MISMATCH` | Check if the IDT and GDT base virtual addresses mismatch between different CPU cores when called from usermode under a root partition | Windows | 50% | | | | |
516517
| `VM::PROCESSOR_NUMBER` | Check for number of processors | Windows | 50% | | | | |

src/cli.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ bool is_unsupported(VM::enum_flags flag) {
453453
case VM::VM_SIDT:
454454
case VM::HDD_SERIAL:
455455
case VM::PORT_CONNECTORS:
456-
case VM::GPU:
456+
case VM::GPU_VM_STRINGS:
457+
case VM::GPU_CAPABILITIES:
457458
case VM::IDT_GDT_MISMATCH:
458459
case VM::PROCESSOR_NUMBER:
459460
case VM::NUMBER_OF_CORES:
@@ -973,7 +974,8 @@ void general() {
973974
checker(VM::VM_SIDT, "VM SIDT");
974975
checker(VM::HDD_SERIAL, "HDD serial number");
975976
checker(VM::PORT_CONNECTORS, "physical connection ports");
976-
checker(VM::GPU, "GPU capabilities");
977+
checker(VM::GPU_CAPABILITIES, "GPU capabilities");
978+
checker(VM::GPU_VM_STRINGS, "GPU strings");
977979
checker(VM::IDT_GDT_MISMATCH, "IDT GDT mismatch");
978980
checker(VM::PROCESSOR_NUMBER, "processor count");
979981
checker(VM::NUMBER_OF_CORES, "CPU core count");

src/vmaware.hpp

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@
183183

184184
#pragma once
185185

186-
#define __VMAWARE_DEBUG__ 1
187-
188186
#if defined(_WIN32) || defined(_WIN64)
189187
#define WINDOWS 1
190188
#define LINUX 0
@@ -641,7 +639,8 @@ struct VM {
641639
VM_SIDT,
642640
HDD_SERIAL,
643641
PORT_CONNECTORS,
644-
GPU,
642+
GPU_VM_STRINGS,
643+
GPU_CAPABILITIES,
645644
VM_DEVICES,
646645
IDT_GDT_MISMATCH,
647646
PROCESSOR_NUMBER,
@@ -7789,13 +7788,13 @@ struct VM {
77897788

77907789

77917790
/**
7792-
* @brief Check for GPU capabilities and specific GPU signatures related to VMs
7791+
* @brief Check for specific GPU string signatures related to VMs
77937792
* @category Windows
77947793
* @author Requiem (https://github.com/NotRequiem)
77957794
* @note utoshu did this with WMI in a removed technique (VM::GPU_CHIPTYPE)
7796-
* @implements VM::GPU
7795+
* @implements VM::GPU_VM_STRING
77977796
*/
7798-
[[nodiscard]] static bool vm_gpu() {
7797+
[[nodiscard]] static bool gpu_vm_strings() {
77997798
#if (!WINDOWS)
78007799
return false;
78017800
#else
@@ -7834,9 +7833,11 @@ struct VM {
78347833

78357834

78367835
if (deviceStrLen == len && wcscmp(deviceStr, name) == 0) {
7836+
#if __VMAWARE_DEBUG__
78377837
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
78387838
std::string narrow_str = converter.to_bytes(name);
7839-
std::cout << "[TEMPORARY FUCKING DEBUG REPLACEMENT SHIT] found" << narrow_str << "\n";
7839+
debug("VM::GPU: found \"", narrow_str, "\" string in GPU");
7840+
#endif
78407841
core::add(brand);
78417842
return true;
78427843
}
@@ -7845,8 +7846,23 @@ struct VM {
78457846
++deviceNum;
78467847
}
78477848

7848-
if (!util::is_admin())
7849+
return false;
7850+
#endif
7851+
}
7852+
7853+
/**
7854+
* @brief Check for GPU capabilities related to VMs
7855+
* @category Windows
7856+
* @author Requiem (https://github.com/NotRequiem)
7857+
* @implements VM::GPU_CAPABILITIES
7858+
*/
7859+
[[nodiscard]] static bool gpu_capabilities() {
7860+
#if (!WINDOWS)
7861+
return false;
7862+
#else
7863+
if (!util::is_admin()) {
78497864
return false;
7865+
}
78507866

78517867
IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
78527868
if (!pD3D) return true;
@@ -7863,10 +7879,12 @@ struct VM {
78637879
return core::add(brands::VBOX);
78647880
}
78657881
}
7882+
78667883
if (FAILED(pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps))) {
78677884
pD3D->Release();
78687885
return true;
78697886
}
7887+
78707888
pD3D->Release();
78717889

78727890
IDXGIFactory* pFactory = nullptr;
@@ -10241,6 +10259,17 @@ struct VM {
1024110259
continue;
1024210260
}
1024310261

10262+
// both of these depend interchangeably, so both scores
10263+
// are "merged" by making it 100 instead of 200 combined.
10264+
// the GPU ones are that exception, and they will be run
10265+
// in the post-processing stage within run_all();
10266+
if (
10267+
(technique_macro == VM::GPU_CAPABILITIES) ||
10268+
(technique_macro == VM::GPU_VM_STRINGS)
10269+
) {
10270+
continue;
10271+
}
10272+
1024410273
// check if the technique is cached already
1024510274
if (memo_enabled && memo::is_cached(technique_macro)) {
1024610275
const memo::data_t data = memo::cache_fetch(technique_macro);
@@ -10263,26 +10292,28 @@ struct VM {
1026310292
// returns the number of techniques that found a VM.
1026410293
detected_count_num++;
1026510294
}
10266-
10295+
10296+
// store the current technique result to the cache
10297+
if (memo_enabled) {
10298+
memo::cache_store(technique_macro, result, technique_data.points);
10299+
}
10300+
1026710301
// for things like VM::detect() and VM::percentage(),
1026810302
// a score of 150+ is guaranteed to be a VM, so
1026910303
// there's no point in running the rest of the techniques
1027010304
// (unless the threshold is set to be higher, but it's the
1027110305
// same story here nonetheless, except the threshold is 300)
10272-
if (shortcut && points >= threshold_points) {
10306+
if (
10307+
(shortcut) &&
10308+
(points >= threshold_points)
10309+
) {
1027310310
return points;
1027410311
}
10275-
10276-
// store the current technique result to the cache
10277-
if (memo_enabled) {
10278-
memo::cache_store(technique_macro, result, technique_data.points);
10279-
}
1028010312
}
1028110313

1028210314
// for custom VM techniques, won't be used most of the time
1028310315
if (!custom_table.empty()) {
1028410316
for (const auto& technique : custom_table) {
10285-
1028610317
// if cached, return that result
1028710318
if (memo_enabled && memo::is_cached(technique.id)) {
1028810319
const memo::data_t data = memo::cache_fetch(technique.id);
@@ -10314,6 +10345,49 @@ struct VM {
1031410345
}
1031510346
}
1031610347

10348+
10349+
// points post-processing stage
10350+
const std::vector<enum_flags> post_processed_techniques = {
10351+
GPU_CAPABILITIES,
10352+
GPU_VM_STRINGS
10353+
};
10354+
10355+
auto merge_scores = [&](
10356+
const enum_flags a,
10357+
const enum_flags b,
10358+
const u8 new_score
10359+
) {
10360+
if (
10361+
core::is_disabled(flags, a) ||
10362+
core::is_disabled(flags, b)
10363+
) {
10364+
return;
10365+
}
10366+
10367+
const bool result_a = check(a);
10368+
const bool result_b = check(b);
10369+
10370+
if (result_a && result_b) {
10371+
points += new_score;
10372+
return;
10373+
} else if ((result_a == false) && (result_b == false)) {
10374+
return;
10375+
} else {
10376+
enum_flags tmp_flag;
10377+
10378+
if (result_a == true) {
10379+
tmp_flag = a;
10380+
} else {
10381+
tmp_flag = b;
10382+
}
10383+
10384+
const technique tmp = technique_table.at(tmp_flag);
10385+
points += tmp.points;
10386+
}
10387+
};
10388+
10389+
merge_scores(GPU_CAPABILITIES, GPU_VM_STRINGS, 100); // instead of 200, it's 100 now
10390+
1031710391
return points;
1031810392
}
1031910393

@@ -10393,7 +10467,6 @@ struct VM {
1039310467

1039410468
// disable all non-default techniques
1039510469
flags.flip(VMWARE_DMESG);
10396-
flags.flip(GPU); // temporary
1039710470

1039810471
// disable all the settings flags
1039910472
flags.flip(NO_MEMO);
@@ -11287,7 +11360,8 @@ struct VM {
1128711360
case VM_SIDT: return "VM_SIDT";
1128811361
case HDD_SERIAL: return "HDD_SERIAL";
1128911362
case PORT_CONNECTORS: return "PORT_CONNECTORS";
11290-
case GPU: return "GPU";
11363+
case GPU_VM_STRINGS: return "GPU_STRINGS";
11364+
case GPU_CAPABILITIES: return "GPU_CAPABILITIES";
1129111365
case VM_DEVICES: return "VM_DEVICES";
1129211366
case IDT_GDT_MISMATCH: return "IDT_GDT_MISMATCH";
1129311367
case PROCESSOR_NUMBER: return "PROCESSOR_NUMBER";
@@ -11851,7 +11925,8 @@ std::pair<VM::enum_flags, VM::core::technique> VM::core::technique_list[] = {
1185111925
{ VM::VM_SIDT, { 100, VM::vm_sidt } },
1185211926
{ VM::HDD_SERIAL, { 100, VM::hdd_serial_number } },
1185311927
{ VM::PORT_CONNECTORS, { 25, VM::port_connectors } },
11854-
{ VM::GPU, { 100, VM::vm_gpu } },
11928+
{ VM::GPU_VM_STRINGS, { 100, VM::gpu_vm_strings } },
11929+
{ VM::GPU_CAPABILITIES, { 100, VM::gpu_capabilities } },
1185511930
{ VM::VM_DEVICES, { 45, VM::vm_devices } },
1185611931
{ VM::IDT_GDT_MISMATCH, { 50, VM::idt_gdt_mismatch } },
1185711932
{ VM::PROCESSOR_NUMBER, { 50, VM::processor_number } },

0 commit comments

Comments
 (0)