-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathpre-patch_hda.sh
executable file
·48 lines (40 loc) · 2.01 KB
/
pre-patch_hda.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
#set -x
unpatched=/System/Library/Extensions
echo "Type your password if requested (to mount EFI partition, and to patch $unpatched/AppleHDA.kext binary)"
# AppleHDA patching function
function prepatchAppleHDAbinary()
{
echo "Patching $unpatched/AppleHDA.kext..."
local EFI=$("$(dirname ${BASH_SOURCE[0]})"/mount_efi.sh)
local TOOLS="$(dirname ${BASH_SOURCE[0]})"
# patch binary using AppleHDA patches in config.plist/KernelAndKextPatches/KextsToPatch
local bin=$unpatched/AppleHDA.kext/Contents/MacOS/AppleHDA
local config="$EFI"/EFI/CLOVER/config.plist
echo $config
for ((patch=0; 1; patch++)); do
comment=`/usr/libexec/PlistBuddy -c "Print :KernelAndKextPatches:KextsToPatch:$patch:Comment" "$config" 2>&1`
if [[ "$comment" == *"Does Not Exist"* ]]; then
break
fi
name=`/usr/libexec/PlistBuddy -c "Print :KernelAndKextPatches:KextsToPatch:$patch:Name" "$config" 2>&1`
if [[ "$name" == "com.apple.driver.AppleHDA" ]]; then
disabled=`/usr/libexec/PlistBuddy -c "Print :KernelAndKextPatches:KextsToPatch:$patch:Disabled" "$config" 2>&1`
if [[ "$disabled" != "true" ]]; then
printf "Comment: %s\n" "$comment"
find=`/usr/libexec/PlistBuddy -x -c "Print :KernelAndKextPatches:KextsToPatch:$patch:Find" "$config" 2>&1`
repl=`/usr/libexec/PlistBuddy -x -c "Print :KernelAndKextPatches:KextsToPatch:$patch:Replace" "$config"`
find=$([[ "$find" =~ \<data\>(.*)\<\/data\> ]] && echo ${BASH_REMATCH[1]})
repl=$([[ "$repl" =~ \<data\>(.*)\<\/data\> ]] && echo ${BASH_REMATCH[1]})
find=`echo $find | base64 --decode | xxd -p | tr '\n' ' '`
repl=`echo $repl | base64 --decode | xxd -p | tr '\n' ' '`
sudo "$TOOLS"/binpatch "$find" "$repl" $bin
fi
fi
done
echo "Done."
}
# patch the binary
prepatchAppleHDAbinary
# update kernel cache
sudo touch /System/Library/Extensions && sudo kextcache -u /