Skip to content

Instantly share code, notes, and snippets.

@slaeryan

slaeryan/GetOSVersion.h

Last active May 16, 2021
Embed
What would you like to do?
#pragma once
#include <Windows.h>
// Ref: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/structs/kuser_shared_data/index.htm
#define KUSER_SHARED_DATA 0x7ffe0000
#define MAJOR_VERSION_OFFSET 0x026C
#define MINOR_VERSION_OFFSET 0x0270
#define BUILD_NUMBER_OFFSET 0x0260
void get_os_version() {
PULONG pMajorVersion = (PULONG)(KUSER_SHARED_DATA + MAJOR_VERSION_OFFSET);
PULONG pMinorVersion = (PULONG)(KUSER_SHARED_DATA + MINOR_VERSION_OFFSET);
PULONG pBuildNumber = (PULONG)(KUSER_SHARED_DATA + BUILD_NUMBER_OFFSET);
// Get values using pointer deferencing
ULONG majorVersion = (*pMajorVersion);
ULONG minorVersion = (*pMinorVersion);
ULONG buildNumber = (*pBuildNumber);
// [DEBUG]
printf("[+] OS Major Version: %d\n", majorVersion);
printf("[+] OS Minor Version: %d\n", minorVersion);
printf("[+] OS Build Number: %d\n", buildNumber);
// Determine OS Version using above-mentioned values
if (majorVersion == 10 && minorVersion == 0) {
printf("[+] Windows 10 / Server 2016\n");
}
else if (majorVersion == 6 && minorVersion == 1 && buildNumber == 7601) {
printf("[+] Windows 7 SP1 / Server 2008 R2\n");
}
else if (majorVersion == 6 && minorVersion == 2) {
printf("[+] Windows 8 / Server 2012\n");
}
else if (majorVersion == 6 && minorVersion == 3) {
printf("[+] Windows 8.1 / Server 2012 R2\n");
}
else {
printf("[-] Unsupported!\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment