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