Skip to content

Commit 61e0be3

Browse files
committed
Allowed different plugins load the same kexts
1 parent 85e1517 commit 61e0be3

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Lilu Changelog
44
#### v1.1.1
55
- Changed loading policy to ignore kexts that are not permitted to load
66
- Increased executable memory buffer from 256 to 1024 bytes
7+
- Allowed different plugins load the same kexts
78

89
#### v1.1.0
910
- Added support for patching different sections/segments

Lilu/Headers/kern_mach.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MachInfo {
3636
off_t fat_offset {0}; // additional fat offset
3737
size_t memory_size {HeaderSize}; // memory size
3838
bool kaslr_slide_set {false}; // kaslr can be null, used for disambiguation
39-
bool allow_decompress {true}; // allows mach decompression
39+
bool allow_decompress {true}; // allows mach decompression
4040

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

117-
MachInfo(bool asKernel=false) : isKernel(asKernel) {
117+
MachInfo(bool asKernel, const char *id) : isKernel(asKernel), objectId(id) {
118118
DBGLOG("mach @ MachInfo asKernel %d object constructed", asKernel);
119119
}
120120
MachInfo(const MachInfo &) = delete;
@@ -131,6 +131,11 @@ class MachInfo {
131131
* Representation mode (kernel/kext)
132132
*/
133133
EXPORT const bool isKernel;
134+
135+
/**
136+
* Specified file identifier
137+
*/
138+
const char *objectId {nullptr};
134139

135140
/**
136141
* MachInfo object generator
@@ -139,7 +144,7 @@ class MachInfo {
139144
*
140145
* @return MachInfo object or nullptr
141146
*/
142-
static MachInfo *create(bool asKernel=false) { return new MachInfo(asKernel); }
147+
static MachInfo *create(bool asKernel=false, const char *id=nullptr) { return new MachInfo(asKernel, id); }
143148
static void deleter(MachInfo *i) { delete i; }
144149

145150
/**

Lilu/Headers/kern_patcher.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class KernelPatcher {
3737
DisasmFailure,
3838
MemoryIssue,
3939
MemoryProtection,
40-
PointerRange
40+
PointerRange,
41+
AlreadyDone
4142
};
4243

4344
/**

Lilu/Sources/kern_api.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ void LiluAPI::processPatcherLoadCallbacks(KernelPatcher &patcher) {
210210
for (size_t j = 0; j < stored->second; j++) {
211211
patcher.loadKinfo(&stored->first[j]);
212212
if (patcher.getError() != KernelPatcher::Error::NoError) {
213-
SYSLOG("api @ failed to load %s kext file", stored->first[j].id);
213+
if (patcher.getError() != KernelPatcher::Error::AlreadyDone)
214+
SYSLOG("api @ failed to load %s kext file", stored->first[j].id);
214215
patcher.clearError();
215216
// Depending on a system some kexts may actually not exist
216217
continue;

Lilu/Sources/kern_patcher.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ void KernelPatcher::deinit() {
6464
}
6565

6666
size_t KernelPatcher::loadKinfo(const char *id, const char * const paths[], size_t num, bool isKernel) {
67-
auto info = MachInfo::create(isKernel);
67+
for (size_t i = 0; i < kinfos.size(); i++) {
68+
if (kinfos[i]->objectId && !strcmp(kinfos[i]->objectId, id)) {
69+
DBGLOG("patcher @ found an already loaded MachInfo for %s at %zu", id, i);
70+
code = Error::AlreadyDone;
71+
return i;
72+
}
73+
}
74+
75+
auto info = MachInfo::create(isKernel, id);
6876
if (!info) {
6977
SYSLOG("patcher @ failed to allocate MachInfo for %s", id);
7078
code = Error::MemoryIssue;
@@ -101,7 +109,7 @@ size_t KernelPatcher::loadKinfo(KernelPatcher::KextInfo *info) {
101109
}
102110

103111
auto idx = loadKinfo(info->id, info->paths, info->pathNum);
104-
if (getError() == Error::NoError) {
112+
if (getError() == Error::NoError || getError() == Error::AlreadyDone) {
105113
info->loadIndex = idx;
106114
DBGLOG("patcher @ loaded kinfo %s at %zu index", info->id, idx);
107115
}

0 commit comments

Comments
 (0)