Skip to content

Commit 52d4af7

Browse files
committed
1. Removed unimplemented genPlatformKey API
2. Applied several cleanups and minor bugfixes thx to static analysis
1 parent c1dec53 commit 52d4af7

23 files changed

+242
-183
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
.scannerwork
23
DerivedData
34
Lilu.kext
45
xcuserdata

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Lilu Changelog
33

44
#### v1.3.0
55
- Fixed a rare kernel panic on user patch failure
6+
- Removed unimplemented `genPlatformKey` API
67

78
#### v1.2.9
89
- Added `kern_atomic.hpp` header to support atomic types with old Clang

Lilu/Headers/kern_crypto.hpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,7 @@ namespace Crypto {
5151
while (len--)
5252
*vptr++ = '\0';
5353
}
54-
55-
/**
56-
* Generates a platform specific encryption key to be used for later encryption/decryption.
57-
* Use very cautiously, this generates a key that should be reproducible on the same hardware.
58-
* This means that the key is NOT meant protect the data from decryption on the same machine,
59-
* but it only tries to circumvent cases when some blobs containing sensitive information
60-
* (e.g. nvram dumps) were accidentally shared.
61-
*
62-
* This is currently UNIMPLEMENTED
63-
*
64-
* @param seed prefixed data blob used for key generation
65-
* @param size seed size
66-
*
67-
* @return generated key of at least BlockSize bits long (must be freeded by Buffer::deleter) or nullptr
68-
*/
69-
EXPORT uint8_t *genPlatformKey(const uint8_t *seed=nullptr, uint32_t size=0);
70-
54+
7155
/**
7256
* Generates cryptographically secure encryption key (from /dev/random)
7357
*
@@ -78,7 +62,7 @@ namespace Crypto {
7862
/**
7963
* Encrypts data of specified size and stores in Encrypted format
8064
*
81-
* @param key encryption key returned by genUniqueKey, genPlatformKey (default if null)
65+
* @param key encryption key returned by genUniqueKey
8266
* @param src source data
8367
* @param size data size, encrypted size is returned on success
8468
*
@@ -89,7 +73,7 @@ namespace Crypto {
8973
/**
9074
* Decrypts data of specified size stored in Encrypted format
9175
*
92-
* @param key encryption key returned by genUniqueKey, genPlatformKey (default if null)
76+
* @param key encryption key returned by genUniqueKey
9377
* @param src source data
9478
* @param size data size, decrypted size is returned on success
9579
*

Lilu/Headers/kern_iokit.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace WIOKit {
1919

2020
/**
21-
* AppleHDAEngine::getLocation teaches us to use while(1) when talking to IOReg
21+
* AppleHDAEngine::getLocation teaches us to use loop infinitely when talking to IOReg
2222
* This feels mad and insane, since it may prevent the system from booting.
2323
* Although this had never happened, we will use a far bigger fail-safe stop value.
2424
*/

