EFI config backup

This commit is contained in:
2022-03-29 10:26:33 +03:00
parent 03b8035141
commit 24449516c0
96 changed files with 33899 additions and 0 deletions

View File

@ -0,0 +1,99 @@
//
// plugin_start.cpp
// Lilu
//
// Copyright © 2016-2017 vit9696. All rights reserved.
//
#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 /* LILU_CUSTOM_KMOD_INIT */
bool ADDPR(debugEnabled) = false;
uint32_t ADDPR(debugPrintDelay) = 0;
#ifndef LILU_CUSTOM_IOKIT_INIT
OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)
PRODUCT_NAME *ADDPR(selfInstance) = nullptr;
IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) {
ADDPR(selfInstance) = this;
setProperty("VersionInfo", kextVersion);
auto service = IOService::probe(provider, score);
return ADDPR(startSuccess) ? service : nullptr;
}
bool PRODUCT_NAME::start(IOService *provider) {
ADDPR(selfInstance) = this;
if (!IOService::start(provider)) {
SYSLOG("init", "failed to start the parent");
return false;
}
return ADDPR(startSuccess);
}
void PRODUCT_NAME::stop(IOService *provider) {
ADDPR(selfInstance) = nullptr;
IOService::stop(provider);
}
#endif /* LILU_CUSTOM_IOKIT_INIT */
#ifndef LILU_CUSTOM_KMOD_INIT
EXPORT extern "C" kern_return_t ADDPR(kern_start)(kmod_info_t *, void *) {
// This is an ugly hack necessary on some systems where buffering kills most of debug output.
lilu_get_boot_args("liludelay", &ADDPR(debugPrintDelay), sizeof(ADDPR(debugPrintDelay)));
auto error = lilu.requestAccess();
if (error == LiluAPI::Error::NoError) {
error = lilu.shouldLoad(ADDPR(config).product, ADDPR(config).version, ADDPR(config).runmode, ADDPR(config).disableArg, ADDPR(config).disableArgNum,
ADDPR(config).debugArg, ADDPR(config).debugArgNum, ADDPR(config).betaArg, ADDPR(config).betaArgNum, ADDPR(config).minKernel,
ADDPR(config).maxKernel, ADDPR(debugEnabled));
if (error == LiluAPI::Error::NoError) {
DBGLOG("init", "%s bootstrap %s", xStringify(PRODUCT_NAME), kextVersion);
(void)kextVersion;
ADDPR(startSuccess) = true;
ADDPR(config).pluginStart();
} else {
SYSLOG("init", "parent said we should not continue %d", error);
}
lilu.releaseAccess();
} else {
SYSLOG("init", "failed to call parent %d", error);
}
for (size_t i = 0; i < ADDPR(config).debugArgNum; i++) {
if (checkKernelArgument(ADDPR(config).debugArg[i])) {
ADDPR(debugEnabled) = true;
break;
}
}
if (checkKernelArgument("-liludbgall"))
ADDPR(debugEnabled) = true;
// Report success but actually do not start and let I/O Kit unload us.
// This works better and increases boot speed in some cases.
return KERN_SUCCESS;
}
EXPORT extern "C" kern_return_t ADDPR(kern_stop)(kmod_info_t *, void *) {
// It is not safe to unload Lilu plugins unless they were disabled!
return ADDPR(startSuccess) ? KERN_FAILURE : KERN_SUCCESS;
}
#endif /* LILU_CUSTOM_KMOD_INIT */

View File

@ -0,0 +1,57 @@
#!/bin/bash
#
# build.tool
# Lilu
#
# Copyright © 2018 vit9696. All rights reserved.
#
cd $(dirname "$0") || exit 1
rm -f *.o *.bin wrappers.inc entry32 entry64
clang -m32 -c entry32.S || exit 1
clang -m64 -c entry64.S || exit 1
clang -m32 entry32.o -o entry32 || exit 1
clang -m64 entry64.o -o entry64 || exit 1
if [ "$(nm entry32.o | grep '00000000 T _main')" == "" ] || [ "$(nm entry64.o | grep '0000000000000000 T _main')" == "" ]; then
echo "Invalid main address"
exit 1
fi
otool -t entry32 | grep -E '^0000' | sed 's#^[0-9a-f]*##' | xxd -r -p > entry32.bin
otool -t entry64 | grep -E '^0000' | sed 's#^[0-9a-f]*##' | xxd -r -p > entry64.bin
sz32=$(stat -f '%z' entry32.bin)
sz64=$(stat -f '%z' entry64.bin)
btr32=$(nm entry32.o | grep -E 't booter$' | cut -f1 -d' ')
btr64=$(nm entry64.o | grep -E 't booter$' | cut -f1 -d' ')
ep32=$(nm entry32.o | grep -E 't entrypoint$' | cut -f1 -d' ')
ep64=$(nm entry64.o | grep -E 't entrypoint$' | cut -f1 -d' ')
echo '//' > wrappers.inc
echo '// wrappers.inc' >> wrappers.inc
echo '// Lilu' >> wrappers.inc
echo '//' >> wrappers.inc
echo '// Copyright © 2018 vit9696. All rights reserved.' >> wrappers.inc
echo '//' >> wrappers.inc
echo '' >> wrappers.inc
echo '// This is an autogenerated file, do not edit!' >> wrappers.inc
echo 'static uint8_t entryWrapper32[] = {' >> wrappers.inc
cat entry32.bin | xxd -i >> wrappers.inc
echo '};' >> wrappers.inc
echo 'static uint8_t entryWrapper64[] = {' >> wrappers.inc
cat entry64.bin | xxd -i >> wrappers.inc
echo '};' >> wrappers.inc
echo "static_assert(sizeof(entryWrapper32) == ${sz32}, \"Invalid entryWrapper32 size\");" >> wrappers.inc
echo "static_assert(sizeof(entryWrapper64) == ${sz64}, \"Invalid entryWrapper64 size\");" >> wrappers.inc
echo "static constexpr size_t EntryWrapper32Booter {0x${btr32}};" >> wrappers.inc
echo "static constexpr size_t EntryWrapper64Booter {0x${btr64}};" >> wrappers.inc
echo "static constexpr size_t EntryWrapper32Entry {0x${ep32}};" >> wrappers.inc
echo "static constexpr size_t EntryWrapper64Entry {0x${ep64}};" >> wrappers.inc
rm -f *.o *.bin entry32 entry64

