Skip to content

Commit

Permalink
Print OS info to log
Browse files Browse the repository at this point in the history
Credit to @Maximilian578 for help
  • Loading branch information
MSuih committed Apr 25, 2019
1 parent 2ade3c5 commit 0c368de
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Utilities/Log.cpp
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions Utilities/sysinfo.cpp
Expand Up @@ -5,8 +5,11 @@

#ifdef _WIN32
#include "windows.h"
#include "sysinfoapi.h"
#else
#include <unistd.h>
#include <sys/utsname.h>
#include <errno.h>
#endif

bool utils::has_ssse3()
Expand Down Expand Up @@ -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<const DWORD*>(peb + 0x118);
const DWORD version_minor = *reinterpret_cast<const DWORD*>(peb + 0x11c);
const WORD build = *reinterpret_cast<const WORD*>(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<const WORD*>(peb + 0x122);
const u64 compatibility_mode = *reinterpret_cast<const u64*>(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;
}
2 changes: 2 additions & 0 deletions Utilities/sysinfo.h
Expand Up @@ -46,4 +46,6 @@ namespace utils
std::string get_system_info();

std::string get_firmware_version();

std::string get_OS_version();
}

0 comments on commit 0c368de

Please sign in to comment.