Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion NightShiftUnlocker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
D51ED55F1ECDF7F10084868D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = FireWolf;
TargetAttributes = {
D51ED5671ECDF7F10084868D = {
Expand Down Expand Up @@ -239,13 +239,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -293,13 +295,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Empty file modified NightShiftUnlocker/Headers/capstone/arm.h
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions NightShiftUnlocker/Headers/capstone/arm64.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ typedef enum arm64_reg {

//> alias registers

ARM64_REG_IP1 = ARM64_REG_X16,
ARM64_REG_IP0 = ARM64_REG_X17,
ARM64_REG_IP0 = ARM64_REG_X16,
ARM64_REG_IP1 = ARM64_REG_X17,
ARM64_REG_FP = ARM64_REG_X29,
ARM64_REG_LR = ARM64_REG_X30,
} arm64_reg;
Expand Down
4 changes: 0 additions & 4 deletions NightShiftUnlocker/Headers/capstone/capstone.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
extern "C" {
#endif

#ifdef CAPSTONE_HAS_OSXKERNEL
#include <Headers/kern_compat.hpp>
#endif

#if !defined(_MSC_VER) || !defined(_KERNEL_MODE)
#include <stdint.h>
#endif
Expand Down
Empty file modified NightShiftUnlocker/Headers/capstone/mips.h
100755 → 100644
Empty file.
Empty file modified NightShiftUnlocker/Headers/capstone/platform.h
100755 → 100644
Empty file.
Empty file modified NightShiftUnlocker/Headers/capstone/ppc.h
100755 → 100644
Empty file.
Empty file modified NightShiftUnlocker/Headers/capstone/sparc.h
100755 → 100644
Empty file.
Empty file modified NightShiftUnlocker/Headers/capstone/systemz.h
100755 → 100644
Empty file.
Empty file modified NightShiftUnlocker/Headers/capstone/x86.h
100755 → 100644
Empty file.
Empty file modified NightShiftUnlocker/Headers/capstone/xcore.h
100755 → 100644
Empty file.
179 changes: 149 additions & 30 deletions NightShiftUnlocker/Headers/kern_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class LiluAPI {
* Initialise lilu api
*/
void init();

/**
* Deinitialise lilu api
*/
void deinit();

/**
* Errors returned by functions
*/
Expand All @@ -42,13 +42,13 @@ class LiluAPI {
TooLate,
Offline
};

/**
* Minimal API version that guarantees forward ABI compatibility
* Present due to lack of OSBundleCompatibleVersion at kext injection
*/
static constexpr size_t CompatibilityVersion {parseModuleVersion("1.2.0")};

/**
* Obtains api access by holding a lock, which is required when accessing out of the main context
*
Expand All @@ -58,7 +58,7 @@ class LiluAPI {
* @return Error::NoError on success
*/
EXPORT Error requestAccess(size_t version=CompatibilityVersion, bool check=false);

/**
* Releases api lock
*
Expand All @@ -71,12 +71,24 @@ class LiluAPI {
* It is assumed that single user mode is equal to normal, because it is generally
* used to continue the load of a complete OS, and by default Lilu itself ignores it.
*/
enum Requirements : uint32_t {
AllowNormal = 1,
AllowInstallerRecovery = 2,
AllowSafeMode = 4
enum RunningMode : uint32_t {
RunningNormal = 1,
AllowNormal = RunningNormal,
RunningInstallerRecovery = 2,
AllowInstallerRecovery = RunningInstallerRecovery,
RunningSafeMode = 4,
AllowSafeMode = RunningSafeMode
};

/**
* Obtain current run mode similarly to requirements
*
* @return run mode mask (RunningMode)
*/
inline uint32_t getRunMode() {
return currentRunMode;
}

/**
* Decides whether you are eligible to continue
*
Expand All @@ -96,15 +108,15 @@ class LiluAPI {
* @return Error::NoError on success
*/
EXPORT Error shouldLoad(const char *product, size_t version, uint32_t runmode, const char **disableArg, size_t disableArgNum, const char **debugArg, size_t debugArgNum, const char **betaArg, size_t betaArgNum, KernelVersion min, KernelVersion max, bool &printDebug);

/**
* Kernel patcher loaded callback
*
* @param user user provided pointer at registering
* @param patcher kernel patcher instance
*/
using t_patcherLoaded = void (*)(void *user, KernelPatcher &patcher);

/**
* Registers custom provided callbacks for later invocation on kernel patcher initialisation
*
Expand All @@ -114,7 +126,22 @@ class LiluAPI {
* @return Error::NoError on success
*/
EXPORT Error onPatcherLoad(t_patcherLoaded callback, void *user=nullptr);


/**
* Registers custom provided callbacks for later invocation on kernel patcher initialisation
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
*
* @param callback your callback function
* @param user your pointer that will be passed to the callback function
*
* @return Error::NoError on success
*/
inline void onPatcherLoadForce(t_patcherLoaded callback, void *user=nullptr) {
auto err = onPatcherLoad(callback, user);
if (err != Error::NoError)
PANIC("api", "onPatcherLoad failed with code %d", err);
}

/**
* Kext loaded callback
* Note that you will get notified of all the requested kexts for speed reasons
Expand All @@ -126,21 +153,53 @@ class LiluAPI {
* @param size loaded memory size
*/
using t_kextLoaded = void (*)(void *user, KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size);

/**
* Registers custom provided callbacks for later invocation on kext load
*
* @param infos your kext list (make sure to point to const memory)
* @param num number of provided kext entries
* @param callback your callback function
* @param callback your callback function (optional)
* @param user your pointer that will be passed to the callback function (optional)
*
* @return Error::NoError on success
*/
EXPORT Error onKextLoad(KernelPatcher::KextInfo *infos, size_t num=1, t_kextLoaded callback=nullptr, void *user=nullptr);

/**
* Registers custom provided callbacks for later invocation on kext load
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
*
* @param infos your kext list (make sure to point to const memory)
* @param num number of provided kext entries
* @param callback your callback function (optional)
* @param user your pointer that will be passed to the callback function (optional)
*
* @return Error::NoError on success
*/
inline void onKextLoadForce(KernelPatcher::KextInfo *infos, size_t num=1, t_kextLoaded callback=nullptr, void *user=nullptr) {
auto err = onKextLoad(infos, num, callback, user);
if (err != Error::NoError)
PANIC("api", "onKextLoad failed with code %d", err);
}

/**
* Registers custom provided callbacks for later invocation on binary load
*
* @param infos your binary list (make sure to point to const memory)
* @param num number of provided binary entries
* @param callback your callback function (could be null)
* @param user your pointer that will be passed to the callback function
* @param mods optional mod list (make sure to point to const memory)
* @param modnum number of provided mod entries
*
* @return Error::NoError on success
*/
EXPORT Error onKextLoad(KernelPatcher::KextInfo *infos, size_t num, t_kextLoaded callback, void *user=nullptr);
EXPORT Error onProcLoad(UserPatcher::ProcInfo *infos, size_t num=1, UserPatcher::t_BinaryLoaded callback=nullptr, void *user=nullptr, UserPatcher::BinaryModInfo *mods=nullptr, size_t modnum=0);

/**
* Registers custom provided callbacks for later invocation on binary load
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
*
* @param infos your binary list (make sure to point to const memory)
* @param num number of provided binary entries
Expand All @@ -151,7 +210,47 @@ class LiluAPI {
*
* @return Error::NoError on success
*/
EXPORT Error onProcLoad(UserPatcher::ProcInfo *infos, size_t num, UserPatcher::t_BinaryLoaded callback, void *user=nullptr, UserPatcher::BinaryModInfo *mods=nullptr, size_t modnum=0);
inline void onProcLoadForce(UserPatcher::ProcInfo *infos, size_t num=1, UserPatcher::t_BinaryLoaded callback=nullptr, void *user=nullptr, UserPatcher::BinaryModInfo *mods=nullptr, size_t modnum=0) {
auto err = onProcLoad(infos, num, callback, user, mods, modnum);
if (err != Error::NoError)
PANIC("api", "onProcLoad failed with code %d", err);
}

/**
* Kext loaded callback
* Note that you will get notified of all the requested kexts for speed reasons
*
* @param user user provided pointer at registering
* @param task task
* @param entitlement loaded kinfo id
* @param original original entitlement value
*/
using t_entitlementRequested = void (*)(void *user, task_t task, const char *entitlement, OSObject *&original);

/**
* Registers custom provided callbacks for later invocation on entitlement registration
*
* @param callback your callback function
* @param user your pointer that will be passed to the callback function
*
* @return Error::NoError on success
*/
EXPORT Error onEntitlementRequest(t_entitlementRequested callback, void *user=nullptr);

/**
* Registers custom provided callbacks for later invocation on entitlement registration
* Enforced version, which panics on registration failure (assuming your code cannot continue otherwise)
*
* @param callback your callback function
* @param user your pointer that will be passed to the callback function
*
* @return Error::NoError on success
*/
inline void onEntitlementRequestForce(t_entitlementRequested callback, void *user=nullptr) {
auto err = onEntitlementRequest(callback, user);
if (err != Error::NoError)
PANIC("api", "onEntitlementRequest failed with code %d", err);
}

/**
* Processes all the registered patcher load callbacks
Expand All @@ -170,14 +269,14 @@ class LiluAPI {
* @param reloadable kinfo could be unloaded
*/
void processKextLoadCallbacks(KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size, bool reloadable);

/**
* Processes all the registered user patcher load callbacks
*
* @param patcher user patcher instance
*/
void processUserLoadCallbacks(UserPatcher &patcher);

/**
* Processes all the registered binary load callbacks
*
Expand All @@ -187,17 +286,17 @@ class LiluAPI {
* @param len path length excluding null terminator
*/
void processBinaryLoadCallbacks(UserPatcher &patcher, vm_map_t map, const char *path, size_t len);

/**
* Activates patchers
*
* @param kpatcher kernel patcher instance
* @param upatcher user patcher instance
*/
void activate(KernelPatcher &kpatcher, UserPatcher &upatcher);

private:

/**
* Api lock
*/
Expand All @@ -212,48 +311,68 @@ class LiluAPI {
* No longer accept any requests
*/
bool apiRequestsOver {false};

/**
* Stores call function and user pointer
*/
template <typename T, typename Y=void *>
using stored_pair = ppair<T, Y>;

/**
* Stores multiple callbacks
*/
template <typename T, typename Y=void *>
using stored_vector = evector<stored_pair<T, Y> *, stored_pair<T, Y>::deleter>;

/**
* List of patcher callbacks
*/
stored_vector<t_patcherLoaded> patcherLoadedCallbacks;

/**
* List of kext callbacks
*/
stored_vector<t_kextLoaded> kextLoadedCallbacks;

/**
* List of binary callbacks
*/
stored_vector<UserPatcher::t_BinaryLoaded> binaryLoadedCallbacks;


/**
* List of entitlement callbacks
*/
stored_vector<t_entitlementRequested> entitlementRequestedCallbacks;

/**
* List of processed kexts
*/
stored_vector<KernelPatcher::KextInfo *, size_t> storedKexts;

/**
* List of processed procs
*/
evector<UserPatcher::ProcInfo *> storedProcs;

/**
* List of processed binary mods
*/
evector<UserPatcher::BinaryModInfo *> storedBinaryMods;

/**
* Copy client entitlement type (see IOUserClient)
*/
using t_copyClientEntitlement = OSObject *(*)(task_t, const char *);

/**
* Hooked entitlement copying method
*/
static OSObject *copyClientEntitlement(task_t task, const char *entitlement);

/**
* Trampoline for original entitlement copying method
*/
t_copyClientEntitlement orgCopyClientEntitlement {nullptr};
};

EXPORT extern LiluAPI lilu;
Expand Down
Loading