@@ -586,8 +586,8 @@ struct VM {
586586
587587 // get the CPU product
588588 [[nodiscard]] static std::string get_brand () {
589- if (memo::is_cpu_brand_cached ()) {
590- return memo::fetch_cpu_brand ();
589+ if (memo::cpu::is_brand_cached ()) {
590+ return memo::cpu::fetch_brand ();
591591 }
592592
593593 if (!core::cpuid_supported) {
@@ -624,7 +624,7 @@ struct VM {
624624
625625 debug (" BRAND: " , " cpu brand = " , brand);
626626
627- memo::store_cpu_brand (brand);
627+ memo::cpu::store_brand (brand);
628628
629629 return brand;
630630#endif
@@ -840,9 +840,6 @@ struct VM {
840840 private:
841841 static std::map<u8 , data_t > cache_table;
842842 static flagset cache_keys;
843- static std::string brand_cache;
844- static std::string multibrand_cache;
845- static std::string cpu_brand_cache;
846843
847844 public:
848845 static void cache_store (const u8 technique_macro, const result_t result, const points_t points) {
@@ -858,46 +855,58 @@ struct VM {
858855 return cache_table.at (technique_macro);
859856 }
860857
861- static std::string fetch_brand () {
862- return brand_cache;
858+ // basically checks whether all the techniques were cached
859+ static bool all_present () {
860+ return (cache_table.size () == technique_count);
863861 }
864862
865- static void store_brand (const std::string &p_brand) {
866- brand_cache = p_brand;
867- }
863+ struct brand {
864+ static std::string brand_cache;
868865
869- static bool is_brand_cached () {
870- return (! brand_cache. empty ()) ;
871- }
866+ static std::string fetch_brand () {
867+ return brand_cache;
868+ }
872869
873- static std::string fetch_multibrand ( ) {
874- return multibrand_cache ;
875- }
870+ static void store_brand ( const std::string &p_brand ) {
871+ brand_cache = p_brand ;
872+ }
876873
877- static void store_multibrand (const std::string &p_brand) {
878- multibrand_cache = p_brand;
879- }
874+ static bool is_brand_cached () {
875+ return (!brand_cache.empty ());
876+ }
877+ };
880878
881- static bool is_multibrand_cached () {
882- return (!multibrand_cache.empty ());
883- }
879+ struct multi {
880+ static std::string brand_cache;
881+
882+ static std::string fetch_brand () {
883+ return brand_cache;
884+ }
885+
886+ static void store_brand (const std::string &p_brand) {
887+ brand_cache = p_brand;
888+ }
889+
890+ static bool is_brand_cached () {
891+ return (!brand_cache.empty ());
892+ }
893+ };
884894
885- static std::string fetch_cpu_brand () {
886- return cpu_brand_cache;
887- }
895+ struct cpu {
896+ static std::string brand_cache;
888897
889- static void store_cpu_brand ( const std::string &p_brand ) {
890- cpu_brand_cache = p_brand ;
891- }
898+ static std::string fetch_brand ( ) {
899+ return brand_cache ;
900+ }
892901
893- static bool is_cpu_brand_cached ( ) {
894- return (!cpu_brand_cache. empty ()) ;
895- }
902+ static void store_brand ( const std::string &p_brand ) {
903+ brand_cache = p_brand ;
904+ }
896905
897- // basically checks whether all the techniques were cached
898- static bool all_present () {
899- return (cache_table. size () == technique_count);
900- }
906+ static bool is_brand_cached () {
907+ return (!brand_cache. empty ());
908+ }
909+ };
901910 };
902911
903912 // miscellaneous functionalities
@@ -6811,7 +6820,7 @@ struct VM {
68116820
68126821 static std::vector<technique> custom_table;
68136822
6814- static bool cpuid_supported; // cpuid check value
6823+ static bool cpuid_supported;
68156824
68166825 // VM scoreboard table specifically for VM::brand()
68176826 static std::map<const char *, brand_score_t > brand_scoreboard;
@@ -6941,8 +6950,8 @@ struct VM {
69416950 if (MSVC && core::disabled (p_flags, WIN_HYPERV_DEFAULT )) {
69426951 std::string tmp_brand;
69436952
6944- if (memo::is_brand_cached ()) {
6945- tmp_brand = memo::fetch_brand ();
6953+ if (memo::brand:: is_brand_cached ()) {
6954+ tmp_brand = memo::brand:: fetch_brand ();
69466955 } else {
69476956 tmp_brand = brand ();
69486957 }
@@ -7054,12 +7063,12 @@ struct VM {
70547063 }
70557064
70567065 if (is_multiple) {
7057- if (memo::is_multibrand_cached ()) {
7058- return memo::fetch_multibrand ();
7066+ if (memo::multi::is_brand_cached ()) {
7067+ return memo::multi::fetch_brand ();
70597068 }
70607069 } else {
7061- if (memo::is_brand_cached ()) {
7062- return memo::fetch_brand ();
7070+ if (memo::brand:: is_brand_cached ()) {
7071+ return memo::brand:: fetch_brand ();
70637072 }
70647073 }
70657074
@@ -7173,9 +7182,9 @@ struct VM {
71737182 }
71747183
71757184 if (is_multiple) {
7176- memo::store_multibrand (current_brand);
7185+ memo::multi::store_brand (current_brand);
71777186 } else {
7178- memo::store_brand (current_brand);
7187+ memo::brand:: store_brand (current_brand);
71797188 }
71807189
71817190 return current_brand;
@@ -7275,6 +7284,8 @@ MSVC_ENABLE_WARNING(ASSIGNMENT_OPERATOR NO_INLINE_FUNC SPECTRE)
72757284// These are added here due to warnings related to C++17 inline variables for C++ standards that are under 17.
72767285// It's easier to just group them together rather than having C++17<= preprocessors with inline stuff
72777286
7287+
7288+ // scoreboard list of brands, if a VM detection technique detects a brand, that will be incremented here as a single point.
72787289std::map<const char *, VM ::brand_score_t > VM ::core::brand_scoreboard {
72797290 { VM ::VBOX , 0 },
72807291 { VM ::VMWARE , 0 },
@@ -7311,20 +7322,23 @@ std::map<const char*, VM::brand_score_t> VM::core::brand_scoreboard {
73117322 { VM ::LMHS , 0 }
73127323};
73137324
7325+
7326+ // initial definitions for cache items
73147327std::map<VM ::u8 , VM ::memo::data_t > VM ::memo::cache_table;
73157328VM ::flagset VM ::memo::cache_keys = 0 ;
7316- std::string VM ::memo::brand_cache = " " ;
7317- std::string VM ::memo::multibrand_cache = " " ;
7318- std::string VM ::memo::cpu_brand_cache = " " ;
7329+ std::string VM ::memo::brand:: brand_cache = " " ;
7330+ std::string VM ::memo::multi::brand_cache = " " ;
7331+ std::string VM ::memo::cpu::brand_cache = " " ;
73197332
73207333
7334+ // default flags
73217335VM ::flagset VM ::DEFAULT = []() -> flagset {
73227336 flagset tmp;
73237337
73247338 // set all bits to 1
73257339 tmp.set ();
73267340
7327- // disable all the non-default flags (WIN_HYPERV_DEFAULT is enabled)
7341+ // disable all the non-default flags
73287342 tmp.flip (EXTREME );
73297343 tmp.flip (NO_MEMO );
73307344 tmp.flip (CURSOR );
@@ -7333,13 +7347,16 @@ VM::flagset VM::DEFAULT = []() -> flagset {
73337347 return tmp;
73347348}();
73357349
7350+
7351+ // flag to enable every technique, basically VM::DEFAULT but with VM::CURSOR technique
73367352VM ::flagset VM ::ALL = []() -> flagset {
73377353 flagset tmp = DEFAULT ;
73387354 tmp.set (CURSOR );
73397355 return tmp;
73407356}();
73417357
73427358
7359+ // check if cpuid is supported
73437360bool VM ::core::cpuid_supported = []() -> bool {
73447361#if (x86)
73457362 #if (MSVC)
0 commit comments