Skip to content

Commit 878606c

Browse files
authored
Merge pull request #333 from NotRequiem/dev
removed VM::PROCESSOR_ID
2 parents 76fdb88 + e7c4756 commit 878606c

7 files changed

Lines changed: 6 additions & 214 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ You can view the full docs [here](docs/documentation.md). All the details such a
239239

240240
> I would've made it strictly MIT so proprietary software can make use of the library, but some of the techniques employed are from GPL projects, and I have no choice but to use the same license for legal reasons.
241241
>
242-
> This gave me an idea to make an MIT version without all of the GPL code so it can also be used without forcing your code to be open source. It should be noted that the MIT version removes <b>7</b> techniques out of 117 (as of 2.0 version), and the lesser the number of techniques, the less accurate the overall result might be.
242+
> This gave me an idea to make an MIT version without all of the GPL code so it can also be used without forcing your code to be open source. It should be noted that the MIT version removes <b>7</b> techniques out of 116 (as of 2.0 version), and the lesser the number of techniques, the less accurate the overall result might be.
243243
244244
</details>
245245

auxiliary/benchmark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
class VMAwareBenchmark {
3737
public:
38-
static uint64_t get_timestamp() {
38+
static inline uint64_t get_timestamp() {
3939
#if defined(_WIN32)
4040
LARGE_INTEGER counter;
4141
QueryPerformanceCounter(&counter);
@@ -51,7 +51,7 @@ class VMAwareBenchmark {
5151
#endif
5252
}
5353

54-
static double get_elapsed(uint64_t start, uint64_t end) {
54+
static inline double get_elapsed(uint64_t start, uint64_t end) {
5555
#if defined(_WIN32)
5656
static LARGE_INTEGER freq;
5757
QueryPerformanceFrequency(&freq);

docs/documentation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ VMAware provides a convenient way to not only check for VMs, but also have the f
515515
| `VM::PROCESSOR_NUMBER` | Check for number of processors | Windows | 50% | | | | |
516516
| `VM::NUMBER_OF_CORES` | Check for number of cores | Windows | 50% | | | | |
517517
| `VM::ACPI_TEMPERATURE` | Check for device's temperature | Windows | 25% | | | | |
518-
| `VM::PROCESSOR_ID` | Check if any processor has an empty Processor ID using SMBIOS data | Windows | 25% | | | | |
519518
| `VM::SYS_QEMU` | Check for existence of "qemu_fw_cfg" directories within /sys/module and /sys/firmware | Linux | 70% | | | | |
520519
| `VM::LSHW_QEMU` | Check for QEMU string instances with lshw command | Linux | 80% | | | | |
521520
| `VM::VIRTUAL_PROCESSORS` | Check if the number of virtual and logical processors are reported correctly by the system | Windows | 50% | | | | |

src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
|------|---------|
33
| `cli.cpp` | Entire CLI tool code |
44
| `vmaware.hpp` | Official and original library header in GPL-3.0, most likely what you're looking for. |
5-
| `vmaware_MIT.hpp` | Same as above but in MIT. But this removes 7 techniques out of 117 |
5+
| `vmaware_MIT.hpp` | Same as above but in MIT. But this removes 7 techniques out of 116 |
66

77
<br>
88

src/cli.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ bool is_unsupported(VM::enum_flags flag) {
458458
case VM::PROCESSOR_NUMBER:
459459
case VM::NUMBER_OF_CORES:
460460
case VM::ACPI_TEMPERATURE:
461-
case VM::PROCESSOR_ID:
462461
case VM::POWER_CAPABILITIES:
463462
case VM::SETUPAPI_DISK:
464463
case VM::VIRTUAL_PROCESSORS:
@@ -974,7 +973,6 @@ void general() {
974973
checker(VM::PROCESSOR_NUMBER, "processor count");
975974
checker(VM::NUMBER_OF_CORES, "CPU core count");
976975
checker(VM::ACPI_TEMPERATURE, "thermal devices");
977-
checker(VM::PROCESSOR_ID, "processor ID");
978976
checker(VM::POWER_CAPABILITIES, "Power capabilities");
979977
checker(VM::SETUPAPI_DISK, "SETUPDI diskdrive");
980978
checker(VM::SYS_QEMU, "QEMU in /sys");

src/vmaware.hpp

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,10 @@
362362
#include <psapi.h>
363363
#include <shlwapi.h>
364364
#include <shlobj_core.h>
365-
#include <dshow.h>
366-
#include <io.h>
367365
#include <winspool.h>
368366
#include <powerbase.h>
369367
#include <setupapi.h>
370-
#include <mmdeviceapi.h>
371-
#include <Functiondiscoverykeys_devpkey.h>
372368
#include <mmsystem.h>
373-
#include <queue>
374369
#include <dxgi.h>
375370
#include <d3d9.h>
376371

@@ -649,7 +644,6 @@ struct VM {
649644
PROCESSOR_NUMBER,
650645
NUMBER_OF_CORES,
651646
ACPI_TEMPERATURE,
652-
PROCESSOR_ID,
653647
SYS_QEMU,
654648
LSHW_QEMU,
655649
VIRTUAL_PROCESSORS,
@@ -1936,7 +1930,7 @@ struct VM {
19361930

19371931
#ifdef __VMAWARE_DEBUG__
19381932
if (result) {
1939-
core_debug("HYPER_X: root partition returned true");
1933+
core_debug("HYPER_X: running under root partition");
19401934
}
19411935
#endif
19421936
return result;
@@ -7831,103 +7825,6 @@ struct VM {
78317825
}
78327826

78337827

7834-
/**
7835-
* @brief Check if any processor has an empty Processor ID using SMBIOS data
7836-
* @category Windows
7837-
* @author Requiem (https://github.com/NotRequiem)
7838-
* @note https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.8.0.pdf (Section 7.5.3, page 54)
7839-
* @implements VM::PROCESSOR_ID
7840-
*/
7841-
[[nodiscard]] static bool processor_id() {
7842-
#if (!WINDOWS)
7843-
return false;
7844-
#else
7845-
#pragma pack(push, 1)
7846-
struct RawSMBIOSData {
7847-
BYTE Used20CallingMethod;
7848-
BYTE SMBIOSMajorVersion;
7849-
BYTE SMBIOSMinorVersion;
7850-
BYTE DmiRevision;
7851-
DWORD Length;
7852-
BYTE SMBIOSTableData[1];
7853-
};
7854-
#pragma pack(pop)
7855-
7856-
UINT bufferSize = GetSystemFirmwareTable('RSMB', 0, nullptr, 0);
7857-
if (bufferSize == 0)
7858-
return false;
7859-
7860-
std::vector<BYTE> buffer(bufferSize);
7861-
if (GetSystemFirmwareTable('RSMB', 0, buffer.data(), bufferSize) != bufferSize)
7862-
return false;
7863-
7864-
if (buffer.size() < sizeof(RawSMBIOSData))
7865-
return false;
7866-
7867-
RawSMBIOSData* raw = reinterpret_cast<RawSMBIOSData*>(buffer.data());
7868-
BYTE* tableData = raw->SMBIOSTableData;
7869-
DWORD tableLength = raw->Length;
7870-
BYTE* tableEnd = tableData + tableLength;
7871-
BYTE* p = tableData;
7872-
7873-
while (p < tableEnd) {
7874-
// header: [Type (1B), Length (1B), Handle (2B)]
7875-
if (p + 4 > tableEnd)
7876-
break;
7877-
7878-
BYTE type = p[0];
7879-
BYTE length = p[1];
7880-
7881-
if (length < 4 || (p + length) > tableEnd)
7882-
break;
7883-
7884-
// Processor Information (Type 4) structures, Processor ID field
7885-
if (type == 4) {
7886-
// the Processor ID is an 8‑byte field starting at offset 8 in the structure
7887-
// Therefore, the structure must be at least 16 bytes long
7888-
if (length >= 16) {
7889-
BYTE* procId = p + 8;
7890-
7891-
#ifdef __VMAWARE_DEBUG__
7892-
std::ostringstream oss;
7893-
oss << "PROCESSOR_ID: ";
7894-
for (int i = 0; i < 8; ++i) {
7895-
oss << std::hex << std::setw(2) << std::setfill('0')
7896-
<< static_cast<int>(procId[i]) << " ";
7897-
}
7898-
debug(oss.str());
7899-
#endif
7900-
bool allZero = true;
7901-
for (int i = 0; i < 8; ++i) {
7902-
if (procId[i] != 0) {
7903-
allZero = false;
7904-
break;
7905-
}
7906-
}
7907-
if (allZero) {
7908-
return true;
7909-
}
7910-
}
7911-
}
7912-
7913-
// Skip the formatted section
7914-
BYTE* next = p + length;
7915-
// Then skip the unformatted string-set (terminated by double-null)
7916-
while (next < tableEnd - 1) {
7917-
if (next[0] == 0 && next[1] == 0) {
7918-
next += 2;
7919-
break;
7920-
}
7921-
++next;
7922-
}
7923-
p = next;
7924-
}
7925-
7926-
return false;
7927-
#endif
7928-
}
7929-
7930-
79317828
/**
79327829
* @brief Check for timing anomalies in the system
79337830
* @category x86
@@ -11339,7 +11236,6 @@ struct VM {
1133911236
case PROCESSOR_NUMBER: return "PROCESSOR_NUMBER";
1134011237
case NUMBER_OF_CORES: return "NUMBER_OF_CORES";
1134111238
case ACPI_TEMPERATURE: return "ACPI_TEMPERATURE";
11342-
case PROCESSOR_ID: return "PROCESSOR_ID";
1134311239
case SYS_QEMU: return "SYS_QEMU";
1134411240
case LSHW_QEMU: return "LSHW_QEMU";
1134511241
case VIRTUAL_PROCESSORS: return "VIRTUAL_PROCESSORS";
@@ -11901,7 +11797,6 @@ std::pair<VM::enum_flags, VM::core::technique> VM::core::technique_list[] = {
1190111797
std::make_pair(VM::PROCESSOR_NUMBER, VM::core::technique(50, VM::processor_number)),
1190211798
std::make_pair(VM::NUMBER_OF_CORES, VM::core::technique(50, VM::number_of_cores)),
1190311799
std::make_pair(VM::ACPI_TEMPERATURE, VM::core::technique(25, VM::acpi_temperature)),
11904-
std::make_pair(VM::PROCESSOR_ID, VM::core::technique(25, VM::processor_id)),
1190511800
std::make_pair(VM::SYS_QEMU, VM::core::technique(70, VM::sys_qemu_dir)),
1190611801
std::make_pair(VM::LSHW_QEMU, VM::core::technique(80, VM::lshw_qemu)),
1190711802
std::make_pair(VM::VIRTUAL_PROCESSORS, VM::core::technique(50, VM::virtual_processors)),

src/vmaware_MIT.hpp

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ struct VM {
664664
PROCESSOR_NUMBER,
665665
NUMBER_OF_CORES,
666666
ACPI_TEMPERATURE,
667-
PROCESSOR_ID,
668667
SYS_QEMU,
669668
LSHW_QEMU,
670669
VIRTUAL_PROCESSORS,
@@ -1955,7 +1954,7 @@ struct VM {
19551954

19561955
#ifdef __VMAWARE_DEBUG__
19571956
if (result) {
1958-
core_debug("HYPER_X: root partition returned true");
1957+
core_debug("HYPER_X: running under root partition");
19591958
}
19601959
#endif
19611960
return result;
@@ -7636,103 +7635,6 @@ struct VM {
76367635
}
76377636

76387637

7639-
/**
7640-
* @brief Check if any processor has an empty Processor ID using SMBIOS data
7641-
* @category Windows
7642-
* @author Requiem (https://github.com/NotRequiem)
7643-
* @note https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.8.0.pdf (Section 7.5.3, page 54)
7644-
* @implements VM::PROCESSOR_ID
7645-
*/
7646-
[[nodiscard]] static bool processor_id() {
7647-
#if (!WINDOWS)
7648-
return false;
7649-
#else
7650-
#pragma pack(push, 1)
7651-
struct RawSMBIOSData {
7652-
BYTE Used20CallingMethod;
7653-
BYTE SMBIOSMajorVersion;
7654-
BYTE SMBIOSMinorVersion;
7655-
BYTE DmiRevision;
7656-
DWORD Length;
7657-
BYTE SMBIOSTableData[1];
7658-
};
7659-
#pragma pack(pop)
7660-
7661-
UINT bufferSize = GetSystemFirmwareTable('RSMB', 0, nullptr, 0);
7662-
if (bufferSize == 0)
7663-
return false;
7664-
7665-
std::vector<BYTE> buffer(bufferSize);
7666-
if (GetSystemFirmwareTable('RSMB', 0, buffer.data(), bufferSize) != bufferSize)
7667-
return false;
7668-
7669-
if (buffer.size() < sizeof(RawSMBIOSData))
7670-
return false;
7671-
7672-
RawSMBIOSData* raw = reinterpret_cast<RawSMBIOSData*>(buffer.data());
7673-
BYTE* tableData = raw->SMBIOSTableData;
7674-
DWORD tableLength = raw->Length;
7675-
BYTE* tableEnd = tableData + tableLength;
7676-
BYTE* p = tableData;
7677-
7678-
while (p < tableEnd) {
7679-
// header: [Type (1B), Length (1B), Handle (2B)]
7680-
if (p + 4 > tableEnd)
7681-
break;
7682-
7683-
BYTE type = p[0];
7684-
BYTE length = p[1];
7685-
7686-
if (length < 4 || (p + length) > tableEnd)
7687-
break;
7688-
7689-
// Processor Information (Type 4) structures, Processor ID field
7690-
if (type == 4) {
7691-
// the Processor ID is an 8‑byte field starting at offset 8 in the structure
7692-
// Therefore, the structure must be at least 16 bytes long
7693-
if (length >= 16) {
7694-
BYTE* procId = p + 8;
7695-
7696-
#ifdef __VMAWARE_DEBUG__
7697-
std::ostringstream oss;
7698-
oss << "PROCESSOR_ID: ";
7699-
for (int i = 0; i < 8; ++i) {
7700-
oss << std::hex << std::setw(2) << std::setfill('0')
7701-
<< static_cast<int>(procId[i]) << " ";
7702-
}
7703-
debug(oss.str());
7704-
#endif
7705-
bool allZero = true;
7706-
for (int i = 0; i < 8; ++i) {
7707-
if (procId[i] != 0) {
7708-
allZero = false;
7709-
break;
7710-
}
7711-
}
7712-
if (allZero) {
7713-
return true;
7714-
}
7715-
}
7716-
}
7717-
7718-
// Skip the formatted section
7719-
BYTE* next = p + length;
7720-
// Then skip the unformatted string-set (terminated by double-null)
7721-
while (next < tableEnd - 1) {
7722-
if (next[0] == 0 && next[1] == 0) {
7723-
next += 2;
7724-
break;
7725-
}
7726-
++next;
7727-
}
7728-
p = next;
7729-
}
7730-
7731-
return false;
7732-
#endif
7733-
}
7734-
7735-
77367638
/**
77377639
* @brief Check for timing anomalies in the system
77387640
* @category x86
@@ -11155,7 +11057,6 @@ struct VM {
1115511057
case PROCESSOR_NUMBER: return "PROCESSOR_NUMBER";
1115611058
case NUMBER_OF_CORES: return "NUMBER_OF_CORES";
1115711059
case ACPI_TEMPERATURE: return "ACPI_TEMPERATURE";
11158-
case PROCESSOR_ID: return "PROCESSOR_ID";
1115911060
case SYS_QEMU: return "SYS_QEMU";
1116011061
case LSHW_QEMU: return "LSHW_QEMU";
1116111062
case VIRTUAL_PROCESSORS: return "VIRTUAL_PROCESSORS";
@@ -11713,7 +11614,6 @@ std::pair<VM::enum_flags, VM::core::technique> VM::core::technique_list[] = {
1171311614
std::make_pair(VM::PROCESSOR_NUMBER, VM::core::technique(50, VM::processor_number)),
1171411615
std::make_pair(VM::NUMBER_OF_CORES, VM::core::technique(50, VM::number_of_cores)),
1171511616
std::make_pair(VM::ACPI_TEMPERATURE, VM::core::technique(25, VM::acpi_temperature)),
11716-
std::make_pair(VM::PROCESSOR_ID, VM::core::technique(25, VM::processor_id)),
1171711617
std::make_pair(VM::SYS_QEMU, VM::core::technique(70, VM::sys_qemu_dir)),
1171811618
std::make_pair(VM::LSHW_QEMU, VM::core::technique(80, VM::lshw_qemu)),
1171911619
std::make_pair(VM::VIRTUAL_PROCESSORS, VM::core::technique(50, VM::virtual_processors)),

0 commit comments

Comments
 (0)