Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
SMode check added
Browse files Browse the repository at this point in the history
  • Loading branch information
mq1n committed Jun 25, 2021
1 parent 361c7e0 commit c8ebe43
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"activityBar.background": "#013618",
"titleBar.activeBackground": "#014B22",
"titleBar.activeForeground": "#ECFFF4"
},
"files.associations": {
"iostream": "cpp"
}
}
52 changes: 46 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,46 @@ int main(int, char* argv[])
return EXIT_FAILURE;
}

typedef NTSTATUS(NTAPI* TRtlGetVersion)(LPOSVERSIONINFOEX OsVersionInfoEx);
const auto RtlGetVersion = reinterpret_cast<TRtlGetVersion>(GetProcAddress(hNtdll, "RtlGetVersion"));
if (!RtlGetVersion)
{
std::cerr << "GetProcAddress(RtlGetVersion) failed with error: " << GetLastError() << std::endl;
return EXIT_FAILURE;
}

// S Mode
{
std::cout << "S Mode checking..." << std::endl;

OSVERSIONINFOEX osVerEx{ 0 };
const auto ntStatus = RtlGetVersion(&osVerEx);
if (ntStatus != STATUS_SUCCESS)
{
std::cerr << "RtlGetVersion failed with status: " << std::hex << ntStatus << std::endl;
return EXIT_FAILURE;
}

std::cout << "\tVersion: " << osVerEx.dwMajorVersion << "." << osVerEx.dwMinorVersion << std::endl;

DWORD dwProductType = 0;
if (!GetProductInfo(osVerEx.dwMajorVersion, osVerEx.dwMinorVersion, 0, 0, &dwProductType))
{
std::cerr << "GetProductInfo failed with error: " << GetLastError() << std::endl;
return EXIT_FAILURE;
}

std::cout << "\tProduct type: " << dwProductType << std::endl;

if (dwProductType == PRODUCT_CLOUD || dwProductType == PRODUCT_CLOUDN)
{
std::cerr << "SMode does not supported!" << std::endl;
return EXIT_FAILURE;
}

std::cout << "S Mode check passed!" << std::endl;
}

// 1 Ghz, 64-bit, dual core CPU
{
std::cout << "CPU checking..." << std::endl;
Expand Down Expand Up @@ -112,15 +152,15 @@ int main(int, char* argv[])
}

PROCESSOR_POWER_INFORMATION processorPowerInfo{ 0 };
const auto dwBufferSize = sizeof(processorPowerInfo) * sysInfo.dwNumberOfProcessors;
const auto lpBuffer = reinterpret_cast<PROCESSOR_POWER_INFORMATION*>(HeapAlloc(hProcHeap, HEAP_ZERO_MEMORY, dwBufferSize));
const ULONG ulBufferSize = sizeof(processorPowerInfo) * sysInfo.dwNumberOfProcessors;
const auto lpBuffer = reinterpret_cast<PROCESSOR_POWER_INFORMATION*>(HeapAlloc(hProcHeap, HEAP_ZERO_MEMORY, ulBufferSize));
if (!lpBuffer)
{
std::cerr << "HeapAlloc(" << dwBufferSize << " bytes) failed with error: " << GetLastError() << std::endl;
std::cerr << "HeapAlloc(" << ulBufferSize << " bytes) failed with error: " << GetLastError() << std::endl;
return EXIT_FAILURE;
}

const auto lStatus = CallNtPowerInformation(ProcessorInformation, nullptr, 0, lpBuffer, dwBufferSize);
const auto lStatus = CallNtPowerInformation(ProcessorInformation, nullptr, 0, lpBuffer, ulBufferSize);
if (lStatus != STATUS_SUCCESS)
{
HeapFree(hProcHeap, 0, lpBuffer);
Expand Down Expand Up @@ -244,7 +284,7 @@ int main(int, char* argv[])
const auto ntStatus = NtQuerySystemInformation(SystemBootEnvironmentInformation, &sbei, sizeof(sbei), &cbSize);
if (ntStatus != STATUS_SUCCESS)
{
std::cerr << "NtQuerySystemInformation(SystemBootEnvironmentInformation) failed with status: " << ntStatus << std::endl;
std::cerr << "NtQuerySystemInformation(SystemBootEnvironmentInformation) failed with status: " << std::hex << ntStatus << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -268,7 +308,7 @@ int main(int, char* argv[])
const auto ntStatus = NtQuerySystemInformation(SystemSecureBootInformation, &ssbi, sizeof(ssbi), &cbSize);
if (ntStatus != STATUS_SUCCESS)
{
std::cerr << "NtQuerySystemInformation(SystemSecureBootInformation) failed with status: " << ntStatus << std::endl;
std::cerr << "NtQuerySystemInformation(SystemSecureBootInformation) failed with status: " << std::hex << ntStatus << std::endl;
return EXIT_FAILURE;
}

Expand Down

0 comments on commit c8ebe43

Please sign in to comment.