From b8f2580cc6cb04f1958c90f529fb06269b7d2dc0 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Thu, 5 Apr 2018 19:25:36 +0300 Subject: [PATCH] Added version info reporting to IORegistry for Lilu and plugins --- Changelog.md | 1 + Lilu/Headers/kern_util.hpp | 51 +++++++++++++++++++++++++++++++++++ Lilu/Library/plugin_start.cpp | 12 +++++++++ Lilu/Sources/kern_start.cpp | 12 +++++++++ 4 files changed, 76 insertions(+) diff --git a/Changelog.md b/Changelog.md index 1d04d1e6..87a63aca 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ Lilu Changelog - Added address-printing macros - Added address validation API - Added strict kext UUID validation to workaround broken kextcache +- Added version info reporting to IORegistry for Lilu and plugins - Fixed several inline function definitions - Fixed crash when loading user patches with no binary patches - Reduced long patch length in function routing API diff --git a/Lilu/Headers/kern_util.hpp b/Lilu/Headers/kern_util.hpp index 0df2674e..c1884f33 100644 --- a/Lilu/Headers/kern_util.hpp +++ b/Lilu/Headers/kern_util.hpp @@ -586,4 +586,55 @@ class evector { } }; +/** + * Slightly non-standard helpers to get the date in a YYYY-MM-DD format. + */ +template +inline constexpr char getBuildYear() { + static_assert(i < 4, "Year consists of four digits"); + return __DATE__[7+i]; +} + +template +inline constexpr char getBuildMonth() { + static_assert(i < 2, "Month consists of two digits"); + auto mon = *reinterpret_cast(__DATE__); + switch (mon) { + case ' naJ': + return "01"[i]; + case ' beF': + return "02"[i]; + case ' raM': + return "03"[i]; + case ' rpA': + return "04"[i]; + case ' yaM': + return "05"[i]; + case ' nuJ': + return "06"[i]; + case ' luJ': + return "07"[i]; + case ' guA': + return "08"[i]; + case ' peS': + return "09"[i]; + case ' tcO': + return "10"[i]; + case ' voN': + return "11"[i]; + case ' ceD': + return "12"[i]; + } + + return '0'; +} + +template +inline constexpr char getBuildDay() { + static_assert(i < 2, "Day consists of two digits"); + if (i == 0 && __DATE__[4+i] == ' ') + return '0'; + return __DATE__[4+i]; +} + #endif /* kern_util_hpp */ diff --git a/Lilu/Library/plugin_start.cpp b/Lilu/Library/plugin_start.cpp index f415dee4..1fb035fe 100644 --- a/Lilu/Library/plugin_start.cpp +++ b/Lilu/Library/plugin_start.cpp @@ -20,12 +20,24 @@ bool ADDPR(debugEnabled) = false; #ifndef LILU_CUSTOM_IOKIT_INIT +static const char kextVersion[] { +#ifdef DEBUG + 'D', 'B', 'G', '-', +#else + 'R', 'E', 'L', '-', +#endif + xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-', + getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-', + getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0' +}; + OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService) PRODUCT_NAME *ADDPR(selfInstance) = nullptr; IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) { ADDPR(selfInstance) = this; + setProperty("VersionInfo", kextVersion); auto service = IOService::probe(provider, score); return ADDPR(startSuccess) ? service : nullptr; } diff --git a/Lilu/Sources/kern_start.cpp b/Lilu/Sources/kern_start.cpp index 9bb86f72..b07ba18c 100644 --- a/Lilu/Sources/kern_start.cpp +++ b/Lilu/Sources/kern_start.cpp @@ -18,7 +18,19 @@ OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService) +static const char kextVersion[] { +#ifdef DEBUG + 'D', 'B', 'G', '-', +#else + 'R', 'E', 'L', '-', +#endif + xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-', + getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-', + getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0' +}; + IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) { + setProperty("VersionInfo", kextVersion); auto service = IOService::probe(provider, score); return config.startSuccess ? service : nullptr; }