mirror of
https://github.com/keylase/nvidia-patch.git
synced 2025-10-11 01:28:01 +00:00
linux: autopatch: Find bytecode and update patch.sh
Have a two-script workflow where one focuses on finding the bytecode in the driver files, and the other focuses on updating patch.sh using the newly found bytecode or a previously existing one. Signed-off-by: Jai Luthra <me@jailuthra.in>
This commit is contained in:
45
tools/autopatch/find_bytecode.sh
Executable file
45
tools/autopatch/find_bytecode.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
(( $# == 2 )) || {
|
||||
>&2 echo "Usage: $0 <version> <URL>"
|
||||
exit 2
|
||||
}
|
||||
|
||||
MATCH_STR=feff85c04189c4
|
||||
driver_version=$1
|
||||
driver_url=$2
|
||||
driver_file=NVIDIA-Linux-x86_64-$driver_version.run
|
||||
|
||||
download_driver() {
|
||||
wget -c $driver_url -O $driver_file 1>&2
|
||||
chmod +x $driver_file
|
||||
}
|
||||
|
||||
extract_driver() {
|
||||
if [[ ! -e ${driver_file%".run"} ]]; then
|
||||
./$driver_file -x
|
||||
fi
|
||||
}
|
||||
|
||||
search_bytecode() {
|
||||
nvenc_file=${driver_file%".run"}/libnvidia-encode.so.$driver_version
|
||||
bytecode=$(xxd -c0 -ps $nvenc_file | grep -oP ".{0,6}$MATCH_STR")
|
||||
echo $bytecode
|
||||
}
|
||||
|
||||
get_patch_str() {
|
||||
bytecode=$1
|
||||
fixed=${bytecode:0:10}29${bytecode:(-8):8}
|
||||
bytecode=$(echo "$bytecode" | sed 's/../\\x&/g')
|
||||
fixed=$(echo "$fixed" | sed 's/../\\x&/g')
|
||||
echo "[\"$driver_version\"]='s/$bytecode/$fixed/g'"
|
||||
}
|
||||
|
||||
mkdir -p temp
|
||||
cd temp
|
||||
download_driver
|
||||
extract_driver
|
||||
get_patch_str $(search_bytecode)
|
||||
cd ..
|
Reference in New Issue
Block a user