Skip to content

Commit 2de0e26

Browse files
committed
fix: removal of active_count variable and manual size management
1 parent aa2ba50 commit 2de0e26

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/vmaware.hpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,12 +4511,9 @@ struct VM {
45114511
brand_list_t active_brands = {};
45124512
active_brands.reserve(MAX_BRANDS);
45134513

4514-
size_t active_count = 0;
4515-
45164514
for (size_t i = 0; i < MAX_BRANDS; ++i) {
45174515
if (core::brand_scoreboard.at(i).score > 0) {
45184516
active_brands.push_back(std::make_pair(core::brand_scoreboard.at(i).name, core::brand_scoreboard.at(i).score));
4519-
active_count++;
45204517
}
45214518
}
45224519

@@ -4527,17 +4524,16 @@ struct VM {
45274524
#endif
45284525

45294526
auto remove = [&](const enum brand_enum brand) noexcept {
4530-
for (const auto b : active_brands) {
4531-
if (b.first == brand) {
4532-
active_brands.at(static_cast<u8>(brand)) = std::make_pair(brand_enum::NULL_BRAND, 0);
4533-
active_count--;
4527+
for (u8 i = 0; i < active_brands.size(); i++) {
4528+
if (brand == active_brands.at(i).first) {
4529+
active_brands.erase(active_brands.begin() + i);
45344530
return;
45354531
}
45364532
}
45374533
};
45384534

45394535
// if all brands have a point of 0, return "Unknown"
4540-
if (active_count == 0) {
4536+
if (active_brands.size() == 0) {
45414537
active_brands.push_back({brand_enum::NULL_BRAND, 1});
45424538
memo::brand_list::store(active_brands);
45434539
return active_brands;
@@ -4547,7 +4543,7 @@ struct VM {
45474543
// We skip this early return if the single brand is HYPERV_ARTIFACT,
45484544
// but we must also nullify the result if the score is above 0,
45494545
// which would most likely indicate a hardened VM instead and return "Unknown".
4550-
if (active_count == 1) {
4546+
if (active_brands.size() == 1) {
45514547
const enum brand_enum brand = active_brands.front().first;
45524548

45534549
if (brand == brand_enum::HYPERV_ROOT && score > 0) {
@@ -4560,7 +4556,7 @@ struct VM {
45604556
}
45614557

45624558
// remove Hyper-V artifacts and Unknown if found with other brands
4563-
if (active_count > 1) {
4559+
if (active_brands.size() > 1) {
45644560
remove(brand_enum::HYPERV_ROOT);
45654561
remove(brand_enum::NULL_BRAND);
45664562
remove(brand_enum::INVALID);
@@ -4583,8 +4579,7 @@ struct VM {
45834579
if (a_hit && b_hit) {
45844580
remove(a);
45854581
remove(b);
4586-
active_brands.at(static_cast<u8>(result)) = std::make_pair(result, 2);
4587-
active_count++;
4582+
active_brands.push_back({result, 2});
45884583
}
45894584
};
45904585

@@ -4598,8 +4593,7 @@ struct VM {
45984593
remove(a);
45994594
remove(b);
46004595
remove(c);
4601-
active_brands.at(static_cast<u8>(result)) = std::make_pair(result, 2);
4602-
active_count++;
4596+
active_brands.push_back({result, 2});
46034597
}
46044598
};
46054599

@@ -4639,8 +4633,8 @@ struct VM {
46394633
merge(brand_enum::VMWARE_HARD, brand_enum::VMWARE_WORKSTATION, brand_enum::VMWARE_HARD);
46404634

46414635

4642-
if (active_count > 1) {
4643-
std::sort(active_brands.begin(), active_brands.begin() + static_cast<std::ptrdiff_t>(active_count), [](
4636+
if (active_brands.size() > 1) {
4637+
std::sort(active_brands.begin(), active_brands.begin() + static_cast<std::ptrdiff_t>(active_brands.size()), [](
46444638
const brand_element_t& a,
46454639
const brand_element_t& b
46464640
) {

0 commit comments

Comments
 (0)