forked from dartraiden/NVIDIA-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux.sh
More file actions
executable file
·75 lines (59 loc) · 2.18 KB
/
Copy pathlinux.sh
File metadata and controls
executable file
·75 lines (59 loc) · 2.18 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
INSTALLER=$(ls NVIDIA-Linux*.run 2>/dev/null | head -n 1)
if [ -z "$INSTALLER" ]; then
echo "Error: Installer not found."
exit 1
fi
# Extract files from installer
echo "Extracting $INSTALLER..."
chmod +x "$INSTALLER"
./"$INSTALLER" --extract-only
# Define the path to the binary inside the extracted directory
# The extracted folder matches the filename without .run
FILE="${INSTALLER%.run}/kernel/nvidia/nv-kernel.o_binary"
BACKUP="$FILE.backup"
if [ ! -f "$FILE" ]; then
echo "Error: File not found: $FILE"
exit 1
fi
echo "Creating backup: $BACKUP"
cp -f "$FILE" "$BACKUP"
# Convert file to hex dump (one big line)
HEX=$(xxd -p "$FILE" | tr -d '\n')
ORIGINAL_HEX=$HEX
# Define patterns in order (name|search|replace)
PATTERNS=(
"P1xx|071b0700871b0700c71b0700071c0700091c0700|ffff0700ffff0700ffff0700ffff0700ffff0700"
"CMP|091e0700491e0700bc1e0700fc1e07000b1f0700812007008220070083200700c2200700892107000d2207004d2207008a240700|ffff0700491e0700bc1e0700fc1e0700ffff070081200700ffff070083200700ffff0700ffff0700ffff07004d220700ffff0700"
"RTX 3080 Ti 20 GB|05220000092200001422000017220000|ffff0000092200001422000017220000"
"RTX 3060 3840SP|01250000052500000925000040250000|ffff0000052500000925000040250000"
"RTX 4070 10 GB|85270000af270000bf270000c2270000|ffff0000af270000bf270000c2270000"
"NVIDIA L40 ES|af260000b0260000bf260000c1260000|ffff0000b0260000bf260000c1260000"
)
# Build sed script for all replacements at once
SED_SCRIPT=""
for pattern in "${PATTERNS[@]}"; do
IFS='|' read -r name search replace <<< "$pattern"
# Count occurrences efficiently
count=$(grep -o "$search" <<< "$HEX" | wc -l)
if [ "$count" -gt 0 ]; then
echo "Found pattern: $name — $count occurrence(s)"
SED_SCRIPT+="s/$search/$replace/g;"
else
echo "Pattern not found: $name"
fi
done
# Apply all replacements in one sed call
if [ -n "$SED_SCRIPT" ]; then
HEX=$(sed "$SED_SCRIPT" <<< "$HEX")
fi
# Check if modified
if [ "$HEX" = "$ORIGINAL_HEX" ]; then
echo "No patterns found. Nothing patched."
exit 0
fi
# Convert back to binary
echo "$HEX" | xxd -r -p > "$FILE"
echo "=== SUCCESS ==="
echo "Patching complete."