blob: 0ac41e111fbb74442bc3b8064bf4fbe8f01cfa92 (
plain)
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
|
#!/usr/bin/env bash
set -euo pipefail
# Files to scan/patch
BROWSERS=$'/opt/google/chrome-beta/chrome
/opt/google/chrome-unstable/chrome
/opt/google/chrome/chrome
/opt/vivaldi/vivaldi-bin'
# Hex patterns
PATCH_BYTES=$'\x1f\x47\x6b\x47\x1f'
ORIG_BYTES=$'\x08\x4d\x56\x4d\x08'
find_offset() {
# Print byte offset of the ALL match
local f=$1
rg -a -b -o $ORIG_BYTES --no-filename --no-line-number -- "$f" | cut -d: -f1
}
patch_at() {
# Overwrite 5 bytes at given byte OFFSET
local f=$1 off=$2
printf "$PATCH_BYTES" | dd conv=notrunc of="$f" bs=1 seek="$off" status=none
}
for browser in $BROWSERS; do
[ -f "$browser" ] || continue
echo "Checking and patching freetype filters in $browser. This can take a while..."
off=$(find_offset "$browser" || true)
if [ -z "${off:-}" ]; then
echo "> Original filter pattern not found in $browser. It might have already been patched."
continue
fi
printf "> Original filter pattern found in %s. Patching at offset 0x%x\n" "$browser" "$off"
if patch_at "$browser" "$off"; then
echo "> Patch successfully"
else
echo "> Failed to patch"
fi
done
|