From 0c368de0e31d7381b832b2557b40c7bcf5c70a36 Mon Sep 17 00:00:00 2001 From: msuih Date: Fri, 19 Apr 2019 15:05:47 +0300 Subject: [PATCH] Print OS info to log Credit to @maximilian578 for help --- Utilities/Log.cpp | 11 +++++++++++ Utilities/sysinfo.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Utilities/sysinfo.h | 2 ++ 3 files changed, 52 insertions(+) diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 1d60e1b3fbb0..103e01e4be5a 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -602,6 +602,17 @@ logs::file_listener::file_listener(const std::string& name) file_writer::log(logs::level::always, ver.text.data(), ver.text.size()); file_writer::log(logs::level::always, "\n", 1); messages.emplace_back(std::move(ver)); + + // Write OS version + stored_message os; + os.m.ch = nullptr; + os.m.sev = level::notice; + os.stamp = 0; + os.text = utils::get_OS_version(); + + file_writer::log(logs::level::notice, os.text.data(), os.text.size()); + file_writer::log(logs::level::notice, "\n", 1); + messages.emplace_back(std::move(os)); } void logs::file_listener::log(u64 stamp, const logs::message& msg, const std::string& prefix, const std::string& _text) diff --git a/Utilities/sysinfo.cpp b/Utilities/sysinfo.cpp index 96226362dd51..dbd3434e0838 100644 --- a/Utilities/sysinfo.cpp +++ b/Utilities/sysinfo.cpp @@ -5,8 +5,11 @@ #ifdef _WIN32 #include "windows.h" +#include "sysinfoapi.h" #else #include +#include +#include #endif bool utils::has_ssse3() @@ -153,3 +156,39 @@ std::string utils::get_firmware_version() } return ""; } + +std::string utils::get_OS_version() +{ + std::string output = ""; +#ifdef _WIN32 + // GetVersionEx is deprecated, RtlGetVersion is kernel-mofe only and AnalyticsInfo is UWP only. + // So we're forced to read PEB instead to get Windows version info. It's ugly but works. + + const DWORD peb_offset = 0x60; + const INT_PTR peb = __readgsqword(peb_offset); + + const DWORD version_major = *reinterpret_cast(peb + 0x118); + const DWORD version_minor = *reinterpret_cast(peb + 0x11c); + const WORD build = *reinterpret_cast(peb + 0x120); + // FIXME: What is this thing? Pointer to UTF-16 string? Two bytes of version numbers? Some magic number? + const WORD service_pack = *reinterpret_cast(peb + 0x122); + const u64 compatibility_mode = *reinterpret_cast(peb + 0x02C8); // Two DWORDs, major & minor version + + fmt::append(output, + "Operating system: Windows, Major: %lu, Minor: %lu, Build: %u, Service Pack: %u, Compatibility mode: %llu", + version_major, version_minor, build, service_pack, compatibility_mode); +#else + struct utsname details = {}; + + if (!uname(&details)) + { + fmt::append(output, "Operating system: POSIX, Name: %s, Release: %s, Version: %s", + details.sysname, details.release, details.version); + } + else + { + fmt::append(output, "Operating system: POSIX, Unknown version! (Error: %d)", errno); + } +#endif + return output; +} diff --git a/Utilities/sysinfo.h b/Utilities/sysinfo.h index 5f2bc1f3ed4b..ba07c22a9f4d 100644 --- a/Utilities/sysinfo.h +++ b/Utilities/sysinfo.h @@ -46,4 +46,6 @@ namespace utils std::string get_system_info(); std::string get_firmware_version(); + + std::string get_OS_version(); }