Lilu/Headers/kern_patcher.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class KernelPatcher {
291291
*
292292
* @param patch patch to apply
293293
* @param startingAddress start with this address (or kext/kernel lowest address)
294-
* @param maxSize maximum size to look for (or kext/kernel max size)
294+
* @param maxSize maximum size to lookup (or kext/kernel max size)
295295
*/
296296
EXPORT void applyLookupPatch(const LookupPatch *patch, uint8_t *startingAddress, size_t maxSize);
297297
#endif /* LILU_KEXTPATCH_SUPPORT */

Lilu/Headers/kern_user.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,10 @@ class UserPatcher {
483483
* @param action passed action, we only need KAUTH_FILEOP_EXEC
484484
* @param arg0 pointer to vnode (vnode *) for executable
485485
* @param arg1 pointer to path (char *) to executable
486-
* @param arg2 unused
487-
* @param arg3 unsed
488486
*
489487
* @return 0 to allow further execution
490488
*/
491-
static int execListener(kauth_cred_t credential, void *idata, kauth_action_t action, uintptr_t arg0, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3);
489+
static int execListener(kauth_cred_t /* credential */, void *idata, kauth_action_t action, uintptr_t /* arg0 */, uintptr_t arg1, uintptr_t, uintptr_t);
492490

493491
/**
494492
* Unrestricted vm_protect, that takes care of Mojave codesign limitations for everyone's good.

Lilu/Headers/kern_util.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ class ThreadLocal {
672672
* Use this deleter when storing scalar types
673673
*/
674674
template <typename T>
675-
static void emptyDeleter(T) {}
675+
static void emptyDeleter(T) { /* no dynamic alloc */ }
676676

677677
template <typename T, typename Y, void (*deleterT)(T)=emptyDeleter<T>, void (*deleterY)(Y)=emptyDeleter<Y>>
678678
struct ppair {
@@ -761,13 +761,13 @@ class evector {
761761
*
762762
* @return elements ptr or null
763763
*/
764-
template <size_t Mul = 1>
764+
template <size_t MUL = 1>
765765
T *reserve(size_t num) {
766766
if (rsvd < num) {
767-
T *nPtr = static_cast<T *>(kern_os_realloc(ptr, Mul * num * sizeof(T)));
767+
T *nPtr = static_cast<T *>(kern_os_realloc(ptr, MUL * num * sizeof(T)));
768768
if (nPtr) {
769769
ptr = nPtr;
770-
rsvd = Mul * num;
770+
rsvd = MUL * num;
771771
} else {
772772
return nullptr;
773773
}
@@ -804,9 +804,9 @@ class evector {
804804
*
805805
* @return true on success
806806
*/
807-
template <size_t Mul = 1>
807+
template <size_t MUL = 1>
808808
bool push_back(T &element) {
809-
if (reserve<Mul>(cnt+1)) {
809+
if (reserve<MUL>(cnt+1)) {
810810
ptr[cnt] = element;
811811
cnt++;
812812
return true;
@@ -823,9 +823,9 @@ class evector {
823823
*
824824
* @return true on success
825825
*/
826-
template <size_t Mul = 1>
826+
template <size_t MUL = 1>
827827
bool push_back(T &&element) {
828-
if (reserve<Mul>(cnt+1)) {
828+
if (reserve<MUL>(cnt+1)) {
829829
ptr[cnt] = element;
830830
cnt++;
831831
return true;
@@ -891,9 +891,9 @@ inline constexpr char getBuildMonth() {
891891
return "11"[i];
892892
case ' ceD':
893893
return "12"[i];
894+
default:
895+
return '0';
894896
}
895-
896-
return '0';
897897
}
898898

899899
template <size_t i>

Lilu/PrivateHeaders/kern_config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Configuration {
8686
*
8787
* @return 0 on success
8888
*/
89-
static int policyCredCheckLabelUpdateExecve(kauth_cred_t old, vnode_t vp, ...);
89+
static int policyCredCheckLabelUpdateExecve(kauth_cred_t, vnode_t, ...);
9090

9191
/**
9292
* TrustedBSD policy called before remounting
@@ -95,7 +95,7 @@ class Configuration {
9595
* @param mp mount point
9696
* @param mlabel mount point label
9797
*/
98-
static int policyCheckRemount(kauth_cred_t cred, mount *mp, label *mlabel);
98+
static int policyCheckRemount(kauth_cred_t, mount *, label *);
9999

100100
/**
101101
* TrustedBSD policy options

Lilu/PrivateHeaders/kern_patcher.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ namespace Patch {
4242

4343
template <typename T>
4444
static void writeType(mach_vm_address_t addr, T value) {
45-
// Completely forbidden to IOLog with disabled interrupts as of High Sierra
46-
// DBGLOG("private @ writing to %X value of %lu which is %X", static_cast<uint32_t>(addr), sizeof(T), (unsigned int)value);
45+
// It is completely forbidden to IOLog with disabled interrupts as of High Sierra, yet DBGLOG may bypass it if needed.
4746
*reinterpret_cast<T *>(addr) = value;
4847
}
4948

@@ -66,11 +65,11 @@ namespace Patch {
6665
};
6766

6867
union All {
69-
All(P<Variant::U8> &&v) : u8(v) {}
70-
All(P<Variant::U16> &&v) : u16(v) {}
71-
All(P<Variant::U32> &&v) : u32(v) {}
72-
All(P<Variant::U64> &&v) : u64(v) {}
73-
All(P<Variant::U128> &&v) : u128(v) {}
68+
explicit All(P<Variant::U8> &&v) : u8(v) {}
69+
explicit All(P<Variant::U16> &&v) : u16(v) {}
70+
explicit All(P<Variant::U32> &&v) : u32(v) {}
71+
explicit All(P<Variant::U64> &&v) : u64(v) {}
72+
explicit All(P<Variant::U128> &&v) : u128(v) {}
7473

7574
P<Variant::U8> u8;
7675
P<Variant::U16> u16;

Lilu/Sources/kern_api.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ LiluAPI::Error LiluAPI::onPatcherLoad(t_patcherLoaded callback, void *user) {
119119

120120
if (!patcherLoadedCallbacks.push_back<2>(pcall)) {
121121
SYSLOG("api", "failed to store stored_pair<t_patcherLoaded>");
122-
pcall->deleter(pcall);
122+
stored_pair<t_patcherLoaded>::deleter(pcall);
123123
return Error::MemoryError;
124124
}
125125

@@ -141,7 +141,7 @@ LiluAPI::Error LiluAPI::onKextLoad(KernelPatcher::KextInfo *infos, size_t num, t
141141

142142
if (!kextLoadedCallbacks.push_back<4>(pcall)) {
143143
SYSLOG("api", "failed to store stored_pair<t_kextLoaded>");
144-
pcall->deleter(pcall);
144+
stored_pair<t_kextLoaded>::deleter(pcall);
145145
return Error::MemoryError;
146146
}
147147
}
@@ -160,7 +160,7 @@ LiluAPI::Error LiluAPI::onKextLoad(KernelPatcher::KextInfo *infos, size_t num, t
160160

161161
if (!storedKexts.push_back<4>(pkext)) {
162162
SYSLOG("api", "failed to store stored_pair<KextInfo>");
163-
pkext->deleter(pkext);
163+
stored_pair<KernelPatcher::KextInfo *, size_t>::deleter(pkext);
164164
return Error::MemoryError;
165165
}
166166
}
@@ -169,10 +169,7 @@ LiluAPI::Error LiluAPI::onKextLoad(KernelPatcher::KextInfo *infos, size_t num, t
169169
}
170170

171171
LiluAPI::Error LiluAPI::onProcLoad(UserPatcher::ProcInfo *infos, size_t num, UserPatcher::t_BinaryLoaded callback, void *user, UserPatcher::BinaryModInfo *mods, size_t modnum) {
172-
// It seems to partially work
173-
// Offer no support for user patcher before 10.9
174-
//if (getKernelVersion() <= KernelVersion::MountainLion)
175-
// return Error::IncompatibleOS;
172+
// We do not officially support user patcher prior to 10.9, yet it seems to partially work
176173

177174
// Store the callbacks
178175
if (callback) {
@@ -188,7 +185,7 @@ LiluAPI::Error LiluAPI::onProcLoad(UserPatcher::ProcInfo *infos, size_t num, Use
188185

189186
if (!binaryLoadedCallbacks.push_back<2>(pcall)) {
190187
SYSLOG("api", "failed to store stored_pair<t_binaryLoaded>");
191-
pcall->deleter(pcall);
188+
stored_pair<UserPatcher::t_BinaryLoaded>::deleter(pcall);
192189
return Error::MemoryError;
193190
}
194191
}
@@ -226,7 +223,7 @@ LiluAPI::Error LiluAPI::onEntitlementRequest(t_entitlementRequested callback, vo
226223

227224
if (!entitlementRequestedCallbacks.push_back<2>(ecall)) {
228225
SYSLOG("api", "failed to store stored_pair<t_entitlementRequested>");
229-
ecall->deleter(ecall);
226+
stored_pair<t_entitlementRequested>::deleter(ecall);
230227
return Error::MemoryError;
231228
}
232229

0 commit comments

Comments
 (0)