Skip to content

Commit

Permalink
Allowed different plugins load the same kexts
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed May 5, 2017
1 parent 85e1517 commit 61e0be3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Lilu Changelog
#### v1.1.1
- Changed loading policy to ignore kexts that are not permitted to load
- Increased executable memory buffer from 256 to 1024 bytes
- Allowed different plugins load the same kexts

#### v1.1.0
- Added support for patching different sections/segments
Expand Down
11 changes: 8 additions & 3 deletions Lilu/Headers/kern_mach.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MachInfo {
off_t fat_offset {0}; // additional fat offset
size_t memory_size {HeaderSize}; // memory size
bool kaslr_slide_set {false}; // kaslr can be null, used for disambiguation
bool allow_decompress {true}; // allows mach decompression
bool allow_decompress {true}; // allows mach decompression

/**
* 16 byte IDT descriptor, used for 32 and 64 bits kernels (64 bit capable cpus!)
Expand Down Expand Up @@ -114,7 +114,7 @@ class MachInfo {
*/
void processMachHeader(void *header);

MachInfo(bool asKernel=false) : isKernel(asKernel) {
MachInfo(bool asKernel, const char *id) : isKernel(asKernel), objectId(id) {
DBGLOG("mach @ MachInfo asKernel %d object constructed", asKernel);
}
MachInfo(const MachInfo &) = delete;
Expand All @@ -131,6 +131,11 @@ class MachInfo {
* Representation mode (kernel/kext)
*/
EXPORT const bool isKernel;

/**
* Specified file identifier
*/
const char *objectId {nullptr};

/**
* MachInfo object generator
Expand All @@ -139,7 +144,7 @@ class MachInfo {
*
* @return MachInfo object or nullptr
*/
static MachInfo *create(bool asKernel=false) { return new MachInfo(asKernel); }
static MachInfo *create(bool asKernel=false, const char *id=nullptr) { return new MachInfo(asKernel, id); }
static void deleter(MachInfo *i) { delete i; }

/**
Expand Down
3 changes: 2 additions & 1 deletion Lilu/Headers/kern_patcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class KernelPatcher {
DisasmFailure,
MemoryIssue,
MemoryProtection,
PointerRange
PointerRange,
AlreadyDone
};

/**
Expand Down
3 changes: 2 additions & 1 deletion Lilu/Sources/kern_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ void LiluAPI::processPatcherLoadCallbacks(KernelPatcher &patcher) {
for (size_t j = 0; j < stored->second; j++) {
patcher.loadKinfo(&stored->first[j]);
if (patcher.getError() != KernelPatcher::Error::NoError) {
SYSLOG("api @ failed to load %s kext file", stored->first[j].id);
if (patcher.getError() != KernelPatcher::Error::AlreadyDone)
SYSLOG("api @ failed to load %s kext file", stored->first[j].id);
patcher.clearError();
// Depending on a system some kexts may actually not exist
continue;
Expand Down
12 changes: 10 additions & 2 deletions Lilu/Sources/kern_patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ void KernelPatcher::deinit() {
}

size_t KernelPatcher::loadKinfo(const char *id, const char * const paths[], size_t num, bool isKernel) {
auto info = MachInfo::create(isKernel);
for (size_t i = 0; i < kinfos.size(); i++) {
if (kinfos[i]->objectId && !strcmp(kinfos[i]->objectId, id)) {
DBGLOG("patcher @ found an already loaded MachInfo for %s at %zu", id, i);
code = Error::AlreadyDone;
return i;
}
}

auto info = MachInfo::create(isKernel, id);
if (!info) {
SYSLOG("patcher @ failed to allocate MachInfo for %s", id);
code = Error::MemoryIssue;
Expand Down Expand Up @@ -101,7 +109,7 @@ size_t KernelPatcher::loadKinfo(KernelPatcher::KextInfo *info) {
}

auto idx = loadKinfo(info->id, info->paths, info->pathNum);
if (getError() == Error::NoError) {
if (getError() == Error::NoError || getError() == Error::AlreadyDone) {
info->loadIndex = idx;
DBGLOG("patcher @ loaded kinfo %s at %zu index", info->id, idx);
}
Expand Down

0 comments on commit 61e0be3

Please sign in to comment.