Skip to content

Instantly share code, notes, and snippets.

@absoIute
Created September 30, 2023 20:46
Show Gist options
  • Save absoIute/b9ad780d76a123d9ea095e1cf79bf5a1 to your computer and use it in GitHub Desktop.
Save absoIute/b9ad780d76a123d9ea095e1cf79bf5a1 to your computer and use it in GitHub Desktop.
Simple Version Detection
#include "version_detect.h"
#include <Windows.h>
std::map<uint32_t, std::string> VersionDetect::s_buildMap =
{
{ 1419173053, "1.900" },
{ 1419880840, "1.910" },
{ 1421745341, "1.920" },
{ 1440638199, "2.000" },
{ 1440643927, "2.001" },
{ 1443053232, "2.010" },
{ 1443077847, "2.011" },
{ 1443077847, "2.020" },
{ 1484612867, "2.100" },
{ 1484626658, "2.101" },
{ 1484737207, "2.102" },
{ 1510526914, "2.110" },
{ 1510538091, "2.111" },
{ 1510619253, "2.112" },
{ 1511220108, "2.113" }
};
std::string VersionDetect::GetVersion()
{
HMODULE hMod = GetModuleHandle(nullptr);
PIMAGE_DOS_HEADER dos_header = (PIMAGE_DOS_HEADER)hMod;
if (dos_header->e_magic == IMAGE_DOS_SIGNATURE)
{
PIMAGE_NT_HEADERS nt_header = (IMAGE_NT_HEADERS *)((uintptr_t)hMod + dos_header->e_lfanew);
if (nt_header->Signature == IMAGE_NT_SIGNATURE)
{
auto it = s_buildMap.find(nt_header->FileHeader.TimeDateStamp);
if (it != s_buildMap.end())
return it->second;
}
}
return std::string();
}
#pragma once
#include <map>
#include <vector>
#include <string>
namespace VersionDetect
{
extern std::string GetVersion();
extern std::map<uint32_t, std::string> s_buildMap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment