Skip to content

Commit

Permalink
Added version info reporting to IORegistry for Lilu and plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Apr 5, 2018
1 parent 22698e3 commit b8f2580
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions Lilu/Headers/kern_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,55 @@ class evector {
}
};

/**
* Slightly non-standard helpers to get the date in a YYYY-MM-DD format.
*/
template <size_t i>
inline constexpr char getBuildYear() {
static_assert(i < 4, "Year consists of four digits");
return __DATE__[7+i];
}

template <size_t i>
inline constexpr char getBuildMonth() {
static_assert(i < 2, "Month consists of two digits");
auto mon = *reinterpret_cast<const uint32_t *>(__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 <size_t i>
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 */
12 changes: 12 additions & 0 deletions Lilu/Library/plugin_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions Lilu/Sources/kern_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b8f2580

Please sign in to comment.