Skip to content

Commit 4113df2

Browse files
authored
Move kextVersion to Headers/kern_version.hpp for kexts only utilize Lilu API (#60)
1 parent e2b4ac8 commit 4113df2

File tree

5 files changed

+92
-81
lines changed

5 files changed

+92
-81
lines changed

Lilu.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
1C3E7B281C84B65400A6448A /* X86Disassembler.c in Sources */ = {isa = PBXBuildFile; fileRef = 1C3E7B131C84B65400A6448A /* X86Disassembler.c */; };
4646
1C3E7B291C84B65400A6448A /* X86BaseInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C3E7B141C84B65400A6448A /* X86BaseInfo.h */; };
4747
1C3E7B2A1C84B65400A6448A /* X86ATTInstPrinter.c in Sources */ = {isa = PBXBuildFile; fileRef = 1C3E7B151C84B65400A6448A /* X86ATTInstPrinter.c */; };
48+
6F86FA742526419900D37571 /* kern_version.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 6F86FA732526419900D37571 /* kern_version.hpp */; };
4849
CE1096261F22876B00B623FC /* umm_malloc.c in Sources */ = {isa = PBXBuildFile; fileRef = CE10961E1F22876B00B623FC /* umm_malloc.c */; };
4950
CE1096271F22876B00B623FC /* umm_malloc.h in Headers */ = {isa = PBXBuildFile; fileRef = CE10961F1F22876B00B623FC /* umm_malloc.h */; };
5051
CE2687F5213BC02900E17BDD /* kern_ubsan.c in Sources */ = {isa = PBXBuildFile; fileRef = CE2687F4213BC02900E17BDD /* kern_ubsan.c */; };
@@ -140,6 +141,7 @@
140141
1C3E7B151C84B65400A6448A /* X86ATTInstPrinter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = X86ATTInstPrinter.c; path = capstone/arch/X86/X86ATTInstPrinter.c; sourceTree = "<group>"; };
141142
1C748C271C21952C0024EED2 /* Lilu.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Lilu.kext; sourceTree = BUILT_PRODUCTS_DIR; };
142143
1C748C2E1C21952C0024EED2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Lilu/Info.plist; sourceTree = "<group>"; };
144+
6F86FA732526419900D37571 /* kern_version.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kern_version.hpp; sourceTree = "<group>"; };
143145
CE10961E1F22876B00B623FC /* umm_malloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = umm_malloc.c; sourceTree = "<group>"; };
144146
CE10961F1F22876B00B623FC /* umm_malloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = umm_malloc.h; sourceTree = "<group>"; };
145147
CE22EA372037A4BB002A88A5 /* kern_cpu.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_cpu.hpp; sourceTree = "<group>"; };
@@ -354,6 +356,7 @@
354356
CE335AE32097442500C60A5F /* kern_rtc.hpp */,
355357
CE2E7B901E2C6A73009AC62A /* kern_user.hpp */,
356358
CE2E7B921E2C6A73009AC62A /* kern_util.hpp */,
359+
6F86FA732526419900D37571 /* kern_version.hpp */,
357360
CE405ED41E4A005400AA0B3D /* plugin_start.hpp */,
358361
);
359362
name = Headers;
@@ -491,6 +494,7 @@
491494
1C3E7AE91C84B61700A6448A /* utils.h in Headers */,
492495
1C3E7AFB1C84B63000A6448A /* mips.h in Headers */,
493496
1C3E7ADE1C84B61700A6448A /* MCDisassembler.h in Headers */,
497+
6F86FA742526419900D37571 /* kern_version.hpp in Headers */,
494498
1C3E7AFE1C84B63000A6448A /* arm.h in Headers */,
495499
1C3E7ADF1C84B61700A6448A /* MCFixedLenDisassembler.h in Headers */,
496500
CE1096271F22876B00B623FC /* umm_malloc.h in Headers */,

