Skip to content

Commit b8f2580

Browse files
committed
Added version info reporting to IORegistry for Lilu and plugins
1 parent 22698e3 commit b8f2580

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Lilu Changelog
1212
- Added address-printing macros
1313
- Added address validation API
1414
- Added strict kext UUID validation to workaround broken kextcache
15+
- Added version info reporting to IORegistry for Lilu and plugins
1516
- Fixed several inline function definitions
1617
- Fixed crash when loading user patches with no binary patches
1718
- Reduced long patch length in function routing API

Lilu/Headers/kern_util.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,4 +586,55 @@ class evector {
586586
}
587587
};
588588

589+
/**
590+
* Slightly non-standard helpers to get the date in a YYYY-MM-DD format.
591+
*/
592+
template <size_t i>
593+
inline constexpr char getBuildYear() {
594+
static_assert(i < 4, "Year consists of four digits");
595+
return __DATE__[7+i];
596+
}
597+
598+
template <size_t i>
599+
inline constexpr char getBuildMonth() {
600+
static_assert(i < 2, "Month consists of two digits");
601+
auto mon = *reinterpret_cast<const uint32_t *>(__DATE__);
602+
switch (mon) {
603+
case ' naJ':
604+
return "01"[i];
605+
case ' beF':
606+
return "02"[i];
607+
case ' raM':
608+
return "03"[i];
609+
case ' rpA':
610+
return "04"[i];
611+
case ' yaM':
612+
return "05"[i];
613+
case ' nuJ':
614+
return "06"[i];
615+
case ' luJ':
616+
return "07"[i];
617+
case ' guA':
618+
return "08"[i];
619+
case ' peS':
620+
return "09"[i];
621+
case ' tcO':
622+
return "10"[i];
623+
case ' voN':
624+
return "11"[i];
625+
case ' ceD':
626+
return "12"[i];
627+
}
628+
629+
return '0';
630+
}
631+
632+
template <size_t i>
633+
inline constexpr char getBuildDay() {
634+
static_assert(i < 2, "Day consists of two digits");
635+
if (i == 0 && __DATE__[4+i] == ' ')
636+
return '0';
637+
return __DATE__[4+i];
638+
}
639+
589640
#endif /* kern_util_hpp */

Lilu/Library/plugin_start.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ bool ADDPR(debugEnabled) = false;
2020

2121
#ifndef LILU_CUSTOM_IOKIT_INIT
2222

23+
static const char kextVersion[] {
24+
#ifdef DEBUG
25+
'D', 'B', 'G', '-',
26+
#else
27+
'R', 'E', 'L', '-',
28+
#endif
29+
xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-',
30+
getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-',
31+
getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0'
32+
};
33+
2334
OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)
2435

2536
PRODUCT_NAME *ADDPR(selfInstance) = nullptr;
2637

2738
IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) {
2839
ADDPR(selfInstance) = this;
40+
setProperty("VersionInfo", kextVersion);
2941
auto service = IOService::probe(provider, score);
3042
return ADDPR(startSuccess) ? service : nullptr;
3143
}

Lilu/Sources/kern_start.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,19 @@
1818

1919
OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)
2020

21+
static const char kextVersion[] {
22+
#ifdef DEBUG
23+
'D', 'B', 'G', '-',
24+
#else
25+
'R', 'E', 'L', '-',
26+
#endif
27+
xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-',
28+
getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-',
29+
getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0'
30+
};
31+
2132
IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) {
33+
setProperty("VersionInfo", kextVersion);
2234
auto service = IOService::probe(provider, score);
2335
return config.startSuccess ? service : nullptr;
2436
}

0 commit comments

Comments
 (0)