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,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};