Skip to content

Commit

Permalink
Move kextVersion to Headers/kern_version.hpp for kexts only utilize L…
Browse files Browse the repository at this point in the history
…ilu API (#60)
  • Loading branch information
zhen-zen authored Oct 1, 2020
1 parent e2b4ac8 commit 4113df2
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 81 deletions.
4 changes: 4 additions & 0 deletions Lilu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
1C3E7B281C84B65400A6448A /* X86Disassembler.c in Sources */ = {isa = PBXBuildFile; fileRef = 1C3E7B131C84B65400A6448A /* X86Disassembler.c */; };
1C3E7B291C84B65400A6448A /* X86BaseInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C3E7B141C84B65400A6448A /* X86BaseInfo.h */; };
1C3E7B2A1C84B65400A6448A /* X86ATTInstPrinter.c in Sources */ = {isa = PBXBuildFile; fileRef = 1C3E7B151C84B65400A6448A /* X86ATTInstPrinter.c */; };
6F86FA742526419900D37571 /* kern_version.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 6F86FA732526419900D37571 /* kern_version.hpp */; };
CE1096261F22876B00B623FC /* umm_malloc.c in Sources */ = {isa = PBXBuildFile; fileRef = CE10961E1F22876B00B623FC /* umm_malloc.c */; };
CE1096271F22876B00B623FC /* umm_malloc.h in Headers */ = {isa = PBXBuildFile; fileRef = CE10961F1F22876B00B623FC /* umm_malloc.h */; };
CE2687F5213BC02900E17BDD /* kern_ubsan.c in Sources */ = {isa = PBXBuildFile; fileRef = CE2687F4213BC02900E17BDD /* kern_ubsan.c */; };
Expand Down Expand Up @@ -140,6 +141,7 @@
1C3E7B151C84B65400A6448A /* X86ATTInstPrinter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = X86ATTInstPrinter.c; path = capstone/arch/X86/X86ATTInstPrinter.c; sourceTree = "<group>"; };
1C748C271C21952C0024EED2 /* Lilu.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Lilu.kext; sourceTree = BUILT_PRODUCTS_DIR; };
1C748C2E1C21952C0024EED2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Lilu/Info.plist; sourceTree = "<group>"; };
6F86FA732526419900D37571 /* kern_version.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kern_version.hpp; sourceTree = "<group>"; };
CE10961E1F22876B00B623FC /* umm_malloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = umm_malloc.c; sourceTree = "<group>"; };
CE10961F1F22876B00B623FC /* umm_malloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = umm_malloc.h; sourceTree = "<group>"; };
CE22EA372037A4BB002A88A5 /* kern_cpu.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_cpu.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -354,6 +356,7 @@
CE335AE32097442500C60A5F /* kern_rtc.hpp */,
CE2E7B901E2C6A73009AC62A /* kern_user.hpp */,
CE2E7B921E2C6A73009AC62A /* kern_util.hpp */,
6F86FA732526419900D37571 /* kern_version.hpp */,
CE405ED41E4A005400AA0B3D /* plugin_start.hpp */,
);
name = Headers;
Expand Down Expand Up @@ -491,6 +494,7 @@
1C3E7AE91C84B61700A6448A /* utils.h in Headers */,
1C3E7AFB1C84B63000A6448A /* mips.h in Headers */,
1C3E7ADE1C84B61700A6448A /* MCDisassembler.h in Headers */,
6F86FA742526419900D37571 /* kern_version.hpp in Headers */,
1C3E7AFE1C84B63000A6448A /* arm.h in Headers */,
1C3E7ADF1C84B61700A6448A /* MCFixedLenDisassembler.h in Headers */,
CE1096271F22876B00B623FC /* umm_malloc.h in Headers */,
Expand Down
54 changes: 0 additions & 54 deletions Lilu/Headers/kern_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,58 +880,4 @@ class evector_base {
template <typename T, void (*deleter)(T)=emptyDeleter<T>>
class evector : public evector_base<typename remove_reference<T>::type, T, deleter> { };

/**
* 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 = static_cast<uint32_t>(__DATE__[0])
| (static_cast<uint32_t>(__DATE__[1]) << 8U)
| (static_cast<uint32_t>(__DATE__[2]) << 16U)
| (static_cast<uint32_t>(__DATE__[3]) << 24U);
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];
default:
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 */
85 changes: 85 additions & 0 deletions Lilu/Headers/kern_version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// kern_version.hpp
// Lilu
//
// Copyright © 2016-2020 vit9696. All rights reserved.
//

#ifndef kern_version_hpp
#define kern_version_hpp

#include <Headers/kern_util.hpp>

#include <stdint.h>
#include <sys/types.h>

/**
* 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 = static_cast<uint32_t>(__DATE__[0])
| (static_cast<uint32_t>(__DATE__[1]) << 8U)
| (static_cast<uint32_t>(__DATE__[2]) << 16U)
| (static_cast<uint32_t>(__DATE__[3]) << 24U);
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];
default:
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];
}

#if !defined(LILU_CUSTOM_KMOD_INIT) || !defined(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'
};

#endif

#endif /* kern_version_hpp */
18 changes: 2 additions & 16 deletions Lilu/Library/plugin_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@
#include <Headers/plugin_start.hpp>
#include <Headers/kern_api.hpp>
#include <Headers/kern_util.hpp>
#include <Headers/kern_version.hpp>

#ifndef LILU_CUSTOM_KMOD_INIT
bool ADDPR(startSuccess) = false;
#else
// Workaround custom kmod code and enable by default
bool ADDPR(startSuccess) = true;
#endif
#endif /* LILU_CUSTOM_KMOD_INIT */

bool ADDPR(debugEnabled) = false;
uint32_t ADDPR(debugPrintDelay) = 0;

#if !defined(LILU_CUSTOM_KMOD_INIT) || !defined(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'
};

#endif

#ifndef LILU_CUSTOM_IOKIT_INIT

OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)
Expand Down
12 changes: 1 addition & 11 deletions Lilu/Sources/kern_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,14 @@
#include <Headers/kern_cpu.hpp>
#include <Headers/kern_file.hpp>
#include <Headers/kern_time.hpp>
#include <Headers/kern_version.hpp>

#include <IOKit/IOLib.h>
#include <IOKit/IORegistryEntry.h>
#include <mach/mach_types.h>

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);
Expand Down

0 comments on commit 4113df2

Please sign in to comment.