// // Error String // const WCHAR UnpatchedString[] = L"Your system either does not have the appropriate patch, " L"or it may not support the information class required.\n";
if (!hntdll) { return SpcSuccess; } NtQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(hntdll, "NtQuerySystemInformation"); if (!NtQuerySystemInformation) { return SpcSuccess; } // // Open the output handle -- also not much we can do if this fails // hStdOut = CreateFile(L"CONOUT$", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hStdOut == INVALID_HANDLE_VALUE) { hStdOut = INVALID_HANDLE_VALUE; errorCode = SpcFailedToOpenStandardOut; goto Exit; }
// // We now have display capabilities -- say hello! // WriteConsole(hStdOut, WelcomeString, ARRAYSIZE(WelcomeString) - 1, NULL, NULL);
// // Get the KVA Shadow Information // status = NtQuerySystemInformation(SystemKernelVaShadowInformation, &kvaInfo, sizeof(kvaInfo), NULL); if (!NT_SUCCESS(status)) { // // Print out an error if this failed // WriteConsole(hStdOut, UnpatchedString, ARRAYSIZE(UnpatchedString) - 1, NULL, NULL); errorCode = SpcFailedToQueryKvaShadowing; goto Exit; }
// // Get the Speculation Control Information // status = NtQuerySystemInformation(SystemSpeculationControlInformation, &specInfo, sizeof(specInfo), NULL); if (!NT_SUCCESS(status)) { // // Print out an error if this failed // WriteConsole(hStdOut, UnpatchedString, ARRAYSIZE(UnpatchedString) - 1, NULL, NULL); errorCode = SpcFailedToQuerySpeculationControl; goto Exit; }
// // Print status of KVA Features // charsWritten = swprintf_s(stateBuffer, ARRAYSIZE(stateBuffer), L"KVA Shadowing Enabled: %s\n" L"KVA Shadowing with User Pages Marked Global: %s\n" L"KVA Shadowing with PCID Support: %s\n" L"KVA Shadowing with INVPCID Support: %s\n\n", kvaInfo.KvaShadowFlags.KvaShadowEnabled ? L"yes" : L"no", kvaInfo.KvaShadowFlags.KvaShadowUserGlobal ? L"yes" : L"no", kvaInfo.KvaShadowFlags.KvaShadowPcid ? L"yes" : L"no", kvaInfo.KvaShadowFlags.KvaShadowInvpcid ? L"yes" : L"no"); WriteConsole(hStdOut, stateBuffer, charsWritten, NULL, NULL);
// // Print status of Speculation Control Features // charsWritten = swprintf_s(stateBuffer, ARRAYSIZE(stateBuffer), L"BPB Enabled: %s\n" L"BPB Disabled due to System Policy: %s\n" L"BPB Disabled due to No Hardware Support: %s\n" L"Speculation Controls Enumerated: %s\n" L"Speculation Commands Enumerated: %s\n" L"IBRS Speculation Control Present: %s\n" L"STIBP Speculation Control Present: %s\n" L"Supervisor Mode Execution Prevention Present: %s\n", specInfo.SpeculationControlFlags.BpbEnabled ? L"yes" : L"no", specInfo.SpeculationControlFlags.BpbDisabledSystemPolicy ? L"yes" : L"no", specInfo.SpeculationControlFlags.BpbDisabledNoHardwareSupport ? L"yes" : L"no", specInfo.SpeculationControlFlags.SpecCtrlEnumerated ? L"yes" : L"no", specInfo.SpeculationControlFlags.SpecCmdEnumerated ? L"yes" : L"no", specInfo.SpeculationControlFlags.IbrsPresent ? L"yes" : L"no", specInfo.SpeculationControlFlags.StibpPresent ? L"yes" : L"no", specInfo.SpeculationControlFlags.SmepPresent ? L"yes" : L"no"); WriteConsole(hStdOut, stateBuffer, charsWritten, NULL, NULL);
// // This is our happy path // errorCode = SpcSuccess;
Exit: // // Close output handle if needed // if (hStdOut != INVALID_HANDLE_VALUE) { CloseHandle(hStdOut); }
// // Return the error code back to the caller, for debugging // return errorCode; }