Skip to content

Commit

Permalink
ci/cd test 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelwernel committed Oct 15, 2024
1 parent e61d37c commit a5c56b4
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,65 @@
#include <vector>
#include <cstdint>
#include <bit>
#include <intrin.h>
#include <Windows.h>

void checkXsetbvVmException() {
UINT64 xcr0 = _xgetbv(0);
#include <cstring>

__try {
_xsetbv(0, xcr0 & ~1);
#ifdef _MSC_VER
#include <intrin.h> // For __sidt on MSVC
#else
#include <x86intrin.h> // For GCC/Clang
#endif

#pragma pack(push, 1)
struct IDTR {
uint16_t limit; // Limit (size of the table)
uint64_t base; // Base address of the IDT
};
#pragma pack(pop)

bool check_virtualization() {
IDTR idtr;

#ifdef _MSC_VER
__sidt(&idtr); // MSVC intrinsic for storing IDTR
#else
asm volatile ("sidt %0" : "=m" (idtr)); // Assembly code for GCC/Clang
#endif

std::cout << "No exception occurred. Likely running on bare metal.\n";
uint64_t idt_base = idtr.base;
std::cout << "IDT base address: 0x" << std::hex << idt_base << std::endl;

// Common virtualization signature checks
// Known IDT base address ranges for virtualized environments
if (idt_base >= 0xF0000000 && idt_base <= 0xF0800000) {
std::cout << "VMware detected based on IDT base address!" << std::endl;
return true;
}
__except (EXCEPTION_EXECUTE_HANDLER) {
std::cout << "Exception caught! VM likely detected (GP fault triggered).\n";
else if (idt_base >= 0xE0000000 && idt_base <= 0xE0800000) {
std::cout << "VirtualBox detected based on IDT base address!" << std::endl;
return true;
}
else if (idt_base == 0xFFFA0000) {
std::cout << "QEMU detected based on IDT base address!" << std::endl;
return true;
}
else {
std::cout << "No known virtualization detected based on IDT base address." << std::endl;
}

return false;
}

int main() {
checkXsetbvVmException();
if (check_virtualization()) {
std::cout << "Virtualization detected!" << std::endl;
}
else {
std::cout << "No virtualization detected." << std::endl;
}

return 0;
}

/*
#if (defined(__GNUC__) || defined(__linux__))
#include <unistd.h>
Expand Down

0 comments on commit a5c56b4

Please sign in to comment.