Lilu/Headers/kern_util.hpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -880,58 +880,4 @@ class evector_base {
880880
template <typename T, void (*deleter)(T)=emptyDeleter<T>>
881881
class evector : public evector_base<typename remove_reference<T>::type, T, deleter> { };
882882

883-
/**
884-
* Slightly non-standard helpers to get the date in a YYYY-MM-DD format.
885-
*/
886-
template <size_t i>
887-
inline constexpr char getBuildYear() {
888-
static_assert(i < 4, "Year consists of four digits");
889-
return __DATE__[7+i];
890-
}
891-
892-
template <size_t i>
893-
inline constexpr char getBuildMonth() {
894-
static_assert(i < 2, "Month consists of two digits");
895-
auto mon = static_cast<uint32_t>(__DATE__[0])
896-
| (static_cast<uint32_t>(__DATE__[1]) << 8U)
897-
| (static_cast<uint32_t>(__DATE__[2]) << 16U)
898-
| (static_cast<uint32_t>(__DATE__[3]) << 24U);
899-
switch (mon) {
900-
case ' naJ':
901-
return "01"[i];
902-
case ' beF':
903-
return "02"[i];
904-
case ' raM':
905-
return "03"[i];
906-
case ' rpA':
907-
return "04"[i];
908-
case ' yaM':
909-
return "05"[i];
910-
case ' nuJ':
911-
return "06"[i];
912-
case ' luJ':
913-
return "07"[i];
914-
case ' guA':
915-
return "08"[i];
916-
case ' peS':
917-
return "09"[i];
918-
case ' tcO':
919-
return "10"[i];
920-
case ' voN':
921-
return "11"[i];
922-
case ' ceD':
923-
return "12"[i];
924-
default:
925-
return '0';
926-
}
927-
}
928-
929-
template <size_t i>
930-
inline constexpr char getBuildDay() {
931-
static_assert(i < 2, "Day consists of two digits");
932-
if (i == 0 && __DATE__[4+i] == ' ')
933-
return '0';
934-
return __DATE__[4+i];
935-
}
936-
937883
#endif /* kern_util_hpp */

Lilu/Headers/kern_version.hpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// kern_version.hpp
3+
// Lilu
4+
//
5+
// Copyright © 2016-2020 vit9696. All rights reserved.
6+
//
7+
8+
#ifndef kern_version_hpp
9+
#define kern_version_hpp
10+
11+
#include <Headers/kern_util.hpp>
12+
13+
#include <stdint.h>
14+
#include <sys/types.h>
15+
16+
/**
17+
* Slightly non-standard helpers to get the date in a YYYY-MM-DD format.
18+
*/
19+
template <size_t i>
20+
inline constexpr char getBuildYear() {
21+
static_assert(i < 4, "Year consists of four digits");
22+
return __DATE__[7+i];
23+
}
24+
25+
template <size_t i>
26+
inline constexpr char getBuildMonth() {
27+
static_assert(i < 2, "Month consists of two digits");
28+
auto mon = static_cast<uint32_t>(__DATE__[0])
29+
| (static_cast<uint32_t>(__DATE__[1]) << 8U)
30+
| (static_cast<uint32_t>(__DATE__[2]) << 16U)
31+
| (static_cast<uint32_t>(__DATE__[3]) << 24U);
32+
switch (mon) {
33+
case ' naJ':
34+
return "01"[i];
35+
case ' beF':
36+
return "02"[i];
37+
case ' raM':
38+
return "03"[i];
39+
case ' rpA':
40+
return "04"[i];
41+
case ' yaM':
42+
return "05"[i];
43+
case ' nuJ':
44+
return "06"[i];
45+
case ' luJ':
46+
return "07"[i];
47+
case ' guA':
48+
return "08"[i];
49+
case ' peS':
50+
return "09"[i];
51+
case ' tcO':
52+
return "10"[i];
53+
case ' voN':
54+
return "11"[i];
55+
case ' ceD':
56+
return "12"[i];
57+
default:
58+
return '0';
59+
}
60+
}
61+
62+
template <size_t i>
63+
inline constexpr char getBuildDay() {
64+
static_assert(i < 2, "Day consists of two digits");
65+
if (i == 0 && __DATE__[4+i] == ' ')
66+
return '0';
67+
return __DATE__[4+i];
68+
}
69+
70+
#if !defined(LILU_CUSTOM_KMOD_INIT) || !defined(LILU_CUSTOM_IOKIT_INIT)
71+
72+
static const char kextVersion[] {
73+
#ifdef DEBUG
74+
'D', 'B', 'G', '-',
75+
#else
76+
'R', 'E', 'L', '-',
77+
#endif
78+
xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-',
79+
getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-',
80+
getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0'
81+
};
82+
83+
#endif
84+
85+
#endif /* kern_version_hpp */

Lilu/Library/plugin_start.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,18 @@
88
#include <Headers/plugin_start.hpp>
99
#include <Headers/kern_api.hpp>
1010
#include <Headers/kern_util.hpp>
11+
#include <Headers/kern_version.hpp>
1112

1213
#ifndef LILU_CUSTOM_KMOD_INIT
1314
bool ADDPR(startSuccess) = false;
1415
#else
1516
// Workaround custom kmod code and enable by default
1617
bool ADDPR(startSuccess) = true;
17-
#endif
18+
#endif /* LILU_CUSTOM_KMOD_INIT */
1819

1920
bool ADDPR(debugEnabled) = false;
2021
uint32_t ADDPR(debugPrintDelay) = 0;
2122

22-
#if !defined(LILU_CUSTOM_KMOD_INIT) || !defined(LILU_CUSTOM_IOKIT_INIT)
23-
24-
static const char kextVersion[] {
25-
#ifdef DEBUG
26-
'D', 'B', 'G', '-',
27-
#else
28-
'R', 'E', 'L', '-',
29-
#endif
30-
xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-',
31-
getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-',
32-
getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0'
33-
};
34-
35-
#endif
36-
3723
#ifndef LILU_CUSTOM_IOKIT_INIT
3824

3925
OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)

Lilu/Sources/kern_start.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,14 @@
1616
#include <Headers/kern_cpu.hpp>
1717
#include <Headers/kern_file.hpp>
1818
#include <Headers/kern_time.hpp>
19+
#include <Headers/kern_version.hpp>
1920

2021
#include <IOKit/IOLib.h>
2122
#include <IOKit/IORegistryEntry.h>
2223
#include <mach/mach_types.h>
2324

2425
OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)
2526

26-
static const char kextVersion[] {
27-
#ifdef DEBUG
28-
'D', 'B', 'G', '-',
29-
#else
30-
'R', 'E', 'L', '-',
31-
#endif
32-
xStringify(MODULE_VERSION)[0], xStringify(MODULE_VERSION)[2], xStringify(MODULE_VERSION)[4], '-',
33-
getBuildYear<0>(), getBuildYear<1>(), getBuildYear<2>(), getBuildYear<3>(), '-',
34-
getBuildMonth<0>(), getBuildMonth<1>(), '-', getBuildDay<0>(), getBuildDay<1>(), '\0'
35-
};
36-
3727
IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) {
3828
setProperty("VersionInfo", kextVersion);
3929
auto service = IOService::probe(provider, score);

0 commit comments

Comments
 (0)