Skip to content

Commit 1c92414

Browse files
committed
fixed hyper_x bug, removed modify_score(), small misc changes
1 parent 7adfd0f commit 1c92414

File tree

1 file changed

+22
-64
lines changed

1 file changed

+22
-64
lines changed

src/vmaware.hpp

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,15 +2279,15 @@ struct VM {
22792279
#else
22802280
const std::string& brand = cpu::get_brand();
22812281

2282-
struct CStrView {
2282+
struct string_view {
22832283
const char* data;
22842284
std::size_t size;
2285-
constexpr CStrView(const char* d, std::size_t s) noexcept
2285+
constexpr string_view(const char* d, std::size_t s) noexcept
22862286
: data(d), size(s) {
22872287
}
22882288
};
22892289

2290-
static constexpr std::array<CStrView, 10> checks{ {
2290+
static constexpr std::array<string_view, 10> checks{ {
22912291
{ "qemu", 4 },
22922292
{ "kvm", 3 },
22932293
{ "vbox", 4 },
@@ -2311,7 +2311,7 @@ struct VM {
23112311
if (v.size == 7 // "monitor"
23122312
|| ((v.size == 6) && (v.data[0] == 'h')) // "hvisor"
23132313
|| ((v.size == 10) && (v.data[0] == 'h')) // "hypervisor"
2314-
) {
2314+
) {
23152315
return true;
23162316
}
23172317

@@ -10542,7 +10542,7 @@ struct VM {
1054210542
if (
1054310543
(shortcut) &&
1054410544
(points >= threshold_points)
10545-
) {
10545+
) {
1054610546
return points;
1054710547
}
1054810548
}
@@ -10961,10 +10961,7 @@ struct VM {
1096110961
// is the multiple setting flag enabled? (meaning multiple
1096210962
// brand strings will be outputted if there's a conflict)
1096310963
const bool is_multiple = core::is_enabled(flags, MULTIPLE);
10964-
10965-
// run all the techniques
10966-
const u16 score = core::run_all(flags);
10967-
10964+
1096810965
// check if the result is already cached and return that instead
1096910966
if (is_multiple) {
1097010967
if (memo::multi_brand::is_cached()) {
@@ -10978,6 +10975,9 @@ struct VM {
1097810975
}
1097910976
}
1098010977

10978+
// run all the techniques
10979+
core::run_all(flags);
10980+
1098110981
// goofy ass C++11 and C++14 linker error workaround.
1098210982
// And yes, this does look stupid.
1098310983
#if (VMA_CPP <= 14)
@@ -11159,9 +11159,7 @@ struct VM {
1115911159
// confirmation is true and percentage is 100%, as if that makes
1116011160
// any sense whatsoever. That's what this part fixes.
1116111161
if (brands.count(TMP_HYPERV_ARTIFACT) > 0) {
11162-
if (score > 0) {
11163-
brands.erase(TMP_HYPERV_ARTIFACT);
11164-
}
11162+
brands.erase(TMP_HYPERV_ARTIFACT);
1116511163
}
1116611164

1116711165

@@ -11234,6 +11232,11 @@ struct VM {
1123411232
// fetch all the flags in a std::bitset
1123511233
flagset flags = core::arg_handler(args...);
1123611234

11235+
// early return, since this is NOT a VM
11236+
if (brand(flags) == brands::HYPERV_ARTIFACT) {
11237+
return false;
11238+
}
11239+
1123711240
// run all the techniques based on the
1123811241
// flags above, and get a total score
1123911242
const u16 points = core::run_all(flags, SHORTCUT);
@@ -11265,6 +11268,11 @@ struct VM {
1126511268
// fetch all the flags in a std::bitset
1126611269
const flagset flags = core::arg_handler(args...);
1126711270

11271+
// early return, since this is NOT a VM
11272+
if (brand(flags) == brands::HYPERV_ARTIFACT) {
11273+
return 0;
11274+
}
11275+
1126811276
// run all the techniques based on the
1126911277
// flags above, and get a total score
1127011278
const u16 points = core::run_all(flags, SHORTCUT);
@@ -11497,56 +11505,6 @@ struct VM {
1149711505
}
1149811506

1149911507

11500-
/**
11501-
* @brief Change the certainty score of a technique
11502-
* @param technique flag, then the new percentage score to overwite
11503-
* @return void
11504-
* @warning ⚠️ FOR DEVELOPMENT USAGE ONLY, NOT MEANT FOR PUBLIC USE FOR NOW ⚠️
11505-
*/
11506-
static void modify_score(
11507-
const enum_flags flag,
11508-
const u8 percent
11509-
#if (VMA_CPP >= 20) && (!CLANG || __clang_major__ >= 16)
11510-
, const std::source_location& loc = std::source_location::current()
11511-
#endif
11512-
) {
11513-
// lambda to throw the error
11514-
auto throw_error = [&](const char* text) -> void {
11515-
std::stringstream ss;
11516-
#if (VMA_CPP >= 20 && !CLANG)
11517-
ss << ", error in " << loc.function_name() << " at " << loc.file_name() << ":" << loc.line() << ")";
11518-
#endif
11519-
ss << ". Consult the documentation's parameters for VM::modify_score()";
11520-
throw std::invalid_argument(std::string(text) + ss.str());
11521-
};
11522-
11523-
if (percent > 100) {
11524-
throw_error("Percentage parameter must be between 0 and 100");
11525-
}
11526-
11527-
#if (VMA_CPP >= 23)
11528-
[[assume(percent <= 100)]];
11529-
#endif
11530-
11531-
// check if the flag provided is a setting flag, which isn't valid.
11532-
if (static_cast<u8>(flag) >= technique_end) {
11533-
throw_error("The flag is not a technique flag");
11534-
}
11535-
11536-
using table_t = std::map<enum_flags, core::technique>;
11537-
11538-
auto modify = [](table_t& table, const enum_flags flag, const u8 percent) noexcept -> void {
11539-
const auto it = table.find(flag);
11540-
11541-
if (it != table.end()) {
11542-
it->second.points = percent;
11543-
}
11544-
};
11545-
11546-
modify(core::technique_table, flag, percent);
11547-
}
11548-
11549-
1155011508
/**
1155111509
* @brief Fetch the total number of detected techniques
1155211510
* @param any flag combination in VM structure or nothing
@@ -11726,7 +11684,7 @@ struct VM {
1172611684
(brand_tmp == brands::AMD_SEV_SNP) ||
1172711685
(brand_tmp == brands::NSJAIL) ||
1172811686
(brand_tmp == brands::NULL_BRAND)
11729-
) {
11687+
) {
1173011688
addition = " an ";
1173111689
}
1173211690

@@ -11740,7 +11698,7 @@ struct VM {
1174011698

1174111699
// Hyper-V artifacts are an exception due to how unique the circumstance is
1174211700
const char* suffix = " VM";
11743-
if (brand_tmp == brands::HYPERV_ARTIFACT && percent_tmp != 100) {
11701+
if (brand_tmp == brands::HYPERV_ARTIFACT) {
1174411702
suffix = "";
1174511703
}
1174611704

0 commit comments

Comments
 (0)