View File

@ -0,0 +1,41 @@
#
# entry32.S
# Lilu
#
# Copyright © 2018 vit9696. All rights reserved.
#
.text
.global _main
_main:
push %ebp
mov %esp, %ebp
# ensure 16-byte alignment
and $0xfffffff0, %esp
# int main(int argc, const char* argv[], const char* envp[], const char* apple[]);
push 20(%ebp)
push 16(%ebp)
push 12(%ebp)
push 8(%ebp)
call get_booter
# entrypoint-compatible wrapper
booter:
.word 0xFFFF
.word 0xFFFF
get_booter:
pop %edx
mov (%edx), %edx
call *%edx
xor %eax, %eax
mov %ebp, %esp
pop %ebp
call get_entrypoint
# original entrypoint (main)
entrypoint:
.word 0xFFFF
.word 0xFFFF
get_entrypoint:
pop %edx
mov (%edx), %edx
jmp *%edx
_end:

View File

@ -0,0 +1,41 @@
#
# entry64.S
# Lilu
#
# Copyright © 2018 vit9696. All rights reserved.
#
.text
.global _main
_main:
push %rbp
mov %rsp, %rbp
# ensure 16-byte alignment
and $0xfffffffffffffff0, %rsp
# int main(int argc, const char* argv[], const char* envp[], const char* apple[]);
push %rdi
push %rsi
push %rdx
push %rcx
call *booter(%rip)
xor %eax, %eax
pop %rcx
pop %rdx
pop %rsi
pop %rdi
mov %rbp, %rsp
pop %rbp
jmp *entrypoint(%rip)
# original entrypoint (main)
entrypoint:
.word 0xFFFF
.word 0xFFFF
.word 0xFFFF
.word 0xFFFF
# entrypoint-compatible wrapper
booter:
.word 0xFFFF
.word 0xFFFF
.word 0xFFFF
.word 0xFFFF
_end:

View File

@ -0,0 +1,28 @@
//
// wrappers.inc
// Lilu
//
// Copyright © 2018 vit9696. All rights reserved.
//
// This is an autogenerated file, do not edit!
static uint8_t entryWrapper32[] = {
0x55, 0x89, 0xe5, 0x83, 0xe4, 0xf0, 0xff, 0x75, 0x14, 0xff, 0x75, 0x10,
0xff, 0x75, 0x0c, 0xff, 0x75, 0x08, 0xe8, 0x04, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0x5a, 0x8b, 0x12, 0xff, 0xd2, 0x31, 0xc0, 0x89, 0xec,
0x5d, 0xe8, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x5a, 0x8b,
0x12, 0xff, 0xe2
};
static uint8_t entryWrapper64[] = {
0x55, 0x48, 0x89, 0xe5, 0x48, 0x83, 0xe4, 0xf0, 0x57, 0x56, 0x52, 0x51,
0xff, 0x15, 0x18, 0x00, 0x00, 0x00, 0x31, 0xc0, 0x59, 0x5a, 0x5e, 0x5f,
0x48, 0x89, 0xec, 0x5d, 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff
};
static_assert(sizeof(entryWrapper32) == 51, "Invalid entryWrapper32 size");
static_assert(sizeof(entryWrapper64) == 50, "Invalid entryWrapper64 size");
static constexpr size_t EntryWrapper32Booter {0x00000017};
static constexpr size_t EntryWrapper64Booter {0x000000000000002a};
static constexpr size_t EntryWrapper32Entry {0x0000002a};
static constexpr size_t EntryWrapper64Entry {0x0000000000000022};