forked from RehabMan/HP-ProBook-4x30s-DSDT-Patch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-patch_hda.sh
executable file
·47 lines (39 loc) · 1.92 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
#!/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..."
efi=`sudo ./mount_efi.sh /`
# patch binary using AppleHDA patches in config.plist/KernelAndKextPatches/KextsToPatch
bin=$unpatched/AppleHDA.kext/Contents/MacOS/AppleHDA
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 /